/** * Return an array with relevant data from an invoice item * * @param \Magento\Sales\Api\Data\InvoiceItemInterface $item * @return array|bool */ protected function convertInvoiceItemToData(\Magento\Sales\Api\Data\InvoiceItemInterface $item) { if (!$this->isProductCalculated($item->getOrderItem())) { return false; } // The AvaTax 15 API doesn't support the concept of line-based discounts, so subtract discount amount // from taxable amount $amount = $item->getBaseRowTotal() - $item->getBaseDiscountAmount(); if ($item->getQty() == 0 || $amount == 0) { return false; } $product = $item->getOrderItem()->getProduct(); $itemCode = $this->taxClassHelper->getItemCodeOverride($product); if (!$itemCode) { $itemCode = $item->getSku(); } $storeId = $item->getStoreId(); return ['StoreId' => $storeId, 'No' => $this->getLineNumber(), 'ItemCode' => $itemCode, 'TaxCode' => $this->taxClassHelper->getAvataxTaxCodeForProduct($product, $storeId), 'Description' => $item->getName(), 'Qty' => $item->getQty(), 'Amount' => $amount, 'Discounted' => (bool) ($item->getBaseDiscountAmount() > 0), 'TaxIncluded' => false, 'Ref1' => $this->taxClassHelper->getRef1ForProduct($product), 'Ref2' => $this->taxClassHelper->getRef2ForProduct($product)]; }
/** * Set quantity to invoice item * * @param \Magento\Sales\Api\Data\InvoiceItemInterface $item * @param float $qty * @return $this * @throws \Magento\Framework\Exception\LocalizedException */ protected function setInvoiceItemQuantity(\Magento\Sales\Api\Data\InvoiceItemInterface $item, $qty) { $qty = $item->getOrderItem()->getIsQtyDecimal() ? (double) $qty : (int) $qty; $qty = $qty > 0 ? $qty : 0; /** * Check qty availability */ $qtyToInvoice = sprintf("%F", $item->getOrderItem()->getQtyToInvoice()); $qty = sprintf("%F", $qty); if ($qty > $qtyToInvoice && !$item->getOrderItem()->isDummy()) { throw new \Magento\Framework\Exception\LocalizedException(__('We found an invalid quantity to invoice item "%1".', $item->getName())); } $item->setQty($qty); return $this; }