src/Invoice/Completor.php
protected function areTotalsEqual()
    {
        $invoice = $this->invoice[Tag::Customer][Tag::Invoice];
        if (!in_array(Meta::LinesAmount, $this->lineTotalsStates['incomplete'])) {
            if (Number::floatsAreEqual($invoice[Meta::InvoiceAmount], $invoice[Meta::LinesAmount], 0.05)) {
                $this->lineTotalsStates['equal'][Meta::LinesAmount] = Meta::InvoiceAmount;
            } else {
                $this->lineTotalsStates['differ'][Meta::LinesAmount] = $invoice[Meta::InvoiceAmount] - $invoice[Meta::LinesAmount];
            }
        }
        if (!in_array(Meta::LinesAmountInc, $this->lineTotalsStates['incomplete'])) {
            if (Number::floatsAreEqual($invoice[Meta::InvoiceAmountInc], $invoice[Meta::LinesAmountInc], 0.05)) {
                $this->lineTotalsStates['equal'][Meta::LinesAmountInc] = Meta::InvoiceAmountInc;
            } else {
                $this->lineTotalsStates['differ'][Meta::LinesAmountInc] = $invoice[Meta::InvoiceAmountInc] - $invoice[Meta::LinesAmountInc];
            }
        }
        if (!in_array(Meta::LinesVatAmount, $this->lineTotalsStates['incomplete'])) {
            if (Number::floatsAreEqual($invoice[Meta::InvoiceVatAmount], $invoice[Meta::LinesVatAmount], 0.05)) {
                $this->lineTotalsStates['equal'][Meta::LinesVatAmount] = Meta::InvoiceVatAmount;
            } else {
                $this->lineTotalsStates['differ'][Meta::LinesVatAmount] = $invoice[Meta::InvoiceVatAmount] - $invoice[Meta::LinesVatAmount];
            }
        }

        $equal = count($this->lineTotalsStates['equal']);
        $differ = count($this->lineTotalsStates['differ']);

        if ($differ > 0) {
            $result = false;
        } elseif ($equal > 0) {
            // If only the vat amounts are equal, while the vat amount = 0, we
            // cannot decide that the totals are equal because this appears to
            // be a vat free/reversed vat invoice without any vatamount.
            $result = $equal === 1 && array_key_exists(Meta::InvoiceVatAmount, $this->lineTotalsStates['differ']) && Number::isZero($invoice[Meta::LinesVatAmount])
                ? null
                : true;
        } else {
            // No equal amounts nor different amounts found: undecided.
            $result = null;
        }
        return $result;
    }
protected function areTotalsEqual()
    {
        $invoice = $this->invoice[Tag::Customer][Tag::Invoice];
        if (!in_array(Meta::LinesAmount, $this->lineTotalsStates['incomplete'])) {
            if (Number::floatsAreEqual($invoice[Meta::InvoiceAmount], $invoice[Meta::LinesAmount], 0.05)) {
                $this->lineTotalsStates['equal'][Meta::LinesAmount] = Meta::InvoiceAmount;
            } else {
                $this->lineTotalsStates['differ'][Meta::LinesAmount] = $invoice[Meta::InvoiceAmount] - $invoice[Meta::LinesAmount];
            }
        }
        if (!in_array(Meta::LinesAmountInc, $this->lineTotalsStates['incomplete'])) {
            if (Number::floatsAreEqual($invoice[Meta::InvoiceAmountInc], $invoice[Meta::LinesAmountInc], 0.05)) {
                $this->lineTotalsStates['equal'][Meta::LinesAmountInc] = Meta::InvoiceAmountInc;
            } else {
                $this->lineTotalsStates['differ'][Meta::LinesAmountInc] = $invoice[Meta::InvoiceAmountInc] - $invoice[Meta::LinesAmountInc];
            }
        }
        if (!in_array(Meta::LinesVatAmount, $this->lineTotalsStates['incomplete'])) {
            if (Number::floatsAreEqual($invoice[Meta::InvoiceVatAmount], $invoice[Meta::LinesVatAmount], 0.05)) {
                $this->lineTotalsStates['equal'][Meta::LinesVatAmount] = Meta::InvoiceVatAmount;
            } else {
                $this->lineTotalsStates['differ'][Meta::LinesVatAmount] = $invoice[Meta::InvoiceVatAmount] - $invoice[Meta::LinesVatAmount];
            }
        }

        $equal = count($this->lineTotalsStates['equal']);
        $differ = count($this->lineTotalsStates['differ']);

        if ($differ > 0) {
            $result = false;
        } elseif ($equal > 0) {
            // If only the vat amounts are equal, while the vat amount = 0, we
            // cannot decide that the totals are equal because this appears to
            // be a vat free/reversed vat invoice without any vatamount.
            $result = $equal === 1 && array_key_exists(Meta::InvoiceVatAmount, $this->lineTotalsStates['differ']) && Number::isZero($invoice[Meta::LinesVatAmount])
                ? null
                : true;
        } else {
            // No equal amounts nor different amounts found: undecided.
            $result = null;
        }
        return $result;
    }
