Skip to content

Commit

Permalink
FIX we should not allow to validate negative invoice if invoice is not a
Browse files Browse the repository at this point in the history
credit note.
  • Loading branch information
eldy committed Dec 30, 2024
1 parent e556dfe commit 7b69b6c
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 6 deletions.
5 changes: 4 additions & 1 deletion htdocs/compta/facture/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -2166,6 +2166,7 @@
$price_ht_devise = '';
$price_ttc = '';
$price_ttc_devise = '';

$price_min = '';
$price_min_ttc = '';

Expand Down Expand Up @@ -5837,7 +5838,9 @@ function js_recalculate_revenuestamp(){
}

// Validate
if ($object->status == Facture::STATUS_DRAFT && count($object->lines) > 0 && ((($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA || $object->type == Facture::TYPE_SITUATION) && (getDolGlobalString('FACTURE_ENABLE_NEGATIVE') || $object->total_ttc >= 0)) || ($object->type == Facture::TYPE_CREDIT_NOTE && $object->total_ttc <= 0))) {
if ($object->status == Facture::STATUS_DRAFT && count($object->lines) > 0
&& ((($object->type == Facture::TYPE_STANDARD || $object->type == Facture::TYPE_REPLACEMENT || $object->type == Facture::TYPE_DEPOSIT || $object->type == Facture::TYPE_PROFORMA || $object->type == Facture::TYPE_SITUATION) && (getDolGlobalString('FACTURE_ENABLE_NEGATIVE') || $object->total_ttc >= 0))
|| ($object->type == Facture::TYPE_CREDIT_NOTE && $object->total_ttc <= 0))) {
if ($usercanvalidate) {
unset($params['attr']['title']);
print dolGetButtonAction($langs->trans('Validate'), '', 'default', $_SERVER["PHP_SELF"].'?facid='.$object->id.'&action=valid&token='.newToken(), '', true, $params);
Expand Down
44 changes: 39 additions & 5 deletions htdocs/fourn/facture/card.php
Original file line number Diff line number Diff line change
Expand Up @@ -1591,12 +1591,26 @@
$idprod = GETPOSTINT('idprod');
}

$price_ht = '';
$price_ht_devise = '';
$price_ttc = '';
$price_ttc_devise = '';

if (GETPOST('price_ht') !== '') {
$price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
}
if (GETPOST('multicurrency_price_ht') !== '') {
$price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2);
}
if (GETPOST('price_ttc') !== '') {
$price_ttc = price2num(GETPOST('price_ttc'), 'MU', 2);
}
if (GETPOST('multicurrency_price_ttc') !== '') {
$price_ttc_devise = price2num(GETPOST('multicurrency_price_ttc'), 'CU', 2);
}

$tva_tx = (GETPOST('tva_tx') ? GETPOST('tva_tx') : 0); // Can be '1.2' or '1.2 (CODE)'

$price_ht = price2num(GETPOST('price_ht'), 'MU', 2);
$price_ht_devise = price2num(GETPOST('multicurrency_price_ht'), 'CU', 2);
$price_ttc = price2num(GETPOST('price_ttc'), 'MU', 2);
$price_ttc_devise = price2num(GETPOST('multicurrency_price_ttc'), 'CU', 2);
$qty = price2num(GETPOST('qty'.$predef, 'alpha'), 'MS');

$remise_percent = (GETPOSTISSET('remise_percent'.$predef) ? price2num(GETPOST('remise_percent'.$predef, 'alpha'), '', 2) : 0);
Expand All @@ -1623,6 +1637,24 @@
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('Type')), null, 'errors');
$error++;
}

if ($prod_entry_mode == 'free' && (!GETPOST('idprodfournprice') || GETPOST('idprodfournprice') == '-1') && (($price_ht < 0 && !getDolGlobalString('SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) || $price_ht == '') && (($price_ht_devise < 0 && !getDolGlobalString('SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) || $price_ht_devise == '') && $price_ttc === '' && $price_ttc_devise === '' && $object->type != FactureFournisseur::TYPE_CREDIT_NOTE) { // Unit price can be 0 but not ''
if (($price_ht < 0 || $price_ttc < 0) && !getDolGlobalString('SUPPLIER_INVOICE_ENABLE_NEGATIVE_LINES')) {

Check failure on line 1642 in htdocs/fourn/facture/card.php

View workflow job for this annotation

GitHub Actions / phpstan / php-stan (8.2)

Comparison operation "<" between '' and 0 is always true.

Check failure on line 1642 in htdocs/fourn/facture/card.php

View workflow job for this annotation

GitHub Actions / phpstan / php-stan (8.2)

Result of || is always true.
$langs->load("errors");
if ($object->type == $object::TYPE_DEPOSIT) {
// Using negative lines on deposit lead to headach and blocking problems when you want to consume them.
setEventMessages($langs->trans("ErrorLinesCantBeNegativeOnDeposits"), null, 'errors');
} else {
setEventMessages($langs->trans("ErrorFieldCantBeNegativeOnInvoice", $langs->transnoentitiesnoconv("UnitPriceHT"), $langs->transnoentitiesnoconv("CustomerAbsoluteDiscountShort")), null, 'errors');
}
$error++;
} else {
setEventMessages($langs->trans("ErrorFieldRequired", $langs->transnoentitiesnoconv("UnitPriceHT")), null, 'errors');
$error++;
}
}


if ($prod_entry_mode == 'free' && GETPOST('price_ht') === '' && GETPOST('price_ttc') === '' && $price_ht_devise === '') { // Unit price can be 0 but not ''
setEventMessages($langs->trans('ErrorFieldRequired', $langs->transnoentitiesnoconv('UnitPrice')), null, 'errors');
$error++;
Expand Down Expand Up @@ -4034,7 +4066,9 @@ function setRadioForTypeOfInvoice() {
}

// Validate
if ($action != 'confirm_edit' && $object->status == FactureFournisseur::STATUS_DRAFT) {
if ($action != 'confirm_edit' && $object->status == FactureFournisseur::STATUS_DRAFT && count($object->lines) > 0
&& ((($object->type == FactureFournisseur::TYPE_STANDARD || $object->type == FactureFournisseur::TYPE_REPLACEMENT || $object->type == FactureFournisseur::TYPE_DEPOSIT || $object->type == FactureFournisseur::TYPE_PROFORMA || $object->type == FactureFournisseur::TYPE_SITUATION) && (getDolGlobalString('SUPPLIER_INVOICE_ENABLE_NEGATIVE') || $object->total_ttc >= 0))

Check warning on line 4070 in htdocs/fourn/facture/card.php

View workflow job for this annotation

GitHub Actions / phan / Run phan

card.php: PhanDeprecatedClassConstant: Reference to deprecated class constant \FactureFournisseur::TYPE_PROFORMA defined at htdocs/core/class/commoninvoice.class.php:238 (Deprecated because: Remove this. A "proforma invoice" is an order with a look of invoice, not an invoice !)
|| ($object->type == FactureFournisseur::TYPE_CREDIT_NOTE && $object->total_ttc <= 0))) {
if (count($object->lines)) {

Check failure on line 4072 in htdocs/fourn/facture/card.php

View workflow job for this annotation

GitHub Actions / phpstan / php-stan (8.2)

If condition is always true.
if ($usercanvalidate) {
print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?id='.$object->id.'&action=valid&token='.newToken().'"';
Expand Down

0 comments on commit 7b69b6c

Please sign in to comment.