zgg 2 maanden geleden
bovenliggende
commit
2b8e502f5d

+ 97 - 1
application/admin/controller/OrderStatistics.php

@@ -69,6 +69,7 @@ class OrderStatistics extends Auth
         }
         $data = list_sort_by($list,'nums','desc');
 
+
         include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
         //实例化PHPExcel类
         $objPHPExcel =new \PHPExcel();
@@ -164,7 +165,6 @@ class OrderStatistics extends Auth
             }
             $data = list_sort_by($list,'nums','desc');
             $result['rows'] = $data;
-
             return json($result);
         }else{
             $this->assign('start',$start);
@@ -173,6 +173,102 @@ class OrderStatistics extends Auth
         }
     }
 
+    public function repairCateExport(){
+        $start = input('start',date('Y-m-d',strtotime('-7 day')));
+        $end = input('end',date('Y-m-d'));
+        $sTime = $start.' 00:00:00';
+        $eTime = $end.' 23:59:59';
+
+        $list = Db::name('order_type')
+            ->field('id,title,parent_id')
+            ->where('enable',1)
+            ->where('del',0)
+            ->where('org_id',$this->orgId)
+            ->where('parent_id','=',0)
+            ->select();
+        foreach ($list as $k=>$v){
+            $type = Db::name('order_type')
+                ->field('id')
+                ->where('enable',1)
+                ->where('del',0)
+                ->where('org_id',$this->orgId)
+                ->where('parent_id',$v['id'])
+                ->select();
+            $ids = [];
+            foreach ($type as $kk=>$vv){
+                $ids[$kk] = $vv['id'];
+            }
+            $list[$k]['ids'] = $ids;
+        }
+
+        foreach ($list as $k=>$v){
+            $list[$k]['nums'] =  Db::name('orders')
+                ->alias('o')
+                ->join('order_repair or','or.order_id=o.id')
+                ->whereIn('or.type_id',$v['ids'])
+                ->where('o.del',0)
+                ->where('o.org_id',$this->orgId)
+                ->where('o.create_time','>=',$sTime)
+                ->where('o.create_time','<=',$eTime)
+                ->count();
+        }
+        $data = list_sort_by($list,'nums','desc');
+
+
+        include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
+        //实例化PHPExcel类
+        $objPHPExcel =new \PHPExcel();
+        //激活当前的sheet表
+        $objPHPExcel->setActiveSheetIndex(0);
+        //设置表格头(即excel表格的第一行)
+        $objPHPExcel->setActiveSheetIndex(0)
+            ->setCellValue('A1', '报修类型')
+            ->setCellValue('B1', '总数');
+        // 设置表格头水平居中
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A1')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('B1')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('C1')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+
+
+        //设置列水平居中
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('A')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('B')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+        $objPHPExcel->setActiveSheetIndex(0)->getStyle('C')->getAlignment()
+            ->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
+
+        //设置单元格宽度
+        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('A')->setWidth(30);
+        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('B')->setWidth(30);
+        $objPHPExcel->setActiveSheetIndex(0)->getColumnDimension('C')->setWidth(30);
+
+
+        //循环刚取出来的数组,将数据逐一添加到excel表格。
+        for ($i = 0; $i < count($data); $i++) {
+            $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $data[$i]['title']);
+            $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $data[$i]['nums']);
+
+        }
+        //设置保存的Excel表格名称
+        $filename = '报修类型统计报表_' . date('YmdHis', time()) . '.xls';
+        //设置当前激活的sheet表格名称
+        $objPHPExcel->getActiveSheet()->setTitle('报修类型统计报表');
+        //设置浏览器窗口下载表格
+        ob_end_clean();
+        header("Content-Type: application/force-download");
+        header("Content-Type: application/octet-stream");
+        header("Content-Type: application/download");
+        header('Content-Disposition:inline;filename="' . $filename);
+        //生成excel文件
+        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
+        //下载文件在浏览器窗口
+        return $objWriter->save('php://output');
+    }
+
     public function repairWorkload($mode){
         $start = input('start',date('Y-m-d 00:00:00',strtotime('-7 day')));
         $end = input('end',date('Y-m-d 23:59:59'));

+ 6 - 7
application/admin/controller/RepairStatistics.php

@@ -981,8 +981,7 @@ class RepairStatistics extends Auth
             ->field('id,title')
             ->where($where)
             ->select();
-
-        $this->assign('mate',$mate);
+        // $this->assign('mate',$mate);
         //获取某年某个月的总天数
 //        $t =  cal_days_in_month(CAL_GREGORIAN,$curMonth,$curYear);
         $t = date('t',strtotime($month));
@@ -1019,7 +1018,6 @@ class RepairStatistics extends Auth
             $total +=$c;
             $subtotal[$k] = $c;
         }
