Invoice.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
  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 Invoice Downloadable Pdf Items renderer
  9. * @api
  10. * @since 100.0.2
  11. */
  12. class Invoice 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. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  67. */
  68. public function draw()
  69. {
  70. $order = $this->getOrder();
  71. $item = $this->getItem();
  72. $pdf = $this->getPdf();
  73. $page = $this->getPage();
  74. $lines = [];
  75. // draw Product name
  76. $lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];
  77. // draw SKU
  78. $lines[0][] = [
  79. 'text' => $this->string->split($this->getSku($item), 17),
  80. 'feed' => 290,
  81. 'align' => 'right',
  82. ];
  83. // draw QTY
  84. $lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 435, 'align' => 'right'];
  85. // draw item Prices
  86. $i = 0;
  87. $prices = $this->getItemPricesForDisplay();
  88. $feedPrice = 395;
  89. $feedSubtotal = $feedPrice + 170;
  90. foreach ($prices as $priceData) {
  91. if (isset($priceData['label'])) {
  92. // draw Price label
  93. $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
  94. // draw Subtotal label
  95. $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
  96. $i++;
  97. }
  98. // draw Price
  99. $lines[$i][] = [
  100. 'text' => $priceData['price'],
  101. 'feed' => $feedPrice,
  102. 'font' => 'bold',
  103. 'align' => 'right',
  104. ];
  105. // draw Subtotal
  106. $lines[$i][] = [
  107. 'text' => $priceData['subtotal'],
  108. 'feed' => $feedSubtotal,
  109. 'font' => 'bold',
  110. 'align' => 'right',
  111. ];
  112. $i++;
  113. }
  114. // draw Tax
  115. $lines[0][] = [
  116. 'text' => $order->formatPriceTxt($item->getTaxAmount()),
  117. 'feed' => 495,
  118. 'font' => 'bold',
  119. 'align' => 'right',
  120. ];
  121. // custom options
  122. $options = $this->getItemOptions();
  123. if ($options) {
  124. foreach ($options as $option) {
  125. // draw options label
  126. $lines[][] = [
  127. 'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
  128. 'font' => 'italic',
  129. 'feed' => 35,
  130. ];
  131. if ($option['value']) {
  132. if (isset($option['print_value'])) {
  133. $printValue = $option['print_value'];
  134. } else {
  135. $printValue = $this->filterManager->stripTags($option['value']);
  136. }
  137. $values = explode(', ', $printValue);
  138. foreach ($values as $value) {
  139. $lines[][] = ['text' => $this->string->split($value, 30, true, true), 'feed' => 40];
  140. }
  141. }
  142. }
  143. }
  144. // downloadable Items
  145. $purchasedItems = $this->getLinks()->getPurchasedItems();
  146. // draw Links title
  147. $lines[][] = [
  148. 'text' => $this->string->split($this->getLinksTitle(), 70, true, true),
  149. 'font' => 'italic',
  150. 'feed' => 35,
  151. ];
  152. // draw Links
  153. foreach ($purchasedItems as $link) {
  154. $lines[][] = ['text' => $this->string->split($link->getLinkTitle(), 50, true, true), 'feed' => 40];
  155. }
  156. $lineBlock = ['lines' => $lines, 'height' => 20];
  157. $page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true]);
  158. $this->setPage($page);
  159. }
  160. }