Blame view

modules/admin/stat/stat.php 5.38 KB
42868d70   andryeyev   Создал GIT
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
  <?php
  
  $array_label = array(0=>"íîâûå çàêàçû",1=>"îáðàáîòàí",2=>"äîñòàâèòü",3=>"îòïðàâèòü",4=>"ñàìîâûâîç",5=>"",6=>"",
  					7=>"âîçâðàò",8=>"",9=>"îòìåíåí",10=>"âûïîëíåí");
  
  $array_label = array(8=>"",9=>"îòìåíåí",10=>"âûïîëíåí");					
  
  function get_day($datestamp, $num_week, $num_day){ 
  
      $year = date("Y", $datestamp); 
      $month = date("m", $datestamp); 
      $day = date("d", $datestamp); 
       
      $days = array("sunday","monday","wednesday","thursday","friday","saturday"); 
      $weeks = array("first","second","third","fourth","fifth"); 
       
      $date = date("d-m-Y",strtotime($weeks[$num_week-1]." ".$days[$num_day], mktime(0,0,0,$month,0,$year))); 
       
      return $date; 
  } 
  
  
  if(isset($_POST['y'],$_POST['m'],$_POST['w'])){
  	if($_POST['y']>0 && $_POST['m']==0 && $_POST['w']==0){
  		$date_start = date("d-m-Y", mktime(0, 0, 0, 1, 1, $_POST['y']));
  		$date_end = date("d-m-Y", mktime(0, 0, 0, 1, 1, $_POST['y']+1));
  	}
  	if($_POST['y']>0 && $_POST['m']>0 && $_POST['w']==0){
  		$date_start = date("d-m-Y", mktime(0, 0, 0, $_POST['m'], 1, $_POST['y']));
  		$date_end = date("d-m-Y", mktime(0, 0, 0, $_POST['m']+1, 1, $_POST['y']));
  	}
  	if($_POST['y']>0 && $_POST['m']>0 && $_POST['w']>0){
  		$date_start = get_day(mktime(0, 0, 0, $_POST['m'], date("d"), $_POST['y']),$_POST['w'],1);
  		$date_end = get_day(mktime(0, 0, 0, $_POST['m'], date("d"), $_POST['y']),$_POST['w']+1,1);
  	}
  
  	if(isset($_POST['date_ot']) && strlen($_POST['date_ot'])>0 && isset($_POST['date_do']) && strlen($_POST['date_do'])>0){
  		$date_start = $_POST['date_ot'];
  		$date_end = $_POST['date_do'];
  	}
  	//$date_start = get_day(mktime(0, 0, 0, $_POST['m'], date("d"), $_POST['y']),$_POST['w'],1);
  	$objCatalogs->tpl->assign('date_start',$date_start);
  
  	//$date_end = get_day(mktime(0, 0, 0, $_POST['m2'], date("d"), $_POST['y2']),$_POST['w2'],1);
  	$objCatalogs->tpl->assign('date_end',$date_end);
  	
  	
  	
  	
  	if($_POST['y2']>0 && $_POST['m2']==0 && $_POST['w2']==0){
  		$date_start2 = date("d-m-Y", mktime(0, 0, 0, 1, 1, $_POST['y2']));
  		$date_end2 = date("d-m-Y", mktime(0, 0, 0, 1, 1, $_POST['y2']+1));
  	}
  	if($_POST['y2']>0 && $_POST['m2']>0 && $_POST['w2']==0){
  		$date_start2 = date("d-m-Y", mktime(0, 0, 0, $_POST['m2'], 1, $_POST['y2']));
  		$date_end2 = date("d-m-Y", mktime(0, 0, 0, $_POST['m2']+1, 1, $_POST['y2']));
  	}
  	if($_POST['y2']>0 && $_POST['m2']>0 && $_POST['w2']>0){
  		$date_start2 = get_day(mktime(0, 0, 0, $_POST['m2'], date("d"), $_POST['y2']),$_POST['w2'],1);
  		$date_end2 = get_day(mktime(0, 0, 0, $_POST['m2'], date("d"), $_POST['y2']),$_POST['w2']+1,1);
  	}
  
  	if(isset($_POST['date2_ot']) && strlen($_POST['date2_ot'])>0 && isset($_POST['date2_do']) && strlen($_POST['date2_do'])>0){
  		$date_start2 = $_POST['date2_ot'];
  		$date_end2 = $_POST['date2_do'];
  	}	
  	//$date_start = get_day(mktime(0, 0, 0, $_POST['m'], date("d"), $_POST['y']),$_POST['w'],1);
  	$objCatalogs->tpl->assign('date_start2',$date_start2);
  
  	//$date_end = get_day(mktime(0, 0, 0, $_POST['m2'], date("d"), $_POST['y2']),$_POST['w2'],1);
  	$objCatalogs->tpl->assign('date_end2',$date_end2);	
  	
  	
  
  $arr = array();
  $arr[] = array('date_start' => $date_start, 'date_end' => $date_end);
  if(isset($date_start2,$date_end2)){
  $arr[] = array('date_start' => $date_start2, 'date_end' => $date_end2);
  }
  //$arr[]['date'] = $date_end;
  if(isset($date_start,$date_end)){
  foreach($arr as $key=>$row){
  	$m = explode('-',$row['date_start']);
  	$mktime_start = mktime(0, 0, 0, $m[1], $m[0], $m[2]);
  	$m = explode('-',$row['date_end']);
  	$mktime_end = mktime(0, 0, 0, $m[1], $m[0], $m[2]);	
  	
  	$arr[$key]['rubrics'] = (!isset($_POST['rubrics'])) ? array(array('id'=>0,'name'=>"Íåò ðóáðèêè")) : $objCatalogs->db->getAll("select id,name from catalogs_rubrics where id in (".implode(',',$_POST['rubrics']).")",array(),DB_FETCHMODE_ASSOC);
  	foreach($arr[$key]['rubrics'] as $keyr=>$rowr){ 
  		$sum = array();$count = array();
  		foreach($array_label as $keyl=>$label){
  		$row_l = $objCatalogs->db->getRow("SELECT o.label, COUNT( o.id ) AS count, SUM( o.total ) AS sum
  											FROM catalogs_orders o
  											LEFT JOIN catalogs_orders_products op ON op.order_id = o.id
  											LEFT JOIN catalogs_modifications m ON m.id = op.product_id
  											LEFT JOIN catalogs_products p ON p.id = m.product_id
  		where ".(($rowr['id']>0) ? "p.rubric_id='".$rowr['id']."' and" : '')." o.label='".$keyl."' and (o.mktime>='".$mktime_start."' and o.mktime<='".$mktime_end."') GROUP BY o.label",array(),DB_FETCHMODE_ASSOC);
  			$sum[] = $row_l['sum'];
  			$count[] = $row_l['count'];
  			$arr[$key]['rubrics'][$keyr]['metka'][] = array('label' => $keyl,'count'=>$row_l['count'],'sum'=>$row_l['sum']);
  		}
  		$arr[$key]['rubrics'][$keyr]['sum'] = array_sum($sum);
  		$arr[$key]['rubrics'][$keyr]['count'] = array_sum($count);
  	/*	$arr[$key]['rubrics'][$keyr]['metka'] = $objCatalogs->db->getAll("select o.label,count(o.id) as count,sum(o.total) as sum from catalogs_orders o 
  		left join catalogs_orders_products op on op.order_id=o.id 
  		left join catalogs_products p on p.id=op.product_id 
  		and p.rubric_id=? where o.mktime>='".$mktime_start."' and o.mktime<='".$mktime_end."' GROUP BY o.label",array($rowr['id']),DB_FETCHMODE_ASSOC);*/
  	}
  	
  }
  }
  
  
  
  //print"<pre>";
  //print_r($arr);
  //print"</pre>";
  $objCatalogs->tpl->assign('orders',$arr);
  }
  
  
  $objCatalogs->viewRubricsAll();
  
  //print_r($_POST);
  
  
  $year = range(2008,date("Y"));
  $objCatalogs->tpl->assign('year',$year);
  
  $week = range(1,5);
  $objCatalogs->tpl->assign('week',$week);
  
  $objCatalogs->tpl->assign('tpl',"stat.tpl");
  ?>