Merge branch 'atm-gauthier-3.7' into 3.7

This commit is contained in:
Laurent Destailleur 2015-02-18 23:16:01 +01:00
commit 6d408724f7
4 changed files with 26 additions and 19 deletions

View File

@ -1261,18 +1261,19 @@ class CommandeFournisseur extends CommonOrder
/** /**
* Add a product into a stock warehouse. * Add a product into a stock warehouse.
* *
* @param User $user User object making change * @param User $user User object making change
* @param int $product Id of product to dispatch * @param int $product Id of product to dispatch
* @param double $qty Qty to dispatch * @param double $qty Qty to dispatch
* @param int $entrepot Id of warehouse to add product * @param int $entrepot Id of warehouse to add product
* @param double $price Unit Price for PMP value calculation (Unit price without Tax and taking into account discount) * @param double $price Unit Price for PMP value calculation (Unit price without Tax and taking into account discount)
* @param string $comment Comment for stock movement * @param string $comment Comment for stock movement
* @param date $eatby eat-by date * @param date $eatby eat-by date
* @param date $sellby sell-by date * @param date $sellby sell-by date
* @param string $batch Lot number * @param string $batch Lot number
* @param int $fk_commandefourndet Id of supplier order line
* @return int <0 if KO, >0 if OK * @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; global $conf;
$error = 0; $error = 0;
@ -1292,8 +1293,8 @@ class CommandeFournisseur extends CommonOrder
$this->db->begin(); $this->db->begin();
$sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseur_dispatch "; $sql = "INSERT INTO ".MAIN_DB_PREFIX."commande_fournisseur_dispatch ";
$sql.= " (fk_commande,fk_product, qty, fk_entrepot, fk_user, datec) VALUES "; $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)."')"; $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); dol_syslog(get_class($this)."::DispatchProduct", LOG_DEBUG);
$resql = $this->db->query($sql); $resql = $this->db->query($sql);

View File

@ -78,9 +78,10 @@ if ($_POST["action"] == 'dispatch' && $user->rights->fournisseur->commande->rece
$qty = "qty_".$reg[1]; $qty = "qty_".$reg[1];
$ent = "entrepot_".$reg[1]; $ent = "entrepot_".$reg[1];
$pu = "pu_".$reg[1]; // This is unit price including discount $pu = "pu_".$reg[1]; // This is unit price including discount
$fk_commandefourndet = "fk_commandefourndet_".$reg[1];
if (GETPOST($ent,'int') > 0) 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 else
{ {
@ -251,22 +252,23 @@ if ($id > 0 || ! empty($ref))
print '<input type="hidden" name="action" value="dispatch">'; print '<input type="hidden" name="action" value="dispatch">';
print '<table class="noborder" width="100%">'; 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.= " 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.= " WHERE cfd.fk_commande = ".$commande->id;
$sql.= " GROUP BY cfd.fk_product"; $sql.= " GROUP BY l.rowid";
$resql = $db->query($sql); $resql = $db->query($sql);
if ($resql) if ($resql)
{ {
while ( $row = $db->fetch_row($resql) ) while ( $row = $db->fetch_row($resql) )
{ {
$products_dispatched[$row[0]] = $row[1]; $products_dispatched[$row[0]] = $row[2];
} }
$db->free($resql); $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.= " p.ref, p.label, p.tobatch";
$sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l"; $sql.= " FROM ".MAIN_DB_PREFIX."commande_fournisseurdet as l";
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON l.fk_product=p.rowid"; $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 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 < 0) $remaintodispatch=0;
if ($remaintodispatch) if ($remaintodispatch)
{ {
@ -343,7 +345,7 @@ if ($id > 0 || ! empty($ref))
print "</td>\n"; print "</td>\n";
print '<td align="right">'.$objp->qty.'</td>'; 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) { 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>'; 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>'; print '<td colspan="2">&nbsp</td>';
} else { } else {
print '<input name="product'.$suffix.'" type="hidden" value="'.$objp->fk_product.'">'; 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 -->'; print '<input name="pu'.$suffix.'" type="hidden" value="'.$up_ht_disc.'"><!-- This is a up including discount -->';
} }

View File

@ -1160,3 +1160,5 @@ ALTER TABLE llx_product ADD CONSTRAINT fk_product_barcode_type FOREIGN KEY (fk_b
-- this update change the old formated url on llx_bank_url -- this update change the old formated url on llx_bank_url
UPDATE llx_bank_url set url = REPLACE( url, 'fiche.php', 'card.php'); UPDATE llx_bank_url set url = REPLACE( url, 'fiche.php', 'card.php');
-- 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, rowid integer AUTO_INCREMENT PRIMARY KEY,
fk_commande integer, fk_commande integer,
fk_product integer, fk_product integer,
fk_commandefourndet integer,
qty float, -- qty qty float, -- qty
fk_entrepot integer, fk_entrepot integer,
fk_user integer, fk_user integer,