123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699 |
- <?php
- /**
- * Copyright © Magento, Inc. All rights reserved.
- * See COPYING.txt for license details.
- */
- namespace Magento\Sales\Model\Order\Invoice;
- use Magento\Framework\Api\AttributeValueFactory;
- use Magento\Sales\Api\Data\InvoiceItemInterface;
- use Magento\Sales\Model\AbstractModel;
- /**
- * @api
- * @method float getBaseWeeeTaxRowDisposition()
- * @method \Magento\Sales\Model\Order\Invoice\Item setBaseWeeeTaxRowDisposition(float $value)
- * @method float getWeeeTaxAppliedRowAmount()
- * @method \Magento\Sales\Model\Order\Invoice\Item setWeeeTaxAppliedRowAmount(float $value)
- * @method float getBaseWeeeTaxAppliedAmount()
- * @method \Magento\Sales\Model\Order\Invoice\Item setBaseWeeeTaxAppliedAmount(float $value)
- * @method float getWeeeTaxRowDisposition()
- * @method \Magento\Sales\Model\Order\Invoice\Item setWeeeTaxRowDisposition(float $value)
- * @method float getBaseWeeeTaxDisposition()
- * @method \Magento\Sales\Model\Order\Invoice\Item setBaseWeeeTaxDisposition(float $value)
- * @method float getWeeeTaxAppliedAmount()
- * @method \Magento\Sales\Model\Order\Invoice\Item setWeeeTaxAppliedAmount(float $value)
- * @method float getWeeeTaxDisposition()
- * @method \Magento\Sales\Model\Order\Invoice\Item setWeeeTaxDisposition(float $value)
- * @method float getBaseWeeeTaxAppliedRowAmnt()
- * @method \Magento\Sales\Model\Order\Invoice\Item setBaseWeeeTaxAppliedRowAmnt(float $value)
- * @method string getWeeeTaxApplied()
- * @method \Magento\Sales\Model\Order\Invoice\Item setWeeeTaxApplied(string $value)
- * @SuppressWarnings(PHPMD.ExcessivePublicCount)
- * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
- * @since 100.0.2
- */
- class Item extends AbstractModel implements InvoiceItemInterface
- {
- /**
- * @var string
- */
- protected $_eventPrefix = 'sales_invoice_item';
- /**
- * @var string
- */
- protected $_eventObject = 'invoice_item';
- /**
- * @var \Magento\Sales\Model\Order\Item|null
- */
- protected $_orderItem = null;
- /**
- * @var \Magento\Sales\Model\Order\ItemFactory
- */
- protected $_orderItemFactory;
- /**
- * @param \Magento\Framework\Model\Context $context
- * @param \Magento\Framework\Registry $registry
- * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
- * @param AttributeValueFactory $customAttributeFactory
- * @param \Magento\Sales\Model\Order\ItemFactory $orderItemFactory
- * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
- * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
- * @param array $data
- */
- public function __construct(
- \Magento\Framework\Model\Context $context,
- \Magento\Framework\Registry $registry,
- \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
- AttributeValueFactory $customAttributeFactory,
- \Magento\Sales\Model\Order\ItemFactory $orderItemFactory,
- \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
- \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
- array $data = []
- ) {
- parent::__construct(
- $context,
- $registry,
- $extensionFactory,
- $customAttributeFactory,
- $resource,
- $resourceCollection,
- $data
- );
- $this->_orderItemFactory = $orderItemFactory;
- }
- /**
- * Initialize resource model
- *
- * @return void
- */
- protected function _construct()
- {
- $this->_init(\Magento\Sales\Model\ResourceModel\Order\Invoice\Item::class);
- }
- /**
- * Declare invoice instance
- *
- * @param \Magento\Sales\Api\Data\InvoiceInterface $invoice
- * @return $this
- */
- public function setInvoice(\Magento\Sales\Api\Data\InvoiceInterface $invoice)
- {
- return $this->setData(self::INVOICE, $invoice);
- }
- /**
- * Retrieve invoice instance
- *
- * @codeCoverageIgnore
- *
- * @return \Magento\Sales\Model\Order\Invoice
- */
- public function getInvoice()
- {
- return $this->getData(self::INVOICE);
- }
- /**
- * Declare order item instance
- *
- * @param \Magento\Sales\Model\Order\Item $item
- * @return $this
- */
- public function setOrderItem(\Magento\Sales\Model\Order\Item $item)
- {
- $this->_orderItem = $item;
- $this->setOrderItemId($item->getId());
- return $this;
- }
- /**
- * Retrieve order item instance
- *
- * @return \Magento\Sales\Model\Order\Item
- */
- public function getOrderItem()
- {
- if ($this->_orderItem === null) {
- if ($this->getInvoice()) {
- $this->_orderItem = $this->getInvoice()->getOrder()->getItemById($this->getOrderItemId());
- } else {
- $this->_orderItem = $this->_orderItemFactory->create()->load($this->getOrderItemId());
- }
- }
- return $this->_orderItem;
- }
- /**
- * Declare qty
- *
- * @codeCoverageIgnore
- *
- * @param float $qty
- * @return $this
- */
- public function setQty($qty)
- {
- return $this->setData(self::QTY, $qty);
- }
- /**
- * Applying qty to order item
- *
- * @return $this
- */
- public function register()
- {
- $orderItem = $this->getOrderItem();
- $orderItem->setQtyInvoiced($orderItem->getQtyInvoiced() + $this->getQty());
- $orderItem->setTaxInvoiced($orderItem->getTaxInvoiced() + $this->getTaxAmount());
- $orderItem->setBaseTaxInvoiced($orderItem->getBaseTaxInvoiced() + $this->getBaseTaxAmount());
- $orderItem->setDiscountTaxCompensationInvoiced(
- $orderItem->getDiscountTaxCompensationInvoiced() + $this->getDiscountTaxCompensationAmount()
- );
- $orderItem->setBaseDiscountTaxCompensationInvoiced(
- $orderItem->getBaseDiscountTaxCompensationInvoiced() + $this->getBaseDiscountTaxCompensationAmount()
- );
- $orderItem->setDiscountInvoiced($orderItem->getDiscountInvoiced() + $this->getDiscountAmount());
- $orderItem->setBaseDiscountInvoiced($orderItem->getBaseDiscountInvoiced() + $this->getBaseDiscountAmount());
- $orderItem->setRowInvoiced($orderItem->getRowInvoiced() + $this->getRowTotal());
- $orderItem->setBaseRowInvoiced($orderItem->getBaseRowInvoiced() + $this->getBaseRowTotal());
- return $this;
- }
- /**
- * Cancelling invoice item
- *
- * @return $this
- */
- public function cancel()
- {
- $orderItem = $this->getOrderItem();
- $orderItem->setQtyInvoiced($orderItem->getQtyInvoiced() - $this->getQty());
- $orderItem->setTaxInvoiced($orderItem->getTaxInvoiced() - $this->getTaxAmount());
- $orderItem->setBaseTaxInvoiced($orderItem->getBaseTaxInvoiced() - $this->getBaseTaxAmount());
- $orderItem->setDiscountTaxCompensationInvoiced(
- $orderItem->getDiscountTaxCompensationInvoiced() - $this->getDiscountTaxCompensationAmount()
- );
- $orderItem->setBaseDiscountTaxCompensationInvoiced(
- $orderItem->getBaseDiscountTaxCompensationInvoiced() - $this->getBaseDiscountTaxCompensationAmount()
- );
- $orderItem->setDiscountInvoiced($orderItem->getDiscountInvoiced() - $this->getDiscountAmount());
- $orderItem->setBaseDiscountInvoiced($orderItem->getBaseDiscountInvoiced() - $this->getBaseDiscountAmount());
- $orderItem->setRowInvoiced($orderItem->getRowInvoiced() - $this->getRowTotal());
- $orderItem->setBaseRowInvoiced($orderItem->getBaseRowInvoiced() - $this->getBaseRowTotal());
- return $this;
- }
- /**
- * Invoice item row total calculation
- *
- * @return $this
- */
- public function calcRowTotal()
- {
- $invoice = $this->getInvoice();
- $orderItem = $this->getOrderItem();
- $orderItemQty = $orderItem->getQtyOrdered();
- $rowTotal = $orderItem->getRowTotal() - $orderItem->getRowInvoiced();
- $baseRowTotal = $orderItem->getBaseRowTotal() - $orderItem->getBaseRowInvoiced();
- $rowTotalInclTax = $orderItem->getRowTotalInclTax();
- $baseRowTotalInclTax = $orderItem->getBaseRowTotalInclTax();
- if (!$this->isLast()) {
- $availableQty = $orderItemQty - $orderItem->getQtyInvoiced();
- $rowTotal = $invoice->roundPrice($rowTotal / $availableQty * $this->getQty());
- $baseRowTotal = $invoice->roundPrice($baseRowTotal / $availableQty * $this->getQty(), 'base');
- }
- $this->setRowTotal($rowTotal);
- $this->setBaseRowTotal($baseRowTotal);
- if ($rowTotalInclTax && $baseRowTotalInclTax) {
- $this->setRowTotalInclTax(
- $invoice->roundPrice($rowTotalInclTax / $orderItemQty * $this->getQty(), 'including')
- );
- $this->setBaseRowTotalInclTax(
- $invoice->roundPrice($baseRowTotalInclTax / $orderItemQty * $this->getQty(), 'including_base')
- );
- }
- return $this;
- }
- /**
- * Checking if the item is last
- *
- * @return bool
- */
- public function isLast()
- {
- if ((string)(double)$this->getQty() == (string)(double)$this->getOrderItem()->getQtyToInvoice()) {
- return true;
- }
- return false;
- }
- //@codeCoverageIgnoreStart
- /**
- * Returns additional_data
- *
- * @return string|null
- */
- public function getAdditionalData()
- {
- return $this->getData(InvoiceItemInterface::ADDITIONAL_DATA);
- }
- /**
- * Returns base_cost
- *
- * @return float|null
- */
- public function getBaseCost()
- {
- return $this->getData(InvoiceItemInterface::BASE_COST);
- }
- /**
- * Returns base_discount_amount
- *
- * @return float|null
- */
- public function getBaseDiscountAmount()
- {
- return $this->getData(InvoiceItemInterface::BASE_DISCOUNT_AMOUNT);
- }
- /**
- * Returns base_discount_tax_compensation_amount
- *
- * @return float|null
- */
- public function getBaseDiscountTaxCompensationAmount()
- {
- return $this->getData(InvoiceItemInterface::BASE_DISCOUNT_TAX_COMPENSATION_AMOUNT);
- }
- /**
- * Returns base_price
- *
- * @return float|null
- */
- public function getBasePrice()
- {
- return $this->getData(InvoiceItemInterface::BASE_PRICE);
- }
- /**
- * Returns base_price_incl_tax
- *
- * @return float|null
- */
- public function getBasePriceInclTax()
- {
- return $this->getData(InvoiceItemInterface::BASE_PRICE_INCL_TAX);
- }
- /**
- * Returns base_row_total
- *
- * @return float|null
- */
- public function getBaseRowTotal()
- {
- return $this->getData(InvoiceItemInterface::BASE_ROW_TOTAL);
- }
- /**
- * Returns base_row_total_incl_tax
- *
- * @return float|null
- */
- public function getBaseRowTotalInclTax()
- {
- return $this->getData(InvoiceItemInterface::BASE_ROW_TOTAL_INCL_TAX);
- }
- /**
- * Returns base_tax_amount
- *
- * @return float|null
- */
- public function getBaseTaxAmount()
- {
- return $this->getData(InvoiceItemInterface::BASE_TAX_AMOUNT);
- }
- /**
- * Returns description
- *
- * @return string|null
- */
- public function getDescription()
- {
- return $this->getData(InvoiceItemInterface::DESCRIPTION);
- }
- /**
- * Returns discount_amount
- *
- * @return float|null
- */
- public function getDiscountAmount()
- {
- return $this->getData(InvoiceItemInterface::DISCOUNT_AMOUNT);
- }
- /**
- * Returns discount_tax_compensation_amount
- *
- * @return float|null
- */
- public function getDiscountTaxCompensationAmount()
- {
- return $this->getData(InvoiceItemInterface::DISCOUNT_TAX_COMPENSATION_AMOUNT);
- }
- /**
- * Returns name
- *
- * @return string|null
- */
- public function getName()
- {
- return $this->getData(InvoiceItemInterface::NAME);
- }
- /**
- * Returns order_item_id
- *
- * @return int
- */
- public function getOrderItemId()
- {
- return $this->getData(InvoiceItemInterface::ORDER_ITEM_ID);
- }
- /**
- * Returns parent_id
- *
- * @return int|null
- */
- public function getParentId()
- {
- return $this->getData(InvoiceItemInterface::PARENT_ID);
- }
- /**
- * Returns price
- *
- * @return float|null
- */
- public function getPrice()
- {
- return $this->getData(InvoiceItemInterface::PRICE);
- }
- /**
- * Returns price_incl_tax
- *
- * @return float|null
- */
- public function getPriceInclTax()
- {
- return $this->getData(InvoiceItemInterface::PRICE_INCL_TAX);
- }
- /**
- * Returns product_id
- *
- * @return int|null
- */
- public function getProductId()
- {
- return $this->getData(InvoiceItemInterface::PRODUCT_ID);
- }
- /**
- * Returns qty
- *
- * @return float
- */
- public function getQty()
- {
- return $this->getData(InvoiceItemInterface::QTY);
- }
- /**
- * Returns row_total
- *
- * @return float|null
- */
- public function getRowTotal()
- {
- return $this->getData(InvoiceItemInterface::ROW_TOTAL);
- }
- /**
- * Returns row_total_incl_tax
- *
- * @return float|null
- */
- public function getRowTotalInclTax()
- {
- return $this->getData(InvoiceItemInterface::ROW_TOTAL_INCL_TAX);
- }
- /**
- * Returns sku
- *
- * @return string
- */
- public function getSku()
- {
- return $this->getData(InvoiceItemInterface::SKU);
- }
- /**
- * Returns tax_amount
- *
- * @return float|null
- */
- public function getTaxAmount()
- {
- return $this->getData(InvoiceItemInterface::TAX_AMOUNT);
- }
- /**
- * {@inheritdoc}
- */
- public function setParentId($id)
- {
- return $this->setData(InvoiceItemInterface::PARENT_ID, $id);
- }
- /**
- * {@inheritdoc}
- */
- public function setBasePrice($price)
- {
- return $this->setData(InvoiceItemInterface::BASE_PRICE, $price);
- }
- /**
- * {@inheritdoc}
- */
- public function setTaxAmount($amount)
- {
- return $this->setData(InvoiceItemInterface::TAX_AMOUNT, $amount);
- }
- /**
- * {@inheritdoc}
- */
- public function setBaseRowTotal($amount)
- {
- return $this->setData(InvoiceItemInterface::BASE_ROW_TOTAL, $amount);
- }
- /**
- * {@inheritdoc}
- */
- public function setDiscountAmount($amount)
- {
- return $this->setData(InvoiceItemInterface::DISCOUNT_AMOUNT, $amount);
- }
- /**
- * {@inheritdoc}
- */
- public function setRowTotal($amount)
- {
- return $this->setData(InvoiceItemInterface::ROW_TOTAL, $amount);
- }
- /**
- * {@inheritdoc}
- */
- public function setBaseDiscountAmount($amount)
- {
- return $this->setData(InvoiceItemInterface::BASE_DISCOUNT_AMOUNT, $amount);
- }
- /**
- * {@inheritdoc}
- */
- public function setPriceInclTax($amount)
- {
- return $this->setData(InvoiceItemInterface::PRICE_INCL_TAX, $amount);
- }
- /**
- * {@inheritdoc}
- */
- public function setBaseTaxAmount($amount)
- {
- return $this->setData(InvoiceItemInterface::BASE_TAX_AMOUNT, $amount);
- }
- /**
- * {@inheritdoc}
- */
- public function setBasePriceInclTax($amount)
- {
- return $this->setData(InvoiceItemInterface::BASE_PRICE_INCL_TAX, $amount);
- }
- /**
- * {@inheritdoc}
- */
- public function setBaseCost($baseCost)
- {
- return $this->setData(InvoiceItemInterface::BASE_COST, $baseCost);
- }
- /**
- * {@inheritdoc}
- */
- public function setPrice($price)
- {
- return $this->setData(InvoiceItemInterface::PRICE, $price);
- }
- /**
- * {@inheritdoc}
- */
- public function setBaseRowTotalInclTax($amount)
- {
- return $this->setData(InvoiceItemInterface::BASE_ROW_TOTAL_INCL_TAX, $amount);
- }
- /**
- * {@inheritdoc}
- */
- public function setRowTotalInclTax($amount)
- {
- return $this->setData(InvoiceItemInterface::ROW_TOTAL_INCL_TAX, $amount);
- }
- /**
- * {@inheritdoc}
- */
- public function setProductId($id)
- {
- return $this->setData(InvoiceItemInterface::PRODUCT_ID, $id);
- }
- /**
- * {@inheritdoc}
- */
- public function setOrderItemId($id)
- {
- return $this->setData(InvoiceItemInterface::ORDER_ITEM_ID, $id);
- }
- /**
- * {@inheritdoc}
- */
- public function setAdditionalData($additionalData)
- {
- return $this->setData(InvoiceItemInterface::ADDITIONAL_DATA, $additionalData);
- }
- /**
- * {@inheritdoc}
- */
- public function setDescription($description)
- {
- return $this->setData(InvoiceItemInterface::DESCRIPTION, $description);
- }
- /**
- * {@inheritdoc}
- */
- public function setSku($sku)
- {
- return $this->setData(InvoiceItemInterface::SKU, $sku);
- }
- /**
- * {@inheritdoc}
- */
- public function setName($name)
- {
- return $this->setData(InvoiceItemInterface::NAME, $name);
- }
- /**
- * {@inheritdoc}
- */
- public function setDiscountTaxCompensationAmount($amount)
- {
- return $this->setData(InvoiceItemInterface::DISCOUNT_TAX_COMPENSATION_AMOUNT, $amount);
- }
- /**
- * {@inheritdoc}
- */
- public function setBaseDiscountTaxCompensationAmount($amount)
- {
- return $this->setData(InvoiceItemInterface::BASE_DISCOUNT_TAX_COMPENSATION_AMOUNT, $amount);
- }
- /**
- * {@inheritdoc}
- *
- * @return \Magento\Sales\Api\Data\InvoiceItemExtensionInterface|null
- */
- public function getExtensionAttributes()
- {
- return $this->_getExtensionAttributes();
- }
- /**
- * {@inheritdoc}
- *
- * @param \Magento\Sales\Api\Data\InvoiceItemExtensionInterface $extensionAttributes
- * @return $this
- */
- public function setExtensionAttributes(\Magento\Sales\Api\Data\InvoiceItemExtensionInterface $extensionAttributes)
- {
- return $this->_setExtensionAttributes($extensionAttributes);
- }
- //@codeCoverageIgnoreEnd
- }
|