Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
Grandtotal.php
Go to the documentation of this file.
1 <?php
7 
8 class Grandtotal extends \Magento\Sales\Model\Order\Pdf\Total\DefaultTotal
9 {
13  protected $_taxConfig;
14 
22  public function __construct(
23  \Magento\Tax\Helper\Data $taxHelper,
24  \Magento\Tax\Model\Calculation $taxCalculation,
25  \Magento\Tax\Model\ResourceModel\Sales\Order\Tax\CollectionFactory $ordersFactory,
26  \Magento\Tax\Model\Config $taxConfig,
27  array $data = []
28  ) {
29  $this->_taxConfig = $taxConfig;
30  parent::__construct($taxHelper, $taxCalculation, $ordersFactory, $data);
31  }
32 
44  public function getTotalsForDisplay()
45  {
46  $store = $this->getOrder()->getStore();
47  if (!$this->_taxConfig->displaySalesTaxWithGrandTotal($store)) {
48  return parent::getTotalsForDisplay();
49  }
50  $amount = $this->getOrder()->formatPriceTxt($this->getAmount());
51  $amountExclTax = $this->getAmount() - $this->getSource()->getTaxAmount();
52  $amountExclTax = $amountExclTax > 0 ? $amountExclTax : 0;
53  $amountExclTax = $this->getOrder()->formatPriceTxt($amountExclTax);
54  $tax = $this->getOrder()->formatPriceTxt($this->getSource()->getTaxAmount());
55  $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
56 
57  $totals = [
58  [
59  'amount' => $this->getAmountPrefix() . $amountExclTax,
60  'label' => __('Grand Total (Excl. Tax)') . ':',
61  'font_size' => $fontSize,
62  ],
63  ];
64 
65  if ($this->_taxConfig->displaySalesFullSummary($store)) {
66  $totals = array_merge($totals, $this->getFullTaxInfo());
67  }
68 
69  $totals[] = [
70  'amount' => $this->getAmountPrefix() . $tax,
71  'label' => __('Tax') . ':',
72  'font_size' => $fontSize,
73  ];
74  $totals[] = [
75  'amount' => $this->getAmountPrefix() . $amount,
76  'label' => __('Grand Total (Incl. Tax)') . ':',
77  'font_size' => $fontSize,
78  ];
79  return $totals;
80  }
81 }
__construct(\Magento\Tax\Helper\Data $taxHelper, \Magento\Tax\Model\Calculation $taxCalculation, \Magento\Tax\Model\ResourceModel\Sales\Order\Tax\CollectionFactory $ordersFactory, \Magento\Tax\Model\Config $taxConfig, array $data=[])
Definition: Grandtotal.php:22
__()
Definition: __.php:13
$amount
Definition: order.php:14
$totals
Definition: totalbar.phtml:10