From 6f248a6590784489904f49f2e44c4975ef210dec Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Sat, 20 Jan 2018 16:40:56 +0100 Subject: [PATCH 1/3] New allow to define order min amount --- htdocs/comm/card.php | 19 ++++++++++++ htdocs/fourn/card.php | 19 ++++++++++++ .../install/mysql/migration/7.0.0-8.0.0.sql | 29 +++++++++++++++++++ htdocs/install/mysql/tables/llx_societe.sql | 2 ++ htdocs/societe/class/societe.class.php | 10 +++++++ 5 files changed, 79 insertions(+) create mode 100644 htdocs/install/mysql/migration/7.0.0-8.0.0.sql diff --git a/htdocs/comm/card.php b/htdocs/comm/card.php index 8fb590d61b4..ee05d0a2456 100644 --- a/htdocs/comm/card.php +++ b/htdocs/comm/card.php @@ -176,6 +176,15 @@ if (empty($reshook)) $result=$object->update($object->id, $user); if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); } + + // update order min amount + if ($action == 'setorder_min_amount') + { + $object->fetch($id); + $object->order_min_amount=GETPOST('order_min_amount'); + $result=$object->update($object->id, $user); + if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); + } if ($action == 'update_extras') { $object->fetch($id); @@ -401,9 +410,19 @@ if ($id > 0) print $form->editfieldval("OutstandingBill",'outstanding_limit',$object->outstanding_limit,$object,$user->rights->societe->creer,$limit_field_type,($object->outstanding_limit != '' ? price($object->outstanding_limit) : '')); //if (empty($object->outstanding_limit)) print $langs->trans("NoLimit"); + print ''; + print ''; + + print ''; + print ''; + print $form->editfieldkey("OrderMinAmount",'order_min_amount',$object->order_min_amount,$object,$user->rights->societe->creer); + print ''; + print $form->editfieldval("OrderMinAmount",'order_min_amount',$object->order_min_amount,$object,$user->rights->societe->creer,$limit_field_type,($object->order_min_amount != '' ? price($object->order_min_amount) : '')); + print ''; print ''; } + // Multiprice level if (! empty($conf->global->PRODUIT_MULTIPRICES)) diff --git a/htdocs/fourn/card.php b/htdocs/fourn/card.php index 6f473f8deb3..9856b4f95b2 100644 --- a/htdocs/fourn/card.php +++ b/htdocs/fourn/card.php @@ -101,6 +101,15 @@ if (empty($reshook)) $result=$object->setPaymentMethods(GETPOST('mode_reglement_supplier_id','int')); if ($result < 0) dol_print_error($db,$object->error); } + + // update supplier order min amount + if ($action == 'setsupplier_order_min_amount') + { + $object->fetch($id); + $object->supplier_order_min_amount=GETPOST('supplier_order_min_amount'); + $result=$object->update($object->id, $user); + if ($result < 0) setEventMessages($object->error, $object->errors, 'errors'); + } } @@ -230,6 +239,16 @@ if ($object->id > 0) } print ""; print ''; + + print ''; + print ''; + print $form->editfieldkey("OrderMinAmount",'supplier_order_min_amount',$object->supplier_order_min_amount,$object,$user->rights->societe->creer); + print ''; + $limit_field_type = (! empty($conf->global->MAIN_USE_JQUERY_JEDITABLE)) ? 'numeric' : 'amount'; + print $form->editfieldval("OrderMinAmount",'supplier_order_min_amount',$object->supplier_order_min_amount,$object,$user->rights->societe->creer,$limit_field_type,($object->supplier_order_min_amount != '' ? price($object->supplier_order_min_amount) : '')); + + print ''; + print ''; // Categories if (! empty($conf->categorie->enabled)) diff --git a/htdocs/install/mysql/migration/7.0.0-8.0.0.sql b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql new file mode 100644 index 00000000000..dd549e684f2 --- /dev/null +++ b/htdocs/install/mysql/migration/7.0.0-8.0.0.sql @@ -0,0 +1,29 @@ +-- +-- Be carefull to requests order. +-- This file must be loaded by calling /install/index.php page +-- when current version is 8.0.0 or higher. +-- +-- To rename a table: ALTER TABLE llx_table RENAME TO llx_table_new; +-- To add a column: ALTER TABLE llx_table ADD COLUMN newcol varchar(60) NOT NULL DEFAULT '0' AFTER existingcol; +-- To rename a column: ALTER TABLE llx_table CHANGE COLUMN oldname newname varchar(60); +-- To drop a column: ALTER TABLE llx_table DROP COLUMN oldname; +-- To change type of field: ALTER TABLE llx_table MODIFY COLUMN name varchar(60); +-- To drop a foreign key: ALTER TABLE llx_table DROP FOREIGN KEY fk_name; +-- To drop an index: -- VMYSQL4.0 DROP INDEX nomindex on llx_table +-- To drop an index: -- VPGSQL8.0 DROP INDEX nomindex +-- To restrict request to Mysql version x.y minimum use -- VMYSQLx.y +-- To restrict request to Pgsql version x.y minimum use -- VPGSQLx.y +-- To make pk to be auto increment (mysql): -- VMYSQL4.3 ALTER TABLE llx_c_shipment_mode CHANGE COLUMN rowid rowid INTEGER NOT NULL AUTO_INCREMENT; +-- To make pk to be auto increment (postgres): -- VPGSQL8.2 NOT POSSIBLE. MUST DELETE/CREATE TABLE +-- To set a field as NULL: -- VMYSQL4.3 ALTER TABLE llx_table MODIFY COLUMN name varchar(60) NULL; +-- To set a field as NULL: -- VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name DROP NOT NULL; +-- To set a field as NOT NULL: -- VMYSQL4.3 ALTER TABLE llx_table MODIFY COLUMN name varchar(60) NOT NULL; +-- To set a field as NOT NULL: -- VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name SET NOT NULL; +-- To set a field as default NULL: -- VPGSQL8.2 ALTER TABLE llx_table ALTER COLUMN name SET DEFAULT NULL; +-- Note: fields with type BLOB/TEXT can't have default value. +-- -- VPGSQL8.2 DELETE FROM llx_usergroup_user WHERE fk_user NOT IN (SELECT rowid from llx_user); +-- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup); + + +ALTER TABLE llx_societe ADD COLUMN order_min_amount double(24,8) DEFAULT NULL AFTER outstanding_limit; +ALTER TABLE llx_societe ADD COLUMN supplier_order_min_amount double(24,8) DEFAULT NULL AFTER order_min_amount; \ No newline at end of file diff --git a/htdocs/install/mysql/tables/llx_societe.sql b/htdocs/install/mysql/tables/llx_societe.sql index c23ca3a183c..0556f77b951 100644 --- a/htdocs/install/mysql/tables/llx_societe.sql +++ b/htdocs/install/mysql/tables/llx_societe.sql @@ -96,6 +96,8 @@ create table llx_societe fk_barcode_type integer NULL DEFAULT 0, -- barcode type price_level integer NULL, -- level of price for multiprices outstanding_limit double(24,8) DEFAULT NULL, -- allowed outstanding limit + order_min_amount double(24,8) DEFAULT NULL, -- min amount for orders + supplier_order_min_amount double(24,8) DEFAULT NULL, -- min amount for supplier orders default_lang varchar(6), -- default language logo varchar(255) DEFAULT NULL, canvas varchar(32) DEFAULT NULL, -- type of canvas if used (null by default) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index cd4b66a23a1..dc91e7f668c 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -334,6 +334,12 @@ class Societe extends CommonObject */ var $price_level; var $outstanding_limit; + + /** + * Min order amounts + */ + var $order_min_amount; + var $supplier_order_min_amount; /** * Id of sales representative to link (used for thirdparty creation). Not filled by a fetch, because we can have several sales representatives. @@ -785,6 +791,8 @@ class Societe extends CommonObject $this->idprof6 = (! empty($this->idprof6)?trim($this->idprof6):''); $this->prefix_comm = trim($this->prefix_comm); $this->outstanding_limit = price2num($this->outstanding_limit); + $this->order_min_amount = price2num($this->order_min_amount); + $this->supplier_order_min_amount = price2num($this->supplier_order_min_amount); $this->tva_assuj = trim($this->tva_assuj); $this->tva_intra = dol_sanitizeFileName($this->tva_intra,''); @@ -955,6 +963,8 @@ class Societe extends CommonObject $sql .= ",default_lang = ".(! empty($this->default_lang)?"'".$this->db->escape($this->default_lang)."'":"null"); $sql .= ",logo = ".(! empty($this->logo)?"'".$this->db->escape($this->logo)."'":"null"); $sql .= ",outstanding_limit= ".($this->outstanding_limit!=''?$this->outstanding_limit:'null'); + $sql .= ",order_min_amount= ".($this->order_min_amount!=''?$this->order_min_amount:'null'); + $sql .= ",supplier_order_min_amount= ".($this->supplier_order_min_amount!=''?$this->supplier_order_min_amount:'null'); $sql .= ",fk_prospectlevel='".$this->db->escape($this->fk_prospectlevel)."'"; $sql .= ",webservices_url = ".(! empty($this->webservices_url)?"'".$this->db->escape($this->webservices_url)."'":"null"); From 9899a026302a211837f36fbe2f09cbe92a1374f9 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Sat, 20 Jan 2018 20:11:30 +0100 Subject: [PATCH 2/3] Display alert if order total is under order min amount --- htdocs/commande/card.php | 6 +++++- htdocs/fourn/commande/card.php | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/htdocs/commande/card.php b/htdocs/commande/card.php index 2d4d138f61a..1c236eda1dd 100644 --- a/htdocs/commande/card.php +++ b/htdocs/commande/card.php @@ -2388,8 +2388,12 @@ if ($action == 'create' && $user->rights->commande->creer) } // Total HT + $alert = ''; + if($object->total_ht < $object->thirdparty->order_min_amount) { + $alert = ' ' . img_warning($langs->trans('OrderMinAmount').': '.price($object->thirdparty->order_min_amount)); + } print '' . $langs->trans('AmountHT') . ''; - print '' . price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency) . ''; + print '' . price($object->total_ht, 1, '', 1, - 1, - 1, $conf->currency) . $alert . ''; // Total VAT print '' . $langs->trans('AmountVAT') . '' . price($object->total_tva, 1, '', 1, - 1, - 1, $conf->currency) . ''; diff --git a/htdocs/fourn/commande/card.php b/htdocs/fourn/commande/card.php index 617039f25da..81ea1a0f951 100644 --- a/htdocs/fourn/commande/card.php +++ b/htdocs/fourn/commande/card.php @@ -2052,8 +2052,12 @@ elseif (! empty($object->id)) } // Total + $alert = ''; + if($object->total_ht < $object->thirdparty->supplier_order_min_amount) { + $alert = ' ' . img_warning($langs->trans('OrderMinAmount').': '.price($object->thirdparty->supplier_order_min_amount)); + } print ''.$langs->trans("AmountHT").''; - print ''.price($object->total_ht,'',$langs,1,-1,-1,$conf->currency).''; + print ''.price($object->total_ht,'',$langs,1,-1,-1,$conf->currency).$alert.''; print ''; // Total VAT From 53e6da8c7c32ad21b7e816a54034cb763c4e3bdf Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Sat, 20 Jan 2018 21:57:36 +0100 Subject: [PATCH 3/3] Missing fetch and translation --- htdocs/langs/en_US/companies.lang | 1 + htdocs/societe/class/societe.class.php | 3 +++ 2 files changed, 4 insertions(+) diff --git a/htdocs/langs/en_US/companies.lang b/htdocs/langs/en_US/companies.lang index 7cff22df092..04528266b64 100644 --- a/htdocs/langs/en_US/companies.lang +++ b/htdocs/langs/en_US/companies.lang @@ -405,6 +405,7 @@ ProductsIntoElements=List of products/services into %s CurrentOutstandingBill=Current outstanding bill OutstandingBill=Max. for outstanding bill OutstandingBillReached=Max. for outstanding bill reached +OrderMinAmount=Minimum amount for order MonkeyNumRefModelDesc=Return numero with format %syymm-nnnn for customer code and %syymm-nnnn for supplier code where yy is year, mm is month and nnnn is a sequence with no break and no return to 0. LeopardNumRefModelDesc=The code is free. This code can be modified at any time. ManagingDirectors=Manager(s) name (CEO, director, president...) diff --git a/htdocs/societe/class/societe.class.php b/htdocs/societe/class/societe.class.php index dc91e7f668c..675dd2a3123 100644 --- a/htdocs/societe/class/societe.class.php +++ b/htdocs/societe/class/societe.class.php @@ -1142,6 +1142,7 @@ class Societe extends CommonObject $sql .= ', s.mode_reglement_supplier, s.cond_reglement_supplier, s.localtax1_assuj, s.localtax1_value, s.localtax2_assuj, s.localtax2_value, s.fk_prospectlevel, s.default_lang, s.logo'; $sql .= ', s.fk_shipping_method'; $sql .= ', s.outstanding_limit, s.import_key, s.canvas, s.fk_incoterms, s.location_incoterms'; + $sql .= ', s.order_min_amount, s.supplier_order_min_amount'; $sql .= ', s.fk_multicurrency, s.multicurrency_code'; $sql .= ', fj.libelle as forme_juridique'; $sql .= ', e.libelle as effectif'; @@ -1289,6 +1290,8 @@ class Societe extends CommonObject $this->webservices_key = $obj->webservices_key; $this->outstanding_limit = $obj->outstanding_limit; + $this->order_min_amount = $obj->order_min_amount; + $this->supplier_order_min_amount = $obj->supplier_order_min_amount; // multiprix $this->price_level = $obj->price_level;