Merge pull request #24760 from NextGestion/dolibarr_fixbugs
NEW Can restore product in stock when deleting the supplier invoice
This commit is contained in:
commit
9d466793fa
4 changed files with 92 additions and 9 deletions
|
|
@ -1856,7 +1856,11 @@ class FactureFournisseur extends CommonInvoice
|
|||
$result = $mouvP->reception($user, $this->lines[$i]->fk_product, $idwarehouse, $this->lines[$i]->qty, $up_ht_disc, $langs->trans("InvoiceValidatedInDolibarr", $num));
|
||||
}
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
$this->error = $mouvP->error;
|
||||
if (count($mouvP->errors)) {
|
||||
$this->errors = $mouvP->errors;
|
||||
}
|
||||
return -2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -1935,9 +1939,10 @@ class FactureFournisseur extends CommonInvoice
|
|||
*
|
||||
* @param User $user Object user that modify
|
||||
* @param int $idwarehouse Id warehouse to use for stock change.
|
||||
* @param int $notrigger 1=Does not execute triggers, 0= execute triggers
|
||||
* @return int <0 if KO, >0 if OK
|
||||
*/
|
||||
public function setDraft($user, $idwarehouse = -1)
|
||||
public function setDraft($user, $idwarehouse = -1, $notrigger = 0)
|
||||
{
|
||||
// phpcs:enable
|
||||
global $conf, $langs;
|
||||
|
|
|
|||
|
|
@ -261,12 +261,42 @@ if (empty($reshook)) {
|
|||
$isErasable = $object->is_erasable();
|
||||
|
||||
if (($usercandelete && $isErasable > 0) || ($usercancreate && $isErasable == 1)) {
|
||||
$result = $object->delete($user);
|
||||
if ($result > 0) {
|
||||
header('Location: list.php?restore_lastsearch_values=1');
|
||||
exit;
|
||||
} else {
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
$revertstock = GETPOST('revertstock');
|
||||
|
||||
if ($revertstock) {
|
||||
$idwarehouse = GETPOST('idwarehouse');
|
||||
|
||||
$qualified_for_stock_change = 0;
|
||||
if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
|
||||
$qualified_for_stock_change = $object->hasProductsOrServices(2);
|
||||
} else {
|
||||
$qualified_for_stock_change = $object->hasProductsOrServices(1);
|
||||
}
|
||||
|
||||
// Check parameters
|
||||
if (isModEnabled('stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
|
||||
$langs->load("stocks");
|
||||
if (!$idwarehouse || $idwarehouse == -1) {
|
||||
$error++;
|
||||
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv("Warehouse")), null, 'errors');
|
||||
$action = 'delete';
|
||||
} else {
|
||||
$result = $object->setDraft($user, $idwarehouse);
|
||||
if ($result < 0) {
|
||||
$error++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (!$error) {
|
||||
$result = $object->delete($user);
|
||||
if ($result > 0) {
|
||||
header('Location: list.php?restore_lastsearch_values=1');
|
||||
exit;
|
||||
} else {
|
||||
setEventMessages($object->error, $object->errors, 'errors');
|
||||
}
|
||||
}
|
||||
}
|
||||
} elseif ($action == 'confirm_deleteline' && $confirm == 'yes' && $usercancreate) {
|
||||
|
|
@ -3013,7 +3043,53 @@ if ($action == 'create') {
|
|||
|
||||
// Confirmation de la suppression de la facture fournisseur
|
||||
if ($action == 'delete') {
|
||||
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteBill'), $langs->trans('ConfirmDeleteBill'), 'confirm_delete', '', 0, 1);
|
||||
$formquestion = array();
|
||||
|
||||
$qualified_for_stock_change = 0;
|
||||
if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
|
||||
$qualified_for_stock_change = $object->hasProductsOrServices(2);
|
||||
} else {
|
||||
$qualified_for_stock_change = $object->hasProductsOrServices(1);
|
||||
}
|
||||
|
||||
if (isModEnabled('stock') && !empty($conf->global->STOCK_CALCULATE_ON_SUPPLIER_BILL) && $qualified_for_stock_change) {
|
||||
$langs->load("stocks");
|
||||
require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
|
||||
$formproduct = new FormProduct($db);
|
||||
$warehouse = new Entrepot($db);
|
||||
$warehouse_array = $warehouse->list_array();
|
||||
|
||||
$selectwarehouse = '<span class="questionrevertstock hidden">';
|
||||
if (count($warehouse_array) == 1) {
|
||||
$label = $object->type == FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans("WarehouseForStockIncrease", current($warehouse_array)) : $langs->trans("WarehouseForStockDecrease", current($warehouse_array));
|
||||
$selectwarehouse .= '<input type="hidden" id="idwarehouse" name="idwarehouse" value="'.key($warehouse_array).'">';
|
||||
} else {
|
||||
$label = $object->type == FactureFournisseur::TYPE_CREDIT_NOTE ? $langs->trans("SelectWarehouseForStockIncrease") : $langs->trans("SelectWarehouseForStockDecrease");
|
||||
$selectwarehouse .= $formproduct->selectWarehouses(GETPOST('idwarehouse') ?GETPOST('idwarehouse') : 'ifone', 'idwarehouse', '', 1);
|
||||
}
|
||||
$selectwarehouse .= '</span>';
|
||||
|
||||
$selectyesno = array(0 => $langs->trans('No'), 1 => $langs->trans('Yes'));
|
||||
|
||||
print '<script type="text/javascript">
|
||||
$(document).ready(function() {
|
||||
$("#revertstock").change(function() {
|
||||
if(this.value > 0) {
|
||||
$(".questionrevertstock").removeClass("hidden");
|
||||
} else {
|
||||
$(".questionrevertstock").addClass("hidden");
|
||||
}
|
||||
});
|
||||
});
|
||||
</script>';
|
||||
|
||||
$formquestion = array(
|
||||
array('type' => 'select', 'name' => 'revertstock', 'label' => $langs->trans("RevertProductsToStock"), 'select_show_empty' => 0, 'values' => $selectyesno),
|
||||
array('type' => 'other', 'name' => 'idwarehouse', 'label' => $label, 'value' => $selectwarehouse, 'tdclass' => 'questionrevertstock hidden')
|
||||
);
|
||||
}
|
||||
|
||||
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"].'?id='.$object->id, $langs->trans('DeleteBill'), $langs->trans('ConfirmDeleteBill'), 'confirm_delete', $formquestion, 1, 1);
|
||||
}
|
||||
if ($action == 'deletepayment') {
|
||||
$payment_id = GETPOST('paiement_id');
|
||||
|
|
|
|||
|
|
@ -119,6 +119,7 @@ PersonalStock=Personal stock %s
|
|||
ThisWarehouseIsPersonalStock=This warehouse represents personal stock of %s %s
|
||||
SelectWarehouseForStockDecrease=Choose warehouse to use for stock decrease
|
||||
SelectWarehouseForStockIncrease=Choose warehouse to use for stock increase
|
||||
RevertProductsToStock=Revert products to stock ?
|
||||
NoStockAction=No stock action
|
||||
DesiredStock=Desired Stock
|
||||
DesiredStockDesc=This stock amount will be the value used to fill the stock by replenishment feature.
|
||||
|
|
|
|||
|
|
@ -119,6 +119,7 @@ PersonalStock=Stock personnel %s
|
|||
ThisWarehouseIsPersonalStock=Cet entrepôt représente le stock personnel de %s %s
|
||||
SelectWarehouseForStockDecrease=Sélectionner l'entrepôt à utiliser pour la décrémentation du stock
|
||||
SelectWarehouseForStockIncrease=Sélectionner l'entrepôt à utiliser pour l'incrémentation du stock
|
||||
RevertProductsToStock=Remettre les produits en stock ?
|
||||
NoStockAction=Pas d'action sur l'entrepôt
|
||||
DesiredStock=Stock désiré optimal
|
||||
DesiredStockDesc=Le stock optimal sera la valeur utilisée pour remplir le stock avec la fonction de réapprovisionnement
|
||||
|
|
|
|||
Loading…
Reference in a new issue