Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DefaultCreditmemo.php
Go to the documentation of this file.
1 <?php
7 
11 class DefaultCreditmemo extends \Magento\Sales\Model\Order\Pdf\Items\AbstractItems
12 {
18  protected $string;
19 
31  public function __construct(
32  \Magento\Framework\Model\Context $context,
33  \Magento\Framework\Registry $registry,
34  \Magento\Tax\Helper\Data $taxData,
35  \Magento\Framework\Filesystem $filesystem,
36  \Magento\Framework\Filter\FilterManager $filterManager,
37  \Magento\Framework\Stdlib\StringUtils $string,
38  \Magento\Framework\Model\ResourceModel\AbstractResource $resource = null,
39  \Magento\Framework\Data\Collection\AbstractDb $resourceCollection = null,
40  array $data = []
41  ) {
42  $this->string = $string;
43  parent::__construct(
44  $context,
45  $registry,
46  $taxData,
49  $resource,
50  $resourceCollection,
51  $data
52  );
53  }
54 
60  public function draw()
61  {
62  $order = $this->getOrder();
63  $item = $this->getItem();
64  $pdf = $this->getPdf();
65  $page = $this->getPage();
66  $lines = [];
67 
68  // draw Product name
69  $lines[0] = [['text' => $this->string->split($item->getName(), 35, true, true), 'feed' => 35]];
70 
71  // draw SKU
72  $lines[0][] = [
73  'text' => $this->string->split($this->getSku($item), 17),
74  'feed' => 255,
75  'align' => 'right',
76  ];
77 
78  // draw Total (ex)
79  $lines[0][] = [
80  'text' => $order->formatPriceTxt($item->getRowTotal()),
81  'feed' => 330,
82  'font' => 'bold',
83  'align' => 'right',
84  ];
85 
86  // draw Discount
87  $lines[0][] = [
88  'text' => $order->formatPriceTxt(-$item->getDiscountAmount()),
89  'feed' => 380,
90  'font' => 'bold',
91  'align' => 'right',
92  ];
93 
94  // draw QTY
95  $lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 445, 'font' => 'bold', 'align' => 'right'];
96 
97  // draw Tax
98  $lines[0][] = [
99  'text' => $order->formatPriceTxt($item->getTaxAmount()),
100  'feed' => 495,
101  'font' => 'bold',
102  'align' => 'right',
103  ];
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 
117  // draw options
118  $options = $this->getItemOptions();
119  if ($options) {
120  foreach ($options as $option) {
121  // draw options label
122  $lines[][] = [
123  'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
124  'font' => 'italic',
125  'feed' => 35,
126  ];
127 
128  // draw options value
129  $printValue = isset(
130  $option['print_value']
131  ) ? $option['print_value'] : $this->filterManager->stripTags(
132  $option['value']
133  );
134  $lines[][] = ['text' => $this->string->split($printValue, 30, true, true), 'feed' => 40];
135  }
136  }
137 
138  $lineBlock = ['lines' => $lines, 'height' => 20];
139 
140  $page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true]);
141  $this->setPage($page);
142  }
143 }
$order
Definition: order.php:55
$resource
Definition: bulk.php:12
$page
Definition: pages.php:8
$filesystem
__construct(\Magento\Framework\Model\Context $context, \Magento\Framework\Registry $registry, \Magento\Tax\Helper\Data $taxData, \Magento\Framework\Filesystem $filesystem, \Magento\Framework\Filter\FilterManager $filterManager, \Magento\Framework\Stdlib\StringUtils $string, \Magento\Framework\Model\ResourceModel\AbstractResource $resource=null, \Magento\Framework\Data\Collection\AbstractDb $resourceCollection=null, array $data=[])