From afc4d89c64c83bc93e5ed8d048e09dfe21a65ade Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Mon, 20 Apr 2015 20:18:17 +0200 Subject: [PATCH 01/20] Orders webservice : Generate pdf document on valid --- htdocs/webservices/server_order.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/htdocs/webservices/server_order.php b/htdocs/webservices/server_order.php index 9229d3b9c26..bf2eab8591c 100644 --- a/htdocs/webservices/server_order.php +++ b/htdocs/webservices/server_order.php @@ -916,7 +916,17 @@ function updateOrder($authentication,$order) if (isset($order['status'])) { if ($order['status'] == -1) $result=$object->cancel($fuser); - if ($order['status'] == 1) $result=$object->valid($fuser); + if ($order['status'] == 1) + { + $result=$object->valid($fuser); + if ($result >= 0) + { + // Define output language + $outputlangs = $langs; + $order->generateDocument($order->modelpdf, $outputlangs); + + } + } if ($order['status'] == 0) $result=$object->set_reopen($fuser); if ($order['status'] == 3) $result=$object->cloture($fuser); } From 97fc99517e50f96f0548aa8f880180a334aa877f Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Wed, 22 Apr 2015 12:47:45 +0200 Subject: [PATCH 02/20] Fixes : contact webservice fix update using ref_ext --- htdocs/webservices/server_contact.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/htdocs/webservices/server_contact.php b/htdocs/webservices/server_contact.php index ec652e80074..e0d76a0eb90 100644 --- a/htdocs/webservices/server_contact.php +++ b/htdocs/webservices/server_contact.php @@ -627,9 +627,15 @@ function updateContact($authentication,$contact) $error=0; $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel); // Check parameters - if (empty($contact['id'])) { - $error++; $errorcode='KO'; $errorlabel="Contact id is mandatory."; + if (empty($contact['id']) && empty($contact['ref_ext']) { + $error++; $errorcode='KO'; $errorlabel="Contact id or ref_ext is mandatory."; } + // Check parameters + if (! $error && ($id && $ref_ext)) + { + $error++; + $errorcode='BAD_PARAMETERS'; $errorlabel="Parameter id and ref_ext can't be all provided. You must choose one of them."; + } if (! $error) { @@ -638,7 +644,7 @@ function updateContact($authentication,$contact) include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; $object=new Contact($db); - $result=$object->fetch($contact['id']); + $result=$object->fetch($contact['id'],0,$contact['ref_ext']); if (!empty($object->id)) { From 13cfae2eb6ab21290cd8f9fd3eb9cefa7168aaa7 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Fri, 24 Apr 2015 23:02:59 +0200 Subject: [PATCH 03/20] 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 04/20] 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 05/20] 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 06/20] 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 * From d8027bd71d2336275848854fbd96b7158c25b0b6 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Mon, 4 May 2015 11:36:40 +0200 Subject: [PATCH 07/20] add thirdparty_id to get invoice --- htdocs/webservices/server_invoice.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index b55a22fbcd9..a9bc0a8ee44 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -343,6 +343,7 @@ function getInvoice($authentication,$id='',$ref='',$ref_ext='') 'id' => $invoice->id, 'ref' => $invoice->ref, 'ref_ext' => $invoice->ref_ext?$invoice->ref_ext:'', // If not defined, field is not added into soap + 'thirdparty_id' => $invoice->socid, 'fk_user_author' => $invoice->user_author?$invoice->user_author:'', 'fk_user_valid' => $invoice->user_valid?$invoice->user_valid:'', 'date' => $invoice->date?dol_print_date($invoice->date,'dayrfc'):'', From d27934419cf5dc51dfe20d47fb8eb2bc7cf4d07d Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Mon, 4 May 2015 11:36:53 +0200 Subject: [PATCH 08/20] fix log --- htdocs/webservices/server_contact.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/webservices/server_contact.php b/htdocs/webservices/server_contact.php index e0d76a0eb90..5db38052c7e 100644 --- a/htdocs/webservices/server_contact.php +++ b/htdocs/webservices/server_contact.php @@ -273,7 +273,7 @@ function getContact($authentication,$id,$ref_ext) ){ $contact_result_fields =array( 'id' => $contact->id, - 'ref_ext' => $contact->ref_ext, + 'ref_ext' => $contact->ref_ext, 'lastname' => $contact->lastname, 'firstname' => $contact->firstname, 'address' => $contact->address, @@ -336,7 +336,7 @@ function getContact($authentication,$id,$ref_ext) else { $error++; - $errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext; + $errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id.' nor ref_ext='.$ref_ext; } } From 8b753dc74323526575c114c5d7bd923837f1ed27 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Chevallier Date: Tue, 5 May 2015 10:05:13 +0200 Subject: [PATCH 09/20] fix typo --- htdocs/webservices/server_contact.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/webservices/server_contact.php b/htdocs/webservices/server_contact.php index 5db38052c7e..cbc126ebb5a 100644 --- a/htdocs/webservices/server_contact.php +++ b/htdocs/webservices/server_contact.php @@ -627,7 +627,7 @@ function updateContact($authentication,$contact) $error=0; $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel); // Check parameters - if (empty($contact['id']) && empty($contact['ref_ext']) { + if (empty($contact['id']) && empty($contact['ref_ext'])) { $error++; $errorcode='KO'; $errorlabel="Contact id or ref_ext is mandatory."; } // Check parameters From d020c4133a643d35c388df3ae34738c5d9b6d194 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Chevallier Date: Tue, 5 May 2015 10:26:05 +0200 Subject: [PATCH 10/20] webservice_order : return all necessary fields --- htdocs/webservices/server_invoice.php | 33 ++++++++++++++++++--------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index a9bc0a8ee44..195662c46f9 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -323,15 +323,19 @@ function getInvoice($authentication,$id='',$ref='',$ref_ext='') $linesresp[]=array( 'id'=>$line->rowid, 'type'=>$line->product_type, - 'desc'=>dol_htmlcleanlastbr($line->desc), - 'total_net'=>$line->total_ht, - 'total_vat'=>$line->total_tva, - 'total'=>$line->total_ttc, - 'vat_rate'=>$line->tva_tx, - 'qty'=>$line->qty, - 'product_ref'=>$line->product_ref, - 'product_label'=>$line->product_label, - 'product_desc'=>$line->product_desc, + 'desc'=>dol_htmlcleanlastbr($line->desc), + 'total_net'=>$line->total_ht, + 'total_vat'=>$line->total_tva, + 'total'=>$line->total_ttc, + 'vat_rate'=>$line->tva_tx, + 'qty'=>$line->qty, + 'unitprice'=> $line->subprice, + 'date_start'=> $line->date_start?dol_print_date($line->date_start,'dayrfc'):'', + 'date_end'=> $line->date_end?dol_print_date($line->date_end,'dayrfc'):'', + 'product_id'=>$line->fk_product, + 'product_ref'=>$line->product_ref, + 'product_label'=>$line->product_label, + 'product_desc'=>$line->product_desc, ); $i++; } @@ -347,6 +351,7 @@ function getInvoice($authentication,$id='',$ref='',$ref_ext='') 'fk_user_author' => $invoice->user_author?$invoice->user_author:'', 'fk_user_valid' => $invoice->user_valid?$invoice->user_valid:'', 'date' => $invoice->date?dol_print_date($invoice->date,'dayrfc'):'', + 'date_due' => $invoice->date_lim_reglement?dol_print_date($invoice->date_lim_reglement,'dayrfc'):'', 'date_creation' => $invoice->date_creation?dol_print_date($invoice->date_creation,'dayhourrfc'):'', 'date_validation' => $invoice->date_validation?dol_print_date($invoice->date_creation,'dayhourrfc'):'', 'date_modification' => $invoice->datem?dol_print_date($invoice->datem,'dayhourrfc'):'', @@ -356,7 +361,8 @@ function getInvoice($authentication,$id='',$ref='',$ref_ext='') 'total' => $invoice->total_ttc, 'note_private' => $invoice->note_private?$invoice->note_private:'', 'note_public' => $invoice->note_public?$invoice->note_public:'', - 'status'=> $invoice->statut, + 'status' => $invoice->statut, + 'project_id' => $invoic->fk_project, '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:'', @@ -458,6 +464,10 @@ function getInvoicesForThirdParty($authentication,$idthirdparty) 'total'=>$line->total_ttc, 'vat_rate'=>$line->tva_tx, 'qty'=>$line->qty, + 'unitprice'=> $line->subprice, + 'date_start'=> $line->date_start?dol_print_date($line->date_start,'dayrfc'):'', + 'date_end'=> $line->date_end?dol_print_date($line->date_end,'dayrfc'):'', + 'product_id'=>$line->fk_product, 'product_ref'=>$line->product_ref, 'product_label'=>$line->product_label, 'product_desc'=>$line->product_desc, @@ -473,7 +483,7 @@ function getInvoicesForThirdParty($authentication,$idthirdparty) 'fk_user_valid' => $invoice->user_valid?$invoice->user_valid:'', 'date' => $invoice->date?dol_print_date($invoice->date,'dayrfc'):'', 'date_due' => $invoice->date_lim_reglement?dol_print_date($invoice->date_lim_reglement,'dayrfc'):'', - 'date_creation' => $invoice->date_creation?dol_print_date($invoice->date_creation,'dayhourrfc'):'', + 'date_creation' => $invoice->date_creation?dol_print_date($invoice->date_creation,'dayhourrfc'):'', 'date_validation' => $invoice->date_validation?dol_print_date($invoice->date_creation,'dayhourrfc'):'', 'date_modification' => $invoice->datem?dol_print_date($invoice->datem,'dayhourrfc'):'', 'type' => $invoice->type, @@ -483,6 +493,7 @@ function getInvoicesForThirdParty($authentication,$idthirdparty) 'note_private' => $invoice->note_private?$invoice->note_private:'', 'note_public' => $invoice->note_public?$invoice->note_public:'', 'status'=> $invoice->statut, + 'project_id' => $invoic->fk_project, '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:'', From 4fd8d6c05af1d387579ebf1abdd139ab966fddad Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Chevallier Date: Tue, 5 May 2015 21:37:10 +0200 Subject: [PATCH 11/20] fix typo --- 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 195662c46f9..3cd6ec97d87 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -793,7 +793,7 @@ function updateInvoice($authentication,$invoice) $order->generateDocument($invoice->modelpdf, $outputlangs); } } - if ($invlice['status'] == 2) + if ($invoice['status'] == 2) { $result = $object->set_paid($fuser,$invoice->close_code,$invoice->close_note); } From 2db885a2b328d6847be90271fcf07c7c5d75f031 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Mon, 11 May 2015 13:51:57 +0200 Subject: [PATCH 12/20] first attempt to add test --- test/phpunit/WebservicesInvoicesTest.php | 225 ++++++++++++++++++++++- 1 file changed, 222 insertions(+), 3 deletions(-) diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php index 20e01595375..a295dbdc64e 100755 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -102,6 +102,8 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; + + // create a third_party, needed to create an invoice print __METHOD__."\n"; } @@ -118,11 +120,118 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase /** - * testWSInvoicesXxx + * testWSInvoicesCreateInvoice * * @return int */ - public function testWSInvoicesXxx() + public function testWSInvoicesCreateInvoice() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php'; + $WS_METHOD = 'createInvoice'; + $ns='http://www.dolibarr.org/ns/'; + + // Set the WebService URL + print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; + $soapclient = new nusoap_client($WS_DOL_URL); + if ($soapclient) + { + $soapclient->soap_defencoding='UTF-8'; + $soapclient->decodeUTF8(false); + } + + $body = array ( + ["id"] => NULL, + ["ref"]=> NULL, + ["ref_ext"]=> "165", + ["thirdparty_id"]=> "209", + ["fk_user_author"] => NULL, + ["fk_user_valid"] => NULL, + ["date"]=> "2015-04-19 20:16:53", + ["date_due"]=> "", + ["date_creation"]=> "", + ["date_validation"]=> "", + ["date_modification"]=> "", + ["type"]=> "", + ["total_net"]=> "36.30", + ["total_vat"]=> "6.00", + ["total"]=> "42.30", + ["payment_mode_id"]=> 50, + ["note_private"]=> "Synchronised from Prestashop", + ["note_public"]=> "", + ["status"]=> "1", + ["close_code"]=> NULL , + ["close_note"]=> NULL, + ["project_id"]=> NULL, + ["lines"] => array( + ["id"] => NULL, + ["type"]=> 0, + ["desc"]=> "Horloge Vinyle Serge", + ["vat_rate"]=> 20, + ["qty"]=> "1", + ["unitprice"]=> "30.000000", + ["total_net"]=> "30.000000", + ["total_vat"]=> "6.00", + ["total"]=> "36.000000", + ["date_start"]=> "", + ["date_end"]=> "", + ["payment_mode_id"]=> "", + ["product_id"]=> "", + ["product_ref"]=> "", + ["product_label"]=> "", + ["product_desc"]=> "" ) + ); + + // Call the WebService method and store its result in $result. + $authentication=array( + 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, + 'sourceapplication'=>'DEMO', + 'login'=>'admin', + 'password'=>'admin', + 'entity'=>''); + + // Test URL + $result=''; + $parameters = array('authentication'=>$authentication,'invoice'=>$body); + print __METHOD__." call method ".$WS_METHOD."\n"; + try { + $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); + } + catch(SoapFault $exception) + { + echo $exception; + $result=0; + } + if (! $result || ! empty($result['faultstring'])) + { + //var_dump($soapclient); + print $soapclient->error_str; + print "\n
\n"; + print $soapclient->request; + print "\n
\n"; + print $soapclient->response; + print "\n"; + } + + print __METHOD__." result=".$result."\n"; + $this->assertEquals('OK',$result['result']['result_code']); + $this->assertEquals('165', $result['ref_ext']); + + + return $result; + } + + /** + * testWSInvoicesGetInvoice + * + * @return int + */ + public function testWSInvoicesGetInvoice() { global $conf,$user,$langs,$db; $conf=$this->savconf; @@ -153,7 +262,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase // Test URL $result=''; - $parameters = array('authentication'=>$authentication,'id'=>1); + $parameters = array('authentication'=>$authentication,'id'=>NULL,'ref'=>NULL,'ref_ext'=>165); print __METHOD__." call method ".$WS_METHOD."\n"; try { $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); @@ -176,6 +285,116 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase print __METHOD__." result=".$result."\n"; $this->assertEquals('OK',$result['result']['result_code']); + $this->assertEquals('165', $result['result']['invoice']->ref_ext); + + + return $result; + } + + /** + * testWSInvoicesUpdateInvoice + * + * @return int + */ + public function testWSInvoicesUpdateInvoice() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php'; + $WS_METHOD = 'updateInvoice'; + $ns='http://www.dolibarr.org/ns/'; + + // Set the WebService URL + print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; + $soapclient = new nusoap_client($WS_DOL_URL); + if ($soapclient) + { + $soapclient->soap_defencoding='UTF-8'; + $soapclient->decodeUTF8(false); + } + + // update status to 2 + $body = array ( + ["id"] => NULL, + ["ref"]=> NULL, + ["ref_ext"]=> "165", + ["thirdparty_id"]=> "209", + ["fk_user_author"] => NULL, + ["fk_user_valid"] => NULL, + ["date"]=> "2015-04-19 20:16:53", + ["date_due"]=> "", + ["date_creation"]=> "", + ["date_validation"]=> "", + ["date_modification"]=> "", + ["type"]=> "", + ["total_net"]=> "36.30", + ["total_vat"]=> "6.00", + ["total"]=> "42.30", + ["payment_mode_id"]=> 50, + ["note_private"]=> "Synchronised from Prestashop", + ["note_public"]=> "", + ["status"]=> "2", + ["close_code"]=> NULL , + ["close_note"]=> NULL, + ["project_id"]=> NULL, + ["lines"] => array( + ["id"] => NULL, + ["type"]=> 0, + ["desc"]=> "Horloge Vinyle Serge", + ["vat_rate"]=> 20, + ["qty"]=> "1", + ["unitprice"]=> "30.000000", + ["total_net"]=> "30.000000", + ["total_vat"]=> "6.00", + ["total"]=> "36.000000", + ["date_start"]=> "", + ["date_end"]=> "", + ["payment_mode_id"]=> "", + ["product_id"]=> "", + ["product_ref"]=> "", + ["product_label"]=> "", + ["product_desc"]=> "" ) + ); + + // Call the WebService method and store its result in $result. + $authentication=array( + 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, + 'sourceapplication'=>'DEMO', + 'login'=>'admin', + 'password'=>'admin', + 'entity'=>''); + + // Test URL + $result=''; + $parameters = array('authentication'=>$authentication,'invoice'=>$body); + print __METHOD__." call method ".$WS_METHOD."\n"; + try { + $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); + } + catch(SoapFault $exception) + { + echo $exception; + $result=0; + } + if (! $result || ! empty($result['faultstring'])) + { + //var_dump($soapclient); + print $soapclient->error_str; + print "\n
\n"; + print $soapclient->request; + print "\n
\n"; + print $soapclient->response; + print "\n"; + } + + print __METHOD__." result=".$result."\n"; + $this->assertEquals('OK',$result['result']['result_code']); + $this->assertEquals('2', $result['result']['invoice']->status); + return $result; } From 278d447e45f1f7863c7c2c943411c0cc8e191116 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Wed, 27 May 2015 15:42:34 +0200 Subject: [PATCH 13/20] Use Constant for status --- htdocs/webservices/server_invoice.php | 51 ++++++++++++++------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index 336917a8c60..d358847c0b6 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -557,25 +557,25 @@ function createInvoice($authentication,$invoice) if (! $error) { - $newobject=new Facture($db); - $newobject->socid=$invoice['thirdparty_id']; - $newobject->type=$invoice['type']; - $newobject->ref_ext=$invoice['ref_ext']; - $newobject->date=dol_stringtotime($invoice['date'],'dayrfc'); - $newobject->note_private=$invoice['note_private']; - $newobject->note_public=$invoice['note_public']; - $newobject->statut= Facture::STATUS_DRAFT; // We start with status draft - $newobject->fk_project=$invoice['project_id']; - $newobject->date_creation=$now; + $new_invoice=new Facture($db); + $new_invoice->socid=$invoice['thirdparty_id']; + $new_invoice->type=$invoice['type']; + $new_invoice->ref_ext=$invoice['ref_ext']; + $new_invoice->date=dol_stringtotime($invoice['date'],'dayrfc'); + $new_invoice->note_private=$invoice['note_private']; + $new_invoice->note_public=$invoice['note_public']; + $new_invoice->statut= Facture::STATUS_DRAFT; // We start with status draft + $new_invoice->fk_project=$invoice['project_id']; + $new_invoice->date_creation=$now; //take mode_reglement and cond_reglement from thirdparty $soc = new Societe($db); - $res=$soc->fetch($newobject->socid); + $res=$soc->fetch($new_invoice->socid); if ($res > 0) { - $newobject->mode_reglement_id = ! empty($invoice['payment_mode_id'])?$invoice['payment_mode_id']:$soc->mode_reglement_id; - $newobject->cond_reglement_id = $soc->cond_reglement_id; + $new_invoice->mode_reglement_id = ! empty($invoice['payment_mode_id'])?$invoice['payment_mode_id']:$soc->mode_reglement_id; + $new_invoice->cond_reglement_id = $soc->cond_reglement_id; } - else $newobject->mode_reglement_id = $invoice['payment_mode_id']; + else $new_invoice->mode_reglement_id = $invoice['payment_mode_id']; // Trick because nusoap does not store data with same structure if there is one or several lines $arrayoflines=array(); @@ -598,22 +598,22 @@ function createInvoice($authentication,$invoice) $newline->date_start=dol_stringtotime($line['date_start']); $newline->date_end=dol_stringtotime($line['date_end']); $newline->fk_product=$line['product_id']; - $newobject->lines[]=$newline; + $new_invoice->lines[]=$newline; } //var_dump($newobject->date_lim_reglement); exit; //var_dump($invoice['lines'][0]['type']); $db->begin(); - $result=$newobject->create($fuser,0,dol_stringtotime($invoice['date_due'],'dayrfc')); + $result=$new_invoice->create($fuser,0,dol_stringtotime($invoice['date_due'],'dayrfc')); if ($result < 0) { $error++; } - if ($invoice['status'] == 1) // We want invoice to have status validated + if (!$error && $invoice['status'] == Facture::STATUS_VALIDATED) // We want invoice to have status validated { - $result=$newobject->validate($fuser); + $result=$new_invoice->validate($fuser); if ($result < 0) { $error++; @@ -623,15 +623,16 @@ function createInvoice($authentication,$invoice) if (! $error) { $db->commit(); - $objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''),'id'=>$newobject->id, - 'ref'=>$newobject->ref,'ref_ext'=>$newobject->ref_ext); + $objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''),'id'=>$new_invoice->id, + 'ref'=>$new_invoice->ref,'ref_ext'=>$new_invoice->ref_ext); } else { $db->rollback(); $error++; $errorcode='KO'; - $errorlabel=$newobject->error; + $errorlabel=$new_invoice->error; + dol_syslog("Function: createInvoice error while creating".$errorlabel); } } @@ -781,8 +782,8 @@ function updateInvoice($authentication,$invoice) if (isset($invoice['status'])) { - if ($invoice['status'] == 0) $result=$object->set_draft($fuser); - if ($invoice['status'] == 1) + if ($invoice['status'] == Facture::STATUS_DRAFT) $result=$object->set_draft($fuser); + if ($invoice['status'] == Facture::STATUS_VALIDATED) { $result=$object->validate($fuser); @@ -793,11 +794,11 @@ function updateInvoice($authentication,$invoice) $order->generateDocument($invoice->modelpdf, $outputlangs); } } - if ($invoice['status'] == 2) + if ($invoice['status'] == Facture::STATUS_CLOSED) { $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 ($invoice['status'] == Facture::STATUS_ABANDONED) $result=$object->set_canceled($fuser,$invoice->close_code,$invoice->close_note); } } From 336b8c49b31637e073d8ce39f3c70437e4ae2747 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Wed, 27 May 2015 15:42:46 +0200 Subject: [PATCH 14/20] update test --- test/phpunit/WebservicesInvoicesTest.php | 190 +++++++++++++---------- 1 file changed, 106 insertions(+), 84 deletions(-) diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php index a295dbdc64e..4731c8f7651 100755 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -53,7 +53,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase protected $savuser; protected $savlangs; protected $savdb; - + /** * Constructor * We save global variables into local variables @@ -79,6 +79,23 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase { global $conf,$user,$langs,$db; $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. + + // create a third_party, needed to create an invoice + $societe=new Societe($db); + $societe->ref=''; + $societe->name='name'; + $societe->ref_ext='209'; + $societe->status=1; + $societe->client=1; + $societe->fournisseur=0; + $societe->date_creation=$now; + $societe->tva_assuj=0; + $societe->particulier=0; + + $societe->create($user); + + print __METHOD__." societe created id=".$societe->id."\n"; + print __METHOD__."\n"; } @@ -102,10 +119,9 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; - - // create a third_party, needed to create an invoice - + print __METHOD__."\n"; + } /** @@ -136,6 +152,11 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $WS_METHOD = 'createInvoice'; $ns='http://www.dolibarr.org/ns/'; + // load societe first + $societe=new Societe($db); + $societe->fetch('', '', '209'); + print __METHOD__." societe loaded id=".$societe->id."\n"; + // Set the WebService URL print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; $soapclient = new nusoap_client($WS_DOL_URL); @@ -144,48 +165,49 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $soapclient->soap_defencoding='UTF-8'; $soapclient->decodeUTF8(false); } + $body = array ( - ["id"] => NULL, - ["ref"]=> NULL, - ["ref_ext"]=> "165", - ["thirdparty_id"]=> "209", - ["fk_user_author"] => NULL, - ["fk_user_valid"] => NULL, - ["date"]=> "2015-04-19 20:16:53", - ["date_due"]=> "", - ["date_creation"]=> "", - ["date_validation"]=> "", - ["date_modification"]=> "", - ["type"]=> "", - ["total_net"]=> "36.30", - ["total_vat"]=> "6.00", - ["total"]=> "42.30", - ["payment_mode_id"]=> 50, - ["note_private"]=> "Synchronised from Prestashop", - ["note_public"]=> "", - ["status"]=> "1", - ["close_code"]=> NULL , - ["close_note"]=> NULL, - ["project_id"]=> NULL, - ["lines"] => array( - ["id"] => NULL, - ["type"]=> 0, - ["desc"]=> "Horloge Vinyle Serge", - ["vat_rate"]=> 20, - ["qty"]=> "1", - ["unitprice"]=> "30.000000", - ["total_net"]=> "30.000000", - ["total_vat"]=> "6.00", - ["total"]=> "36.000000", - ["date_start"]=> "", - ["date_end"]=> "", - ["payment_mode_id"]=> "", - ["product_id"]=> "", - ["product_ref"]=> "", - ["product_label"]=> "", - ["product_desc"]=> "" ) - ); + "id" => NULL, + "ref" => NULL, + "ref_ext" => "165", + "thirdparty_id" => $societe->id, + "fk_user_author" => NULL, + "fk_user_valid" => NULL, + "date" => "2015-04-19 20:16:53", + "date_due" => "", + "date_creation" => "", + "date_validation" => "", + "date_modification" => "", + "type" => "", + "total_net" => "36.30", + "total_vat" => "6.00", + "total" => "42.30", + "payment_mode_id" => 50, + "note_private" => "Synchronised from Prestashop", + "note_public" => "", + "status" => "1", + "close_code" => NULL , + "close_note" => NULL, + "project_id" => NULL, + "lines" => array( + "id" => NULL, + "type" => 0, + "desc" => "Horloge Vinyle Serge", + "vat_rate" => 20, + "qty" => "1", + "unitprice" => "30.000000", + "total_net" => "30.000000", + "total_vat" => "6.00", + "total" => "36.000000", + "date_start" => "", + "date_end" => "", + "payment_mode_id" => "", + "product_id" => "", + "product_ref" => "", + "product_label" => "", + "product_desc" => "" ) + ); // Call the WebService method and store its result in $result. $authentication=array( @@ -218,7 +240,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase print "\n"; } - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result['result']['result_label']."\n"; $this->assertEquals('OK',$result['result']['result_code']); $this->assertEquals('165', $result['ref_ext']); @@ -319,45 +341,45 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase // update status to 2 $body = array ( - ["id"] => NULL, - ["ref"]=> NULL, - ["ref_ext"]=> "165", - ["thirdparty_id"]=> "209", - ["fk_user_author"] => NULL, - ["fk_user_valid"] => NULL, - ["date"]=> "2015-04-19 20:16:53", - ["date_due"]=> "", - ["date_creation"]=> "", - ["date_validation"]=> "", - ["date_modification"]=> "", - ["type"]=> "", - ["total_net"]=> "36.30", - ["total_vat"]=> "6.00", - ["total"]=> "42.30", - ["payment_mode_id"]=> 50, - ["note_private"]=> "Synchronised from Prestashop", - ["note_public"]=> "", - ["status"]=> "2", - ["close_code"]=> NULL , - ["close_note"]=> NULL, - ["project_id"]=> NULL, - ["lines"] => array( - ["id"] => NULL, - ["type"]=> 0, - ["desc"]=> "Horloge Vinyle Serge", - ["vat_rate"]=> 20, - ["qty"]=> "1", - ["unitprice"]=> "30.000000", - ["total_net"]=> "30.000000", - ["total_vat"]=> "6.00", - ["total"]=> "36.000000", - ["date_start"]=> "", - ["date_end"]=> "", - ["payment_mode_id"]=> "", - ["product_id"]=> "", - ["product_ref"]=> "", - ["product_label"]=> "", - ["product_desc"]=> "" ) + "id" => NULL, + "ref" => NULL, + "ref_ext" => "165", + "thirdparty_id" => "209", + "fk_user_author" => NULL, + "fk_user_valid" => NULL, + "date" => "2015-04-19 20:16:53", + "date_due" => "", + "date_creation" => "", + "date_validation" => "", + "date_modification" => "", + "type" => "", + "total_net" => "36.30", + "total_vat" => "6.00", + "total" => "42.30", + "payment_mode_id" => 50, + "note_private" => "Synchronised from Prestashop", + "note_public" => "", + "status" => "2", + "close_code" => NULL , + "close_note" => NULL, + "project_id" => NULL, + "lines" => array( + "id" => NULL, + "type" => 0, + "desc" => "Horloge Vinyle Serge", + "vat_rate" => 20, + "qty" => "1", + "unitprice" => "30.000000", + "total_net" => "30.000000", + "total_vat" => "6.00", + "total" => "36.000000", + "date_start" => "", + "date_end" => "", + "payment_mode_id" => "", + "product_id" => "", + "product_ref" => "", + "product_label" => "", + "product_desc" => "" ) ); // Call the WebService method and store its result in $result. From 33d5299a22dfd7506899d6648ae29bf810f3701c Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Thu, 28 May 2015 15:40:38 +0200 Subject: [PATCH 15/20] add deleteThirdParty api call + add tests --- test/phpunit/WebservicesThirdpartyTest.php | 258 +++++++++++++++++++-- 1 file changed, 237 insertions(+), 21 deletions(-) diff --git a/test/phpunit/WebservicesThirdpartyTest.php b/test/phpunit/WebservicesThirdpartyTest.php index 0c99d7d362a..71c90b3f636 100755 --- a/test/phpunit/WebservicesThirdpartyTest.php +++ b/test/phpunit/WebservicesThirdpartyTest.php @@ -52,6 +52,13 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase protected $savuser; protected $savlangs; protected $savdb; + protected $soapclient; + + private $WS_DOL_URL; + private $ns='http://www.dolibarr.org/ns/'; + + + /** * Constructor @@ -67,6 +74,16 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase $this->savuser=$user; $this->savlangs=$langs; $this->savdb=$db; + + $this->WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php'; + + // Set the WebService URL + print __METHOD__." create nusoap_client for URL=".$this->WS_DOL_URL."\n"; + $this->soapclient = new nusoap_client($this->WS_DOL_URL); + if ($this->soapclient) { + $this->soapclient->soap_defencoding='UTF-8'; + $this->soapclient->decodeUTF8(false); + } print __METHOD__." db->type=".$db->type." user->id=".$user->id; //print " - db ".$db->db; @@ -117,31 +134,113 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase print __METHOD__."\n"; } - /** - * testWSThirdpartygetThirdParty + * testWSThirdpartycreateThirdParty * * @return int */ - public function testWSThirdpartygetThirdParty() + public function testWSThirdpartycreateThirdParty() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $WS_METHOD = 'createThirdParty'; + + + // Call the WebService method and store its result in $result. + $authentication=array( + 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, + 'sourceapplication'=>'DEMO', + 'login'=>'admin', + 'password'=>'admin', + 'entity'=>''); + + $body = array ( + "id" => NULL, + "ref" => "name", + "ref_ext" => "12", + "fk_user_author" => NULL, + "status" => NULL, + "client" => 1, + "supplier" => 0, + "customer_code" => "", + "supplier_code" => "", + "customer_code_accountancy" => "", + "supplier_code_accountancy" => "", + "date_creation" => "", // dateTime + "date_modification" => "", // dateTime + "note_private" => "", + "note_public" => "", + "address" => "", + "zip" => "", + "town" => "", + "province_id" => "", + "country_id" => "", + "country_code" => "", + "country" => "", + "phone" => "", + "fax" => "", + "email" => "", + "url" => "", + "profid1" => "", + "profid2" => "", + "profid3" => "", + "profid4" => "", + "profid5" => "", + "profid6" => "", + "capital" => "", + "vat_used" => "", + "vat_number" => "" + ); + + // Test URL + $result=''; + $parameters = array('authentication'=>$authentication, 'thirdparty'=>$body); + print __METHOD__." call method ".$WS_METHOD."\n"; + try { + $result = $this->soapclient->call($WS_METHOD,$parameters,$thid->ns,''); + } catch(SoapFault $exception) { + echo $exception; + $result=0; + } + if (! $result || ! empty($result['faultstring'])) { + //var_dump($soapclient); + print $this->soapclient->error_str; + print "\n
\n"; + print $this->soapclient->request; + print "\n
\n"; + print $this->soapclient->response; + print "\n"; + } + + print __METHOD__." result=".$result['result']['result_code']."\n"; + $this->assertEquals('OK',$result['result']['result_code']); + $this->assertEquals('name',$result['ref']); + + return $result; + } + + /** + * testWSThirdpartygetThirdPartyById + * + * Use id to retrieve thirdparty + * @depends testWSThirdpartycreateThirdParty + * + * @return int + */ + public function testWSThirdpartygetThirdPartyById($result) { global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; + $id = $result['id']; - $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php'; $WS_METHOD = 'getThirdParty'; - $ns='http://www.dolibarr.org/ns/'; - - // Set the WebService URL - print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; - $soapclient = new nusoap_client($WS_DOL_URL); - if ($soapclient) { - $soapclient->soap_defencoding='UTF-8'; - $soapclient->decodeUTF8(false); - } // Call the WebService method and store its result in $result. $authentication=array( @@ -151,30 +250,147 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase 'password'=>'admin', 'entity'=>''); - // Test URL $result=''; - $parameters = array('authentication'=>$authentication, 'id'=>1); + $parameters = array('authentication'=>$authentication, 'id'=>$id); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); } catch(SoapFault $exception) { echo $exception; $result=0; } if (! $result || ! empty($result['faultstring'])) { //var_dump($soapclient); - print $soapclient->error_str; + print $this->soapclient->error_str; print "\n
\n"; - print $soapclient->request; + print $this->soapclient->request; print "\n
\n"; - print $soapclient->response; + print $this->soapclient->response; print "\n"; } - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result['result']['result_code']."\n"; $this->assertEquals('OK',$result['result']['result_code']); - + $this->assertEquals($id, $result['thirdparty']['id']); + $this->assertEquals('name', $result['thirdparty']['ref']); + $this->assertEquals('12', $result['thirdparty']['ref_ext']); + $this->assertEquals('0', $result['thirdparty']['status']); + $this->assertEquals('1', $result['thirdparty']['client']); + $this->assertEquals('0', $result['thirdparty']['supplier']); + + return $result; } + + /** + * testWSThirdpartygetThirdPartyByRefExt + * + * Use ref_ext to retrieve thirdparty + * + * @depends testWSThirdpartycreateThirdParty + * @return int + */ + public function testWSThirdpartygetThirdPartyByRefExt($result) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + $id = $result['id']; + + $WS_METHOD = 'getThirdParty'; + + // Call the WebService method and store its result in $result. + $authentication=array( + 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, + 'sourceapplication'=>'DEMO', + 'login'=>'admin', + 'password'=>'admin', + 'entity'=>''); + + // Test URL + $result=''; + $parameters = array('authentication'=>$authentication, 'id'=>'', 'ref'=>'', 'ref_ext'=>'12'); + print __METHOD__." call method ".$WS_METHOD."\n"; + try { + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); + } catch(SoapFault $exception) { + echo $exception; + $result=0; + } + print $this->soapclient->response; + if (! $result || ! empty($result['faultstring'])) { + //var_dump($soapclient); + print $this->soapclient->error_str; + print "\n
\n"; + print $this->soapclient->request; + print "\n
\n"; + print $this->soapclient->response; + print "\n"; + } + + print __METHOD__." result=".$result['result']['result_code']."\n"; + $this->assertEquals('OK',$result['result']['result_code']); + $this->assertEquals($id, $result['thirdparty']['id']); + $this->assertEquals('name', $result['thirdparty']['ref']); + $this->assertEquals('12', $result['thirdparty']['ref_ext']); + $this->assertEquals('0', $result['thirdparty']['status']); + $this->assertEquals('1', $result['thirdparty']['client']); + $this->assertEquals('0', $result['thirdparty']['supplier']); + + + return $result; + } + + /** + * testWSThirdpartydeleteThirdParty + * + * @depends testWSThirdpartycreateThirdParty + * + * @return int + */ + public function testWSThirdpartydeleteThirdPartyById($result) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + $id = $result['id']; + + $WS_METHOD = 'deleteThirdParty'; + + // Call the WebService method and store its result in $result. + $authentication=array( + 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, + 'sourceapplication'=>'DEMO', + 'login'=>'admin', + 'password'=>'admin', + 'entity'=>''); + + $result=''; + $parameters = array('authentication'=>$authentication, 'id'=>$id, 'ref'=>'', 'ref_ext'=>''); + print __METHOD__." call method ".$WS_METHOD."\n"; + try { + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); + } catch(SoapFault $exception) { + echo $exception; + $result=0; + } + //if (! $result || ! empty($result['faultstring'])) { + print $this->soapclient->error_str; + print "\n
\n"; + print $this->soapclient->request; + print "\n
\n"; + print $this->soapclient->response; + print "\n"; + //} + + print __METHOD__." result=".$result['result']['result_code']."\n"; + $this->assertEquals('OK',$result['result']['result_code']); + + return $result; + } } From 05a7ab158b51a05dbb38ac7b02abf0d2c1df9891 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Thu, 28 May 2015 15:40:38 +0200 Subject: [PATCH 16/20] add deleteThirdParty api call + add tests --- htdocs/webservices/server_thirdparty.php | 106 +++++++++ test/phpunit/WebservicesThirdpartyTest.php | 258 +++++++++++++++++++-- 2 files changed, 343 insertions(+), 21 deletions(-) diff --git a/htdocs/webservices/server_thirdparty.php b/htdocs/webservices/server_thirdparty.php index c7ca5911d62..542e2980c45 100644 --- a/htdocs/webservices/server_thirdparty.php +++ b/htdocs/webservices/server_thirdparty.php @@ -258,8 +258,31 @@ $server->register( 'WS to get list of thirdparties id and ref' ); +// Register WSDL +$server->register( + 'deleteThirdParty', + // Entry values + array('authentication'=>'tns:authentication','id'=>'xsd:string','ref'=>'xsd:string','ref_ext'=>'xsd:string'), + // Exit values + array('result'=>'tns:result','id'=>'xsd:string'), + $ns, + $ns.'#deleteThirdParty', + $styledoc, + $styleuse, + 'WS to delete a thirdparty from its id, ref or ref_ext' +); + // Full methods code +/** + * Get a thirdparty + * + * @param array $authentication Array of authentication information + * @param string $id internal id + * @param string $ref internal reference + * @param string $ref_ext external reference + * @return array Array result + */ function getThirdParty($authentication,$id='',$ref='',$ref_ext='') { global $db,$conf,$langs; @@ -728,5 +751,88 @@ function getListOfThirdParties($authentication,$filterthirdparty) return $objectresp; } +/** + * Delete a thirdparty + * + * @param array $authentication Array of authentication information + * @param string $id internal id + * @param string $ref internal reference + * @param string $ref_ext external reference + * @return array Array result + */ +function deleteThirdParty($authentication,$id='',$ref='',$ref_ext='') +{ + global $db,$conf,$langs; + + dol_syslog("Function: deleteThirdParty login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$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 (! $error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) + { + dol_syslog("Function: deleteThirdParty checkparam"); + $error++; + $errorcode='BAD_PARAMETERS'; $errorlabel="Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both."; + } + dol_syslog("Function: deleteThirdParty 1"); + + if (! $error) + { + $fuser->getrights(); + + if ($fuser->rights->societe->lire && $fuser->rights->societe->supprimer) + { + $thirdparty=new Societe($db); + $result=$thirdparty->fetch($id,$ref,$ref_ext); + + if ($result > 0) + { + $db->begin(); + + $result=$thirdparty->delete($thirdparty->id, $fuser); + + if ($result > 0) + { + $db->commit(); + + $objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>'')); + } + else + { + $db->rollback(); + $error++; + $errorcode='KO'; + $errorlabel=$thirdparty->error; + dol_syslog("Function: deleteThirdParty cant delete"); + } + } + else + { + $error++; + $errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext; + + } + } + 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)); + } + + return $objectresp; +} + // Return the results. $server->service(file_get_contents("php://input")); diff --git a/test/phpunit/WebservicesThirdpartyTest.php b/test/phpunit/WebservicesThirdpartyTest.php index 0c99d7d362a..71c90b3f636 100755 --- a/test/phpunit/WebservicesThirdpartyTest.php +++ b/test/phpunit/WebservicesThirdpartyTest.php @@ -52,6 +52,13 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase protected $savuser; protected $savlangs; protected $savdb; + protected $soapclient; + + private $WS_DOL_URL; + private $ns='http://www.dolibarr.org/ns/'; + + + /** * Constructor @@ -67,6 +74,16 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase $this->savuser=$user; $this->savlangs=$langs; $this->savdb=$db; + + $this->WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php'; + + // Set the WebService URL + print __METHOD__." create nusoap_client for URL=".$this->WS_DOL_URL."\n"; + $this->soapclient = new nusoap_client($this->WS_DOL_URL); + if ($this->soapclient) { + $this->soapclient->soap_defencoding='UTF-8'; + $this->soapclient->decodeUTF8(false); + } print __METHOD__." db->type=".$db->type." user->id=".$user->id; //print " - db ".$db->db; @@ -117,31 +134,113 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase print __METHOD__."\n"; } - /** - * testWSThirdpartygetThirdParty + * testWSThirdpartycreateThirdParty * * @return int */ - public function testWSThirdpartygetThirdParty() + public function testWSThirdpartycreateThirdParty() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $WS_METHOD = 'createThirdParty'; + + + // Call the WebService method and store its result in $result. + $authentication=array( + 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, + 'sourceapplication'=>'DEMO', + 'login'=>'admin', + 'password'=>'admin', + 'entity'=>''); + + $body = array ( + "id" => NULL, + "ref" => "name", + "ref_ext" => "12", + "fk_user_author" => NULL, + "status" => NULL, + "client" => 1, + "supplier" => 0, + "customer_code" => "", + "supplier_code" => "", + "customer_code_accountancy" => "", + "supplier_code_accountancy" => "", + "date_creation" => "", // dateTime + "date_modification" => "", // dateTime + "note_private" => "", + "note_public" => "", + "address" => "", + "zip" => "", + "town" => "", + "province_id" => "", + "country_id" => "", + "country_code" => "", + "country" => "", + "phone" => "", + "fax" => "", + "email" => "", + "url" => "", + "profid1" => "", + "profid2" => "", + "profid3" => "", + "profid4" => "", + "profid5" => "", + "profid6" => "", + "capital" => "", + "vat_used" => "", + "vat_number" => "" + ); + + // Test URL + $result=''; + $parameters = array('authentication'=>$authentication, 'thirdparty'=>$body); + print __METHOD__." call method ".$WS_METHOD."\n"; + try { + $result = $this->soapclient->call($WS_METHOD,$parameters,$thid->ns,''); + } catch(SoapFault $exception) { + echo $exception; + $result=0; + } + if (! $result || ! empty($result['faultstring'])) { + //var_dump($soapclient); + print $this->soapclient->error_str; + print "\n
\n"; + print $this->soapclient->request; + print "\n
\n"; + print $this->soapclient->response; + print "\n"; + } + + print __METHOD__." result=".$result['result']['result_code']."\n"; + $this->assertEquals('OK',$result['result']['result_code']); + $this->assertEquals('name',$result['ref']); + + return $result; + } + + /** + * testWSThirdpartygetThirdPartyById + * + * Use id to retrieve thirdparty + * @depends testWSThirdpartycreateThirdParty + * + * @return int + */ + public function testWSThirdpartygetThirdPartyById($result) { global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; + $id = $result['id']; - $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php'; $WS_METHOD = 'getThirdParty'; - $ns='http://www.dolibarr.org/ns/'; - - // Set the WebService URL - print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; - $soapclient = new nusoap_client($WS_DOL_URL); - if ($soapclient) { - $soapclient->soap_defencoding='UTF-8'; - $soapclient->decodeUTF8(false); - } // Call the WebService method and store its result in $result. $authentication=array( @@ -151,30 +250,147 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase 'password'=>'admin', 'entity'=>''); - // Test URL $result=''; - $parameters = array('authentication'=>$authentication, 'id'=>1); + $parameters = array('authentication'=>$authentication, 'id'=>$id); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); } catch(SoapFault $exception) { echo $exception; $result=0; } if (! $result || ! empty($result['faultstring'])) { //var_dump($soapclient); - print $soapclient->error_str; + print $this->soapclient->error_str; print "\n
\n"; - print $soapclient->request; + print $this->soapclient->request; print "\n
\n"; - print $soapclient->response; + print $this->soapclient->response; print "\n"; } - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result['result']['result_code']."\n"; $this->assertEquals('OK',$result['result']['result_code']); - + $this->assertEquals($id, $result['thirdparty']['id']); + $this->assertEquals('name', $result['thirdparty']['ref']); + $this->assertEquals('12', $result['thirdparty']['ref_ext']); + $this->assertEquals('0', $result['thirdparty']['status']); + $this->assertEquals('1', $result['thirdparty']['client']); + $this->assertEquals('0', $result['thirdparty']['supplier']); + + return $result; } + + /** + * testWSThirdpartygetThirdPartyByRefExt + * + * Use ref_ext to retrieve thirdparty + * + * @depends testWSThirdpartycreateThirdParty + * @return int + */ + public function testWSThirdpartygetThirdPartyByRefExt($result) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + $id = $result['id']; + + $WS_METHOD = 'getThirdParty'; + + // Call the WebService method and store its result in $result. + $authentication=array( + 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, + 'sourceapplication'=>'DEMO', + 'login'=>'admin', + 'password'=>'admin', + 'entity'=>''); + + // Test URL + $result=''; + $parameters = array('authentication'=>$authentication, 'id'=>'', 'ref'=>'', 'ref_ext'=>'12'); + print __METHOD__." call method ".$WS_METHOD."\n"; + try { + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); + } catch(SoapFault $exception) { + echo $exception; + $result=0; + } + print $this->soapclient->response; + if (! $result || ! empty($result['faultstring'])) { + //var_dump($soapclient); + print $this->soapclient->error_str; + print "\n
\n"; + print $this->soapclient->request; + print "\n
\n"; + print $this->soapclient->response; + print "\n"; + } + + print __METHOD__." result=".$result['result']['result_code']."\n"; + $this->assertEquals('OK',$result['result']['result_code']); + $this->assertEquals($id, $result['thirdparty']['id']); + $this->assertEquals('name', $result['thirdparty']['ref']); + $this->assertEquals('12', $result['thirdparty']['ref_ext']); + $this->assertEquals('0', $result['thirdparty']['status']); + $this->assertEquals('1', $result['thirdparty']['client']); + $this->assertEquals('0', $result['thirdparty']['supplier']); + + + return $result; + } + + /** + * testWSThirdpartydeleteThirdParty + * + * @depends testWSThirdpartycreateThirdParty + * + * @return int + */ + public function testWSThirdpartydeleteThirdPartyById($result) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + $id = $result['id']; + + $WS_METHOD = 'deleteThirdParty'; + + // Call the WebService method and store its result in $result. + $authentication=array( + 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, + 'sourceapplication'=>'DEMO', + 'login'=>'admin', + 'password'=>'admin', + 'entity'=>''); + + $result=''; + $parameters = array('authentication'=>$authentication, 'id'=>$id, 'ref'=>'', 'ref_ext'=>''); + print __METHOD__." call method ".$WS_METHOD."\n"; + try { + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); + } catch(SoapFault $exception) { + echo $exception; + $result=0; + } + //if (! $result || ! empty($result['faultstring'])) { + print $this->soapclient->error_str; + print "\n
\n"; + print $this->soapclient->request; + print "\n
\n"; + print $this->soapclient->response; + print "\n"; + //} + + print __METHOD__." result=".$result['result']['result_code']."\n"; + $this->assertEquals('OK',$result['result']['result_code']); + + return $result; + } } From 3003b41a88c6ba4853646a63484280caeb6a3df7 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Thu, 28 May 2015 16:57:28 +0200 Subject: [PATCH 17/20] add test for invoices API --- htdocs/webservices/server_invoice.php | 14 +- test/phpunit/WebservicesInvoicesTest.php | 212 +++++++++++------------ 2 files changed, 108 insertions(+), 118 deletions(-) diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index d358847c0b6..4a495607a29 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -751,8 +751,8 @@ 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); + 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']; @@ -782,10 +782,13 @@ function updateInvoice($authentication,$invoice) if (isset($invoice['status'])) { - if ($invoice['status'] == Facture::STATUS_DRAFT) $result=$object->set_draft($fuser); + if ($invoice['status'] == Facture::STATUS_DRAFT) + { + $result = $object->set_draft($fuser); + } if ($invoice['status'] == Facture::STATUS_VALIDATED) { - $result=$object->validate($fuser); + $result = $object->validate($fuser); if ($result >= 0) { @@ -798,7 +801,8 @@ function updateInvoice($authentication,$invoice) { $result = $object->set_paid($fuser,$invoice->close_code,$invoice->close_note); } - if ($invoice['status'] == Facture::STATUS_ABANDONED) $result=$object->set_canceled($fuser,$invoice->close_code,$invoice->close_note); + if ($invoice['status'] == Facture::STATUS_ABANDONED) + $result = $object->set_canceled($fuser,$invoice->close_code,$invoice->close_note); } } diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php index 4731c8f7651..bbcf6d0b136 100755 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -53,6 +53,10 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase protected $savuser; protected $savlangs; protected $savdb; + protected $soapclient; + protected $socid; + + protected $ns = 'http://www.dolibarr.org/ns/'; /** * Constructor @@ -68,17 +72,17 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $this->savuser=$user; $this->savlangs=$langs; $this->savdb=$db; - - print __METHOD__." db->type=".$db->type." user->id=".$user->id; - //print " - db ".$db->db; - print "\n"; - } - - // Static methods - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; - $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. + $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php'; + + + // Set the WebService URL + print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; + $this->soapclient = new nusoap_client($WS_DOL_URL); + if ($this->soapclient) + { + $this->soapclient->soap_defencoding='UTF-8'; + $this->soapclient->decodeUTF8(false); + } // create a third_party, needed to create an invoice $societe=new Societe($db); @@ -94,8 +98,20 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $societe->create($user); - print __METHOD__." societe created id=".$societe->id."\n"; + $this->socid = $societe->id; + print __METHOD__." societe created id=".$societe->id."\n"; + + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } + + // Static methods + public static function setUpBeforeClass() + { + global $conf,$user,$langs,$db; + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. print __METHOD__."\n"; } @@ -148,23 +164,12 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $langs=$this->savlangs; $db=$this->savdb; - $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php'; $WS_METHOD = 'createInvoice'; - $ns='http://www.dolibarr.org/ns/'; // load societe first $societe=new Societe($db); $societe->fetch('', '', '209'); print __METHOD__." societe loaded id=".$societe->id."\n"; - - // Set the WebService URL - print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; - $soapclient = new nusoap_client($WS_DOL_URL); - if ($soapclient) - { - $soapclient->soap_defencoding='UTF-8'; - $soapclient->decodeUTF8(false); - } $body = array ( @@ -191,11 +196,11 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase "close_note" => NULL, "project_id" => NULL, "lines" => array( - "id" => NULL, + array("id" => NULL, "type" => 0, "desc" => "Horloge Vinyle Serge", "vat_rate" => 20, - "qty" => "1", + "qty" => 1, "unitprice" => "30.000000", "total_net" => "30.000000", "total_vat" => "6.00", @@ -206,7 +211,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase "product_id" => "", "product_ref" => "", "product_label" => "", - "product_desc" => "" ) + "product_desc" => "" )) ); // Call the WebService method and store its result in $result. @@ -222,7 +227,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $parameters = array('authentication'=>$authentication,'invoice'=>$body); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); } catch(SoapFault $exception) { @@ -232,15 +237,15 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase if (! $result || ! empty($result['faultstring'])) { //var_dump($soapclient); - print $soapclient->error_str; + print $this->soapclient->error_str; print "\n
\n"; - print $soapclient->request; + print $this->soapclient->request; print "\n
\n"; - print $soapclient->response; + print $this->soapclient->response; print "\n"; } - print __METHOD__." result=".$result['result']['result_label']."\n"; + print __METHOD__." result=".$result['result']['result_code']."\n"; $this->assertEquals('OK',$result['result']['result_code']); $this->assertEquals('165', $result['ref_ext']); @@ -249,11 +254,13 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase } /** - * testWSInvoicesGetInvoice - * + * testWSInvoicesGetInvoiceByRefExt + * + * Retrieve an invoice using ref_ext + * @depends testWSInvoicesCreateInvoice * @return int */ - public function testWSInvoicesGetInvoice() + public function testWSInvoicesGetInvoiceByRefExt($result) { global $conf,$user,$langs,$db; $conf=$this->savconf; @@ -261,18 +268,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $langs=$this->savlangs; $db=$this->savdb; - $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php'; $WS_METHOD = 'getInvoice'; - $ns='http://www.dolibarr.org/ns/'; - - // Set the WebService URL - print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; - $soapclient = new nusoap_client($WS_DOL_URL); - if ($soapclient) - { - $soapclient->soap_defencoding='UTF-8'; - $soapclient->decodeUTF8(false); - } // Call the WebService method and store its result in $result. $authentication=array( @@ -287,7 +283,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $parameters = array('authentication'=>$authentication,'id'=>NULL,'ref'=>NULL,'ref_ext'=>165); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); } catch(SoapFault $exception) { @@ -296,29 +292,30 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase } if (! $result || ! empty($result['faultstring'])) { - //var_dump($soapclient); - print $soapclient->error_str; + print $this->soapclient->error_str; print "\n
\n"; - print $soapclient->request; + print $this->soapclient->request; print "\n
\n"; - print $soapclient->response; + print $this->soapclient->response; print "\n"; } - - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result['result']['result_code']."\n"; $this->assertEquals('OK',$result['result']['result_code']); - $this->assertEquals('165', $result['result']['invoice']->ref_ext); + $this->assertEquals('165', $result['invoice']['ref_ext']); return $result; } /** - * testWSInvoicesUpdateInvoice + * testWSInvoicesUpdateInvoiceByRefExt + * + * Update an invoice using ref_ext + * @depends testWSInvoicesCreateInvoice * * @return int */ - public function testWSInvoicesUpdateInvoice() + public function testWSInvoicesUpdateInvoiceByRefExt($result) { global $conf,$user,$langs,$db; $conf=$this->savconf; @@ -326,61 +323,51 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $langs=$this->savlangs; $db=$this->savdb; - $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php'; $WS_METHOD = 'updateInvoice'; - $ns='http://www.dolibarr.org/ns/'; - // Set the WebService URL - print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; - $soapclient = new nusoap_client($WS_DOL_URL); - if ($soapclient) - { - $soapclient->soap_defencoding='UTF-8'; - $soapclient->decodeUTF8(false); - } - // update status to 2 - $body = array ( - "id" => NULL, - "ref" => NULL, - "ref_ext" => "165", - "thirdparty_id" => "209", - "fk_user_author" => NULL, - "fk_user_valid" => NULL, - "date" => "2015-04-19 20:16:53", - "date_due" => "", - "date_creation" => "", - "date_validation" => "", - "date_modification" => "", - "type" => "", - "total_net" => "36.30", + $body = array ( + "id" => NULL, + "ref" => NULL, + "ref_ext" => "165", + "thirdparty_id" => "209", + "fk_user_author" => NULL, + "fk_user_valid" => NULL, + "date" => "2015-04-19 20:16:53", + "date_due" => "", + "date_creation" => "", + "date_validation" => "", + "date_modification" => "", + "type" => "", + "total_net" => "36.30", + "total_vat" => "6.00", + "total" => "42.30", + "payment_mode_id" => 50, + "note_private" => "Synchronised from Prestashop", + "note_public" => "", + "status" => "2", + "close_code" => NULL , + "close_note" => NULL, + "project_id" => NULL, + "lines" => array( + array( + "id" => NULL, + "type" => 0, + "desc" => "Horloge Vinyle Serge", + "vat_rate" => 20, + "qty" => "1", + "unitprice" => "30.000000", + "total_net" => "30.000000", "total_vat" => "6.00", - "total" => "42.30", - "payment_mode_id" => 50, - "note_private" => "Synchronised from Prestashop", - "note_public" => "", - "status" => "2", - "close_code" => NULL , - "close_note" => NULL, - "project_id" => NULL, - "lines" => array( - "id" => NULL, - "type" => 0, - "desc" => "Horloge Vinyle Serge", - "vat_rate" => 20, - "qty" => "1", - "unitprice" => "30.000000", - "total_net" => "30.000000", - "total_vat" => "6.00", - "total" => "36.000000", - "date_start" => "", - "date_end" => "", - "payment_mode_id" => "", - "product_id" => "", - "product_ref" => "", - "product_label" => "", - "product_desc" => "" ) - ); + "total" => "36.000000", + "date_start" => "", + "date_end" => "", + "payment_mode_id" => "", + "product_id" => "", + "product_ref" => "", + "product_label" => "", + "product_desc" => "" )) + ); // Call the WebService method and store its result in $result. $authentication=array( @@ -395,7 +382,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $parameters = array('authentication'=>$authentication,'invoice'=>$body); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); } catch(SoapFault $exception) { @@ -404,18 +391,17 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase } if (! $result || ! empty($result['faultstring'])) { - //var_dump($soapclient); - print $soapclient->error_str; + print $this->soapclient->error_str; print "\n
\n"; - print $soapclient->request; + print $this->soapclient->request; print "\n
\n"; - print $soapclient->response; + print $this->soapclient->response; print "\n"; } - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result['result']['result_code'].$result['result']['result_label']."\n"; $this->assertEquals('OK',$result['result']['result_code']); - $this->assertEquals('2', $result['result']['invoice']->status); + $this->assertEquals('165', $result['ref_ext']); return $result; From 0c66c9745e4c52ad0c7e6b5dd0930639ac7e4dec Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Mon, 1 Jun 2015 13:04:33 +0200 Subject: [PATCH 18/20] fix travis error --- test/phpunit/WebservicesInvoicesTest.php | 4 ++-- test/phpunit/WebservicesThirdpartyTest.php | 24 +++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php index bbcf6d0b136..12d5ae2011c 100755 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -258,7 +258,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase * * Retrieve an invoice using ref_ext * @depends testWSInvoicesCreateInvoice - * @return int + * @return array Invoice */ public function testWSInvoicesGetInvoiceByRefExt($result) { @@ -313,7 +313,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase * Update an invoice using ref_ext * @depends testWSInvoicesCreateInvoice * - * @return int + * @return array Invoice */ public function testWSInvoicesUpdateInvoiceByRefExt($result) { diff --git a/test/phpunit/WebservicesThirdpartyTest.php b/test/phpunit/WebservicesThirdpartyTest.php index 71c90b3f636..6ae126b7e70 100755 --- a/test/phpunit/WebservicesThirdpartyTest.php +++ b/test/phpunit/WebservicesThirdpartyTest.php @@ -54,8 +54,8 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase protected $savdb; protected $soapclient; - private $WS_DOL_URL; - private $ns='http://www.dolibarr.org/ns/'; + private $_WS_DOL_URL; + private $_ns='http://www.dolibarr.org/ns/'; @@ -75,11 +75,11 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase $this->savlangs=$langs; $this->savdb=$db; - $this->WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php'; + $this->_WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php'; // Set the WebService URL - print __METHOD__." create nusoap_client for URL=".$this->WS_DOL_URL."\n"; - $this->soapclient = new nusoap_client($this->WS_DOL_URL); + print __METHOD__." create nusoap_client for URL=".$this->_WS_DOL_URL."\n"; + $this->soapclient = new nusoap_client($this->_WS_DOL_URL); if ($this->soapclient) { $this->soapclient->soap_defencoding='UTF-8'; $this->soapclient->decodeUTF8(false); @@ -137,7 +137,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase /** * testWSThirdpartycreateThirdParty * - * @return int + * @return array thirdparty created */ public function testWSThirdpartycreateThirdParty() { @@ -229,7 +229,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * Use id to retrieve thirdparty * @depends testWSThirdpartycreateThirdParty * - * @return int + * @return array thirpdarty updated */ public function testWSThirdpartygetThirdPartyById($result) { @@ -254,7 +254,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase $parameters = array('authentication'=>$authentication, 'id'=>$id); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->_ns,''); } catch(SoapFault $exception) { echo $exception; $result=0; @@ -288,7 +288,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * Use ref_ext to retrieve thirdparty * * @depends testWSThirdpartycreateThirdParty - * @return int + * @return array thirdparty */ public function testWSThirdpartygetThirdPartyByRefExt($result) { @@ -314,7 +314,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase $parameters = array('authentication'=>$authentication, 'id'=>'', 'ref'=>'', 'ref_ext'=>'12'); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->_ns,''); } catch(SoapFault $exception) { echo $exception; $result=0; @@ -348,7 +348,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * * @depends testWSThirdpartycreateThirdParty * - * @return int + * @return array thirdparty */ public function testWSThirdpartydeleteThirdPartyById($result) { @@ -373,7 +373,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase $parameters = array('authentication'=>$authentication, 'id'=>$id, 'ref'=>'', 'ref_ext'=>''); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->_ns,''); } catch(SoapFault $exception) { echo $exception; $result=0; From 3099e2acc4168f37d46c0b04b6906b90f559a2fe Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Mon, 1 Jun 2015 14:15:09 +0200 Subject: [PATCH 19/20] fix travis issues again --- test/phpunit/WebservicesInvoicesTest.php | 5 ++++- test/phpunit/WebservicesThirdpartyTest.php | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php index 12d5ae2011c..ff8a9a30e73 100755 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -258,6 +258,8 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase * * Retrieve an invoice using ref_ext * @depends testWSInvoicesCreateInvoice + * + * @param result invoice created by create method * @return array Invoice */ public function testWSInvoicesGetInvoiceByRefExt($result) @@ -312,7 +314,8 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase * * Update an invoice using ref_ext * @depends testWSInvoicesCreateInvoice - * + * + * @param result invoice created by create method * @return array Invoice */ public function testWSInvoicesUpdateInvoiceByRefExt($result) diff --git a/test/phpunit/WebservicesThirdpartyTest.php b/test/phpunit/WebservicesThirdpartyTest.php index 6ae126b7e70..2bf3f3fe094 100755 --- a/test/phpunit/WebservicesThirdpartyTest.php +++ b/test/phpunit/WebservicesThirdpartyTest.php @@ -228,7 +228,8 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * * Use id to retrieve thirdparty * @depends testWSThirdpartycreateThirdParty - * + * + * @param result thirdparty created by create method * @return array thirpdarty updated */ public function testWSThirdpartygetThirdPartyById($result) @@ -288,6 +289,8 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * Use ref_ext to retrieve thirdparty * * @depends testWSThirdpartycreateThirdParty + * + * @param result thirdparty created by create method * @return array thirdparty */ public function testWSThirdpartygetThirdPartyByRefExt($result) @@ -348,6 +351,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * * @depends testWSThirdpartycreateThirdParty * + * @param result thirdparty created by create method * @return array thirdparty */ public function testWSThirdpartydeleteThirdPartyById($result) From ed657d2bdfe6d13328271c5a7b2efb0bed39b559 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Mon, 1 Jun 2015 20:39:51 +0200 Subject: [PATCH 20/20] hopefully fix travis errors --- test/phpunit/WebservicesInvoicesTest.php | 10 +++++----- test/phpunit/WebservicesThirdpartyTest.php | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php index ff8a9a30e73..bbfde0a66e5 100755 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -154,7 +154,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase /** * testWSInvoicesCreateInvoice * - * @return int + * @return int invoice created */ public function testWSInvoicesCreateInvoice() { @@ -259,8 +259,8 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase * Retrieve an invoice using ref_ext * @depends testWSInvoicesCreateInvoice * - * @param result invoice created by create method - * @return array Invoice + * @param array $result Invoice created by create method + * @return array Invoice */ public function testWSInvoicesGetInvoiceByRefExt($result) { @@ -315,8 +315,8 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase * Update an invoice using ref_ext * @depends testWSInvoicesCreateInvoice * - * @param result invoice created by create method - * @return array Invoice + * @param array $result invoice created by create method + * @return array Invoice */ public function testWSInvoicesUpdateInvoiceByRefExt($result) { diff --git a/test/phpunit/WebservicesThirdpartyTest.php b/test/phpunit/WebservicesThirdpartyTest.php index 2bf3f3fe094..2888c432e73 100755 --- a/test/phpunit/WebservicesThirdpartyTest.php +++ b/test/phpunit/WebservicesThirdpartyTest.php @@ -229,8 +229,8 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * Use id to retrieve thirdparty * @depends testWSThirdpartycreateThirdParty * - * @param result thirdparty created by create method - * @return array thirpdarty updated + * @param array $result thirdparty created by create method + * @return array thirpdarty updated */ public function testWSThirdpartygetThirdPartyById($result) { @@ -290,8 +290,8 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * * @depends testWSThirdpartycreateThirdParty * - * @param result thirdparty created by create method - * @return array thirdparty + * @param array $result thirdparty created by create method + * @return array thirdparty */ public function testWSThirdpartygetThirdPartyByRefExt($result) { @@ -351,8 +351,8 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * * @depends testWSThirdpartycreateThirdParty * - * @param result thirdparty created by create method - * @return array thirdparty + * @param array $result thirdparty created by create method + * @return array thirdparty */ public function testWSThirdpartydeleteThirdPartyById($result) { @@ -382,14 +382,14 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase echo $exception; $result=0; } - //if (! $result || ! empty($result['faultstring'])) { + if (! $result || ! empty($result['faultstring'])) { print $this->soapclient->error_str; print "\n
\n"; print $this->soapclient->request; print "\n
\n"; print $this->soapclient->response; print "\n"; - //} + } print __METHOD__." result=".$result['result']['result_code']."\n"; $this->assertEquals('OK',$result['result']['result_code']);