Can filter on serial number into movement list

This commit is contained in:
Laurent Destailleur 2015-04-10 12:59:33 +02:00
parent 787083028b
commit d76c1a9f42
3 changed files with 77 additions and 48 deletions

View File

@ -1391,7 +1391,7 @@ class CommandeFournisseur extends CommonOrder
*/
function dispatchProduct($user, $product, $qty, $entrepot, $price=0, $comment='', $eatby='', $sellby='', $batch='', $fk_commandefourndet=0, $notrigger=0)
{
global $conf;
global $conf, $langs;
$error = 0;
require_once DOL_DOCUMENT_ROOT .'/product/stock/class/mouvementstock.class.php';
@ -1409,10 +1409,44 @@ class CommandeFournisseur extends CommonOrder
}
$dispatchstatus = 1;
if (! empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) $dispatchstatus = 0; // Setting dispatch status (a validation step after receiving products) will be done manually to 1 if this option is on
if (! empty($conf->global->SUPPLIER_ORDER_USE_DISPATCH_STATUS)) $dispatchstatus = 0; // Setting dispatch status (a validation step after receiving products) will be done manually to 1 or 2 if this option is on
$now=dol_now();
// If a serial number is provided, we check that sellby and eatby match already existing serial
if ($batch)
{
$sql = "SELECT rowid, batch, eatby, sellby FROM ".MAIN_DB_PREFIX."product_batch WHERE batch = '".$this->db->escape($batch)."'";
dol_syslog(get_class($this)."::dispatchProduct scan serial to check if eatby and sellby match", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
$num = $this->db->num_rows($resql);
$i=0;
while ($i < $num)
{
$obj = $this->db->fetch_object($resql);
if ($obj->eatby != $eatby)
{
$this->error=$langs->trans("ThisSerialAlreadyExistWithDifferentDate", $batch, $obj->eatby);
return -1;
}
if ($obj->sellby != $sellby)
{
$this->error=$langs->trans("ThisSerialAlreadyExistWithDifferentDate", $batch, $obj->sellby);
return -1;
}
$i++;
}
}
else
{
dol_print_error($this->db);
return -1;
}
}
if (($this->statut == 3 || $this->statut == 4 || $this->statut == 5))
{
$this->db->begin();
@ -1480,7 +1514,7 @@ class CommandeFournisseur extends CommonOrder
}
}
else
{
{
$this->error='BadStatusForObject';
return -2;
}

View File

@ -127,11 +127,15 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner)
$db->begin();
$pos=0;
foreach($_POST as $key => $value)
{
if (preg_match('/^product_([0-9]+)$/i', $key, $reg)) // without batch module enabled
{
$numline=$reg[1] + 1; // line of product
$pos++;
//$numline=$reg[1] + 1; // line of product
$numline=$pos;
$prod = "product_".$reg[1];
$qty = "qty_".$reg[1];
$ent = "entrepot_".$reg[1];
@ -161,8 +165,11 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner)
}
if (preg_match('/^product_([0-9]+)_([0-9]+)$/i', $key, $reg)) // with batch module enabled
{
$pos++;
//eat-by date dispatch
$numline=$reg[2] + 1; // line of product
//$numline=$reg[2] + 1; // line of product
$numline=$pos;
$prod = "product_".$reg[1]."_".$reg[2];
$qty = "qty_".$reg[1]."_".$reg[2];
$ent = "entrepot_".$reg[1]."_".$reg[2];
@ -202,7 +209,6 @@ if ($action == 'dispatch' && $user->rights->fournisseur->commande->receptionner)
}
}
}
}
if (! $notrigger && ! $error)
@ -430,6 +436,20 @@ if ($id > 0 || ! empty($ref))
$nbproduct++;
$var=!$var;
// To show detail cref and description value, we must make calculation by cref
//print ($objp->cref?' ('.$objp->cref.')':'');
//if ($objp->description) print '<br>'.nl2br($objp->description);
if ((empty($conf->productbatch->enabled)) || $objp->tobatch==0)
{
$suffix='_'.$i;
} else {
$suffix='_0_'.$i;
}
print "\n";
print '<!-- Line '.$suffix.' -->'."\n";
print "<tr ".$bc[$var].">";
$linktoprod='<a href="'.DOL_URL_ROOT.'/product/fournisseurs.php?id='.$objp->fk_product.'">'.img_object($langs->trans("ShowProduct"),'product').' '.$objp->ref.'</a>';
@ -460,16 +480,6 @@ if ($id > 0 || ! empty($ref))
print "</td>";
}
// To show detail cref and description value, we must make calculation by cref
//print ($objp->cref?' ('.$objp->cref.')':'');
//if ($objp->description) print '<br>'.nl2br($objp->description);
if ((empty($conf->productbatch->enabled)) || $objp->tobatch==0)
{
$suffix='_'.$i;
} else {
$suffix='_0_'.$i;
}
$up_ht_disc=$objp->subprice;
if (! empty($objp->remise_percent) && empty($conf->global->STOCK_EXCLUDE_DISCOUNT_FOR_PMP)) $up_ht_disc=price2num($up_ht_disc * (100 - $objp->remise_percent) / 100, 'MU');

View File

