From afc4d89c64c83bc93e5ed8d048e09dfe21a65ade Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Mon, 20 Apr 2015 20:18:17 +0200 Subject: [PATCH 01/36] 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 9229d3b9c2698..bf2eab8591ce2 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/36] 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 ec652e800749e..e0d76a0eb905f 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/36] 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 9c5bd24b46303..cb3f03121b5ba 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -102,7 +102,6 @@ '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 @@ '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/36] 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 694404a3d8ee5..5db4adb256054 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/36] 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 cb3f03121b5ba..4972002658201 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -250,6 +250,18 @@ $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/36] 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 4972002658201..b55a22fbcd90a 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -243,13 +243,25 @@ // 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/36] 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 b55a22fbcd90a..a9bc0a8ee443f 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/36] 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 e0d76a0eb905f..5db38052c7eef 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/36] 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 5db38052c7eef..cbc126ebb5a38 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/36] 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 a9bc0a8ee443f..195662c46f997 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/36] 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 195662c46f997..3cd6ec97d87f2 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/36] 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 20e015953757a..a295dbdc64e86 100755 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -102,6 +102,8 @@ protected function setUp() $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 @@ protected function tearDown() /** - * 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 @@ public function testWSInvoicesXxx() // 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 @@ public function testWSInvoicesXxx() 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/36] 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 336917a8c6023..d358847c0b607 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/36] 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 a295dbdc64e86..4731c8f765193 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 @@ 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. + + // 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 @@ protected function setUp() $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 @@ public function testWSInvoicesCreateInvoice() $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 @@ public function testWSInvoicesCreateInvoice() $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 @@ public function testWSInvoicesCreateInvoice() 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 @@ public function testWSInvoicesUpdateInvoice() // 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/36] add deleteThirdParty api call + add tests --- test/phpunit/WebservicesThirdpartyTest.php | 256 +++++++++++++++++++-- 1 file changed, 236 insertions(+), 20 deletions(-) diff --git a/test/phpunit/WebservicesThirdpartyTest.php b/test/phpunit/WebservicesThirdpartyTest.php index 0c99d7d362ae2..71c90b3f63644 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 @@ function __construct() $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 @@ protected function tearDown() print __METHOD__."\n"; } + /** + * testWSThirdpartycreateThirdParty + * + * @return int + */ + 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; + } /** - * testWSThirdpartygetThirdParty + * testWSThirdpartygetThirdPartyById + * + * Use id to retrieve thirdparty + * @depends testWSThirdpartycreateThirdParty * * @return int */ - public function testWSThirdpartygetThirdParty() + 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 @@ public function testWSThirdpartygetThirdParty() '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/36] add deleteThirdParty api call + add tests --- htdocs/webservices/server_thirdparty.php | 106 +++++++++ test/phpunit/WebservicesThirdpartyTest.php | 256 +++++++++++++++++++-- 2 files changed, 342 insertions(+), 20 deletions(-) diff --git a/htdocs/webservices/server_thirdparty.php b/htdocs/webservices/server_thirdparty.php index c7ca5911d6207..542e2980c45b0 100644 --- a/htdocs/webservices/server_thirdparty.php +++ b/htdocs/webservices/server_thirdparty.php @@ -258,8 +258,31 @@ '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 0c99d7d362ae2..71c90b3f63644 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 @@ function __construct() $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 @@ protected function tearDown() print __METHOD__."\n"; } + /** + * testWSThirdpartycreateThirdParty + * + * @return int + */ + 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; + } /** - * testWSThirdpartygetThirdParty + * testWSThirdpartygetThirdPartyById + * + * Use id to retrieve thirdparty + * @depends testWSThirdpartycreateThirdParty * * @return int */ - public function testWSThirdpartygetThirdParty() + 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 @@ public function testWSThirdpartygetThirdParty() '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/36] 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 d358847c0b607..4a495607a2939 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 4731c8f765193..bbcf6d0b13661 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 @@ function __construct() $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 @@ public static function setUpBeforeClass() $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 @@ public function testWSInvoicesCreateInvoice() $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 @@ public function testWSInvoicesCreateInvoice() "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 @@ public function testWSInvoicesCreateInvoice() "product_id" => "", "product_ref" => "", "product_label" => "", - "product_desc" => "" ) + "product_desc" => "" )) ); // Call the WebService method and store its result in $result. @@ -222,7 +227,7 @@ public function testWSInvoicesCreateInvoice() $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 @@ public function testWSInvoicesCreateInvoice() 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 @@ public function testWSInvoicesCreateInvoice() } /** - * 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 @@ public function testWSInvoicesGetInvoice() $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 @@ public function testWSInvoicesGetInvoice() $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 @@ public function testWSInvoicesGetInvoice() } 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 @@ public function testWSInvoicesUpdateInvoice() $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 @@ public function testWSInvoicesUpdateInvoice() $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 @@ public function testWSInvoicesUpdateInvoice() } 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/36] 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 bbcf6d0b13661..12d5ae2011c28 100755 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -258,7 +258,7 @@ public function testWSInvoicesCreateInvoice() * * Retrieve an invoice using ref_ext * @depends testWSInvoicesCreateInvoice - * @return int + * @return array Invoice */ public function testWSInvoicesGetInvoiceByRefExt($result) { @@ -313,7 +313,7 @@ public function testWSInvoicesGetInvoiceByRefExt($result) * 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 71c90b3f63644..6ae126b7e7029 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 @@ function __construct() $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 @@ protected function tearDown() /** * testWSThirdpartycreateThirdParty * - * @return int + * @return array thirdparty created */ public function testWSThirdpartycreateThirdParty() { @@ -229,7 +229,7 @@ public function testWSThirdpartycreateThirdParty() * Use id to retrieve thirdparty * @depends testWSThirdpartycreateThirdParty * - * @return int + * @return array thirpdarty updated */ public function testWSThirdpartygetThirdPartyById($result) { @@ -254,7 +254,7 @@ public function testWSThirdpartygetThirdPartyById($result) $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 @@ public function testWSThirdpartygetThirdPartyById($result) * Use ref_ext to retrieve thirdparty * * @depends testWSThirdpartycreateThirdParty - * @return int + * @return array thirdparty */ public function testWSThirdpartygetThirdPartyByRefExt($result) { @@ -314,7 +314,7 @@ public function testWSThirdpartygetThirdPartyByRefExt($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,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->_ns,''); } catch(SoapFault $exception) { echo $exception; $result=0; @@ -348,7 +348,7 @@ public function testWSThirdpartygetThirdPartyByRefExt($result) * * @depends testWSThirdpartycreateThirdParty * - * @return int + * @return array thirdparty */ public function testWSThirdpartydeleteThirdPartyById($result) { @@ -373,7 +373,7 @@ public function testWSThirdpartydeleteThirdPartyById($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,''); + $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/36] 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 12d5ae2011c28..ff8a9a30e7369 100755 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -258,6 +258,8 @@ public function testWSInvoicesCreateInvoice() * * 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 @@ public function testWSInvoicesGetInvoiceByRefExt($result) * * 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 6ae126b7e7029..2bf3f3fe09436 100755 --- a/test/phpunit/WebservicesThirdpartyTest.php +++ b/test/phpunit/WebservicesThirdpartyTest.php @@ -228,7 +228,8 @@ public function testWSThirdpartycreateThirdParty() * * 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 @@ public function testWSThirdpartygetThirdPartyById($result) * 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 @@ public function testWSThirdpartygetThirdPartyByRefExt($result) * * @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/36] 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 ff8a9a30e7369..bbfde0a66e532 100755 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -154,7 +154,7 @@ protected function tearDown() /** * testWSInvoicesCreateInvoice * - * @return int + * @return int invoice created */ public function testWSInvoicesCreateInvoice() { @@ -259,8 +259,8 @@ public function testWSInvoicesCreateInvoice() * 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 @@ public function testWSInvoicesGetInvoiceByRefExt($result) * 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 2bf3f3fe09436..2888c432e7325 100755 --- a/test/phpunit/WebservicesThirdpartyTest.php +++ b/test/phpunit/WebservicesThirdpartyTest.php @@ -229,8 +229,8 @@ public function testWSThirdpartycreateThirdParty() * 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 @@ public function testWSThirdpartygetThirdPartyById($result) * * @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 @@ public function testWSThirdpartygetThirdPartyByRefExt($result) * * @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 @@ public function testWSThirdpartydeleteThirdPartyById($result) 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']); From 2164729bad0d20906f66e002e416a22d1bd1703a Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Thu, 4 Jun 2015 13:34:08 +0200 Subject: [PATCH 21/36] if duration is present on service, we use it not logic to entered always 1h --- htdocs/fichinter/card.php | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index dac78d9ae3bf6..b5a00b694bf6e 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -248,7 +248,24 @@ $prod = new Product($db); $prod->id=$lines[$i]->fk_product; $prod->getMultiLangs(); - + // We show if duration is present on service (so we get it) + $prod->fetch($lines[$i]->fk_product); + if ($prod->duration_value) + { + switch($prod->duration_unit) + { + case 'h': + $durationproduct=$prod->duration_value * 3600 * $lines[$i]->qty; + break; + case 'd': + $durationproduct=$prod->duration_value * 3600 * 24 * $lines[$i]->qty; + break; + case 'w': + $durationproduct=$prod->duration_value * 3600 * 24 * 7 * $lines[$i]->qty; + break; + + } + } $outputlangs = $langs; $newlang=''; if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id'); @@ -268,7 +285,7 @@ $desc = $label; $desc .= ' ('.$langs->trans('Quantity').': '.$lines[$i]->qty.')'; - } + else { $desc = dol_htmlentitiesbr($lines[$i]->desc); $desc .= ' ('.$langs->trans('Quantity').': '.$lines[$i]->qty.')'; @@ -277,7 +294,7 @@ $date_intervention=dol_mktime(0,0,0,$timearray['mon'],$timearray['mday'],$timearray['year']); if ($product_type == 1) { //service - $duration = 3600; + $duration = ($durationproduct ? $durationproduct : 3600); } else { //product From b57f0a0e5fb4ab17565551bcc1f70fdd31054abf Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 5 Jun 2015 18:32:49 +0200 Subject: [PATCH 22/36] Fix option to use old path for product is for compatibility if user come from 3.6 or lower. Must not be enabled on 3.7.0 or +. --- htdocs/install/mysql/migration/3.6.0-3.7.0.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql index b74c8ddba1758..f6282edf3695c 100755 --- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql +++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql @@ -1177,4 +1177,5 @@ insert into llx_c_tva(rowid,fk_pays,taux,recuperableonly,localtax1,localtax1_typ ALTER TABLE llx_livraison MODIFY COLUMN date_delivery DATETIME NULL DEFAULT NULL; -INSERT INTO llx_const (name, value, type, note, visible, entity) SELECT __ENCRYPT('PRODUCT_USE_OLD_PATH_FOR_PHOTO')__,__ENCRYPT('1')__,'chaine','Use old path for products images',1,0 FROM llx_const WHERE __DECRYPT('name')__ = 'MAIN_VERSION_LAST_INSTALL' AND __DECRYPT('value')__ <= '3.7.2'; +-- This constant is for compatibility if user come from 3.6 or lower. Must not be enabled on 3.7.0 or + +INSERT INTO llx_const (name, value, type, note, visible, entity) SELECT __ENCRYPT('PRODUCT_USE_OLD_PATH_FOR_PHOTO')__,__ENCRYPT('1')__,'chaine','Use old path for products images',1,0 FROM llx_const WHERE __DECRYPT('name')__ = 'MAIN_VERSION_LAST_INSTALL' AND __DECRYPT('value')__ < '3.7.0'; From 9a812a6c287913437e0262b4aea5e5acb37318bb Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 6 Jun 2015 13:03:02 +0200 Subject: [PATCH 23/36] Fix: add filter for "dol_most_recent_files" for avoid conflict with option "Save file on server with name "FA0700034-Original filename"" --- htdocs/comm/propal.php | 4 ++-- htdocs/commande/card.php | 6 +++--- htdocs/compta/facture.php | 6 +++--- htdocs/core/tpl/document_actions_post_headers.tpl.php | 2 +- htdocs/expedition/card.php | 4 ++-- htdocs/fichinter/card.php | 4 ++-- htdocs/fourn/commande/card.php | 4 ++-- htdocs/fourn/facture/card.php | 4 ++-- 8 files changed, 17 insertions(+), 17 deletions(-) diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index a0ef8878d1f7a..b5302063a65c4 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -2194,7 +2194,7 @@ $ref = dol_sanitizeFileName($object->ref); include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; - $fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref, preg_quote($ref, '/')); + $fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref, preg_quote($ref, '/').'([^\-])+'); $file = $fileparams ['fullname']; // Define output language @@ -2219,7 +2219,7 @@ dol_print_error($db, $result); exit(); } - $fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref, preg_quote($ref, '/')); + $fileparams = dol_most_recent_file($conf->propal->dir_output . '/' . $ref, preg_quote($ref, '/').'([^\-])+'); $file = $fileparams ['fullname']; } diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index e6be7a8d74bf9..c326959619a8a 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -2,7 +2,7 @@ /* Copyright (C) 2003-2006 Rodolphe Quiedeville * Copyright (C) 2004-2014 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo - * Copyright (C) 2005-2013 Regis Houssin + * Copyright (C) 2005-2015 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2010-2013 Juanjo Menent * Copyright (C) 2011 Philippe Grand @@ -2285,7 +2285,7 @@ $ref = dol_sanitizeFileName($object->ref); include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; - $fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/')); + $fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/').'([^\-])+'); $file = $fileparams ['fullname']; // Define output language @@ -2310,7 +2310,7 @@ dol_print_error($db, $result); exit(); } - $fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/')); + $fileparams = dol_most_recent_file($conf->commande->dir_output . '/' . $ref, preg_quote($ref, '/').'([^\-])+'); $file = $fileparams ['fullname']; } diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index e247863a01519..b360f6b63157c 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -3,7 +3,7 @@ * Copyright (C) 2004 Eric Seigne * Copyright (C) 2004-2014 Laurent Destailleur * Copyright (C) 2005 Marc Barilley / Ocebo - * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2005-2015 Regis Houssin * Copyright (C) 2006 Andre Cianfarani * Copyright (C) 2010-2015 Juanjo Menent * Copyright (C) 2012-2013 Christophe Battarel @@ -3561,7 +3561,7 @@ $ref = dol_sanitizeFileName($object->ref); include_once DOL_DOCUMENT_ROOT . '/core/lib/files.lib.php'; - $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/')); + $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/').'([^\-])+'); $file = $fileparams ['fullname']; // Define output language @@ -3586,7 +3586,7 @@ dol_print_error($db, $result); exit(); } - $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/')); + $fileparams = dol_most_recent_file($conf->facture->dir_output . '/' . $ref, preg_quote($ref, '/').'([^\-])+'); $file = $fileparams ['fullname']; } diff --git a/htdocs/core/tpl/document_actions_post_headers.tpl.php b/htdocs/core/tpl/document_actions_post_headers.tpl.php index d1a1cedca6133..75d18c2b1a56e 100644 --- a/htdocs/core/tpl/document_actions_post_headers.tpl.php +++ b/htdocs/core/tpl/document_actions_post_headers.tpl.php @@ -48,7 +48,7 @@ //var_dump($modulepart); if (in_array($modulepart,array('facture_fournisseur','commande_fournisseur','facture','commande','propal','ficheinter','contract','project','project_task'))) { - $savingdocmask=$object->ref.'___file__'; + $savingdocmask=$object->ref.'-__file__'; } /*if (in_array($modulepart,array('member'))) { diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index 7187506db148c..7dd0d680bee5d 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -1621,7 +1621,7 @@ { $ref = dol_sanitizeFileName($object->ref); include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - $fileparams = dol_most_recent_file($conf->expedition->dir_output . '/sending/' . $ref, preg_quote($ref,'/')); + $fileparams = dol_most_recent_file($conf->expedition->dir_output . '/sending/' . $ref, preg_quote($ref, '/').'([^\-])+'); $file=$fileparams['fullname']; // Define output language @@ -1648,7 +1648,7 @@ dol_print_error($db,$result); exit; } - $fileparams = dol_most_recent_file($conf->expedition->dir_output . '/sending/' . $ref, preg_quote($ref,'/')); + $fileparams = dol_most_recent_file($conf->expedition->dir_output . '/sending/' . $ref, preg_quote($ref, '/').'([^\-])+'); $file=$fileparams['fullname']; } diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index f5fcd07670997..6fb4d374a7a4e 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -1732,7 +1732,7 @@ { $ref = dol_sanitizeFileName($object->ref); include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - $fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref, preg_quote($ref,'/')); + $fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref, preg_quote($ref, '/').'([^\-])+'); $file=$fileparams['fullname']; // Define output language @@ -1759,7 +1759,7 @@ dol_print_error($db,$result); exit; } - $fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref, preg_quote($ref,'/')); + $fileparams = dol_most_recent_file($conf->ficheinter->dir_output . '/' . $ref, preg_quote($ref, '/').'([^\-])+'); $file=$fileparams['fullname']; } diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index a6ac9c42b56bc..584b5e337e0d7 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -1920,7 +1920,7 @@ { $ref = dol_sanitizeFileName($object->ref); include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - $fileparams = dol_most_recent_file($conf->fournisseur->commande->dir_output . '/' . $ref, preg_quote($ref,'/')); + $fileparams = dol_most_recent_file($conf->fournisseur->commande->dir_output . '/' . $ref, preg_quote($ref, '/').'([^\-])+'); $file=$fileparams['fullname']; // Define output language @@ -1947,7 +1947,7 @@ dol_print_error($db,$result); exit; } - $fileparams = dol_most_recent_file($conf->fournisseur->commande->dir_output . '/' . $ref, preg_quote($ref,'/')); + $fileparams = dol_most_recent_file($conf->fournisseur->commande->dir_output . '/' . $ref, preg_quote($ref, '/').'([^\-])+'); $file=$fileparams['fullname']; } diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index 54ef660f6aa79..08bffd09a6750 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -2396,7 +2396,7 @@ { $ref = dol_sanitizeFileName($object->ref); include_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; - $fileparams = dol_most_recent_file($conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref, preg_quote($ref,'/')); + $fileparams = dol_most_recent_file($conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref, preg_quote($ref, '/').'([^\-])+'); $file=$fileparams['fullname']; // Define output language @@ -2423,7 +2423,7 @@ dol_print_error($db,$result); exit; } - $fileparams = dol_most_recent_file($conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref, preg_quote($ref,'/')); + $fileparams = dol_most_recent_file($conf->fournisseur->facture->dir_output.'/'.get_exdir($object->id,2).$ref, preg_quote($ref, '/').'([^\-])+'); $file=$fileparams['fullname']; } From 536f565d4e4105844e536a3e573da54ab6e50aff Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 7 Jun 2015 02:43:51 +0200 Subject: [PATCH 24/36] Fix Return value is always utf8 encoded and without entities. --- htdocs/core/lib/company.lib.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index a9663d447bcdc..e124c312a7727 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -352,7 +352,7 @@ function getState($id,$withcode='',$dbtouse=0) } else { - return $langs->trans("NotDefined"); + return $langs->transnoentitiesnoconv("NotDefined"); } } else dol_print_error($dbtouse,''); From bcf9bdc92e9d2c97cbd9232637e45edd05a9e998 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Sun, 7 Jun 2015 23:18:51 +0200 Subject: [PATCH 25/36] Update card.php new setting vars FICHINTER_USE_SERVICE_DURATION --- htdocs/fichinter/card.php | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index b5a00b694bf6e..73f8b16fdb3db 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -5,6 +5,7 @@ * Copyright (C) 2011-2013 Juanjo Menent * Copyright (C) 2013 Florian Henry * Copyright (C) 2014 Ferran Marcet + * Copyright (C) 201 Charlie Benke * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -250,22 +251,12 @@ $prod->getMultiLangs(); // We show if duration is present on service (so we get it) $prod->fetch($lines[$i]->fk_product); - if ($prod->duration_value) + if ($prod->duration_value && $prod->duration_unit == 'h' && $conf->global->FICHINTER_USE_SERVICE_DURATION) { - switch($prod->duration_unit) - { - case 'h': - $durationproduct=$prod->duration_value * 3600 * $lines[$i]->qty; - break; - case 'd': - $durationproduct=$prod->duration_value * 3600 * 24 * $lines[$i]->qty; - break; - case 'w': - $durationproduct=$prod->duration_value * 3600 * 24 * 7 * $lines[$i]->qty; - break; - - } + $durationproduct=$prod->duration_value * 3600 * $lines[$i]->qty; } + else + $durationproduct=3600; $outputlangs = $langs; $newlang=''; if (empty($newlang) && GETPOST('lang_id')) $newlang=GETPOST('lang_id'); @@ -294,11 +285,11 @@ $date_intervention=dol_mktime(0,0,0,$timearray['mon'],$timearray['mday'],$timearray['year']); if ($product_type == 1) { //service - $duration = ($durationproduct ? $durationproduct : 3600); + $duration = $durationproduct; } else { //product - $duration = 0; + $duration = 0; } $predef = ''; From 67c9a95ffbdff3f38c0d6598fa8dcb5aba777d98 Mon Sep 17 00:00:00 2001 From: aspangaro Date: Mon, 8 Jun 2015 05:28:12 +0200 Subject: [PATCH 26/36] FIX: Correct migration script --- htdocs/install/mysql/migration/3.7.0-3.8.0.sql | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql index 140475ed5df0b..1b3633c9ae543 100755 --- a/htdocs/install/mysql/migration/3.7.0-3.8.0.sql +++ b/htdocs/install/mysql/migration/3.7.0-3.8.0.sql @@ -647,12 +647,12 @@ ALTER TABLE llx_actioncomm ADD COLUMN email_sender varchar(256); ALTER TABLE llx_actioncomm ADD COLUMN email_to varchar(256); ALTER TABLE llx_actioncomm ADD COLUMN errors_to varchar(256); --- Recuring events +-- Recurring events ALTER TABLE llx_actioncomm ADD COLUMN recurid varchar(128); ALTER TABLE llx_actioncomm ADD COLUMN recurrule varchar(128); ALTER TABLE llx_actioncomm ADD COLUMN recurdateend datetime; -ALTER TABLE llx_stcomm ADD COLUMN picto varchar(128); +ALTER TABLE llx_c_stcomm ADD COLUMN picto varchar(128); -- New trigger for Supplier invoice unvalidation INSERT INTO llx_c_action_trigger (code, label, description, elementtype, rang) VALUES ('BILL_SUPPLIER_UNVALIDATE','Supplier invoice unvalidated','Executed when a supplier invoice status is set back to draft','invoice_supplier',15); From de0dd5da603e93998e9e38d745788ff0fd1dad64 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 8 Jun 2015 09:13:21 +0200 Subject: [PATCH 27/36] Fix: Drop foreign key for avoid Mysql crash --- htdocs/install/mysql/migration/3.6.0-3.7.0.sql | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql index f6282edf3695c..57f29ef9a90cd 100755 --- a/htdocs/install/mysql/migration/3.6.0-3.7.0.sql +++ b/htdocs/install/mysql/migration/3.6.0-3.7.0.sql @@ -208,10 +208,14 @@ UPDATE llx_product SET fk_barcode_type = NULL WHERE fk_barcode_type NOT IN (SELE ALTER TABLE llx_product_price ADD INDEX idx_product_price_fk_user_author (fk_user_author); UPDATE llx_product_price set fk_user_author = null where fk_user_author = 0; UPDATE llx_product_price set fk_user_author = null where fk_user_author not in (select rowid from llx_user); +-- drop foreign key for avoid a mysql crash +ALTER TABLE llx_product_price DROP FOREIGN KEY fk_product_price_user_author; ALTER TABLE llx_product_price ADD CONSTRAINT fk_product_price_user_author FOREIGN KEY (fk_user_author) REFERENCES llx_user (rowid); -- fk_product ALTER TABLE llx_product_price ADD INDEX idx_product_price_fk_product (fk_product); DELETE from llx_product_price where fk_product NOT IN (SELECT rowid from llx_product); +-- drop foreign key for avoid a mysql crash +ALTER TABLE llx_product_price DROP FOREIGN KEY fk_product_price_product; ALTER TABLE llx_product_price ADD CONSTRAINT fk_product_price_product FOREIGN KEY (fk_product) REFERENCES llx_product (rowid); ALTER TABLE llx_commande_fournisseur MODIFY COLUMN date_livraison datetime; From 4a18b730b52cdecd38c198538328c235ed0a285c Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 8 Jun 2015 13:49:09 +0200 Subject: [PATCH 28/36] Fix: Avoid warning in expense report validation Fix: navigation in expense report --- htdocs/core/class/html.form.class.php | 4 +- htdocs/expensereport/card.php | 242 ++++++++++-------- .../class/expensereport.class.php | 64 ++--- htdocs/expensereport/index.php | 2 +- htdocs/expensereport/list.php | 3 +- htdocs/societe/class/societe.class.php | 2 +- htdocs/societe/societe.php | 2 +- htdocs/theme/eldy/style.css.php | 7 +- htdocs/user/class/user.class.php | 1 - 9 files changed, 175 insertions(+), 152 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index e770bb5ea721d..07fcee8e70927 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -4964,7 +4964,7 @@ function select_export_model($selected='',$htmlname='exportmodelid',$type='',$us * @param string $paramid Name of parameter to use to name the id into the URL link * @param string $morehtml More html content to output just before the nav bar * @param int $shownav Show Condition (navigation is shown if value is 1) - * @param string $fieldid Nom du champ en base a utiliser pour select next et previous + * @param string $fieldid Nom du champ en base a utiliser pour select next et previous (we make the select max and min on this field) * @param string $fieldref Nom du champ objet ref (object->ref) a utiliser pour select next et previous * @param string $morehtmlref Code html supplementaire a afficher apres ref * @param string $moreparam More param to add in nav link url. @@ -4990,7 +4990,7 @@ function showrefnav($object,$paramid,$morehtml='',$shownav=1,$fieldid='rowid',$f //print "xx".$previous_ref."x".$next_ref; //if ($previous_ref || $next_ref || $morehtml) { //$ret.=''; print ''; @@ -1376,7 +1392,7 @@ // Ref print ''; print ''; @@ -1450,6 +1466,7 @@ print ''; } + // User to inform if($object->fk_statut<3) // informed { print ''; @@ -1460,6 +1477,7 @@ $userfee=new User($db); $userfee->fetch($object->fk_user_validator); print $userfee->getNomUrl(1); + if (empty($userfee->email) || ! isValidEmail($userfee->email)) print img_warning($langs->trans("EmailNotValid")); } print ''; } @@ -1530,7 +1548,7 @@ $sql.= ' FROM '.MAIN_DB_PREFIX.'expensereport_det as fde'; $sql.= ' INNER JOIN '.MAIN_DB_PREFIX.'c_type_fees as ctf ON fde.fk_c_type_fees=ctf.id'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'projet as pjt ON fde.fk_projet=pjt.rowid'; - $sql.= ' WHERE fde.fk_expensereport = '.$id; + $sql.= ' WHERE fde.fk_expensereport = '.$object->id; $resql = $db->query($sql); if ($resql) @@ -1692,8 +1710,8 @@ print_fiche_titre($langs->trans("AddLine"),'',''); print ''; - print ''; - print ''; + print ''; + print ''; print ''; print '
'; - $ret.='
'; + $ret.='
'; //} $ret.=dol_htmlentities($object->$fieldref); diff --git a/htdocs/expensereport/card.php b/htdocs/expensereport/card.php index 2d9bcbceead41..0b688790af763 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -46,6 +46,7 @@ $date_end = dol_mktime(0, 0, 0, GETPOST('date_finmonth'), GETPOST('date_finday'), GETPOST('date_finyear')); $date = dol_mktime(0, 0, 0, GETPOST('datemonth'), GETPOST('dateday'), GETPOST('dateyear')); $fk_projet=GETPOST('fk_projet'); +$ref=GETPOST("ref",'alpha'); // If socid provided by ajax company selector if (! empty($_REQUEST['socid_id'])) @@ -92,7 +93,7 @@ if ($action == 'confirm_delete' && GETPOST("confirm") == "yes" && $id > 0 && $user->rights->expensereport->supprimer) { $object = new ExpenseReport($db); - $result=$object->delete($id); + $result=$object->delete($id, $user); if ($result >= 0) { header("Location: index.php"); @@ -214,59 +215,67 @@ $expediteur->fetch($object->fk_user_author); $emailFrom = $expediteur->email; - // SUBJECT - $subject = $langs->trans("ExpenseReportWaitingForApproval"); + if ($emailTo && $emailFrom) + { + // SUBJECT + $subject = $langs->trans("ExpenseReportWaitingForApproval"); - // CONTENT - $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; - $message = $langs->trans("ExpenseReportWaitingForApprovalMessage", $expediteur->getFullName($langs), get_date_range($object->date_debut,$object->date_fin,'',$langs), $link); + // CONTENT + $link = $urlwithroot.'/expensereport/card.php?id='.$object->id; + $message = $langs->trans("ExpenseReportWaitingForApprovalMessage", $expediteur->getFullName($langs), get_date_range($object->date_debut,$object->date_fin,'',$langs), $link); - // Rebuild pdf - /* - $object->setDocModel($user,""); - $resultPDF = expensereport_pdf_create($db,$id,'',"",$langs); + // Rebuild pdf + /* + $object->setDocModel($user,""); + $resultPDF = expensereport_pdf_create($db,$id,'',"",$langs); - if($resultPDF): - // ATTACHMENT - $filename=array(); $filedir=array(); $mimetype=array(); - array_push($filename,dol_sanitizeFileName($object->ref).".pdf"); - array_push($filedir,$conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref) . "/" . dol_sanitizeFileName($object->ref).".pdf"); - array_push($mimetype,"application/pdf"); - */ + if($resultPDF): + // ATTACHMENT + $filename=array(); $filedir=array(); $mimetype=array(); + array_push($filename,dol_sanitizeFileName($object->ref).".pdf"); + array_push($filedir,$conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref) . "/" . dol_sanitizeFileName($object->ref).".pdf"); + array_push($mimetype,"application/pdf"); + */ - // PREPARE SEND - $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); + // PREPARE SEND + $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); - if ($mailfile) - { - // SEND - $result=$mailfile->sendfile(); - if ($result) - { - $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2)); - setEventMessage($mesg); - header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); - exit; - } - else + if ($mailfile) { - $langs->load("other"); - if ($mailfile->error) + // SEND + $result=$mailfile->sendfile(); + if ($result) { - $mesg=''; - $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto); - $mesg.='
'.$mailfile->error; - setEventMessage($mesg,'errors'); + $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2)); + setEventMessage($mesg); + header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); + exit; } else { - setEventMessage('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', 'warnings'); + $langs->load("other"); + if ($mailfile->error) + { + $mesg=''; + $mesg.=$langs->trans('ErrorFailedToSendMail',$from,$sendto); + $mesg.='
'.$mailfile->error; + setEventMessage($mesg,'errors'); + } + else + { + setEventMessage('No mail sent. Feature is disabled by option MAIN_DISABLE_ALL_MAILS', 'warnings'); + } } } + else + { + setEventMessages($mailfile->error,$mailfile->errors,'errors'); + $action=''; + } } else { - setEventMessages($mailfile->error,$mailfile->errors,'errors'); + setEventMessage($langs->trans("NoEmailSentBadSenderOrRecipientEmail"), 'warnings'); $action=''; } } @@ -304,66 +313,73 @@ if ($result > 0) { - // Send mail if (! empty($conf->global->DEPLACEMENT_TO_CLEAN)) { + // Send mail + // TO $destinataire = new User($db); $destinataire->fetch($object->fk_user_validator); $emailTo = $destinataire->email; - // FROM - $expediteur = new User($db); - $expediteur->fetch($object->fk_user_author); - $emailFrom = $expediteur->email; - - // SUBJECT - $subject = "' ERP - Note de frais à re-approuver"; - - // CONTENT - $dateRefusEx = explode(" ",$object->date_refuse); - - $message = "Bonjour {$destinataire->firstname},\n\n"; - $message.= "Le {$dateRefusEx[0]} à {$dateRefusEx[1]} vous avez refusé d'approuver la note de frais \"{$object->ref}\". Vous aviez émis le motif suivant : {$object->detail_refuse}\n\n"; - $message.= "L'auteur vient de modifier la note de frais, veuillez trouver la nouvelle version en pièce jointe.\n"; - $message.= "- Déclarant : {$expediteur->firstname} {$expediteur->lastname}\n"; - $message.= "- Période : du {$object->date_debut} au {$object->date_fin}\n"; - $message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n"; - $message.= "Bien cordialement,\n' SI"; - - // Génération du pdf avant attachement - $object->setDocModel($user,""); - $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); + if ($emailTo) + { + // FROM + $expediteur = new User($db); + $expediteur->fetch($object->fk_user_author); + $emailFrom = $expediteur->email; - if($resultPDF): - // ATTACHMENT - $filename=array(); $filedir=array(); $mimetype=array(); - array_push($filename,dol_sanitizeFileName($object->ref).".pdf"); - array_push($filedir,$conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref) . "/" . dol_sanitizeFileName($object->ref_number).".pdf"); - array_push($mimetype,"application/pdf"); + // SUBJECT + $subject = "' ERP - Note de frais à re-approuver"; - // PREPARE SEND - $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); + // CONTENT + $dateRefusEx = explode(" ",$object->date_refuse); - if(!$mailfile->error): + $message = "Bonjour {$destinataire->firstname},\n\n"; + $message.= "Le {$dateRefusEx[0]} à {$dateRefusEx[1]} vous avez refusé d'approuver la note de frais \"{$object->ref}\". Vous aviez émis le motif suivant : {$object->detail_refuse}\n\n"; + $message.= "L'auteur vient de modifier la note de frais, veuillez trouver la nouvelle version en pièce jointe.\n"; + $message.= "- Déclarant : {$expediteur->firstname} {$expediteur->lastname}\n"; + $message.= "- Période : du {$object->date_debut} au {$object->date_fin}\n"; + $message.= "- Lien : {$dolibarr_main_url_root}/expensereport/card.php?id={$object->id}\n\n"; + $message.= "Bien cordialement,\n' SI"; - // SEND - $result=$mailfile->sendfile(); - if ($result): - Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); - exit; - endif; + // Génération du pdf avant attachement + $object->setDocModel($user,""); + $resultPDF = expensereport_pdf_create($db,$object,'',"",$langs); - else: + if($resultPDF) + { + // ATTACHMENT + $filename=array(); $filedir=array(); $mimetype=array(); + array_push($filename,dol_sanitizeFileName($object->ref).".pdf"); + array_push($filedir,$conf->expensereport->dir_output . "/" . dol_sanitizeFileName($object->ref) . "/" . dol_sanitizeFileName($object->ref_number).".pdf"); + array_push($mimetype,"application/pdf"); - $mesg="Impossible d'envoyer l'email."; + // PREPARE SEND + $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); - endif; - // END - Send mail - else: - dol_print_error($db,$resultPDF); - exit; - endif; + if (! $mailfile->error) + { + // SEND + $result=$mailfile->sendfile(); + if ($result) + { + Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); + exit; + } + else + { + $mesg=$mailfile->error; + } + // END - Send mail + } + else + { + dol_print_error($db,$resultPDF); + exit; + } + } + } } } else @@ -1168,10 +1184,10 @@ } else { - if($id > 0) + if($id > 0 || $ref) { $object = new ExpenseReport($db); - $result = $object->fetch($id); + $result = $object->fetch($id, $ref); if ($result > 0) { @@ -1218,7 +1234,7 @@ // Ref print '
'.$langs->trans("Ref").''; - print $form->showrefnav($object, 'id', $linkback, 1, 'rowid', 'ref', ''); + print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', ''); print '
'.$langs->trans("Ref").''; - print $form->showrefnav($object, 'id', $linkback, 1, 'ref', 'ref', ''); + print $form->showrefnav($object, 'ref', $linkback, 1, 'ref', 'ref', ''); print '
'; @@ -1789,7 +1807,7 @@ if ($action != 'create' && $action != 'edit') { $object = new ExpenseReport($db); - $object->fetch($id); + $object->fetch($id, $ref); /* Si l'état est "Brouillon" @@ -1802,18 +1820,18 @@ if ($object->fk_user_author == $user->id) { // Modify - print ''.$langs->trans('Modify').''; + print 'id.'">'.$langs->trans('Modify').''; // Validate if (count($object->lines) > 0 || count($object->lignes) > 0) { - print ''.$langs->trans('ValidateAndSubmit').''; + print 'id.'">'.$langs->trans('ValidateAndSubmit').''; } if ($user->rights->expensereport->supprimer) { // Delete - print ''.$langs->trans('Delete').''; + print 'id.'">'.$langs->trans('Delete').''; } } } @@ -1828,17 +1846,17 @@ if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) { // Modify - print ''.$langs->trans('Modify').''; + print 'id.'">'.$langs->trans('Modify').''; // Brouillonner (le statut refusée est identique à brouillon) //print ''.$langs->trans('BROUILLONNER').''; // Enregistrer depuis le statut "Refusée" - print ''.$langs->trans('ValidateAndSubmit').''; + print 'id.'">'.$langs->trans('ValidateAndSubmit').''; if ($user->rights->expensereport->supprimer) { // Delete - print ''.$langs->trans('Delete').''; + print 'id.'">'.$langs->trans('Delete').''; } } } @@ -1848,7 +1866,7 @@ if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) { // Brouillonner - print ''.$langs->trans('SetToDraft').''; + print 'id.'">'.$langs->trans('SetToDraft').''; } } @@ -1862,7 +1880,7 @@ if ($object->fk_user_author == $user->id) { // Brouillonner - print ''.$langs->trans('SetToDraft').''; + print 'id.'">'.$langs->trans('SetToDraft').''; } } @@ -1871,21 +1889,21 @@ //if($object->fk_user_validator==$user->id) //{ // Validate - print ''.$langs->trans('Approve').''; + print 'id.'">'.$langs->trans('Approve').''; // Deny - print ''.$langs->trans('Deny').''; + print 'id.'">'.$langs->trans('Deny').''; //} if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) { // Cancel - print ''.$langs->trans('Cancel').''; + print 'id.'">'.$langs->trans('Cancel').''; } if($user->rights->expensereport->supprimer) { // Delete - print ''.$langs->trans('Delete').''; + print 'id.'">'.$langs->trans('Delete').''; } } @@ -1896,18 +1914,18 @@ if ($user->rights->expensereport->to_paid && $object->fk_statut == 5) { // Pay - print ''.$langs->trans('TO_PAID').''; + print 'id.'">'.$langs->trans('TO_PAID').''; // Cancel if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) { - print ''.$langs->trans('Cancel').''; + print 'id.'">'.$langs->trans('Cancel').''; } if($user->rights->expensereport->supprimer) { // Delete - print ''.$langs->trans('Delete').''; + print 'id.'">'.$langs->trans('Delete').''; } } @@ -1919,11 +1937,11 @@ if ($user->rights->expensereport->approve && $user->rights->expensereport->to_paid && $object->fk_statut==6) { // Cancel - print ''.$langs->trans('Cancel').''; + print 'id.'">'.$langs->trans('Cancel').''; if($user->rights->expensereport->supprimer) { // Delete - print ''.$langs->trans('Delete').''; + print 'id.'">'.$langs->trans('Delete').''; } } @@ -1937,11 +1955,11 @@ if ($user->id == $object->fk_user_author || $user->id == $object->fk_user_valid) { // Brouillonner - print ''.$langs->trans('ReOpen').''; + print 'id.'">'.$langs->trans('ReOpen').''; } // Delete - print ''.$langs->trans('Delete').''; + print 'id.'">'.$langs->trans('Delete').''; } } diff --git a/htdocs/expensereport/class/expensereport.class.php b/htdocs/expensereport/class/expensereport.class.php index 6d8dd793a3d52..98a6aea00e7eb 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -348,7 +348,8 @@ function fetch($id, $ref='') $this->code_statut = $obj->code_statut; $this->code_paiement = $obj->code_paiement; - $this->lignes = array(); + $this->lignes = array(); // deprecated + $this->lines = array(); $result=$this->fetch_lines(); @@ -772,9 +773,10 @@ function fetch_lines() * delete * * @param int $rowid Id to delete (optional) + * @param User $fuser User that delete * @return int <0 if KO, >0 if OK */ - function delete($rowid=0) + function delete($rowid=0, User $fuser=null) { global $user,$langs,$conf; @@ -810,10 +812,10 @@ function delete($rowid=0) /** * Set to status validate * - * @param User $user User + * @param User $fuser User * @return int <0 if KO, >0 if OK */ - function setValidate($user) + function setValidate($fuser) { global $conf,$langs; @@ -836,13 +838,13 @@ function setValidate($user) { $prefix="ER"; if (! empty($conf->global->EXPENSE_REPORT_PREFIX)) $prefix=$conf->global->EXPENSE_REPORT_PREFIX; - $this->ref = strtoupper($user->login).$expld_car.$prefix.$this->ref.$expld_car.dol_print_date($this->date_debut,'%y%m%d'); + $this->ref = strtoupper($fuser->login).$expld_car.$prefix.$this->ref.$expld_car.dol_print_date($this->date_debut,'%y%m%d'); } if ($this->fk_statut != 2) { $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; - $sql.= " SET ref = '".$this->ref."', fk_statut = 2, fk_user_valid = ".$user->id.","; + $sql.= " SET ref = '".$this->ref."', fk_statut = 2, fk_user_valid = ".$fuser->id.","; $sql.= " ref_number_int = ".$ref_number_int; $sql.= ' WHERE rowid = '.$this->id; @@ -867,10 +869,10 @@ function setValidate($user) /** * set_save_from_refuse * - * @param User $user User + * @param User $fuser User * @return int <0 if KO, >0 if OK */ - function set_save_from_refuse($user) + function set_save_from_refuse($fuser) { global $conf,$langs; @@ -912,10 +914,10 @@ function set_save_from_refuse($user) /** * Set status to approved * - * @param User $user User + * @param User $fuser User * @return int <0 if KO, >0 if OK */ - function setApproved($user) + function setApproved($fuser) { $now=dol_now(); @@ -924,7 +926,7 @@ function setApproved($user) if ($this->fk_statut != 5) { $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; - $sql.= " SET ref = '".$this->ref."', fk_statut = 5, fk_user_approve = ".$user->id.","; + $sql.= " SET ref = '".$this->ref."', fk_statut = 5, fk_user_approve = ".$fuser->id.","; $sql.= " date_approve='".$this->date_approve."'"; $sql.= ' WHERE rowid = '.$this->id; if ($this->db->query($sql)) @@ -946,10 +948,10 @@ function setApproved($user) /** * setDeny * - * @param User $user User + * @param User $fuser User * @param Details $details Details */ - function setDeny($user,$details) + function setDeny($fuser,$details) { $now = dol_now(); @@ -957,7 +959,7 @@ function setDeny($user,$details) if ($this->fk_statut != 99) { $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; - $sql.= " SET ref = '".$this->ref."', fk_statut = 99, fk_user_refuse = ".$user->id.","; + $sql.= " SET ref = '".$this->ref."', fk_statut = 99, fk_user_refuse = ".$fuser->id.","; $sql.= " date_refuse='".$this->db->idate($now)."',"; $sql.= " detail_refuse='".$this->db->escape($details)."'"; $sql.= " fk_user_approve=NULL,"; @@ -965,7 +967,7 @@ function setDeny($user,$details) if ($this->db->query($sql)) { $this->fk_statut = 99; - $this->fk_user_refuse = $user->id; + $this->fk_user_refuse = $fuser->id; $this->detail_refuse = $details; $this->date_refuse = $now; return 1; @@ -985,10 +987,10 @@ function setDeny($user,$details) /** * setPaid * - * @param User $user User + * @param User $fuser User * @return int <0 if KO, >0 if OK */ - function setPaid($user) + function setPaid($fuser) { $now= dol_now(); @@ -996,7 +998,7 @@ function setPaid($user) if ($this->fk_statut != 6) { $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; - $sql.= " SET fk_statut = 6, fk_user_paid = ".$user->id.","; + $sql.= " SET fk_statut = 6, fk_user_paid = ".$fuser->id.","; $sql.= " date_paiement='".$this->db->idate($this->date_paiement)."'"; $sql.= ' WHERE rowid = '.$this->id; @@ -1020,10 +1022,10 @@ function setPaid($user) /** * set_unpaid * - * @param User $user User + * @param User $fuser User * @return int <0 if KO, >0 if OK */ - function set_unpaid($user) + function set_unpaid($fuser) { if ($this->fk_c_deplacement_statuts != 5) { @@ -1049,17 +1051,17 @@ function set_unpaid($user) /** * set_cancel * - * @param User $user User + * @param User $fuser User * @param string $detail Detail * @return int <0 if KO, >0 if OK */ - function set_cancel($user,$detail) + function set_cancel($fuser,$detail) { $this->date_cancel = $this->db->idate(gmmktime()); if ($this->fk_statut != 4) { $sql = 'UPDATE '.MAIN_DB_PREFIX.$this->table_element; - $sql.= " SET fk_statut = 4, fk_user_cancel = ".$user->id; + $sql.= " SET fk_statut = 4, fk_user_cancel = ".$fuser->id; $sql.= ", date_cancel='".$this->date_cancel."'"; $sql.= " ,detail_cancel='".$this->db->escape($detail)."'"; $sql.= ' WHERE rowid = '.$this->id; @@ -1271,10 +1273,10 @@ function updateline($rowid, $type_fees_id, $projet_id, $vatrate, $comments, $qty * deleteline * * @param int $rowid Row id - * @param User $user User + * @param User $fuser User * @return int <0 if KO, >0 if OK */ - function deleteline($rowid, $user='') + function deleteline($rowid, $fuser='') { $this->db->begin(); @@ -1299,16 +1301,16 @@ function deleteline($rowid, $user='') /** * periode_existe * - * @param User $user User + * @param User $fuser User * @param Date $date_debut Start date * @param Date $date_fin End date * @return int <0 if KO, >0 if OK */ - function periode_existe($user, $date_debut, $date_fin) + function periode_existe($fuser, $date_debut, $date_fin) { $sql = "SELECT rowid, date_debut, date_fin"; $sql.= " FROM ".MAIN_DB_PREFIX.$this->table_element; - $sql.= " WHERE fk_user_author = '{$user->id}'"; + $sql.= " WHERE fk_user_author = '{$fuser->id}'"; dol_syslog(get_class($this)."::periode_existe sql=".$sql); $result = $this->db->query($sql); @@ -1617,12 +1619,12 @@ function insert($notrigger=0) /** * update * - * @param User $user User + * @param User $fuser User * @return int <0 if KO, >0 if OK */ - function update($user) + function update($fuser) { - global $user,$langs,$conf; + global $fuser,$langs,$conf; $error=0; diff --git a/htdocs/expensereport/index.php b/htdocs/expensereport/index.php index 4af39adb6333d..5b157f6df8bd3 100644 --- a/htdocs/expensereport/index.php +++ b/htdocs/expensereport/index.php @@ -107,7 +107,7 @@ print '
'; -print '
'; +print '
'; print ''; print ''; print "\n"; diff --git a/htdocs/expensereport/list.php b/htdocs/expensereport/list.php index 58002c19dbadd..c0b30b6c87330 100644 --- a/htdocs/expensereport/list.php +++ b/htdocs/expensereport/list.php @@ -180,6 +180,7 @@ print_barre_liste($langs->trans("ListTripsAndExpenses"), $page, $_SERVER["PHP_SELF"],$param,$sortfield,$sortorder,'',$num,$nbtotalofrecords); print ''."\n"; + print '
'.$langs->trans("Statistics").'
'; print ""; print_liste_field_titre($langs->trans("Ref"),$_SERVER["PHP_SELF"],"d.rowid","",$param,'',$sortfield,$sortorder); @@ -190,7 +191,7 @@ print_liste_field_titre($langs->trans("TotalVAT"),$_SERVER["PHP_SELF"],"d.total_tva","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("TotalTTC"),$_SERVER["PHP_SELF"],"d.total_ttc","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Statut"),$_SERVER["PHP_SELF"],"","",$param,'align="right"',$sortfield,$sortorder); - print ''; + print_liste_field_titre(''); print "\n"; // Filters diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index c61b08b1ecf03..4d55732b801b9 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1045,7 +1045,7 @@ function fetch($rowid, $ref='', $ref_ext='', $ref_int='', $idprof1='',$idprof2=' $num=$this->db->num_rows($resql); if ($num > 1) { - $this->error='Fetch several records found for ref='.$ref; + $this->error='Fetch several records found request'; dol_syslog($this->error, LOG_ERR); $result = -2; } diff --git a/htdocs/societe/societe.php b/htdocs/societe/societe.php index 0a8ec08da1dd2..9ab7e921faa6f 100644 --- a/htdocs/societe/societe.php +++ b/htdocs/societe/societe.php @@ -338,7 +338,7 @@ print_liste_field_titre($form->textwithpicto($langs->trans("ProfId2Short"),$textprofid[2],1,0),$_SERVER["PHP_SELF"],"s.siret","",$params,'class="nowrap"',$sortfield,$sortorder); print_liste_field_titre($form->textwithpicto($langs->trans("ProfId3Short"),$textprofid[3],1,0),$_SERVER["PHP_SELF"],"s.ape","",$params,'class="nowrap"',$sortfield,$sortorder); print_liste_field_titre($form->textwithpicto($langs->trans("ProfId4Short"),$textprofid[4],1,0),$_SERVER["PHP_SELF"],"s.idprof4","",$params,'class="nowrap"',$sortfield,$sortorder); - print ''; + print_liste_field_titre(''); print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"s.status","",$params,'align="right"',$sortfield,$sortorder); print "\n"; diff --git a/htdocs/theme/eldy/style.css.php b/htdocs/theme/eldy/style.css.php index 01caa7a728228..94f3277ea42f4 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -1974,9 +1974,12 @@ /* Pagination */ -div.refid { +div.refidpadding { padding-top: dol_use_jmobile)?'8':'12'; ?>px; - font-weight: bold; +} +div.refid { + padding-top: dol_use_jmobile)?'5':'12'; ?>px; + font-weight: bold; color: #766; font-size: 120%; } diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 4d7a3d18a5c03..bca20fccbb9df 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -1833,7 +1833,6 @@ function getNomUrl($withpicto=0, $option='', $infologin=0, $notooltip=0, $maxlen $label.= '' . $langs->trans('Name') . ': ' . $this->getFullName($langs,'',''); if (! empty($this->login)) $label.= '
' . $langs->trans('Login') . ': ' . $this->login; - if (! empty($this->email)) $label.= '
' . $langs->trans("EMail").': '.$this->email; if (! empty($this->admin)) $label.= '
' . $langs->trans("Administrator").': '.yn($this->admin); From e9526066b7ee8eb2bae3182e9f0be5dfbd240e59 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 8 Jun 2015 14:12:57 +0200 Subject: [PATCH 29/36] Prepare edition of field "bydefaultinlist" for extrafields. --- htdocs/core/actions_extrafields.inc.php | 33 +++++++++++++++++-- htdocs/core/tpl/admin_extrafields_add.tpl.php | 10 ++++-- .../core/tpl/admin_extrafields_edit.tpl.php | 9 ++++- htdocs/fichinter/card.php | 4 +-- 4 files changed, 48 insertions(+), 8 deletions(-) diff --git a/htdocs/core/actions_extrafields.inc.php b/htdocs/core/actions_extrafields.inc.php index 03d724b9bba4c..4c5f0b512d24d 100644 --- a/htdocs/core/actions_extrafields.inc.php +++ b/htdocs/core/actions_extrafields.inc.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2011-2015 Laurent Destailleur * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -148,7 +148,21 @@ } } - $result=$extrafields->addExtraField($_POST['attrname'],$_POST['label'],$_POST['type'],$_POST['pos'],$extrasize,$elementtype,(GETPOST('unique')?1:0),(GETPOST('required')?1:0),$default_value,$params,(GETPOST('alwayseditable')?1:0)); + $result=$extrafields->addExtraField( + GETPOST('attrname'), + GETPOST('label'), + GETPOST('type'), + GETPOST('pos'), + $extrasize, + $elementtype, + (GETPOST('unique')?1:0), + (GETPOST('required')?1:0), + $default_value, + $params, + (GETPOST('alwayseditable')?1:0), + (GETPOST('perms')?GETPOST('perms'):''), + (GETPOST('list')?1:0) + ); if ($result > 0) { setEventMessage($langs->trans('SetupSaved')); @@ -285,7 +299,20 @@ $params['options'][$key] = $value; } } - $result=$extrafields->update($_POST['attrname'],$_POST['label'],$_POST['type'],$extrasize,$elementtype,(GETPOST('unique')?1:0),(GETPOST('required')?1:0),$pos,$params,(GETPOST('alwayseditable')?1:0)); + $result=$extrafields->update( + GETPOST('attrname'), + GETPOST('label'), + GETPOST('type'), + $extrasize, + $elementtype, + (GETPOST('unique')?1:0), + (GETPOST('required')?1:0), + $pos, + $params, + (GETPOST('alwayseditable')?1:0), + (GETPOST('perms')?GETPOST('perms'):''), + (GETPOST('list')?1:0) + ); if ($result > 0) { setEventMessage($langs->trans('SetupSaved')); diff --git a/htdocs/core/tpl/admin_extrafields_add.tpl.php b/htdocs/core/tpl/admin_extrafields_add.tpl.php index 44de526942fc7..fc13acc7072b8 100644 --- a/htdocs/core/tpl/admin_extrafields_add.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_add.tpl.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2010-2015 Laurent Destailleur * Copyright (C) 2012 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -20,7 +20,7 @@ * The following vars must be defined * $type2label * $form - * $conf, $lang, + * $conf, $lang, */ ?> @@ -113,6 +113,12 @@ function init_typeoffields(type) +global->MAIN_FEATURES_LEVEL >= 2) { ?> + + +
 
