Advertisement
svfedorof

Untitled

Oct 19th, 2014
296
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. /*
  4.  
  5. Статистика заказов
  6.  
  7. */
  8.  
  9. $modx->addPackage('minishop2', MODX_CORE_PATH.'components/minishop2/model/');
  10.  
  11. $q_where = "`date` + INTERVAL ".date('j')." DAY > NOW()";
  12.  
  13. $chunkArr = array(
  14. 'lang' => $modx->config['manager_language'],
  15. 'new_count' => $modx->getCount('msOrder',array('status' => 1),$q_where),
  16. 'canceled_count' => $modx->getCount('msOrder',array('status' => 4),$q_where),
  17. 'done_count' => $modx->getCount('msOrder',array('status' => 2),$q_where),
  18. 'all_count' => $modx->getCount('msOrder')
  19. );
  20. $pages = $modx->getCollection('msOrder', array('status' => 1));
  21.  
  22. $current_month = date('n');
  23.  
  24. $months = array(
  25. '1' => 'Январь',
  26. '2' => 'Февраль',
  27. '3' => 'Март',
  28. '4' => 'Апрель',
  29. '5' => 'Май',
  30. '6' => 'Июнь',
  31. '7' => 'Июль',
  32. '8' => 'Август',
  33. '9' => 'Сентябрь',
  34. '10' => 'Октябрь',
  35. '11' => 'Ноябрь',
  36. '12' => 'Декабрь',
  37. );
  38.  
  39. $stat_month = array();
  40. $sql = "
  41. SELECT month(`createdon`) AS `order_month`, count(*) AS `order_count`, SUM(cart_cost) AS order_cost
  42. FROM ".$modx->getTableName('msOrder')."
  43. WHERE year(`createdon`) = ".date('Y')."
  44. GROUP BY month(`createdon`)
  45. ORDER BY month(`createdon`)
  46. ";
  47. $stmt = $modx->prepare($sql);
  48. if ($stmt && $stmt->execute()) {
  49. while ($row = $stmt->fetch(PDO::FETCH_ASSOC)){
  50. $stat_month[] = array("name"=>$months[$row['order_month']],"count"=>$row['order_count'],"cost"=>$row['order_cost']);
  51. }
  52. $stmt->closeCursor();
  53. }
  54.  
  55. $chunkArr['stat_month'] = json_encode($stat_month);
  56.  
  57. $tpl = <<<EOT
  58. <script type="text/javascript">
  59. Ext.chart.Chart.CHART_URL = 'assets/ext3/resources/charts.swf';
  60. Ext.onReady(function(){
  61.  
  62. var store = new Ext.data.JsonStore({
  63. fields: ['categorytitle', 'total'],
  64. data: [{
  65. categorytitle: 'Новые ([[+new_count]])',
  66. total: [[+new_count]]
  67. },{
  68. categorytitle: 'Оплаченые ([[+done_count]])',
  69. total: [[+done_count]]
  70. },{
  71. categorytitle: 'Отмененны ([[+canceled_count]])',
  72. total: [[+canceled_count]]
  73. }]
  74. });
  75.  
  76. new Ext.Panel({
  77. width: 300,
  78. height: 250,
  79. title: 'Статистика за этот месяц',
  80. renderTo: 'ms2_stat',
  81. border: false,
  82. items: {
  83. store: store,
  84. xtype: 'piechart',
  85. dataField: 'total',
  86. categoryField: 'categorytitle',
  87. series: [{
  88. style: {
  89. colors: ["#99CCFF", "#CCFFCC", "#FF99CC"]
  90. }
  91. }],
  92. extraStyle:{
  93. legend:{
  94. display: 'bottom',
  95. padding: 5,
  96. font:{
  97. family: 'Tahoma',
  98. size: 11
  99. }
  100. }
  101. }
  102. }
  103. });
  104.  
  105. var store2 = new Ext.data.JsonStore({
  106. fields:['name', 'count', 'cost'],
  107. data: [[+stat_month]]
  108. });
  109.  
  110. new Ext.Panel({
  111. title: 'Статистика по месяцам',
  112. renderTo: 'ms2_stat2',
  113. //width:500,
  114. height:250,
  115. layout:'fit',
  116. border: false,
  117. items: {
  118. xtype: 'linechart',
  119. store: store2,
  120. xField: 'name',
  121. yField: 'count',
  122. yField: 'cost',
  123. border: false,
  124. listeners: {
  125. itemclick: function(o){
  126. /*
  127. var rec = store2.getAt(o.index);
  128. MODx.msg.status({
  129. title: 'Item Selected',
  130. message: 'You chose: '+rec.get('name'),
  131. delay: 3
  132. });
  133. */
  134. }
  135. },
  136. series: [{
  137. type: 'column',
  138. displayName: 'Кол-во заказов за',
  139. yField: 'count',
  140. style: {
  141. image:'bar.gif',
  142. mode: 'stretch',
  143. color:0x99BBE8
  144. }
  145. },{
  146. type:'line',
  147. displayName: 'Кол-во заказов за',
  148. yField: 'count',
  149. style: {
  150. color: 0x15428B
  151. }
  152. },{
  153. type: 'column',
  154. displayName: 'Доход за',
  155. yField: 'cost',
  156. style: {
  157. image:'bar.gif',
  158. mode: 'stretch',
  159. color:0x4db848
  160. }
  161. },{
  162. type:'line',
  163. displayName: 'Доход за',
  164. yField: 'cost',
  165. style: {
  166. color: 0x2c6829
  167. }
  168. }]
  169. }
  170. });
  171.  
  172. });
  173. </script>
  174.  
  175. <table width="100%">
  176. <col width="*">
  177. <col width="30">
  178. <col width="*">
  179. <col width="*">
  180. <tr>
  181. <td> </td>
  182. <td>
  183. <div id="ms2_stat"></div>
  184. </td>
  185. <td>
  186. <div id="ms2_stat2"></div>
  187. </td>
  188. </tr>
  189. <tr>
  190. <td> </td>
  191. <td>
  192. <p style="color:#000;">Всего заказов: <b>[[+all_count]]</b></p>
  193. </td>
  194. <td> </td>
  195. </tr>
  196. </table>
  197. EOT;
  198.  
  199. $chunk = $modx->newObject('modChunk');
  200. $chunk->fromArray(array('name'=>"INLINE-".uniqid(),'snippet'=>$tpl));
  201. $chunk->setCacheable(false);
  202.  
  203. $output = $chunk->process($chunkArr);
  204.  
  205. return $output;
Advertisement
RAW Paste Data Copied
Advertisement