From 210926d23a7cf2f3cfdd28bb7216b832a863f4b3 Mon Sep 17 00:00:00 2001 From: Gauthier PC portable 024 Date: Wed, 20 Oct 2021 09:32:03 +0200 Subject: [PATCH] FIX : action buttons only if $permissiontoadd --- .../stocktransfer/stocktransfer_card.php | 165 +++++++++--------- 1 file changed, 84 insertions(+), 81 deletions(-) diff --git a/htdocs/product/stock/stocktransfer/stocktransfer_card.php b/htdocs/product/stock/stocktransfer/stocktransfer_card.php index 0c1d46bcd3e..7a2c3547bd8 100644 --- a/htdocs/product/stock/stocktransfer/stocktransfer_card.php +++ b/htdocs/product/stock/stocktransfer/stocktransfer_card.php @@ -281,89 +281,92 @@ if (empty($reshook)) { } } - // Décrémentation - if ($action == 'confirm_destock' && $confirm == 'yes' && $object->status == $object::STATUS_VALIDATED) { - $lines = $object->getLinesArray(); - if (!empty($lines)) { - $db->begin(); - foreach ($lines as $line) { - $res = $line->doStockMovement($label, $code_inv, $line->fk_warehouse_source); - if ($res <= 0) $error++; + if($permissiontoadd) { + // Décrémentation + if ($action == 'confirm_destock' && $confirm == 'yes' && $object->status == $object::STATUS_VALIDATED) { + $lines = $object->getLinesArray(); + if (!empty($lines)) { + $db->begin(); + foreach ($lines as $line) { + $res = $line->doStockMovement($label, $code_inv, $line->fk_warehouse_source); + if ($res <= 0) $error++; + } + if (empty($error)) $db->commit(); + else $db->rollback(); + } + if (empty($error)) { + $object->setStatut($object::STATUS_TRANSFERED, $id); + $object->status = $object::STATUS_TRANSFERED; + $object->date_reelle_depart = date('Y-m-d'); + $object->update($user); + setEventMessage('StockStransferDecremented'); } - if (empty($error)) $db->commit(); - else $db->rollback(); } - if (empty($error)) { - $object->setStatut($object::STATUS_TRANSFERED, $id); - $object->status = $object::STATUS_TRANSFERED; - $object->date_reelle_depart = date('Y-m-d'); - $object->update($user); - setEventMessage('StockStransferDecremented'); + + // Annulation décrémentation + if ($action == 'confirm_destockcancel' && $confirm == 'yes' && $object->status == $object::STATUS_TRANSFERED) { + $lines = $object->getLinesArray(); + if (!empty($lines)) { + $db->begin(); + foreach ($lines as $line) { + $res = $line->doStockMovement($label, $code_inv, $line->fk_warehouse_source, 0); + if ($res <= 0) $error++; + } + if (empty($error)) $db->commit(); + else $db->rollback(); + } + if (empty($error)) { + $object->setStatut($object::STATUS_VALIDATED, $id); + $object->status = $object::STATUS_VALIDATED; + $object->date_reelle_depart = null; + $object->update($user); + setEventMessage('StockStransferDecrementedCancel', 'warnings'); + } + } + + // Incrémentation + if ($action == 'confirm_addstock' && $confirm == 'yes' && $object->status == $object::STATUS_TRANSFERED) { + $lines = $object->getLinesArray(); + if (!empty($lines)) { + $db->begin(); + foreach ($lines as $line) { + $res = $line->doStockMovement($label, $code_inv, $line->fk_warehouse_destination, 0); + if ($res <= 0) $error++; + } + if (empty($error)) $db->commit(); + else $db->rollback(); + } + if (empty($error)) { + $object->setStatut($object::STATUS_CLOSED, $id); + $object->status = $object::STATUS_CLOSED; + $object->date_reelle_arrivee = date('Y-m-d'); + $object->update($user); + setEventMessage('StockStransferIncrementedShort'); + } + } + + // Annulation incrémentation + if ($action == 'confirm_addstockcancel' && $confirm == 'yes' && $object->status == $object::STATUS_CLOSED) { + $lines = $object->getLinesArray(); + if (!empty($lines)) { + $db->begin(); + foreach ($lines as $line) { + $res = $line->doStockMovement($label, $code_inv, $line->fk_warehouse_destination); + if ($res <= 0) $error++; + } + if (empty($error)) $db->commit(); + else $db->rollback(); + } + if (empty($error)) { + $object->setStatut($object::STATUS_TRANSFERED, $id); + $object->status = $object::STATUS_TRANSFERED; + $object->date_reelle_arrivee = null; + $object->update($user); + setEventMessage('StockStransferIncrementedShortCancel', 'warnings'); + } } } - // Annulation décrémentation - if ($action == 'confirm_destockcancel' && $confirm == 'yes' && $object->status == $object::STATUS_TRANSFERED) { - $lines = $object->getLinesArray(); - if (!empty($lines)) { - $db->begin(); - foreach ($lines as $line) { - $res = $line->doStockMovement($label, $code_inv, $line->fk_warehouse_source, 0); - if ($res <= 0) $error++; - } - if (empty($error)) $db->commit(); - else $db->rollback(); - } - if (empty($error)) { - $object->setStatut($object::STATUS_VALIDATED, $id); - $object->status = $object::STATUS_VALIDATED; - $object->date_reelle_depart = null; - $object->update($user); - setEventMessage('StockStransferDecrementedCancel', 'warnings'); - } - } - - // Incrémentation - if ($action == 'confirm_addstock' && $confirm == 'yes' && $object->status == $object::STATUS_TRANSFERED) { - $lines = $object->getLinesArray(); - if (!empty($lines)) { - $db->begin(); - foreach ($lines as $line) { - $res = $line->doStockMovement($label, $code_inv, $line->fk_warehouse_destination, 0); - if ($res <= 0) $error++; - } - if (empty($error)) $db->commit(); - else $db->rollback(); - } - if (empty($error)) { - $object->setStatut($object::STATUS_CLOSED, $id); - $object->status = $object::STATUS_CLOSED; - $object->date_reelle_arrivee = date('Y-m-d'); - $object->update($user); - setEventMessage('StockStransferIncrementedShort'); - } - } - - // Annulation incrémentation - if ($action == 'confirm_addstockcancel' && $confirm == 'yes' && $object->status == $object::STATUS_CLOSED) { - $lines = $object->getLinesArray(); - if (!empty($lines)) { - $db->begin(); - foreach ($lines as $line) { - $res = $line->doStockMovement($label, $code_inv, $line->fk_warehouse_destination); - if ($res <= 0) $error++; - } - if (empty($error)) $db->commit(); - else $db->rollback(); - } - if (empty($error)) { - $object->setStatut($object::STATUS_TRANSFERED, $id); - $object->status = $object::STATUS_TRANSFERED; - $object->date_reelle_arrivee = null; - $object->update($user); - setEventMessage('StockStransferIncrementedShortCancel', 'warnings'); - } - } // Set incoterm if ($action == 'set_incoterms' && !empty($conf->incoterm->enabled) && $permissiontoadd) { $result = $object->setIncoterms(GETPOST('incoterm_id', 'int'), GETPOST('location_incoterms', 'alpha')); @@ -982,12 +985,12 @@ if ($object->id > 0 && (empty($action) || ($action != 'edit' && $action != 'crea print ''.$langs->trans("Validate").''; } } - } elseif ($object->status == $object::STATUS_VALIDATED) { + } elseif ($object->status == $object::STATUS_VALIDATED && $permissiontoadd) { print ''.$langs->trans("StockTransferDecrementation").''; - } elseif ($object->status == $object::STATUS_TRANSFERED) { + } elseif ($object->status == $object::STATUS_TRANSFERED && $permissiontoadd) { print ''.$langs->trans("StockTransferDecrementationCancel").''; print ''.$langs->trans("StockTransferIncrementation").''; - } elseif ($object->status == $object::STATUS_CLOSED) { + } elseif ($object->status == $object::STATUS_CLOSED && $permissiontoadd) { print ''.$langs->trans("StockTransferIncrementationCancel").''; }