PageRenderTime 44ms CodeModel.GetById 13ms RepoModel.GetById 0ms app.codeStats 0ms

/scripts/admin_pages/includes/admin_home/ordersPerMonth.php

https://bitbucket.org/ymauray/multishop
PHP | 117 lines | 112 code | 0 blank | 5 comment | 22 complexity | ead00ecefd7fa46e08286f03c2da73de MD5 | raw file
Possible License(s): MIT, Apache-2.0, LGPL-2.1
  1. <?php
  2. if (!defined('TYPO3_MODE')) {
  3. die ('Access denied.');
  4. }
  5. $compiledWidget['key'] = 'ordersPerMonth';
  6. $compiledWidget['defaultCol'] = 1;
  7. $compiledWidget['title'] = $this->pi_getLL('orders_volume_by_month', 'Bestellingen');
  8. $where = array();
  9. $where[] = '(o.deleted=0)';
  10. switch ($this->dashboardArray['section']) {
  11. case 'admin_home':
  12. break;
  13. case 'admin_edit_customer':
  14. if ($this->get['tx_multishop_pi1']['cid'] && is_numeric($this->get['tx_multishop_pi1']['cid'])) {
  15. $where[] = '(o.customer_id=' . $this->get['tx_multishop_pi1']['cid'] . ')';
  16. }
  17. break;
  18. }
  19. $str = $GLOBALS['TYPO3_DB']->SELECTquery('o.crdate', // SELECT ...
  20. 'tx_multishop_orders o', // FROM ...
  21. '(' . implode(" AND ", $where) . ')', // WHERE...
  22. '', // GROUP BY...
  23. 'orders_id asc', // ORDER BY...
  24. '1' // LIMIT ...
  25. );
  26. $qry_year = $GLOBALS['TYPO3_DB']->sql_query($str);
  27. $row_year = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($qry_year);
  28. if ($row_year['crdate'] > 0) {
  29. $oldest_year = date("Y", $row_year['crdate']);
  30. } else {
  31. $oldest_year = date("Y");
  32. }
  33. $current_year = date("Y");
  34. $dates = array();
  35. //$compiledWidget['content'].='<h2>'.htmlspecialchars($this->pi_getLL('sales_volume_by_month')).'</h2>';
  36. for ($i = 3; $i >= 0; $i--) {
  37. //$time=strtotime("-".$i." month");
  38. $time = strtotime(date('Y-m-01') . ' -' . $i . ' MONTH');
  39. // $time=strtotime(date($selected_year.$i."-01")." 00:00:00");
  40. $dates[strftime("%B %Y", $time)] = date("Y-m", $time);
  41. }
  42. $compiledWidget['content'] .= '<table width="100%" class="table table-striped table-bordered" cellspacing="0" cellpadding="0" border="0" >';
  43. $compiledWidget['content'] .= '<tr class="odd">';
  44. foreach ($dates as $key => $value) {
  45. $compiledWidget['content'] .= '<td align="right">' . ucfirst($key) . '</td>';
  46. }
  47. $compiledWidget['content'] .= '<td align="right" nowrap>' . htmlspecialchars($this->pi_getLL('total')) . '</td>';
  48. $compiledWidget['content'] .= '<td align="right" nowrap>' . htmlspecialchars($this->pi_getLL('cumulative')) . '</td>';
  49. $compiledWidget['content'] .= '</tr>';
  50. $compiledWidget['content'] .= '<tr class="even">';
  51. $total_amount = 0;
  52. foreach ($dates as $key => $value) {
  53. $total_orders = 0;
  54. $start_time = strtotime($value . "-01 00:00:00");
  55. //$end_time=strtotime($value."-31 23:59:59");
  56. $end_time = strtotime($value . "-01 23:59:59 +1 MONTH -1 DAY");
  57. $data_query = array();
  58. $data_query['where'][] = '(o.deleted=0)';
  59. $data_query['where'][] = '(o.crdate BETWEEN ' . $start_time . ' and ' . $end_time . ')';
  60. switch ($this->dashboardArray['section']) {
  61. case 'admin_home':
  62. break;
  63. case 'admin_edit_customer':
  64. if ($this->get['tx_multishop_pi1']['cid'] && is_numeric($this->get['tx_multishop_pi1']['cid'])) {
  65. $data_query['where'][] = '(o.customer_id=' . $this->get['tx_multishop_pi1']['cid'] . ')';
  66. }
  67. break;
  68. }
  69. // hook
  70. if (is_array($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/scripts/admin_pages/includes/admin_home/ordersPerMonth.php']['ordersPerMonthHomeStatsQueryHookPreProc'])) {
  71. $params = array(
  72. 'data_query' => &$data_query
  73. );
  74. foreach ($GLOBALS['TYPO3_CONF_VARS']['SC_OPTIONS']['ext/multishop/scripts/admin_pages/includes/admin_home/ordersPerMonth.php']['ordersPerMonthHomeStatsQueryHookPreProc'] as $funcRef) {
  75. \TYPO3\CMS\Core\Utility\GeneralUtility::callUserFunction($funcRef, $params, $this);
  76. }
  77. }
  78. $str = $GLOBALS['TYPO3_DB']->SELECTquery('count(1) as total', // SELECT ...
  79. 'tx_multishop_orders o', // FROM ...
  80. '(' . implode(" AND ", $data_query['where']) . ')', // WHERE...
  81. '', // GROUP BY...
  82. '', // ORDER BY...
  83. '' // LIMIT ...
  84. );
  85. $qry = $GLOBALS['TYPO3_DB']->sql_query($str);
  86. while (($row = $GLOBALS['TYPO3_DB']->sql_fetch_assoc($qry)) != false) {
  87. $total_orders = ($total_orders + $row['total']);
  88. }
  89. $compiledWidget['content'] .= '<td align="right">' . number_format($total_orders, 0, '', '.') . '</td>';
  90. $total_amount = $total_amount + $total_orders;
  91. }
  92. if ($this->cookie['stats_year_sb'] == date("Y") || !$this->cookie['stats_year_sb']) {
  93. $month = date("m");
  94. $currentDay = date("d");
  95. $dayOfTheYear = date("z");
  96. $currentYear = 1;
  97. if ($month == 1) {
  98. $currentMonth = 1;
  99. }
  100. } else {
  101. $month = 12;
  102. $dayOfTheYear = 365;
  103. $currentDay = 31;
  104. $currentYear = 0;
  105. $currentMonth = 0;
  106. }
  107. $compiledWidget['content'] .= '<td align="right" nowrap>' . number_format($total_amount, 0, '', '.') . '</td>';
  108. $compiledWidget['content'] .= '<td align="right" nowrap>' . number_format(($total_amount / $dayOfTheYear) * 365, 0, '', '.') . '</td>';
  109. $compiledWidget['content'] .= '</tr>';
  110. if (!$tr_type or $tr_type == 'even') {
  111. $tr_type = 'odd';
  112. } else {
  113. $tr_type = 'even';
  114. }
  115. $compiledWidget['content'] .= '
  116. </table>';
  117. ?>