From d76c1a9f4245f70b1aa15214a8782b1f01934bc7 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Fri, 10 Apr 2015 12:59:33 +0200 Subject: [PATCH] Can filter on serial number into movement list --- .../class/fournisseur.commande.class.php | 40 +++++++++++++-- htdocs/fourn/commande/dispatch.php | 36 +++++++++----- htdocs/product/stock/mouvement.php | 49 +++++++------------ 3 files changed, 77 insertions(+), 48 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.commande.class.php b/htdocs/fourn/class/fournisseur.commande.class.php index 7f091749660..f6575eb2140 100644 --- a/htdocs/fourn/class/fournisseur.commande.class.php +++ b/htdocs/fourn/class/fournisseur.commande.class.php @@ -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; } diff --git a/htdocs/fourn/commande/dispatch.php b/htdocs/fourn/commande/dispatch.php index 429378ac291..b3d1c9b12dd 100644 --- a/htdocs/fourn/commande/dispatch.php +++ b/htdocs/fourn/commande/dispatch.php @@ -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 '
'.nl2br($objp->description); + if ((empty($conf->productbatch->enabled)) || $objp->tobatch==0) + { + $suffix='_'.$i; + } else { + $suffix='_0_'.$i; + } + + + print "\n"; + print ''."\n"; print ""; $linktoprod=''.img_object($langs->trans("ShowProduct"),'product').' '.$objp->ref.''; @@ -460,16 +480,6 @@ if ($id > 0 || ! empty($ref)) print ""; } - // To show detail cref and description value, we must make calculation by cref - //print ($objp->cref?' ('.$objp->cref.')':''); - //if ($objp->description) print '
'.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'); diff --git a/htdocs/product/stock/mouvement.php b/htdocs/product/stock/mouvement.php index 913be813815..a27713d8b0f 100644 --- a/htdocs/product/stock/mouvement.php +++ b/htdocs/product/stock/mouvement.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2013 Laurent Destailleur + * Copyright (C) 2004-2015 Laurent Destailleur * Copyright (C) 2005-2014 Regis Houssin * Copyright (C) 2015 Juanjo Menent * @@ -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 ''.$langs->trans("BatchNumberShort").''; - print ''.$langs->trans("l_eatby").''; - print ''.$langs->trans("l_sellby").''; + 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 ''; + print ''; print ''; print ''; } // Warehouse print ''; - print ''; + print ''; print ''; // Author print ''; @@ -492,7 +477,7 @@ if ($resql) print ''; // Label of movement print ''; - print ''; + print ''; print ''; // Origin of movement print ''; @@ -544,7 +529,7 @@ if ($resql) // Batch if (! empty($conf->productbatch->enabled)) { - print ''.$objp->batch.''; + print ''.$objp->batch.''; print ''. dol_print_date($objp->eatby,'day') .''; print ''. dol_print_date($objp->sellby,'day') .''; }