Grandtotal.php 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Tax\Model\Sales\Pdf;
  7. class Grandtotal extends \Magento\Sales\Model\Order\Pdf\Total\DefaultTotal
  8. {
  9. /**
  10. * @var \Magento\Tax\Model\Config
  11. */
  12. protected $_taxConfig;
  13. /**
  14. * @param \Magento\Tax\Helper\Data $taxHelper
  15. * @param \Magento\Tax\Model\Calculation $taxCalculation
  16. * @param \Magento\Tax\Model\ResourceModel\Sales\Order\Tax\CollectionFactory $ordersFactory
  17. * @param \Magento\Tax\Model\Config $taxConfig
  18. * @param array $data
  19. */
  20. public function __construct(
  21. \Magento\Tax\Helper\Data $taxHelper,
  22. \Magento\Tax\Model\Calculation $taxCalculation,
  23. \Magento\Tax\Model\ResourceModel\Sales\Order\Tax\CollectionFactory $ordersFactory,
  24. \Magento\Tax\Model\Config $taxConfig,
  25. array $data = []
  26. ) {
  27. $this->_taxConfig = $taxConfig;
  28. parent::__construct($taxHelper, $taxCalculation, $ordersFactory, $data);
  29. }
  30. /**
  31. * Check if tax amount should be included to grandtotals block
  32. * array(
  33. * $index => array(
  34. * 'amount' => $amount,
  35. * 'label' => $label,
  36. * 'font_size'=> $font_size
  37. * )
  38. * )
  39. * @return array
  40. */
  41. public function getTotalsForDisplay()
  42. {
  43. $store = $this->getOrder()->getStore();
  44. if (!$this->_taxConfig->displaySalesTaxWithGrandTotal($store)) {
  45. return parent::getTotalsForDisplay();
  46. }
  47. $amount = $this->getOrder()->formatPriceTxt($this->getAmount());
  48. $amountExclTax = $this->getAmount() - $this->getSource()->getTaxAmount();
  49. $amountExclTax = $amountExclTax > 0 ? $amountExclTax : 0;
  50. $amountExclTax = $this->getOrder()->formatPriceTxt($amountExclTax);
  51. $tax = $this->getOrder()->formatPriceTxt($this->getSource()->getTaxAmount());
  52. $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
  53. $totals = [
  54. [
  55. 'amount' => $this->getAmountPrefix() . $amountExclTax,
  56. 'label' => __('Grand Total (Excl. Tax)') . ':',
  57. 'font_size' => $fontSize,
  58. ],
  59. ];
  60. if ($this->_taxConfig->displaySalesFullSummary($store)) {
  61. $totals = array_merge($totals, $this->getFullTaxInfo());
  62. }
  63. $totals[] = [
  64. 'amount' => $this->getAmountPrefix() . $tax,
  65. 'label' => __('Tax') . ':',
  66. 'font_size' => $fontSize,
  67. ];
  68. $totals[] = [
  69. 'amount' => $this->getAmountPrefix() . $amount,
  70. 'label' => __('Grand Total (Incl. Tax)') . ':',
  71. 'font_size' => $fontSize,
  72. ];
  73. return $totals;
  74. }
  75. }