From 66ea799eb7de0dd3e7fd9f6246acc66a86c55448 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Tue, 26 Apr 2016 13:27:32 +0200 Subject: [PATCH] Uniformize code and add more comment to understand workflow --- htdocs/expedition/card.php | 16 ++++++++-- htdocs/expedition/class/expedition.class.php | 31 +++++++++++++++++-- .../install/mysql/migration/3.9.0-4.0.0.sql | 2 ++ .../install/mysql/tables/llx_expedition.sql | 5 +-- 4 files changed, 46 insertions(+), 8 deletions(-) diff --git a/htdocs/expedition/card.php b/htdocs/expedition/card.php index 867ea7a7245..c52c72ff509 100644 --- a/htdocs/expedition/card.php +++ b/htdocs/expedition/card.php @@ -533,6 +533,12 @@ if (empty($reshook)) $object->set_billed(); } + elseif ($action == 'classifyclosed') + { + $object->fetch($id); + $object->setClosed(); + } + include DOL_DOCUMENT_ROOT.'/core/actions_printing.inc.php'; // Actions to send emails @@ -1780,10 +1786,14 @@ else if ($id || $ref) { if ($user->rights->expedition->creer && $object->statut > 0 && ! $object->billed) { - $label="Close"; // = Transferred/Received + $label="Close"; $paramaction='classifyclosed'; // = Transferred/Received // Label here should be "Close" or "ClassifyBilled" if we decided to make bill on shipments instead of orders - if (! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) $label="ClassifyBilled"; - print ''.$langs->trans($label).''; + if (! empty($conf->global->WORKFLOW_BILL_ON_SHIPMENT)) // TODO Quand l'option est on, il faut avoir le bouton en plus et non en remplacement du Close. + { + $label="ClassifyBilled"; + $paramaction='classifybilled'; + } + print ''.$langs->trans($label).''; } } diff --git a/htdocs/expedition/class/expedition.class.php b/htdocs/expedition/class/expedition.class.php index a0ba1567c24..0024c1a9375 100644 --- a/htdocs/expedition/class/expedition.class.php +++ b/htdocs/expedition/class/expedition.class.php @@ -1795,11 +1795,11 @@ class Expedition extends CommonObject } /** - * Classify the shipping as invoiced + * Classify the shipping as closed * * @return int <0 if ko, >0 if ok */ - function set_billed() + function setClosed() { global $conf; @@ -1809,7 +1809,32 @@ class Expedition extends CommonObject $resql=$this->db->query($sql); if ($resql) { - //TODO: Add option/checkbox to set order billed if 100% of order is shipped + // TODO: Add option/checkbox to set order billed if 100% of order is shipped + $this->statut=2; + return 1; + } + else + { + dol_print_error($this->db); + return -1; + } + } + + /** + * Classify the shipping as invoiced (used when WORKFLOW_BILL_ON_SHIPMENT is on) + * + * @return int <0 if ko, >0 if ok + */ + function set_billed() + { + global $conf; + + $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'; + + $resql=$this->db->query($sql); + if ($resql) + { $this->statut=2; $this->billed=1; return 1; diff --git a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql index 002930c276c..832107e7f6f 100644 --- a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql +++ b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql @@ -36,6 +36,8 @@ ALTER TABLE llx_product_customer_price_log ADD COLUMN localtax1_type varchar(10) ALTER TABLE llx_product_customer_price_log ADD COLUMN localtax2_type varchar(10) NOT NULL DEFAULT '0' after localtax2_tx; +ALTER TABLE llx_expedition ADD COLUMN billed smallint DEFAULT 0; + CREATE TABLE llx_product_lot ( rowid integer AUTO_INCREMENT PRIMARY KEY, tms timestamp, diff --git a/htdocs/install/mysql/tables/llx_expedition.sql b/htdocs/install/mysql/tables/llx_expedition.sql index 8421bb1649c..12dba35f89d 100644 --- a/htdocs/install/mysql/tables/llx_expedition.sql +++ b/htdocs/install/mysql/tables/llx_expedition.sql @@ -40,8 +40,9 @@ create table llx_expedition fk_address integer DEFAULT NULL, -- delivery address (deprecated) fk_shipping_method integer, tracking_number varchar(50), - fk_statut smallint DEFAULT 0, - + fk_statut smallint DEFAULT 0, -- 0 = draft, 1 = validated, 2 = billed or closed depending on WORKFLOW_BILL_ON_SHIPMENT option + billed smallint DEFAULT 0, + height float, -- height width float, -- with size_units integer, -- unit of all sizes (height, width, depth)