{@inheritdoc}

This override provides the values meta-invoice-amountinc and
meta-invoice-amount.
346375
protected function getAvailableTotals()
    {
        $sign = $this->getSign();
        if ($this->getType() === Source::Order) {
            $amount = $this->source->getTotalProductsWithoutTaxes()
                      + $this->source->total_shipping_tax_excl
                      + $this->source->total_wrapping_tax_excl
                      - $this->source->total_discounts_tax_excl;
            $amountInc = $this->source->getTotalProductsWithTaxes()
                         + $this->source->total_shipping_tax_incl
                         + $this->source->total_wrapping_tax_incl
                         - $this->source->total_discounts_tax_incl;
        } else {
            // On credit notes, the amount ex VAT will not have been corrected
            // for discounts that are subtracted from the refund. This will be
            // corrected later in getDiscountLinesCreditNote().
            $amount = $this->source->total_products_tax_excl
                      + $this->source->total_shipping_tax_excl;
            $amountInc = $this->source->total_products_tax_incl
                         + $this->source->total_shipping_tax_incl;
        }

        return array(
            Meta::InvoiceAmountInc => $sign * $amountInc,
            Meta::InvoiceAmount => $sign * $amount,
        );
    }
107135
public function initTotals()
    {
        $parent = $this->getParentBlock();
        $this->_source = $parent->getSource();
        $total = new Varien_Object(
            array(
                'code' => 'adjust_adyen_fee_payment_fee',
                'block_name' => $this->getNameInLayout()
            )
        );

        // remove totals because you only want to show editable field
        $parent->removeTotal('payment_fee_excl');
        $parent->removeTotal('payment_fee_incl');

        $parent->addTotalBefore($total, 'agjustments'); // Yes, misspelled in Magento Core
        return $this;
    }
996705
public function setPayer(\AgentSIB\Diadoc\Api\Proto\Invoicing\OrganizationInfo $value = null)
    {
        $this->Payer = $value;
    }
524603
public function settle(Payable $invoiceA, Payable $invoiceB, $sendEmail = false)
    {
        if ($invoiceA->state != 'open' && $invoiceA->state != 'late') {
            throw new InvalidStateException('Invalid state for invoice '.$invoiceA->id);
        }
        if ($invoiceB->state != 'open' && $invoiceB->state != 'late') {
            throw new InvalidStateException('Invalid state for invoice '.$invoiceB->id);
        }

        $typeA = $this->getType($invoiceA);
        $typeB = $this->getType($invoiceB);
        if ($typeA != $typeB) {
            throw new UnableToSettleException('Unable to settle invoices, types are not equal');
        }
        if (
            ($invoiceA->totalUnpaid > 0 && $invoiceB->totalUnpaid > 0) ||
            ($invoiceA->totalUnpaid < 0 && $invoiceB->totalUnpaid < 0)
        ) {
            throw new UnableToSettleException('Unable to settle invoices, signs are equal');
        }

        $price = min(abs($invoiceA->totalUnpaid), abs($invoiceB->totalUnpaid));

        $paymentClassA = __NAMESPACE__.'\\'.$typeA.'\\Payment';
        $paymentClassB = __NAMESPACE__.'\\'.$typeB.'\\Payment';
        $paymentA = new $paymentClassA(array(
            'paymentDate' => new DateTime(),
            'paymentMethod' => 'credit_invoice',
            'price' => ($invoiceA->totalUnpaid > 0 ? 1 : -1) * $price,
            'sendEmail' => $sendEmail,
        ));
        $paymentB = new $paymentClassB(array(
            'paymentDate' => new DateTime(),
            'paymentMethod' => 'credit_invoice',
            'price' => ($invoiceB->totalUnpaid > 0 ? 1 : -1) * $price,
            'sendEmail' => $sendEmail,
        ));

        $invoiceA->registerPayment($this->getService($typeA), $paymentA);
        $invoiceB->registerPayment($this->getService($typeB), $paymentB);
    }
777750
public function collect(Invoice $invoice)
    {
        parent::collect($invoice);

        $baseInterest = (float) $invoice->getBaseGabrielqsInstallmentsInterestAmount();
        $interest = (float) $invoice->getGabrielqsInstallmentsInterestAmount();
        if ($baseInterest) {
            $invoice->setBaseGrandTotal($invoice->getBaseGrandTotal() + $baseInterest);
            $invoice->setGrandTotal($invoice->getGrandTotal() + $interest);
        }

        return $this;
    }