protected function areTotalsEqual ( ) { $ invoice = $ this -> invoice [ Tag :: Customer ] [ Tag :: Invoice ] ; if ( ! in_array ( Meta :: LinesAmount , $ this -> lineTotalsStates [ 'incomplete' ] ) ) { if ( Number :: floatsAreEqual ( $ invoice [ Meta :: InvoiceAmount ] , $ invoice [ Meta :: LinesAmount ] , 0.05 ) ) { $ this -> lineTotalsStates [ 'equal' ] [ Meta :: LinesAmount ] = Meta :: InvoiceAmount ; } else { $ this -> lineTotalsStates [ 'differ' ] [ Meta :: LinesAmount ] = $ invoice [ Meta :: InvoiceAmount ] - $ invoice [ Meta :: LinesAmount ] ; } } if ( ! in_array ( Meta :: LinesAmountInc , $ this -> lineTotalsStates [ 'incomplete' ] ) ) { if ( Number :: floatsAreEqual ( $ invoice [ Meta :: InvoiceAmountInc ] , $ invoice [ Meta :: LinesAmountInc ] , 0.05 ) ) { $ this -> lineTotalsStates [ 'equal' ] [ Meta :: LinesAmountInc ] = Meta :: InvoiceAmountInc ; } else { $ this -> lineTotalsStates [ 'differ' ] [ Meta :: LinesAmountInc ] = $ invoice [ Meta :: InvoiceAmountInc ] - $ invoice [ Meta :: LinesAmountInc ] ; } } if ( ! in_array ( Meta :: LinesVatAmount , $ this -> lineTotalsStates [ 'incomplete' ] ) ) { if ( Number :: floatsAreEqual ( $ invoice [ Meta :: InvoiceVatAmount ] , $ invoice [ Meta :: LinesVatAmount ] , 0.05 ) ) { $ this -> lineTotalsStates [ 'equal' ] [ Meta :: LinesVatAmount ] = Meta :: InvoiceVatAmount ; } else { $ this -> lineTotalsStates [ 'differ' ] [ Meta :: LinesVatAmount ] = $ invoice [ Meta :: InvoiceVatAmount ] - $ invoice [ Meta :: LinesVatAmount ] ; } } $ equal = count ( $ this -> lineTotalsStates [ 'equal' ] ) ; $ differ = count ( $ this -> lineTotalsStates [ 'differ' ] ) ; if ( $ differ > 0 ) { $ result = false ; } elseif ( $ equal > 0 ) { // If only the vat amounts are equal, while the vat amount = 0, we // cannot decide that the totals are equal because this appears to // be a vat free/reversed vat invoice without any vatamount. $ result = $ equal === 1 && array_key_exists ( Meta :: InvoiceVatAmount , $ this -> lineTotalsStates [ 'differ' ] ) && Number :: isZero ( $ invoice [ Meta :: LinesVatAmount ] ) ? null : true ; } else { // No equal amounts nor different amounts found: undecided. $ result = null ; } return $ result ; }
Compares the invoice totals metadata with the line totals metadata.

If any of the 3 values are equal we do consider the totals to be equal
(except for a 0 VAT amount (for reversed VAT invoices)). This because in
many cases 1 or 2 of the 3 values are either incomplete or incorrect.

@return bool|null
True if the totals are equal, false if not equal, null if undecided
(all 3 values are incomplete).
Compares the invoice totals metadata with the line totals metadata .