-
         include_once env('root_path').'/extend/phpexcel/Classes/PHPExcel.php';
         //实例化PHPExcel类
         $objPHPExcel =new \PHPExcel();
@@ -1027,8 +1025,8 @@ class RepairStatistics extends Auth
         $objPHPExcel->setActiveSheetIndex(0);
         //设置表格头(即excel表格的第一行)
         $sheet = $objPHPExcel->setActiveSheetIndex(0);
-        $arr = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T');
-        foreach ($arr as $k=>$v) {
+        $arr2 = array('A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T');
+        foreach ($arr2 as $k=>$v) {
             $objPHPExcel->getActiveSheet()->getStyle($v)->getAlignment()->setWrapText(false);//换行
             $objPHPExcel->getActiveSheet()->getStyle($v.'1')->getFont()->setBold(true);
             $objPHPExcel->getActiveSheet()->getStyle($v.'1')->getAlignment()->setHorizontal(\PHPExcel_Style_Alignment::HORIZONTAL_CENTER);
@@ -1046,6 +1044,7 @@ class RepairStatistics extends Auth
             $sheet->setCellValueByColumnAndRow(0, $k + 2, $v['title']);
             foreach ($mate as $kk=>$vv){
                 $sheet->setCellValueByColumnAndRow($kk+1, $k + 2, $v['type'.$vv['id']]);
+
             }
 
         }
@@ -1060,7 +1059,7 @@ class RepairStatistics extends Auth
 
 
         //设置保存的Excel表格名称
-        $filename = '报修耗材报表_' . date('YmdHis', time()) . '.xls';
+        $filename = '报修耗材报表_' . date('YmdHis', time()) . '.xlsx';
         //设置当前激活的sheet表格名称
         $objPHPExcel->getActiveSheet()->setTitle('报修耗材报表');
         //设置浏览器窗口下载表格
@@ -1070,7 +1069,7 @@ class RepairStatistics extends Auth
         header("Content-Type: application/download");
         header('Content-Disposition:inline;filename="' . $filename);
         //生成excel文件
-        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel5');
+        $objWriter = \PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
         //下载文件在浏览器窗口
         return $objWriter->save('php://output');
 

+ 7 - 2
application/admin/view/order_statistics/repair_cate.html

@@ -17,7 +17,7 @@
             <div class="col-xs-3">
                 <div class="btn-group pull-left">
                     <a href="javascript:;" onclick="printer()" class="btn btn-sm btn btn-primary"><i class="glyphicon glyphicon-print"></i> 打印</a>
-                    <a href="{:url('repairItemsExport',['start'=>$start,'end'=>$end])}" class="btn btn-sm btn-danger"><i class="fa fa-cloud-download"> 导出</i></a>
+                    <a href="javascript:void(0)" id="exportBtn" class="btn btn-sm btn-danger"><i class="fa fa-cloud-download"> 导出</i></a>
                 </div>
             </div>
             <div class="col-xs-9" style="text-align: right;">
@@ -105,7 +105,12 @@
             },
         });
     });
-
+    $('#exportBtn').click(function (){
+        var  start = $('#start').val();
+        var  end = $('#end').val();
+        console.log(start,end);
+        window.location.href = "{:url('OrderStatistics/repairCateExport')}?start="+start+'&end='+end;
+    })
 
 </script>
 {/block}