438445
private function createOperationsFromInvoice(array $invoice, VendorInterface $vendor, DateTime $cycleDate)
    {
        if ($invoice['summary']['amount_transferred'] > 0) {

            $operations = array();

            try {
                // Calculate adjusted amount (for past negative operations)
                $adjustedInfos = $this->getAdjustedAmount($invoice['summary']['amount_transferred'], $vendor);

                $this->logger->debug(
                    "Vendor origin amount " . $invoice['summary']['amount_transferred'],
                    array('miraklId' => $invoice['shop_id'], "action" => "Operations creation")
                );

                $this->logger->debug(
                    "Vendor adjusted amount " .
                    $adjustedInfos['adjustedAmount'] .
                    " (" .
                    count($adjustedInfos['adujstedOperationsIds']) .
                    " operations adjusted)",
                    array('miraklId' => $invoice['shop_id'], "action" => "Operations creation")
                );

                // Vendor operation
                $operations[] = $this->createOperation(
                    $adjustedInfos['adjustedAmount'],
                    $invoice['summary']['amount_transferred'],
                    $cycleDate,
                    $invoice['invoice_id'],
                    $vendor,
                    $adjustedInfos['adujstedOperationsIds']
                );

                // operator operation
                $operations[] = $this->createOperation(
                    $invoice['total_charged_amount'],
                    null,
                    $cycleDate,
                    $invoice['invoice_id'],
                    $this->operator
                );

                // save in memory for future saving in database
                $this->adjustedOperations = array_merge(
                    $this->adjustedOperations,
                    $adjustedInfos["adujstedOperations"]
                );

                return $operations;
            } catch (Exception $e) {
                $this->handleException($e);
                return false;
            }
        } else {
            $this->logger->warning(
                "Invoice n° " . $invoice['invoice_id'] . " has a negative amount, will not be treated",
                array('miraklId' => $invoice['shop_id'], "action" => "Operations creation")
            );
        }
    }
1238992
private static function checkValues(Meta $m)
    {
        if ($m->getType() === "json") {
            if (!empty($m->getValue()) && !empty($m->getAllow()['values'])) {
                if (in_array($m->getFormat(), ["sources", "source"])) {
                    foreach (json_decode($m->getValue(), true) as $v) {
                        if (!in_array(pathinfo($v['url'], PATHINFO_EXTENSION), $m->getAllow()['values']))
                            $m->setError("valor não é permitido");
                    }
                } else {
                    foreach (json_decode($m->getValue(), true) as $item) {
                        if (!empty($item) && !in_array($item, $m->getAllow()['values']))
                            $m->setError("valor não é permitido");
                    }
                }
            }
        } elseif (!empty($m->getAllow()['values']) && $m->getKey() !== "information" && !empty($m->getValue()) && !in_array($m->getValue(), $m->getAllow()['values'])) {
            $m->setError("valor não é permitido");
        }
    }
524994
public function setLimit($value)
    {
        if ($value === null) {
            $this->_limit = null;
        } elseif (is_int($value)) {
            if ($value < 0 || $value > self::MAX_LIMIT_VALUE) {
                throw new InvalidPropertyValueException(
                    'Invalid limit value in PaymentsRequest', 0, 'PaymentsRequest.limit', $value
                );
            }
            $this->_limit = $value;
        } else {
            throw new InvalidPropertyValueTypeException(
                'Invalid limit value type in PaymentsRequest', 0, 'PaymentsRequest.limit', $value
            );
        }
    }
1043790
protected function setInvoiceSource($invoiceSource)
    {
        parent::setInvoiceSource($invoiceSource);
        switch ($this->invoiceSource->getType()) {
            case Source::Order:
                $this->order = $this->invoiceSource->getSource();
                break;
            case Source::CreditNote:
                $this->creditSlip = $this->invoiceSource->getSource();
                $this->order = $this->invoiceSource->getOrder()->getSource();
                break;
        }
    }
453759
public function getDynValues()
    {
        if (!$this->_aDynValues) {
            $sRawDynValue = null;
            if (is_object($this->oxpayments__oxvaldesc)) {
                $sRawDynValue = $this->oxpayments__oxvaldesc->getRawValue();
            }

            $this->_aDynValues = \OxidEsales\Eshop\Core\Registry::getUtils()->assignValuesFromText($sRawDynValue);
        }

        return $this->_aDynValues;
    }
