From 13cfae2eb6ab21290cd8f9fd3eb9cefa7168aaa7 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Fri, 24 Apr 2015 23:02:59 +0200 Subject: [PATCH 1/4] payment_mode_id should be in Invoice not InvoiceLine --- htdocs/webservices/server_invoice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index 9c5bd24b463..cb3f03121b5 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -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'), From 918d59b0d48203968242bcc5cb68a448a337abaa Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Fri, 24 Apr 2015 23:41:54 +0200 Subject: [PATCH 2/4] fix updateOrder result values --- htdocs/webservices/server_order.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/webservices/server_order.php b/htdocs/webservices/server_order.php index 694404a3d8e..5db4adb2560 100644 --- a/htdocs/webservices/server_order.php +++ b/htdocs/webservices/server_order.php @@ -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) From fa9cb49fcb06da72317627c2f9c3cf45ed010197 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Fri, 24 Apr 2015 23:42:35 +0200 Subject: [PATCH 3/4] add updateInvoice webservice call --- htdocs/webservices/server_invoice.php | 117 +++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 3 deletions(-) diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index cb3f03121b5..49720026582 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -250,6 +250,18 @@ $server->register( $styleuse, 'WS to create an invoice' ); +$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 +399,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 +472,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 +515,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 +526,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); @@ -601,5 +619,98 @@ function createInvoice($authentication,$invoice) 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")); From 4e10b94b6b3f7cbcc795770cac685ea6632df4eb Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Sat, 25 Apr 2015 00:38:32 +0200 Subject: [PATCH 4/4] Add webservice method createInvoiceFromOrder --- htdocs/webservices/server_invoice.php | 112 +++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 2 deletions(-) diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index 49720026582..b55a22fbcd9 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -243,13 +243,25 @@ $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 @@ -599,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 { @@ -619,6 +632,101 @@ 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 *