Merge branch '3.7-webservices-fix' of https://github.com/aaujon/dolibarr into 3.7-webservices-fix

This commit is contained in:
Arnaud Aujon 2015-05-04 10:36:17 +02:00
commit ef08283bbd
2 changed files with 228 additions and 7 deletions

View File

@ -102,7 +102,6 @@ $server->wsdl->addComplexType(
'total' => array('name'=>'total','type'=>'xsd:double'),
'date_start' => array('name'=>'date_start','type'=>'xsd:date'),
'date_end' => array('name'=>'date_end','type'=>'xsd:date'),
'payment_mode_id' => array('name'=>'payment_mode_id','type'=>'xsd:string'),
// From product
'product_id' => array('name'=>'product_id','type'=>'xsd:int'),
'product_ref' => array('name'=>'product_ref','type'=>'xsd:string'),
@ -160,6 +159,7 @@ $server->wsdl->addComplexType(
'date_creation' => array('name'=>'date_creation','type'=>'xsd:dateTime'),
'date_validation' => array('name'=>'date_validation','type'=>'xsd:dateTime'),
'date_modification' => array('name'=>'date_modification','type'=>'xsd:dateTime'),
'payment_mode_id' => array('name'=>'payment_mode_id','type'=>'xsd:string'),
'type' => array('name'=>'type','type'=>'xsd:int'),
'total_net' => array('name'=>'type','type'=>'xsd:double'),
'total_vat' => array('name'=>'type','type'=>'xsd:double'),
@ -243,13 +243,37 @@ $server->register(
// Entry values
array('authentication'=>'tns:authentication','invoice'=>'tns:invoice'),
// Exit values
array('result'=>'tns:result','id'=>'xsd:string','ref'=>'xsd:string'),
array('result'=>'tns:result','id'=>'xsd:string','ref'=>'xsd:string','ref_ext'=>'xsd:string'),
$ns,
$ns.'#createInvoice',
$styledoc,
$styleuse,
'WS to create an invoice'
);
$server->register(
'createInvoiceFromOrder',
// Entry values
array('authentication'=>'tns:authentication','invoice'=>'tns:invoice'),
// Exit values
array('result'=>'tns:result','invoice'=>'tns:invoice'),
$ns,
$ns.'#createInvoiceFromOrder',
$styledoc,
$styleuse,
'WS to create an invoice from an order'
);
$server->register(
'updateInvoice',
// Entry values
array('authentication'=>'tns:authentication','invoice'=>'tns:invoice'),
// Exit values
array('result'=>'tns:result','id'=>'xsd:string','ref'=>'xsd:string','ref_ext'=>'xsd:string'),
$ns,
$ns.'#updateInvoice',
$styledoc,
$styleuse,
'WS to update an invoice'
);
/**
@ -387,7 +411,7 @@ function getInvoicesForThirdParty($authentication,$idthirdparty)
if (! $error && empty($idthirdparty))
{
$error++;
$errorcode='BAD_PARAMETERS'; $errorlabel='Parameter id is not provided';
$errorcode='BAD_PARAMETERS'; $errorlabel='Parameter idthirdparty is not provided';
}
if (! $error)
@ -460,7 +484,7 @@ function getInvoicesForThirdParty($authentication,$idthirdparty)
'status'=> $invoice->statut,
'close_code' => $invoice->close_code?$invoice->close_code:'',
'close_note' => $invoice->close_note?$invoice->close_note:'',
'payment_mode_id' => $invoice->mode_reglement_id?$invoice->mode_reglement_id:'',
'payment_mode_id' => $invoice->mode_reglement_id?$invoice->mode_reglement_id:'',
'lines' => $linesresp
);
}
@ -503,7 +527,8 @@ function createInvoice($authentication,$invoice)
$now=dol_now();
dol_syslog("Function: createInvoiceForThirdParty login=".$authentication['login']);
dol_syslog("Function: createInvoice login=".$authentication['login']." id=".$invoice->id.
", ref=".$invoice->ref.", ref_ext=".$invoice->ref_ext);
if ($authentication['entity']) $conf->entity=$authentication['entity'];
@ -513,6 +538,11 @@ function createInvoice($authentication,$invoice)
$error=0;
$fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
// Check parameters
if (empty($invoice['id']) && empty($invoice['ref']) && empty($invoice['ref_ext'])) {
$error++; $errorcode='KO'; $errorlabel="Invoice id or ref or ref_ext is mandatory.";
}
if (! $error)
{
$newobject=new Facture($db);
@ -581,7 +611,8 @@ function createInvoice($authentication,$invoice)
if (! $error)
{
$db->commit();
$objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''),'id'=>$newobject->id,'ref'=>$newobject->ref);
$objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''),'id'=>$newobject->id,
'ref'=>$newobject->ref,'ref_ext'=>$newobject->ref_ext);
}
else
{
@ -601,5 +632,193 @@ function createInvoice($authentication,$invoice)
return $objectresp;
}
/**
* Create an invoice from an order
*
* @param array $authentication Array of authentication information
* @param string $id_order id of order to copy invoice from
* @param string $ref_order ref of order to copy invoice from
* @param string $ref_ext_order ref_ext of order to copy invoice from
* @param string $id_invoice invoice id
* @param string $ref_invoice invoice ref
* @param string $ref_ext_invoice invoice ref_ext
* @return array Array result
*/
function createInvoiceFromOrder($authentication,$id_order='', $ref_order='', $ref_ext_order='',
$id_invoice='', $ref_invoice='', $ref_ext_invoice='')
{
global $db,$conf,$langs;
$now=dol_now();
dol_syslog("Function: createInvoiceFromOrder login=".$authentication['login']." id=".$id_order.
", ref=".$ref_order.", ref_ext=".$ref_ext_order);
if ($authentication['entity']) $conf->entity=$authentication['entity'];
// Init and check authentication
$objectresp=array();
$errorcode='';$errorlabel='';
$error=0;
$fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
// Check parameters
if (empty($id_order) && empty($ref_order) && empty($ref_ext_order)) {
$error++; $errorcode='KO'; $errorlabel="order id or ref or ref_ext is mandatory.";
} else if (empty($id_invoice) && empty($ref_invoice) && empty($ref_ext_invoice)) {
$error++; $errorcode='KO'; $errorlabel="invoice id or ref or ref_ext is mandatory.";
}
//////////////////////
if (! $error)
{
$fuser->getrights();
if ($fuser->rights->commande->lire)
{
$order=new Commande($db);
$result=$order->fetch($id,$ref,$ref_ext);
if ($result > 0)
{
// Security for external user
if( $socid && ( $socid != $order->socid) )
{
$error++;
$errorcode='PERMISSION_DENIED'; $errorlabel=$order->socid.'User does not have permission for this request';
}
if(!$error)
{
$newobject=new Facture($db);
$result = $newobject->createFromOrder($order);
if ($result < 0)
{
$error++;
dol_syslog("Webservice server_invoice:: invoice creation from order failed", LOG_ERR);
}
}
}
else
{
$error++;
$errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id_order.' nor ref='.$ref_order.' nor ref_ext='.$ref_ext_order;
}
}
else
{
$error++;
$errorcode='PERMISSION_DENIED'; $errorlabel='User does not have permission for this request';
}
}
if ($error)
{
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
}
else
{
$objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''),'invoice'=>$newobject);
}
return $objectresp;
}
/**
* Uddate an invoice, only change the state of an invoice
*
* @param array $authentication Array of authentication information
* @param Facture $invoice Invoice
* @return array Array result
*/
function updateInvoice($authentication,$invoice)
{
global $db,$conf,$langs;
dol_syslog("Function: updateInvoice login=".$authentication['login']." id=".$invoice->id.
", ref=".$invoice->ref.", ref_ext=".$invoice->ref_ext);
if ($authentication['entity']) $conf->entity=$authentication['entity'];
// Init and check authentication
$objectresp=array();
$errorcode='';$errorlabel='';
$error=0;
$fuser=check_authentication($authentication,$error,$errorcode,$errorlabel);
// Check parameters
if (empty($invoice['id']) && empty($invoice['ref']) && empty($invoice['ref_ext'])) {
$error++; $errorcode='KO'; $errorlabel="Invoice id or ref or ref_ext is mandatory.";
}
if (! $error)
{
$objectfound=false;
$object=new Facture($db);
$result=$object->fetch($invoice['id'],$invoice['ref'],$invoice['ref_ext'], '');
if (!empty($object->id)) {
$objectfound=true;
$db->begin();
if (isset($invoice['status']))
{
if ($invoice['status'] == 0) $result=$object->set_draft($fuser);
if ($invoice['status'] == 1)
{
$result=$object->validate($fuser);
if ($result >= 0)
{
// Define output language
$outputlangs = $langs;
$order->generateDocument($invoice->modelpdf, $outputlangs);
}
}
if ($invlice['status'] == 2)
{
$result = $object->set_paid($fuser,$invoice->close_code,$invoice->close_note);
}
if ($invoice['status'] == 3) $result=$object->set_canceled($fuser,$invoice->close_code,$invoice->close_note);
}
}
if ((! $error) && ($objectfound))
{
$db->commit();
$objectresp=array(
'result'=>array('result_code'=>'OK', 'result_label'=>''),
'id'=>$object->id,
'ref'=>$object->ref,
'ref_ext'=>$object->ref_ext
);
}
elseif ($objectfound)
{
$db->rollback();
$error++;
$errorcode='KO';
$errorlabel=$object->error;
} else {
$error++;
$errorcode='NOT_FOUND';
$errorlabel='Invoice id='.$invoice['id'].' ref='.$invoice['ref'].' ref_ext='.$invoice['ref_ext'].' cannot be found';
}
}
if ($error)
{
$objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel));
}
return $objectresp;
}
// Return the results.
$server->service(file_get_contents("php://input"));

View File

@ -961,7 +961,9 @@ function updateOrder($authentication,$order)
$db->commit();
$objectresp=array(
'result'=>array('result_code'=>'OK', 'result_label'=>''),
'id'=>$object->id
'id'=>$object->id,
'ref'=>$object->ref,
'ref_ext'=>$object->ref_ext
);
}
elseif ($objectfound)