303439
protected function completeLineTotals()
    {
        $linesAmount = 0.0;
        $linesAmountInc = 0.0;
        $linesVatAmount = 0.0;
        $this->lineTotalsStates = array(
            'incomplete' => array(),
            'equal' => array(),
            'differ' => array(),
        );

        $invoiceLines = $this->invoice[Tag::Customer][Tag::Invoice][Tag::Line];
        foreach ($invoiceLines as $line) {
            if (isset($line[Meta::LineAmount])) {
                $linesAmount += $line[Meta::LineAmount];
            } elseif (isset($line[Tag::UnitPrice])) {
                $linesAmount += $line[Tag::Quantity] * $line[Tag::UnitPrice];
            } else {
                $this->lineTotalsStates['incomplete'][Meta::LinesAmount] = Meta::LinesAmount;
            }

            if (isset($line[Meta::LineAmountInc])) {
                $linesAmountInc += $line[Meta::LineAmountInc];
            } elseif (isset($line[Meta::UnitPriceInc])) {
                $linesAmountInc += $line[Tag::Quantity] * $line[Meta::UnitPriceInc];
            } else {
                $this->lineTotalsStates['incomplete'][Meta::LinesAmountInc] = Meta::LinesAmountInc;
            }

            if (isset($line[Meta::LineVatAmount])) {
                $linesVatAmount += $line[Meta::LineVatAmount];
            } elseif (isset($line[Meta::VatAmount])) {
                $linesVatAmount += $line[Tag::Quantity] * $line[Meta::VatAmount];
            } else {
                $this->lineTotalsStates['incomplete'][Meta::LinesVatAmount] = Meta::LinesVatAmount;
            }
        }

        $this->invoice[Tag::Customer][Tag::Invoice][Meta::LinesAmount ] = $linesAmount;
        $this->invoice[Tag::Customer][Tag::Invoice][Meta::LinesAmountInc] = $linesAmountInc;
        $this->invoice[Tag::Customer][Tag::Invoice][Meta::LinesVatAmount] = $linesVatAmount;
        if (!empty($this->lineTotalsStates['incomplete'])) {
            sort($this->lineTotalsStates['incomplete']);
            $this->invoice[Tag::Customer][Tag::Invoice][Meta::LinesIncomplete] = implode(',', $this->lineTotalsStates['incomplete']);
        }
    }
1285079
private function getAmountFields(Source $source, array $entry)
    {
        $fields = array();
        if (!empty($entry['totalvalue']) && !empty($entry['totalvalueexclvat'])) {
            // Get Acumulus amounts.
            $amountExAcumulus = $entry['totalvalueexclvat'];
            $amountIncAcumulus = $entry['totalvalue'];
            $amountVatAcumulus = $amountIncAcumulus - $amountExAcumulus;

            // Get local amounts.
            $localTotals = $source->getTotals();

            // Compare.
            $amountExStatus = $this->getAmountStatus($amountExAcumulus, $localTotals[Meta::InvoiceAmount]);
            $amountIncStatus = $this->getAmountStatus($amountIncAcumulus, $localTotals[Meta::InvoiceAmountInc]);
            $amountVatStatus = $this->getAmountStatus($amountVatAcumulus, $localTotals[Meta::InvoiceVatAmount]);

            $amountEx = $this->getFormattedAmount($amountExAcumulus, $amountExStatus);
            $amountInc = $this->getFormattedAmount($amountIncAcumulus, $amountIncStatus);
            $amountVat = $this->getFormattedAmount($amountVatAcumulus, $amountVatStatus);

            $fields['invoice_amount'] = array(
                'type' => 'markup',
                'label' => $this->t('invoice_amount'),
                'value' => sprintf('<div class="acumulus-amount">%1$s%2$s %4$s%3$s</div>', $amountEx, $amountVat, $amountInc, $this->t('vat')),
            );
        }
        return $fields;
    }
893282
public function setAmount($value)
    {
        if (empty($value)) {
            $this->currentObject->setAmount(null);
        } elseif ($value instanceof AmountInterface) {
            if ($value->getValue() > 0.0) {
                $this->currentObject->setAmount($value->getValue());
            }
            $this->currentObject->setCurrency($value->getCurrency());
        } else {
            $this->currentObject->setAmount($value);
        }
        return $this;
    }
