From 32a0f4c530ecd7224c99ac283803fd3065aa2790 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Fri, 20 May 2016 20:03:29 +0200 Subject: [PATCH 1/5] Add trigger into expedition class --- htdocs/expedition/class/expedition.class.php | 24 ++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index 6d3f7b05966..fd2d7ff1777 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -1806,6 +1806,14 @@ class Expedition extends CommonObject { // TODO: Add option/checkbox to set order billed if 100% of order is shipped $this->statut=2; + + // Call trigger + $result=$this->call_trigger('SHIPPING_CLOSED',$user); + if ($result < 0) { + return -1; + } + // End call triggers + return 1; } else @@ -1831,6 +1839,15 @@ class Expedition extends CommonObject { $this->statut=2; $this->billed=1; + + // Call trigger + $result=$this->call_trigger('SHIPPING_BILLED',$user); + if ($result < 0) { + return -1; + } + // End call triggers + + return 1; } else @@ -1856,6 +1873,13 @@ class Expedition extends CommonObject { $this->statut=1; $this->billed=0; + + // Call trigger + $result=$this->call_trigger('SHIPPING_REOPENED',$user); + if ($result < 0) { + return -1; + } + return 1; } else From 82d6f4c8080dec3cdb04f2dcef959776fd4bd4fc Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Fri, 20 May 2016 20:09:30 +0200 Subject: [PATCH 2/5] add trigger on set draft order --- htdocs/commande/class/commande.class.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index a2788ba9808..30b06a351d2 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -464,6 +464,12 @@ class Commande extends CommonOrder } } + if (!$error) { + // Call trigger + $result=$this->call_trigger('ORDER_SETDRAFT',$user); + if ($result < 0) $error++; + } + if (!$error) { $this->statut=self::STATUS_DRAFT; From acdf781202054005f70634f8624561eb595c40e9 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Fri, 20 May 2016 20:12:23 +0200 Subject: [PATCH 3/5] change tirrger name to harmonised --- htdocs/expedition/class/expedition.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index fd2d7ff1777..b9aaa01b667 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -1875,7 +1875,7 @@ class Expedition extends CommonObject $this->billed=0; // Call trigger - $result=$this->call_trigger('SHIPPING_REOPENED',$user); + $result=$this->call_trigger('SHIPPING_REOPEN',$user); if ($result < 0) { return -1; } From 4e707af0fd371387ae2acf72b51cf8acb63e5638 Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Mon, 23 May 2016 09:16:47 +0200 Subject: [PATCH 4/5] Add demo information and transsaction management --- .../interface_90_all_Demo.class.php-NORUN | 4 ++ htdocs/expedition/class/expedition.class.php | 47 ++++++++++++++++--- 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN b/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN index f25a99f3b59..717ef6585f5 100644 --- a/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN +++ b/htdocs/core/triggers/interface_90_all_Demo.class.php-NORUN @@ -119,6 +119,7 @@ class InterfaceDemo extends DolibarrTriggers case 'ORDER_CANCEL': case 'ORDER_SENTBYMAIL': case 'ORDER_CLASSIFY_BILLED': + case 'ORDER_SETDRAFT': case 'LINEORDER_INSERT': case 'LINEORDER_UPDATE': case 'LINEORDER_DELETE': @@ -258,6 +259,9 @@ class InterfaceDemo extends DolibarrTriggers case 'SHIPPING_MODIFY': case 'SHIPPING_VALIDATE': case 'SHIPPING_SENTBYMAIL': + case 'SHIPPING_BILLED': + case 'SHIPPING_CLOSED': + case 'SHIPPING_REOPEN': case 'SHIPPING_DELETE': dol_syslog("Trigger '".$this->name."' for action '$action' launched by ".__FILE__.". id=".$object->id); break; diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index b9aaa01b667..b2f5d4bde40 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -1798,6 +1798,10 @@ class Expedition extends CommonObject function setClosed() { + $error=0; + + $this->db->begin(); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=2'; $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0'; @@ -1810,15 +1814,23 @@ class Expedition extends CommonObject // Call trigger $result=$this->call_trigger('SHIPPING_CLOSED',$user); if ($result < 0) { - return -1; + $error++; } - // End call triggers + } else { + $error++; + $this->errors[]=$this->db->lasterror; + } + + if (empty($error)) { + $this->db->commit(); return 1; } else { + $this->db->rollback(); dol_print_error($this->db); + return -1; } } @@ -1830,6 +1842,9 @@ class Expedition extends CommonObject */ function set_billed() { + $error=0; + + $this->db->begin(); $sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=2, billed=1'; // TODO Update only billed $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0'; @@ -1843,16 +1858,23 @@ class Expedition extends CommonObject // Call trigger $result=$this->call_trigger('SHIPPING_BILLED',$user); if ($result < 0) { - return -1; + $error++; } - // End call triggers - + } else { + $error++; + $this->errors[]=$this->db->lasterror; + } + + if (empty($error)) { + $this->db->commit(); return 1; } else { + $this->db->rollback(); dol_print_error($this->db); + return -1; } } @@ -1865,6 +1887,10 @@ class Expedition extends CommonObject function reOpen() { + $error=0; + + $this->db->begin(); + $sql = 'UPDATE '.MAIN_DB_PREFIX.'expedition SET fk_statut=1'; $sql .= ' WHERE rowid = '.$this->id.' AND fk_statut > 0'; @@ -1877,14 +1903,23 @@ class Expedition extends CommonObject // Call trigger $result=$this->call_trigger('SHIPPING_REOPEN',$user); if ($result < 0) { - return -1; + $error++; } + } else { + $error++; + $this->errors[]=$this->db->lasterror; + } + + if (empty($error)) { + $this->db->commit(); return 1; } else { + $this->db->rollback(); dol_print_error($this->db); + return -1; } } From 37d366478ff5dbcd4b134ba300bb0ba8944b9e4a Mon Sep 17 00:00:00 2001 From: florian HENRY Date: Mon, 23 May 2016 14:18:29 +0200 Subject: [PATCH 5/5] change trigger position --- htdocs/commande/class/commande.class.php | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/htdocs/commande/class/commande.class.php b/htdocs/commande/class/commande.class.php index f89d7d5d5a2..44f14bb09e5 100644 --- a/htdocs/commande/class/commande.class.php +++ b/htdocs/commande/class/commande.class.php @@ -464,12 +464,6 @@ class Commande extends CommonOrder } } - if (!$error) { - // Call trigger - $result=$this->call_trigger('ORDER_SETDRAFT',$user); - if ($result < 0) $error++; - } - if (!$error) { $this->statut=self::STATUS_DRAFT; @@ -484,9 +478,20 @@ class Commande extends CommonOrder } } - $this->statut=self::STATUS_DRAFT; - $this->db->commit(); - return 1; + if (!$error) { + // Call trigger + $result=$this->call_trigger('ORDER_SETDRAFT',$user); + if ($result < 0) $error++; + } + + if (!$error) { + $this->statut=self::STATUS_DRAFT; + $this->db->commit(); + return 1; + }else { + $this->db->rollback(); + return -1; + } } else {