fix phpcs was disabled

This commit is contained in:
Frédéric FRANCE 2021-05-19 15:48:08 +02:00
parent 8e39eff180
commit 83521311dc
No known key found for this signature in database
GPG Key ID: 06809324E4B2ABC1

View File

@ -150,7 +150,7 @@ class MouvementStock extends CommonObject
*/
public function _create($user, $fk_product, $entrepot_id, $qty, $type, $price = 0, $label = '', $inventorycode = '', $datem = '', $eatby = '', $sellby = '', $batch = '', $skip_batch = false, $id_product_batch = 0, $disablestockchangeforsubproduct = 0)
{
// phpcs:disable
// phpcs:enable
global $conf, $langs;
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
@ -160,26 +160,26 @@ class MouvementStock extends CommonObject
dol_syslog(get_class($this)."::_create start userid=$user->id, fk_product=$fk_product, warehouse_id=$entrepot_id, qty=$qty, type=$type, price=$price, label=$label, inventorycode=$inventorycode, datem=".$datem.", eatby=".$eatby.", sellby=".$sellby.", batch=".$batch.", skip_batch=".$skip_batch);
// start hook at beginning
global $action, $hookmanager;
$hookmanager->initHooks(array('mouvementstock'));
// Hook of thirdparty module
if (is_object($hookmanager)) {
global $action, $hookmanager;
$hookmanager->initHooks(array('mouvementstock'));
// Hook of thirdparty module
if (is_object($hookmanager)) {
$parameters = array(
'currentcontext' => 'mouvementstock',
'user' => &$user,
'fk_product' => &$fk_product,
'entrepot_id' => &$entrepot_id,
'qty' => &$qty,
'type' => &$type,
'price' => &$price,
'label' => &$label,
'inventorycode' => &$inventorycode,
'datem' => &$datem,
'eatby' => &$eatby,
'sellby' => &$sellby,
'batch' => &$batch,
'skip_batch' => &$skip_batch,
'id_product_batch' => &$id_product_batch
'currentcontext' => 'mouvementstock',
'user' => &$user,
'fk_product' => &$fk_product,
'entrepot_id' => &$entrepot_id,
'qty' => &$qty,
'type' => &$type,
'price' => &$price,
'label' => &$label,
'inventorycode' => &$inventorycode,
'datem' => &$datem,
'eatby' => &$eatby,
'sellby' => &$sellby,
'batch' => &$batch,
'skip_batch' => &$skip_batch,
'id_product_batch' => &$id_product_batch
);
$reshook = $hookmanager->executeHooks('stockMovementCreate', $parameters, $this, $action); // Note that $action and $object may have been modified by some hooks
@ -190,8 +190,8 @@ class MouvementStock extends CommonObject
} elseif ($reshook > 0) {
return $hookmanager->resPrint;
}
}
// end hook at beginning
}
// end hook at beginning
// Clean parameters
$price = price2num($price, 'MU'); // Clean value for the casse we receive a float zero value, to have it a real zero value.
@ -244,10 +244,8 @@ class MouvementStock extends CommonObject
$product->load_stock('novirtual');
// Test if product require batch data. If yes, and there is not, we throw an error.
if (!empty($conf->productbatch->enabled) && $product->hasbatch() && !$skip_batch)
{
if (empty($batch))
{
if (!empty($conf->productbatch->enabled) && $product->hasbatch() && !$skip_batch) {
if (empty($batch)) {
$langs->load("errors");
$this->errors[] = $langs->transnoentitiesnoconv("ErrorTryToMakeMoveOnProductRequiringBatchData", $product->ref);
dol_syslog("Try to make a movement of a product with status_batch on without any batch data");
@ -266,23 +264,17 @@ class MouvementStock extends CommonObject
$sql .= " WHERE pb.fk_product = ".$fk_product." AND pb.batch = '".$this->db->escape($batch)."'";
dol_syslog(get_class($this)."::_create scan serial for this product to check if eatby and sellby match", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$num = $this->db->num_rows($resql);
$i = 0;
if ($num > 0)
{
while ($i < $num)
{
if ($num > 0) {
while ($i < $num) {
$obj = $this->db->fetch_object($resql);
if ($obj->eatby)
{
if ($eatby)
{
if ($obj->eatby) {
if ($eatby) {
$tmparray = dol_getdate($eatby, true);
$eatbywithouthour = dol_mktime(0, 0, 0, $tmparray['mon'], $tmparray['mday'], $tmparray['year']);
if ($this->db->jdate($obj->eatby) != $eatby && $this->db->jdate($obj->eatby) != $eatbywithouthour) // We test date without hours and with hours for backward compatibility
{
if ($this->db->jdate($obj->eatby) != $eatby && $this->db->jdate($obj->eatby) != $eatbywithouthour) { // We test date without hours and with hours for backward compatibility
// If found and eatby/sellby defined into table and provided and differs, return error
$langs->load("stocks");
$this->errors[] = $langs->transnoentitiesnoconv("ThisSerialAlreadyExistWithDifferentDate", $batch, dol_print_date($this->db->jdate($obj->eatby), 'dayhour'), dol_print_date($eatbywithouthour, 'dayhour'));
@ -294,14 +286,12 @@ class MouvementStock extends CommonObject
$eatby = $obj->eatby; // If found and eatby/sellby defined into table and not provided, we take value from table
}
} else {
if ($eatby) // If found and eatby/sellby not defined into table and provided, we update table
{
if ($eatby) { // If found and eatby/sellby not defined into table and provided, we update table
$productlot = new Productlot($this->db);
$result = $productlot->fetch($obj->rowid);
$productlot->eatby = $eatby;
$result = $productlot->update($user);
if ($result <= 0)
{
if ($result <= 0) {
$this->error = $productlot->error;
$this->errors = $productlot->errors;
$this->db->rollback();
@ -309,14 +299,11 @@ class MouvementStock extends CommonObject
}
}
}
if ($obj->sellby)
{
if ($sellby)
{
if ($obj->sellby) {
if ($sellby) {
$tmparray = dol_getdate($sellby, true);
$sellbywithouthour = dol_mktime(0, 0, 0, $tmparray['mon'], $tmparray['mday'], $tmparray['year']);
if ($this->db->jdate($obj->sellby) != $sellby && $this->db->jdate($obj->sellby) != $sellbywithouthour) // We test date without hours and with hours for backward compatibility
{
if ($this->db->jdate($obj->sellby) != $sellby && $this->db->jdate($obj->sellby) != $sellbywithouthour) { // We test date without hours and with hours for backward compatibility
// If found and eatby/sellby defined into table and provided and differs, return error
$this->errors[] = $langs->transnoentitiesnoconv("ThisSerialAlreadyExistWithDifferentDate", $batch, dol_print_date($this->db->jdate($obj->sellby)), dol_print_date($sellby));
dol_syslog($langs->transnoentities("ThisSerialAlreadyExistWithDifferentDate", $batch, dol_print_date($this->db->jdate($obj->sellby)), dol_print_date($sellby)), LOG_ERR);
@ -326,17 +313,13 @@ class MouvementStock extends CommonObject
} else {
$sellby = $obj->sellby; // If found and eatby/sellby defined into table and not provided, we take value from table
}
}
else
{
if ($sellby) // If found and eatby/sellby not defined into table and provided, we update table
{
} else {
if ($sellby) { // If found and eatby/sellby not defined into table and provided, we update table
$productlot = new Productlot($this->db);
$result = $productlot->fetch($obj->rowid);
$productlot->sellby = $sellby;
$result = $productlot->update($user);
if ($result <= 0)
{
if ($result <= 0) {
$this->error = $productlot->error;
$this->errors = $productlot->errors;
$this->db->rollback();
@ -347,9 +330,7 @@ class MouvementStock extends CommonObject
$i++;
}
}
else // If not found, we add record
{
} else { // If not found, we add record
$productlot = new Productlot($this->db);
$productlot->entity = $conf->entity;
$productlot->fk_product = $fk_product;
@ -358,17 +339,14 @@ class MouvementStock extends CommonObject
$productlot->eatby = $eatby;
$productlot->sellby = $sellby;
$result = $productlot->create($user);
if ($result <= 0)
{
if ($result <= 0) {
$this->error = $productlot->error;
$this->errors = $productlot->errors;
$this->db->rollback();
return -4;
}
}
}
else
{
} else {
dol_print_error($this->db);
$this->db->rollback();
return -1;
@ -381,21 +359,17 @@ class MouvementStock extends CommonObject
// Check if stock is enough when qty is < 0
// Note that qty should be > 0 with type 0 or 3, < 0 with type 1 or 2.
if ($movestock && $qty < 0 && empty($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER))
{
if (!empty($conf->productbatch->enabled) && $product->hasbatch() && !$skip_batch)
{
if ($movestock && $qty < 0 && empty($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER)) {
if (!empty($conf->productbatch->enabled) && $product->hasbatch() && !$skip_batch) {
$foundforbatch = 0;
$qtyisnotenough = 0;
foreach ($product->stock_warehouse[$entrepot_id]->detail_batch as $batchcursor => $prodbatch)
{
foreach ($product->stock_warehouse[$entrepot_id]->detail_batch as $batchcursor => $prodbatch) {
if ($batch != $batchcursor) continue;
$foundforbatch = 1;
if ($prodbatch->qty < abs($qty)) $qtyisnotenough = $prodbatch->qty;
break;
}
if (!$foundforbatch || $qtyisnotenough)
{
if (!$foundforbatch || $qtyisnotenough) {
$langs->load("stocks");
include_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
$tmpwarehouse = new Entrepot($this->db);
@ -406,11 +380,8 @@ class MouvementStock extends CommonObject
$this->db->rollback();
return -8;
}
}
else
{
if (empty($product->stock_warehouse[$entrepot_id]->real) || $product->stock_warehouse[$entrepot_id]->real < abs($qty))
{
} else {
if (empty($product->stock_warehouse[$entrepot_id]->real) || $product->stock_warehouse[$entrepot_id]->real < abs($qty)) {
$langs->load("stocks");
$this->error = $langs->trans('qtyToTranferIsNotEnough').' : '.$product->ref;
$this->errors[] = $langs->trans('qtyToTranferIsNotEnough').' : '.$product->ref;
@ -420,8 +391,7 @@ class MouvementStock extends CommonObject
}
}
if ($movestock && $entrepot_id > 0) // Change stock for current product, change for subproduct is done after
{
if ($movestock && $entrepot_id > 0) { // Change stock for current product, change for subproduct is done after
// Set $origintype, fk_origin, fk_project
$fk_project = 0;
if (!empty($this->origin)) { // This is set by caller for tracking reason
@ -431,10 +401,8 @@ class MouvementStock extends CommonObject
$fk_project = $fk_origin;
} else {
$res = $this->origin->fetch($fk_origin);
if ($res > 0)
{
if (!empty($this->origin->fk_project))
{
if ($res > 0) {
if (!empty($this->origin->fk_project)) {
$fk_project = $this->origin->fk_project;
}
}
@ -466,13 +434,10 @@ class MouvementStock extends CommonObject
dol_syslog(get_class($this)."::_create insert record into stock_mouvement", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$mvid = $this->db->last_insert_id(MAIN_DB_PREFIX."stock_mouvement");
$this->id = $mvid;
}
else
{
} else {
$this->error = $this->db->lasterror();
$this->errors[] = $this->error;
$error = -1;
@ -485,18 +450,15 @@ class MouvementStock extends CommonObject
// Test if there is already a record for couple (warehouse / product), so later we will make an update or create.
$alreadyarecord = 0;
if (!$error)
{
if (!$error) {
$sql = "SELECT rowid, reel FROM ".MAIN_DB_PREFIX."product_stock";
$sql .= " WHERE fk_entrepot = ".((int) $entrepot_id)." AND fk_product = ".((int) $fk_product); // This is a unique key
dol_syslog(get_class($this)."::_create check if a record already exists in product_stock", LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$obj = $this->db->fetch_object($resql);
if ($obj)
{
if ($obj) {
$alreadyarecord = 1;
$oldqtywarehouse = $obj->reel;
$fk_product_stock = $obj->rowid;
@ -510,10 +472,8 @@ class MouvementStock extends CommonObject
// Calculate new AWP (PMP)
$newpmp = 0;
if (!$error)
{
if ($type == 0 || $type == 3)
{
if (!$error) {
if ($type == 0 || $type == 3) {
// After a stock increase
// Note: PMP is calculated on stock input only (type of movement = 0 or 3). If type == 0 or 3, qty should be > 0.
// Note: Price should always be >0 or 0. PMP should be always >0 (calculated on input)
@ -540,10 +500,8 @@ class MouvementStock extends CommonObject
}
}
// Update stock quantity
if (!$error)
{
if ($alreadyarecord > 0)
{
if (!$error) {
if ($alreadyarecord > 0) {
$sql = "UPDATE ".MAIN_DB_PREFIX."product_stock SET reel = reel + ".((float) $qty);
$sql .= " WHERE fk_entrepot = ".((int) $entrepot_id)." AND fk_product = ".((int) $fk_product);
} else {
@ -554,39 +512,29 @@ class MouvementStock extends CommonObject
dol_syslog(get_class($this)."::_create update stock value", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql)
{
if (!$resql) {
$this->errors[] = $this->db->lasterror();
$error = -3;
}
elseif (empty($fk_product_stock))
{
} elseif (empty($fk_product_stock)) {
$fk_product_stock = $this->db->last_insert_id(MAIN_DB_PREFIX."product_stock");
}
}
// 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 )
{
if ( $this->getBatchCount($fk_product, $batch) > 0 )
{
if ( $product->status_batch == 2 && $qty > 0 ) {
if ( $this->getBatchCount($fk_product, $batch) > 0 ) {
$error++;
$this->errors[] = $langs->trans("SerialNumberAlreadyInUse", $batch, $product->ref);
}
elseif ( $qty > 1 )
{
} elseif ( $qty > 1 ) {
$error++;
$this->errors[] = $langs->trans("TooManyQtyForSerialNumber", $product->ref, $batch);
}
}
if ( ! $error )
{
if ($id_product_batch > 0)
{
if ( ! $error ) {
if ($id_product_batch > 0) {
$result = $this->createBatch($id_product_batch, $qty);
} else {
$param_batch = array('fk_product_stock' =>$fk_product_stock, 'batchnumber'=>$batch);
@ -597,8 +545,7 @@ class MouvementStock extends CommonObject
}
// Update PMP and denormalized value of stock qty at product level
if (!$error)
{
if (!$error) {
$newpmp = price2num($newpmp, 'MU');
// $sql = "UPDATE ".MAIN_DB_PREFIX."product SET pmp = ".$newpmp.", stock = ".$this->db->ifsql("stock IS NULL", 0, "stock") . " + ".$qty;
@ -610,8 +557,7 @@ class MouvementStock extends CommonObject
dol_syslog(get_class($this)."::_create update AWP", LOG_DEBUG);
$resql = $this->db->query($sql);
if (!$resql)
{
if (!$resql) {
$this->errors[] = $this->db->lasterror();
$error = -4;
}
@ -625,26 +571,21 @@ class MouvementStock extends CommonObject
}
// Add movement for sub products (recursive call)
if (!$error && !empty($conf->global->PRODUIT_SOUSPRODUITS) && empty($conf->global->INDEPENDANT_SUBPRODUCT_STOCK) && empty($disablestockchangeforsubproduct))
{
if (!$error && !empty($conf->global->PRODUIT_SOUSPRODUITS) && empty($conf->global->INDEPENDANT_SUBPRODUCT_STOCK) && empty($disablestockchangeforsubproduct)) {
$error = $this->_createSubProduct($user, $fk_product, $entrepot_id, $qty, $type, 0, $label, $inventorycode); // we use 0 as price, because AWP must not change for subproduct
}
if ($movestock && !$error)
{
if ($movestock && !$error) {
// Call trigger
$result = $this->call_trigger('STOCK_MOVEMENT', $user);
if ($result < 0) $error++;
// End call triggers
}
if (!$error)
{
if (!$error) {
$this->db->commit();
return $mvid;
}
else
{
} else {
$this->db->rollback();
dol_syslog(get_class($this)."::_create error code=".$error, LOG_ERR);
return -6;
@ -768,35 +709,27 @@ class MouvementStock extends CommonObject
dol_syslog(get_class($this)."::_createSubProduct for parent product ".$idProduct, LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$i = 0;
while ($obj = $this->db->fetch_object($resql))
{
while ($obj = $this->db->fetch_object($resql)) {
$pids[$i] = $obj->fk_product_fils;
$pqtys[$i] = $obj->qty;
$i++;
}
$this->db->free($resql);
}
else
{
} else {
$error = -2;
}
// Create movement for each subproduct
foreach ($pids as $key => $value)
{
if (!$error)
{
foreach ($pids as $key => $value) {
if (!$error) {
$tmpmove = dol_clone($this, 1);
$result = $tmpmove->_create($user, $pids[$key], $entrepot_id, ($qty * $pqtys[$key]), $type, 0, $label, $inventorycode); // This will also call _createSubProduct making this recursive
if ($result < 0)
{
if ($result < 0) {
$this->error = $tmpmove->error;
$this->errors = array_merge($this->errors, $tmpmove->errors);
if ($result == -2)
{
if ($result == -2) {
$this->errors[] = $langs->trans("ErrorNoteAlsoThatSubProductCantBeFollowedByLot");
}
$error = $result;
@ -862,27 +795,26 @@ class MouvementStock extends CommonObject
}
/**
* Return nb of subproducts lines for a product
*
* @param int $id Id of product
* @return int <0 if KO, nb of subproducts if OK
* @deprecated A count($product->getChildsArbo($id,1)) is same. No reason to have this in this class.
*/
/*
public function nbOfSubProducts($id)
{
$nbSP=0;
// /**
// * Return nb of subproducts lines for a product
// *
// * @param int $id Id of product
// * @return int <0 if KO, nb of subproducts if OK
// * @deprecated A count($product->getChildsArbo($id,1)) is same. No reason to have this in this class.
// */
// public function nbOfSubProducts($id)
// {
// $nbSP=0;
$resql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."product_association";
$resql.= " WHERE fk_product_pere = ".((int) $id);
if ($this->db->query($resql))
{
$obj=$this->db->fetch_object($resql);
$nbSP=$obj->nb;
}
return $nbSP;
}*/
// $resql = "SELECT count(*) as nb FROM ".MAIN_DB_PREFIX."product_association";
// $resql.= " WHERE fk_product_pere = ".((int) $id);
// if ($this->db->query($resql))
// {
// $obj=$this->db->fetch_object($resql);
// $nbSP=$obj->nb;
// }
// return $nbSP;
// }
/**
* Count number of product in stock before a specific date
@ -901,8 +833,7 @@ class MouvementStock extends CommonObject
dol_syslog(get_class($this).__METHOD__.'', LOG_DEBUG);
$resql = $this->db->query($sql);
if ($resql)
{
if ($resql) {
$obj = $this->db->fetch_object($resql);
if ($obj) $nb = $obj->nb;
return (empty($nb) ? 0 : $nb);
@ -930,19 +861,16 @@ class MouvementStock extends CommonObject
$result = 0;
// Try to find an existing record with same batch number or id
if (is_numeric($dluo))
{
if (is_numeric($dluo)) {
$result = $pdluo->fetch($dluo);
if (empty($pdluo->id))
{
if (empty($pdluo->id)) {
// We didn't find the line. May be it was deleted before by a previous move in same transaction.
$this->error = 'Error. You ask a move on a record for a serial that does not exists anymore. May be you take the same serial on same warehouse several times in same shipment or it was used by another shipment. Remove this shipment and prepare another one.';
$this->errors[] = $this->error;
$result = -2;
}
} elseif (is_array($dluo)) {
if (isset($dluo['fk_product_stock']))
{
if (isset($dluo['fk_product_stock'])) {
$vfk_product_stock = $dluo['fk_product_stock'];
$vbatchnumber = $dluo['batchnumber'];
@ -956,8 +884,7 @@ class MouvementStock extends CommonObject
$result = -1;
}
if ($result >= 0)
{
if ($result >= 0) {
// No error
if ($pdluo->id > 0) { // product_batch record found
//print "Avant ".$pdluo->qty." Apres ".($pdluo->qty + $qty)."<br>";
@ -975,8 +902,7 @@ class MouvementStock extends CommonObject
$pdluo->batch = $vbatchnumber;
$result = $pdluo->create($user, 1);
if ($result < 0)
{
if ($result < 0) {
$this->error = $pdluo->error;
$this->errors = $pdluo->errors;
}