Shipping.php 2.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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 Shipping 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. * Get array of arrays with totals information for display in PDF
  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. $amount = $this->getOrder()->formatPriceTxt($this->getAmount());
  45. $amountInclTax = $this->getSource()->getShippingInclTax();
  46. if (!$amountInclTax) {
  47. $amountInclTax = $this->getAmount() + $this->getSource()->getShippingTaxAmount();
  48. }
  49. $amountInclTax = $this->getOrder()->formatPriceTxt($amountInclTax);
  50. $fontSize = $this->getFontSize() ? $this->getFontSize() : 7;
  51. if ($this->_taxConfig->displaySalesShippingBoth($store)) {
  52. $totals = [
  53. [
  54. 'amount' => $this->getAmountPrefix() . $amount,
  55. 'label' => __('Shipping (Excl. Tax)') . ':',
  56. 'font_size' => $fontSize,
  57. ],
  58. [
  59. 'amount' => $this->getAmountPrefix() . $amountInclTax,
  60. 'label' => __('Shipping (Incl. Tax)') . ':',
  61. 'font_size' => $fontSize
  62. ],
  63. ];
  64. } elseif ($this->_taxConfig->displaySalesShippingInclTax($store)) {
  65. $totals = [
  66. [
  67. 'amount' => $this->getAmountPrefix() . $amountInclTax,
  68. 'label' => __($this->getTitle()) . ':',
  69. 'font_size' => $fontSize,
  70. ],
  71. ];
  72. } else {
  73. $totals = [
  74. [
  75. 'amount' => $this->getAmountPrefix() . $amount,
  76. 'label' => __($this->getTitle()) . ':',
  77. 'font_size' => $fontSize,
  78. ],
  79. ];
  80. }
  81. return $totals;
  82. }
  83. }