From 45067c63d82b2b1b7a070366d673c7751565a02e Mon Sep 17 00:00:00 2001 From: Alexis Algoud Date: Thu, 15 May 2014 11:37:40 +0200 Subject: [PATCH 1/5] Add delivery date into supplier order list --- htdocs/fourn/commande/liste.php | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/htdocs/fourn/commande/liste.php b/htdocs/fourn/commande/liste.php index 4da9f5e40c153..47bcb468e842e 100644 --- a/htdocs/fourn/commande/liste.php +++ b/htdocs/fourn/commande/liste.php @@ -32,6 +32,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formorder.class.php'; $langs->load("orders"); +$langs->load("sendings"); $search_ref=GETPOST('search_ref'); @@ -83,7 +84,7 @@ */ $sql = "SELECT s.rowid as socid, s.nom, cf.date_commande as dc,"; -$sql.= " cf.rowid,cf.ref, cf.ref_supplier, cf.fk_statut, cf.total_ttc, cf.fk_user_author,"; +$sql.= " cf.rowid,cf.ref, cf.ref_supplier, cf.fk_statut, cf.total_ttc, cf.fk_user_author,cf.date_livraison,"; $sql.= " u.login"; $sql.= " FROM (".MAIN_DB_PREFIX."societe as s,"; $sql.= " ".MAIN_DB_PREFIX."commande_fournisseur as cf"; @@ -156,6 +157,7 @@ print_liste_field_titre($langs->trans("Author"),$_SERVER["PHP_SELF"],"u.login","",$param,'',$sortfield,$sortorder); print_liste_field_titre($langs->trans("AmountTTC"),$_SERVER["PHP_SELF"],"total_ttc","",$param,$sortfield,$sortorder); print_liste_field_titre($langs->trans("OrderDate"),$_SERVER["PHP_SELF"],"dc","",$param,'align="center"',$sortfield,$sortorder); + print_liste_field_titre($langs->trans('DateDeliveryPlanned'),$_SERVER["PHP_SELF"],'cf.date_livraison','',$param, 'align="right"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("Status"),$_SERVER["PHP_SELF"],"cf.fk_statut","",$param,'align="right"',$sortfield,$sortorder); print_liste_field_titre(''); print "\n"; @@ -168,6 +170,7 @@ print ''; print ''; print ' '; + print ' '; print ''; $formorder->selectSupplierOrderStatus($search_status,1,'search_status'); print ''; @@ -226,6 +229,12 @@ } print ''; + // Delivery date + print ''; + print dol_print_date($db->jdate($obj->date_livraison), 'day'); + print ''; + + // Statut print ''.$commandestatic->LibStatut($obj->fk_statut, 5).''; From 2f78446433b2fcbd765be00f61b30592612f4de8 Mon Sep 17 00:00:00 2001 From: Alexis Algoud Date: Thu, 15 May 2014 11:43:55 +0200 Subject: [PATCH 2/5] FIX alert for supplier order wasn't on delivery_date if exist --- htdocs/fourn/class/fournisseur.commande.class.php | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 591fce671b12d..704e06b2f3bd1 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -1917,7 +1917,7 @@ function load_board($user) $this->nbtodo=$this->nbtodolate=0; $clause = " WHERE"; - $sql = "SELECT c.rowid, c.date_creation as datec, c.fk_statut"; + $sql = "SELECT c.rowid, c.date_creation as datec, c.fk_statut,c.date_livraison as delivery_date"; $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur as c"; if (!$user->rights->societe->client->voir && !$user->societe_id) { @@ -1935,7 +1935,9 @@ function load_board($user) while ($obj=$this->db->fetch_object($resql)) { $this->nbtodo++; - if ($obj->fk_statut != 3 && $this->db->jdate($obj->datec) < ($now - $conf->commande->fournisseur->warning_delay)) $this->nbtodolate++; + + $date_to_test = empty($obj->delivery_date) ? $obj->datec : $obj->delivery_date; + if ($obj->fk_statut != 3 && $this->db->jdate($date_to_test) < ($now - $conf->commande->fournisseur->warning_delay)) $this->nbtodolate++; } return 1; } From 30a25251d92b29b91571ca482491f887a9168ce2 Mon Sep 17 00:00:00 2001 From: guerinaxel Date: Tue, 20 May 2014 09:59:42 +0200 Subject: [PATCH 3/5] Adding var mode_reglement_id to facture Adding var mode_reglement_id to facture in order to change the payment method. --- htdocs/webservices/server_invoice.php | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index c79c862146c04..321547761540e 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -102,6 +102,7 @@ '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'), + 'mode_reglement_id' => array('name'=>'mode_reglement_id','type'=>'xsd:string'), // From product 'product_id' => array('name'=>'product_id','type'=>'xsd:int'), 'product_ref' => array('name'=>'product_ref','type'=>'xsd:string'), @@ -329,6 +330,7 @@ function getInvoice($authentication,$id='',$ref='',$ref_ext='') 'status'=> $invoice->statut, 'close_code' => $invoice->close_code?$invoice->close_code:'', 'close_note' => $invoice->close_note?$invoice->close_note:'', + 'mode_reglement_id' => $invoice->mode_reglement_id?$invoice->mode_reglement_id:'', 'lines' => $linesresp )); } @@ -454,6 +456,7 @@ function getInvoicesForThirdParty($authentication,$idthirdparty) 'status'=> $invoice->statut, 'close_code' => $invoice->close_code?$invoice->close_code:'', 'close_note' => $invoice->close_note?$invoice->close_note:'', + 'mode_reglement_id' => $invoice->mode_reglement_id?$invoice->mode_reglement_id:'', 'lines' => $linesresp ); } @@ -518,6 +521,7 @@ function createInvoice($authentication,$invoice) $newobject->statut=0; // We start with status draft $newobject->fk_project=$invoice['project_id']; $newobject->date_creation=$now; + $newobject->mode_reglement_id = $invoice['mode_reglement_id']; // Trick because nusoap does not store data with same structure if there is one or several lines $arrayoflines=array(); From 0d71350c7636991dfd1bf6c80649083dedcc79fc Mon Sep 17 00:00:00 2001 From: guerinaxel Date: Thu, 22 May 2014 08:54:14 +0200 Subject: [PATCH 4/5] Rename mode_reglement_id into payment_mode_id --- htdocs/webservices/server_invoice.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/htdocs/webservices/server_invoice.php b/htdocs/webservices/server_invoice.php index 321547761540e..e8c6f166890ff 100644 --- a/htdocs/webservices/server_invoice.php +++ b/htdocs/webservices/server_invoice.php @@ -102,7 +102,7 @@ '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'), - 'mode_reglement_id' => array('name'=>'mode_reglement_id','type'=>'xsd:string'), + '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'), @@ -330,7 +330,7 @@ function getInvoice($authentication,$id='',$ref='',$ref_ext='') 'status'=> $invoice->statut, 'close_code' => $invoice->close_code?$invoice->close_code:'', 'close_note' => $invoice->close_note?$invoice->close_note:'', - 'mode_reglement_id' => $invoice->mode_reglement_id?$invoice->mode_reglement_id:'', + 'payment_mode_id' => $invoice->mode_reglement_id?$invoice->mode_reglement_id:'', 'lines' => $linesresp )); } @@ -456,7 +456,7 @@ function getInvoicesForThirdParty($authentication,$idthirdparty) 'status'=> $invoice->statut, 'close_code' => $invoice->close_code?$invoice->close_code:'', 'close_note' => $invoice->close_note?$invoice->close_note:'', - 'mode_reglement_id' => $invoice->mode_reglement_id?$invoice->mode_reglement_id:'', + 'payment_mode_id' => $invoice->mode_reglement_id?$invoice->mode_reglement_id:'', 'lines' => $linesresp ); } @@ -521,7 +521,7 @@ function createInvoice($authentication,$invoice) $newobject->statut=0; // We start with status draft $newobject->fk_project=$invoice['project_id']; $newobject->date_creation=$now; - $newobject->mode_reglement_id = $invoice['mode_reglement_id']; + $newobject->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(); From 92f1778c9df42164d4c5fc71cc3a6afdb443bd8f Mon Sep 17 00:00:00 2001 From: KreizIT Date: Wed, 25 Jun 2014 16:51:26 +0200 Subject: [PATCH 5/5] Fix : [ bug #1459 ] _ADD_CONTACT and _DEL_CONTACT triggers do not intercept insertion when reported an error Start refactoring trigger call from within object --- ChangeLog | 3 + htdocs/core/class/commonobject.class.php | 77 +++++++++++++++--------- 2 files changed, 52 insertions(+), 28 deletions(-) diff --git a/ChangeLog b/ChangeLog index 4a88f51c07d48..76fc8bbf8015e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -65,6 +65,7 @@ For users: - Fix: Add actions events not implemented. - Fix: Price min of composition is not supplier price min by quantity. - Fix: [ bug #1356 ] Bank accountancy number is limited to 8 numbers. +- Fix: [ bug #1459 ] _ADD_CONTACT and _DEL_CONTACT triggers do not intercept insertion when reported an error TODO - New: Predefined product and free product use same form. @@ -89,6 +90,8 @@ For developers: - New: A module can disable a standard ECM view. - New: Add multilang support into product webservice. - New: Add hooks on project card page. +- New: Add call_trigger method on CommonObject class. So new trigger call within object it's just : +$result = $this->call_trigger($triger_name, $user) and do what you need to do if trigger fail WARNING: Following change may create regression for some external modules, but was necessary to make Dolibarr better: diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 914d9be59a3b1..0c1d18e28edfb 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -164,7 +164,6 @@ function add_contact($fk_socpeople, $type_contact, $source='external',$notrigger { global $user,$conf,$langs; - $error=0; dol_syslog(get_class($this)."::add_contact $fk_socpeople, $type_contact, $source"); @@ -205,6 +204,8 @@ function add_contact($fk_socpeople, $type_contact, $source='external',$notrigger $datecreate = dol_now(); + $this->db->begin(); + // Insertion dans la base $sql = "INSERT INTO ".MAIN_DB_PREFIX."element_contact"; $sql.= " (element_id, fk_socpeople, datecreate, statut, fk_c_type_contact) "; @@ -219,20 +220,16 @@ function add_contact($fk_socpeople, $type_contact, $source='external',$notrigger { if (! $notrigger) { - // Call triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers(strtoupper($this->element).'_ADD_CONTACT',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // End call triggers + $result=$this->call_trigger(strtoupper($this->element).'_ADD_CONTACT', $user); + if ($result < 0) { $this->db->rollback(); return -1; } } - + + $this->db->commit(); return 1; } else { + $this->db->rollback(); if ($this->db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') { $this->error=$this->db->errno(); @@ -311,8 +308,9 @@ function delete_contact($rowid, $notrigger=0) { global $user,$langs,$conf; - $error=0; + $this->db->begin(); + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_contact"; $sql.= " WHERE rowid =".$rowid; @@ -321,21 +319,17 @@ function delete_contact($rowid, $notrigger=0) { if (! $notrigger) { - // Call triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers(strtoupper($this->element).'_DELETE_CONTACT',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // End call triggers + $result=$this->call_trigger(strtoupper($this->element).'_DELETE_CONTACT', $user); + if ($result < 0) { $this->db->rollback(); return -1; } } + $this->db->commit(); return 1; } else { $this->error=$this->db->lasterror(); + $this->db->rollback(); dol_syslog(get_class($this)."::delete_contact error=".$this->error, LOG_ERR); return -1; } @@ -3354,8 +3348,9 @@ function delete_resource($rowid, $element, $notrigger=0) { global $user,$langs,$conf; - $error=0; + $this->db->begin(); + $sql = "DELETE FROM ".MAIN_DB_PREFIX."element_resources"; $sql.= " WHERE rowid =".$rowid; @@ -3364,14 +3359,8 @@ function delete_resource($rowid, $element, $notrigger=0) { if (! $notrigger) { - // Call triggers - include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; - $interface=new Interfaces($this->db); - $result=$interface->run_triggers(strtoupper($element).'_DELETE_RESOURCE',$this,$user,$langs,$conf); - if ($result < 0) { - $error++; $this->errors=$interface->errors; - } - // End call triggers + $result=$this->call_trigger(strtoupper($element).'_DELETE_RESOURCE', $user); + if ($result < 0) { $this->db->rollback(); return -1; } } return 1; @@ -3379,6 +3368,7 @@ function delete_resource($rowid, $element, $notrigger=0) else { $this->error=$this->db->lasterror(); + $this->db->rollback(); dol_syslog(get_class($this)."::delete_resource error=".$this->error, LOG_ERR); return -1; } @@ -3402,5 +3392,36 @@ function __clone() } } } + + /** + * Call trigger based on this instance + * + * NB: Error from trigger are stacked in errors + * NB2: if trigger fail, action should be canceled. + * + * @param string $trigger_name trigger's name to execute + * @param User $user Object user + * @return int Result of run_triggers + */ + function call_trigger($trigger_name, $user) + { + global $langs,$conf; + + include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php'; + $interface=new Interfaces($this->db); + $result=$interface->run_triggers($trigger_name,$this,$user,$langs,$conf); + if ($result < 0) { + if (!empty($this->errors)) + { + $this->errors=array_merge($this->errors,$interface->errors); + } + else + { + $this->errors=$interface->errors; + } + } + return $result; + + } }