New : replenish function adds new lines into already existing draft supplier order instead of creating a new supplier order
This commit is contained in:
parent
94751ba57b
commit
504cc89078
@ -148,22 +148,58 @@ if ($action == 'order' && isset($_POST['valid']))
|
|||||||
foreach ($suppliers as $supplier)
|
foreach ($suppliers as $supplier)
|
||||||
{
|
{
|
||||||
$order = new CommandeFournisseur($db);
|
$order = new CommandeFournisseur($db);
|
||||||
$order->socid = $suppliersid[$i];
|
// Check if an order for the supplier exists
|
||||||
//trick to know which orders have been generated this way
|
$sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."commande_fournisseur";
|
||||||
$order->source = 42;
|
$sql.= " WHERE fk_soc = ".$suppliersid[$i];
|
||||||
foreach ($supplier['lines'] as $line) {
|
$sql.= " AND source = 42 AND fk_statut = 0";
|
||||||
$order->lines[] = $line;
|
$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)
|
if (! $fail && $id)
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user