Creditmemo.php 37 KB

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