@ -1,6 +1,6 @@
<?php
/* Copyright (C) 2001-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2013 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2014 Regis Houssin <regis.houssin@capnetworks.com>
* Copyright (C) 2015 Juanjo Menent <jmenent@2byte.es>
*
@ -53,6 +53,7 @@ $search_product = trim(GETPOST("search_product"));
$search_warehouse = trim(GETPOST("search_warehouse"));
$search_inventorycode = trim(GETPOST("search_inventorycode"));
$search_user = trim(GETPOST("search_user"));
$search_batch = trim(GETPOST("search_batch"));
$page = GETPOST("page",'int');
$sortfield = GETPOST("sortfield",'alpha');
$sortorder = GETPOST("sortorder",'alpha');
@ -71,6 +72,7 @@ if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter")) // Both
$search_product="";
$search_warehouse="";
$search_user="";
$search_batch="";
$sall="";
}
@ -148,34 +150,17 @@ else if ($year > 0)
{
$sql.= " AND m.datem BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
}
if (! empty($search_movement))
{
$sql.= " AND m.label LIKE '%".$db->escape($search_movement)."%'";
}
if (! empty($search_inventorycode))
{
$sql.= " AND m.inventorycode LIKE '%".$db->escape($search_inventorycode)."%'";
}
if (! empty($search_product_ref))
{
$sql.= " AND p.ref LIKE '%".$db->escape($search_product_ref)."%'";
}
if (! empty($search_product))
{
$sql.= " AND p.label LIKE '%".$db->escape($search_product)."%'";
}
if (! empty($search_warehouse))
{
$sql.= " AND e.label LIKE '%".$db->escape($search_warehouse)."%'";
}
if (! empty($search_user))
{
$sql.= " AND u.login LIKE '%".$db->escape($search_user)."%'";
}
if ($idproduct > 0)
{
$sql.= " AND p.rowid = '".$idproduct."'";
}
if (! empty($search_movement)) $sql.= " AND m.label LIKE '%".$db->escape($search_movement)."%'";
if (! empty($search_inventorycode)) $sql.= " AND m.inventorycode LIKE '%".$db->escape($search_inventorycode)."%'";
if (! empty($search_product_ref)) $sql.= " AND p.ref LIKE '%".$db->escape($search_product_ref)."%'";
if (! empty($search_product)) $sql.= " AND p.label LIKE '%".$db->escape($search_product)."%'";
if (! empty($search_warehouse)) $sql.= " AND e.label LIKE '%".$db->escape($search_warehouse)."%'";
if (! empty($search_user)) $sql.= " AND u.login LIKE '%".$db->escape($search_user)."%'";
if (! empty($search_batch)) $sql.= " AND m.batch LIKE '%".$db->escape($search_batch)."%'";
$sql.= $db->order($sortfield,$sortorder);
$sql.= $db->plimit($conf->liste_limit+1, $offset);
@ -440,9 +425,9 @@ if ($resql)
if (! empty($conf->productbatch->enabled))
{
$langs->load("productbatch");
print '<td align="right" width="10%">'.$langs->trans("BatchNumberShort").'</td>';
print '<td align="center" width="10%">'.$langs->trans("l_eatby").'</td>';
print '<td align="center" width="10%">'.$langs->trans("l_sellby").'</td>';
print_liste_field_titre($langs->trans("BatchNumberShort"),$_SERVER["PHP_SELF"],'m.batch','',$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("l_eatby"),$_SERVER["PHP_SELF"],'m.eatby','',$param,'align="center"',$sortfield,$sortorder);
print_liste_field_titre($langs->trans("l_sellby"),$_SERVER["PHP_SELF"],'m.sellby','',$param,'align="center"',$sortfield,$sortorder);
}
print_liste_field_titre($langs->trans("Warehouse"),$_SERVER["PHP_SELF"], "","",$param,"",$sortfield,$sortorder); // We are on a specific warehouse card, no filter on other should be possible
print_liste_field_titre($langs->trans("Author"),$_SERVER["PHP_SELF"], "m.fk_user_author","",$param,"",$sortfield,$sortorder);
@ -474,13 +459,13 @@ if ($resql)
// Batch
if (! empty($conf->productbatch->enabled))
{
print '<td></td>';
print '<td align="center"><input class="flat" type="text" size="5" name="search_batch" value="'.($search_batch).'"></td>';
print '<td></td>';
print '<td></td>';
}
// Warehouse
print '<td class="liste_titre" align="left">';
print '<input class="flat" type="text" size="10" name="search_warehouse" value="'.($search_warehouse).'">';
print '<input class="flat" type="text" size="8" name="search_warehouse" value="'.($search_warehouse).'">';
print '</td>';
// Author
print '<td class="liste_titre" align="left">';
@ -492,7 +477,7 @@ if ($resql)
print '</td>';
// Label of movement
print '<td class="liste_titre" align="left">';
print '<input class="flat" type="text" size="10" name="search_movement" value="'.$search_movement.'">';
print '<input class="flat" type="text" size="8" name="search_movement" value="'.$search_movement.'">';
print '</td>';
// Origin of movement
print '<td class="liste_titre" align="left">';
@ -544,7 +529,7 @@ if ($resql)
// Batch
if (! empty($conf->productbatch->enabled))
{
print '<td align="right">'.$objp->batch.'</td>';
print '<td align="center">'.$objp->batch.'</td>';
print '<td align="center">'. dol_print_date($objp->eatby,'day') .'</td>';
print '<td align="center">'. dol_print_date($objp->sellby,'day') .'</td>';
}