trans("Required"); ?>>
trans("AlwaysEditable"); ?>>
trans("ByDefaultInList"); ?> +trans("FeatureNotYetSupported")); ?> +>

">   diff --git a/htdocs/core/tpl/admin_extrafields_edit.tpl.php b/htdocs/core/tpl/admin_extrafields_edit.tpl.php index 9c283b83867d7..286eba8c3b781 100644 --- a/htdocs/core/tpl/admin_extrafields_edit.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_edit.tpl.php @@ -56,6 +56,8 @@ function init_typeoffields(type) $pos=$extrafields->attribute_pos[$attrname]; $alwayseditable=$extrafields->attribute_alwayseditable[$attrname]; $param=$extrafields->attribute_param[$attrname]; +$perms=$extrafields->attribute_perms[$attrname]; +$list=$extrafields->attribute_list[$attrname]; if((($type == 'select') || ($type == 'checkbox') || ($type == 'radio')) && is_array($param)) { @@ -113,7 +115,12 @@ function init_typeoffields(type) trans("Required"); ?>> trans("AlwaysEditable"); ?>> - + +global->MAIN_FEATURES_LEVEL >= 2) { ?> +trans("ByDefaultInList"); ?> +trans("FeatureNotYetSupported")); ?> +> +

">   diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index bc269822da4e9..3409c075761e5 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -251,7 +251,7 @@ $prod->getMultiLangs(); // We show if duration is present on service (so we get it) $prod->fetch($lines[$i]->fk_product); - if ($prod->duration_value && $prod->duration_unit == 'h' && $conf->global->FICHINTER_USE_SERVICE_DURATION) + if ($prod->duration_value && $prod->duration_unit == 'h' && $conf->global->FICHINTER_USE_SERVICE_DURATION) { $durationproduct=$prod->duration_value * 3600 * $lines[$i]->qty; } @@ -276,7 +276,7 @@ $desc = $label; $desc .= ' ('.$langs->trans('Quantity').': '.$lines[$i]->qty.')'; - + } else { $desc = dol_htmlentitiesbr($lines[$i]->desc); $desc .= ' ('.$langs->trans('Quantity').': '.$lines[$i]->qty.')'; From df1dfcbd8a76d8d3432a80abeb30b856485f6250 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 8 Jun 2015 15:07:37 +0200 Subject: [PATCH 30/36] NEW Can filter proposal on a tag of a product Enhance also the prototype test_arrays to include select form before table. --- htdocs/comm/propal/list.php | 33 ++++++++++++++++++++------- htdocs/core/class/html.form.class.php | 8 ++++--- htdocs/langs/en_US/products.lang | 1 + htdocs/public/test/test_arrays.php | 33 +++++++++++++++++++++++++++ htdocs/theme/eldy/style.css.php | 4 ++++ 5 files changed, 68 insertions(+), 11 deletions(-) diff --git a/htdocs/comm/propal/list.php b/htdocs/comm/propal/list.php index 9fbdb2ffd7ef5..c8e96919f8431 100644 --- a/htdocs/comm/propal/list.php +++ b/htdocs/comm/propal/list.php @@ -56,6 +56,7 @@ $search_societe=GETPOST('search_societe','alpha'); $search_montant_ht=GETPOST('search_montant_ht','alpha'); $search_author=GETPOST('search_author','alpha'); +$search_product_category=GETPOST('search_product_category','int'); $search_town=GETPOST('search_town','alpha'); $viewstatut=$db->escape(GETPOST('viewstatut')); $object_statut=$db->escape(GETPOST('propal_statut')); @@ -91,6 +92,7 @@ $search_societe=''; $search_montant_ht=''; $search_author=''; + $search_product_category=''; $search_town=''; $year=''; $month=''; @@ -145,14 +147,15 @@ $limit = $conf->liste_limit; -if (! $sall) $sql = 'SELECT'; -else $sql = 'SELECT DISTINCT'; +$sql = 'SELECT'; +if ($sall || $search_product_category > 0) $sql = 'SELECT DISTINCT'; $sql.= ' s.rowid, s.nom as name, s.town, s.client, s.code_client,'; $sql.= ' p.rowid as propalid, p.note_private, p.total_ht, p.ref, p.ref_client, p.fk_statut, p.fk_user_author, p.datep as dp, p.fin_validite as dfv,'; if (! $user->rights->societe->client->voir && ! $socid) $sql .= " sc.fk_soc, sc.fk_user,"; $sql.= ' u.login'; $sql.= ' FROM '.MAIN_DB_PREFIX.'societe as s, '.MAIN_DB_PREFIX.'propal as p'; -if ($sall) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'propaldet as pd ON p.rowid=pd.fk_propal'; +if ($sall || $search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'propaldet as pd ON p.rowid=pd.fk_propal'; +if ($search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product'; $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON p.fk_user_author = u.rowid'; // We'll need this table joined to the select in order to filter by sale if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc"; @@ -190,7 +193,8 @@ if ($sall) { $sql .= natural_search(array('s.nom', 'p.note_private', 'p.note_public', 'pd.description'), $sall); } -if ($socid) $sql.= ' AND s.rowid = '.$socid; +if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$search_product_category; +if ($socid > 0) $sql.= ' AND s.rowid = '.$socid; if ($viewstatut <> '') { $sql.= ' AND p.fk_statut IN ('.$viewstatut.')'; @@ -223,7 +227,7 @@ $result = $db->query($sql); $nbtotalofrecords = $db->num_rows($result); } - +//print $sql; $sql.= $db->plimit($limit + 1,$offset); $result=$db->query($sql); @@ -265,15 +269,28 @@ if ($user->rights->societe->client->voir || $socid) { $langs->load("commercial"); - $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': '; + $moreforfilter.='
'; + $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': '; $moreforfilter.=$formother->select_salesrepresentatives($search_sale,'search_sale',$user); - $moreforfilter.='       '; + $moreforfilter.='
'; } // If the user can view prospects other than his' if ($user->rights->societe->client->voir || $socid) { - $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': '; + $moreforfilter.='
'; + $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': '; $moreforfilter.=$form->select_dolusers($search_user,'search_user',1); + $moreforfilter.='
'; + } + // If the user can view prospects other than his' + if ($conf->categorie->enabled && $user->rights->produit->lire) + { + include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; + $moreforfilter.='
'; + $moreforfilter.=$langs->trans('IncludingProductWithTag'). ': '; + $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1); + $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, '', 1); + $moreforfilter.='
'; } if (! empty($moreforfilter)) { diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 07fcee8e70927..394b77b97689e 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -4357,16 +4357,18 @@ static function selectarray($htmlname, $array, $id='', $show_empty=0, $key_in_la global $conf, $langs; // Do we want a multiselect ? - $multiselect = 0; - if (preg_match('/^multi/',$htmlname)) $multiselect = 1; + //$jsbeautify = 0; + //if (preg_match('/^multi/',$htmlname)) $jsbeautify = 1; + $jsbeautify = 1; if ($value_as_key) $array=array_combine($array, $array); $out=''; // Add code for jquery to use multiselect - if ($addjscombo && empty($conf->dol_use_jmobile) && $multiselect) + if ($addjscombo && empty($conf->dol_use_jmobile) && $jsbeautify) { + $minLengthToAutocomplete=0; $tmpplugin=empty($conf->global->MAIN_USE_JQUERY_MULTISELECT)?constant('REQUIRE_JQUERY_MULTISELECT')?constant('REQUIRE_JQUERY_MULTISELECT'):'select2':$conf->global->MAIN_USE_JQUERY_MULTISELECT; $out.='