Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Public Member Functions | Static Public Member Functions | Data Fields | Protected Member Functions | Protected Attributes | Static Protected Attributes
Invoice Class Reference
Inheritance diagram for Invoice:
AbstractModel EntityInterface InvoiceInterface AbstractExtensibleModel ExtensibleDataInterface AbstractModel CustomAttributesDataInterface DataObject ExtensibleDataInterface

Public Member Functions

 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Sales\Model\Order\Invoice\Config $invoiceConfig, \Magento\Sales\Model\OrderFactory $orderFactory, \Magento\Framework\Math\CalculatorFactory $calculatorFactory, \Magento\Sales\Model\ResourceModel\Order\Invoice\Item\CollectionFactory $invoiceItemCollectionFactory, \Magento\Sales\Model\Order\Invoice\CommentFactory $invoiceCommentFactory, \Magento\Sales\Model\ResourceModel\Order\Invoice\Comment\CollectionFactory $commentCollectionFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 loadByIncrementId ($incrementId)
 
 getConfig ()
 
 getStore ()
 
 setOrder (\Magento\Sales\Model\Order $order)
 
 getOrder ()
 
 getEntityType ()
 
 getBillingAddress ()
 
 getShippingAddress ()
 
 isCanceled ()
 
 canCapture ()
 
 canVoid ()
 
 canCancel ()
 
 canRefund ()
 
 capture ()
 
 pay ()
 
 wasPayCalled ()
 
 void ()
 
 cancel ()
 
 collectTotals ()
 
 roundPrice ($price, $type='regular', $negative=false)
 
 getItemsCollection ()
 
 getAllItems ()
 
 getItemById ($itemId)
 
 addItem (\Magento\Sales\Model\Order\Invoice\Item $item)
 
 getStateName ($stateId=null)
 
 register ()
 
 isLast ()
 
 addComment ($comment, $notify=false, $visibleOnFront=false)
 
 getCommentsCollection ($reload=false)
 
 reset ()
 
 getItems ()
 
 getComments ()
 
 getIncrementId ()
 
 getBaseTotalRefunded ()
 
 getDiscountDescription ()
 
 setItems ($items)
 
 getBaseCurrencyCode ()
 
 getBaseDiscountAmount ()
 
 getBaseGrandTotal ()
 
 getBaseDiscountTaxCompensationAmount ()
 
 getBaseShippingAmount ()
 
 getBaseShippingDiscountTaxCompensationAmnt ()
 
 getBaseShippingInclTax ()
 
 getBaseShippingTaxAmount ()
 
 getBaseSubtotal ()
 
 getBaseSubtotalInclTax ()
 
 getBaseTaxAmount ()
 
 getBaseToGlobalRate ()
 
 getBaseToOrderRate ()
 
 getBillingAddressId ()
 
 getCanVoidFlag ()
 
 getCreatedAt ()
 
 setCreatedAt ($createdAt)
 
 getDiscountAmount ()
 
 getEmailSent ()
 
 getGlobalCurrencyCode ()
 
 getGrandTotal ()
 
 getDiscountTaxCompensationAmount ()
 
 getIsUsedForRefund ()
 
 getOrderCurrencyCode ()
 
 getOrderId ()
 
 getShippingAddressId ()
 
 getShippingAmount ()
 
 getShippingDiscountTaxCompensationAmount ()
 
 getShippingInclTax ()
 
 getShippingTaxAmount ()
 
 getState ()
 
 getStoreCurrencyCode ()
 
 getStoreId ()
 
 getStoreToBaseRate ()
 
 getStoreToOrderRate ()
 
 getSubtotal ()
 
 getSubtotalInclTax ()
 
 getTaxAmount ()
 
 getTotalQty ()
 
 getTransactionId ()
 
 setTransactionId ($transactionId)
 
 getUpdatedAt ()
 
 setComments ($comments)
 
 setUpdatedAt ($timestamp)
 
 setStoreId ($id)
 
 setBaseGrandTotal ($amount)
 
 setShippingTaxAmount ($amount)
 
 setTaxAmount ($amount)
 
 setBaseTaxAmount ($amount)
 
 setStoreToOrderRate ($rate)
 
 setBaseShippingTaxAmount ($amount)
 
 setBaseDiscountAmount ($amount)
 
 setBaseToOrderRate ($rate)
 
 setGrandTotal ($amount)
 
 setShippingAmount ($amount)
 
 setSubtotalInclTax ($amount)
 
 setBaseSubtotalInclTax ($amount)
 
 setStoreToBaseRate ($rate)
 
 setBaseShippingAmount ($amount)
 
 setTotalQty ($qty)
 
 setBaseToGlobalRate ($rate)
 
 setSubtotal ($amount)
 
 setBaseSubtotal ($amount)
 
 setDiscountAmount ($amount)
 
 setBillingAddressId ($id)
 
 setIsUsedForRefund ($isUsedForRefund)
 
 setOrderId ($id)
 
 setEmailSent ($emailSent)
 
 setCanVoidFlag ($canVoidFlag)
 
 setState ($state)
 
 setShippingAddressId ($id)
 
 setStoreCurrencyCode ($code)
 
 setOrderCurrencyCode ($code)
 
 setBaseCurrencyCode ($code)
 
 setGlobalCurrencyCode ($code)
 
 setIncrementId ($id)
 
 setDiscountTaxCompensationAmount ($amount)
 
 setBaseDiscountTaxCompensationAmount ($amount)
 
 setShippingDiscountTaxCompensationAmount ($amount)
 
 setBaseShippingDiscountTaxCompensationAmnt ($amnt)
 
 setShippingInclTax ($amount)
 
 setBaseShippingInclTax ($amount)
 
 setBaseTotalRefunded ($amount)
 
 setDiscountDescription ($description)
 
 getExtensionAttributes ()
 
 setExtensionAttributes (\Magento\Sales\Api\Data\InvoiceExtensionInterface $extensionAttributes)
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 getEventObject ()
 
- Public Member Functions inherited from AbstractExtensibleModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, ExtensionAttributesFactory $extensionFactory, AttributeValueFactory $customAttributeFactory, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 getCustomAttributes ()
 
 getCustomAttribute ($attributeCode)
 
 setCustomAttributes (array $attributes)
 
 setCustomAttribute ($attributeCode, $attributeValue)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 setId ($value)
 
 __sleep ()
 
 __wakeup ()
 
- Public Member Functions inherited from AbstractModel
 __construct (\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])
 
 __sleep ()
 
 __wakeup ()
 
 setIdFieldName ($name)
 
 getIdFieldName ()
 
 getId ()
 
 setId ($value)
 
 isDeleted ($isDeleted=null)
 
 hasDataChanges ()
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 setDataChanges ($value)
 
 getOrigData ($key=null)
 
 setOrigData ($key=null, $data=null)
 
 dataHasChangedFor ($field)
 
 getResourceName ()
 
 getResourceCollection ()
 
 getCollection ()
 
 load ($modelId, $field=null)
 
 beforeLoad ($identifier, $field=null)
 
 afterLoad ()
 
 isSaveAllowed ()
 
 setHasDataChanges ($flag)
 
 save ()
 
 afterCommitCallback ()
 
 isObjectNew ($flag=null)
 
 beforeSave ()
 
 validateBeforeSave ()
 
 getCacheTags ()
 
 cleanModelCache ()
 
 afterSave ()
 
 delete ()
 
 beforeDelete ()
 
 afterDelete ()
 
 afterDeleteCommit ()
 
 getResource ()
 
 getEntityId ()
 
 setEntityId ($entityId)
 
 clearInstance ()
 
 getStoredData ()
 
 getEventPrefix ()
 