197811
public function map($data): Invoice
    {
        $services = [];

        foreach ($data['services'] as $service) {
            $services[] = (new Invoice\Service())
                ->setId((int) $service['id'])
                ->setName($service['name'])
                ->setTaxSymbol($service['tax_symbol'])
                ->setUnit($service['unit'])
                ->setQuantity((float) $service['quantity'])
                ->setUnitNetPrice($this->mapPrice($service['unit_net_price']))
                ->setUnitNetPriceBeforeDiscount($this->mapPrice($service['unit_net_price_before_discount']))
                ->setNetPrice($this->mapPrice($service['net_price']))
                ->setGrossPrice($this->mapPrice($service['gross_price']))
                ->setTaxPrice($this->mapPrice($service['tax_price']))
                ->setSymbol($service['symbol'])
                ->setDiscount((float) $service['discount']);
        }

        $invoice = (new Invoice())
            ->setId((int) $data['id'])
            ->setNumber($data['number'])
            ->setInvoiceDate($this->mapDate($data['invoice_date']))
            ->setCurrency($data['currency'])
            ->setPaidPrice($this->mapPrice($data['paid_price']))
            ->setNotes($data['notes'])
            ->setKind($data['kind'])
            ->setPaymentMethod($data['payment_method'])
            ->setSellerSignature($data['seller_signature'])
            ->setRecipientSignature($data['recipient_signature'])
            ->setSaleDate($this->mapDate($data['sale_date']))
            ->setStatus($data['status'])
            ->setPaymentDate($this->mapDate($data['payment_date']))
            ->setPaidDate($this->mapDate($data['paid_date']))
            ->setNetPrice($this->mapPrice($data['net_price']))
            ->setTaxPrice($this->mapPrice($data['tax_price']))
            ->setGrossPrice($this->mapPrice($data['gross_price']))
            ->setClientId($data['client_id'] ? (int) $data['client_id'] : null)
            ->setClientCompanyName($data['client_company_name'])
            ->setClientStreet($data['client_street'])
            ->setClientCity($data['client_city'])
            ->setClientPostCode($data['client_post_code'])
            ->setClientTaxCode($data['client_tax_code'])
            ->setClientCountry($data['client_country'])
            ->setBankAccount($data['bank_account'])
            ->setBankName($data['bank_name'])
            ->setSwift($data['swift'])
            ->setVatExemptionReason($data['vat_exemption_reason'] ?: null)
            ->setSaleDate($this->mapDate($data['sale_date']))
            ->setSaleType($data['sale_type'])
            ->setInvoiceDateKind($data['invoice_date_kind'])
            ->setServices($services)
            ->setExtensions((new Invoice\Extension())
                ->setPayment((new Invoice\Extension\Payment())
                    ->setLink($data['extensions']['payments']['link'])
                    ->setAvailable($data['extensions']['payments']['available']))
                ->setShare((new Invoice\Extension\Share())
                    ->setLink($data['extensions']['shares']['link'])
                    ->setAvailable($data['extensions']['payments']['available'])
                    ->setValidUntil($this->mapDate($data['extensions']['shares']['valid_until'])))
            );

        return $invoice;
    }
41138
public function setTotalsInc(\AgentSIB\Diadoc\Api\Proto\Invoicing\InvoiceTotalsDiff $value = null)
    {
        $this->TotalsInc = $value;
    }
552939
public function setAmount($value)
    {
        if ($value === null || $value === '') {
            $this->_amount = null;
        } else {
            if (!is_scalar($value)) {
                if (!is_object($value) || !method_exists($value, '__toString')) {
                    throw new InvalidPropertyValueTypeException(
                        'Invalid amount value type', 0, 'amount.value', $value
                    );
                }
                $value = (string)$value;
            }
            if (!is_numeric($value) || $value < 0.0) {
                throw new InvalidPropertyValueException(
                    'Invalid amount value "' . $value . '"', 0, 'amount.value', $value
                );
            } elseif ($value < 0.01) {
                $this->_amount = null;
            } else {
                $this->_amount = number_format($value, 2, '.', '');
            }
        }
    }
352094
public function odpocetZDD($invoice, $odpocet = [])
    {
        if (!isset($odpocet['castkaZaklMen'])) {
            $odpocet['castkaZaklMen'] = $invoice->getDataValue('sumZklZakl');
        }
        if (!isset($odpocet['castkaSnizMen'])) {
            $odpocet['castkaSnizMen'] = $invoice->getDataValue('sumZklSniz');
        }
        if (!isset($odpocet['castkaSniz2Men'])) {
            $odpocet['castkaSniz2Men'] = $invoice->getDataValue('sumZklSniz2');
        }
        if (!isset($odpocet['castkaOsvMen'])) {
            $odpocet['castkaOsvMen'] = $invoice->getDataValue('sumOsv');
        }
        if (!isset($odpocet['id'])) {
            $odpocet['id'] = 'ext:odpocet1';
        }
        $odpocet['doklad'] = $invoice;

        $this->setDataValue('odpocty-zaloh', ['odpocet' => $odpocet]);
        $this->insertToFlexiBee();
        return $this->lastResponseCode == 201;
    }