Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
DefaultInvoice.php
Go to the documentation of this file.
1 <?php
7 
11 class DefaultInvoice 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' => 290,
75  'align' => 'right',
76  ];
77 
78  // draw QTY
79  $lines[0][] = ['text' => $item->getQty() * 1, 'feed' => 435, 'align' => 'right'];
80 
81  // draw item Prices
82  $i = 0;
84  $feedPrice = 395;
85  $feedSubtotal = $feedPrice + 170;
86  foreach ($prices as $priceData) {
87  if (isset($priceData['label'])) {
88  // draw Price label
89  $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedPrice, 'align' => 'right'];
90  // draw Subtotal label
91  $lines[$i][] = ['text' => $priceData['label'], 'feed' => $feedSubtotal, 'align' => 'right'];
92  $i++;
93  }
94  // draw Price
95  $lines[$i][] = [
96  'text' => $priceData['price'],
97  'feed' => $feedPrice,
98  'font' => 'bold',
99  'align' => 'right',
100  ];
101  // draw Subtotal
102  $lines[$i][] = [
103  'text' => $priceData['subtotal'],
104  'feed' => $feedSubtotal,
105  'font' => 'bold',
106  'align' => 'right',
107  ];
108  $i++;
109  }
110 
111  // draw Tax
112  $lines[0][] = [
113  'text' => $order->formatPriceTxt($item->getTaxAmount()),
114  'feed' => 495,
115  'font' => 'bold',
116  'align' => 'right',
117  ];
118 
119  // custom options
120  $options = $this->getItemOptions();
121  if ($options) {
122  foreach ($options as $option) {
123  // draw options label
124  $lines[][] = [
125  'text' => $this->string->split($this->filterManager->stripTags($option['label']), 40, true, true),
126  'font' => 'italic',
127  'feed' => 35,
128  ];
129 
130  // Checking whether option value is not null
131  if ($option['value'] !== null) {
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 
145  $lineBlock = ['lines' => $lines, 'height' => 20];
146 
147  $page = $pdf->drawLineBlocks($page, [$lineBlock], ['table_header' => true]);
148  $this->setPage($page);
149  }
150 }
__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=[])
$order
Definition: order.php:55
$values
Definition: options.phtml:88
$resource
Definition: bulk.php:12
$value
Definition: gender.phtml:16
$page
Definition: pages.php:8
$filesystem
$i
Definition: gallery.phtml:31