- Public Member Functions inherited from DataObject
 __construct (array $data=[])
 
 addData (array $arr)
 
 setData ($key, $value=null)
 
 unsetData ($key=null)
 
 getData ($key='', $index=null)
 
 getDataByPath ($path)
 
 getDataByKey ($key)
 
 setDataUsingMethod ($key, $args=[])
 
 getDataUsingMethod ($key, $args=null)
 
 hasData ($key='')
 
 toArray (array $keys=[])
 
 convertToArray (array $keys=[])
 
 toXml (array $keys=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 convertToXml (array $arrAttributes=[], $rootName='item', $addOpenTag=false, $addCdata=true)
 
 toJson (array $keys=[])
 
 convertToJson (array $keys=[])
 
 toString ($format='')
 
 __call ($method, $args)
 
 isEmpty ()
 
 serialize ($keys=[], $valueSeparator='=', $fieldSeparator=' ', $quote='"')
 
 debug ($data=null, &$objects=[])
 
 offsetSet ($offset, $value)
 
 offsetExists ($offset)
 
 offsetUnset ($offset)
 
 offsetGet ($offset)
 
- Public Member Functions inherited from InvoiceInterface
 getEntityId ()
 
 setEntityId ($entityId)
 
 setExtensionAttributes (\Magento\Sales\Api\Data\InvoiceExtensionInterface $extensionAttributes)
 

Static Public Member Functions

static getStates ()
 

Data Fields

const STATE_OPEN = 1
 
const STATE_PAID = 2
 
const STATE_CANCELED = 3
 
const CAPTURE_ONLINE = 'online'
 
const CAPTURE_OFFLINE = 'offline'
 
const NOT_CAPTURE = 'not_capture'
 
const REPORT_DATE_TYPE_ORDER_CREATED = 'order_created'
 
const REPORT_DATE_TYPE_INVOICE_CREATED = 'invoice_created'
 
- Data Fields inherited from CustomAttributesDataInterface
const CUSTOM_ATTRIBUTES = 'custom_attributes'
 
- Data Fields inherited from ExtensibleDataInterface
const EXTENSION_ATTRIBUTES_KEY = 'extension_attributes'
 
- Data Fields inherited from InvoiceInterface
const ENTITY_ID = 'entity_id'
 
const STORE_ID = 'store_id'
 
const BASE_GRAND_TOTAL = 'base_grand_total'
 
const SHIPPING_TAX_AMOUNT = 'shipping_tax_amount'
 
const TAX_AMOUNT = 'tax_amount'
 
const BASE_TAX_AMOUNT = 'base_tax_amount'
 
const STORE_TO_ORDER_RATE = 'store_to_order_rate'
 
const BASE_SHIPPING_TAX_AMOUNT = 'base_shipping_tax_amount'
 
const BASE_DISCOUNT_AMOUNT = 'base_discount_amount'
 
const BASE_TO_ORDER_RATE = 'base_to_order_rate'
 
const GRAND_TOTAL = 'grand_total'
 
const SHIPPING_AMOUNT = 'shipping_amount'
 
const SUBTOTAL_INCL_TAX = 'subtotal_incl_tax'
 
const BASE_SUBTOTAL_INCL_TAX = 'base_subtotal_incl_tax'
 
const STORE_TO_BASE_RATE = 'store_to_base_rate'
 
const BASE_SHIPPING_AMOUNT = 'base_shipping_amount'
 
const TOTAL_QTY = 'total_qty'
 
const BASE_TO_GLOBAL_RATE = 'base_to_global_rate'
 
const SUBTOTAL = 'subtotal'
 
const BASE_SUBTOTAL = 'base_subtotal'
 
const DISCOUNT_AMOUNT = 'discount_amount'
 
const BILLING_ADDRESS_ID = 'billing_address_id'
 
const IS_USED_FOR_REFUND = 'is_used_for_refund'
 
const ORDER_ID = 'order_id'
 
const EMAIL_SENT = 'email_sent'
 
const CAN_VOID_FLAG = 'can_void_flag'
 
const STATE = 'state'
 
const SHIPPING_ADDRESS_ID = 'shipping_address_id'
 
const STORE_CURRENCY_CODE = 'store_currency_code'
 
const TRANSACTION_ID = 'transaction_id'
 
const ORDER_CURRENCY_CODE = 'order_currency_code'
 
const BASE_CURRENCY_CODE = 'base_currency_code'
 
const GLOBAL_CURRENCY_CODE = 'global_currency_code'
 
const INCREMENT_ID = 'increment_id'
 
const CREATED_AT = 'created_at'
 
const UPDATED_AT = 'updated_at'
 
const DISCOUNT_TAX_COMPENSATION_AMOUNT = 'discount_tax_compensation_amount'
 
const BASE_DISCOUNT_TAX_COMPENSATION_AMOUNT = 'base_discount_tax_compensation_amount'
 
const SHIPPING_DISCOUNT_TAX_COMPENSATION_AMOUNT = 'shipping_discount_tax_compensation_amount'
 
const BASE_SHIPPING_DISCOUNT_TAX_COMPENSATION_AMNT = 'base_shipping_discount_tax_compensation_amnt'
 
const SHIPPING_INCL_TAX = 'shipping_incl_tax'
 
const BASE_SHIPPING_INCL_TAX = 'base_shipping_incl_tax'
 
const BASE_TOTAL_REFUNDED = 'base_total_refunded'
 
const DISCOUNT_DESCRIPTION = 'discount_description'
 
const ITEMS = 'items'
 
const COMMENTS = 'comments'
 

Protected Member Functions

 _construct ()
 
 _beforeSave ()
 
 _afterSave ()
 
- Protected Member Functions inherited from AbstractExtensibleModel
 filterCustomAttributes ($data)
 
 initializeCustomAttributes ()
 
 convertCustomAttributeValues (array &$customAttributes)
 
 getCustomAttributesCodes ()
 
 _setExtensionAttributes (\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)
 
 _getExtensionAttributes ()
 
- Protected Member Functions inherited from AbstractModel
 _construct ()
 
 _init ($resourceModel)
 
 _setResourceModel ($resourceName, $collectionName=null)
 
 _getResource ()
 
 _getEventData ()
 
 _beforeLoad ($modelId, $field=null)
 
 _afterLoad ()
 
 _hasModelChanged ()
 
 _getValidatorBeforeSave ()
 
 _createValidatorBeforeSave ()
 
 _getValidationRulesBeforeSave ()
 
 _clearReferences ()
 
 _clearData ()
 
- Protected Member Functions inherited from DataObject
 _getData ($key)
 
 _underscore ($name)
 

Protected Attributes

 $entityType = 'invoice'
 
 $_order
 
 $_rounders = []
 
 $_saveBeforeDestruct = false
 
 $_eventPrefix = 'sales_order_invoice'
 
 $_eventObject = 'invoice'
 
 $_wasPayCalled = false
 
 $_invoiceConfig
 
 $_orderFactory
 
 $_calculatorFactory
 
 $_invoiceItemCollectionFactory
 
 $_invoiceCommentFactory
 
 $_commentCollectionFactory
 
- Protected Attributes inherited from AbstractExtensibleModel
 $extensionAttributesFactory
 
 $extensionAttributes
 
 $customAttributeFactory
 
 $customAttributesCodes = null
 
 $customAttributesChanged = false
 
- Protected Attributes inherited from AbstractModel
 $_eventPrefix = 'core_abstract'
 
 $_eventObject = 'object'
 
 $_idFieldName = 'id'
 
 $_hasDataChanges = false
 
 $_origData
 
 $_isDeleted = false
 
 $_resource
 
 $_resourceCollection
 
 $_resourceName
 
 $_collectionName
 
 $_cacheTag = false
 
 $_dataSaveAllowed = true
 
 $_isObjectNew = null
 
 $_validatorBeforeSave = null
 
 $_eventManager
 
 $_cacheManager
 
 $_registry
 
 $_logger
 
 $_appState
 
 $_actionValidator
 
 $storedData = []
 
- Protected Attributes inherited from DataObject
 $_data = []
 

Static Protected Attributes

static $_states
 
- Static Protected Attributes inherited from DataObject
static $_underscoreCache = []
 

Detailed Description

@api @method \Magento\Sales\Model\Order\Invoice setSendEmail(bool $value) @method \Magento\Sales\Model\Order\Invoice setCustomerNote(string $value) @method string getCustomerNote() @method \Magento\Sales\Model\Order\Invoice setCustomerNoteNotify(bool $value) @method bool getCustomerNoteNotify() @SuppressWarnings(PHPMD.ExcessivePublicCount) @SuppressWarnings(PHPMD.ExcessiveClassComplexity) @SuppressWarnings(PHPMD.CouplingBetweenObjects)

Since
100.0.2

Definition at line 25 of file Invoice.php.

Constructor & Destructor Documentation

◆ __construct()

__construct ( \Magento\Framework\Model\Context  $context,
\Magento\Framework\Registry  $registry,
\Magento\Framework\Api\ExtensionAttributesFactory  $extensionFactory,
AttributeValueFactory  $customAttributeFactory,
\Magento\Sales\Model\Order\Invoice\Config  $invoiceConfig,
\Magento\Sales\Model\OrderFactory  $orderFactory,
\Magento\Framework\Math\CalculatorFactory  $calculatorFactory,
\Magento\Sales\Model\ResourceModel\Order\Invoice\Item\CollectionFactory  $invoiceItemCollectionFactory,
\Magento\Sales\Model\Order\Invoice\CommentFactory  $invoiceCommentFactory,
\Magento\Sales\Model\ResourceModel\Order\Invoice\Comment\CollectionFactory  $commentCollectionFactory,
\Magento\Framework\Model\ResourceModel\AbstractResource  $resource = null,
\Magento\Framework\Data\Collection\AbstractDb  $resourceCollection = null,
array  $data = [] 
)
Parameters
\Magento\Framework\Model\Context$context
\Magento\Framework\Registry$registry
\Magento\Framework\Api\ExtensionAttributesFactory$extensionFactory
AttributeValueFactory$customAttributeFactory
Invoice\Config$invoiceConfig
\Magento\Sales\Model\OrderFactory$orderFactory
\Magento\Framework\Math\CalculatorFactory$calculatorFactory
\Magento\Sales\Model\ResourceModel\Order\Invoice\Item\CollectionFactory$invoiceItemCollectionFactory
Invoice\CommentFactory$invoiceCommentFactory
\Magento\Sales\Model\ResourceModel\Order\Invoice\Comment\CollectionFactory$commentCollectionFactory
\Magento\Framework\Model\ResourceModel\AbstractResource$resource
\Magento\Framework\Data\Collection\AbstractDb$resourceCollection
array$data@SuppressWarnings(PHPMD.ExcessiveParameterList)

Definition at line 139 of file Invoice.php.

153  {
154  $this->_invoiceConfig = $invoiceConfig;
155  $this->_orderFactory = $orderFactory;
156  $this->_calculatorFactory = $calculatorFactory;
157  $this->_invoiceItemCollectionFactory = $invoiceItemCollectionFactory;
158  $this->_invoiceCommentFactory = $invoiceCommentFactory;
159  $this->_commentCollectionFactory = $commentCollectionFactory;
160  parent::__construct(
161  $context,
162  $registry,
163  $extensionFactory,
165  $resource,
166  $resourceCollection,
167  $data
168  );
169  }
$resource
Definition: bulk.php:12

Member Function Documentation

◆ _afterSave()

_afterSave ( )
protected

After object save manipulation

Returns
$this

Definition at line 770 of file Invoice.php.

771  {
772  return parent::_afterSave();
773  }

◆ _beforeSave()

_beforeSave ( )
protected

Before object save manipulations

Returns
$this

Perform actions before object save

Parameters
\Magento\Framework\Model\AbstractModel | \Magento\Framework\DataObject$object
Returns
$this

Definition at line 760 of file Invoice.php.

761  {
762  return parent::_beforeSave();
763  }

◆ _construct()

_construct ( )
protected

Initialize invoice resource model

Returns
void

Definition at line 176 of file Invoice.php.

177  {
178  $this->_init(\Magento\Sales\Model\ResourceModel\Order\Invoice::class);
179  }

◆ addComment()

addComment (   $comment,
  $notify = false,
  $visibleOnFront = false 
)

Adds comment to invoice with additional possibility to send it to customer via email and show it in customer account

Parameters
string$comment
bool$notify
bool$visibleOnFront
Returns
$this

Definition at line 693 of file Invoice.php.

694  {
695  if (!$comment instanceof \Magento\Sales\Model\Order\Invoice\Comment) {
696  $comment = $this->_invoiceCommentFactory->create()->setComment(
697  $comment
698  )->setIsCustomerNotified(
699  $notify
700  )->setIsVisibleOnFront(
701  $visibleOnFront
702  );
703  }
704  $comment->setInvoice($this)->setStoreId($this->getStoreId())->setParentId($this->getId());
705  if (!$comment->getId()) {
706  $this->getCommentsCollection()->addItem($comment);
707  }
708  $this->_hasDataChanges = true;
709  return $this;
710  }
getCommentsCollection($reload=false)
Definition: Invoice.php:716

◆ addItem()

Parameters
\Magento\Sales\Model\Order\Invoice\Item$item
Returns
$this

Definition at line 542 of file Invoice.php.

543  {
544  $item->setInvoice($this)->setParentId($this->getId())->setStoreId($this->getStoreId());
545 
546  if (!$item->getId()) {
547  $this->getItemsCollection()->addItem($item);
548  }
549  return $this;
550  }

◆ canCancel()

canCancel ( )

Check invoice cancel action availability

Returns
bool

Definition at line 316 of file Invoice.php.

317  {
318  return $this->getState() == self::STATE_OPEN;
319  }

◆ canCapture()

canCapture ( )

Check invoice capture action availability

Returns
bool

Definition at line 289 of file Invoice.php.

290  {
291  return $this->getState() != self::STATE_CANCELED &&
292  $this->getState() != self::STATE_PAID &&
293  $this->getOrder()->getPayment()->canCapture();
294  }

◆ cancel()

cancel ( )

Cancel invoice action

Returns
$this

Unregister order totals only for invoices in state PAID

Definition at line 408 of file Invoice.php.

409  {
410  if (!$this->canCancel()) {
411  return $this;
412  }
413  $order = $this->getOrder();
414  $order->getPayment()->cancelInvoice($this);
415  foreach ($this->getAllItems() as $item) {
416  $item->cancel();
417  }
418 
422  $order->setTotalInvoiced($order->getTotalInvoiced() - $this->getGrandTotal());
423  $order->setBaseTotalInvoiced($order->getBaseTotalInvoiced() - $this->getBaseGrandTotal());
424 
425  $order->setSubtotalInvoiced($order->getSubtotalInvoiced() - $this->getSubtotal());
426  $order->setBaseSubtotalInvoiced($order->getBaseSubtotalInvoiced() - $this->getBaseSubtotal());
427 
428  $order->setTaxInvoiced($order->getTaxInvoiced() - $this->getTaxAmount());
429  $order->setBaseTaxInvoiced($order->getBaseTaxInvoiced() - $this->getBaseTaxAmount());
430 
431  $order->setDiscountTaxCompensationInvoiced(
432  $order->getDiscountTaxCompensationInvoiced() - $this->getDiscountTaxCompensationAmount()
433  );
434  $order->setBaseDiscountTaxCompensationInvoiced(
435  $order->getBaseDiscountTaxCompensationInvoiced() - $this->getBaseDiscountTaxCompensationAmount()
436  );
437 
438  $order->setShippingTaxInvoiced($order->getShippingTaxInvoiced() - $this->getShippingTaxAmount());
439  $order->setBaseShippingTaxInvoiced($order->getBaseShippingTaxInvoiced() - $this->getBaseShippingTaxAmount());
440 
441  $order->setShippingInvoiced($order->getShippingInvoiced() - $this->getShippingAmount());
442  $order->setBaseShippingInvoiced($order->getBaseShippingInvoiced() - $this->getBaseShippingAmount());
443 
444  $order->setDiscountInvoiced($order->getDiscountInvoiced() - $this->getDiscountAmount());
445  $order->setBaseDiscountInvoiced($order->getBaseDiscountInvoiced() - $this->getBaseDiscountAmount());
446  $order->setBaseTotalInvoicedCost($order->getBaseTotalInvoicedCost() - $this->getBaseCost());
447 
448  if ($this->getState() == self::STATE_PAID) {
449  $order->setTotalPaid($order->getTotalPaid() - $this->getGrandTotal());
450  $order->setBaseTotalPaid($order->getBaseTotalPaid() - $this->getBaseGrandTotal());
451  }
452  $this->setState(self::STATE_CANCELED);
453  $order->setState(\Magento\Sales\Model\Order::STATE_PROCESSING)
454  ->setStatus($order->getConfig()->getStateDefaultStatus(\Magento\Sales\Model\Order::STATE_PROCESSING));
455  $this->_eventManager->dispatch('sales_order_invoice_cancel', [$this->_eventObject => $this]);
456  return $this;
457  }
$order
Definition: order.php:55

◆ canRefund()

canRefund ( )

Check invoice refund action availability

Returns
bool

Definition at line 326 of file Invoice.php.

327  {
328  if ($this->getState() != self::STATE_PAID) {
329  return false;
330  }
331  if (abs($this->getBaseGrandTotal() - $this->getBaseTotalRefunded()) < .0001) {
332  return false;
333  }
334  return true;
335  }

◆ canVoid()

canVoid ( )

Check invoice void action availability

Returns
bool

Definition at line 301 of file Invoice.php.

302  {
303  if ($this->getState() == self::STATE_PAID) {
304  if ($this->getCanVoidFlag() === null) {
305  return (bool)$this->getOrder()->getPayment()->canVoid();
306  }
307  }
308  return (bool)$this->getCanVoidFlag();
309  }

◆ capture()

capture ( )

Capture invoice

Returns
$this

Definition at line 342 of file Invoice.php.

343  {
344  $this->getOrder()->getPayment()->capture($this);
345  if ($this->getIsPaid()) {
346  $this->pay();
347  }
348  return $this;
349  }

◆ collectTotals()

collectTotals ( )

Invoice totals collecting

Returns
$this

Definition at line 464 of file Invoice.php.

465  {
466  foreach ($this->getConfig()->getTotalModels() as $model) {
467  $model->collect($this);
468  }
469  return $this;
470  }

◆ getAllItems()

getAllItems ( )
Returns
array

Definition at line 513 of file Invoice.php.

514  {
515  $items = [];
516  foreach ($this->getItemsCollection() as $item) {
517  if (!$item->isDeleted()) {
518  $items[] = $item;
519  }
520  }
521  return $items;
522  }
$items

◆ getBaseCurrencyCode()

getBaseCurrencyCode ( )

Returns base_currency_code

Returns
string|null

Implements InvoiceInterface.

Definition at line 854 of file Invoice.php.

◆ getBaseDiscountAmount()

getBaseDiscountAmount ( )

Returns base_discount_amount

Returns
float|null

Implements InvoiceInterface.

Definition at line 864 of file Invoice.php.

◆ getBaseDiscountTaxCompensationAmount()

getBaseDiscountTaxCompensationAmount ( )

Returns base_discount_tax_compensation_amount

Returns
float|null

Implements InvoiceInterface.

Definition at line 884 of file Invoice.php.

◆ getBaseGrandTotal()

getBaseGrandTotal ( )

Returns base_grand_total

Returns
float|null

Implements InvoiceInterface.

Definition at line 874 of file Invoice.php.

◆ getBaseShippingAmount()

getBaseShippingAmount ( )

Returns base_shipping_amount

Returns
float|null

Implements InvoiceInterface.

Definition at line 894 of file Invoice.php.

◆ getBaseShippingDiscountTaxCompensationAmnt()

getBaseShippingDiscountTaxCompensationAmnt ( )

Returns base_shipping_discount_tax_compensation_amnt

Returns
float|null

Implements InvoiceInterface.

Definition at line 904 of file Invoice.php.

◆ getBaseShippingInclTax()

getBaseShippingInclTax ( )

Returns base_shipping_incl_tax

Returns
float|null

Implements InvoiceInterface.

Definition at line 914 of file Invoice.php.

◆ getBaseShippingTaxAmount()

getBaseShippingTaxAmount ( )

Returns base_shipping_tax_amount

Returns
float|null

Implements InvoiceInterface.

Definition at line 924 of file Invoice.php.

◆ getBaseSubtotal()

getBaseSubtotal ( )

Returns base_subtotal

Returns
float|null

Implements InvoiceInterface.

Definition at line 934 of file Invoice.php.

◆ getBaseSubtotalInclTax()

getBaseSubtotalInclTax ( )

Returns base_subtotal_incl_tax

Returns
float|null

Implements InvoiceInterface.

Definition at line 944 of file Invoice.php.

◆ getBaseTaxAmount()

getBaseTaxAmount ( )

Returns base_tax_amount

Returns
float|null

Implements InvoiceInterface.

Definition at line 954 of file Invoice.php.

◆ getBaseToGlobalRate()

getBaseToGlobalRate ( )

Returns base_to_global_rate

Returns
float|null

Implements InvoiceInterface.

Definition at line 964 of file Invoice.php.

◆ getBaseToOrderRate()

getBaseToOrderRate ( )

Returns base_to_order_rate

Returns
float|null

Implements InvoiceInterface.

Definition at line 974 of file Invoice.php.

◆ getBaseTotalRefunded()

getBaseTotalRefunded ( )

Returns base_total_refunded

Returns
float|null

Implements InvoiceInterface.

Definition at line 826 of file Invoice.php.

◆ getBillingAddress()

getBillingAddress ( )

Retrieve billing address

Returns
Address

Definition at line 259 of file Invoice.php.

260  {
261  return $this->getOrder()->getBillingAddress();
262  }

◆ getBillingAddressId()

getBillingAddressId ( )

Returns billing_address_id

Returns
int|null

Implements InvoiceInterface.

Definition at line 984 of file Invoice.php.

◆ getCanVoidFlag()

getCanVoidFlag ( )

Returns can_void_flag

Returns
int|null

Implements InvoiceInterface.

Definition at line 994 of file Invoice.php.

◆ getComments()

getComments ( )

Return invoice comments

Returns
\Magento\Sales\Api\Data\InvoiceCommentInterface[]|null

Implements InvoiceInterface.

Definition at line 797 of file Invoice.php.

798  {
799  if ($this->getData(InvoiceInterface::COMMENTS) === null && $this->getId()) {
800  $collection = $this->_commentCollectionFactory->create()->setInvoiceFilter($this->getId());
801  foreach ($collection as $comment) {
802  $comment->setInvoice($this);
803  }
804  $this->setData(InvoiceInterface::COMMENTS, $collection->getItems());
805  }
806  return $this->getData(InvoiceInterface::COMMENTS);
807  }

◆ getCommentsCollection()

getCommentsCollection (   $reload = false)
Parameters
bool$reload
Returns
\Magento\Sales\Model\ResourceModel\Order\Invoice\Comment\Collection

When invoice created with adding comment, comments collection must be loaded before we added this comment.

Definition at line 716 of file Invoice.php.

717  {
718  if (!$this->hasData(InvoiceInterface::COMMENTS) || $reload) {
719  $comments = $this->_commentCollectionFactory->create()->setInvoiceFilter($this->getId())
720  ->setCreatedAtOrder();
721 
722  $this->setComments($comments);
727  $this->getComments()->load();
728 
729  if ($this->getId()) {
730  foreach ($this->getComments() as $comment) {
731  $comment->setInvoice($this);
732  }
733  }
734  }
735  return $this->getComments();
736  }

◆ getConfig()

getConfig ( )

Retrieve invoice configuration model

Returns
\Magento\Sales\Model\Order\Invoice\Config

Definition at line 203 of file Invoice.php.

204  {
205  return $this->_invoiceConfig;
206  }

◆ getCreatedAt()

getCreatedAt ( )

Returns created_at

Returns
string|null

Implements InvoiceInterface.

Definition at line 1004 of file Invoice.php.

◆ getDiscountAmount()

getDiscountAmount ( )

Returns discount_amount

Returns
float|null

Implements InvoiceInterface.

Definition at line 1022 of file Invoice.php.

◆ getDiscountDescription()

getDiscountDescription ( )

Returns discount_description

Returns
string|null

Implements InvoiceInterface.

Definition at line 836 of file Invoice.php.

◆ getDiscountTaxCompensationAmount()

getDiscountTaxCompensationAmount ( )

Returns discount_tax_compensation_amount

Returns
float|null

Implements InvoiceInterface.

Definition at line 1062 of file Invoice.php.

◆ getEmailSent()

getEmailSent ( )

Returns email_sent

Returns
int|null

Implements InvoiceInterface.

Definition at line 1032 of file Invoice.php.

◆ getEntityType()

getEntityType ( )

Return order history item identifier

Returns
string

Definition at line 249 of file Invoice.php.

250  {
251  return $this->entityType;
252  }

◆ getExtensionAttributes()

getExtensionAttributes ( )

{Retrieve existing extension attributes object or create a new one.

Returns
\Magento\Sales\Api\Data\InvoiceExtensionInterface|null
}

Returns
\Magento\Sales\Api\Data\InvoiceExtensionInterface|null

Implements InvoiceInterface.

Definition at line 1609 of file Invoice.php.

◆ getGlobalCurrencyCode()

getGlobalCurrencyCode ( )

Returns global_currency_code

Returns
string|null

Implements InvoiceInterface.

Definition at line 1042 of file Invoice.php.

◆ getGrandTotal()

getGrandTotal ( )

Returns grand_total

Returns
float|null

Implements InvoiceInterface.

Definition at line 1052 of file Invoice.php.

◆ getIncrementId()

getIncrementId ( )

Returns increment id

Returns
string

Implements InvoiceInterface.

Definition at line 816 of file Invoice.php.

817  {
818  return $this->getData('increment_id');
819  }

◆ getIsUsedForRefund()

getIsUsedForRefund ( )

Returns is_used_for_refund

Returns
int|null

Implements InvoiceInterface.

Definition at line 1072 of file Invoice.php.

◆ getItemById()

getItemById (   $itemId)
Parameters
int | string$itemId
Returns
bool|\Magento\Sales\Model\Order\Invoice\Item

Definition at line 528 of file Invoice.php.

529  {
530  foreach ($this->getItemsCollection() as $item) {
531  if ($item->getId() == $itemId) {
532  return $item;
533  }
534  }
535  return false;
536  }

◆ getItems()

getItems ( )

Returns invoice items

Returns
\Magento\Sales\Api\Data\InvoiceItemInterface[]

Implements InvoiceInterface.

Definition at line 780 of file Invoice.php.

781  {
782  if ($this->getData(InvoiceInterface::ITEMS) === null && $this->getId()) {
783  $collection = $this->_invoiceItemCollectionFactory->create()->setInvoiceFilter($this->getId());
784  foreach ($collection as $item) {
785  $item->setInvoice($this);
786  }
787  $this->setData(InvoiceInterface::ITEMS, $collection->getItems());
788  }
789  return $this->getData(InvoiceInterface::ITEMS);
790  }

◆ getItemsCollection()

getItemsCollection ( )

Get invoice items collection

Returns
\Magento\Sales\Model\ResourceModel\Order\Invoice\Item\Collection

Definition at line 496 of file Invoice.php.

497  {
498  if (!$this->hasData(InvoiceInterface::ITEMS)) {
499  $this->setItems($this->_invoiceItemCollectionFactory->create()->setInvoiceFilter($this->getId()));
500 
501  if ($this->getId()) {
502  foreach ($this->getItems() as $item) {
503  $item->setInvoice($this);
504  }
505  }
506  }
507  return $this->getItems();
508  }

◆ getOrder()

getOrder ( )

Retrieve the order the invoice for created for

Returns
\Magento\Sales\Model\Order

Definition at line 236 of file Invoice.php.

237  {
238  if (!$this->_order instanceof \Magento\Sales\Model\Order) {
239  $this->_order = $this->_orderFactory->create()->load($this->getOrderId());
240  }
241  return $this->_order->setHistoryEntityName($this->entityType);
242  }

◆ getOrderCurrencyCode()

getOrderCurrencyCode ( )

Returns order_currency_code

Returns
string|null

Implements InvoiceInterface.

Definition at line 1082 of file Invoice.php.

◆ getOrderId()

getOrderId ( )

Returns order_id

Returns
int

Implements InvoiceInterface.

Definition at line 1092 of file Invoice.php.

◆ getShippingAddress()

getShippingAddress ( )

Retrieve shipping address

Returns
Address

Definition at line 269 of file Invoice.php.

270  {
271  return $this->getOrder()->getShippingAddress();
272  }

◆ getShippingAddressId()

getShippingAddressId ( )

Returns shipping_address_id

Returns
int|null

Implements InvoiceInterface.

Definition at line 1102 of file Invoice.php.

◆ getShippingAmount()

getShippingAmount ( )

Returns shipping_amount

Returns
float|null

Implements InvoiceInterface.

Definition at line 1112 of file Invoice.php.

◆ getShippingDiscountTaxCompensationAmount()

getShippingDiscountTaxCompensationAmount ( )

Returns shipping_discount_tax_compensation_amount

Returns
float|null

Implements InvoiceInterface.

Definition at line 1122 of file Invoice.php.

◆ getShippingInclTax()

getShippingInclTax ( )

Returns shipping_incl_tax

Returns
float|null

Implements InvoiceInterface.

Definition at line 1132 of file Invoice.php.

◆ getShippingTaxAmount()

getShippingTaxAmount ( )

Returns shipping_tax_amount

Returns
float|null

Implements InvoiceInterface.

Definition at line 1142 of file Invoice.php.

◆ getState()

getState ( )

Returns state

Returns
int|null

Implements InvoiceInterface.

Definition at line 1152 of file Invoice.php.

◆ getStateName()

getStateName (   $stateId = null)

Retrieve invoice state name by state identifier

Parameters
int | null$stateId
Returns
\Magento\Framework\Phrase

Definition at line 575 of file Invoice.php.

576  {
577  if ($stateId === null) {
578  $stateId = $this->getState();
579  }
580 
581  if (null === static::$_states) {
582  static::getStates();
583  }
584  if (isset(static::$_states[$stateId])) {
585  return static::$_states[$stateId];
586  }
587  return __('Unknown State');
588  }
__()
Definition: __.php:13

◆ getStates()

static getStates ( )
static

Retrieve invoice states array

Returns
array

Definition at line 557 of file Invoice.php.

558  {
559  if (null === static::$_states) {
560  static::$_states = [
561  self::STATE_OPEN => __('Pending'),
562  self::STATE_PAID => __('Paid'),
563  self::STATE_CANCELED => __('Canceled'),
564  ];
565  }
566  return static::$_states;
567  }
__()
Definition: __.php:13

◆ getStore()

getStore ( )

Retrieve store model instance

Returns
\Magento\Store\Model\Store

Definition at line 213 of file Invoice.php.

214  {
215  return $this->getOrder()->getStore();
216  }

◆ getStoreCurrencyCode()

getStoreCurrencyCode ( )

Returns store_currency_code

Returns
string|null

Implements InvoiceInterface.

Definition at line 1162 of file Invoice.php.

◆ getStoreId()

getStoreId ( )

Returns store_id

Returns
int|null

Implements InvoiceInterface.

Definition at line 1172 of file Invoice.php.

◆ getStoreToBaseRate()

getStoreToBaseRate ( )

Returns store_to_base_rate

Returns
float|null

Implements InvoiceInterface.

Definition at line 1182 of file Invoice.php.

◆ getStoreToOrderRate()

getStoreToOrderRate ( )

Returns store_to_order_rate

Returns
float|null

Implements InvoiceInterface.

Definition at line 1192 of file Invoice.php.

◆ getSubtotal()

getSubtotal ( )

Returns subtotal

Returns
float|null

Implements InvoiceInterface.

Definition at line 1202 of file Invoice.php.

◆ getSubtotalInclTax()

getSubtotalInclTax ( )

Returns subtotal_incl_tax

Returns
float|null

Implements InvoiceInterface.

Definition at line 1212 of file Invoice.php.

◆ getTaxAmount()

getTaxAmount ( )

Returns tax_amount

Returns
float|null

Implements InvoiceInterface.

Definition at line 1222 of file Invoice.php.

◆ getTotalQty()

getTotalQty ( )

Returns total_qty

Returns
float

Implements InvoiceInterface.

Definition at line 1232 of file Invoice.php.

◆ getTransactionId()

getTransactionId ( )

Returns transaction_id

Returns
string|null

Implements InvoiceInterface.

Definition at line 1242 of file Invoice.php.

◆ getUpdatedAt()

getUpdatedAt ( )

Returns updated_at

Returns
string|null

Implements InvoiceInterface.

Definition at line 1263 of file Invoice.php.

◆ isCanceled()

isCanceled ( )

Check invoice cancel state

Returns
bool

Definition at line 279 of file Invoice.php.

280  {
281  return $this->getState() == self::STATE_CANCELED;
282  }

◆ isLast()

isLast ( )

Checking if the invoice is last

Returns
bool

Definition at line 674 of file Invoice.php.

675  {
676  foreach ($this->getAllItems() as $item) {
677  if (!$item->isLast()) {
678  return false;
679  }
680  }
681  return true;
682  }

◆ loadByIncrementId()

loadByIncrementId (   $incrementId)

Load invoice by increment id

Parameters
string$incrementId
Returns
$this

Definition at line 187 of file Invoice.php.

188  {
189  $ids = $this->getCollection()->addAttributeToFilter('increment_id', $incrementId)->getAllIds();
190 
191  if (!empty($ids)) {
192  reset($ids);
193  $this->load(current($ids));
194  }
195  return $this;
196  }

◆ pay()

pay ( )

Pay invoice

Returns
$this

Definition at line 356 of file Invoice.php.

357  {
358  if ($this->_wasPayCalled) {
359  return $this;
360  }
361  $this->_wasPayCalled = true;
362 
363  $this->setState(self::STATE_PAID);
364 
365  $order = $this->getOrder();
366  $order->getPayment()->pay($this);
367  $totalPaid = $this->getGrandTotal();
368  $baseTotalPaid = $this->getBaseGrandTotal();
369  $invoiceList = $order->getInvoiceCollection();
370  // calculate all totals
371  if (count($invoiceList->getItems()) > 1) {
372  $totalPaid += $order->getTotalPaid();
373  $baseTotalPaid += $order->getBaseTotalPaid();
374  }
375  $order->setTotalPaid($totalPaid);
376  $order->setBaseTotalPaid($baseTotalPaid);
377  $this->_eventManager->dispatch('sales_order_invoice_pay', [$this->_eventObject => $this]);
378  return $this;
379  }
$order
Definition: order.php:55

◆ register()

register ( )

Register invoice

Apply to order, order items etc.

Returns
$this
Exceptions

Definition at line 599 of file Invoice.php.

600  {
601  if ($this->getId()) {
602  throw new \Magento\Framework\Exception\LocalizedException(__('We cannot register an existing invoice'));
603  }
604 
605  foreach ($this->getAllItems() as $item) {
606  if ($item->getQty() > 0) {
607  $item->register();
608  } else {
609  $item->isDeleted(true);
610  }
611  }
612 
613  $order = $this->getOrder();
614  $captureCase = $this->getRequestedCaptureCase();
615  if ($this->canCapture()) {
616  if ($captureCase) {
617  if ($captureCase == self::CAPTURE_ONLINE) {
618  $this->capture();
619  } elseif ($captureCase == self::CAPTURE_OFFLINE) {
620  $this->setCanVoidFlag(false);
621  $this->pay();
622  }
623  }
624  } elseif (!$order->getPayment()->getMethodInstance()->isGateway() || $captureCase == self::CAPTURE_OFFLINE) {
625  if (!$order->getPayment()->getIsTransactionPending()) {
626  $this->setCanVoidFlag(false);
627  $this->pay();
628  }
629  }
630 
631  $order->setTotalInvoiced($order->getTotalInvoiced() + $this->getGrandTotal());
632  $order->setBaseTotalInvoiced($order->getBaseTotalInvoiced() + $this->getBaseGrandTotal());
633 
634  $order->setSubtotalInvoiced($order->getSubtotalInvoiced() + $this->getSubtotal());
635  $order->setBaseSubtotalInvoiced($order->getBaseSubtotalInvoiced() + $this->getBaseSubtotal());
636 
637  $order->setTaxInvoiced($order->getTaxInvoiced() + $this->getTaxAmount());
638  $order->setBaseTaxInvoiced($order->getBaseTaxInvoiced() + $this->getBaseTaxAmount());
639 
640  $order->setDiscountTaxCompensationInvoiced(
641  $order->getDiscountTaxCompensationInvoiced() + $this->getDiscountTaxCompensationAmount()
642  );
643  $order->setBaseDiscountTaxCompensationInvoiced(
644  $order->getBaseDiscountTaxCompensationInvoiced() + $this->getBaseDiscountTaxCompensationAmount()
645  );
646 
647  $order->setShippingTaxInvoiced($order->getShippingTaxInvoiced() + $this->getShippingTaxAmount());
648  $order->setBaseShippingTaxInvoiced($order->getBaseShippingTaxInvoiced() + $this->getBaseShippingTaxAmount());
649 
650  $order->setShippingInvoiced($order->getShippingInvoiced() + $this->getShippingAmount());
651  $order->setBaseShippingInvoiced($order->getBaseShippingInvoiced() + $this->getBaseShippingAmount());
652 
653  $order->setDiscountInvoiced($order->getDiscountInvoiced() + $this->getDiscountAmount());
654  $order->setBaseDiscountInvoiced($order->getBaseDiscountInvoiced() + $this->getBaseDiscountAmount());
655  $order->setBaseTotalInvoicedCost($order->getBaseTotalInvoicedCost() + $this->getBaseCost());
656 
657  $state = $this->getState();
658  if (null === $state) {
659  $this->setState(self::STATE_OPEN);
660  }
661 
662  $this->_eventManager->dispatch(
663  'sales_order_invoice_register',
664  [$this->_eventObject => $this, 'order' => $order]
665  );
666  return $this;
667  }
elseif(isset( $params[ 'redirect_parent']))
Definition: iframe.phtml:17
$order
Definition: order.php:55
__()
Definition: __.php:13

◆ reset()

reset ( )

Reset invoice object

Returns
$this

Definition at line 743 of file Invoice.php.

744  {
745  $this->unsetData();
746  $this->_origData = null;
747  $this->setItems(null);
748  $this->setComments(null);
749  $this->_order = null;
750  $this->_saveBeforeDestruct = false;
751  $this->_wasPayCalled = false;
752  return $this;
753  }

◆ roundPrice()

roundPrice (   $price,
  $type = 'regular',
  $negative = false 
)

Round price considering delta

Parameters
float$price
string$type
bool$negativeIndicates if we perform addition (true) or subtraction (false) of rounded value
Returns
float

Definition at line 480 of file Invoice.php.

481  {
482  if ($price) {
483  if (!isset($this->_rounders[$type])) {
484  $this->_rounders[$type] = $this->_calculatorFactory->create(['scope' => $this->getStore()]);
485  }
486  $price = $this->_rounders[$type]->deltaRound($price, $negative);
487  }
488  return $price;
489  }
$price
$type
Definition: item.phtml:13

◆ setBaseCurrencyCode()

setBaseCurrencyCode (   $code)

{Sets the base currency code for the invoice.

Parameters
string$code
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1519 of file Invoice.php.

◆ setBaseDiscountAmount()

setBaseDiscountAmount (   $amount)

{Sets the base discount amount for the invoice.

Parameters
float$amount
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1343 of file Invoice.php.

◆ setBaseDiscountTaxCompensationAmount()

setBaseDiscountTaxCompensationAmount (   $amount)

{Sets the base discount tax compensation amount for the invoice.

Parameters
float$amount
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1551 of file Invoice.php.

◆ setBaseGrandTotal()

setBaseGrandTotal (   $amount)

{Sets the base grand total for the invoice.

Parameters
float$amount
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1295 of file Invoice.php.

◆ setBaseShippingAmount()

setBaseShippingAmount (   $amount)

{Sets the base shipping amount for the invoice.

Parameters
float$amount
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1399 of file Invoice.php.

◆ setBaseShippingDiscountTaxCompensationAmnt()

setBaseShippingDiscountTaxCompensationAmnt (   $amnt)

{Sets the base shipping discount tax compensation amount for the invoice.

Parameters
float$amnt
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1567 of file Invoice.php.

◆ setBaseShippingInclTax()

setBaseShippingInclTax (   $amount)

{Sets the base shipping including tax for the invoice.

Parameters
float$amount
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1583 of file Invoice.php.

◆ setBaseShippingTaxAmount()

setBaseShippingTaxAmount (   $amount)

{Sets the base shipping tax amount for the invoice.

Parameters
float$amount
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1335 of file Invoice.php.

◆ setBaseSubtotal()

setBaseSubtotal (   $amount)

{Sets the base subtotal for the invoice.

Parameters
float$amount
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1431 of file Invoice.php.

◆ setBaseSubtotalInclTax()

setBaseSubtotalInclTax (   $amount)

{Sets the base subtotal including tax for the invoice.

Parameters
float$amount
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1383 of file Invoice.php.

◆ setBaseTaxAmount()

setBaseTaxAmount (   $amount)

{Sets the base tax amount for the invoice.

Parameters
float$amount
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1319 of file Invoice.php.

◆ setBaseToGlobalRate()

setBaseToGlobalRate (   $rate)

{Sets the base-to-global rate for the invoice.

Parameters
float$rate
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1415 of file Invoice.php.

◆ setBaseToOrderRate()

setBaseToOrderRate (   $rate)

{Sets the base-to-order rate for the invoice.

Parameters
float$rate
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1351 of file Invoice.php.

◆ setBaseTotalRefunded()

setBaseTotalRefunded (   $amount)

{Sets the base total refunded for the invoice.

Parameters
float$amount
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1591 of file Invoice.php.

◆ setBillingAddressId()

setBillingAddressId (   $id)

{Sets the billing address ID for the invoice.

Parameters
int$id
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1447 of file Invoice.php.

◆ setCanVoidFlag()

setCanVoidFlag (   $canVoidFlag)

{Sets the can void flag value for the invoice.

Parameters
int$canVoidFlag
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1479 of file Invoice.php.

◆ setComments()

setComments (   $comments)

{Sets the comments, if any, for the invoice.

Parameters
}

Implements InvoiceInterface.

Definition at line 1271 of file Invoice.php.

◆ setCreatedAt()

setCreatedAt (   $createdAt)

{Sets the created-at timestamp for the invoice.

Parameters
string$createdAttimestamp
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1012 of file Invoice.php.

◆ setDiscountAmount()

setDiscountAmount (   $amount)

{Sets the discount amount for the invoice.

Parameters
float$amount
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1439 of file Invoice.php.

◆ setDiscountDescription()

setDiscountDescription (   $description)

{Sets the discount description for the invoice.

Parameters
string$description
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1599 of file Invoice.php.

◆ setDiscountTaxCompensationAmount()

setDiscountTaxCompensationAmount (   $amount)

{Sets the discount tax compensation amount for the invoice.

Parameters
float$amount
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1543 of file Invoice.php.

◆ setEmailSent()

setEmailSent (   $emailSent)

{Sets the email-sent flag value for the invoice.

Parameters
int$emailSent
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1471 of file Invoice.php.

◆ setExtensionAttributes()

setExtensionAttributes ( \Magento\Sales\Api\Data\InvoiceExtensionInterface  $extensionAttributes)

{}

Parameters
\Magento\Sales\Api\Data\InvoiceExtensionInterface$extensionAttributes
Returns
$this

Definition at line 1620 of file Invoice.php.

1621  {
1623  }
_setExtensionAttributes(\Magento\Framework\Api\ExtensionAttributesInterface $extensionAttributes)

◆ setGlobalCurrencyCode()

setGlobalCurrencyCode (   $code)

{Sets the global currency code for the invoice.

Parameters
string$code
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1527 of file Invoice.php.

◆ setGrandTotal()

setGrandTotal (   $amount)

{Sets the grand total for the invoice.

Parameters
float$amount
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1359 of file Invoice.php.

◆ setIncrementId()

setIncrementId (   $id)

{Sets the increment ID for the invoice.

Parameters
string$id
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1535 of file Invoice.php.

◆ setIsUsedForRefund()

setIsUsedForRefund (   $isUsedForRefund)

{Sets the is-used-for-refund flag value for the invoice.

Parameters
int$isUsedForRefund
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1455 of file Invoice.php.

◆ setItems()

setItems (   $items)

{Sets the items in the invoice.

Parameters
}

Implements InvoiceInterface.

Definition at line 844 of file Invoice.php.

◆ setOrder()

setOrder ( \Magento\Sales\Model\Order  $order)

Declare order for invoice

Parameters
\Magento\Sales\Model\Order$order
Returns
$this

Definition at line 224 of file Invoice.php.

225  {
226  $this->_order = $order;
227  $this->setOrderId($order->getId())->setStoreId($order->getStoreId());
228  return $this;
229  }
$order
Definition: order.php:55

◆ setOrderCurrencyCode()

setOrderCurrencyCode (   $code)

{Sets the order currency code for the invoice.

Parameters
string$code
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1511 of file Invoice.php.

◆ setOrderId()

setOrderId (   $id)

{Sets the order ID for the invoice.

Parameters
int$id
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1463 of file Invoice.php.

◆ setShippingAddressId()

setShippingAddressId (   $id)

{Sets the shipping address ID for the invoice.

Parameters
int$id
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1495 of file Invoice.php.

◆ setShippingAmount()

setShippingAmount (   $amount)

{Sets the shipping amount for the invoice.

Parameters
float$amount
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1367 of file Invoice.php.

◆ setShippingDiscountTaxCompensationAmount()

setShippingDiscountTaxCompensationAmount (   $amount)

{Sets the shipping discount tax compensation amount for the invoice.

Parameters
float$amount
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1559 of file Invoice.php.

◆ setShippingInclTax()

setShippingInclTax (   $amount)

{Sets the shipping including tax for the invoice.

Parameters
float$amount
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1575 of file Invoice.php.

◆ setShippingTaxAmount()

setShippingTaxAmount (   $amount)

{Sets the shipping tax amount for the invoice.

Parameters
float$amount
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1303 of file Invoice.php.

◆ setState()

setState (   $state)

{Sets the state for the invoice.

Parameters
int$state
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1487 of file Invoice.php.

◆ setStoreCurrencyCode()

setStoreCurrencyCode (   $code)

{Sets the store currency code for the invoice.

Parameters
string$code
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1503 of file Invoice.php.

◆ setStoreId()

setStoreId (   $id)

{Sets the store ID for the invoice.

Parameters
int$id
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1287 of file Invoice.php.

◆ setStoreToBaseRate()

setStoreToBaseRate (   $rate)

{Sets the store-to-base rate for the invoice.

Parameters
float$rate
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1391 of file Invoice.php.

◆ setStoreToOrderRate()

setStoreToOrderRate (   $rate)

{Sets the store-to-order rate for the invoice.

Parameters
float$rate
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1327 of file Invoice.php.

◆ setSubtotal()

setSubtotal (   $amount)

{Sets the subtotal for the invoice.

Parameters
float$amount
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1423 of file Invoice.php.

◆ setSubtotalInclTax()

setSubtotalInclTax (   $amount)

{Sets the subtotal including tax for the invoice.

Parameters
float$amount
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1375 of file Invoice.php.

◆ setTaxAmount()

setTaxAmount (   $amount)

{Sets the tax amount for the invoice.

Parameters
float$amount
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1311 of file Invoice.php.

◆ setTotalQty()

setTotalQty (   $qty)

{Sets the total quantity for the invoice.

Parameters
float$qty
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1407 of file Invoice.php.

◆ setTransactionId()

setTransactionId (   $transactionId)

Sets transaction_id

Parameters
string$transactionId
Returns
$this

Implements InvoiceInterface.

Definition at line 1253 of file Invoice.php.

◆ setUpdatedAt()

setUpdatedAt (   $timestamp)

{Sets the updated-at timestamp for the invoice.

Parameters
string$timestamp
Returns
$this
}

Implements InvoiceInterface.

Definition at line 1279 of file Invoice.php.

◆ void()

void ( )

Void invoice

Returns
$this

Definition at line 396 of file Invoice.php.

397  {
398  $this->getOrder()->getPayment()->void($this);
399  $this->cancel();
400  return $this;
401  }

◆ wasPayCalled()

wasPayCalled ( )

Whether pay() method was called (whether order and payment totals were updated)

Returns
bool

Definition at line 386 of file Invoice.php.

387  {
388  return $this->_wasPayCalled;
389  }

Field Documentation

◆ $_calculatorFactory

$_calculatorFactory
protected

Definition at line 106 of file Invoice.php.

◆ $_commentCollectionFactory

$_commentCollectionFactory
protected

Definition at line 121 of file Invoice.php.

◆ $_eventObject

$_eventObject = 'invoice'
protected

Definition at line 84 of file Invoice.php.

◆ $_eventPrefix

$_eventPrefix = 'sales_order_invoice'
protected

Definition at line 79 of file Invoice.php.

◆ $_invoiceCommentFactory

$_invoiceCommentFactory
protected

Definition at line 116 of file Invoice.php.

◆ $_invoiceConfig

$_invoiceConfig
protected

Definition at line 96 of file Invoice.php.

◆ $_invoiceItemCollectionFactory

$_invoiceItemCollectionFactory
protected

Definition at line 111 of file Invoice.php.

◆ $_order

$_order
protected

Definition at line 62 of file Invoice.php.

◆ $_orderFactory

$_orderFactory
protected

Definition at line 101 of file Invoice.php.

◆ $_rounders

$_rounders = []
protected

Definition at line 69 of file Invoice.php.

◆ $_saveBeforeDestruct

$_saveBeforeDestruct = false
protected

Definition at line 74 of file Invoice.php.

◆ $_states

$_states
staticprotected

Definition at line 57 of file Invoice.php.

◆ $_wasPayCalled

$_wasPayCalled = false
protected

Definition at line 91 of file Invoice.php.

◆ $entityType

$entityType = 'invoice'
protected

Definition at line 52 of file Invoice.php.

◆ CAPTURE_OFFLINE

const CAPTURE_OFFLINE = 'offline'

Definition at line 39 of file Invoice.php.

◆ CAPTURE_ONLINE

const CAPTURE_ONLINE = 'online'

#-

Definition at line 37 of file Invoice.php.

◆ NOT_CAPTURE

const NOT_CAPTURE = 'not_capture'

Definition at line 41 of file Invoice.php.

◆ REPORT_DATE_TYPE_INVOICE_CREATED

const REPORT_DATE_TYPE_INVOICE_CREATED = 'invoice_created'

Definition at line 45 of file Invoice.php.

◆ REPORT_DATE_TYPE_ORDER_CREATED

const REPORT_DATE_TYPE_ORDER_CREATED = 'order_created'

Definition at line 43 of file Invoice.php.

◆ STATE_CANCELED

const STATE_CANCELED = 3

Definition at line 34 of file Invoice.php.

◆ STATE_OPEN

const STATE_OPEN = 1

#+ Invoice states

Definition at line 30 of file Invoice.php.

◆ STATE_PAID

const STATE_PAID = 2

Definition at line 32 of file Invoice.php.


The documentation for this class was generated from the following file: