Fix: [ bug #1436 ] réapprovisionnement sur plusieurs pages

Removed also strange image (no way to understand meaning).
This commit is contained in:
Laurent Destailleur 2014-06-20 14:34:13 +02:00
parent d0dffc8999
commit e1a461b3d6
2 changed files with 88 additions and 75 deletions

View File

@ -26,9 +26,9 @@ require_once DOL_DOCUMENT_ROOT . '/fourn/class/fournisseur.commande.class.php';
/** /**
* dispatched * dispatched
* *
* @param int $order_id Id of order * @param int $order_id Id of order
* @return boolean * @return boolean
*/ */
function dispatched($order_id) function dispatched($order_id)
{ {
@ -39,7 +39,7 @@ function dispatched($order_id)
$resql = $db->query($sql); $resql = $db->query($sql);
$dispatched = array(); $dispatched = array();
$ordered = array(); $ordered = array();
if($resql && $db->num_rows($resql)) if($resql && $db->num_rows($resql))
{ {
while($res = $db->fetch_object($resql)) while($res = $db->fetch_object($resql))
$dispatched[] = $res; $dispatched[] = $res;
@ -57,7 +57,7 @@ function dispatched($order_id)
/** /**
* dispatchedOrders * dispatchedOrders
* *
* @return Ambigous <string, multitype:NULL > * @return Ambigous <string, multitype:NULL >
*/ */
function dispatchedOrders() function dispatchedOrders()
@ -84,48 +84,53 @@ function dispatchedOrders()
/** /**
* ordered * ordered
* *
* @param int $product_id Product id * @param int $product_id Product id
* @return void * @return void
*/ */
function ordered($product_id) function ordered($product_id)
{ {
global $db, $langs, $conf; global $db, $langs, $conf;
$sql = 'SELECT DISTINCT cfd.fk_product, SUM(cfd.qty) FROM';
$sql .= ' ' . MAIN_DB_PREFIX . 'commande_fournisseurdet as cfd ';
$sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'commande_fournisseur as cf';
$sql .= ' ON cfd.fk_commande = cf.rowid WHERE';
if ($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) {
$sql .= ' cf.fk_statut < 3';
} else if ($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) {
$sql .= ' cf.fk_statut < 6 AND cf.rowid NOT IN ' . dispatchedOrders();
} else {
$sql .= ' cf.fk_statut < 5';
}
$sql .= ' AND cfd.fk_product = ' . $product_id;
$sql .= ' GROUP BY cfd.fk_product';
$resql = $db->query($sql); $sql = 'SELECT DISTINCT cfd.fk_product, SUM(cfd.qty) as qty FROM';
if ($resql) { $sql .= ' ' . MAIN_DB_PREFIX . 'commande_fournisseurdet as cfd ';
$exists = $db->num_rows($resql); $sql .= ' LEFT JOIN ' . MAIN_DB_PREFIX . 'commande_fournisseur as cf';
if ($exists) { $sql .= ' ON cfd.fk_commande = cf.rowid WHERE';
$obj = $db->fetch_array($resql); if ($conf->global->STOCK_CALCULATE_ON_SUPPLIER_VALIDATE_ORDER) {
return $obj['SUM(cfd.qty)']; //. ' ' . img_picto('','tick'); $sql .= ' cf.fk_statut < 3';
} else { } else if ($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) {
return null;//img_picto('', 'stcomm-1'); $sql .= ' cf.fk_statut < 6 AND cf.rowid NOT IN ' . dispatchedOrders();
} } else {
} else { $sql .= ' cf.fk_statut < 5';
$error = $db->lasterror(); }
dol_print_error($db); $sql .= ' AND cfd.fk_product = ' . $product_id;
dol_syslog('replenish.php: ' . $error, LOG_ERR); $sql .= ' GROUP BY cfd.fk_product';
return $langs->trans('error'); $resql = $db->query($sql);
} if ($resql)
{
$exists = $db->num_rows($resql);
if ($exists)
{
$obj = $db->fetch_array($resql);
return $obj['qty']; //. ' ' . img_picto('','tick');
} else {
return null; //img_picto('', 'stcomm-1');
}
}
else
{
$error = $db->lasterror();
dol_print_error($db);
dol_syslog('replenish.php: ' . $error, LOG_ERR);
return $langs->trans('error');
}
} }
/** /**
* getProducts * getProducts
* *
* @param int $order_id Order id * @param int $order_id Order id
* @return void * @return void
*/ */

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr> /* Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
* Copyright (C) 2013 Laurent Destaileur <ely@users.sourceforge.net> * Copyright (C) 2013-2014 Laurent Destaileur <ely@users.sourceforge.net>
* *
* This program is free software: you can redistribute it and/or modify * 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 * it under the terms of the GNU General Public License as published by
@ -64,6 +64,10 @@ if (!$sortorder) {
$limit = $conf->liste_limit; $limit = $conf->liste_limit;
$offset = $limit * $page ; $offset = $limit * $page ;
// Force limit to non (currently solution to solve loosing selection when using pagination. No pagination on this page)
$limit = 0;
/* /*
* Actions * Actions
*/ */
@ -82,10 +86,10 @@ if ($action == 'order' && isset($_POST['valid']))
$linecount = GETPOST('linecount', 'int'); $linecount = GETPOST('linecount', 'int');
$box = 0; $box = 0;
unset($_POST['linecount']); unset($_POST['linecount']);
if ($linecount > 0) if ($linecount > 0)
{ {
$db->begin(); $db->begin();
$suppliers = array(); $suppliers = array();
for ($i = 0; $i < $linecount; $i++) for ($i = 0; $i < $linecount; $i++)
{ {
@ -158,21 +162,21 @@ if ($action == 'order' && isset($_POST['valid']))
} }
$i++; $i++;
} }
if (! $fail && $id) if (! $fail && $id)
{ {
$db->commit(); $db->commit();
setEventMessage($langs->trans('OrderCreated'), 'mesgs'); setEventMessage($langs->trans('OrderCreated'), 'mesgs');
header('Location: replenishorders.php'); header('Location: replenishorders.php');
exit; exit;
} }
else else
{ {
$db->rollback(); $db->rollback();
} }
} }
if ($box == 0) if ($box == 0)
{ {
setEventMessage($langs->trans('SelectProductWithNotNullQty'), 'warnings'); setEventMessage($langs->trans('SelectProductWithNotNullQty'), 'warnings');
} }
@ -183,6 +187,8 @@ if ($action == 'order' && isset($_POST['valid']))
* View * View
*/ */
$form = new Form($db);
$virtualdiffersfromphysical=0; $virtualdiffersfromphysical=0;
if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT) if (! empty($conf->global->STOCK_CALCULATE_ON_SHIPMENT)
|| ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER) || ! empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_DISPATCH_ORDER)
@ -250,7 +256,7 @@ if($usevirtualstock) {
$sqlCommandesCli.= " AND c.entity = ".$conf->entity; $sqlCommandesCli.= " AND c.entity = ".$conf->entity;
$sqlCommandesCli.= " AND cd.fk_product = p.rowid"; $sqlCommandesCli.= " AND cd.fk_product = p.rowid";
$sqlCommandesCli.= " AND c.fk_statut in (1,2))"; $sqlCommandesCli.= " AND c.fk_statut in (1,2))";
$sqlCommandesFourn = "(SELECT SUM(cd.qty) as qty"; $sqlCommandesFourn = "(SELECT SUM(cd.qty) as qty";
$sqlCommandesFourn.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd"; $sqlCommandesFourn.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as cd";
$sqlCommandesFourn.= ", ".MAIN_DB_PREFIX."commande_fournisseur as c"; $sqlCommandesFourn.= ", ".MAIN_DB_PREFIX."commande_fournisseur as c";
@ -258,7 +264,7 @@ if($usevirtualstock) {
$sqlCommandesFourn.= " AND c.entity = ".$conf->entity; $sqlCommandesFourn.= " AND c.entity = ".$conf->entity;
$sqlCommandesFourn.= " AND cd.fk_product = p.rowid"; $sqlCommandesFourn.= " AND cd.fk_product = p.rowid";
$sqlCommandesFourn.= " AND c.fk_statut in (3))"; $sqlCommandesFourn.= " AND c.fk_statut in (3))";
$sql.= ' HAVING p.desiredstock > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')'; $sql.= ' HAVING p.desiredstock > SUM('.$db->ifsql("s.reel IS NULL", "0", "s.reel").')';
$sql.= ' - '.$db->ifsql($sqlCommandesCli.' IS NULL', '0', $sqlCommandesCli).' + '.$db->ifsql($sqlCommandesFourn.' IS NULL', '0', $sqlCommandesFourn); $sql.= ' - '.$db->ifsql($sqlCommandesCli.' IS NULL', '0', $sqlCommandesCli).' + '.$db->ifsql($sqlCommandesFourn.' IS NULL', '0', $sqlCommandesFourn);
} else { } else {
@ -362,9 +368,9 @@ $param .= '&fourn_id=' . $fourn_id . '&snom='. $snom . '&salert=' . $salert;
$param .= '&sref=' . $sref; $param .= '&sref=' . $sref;
$param .= '&mode=' . $mode; $param .= '&mode=' . $mode;
// Lignes des titres // Lines of title
print '<tr class="liste_titre">'. print '<tr class="liste_titre"><td><input type="checkbox" onClick="toggle(this)" /></td>';
'<td><input type="checkbox" onClick="toggle(this)" /></td>';
print_liste_field_titre( print_liste_field_titre(
$langs->trans('Ref'), $langs->trans('Ref'),
$_SERVER["PHP_SELF"], $_SERVER["PHP_SELF"],
@ -481,7 +487,7 @@ print '<td class="liste_titre">&nbsp;</td>'.
$prod = new Product($db); $prod = new Product($db);
$var = True; $var = True;
while ($i < min($num, $limit)) while ($i < ($limit ? min($num, $limit) : $num))
{ {
$objp = $db->fetch_object($resql); $objp = $db->fetch_object($resql);
@ -503,13 +509,15 @@ while ($i < min($num, $limit))
if (!empty($objtp->label)) $objp->label = $objtp->label; if (!empty($objtp->label)) $objp->label = $objtp->label;
} }
} }
$form = new Form($db);
$var =! $var; $var =! $var;
$prod->ref = $objp->ref; $prod->ref = $objp->ref;
$prod->id = $objp->rowid; $prod->id = $objp->rowid;
$prod->type = $objp->fk_product_type; $prod->type = $objp->fk_product_type;
// Get number already ordered.
$ordered = ordered($prod->id); $ordered = ordered($prod->id);
// Defined current stock number and warning if required
if ($usevirtualstock) if ($usevirtualstock)
{ {
// If option to increase/decrease is not on an object validation, virtual stock may differs from physical stock. // If option to increase/decrease is not on an object validation, virtual stock may differs from physical stock.
@ -531,26 +539,29 @@ while ($i < min($num, $limit))
$stock = $objp->stock_physique; $stock = $objp->stock_physique;
} }
$warning=''; $warning='';
if ($objp->seuil_stock_alerte && ($stock < $objp->seuil_stock_alerte)) if ($objp->seuil_stock_alerte && ($stock < $objp->seuil_stock_alerte))
{ {
$warning = img_warning($langs->trans('StockTooLow')) . ' '; $warning = img_warning($langs->trans('StockTooLow')) . ' ';
} }
//depending on conf, use either physical stock or //depending on conf, use either physical stock or
//virtual stock to compute the stock to buy value //virtual stock to compute the stock to buy value
$stocktobuy = max($objp->desiredstock - $stock - $ordered, 0); $stocktobuy = max($objp->desiredstock - $stock - $ordered, 0);
/*
$disabled = ''; $disabled = '';
if($ordered > 0) { if($ordered > 0)
if($ordered + $stock >= $objp->desiredstock) { {
$picto = img_picto('', './img/yes', '', 1); if ($ordered + $stock >= $objp->desiredstock)
{
$picto = img_picto('', 'ok', '');
$disabled = 'disabled="disabled"'; $disabled = 'disabled="disabled"';
} }
else { else {
$picto = img_picto('', './img/no', '', 1); $picto = img_picto($langs->trans("NotEnough"), 'warning', '');
} }
} else { } else {
$picto = img_picto('', './img/no', '', 1); $picto = img_picto('', 'info', '');
} }*/
print '<tr '.$bc[$var].'>'; print '<tr '.$bc[$var].'>';
@ -558,13 +569,12 @@ while ($i < min($num, $limit))
//print '<td><input type="checkbox" class="check" name="' . $i . '"' . $disabled . '></td>'; //print '<td><input type="checkbox" class="check" name="' . $i . '"' . $disabled . '></td>';
print '<td><input type="checkbox" class="check" name="'.$i.'"></td>'; print '<td><input type="checkbox" class="check" name="'.$i.'"></td>';
print '<td class="nowrap">'. print '<td class="nowrap">'.$prod->getNomUrl(1, '', 16).'</td>';
$prod->getNomUrl(1, '', 16).
'</td>'.
'<td>' . $objp->label . '</td>'.
'<input type="hidden" name="desc' . $i . '" value="' . $objp->label . '" >';
if (!empty($conf->service->enabled) && $type == 1) { print '<td>' . $objp->label . '<input type="hidden" name="desc' . $i . '" value="' . $objp->label . '" ></td>';
if (!empty($conf->service->enabled) && $type == 1)
{
if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) { if (preg_match('/([0-9]+)y/i', $objp->duration, $regs)) {
$duration = $regs[1] . ' ' . $langs->trans('DurationYear'); $duration = $regs[1] . ' ' . $langs->trans('DurationYear');
} elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) { } elseif (preg_match('/([0-9]+)m/i', $objp->duration, $regs)) {
@ -574,19 +584,17 @@ while ($i < min($num, $limit))
} else { } else {
$duration = $objp->duration; $duration = $objp->duration;
} }
print '<td align="center">'. print '<td align="center">'.$duration.'</td>';
$duration.
'</td>';
} }
print '<td align="right">' . $objp->desiredstock . '</td>'. // Desired stock
'<td align="right">'. print '<td align="right">' . $objp->desiredstock . '</td>';
$warning . $stock.
'</td>'. // Current stock
'<td align="right">'. print '<td align="right">'. $warning . $stock. '</td>';
'<a href="replenishorders.php?sproduct=' . $prod->id . '">'.
$ordered . '</a> ' . $picto. // Already ordered
'</td>'; print '<td align="right"><a href="replenishorders.php?sproduct=' . $prod->id . '">'. $ordered . '</a> ' . $picto. '</td>';
// To order // To order
//print '<td align="right"><input type="text" name="tobuy'.$i.'" value="'.$stocktobuy.'" '.$disabled.'></td>'; //print '<td align="right"><input type="text" name="tobuy'.$i.'" value="'.$stocktobuy.'" '.$disabled.'></td>';