src/Invoice/Completor.php
protected function correctMarginInvoice()
    {
        if (isset($this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType]) && $this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType] === Api::VatType_MarginScheme) {
            foreach ($this->invoice[Tag::Customer][Tag::Invoice][Tag::Line] as &$line) {
                // For margin invoices, Acumulus expects the unitprice to be the
                // sales price, ie the price the client pays. So we set
                // unitprice to unitpriceinc.
                // Non margin lines may "officially" not appear on margin
                // invoices, so we turn them into margin lines by adding a
                // costprice of 0 and also setting unitprice to unitpriceinc.
                if (!isset($line[Tag::CostPrice])) {
                    // "Normal" line: set costprice as 0.
                    $line[Tag::CostPrice] = 0.0;
                }
                // Add "marker" tag (for debug purposes) for this correction.
                $line[Meta::RecalculateOldPrice] = $line[Tag::UnitPrice];
                // Change unitprice tag to include VAT.
                if (isset($line[Meta::UnitPriceInc])) {
                    $line[Tag::UnitPrice] = $line[Meta::UnitPriceInc];
                } elseif (isset($line[Meta::VatAmount])) {
                    $line[Tag::UnitPrice] += $line[Meta::VatAmount];
                } elseif (isset($line[Tag::VatRate])) {
                    $line[Tag::UnitPrice] += $line[Tag::VatRate]/100.0 * ($line[Tag::UnitPrice] - $line[Tag::CostPrice]);
                } //else {
                    // Impossible to correct the unitprice. Probably all
                    // strategies failed, so the invoice should already
                    // have a warning.
                //}
            }
        }
    }
protected function correctMarginInvoice()
    {
        if (isset($this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType]) && $this->invoice[Tag::Customer][Tag::Invoice][Tag::VatType] === Api::VatType_MarginScheme) {
            foreach ($this->invoice[Tag::Customer][Tag::Invoice][Tag::Line] as &$line) {
                // For margin invoices, Acumulus expects the unitprice to be the
                // sales price, ie the price the client pays. So we set
                // unitprice to unitpriceinc.
                // Non margin lines may "officially" not appear on margin
                // invoices, so we turn them into margin lines by adding a
                // costprice of 0 and also setting unitprice to unitpriceinc.
                if (!isset($line[Tag::CostPrice])) {
                    // "Normal" line: set costprice as 0.
                    $line[Tag::CostPrice] = 0.0;
                }
                // Add "marker" tag (for debug purposes) for this correction.
                $line[Meta::RecalculateOldPrice] = $line[Tag::UnitPrice];
                // Change unitprice tag to include VAT.
                if (isset($line[Meta::UnitPriceInc])) {
                    $line[Tag::UnitPrice] = $line[Meta::UnitPriceInc];
                } elseif (isset($line[Meta::VatAmount])) {
                    $line[Tag::UnitPrice] += $line[Meta::VatAmount];
                } elseif (isset($line[Tag::VatRate])) {
                    $line[Tag::UnitPrice] += $line[Tag::VatRate]/100.0 * ($line[Tag::UnitPrice] - $line[Tag::CostPrice]);
                } //else {
                    // Impossible to correct the unitprice. Probably all
                    // strategies failed, so the invoice should already
                    // have a warning.
                //}
            }
        }
    }
protected function correctMarginInvoice ( ) { if ( isset ( $ this -> invoice [ Tag :: Customer ] [ Tag :: Invoice ] [ Tag :: VatType ] ) && $ this -> invoice [ Tag :: Customer ] [ Tag :: Invoice ] [ Tag :: VatType ] === Api :: VatType_MarginScheme ) { foreach ( $ this -> invoice [ Tag :: Customer ] [ Tag :: Invoice ] [ Tag :: Line ] as & $ line ) { // For margin invoices, Acumulus expects the unitprice to be the // sales price, ie the price the client pays. So we set // unitprice to unitpriceinc. // Non margin lines may "officially" not appear on margin // invoices, so we turn them into margin lines by adding a // costprice of 0 and also setting unitprice to unitpriceinc. if ( ! isset ( $ line [ Tag :: CostPrice ] ) ) { // "Normal" line: set costprice as 0. $ line [ Tag :: CostPrice ] = 0.0 ; } // Add "marker" tag (for debug purposes) for this correction. $ line [ Meta :: RecalculateOldPrice ] = $ line [ Tag :: UnitPrice ] ; // Change unitprice tag to include VAT. if ( isset ( $ line [ Meta :: UnitPriceInc ] ) ) { $ line [ Tag :: UnitPrice ] = $ line [ Meta :: UnitPriceInc ] ; } elseif ( isset ( $ line [ Meta :: VatAmount ] ) ) { $ line [ Tag :: UnitPrice ] += $ line [ Meta :: VatAmount ] ; } elseif ( isset ( $ line [ Tag :: VatRate ] ) ) { $ line [ Tag :: UnitPrice ] += $ line [ Tag :: VatRate ] / 100.0 * ( $ line [ Tag :: UnitPrice ] - $ line [ Tag :: CostPrice ] ) ; } //else { // Impossible to correct the unitprice. Probably all // strategies failed, so the invoice should already // have a warning. //} } } }
Corrects an invoice if it is a margin scheme invoice.

If an invoice is of the margin scheme type, all lines have to follow the
margin scheme rules. These rules are:
- Each line must have a costprice, but that cost price may be 0.
- The unitprice should now contain the price including VAT (requirement
of the web service API).
Thus if there are e.g. shipping lines or other fee lines, they have to be
converted to the margin scheme (costprice tag and change of unitprice).
Corrects an invoice if it is a margin scheme invoice .