src/Invoice/CompletorInvoiceLines.php
public function correctVatRateByRange(array $line)
    {
        $line[Meta::VatRateRangeMatches] = $this->filterVatRateInfosByRange($line[Meta::VatRateMin], $line[Meta::VatRateMax]);
        $vatRate = $this->getUniqueVatRate($line[Meta::VatRateRangeMatches]);

        if ($vatRate === null) {
            // No match at all.
            unset($line[Tag::VatRate]);
            if (!empty($line[Meta::StrategySplit])) {
                // If this line may be split, we make it a strategy line (even
                // though 2 out of the 3 fields ex, inc, and vat are known).
                // This way the strategy phase may be able to correct this line.
                $line[Tag::VatRate] = null;
                $line[Meta::VatRateSource] = Creator::VatRateSource_Strategy;
            } else {
                // Set vatrate to null and try to use lookup data to get a vat
                // rate. It will be invalid but may be better than the "setting
                // to standard 21%".
                $line[Tag::VatRate] = null;
                $line[Meta::VatRateSource] = Creator::VatRateSource_Completor;
                $this->completor->changeInvoiceToConcept('message_warning_no_vatrate', 821);
                // @todo: this can also happen with exact or looked up vat rates
                //   add a checker in the Completor that checks all lines for
                //   no or an incorrect vat rate and changes the invoice into a
                //   concept.
            }
        } elseif ($vatRate === false) {
            // Multiple matches: set vatrate to null and try to use lookup data.
            $line[Tag::VatRate] = null;
            $line[Meta::VatRateSource] = Creator::VatRateSource_Completor;
        } else {
            // Single match: fill it in as the vat rate for this line.
            $line[Tag::VatRate] = $vatRate;
            $line[Meta::VatRateSource] = Completor::VatRateSource_Completor_Range;
        }

        return $line;
    }
public function correctVatRateByRange(array $line)
    {
        $line[Meta::VatRateRangeMatches] = $this->filterVatRateInfosByRange($line[Meta::VatRateMin], $line[Meta::VatRateMax]);
        $vatRate = $this->getUniqueVatRate($line[Meta::VatRateRangeMatches]);

        if ($vatRate === null) {
            // No match at all.
            unset($line[Tag::VatRate]);
            if (!empty($line[Meta::StrategySplit])) {
                // If this line may be split, we make it a strategy line (even
                // though 2 out of the 3 fields ex, inc, and vat are known).
                // This way the strategy phase may be able to correct this line.
                $line[Tag::VatRate] = null;
                $line[Meta::VatRateSource] = Creator::VatRateSource_Strategy;
            } else {
                // Set vatrate to null and try to use lookup data to get a vat
                // rate. It will be invalid but may be better than the "setting
                // to standard 21%".
                $line[Tag::VatRate] = null;
                $line[Meta::VatRateSource] = Creator::VatRateSource_Completor;
                $this->completor->changeInvoiceToConcept('message_warning_no_vatrate', 821);
                // @todo: this can also happen with exact or looked up vat rates
                //   add a checker in the Completor that checks all lines for
                //   no or an incorrect vat rate and changes the invoice into a
                //   concept.
            }
        } elseif ($vatRate === false) {
            // Multiple matches: set vatrate to null and try to use lookup data.
            $line[Tag::VatRate] = null;
            $line[Meta::VatRateSource] = Creator::VatRateSource_Completor;
        } else {
            // Single match: fill it in as the vat rate for this line.
            $line[Tag::VatRate] = $vatRate;
            $line[Meta::VatRateSource] = Completor::VatRateSource_Completor_Range;
        }

        return $line;
    }
public function correctVatRateByRange ( array $ line ) { $ line [ Meta :: VatRateRangeMatches ] = $ this -> filterVatRateInfosByRange ( $ line [ Meta :: VatRateMin ] , $ line [ Meta :: VatRateMax ] ) ; $ vatRate = $ this -> getUniqueVatRate ( $ line [ Meta :: VatRateRangeMatches ] ) ; if ( $ vatRate === null ) { // No match at all. unset ( $ line [ Tag :: VatRate ] ) ; if ( ! empty ( $ line [ Meta :: StrategySplit ] ) ) { // If this line may be split, we make it a strategy line (even // though 2 out of the 3 fields ex, inc, and vat are known). // This way the strategy phase may be able to correct this line. $ line [ Tag :: VatRate ] = null ; $ line [ Meta :: VatRateSource ] = Creator :: VatRateSource_Strategy ; } else { // Set vatrate to null and try to use lookup data to get a vat // rate. It will be invalid but may be better than the "setting // to standard 21%". $ line [ Tag :: VatRate ] = null ; $ line [ Meta :: VatRateSource ] = Creator :: VatRateSource_Completor ; $ this -> completor -> changeInvoiceToConcept ( 'message_warning_no_vatrate' , 821 ) ; // @todo: this can also happen with exact or looked up vat rates //   add a checker in the Completor that checks all lines for //   no or an incorrect vat rate and changes the invoice into a //   concept. } } elseif ( $ vatRate === false ) { // Multiple matches: set vatrate to null and try to use lookup data. $ line [ Tag :: VatRate ] = null ; $ line [ Meta :: VatRateSource ] = Creator :: VatRateSource_Completor ; } else { // Single match: fill it in as the vat rate for this line. $ line [ Tag :: VatRate ] = $ vatRate ; $ line [ Meta :: VatRateSource ] = Completor :: VatRateSource_Completor_Range ; } return $ line ; }
Checks and corrects a 'calculated' vat rate to an allowed vat rate.

The meta-vatrate-source must be Creator::VatRateSource_Calculated.

The check is done on comparing allowed vat rates with the
meta-vatrate-min and meta-vatrate-max values. If only 1 match is found
that will be used.

If multiple matches are found with all equal rates - e.g. Dutch and
Belgium 21% - the vat rate will be corrected, but the VAT Type will
remain undecided, unless the vat class could be looked up and thus used
to differentiate between national and foreign vat.

This method is public to allow a 2nd call to just this method for a
single line (a missing amount line) added after a 1st round of
correcting. Do not use unless $this->possibleVatRates has been
initialized.

@param array $line
An invoice line with a calculated vat rate.

@return array
The invoice line with a corrected vat rate.
Checks and corrects a calculated vat rate to an allowed vat rate .