Fix test if qualified for stock change at wrong place

This commit is contained in:
Laurent Destailleur 2019-05-20 12:47:02 +02:00
parent 3c1b860da4
commit 827a2e1809

View File

@ -518,6 +518,9 @@ if (empty($reshook))
} }
} }
// Check for warehouse
if ($object->type != Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL))
{
$qualified_for_stock_change = 0; $qualified_for_stock_change = 0;
if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
$qualified_for_stock_change = $object->hasProductsOrServices(2); $qualified_for_stock_change = $object->hasProductsOrServices(2);
@ -525,8 +528,7 @@ if (empty($reshook))
$qualified_for_stock_change = $object->hasProductsOrServices(1); $qualified_for_stock_change = $object->hasProductsOrServices(1);
} }
// Check for warehouse if ($qualified_for_stock_change)
if ($object->type != Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change)
{ {
if (! $idwarehouse || $idwarehouse == - 1) { if (! $idwarehouse || $idwarehouse == - 1) {
$error++; $error++;
@ -534,6 +536,7 @@ if (empty($reshook))
$action = ''; $action = '';
} }
} }
}
if (! $error) if (! $error)
{ {
@ -575,6 +578,9 @@ if (empty($reshook))
$object->fetch($id); $object->fetch($id);
$object->fetch_thirdparty(); $object->fetch_thirdparty();
// Check parameters
if ($object->type != Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL))
{
$qualified_for_stock_change = 0; $qualified_for_stock_change = 0;
if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
$qualified_for_stock_change = $object->hasProductsOrServices(2); $qualified_for_stock_change = $object->hasProductsOrServices(2);
@ -582,8 +588,7 @@ if (empty($reshook))
$qualified_for_stock_change = $object->hasProductsOrServices(1); $qualified_for_stock_change = $object->hasProductsOrServices(1);
} }
// Check parameters if ($qualified_for_stock_change))
if ($object->type != Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change)
{ {
if (! $idwarehouse || $idwarehouse == - 1) { if (! $idwarehouse || $idwarehouse == - 1) {
$error++; $error++;
@ -591,6 +596,7 @@ if (empty($reshook))
$action = ''; $action = '';
} }
} }
}
if (! $error) { if (! $error) {
// On verifie si la facture a des paiements // On verifie si la facture a des paiements
@ -3426,6 +3432,8 @@ elseif ($id > 0 || ! empty($ref))
$text = $langs->trans('ConfirmDeleteBill', $object->ref); $text = $langs->trans('ConfirmDeleteBill', $object->ref);
$formquestion = array(); $formquestion = array();
if ($object->type != Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $object->statut >= 1)
{
$qualified_for_stock_change = 0; $qualified_for_stock_change = 0;
if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
$qualified_for_stock_change = $object->hasProductsOrServices(2); $qualified_for_stock_change = $object->hasProductsOrServices(2);
@ -3433,7 +3441,7 @@ elseif ($id > 0 || ! empty($ref))
$qualified_for_stock_change = $object->hasProductsOrServices(1); $qualified_for_stock_change = $object->hasProductsOrServices(1);
} }
if ($object->type != Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change && $object->statut >= 1) if ($qualified_for_stock_change)
{ {
$langs->load("stocks"); $langs->load("stocks");
require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php'; require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php';
@ -3448,6 +3456,11 @@ elseif ($id > 0 || ! empty($ref))
array('type' => 'other','name' => 'idwarehouse','label' => $label,'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1, 0, 0, $langs->trans("NoStockAction"), 0, $forcecombo)) array('type' => 'other','name' => 'idwarehouse','label' => $label,'value' => $formproduct->selectWarehouses(GETPOST('idwarehouse')?GETPOST('idwarehouse'):'ifone', 'idwarehouse', '', 1, 0, 0, $langs->trans("NoStockAction"), 0, $forcecombo))
); );
$formconfirm = $form->formconfirm($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $langs->trans('DeleteBill'), $text, 'confirm_delete', $formquestion, "yes", 1); $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $langs->trans('DeleteBill'), $text, 'confirm_delete', $formquestion, "yes", 1);
}
else
{
$formconfirm = $form->formconfirm($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $langs->trans('DeleteBill'), $text, 'confirm_delete', '', 'no', 1);
}
} else { } else {
$formconfirm = $form->formconfirm($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $langs->trans('DeleteBill'), $text, 'confirm_delete', '', 'no', 1); $formconfirm = $form->formconfirm($_SERVER['PHP_SELF'] . '?facid=' . $object->id, $langs->trans('DeleteBill'), $text, 'confirm_delete', '', 'no', 1);
} }
@ -3496,6 +3509,8 @@ elseif ($id > 0 || ! empty($ref))
} }
$formquestion = array(); $formquestion = array();
if ($object->type != Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL))
{
$qualified_for_stock_change = 0; $qualified_for_stock_change = 0;
if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
$qualified_for_stock_change = $object->hasProductsOrServices(2); $qualified_for_stock_change = $object->hasProductsOrServices(2);
@ -3503,7 +3518,7 @@ elseif ($id > 0 || ! empty($ref))
$qualified_for_stock_change = $object->hasProductsOrServices(1); $qualified_for_stock_change = $object->hasProductsOrServices(1);
} }
if ($object->type != Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change) if ($qualified_for_stock_change)
{ {
$langs->load("stocks"); $langs->load("stocks");
require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php'; require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php';
@ -3526,6 +3541,7 @@ elseif ($id > 0 || ! empty($ref))
// => 1), // => 1),
array('type' => 'other','name' => 'idwarehouse','label' => $label,'value' => $value)); array('type' => 'other','name' => 'idwarehouse','label' => $label,'value' => $value));
} }
}
if ($object->type != Facture::TYPE_CREDIT_NOTE && $object->total_ttc < 0) // Can happen only if $conf->global->FACTURE_ENABLE_NEGATIVE is on if ($object->type != Facture::TYPE_CREDIT_NOTE && $object->total_ttc < 0) // Can happen only if $conf->global->FACTURE_ENABLE_NEGATIVE is on
{ {
$text .= '<br>' . img_warning() . ' ' . $langs->trans("ErrorInvoiceOfThisTypeMustBePositive"); $text .= '<br>' . img_warning() . ' ' . $langs->trans("ErrorInvoiceOfThisTypeMustBePositive");
@ -3538,13 +3554,17 @@ elseif ($id > 0 || ! empty($ref))
$text = $langs->trans('ConfirmUnvalidateBill', $object->ref); $text = $langs->trans('ConfirmUnvalidateBill', $object->ref);
$formquestion = array(); $formquestion = array();
if ($object->type != Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL))
{
$qualified_for_stock_change = 0; $qualified_for_stock_change = 0;
if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) { if (empty($conf->global->STOCK_SUPPORTS_SERVICES)) {
$qualified_for_stock_change = $object->hasProductsOrServices(2); $qualified_for_stock_change = $object->hasProductsOrServices(2);
} else { } else {
$qualified_for_stock_change = $object->hasProductsOrServices(1); $qualified_for_stock_change = $object->hasProductsOrServices(1);
} }
if ($object->type != Facture::TYPE_DEPOSIT && ! empty($conf->global->STOCK_CALCULATE_ON_BILL) && $qualified_for_stock_change) {
if ($qualified_for_stock_change)
{
$langs->load("stocks"); $langs->load("stocks");
require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php'; require_once DOL_DOCUMENT_ROOT . '/product/class/html.formproduct.class.php';
require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php'; require_once DOL_DOCUMENT_ROOT . '/product/stock/class/entrepot.class.php';
@ -3566,6 +3586,7 @@ elseif ($id > 0 || ! empty($ref))
// => 1), // => 1),
array('type' => 'other','name' => 'idwarehouse','label' => $label,'value' => $value)); array('type' => 'other','name' => 'idwarehouse','label' => $label,'value' => $value));
} }
}
$formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?facid=' . $object->id, $langs->trans('UnvalidateBill'), $text, 'confirm_modif', $formquestion, "yes", 1); $formconfirm = $form->formconfirm($_SERVER["PHP_SELF"] . '?facid=' . $object->id, $langs->trans('UnvalidateBill'), $text, 'confirm_modif', $formquestion, "yes", 1);
} }