FIX : Display error on dispatched quantity when we have several times same product in a supplier order

This commit is contained in:
Gauthier 2015-02-12 12:56:21 +01:00
parent 17d2368bdc
commit be56f76743
4 changed files with 16 additions and 10 deletions

View File

@ -1272,7 +1272,7 @@ class CommandeFournisseur extends CommonOrder
* @param string $batch Lot number
* @return int <0 if KO, >0 if OK
*/
function DispatchProduct($user, $product, $qty, $entrepot, $price=0, $comment='', $eatby='', $sellby='', $batch='')
function DispatchProduct($user, $product, $qty, $entrepot, $price=0, $comment='', $eatby='', $sellby='', $batch='', $fk_commandefourndet='')
{
global $conf;
$error = 0;
@ -1292,8 +1292,8 @@ class CommandeFournisseur extends CommonOrder
$this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseur_dispatch ";
$sql.= " (fk_commande,fk_product, qty, fk_entrepot, fk_user, datec) VALUES ";
$sql.= " ('".$this->id."','".$product."','".$qty."',".($entrepot>0?"'".$entrepot."'":"null").",'".$user->id."','".$this->db->idate($now)."')";
$sql.= " (fk_commande,fk_product, qty, fk_entrepot, fk_user, datec, fk_commandefourndet) VALUES ";
$sql.= " ('".$this->id."','".$product."','".$qty."',".($entrepot>0?"'".$entrepot."'":"null").",'".$user->id."','".$this->db->idate($now)."','".$fk_commandefourndet."')";
dol_syslog(get_class($this)."::DispatchProduct", LOG_DEBUG);
$resql = $this->db->query($sql);

View File

@ -78,9 +78,10 @@ if ($_POST["action"] == 'dispatch' && $user->rights->fournisseur->commande->rece
$qty = "qty_".$reg[1];
$ent = "entrepot_".$reg[1];
$pu = "pu_".$reg[1]; // This is unit price including discount
$fk_commandefourndet = "fk_commandefourndet_".$reg[1];
if (GETPOST($ent,'int') > 0)
{
$result = $commande->DispatchProduct($user, GETPOST($prod,'int'),GETPOST($qty), GETPOST($ent,'int'), GETPOST($pu), GETPOST("comment"));
$result = $commande->DispatchProduct($user, GETPOST($prod,'int'),GETPOST($qty), GETPOST($ent,'int'), GETPOST($pu), GETPOST("comment"), '', '', '', GETPOST($fk_commandefourndet, 'int'));
}
else
{
@ -251,22 +252,23 @@ if ($id > 0 || ! empty($ref))
print '<input type="hidden" name="action" value="dispatch">';
print '<table class="noborder" width="100%">';
$sql = "SELECT cfd.fk_product, sum(cfd.qty) as qty";
$sql = "SELECT l.rowid, cfd.fk_product, sum(cfd.qty) as qty";
$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseur_dispatch as cfd";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."commande_fournisseurdet as l on (l.rowid = cfd.fk_commandefourndet)";
$sql.= " WHERE cfd.fk_commande = ".$commande->id;
$sql.= " GROUP BY cfd.fk_product";
$sql.= " GROUP BY l.rowid";
$resql = $db->query($sql);
if ($resql)
{
while ( $row = $db->fetch_row($resql) )
{
$products_dispatched[$row[0]] = $row[1];
$products_dispatched[$row[0]] = $row[2];
}
$db->free($resql);
}
$sql = "SELECT l.fk_product, l.subprice, l.remise_percent, SUM(l.qty) as qty,";
$sql = "SELECT l.rowid, l.fk_product, l.subprice, l.remise_percent, SUM(l.qty) as qty,";
$sql.= " p.ref, p.label, p.tobatch";
$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product=p.rowid";
@ -317,7 +319,7 @@ if ($id > 0 || ! empty($ref))
}
else
{
$remaintodispatch=($objp->qty - $products_dispatched[$objp->fk_product]); // Calculation of dispatched
$remaintodispatch=($objp->qty - $products_dispatched[$objp->rowid]); // Calculation of dispatched
if ($remaintodispatch < 0) $remaintodispatch=0;
if ($remaintodispatch)
{
@ -343,7 +345,7 @@ if ($id > 0 || ! empty($ref))
print "</td>\n";
print '<td align="right">'.$objp->qty.'</td>';
print '<td align="right">'.$products_dispatched[$objp->fk_product].'</td>';
print '<td align="right">'.$products_dispatched[$objp->rowid].'</td>';
if ( !(empty($conf->productbatch->enabled)) && $objp->tobatch==1) {
print '<td colspan="2" align="center">'.img_picto_common($langs->trans('AddDispatchBatchLine'),'treemenu/plustop2.gif','onClick="AddLineBatch('.$i.')"').'</td>';
@ -361,6 +363,7 @@ if ($id > 0 || ! empty($ref))
print '<td colspan="2">&nbsp</td>';
} else {
print '<input name="product'.$suffix.'" type="hidden" value="'.$objp->fk_product.'">';
print '<input name="fk_commandefourndet'.$suffix.'" type="hidden" value="'.$objp->rowid.'">';
print '<input name="pu'.$suffix.'" type="hidden" value="'.$up_ht_disc.'"><!-- This is a up including discount -->';
}

View File

@ -1155,3 +1155,5 @@ ALTER TABLE llx_resource MODIFY COLUMN entity integer DEFAULT 1 NOT NULL;
-- This request make mysql drop (mysql bug, so we add it at end):
ALTER TABLE llx_product ADD CONSTRAINT fk_product_barcode_type FOREIGN KEY (fk_barcode_type) REFERENCES llx_c_barcode_type(rowid);
-- Add id commandefourndet in llx_commande_fournisseur_dispatch to correct /fourn/commande/dispatch.php display when several times same product in supplier order
ALTER TABLE llx_commande_fournisseur_dispatch ADD COLUMN fk_commandefourndet INT(11) NOT NULL DEFAULT '0' AFTER fk_product;

View File

@ -21,6 +21,7 @@ create table llx_commande_fournisseur_dispatch
rowid integer AUTO_INCREMENT PRIMARY KEY,
fk_commande integer,
fk_product integer,
fk_commandefourndet integer,
qty float, -- qty
fk_entrepot integer,
fk_user integer,