/vendor/magento/module-reports/Block/Adminhtml/Sales/Sales/Grid.php

https://gitlab.com/yousafsyed/easternglamor · PHP · 318 lines · 267 code · 24 blank · 27 comment · 2 complexity · 6e14ea76d76d74052e40d6f204b3c77c MD5 · raw file

  1. <?php
  2. /**
  3. * Copyright © 2016 Magento. All rights reserved.
  4. * See COPYING.txt for license details.
  5. */
  6. namespace Magento\Reports\Block\Adminhtml\Sales\Sales;
  7. /**
  8. * Adminhtml sales 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. }
  30. /**
  31. * {@inheritdoc}
  32. */
  33. public function getResourceCollectionName()
  34. {
  35. return $this->getFilterData()->getData('report_type') == 'updated_at_order'
  36. ? 'Magento\Sales\Model\ResourceModel\Report\Order\Updatedat\Collection'
  37. : 'Magento\Sales\Model\ResourceModel\Report\Order\Collection';
  38. }
  39. /**
  40. * {@inheritdoc}
  41. *
  42. * @SuppressWarnings(PHPMD.ExcessiveMethodLength)
  43. */
  44. protected function _prepareColumns()
  45. {
  46. $this->addColumn(
  47. 'period',
  48. [
  49. 'header' => __('Interval'),
  50. 'index' => 'period',
  51. 'sortable' => false,
  52. 'period_type' => $this->getPeriodType(),
  53. 'renderer' => 'Magento\Reports\Block\Adminhtml\Sales\Grid\Column\Renderer\Date',
  54. 'totals_label' => __('Total'),
  55. 'html_decorators' => ['nobr'],
  56. 'header_css_class' => 'col-period',
  57. 'column_css_class' => 'col-period'
  58. ]
  59. );
  60. $this->addColumn(
  61. 'orders_count',
  62. [
  63. 'header' => __('Orders'),
  64. 'index' => 'orders_count',
  65. 'type' => 'number',
  66. 'total' => 'sum',
  67. 'sortable' => false,
  68. 'header_css_class' => 'col-orders',
  69. 'column_css_class' => 'col-orders'
  70. ]
  71. );
  72. $this->addColumn(
  73. 'total_qty_ordered',
  74. [
  75. 'header' => __('Sales Items'),
  76. 'index' => 'total_qty_ordered',
  77. 'type' => 'number',
  78. 'total' => 'sum',
  79. 'sortable' => false,
  80. 'header_css_class' => 'col-sales-items',
  81. 'column_css_class' => 'col-sales-items'
  82. ]
  83. );
  84. $this->addColumn(
  85. 'total_qty_invoiced',
  86. [
  87. 'header' => __('Items'),
  88. 'index' => 'total_qty_invoiced',
  89. 'type' => 'number',
  90. 'total' => 'sum',
  91. 'sortable' => false,
  92. 'visibility_filter' => ['show_actual_columns'],
  93. 'header_css_class' => 'col-items',
  94. 'column_css_class' => 'col-items'
  95. ]
  96. );
  97. if ($this->getFilterData()->getStoreIds()) {
  98. $this->setStoreIds(explode(',', $this->getFilterData()->getStoreIds()));
  99. }
  100. $currencyCode = $this->getCurrentCurrencyCode();
  101. $rate = $this->getRate($currencyCode);
  102. $this->addColumn(
  103. 'total_income_amount',
  104. [
  105. 'header' => __('Sales Total'),
  106. 'type' => 'currency',
  107. 'currency_code' => $currencyCode,
  108. 'index' => 'total_income_amount',
  109. 'total' => 'sum',
  110. 'sortable' => false,
  111. 'rate' => $rate,
  112. 'header_css_class' => 'col-sales-total',
  113. 'column_css_class' => 'col-sales-total'
  114. ]
  115. );
  116. $this->addColumn(
  117. 'total_revenue_amount',
  118. [
  119. 'header' => __('Revenue'),
  120. 'type' => 'currency',
  121. 'currency_code' => $currencyCode,
  122. 'index' => 'total_revenue_amount',
  123. 'total' => 'sum',
  124. 'sortable' => false,
  125. 'visibility_filter' => ['show_actual_columns'],
  126. 'rate' => $rate,
  127. 'header_css_class' => 'col-revenue',
  128. 'column_css_class' => 'col-revenue'
  129. ]
  130. );
  131. $this->addColumn(
  132. 'total_profit_amount',
  133. [
  134. 'header' => __('Profit'),
  135. 'type' => 'currency',
  136. 'currency_code' => $currencyCode,
  137. 'index' => 'total_profit_amount',
  138. 'total' => 'sum',
  139. 'sortable' => false,
  140. 'visibility_filter' => ['show_actual_columns'],
  141. 'rate' => $rate,
  142. 'header_css_class' => 'col-profit',
  143. 'column_css_class' => 'col-profit'
  144. ]
  145. );
  146. $this->addColumn(
  147. 'total_invoiced_amount',
  148. [
  149. 'header' => __('Invoiced'),
  150. 'type' => 'currency',
  151. 'currency_code' => $currencyCode,
  152. 'index' => 'total_invoiced_amount',
  153. 'total' => 'sum',
  154. 'sortable' => false,
  155. 'rate' => $rate,
  156. 'header_css_class' => 'col-invoiced',
  157. 'column_css_class' => 'col-invoiced'
  158. ]
  159. );
  160. $this->addColumn(
  161. 'total_paid_amount',
  162. [
  163. 'header' => __('Paid'),
  164. 'type' => 'currency',
  165. 'currency_code' => $currencyCode,
  166. 'index' => 'total_paid_amount',
  167. 'total' => 'sum',
  168. 'sortable' => false,
  169. 'visibility_filter' => ['show_actual_columns'],
  170. 'rate' => $rate,
  171. 'header_css_class' => 'col-paid',
  172. 'column_css_class' => 'col-paid'
  173. ]
  174. );
  175. $this->addColumn(
  176. 'total_refunded_amount',
  177. [
  178. 'header' => __('Refunded'),
  179. 'type' => 'currency',
  180. 'currency_code' => $currencyCode,
  181. 'index' => 'total_refunded_amount',
  182. 'total' => 'sum',
  183. 'sortable' => false,
  184. 'rate' => $rate,
  185. 'header_css_class' => 'col-refunded',
  186. 'column_css_class' => 'col-refunded'
  187. ]
  188. );
  189. $this->addColumn(
  190. 'total_tax_amount',
  191. [
  192. 'header' => __('Sales Tax'),
  193. 'type' => 'currency',
  194. 'currency_code' => $currencyCode,
  195. 'index' => 'total_tax_amount',
  196. 'total' => 'sum',
  197. 'sortable' => false,
  198. 'rate' => $rate,
  199. 'header_css_class' => 'col-sales-tax',
  200. 'column_css_class' => 'col-sales-tax'
  201. ]
  202. );
  203. $this->addColumn(
  204. 'total_tax_amount_actual',
  205. [
  206. 'header' => __('Tax'),
  207. 'type' => 'currency',
  208. 'currency_code' => $currencyCode,
  209. 'index' => 'total_tax_amount_actual',
  210. 'total' => 'sum',
  211. 'sortable' => false,
  212. 'visibility_filter' => ['show_actual_columns'],
  213. 'rate' => $rate,
  214. 'header_css_class' => 'col-tax',
  215. 'column_css_class' => 'col-tax'
  216. ]
  217. );
  218. $this->addColumn(
  219. 'total_shipping_amount',
  220. [
  221. 'header' => __('Sales Shipping'),
  222. 'type' => 'currency',
  223. 'currency_code' => $currencyCode,
  224. 'index' => 'total_shipping_amount',
  225. 'total' => 'sum',
  226. 'sortable' => false,
  227. 'rate' => $rate,
  228. 'header_css_class' => 'col-sales-shipping',
  229. 'column_css_class' => 'col-sales-shipping'
  230. ]
  231. );
  232. $this->addColumn(
  233. 'total_shipping_amount_actual',
  234. [
  235. 'header' => __('Shipping'),
  236. 'type' => 'currency',
  237. 'currency_code' => $currencyCode,
  238. 'index' => 'total_shipping_amount_actual',
  239. 'total' => 'sum',
  240. 'sortable' => false,
  241. 'visibility_filter' => ['show_actual_columns'],
  242. 'rate' => $rate,
  243. 'header_css_class' => 'col-shipping',
  244. 'column_css_class' => 'col-shipping'
  245. ]
  246. );
  247. $this->addColumn(
  248. 'total_discount_amount',
  249. [
  250. 'header' => __('Sales Discount'),
  251. 'type' => 'currency',
  252. 'currency_code' => $currencyCode,
  253. 'index' => 'total_discount_amount',
  254. 'total' => 'sum',
  255. 'sortable' => false,
  256. 'rate' => $rate,
  257. 'header_css_class' => 'col-sales-discount',
  258. 'column_css_class' => 'col-sales-discount'
  259. ]
  260. );
  261. $this->addColumn(
  262. 'total_discount_amount_actual',
  263. [
  264. 'header' => __('Discount'),
  265. 'type' => 'currency',
  266. 'currency_code' => $currencyCode,
  267. 'index' => 'total_discount_amount_actual',
  268. 'total' => 'sum',
  269. 'sortable' => false,
  270. 'visibility_filter' => ['show_actual_columns'],
  271. 'rate' => $rate,
  272. 'header_css_class' => 'col-discount',
  273. 'column_css_class' => 'col-discount'
  274. ]
  275. );
  276. $this->addColumn(
  277. 'total_canceled_amount',
  278. [
  279. 'header' => __('Canceled'),
  280. 'type' => 'currency',
  281. 'currency_code' => $currencyCode,
  282. 'index' => 'total_canceled_amount',
  283. 'total' => 'sum',
  284. 'sortable' => false,
  285. 'rate' => $rate,
  286. 'header_css_class' => 'col-canceled',
  287. 'column_css_class' => 'col-canceled'
  288. ]
  289. );
  290. $this->addExportType('*/*/exportSalesCsv', __('CSV'));
  291. $this->addExportType('*/*/exportSalesExcel', __('Excel XML'));
  292. return parent::_prepareColumns();
  293. }
  294. }