src/PrestaShop/Invoice/Creator.php
protected function getDiscountLinesCreditNote()
    {
        $result = array();

        // Get total amount credited.
        /** @noinspection PhpUndefinedFieldInspection */
        $creditSlipAmountInc = $this->creditSlip->total_products_tax_incl;

        // Get sum of product lines.
        $lines = $this->creditSlip->getOrdersSlipProducts($this->invoiceSource->getId(), $this->order);
        $detailsAmountInc = array_reduce($lines, function ($sum, $item) {
            $sum += $item['total_price_tax_incl'];
            return $sum;
        }, 0.0);

        // We assume that if total < sum(details), a discount given on the
        // original order has now been subtracted from the amount credited.
        if (!Number::floatsAreEqual($creditSlipAmountInc, $detailsAmountInc, 0.05)
            && $creditSlipAmountInc < $detailsAmountInc
        ) {
            // PS Error: total_products_tax_excl is not adjusted (whereas
            // total_products_tax_incl is) when a discount is subtracted from
            // the amount to be credited.
            // So we cannot calculate the discount ex VAT ourselves.
            // What we can try is the following: Get the order cart rules to see
            // if 1 or all of those match the discount amount here.
            $discountAmountInc = $detailsAmountInc - $creditSlipAmountInc;
            $totalOrderDiscountInc = 0.0;
            // Note: The sign of the entries in $orderDiscounts will be correct.
            $orderDiscounts = $this->getDiscountLinesOrder();

            foreach ($orderDiscounts as $key => $orderDiscount) {
                if (Number::floatsAreEqual($orderDiscount[Meta::UnitPriceInc], $discountAmountInc)) {
                    // Return this single line.
                    $from = $to = $key;
                    break;
                }
                $totalOrderDiscountInc += $orderDiscount[Meta::UnitPriceInc];
                if (Number::floatsAreEqual($totalOrderDiscountInc, $discountAmountInc)) {
                    // Return all lines up to here.
                    $from = 0;
                    $to = $key;
                    break;
                }
            }

            if (isset($from) && isset($to)) {
                $result = array_slice($orderDiscounts, $from, $to - $from + 1);
                // Correct meta-invoice-amount.
                $totalOrderDiscountEx = array_reduce($result, function ($sum, $item) {
                    $sum += $item[Tag::Quantity] * $item[Tag::UnitPrice];
                    return $sum;
                }, 0.0);
                $this->invoice[Tag::Customer][Tag::Invoice][Meta::InvoiceAmount] += $totalOrderDiscountEx;
            } //else {
                // We could not match a discount with the difference between the
                // total amount credited and the sum of the products returned. A
                // manual line will correct the invoice.
            //}
        }
        return $result;
    }
protected function getDiscountLinesCreditNote()
    {
        $result = array();

        // Get total amount credited.
        /** @noinspection PhpUndefinedFieldInspection */
        $creditSlipAmountInc = $this->creditSlip->total_products_tax_incl;

        // Get sum of product lines.
        $lines = $this->creditSlip->getOrdersSlipProducts($this->invoiceSource->getId(), $this->order);
        $detailsAmountInc = array_reduce($lines, function ($sum, $item) {
            $sum += $item['total_price_tax_incl'];
            return $sum;
        }, 0.0);

        // We assume that if total < sum(details), a discount given on the
        // original order has now been subtracted from the amount credited.
        if (!Number::floatsAreEqual($creditSlipAmountInc, $detailsAmountInc, 0.05)
            && $creditSlipAmountInc < $detailsAmountInc
        ) {
            // PS Error: total_products_tax_excl is not adjusted (whereas
            // total_products_tax_incl is) when a discount is subtracted from
            // the amount to be credited.
            // So we cannot calculate the discount ex VAT ourselves.
            // What we can try is the following: Get the order cart rules to see
            // if 1 or all of those match the discount amount here.
            $discountAmountInc = $detailsAmountInc - $creditSlipAmountInc;
            $totalOrderDiscountInc = 0.0;
            // Note: The sign of the entries in $orderDiscounts will be correct.
            $orderDiscounts = $this->getDiscountLinesOrder();

            foreach ($orderDiscounts as $key => $orderDiscount) {
                if (Number::floatsAreEqual($orderDiscount[Meta::UnitPriceInc], $discountAmountInc)) {
                    // Return this single line.
                    $from = $to = $key;
                    break;
                }
                $totalOrderDiscountInc += $orderDiscount[Meta::UnitPriceInc];
                if (Number::floatsAreEqual($totalOrderDiscountInc, $discountAmountInc)) {
                    // Return all lines up to here.
                    $from = 0;
                    $to = $key;
                    break;
                }
            }

            if (isset($from) && isset($to)) {
                $result = array_slice($orderDiscounts, $from, $to - $from + 1);
                // Correct meta-invoice-amount.
                $totalOrderDiscountEx = array_reduce($result, function ($sum, $item) {
                    $sum += $item[Tag::Quantity] * $item[Tag::UnitPrice];
                    return $sum;
                }, 0.0);
                $this->invoice[Tag::Customer][Tag::Invoice][Meta::InvoiceAmount] += $totalOrderDiscountEx;
            } //else {
                // We could not match a discount with the difference between the
                // total amount credited and the sum of the products returned. A
                // manual line will correct the invoice.
            //}
        }
        return $result;
    }
