Grid.php 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132
  1. <?php
  2. /**
  3. * Copyright © Magento, Inc. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Reports\Block\Adminhtml\Sales\Shipping;
  7. /**
  8. * Adminhtml shipping report grid block
  9. *
  10. * @author Magento Core Team <core@magentocommerce.com>
  11. * @SuppressWarnings(PHPMD.DepthOfInheritance)
  12. */
  13. class Grid extends \Magento\Reports\Block\Adminhtml\Grid\AbstractGrid
  14. {
  15. /**
  16. * Group by criteria
  17. *
  18. * @var string
  19. */
  20. protected $_columnGroupBy = 'period';
  21. /**
  22. * {@inheritdoc}
  23. * @codeCoverageIgnore
  24. */
  25. protected function _construct()
  26. {
  27. parent::_construct();
  28. $this->setCountTotals(true);
  29. $this->setCountSubTotals(true);
  30. }
  31. /**
  32. * {@inheritdoc}
  33. */
  34. public function getResourceCollectionName()
  35. {
  36. return $this->getFilterData()->getData('report_type') == 'created_at_shipment'
  37. ? \Magento\Sales\Model\ResourceModel\Report\Shipping\Collection\Shipment::class
  38. : \Magento\Sales\Model\ResourceModel\Report\Shipping\Collection\Order::class;
  39. }
  40. /**
  41. * {@inheritdoc}
  42. */
  43. protected function _prepareColumns()
  44. {
  45. $this->addColumn(
  46. 'period',
  47. [
  48. 'header' => __('Interval'),
  49. 'index' => 'period',
  50. 'sortable' => false,
  51. 'period_type' => $this->getPeriodType(),
  52. 'renderer' => \Magento\Reports\Block\Adminhtml\Sales\Grid\Column\Renderer\Date::class,
  53. 'totals_label' => __('Total'),
  54. 'subtotals_label' => __('Subtotal'),
  55. 'html_decorators' => ['nobr'],
  56. 'header_css_class' => 'col-period',
  57. 'column_css_class' => 'col-period'
  58. ]
  59. );
  60. $this->addColumn(
  61. 'shipping_description',
  62. [
  63. 'header' => __('Carrier/Method'),
  64. 'index' => 'shipping_description',
  65. 'sortable' => false,
  66. 'header_css_class' => 'col-method',
  67. 'column_css_class' => 'col-method'
  68. ]
  69. );
  70. $this->addColumn(
  71. 'orders_count',
  72. [
  73. 'header' => __('Orders'),
  74. 'index' => 'orders_count',
  75. 'total' => 'sum',
  76. 'type' => 'number',
  77. 'sortable' => false,
  78. 'header_css_class' => 'col-qty',
  79. 'column_css_class' => 'col-qty'
  80. ]
  81. );
  82. if ($this->getFilterData()->getStoreIds()) {
  83. $this->setStoreIds(explode(',', $this->getFilterData()->getStoreIds()));
  84. }
  85. $currencyCode = $this->getCurrentCurrencyCode();
  86. $rate = $this->getRate($currencyCode);
  87. $this->addColumn(
  88. 'total_shipping',
  89. [
  90. 'header' => __('Total Sales Shipping'),
  91. 'type' => 'currency',
  92. 'currency_code' => $currencyCode,
  93. 'index' => 'total_shipping',
  94. 'total' => 'sum',
  95. 'sortable' => false,
  96. 'rate' => $rate,
  97. 'header_css_class' => 'col-total-sales-shipping',
  98. 'column_css_class' => 'col-total-sales-shipping'
  99. ]
  100. );
  101. $this->addColumn(
  102. 'total_shipping_actual',
  103. [
  104. 'header' => __('Total Shipping'),
  105. 'type' => 'currency',
  106. 'currency_code' => $currencyCode,
  107. 'index' => 'total_shipping_actual',
  108. 'total' => 'sum',
  109. 'sortable' => false,
  110. 'rate' => $rate,
  111. 'header_css_class' => 'col-total-shipping',
  112. 'column_css_class' => 'col-total-shipping'
  113. ]
  114. );
  115. $this->addExportType('*/*/exportShippingCsv', __('CSV'));
  116. $this->addExportType('*/*/exportShippingExcel', __('Excel XML'));
  117. return parent::_prepareColumns();
  118. }
  119. }