Example #1
0
 function create_total_count_sql($start_date, $end_date)
 {
     $start_date = date('y-n-', strtotime($start_date));
     $end_date = date('y-n-', strtotime($end_date));
     // sql
     $sql = "SELECT * FROM productions WHERE ";
     if ($start_date == $end_date) {
         // 单月
         $sql .= "num LIKE '%{$start_date}%' ";
     } else {
         // 跨年/跨月
         $dates = get_dates_array($start_date, $end_date);
         foreach ($dates as $count => $date) {
             if (!$count) {
                 $sql .= " num LIKE '%{$date}%' ";
             } else {
                 $sql .= " OR num LIKE '%{$date}%' ";
             }
         }
     }
     $sql .= " ORDER BY num asc";
     return $sql;
 }
Example #2
0
 function stat_proc_table($start_date, $end_date)
 {
     $app = get_app();
     // month scope
     $start_date = date('y-n-', strtotime($start_date));
     $end_date = date('y-n-', strtotime($end_date));
     //
     $dates = get_dates_array($start_date, $end_date);
     $months = get_months_array($dates);
     //
     $procs = array();
     //
     foreach ($months as $key => $mon) {
         // $key: '14-1'
         $sql = "SELECT * FROM parts WHERE num LIKE '%{$key}%' ORDER BY num asc";
         $parts = Part::find_by_sql($sql);
         // parts
         foreach ($parts as $part) {
             // procs
             foreach ($part->processes as $proc) {
                 // create proc item
                 if (!array_key_exists($proc->name, $procs)) {
                     $procs[$proc->name] = array();
                 }
                 // create proc_month item
                 if (!array_key_exists($key, $procs[$proc->name])) {
                     $procs[$proc->name][$key] = array('done_count' => 0, 'undo_count' => 0);
                 }
                 //
                 if ($proc->is_done) {
                     $procs[$proc->name][$key]['done_count'] += get_proc_time($proc);
                 }
                 if (!$proc->is_done) {
                     $procs[$proc->name][$key]['undo_count'] += get_proc_time($proc);
                 }
             }
         }
     }
     // 如果有月份没有数据
     // 自动补0
     foreach ($procs as $p_key => $proc) {
         foreach ($months as $m_key => $mon) {
             if (!array_key_exists($m_key, $procs[$p_key])) {
                 $procs[$p_key][$m_key] = array('done_count' => 0, 'undo_count' => 0);
             }
         }
         uksort($procs[$p_key], 'month_key_cmp');
     }
     ksort($procs);
     render_with_layout('misc.php', 'Statistics/stat_proc_table.php', compact('procs', 'months'));
 }