From 504cc890784cc9f4ac2dfd4cf4a73cf2e5ba8e89 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Fri, 20 Feb 2015 09:24:33 +0100 Subject: [PATCH 01/11] New : replenish function adds new lines into already existing draft supplier order instead of creating a new supplier order --- htdocs/product/stock/replenish.php | 66 +++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 15 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 35835709ab8..6bcabecbe9d 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -148,22 +148,58 @@ if ($action == 'order' && isset($_POST['valid'])) foreach ($suppliers as $supplier) { $order = new CommandeFournisseur($db); - $order->socid = $suppliersid[$i]; - //trick to know which orders have been generated this way - $order->source = 42; - foreach ($supplier['lines'] as $line) { - $order->lines[] = $line; + // Check if an order for the supplier exists + $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande_fournisseur"; + $sql.= " WHERE fk_soc = ".$suppliersid[$i]; + $sql.= " AND source = 42 AND fk_statut = 0"; + $sql.= " ORDER BY date_creation DESC"; + $resql = $db->query($sql); + if($resql && $db->num_rows($resql) > 0) { + $obj = $db->fetch_object($resql); + $order->fetch($obj->rowid); + foreach ($supplier['lines'] as $line) { + $result = $order->addline( + $line->desc, + $line->subprice, + $line->qty, + $line->tva_tx, + $line->localtax1_tx, + $line->localtax2_tx, + $line->fk_product, + 0, + $line->ref_fourn, + $line->remise_percent, + 'HT', + 0, + $line->info_bits + ); + } + if ($result < 0) { + $fail++; + $msg = $langs->trans('OrderFail') . " : "; + $msg .= $order->error; + setEventMessage($msg, 'errors'); + } else { + $id = $result; + } + } else { + $order->socid = $suppliersid[$i]; + //trick to know which orders have been generated this way + $order->source = 42; + foreach ($supplier['lines'] as $line) { + $order->lines[] = $line; + } + $order->cond_reglement_id = 0; + $order->mode_reglement_id = 0; + $id = $order->create($user); + if ($id < 0) { + $fail++; + $msg = $langs->trans('OrderFail') . " : "; + $msg .= $order->error; + setEventMessage($msg, 'errors'); + } + $i++; } - $order->cond_reglement_id = 0; - $order->mode_reglement_id = 0; - $id = $order->create($user); - if ($id < 0) { - $fail++; - $msg = $langs->trans('OrderFail') . " : "; - $msg .= $order->error; - setEventMessage($msg, 'errors'); - } - $i++; } if (! $fail && $id) From 2547d96ffd7e88ded871cb22420585f8b84de9eb Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Fri, 20 Feb 2015 09:26:53 +0100 Subject: [PATCH 02/11] New : Use supplier default payment terms when creating a replenish order --- htdocs/product/stock/replenish.php | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php index 6bcabecbe9d..3c8f3746c45 100644 --- a/htdocs/product/stock/replenish.php +++ b/htdocs/product/stock/replenish.php @@ -184,13 +184,14 @@ if ($action == 'order' && isset($_POST['valid'])) } } else { $order->socid = $suppliersid[$i]; + $order->fetch_thirdparty(); //trick to know which orders have been generated this way $order->source = 42; foreach ($supplier['lines'] as $line) { $order->lines[] = $line; } - $order->cond_reglement_id = 0; - $order->mode_reglement_id = 0; + $order->cond_reglement_id = $order->thirdparty->cond_reglement_supplier_id; + $order->mode_reglement_id = $order->thirdparty->mode_reglement_supplier_id; $id = $order->create($user); if ($id < 0) { $fail++; From db4bbf46fc98a42b7007564bab4c165ecb6229cc Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Tue, 10 Mar 2015 14:43:13 +0100 Subject: [PATCH 03/11] New : allow to edit social contribution amount --- htdocs/compta/sociales/charges.php | 77 +++++++++++-------- .../sociales/class/chargesociales.class.php | 3 +- 2 files changed, 49 insertions(+), 31 deletions(-) diff --git a/htdocs/compta/sociales/charges.php b/htdocs/compta/sociales/charges.php index afe2c27a3be..a7a9e76a78b 100644 --- a/htdocs/compta/sociales/charges.php +++ b/htdocs/compta/sociales/charges.php @@ -77,8 +77,10 @@ if ($action == 'confirm_delete' && $confirm == 'yes') // Add social contribution if ($action == 'add' && $user->rights->tax->charges->creer) { - $dateech=@dol_mktime($_POST["echhour"],$_POST["echmin"],$_POST["echsec"],$_POST["echmonth"],$_POST["echday"],$_POST["echyear"]); - $dateperiod=@dol_mktime($_POST["periodhour"],$_POST["periodmin"],$_POST["periodsec"],$_POST["periodmonth"],$_POST["periodday"],$_POST["periodyear"]); + $dateech=@dol_mktime(GETPOST('echhour'),GETPOST('echmin'),GETPOST('echsec'),GETPOST('echmonth'),GETPOST('echday'),GETPOST('echyear')); + $dateperiod=@dol_mktime(GETPOST('periodhour'),GETPOST('periodmin'),GETPOST('periodsec'),GETPOST('periodmonth'),GETPOST('periodday'),GETPOST('periodyear')); + $amount=GETPOST('amount'); + $actioncode=GETPOST('actioncode'); if (! $dateech) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")), 'errors'); @@ -89,12 +91,12 @@ if ($action == 'add' && $user->rights->tax->charges->creer) setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")), 'errors'); $action = 'create'; } - elseif (! $_POST["actioncode"] > 0) + elseif (! $actioncode > 0) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Type")), 'errors'); $action = 'create'; } - elseif (! $_POST["amount"]) + elseif (empty($amount)) { setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount")), 'errors'); $action = 'create'; @@ -103,11 +105,11 @@ if ($action == 'add' && $user->rights->tax->charges->creer) { $chargesociales=new ChargeSociales($db); - $chargesociales->type=$_POST["actioncode"]; - $chargesociales->lib=$_POST["label"]; + $chargesociales->type=$actioncode; + $chargesociales->lib=GETPOST('label'); $chargesociales->date_ech=$dateech; $chargesociales->periode=$dateperiod; - $chargesociales->amount=$_POST["amount"]; + $chargesociales->amount=price2num($amount); $id=$chargesociales->create($user); if ($id <= 0) @@ -120,32 +122,39 @@ if ($action == 'add' && $user->rights->tax->charges->creer) if ($action == 'update' && ! $_POST["cancel"] && $user->rights->tax->charges->creer) { - $dateech=dol_mktime($_POST["echhour"],$_POST["echmin"],$_POST["echsec"],$_POST["echmonth"],$_POST["echday"],$_POST["echyear"]); - $dateperiod=dol_mktime($_POST["periodhour"],$_POST["periodmin"],$_POST["periodsec"],$_POST["periodmonth"],$_POST["periodday"],$_POST["periodyear"]); - if (! $dateech) - { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")), 'errors'); - $action = 'edit'; - } - elseif (! $dateperiod) - { - setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")), 'errors'); - $action = 'edit'; - } + $dateech=dol_mktime(GETPOST('echhour'),GETPOST('echmin'),GETPOST('echsec'),GETPOST('echmonth'),GETPOST('echday'),GETPOST('echyear')); + $dateperiod=dol_mktime(GETPOST('periodhour'),GETPOST('periodmin'),GETPOST('periodsec'),GETPOST('periodmonth'),GETPOST('periodday'),GETPOST('periodyear')); + $amount=GETPOST('amount'); + if (! $dateech) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("DateDue")), 'errors'); + $action = 'edit'; + } + elseif (! $dateperiod) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Period")), 'errors'); + $action = 'edit'; + } + elseif (empty($amount)) + { + setEventMessage($langs->trans("ErrorFieldRequired",$langs->transnoentities("Amount")), 'errors'); + $action = 'edit'; + } else { - $chargesociales=new ChargeSociales($db); - $result=$chargesociales->fetch($_GET["id"]); + $chargesociales=new ChargeSociales($db); + $result=$chargesociales->fetch($id); - $chargesociales->lib=$_POST["label"]; - $chargesociales->date_ech=$dateech; - $chargesociales->periode=$dateperiod; + $chargesociales->lib=GETPOST('label'); + $chargesociales->date_ech=$dateech; + $chargesociales->periode=$dateperiod; + $chargesociales->amount=price2num($amount); - $result=$chargesociales->update($user); - if ($result <= 0) - { - setEventMessage($chargesociales->error, 'errors'); - } + $result=$chargesociales->update($user); + if ($result <= 0) + { + setEventMessage($chargesociales->error, 'errors'); + } } } @@ -437,7 +446,15 @@ if ($id > 0) } // Amount - print ''.$langs->trans("AmountTTC").''.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).''; + if ($action == 'edit') + { + print ''.$langs->trans("AmountTTC").""; + print ''; + print ""; + } + else { + print ''.$langs->trans("AmountTTC").''.price($object->amount,0,$outputlangs,1,-1,-1,$conf->currency).''; + } // Status print ''.$langs->trans("Status").''.$object->getLibStatut(4, $totalpaye).''; diff --git a/htdocs/compta/sociales/class/chargesociales.class.php b/htdocs/compta/sociales/class/chargesociales.class.php index 96f55ce34ba..6f68e76303c 100644 --- a/htdocs/compta/sociales/class/chargesociales.class.php +++ b/htdocs/compta/sociales/class/chargesociales.class.php @@ -266,7 +266,8 @@ class ChargeSociales extends CommonObject $sql = "UPDATE ".MAIN_DB_PREFIX."chargesociales"; $sql.= " SET libelle='".$this->db->escape($this->lib)."',"; $sql.= " date_ech='".$this->db->idate($this->date_ech)."',"; - $sql.= " periode='".$this->db->idate($this->periode)."'"; + $sql.= " periode='".$this->db->idate($this->periode)."',"; + $sql.= " amount='".price2num($this->amount,'MT')."'"; $sql.= " WHERE rowid=".$this->id; dol_syslog(get_class($this)."::update", LOG_DEBUG); From f90df57dc567d67c6ac341d57d94d839ae0b9007 Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Tue, 10 Mar 2015 14:49:36 +0100 Subject: [PATCH 04/11] New : disallow social contribution modification if paid --- htdocs/compta/sociales/charges.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/htdocs/compta/sociales/charges.php b/htdocs/compta/sociales/charges.php index a7a9e76a78b..251bd6f7f6a 100644 --- a/htdocs/compta/sociales/charges.php +++ b/htdocs/compta/sociales/charges.php @@ -483,7 +483,7 @@ if ($id > 0) print "
\n"; // Edit - if ($user->rights->tax->charges->creer) + if ($object->paye == 0 && $user->rights->tax->charges->creer) { print "id&action=edit\">".$langs->trans("Modify").""; } @@ -517,7 +517,7 @@ if ($id > 0) } else { - /* Charge non trouv� */ + /* Social contribution not found */ dol_print_error('',$object->error); } } From 6113a5b0f50b87e4fc4ac3a4c09e52c12055b28d Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Tue, 10 Mar 2015 15:27:36 +0100 Subject: [PATCH 05/11] FIX : [bug #1883] missing field in SQL installation --- htdocs/install/mysql/tables/llx_product_fournisseur_price.sql | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/htdocs/install/mysql/tables/llx_product_fournisseur_price.sql b/htdocs/install/mysql/tables/llx_product_fournisseur_price.sql index f3905ab4fbe..fb5184715d1 100755 --- a/htdocs/install/mysql/tables/llx_product_fournisseur_price.sql +++ b/htdocs/install/mysql/tables/llx_product_fournisseur_price.sql @@ -40,5 +40,6 @@ create table llx_product_fournisseur_price info_bits integer NOT NULL DEFAULT 0, fk_user integer, fk_supplier_price_expression integer, -- Link to the rule for dynamic price calculation - import_key varchar(14) -- Import key + import_key varchar(14), -- Import key + delivery_time_days integer )ENGINE=innodb; From fa628bba6f92cae12e0e7ec7f34a050097eafedc Mon Sep 17 00:00:00 2001 From: Maxime Kohlhaas Date: Tue, 10 Mar 2015 15:34:48 +0100 Subject: [PATCH 06/11] Fix SQL error when installing --- htdocs/install/mysql/tables/llx_projet_task_time.sql | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/install/mysql/tables/llx_projet_task_time.sql b/htdocs/install/mysql/tables/llx_projet_task_time.sql index d58b35146a7..6c34440a58b 100644 --- a/htdocs/install/mysql/tables/llx_projet_task_time.sql +++ b/htdocs/install/mysql/tables/llx_projet_task_time.sql @@ -22,7 +22,7 @@ create table llx_projet_task_time fk_task integer NOT NULL, task_date date, -- only the day task_datehour datetime, -- day + hour - task_date_withhour integer DEFAULT 0; -- 0 by default, 1 if date was entered with start hour + task_date_withhour integer DEFAULT 0, -- 0 by default, 1 if date was entered with start hour task_duration double, fk_user integer, thm double(24,8), From 41a05bc4bad8260d01796beecadeae92e80cc40a Mon Sep 17 00:00:00 2001 From: BENKE Charles Date: Sat, 14 Mar 2015 12:04:00 +0100 Subject: [PATCH 07/11] Update actions_extrafields.inc.php add new type of extrafields "link" : linked to dolibarr element --- htdocs/core/actions_extrafields.inc.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/htdocs/core/actions_extrafields.inc.php b/htdocs/core/actions_extrafields.inc.php index d5f8ea7c18c..03d724b9bba 100644 --- a/htdocs/core/actions_extrafields.inc.php +++ b/htdocs/core/actions_extrafields.inc.php @@ -80,6 +80,13 @@ if ($action == 'add') $mesg[]=$langs->trans("ErrorNoValueForCheckBoxType"); $action = 'create'; } + if (GETPOST('type')=='link' && !GETPOST('param')) + { + $error++; + $langs->load("errors"); + $mesg[]=$langs->trans("ErrorNoValueForLinkType"); + $action = 'create'; + } if (GETPOST('type')=='radio' && !GETPOST('param')) { $error++; From df9f822a705968e57349ad487eab910dfeabfa16 Mon Sep 17 00:00:00 2001 From: BENKE Charles Date: Sat, 14 Mar 2015 12:25:17 +0100 Subject: [PATCH 08/11] Update commonobject.class.php new extafields type --- htdocs/core/class/commonobject.class.php | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/htdocs/core/class/commonobject.class.php b/htdocs/core/class/commonobject.class.php index 36101e4b081..a316c3cd511 100644 --- a/htdocs/core/class/commonobject.class.php +++ b/htdocs/core/class/commonobject.class.php @@ -3624,6 +3624,7 @@ abstract class CommonObject $attributeType = $extrafields->attribute_type[$attributeKey]; $attributeSize = $extrafields->attribute_size[$attributeKey]; $attributeLabel = $extrafields->attribute_label[$attributeKey]; + $attributeParam = $extrafields->attribute_param[$attributeKey]; switch ($attributeType) { case 'int': @@ -3646,6 +3647,19 @@ abstract class CommonObject case 'datetime': $this->array_options[$key]=$this->db->idate($this->array_options[$key]); break; + case 'link': + $param_list=array_keys($attributeParam ['options']); + // 0 : ObjectName + // 1 : classPath + $InfoFieldList = explode(":", $param_list[0]); + dol_include_once($InfoFieldList[1]); + $object = new $InfoFieldList[0]($this->db); + if ($value) + { + $object->fetch(0,$value); + $this->array_options[$key]=$object->id; + } + break; } } $this->db->begin(); From 0aa236069193adc9e0704153ed25edaafd80c7f2 Mon Sep 17 00:00:00 2001 From: BENKE Charles Date: Sat, 14 Mar 2015 12:31:22 +0100 Subject: [PATCH 09/11] Update extrafields.class.php add new extrafields type 'link' --- htdocs/core/class/extrafields.class.php | 36 +++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/htdocs/core/class/extrafields.class.php b/htdocs/core/class/extrafields.class.php index 7bebeb0b660..361c14319eb 100644 --- a/htdocs/core/class/extrafields.class.php +++ b/htdocs/core/class/extrafields.class.php @@ -6,6 +6,7 @@ * Copyright (C) 2009-2012 Laurent Destailleur * Copyright (C) 2009-2012 Regis Houssin * Copyright (C) 2013 Florian Henry + * Copyright (C) 2015 Charles-Fr 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 @@ -77,6 +78,7 @@ class ExtraFields 'checkbox' => 'ExtrafieldCheckBox', 'radio' => 'ExtrafieldRadio', 'chkbxlst' => 'ExtrafieldCheckBoxFromList', + 'link' => 'ExtrafieldLink', ); /** @@ -187,6 +189,9 @@ class ExtraFields } elseif (($type=='select') || ($type=='sellist') || ($type=='radio') ||($type=='checkbox') ||($type=='chkbxlst')){ $typedb='text'; $lengthdb=''; + } elseif ($type=='link') { + $typedb='int'; + $lengthdb='11'; } else { $typedb=$type; $lengthdb=$length; @@ -404,6 +409,9 @@ class ExtraFields } elseif (($type=='select') || ($type=='sellist') || ($type=='radio') || ($type=='checkbox') || ($type=='chkbxlst')) { $typedb='text'; $lengthdb=''; + } elseif ($type=='link') { + $typedb='int'; + $lengthdb='11'; } else { $typedb=$type; $lengthdb=$length; @@ -1043,6 +1051,19 @@ class ExtraFields } $out .= ''; } + elseif ($type == 'link') + { + $out=''; + $param_list=array_keys($param['options']); + // 0 : ObjectName + // 1 : classPath + $InfoFieldList = explode(":", $param_list[0]); + dol_include_once($InfoFieldList[1]); + $object = new $InfoFieldList[0]($this->db); + $object->fetch($value); + $out=''; + + } /* Add comments if ($type == 'date') $out.=' (YYYY-MM-DD)'; elseif ($type == 'datetime') $out.=' (YYYY-MM-DD HH:MM:SS)'; @@ -1268,6 +1289,21 @@ class ExtraFields } else dol_syslog(get_class($this) . '::showOutputField error ' . $this->db->lasterror(), LOG_WARNING); } + elseif ($type == 'link') + { + $out=''; + $param_list=array_keys($params['options']); + // 0 : ObjectName + // 1 : classPath + $InfoFieldList = explode(":", $param_list[0]); + dol_include_once($InfoFieldList[1]); + $object = new $InfoFieldList[0]($this->db); + if ($value) + { + $object->fetch($value); + $value=$object->getNomUrl(3); + } + } else { $showsize=round($size); From 4783db82ac034eba9d7a13e004a89197d5d497d2 Mon Sep 17 00:00:00 2001 From: BENKE Charles Date: Sat, 14 Mar 2015 12:42:52 +0100 Subject: [PATCH 10/11] Update admin_extrafields_add.tpl.php new type of extrafield : link --- htdocs/core/tpl/admin_extrafields_add.tpl.php | 1 + 1 file changed, 1 insertion(+) diff --git a/htdocs/core/tpl/admin_extrafields_add.tpl.php b/htdocs/core/tpl/admin_extrafields_add.tpl.php index 1f61064183b..72eddc012d2 100644 --- a/htdocs/core/tpl/admin_extrafields_add.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_add.tpl.php @@ -48,6 +48,7 @@ else if (type == 'boolean') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide();} else if (type == 'price') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").hide();jQuery("#helpchkbxlst").hide();} else if (type == 'select') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").show();jQuery("#helpselect").show();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();} + else if (type == 'link') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").show();jQuery("#helpselect").show();jQuery("#helpsellist").hide();} else if (type == 'sellist') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").show();jQuery("#helpselect").hide();jQuery("#helpsellist").show();jQuery("#helpchkbxlst").hide();} else if (type == 'checkbox') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").show();jQuery("#helpselect").show();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();} else if (type == 'radio') { size.val('').attr('disabled','disabled'); unique.attr('disabled','disabled'); jQuery("#value_choice").show();jQuery("#helpselect").show();jQuery("#helpsellist").hide();jQuery("#helpchkbxlst").hide();} From 9e62013bcadddec54ef66ed8c779fe03f6be3aa1 Mon Sep 17 00:00:00 2001 From: BENKE Charles Date: Sat, 14 Mar 2015 12:44:26 +0100 Subject: [PATCH 11/11] Update admin_extrafields_edit.tpl.php add new type of extrafields : link --- htdocs/core/tpl/admin_extrafields_edit.tpl.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/core/tpl/admin_extrafields_edit.tpl.php b/htdocs/core/tpl/admin_extrafields_edit.tpl.php index 13a6486aa4f..76713be57df 100644 --- a/htdocs/core/tpl/admin_extrafields_edit.tpl.php +++ b/htdocs/core/tpl/admin_extrafields_edit.tpl.php @@ -68,7 +68,7 @@ if((($type == 'select') || ($type == 'checkbox') || ($type == 'radio')) && is_ar } } } -elseif (($type== 'sellist') || ($type == 'chkbxlst')) +elseif (($type== 'sellist') || ($type == 'chkbxlst') || ($type == 'link') ) { $paramlist=array_keys($param['options']); $param_chain = $paramlist[0];