Creditmemo.php 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Downloadable\Model\Sales\Order\Pdf\Items;
  7. /**
  8. * Order Creditmemo Downloadable Pdf Items renderer
  9. * @api
  10. * @since 100.0.2
  11. */
  12. class Creditmemo extends \Magento\Downloadable\Model\Sales\Order\Pdf\Items\AbstractItems
  13. {
  14. /**
  15. * @var \Magento\Framework\Stdlib\StringUtils
  16. */
  17. protected $string;
  18. /**
  19. * @param \Magento\Framework\Model\Context $context
  20. * @param \Magento\Framework\Registry $registry
  21. * @param \Magento\Tax\Helper\Data $taxData
  22. * @param \Magento\Framework\Filesystem $filesystem
  23. * @param \Magento\Framework\Filter\FilterManager $filterManager
  24. * @param \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig
  25. * @param \Magento\Downloadable\Model\Link\PurchasedFactory $purchasedFactory
  26. * @param \Magento\Downloadable\Model\ResourceModel\Link\Purchased\Item\CollectionFactory $itemsFactory
  27. * @param \Magento\Framework\Stdlib\StringUtils $string
  28. * @param \Magento\Framework\Model\ResourceModel\AbstractResource $resource
  29. * @param \Magento\Framework\Data\Collection\AbstractDb $resourceCollection
  30. * @param array $data
  31. * @SuppressWarnings(PHPMD.ExcessiveParameterList)
  32. */
  33. public function __construct(
  34. \Magento\Framework\Model\Context $context,
  35. \Magento\Framework\Registry $registry,
  36. \Magento\Tax\Helper\Data $taxData,
  37. \Magento\Framework\Filesystem $filesystem,
  38. \Magento\Framework\Filter\FilterManager $filterManager,
  39. \Magento\Framework\App\Config\ScopeConfigInterface $scopeConfig,
  40. \Magento\Downloadable\Model\Link\PurchasedFactory $purchasedFactory,
  41. \Magento\Downloadable\Model\ResourceModel\Link\Purchased\Item\CollectionFactory $itemsFactory,
  42. \Magento\Framework\Stdlib\StringUtils $string,
  43. \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
  44. \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
  45. array $data = []
  46. ) {
  47. $this->string = $string;
  48. parent::__construct(
  49. $context,
  50. $registry,
  51. $taxData,
  52. $filesystem,
  53. $filterManager,
  54. $scopeConfig,
  55. $purchasedFactory,
  56. $itemsFactory,
  57. $resource,
  58. $resourceCollection,
  59. $data
  60. );
  61. }
  62. /**
  63. * Draw item line
  64. *
  65. * @return void
  66. */
  67. public function draw()
  68. {
  69. $order = $this->getOrder();
  70. $item = $this->getItem();
  71. $pdf = $this->getPdf();
  72. $page = $this->getPage();
  73. $lines = [];
  74. // draw Product name
  75. $lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];
  76. // draw SKU
  77. $lines[0][] = [
  78. 'text' => $this->string->split($this->getSku($item), 17),
  79. 'feed' => 255,
  80. 'align' => 'right',
  81. ];
  82. // draw Total (ex)
  83. $lines[0][] = [
  84. 'text' => $order->formatPriceTxt($item->getRowTotal()),
  85. 'feed' => 330,
  86. 'font' => 'bold',
  87. 'align' => 'right',
  88. ];
  89. // draw Discount
  90. $lines[0][] = [
  91. 'text' => $order->formatPriceTxt(-$item->getDiscountAmount()),
  92. 'feed' => 380,
  93. 'font' => 'bold',
  94. 'align' => 'right',
  95. ];
  96. // draw QTY
  97. $lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 445, 'font' => 'bold', 'align' => 'right'];
  98. // draw Tax
  99. $lines[0][] = [
  100. 'text' => $order->formatPriceTxt($item->getTaxAmount()),
  101. 'feed' => 495,
  102. 'font' => 'bold',
  103. 'align' => 'right',
  104. ];
  105. // draw Total (inc)
  106. $subtotal = $item->getRowTotal() +
  107. $item->getTaxAmount() +
  108. $item->getDiscountTaxCompensationAmount() -
  109. $item->getDiscountAmount();
  110. $lines[0][] = [
  111. 'text' => $order->formatPriceTxt($subtotal),
  112. 'feed' => 565,
  113. 'font' => 'bold',
  114. 'align' => 'right',
  115. ];
  116. // draw options
  117. $options = $this->getItemOptions();
  118. if ($options) {
  119. foreach ($options as $option) {
  120. // draw options label
  121. $lines[][] = [
  122. 'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
  123. 'font' => 'italic',
  124. 'feed' => 35,
  125. ];
  126. // draw options value
  127. $printValue = isset(
  128. $option['print_value']
  129. ) ? $option['print_value'] : $this->filterManager->stripTags(
  130. $option['value']
  131. );
  132. $lines[][] = ['text' => $this->string->split($printValue, 30, true, true), 'feed' => 40];
  133. }
  134. }
  135. // downloadable Items
  136. $purchasedItems = $this->getLinks()->getPurchasedItems();
  137. // draw Links title
  138. $lines[][] = [
  139. 'text' => $this->string->split($this->getLinksTitle(), 70, true, true),
  140. 'font' => 'italic',
  141. 'feed' => 35,
  142. ];
  143. // draw Links
  144. foreach ($purchasedItems as $link) {
  145. $lines[][] = ['text' => $this->string->split($link->getLinkTitle(), 50, true, true), 'feed' => 40];
  146. }
  147. $lineBlock = ['lines' => $lines, 'height' => 20];
  148. $page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true]);
  149. $this->setPage($page);
  150. }
  151. }