Accounting/Export/AccountingExporter.php
protected function writeInvoiceGrandTotal()
    {
        $sale = $this->invoice->getSale();
        $date = $sale->getCreatedAt();

        // Grand total row
        if ($this->config['total_as_payment']) {

            // Credit case
            if ($this->invoice->getType() === InvoiceTypes::TYPE_CREDIT) {
                $account = $this->getPaymentAccountNumber(
                    $this->invoice->getPaymentMethod(),
                    $this->invoice->getNumber()
                );

                $amount = $this->round($this->invoice->getGrandTotal());

                $this->writer->debit($account, (string)$amount, $date);
                $this->balance += $amount;

                return;
            }

            // Invoice case
            $unpaid = $this->invoice->getGrandTotal();

            $payments = $this->invoicePaymentResolver->resolve($this->invoice);

            // Payments
            foreach ($payments as $payment) {
                $account = $this->getPaymentAccountNumber(
                    $payment->getPayment()->getMethod(),
                    $payment->getPayment()->getNumber()
                );

                $amount = $this->round($payment->getAmount());

                $this->writer->credit($account, (string)$amount, $date);

                $unpaid -= $amount;
                $this->balance -= $amount;
            }

            // Unpaid amount
            if (1 === $this->compare($unpaid, 0)) {
                $account = $this->getUnpaidAccountNumber($sale->getCustomerGroup(), $this->invoice->getNumber());

                $this->writer->credit($account, (string)$unpaid, $date);

                $this->balance -= $unpaid;
            }

            return;
        }

        if ($customer = $sale->getCustomer()) {
            $account = '1' . str_pad($customer->getId(), '7', '0', STR_PAD_LEFT);
        } else {
            $account = $this->config['default_customer'];
        }

        $amount = $this->round($this->invoice->getGrandTotal());

        if ($this->invoice->getType() === InvoiceTypes::TYPE_CREDIT) {
            $this->writer->debit($account, (string)$amount, $date);
            $this->balance += $amount;
        } else {
            $this->writer->credit($account, (string)$amount, $date);
            $this->balance -= $amount;
        }
    }
protected function writeInvoiceGrandTotal()
    {
        $sale = $this->invoice->getSale();
        $date = $sale->getCreatedAt();

        // Grand total row
        if ($this->config['total_as_payment']) {

            // Credit case
            if ($this->invoice->getType() === InvoiceTypes::TYPE_CREDIT) {
                $account = $this->getPaymentAccountNumber(
                    $this->invoice->getPaymentMethod(),
                    $this->invoice->getNumber()
                );

                $amount = $this->round($this->invoice->getGrandTotal());

                $this->writer->debit($account, (string)$amount, $date);
                $this->balance += $amount;

                return;
            }

            // Invoice case
            $unpaid = $this->invoice->getGrandTotal();

            $payments = $this->invoicePaymentResolver->resolve($this->invoice);

            // Payments
            foreach ($payments as $payment) {
                $account = $this->getPaymentAccountNumber(
                    $payment->getPayment()->getMethod(),
                    $payment->getPayment()->getNumber()
                );

                $amount = $this->round($payment->getAmount());

                $this->writer->credit($account, (string)$amount, $date);

                $unpaid -= $amount;
                $this->balance -= $amount;
            }

            // Unpaid amount
            if (1 === $this->compare($unpaid, 0)) {
                $account = $this->getUnpaidAccountNumber($sale->getCustomerGroup(), $this->invoice->getNumber());

                $this->writer->credit($account, (string)$unpaid, $date);

                $this->balance -= $unpaid;
            }

            return;
        }

        if ($customer = $sale->getCustomer()) {
            $account = '1' . str_pad($customer->getId(), '7', '0', STR_PAD_LEFT);
        } else {
            $account = $this->config['default_customer'];
        }

        $amount = $this->round($this->invoice->getGrandTotal());

        if ($this->invoice->getType() === InvoiceTypes::TYPE_CREDIT) {
            $this->writer->debit($account, (string)$amount, $date);
            $this->balance += $amount;
        } else {
            $this->writer->credit($account, (string)$amount, $date);
            $this->balance -= $amount;
        }
    }
protected function writeInvoiceGrandTotal ( ) { $ sale = $ this -> invoice -> getSale ( ) ; $ date = $ sale -> getCreatedAt ( ) ; // Grand total row if ( $ this -> config [ 'total_as_payment' ] ) { // Credit case if ( $ this -> invoice -> getType ( ) === InvoiceTypes :: TYPE_CREDIT ) { $ account = $ this -> getPaymentAccountNumber ( $ this -> invoice -> getPaymentMethod ( ) , $ this -> invoice -> getNumber ( ) ) ; $ amount = $ this -> round ( $ this -> invoice -> getGrandTotal ( ) ) ; $ this -> writer -> debit ( $ account , ( string ) $ amount , $ date ) ; $ this -> balance += $ amount ; return ; } // Invoice case $ unpaid = $ this -> invoice -> getGrandTotal ( ) ; $ payments = $ this -> invoicePaymentResolver -> resolve ( $ this -> invoice ) ; // Payments foreach ( $ payments as $ payment ) { $ account = $ this -> getPaymentAccountNumber ( $ payment -> getPayment ( ) -> getMethod ( ) , $ payment -> getPayment ( ) -> getNumber ( ) ) ; $ amount = $ this -> round ( $ payment -> getAmount ( ) ) ; $ this -> writer -> credit ( $ account , ( string ) $ amount , $ date ) ; $ unpaid -= $ amount ; $ this -> balance -= $ amount ; } // Unpaid amount if ( 1 === $ this -> compare ( $ unpaid , 0 ) ) { $ account = $ this -> getUnpaidAccountNumber ( $ sale -> getCustomerGroup ( ) , $ this -> invoice -> getNumber ( ) ) ; $ this -> writer -> credit ( $ account , ( string ) $ unpaid , $ date ) ; $ this -> balance -= $ unpaid ; } return ; } if ( $ customer = $ sale -> getCustomer ( ) ) { $ account = '1' . str_pad ( $ customer -> getId ( ) , '7' , '0' , STR_PAD_LEFT ) ; } else { $ account = $ this -> config [ 'default_customer' ] ; } $ amount = $ this -> round ( $ this -> invoice -> getGrandTotal ( ) ) ; if ( $ this -> invoice -> getType ( ) === InvoiceTypes :: TYPE_CREDIT ) { $ this -> writer -> debit ( $ account , ( string ) $ amount , $ date ) ; $ this -> balance += $ amount ; } else { $ this -> writer -> credit ( $ account , ( string ) $ amount , $ date ) ; $ this -> balance -= $ amount ; } }
Writes the invoice's grand total line(s).
Writes the invoice s grand total line ( s ) .