From 6d94c6150b4d481cfd80c6aa24e6eb160c3c1b79 Mon Sep 17 00:00:00 2001 From: Laurent Destailleur Date: Mon, 13 Dec 2021 17:56:28 +0100 Subject: [PATCH] FIX sign of unit price into the supplier credit note --- htdocs/fourn/class/fournisseur.facture.class.php | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/htdocs/fourn/class/fournisseur.facture.class.php b/htdocs/fourn/class/fournisseur.facture.class.php index d966a94769d..6dd88d68374 100644 --- a/htdocs/fourn/class/fournisseur.facture.class.php +++ b/htdocs/fourn/class/fournisseur.facture.class.php @@ -2147,10 +2147,12 @@ class FactureFournisseur extends CommonInvoice $line->context = $this->context; $line->description = $desc; - $line->subprice = $pu_ht; - $line->pu_ht = $pu_ht; - $line->pu_ttc = $pu_ttc; - $line->qty = $qty; + + $line->qty = ($this->type == self::TYPE_CREDIT_NOTE ? abs($qty) : $qty); // For credit note, quantity is always positive and unit price negative + $line->subprice = ($this->type == self::TYPE_CREDIT_NOTE ? -abs($pu_ht) : $pu_ht); // For credit note, unit price always negative, always positive otherwise + $line->pu_ht = ($this->type == self::TYPE_CREDIT_NOTE ? -abs($pu_ht) : $pu_ht); // For credit note, unit price always negative, always positive otherwise + $line->pu_ttc = ($this->type == self::TYPE_CREDIT_NOTE ? -abs($pu_ttc) : $pu_ttc); // For credit note, unit price always negative, always positive otherwise + $line->remise_percent = $remise_percent; $line->ref_supplier = $ref_supplier; @@ -2163,11 +2165,13 @@ class FactureFournisseur extends CommonInvoice $line->localtax2_tx = $txlocaltax2; $line->localtax1_type = empty($localtaxes_type[0]) ? '' : $localtaxes_type[0]; $line->localtax2_type = empty($localtaxes_type[2]) ? '' : $localtaxes_type[2]; + $line->total_ht = (($this->type == self::TYPE_CREDIT_NOTE || $qty < 0) ?-abs($total_ht) : $total_ht); $line->total_tva = (($this->type == self::TYPE_CREDIT_NOTE || $qty < 0) ?-abs($total_tva) : $total_tva); $line->total_localtax1 = $total_localtax1; $line->total_localtax2 = $total_localtax2; $line->total_ttc = (($this->type == self::TYPE_CREDIT_NOTE || $qty < 0) ?-abs($total_ttc) : $total_ttc); + $line->fk_product = $idproduct; $line->product_type = $product_type; $line->info_bits = $info_bits;