Invoice.php 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Model\Order;
  7. use Magento\Framework\Api\AttributeValueFactory;
  8. use Magento\Sales\Api\Data\InvoiceInterface;
  9. use Magento\Sales\Model\AbstractModel;
  10. use Magento\Sales\Model\EntityInterface;
  11. /**
  12. * Invoice model.
  13. *
  14. * @api
  15. * @method \Magento\Sales\Model\Order\Invoice setSendEmail(bool $value)
  16. * @method \Magento\Sales\Model\Order\Invoice setCustomerNote(string $value)
  17. * @method string getCustomerNote()
  18. * @method \Magento\Sales\Model\Order\Invoice setCustomerNoteNotify(bool $value)
  19. * @method bool getCustomerNoteNotify()
  20. * @SuppressWarnings(PHPMD.ExcessivePublicCount)
  21. * @SuppressWarnings(PHPMD.ExcessiveClassComplexity)
  22. * @SuppressWarnings(PHPMD.CouplingBetweenObjects)
  23. * @since 100.0.2
  24. */
  25. class Invoice extends AbstractModel implements EntityInterface, InvoiceInterface
  26. {
  27. /**#@+
  28. * Invoice states
  29. */
  30. const STATE_OPEN = 1;
  31. const STATE_PAID = 2;
  32. const STATE_CANCELED = 3;
  33. /**#@-*/
  34. const CAPTURE_ONLINE = 'online';
  35. const CAPTURE_OFFLINE = 'offline';
  36. const NOT_CAPTURE = 'not_capture';
  37. const REPORT_DATE_TYPE_ORDER_CREATED = 'order_created';
  38. const REPORT_DATE_TYPE_INVOICE_CREATED = 'invoice_created';
  39. /**
  40. * Identifier for history item
  41. *
  42. * @var string
  43. */
  44. protected $entityType = 'invoice';
  45. /**
  46. * @var array
  47. */
  48. protected static $_states;
  49. /**
  50. * @var \Magento\Sales\Model\Order
  51. */
  52. protected $_order;
  53. /**
  54. * Calculator instances for delta rounding of prices
  55. *
  56. * @var array
  57. */
  58. protected $_rounders = [];
  59. /**
  60. * @var bool
  61. */
  62. protected $_saveBeforeDestruct = false;
  63. /**
  64. * @var string
  65. */
  66. protected $_eventPrefix = 'sales_order_invoice';
  67. /**
  68. * @var string
  69. */
  70. protected $_eventObject = 'invoice';
  71. /**
  72. * Whether the pay() was called
  73. *
  74. * @var bool
  75. */
  76. protected $_wasPayCalled = false;
  77. /**
  78. * @var \Magento\Sales\Model\Order\Invoice\Config
  79. */
  80. protected $_invoiceConfig;
  81. /**
  82. * @var \Magento\Sales\Model\OrderFactory
  83. */
  84. protected $_orderFactory;
  85. /**
  86. * @var \Magento\Framework\Math\CalculatorFactory
  87. */
  88. protected $_calculatorFactory;
  89. /**
  90. * @var \Magento\Sales\Model\ResourceModel\Order\Invoice\Item\CollectionFactory
  91. */
  92. protected $_invoiceItemCollectionFactory;
  93. /**
  94. * @var \Magento\Sales\Model\Order\Invoice\CommentFactory
  95. */
  96. protected $_invoiceCommentFactory;
  97. /**
  98. * @var \Magento\Sales\Model\ResourceModel\Order\Invoice\Comment\CollectionFactory
  99. */
  100. protected $_commentCollectionFactory;
  101. /**
  102. * @param \Magento\Framework\Model\Context $context
  103. * @param \Magento\Framework\Registry $registry
  104. * @param \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory
  105. * @param AttributeValueFactory $customAttributeFactory
  106. * @param Invoice\Config $invoiceConfig
  107. * @param \Magento\Sales\Model\OrderFactory $orderFactory
  108. * @param \Magento\Framework\Math\CalculatorFactory $calculatorFactory
  109. * @param \Magento\Sales\Model\ResourceModel\Order\Invoice\Item\CollectionFactory $invoiceItemCollectionFactory
  110. * @param Invoice\CommentFactory $invoiceCommentFactory
  111. * @param \Magento\Sales\Model\ResourceModel\Order\Invoice\Comment\CollectionFactory $commentCollectionFactory
  112. * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
  113. * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
  114. * @param array $data
  115. * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  116. */
  117. public function __construct(
  118. \Magento\Framework\Model\Context $context,
  119. \Magento\Framework\Registry $registry,
  120. \Magento\Framework\Api\ExtensionAttributesFactory $extensionFactory,
  121. AttributeValueFactory $customAttributeFactory,
  122. \Magento\Sales\Model\Order\Invoice\Config $invoiceConfig,
  123. \Magento\Sales\Model\OrderFactory $orderFactory,
  124. \Magento\Framework\Math\CalculatorFactory $calculatorFactory,
  125. \Magento\Sales\Model\ResourceModel\Order\Invoice\Item\CollectionFactory $invoiceItemCollectionFactory,
  126. \Magento\Sales\Model\Order\Invoice\CommentFactory $invoiceCommentFactory,
  127. \Magento\Sales\Model\ResourceModel\Order\Invoice\Comment\CollectionFactory $commentCollectionFactory,
  128. \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
  129. \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
  130. array $data = []
  131. ) {
  132. $this->_invoiceConfig = $invoiceConfig;
  133. $this->_orderFactory = $orderFactory;
  134. $this->_calculatorFactory = $calculatorFactory;
  135. $this->_invoiceItemCollectionFactory = $invoiceItemCollectionFactory;
  136. $this->_invoiceCommentFactory = $invoiceCommentFactory;
  137. $this->_commentCollectionFactory = $commentCollectionFactory;
  138. parent::__construct(
  139. $context,
  140. $registry,
  141. $extensionFactory,
  142. $customAttributeFactory,
  143. $resource,
  144. $resourceCollection,
  145. $data
  146. );
  147. }
  148. /**
  149. * Initialize invoice resource model
  150. *
  151. * @return void
  152. */
  153. protected function _construct()
  154. {
  155. $this->_init(\Magento\Sales\Model\ResourceModel\Order\Invoice::class);
  156. }
  157. /**
  158. * Load invoice by increment id
  159. *
  160. * @param string $incrementId
  161. * @return $this
  162. */
  163. public function loadByIncrementId($incrementId)
  164. {
  165. $ids = $this->getCollection()->addAttributeToFilter('increment_id', $incrementId)->getAllIds();
  166. if (!empty($ids)) {
  167. reset($ids);
  168. $this->load(current($ids));
  169. }
  170. return $this;
  171. }
  172. /**
  173. * Retrieve invoice configuration model
  174. *
  175. * @return \Magento\Sales\Model\Order\Invoice\Config
  176. */
  177. public function getConfig()
  178. {
  179. return $this->_invoiceConfig;
  180. }
  181. /**
  182. * Retrieve store model instance
  183. *
  184. * @return \Magento\Store\Model\Store
  185. */
  186. public function getStore()
  187. {
  188. return $this->getOrder()->getStore();
  189. }
  190. /**
  191. * Declare order for invoice
  192. *
  193. * @param \Magento\Sales\Model\Order $order
  194. * @return $this
  195. */
  196. public function setOrder(\Magento\Sales\Model\Order $order)
  197. {
  198. $this->_order = $order;
  199. $this->setOrderId($order->getId())->setStoreId($order->getStoreId());
  200. return $this;
  201. }
  202. /**
  203. * Retrieve the order the invoice for created for
  204. *
  205. * @return \Magento\Sales\Model\Order
  206. */
  207. public function getOrder()
  208. {
  209. if (!$this->_order instanceof \Magento\Sales\Model\Order) {
  210. $this->_order = $this->_orderFactory->create()->load($this->getOrderId());
  211. }
  212. return $this->_order->setHistoryEntityName($this->entityType);
  213. }
  214. /**
  215. * Return order history item identifier
  216. *
  217. * @return string
  218. */
  219. public function getEntityType()
  220. {
  221. return $this->entityType;
  222. }
  223. /**
  224. * Retrieve billing address
  225. *
  226. * @return Address
  227. */
  228. public function getBillingAddress()
  229. {
  230. return $this->getOrder()->getBillingAddress();
  231. }
  232. /**
  233. * Retrieve shipping address
  234. *
  235. * @return Address
  236. */
  237. public function getShippingAddress()
  238. {
  239. return $this->getOrder()->getShippingAddress();
  240. }
  241. /**
  242. * Check invoice cancel state
  243. *
  244. * @return bool
  245. */
  246. public function isCanceled()
  247. {
  248. return $this->getState() == self::STATE_CANCELED;
  249. }
  250. /**
  251. * Check invoice capture action availability
  252. *
  253. * @return bool
  254. */
  255. public function canCapture()
  256. {
  257. return $this->getState() != self::STATE_CANCELED &&
  258. $this->getState() != self::STATE_PAID &&
  259. $this->getOrder()->getPayment()->canCapture();
  260. }
  261. /**
  262. * Check invoice void action availability
  263. *
  264. * @return bool
  265. */
  266. public function canVoid()
  267. {
  268. if ($this->getState() == self::STATE_PAID) {
  269. if ($this->getCanVoidFlag() === null) {
  270. return (bool)$this->getOrder()->getPayment()->canVoid();
  271. }
  272. }
  273. return (bool)$this->getCanVoidFlag();
  274. }
  275. /**
  276. * Check invoice cancel action availability
  277. *
  278. * @return bool
  279. */
  280. public function canCancel()
  281. {
  282. return $this->getState() == self::STATE_OPEN;
  283. }
  284. /**
  285. * Check invoice refund action availability
  286. *
  287. * @return bool
  288. */
  289. public function canRefund()
  290. {
  291. if ($this->getState() != self::STATE_PAID) {
  292. return false;
  293. }
  294. if (abs($this->getBaseGrandTotal() - $this->getBaseTotalRefunded()) < .0001) {
  295. return false;
  296. }
  297. return true;
  298. }
  299. /**
  300. * Capture invoice
  301. *
  302. * @return $this
  303. */
  304. public function capture()
  305. {
  306. $this->getOrder()->getPayment()->capture($this);
  307. if ($this->getIsPaid()) {
  308. $this->pay();
  309. }
  310. return $this;
  311. }
  312. /**
  313. * Pay invoice
  314. *
  315. * @return $this
  316. */
  317. public function pay()
  318. {
  319. if ($this->_wasPayCalled) {
  320. return $this;
  321. }
  322. $this->_wasPayCalled = true;
  323. $this->setState(self::STATE_PAID);
  324. $order = $this->getOrder();
  325. $order->getPayment()->pay($this);
  326. $totalPaid = $this->getGrandTotal();
  327. $baseTotalPaid = $this->getBaseGrandTotal();
  328. $invoiceList = $order->getInvoiceCollection();
  329. // calculate all totals
  330. if (count($invoiceList->getItems()) > 1) {
  331. $totalPaid += $order->getTotalPaid();
  332. $baseTotalPaid += $order->getBaseTotalPaid();
  333. }
  334. $order->setTotalPaid($totalPaid);
  335. $order->setBaseTotalPaid($baseTotalPaid);
  336. $this->_eventManager->dispatch('sales_order_invoice_pay', [$this->_eventObject => $this]);
  337. return $this;
  338. }
  339. /**
  340. * Whether pay() method was called (whether order and payment totals were updated)
  341. *
  342. * @return bool
  343. */
  344. public function wasPayCalled()
  345. {
  346. return $this->_wasPayCalled;
  347. }
  348. /**
  349. * Void invoice
  350. *
  351. * @return $this
  352. */
  353. public function void()
  354. {
  355. $this->getOrder()->getPayment()->void($this);
  356. $this->cancel();
  357. return $this;
  358. }
  359. /**
  360. * Cancel invoice action
  361. *
  362. * @return $this
  363. */
  364. public function cancel()
  365. {
  366. if (!$this->canCancel()) {
  367. return $this;
  368. }
  369. $order = $this->getOrder();
  370. $order->getPayment()->cancelInvoice($this);
  371. foreach ($this->getAllItems() as $item) {
  372. $item->cancel();
  373. }
  374. /**
  375. * Unregister order totals only for invoices in state PAID
  376. */
  377. $order->setTotalInvoiced($order->getTotalInvoiced() - $this->getGrandTotal());
  378. $order->setBaseTotalInvoiced($order->getBaseTotalInvoiced() - $this->getBaseGrandTotal());
  379. $order->setSubtotalInvoiced($order->getSubtotalInvoiced() - $this->getSubtotal());
  380. $order->setBaseSubtotalInvoiced($order->getBaseSubtotalInvoiced() - $this->getBaseSubtotal());
  381. $order->setTaxInvoiced($order->getTaxInvoiced() - $this->getTaxAmount());
  382. $order->setBaseTaxInvoiced($order->getBaseTaxInvoiced() - $this->getBaseTaxAmount());
  383. $order->setDiscountTaxCompensationInvoiced(
  384. $order->getDiscountTaxCompensationInvoiced() - $this->getDiscountTaxCompensationAmount()
  385. );
  386. $order->setBaseDiscountTaxCompensationInvoiced(
  387. $order->getBaseDiscountTaxCompensationInvoiced() - $this->getBaseDiscountTaxCompensationAmount()
  388. );
  389. $order->setShippingTaxInvoiced($order->getShippingTaxInvoiced() - $this->getShippingTaxAmount());
  390. $order->setBaseShippingTaxInvoiced($order->getBaseShippingTaxInvoiced() - $this->getBaseShippingTaxAmount());
  391. $order->setShippingInvoiced($order->getShippingInvoiced() - $this->getShippingAmount());
  392. $order->setBaseShippingInvoiced($order->getBaseShippingInvoiced() - $this->getBaseShippingAmount());
  393. $order->setDiscountInvoiced($order->getDiscountInvoiced() - $this->getDiscountAmount());
  394. $order->setBaseDiscountInvoiced($order->getBaseDiscountInvoiced() - $this->getBaseDiscountAmount());
  395. $order->setBaseTotalInvoicedCost($order->getBaseTotalInvoicedCost() - $this->getBaseCost());
  396. $this->setState(self::STATE_CANCELED);
  397. $order->setState(\Magento\Sales\Model\Order::STATE_PROCESSING)
  398. ->setStatus($order->getConfig()->getStateDefaultStatus(\Magento\Sales\Model\Order::STATE_PROCESSING));
  399. $this->_eventManager->dispatch('sales_order_invoice_cancel', [$this->_eventObject => $this]);
  400. return $this;
  401. }
  402. /**
  403. * Invoice totals collecting
  404. *
  405. * @return $this
  406. */
  407. public function collectTotals()
  408. {
  409. foreach ($this->getConfig()->getTotalModels() as $model) {
  410. $model->collect($this);
  411. }
  412. return $this;
  413. }
  414. /**
  415. * Round price considering delta
  416. *
  417. * @param float $price
  418. * @param string $type
  419. * @param bool $negative Indicates if we perform addition (true) or subtraction (false) of rounded value
  420. * @return float
  421. */
  422. public function roundPrice($price, $type = 'regular', $negative = false)
  423. {
  424. if ($price) {
  425. if (!isset($this->_rounders[$type])) {
  426. $this->_rounders[$type] = $this->_calculatorFactory->create(['scope' => $this->getStore()]);
  427. }
  428. $price = $this->_rounders[$type]->deltaRound($price, $negative);
  429. }
  430. return $price;
  431. }
  432. /**
  433. * Get invoice items collection
  434. *
  435. * @return \Magento\Sales\Model\ResourceModel\Order\Invoice\Item\Collection
  436. */
  437. public function getItemsCollection()
  438. {
  439. if (!$this->hasData(InvoiceInterface::ITEMS)) {
  440. $this->setItems($this->_invoiceItemCollectionFactory->create()->setInvoiceFilter($this->getId()));
  441. if ($this->getId()) {
  442. foreach ($this->getItems() as $item) {
  443. $item->setInvoice($this);
  444. }
  445. }
  446. }
  447. return $this->getItems();
  448. }
  449. /**
  450. * Get all Invoice Items.
  451. *
  452. * @return array
  453. */
  454. public function getAllItems()
  455. {
  456. $items = [];
  457. foreach ($this->getItemsCollection() as $item) {
  458. if (!$item->isDeleted()) {
  459. $items[] = $item;
  460. }
  461. }
  462. return $items;
  463. }
  464. /**
  465. * Get Invoice Item by id.
  466. *
  467. * @param int|string $itemId
  468. * @return bool|\Magento\Sales\Model\Order\Invoice\Item
  469. */
  470. public function getItemById($itemId)
  471. {
  472. foreach ($this->getItemsCollection() as $item) {
  473. if ($item->getId() == $itemId) {
  474. return $item;
  475. }
  476. }
  477. return false;
  478. }
  479. /**
  480. * Add Item to Invoice.
  481. *
  482. * @param \Magento\Sales\Model\Order\Invoice\Item $item
  483. * @return $this
  484. * @throws \Exception
  485. */
  486. public function addItem(\Magento\Sales\Model\Order\Invoice\Item $item)
  487. {
  488. $item->setInvoice($this)->setParentId($this->getId())->setStoreId($this->getStoreId());
  489. if (!$item->getId()) {
  490. $this->getItemsCollection()->addItem($item);
  491. }
  492. return $this;
  493. }
  494. /**
  495. * Retrieve invoice states array
  496. *
  497. * @return array
  498. */
  499. public static function getStates()
  500. {
  501. if (null === static::$_states) {
  502. static::$_states = [
  503. self::STATE_OPEN => __('Pending'),
  504. self::STATE_PAID => __('Paid'),
  505. self::STATE_CANCELED => __('Canceled'),
  506. ];
  507. }
  508. return static::$_states;
  509. }
  510. /**
  511. * Retrieve invoice state name by state identifier
  512. *
  513. * @param int|null $stateId
  514. * @return \Magento\Framework\Phrase
  515. */
  516. public function getStateName($stateId = null)
  517. {
  518. if ($stateId === null) {
  519. $stateId = $this->getState();
  520. }
  521. if (null === static::$_states) {
  522. static::getStates();
  523. }
  524. if (isset(static::$_states[$stateId])) {
  525. return static::$_states[$stateId];
  526. }
  527. return __('Unknown State');
  528. }
  529. /**
  530. * Register invoice
  531. *
  532. * Apply to order, order items etc.
  533. *
  534. * @return $this
  535. * @throws \Magento\Framework\Exception\LocalizedException
  536. * @SuppressWarnings(PHPMD.CyclomaticComplexity)
  537. */
  538. public function register()
  539. {
  540. if ($this->getId()) {
  541. throw new \Magento\Framework\Exception\LocalizedException(__('We cannot register an existing invoice'));
  542. }
  543. foreach ($this->getAllItems() as $item) {
  544. if ($item->getQty() > 0) {
  545. $item->register();
  546. } else {
  547. $item->isDeleted(true);
  548. }
  549. }
  550. $order = $this->getOrder();
  551. $captureCase = $this->getRequestedCaptureCase();
  552. if ($this->canCapture()) {
  553. if ($captureCase) {
  554. if ($captureCase == self::CAPTURE_ONLINE) {
  555. $this->capture();
  556. } elseif ($captureCase == self::CAPTURE_OFFLINE) {
  557. $this->setCanVoidFlag(false);
  558. $this->pay();
  559. }
  560. }
  561. } elseif (!$order->getPayment()->getMethodInstance()->isGateway() || $captureCase == self::CAPTURE_OFFLINE) {
  562. if (!$order->getPayment()->getIsTransactionPending()) {
  563. $this->setCanVoidFlag(false);
  564. $this->pay();
  565. }
  566. }
  567. $order->setTotalInvoiced($order->getTotalInvoiced() + $this->getGrandTotal());
  568. $order->setBaseTotalInvoiced($order->getBaseTotalInvoiced() + $this->getBaseGrandTotal());
  569. $order->setSubtotalInvoiced($order->getSubtotalInvoiced() + $this->getSubtotal());
  570. $order->setBaseSubtotalInvoiced($order->getBaseSubtotalInvoiced() + $this->getBaseSubtotal());
  571. $order->setTaxInvoiced($order->getTaxInvoiced() + $this->getTaxAmount());
  572. $order->setBaseTaxInvoiced($order->getBaseTaxInvoiced() + $this->getBaseTaxAmount());
  573. $order->setDiscountTaxCompensationInvoiced(
  574. $order->getDiscountTaxCompensationInvoiced() + $this->getDiscountTaxCompensationAmount()
  575. );
  576. $order->setBaseDiscountTaxCompensationInvoiced(
  577. $order->getBaseDiscountTaxCompensationInvoiced() + $this->getBaseDiscountTaxCompensationAmount()
  578. );
  579. $order->setShippingTaxInvoiced($order->getShippingTaxInvoiced() + $this->getShippingTaxAmount());
  580. $order->setBaseShippingTaxInvoiced($order->getBaseShippingTaxInvoiced() + $this->getBaseShippingTaxAmount());
  581. $order->setShippingInvoiced($order->getShippingInvoiced() + $this->getShippingAmount());
  582. $order->setBaseShippingInvoiced($order->getBaseShippingInvoiced() + $this->getBaseShippingAmount());
  583. $order->setDiscountInvoiced($order->getDiscountInvoiced() + $this->getDiscountAmount());
  584. $order->setBaseDiscountInvoiced($order->getBaseDiscountInvoiced() + $this->getBaseDiscountAmount());
  585. $order->setBaseTotalInvoicedCost($order->getBaseTotalInvoicedCost() + $this->getBaseCost());
  586. $state = $this->getState();
  587. if (null === $state) {
  588. $this->setState(self::STATE_OPEN);
  589. }
  590. $this->_eventManager->dispatch(
  591. 'sales_order_invoice_register',
  592. [$this->_eventObject => $this, 'order' => $order]
  593. );
  594. return $this;
  595. }
  596. /**
  597. * Checking if the invoice is last
  598. *
  599. * @return bool
  600. */
  601. public function isLast()
  602. {
  603. foreach ($this->getAllItems() as $item) {
  604. if (!$item->isLast()) {
  605. return false;
  606. }
  607. }
  608. return true;
  609. }
  610. /**
  611. * Add comment with possibility to send it to customer via email and show it in customer account.
  612. *
  613. * @param string $comment
  614. * @param bool $notify
  615. * @param bool $visibleOnFront
  616. * @return $this
  617. * @throws \Exception
  618. */
  619. public function addComment($comment, $notify = false, $visibleOnFront = false)
  620. {
  621. if (!$comment instanceof \Magento\Sales\Model\Order\Invoice\Comment) {
  622. $comment = $this->_invoiceCommentFactory->create()->setComment(
  623. $comment
  624. )->setIsCustomerNotified(
  625. $notify
  626. )->setIsVisibleOnFront(
  627. $visibleOnFront
  628. );
  629. }
  630. $comment->setInvoice($this)->setStoreId($this->getStoreId())->setParentId($this->getId());
  631. if (!$comment->getId()) {
  632. $this->getCommentsCollection()->addItem($comment);
  633. }
  634. $this->_hasDataChanges = true;
  635. return $this;
  636. }
  637. /**
  638. * Get Invoice comments.
  639. *
  640. * @param bool $reload
  641. * @return \Magento\Sales\Model\ResourceModel\Order\Invoice\Comment\Collection
  642. */
  643. public function getCommentsCollection($reload = false)
  644. {
  645. if (!$this->hasData(InvoiceInterface::COMMENTS) || $reload) {
  646. $comments = $this->_commentCollectionFactory->create()->setInvoiceFilter($this->getId())
  647. ->setCreatedAtOrder();
  648. $this->setComments($comments);
  649. /**
  650. * When invoice created with adding comment, comments collection
  651. * must be loaded before we added this comment.
  652. */
  653. $this->getComments()->load();
  654. if ($this->getId()) {
  655. foreach ($this->getComments() as $comment) {
  656. $comment->setInvoice($this);
  657. }
  658. }
  659. }
  660. return $this->getComments();
  661. }
  662. /**
  663. * Reset invoice object
  664. *
  665. * @return $this
  666. */
  667. public function reset()
  668. {
  669. $this->unsetData();
  670. $this->_origData = null;
  671. $this->setItems(null);
  672. $this->setComments(null);
  673. $this->_order = null;
  674. $this->_saveBeforeDestruct = false;
  675. $this->_wasPayCalled = false;
  676. return $this;
  677. }
  678. /**
  679. * Before object save manipulations
  680. *
  681. * @return $this
  682. */
  683. protected function _beforeSave()
  684. {
  685. return parent::_beforeSave();
  686. }
  687. /**
  688. * After object save manipulation
  689. *
  690. * @return $this
  691. */
  692. protected function _afterSave()
  693. {
  694. return parent::_afterSave();
  695. }
  696. /**
  697. * Returns invoice items
  698. *
  699. * @return \Magento\Sales\Api\Data\InvoiceItemInterface[]
  700. */
  701. public function getItems()
  702. {
  703. if ($this->getData(InvoiceInterface::ITEMS) === null && $this->getId()) {
  704. $collection = $this->_invoiceItemCollectionFactory->create()->setInvoiceFilter($this->getId());
  705. foreach ($collection as $item) {
  706. $item->setInvoice($this);
  707. }
  708. $this->setData(InvoiceInterface::ITEMS, $collection->getItems());
  709. }
  710. return $this->getData(InvoiceInterface::ITEMS);
  711. }
  712. /**
  713. * Return invoice comments
  714. *
  715. * @return \Magento\Sales\Api\Data\InvoiceCommentInterface[]|null
  716. */
  717. public function getComments()
  718. {
  719. if ($this->getData(InvoiceInterface::COMMENTS) === null && $this->getId()) {
  720. $collection = $this->_commentCollectionFactory->create()->setInvoiceFilter($this->getId());
  721. foreach ($collection as $comment) {
  722. $comment->setInvoice($this);
  723. }
  724. $this->setData(InvoiceInterface::COMMENTS, $collection->getItems());
  725. }
  726. return $this->getData(InvoiceInterface::COMMENTS);
  727. }
  728. //@codeCoverageIgnoreStart
  729. /**
  730. * Returns increment id
  731. *
  732. * @return string
  733. */
  734. public function getIncrementId()
  735. {
  736. return $this->getData('increment_id');
  737. }
  738. /**
  739. * Returns base_total_refunded
  740. *
  741. * @return float|null
  742. */
  743. public function getBaseTotalRefunded()
  744. {
  745. return $this->getData(InvoiceInterface::BASE_TOTAL_REFUNDED);
  746. }
  747. /**
  748. * Returns discount_description
  749. *
  750. * @return string|null
  751. */
  752. public function getDiscountDescription()
  753. {
  754. return $this->getData(InvoiceInterface::DISCOUNT_DESCRIPTION);
  755. }
  756. /**
  757. * @inheritdoc
  758. */
  759. public function setItems($items)
  760. {
  761. return $this->setData(InvoiceInterface::ITEMS, $items);
  762. }
  763. /**
  764. * Returns base_currency_code
  765. *
  766. * @return string|null
  767. */
  768. public function getBaseCurrencyCode()
  769. {
  770. return $this->getData(InvoiceInterface::BASE_CURRENCY_CODE);
  771. }
  772. /**
  773. * Returns base_discount_amount
  774. *
  775. * @return float|null
  776. */
  777. public function getBaseDiscountAmount()
  778. {
  779. return $this->getData(InvoiceInterface::BASE_DISCOUNT_AMOUNT);
  780. }
  781. /**
  782. * Returns base_grand_total
  783. *
  784. * @return float|null
  785. */
  786. public function getBaseGrandTotal()
  787. {
  788. return $this->getData(InvoiceInterface::BASE_GRAND_TOTAL);
  789. }
  790. /**
  791. * Returns base_discount_tax_compensation_amount
  792. *
  793. * @return float|null
  794. */
  795. public function getBaseDiscountTaxCompensationAmount()
  796. {
  797. return $this->getData(InvoiceInterface::BASE_DISCOUNT_TAX_COMPENSATION_AMOUNT);
  798. }
  799. /**
  800. * Returns base_shipping_amount
  801. *
  802. * @return float|null
  803. */
  804. public function getBaseShippingAmount()
  805. {
  806. return $this->getData(InvoiceInterface::BASE_SHIPPING_AMOUNT);
  807. }
  808. /**
  809. * Returns base_shipping_discount_tax_compensation_amnt
  810. *
  811. * @return float|null
  812. */
  813. public function getBaseShippingDiscountTaxCompensationAmnt()
  814. {
  815. return $this->getData(InvoiceInterface::BASE_SHIPPING_DISCOUNT_TAX_COMPENSATION_AMNT);
  816. }
  817. /**
  818. * Returns base_shipping_incl_tax
  819. *
  820. * @return float|null
  821. */
  822. public function getBaseShippingInclTax()
  823. {
  824. return $this->getData(InvoiceInterface::BASE_SHIPPING_INCL_TAX);
  825. }
  826. /**
  827. * Returns base_shipping_tax_amount
  828. *
  829. * @return float|null
  830. */
  831. public function getBaseShippingTaxAmount()
  832. {
  833. return $this->getData(InvoiceInterface::BASE_SHIPPING_TAX_AMOUNT);
  834. }
  835. /**
  836. * Returns base_subtotal
  837. *
  838. * @return float|null
  839. */
  840. public function getBaseSubtotal()
  841. {
  842. return $this->getData(InvoiceInterface::BASE_SUBTOTAL);
  843. }
  844. /**
  845. * Returns base_subtotal_incl_tax
  846. *
  847. * @return float|null
  848. */
  849. public function getBaseSubtotalInclTax()
  850. {
  851. return $this->getData(InvoiceInterface::BASE_SUBTOTAL_INCL_TAX);
  852. }
  853. /**
  854. * Returns base_tax_amount
  855. *
  856. * @return float|null
  857. */
  858. public function getBaseTaxAmount()
  859. {
  860. return $this->getData(InvoiceInterface::BASE_TAX_AMOUNT);
  861. }
  862. /**
  863. * Returns base_to_global_rate
  864. *
  865. * @return float|null
  866. */
  867. public function getBaseToGlobalRate()
  868. {
  869. return $this->getData(InvoiceInterface::BASE_TO_GLOBAL_RATE);
  870. }
  871. /**
  872. * Returns base_to_order_rate
  873. *
  874. * @return float|null
  875. */
  876. public function getBaseToOrderRate()
  877. {
  878. return $this->getData(InvoiceInterface::BASE_TO_ORDER_RATE);
  879. }
  880. /**
  881. * Returns billing_address_id
  882. *
  883. * @return int|null
  884. */
  885. public function getBillingAddressId()
  886. {
  887. return $this->getData(InvoiceInterface::BILLING_ADDRESS_ID);
  888. }
  889. /**
  890. * Returns can_void_flag
  891. *
  892. * @return int|null
  893. */
  894. public function getCanVoidFlag()
  895. {
  896. return $this->getData(InvoiceInterface::CAN_VOID_FLAG);
  897. }
  898. /**
  899. * Returns created_at
  900. *
  901. * @return string|null
  902. */
  903. public function getCreatedAt()
  904. {
  905. return $this->getData(InvoiceInterface::CREATED_AT);
  906. }
  907. /**
  908. * @inheritdoc
  909. */
  910. public function setCreatedAt($createdAt)
  911. {
  912. return $this->setData(InvoiceInterface::CREATED_AT, $createdAt);
  913. }
  914. /**
  915. * Returns discount_amount
  916. *
  917. * @return float|null
  918. */
  919. public function getDiscountAmount()
  920. {
  921. return $this->getData(InvoiceInterface::DISCOUNT_AMOUNT);
  922. }
  923. /**
  924. * Returns email_sent
  925. *
  926. * @return int|null
  927. */
  928. public function getEmailSent()
  929. {
  930. return $this->getData(InvoiceInterface::EMAIL_SENT);
  931. }
  932. /**
  933. * Returns global_currency_code
  934. *
  935. * @return string|null
  936. */
  937. public function getGlobalCurrencyCode()
  938. {
  939. return $this->getData(InvoiceInterface::GLOBAL_CURRENCY_CODE);
  940. }
  941. /**
  942. * Returns grand_total
  943. *
  944. * @return float|null
  945. */
  946. public function getGrandTotal()
  947. {
  948. return $this->getData(InvoiceInterface::GRAND_TOTAL);
  949. }
  950. /**
  951. * Returns discount_tax_compensation_amount
  952. *
  953. * @return float|null
  954. */
  955. public function getDiscountTaxCompensationAmount()
  956. {
  957. return $this->getData(InvoiceInterface::DISCOUNT_TAX_COMPENSATION_AMOUNT);
  958. }
  959. /**
  960. * Returns is_used_for_refund
  961. *
  962. * @return int|null
  963. */
  964. public function getIsUsedForRefund()
  965. {
  966. return $this->getData(InvoiceInterface::IS_USED_FOR_REFUND);
  967. }
  968. /**
  969. * Returns order_currency_code
  970. *
  971. * @return string|null
  972. */
  973. public function getOrderCurrencyCode()
  974. {
  975. return $this->getData(InvoiceInterface::ORDER_CURRENCY_CODE);
  976. }
  977. /**
  978. * Returns order_id
  979. *
  980. * @return int
  981. */
  982. public function getOrderId()
  983. {
  984. return $this->getData(InvoiceInterface::ORDER_ID);
  985. }
  986. /**
  987. * Returns shipping_address_id
  988. *
  989. * @return int|null
  990. */
  991. public function getShippingAddressId()
  992. {
  993. return $this->getData(InvoiceInterface::SHIPPING_ADDRESS_ID);
  994. }
  995. /**
  996. * Returns shipping_amount
  997. *
  998. * @return float|null
  999. */
  1000. public function getShippingAmount()
  1001. {
  1002. return $this->getData(InvoiceInterface::SHIPPING_AMOUNT);
  1003. }
  1004. /**
  1005. * Returns shipping_discount_tax_compensation_amount
  1006. *
  1007. * @return float|null
  1008. */
  1009. public function getShippingDiscountTaxCompensationAmount()
  1010. {
  1011. return $this->getData(InvoiceInterface::SHIPPING_DISCOUNT_TAX_COMPENSATION_AMOUNT);
  1012. }
  1013. /**
  1014. * Returns shipping_incl_tax
  1015. *
  1016. * @return float|null
  1017. */
  1018. public function getShippingInclTax()
  1019. {
  1020. return $this->getData(InvoiceInterface::SHIPPING_INCL_TAX);
  1021. }
  1022. /**
  1023. * Returns shipping_tax_amount
  1024. *
  1025. * @return float|null
  1026. */
  1027. public function getShippingTaxAmount()
  1028. {
  1029. return $this->getData(InvoiceInterface::SHIPPING_TAX_AMOUNT);
  1030. }
  1031. /**
  1032. * Returns state
  1033. *
  1034. * @return int|null
  1035. */
  1036. public function getState()
  1037. {
  1038. return $this->getData(InvoiceInterface::STATE);
  1039. }
  1040. /**
  1041. * Returns store_currency_code
  1042. *
  1043. * @return string|null
  1044. */
  1045. public function getStoreCurrencyCode()
  1046. {
  1047. return $this->getData(InvoiceInterface::STORE_CURRENCY_CODE);
  1048. }
  1049. /**
  1050. * Returns store_id
  1051. *
  1052. * @return int|null
  1053. */
  1054. public function getStoreId()
  1055. {
  1056. return $this->getData(InvoiceInterface::STORE_ID);
  1057. }
  1058. /**
  1059. * Returns store_to_base_rate
  1060. *
  1061. * @return float|null
  1062. */
  1063. public function getStoreToBaseRate()
  1064. {
  1065. return $this->getData(InvoiceInterface::STORE_TO_BASE_RATE);
  1066. }
  1067. /**
  1068. * Returns store_to_order_rate
  1069. *
  1070. * @return float|null
  1071. */
  1072. public function getStoreToOrderRate()
  1073. {
  1074. return $this->getData(InvoiceInterface::STORE_TO_ORDER_RATE);
  1075. }
  1076. /**
  1077. * Returns subtotal
  1078. *
  1079. * @return float|null
  1080. */
  1081. public function getSubtotal()
  1082. {
  1083. return $this->getData(InvoiceInterface::SUBTOTAL);
  1084. }
  1085. /**
  1086. * Returns subtotal_incl_tax
  1087. *
  1088. * @return float|null
  1089. */
  1090. public function getSubtotalInclTax()
  1091. {
  1092. return $this->getData(InvoiceInterface::SUBTOTAL_INCL_TAX);
  1093. }
  1094. /**
  1095. * Returns tax_amount
  1096. *
  1097. * @return float|null
  1098. */
  1099. public function getTaxAmount()
  1100. {
  1101. return $this->getData(InvoiceInterface::TAX_AMOUNT);
  1102. }
  1103. /**
  1104. * Returns total_qty
  1105. *
  1106. * @return float
  1107. */
  1108. public function getTotalQty()
  1109. {
  1110. return $this->getData(InvoiceInterface::TOTAL_QTY);
  1111. }
  1112. /**
  1113. * Returns transaction_id
  1114. *
  1115. * @return string|null
  1116. */
  1117. public function getTransactionId()
  1118. {
  1119. return $this->getData(InvoiceInterface::TRANSACTION_ID);
  1120. }
  1121. /**
  1122. * Sets transaction_id
  1123. *
  1124. * @param string $transactionId
  1125. * @return $this
  1126. */
  1127. public function setTransactionId($transactionId)
  1128. {
  1129. return $this->setData(InvoiceInterface::TRANSACTION_ID, $transactionId);
  1130. }
  1131. /**
  1132. * Returns updated_at
  1133. *
  1134. * @return string|null
  1135. */
  1136. public function getUpdatedAt()
  1137. {
  1138. return $this->getData(InvoiceInterface::UPDATED_AT);
  1139. }
  1140. /**
  1141. * @inheritdoc
  1142. */
  1143. public function setComments($comments)
  1144. {
  1145. return $this->setData(InvoiceInterface::COMMENTS, $comments);
  1146. }
  1147. /**
  1148. * @inheritdoc
  1149. */
  1150. public function setUpdatedAt($timestamp)
  1151. {
  1152. return $this->setData(InvoiceInterface::UPDATED_AT, $timestamp);
  1153. }
  1154. /**
  1155. * @inheritdoc
  1156. */
  1157. public function setStoreId($id)
  1158. {
  1159. return $this->setData(InvoiceInterface::STORE_ID, $id);
  1160. }
  1161. /**
  1162. * @inheritdoc
  1163. */
  1164. public function setBaseGrandTotal($amount)
  1165. {
  1166. return $this->setData(InvoiceInterface::BASE_GRAND_TOTAL, $amount);
  1167. }
  1168. /**
  1169. * @inheritdoc
  1170. */
  1171. public function setShippingTaxAmount($amount)
  1172. {
  1173. return $this->setData(InvoiceInterface::SHIPPING_TAX_AMOUNT, $amount);
  1174. }
  1175. /**
  1176. * @inheritdoc
  1177. */
  1178. public function setTaxAmount($amount)
  1179. {
  1180. return $this->setData(InvoiceInterface::TAX_AMOUNT, $amount);
  1181. }
  1182. /**
  1183. * @inheritdoc
  1184. */
  1185. public function setBaseTaxAmount($amount)
  1186. {
  1187. return $this->setData(InvoiceInterface::BASE_TAX_AMOUNT, $amount);
  1188. }
  1189. /**
  1190. * @inheritdoc
  1191. */
  1192. public function setStoreToOrderRate($rate)
  1193. {
  1194. return $this->setData(InvoiceInterface::STORE_TO_ORDER_RATE, $rate);
  1195. }
  1196. /**
  1197. * @inheritdoc
  1198. */
  1199. public function setBaseShippingTaxAmount($amount)
  1200. {
  1201. return $this->setData(InvoiceInterface::BASE_SHIPPING_TAX_AMOUNT, $amount);
  1202. }
  1203. /**
  1204. * @inheritdoc
  1205. */
  1206. public function setBaseDiscountAmount($amount)
  1207. {
  1208. return $this->setData(InvoiceInterface::BASE_DISCOUNT_AMOUNT, $amount);
  1209. }
  1210. /**
  1211. * @inheritdoc
  1212. */
  1213. public function setBaseToOrderRate($rate)
  1214. {
  1215. return $this->setData(InvoiceInterface::BASE_TO_ORDER_RATE, $rate);
  1216. }
  1217. /**
  1218. * @inheritdoc
  1219. */
  1220. public function setGrandTotal($amount)
  1221. {
  1222. return $this->setData(InvoiceInterface::GRAND_TOTAL, $amount);
  1223. }
  1224. /**
  1225. * @inheritdoc
  1226. */
  1227. public function setShippingAmount($amount)
  1228. {
  1229. return $this->setData(InvoiceInterface::SHIPPING_AMOUNT, $amount);
  1230. }
  1231. /**
  1232. * @inheritdoc
  1233. */
  1234. public function setSubtotalInclTax($amount)
  1235. {
  1236. return $this->setData(InvoiceInterface::SUBTOTAL_INCL_TAX, $amount);
  1237. }
  1238. /**
  1239. * @inheritdoc
  1240. */
  1241. public function setBaseSubtotalInclTax($amount)
  1242. {
  1243. return $this->setData(InvoiceInterface::BASE_SUBTOTAL_INCL_TAX, $amount);
  1244. }
  1245. /**
  1246. * @inheritdoc
  1247. */
  1248. public function setStoreToBaseRate($rate)
  1249. {
  1250. return $this->setData(InvoiceInterface::STORE_TO_BASE_RATE, $rate);
  1251. }
  1252. /**
  1253. * @inheritdoc
  1254. */
  1255. public function setBaseShippingAmount($amount)
  1256. {
  1257. return $this->setData(InvoiceInterface::BASE_SHIPPING_AMOUNT, $amount);
  1258. }
  1259. /**
  1260. * @inheritdoc
  1261. */
  1262. public function setTotalQty($qty)
  1263. {
  1264. return $this->setData(InvoiceInterface::TOTAL_QTY, $qty);
  1265. }
  1266. /**
  1267. * @inheritdoc
  1268. */
  1269. public function setBaseToGlobalRate($rate)
  1270. {
  1271. return $this->setData(InvoiceInterface::BASE_TO_GLOBAL_RATE, $rate);
  1272. }
  1273. /**
  1274. * @inheritdoc
  1275. */
  1276. public function setSubtotal($amount)
  1277. {
  1278. return $this->setData(InvoiceInterface::SUBTOTAL, $amount);
  1279. }
  1280. /**
  1281. * @inheritdoc
  1282. */
  1283. public function setBaseSubtotal($amount)
  1284. {
  1285. return $this->setData(InvoiceInterface::BASE_SUBTOTAL, $amount);
  1286. }
  1287. /**
  1288. * @inheritdoc
  1289. */
  1290. public function setDiscountAmount($amount)
  1291. {
  1292. return $this->setData(InvoiceInterface::DISCOUNT_AMOUNT, $amount);
  1293. }
  1294. /**
  1295. * @inheritdoc
  1296. */
  1297. public function setBillingAddressId($id)
  1298. {
  1299. return $this->setData(InvoiceInterface::BILLING_ADDRESS_ID, $id);
  1300. }
  1301. /**
  1302. * @inheritdoc
  1303. */
  1304. public function setIsUsedForRefund($isUsedForRefund)
  1305. {
  1306. return $this->setData(InvoiceInterface::IS_USED_FOR_REFUND, $isUsedForRefund);
  1307. }
  1308. /**
  1309. * @inheritdoc
  1310. */
  1311. public function setOrderId($id)
  1312. {
  1313. return $this->setData(InvoiceInterface::ORDER_ID, $id);
  1314. }
  1315. /**
  1316. * @inheritdoc
  1317. */
  1318. public function setEmailSent($emailSent)
  1319. {
  1320. return $this->setData(InvoiceInterface::EMAIL_SENT, $emailSent);
  1321. }
  1322. /**
  1323. * @inheritdoc
  1324. */
  1325. public function setCanVoidFlag($canVoidFlag)
  1326. {
  1327. return $this->setData(InvoiceInterface::CAN_VOID_FLAG, $canVoidFlag);
  1328. }
  1329. /**
  1330. * @inheritdoc
  1331. */
  1332. public function setState($state)
  1333. {
  1334. return $this->setData(InvoiceInterface::STATE, $state);
  1335. }
  1336. /**
  1337. * @inheritdoc
  1338. */
  1339. public function setShippingAddressId($id)
  1340. {
  1341. return $this->setData(InvoiceInterface::SHIPPING_ADDRESS_ID, $id);
  1342. }
  1343. /**
  1344. * @inheritdoc
  1345. */
  1346. public function setStoreCurrencyCode($code)
  1347. {
  1348. return $this->setData(InvoiceInterface::STORE_CURRENCY_CODE, $code);
  1349. }
  1350. /**
  1351. * @inheritdoc
  1352. */
  1353. public function setOrderCurrencyCode($code)
  1354. {
  1355. return $this->setData(InvoiceInterface::ORDER_CURRENCY_CODE, $code);
  1356. }
  1357. /**
  1358. * @inheritdoc
  1359. */
  1360. public function setBaseCurrencyCode($code)
  1361. {
  1362. return $this->setData(InvoiceInterface::BASE_CURRENCY_CODE, $code);
  1363. }
  1364. /**
  1365. * @inheritdoc
  1366. */
  1367. public function setGlobalCurrencyCode($code)
  1368. {
  1369. return $this->setData(InvoiceInterface::GLOBAL_CURRENCY_CODE, $code);
  1370. }
  1371. /**
  1372. * @inheritdoc
  1373. */
  1374. public function setIncrementId($id)
  1375. {
  1376. return $this->setData(InvoiceInterface::INCREMENT_ID, $id);
  1377. }
  1378. /**
  1379. * @inheritdoc
  1380. */
  1381. public function setDiscountTaxCompensationAmount($amount)
  1382. {
  1383. return $this->setData(InvoiceInterface::DISCOUNT_TAX_COMPENSATION_AMOUNT, $amount);
  1384. }
  1385. /**
  1386. * @inheritdoc
  1387. */
  1388. public function setBaseDiscountTaxCompensationAmount($amount)
  1389. {
  1390. return $this->setData(InvoiceInterface::BASE_DISCOUNT_TAX_COMPENSATION_AMOUNT, $amount);
  1391. }
  1392. /**
  1393. * @inheritdoc
  1394. */
  1395. public function setShippingDiscountTaxCompensationAmount($amount)
  1396. {
  1397. return $this->setData(InvoiceInterface::SHIPPING_DISCOUNT_TAX_COMPENSATION_AMOUNT, $amount);
  1398. }
  1399. /**
  1400. * @inheritdoc
  1401. */
  1402. public function setBaseShippingDiscountTaxCompensationAmnt($amnt)
  1403. {
  1404. return $this->setData(InvoiceInterface::BASE_SHIPPING_DISCOUNT_TAX_COMPENSATION_AMNT, $amnt);
  1405. }
  1406. /**
  1407. * @inheritdoc
  1408. */
  1409. public function setShippingInclTax($amount)
  1410. {
  1411. return $this->setData(InvoiceInterface::SHIPPING_INCL_TAX, $amount);
  1412. }
  1413. /**
  1414. * @inheritdoc
  1415. */
  1416. public function setBaseShippingInclTax($amount)
  1417. {
  1418. return $this->setData(InvoiceInterface::BASE_SHIPPING_INCL_TAX, $amount);
  1419. }
  1420. /**
  1421. * @inheritdoc
  1422. */
  1423. public function setBaseTotalRefunded($amount)
  1424. {
  1425. return $this->setData(InvoiceInterface::BASE_TOTAL_REFUNDED, $amount);
  1426. }
  1427. /**
  1428. * @inheritdoc
  1429. */
  1430. public function setDiscountDescription($description)
  1431. {
  1432. return $this->setData(InvoiceInterface::DISCOUNT_DESCRIPTION, $description);
  1433. }
  1434. /**
  1435. * @inheritdoc
  1436. *
  1437. * @return \Magento\Sales\Api\Data\InvoiceExtensionInterface|null
  1438. */
  1439. public function getExtensionAttributes()
  1440. {
  1441. return $this->_getExtensionAttributes();
  1442. }
  1443. /**
  1444. * @inheritdoc
  1445. *
  1446. * @param \Magento\Sales\Api\Data\InvoiceExtensionInterface $extensionAttributes
  1447. * @return $this
  1448. */
  1449. public function setExtensionAttributes(\Magento\Sales\Api\Data\InvoiceExtensionInterface $extensionAttributes)
  1450. {
  1451. return $this->_setExtensionAttributes($extensionAttributes);
  1452. }
  1453. //@codeCoverageIgnoreEnd
  1454. }