From afc4d89c64c83bc93e5ed8d048e09dfe21a65ade Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Mon, 20 Apr 2015 20:18:17 +0200 Subject: [PATCH 01/56] Orders webservice : Generate pdf document on valid --- htdocs/webservices/server_order.php | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/htdocs/webservices/server_order.php b/htdocs/webservices/server_order.php index 9229d3b9c26..bf2eab8591c 100644 --- a/htdocs/webservices/server_order.php +++ b/htdocs/webservices/server_order.php @@ -916,7 +916,17 @@ function updateOrder($authentication,$order) if (isset($order['status'])) { if ($order['status'] == -1) $result=$object->cancel($fuser); - if ($order['status'] == 1) $result=$object->valid($fuser); + if ($order['status'] == 1) + { + $result=$object->valid($fuser); + if ($result >= 0) + { + // Define output language + $outputlangs = $langs; + $order->generateDocument($order->modelpdf, $outputlangs); + + } + } if ($order['status'] == 0) $result=$object->set_reopen($fuser); if ($order['status'] == 3) $result=$object->cloture($fuser); } From 97fc99517e50f96f0548aa8f880180a334aa877f Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Wed, 22 Apr 2015 12:47:45 +0200 Subject: [PATCH 02/56] Fixes : contact webservice fix update using ref_ext --- htdocs/webservices/server_contact.php | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/htdocs/webservices/server_contact.php b/htdocs/webservices/server_contact.php index ec652e80074..e0d76a0eb90 100644 --- a/htdocs/webservices/server_contact.php +++ b/htdocs/webservices/server_contact.php @@ -627,9 +627,15 @@ function updateContact($authentication,$contact) $error=0; $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel); // Check parameters - if (empty($contact['id'])) { - $error++; $errorcode='KO'; $errorlabel="Contact id is mandatory."; + if (empty($contact['id']) && empty($contact['ref_ext']) { + $error++; $errorcode='KO'; $errorlabel="Contact id or ref_ext is mandatory."; } + // Check parameters + if (! $error && ($id && $ref_ext)) + { + $error++; + $errorcode='BAD_PARAMETERS'; $errorlabel="Parameter id and ref_ext can't be all provided. You must choose one of them."; + } if (! $error) { @@ -638,7 +644,7 @@ function updateContact($authentication,$contact) include_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php'; $object=new Contact($db); - $result=$object->fetch($contact['id']); + $result=$object->fetch($contact['id'],0,$contact['ref_ext']); if (!empty($object->id)) { From 13cfae2eb6ab21290cd8f9fd3eb9cefa7168aaa7 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Fri, 24 Apr 2015 23:02:59 +0200 Subject: [PATCH 03/56] payment_mode_id should be in Invoice not InvoiceLine --- htdocs/webservices/server_invoice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index 9c5bd24b463..cb3f03121b5 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -102,7 +102,6 @@ $server->wsdl->addComplexType( 'total' => array('name'=>'total','type'=>'xsd:double'), 'date_start' => array('name'=>'date_start','type'=>'xsd:date'), 'date_end' => array('name'=>'date_end','type'=>'xsd:date'), - 'payment_mode_id' => array('name'=>'payment_mode_id','type'=>'xsd:string'), // From product 'product_id' => array('name'=>'product_id','type'=>'xsd:int'), 'product_ref' => array('name'=>'product_ref','type'=>'xsd:string'), @@ -160,6 +159,7 @@ $server->wsdl->addComplexType( 'date_creation' => array('name'=>'date_creation','type'=>'xsd:dateTime'), 'date_validation' => array('name'=>'date_validation','type'=>'xsd:dateTime'), 'date_modification' => array('name'=>'date_modification','type'=>'xsd:dateTime'), + 'payment_mode_id' => array('name'=>'payment_mode_id','type'=>'xsd:string'), 'type' => array('name'=>'type','type'=>'xsd:int'), 'total_net' => array('name'=>'type','type'=>'xsd:double'), 'total_vat' => array('name'=>'type','type'=>'xsd:double'), From 918d59b0d48203968242bcc5cb68a448a337abaa Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Fri, 24 Apr 2015 23:41:54 +0200 Subject: [PATCH 04/56] fix updateOrder result values --- htdocs/webservices/server_order.php | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/htdocs/webservices/server_order.php b/htdocs/webservices/server_order.php index 694404a3d8e..5db4adb2560 100644 --- a/htdocs/webservices/server_order.php +++ b/htdocs/webservices/server_order.php @@ -961,7 +961,9 @@ function updateOrder($authentication,$order) $db->commit(); $objectresp=array( 'result'=>array('result_code'=>'OK', 'result_label'=>''), - 'id'=>$object->id + 'id'=>$object->id, + 'ref'=>$object->ref, + 'ref_ext'=>$object->ref_ext ); } elseif ($objectfound) From fa9cb49fcb06da72317627c2f9c3cf45ed010197 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Fri, 24 Apr 2015 23:42:35 +0200 Subject: [PATCH 05/56] add updateInvoice webservice call --- htdocs/webservices/server_invoice.php | 117 +++++++++++++++++++++++++- 1 file changed, 114 insertions(+), 3 deletions(-) diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index cb3f03121b5..49720026582 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -250,6 +250,18 @@ $server->register( $styleuse, 'WS to create an invoice' ); +$server->register( + 'updateInvoice', + // Entry values + array('authentication'=>'tns:authentication','invoice'=>'tns:invoice'), + // Exit values + array('result'=>'tns:result','id'=>'xsd:string','ref'=>'xsd:string','ref_ext'=>'xsd:string'), + $ns, + $ns.'#updateInvoice', + $styledoc, + $styleuse, + 'WS to update an invoice' +); /** @@ -387,7 +399,7 @@ function getInvoicesForThirdParty($authentication,$idthirdparty) if (! $error && empty($idthirdparty)) { $error++; - $errorcode='BAD_PARAMETERS'; $errorlabel='Parameter id is not provided'; + $errorcode='BAD_PARAMETERS'; $errorlabel='Parameter idthirdparty is not provided'; } if (! $error) @@ -460,7 +472,7 @@ function getInvoicesForThirdParty($authentication,$idthirdparty) 'status'=> $invoice->statut, 'close_code' => $invoice->close_code?$invoice->close_code:'', 'close_note' => $invoice->close_note?$invoice->close_note:'', - 'payment_mode_id' => $invoice->mode_reglement_id?$invoice->mode_reglement_id:'', + 'payment_mode_id' => $invoice->mode_reglement_id?$invoice->mode_reglement_id:'', 'lines' => $linesresp ); } @@ -503,7 +515,8 @@ function createInvoice($authentication,$invoice) $now=dol_now(); - dol_syslog("Function: createInvoiceForThirdParty login=".$authentication['login']); + dol_syslog("Function: createInvoice login=".$authentication['login']." id=".$invoice->id. + ", ref=".$invoice->ref.", ref_ext=".$invoice->ref_ext); if ($authentication['entity']) $conf->entity=$authentication['entity']; @@ -513,6 +526,11 @@ function createInvoice($authentication,$invoice) $error=0; $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel); + // Check parameters + if (empty($invoice['id']) && empty($invoice['ref']) && empty($invoice['ref_ext'])) { + $error++; $errorcode='KO'; $errorlabel="Invoice id or ref or ref_ext is mandatory."; + } + if (! $error) { $newobject=new Facture($db); @@ -601,5 +619,98 @@ function createInvoice($authentication,$invoice) return $objectresp; } +/** + * Uddate an invoice, only change the state of an invoice + * + * @param array $authentication Array of authentication information + * @param Facture $invoice Invoice + * @return array Array result + */ +function updateInvoice($authentication,$invoice) +{ + global $db,$conf,$langs; + + dol_syslog("Function: updateInvoice login=".$authentication['login']." id=".$invoice->id. + ", ref=".$invoice->ref.", ref_ext=".$invoice->ref_ext); + + if ($authentication['entity']) $conf->entity=$authentication['entity']; + + // Init and check authentication + $objectresp=array(); + $errorcode='';$errorlabel=''; + $error=0; + $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel); + + // Check parameters + if (empty($invoice['id']) && empty($invoice['ref']) && empty($invoice['ref_ext'])) { + $error++; $errorcode='KO'; $errorlabel="Invoice id or ref or ref_ext is mandatory."; + } + + if (! $error) + { + $objectfound=false; + + $object=new Facture($db); + $result=$object->fetch($invoice['id'],$invoice['ref'],$invoice['ref_ext'], ''); + + if (!empty($object->id)) { + + $objectfound=true; + + $db->begin(); + + if (isset($invoice['status'])) + { + if ($invoice['status'] == 0) $result=$object->set_draft($fuser); + if ($invoice['status'] == 1) + { + $result=$object->validate($fuser); + + if ($result >= 0) + { + // Define output language + $outputlangs = $langs; + $order->generateDocument($invoice->modelpdf, $outputlangs); + } + } + if ($invlice['status'] == 2) + { + $result = $object->set_paid($fuser,$invoice->close_code,$invoice->close_note); + } + if ($invoice['status'] == 3) $result=$object->set_canceled($fuser,$invoice->close_code,$invoice->close_note); + } + } + + if ((! $error) && ($objectfound)) + { + $db->commit(); + $objectresp=array( + 'result'=>array('result_code'=>'OK', 'result_label'=>''), + 'id'=>$object->id, + 'ref'=>$object->ref, + 'ref_ext'=>$object->ref_ext + ); + } + elseif ($objectfound) + { + $db->rollback(); + $error++; + $errorcode='KO'; + $errorlabel=$object->error; + } else { + $error++; + $errorcode='NOT_FOUND'; + $errorlabel='Invoice id='.$invoice['id'].' ref='.$invoice['ref'].' ref_ext='.$invoice['ref_ext'].' cannot be found'; + } + } + + if ($error) + { + $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)); + } + + return $objectresp; +} + // Return the results. $server->service(file_get_contents("php://input")); From 4e10b94b6b3f7cbcc795770cac685ea6632df4eb Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Sat, 25 Apr 2015 00:38:32 +0200 Subject: [PATCH 06/56] Add webservice method createInvoiceFromOrder --- htdocs/webservices/server_invoice.php | 112 +++++++++++++++++++++++++- 1 file changed, 110 insertions(+), 2 deletions(-) diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index 49720026582..b55a22fbcd9 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -243,13 +243,25 @@ $server->register( // Entry values array('authentication'=>'tns:authentication','invoice'=>'tns:invoice'), // Exit values - array('result'=>'tns:result','id'=>'xsd:string','ref'=>'xsd:string'), + array('result'=>'tns:result','id'=>'xsd:string','ref'=>'xsd:string','ref_ext'=>'xsd:string'), $ns, $ns.'#createInvoice', $styledoc, $styleuse, 'WS to create an invoice' ); +$server->register( + 'createInvoiceFromOrder', + // Entry values + array('authentication'=>'tns:authentication','invoice'=>'tns:invoice'), + // Exit values + array('result'=>'tns:result','invoice'=>'tns:invoice'), + $ns, + $ns.'#createInvoiceFromOrder', + $styledoc, + $styleuse, + 'WS to create an invoice from an order' +); $server->register( 'updateInvoice', // Entry values @@ -599,7 +611,8 @@ function createInvoice($authentication,$invoice) if (! $error) { $db->commit(); - $objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''),'id'=>$newobject->id,'ref'=>$newobject->ref); + $objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''),'id'=>$newobject->id, + 'ref'=>$newobject->ref,'ref_ext'=>$newobject->ref_ext); } else { @@ -619,6 +632,101 @@ function createInvoice($authentication,$invoice) return $objectresp; } +/** + * Create an invoice from an order + * + * @param array $authentication Array of authentication information + * @param string $id_order id of order to copy invoice from + * @param string $ref_order ref of order to copy invoice from + * @param string $ref_ext_order ref_ext of order to copy invoice from + * @param string $id_invoice invoice id + * @param string $ref_invoice invoice ref + * @param string $ref_ext_invoice invoice ref_ext + * @return array Array result + */ +function createInvoiceFromOrder($authentication,$id_order='', $ref_order='', $ref_ext_order='', + $id_invoice='', $ref_invoice='', $ref_ext_invoice='') +{ + global $db,$conf,$langs; + + $now=dol_now(); + + dol_syslog("Function: createInvoiceFromOrder login=".$authentication['login']." id=".$id_order. + ", ref=".$ref_order.", ref_ext=".$ref_ext_order); + + if ($authentication['entity']) $conf->entity=$authentication['entity']; + + // Init and check authentication + $objectresp=array(); + $errorcode='';$errorlabel=''; + $error=0; + $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel); + + // Check parameters + if (empty($id_order) && empty($ref_order) && empty($ref_ext_order)) { + $error++; $errorcode='KO'; $errorlabel="order id or ref or ref_ext is mandatory."; + } else if (empty($id_invoice) && empty($ref_invoice) && empty($ref_ext_invoice)) { + $error++; $errorcode='KO'; $errorlabel="invoice id or ref or ref_ext is mandatory."; + } + + ////////////////////// + if (! $error) + { + $fuser->getrights(); + + if ($fuser->rights->commande->lire) + { + $order=new Commande($db); + $result=$order->fetch($id,$ref,$ref_ext); + if ($result > 0) + { + // Security for external user + if( $socid && ( $socid != $order->socid) ) + { + $error++; + $errorcode='PERMISSION_DENIED'; $errorlabel=$order->socid.'User does not have permission for this request'; + } + + if(!$error) + { + + $newobject=new Facture($db); + $result = $newobject->createFromOrder($order); + + if ($result < 0) + { + $error++; + dol_syslog("Webservice server_invoice:: invoice creation from order failed", LOG_ERR); + } + + } + } + else + { + $error++; + $errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id_order.' nor ref='.$ref_order.' nor ref_ext='.$ref_ext_order; + } + } + else + { + $error++; + $errorcode='PERMISSION_DENIED'; $errorlabel='User does not have permission for this request'; + } + } + + if ($error) + { + $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)); + } + else + { + $objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>''),'invoice'=>$newobject); + + } + + return $objectresp; +} + /** * Uddate an invoice, only change the state of an invoice * From d8027bd71d2336275848854fbd96b7158c25b0b6 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Mon, 4 May 2015 11:36:40 +0200 Subject: [PATCH 07/56] add thirdparty_id to get invoice --- htdocs/webservices/server_invoice.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index b55a22fbcd9..a9bc0a8ee44 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -343,6 +343,7 @@ function getInvoice($authentication,$id='',$ref='',$ref_ext='') 'id' => $invoice->id, 'ref' => $invoice->ref, 'ref_ext' => $invoice->ref_ext?$invoice->ref_ext:'', // If not defined, field is not added into soap + 'thirdparty_id' => $invoice->socid, 'fk_user_author' => $invoice->user_author?$invoice->user_author:'', 'fk_user_valid' => $invoice->user_valid?$invoice->user_valid:'', 'date' => $invoice->date?dol_print_date($invoice->date,'dayrfc'):'', From d27934419cf5dc51dfe20d47fb8eb2bc7cf4d07d Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Mon, 4 May 2015 11:36:53 +0200 Subject: [PATCH 08/56] fix log --- htdocs/webservices/server_contact.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/webservices/server_contact.php b/htdocs/webservices/server_contact.php index e0d76a0eb90..5db38052c7e 100644 --- a/htdocs/webservices/server_contact.php +++ b/htdocs/webservices/server_contact.php @@ -273,7 +273,7 @@ function getContact($authentication,$id,$ref_ext) ){ $contact_result_fields =array( 'id' => $contact->id, - 'ref_ext' => $contact->ref_ext, + 'ref_ext' => $contact->ref_ext, 'lastname' => $contact->lastname, 'firstname' => $contact->firstname, 'address' => $contact->address, @@ -336,7 +336,7 @@ function getContact($authentication,$id,$ref_ext) else { $error++; - $errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext; + $errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id.' nor ref_ext='.$ref_ext; } } From 8b753dc74323526575c114c5d7bd923837f1ed27 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Chevallier Date: Tue, 5 May 2015 10:05:13 +0200 Subject: [PATCH 09/56] fix typo --- htdocs/webservices/server_contact.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/webservices/server_contact.php b/htdocs/webservices/server_contact.php index 5db38052c7e..cbc126ebb5a 100644 --- a/htdocs/webservices/server_contact.php +++ b/htdocs/webservices/server_contact.php @@ -627,7 +627,7 @@ function updateContact($authentication,$contact) $error=0; $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel); // Check parameters - if (empty($contact['id']) && empty($contact['ref_ext']) { + if (empty($contact['id']) && empty($contact['ref_ext'])) { $error++; $errorcode='KO'; $errorlabel="Contact id or ref_ext is mandatory."; } // Check parameters From d020c4133a643d35c388df3ae34738c5d9b6d194 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Chevallier Date: Tue, 5 May 2015 10:26:05 +0200 Subject: [PATCH 10/56] webservice_order : return all necessary fields --- htdocs/webservices/server_invoice.php | 33 ++++++++++++++++++--------- 1 file changed, 22 insertions(+), 11 deletions(-) diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index a9bc0a8ee44..195662c46f9 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -323,15 +323,19 @@ function getInvoice($authentication,$id='',$ref='',$ref_ext='') $linesresp[]=array( 'id'=>$line->rowid, 'type'=>$line->product_type, - 'desc'=>dol_htmlcleanlastbr($line->desc), - 'total_net'=>$line->total_ht, - 'total_vat'=>$line->total_tva, - 'total'=>$line->total_ttc, - 'vat_rate'=>$line->tva_tx, - 'qty'=>$line->qty, - 'product_ref'=>$line->product_ref, - 'product_label'=>$line->product_label, - 'product_desc'=>$line->product_desc, + 'desc'=>dol_htmlcleanlastbr($line->desc), + 'total_net'=>$line->total_ht, + 'total_vat'=>$line->total_tva, + 'total'=>$line->total_ttc, + 'vat_rate'=>$line->tva_tx, + 'qty'=>$line->qty, + 'unitprice'=> $line->subprice, + 'date_start'=> $line->date_start?dol_print_date($line->date_start,'dayrfc'):'', + 'date_end'=> $line->date_end?dol_print_date($line->date_end,'dayrfc'):'', + 'product_id'=>$line->fk_product, + 'product_ref'=>$line->product_ref, + 'product_label'=>$line->product_label, + 'product_desc'=>$line->product_desc, ); $i++; } @@ -347,6 +351,7 @@ function getInvoice($authentication,$id='',$ref='',$ref_ext='') 'fk_user_author' => $invoice->user_author?$invoice->user_author:'', 'fk_user_valid' => $invoice->user_valid?$invoice->user_valid:'', 'date' => $invoice->date?dol_print_date($invoice->date,'dayrfc'):'', + 'date_due' => $invoice->date_lim_reglement?dol_print_date($invoice->date_lim_reglement,'dayrfc'):'', 'date_creation' => $invoice->date_creation?dol_print_date($invoice->date_creation,'dayhourrfc'):'', 'date_validation' => $invoice->date_validation?dol_print_date($invoice->date_creation,'dayhourrfc'):'', 'date_modification' => $invoice->datem?dol_print_date($invoice->datem,'dayhourrfc'):'', @@ -356,7 +361,8 @@ function getInvoice($authentication,$id='',$ref='',$ref_ext='') 'total' => $invoice->total_ttc, 'note_private' => $invoice->note_private?$invoice->note_private:'', 'note_public' => $invoice->note_public?$invoice->note_public:'', - 'status'=> $invoice->statut, + 'status' => $invoice->statut, + 'project_id' => $invoic->fk_project, 'close_code' => $invoice->close_code?$invoice->close_code:'', 'close_note' => $invoice->close_note?$invoice->close_note:'', 'payment_mode_id' => $invoice->mode_reglement_id?$invoice->mode_reglement_id:'', @@ -458,6 +464,10 @@ function getInvoicesForThirdParty($authentication,$idthirdparty) 'total'=>$line->total_ttc, 'vat_rate'=>$line->tva_tx, 'qty'=>$line->qty, + 'unitprice'=> $line->subprice, + 'date_start'=> $line->date_start?dol_print_date($line->date_start,'dayrfc'):'', + 'date_end'=> $line->date_end?dol_print_date($line->date_end,'dayrfc'):'', + 'product_id'=>$line->fk_product, 'product_ref'=>$line->product_ref, 'product_label'=>$line->product_label, 'product_desc'=>$line->product_desc, @@ -473,7 +483,7 @@ function getInvoicesForThirdParty($authentication,$idthirdparty) 'fk_user_valid' => $invoice->user_valid?$invoice->user_valid:'', 'date' => $invoice->date?dol_print_date($invoice->date,'dayrfc'):'', 'date_due' => $invoice->date_lim_reglement?dol_print_date($invoice->date_lim_reglement,'dayrfc'):'', - 'date_creation' => $invoice->date_creation?dol_print_date($invoice->date_creation,'dayhourrfc'):'', + 'date_creation' => $invoice->date_creation?dol_print_date($invoice->date_creation,'dayhourrfc'):'', 'date_validation' => $invoice->date_validation?dol_print_date($invoice->date_creation,'dayhourrfc'):'', 'date_modification' => $invoice->datem?dol_print_date($invoice->datem,'dayhourrfc'):'', 'type' => $invoice->type, @@ -483,6 +493,7 @@ function getInvoicesForThirdParty($authentication,$idthirdparty) 'note_private' => $invoice->note_private?$invoice->note_private:'', 'note_public' => $invoice->note_public?$invoice->note_public:'', 'status'=> $invoice->statut, + 'project_id' => $invoic->fk_project, 'close_code' => $invoice->close_code?$invoice->close_code:'', 'close_note' => $invoice->close_note?$invoice->close_note:'', 'payment_mode_id' => $invoice->mode_reglement_id?$invoice->mode_reglement_id:'', From 4fd8d6c05af1d387579ebf1abdd139ab966fddad Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Chevallier Date: Tue, 5 May 2015 21:37:10 +0200 Subject: [PATCH 11/56] fix typo --- htdocs/webservices/server_invoice.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index 195662c46f9..3cd6ec97d87 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -793,7 +793,7 @@ function updateInvoice($authentication,$invoice) $order->generateDocument($invoice->modelpdf, $outputlangs); } } - if ($invlice['status'] == 2) + if ($invoice['status'] == 2) { $result = $object->set_paid($fuser,$invoice->close_code,$invoice->close_note); } From 2db885a2b328d6847be90271fcf07c7c5d75f031 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Mon, 11 May 2015 13:51:57 +0200 Subject: [PATCH 12/56] first attempt to add test --- test/phpunit/WebservicesInvoicesTest.php | 225 ++++++++++++++++++++++- 1 file changed, 222 insertions(+), 3 deletions(-) diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php index 20e01595375..a295dbdc64e 100755 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -102,6 +102,8 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; + + // create a third_party, needed to create an invoice print __METHOD__."\n"; } @@ -118,11 +120,118 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase /** - * testWSInvoicesXxx + * testWSInvoicesCreateInvoice * * @return int */ - public function testWSInvoicesXxx() + public function testWSInvoicesCreateInvoice() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php'; + $WS_METHOD = 'createInvoice'; + $ns='http://www.dolibarr.org/ns/'; + + // Set the WebService URL + print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; + $soapclient = new nusoap_client($WS_DOL_URL); + if ($soapclient) + { + $soapclient->soap_defencoding='UTF-8'; + $soapclient->decodeUTF8(false); + } + + $body = array ( + ["id"] => NULL, + ["ref"]=> NULL, + ["ref_ext"]=> "165", + ["thirdparty_id"]=> "209", + ["fk_user_author"] => NULL, + ["fk_user_valid"] => NULL, + ["date"]=> "2015-04-19 20:16:53", + ["date_due"]=> "", + ["date_creation"]=> "", + ["date_validation"]=> "", + ["date_modification"]=> "", + ["type"]=> "", + ["total_net"]=> "36.30", + ["total_vat"]=> "6.00", + ["total"]=> "42.30", + ["payment_mode_id"]=> 50, + ["note_private"]=> "Synchronised from Prestashop", + ["note_public"]=> "", + ["status"]=> "1", + ["close_code"]=> NULL , + ["close_note"]=> NULL, + ["project_id"]=> NULL, + ["lines"] => array( + ["id"] => NULL, + ["type"]=> 0, + ["desc"]=> "Horloge Vinyle Serge", + ["vat_rate"]=> 20, + ["qty"]=> "1", + ["unitprice"]=> "30.000000", + ["total_net"]=> "30.000000", + ["total_vat"]=> "6.00", + ["total"]=> "36.000000", + ["date_start"]=> "", + ["date_end"]=> "", + ["payment_mode_id"]=> "", + ["product_id"]=> "", + ["product_ref"]=> "", + ["product_label"]=> "", + ["product_desc"]=> "" ) + ); + + // Call the WebService method and store its result in $result. + $authentication=array( + 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, + 'sourceapplication'=>'DEMO', + 'login'=>'admin', + 'password'=>'admin', + 'entity'=>''); + + // Test URL + $result=''; + $parameters = array('authentication'=>$authentication,'invoice'=>$body); + print __METHOD__." call method ".$WS_METHOD."\n"; + try { + $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); + } + catch(SoapFault $exception) + { + echo $exception; + $result=0; + } + if (! $result || ! empty($result['faultstring'])) + { + //var_dump($soapclient); + print $soapclient->error_str; + print "\n
\n"; + print $soapclient->request; + print "\n
\n"; + print $soapclient->response; + print "\n"; + } + + print __METHOD__." result=".$result."\n"; + $this->assertEquals('OK',$result['result']['result_code']); + $this->assertEquals('165', $result['ref_ext']); + + + return $result; + } + + /** + * testWSInvoicesGetInvoice + * + * @return int + */ + public function testWSInvoicesGetInvoice() { global $conf,$user,$langs,$db; $conf=$this->savconf; @@ -153,7 +262,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase // Test URL $result=''; - $parameters = array('authentication'=>$authentication,'id'=>1); + $parameters = array('authentication'=>$authentication,'id'=>NULL,'ref'=>NULL,'ref_ext'=>165); print __METHOD__." call method ".$WS_METHOD."\n"; try { $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); @@ -176,6 +285,116 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase print __METHOD__." result=".$result."\n"; $this->assertEquals('OK',$result['result']['result_code']); + $this->assertEquals('165', $result['result']['invoice']->ref_ext); + + + return $result; + } + + /** + * testWSInvoicesUpdateInvoice + * + * @return int + */ + public function testWSInvoicesUpdateInvoice() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php'; + $WS_METHOD = 'updateInvoice'; + $ns='http://www.dolibarr.org/ns/'; + + // Set the WebService URL + print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; + $soapclient = new nusoap_client($WS_DOL_URL); + if ($soapclient) + { + $soapclient->soap_defencoding='UTF-8'; + $soapclient->decodeUTF8(false); + } + + // update status to 2 + $body = array ( + ["id"] => NULL, + ["ref"]=> NULL, + ["ref_ext"]=> "165", + ["thirdparty_id"]=> "209", + ["fk_user_author"] => NULL, + ["fk_user_valid"] => NULL, + ["date"]=> "2015-04-19 20:16:53", + ["date_due"]=> "", + ["date_creation"]=> "", + ["date_validation"]=> "", + ["date_modification"]=> "", + ["type"]=> "", + ["total_net"]=> "36.30", + ["total_vat"]=> "6.00", + ["total"]=> "42.30", + ["payment_mode_id"]=> 50, + ["note_private"]=> "Synchronised from Prestashop", + ["note_public"]=> "", + ["status"]=> "2", + ["close_code"]=> NULL , + ["close_note"]=> NULL, + ["project_id"]=> NULL, + ["lines"] => array( + ["id"] => NULL, + ["type"]=> 0, + ["desc"]=> "Horloge Vinyle Serge", + ["vat_rate"]=> 20, + ["qty"]=> "1", + ["unitprice"]=> "30.000000", + ["total_net"]=> "30.000000", + ["total_vat"]=> "6.00", + ["total"]=> "36.000000", + ["date_start"]=> "", + ["date_end"]=> "", + ["payment_mode_id"]=> "", + ["product_id"]=> "", + ["product_ref"]=> "", + ["product_label"]=> "", + ["product_desc"]=> "" ) + ); + + // Call the WebService method and store its result in $result. + $authentication=array( + 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, + 'sourceapplication'=>'DEMO', + 'login'=>'admin', + 'password'=>'admin', + 'entity'=>''); + + // Test URL + $result=''; + $parameters = array('authentication'=>$authentication,'invoice'=>$body); + print __METHOD__." call method ".$WS_METHOD."\n"; + try { + $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); + } + catch(SoapFault $exception) + { + echo $exception; + $result=0; + } + if (! $result || ! empty($result['faultstring'])) + { + //var_dump($soapclient); + print $soapclient->error_str; + print "\n
\n"; + print $soapclient->request; + print "\n
\n"; + print $soapclient->response; + print "\n"; + } + + print __METHOD__." result=".$result."\n"; + $this->assertEquals('OK',$result['result']['result_code']); + $this->assertEquals('2', $result['result']['invoice']->status); + return $result; } From 278d447e45f1f7863c7c2c943411c0cc8e191116 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Wed, 27 May 2015 15:42:34 +0200 Subject: [PATCH 13/56] Use Constant for status --- htdocs/webservices/server_invoice.php | 51 ++++++++++++++------------- 1 file changed, 26 insertions(+), 25 deletions(-) diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index 336917a8c60..d358847c0b6 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -557,25 +557,25 @@ function createInvoice($authentication,$invoice) if (! $error) { - $newobject=new Facture($db); - $newobject->socid=$invoice['thirdparty_id']; - $newobject->type=$invoice['type']; - $newobject->ref_ext=$invoice['ref_ext']; - $newobject->date=dol_stringtotime($invoice['date'],'dayrfc'); - $newobject->note_private=$invoice['note_private']; - $newobject->note_public=$invoice['note_public']; - $newobject->statut= Facture::STATUS_DRAFT; // We start with status draft - $newobject->fk_project=$invoice['project_id']; - $newobject->date_creation=$now; + $new_invoice=new Facture($db); + $new_invoice->socid=$invoice['thirdparty_id']; + $new_invoice->type=$invoice['type']; + $new_invoice->ref_ext=$invoice['ref_ext']; + $new_invoice->date=dol_stringtotime($invoice['date'],'dayrfc'); + $new_invoice->note_private=$invoice['note_private']; + $new_invoice->note_public=$invoice['note_public']; + $new_invoice->statut= Facture::STATUS_DRAFT; // We start with status draft + $new_invoice->fk_project=$invoice['project_id']; + $new_invoice->date_creation=$now; //take mode_reglement and cond_reglement from thirdparty $soc = new Societe($db); - $res=$soc->fetch($newobject->socid); + $res=$soc->fetch($new_invoice->socid); if ($res > 0) { - $newobject->mode_reglement_id = ! empty($invoice['payment_mode_id'])?$invoice['payment_mode_id']:$soc->mode_reglement_id; - $newobject->cond_reglement_id = $soc->cond_reglement_id; + $new_invoice->mode_reglement_id = ! empty($invoice['payment_mode_id'])?$invoice['payment_mode_id']:$soc->mode_reglement_id; + $new_invoice->cond_reglement_id = $soc->cond_reglement_id; } - else $newobject->mode_reglement_id = $invoice['payment_mode_id']; + else $new_invoice->mode_reglement_id = $invoice['payment_mode_id']; // Trick because nusoap does not store data with same structure if there is one or several lines $arrayoflines=array(); @@ -598,22 +598,22 @@ function createInvoice($authentication,$invoice) $newline->date_start=dol_stringtotime($line['date_start']); $newline->date_end=dol_stringtotime($line['date_end']); $newline->fk_product=$line['product_id']; - $newobject->lines[]=$newline; + $new_invoice->lines[]=$newline; } //var_dump($newobject->date_lim_reglement); exit; //var_dump($invoice['lines'][0]['type']); $db->begin(); - $result=$newobject->create($fuser,0,dol_stringtotime($invoice['date_due'],'dayrfc')); + $result=$new_invoice->create($fuser,0,dol_stringtotime($invoice['date_due'],'dayrfc')); if ($result < 0) { $error++; } - if ($invoice['status'] == 1) // We want invoice to have status validated + if (!$error && $invoice['status'] == Facture::STATUS_VALIDATED) // We want invoice to have status validated { - $result=$newobject->validate($fuser); + $result=$new_invoice->validate($fuser); if ($result < 0) { $error++; @@ -623,15 +623,16 @@ function createInvoice($authentication,$invoice) if (! $error) { $db->commit(); - $objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''),'id'=>$newobject->id, - 'ref'=>$newobject->ref,'ref_ext'=>$newobject->ref_ext); + $objectresp=array('result'=>array('result_code'=>'OK', 'result_label'=>''),'id'=>$new_invoice->id, + 'ref'=>$new_invoice->ref,'ref_ext'=>$new_invoice->ref_ext); } else { $db->rollback(); $error++; $errorcode='KO'; - $errorlabel=$newobject->error; + $errorlabel=$new_invoice->error; + dol_syslog("Function: createInvoice error while creating".$errorlabel); } } @@ -781,8 +782,8 @@ function updateInvoice($authentication,$invoice) if (isset($invoice['status'])) { - if ($invoice['status'] == 0) $result=$object->set_draft($fuser); - if ($invoice['status'] == 1) + if ($invoice['status'] == Facture::STATUS_DRAFT) $result=$object->set_draft($fuser); + if ($invoice['status'] == Facture::STATUS_VALIDATED) { $result=$object->validate($fuser); @@ -793,11 +794,11 @@ function updateInvoice($authentication,$invoice) $order->generateDocument($invoice->modelpdf, $outputlangs); } } - if ($invoice['status'] == 2) + if ($invoice['status'] == Facture::STATUS_CLOSED) { $result = $object->set_paid($fuser,$invoice->close_code,$invoice->close_note); } - if ($invoice['status'] == 3) $result=$object->set_canceled($fuser,$invoice->close_code,$invoice->close_note); + if ($invoice['status'] == Facture::STATUS_ABANDONED) $result=$object->set_canceled($fuser,$invoice->close_code,$invoice->close_note); } } From 336b8c49b31637e073d8ce39f3c70437e4ae2747 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Wed, 27 May 2015 15:42:46 +0200 Subject: [PATCH 14/56] update test --- test/phpunit/WebservicesInvoicesTest.php | 190 +++++++++++++---------- 1 file changed, 106 insertions(+), 84 deletions(-) diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php index a295dbdc64e..4731c8f7651 100755 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -53,7 +53,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase protected $savuser; protected $savlangs; protected $savdb; - + /** * Constructor * We save global variables into local variables @@ -79,6 +79,23 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase { global $conf,$user,$langs,$db; $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. + + // create a third_party, needed to create an invoice + $societe=new Societe($db); + $societe->ref=''; + $societe->name='name'; + $societe->ref_ext='209'; + $societe->status=1; + $societe->client=1; + $societe->fournisseur=0; + $societe->date_creation=$now; + $societe->tva_assuj=0; + $societe->particulier=0; + + $societe->create($user); + + print __METHOD__." societe created id=".$societe->id."\n"; + print __METHOD__."\n"; } @@ -102,10 +119,9 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; - - // create a third_party, needed to create an invoice - + print __METHOD__."\n"; + } /** @@ -136,6 +152,11 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $WS_METHOD = 'createInvoice'; $ns='http://www.dolibarr.org/ns/'; + // load societe first + $societe=new Societe($db); + $societe->fetch('', '', '209'); + print __METHOD__." societe loaded id=".$societe->id."\n"; + // Set the WebService URL print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; $soapclient = new nusoap_client($WS_DOL_URL); @@ -144,48 +165,49 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $soapclient->soap_defencoding='UTF-8'; $soapclient->decodeUTF8(false); } + $body = array ( - ["id"] => NULL, - ["ref"]=> NULL, - ["ref_ext"]=> "165", - ["thirdparty_id"]=> "209", - ["fk_user_author"] => NULL, - ["fk_user_valid"] => NULL, - ["date"]=> "2015-04-19 20:16:53", - ["date_due"]=> "", - ["date_creation"]=> "", - ["date_validation"]=> "", - ["date_modification"]=> "", - ["type"]=> "", - ["total_net"]=> "36.30", - ["total_vat"]=> "6.00", - ["total"]=> "42.30", - ["payment_mode_id"]=> 50, - ["note_private"]=> "Synchronised from Prestashop", - ["note_public"]=> "", - ["status"]=> "1", - ["close_code"]=> NULL , - ["close_note"]=> NULL, - ["project_id"]=> NULL, - ["lines"] => array( - ["id"] => NULL, - ["type"]=> 0, - ["desc"]=> "Horloge Vinyle Serge", - ["vat_rate"]=> 20, - ["qty"]=> "1", - ["unitprice"]=> "30.000000", - ["total_net"]=> "30.000000", - ["total_vat"]=> "6.00", - ["total"]=> "36.000000", - ["date_start"]=> "", - ["date_end"]=> "", - ["payment_mode_id"]=> "", - ["product_id"]=> "", - ["product_ref"]=> "", - ["product_label"]=> "", - ["product_desc"]=> "" ) - ); + "id" => NULL, + "ref" => NULL, + "ref_ext" => "165", + "thirdparty_id" => $societe->id, + "fk_user_author" => NULL, + "fk_user_valid" => NULL, + "date" => "2015-04-19 20:16:53", + "date_due" => "", + "date_creation" => "", + "date_validation" => "", + "date_modification" => "", + "type" => "", + "total_net" => "36.30", + "total_vat" => "6.00", + "total" => "42.30", + "payment_mode_id" => 50, + "note_private" => "Synchronised from Prestashop", + "note_public" => "", + "status" => "1", + "close_code" => NULL , + "close_note" => NULL, + "project_id" => NULL, + "lines" => array( + "id" => NULL, + "type" => 0, + "desc" => "Horloge Vinyle Serge", + "vat_rate" => 20, + "qty" => "1", + "unitprice" => "30.000000", + "total_net" => "30.000000", + "total_vat" => "6.00", + "total" => "36.000000", + "date_start" => "", + "date_end" => "", + "payment_mode_id" => "", + "product_id" => "", + "product_ref" => "", + "product_label" => "", + "product_desc" => "" ) + ); // Call the WebService method and store its result in $result. $authentication=array( @@ -218,7 +240,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase print "\n"; } - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result['result']['result_label']."\n"; $this->assertEquals('OK',$result['result']['result_code']); $this->assertEquals('165', $result['ref_ext']); @@ -319,45 +341,45 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase // update status to 2 $body = array ( - ["id"] => NULL, - ["ref"]=> NULL, - ["ref_ext"]=> "165", - ["thirdparty_id"]=> "209", - ["fk_user_author"] => NULL, - ["fk_user_valid"] => NULL, - ["date"]=> "2015-04-19 20:16:53", - ["date_due"]=> "", - ["date_creation"]=> "", - ["date_validation"]=> "", - ["date_modification"]=> "", - ["type"]=> "", - ["total_net"]=> "36.30", - ["total_vat"]=> "6.00", - ["total"]=> "42.30", - ["payment_mode_id"]=> 50, - ["note_private"]=> "Synchronised from Prestashop", - ["note_public"]=> "", - ["status"]=> "2", - ["close_code"]=> NULL , - ["close_note"]=> NULL, - ["project_id"]=> NULL, - ["lines"] => array( - ["id"] => NULL, - ["type"]=> 0, - ["desc"]=> "Horloge Vinyle Serge", - ["vat_rate"]=> 20, - ["qty"]=> "1", - ["unitprice"]=> "30.000000", - ["total_net"]=> "30.000000", - ["total_vat"]=> "6.00", - ["total"]=> "36.000000", - ["date_start"]=> "", - ["date_end"]=> "", - ["payment_mode_id"]=> "", - ["product_id"]=> "", - ["product_ref"]=> "", - ["product_label"]=> "", - ["product_desc"]=> "" ) + "id" => NULL, + "ref" => NULL, + "ref_ext" => "165", + "thirdparty_id" => "209", + "fk_user_author" => NULL, + "fk_user_valid" => NULL, + "date" => "2015-04-19 20:16:53", + "date_due" => "", + "date_creation" => "", + "date_validation" => "", + "date_modification" => "", + "type" => "", + "total_net" => "36.30", + "total_vat" => "6.00", + "total" => "42.30", + "payment_mode_id" => 50, + "note_private" => "Synchronised from Prestashop", + "note_public" => "", + "status" => "2", + "close_code" => NULL , + "close_note" => NULL, + "project_id" => NULL, + "lines" => array( + "id" => NULL, + "type" => 0, + "desc" => "Horloge Vinyle Serge", + "vat_rate" => 20, + "qty" => "1", + "unitprice" => "30.000000", + "total_net" => "30.000000", + "total_vat" => "6.00", + "total" => "36.000000", + "date_start" => "", + "date_end" => "", + "payment_mode_id" => "", + "product_id" => "", + "product_ref" => "", + "product_label" => "", + "product_desc" => "" ) ); // Call the WebService method and store its result in $result. From 33d5299a22dfd7506899d6648ae29bf810f3701c Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Thu, 28 May 2015 15:40:38 +0200 Subject: [PATCH 15/56] add deleteThirdParty api call + add tests --- test/phpunit/WebservicesThirdpartyTest.php | 258 +++++++++++++++++++-- 1 file changed, 237 insertions(+), 21 deletions(-) diff --git a/test/phpunit/WebservicesThirdpartyTest.php b/test/phpunit/WebservicesThirdpartyTest.php index 0c99d7d362a..71c90b3f636 100755 --- a/test/phpunit/WebservicesThirdpartyTest.php +++ b/test/phpunit/WebservicesThirdpartyTest.php @@ -52,6 +52,13 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase protected $savuser; protected $savlangs; protected $savdb; + protected $soapclient; + + private $WS_DOL_URL; + private $ns='http://www.dolibarr.org/ns/'; + + + /** * Constructor @@ -67,6 +74,16 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase $this->savuser=$user; $this->savlangs=$langs; $this->savdb=$db; + + $this->WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php'; + + // Set the WebService URL + print __METHOD__." create nusoap_client for URL=".$this->WS_DOL_URL."\n"; + $this->soapclient = new nusoap_client($this->WS_DOL_URL); + if ($this->soapclient) { + $this->soapclient->soap_defencoding='UTF-8'; + $this->soapclient->decodeUTF8(false); + } print __METHOD__." db->type=".$db->type." user->id=".$user->id; //print " - db ".$db->db; @@ -117,31 +134,113 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase print __METHOD__."\n"; } - /** - * testWSThirdpartygetThirdParty + * testWSThirdpartycreateThirdParty * * @return int */ - public function testWSThirdpartygetThirdParty() + public function testWSThirdpartycreateThirdParty() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $WS_METHOD = 'createThirdParty'; + + + // Call the WebService method and store its result in $result. + $authentication=array( + 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, + 'sourceapplication'=>'DEMO', + 'login'=>'admin', + 'password'=>'admin', + 'entity'=>''); + + $body = array ( + "id" => NULL, + "ref" => "name", + "ref_ext" => "12", + "fk_user_author" => NULL, + "status" => NULL, + "client" => 1, + "supplier" => 0, + "customer_code" => "", + "supplier_code" => "", + "customer_code_accountancy" => "", + "supplier_code_accountancy" => "", + "date_creation" => "", // dateTime + "date_modification" => "", // dateTime + "note_private" => "", + "note_public" => "", + "address" => "", + "zip" => "", + "town" => "", + "province_id" => "", + "country_id" => "", + "country_code" => "", + "country" => "", + "phone" => "", + "fax" => "", + "email" => "", + "url" => "", + "profid1" => "", + "profid2" => "", + "profid3" => "", + "profid4" => "", + "profid5" => "", + "profid6" => "", + "capital" => "", + "vat_used" => "", + "vat_number" => "" + ); + + // Test URL + $result=''; + $parameters = array('authentication'=>$authentication, 'thirdparty'=>$body); + print __METHOD__." call method ".$WS_METHOD."\n"; + try { + $result = $this->soapclient->call($WS_METHOD,$parameters,$thid->ns,''); + } catch(SoapFault $exception) { + echo $exception; + $result=0; + } + if (! $result || ! empty($result['faultstring'])) { + //var_dump($soapclient); + print $this->soapclient->error_str; + print "\n
\n"; + print $this->soapclient->request; + print "\n
\n"; + print $this->soapclient->response; + print "\n"; + } + + print __METHOD__." result=".$result['result']['result_code']."\n"; + $this->assertEquals('OK',$result['result']['result_code']); + $this->assertEquals('name',$result['ref']); + + return $result; + } + + /** + * testWSThirdpartygetThirdPartyById + * + * Use id to retrieve thirdparty + * @depends testWSThirdpartycreateThirdParty + * + * @return int + */ + public function testWSThirdpartygetThirdPartyById($result) { global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; + $id = $result['id']; - $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php'; $WS_METHOD = 'getThirdParty'; - $ns='http://www.dolibarr.org/ns/'; - - // Set the WebService URL - print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; - $soapclient = new nusoap_client($WS_DOL_URL); - if ($soapclient) { - $soapclient->soap_defencoding='UTF-8'; - $soapclient->decodeUTF8(false); - } // Call the WebService method and store its result in $result. $authentication=array( @@ -151,30 +250,147 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase 'password'=>'admin', 'entity'=>''); - // Test URL $result=''; - $parameters = array('authentication'=>$authentication, 'id'=>1); + $parameters = array('authentication'=>$authentication, 'id'=>$id); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); } catch(SoapFault $exception) { echo $exception; $result=0; } if (! $result || ! empty($result['faultstring'])) { //var_dump($soapclient); - print $soapclient->error_str; + print $this->soapclient->error_str; print "\n
\n"; - print $soapclient->request; + print $this->soapclient->request; print "\n
\n"; - print $soapclient->response; + print $this->soapclient->response; print "\n"; } - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result['result']['result_code']."\n"; $this->assertEquals('OK',$result['result']['result_code']); - + $this->assertEquals($id, $result['thirdparty']['id']); + $this->assertEquals('name', $result['thirdparty']['ref']); + $this->assertEquals('12', $result['thirdparty']['ref_ext']); + $this->assertEquals('0', $result['thirdparty']['status']); + $this->assertEquals('1', $result['thirdparty']['client']); + $this->assertEquals('0', $result['thirdparty']['supplier']); + + return $result; } + + /** + * testWSThirdpartygetThirdPartyByRefExt + * + * Use ref_ext to retrieve thirdparty + * + * @depends testWSThirdpartycreateThirdParty + * @return int + */ + public function testWSThirdpartygetThirdPartyByRefExt($result) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + $id = $result['id']; + + $WS_METHOD = 'getThirdParty'; + + // Call the WebService method and store its result in $result. + $authentication=array( + 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, + 'sourceapplication'=>'DEMO', + 'login'=>'admin', + 'password'=>'admin', + 'entity'=>''); + + // Test URL + $result=''; + $parameters = array('authentication'=>$authentication, 'id'=>'', 'ref'=>'', 'ref_ext'=>'12'); + print __METHOD__." call method ".$WS_METHOD."\n"; + try { + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); + } catch(SoapFault $exception) { + echo $exception; + $result=0; + } + print $this->soapclient->response; + if (! $result || ! empty($result['faultstring'])) { + //var_dump($soapclient); + print $this->soapclient->error_str; + print "\n
\n"; + print $this->soapclient->request; + print "\n
\n"; + print $this->soapclient->response; + print "\n"; + } + + print __METHOD__." result=".$result['result']['result_code']."\n"; + $this->assertEquals('OK',$result['result']['result_code']); + $this->assertEquals($id, $result['thirdparty']['id']); + $this->assertEquals('name', $result['thirdparty']['ref']); + $this->assertEquals('12', $result['thirdparty']['ref_ext']); + $this->assertEquals('0', $result['thirdparty']['status']); + $this->assertEquals('1', $result['thirdparty']['client']); + $this->assertEquals('0', $result['thirdparty']['supplier']); + + + return $result; + } + + /** + * testWSThirdpartydeleteThirdParty + * + * @depends testWSThirdpartycreateThirdParty + * + * @return int + */ + public function testWSThirdpartydeleteThirdPartyById($result) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + $id = $result['id']; + + $WS_METHOD = 'deleteThirdParty'; + + // Call the WebService method and store its result in $result. + $authentication=array( + 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, + 'sourceapplication'=>'DEMO', + 'login'=>'admin', + 'password'=>'admin', + 'entity'=>''); + + $result=''; + $parameters = array('authentication'=>$authentication, 'id'=>$id, 'ref'=>'', 'ref_ext'=>''); + print __METHOD__." call method ".$WS_METHOD."\n"; + try { + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); + } catch(SoapFault $exception) { + echo $exception; + $result=0; + } + //if (! $result || ! empty($result['faultstring'])) { + print $this->soapclient->error_str; + print "\n
\n"; + print $this->soapclient->request; + print "\n
\n"; + print $this->soapclient->response; + print "\n"; + //} + + print __METHOD__." result=".$result['result']['result_code']."\n"; + $this->assertEquals('OK',$result['result']['result_code']); + + return $result; + } } From 05a7ab158b51a05dbb38ac7b02abf0d2c1df9891 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Thu, 28 May 2015 15:40:38 +0200 Subject: [PATCH 16/56] add deleteThirdParty api call + add tests --- htdocs/webservices/server_thirdparty.php | 106 +++++++++ test/phpunit/WebservicesThirdpartyTest.php | 258 +++++++++++++++++++-- 2 files changed, 343 insertions(+), 21 deletions(-) diff --git a/htdocs/webservices/server_thirdparty.php b/htdocs/webservices/server_thirdparty.php index c7ca5911d62..542e2980c45 100644 --- a/htdocs/webservices/server_thirdparty.php +++ b/htdocs/webservices/server_thirdparty.php @@ -258,8 +258,31 @@ $server->register( 'WS to get list of thirdparties id and ref' ); +// Register WSDL +$server->register( + 'deleteThirdParty', + // Entry values + array('authentication'=>'tns:authentication','id'=>'xsd:string','ref'=>'xsd:string','ref_ext'=>'xsd:string'), + // Exit values + array('result'=>'tns:result','id'=>'xsd:string'), + $ns, + $ns.'#deleteThirdParty', + $styledoc, + $styleuse, + 'WS to delete a thirdparty from its id, ref or ref_ext' +); + // Full methods code +/** + * Get a thirdparty + * + * @param array $authentication Array of authentication information + * @param string $id internal id + * @param string $ref internal reference + * @param string $ref_ext external reference + * @return array Array result + */ function getThirdParty($authentication,$id='',$ref='',$ref_ext='') { global $db,$conf,$langs; @@ -728,5 +751,88 @@ function getListOfThirdParties($authentication,$filterthirdparty) return $objectresp; } +/** + * Delete a thirdparty + * + * @param array $authentication Array of authentication information + * @param string $id internal id + * @param string $ref internal reference + * @param string $ref_ext external reference + * @return array Array result + */ +function deleteThirdParty($authentication,$id='',$ref='',$ref_ext='') +{ + global $db,$conf,$langs; + + dol_syslog("Function: deleteThirdParty login=".$authentication['login']." id=".$id." ref=".$ref." ref_ext=".$ref_ext); + + if ($authentication['entity']) $conf->entity=$authentication['entity']; + + // Init and check authentication + $objectresp=array(); + $errorcode='';$errorlabel=''; + $error=0; + $fuser=check_authentication($authentication,$error,$errorcode,$errorlabel); + // Check parameters + if (! $error && (($id && $ref) || ($id && $ref_ext) || ($ref && $ref_ext))) + { + dol_syslog("Function: deleteThirdParty checkparam"); + $error++; + $errorcode='BAD_PARAMETERS'; $errorlabel="Parameter id, ref and ref_ext can't be both provided. You must choose one or other but not both."; + } + dol_syslog("Function: deleteThirdParty 1"); + + if (! $error) + { + $fuser->getrights(); + + if ($fuser->rights->societe->lire && $fuser->rights->societe->supprimer) + { + $thirdparty=new Societe($db); + $result=$thirdparty->fetch($id,$ref,$ref_ext); + + if ($result > 0) + { + $db->begin(); + + $result=$thirdparty->delete($thirdparty->id, $fuser); + + if ($result > 0) + { + $db->commit(); + + $objectresp = array('result'=>array('result_code'=>'OK', 'result_label'=>'')); + } + else + { + $db->rollback(); + $error++; + $errorcode='KO'; + $errorlabel=$thirdparty->error; + dol_syslog("Function: deleteThirdParty cant delete"); + } + } + else + { + $error++; + $errorcode='NOT_FOUND'; $errorlabel='Object not found for id='.$id.' nor ref='.$ref.' nor ref_ext='.$ref_ext; + + } + } + else + { + $error++; + $errorcode='PERMISSION_DENIED'; $errorlabel='User does not have permission for this request'; + } + } + + if ($error) + { + $objectresp = array('result'=>array('result_code' => $errorcode, 'result_label' => $errorlabel)); + } + + return $objectresp; +} + // Return the results. $server->service(file_get_contents("php://input")); diff --git a/test/phpunit/WebservicesThirdpartyTest.php b/test/phpunit/WebservicesThirdpartyTest.php index 0c99d7d362a..71c90b3f636 100755 --- a/test/phpunit/WebservicesThirdpartyTest.php +++ b/test/phpunit/WebservicesThirdpartyTest.php @@ -52,6 +52,13 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase protected $savuser; protected $savlangs; protected $savdb; + protected $soapclient; + + private $WS_DOL_URL; + private $ns='http://www.dolibarr.org/ns/'; + + + /** * Constructor @@ -67,6 +74,16 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase $this->savuser=$user; $this->savlangs=$langs; $this->savdb=$db; + + $this->WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php'; + + // Set the WebService URL + print __METHOD__." create nusoap_client for URL=".$this->WS_DOL_URL."\n"; + $this->soapclient = new nusoap_client($this->WS_DOL_URL); + if ($this->soapclient) { + $this->soapclient->soap_defencoding='UTF-8'; + $this->soapclient->decodeUTF8(false); + } print __METHOD__." db->type=".$db->type." user->id=".$user->id; //print " - db ".$db->db; @@ -117,31 +134,113 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase print __METHOD__."\n"; } - /** - * testWSThirdpartygetThirdParty + * testWSThirdpartycreateThirdParty * * @return int */ - public function testWSThirdpartygetThirdParty() + public function testWSThirdpartycreateThirdParty() + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + + $WS_METHOD = 'createThirdParty'; + + + // Call the WebService method and store its result in $result. + $authentication=array( + 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, + 'sourceapplication'=>'DEMO', + 'login'=>'admin', + 'password'=>'admin', + 'entity'=>''); + + $body = array ( + "id" => NULL, + "ref" => "name", + "ref_ext" => "12", + "fk_user_author" => NULL, + "status" => NULL, + "client" => 1, + "supplier" => 0, + "customer_code" => "", + "supplier_code" => "", + "customer_code_accountancy" => "", + "supplier_code_accountancy" => "", + "date_creation" => "", // dateTime + "date_modification" => "", // dateTime + "note_private" => "", + "note_public" => "", + "address" => "", + "zip" => "", + "town" => "", + "province_id" => "", + "country_id" => "", + "country_code" => "", + "country" => "", + "phone" => "", + "fax" => "", + "email" => "", + "url" => "", + "profid1" => "", + "profid2" => "", + "profid3" => "", + "profid4" => "", + "profid5" => "", + "profid6" => "", + "capital" => "", + "vat_used" => "", + "vat_number" => "" + ); + + // Test URL + $result=''; + $parameters = array('authentication'=>$authentication, 'thirdparty'=>$body); + print __METHOD__." call method ".$WS_METHOD."\n"; + try { + $result = $this->soapclient->call($WS_METHOD,$parameters,$thid->ns,''); + } catch(SoapFault $exception) { + echo $exception; + $result=0; + } + if (! $result || ! empty($result['faultstring'])) { + //var_dump($soapclient); + print $this->soapclient->error_str; + print "\n
\n"; + print $this->soapclient->request; + print "\n
\n"; + print $this->soapclient->response; + print "\n"; + } + + print __METHOD__." result=".$result['result']['result_code']."\n"; + $this->assertEquals('OK',$result['result']['result_code']); + $this->assertEquals('name',$result['ref']); + + return $result; + } + + /** + * testWSThirdpartygetThirdPartyById + * + * Use id to retrieve thirdparty + * @depends testWSThirdpartycreateThirdParty + * + * @return int + */ + public function testWSThirdpartygetThirdPartyById($result) { global $conf,$user,$langs,$db; $conf=$this->savconf; $user=$this->savuser; $langs=$this->savlangs; $db=$this->savdb; + $id = $result['id']; - $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php'; $WS_METHOD = 'getThirdParty'; - $ns='http://www.dolibarr.org/ns/'; - - // Set the WebService URL - print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; - $soapclient = new nusoap_client($WS_DOL_URL); - if ($soapclient) { - $soapclient->soap_defencoding='UTF-8'; - $soapclient->decodeUTF8(false); - } // Call the WebService method and store its result in $result. $authentication=array( @@ -151,30 +250,147 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase 'password'=>'admin', 'entity'=>''); - // Test URL $result=''; - $parameters = array('authentication'=>$authentication, 'id'=>1); + $parameters = array('authentication'=>$authentication, 'id'=>$id); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); } catch(SoapFault $exception) { echo $exception; $result=0; } if (! $result || ! empty($result['faultstring'])) { //var_dump($soapclient); - print $soapclient->error_str; + print $this->soapclient->error_str; print "\n
\n"; - print $soapclient->request; + print $this->soapclient->request; print "\n
\n"; - print $soapclient->response; + print $this->soapclient->response; print "\n"; } - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result['result']['result_code']."\n"; $this->assertEquals('OK',$result['result']['result_code']); - + $this->assertEquals($id, $result['thirdparty']['id']); + $this->assertEquals('name', $result['thirdparty']['ref']); + $this->assertEquals('12', $result['thirdparty']['ref_ext']); + $this->assertEquals('0', $result['thirdparty']['status']); + $this->assertEquals('1', $result['thirdparty']['client']); + $this->assertEquals('0', $result['thirdparty']['supplier']); + + return $result; } + + /** + * testWSThirdpartygetThirdPartyByRefExt + * + * Use ref_ext to retrieve thirdparty + * + * @depends testWSThirdpartycreateThirdParty + * @return int + */ + public function testWSThirdpartygetThirdPartyByRefExt($result) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + $id = $result['id']; + + $WS_METHOD = 'getThirdParty'; + + // Call the WebService method and store its result in $result. + $authentication=array( + 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, + 'sourceapplication'=>'DEMO', + 'login'=>'admin', + 'password'=>'admin', + 'entity'=>''); + + // Test URL + $result=''; + $parameters = array('authentication'=>$authentication, 'id'=>'', 'ref'=>'', 'ref_ext'=>'12'); + print __METHOD__." call method ".$WS_METHOD."\n"; + try { + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); + } catch(SoapFault $exception) { + echo $exception; + $result=0; + } + print $this->soapclient->response; + if (! $result || ! empty($result['faultstring'])) { + //var_dump($soapclient); + print $this->soapclient->error_str; + print "\n
\n"; + print $this->soapclient->request; + print "\n
\n"; + print $this->soapclient->response; + print "\n"; + } + + print __METHOD__." result=".$result['result']['result_code']."\n"; + $this->assertEquals('OK',$result['result']['result_code']); + $this->assertEquals($id, $result['thirdparty']['id']); + $this->assertEquals('name', $result['thirdparty']['ref']); + $this->assertEquals('12', $result['thirdparty']['ref_ext']); + $this->assertEquals('0', $result['thirdparty']['status']); + $this->assertEquals('1', $result['thirdparty']['client']); + $this->assertEquals('0', $result['thirdparty']['supplier']); + + + return $result; + } + + /** + * testWSThirdpartydeleteThirdParty + * + * @depends testWSThirdpartycreateThirdParty + * + * @return int + */ + public function testWSThirdpartydeleteThirdPartyById($result) + { + global $conf,$user,$langs,$db; + $conf=$this->savconf; + $user=$this->savuser; + $langs=$this->savlangs; + $db=$this->savdb; + $id = $result['id']; + + $WS_METHOD = 'deleteThirdParty'; + + // Call the WebService method and store its result in $result. + $authentication=array( + 'dolibarrkey'=>$conf->global->WEBSERVICES_KEY, + 'sourceapplication'=>'DEMO', + 'login'=>'admin', + 'password'=>'admin', + 'entity'=>''); + + $result=''; + $parameters = array('authentication'=>$authentication, 'id'=>$id, 'ref'=>'', 'ref_ext'=>''); + print __METHOD__." call method ".$WS_METHOD."\n"; + try { + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); + } catch(SoapFault $exception) { + echo $exception; + $result=0; + } + //if (! $result || ! empty($result['faultstring'])) { + print $this->soapclient->error_str; + print "\n
\n"; + print $this->soapclient->request; + print "\n
\n"; + print $this->soapclient->response; + print "\n"; + //} + + print __METHOD__." result=".$result['result']['result_code']."\n"; + $this->assertEquals('OK',$result['result']['result_code']); + + return $result; + } } From 3003b41a88c6ba4853646a63484280caeb6a3df7 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Thu, 28 May 2015 16:57:28 +0200 Subject: [PATCH 17/56] add test for invoices API --- htdocs/webservices/server_invoice.php | 14 +- test/phpunit/WebservicesInvoicesTest.php | 212 +++++++++++------------ 2 files changed, 108 insertions(+), 118 deletions(-) diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index d358847c0b6..4a495607a29 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -751,8 +751,8 @@ function updateInvoice($authentication,$invoice) { global $db,$conf,$langs; - dol_syslog("Function: updateInvoice login=".$authentication['login']." id=".$invoice->id. - ", ref=".$invoice->ref.", ref_ext=".$invoice->ref_ext); + dol_syslog("Function: updateInvoice login=".$authentication['login']." id=".$invoice['id']. + ", ref=".$invoice['ref'].", ref_ext=".$invoice['ref_ext']); if ($authentication['entity']) $conf->entity=$authentication['entity']; @@ -782,10 +782,13 @@ function updateInvoice($authentication,$invoice) if (isset($invoice['status'])) { - if ($invoice['status'] == Facture::STATUS_DRAFT) $result=$object->set_draft($fuser); + if ($invoice['status'] == Facture::STATUS_DRAFT) + { + $result = $object->set_draft($fuser); + } if ($invoice['status'] == Facture::STATUS_VALIDATED) { - $result=$object->validate($fuser); + $result = $object->validate($fuser); if ($result >= 0) { @@ -798,7 +801,8 @@ function updateInvoice($authentication,$invoice) { $result = $object->set_paid($fuser,$invoice->close_code,$invoice->close_note); } - if ($invoice['status'] == Facture::STATUS_ABANDONED) $result=$object->set_canceled($fuser,$invoice->close_code,$invoice->close_note); + if ($invoice['status'] == Facture::STATUS_ABANDONED) + $result = $object->set_canceled($fuser,$invoice->close_code,$invoice->close_note); } } diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php index 4731c8f7651..bbcf6d0b136 100755 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -53,6 +53,10 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase protected $savuser; protected $savlangs; protected $savdb; + protected $soapclient; + protected $socid; + + protected $ns = 'http://www.dolibarr.org/ns/'; /** * Constructor @@ -68,17 +72,17 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $this->savuser=$user; $this->savlangs=$langs; $this->savdb=$db; - - print __METHOD__." db->type=".$db->type." user->id=".$user->id; - //print " - db ".$db->db; - print "\n"; - } - - // Static methods - public static function setUpBeforeClass() - { - global $conf,$user,$langs,$db; - $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. + $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php'; + + + // Set the WebService URL + print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; + $this->soapclient = new nusoap_client($WS_DOL_URL); + if ($this->soapclient) + { + $this->soapclient->soap_defencoding='UTF-8'; + $this->soapclient->decodeUTF8(false); + } // create a third_party, needed to create an invoice $societe=new Societe($db); @@ -94,8 +98,20 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $societe->create($user); - print __METHOD__." societe created id=".$societe->id."\n"; + $this->socid = $societe->id; + print __METHOD__." societe created id=".$societe->id."\n"; + + print __METHOD__." db->type=".$db->type." user->id=".$user->id; + //print " - db ".$db->db; + print "\n"; + } + + // Static methods + public static function setUpBeforeClass() + { + global $conf,$user,$langs,$db; + $db->begin(); // This is to have all actions inside a transaction even if test launched without suite. print __METHOD__."\n"; } @@ -148,23 +164,12 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $langs=$this->savlangs; $db=$this->savdb; - $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php'; $WS_METHOD = 'createInvoice'; - $ns='http://www.dolibarr.org/ns/'; // load societe first $societe=new Societe($db); $societe->fetch('', '', '209'); print __METHOD__." societe loaded id=".$societe->id."\n"; - - // Set the WebService URL - print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; - $soapclient = new nusoap_client($WS_DOL_URL); - if ($soapclient) - { - $soapclient->soap_defencoding='UTF-8'; - $soapclient->decodeUTF8(false); - } $body = array ( @@ -191,11 +196,11 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase "close_note" => NULL, "project_id" => NULL, "lines" => array( - "id" => NULL, + array("id" => NULL, "type" => 0, "desc" => "Horloge Vinyle Serge", "vat_rate" => 20, - "qty" => "1", + "qty" => 1, "unitprice" => "30.000000", "total_net" => "30.000000", "total_vat" => "6.00", @@ -206,7 +211,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase "product_id" => "", "product_ref" => "", "product_label" => "", - "product_desc" => "" ) + "product_desc" => "" )) ); // Call the WebService method and store its result in $result. @@ -222,7 +227,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $parameters = array('authentication'=>$authentication,'invoice'=>$body); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); } catch(SoapFault $exception) { @@ -232,15 +237,15 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase if (! $result || ! empty($result['faultstring'])) { //var_dump($soapclient); - print $soapclient->error_str; + print $this->soapclient->error_str; print "\n
\n"; - print $soapclient->request; + print $this->soapclient->request; print "\n
\n"; - print $soapclient->response; + print $this->soapclient->response; print "\n"; } - print __METHOD__." result=".$result['result']['result_label']."\n"; + print __METHOD__." result=".$result['result']['result_code']."\n"; $this->assertEquals('OK',$result['result']['result_code']); $this->assertEquals('165', $result['ref_ext']); @@ -249,11 +254,13 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase } /** - * testWSInvoicesGetInvoice - * + * testWSInvoicesGetInvoiceByRefExt + * + * Retrieve an invoice using ref_ext + * @depends testWSInvoicesCreateInvoice * @return int */ - public function testWSInvoicesGetInvoice() + public function testWSInvoicesGetInvoiceByRefExt($result) { global $conf,$user,$langs,$db; $conf=$this->savconf; @@ -261,18 +268,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $langs=$this->savlangs; $db=$this->savdb; - $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php'; $WS_METHOD = 'getInvoice'; - $ns='http://www.dolibarr.org/ns/'; - - // Set the WebService URL - print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; - $soapclient = new nusoap_client($WS_DOL_URL); - if ($soapclient) - { - $soapclient->soap_defencoding='UTF-8'; - $soapclient->decodeUTF8(false); - } // Call the WebService method and store its result in $result. $authentication=array( @@ -287,7 +283,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $parameters = array('authentication'=>$authentication,'id'=>NULL,'ref'=>NULL,'ref_ext'=>165); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); } catch(SoapFault $exception) { @@ -296,29 +292,30 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase } if (! $result || ! empty($result['faultstring'])) { - //var_dump($soapclient); - print $soapclient->error_str; + print $this->soapclient->error_str; print "\n
\n"; - print $soapclient->request; + print $this->soapclient->request; print "\n
\n"; - print $soapclient->response; + print $this->soapclient->response; print "\n"; } - - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result['result']['result_code']."\n"; $this->assertEquals('OK',$result['result']['result_code']); - $this->assertEquals('165', $result['result']['invoice']->ref_ext); + $this->assertEquals('165', $result['invoice']['ref_ext']); return $result; } /** - * testWSInvoicesUpdateInvoice + * testWSInvoicesUpdateInvoiceByRefExt + * + * Update an invoice using ref_ext + * @depends testWSInvoicesCreateInvoice * * @return int */ - public function testWSInvoicesUpdateInvoice() + public function testWSInvoicesUpdateInvoiceByRefExt($result) { global $conf,$user,$langs,$db; $conf=$this->savconf; @@ -326,61 +323,51 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $langs=$this->savlangs; $db=$this->savdb; - $WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_invoice.php'; $WS_METHOD = 'updateInvoice'; - $ns='http://www.dolibarr.org/ns/'; - // Set the WebService URL - print __METHOD__." create nusoap_client for URL=".$WS_DOL_URL."\n"; - $soapclient = new nusoap_client($WS_DOL_URL); - if ($soapclient) - { - $soapclient->soap_defencoding='UTF-8'; - $soapclient->decodeUTF8(false); - } - // update status to 2 - $body = array ( - "id" => NULL, - "ref" => NULL, - "ref_ext" => "165", - "thirdparty_id" => "209", - "fk_user_author" => NULL, - "fk_user_valid" => NULL, - "date" => "2015-04-19 20:16:53", - "date_due" => "", - "date_creation" => "", - "date_validation" => "", - "date_modification" => "", - "type" => "", - "total_net" => "36.30", + $body = array ( + "id" => NULL, + "ref" => NULL, + "ref_ext" => "165", + "thirdparty_id" => "209", + "fk_user_author" => NULL, + "fk_user_valid" => NULL, + "date" => "2015-04-19 20:16:53", + "date_due" => "", + "date_creation" => "", + "date_validation" => "", + "date_modification" => "", + "type" => "", + "total_net" => "36.30", + "total_vat" => "6.00", + "total" => "42.30", + "payment_mode_id" => 50, + "note_private" => "Synchronised from Prestashop", + "note_public" => "", + "status" => "2", + "close_code" => NULL , + "close_note" => NULL, + "project_id" => NULL, + "lines" => array( + array( + "id" => NULL, + "type" => 0, + "desc" => "Horloge Vinyle Serge", + "vat_rate" => 20, + "qty" => "1", + "unitprice" => "30.000000", + "total_net" => "30.000000", "total_vat" => "6.00", - "total" => "42.30", - "payment_mode_id" => 50, - "note_private" => "Synchronised from Prestashop", - "note_public" => "", - "status" => "2", - "close_code" => NULL , - "close_note" => NULL, - "project_id" => NULL, - "lines" => array( - "id" => NULL, - "type" => 0, - "desc" => "Horloge Vinyle Serge", - "vat_rate" => 20, - "qty" => "1", - "unitprice" => "30.000000", - "total_net" => "30.000000", - "total_vat" => "6.00", - "total" => "36.000000", - "date_start" => "", - "date_end" => "", - "payment_mode_id" => "", - "product_id" => "", - "product_ref" => "", - "product_label" => "", - "product_desc" => "" ) - ); + "total" => "36.000000", + "date_start" => "", + "date_end" => "", + "payment_mode_id" => "", + "product_id" => "", + "product_ref" => "", + "product_label" => "", + "product_desc" => "" )) + ); // Call the WebService method and store its result in $result. $authentication=array( @@ -395,7 +382,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase $parameters = array('authentication'=>$authentication,'invoice'=>$body); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $soapclient->call($WS_METHOD,$parameters,$ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); } catch(SoapFault $exception) { @@ -404,18 +391,17 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase } if (! $result || ! empty($result['faultstring'])) { - //var_dump($soapclient); - print $soapclient->error_str; + print $this->soapclient->error_str; print "\n
\n"; - print $soapclient->request; + print $this->soapclient->request; print "\n
\n"; - print $soapclient->response; + print $this->soapclient->response; print "\n"; } - print __METHOD__." result=".$result."\n"; + print __METHOD__." result=".$result['result']['result_code'].$result['result']['result_label']."\n"; $this->assertEquals('OK',$result['result']['result_code']); - $this->assertEquals('2', $result['result']['invoice']->status); + $this->assertEquals('165', $result['ref_ext']); return $result; From 0c66c9745e4c52ad0c7e6b5dd0930639ac7e4dec Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Mon, 1 Jun 2015 13:04:33 +0200 Subject: [PATCH 18/56] fix travis error --- test/phpunit/WebservicesInvoicesTest.php | 4 ++-- test/phpunit/WebservicesThirdpartyTest.php | 24 +++++++++++----------- 2 files changed, 14 insertions(+), 14 deletions(-) diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php index bbcf6d0b136..12d5ae2011c 100755 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -258,7 +258,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase * * Retrieve an invoice using ref_ext * @depends testWSInvoicesCreateInvoice - * @return int + * @return array Invoice */ public function testWSInvoicesGetInvoiceByRefExt($result) { @@ -313,7 +313,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase * Update an invoice using ref_ext * @depends testWSInvoicesCreateInvoice * - * @return int + * @return array Invoice */ public function testWSInvoicesUpdateInvoiceByRefExt($result) { diff --git a/test/phpunit/WebservicesThirdpartyTest.php b/test/phpunit/WebservicesThirdpartyTest.php index 71c90b3f636..6ae126b7e70 100755 --- a/test/phpunit/WebservicesThirdpartyTest.php +++ b/test/phpunit/WebservicesThirdpartyTest.php @@ -54,8 +54,8 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase protected $savdb; protected $soapclient; - private $WS_DOL_URL; - private $ns='http://www.dolibarr.org/ns/'; + private $_WS_DOL_URL; + private $_ns='http://www.dolibarr.org/ns/'; @@ -75,11 +75,11 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase $this->savlangs=$langs; $this->savdb=$db; - $this->WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php'; + $this->_WS_DOL_URL = DOL_MAIN_URL_ROOT.'/webservices/server_thirdparty.php'; // Set the WebService URL - print __METHOD__." create nusoap_client for URL=".$this->WS_DOL_URL."\n"; - $this->soapclient = new nusoap_client($this->WS_DOL_URL); + print __METHOD__." create nusoap_client for URL=".$this->_WS_DOL_URL."\n"; + $this->soapclient = new nusoap_client($this->_WS_DOL_URL); if ($this->soapclient) { $this->soapclient->soap_defencoding='UTF-8'; $this->soapclient->decodeUTF8(false); @@ -137,7 +137,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase /** * testWSThirdpartycreateThirdParty * - * @return int + * @return array thirdparty created */ public function testWSThirdpartycreateThirdParty() { @@ -229,7 +229,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * Use id to retrieve thirdparty * @depends testWSThirdpartycreateThirdParty * - * @return int + * @return array thirpdarty updated */ public function testWSThirdpartygetThirdPartyById($result) { @@ -254,7 +254,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase $parameters = array('authentication'=>$authentication, 'id'=>$id); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->_ns,''); } catch(SoapFault $exception) { echo $exception; $result=0; @@ -288,7 +288,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * Use ref_ext to retrieve thirdparty * * @depends testWSThirdpartycreateThirdParty - * @return int + * @return array thirdparty */ public function testWSThirdpartygetThirdPartyByRefExt($result) { @@ -314,7 +314,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase $parameters = array('authentication'=>$authentication, 'id'=>'', 'ref'=>'', 'ref_ext'=>'12'); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->_ns,''); } catch(SoapFault $exception) { echo $exception; $result=0; @@ -348,7 +348,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * * @depends testWSThirdpartycreateThirdParty * - * @return int + * @return array thirdparty */ public function testWSThirdpartydeleteThirdPartyById($result) { @@ -373,7 +373,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase $parameters = array('authentication'=>$authentication, 'id'=>$id, 'ref'=>'', 'ref_ext'=>''); print __METHOD__." call method ".$WS_METHOD."\n"; try { - $result = $this->soapclient->call($WS_METHOD,$parameters,$this->ns,''); + $result = $this->soapclient->call($WS_METHOD,$parameters,$this->_ns,''); } catch(SoapFault $exception) { echo $exception; $result=0; From 3099e2acc4168f37d46c0b04b6906b90f559a2fe Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Mon, 1 Jun 2015 14:15:09 +0200 Subject: [PATCH 19/56] fix travis issues again --- test/phpunit/WebservicesInvoicesTest.php | 5 ++++- test/phpunit/WebservicesThirdpartyTest.php | 6 +++++- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php index 12d5ae2011c..ff8a9a30e73 100755 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -258,6 +258,8 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase * * Retrieve an invoice using ref_ext * @depends testWSInvoicesCreateInvoice + * + * @param result invoice created by create method * @return array Invoice */ public function testWSInvoicesGetInvoiceByRefExt($result) @@ -312,7 +314,8 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase * * Update an invoice using ref_ext * @depends testWSInvoicesCreateInvoice - * + * + * @param result invoice created by create method * @return array Invoice */ public function testWSInvoicesUpdateInvoiceByRefExt($result) diff --git a/test/phpunit/WebservicesThirdpartyTest.php b/test/phpunit/WebservicesThirdpartyTest.php index 6ae126b7e70..2bf3f3fe094 100755 --- a/test/phpunit/WebservicesThirdpartyTest.php +++ b/test/phpunit/WebservicesThirdpartyTest.php @@ -228,7 +228,8 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * * Use id to retrieve thirdparty * @depends testWSThirdpartycreateThirdParty - * + * + * @param result thirdparty created by create method * @return array thirpdarty updated */ public function testWSThirdpartygetThirdPartyById($result) @@ -288,6 +289,8 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * Use ref_ext to retrieve thirdparty * * @depends testWSThirdpartycreateThirdParty + * + * @param result thirdparty created by create method * @return array thirdparty */ public function testWSThirdpartygetThirdPartyByRefExt($result) @@ -348,6 +351,7 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * * @depends testWSThirdpartycreateThirdParty * + * @param result thirdparty created by create method * @return array thirdparty */ public function testWSThirdpartydeleteThirdPartyById($result) From ed657d2bdfe6d13328271c5a7b2efb0bed39b559 Mon Sep 17 00:00:00 2001 From: Arnaud Aujon Date: Mon, 1 Jun 2015 20:39:51 +0200 Subject: [PATCH 20/56] hopefully fix travis errors --- test/phpunit/WebservicesInvoicesTest.php | 10 +++++----- test/phpunit/WebservicesThirdpartyTest.php | 16 ++++++++-------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/test/phpunit/WebservicesInvoicesTest.php b/test/phpunit/WebservicesInvoicesTest.php index ff8a9a30e73..bbfde0a66e5 100755 --- a/test/phpunit/WebservicesInvoicesTest.php +++ b/test/phpunit/WebservicesInvoicesTest.php @@ -154,7 +154,7 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase /** * testWSInvoicesCreateInvoice * - * @return int + * @return int invoice created */ public function testWSInvoicesCreateInvoice() { @@ -259,8 +259,8 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase * Retrieve an invoice using ref_ext * @depends testWSInvoicesCreateInvoice * - * @param result invoice created by create method - * @return array Invoice + * @param array $result Invoice created by create method + * @return array Invoice */ public function testWSInvoicesGetInvoiceByRefExt($result) { @@ -315,8 +315,8 @@ class WebservicesInvoicesTest extends PHPUnit_Framework_TestCase * Update an invoice using ref_ext * @depends testWSInvoicesCreateInvoice * - * @param result invoice created by create method - * @return array Invoice + * @param array $result invoice created by create method + * @return array Invoice */ public function testWSInvoicesUpdateInvoiceByRefExt($result) { diff --git a/test/phpunit/WebservicesThirdpartyTest.php b/test/phpunit/WebservicesThirdpartyTest.php index 2bf3f3fe094..2888c432e73 100755 --- a/test/phpunit/WebservicesThirdpartyTest.php +++ b/test/phpunit/WebservicesThirdpartyTest.php @@ -229,8 +229,8 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * Use id to retrieve thirdparty * @depends testWSThirdpartycreateThirdParty * - * @param result thirdparty created by create method - * @return array thirpdarty updated + * @param array $result thirdparty created by create method + * @return array thirpdarty updated */ public function testWSThirdpartygetThirdPartyById($result) { @@ -290,8 +290,8 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * * @depends testWSThirdpartycreateThirdParty * - * @param result thirdparty created by create method - * @return array thirdparty + * @param array $result thirdparty created by create method + * @return array thirdparty */ public function testWSThirdpartygetThirdPartyByRefExt($result) { @@ -351,8 +351,8 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase * * @depends testWSThirdpartycreateThirdParty * - * @param result thirdparty created by create method - * @return array thirdparty + * @param array $result thirdparty created by create method + * @return array thirdparty */ public function testWSThirdpartydeleteThirdPartyById($result) { @@ -382,14 +382,14 @@ class WebservicesThirdpartyTest extends PHPUnit_Framework_TestCase echo $exception; $result=0; } - //if (! $result || ! empty($result['faultstring'])) { + if (! $result || ! empty($result['faultstring'])) { print $this->soapclient->error_str; print "\n
\n"; print $this->soapclient->request; print "\n
\n"; print $this->soapclient->response; print "\n"; - //} + } print __METHOD__." result=".$result['result']['result_code']."\n"; $this->assertEquals('OK',$result['result']['result_code']); From 2164729bad0d20906f66e002e416a22d1bd1703a Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Thu, 4 Jun 2015 13:34:08 +0200 Subject: [PATCH 21/56] if duration is present on service, we use it not logic to entered always 1h --- htdocs/fichinter/card.php | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index dac78d9ae3b..b5a00b694bf 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -248,7 +248,24 @@ else if ($action == 'add' && $user->rights->ficheinter->creer) $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 @@ else if ($action == 'add' && $user->rights->ficheinter->creer) $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 @@ else if ($action == 'add' && $user->rights->ficheinter->creer) $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/56] 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 b74c8ddba17..f6282edf369 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 6331290056d728e115fcd5a704d1266a699e8857 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 5 Jun 2015 20:23:04 +0200 Subject: [PATCH 23/56] Fix phpcs --- htdocs/api/class/api_access.class.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/api/class/api_access.class.php b/htdocs/api/class/api_access.class.php index f4aba956817..9cd40f56498 100644 --- a/htdocs/api/class/api_access.class.php +++ b/htdocs/api/class/api_access.class.php @@ -44,6 +44,8 @@ class DolibarrApiAccess implements iAuthenticate */ public static $user = ''; + // @codingStandardsIgnoreStart + /** * Check access * @@ -106,7 +108,6 @@ class DolibarrApiAccess implements iAuthenticate return in_array(static::$role, (array) static::$requires) || static::$role == 'admin'; } - // @codingStandardsIgnoreStart /** * @return string string to be used with WWW-Authenticate header * @example Basic From f42065146a9f1fb2f7e9c37eae9a464b56cb82d4 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 6 Jun 2015 12:26:47 +0200 Subject: [PATCH 24/56] Start to clean html.form class. --- dev/skeletons/skeleton_page.php | 2 +- htdocs/cashdesk/admin/cashdesk.php | 8 +- htdocs/comm/askpricesupplier/card.php | 2 +- htdocs/comm/propal.php | 2 +- htdocs/commande/card.php | 2 +- htdocs/compta/facture.php | 2 +- htdocs/contrat/card.php | 2 +- htdocs/core/class/commonobject.class.php | 83 ++-------------- htdocs/core/class/html.form.class.php | 119 ++++++++++++++++++----- htdocs/core/lib/agenda.lib.php | 2 +- htdocs/expedition/card.php | 2 +- htdocs/fichinter/card.php | 10 +- htdocs/fourn/commande/card.php | 2 +- htdocs/fourn/facture/card.php | 2 +- htdocs/livraison/card.php | 2 +- htdocs/public/test/test_forms.php | 2 +- htdocs/societe/soc.php | 2 +- 17 files changed, 126 insertions(+), 120 deletions(-) diff --git a/dev/skeletons/skeleton_page.php b/dev/skeletons/skeleton_page.php index ac329318ae5..482208e8ab1 100644 --- a/dev/skeletons/skeleton_page.php +++ b/dev/skeletons/skeleton_page.php @@ -353,7 +353,7 @@ if ($id && (empty($action) || $action == 'view')) // Example 2 : Adding links to objects // The class must extends CommonObject class to have this method available - //$somethingshown=$object->showLinkedObjectBlock(); + //$somethingshown=$form->showLinkedObjectBlock($object); } diff --git a/htdocs/cashdesk/admin/cashdesk.php b/htdocs/cashdesk/admin/cashdesk.php index a8ef98b0b0b..48804958b20 100644 --- a/htdocs/cashdesk/admin/cashdesk.php +++ b/htdocs/cashdesk/admin/cashdesk.php @@ -102,7 +102,7 @@ print "\n"; $var=!$var; print ''.$langs->trans("CashDeskThirdPartyForSell").''; print ''; -print $form->select_thirdparty($conf->global->CASHDESK_ID_THIRDPARTY,'socid','s.client in (1,3)',0,array(),1); +print $form->select_company($conf->global->CASHDESK_ID_THIRDPARTY,'socid','s.client in (1,3)',1,0,1,array(),0); print ''; if (! empty($conf->banque->enabled)) { @@ -133,17 +133,17 @@ if (! empty($conf->stock->enabled)) if (empty($conf->productbatch->enabled)) { print $form->selectyesno('CASHDESK_NO_DECREASE_STOCK',$conf->global->CASHDESK_NO_DECREASE_STOCK,1); } - else + else { if (!$conf->global->CASHDESK_NO_DECREASE_STOCK) { $res = dolibarr_set_const($db,"CASHDESK_NO_DECREASE_STOCK",1,'chaine',0,'',$conf->entity); } - print $langs->trans('StockDecreaseForPointOfSaleDisabledbyBatch'); + print $langs->trans('StockDecreaseForPointOfSaleDisabledbyBatch'); } print ''; $disabled=$conf->global->CASHDESK_NO_DECREASE_STOCK; - + $var=!$var; print ''.$langs->trans("CashDeskIdWareHouse").''; // Force warehouse (this is not a default value) print ''; diff --git a/htdocs/comm/askpricesupplier/card.php b/htdocs/comm/askpricesupplier/card.php index 6759ae22196..939d874a0f2 100644 --- a/htdocs/comm/askpricesupplier/card.php +++ b/htdocs/comm/askpricesupplier/card.php @@ -1712,7 +1712,7 @@ if ($action == 'create') /* * Linked object block */ - $somethingshown = $object->showLinkedObjectBlock(); + $somethingshown = $form->showLinkedObjectBlock($object); print '
'; diff --git a/htdocs/comm/propal.php b/htdocs/comm/propal.php index ce22d192f81..ccdcd850493 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -2310,7 +2310,7 @@ if ($action == 'create') /* * Linked object block */ - $somethingshown = $object->showLinkedObjectBlock(); + $somethingshown = $form->showLinkedObjectBlock($object); print '
'; // print ''; diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index fcd96f8c898..04ea05d3f5d 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -2308,7 +2308,7 @@ if ($action == 'create' && $user->rights->commande->creer) /* * Linked object block */ - $somethingshown = $object->showLinkedObjectBlock(); + $somethingshown = $form->showLinkedObjectBlock($object); print '
'; // print ''; diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 379d2d2ee5d..3abe4fc6c99 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -3776,7 +3776,7 @@ if ($action == 'create') $somethingshown = $formfile->numoffiles; // Linked object block - $somethingshown = $object->showLinkedObjectBlock(); + $somethingshown = $form->showLinkedObjectBlock($object); $linktoelem=''; diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 192a2d16b17..3df24e4e667 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -1874,7 +1874,7 @@ else /* * Linked object block */ - $somethingshown=$object->showLinkedObjectBlock(); + $somethingshown=$form->showLinkedObjectBlock($object); print '
'; diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 4c511726979..3ea0e010eb5 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -135,8 +135,8 @@ abstract class CommonObject $sql = "SELECT rowid, ref, ref_ext"; $sql.= " FROM ".MAIN_DB_PREFIX.$element; - $sql.= " WHERE entity IN (".getEntity($element).")" ; - + $sql.= " WHERE entity IN (".getEntity($element).")" ; + if ($id > 0) $sql.= " AND rowid = ".$db->escape($id); else if ($ref) $sql.= " AND ref = '".$db->escape($ref)."'"; else if ($ref_ext) $sql.= " AND ref_ext = '".$db->escape($ref_ext)."'"; @@ -2580,88 +2580,19 @@ abstract class CommonObject // TODO: All functions here must be redesigned and moved as they are not business functions but output functions // -------------------- - /* This is to show linked object block */ - /** - * Show linked object block - * TODO Move this into html.class.php - * But for the moment we don't know if it's possible as we keep a method available on overloaded objects. + * Show linked object block. * - * @return int + * @return int <0 if KO, >0 if OK + * @deprecated Use instead $form->shoLinkedObjectBlock($object) */ function showLinkedObjectBlock() { - global $conf,$langs,$hookmanager; - global $bc; - - $this->fetchObjectLinked(); - - // Bypass the default method - $hookmanager->initHooks(array('commonobject')); - $parameters=array(); - $reshook=$hookmanager->executeHooks('showLinkedObjectBlock',$parameters,$this,$action); // Note that $action and $object may have been modified by hook - - if (empty($reshook)) - { - $num = count($this->linkedObjects); - - foreach($this->linkedObjects as $objecttype => $objects) - { - $tplpath = $element = $subelement = $objecttype; - - if (preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs)) - { - $element = $regs[1]; - $subelement = $regs[2]; - $tplpath = $element.'/'.$subelement; - } - - // To work with non standard path - if ($objecttype == 'facture') { - $tplpath = 'compta/'.$element; - if (empty($conf->facture->enabled)) continue; // Do not show if module disabled - } - else if ($objecttype == 'propal') { - $tplpath = 'comm/'.$element; - if (empty($conf->propal->enabled)) continue; // Do not show if module disabled - } - else if ($objecttype == 'askpricesupplier') { - $tplpath = 'comm/'.$element; - if (empty($conf->askpricesupplier->enabled)) continue; // Do not show if module disabled - } - else if ($objecttype == 'shipping' || $objecttype == 'shipment') { - $tplpath = 'expedition'; - if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled - } - else if ($objecttype == 'delivery') { - $tplpath = 'livraison'; - if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled - } - else if ($objecttype == 'invoice_supplier') { - $tplpath = 'fourn/facture'; - } - else if ($objecttype == 'order_supplier') { - $tplpath = 'fourn/commande'; - } - - global $linkedObjectBlock; - $linkedObjectBlock = $objects; - - // Output template part (modules that overwrite templates must declare this into descriptor) - $dirtpls=array_merge($conf->modules_parts['tpl'],array('/'.$tplpath.'/tpl')); - foreach($dirtpls as $reldir) - { - $res=@include dol_buildpath($reldir.'/linkedobjectblock.tpl.php'); - if ($res) break; - } - } - - return $num; - } + global $form; + return $form->showLinkedObjectBlock($this); } - /* This is to show add lines */ /** diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index bdb4f57a4cc..dfb310c20f8 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -803,11 +803,28 @@ class Form * @param array $ajaxoptions Options for ajax_autocompleter * @param int $forcecombo Force to use combo box * @return string Return select box for thirdparty. + * @deprecated Use select_company instead. For exemple $form->select_thirdparty(GETPOST('socid'),'socid','',0) => $form->select_company(GETPOST('socid'),'socid','',1,0,0,array(),0) */ function select_thirdparty($selected='', $htmlname='socid', $filter='', $limit=20, $ajaxoptions=array(), $forcecombo=0) { - global $langs,$conf; + return $this->select_thirdparty_list($selected,$htmlname,$filter,1,0,$forcecombo,array(),'',0,$limit); + } + /** + * Output html form to select a third party + * + * @param string $selected Preselected type + * @param string $htmlname Name of field in form + * @param string $filter optional filters criteras (example: 's.rowid <> x') + * @param int $showempty Add an empty field + * @param int $showtype Show third party type in combolist (customer, prospect or supplier) + * @param int $forcecombo Force to use combo box + * @param array $events Ajax event options to run on change. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) + * @param int $limit Maximum number of elements + * @return string HTML string with select box for thirdparty. + */ + function select_company($selected='', $htmlname='socid', $filter='', $showempty=0, $showtype=0, $forcecombo=0, $events=array(), $limit=0) + { $out=''; /* TODO Use ajax_autocompleter like for products (not finished) @@ -840,32 +857,12 @@ class Form } else {*/ - $out.=$this->select_thirdparty_list($selected,$htmlname,$filter,1,0,$forcecombo,array(),'',0,$limit); + $out.=$this->select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, '', 0, $limit); //} return $out; } - /** - * Output html form to select a third party - * - * @param string $selected Preselected type - * @param string $htmlname Name of field in form - * @param string $filter optional filters criteras (example: 's.rowid <> x') - * @param int $showempty Add an empty field - * @param int $showtype Show third party type in combolist (customer, prospect or supplier) - * @param int $forcecombo Force to use combo box - * @param array $events Event options to run on change. Example: array(array('method'=>'getContacts', 'url'=>dol_buildpath('/core/ajax/contacts.php',1), 'htmlname'=>'contactid', 'params'=>array('add-customer-contact'=>'disabled'))) - * @param int $limit Maximum number of elements - * @return string HTML string with - * @deprecated Use select_thirdparty instead - * @see select_thirdparty() - */ - function select_company($selected='', $htmlname='socid', $filter='', $showempty=0, $showtype=0, $forcecombo=0, $events=array(), $limit=0) - { - return $this->select_thirdparty_list($selected, $htmlname, $filter, $showempty, $showtype, $forcecombo, $events, '', 0, $limit); - } - /** * Output html form to select a third party * @@ -4620,6 +4617,84 @@ class Form } + /** + * Show linked object block. + * + * @param CommonObject $object Object we want to show links to + * @return int <0 if KO, >0 if OK + */ + function showLinkedObjectBlock($object) + { + global $conf,$langs,$hookmanager; + global $bc; + + $object->fetchObjectLinked(); + + // Bypass the default method + $hookmanager->initHooks(array('commonobject')); + $parameters=array(); + $reshook=$hookmanager->executeHooks('showLinkedObjectBlock',$parameters,$object,$action); // Note that $action and $object may have been modified by hook + + if (empty($reshook)) + { + $num = count($object->linkedObjects); + + foreach($object->linkedObjects as $objecttype => $objects) + { + $tplpath = $element = $subelement = $objecttype; + + if (preg_match('/^([^_]+)_([^_]+)/i',$objecttype,$regs)) + { + $element = $regs[1]; + $subelement = $regs[2]; + $tplpath = $element.'/'.$subelement; + } + + // To work with non standard path + if ($objecttype == 'facture') { + $tplpath = 'compta/'.$element; + if (empty($conf->facture->enabled)) continue; // Do not show if module disabled + } + else if ($objecttype == 'propal') { + $tplpath = 'comm/'.$element; + if (empty($conf->propal->enabled)) continue; // Do not show if module disabled + } + else if ($objecttype == 'askpricesupplier') { + $tplpath = 'comm/'.$element; + if (empty($conf->askpricesupplier->enabled)) continue; // Do not show if module disabled + } + else if ($objecttype == 'shipping' || $objecttype == 'shipment') { + $tplpath = 'expedition'; + if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled + } + else if ($objecttype == 'delivery') { + $tplpath = 'livraison'; + if (empty($conf->expedition->enabled)) continue; // Do not show if module disabled + } + else if ($objecttype == 'invoice_supplier') { + $tplpath = 'fourn/facture'; + } + else if ($objecttype == 'order_supplier') { + $tplpath = 'fourn/commande'; + } + + global $linkedObjectBlock; + $linkedObjectBlock = $objects; + + // Output template part (modules that overwrite templates must declare this into descriptor) + $dirtpls=array_merge($conf->modules_parts['tpl'],array('/'.$tplpath.'/tpl')); + foreach($dirtpls as $reldir) + { + $res=@include dol_buildpath($reldir.'/linkedobjectblock.tpl.php'); + if ($res) break; + } + } + + return $num; + } + } + + /** * Return an html string with a select combo box to choose yes or no * diff --git a/htdocs/core/lib/agenda.lib.php b/htdocs/core/lib/agenda.lib.php index 8ebdc547cc8..fd2a3cd4099 100644 --- a/htdocs/core/lib/agenda.lib.php +++ b/htdocs/core/lib/agenda.lib.php @@ -103,7 +103,7 @@ function print_actions_filter($form, $canedit, $status, $year, $month, $day, $sh print ''; print $langs->trans("ThirdParty").'   '; print ''; - print $form->select_thirdparty($socid, 'socid'); + print $form->select_company($socid, 'socid'); print ''; } diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index 2475f420dd0..85380907bbf 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -1505,7 +1505,7 @@ else if ($id || $ref) /* * Linked object block */ - $somethingshown=$object->showLinkedObjectBlock(); + $somethingshown=$form->showLinkedObjectBlock($object); if ($genallowed && ! $somethingshown) $somethingshown=1; diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index dac78d9ae3b..ad224ab9fe2 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -1019,7 +1019,7 @@ if ($action == 'create') print ''; dol_fiche_head(''); - + print ''; print ''; @@ -1125,7 +1125,7 @@ if ($action == 'create') } dol_fiche_end(); - + print '
'; print ''; print '
'; @@ -1135,7 +1135,7 @@ if ($action == 'create') else { dol_fiche_head(''); - + print ''; print '
'; print '
'.$langs->trans("ThirdParty").''; @@ -1144,7 +1144,7 @@ if ($action == 'create') print '
'; dol_fiche_end(); - + print '
'; print ''; print ''; @@ -1722,7 +1722,7 @@ else if ($id > 0 || ! empty($ref)) /* * Linked object block */ - $somethingshown=$object->showLinkedObjectBlock(); + $somethingshown=$form->showLinkedObjectBlock($object); //print ''; print '
'; diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index 35165b33298..95442273495 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -2766,7 +2766,7 @@ elseif (! empty($object->id)) /* * Linked object block */ - $somethingshown=$object->showLinkedObjectBlock(); + $somethingshown=$form->showLinkedObjectBlock($object); print '
'; diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index b4b853b58bc..e365f8a7070 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -2415,7 +2415,7 @@ else /* * Linked object block */ - $somethingshown=$object->showLinkedObjectBlock(); + $somethingshown=$form->showLinkedObjectBlock($object); $linktoelem=''; diff --git a/htdocs/livraison/card.php b/htdocs/livraison/card.php index fb087e71800..5e477d1926d 100644 --- a/htdocs/livraison/card.php +++ b/htdocs/livraison/card.php @@ -788,7 +788,7 @@ else $shipment = new Expedition($db); $shipment->fetch($object->origin_id); - $somethingshown=$shipment->showLinkedObjectBlock(); + $somethingshown=$form->showLinkedObjectBlock($shipment); } if ($genallowed && ! $somethingshown) $somethingshown=1; diff --git a/htdocs/public/test/test_forms.php b/htdocs/public/test/test_forms.php index 0a99b11e3aa..a6a361620e9 100644 --- a/htdocs/public/test/test_forms.php +++ b/htdocs/public/test/test_forms.php @@ -75,7 +75,7 @@ print '

'."\n"; // Test4d: form->select_thirdparty print "Test 4d: Select thirdparty
\n"; -print $form->select_thirdparty(0,'thirdpartytest'); +print $form->select_company(0,'thirdpartytest'); print '

'."\n"; diff --git a/htdocs/societe/soc.php b/htdocs/societe/soc.php index ec9a63f64d4..70ec2a08a49 100644 --- a/htdocs/societe/soc.php +++ b/htdocs/societe/soc.php @@ -1849,7 +1849,7 @@ else 'name' => 'soc_origin', 'label' => $langs->trans('MergeOriginThirdparty'), 'type' => 'other', - 'value' => $form->select_thirdparty('', 'soc_origin', 's.rowid != '.$object->id) + 'value' => $form->select_company('', 'soc_origin', 's.rowid != '.$object->id) ) ); From 9a812a6c287913437e0262b4aea5e5acb37318bb Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Sat, 6 Jun 2015 13:03:02 +0200 Subject: [PATCH 25/56] 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 a0ef8878d1f..b5302063a65 100644 --- a/htdocs/comm/propal.php +++ b/htdocs/comm/propal.php @@ -2194,7 +2194,7 @@ if ($action == 'create') $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 @@ if ($action == 'create') 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 e6be7a8d74b..c326959619a 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 @@ if ($action == 'create' && $user->rights->commande->creer) { $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 @@ if ($action == 'create' && $user->rights->commande->creer) { 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 e247863a015..b360f6b6315 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 @@ if ($action == 'create') $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 @@ if ($action == 'create') 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 d1a1cedca61..75d18c2b1a5 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 @@ if (empty($conf->global->MAIN_DISABLE_SUGGEST_REF_AS_PREFIX)) //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 7187506db14..7dd0d680bee 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -1621,7 +1621,7 @@ else if ($id || $ref) { $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 @@ else if ($id || $ref) 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 f5fcd076709..6fb4d374a7a 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -1732,7 +1732,7 @@ else if ($id > 0 || ! empty($ref)) { $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 @@ else if ($id > 0 || ! empty($ref)) 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 a6ac9c42b56..584b5e337e0 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -1920,7 +1920,7 @@ elseif (! empty($object->id)) { $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 @@ elseif (! empty($object->id)) 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 54ef660f6aa..08bffd09a67 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -2396,7 +2396,7 @@ else { $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 @@ else 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 1880ed701f9a3206c3dc7e29f6b69ebd6e8a0fc6 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 6 Jun 2015 13:22:15 +0200 Subject: [PATCH 26/56] Uniformize code --- htdocs/core/class/html.form.class.php | 126 +++++++++++++++----------- 1 file changed, 74 insertions(+), 52 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index dfb310c20f8..399985c4f2f 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -41,6 +41,8 @@ /** * Class to manage generation of HTML components * Only common components must be here. + * + * TODO Merge all function load_cache_* into one generic function */ class Form { @@ -101,7 +103,7 @@ class Form } } else - { + { $ret.=''; @@ -712,22 +714,23 @@ class Form /** * Load into cache cache_types_fees, array of types of fees * - * @return int Nb of lines loaded, 0 if already loaded, <0 if ko - * TODO move in DAO class + * @return int Nb of lines loaded, <0 if KO */ function load_cache_types_fees() { global $langs; - $langs->load("trips"); + $num = count($this->cache_types_fees); + if ($num > 0) return 0; // Cache already loaded - if (count($this->cache_types_fees)) return 0; // Cache already load + dol_syslog(__METHOD__, LOG_DEBUG); + + $langs->load("trips"); $sql = "SELECT c.code, c.label"; $sql.= " FROM ".MAIN_DB_PREFIX."c_type_fees as c"; - //$sql.= " ORDER BY c.label ASC"; // No sort here, sort must be done after translation + $sql.= " WHERE active > 0"; - dol_syslog(get_class($this).'::load_cache_types_fees', LOG_DEBUG); $resql=$this->db->query($sql); if ($resql) { @@ -749,7 +752,7 @@ class Form return $num; } else - { + { dol_print_error($this->db); return -1; } @@ -767,7 +770,7 @@ class Form { global $user, $langs; - dol_syslog(get_class($this)."::select_type_fees ".$selected.", ".$htmlname, LOG_DEBUG); + dol_syslog(__METHOD__." selected=".$selected.", htmlname=".$htmlname, LOG_DEBUG); $this->load_cache_types_fees(); @@ -803,7 +806,7 @@ class Form * @param array $ajaxoptions Options for ajax_autocompleter * @param int $forcecombo Force to use combo box * @return string Return select box for thirdparty. - * @deprecated Use select_company instead. For exemple $form->select_thirdparty(GETPOST('socid'),'socid','',0) => $form->select_company(GETPOST('socid'),'socid','',1,0,0,array(),0) + * @deprecated 3.8 Use select_company instead. For exemple $form->select_thirdparty(GETPOST('socid'),'socid','',0) => $form->select_company(GETPOST('socid'),'socid','',1,0,0,array(),0) */ function select_thirdparty($selected='', $htmlname='socid', $filter='', $limit=20, $ajaxoptions=array(), $forcecombo=0) { @@ -2321,19 +2324,22 @@ class Form /** * Charge dans cache la liste des conditions de paiements possibles * - * @return int Nb lignes chargees, 0 si deja chargees, <0 si ko + * @return int Nb of lines loaded, <0 if KO */ function load_cache_conditions_paiements() { global $langs; - if (count($this->cache_conditions_paiements)) return 0; // Cache deja charge + $num = count($this->cache_conditions_paiements); + if ($num > 0) return 0; // Cache already loaded - $sql = "SELECT rowid, code, libelle"; + dol_syslog(__METHOD__, LOG_DEBUG); + + $sql = "SELECT rowid, code, libelle as label"; $sql.= " FROM ".MAIN_DB_PREFIX.'c_payment_term'; - $sql.= " WHERE active=1"; + $sql.= " WHERE active > 0"; $sql.= " ORDER BY sortorder"; - dol_syslog(get_class($this).'::load_cache_conditions_paiements', LOG_DEBUG); + $resql = $this->db->query($sql); if ($resql) { @@ -2344,14 +2350,18 @@ class Form $obj = $this->db->fetch_object($resql); // Si traduction existe, on l'utilise, sinon on prend le libelle par defaut - $libelle=($langs->trans("PaymentConditionShort".$obj->code)!=("PaymentConditionShort".$obj->code)?$langs->trans("PaymentConditionShort".$obj->code):($obj->libelle!='-'?$obj->libelle:'')); + $label=($langs->trans("PaymentConditionShort".$obj->code)!=("PaymentConditionShort".$obj->code)?$langs->trans("PaymentConditionShort".$obj->code):($obj->label!='-'?$obj->label:'')); $this->cache_conditions_paiements[$obj->rowid]['code'] =$obj->code; - $this->cache_conditions_paiements[$obj->rowid]['label']=$libelle; + $this->cache_conditions_paiements[$obj->rowid]['label']=$label; $i++; } - return 1; + + //$this->cache_conditions_paiements=dol_sort_array($this->cache_conditions_paiements, 'label'); // We use the sortorder + + return $num; } - else { + else + { dol_print_error($this->db); return -1; } @@ -2360,19 +2370,21 @@ class Form /** * Charge dans cache la liste des délais de livraison possibles * - * @return int Nb lignes chargees, 0 si deja chargees, <0 si ko + * @return int Nb of lines loaded, <0 if KO */ function load_cache_availability() { global $langs; - if (count($this->cache_availability)) return 0; // Cache deja charge + $num = count($this->cache_availability); + if ($num > 0) return 0; // Cache already loaded + + dol_syslog(__METHOD__, LOG_DEBUG); $sql = "SELECT rowid, code, label"; $sql.= " FROM ".MAIN_DB_PREFIX.'c_availability'; - $sql.= " WHERE active=1"; - $sql.= " ORDER BY rowid"; - dol_syslog(get_class($this).'::load_cache_availability', LOG_DEBUG); + $sql.= " WHERE active > 0"; + $resql = $this->db->query($sql); if ($resql) { @@ -2388,9 +2400,13 @@ class Form $this->cache_availability[$obj->rowid]['label']=$label; $i++; } - return 1; + + $this->cache_availability = dol_sort_array($this->cache_availability, 'label'); + + return $num; } - else { + else + { dol_print_error($this->db); return -1; } @@ -2411,6 +2427,8 @@ class Form $this->load_cache_availability(); + dol_syslog(__METHOD__." selected=".$selected.", htmlname=".$htmlname, LOG_DEBUG); + print ''; @@ -2604,7 +2629,7 @@ class Form { global $langs,$user; - dol_syslog(get_class($this)."::select_type_paiements ".$selected.", ".$htmlname.", ".$filtertype.", ".$format,LOG_DEBUG); + dol_syslog(__METHOD__." ".$selected.", ".$htmlname.", ".$filtertype.", ".$format, LOG_DEBUG); $filterarray=array(); if ($filtertype == 'CRDT') $filterarray=array(0,2,3); @@ -3518,9 +3543,9 @@ class Form * * @param string $page Page * @param string $selected Id of user preselected - * @param string $htmlname Name of input html field - * @param array $exclude List of users id to exclude - * @param array $include List of users id to include + * @param string $htmlname Name of input html field. If 'none', we just output the user link. + * @param array $exclude List of users id to exclude + * @param array $include List of users id to include * @return void */ function form_users($page, $selected='', $htmlname='userid', $exclude='', $include='') @@ -3540,12 +3565,10 @@ class Form print '
'; $ret.=$langs->trans($text); $ret.='
'; } else - { + { if ($selected) { require_once DOL_DOCUMENT_ROOT .'/user/class/user.class.php'; - //$this->load_cache_contacts(); - //print $this->cache_contacts[$selected]; $theuser=new User($this->db); $theuser->fetch($selected); print $theuser->getNomUrl(1); @@ -3656,12 +3679,12 @@ class Form /** - * Affiche formulaire de selection des contacts + * Show forms to select a contact * - * @param string $page Page - * @param Societe $societe Third party - * @param int $selected Id contact pre-selectionne - * @param string $htmlname Nom du formulaire select + * @param string $page Page + * @param Societe $societe Filter on third party + * @param int $selected Id contact pre-selectionne + * @param string $htmlname Name of HTML select. If 'none', we just show contact link. * @return void */ function form_contacts($page, $societe, $selected='', $htmlname='contactid') @@ -3691,8 +3714,6 @@ class Form if ($selected) { require_once DOL_DOCUMENT_ROOT .'/contact/class/contact.class.php'; - //$this->load_cache_contacts(); - //print $this->cache_contacts[$selected]; $contact=new Contact($this->db); $contact->fetch($selected); print $contact->getFullName($langs); @@ -3808,12 +3829,14 @@ class Form global $langs; $num = count($this->cache_vatrates); - if ($num > 0) return $num; // Cache deja charge + if ($num > 0) return $num; // Cache already loaded - $sql = "SELECT DISTINCT t.taux, t.recuperableonly"; + dol_syslog(__METHOD__, LOG_DEBUG); + + $sql = "SELECT DISTINCT t.taux, t.recuperableonly"; $sql.= " FROM ".MAIN_DB_PREFIX."c_tva as t, ".MAIN_DB_PREFIX."c_country as c"; $sql.= " WHERE t.fk_pays = c.rowid"; - $sql.= " AND t.active = 1"; + $sql.= " AND t.active > 0"; $sql.= " AND c.code IN (".$country_code.")"; $sql.= " ORDER BY t.taux ASC, t.recuperableonly ASC"; @@ -4431,7 +4454,7 @@ class Form { $out = ''; - // Add code for jquery to use multiselect + // Add code for jquery to use select2 if ($addjscombo && empty($conf->dol_use_jmobile)) { $tmpplugin='select2'; @@ -4938,7 +4961,6 @@ class Form $cache='0'; if ($file && file_exists($dir."/".$file)) { - // TODO Link to large image $ret.=''; $ret.='Photo'; $ret.=''; From 89f77f5e2b1ab511959dc5c5368f6db5cd636598 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 6 Jun 2015 14:21:18 +0200 Subject: [PATCH 27/56] Uniformize code --- ChangeLog | 1 + htdocs/compta/facture.php | 2 +- htdocs/core/class/html.form.class.php | 77 +++++++++---------- htdocs/core/lib/functions.lib.php | 4 +- htdocs/main.inc.php | 4 +- htdocs/product/admin/product_tools.php | 2 +- .../product/actions_card_product.class.php | 2 +- .../service/actions_card_service.class.php | 2 +- htdocs/product/card.php | 2 +- htdocs/product/fournisseurs.php | 2 +- htdocs/product/price.php | 8 +- htdocs/societe/price.php | 4 +- 12 files changed, 53 insertions(+), 57 deletions(-) diff --git a/ChangeLog b/ChangeLog index e70169095be..98339d3874a 100644 --- a/ChangeLog +++ b/ChangeLog @@ -41,6 +41,7 @@ Dolibarr better: - Hooks 'printLeftBlock' and 'formConfirm' are now compliant with hook development rules. They are "addreplace" hooks, so you must return content with "->resprints='mycontent'" and not with "return 'mycontent'" - All fields "fk_societe" were renamed into "fk_soc". +- Method select_PriceBaseType and load_PriceBaseType were merged into selectPriceBaseType ***** ChangeLog for 3.7.1 compared to 3.7.* ***** FIX Bug in the new photo system diff --git a/htdocs/compta/facture.php b/htdocs/compta/facture.php index 3abe4fc6c99..a73a1de3607 100644 --- a/htdocs/compta/facture.php +++ b/htdocs/compta/facture.php @@ -2134,7 +2134,7 @@ if ($action == 'create') print '
'; // Next situation invoice - $opt = $form->load_situation_invoices(GETPOST('originid'), $socid); + $opt = $form->selectSituationInvoices(GETPOST('originid'), $socid); print '
'; $tmp='' . $langs->trans('NoSituations') . '') || (GETPOST('origin') && GETPOST('origin') != 'facture')) $tmp.=' disabled'; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 399985c4f2f..be0d2656ec2 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -42,7 +42,7 @@ * Class to manage generation of HTML components * Only common components must be here. * - * TODO Merge all function load_cache_* into one generic function + * TODO Merge all function load_cache_* and loadCache* (except load_cache_vatrates) into one generic function loadCacheTable */ class Form { @@ -499,7 +499,7 @@ class Form $sql = "SELECT rowid, code as code_iso, code_iso as code_iso3, label, favorite"; $sql.= " FROM ".MAIN_DB_PREFIX."c_country"; - $sql.= " WHERE active = 1"; + $sql.= " WHERE active > 0"; //$sql.= " ORDER BY code ASC"; dol_syslog(get_class($this)."::select_country", LOG_DEBUG); @@ -587,7 +587,7 @@ class Form $sql = "SELECT rowid, code"; $sql.= " FROM ".MAIN_DB_PREFIX."c_incoterms"; - $sql.= " WHERE active = 1"; + $sql.= " WHERE active > 0"; $sql.= " ORDER BY code ASC"; dol_syslog(get_class($this)."::select_incoterm", LOG_DEBUG); @@ -896,7 +896,7 @@ class Form if (! empty($user->societe_id)) $sql.= " AND s.rowid = ".$user->societe_id; if ($filter) $sql.= " AND (".$filter.")"; if (!$user->rights->societe->client->voir && !$user->societe_id) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id; - if (! empty($conf->global->COMPANY_HIDE_INACTIVE_IN_COMBOBOX)) $sql.= " AND s.status<>0 "; + if (! empty($conf->global->COMPANY_HIDE_INACTIVE_IN_COMBOBOX)) $sql.= " AND s.status <> 0"; // Add criteria if ($filterkey && $filterkey != '') { @@ -1123,7 +1123,7 @@ class Form if ($showsoc > 0) $sql.= " LEFT OUTER JOIN ".MAIN_DB_PREFIX ."societe as s ON s.rowid=sp.fk_soc"; $sql.= " WHERE sp.entity IN (".getEntity('societe', 1).")"; if ($socid > 0) $sql.= " AND sp.fk_soc=".$socid; - if (! empty($conf->global->CONTACT_HIDE_INACTIVE_IN_COMBOBOX)) $sql.= " AND sp.statut<>0"; + if (! empty($conf->global->CONTACT_HIDE_INACTIVE_IN_COMBOBOX)) $sql.= " AND sp.statut <> 0"; $sql.= " ORDER BY sp.lastname ASC"; dol_syslog(get_class($this)."::select_contacts", LOG_DEBUG); @@ -2451,19 +2451,19 @@ class Form /** * Load into cache cache_demand_reason, array of input reasons * - * @return int Nb of lines loaded, 0 if already loaded, <0 if ko + * @return int Nb of lines loaded, <0 if KO */ function loadCacheInputReason() { global $langs; - if (count($this->cache_demand_reason)) return 0; // Cache already loaded + $num = count($this->cache_demand_reason); + if ($num > 0) return 0; // Cache already loaded $sql = "SELECT rowid, code, label"; $sql.= " FROM ".MAIN_DB_PREFIX.'c_input_reason'; - $sql.= " WHERE active=1"; - $sql.= " ORDER BY rowid"; - dol_syslog(get_class($this)."::loadCacheInputReason", LOG_DEBUG); + $sql.= " WHERE active > 0"; + $resql = $this->db->query($sql); if ($resql) { @@ -2481,12 +2481,14 @@ class Form $tmparray[$obj->rowid]['label']=$label; $i++; } + $this->cache_demand_reason=dol_sort_array($tmparray, 'label', 'asc'); unset($tmparray); - return 1; + return $num; } - else { + else + { dol_print_error($this->db); return -1; } @@ -2669,26 +2671,13 @@ class Form /** - * Selection HT or TTC + * Selection HT or TTC * - * @param string $selected Id pre-selectionne - * @param string $htmlname Nom de la zone select - * @return void + * @param string $selected Id pre-selectionne + * @param string $htmlname Nom de la zone select + * @return string Code of HTML select to chose tax or not */ - function select_PriceBaseType($selected='',$htmlname='price_base_type') - { - print $this->load_PriceBaseType($selected,$htmlname); - } - - - /** - * Selection HT or TTC - * - * @param string $selected Id pre-selectionne - * @param string $htmlname Nom de la zone select - * @return void - */ - function load_PriceBaseType($selected='',$htmlname='price_base_type') + function selectPriceBaseType($selected='',$htmlname='price_base_type') { global $langs; @@ -2733,9 +2722,9 @@ class Form $langs->load("admin"); $langs->load("deliveries"); - $sql = "SELECT rowid, code, libelle"; + $sql = "SELECT rowid, code, libelle as label"; $sql.= " FROM ".MAIN_DB_PREFIX."c_shipment_mode"; - $sql.= " WHERE active = 1"; + $sql.= " WHERE active > 0"; if ($filtre) $sql.=" AND ".$filtre; $sql.= " ORDER BY libelle ASC"; @@ -2756,7 +2745,7 @@ class Form } else { print ''; $i++; } @@ -2808,12 +2797,12 @@ class Form /** * Creates HTML last in cycle situation invoices selector * - * @param string $selected Preselected ID - * @param int $socid Company ID + * @param string $selected Preselected ID + * @param int $socid Company ID * * @return string HTML select */ - function load_situation_invoices($selected = '', $socid = '') + function selectSituationInvoices($selected = '', $socid = 0) { global $langs; @@ -2821,7 +2810,7 @@ class Form $opt = ''; $sql = 'SELECT rowid, facnumber, situation_cycle_ref, situation_counter, situation_final, fk_soc FROM ' . MAIN_DB_PREFIX . 'facture WHERE situation_counter>=1'; - $sql .= ' order by situation_cycle_ref, situation_counter desc'; + $sql.= ' ORDER by situation_cycle_ref, situation_counter desc'; $resql = $this->db->query($sql); if ($resql && $this->db->num_rows($resql) > 0) { // Last seen cycle @@ -2847,10 +2836,13 @@ class Form } } } - } else { + } + else + { dol_syslog("Error sql=" . $sql . ", error=" . $this->error, LOG_ERR); } - if ($opt == '') { + if ($opt == '') + { $opt = ''; } return $opt; @@ -2872,7 +2864,9 @@ class Form $return= ''; - print '' . $objp->ref . ''; - print '' . $objp->ref_client . ''; - print '' . price($objp->total_ht) . ''; - print '' . $objp->name . ''; - print ''; - print ''; - } - - $i ++; - } - print ''; - print '
     
'; - print ''; - $db->free($resqlorderlist); - } else { - dol_print_error($db); - } - - print '
'; - } - - // Show link to elements + // Show links to link elements + $linktoelem = $form->showLinkToObjectBlock($object,array('order')); if ($linktoelem) print '
'.$linktoelem; // Link for paypal payment diff --git a/htdocs/contrat/card.php b/htdocs/contrat/card.php index 3df24e4e667..6bf7dcaeacc 100644 --- a/htdocs/contrat/card.php +++ b/htdocs/contrat/card.php @@ -1871,10 +1871,13 @@ else $somethingshown = $formfile->show_documents('contract', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang); - /* - * Linked object block - */ - $somethingshown=$form->showLinkedObjectBlock($object); + // Linked object block + $somethingshown = $form->showLinkedObjectBlock($object); + + // Show links to link elements + $linktoelem = $form->showLinkToObjectBlock($object); + if ($linktoelem) print '
'.$linktoelem; + print '
'; diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index be0d2656ec2..cef6d9a0ae4 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -4712,6 +4712,159 @@ class Form } } + /** + * Show block with links to link to other objects. + * + * @param CommonObject $object Object we want to show links to + * @param Societe $thirdparty Object thirdparty + * @param array $restrictlinksto Restrict links to some elements, for exemple array('order') or array('supplier_order') + * @return int <0 if KO, >0 if OK + */ + function showLinkToObjectBlock($object, $restrictlinksto=array()) + { + global $conf, $langs, $hookmanager; + global $bc; + + $linktoelem=''; + + if (! is_object($object->thirdparty)) $object->fetch_thirdparty(); + + + if (((! is_array($restrictlinksto)) || in_array('order',$restrictlinksto)) + && ! empty($conf->commande->enabled)) + { + $linktoelem.=($linktoelem?'   ':'').'' . $langs->trans('LinkedOrder') . ''; + + print ' + + '; + + print '
global->MAIN_OPTIMIZEFORTEXTBROWSER)?' style="display:none"':'').'>'; + + $sql = "SELECT s.rowid as socid, s.nom as name, s.client, c.rowid, c.ref, c.ref_client, c.total_ht"; + $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; + $sql .= ", " . MAIN_DB_PREFIX . "commande as c"; + $sql .= ' WHERE c.fk_soc = s.rowid AND c.fk_soc = ' . $object->thirdparty->id . ''; + + $resqlorderlist = $this->db->query($sql); + if ($resqlorderlist) + { + $num = $this->db->num_rows($resqlorderlist); + $i = 0; + + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + while ($i < $num) + { + $objp = $this->db->fetch_object($resqlorderlist); + + $var = ! $var; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + + $i ++; + } + print '
' . $langs->trans("Ref") . '' . $langs->trans("RefCustomer") . '' . $langs->trans("AmountHTShort") . '' . $langs->trans("Company") . '
'; + print ''; + print '' . $objp->ref . '' . $objp->ref_client . '' . price($objp->total_ht) . '' . $objp->name . '
'; + print '
     
'; + print '
'; + $this->db->free($resqlorderlist); + } else { + dol_print_error($this->db); + } + + print '
'; + } + + if (((! is_array($restrictlinksto)) || in_array('supplier_order',$restrictlinksto)) + && ! empty($conf->fournisseur->enabled)) + { + $linktoelem.=($linktoelem?'   ':'').'' . $langs->trans('LinkedOrder') . ''; + + print ' + + '; + + print '
global->MAIN_OPTIMIZEFORTEXTBROWSER)?' style="display:none"':'').'>'; + + $sql = "SELECT s.rowid as socid, s.nom as name, s.client, c.rowid, c.ref, c.ref_supplier, c.total_ht"; + $sql .= " FROM " . MAIN_DB_PREFIX . "societe as s"; + $sql .= ", " . MAIN_DB_PREFIX . "commande_fournisseur as c"; + $sql .= ' WHERE c.fk_soc = s.rowid AND c.fk_soc = ' . $object->thirdparty->id; + + $resqlorderlist = $this->db->query($sql); + if ($resqlorderlist) + { + $num = $this->db->num_rows($resqlorderlist); + $i = 0; + + print '
'; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + while ($i < $num) { + $objp = $this->db->fetch_object($resqlorderlist); + if ($objp->socid == $societe->id) { + $var = ! $var; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + print ''; + } + + $i ++; + } + print '
' . $langs->trans("Ref") . '' . $langs->trans("RefSupplier") . '' . $langs->trans("AmountHTShort") . '' . $langs->trans("Company") . '
'; + print ''; + print '' . $objp->ref . '' . $objp->ref_supplier . '' . price($objp->total_ht) . '' . $objp->name . '
'; + print '
 
'; + print '
'; + $this->db->free($resqlorderlist); + } else { + dol_print_error($this->db); + } + + print '
'; + } + + + return $linktoelem; + } /** * Return an html string with a select combo box to choose yes or no diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index 85380907bbf..344e17166ad 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -1502,12 +1502,12 @@ else if ($id || $ref) $somethingshown=$formfile->show_documents('expedition',$objectref,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang); - /* - * Linked object block - */ - $somethingshown=$form->showLinkedObjectBlock($object); + // Linked object block + $somethingshown = $form->showLinkedObjectBlock($object); - if ($genallowed && ! $somethingshown) $somethingshown=1; + // Show links to link elements + //$linktoelem = $form->showLinkToObjectBlock($object); + //if ($linktoelem) print '
'.$linktoelem; print ''; diff --git a/htdocs/fichinter/card.php b/htdocs/fichinter/card.php index ad224ab9fe2..9b8e7d9a6a8 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -1701,7 +1701,6 @@ else if ($id > 0 || ! empty($ref)) if ($action != 'presend') { print '
'; - //print '
'; /* * Built documents @@ -1719,12 +1718,14 @@ else if ($id > 0 || ! empty($ref)) //print "
\n"; $somethingshown=$formfile->show_documents('ficheinter',$filename,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,28,0,'','','',$soc->default_lang); - /* - * Linked object block - */ - $somethingshown=$form->showLinkedObjectBlock($object); + // Linked object block + $somethingshown = $form->showLinkedObjectBlock($object); + + // Show links to link elements + //$linktoelem = $form->showLinkToObjectBlock($object); + //if ($linktoelem) print '
'.$linktoelem; + - //print '
'; print '
'; // List of actions on element @@ -1733,7 +1734,6 @@ else if ($id > 0 || ! empty($ref)) $somethingshown=$formactions->showactions($object,'fichinter',$socid); print '
'; - //print "
\n"; } diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index 95442273495..b56bba0c4a5 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -2763,10 +2763,13 @@ elseif (! empty($object->id)) print $formfile->showdocuments('commande_fournisseur',$comfournref,$filedir,$urlsource,$genallowed,$delallowed,$object->modelpdf,1,0,0,0,0,'','','',$object->thirdparty->default_lang); $somethingshown=$formfile->numoffiles; - /* - * Linked object block - */ - $somethingshown=$form->showLinkedObjectBlock($object); + // Linked object block + $somethingshown = $form->showLinkedObjectBlock($object); + + // Show links to link elements + //$linktoelem = $form->showLinkToObjectBlock($object); + //if ($linktoelem) print '
'.$linktoelem; + print '
'; diff --git a/htdocs/fourn/facture/card.php b/htdocs/fourn/facture/card.php index e365f8a7070..2491c6eaff6 100644 --- a/htdocs/fourn/facture/card.php +++ b/htdocs/fourn/facture/card.php @@ -2412,80 +2412,14 @@ else print $formfile->showdocuments('facture_fournisseur',$subdir,$filedir,$urlsource,$genallowed,$delallowed,$modelpdf,1,0,0,40,0,'','','',$societe->default_lang); $somethingshown=$formfile->numoffiles; - /* - * Linked object block - */ - $somethingshown=$form->showLinkedObjectBlock($object); + // Linked object block + $somethingshown = $form->showLinkedObjectBlock($object); - $linktoelem=''; - - if (empty($somethingshown) && ! empty($conf->fournisseur->enabled)) - { - $linktoelem.=($linktoelem?'   ':'').'' . $langs->trans('LinkedOrder') . ''; - - print ' - - '; - - print ''; - } - - // Show link to elements + // Show links to link elements + $linktoelem = $form->showLinkToObjectBlock($object,array('supplier_order')); if ($linktoelem) print '
'.$linktoelem; + print '
'; //print ''; //print '
'; diff --git a/htdocs/livraison/card.php b/htdocs/livraison/card.php index 5e477d1926d..7ea9920d65b 100644 --- a/htdocs/livraison/card.php +++ b/htdocs/livraison/card.php @@ -788,10 +788,14 @@ else $shipment = new Expedition($db); $shipment->fetch($object->origin_id); - $somethingshown=$form->showLinkedObjectBlock($shipment); + // Linked object block + $somethingshown = $form->showLinkedObjectBlock($shipment); + + // Show links to link elements + //$linktoelem = $form->showLinkToObjectBlock($shipment); + //if ($linktoelem) print '
'.$linktoelem; } - if ($genallowed && ! $somethingshown) $somethingshown=1; print ''; From b89473383c11091eea9f0bd36ed1bb88e77cf4ac Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sat, 6 Jun 2015 16:41:11 +0200 Subject: [PATCH 31/56] Fix phpcs --- htdocs/core/class/html.form.class.php | 1 - 1 file changed, 1 deletion(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index cef6d9a0ae4..e770bb5ea72 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -4716,7 +4716,6 @@ class Form * Show block with links to link to other objects. * * @param CommonObject $object Object we want to show links to - * @param Societe $thirdparty Object thirdparty * @param array $restrictlinksto Restrict links to some elements, for exemple array('order') or array('supplier_order') * @return int <0 if KO, >0 if OK */ From c4ccf6f74461db500d9de8b205b8cffbdcab2d84 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 7 Jun 2015 00:06:11 +0200 Subject: [PATCH 32/56] Fix: Missing the delete command --- htdocs/core/lib/geturl.lib.php | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/htdocs/core/lib/geturl.lib.php b/htdocs/core/lib/geturl.lib.php index 8f6847bcb9a..c02c896eb1b 100644 --- a/htdocs/core/lib/geturl.lib.php +++ b/htdocs/core/lib/geturl.lib.php @@ -28,7 +28,7 @@ * @param string $postorget 'POST', 'GET', 'HEAD' * @param string $param Parameters of URL (x=value1&y=value2) * @param string $followlocation 1=Follow location, 0=Do not follow - * @param array $addheaders Array of string to add into header. Example: ('Accept: application/xrds+xml', ....) + * @param array $addheaders Array of string to add into header. Example: array('Accept: application/xrds+xml', ....) * @return array Returns an associative array containing the response from the server array('content'=>response,'curl_error_no'=>errno,'curl_error_msg'=>errmsg...) */ function getURLContent($url,$postorget='GET',$param='',$followlocation=1,$addheaders=array()) @@ -76,13 +76,17 @@ function getURLContent($url,$postorget='GET',$param='',$followlocation=1,$addhea curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // HTTP request is 'PUT' if ( ! is_array($param) ) parse_str($param, $array_param); - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array_param)); // Setting param x=a&y=z as PUT fields + curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array_param)); // Setting param x=a&y=z as PUT fields } else if ($postorget == 'HEAD') { curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'HEAD'); // HTTP request is 'HEAD' curl_setopt($ch, CURLOPT_NOBODY, true); } + else if ($postorget == 'DELETE') + { + curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'DELETE'); // POST + } else { curl_setopt($ch, CURLOPT_POST, 0); // GET From 7e4abf94b47ecffad742d186859ca1280bac6d91 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 7 Jun 2015 02:43:51 +0200 Subject: [PATCH 33/56] 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 9c93fa8fe89..7d4ce9ceebf 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -364,7 +364,7 @@ function getState($id,$withcode='',$dbtouse=0) } else { - return $langs->trans("NotDefined"); + return $langs->transnoentitiesnoconv("NotDefined"); } } else dol_print_error($dbtouse,''); From 536f565d4e4105844e536a3e573da54ab6e50aff Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 7 Jun 2015 02:43:51 +0200 Subject: [PATCH 34/56] 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 a9663d447bc..e124c312a77 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 dd08d5d660190215a8ac62275c44ce8b058f4821 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 7 Jun 2015 03:39:43 +0200 Subject: [PATCH 35/56] Fix bad parameter for PUT method --- htdocs/core/lib/company.lib.php | 2 +- htdocs/core/lib/geturl.lib.php | 4 +--- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/htdocs/core/lib/company.lib.php b/htdocs/core/lib/company.lib.php index 9c93fa8fe89..7d4ce9ceebf 100644 --- a/htdocs/core/lib/company.lib.php +++ b/htdocs/core/lib/company.lib.php @@ -364,7 +364,7 @@ function getState($id,$withcode='',$dbtouse=0) } else { - return $langs->trans("NotDefined"); + return $langs->transnoentitiesnoconv("NotDefined"); } } else dol_print_error($dbtouse,''); diff --git a/htdocs/core/lib/geturl.lib.php b/htdocs/core/lib/geturl.lib.php index c02c896eb1b..af0c6b91da0 100644 --- a/htdocs/core/lib/geturl.lib.php +++ b/htdocs/core/lib/geturl.lib.php @@ -74,9 +74,7 @@ function getURLContent($url,$postorget='GET',$param='',$followlocation=1,$addhea else if ($postorget == 'PUT') { curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'PUT'); // HTTP request is 'PUT' - if ( ! is_array($param) ) - parse_str($param, $array_param); - curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($array_param)); // Setting param x=a&y=z as PUT fields + curl_setopt($ch, CURLOPT_POSTFIELDS, $param); // Setting param x=a&y=z as PUT fields } else if ($postorget == 'HEAD') { From 37cadaf4bfeec7df9bdc47569dd686b1df0af1f5 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 7 Jun 2015 03:41:12 +0200 Subject: [PATCH 36/56] Fix the trigger on delete thirdparty was not called --- htdocs/categories/class/categorie.class.php | 16 +++++----------- htdocs/societe/class/societe.class.php | 16 ++++++++++------ 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 36251073028..190f58d9388 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -1215,7 +1215,7 @@ class Categorie extends CommonObject } /** - * Return list of categories (id or instances) linked to element of id $id and type $type + * Return list of categories (object instances or labels) linked to element of id $id and type $type * Should be named getListOfCategForObject * * @param int $id Id of element @@ -1228,20 +1228,15 @@ class Categorie extends CommonObject */ function containing($id,$type,$mode='object') { - // Deprecation warning - if (is_numeric($type)) { - dol_syslog(__METHOD__ . ': using numeric types is deprecated.', LOG_WARNING); - } - $cats = array(); // For backward compatibility - if (is_numeric( $type )) { + if (is_numeric($type)) + { + dol_syslog(__METHOD__ . ': using numeric value for parameter type is deprecated. Use string code instead.', LOG_WARNING); // We want to reverse lookup - $map_type = array_flip( $this->MAP_ID ); + $map_type = array_flip($this->MAP_ID); $type = $map_type[$type]; - dol_syslog( get_class( $this ) . "::containing(): numeric types are deprecated, please use string instead", - LOG_WARNING ); } $sql = "SELECT ct.fk_categorie, c.label"; @@ -1249,7 +1244,6 @@ class Categorie extends CommonObject $sql .= " WHERE ct.fk_categorie = c.rowid AND ct.fk_" . $this->MAP_CAT_FK[$type] . " = " . $id . " AND c.type = " . $this->MAP_ID[$type]; $sql .= " AND c.entity IN (" . getEntity( 'category', 1 ) . ")"; - dol_syslog(get_class($this).'::containing', LOG_DEBUG); $res = $this->db->query($sql); if ($res) { diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index bce15b081bb..238d1b46606 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -317,6 +317,7 @@ class Societe extends CommonObject * @var string */ var $note_public; + //! code statut prospect var $stcomm_id; var $statut_commercial; @@ -1303,11 +1304,13 @@ class Societe extends CommonObject * @param int $id Id of third party to delete * @param User $user User who ask to delete thirparty * @param int $call_trigger 0=No, 1=yes - * @return int <0 if KO, 0 if nothing done, >0 if OK + * @return int <0 if KO, 0 if nothing done, >0 if OK */ - function delete($id, $user='', $call_trigger=1) + function delete($id, User $fuser=null, $call_trigger=1) { - global $langs, $conf; + global $langs, $conf, $user; + + if (empty($fuser)) $fuser=$user; require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php'; @@ -1323,10 +1326,10 @@ class Societe extends CommonObject $this->db->begin(); // User is mandatory for trigger call - if ($user && $call_trigger) + if ($call_trigger) { // Call trigger - $result=$this->call_trigger('COMPANY_DELETE',$user); + $result=$this->call_trigger('COMPANY_DELETE',$fuser); if ($result < 0) $error++; // End call triggers } @@ -1451,7 +1454,8 @@ class Societe extends CommonObject return 1; } else - { + { + dol_syslog($this->error, LOG_ERR); $this->db->rollback(); return -1; } From 101a9a4cf3ac701876ece9be02501f1e77faf279 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Sun, 7 Jun 2015 19:35:47 +0200 Subject: [PATCH 37/56] Fix: object user must not be overwritten --- htdocs/societe/class/societe.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index 238d1b46606..c61b08b1ecf 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1302,7 +1302,7 @@ class Societe extends CommonObject * Delete a third party from database and all its dependencies (contacts, rib...) * * @param int $id Id of third party to delete - * @param User $user User who ask to delete thirparty + * @param User $fuser User who ask to delete thirparty * @param int $call_trigger 0=No, 1=yes * @return int <0 if KO, 0 if nothing done, >0 if OK */ From bcf9bdc92e9d2c97cbd9232637e45edd05a9e998 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Sun, 7 Jun 2015 23:18:51 +0200 Subject: [PATCH 38/56] 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 b5a00b694bf..73f8b16fdb3 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 @@ else if ($action == 'add' && $user->rights->ficheinter->creer) $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 @@ else if ($action == 'add' && $user->rights->ficheinter->creer) $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 39/56] 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 140475ed5df..1b3633c9ae5 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 40/56] 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 f6282edf369..57f29ef9a90 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 41/56] Fix: Avoid warning in expense report validation Fix: navigation in expense report --- htdocs/core/class/html.form.class.php | 4 +- htdocs/expensereport/card.php | 250 ++++++++++-------- .../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, 179 insertions(+), 156 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index e770bb5ea72..07fcee8e709 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -4964,7 +4964,7 @@ class Form * @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 @@ class Form //print "xx".$previous_ref."x".$next_ref; //if ($previous_ref || $next_ref || $morehtml) { //$ret.=''; print ''; @@ -1376,7 +1392,7 @@ else // Ref print ''; print ''; @@ -1450,6 +1466,7 @@ else print ''; } + // User to inform if($object->fk_statut<3) // informed { print ''; @@ -1460,6 +1477,7 @@ else $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 @@ else $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 @@ else 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 2d9bcbceead..0b688790af7 100644 --- a/htdocs/expensereport/card.php +++ b/htdocs/expensereport/card.php @@ -46,6 +46,7 @@ $date_start = dol_mktime(0, 0, 0, GETPOST('date_debutmonth'), GETPOST('date_debu $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 ($cancel) $action=''; 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 @@ if ($action == "confirm_save" && GETPOST("confirm") == "yes" && $id > 0 && $user $expediteur->fetch($object->fk_user_author); $emailFrom = $expediteur->email; - // 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); - - // 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"); - */ - - // PREPARE SEND - $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); - - if ($mailfile) + if ($emailTo && $emailFrom) { - // SEND - $result=$mailfile->sendfile(); - if ($result) + // 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); + + // 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"); + */ + + // PREPARE SEND + $mailfile = new CMailFile($subject,$emailTo,$emailFrom,$message,$filedir,$mimetype,$filename); + + if ($mailfile) { - $mesg=$langs->trans('MailSuccessfulySent',$mailfile->getValidAddress($emailFrom,2),$mailfile->getValidAddress($emailTo,2)); - setEventMessage($mesg); - header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); - exit; - } - else - { - $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 ($action == "confirm_save_from_refuse" && GETPOST("confirm") == "yes" && $id 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; + if ($emailTo) + { + // FROM + $expediteur = new User($db); + $expediteur->fetch($object->fk_user_author); + $emailFrom = $expediteur->email; - // SUBJECT - $subject = "' ERP - Note de frais à re-approuver"; + // SUBJECT + $subject = "' ERP - Note de frais à re-approuver"; - // CONTENT - $dateRefusEx = explode(" ",$object->date_refuse); + // 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"; + $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); + // Génération du pdf avant attachement + $object->setDocModel($user,""); + $resultPDF = expensereport_pdf_create($db,$object,'',"",$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_number).".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_number).".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->error): - - // SEND - $result=$mailfile->sendfile(); - if ($result): - Header("Location: ".$_SERVER["PHP_SELF"]."?id=".$id); - exit; - endif; - - else: - - $mesg="Impossible d'envoyer l'email."; - - 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 @@ if ($action == 'create') } 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 @@ else // 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 @@ print '
'; 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 ($action != 'create' && $action != 'edit') 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 ($action != 'create' && $action != 'edit') 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 ($action != 'create' && $action != 'edit') 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 ($action != 'create' && $action != 'edit') if ($object->fk_user_author == $user->id) { // Brouillonner - print ''.$langs->trans('SetToDraft').''; + print 'id.'">'.$langs->trans('SetToDraft').''; } } @@ -1871,21 +1889,21 @@ if ($action != 'create' && $action != 'edit') //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 ($action != 'create' && $action != 'edit') 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 ($action != 'create' && $action != 'edit') 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 ($action != 'create' && $action != 'edit') 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 6d8dd793a3d..98a6aea00e7 100644 --- a/htdocs/expensereport/class/expensereport.class.php +++ b/htdocs/expensereport/class/expensereport.class.php @@ -348,7 +348,8 @@ class ExpenseReport extends CommonObject $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 @@ class ExpenseReport extends CommonObject * 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 @@ class ExpenseReport extends CommonObject /** * 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 @@ class ExpenseReport extends CommonObject { $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 @@ class ExpenseReport extends CommonObject /** * 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 @@ class ExpenseReport extends CommonObject /** * 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 @@ class ExpenseReport extends CommonObject 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 @@ class ExpenseReport extends CommonObject /** * 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 @@ class ExpenseReport extends CommonObject 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 @@ class ExpenseReport extends CommonObject 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 @@ class ExpenseReport extends CommonObject /** * 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 @@ class ExpenseReport extends CommonObject 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 @@ class ExpenseReport extends CommonObject /** * 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 @@ class ExpenseReport extends CommonObject /** * 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 @@ class ExpenseReport extends CommonObject * 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 @@ class ExpenseReport extends CommonObject /** * 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 @@ class ExpenseReportLine /** * 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 4af39adb633..5b157f6df8b 100644 --- a/htdocs/expensereport/index.php +++ b/htdocs/expensereport/index.php @@ -107,7 +107,7 @@ print_fiche_titre($langs->trans("ExpensesArea")); print '
'; -print '
'; +print '
'; print ''; print ''; print "\n"; diff --git a/htdocs/expensereport/list.php b/htdocs/expensereport/list.php index 58002c19dba..c0b30b6c873 100644 --- a/htdocs/expensereport/list.php +++ b/htdocs/expensereport/list.php @@ -180,6 +180,7 @@ if ($resql) 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 @@ if ($resql) 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 c61b08b1ecf..4d55732b801 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1045,7 +1045,7 @@ class Societe extends CommonObject $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 0a8ec08da1d..9ab7e921faa 100644 --- a/htdocs/societe/societe.php +++ b/htdocs/societe/societe.php @@ -338,7 +338,7 @@ if ($resql) 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 01caa7a7282..94f3277ea42 100644 --- a/htdocs/theme/eldy/style.css.php +++ b/htdocs/theme/eldy/style.css.php @@ -1974,9 +1974,12 @@ table.liste td { /* 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 4d7a3d18a5c..bca20fccbb9 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -1833,7 +1833,6 @@ class User extends CommonObject $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 42/56] 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 03d724b9bba..4c5f0b512d2 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 @@ if ($action == 'add') } } - $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 @@ if ($action == 'update') $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 44de526942f..fc13acc7072 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 @@ +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 9c283b83867..286eba8c3b7 100644 --- a/htdocs/core/tpl/admin_extrafields_edit.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_edit.tpl.php @@ -56,6 +56,8 @@ $required=$extrafields->attribute_required[$attrname]; $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 @@ if(($type == 'select') || ($type == 'sellist') || ($type == 'checkbox') || ($typ 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 bc269822da4..3409c075761 100644 --- a/htdocs/fichinter/card.php +++ b/htdocs/fichinter/card.php @@ -251,7 +251,7 @@ else if ($action == 'add' && $user->rights->ficheinter->creer) $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 @@ else if ($action == 'add' && $user->rights->ficheinter->creer) $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 43/56] 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 9fbdb2ffd7e..c8e96919f84 100644 --- a/htdocs/comm/propal/list.php +++ b/htdocs/comm/propal/list.php @@ -56,6 +56,7 @@ $search_refcustomer=GETPOST('search_refcustomer','alpha'); $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 @@ if (GETPOST("button_removefilter") || GETPOST("button_removefilter_x")) // Both $search_societe=''; $search_montant_ht=''; $search_author=''; + $search_product_category=''; $search_town=''; $year=''; $month=''; @@ -145,14 +147,15 @@ if (! $sortorder) $sortorder='DESC'; $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 ($search_montant_ht != '') 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 @@ if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) $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 ($result) 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 07fcee8e709..394b77b9768 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -4357,16 +4357,18 @@ class Form 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.='