diff --git a/htdocs/compta/sociales/charges.php b/htdocs/compta/sociales/charges.php
index afe2c27a3be..251bd6f7f6a 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).' |
';
@@ -466,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")."";
}
@@ -500,7 +517,7 @@ if ($id > 0)
}
else
{
- /* Charge non trouv� */
+ /* Social contribution not found */
dol_print_error('',$object->error);
}
}
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);
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;
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),
diff --git a/htdocs/product/stock/replenish.php b/htdocs/product/stock/replenish.php
index efb008df4ff..289c3c31457 100644
--- a/htdocs/product/stock/replenish.php
+++ b/htdocs/product/stock/replenish.php
@@ -148,22 +148,59 @@ 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];
+ $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 = $order->thirdparty->cond_reglement_supplier_id;
+ $order->mode_reglement_id = $order->thirdparty->mode_reglement_supplier_id;
+ $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)