Skip to content

Commit

Permalink
FIX phpcs nestling too high level
Browse files Browse the repository at this point in the history
  • Loading branch information
lvessiller-opendsi committed Feb 21, 2020
1 parent 71c9b94 commit ec19b2f
Showing 1 changed file with 36 additions and 35 deletions.
71 changes: 36 additions & 35 deletions htdocs/compta/facture/class/facture.class.php
Expand Up @@ -2594,54 +2594,55 @@ public function validate($user, $force_number = '', $idwarehouse = 0, $notrigger
if (!is_array($resBatchList)) {
$error++;
$this->error = $this->db->lasterror();
} else {
}

if (!$error) {
$batchList = $resBatchList;
if (empty($batchList)) {
$error++;
$langs->load('errors');
$warehouseStatic->fetch($idwarehouse);
$this->error = $langs->trans('ErrorBatchNoFoundForProductInWarehouse', $productStatic->label, $warehouseStatic->ref);
dol_syslog(__METHOD__ . ' Error: ' . $langs->transnoentitiesnoconv('ErrorBatchNoFoundForProductInWarehouse', $productStatic->label, $warehouseStatic->ref), LOG_ERR);
} else {
foreach ($batchList as $batch) {
if ($batch->qty <= 0) continue; // try to decrement only batches have positive quantity first
}

// enough quantity in this batch
if ($batch->qty >= $product_qty_remain) {
$product_batch_qty = $product_qty_remain;
}
// not enough (take all in batch)
else {
$product_batch_qty = $batch->qty;
}
$result = $mouvP->livraison($user, $productStatic->id, $idwarehouse, $product_batch_qty, $this->lines[$i]->subprice, $langs->trans('InvoiceValidatedInDolibarr', $num), '', '', '', $batch->batch);
if ($result < 0) {
$error++;
$this->error = $mouvP->error;
break;
}
foreach ($batchList as $batch) {
if ($batch->qty <= 0) continue; // try to decrement only batches have positive quantity first

$product_qty_remain -= $product_batch_qty;
// all product quantity was decremented
if ($product_qty_remain <= 0) break;
// enough quantity in this batch
if ($batch->qty >= $product_qty_remain) {
$product_batch_qty = $product_qty_remain;
} // not enough (take all in batch)
else {
$product_batch_qty = $batch->qty;
}
$result = $mouvP->livraison($user, $productStatic->id, $idwarehouse, $product_batch_qty, $this->lines[$i]->subprice, $langs->trans('InvoiceValidatedInDolibarr', $num), '', '', '', $batch->batch);
if ($result < 0) {
$error++;
$this->error = $mouvP->error;
break;
}

if (!$error && $product_qty_remain>0) {
if ($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER) {
// take in the first batch
$batch = $batchList[0];
$result = $mouvP->livraison($user, $productStatic->id, $idwarehouse, $product_qty_remain, $this->lines[$i]->subprice, $langs->trans('InvoiceValidatedInDolibarr', $num), '', '', '', $batch->batch);
if ($result < 0) {
$error++;
$this->error = $mouvP->error;
}
} else {
$product_qty_remain -= $product_batch_qty;
// all product quantity was decremented
if ($product_qty_remain <= 0) break;
}

if (!$error && $product_qty_remain > 0) {
if ($conf->global->STOCK_ALLOW_NEGATIVE_TRANSFER) {
// take in the first batch
$batch = $batchList[0];
$result = $mouvP->livraison($user, $productStatic->id, $idwarehouse, $product_qty_remain, $this->lines[$i]->subprice, $langs->trans('InvoiceValidatedInDolibarr', $num), '', '', '', $batch->batch);
if ($result < 0) {
$error++;
$langs->load('errors');
$warehouseStatic->fetch($idwarehouse);
$this->error = $langs->trans('ErrorBatchNoFoundEnoughQuantityForProductInWarehouse', $productStatic->label, $warehouseStatic->ref);
dol_syslog(__METHOD__ . ' Error: ' . $langs->transnoentitiesnoconv('ErrorBatchNoFoundEnoughQuantityForProductInWarehouse', $productStatic->label, $warehouseStatic->ref), LOG_ERR);
$this->error = $mouvP->error;
}
} else {
$error++;
$langs->load('errors');
$warehouseStatic->fetch($idwarehouse);
$this->error = $langs->trans('ErrorBatchNoFoundEnoughQuantityForProductInWarehouse', $productStatic->label, $warehouseStatic->ref);
dol_syslog(__METHOD__ . ' Error: ' . $langs->transnoentitiesnoconv('ErrorBatchNoFoundEnoughQuantityForProductInWarehouse', $productStatic->label, $warehouseStatic->ref), LOG_ERR);
}
}
}
Expand Down

0 comments on commit ec19b2f

Please sign in to comment.