protected function getDiscountLinesCreditNote ( ) { $ result = array ( ) ; // Get total amount credited. /** @noinspection PhpUndefinedFieldInspection */ $ creditSlipAmountInc = $ this -> creditSlip -> total_products_tax_incl ; // Get sum of product lines. $ lines = $ this -> creditSlip -> getOrdersSlipProducts ( $ this -> invoiceSource -> getId ( ) , $ this -> order ) ; $ detailsAmountInc = array_reduce ( $ lines , function ( $ sum , $ item ) { $ sum += $ item [ 'total_price_tax_incl' ] ; return $ sum ; } , 0.0 ) ; // We assume that if total < sum(details), a discount given on the // original order has now been subtracted from the amount credited. if ( ! Number :: floatsAreEqual ( $ creditSlipAmountInc , $ detailsAmountInc , 0.05 ) && $ creditSlipAmountInc < $ detailsAmountInc ) { // PS Error: total_products_tax_excl is not adjusted (whereas // total_products_tax_incl is) when a discount is subtracted from // the amount to be credited. // So we cannot calculate the discount ex VAT ourselves. // What we can try is the following: Get the order cart rules to see // if 1 or all of those match the discount amount here. $ discountAmountInc = $ detailsAmountInc - $ creditSlipAmountInc ; $ totalOrderDiscountInc = 0.0 ; // Note: The sign of the entries in $orderDiscounts will be correct. $ orderDiscounts = $ this -> getDiscountLinesOrder ( ) ; foreach ( $ orderDiscounts as $ key => $ orderDiscount ) { if ( Number :: floatsAreEqual ( $ orderDiscount [ Meta :: UnitPriceInc ] , $ discountAmountInc ) ) { // Return this single line. $ from = $ to = $ key ; break ; } $ totalOrderDiscountInc += $ orderDiscount [ Meta :: UnitPriceInc ] ; if ( Number :: floatsAreEqual ( $ totalOrderDiscountInc , $ discountAmountInc ) ) { // Return all lines up to here. $ from = 0 ; $ to = $ key ; break ; } } if ( isset ( $ from ) && isset ( $ to ) ) { $ result = array_slice ( $ orderDiscounts , $ from , $ to - $ from + 1 ) ; // Correct meta-invoice-amount. $ totalOrderDiscountEx = array_reduce ( $ result , function ( $ sum , $ item ) { $ sum += $ item [ Tag :: Quantity ] * $ item [ Tag :: UnitPrice ] ; return $ sum ; } , 0.0 ) ; $ this -> invoice [ Tag :: Customer ] [ Tag :: Invoice ] [ Meta :: InvoiceAmount ] += $ totalOrderDiscountEx ; } //else { // We could not match a discount with the difference between the // total amount credited and the sum of the products returned. A // manual line will correct the invoice. //} } return $ result ; }
In a Prestashop credit slip, the discounts are not visible anymore, but
can be computed by looking at the difference between the value of
total_products_tax_incl and the sum of the OrderSlipDetail amounts.

@return array[]
In a Prestashop credit slip the discounts are not visible anymore but can be computed by looking at the difference between the value of total_products_tax_incl and the sum of the OrderSlipDetail amounts .