Adjustments.php 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Sales\Block\Adminhtml\Order\Creditmemo\Create;
  7. use Magento\Framework\Pricing\PriceCurrencyInterface;
  8. /**
  9. * Credit memo adjustmets block
  10. *
  11. * @api
  12. * @since 100.0.2
  13. */
  14. class Adjustments extends \Magento\Backend\Block\Template
  15. {
  16. /**
  17. * Source object
  18. *
  19. * @var \Magento\Framework\DataObject
  20. */
  21. protected $_source;
  22. /**
  23. * Tax config
  24. *
  25. * @var \Magento\Tax\Model\Config
  26. */
  27. protected $_taxConfig;
  28. /**
  29. * @var PriceCurrencyInterface
  30. */
  31. protected $priceCurrency;
  32. /**
  33. * @param \Magento\Backend\Block\Template\Context $context
  34. * @param \Magento\Tax\Model\Config $taxConfig
  35. * @param PriceCurrencyInterface $priceCurrency
  36. * @param array $data
  37. */
  38. public function __construct(
  39. \Magento\Backend\Block\Template\Context $context,
  40. \Magento\Tax\Model\Config $taxConfig,
  41. PriceCurrencyInterface $priceCurrency,
  42. array $data = []
  43. ) {
  44. $this->_taxConfig = $taxConfig;
  45. $this->priceCurrency = $priceCurrency;
  46. parent::__construct($context, $data);
  47. }
  48. /**
  49. * Initialize creditmemo adjustment totals
  50. *
  51. * @return $this
  52. */
  53. public function initTotals()
  54. {
  55. $parent = $this->getParentBlock();
  56. $this->_source = $parent->getSource();
  57. $total = new \Magento\Framework\DataObject(['code' => 'agjustments', 'block_name' => $this->getNameInLayout()]);
  58. $parent->removeTotal('shipping');
  59. $parent->removeTotal('adjustment_positive');
  60. $parent->removeTotal('adjustment_negative');
  61. $parent->addTotal($total);
  62. return $this;
  63. }
  64. /**
  65. * Get source object
  66. *
  67. * @return \Magento\Framework\DataObject
  68. */
  69. public function getSource()
  70. {
  71. return $this->_source;
  72. }
  73. /**
  74. * Get credit memo shipping amount depend on configuration settings
  75. *
  76. * @return float
  77. */
  78. public function getShippingAmount()
  79. {
  80. $source = $this->getSource();
  81. if ($this->_taxConfig->displaySalesShippingInclTax($source->getOrder()->getStoreId())) {
  82. $shipping = $source->getBaseShippingInclTax();
  83. } else {
  84. $shipping = $source->getBaseShippingAmount();
  85. }
  86. return $this->priceCurrency->round($shipping) * 1;
  87. }
  88. /**
  89. * Get label for shipping total based on configuration settings
  90. *
  91. * @return string
  92. */
  93. public function getShippingLabel()
  94. {
  95. $source = $this->getSource();
  96. if ($this->_taxConfig->displaySalesShippingInclTax($source->getOrder()->getStoreId())) {
  97. $label = __('Refund Shipping (Incl. Tax)');
  98. } elseif ($this->_taxConfig->displaySalesShippingBoth($source->getOrder()->getStoreId())) {
  99. $label = __('Refund Shipping (Excl. Tax)');
  100. } else {
  101. $label = __('Refund Shipping');
  102. }
  103. return $label;
  104. }
  105. }