check unicity of serial number
This commit is contained in:
parent
43e58f70a1
commit
6a242edd8b
@ -24,3 +24,5 @@ ProductLotSetup=Setup of module lot/serial
|
|||||||
ShowCurrentStockOfLot=Show current stock for couple product/lot
|
ShowCurrentStockOfLot=Show current stock for couple product/lot
|
||||||
ShowLogOfMovementIfLot=Show log of movements for couple product/lot
|
ShowLogOfMovementIfLot=Show log of movements for couple product/lot
|
||||||
StockDetailPerBatch=Stock detail per lot
|
StockDetailPerBatch=Stock detail per lot
|
||||||
|
SerialNumberAlreadyInUse=Serial number %s is already used for product %s
|
||||||
|
|
||||||
|
|||||||
@ -24,3 +24,5 @@ ProductLotSetup=Configuration du module lot/série
|
|||||||
ShowCurrentStockOfLot=Afficher le stock actuel pour le couple produit / lot
|
ShowCurrentStockOfLot=Afficher le stock actuel pour le couple produit / lot
|
||||||
ShowLogOfMovementIfLot=Afficher l'historique des mouvements de couple produit / lot
|
ShowLogOfMovementIfLot=Afficher l'historique des mouvements de couple produit / lot
|
||||||
StockDetailPerBatch=Stock détaillé par lot
|
StockDetailPerBatch=Stock détaillé par lot
|
||||||
|
SerialNumberAlreadyInUse=Le numéro de série %s est déjà utilisé pour le produit %s
|
||||||
|
|
||||||
|
|||||||
@ -568,6 +568,13 @@ class MouvementStock extends CommonObject
|
|||||||
// Update detail stock for batch product
|
// Update detail stock for batch product
|
||||||
if (!$error && !empty($conf->productbatch->enabled) && $product->hasbatch() && !$skip_batch)
|
if (!$error && !empty($conf->productbatch->enabled) && $product->hasbatch() && !$skip_batch)
|
||||||
{
|
{
|
||||||
|
// check unicity for serial numbered equipments ( different for lots managed products)
|
||||||
|
if ( $product->status_batch == 2 && $qty > 0 && $this->getBatchCount($fk_product, $batch) > 0 )
|
||||||
|
{
|
||||||
|
$error++;
|
||||||
|
$this->errors[] = $langs->trans("SerialNumberAlreadyInUse", $batch, $product->ref);
|
||||||
|
}
|
||||||
|
|
||||||
if ($id_product_batch > 0)
|
if ($id_product_batch > 0)
|
||||||
{
|
{
|
||||||
$result = $this->createBatch($id_product_batch, $qty);
|
$result = $this->createBatch($id_product_batch, $qty);
|
||||||
@ -1208,4 +1215,42 @@ class MouvementStock extends CommonObject
|
|||||||
return $this->deleteCommon($user, $notrigger);
|
return $this->deleteCommon($user, $notrigger);
|
||||||
//return $this->deleteCommon($user, $notrigger, 1);
|
//return $this->deleteCommon($user, $notrigger, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve number of equipments for a product batch
|
||||||
|
*
|
||||||
|
* @return int <0 if KO, number of equipments if OK
|
||||||
|
*/
|
||||||
|
private function getBatchCount($fk_product, $batch)
|
||||||
|
{
|
||||||
|
global $conf;
|
||||||
|
|
||||||
|
$cpt = 0;
|
||||||
|
|
||||||
|
$sql = "SELECT sum(pb.qty) as cpt";
|
||||||
|
$sql .= " FROM ".MAIN_DB_PREFIX."product_batch as pb";
|
||||||
|
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product_stock as ps ON ps.rowid = pb.fk_product_stock";
|
||||||
|
$sql .= " WHERE ps.fk_product = " . $fk_product;
|
||||||
|
$sql .= " AND pb.batch = '" . $batch . "'";
|
||||||
|
|
||||||
|
$result = $this->db->query($sql);
|
||||||
|
if ($result) {
|
||||||
|
if ($this->db->num_rows($result)) {
|
||||||
|
|
||||||
|
$obj = $this->db->fetch_object($result);
|
||||||
|
|
||||||
|
$cpt = $obj->cpt;
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->db->free($result);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
dol_print_error($this->db);
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
return $cpt;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user