New : replenish function adds new lines into already existing draft supplier order instead of creating a new supplier order

This commit is contained in:
Maxime Kohlhaas 2015-02-20 09:24:33 +01:00
parent 94751ba57b
commit 504cc89078

View File

@ -148,6 +148,41 @@ if ($action == 'order' && isset($_POST['valid']))
foreach ($suppliers as $supplier) foreach ($suppliers as $supplier)
{ {
$order = new CommandeFournisseur($db); $order = new CommandeFournisseur($db);
// 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') . "&nbsp;:&nbsp;";
$msg .= $order->error;
setEventMessage($msg, 'errors');
} else {
$id = $result;
}
} else {
$order->socid = $suppliersid[$i]; $order->socid = $suppliersid[$i];
//trick to know which orders have been generated this way //trick to know which orders have been generated this way
$order->source = 42; $order->source = 42;
@ -165,6 +200,7 @@ if ($action == 'order' && isset($_POST['valid']))
} }
$i++; $i++;
} }
}
if (! $fail && $id) if (! $fail && $id)
{ {