Browse Source

增加运送报表

zgg 4 months ago
parent
commit
645ebfb7e6

+ 141 - 0
application/admin/controller/ConveyStatistics.php

@@ -221,4 +221,145 @@ class ConveyStatistics extends Auth
         return $objWriter->save('php://output');
     }
 
+    public function conveyOrder(){
+        $start = input('start',date('Y-m-d',strtotime('-7 day')));
+        $end = input('end',date('Y-m-d'));
+        $address = input('address');
+        if(request()->isAjax()){
+            $sTime = $start.' 00:00:00';
+            $eTime = $end.' 23:59:59';
+            $map = [];
+            if(!empty($address)){
+                $ids = explode(',',$address);
+                $map[] = ['id','in',$ids];
+            }
+            $list  = Db::name('address')
+                ->field('id,title')
+                ->where('enable',1)
+                ->where('del',0)
+                ->where($map)
+                ->where('org_id',$this->orgId)
+                ->where('find_in_set(2,types)')
+                ->select();
+
+            foreach ($list as $k=>$v){
+                $list[$k]['nums'] = Db::name('orders')
+                    ->alias('a')
+                    ->join('order_convey b','a.id=b.order_id')
+                    ->where('a.org_id',$this->orgId)
+                    ->where('a.del',0)
+                    ->where('a.work_type_mode',3)
+                    ->where('a.order_mode','in',[5,6])
+                    ->where('b.start',$v['id'])
+                    ->where('a.create_time','>=',$sTime)
+                    ->where('a.create_time','<=',$eTime)
+                    ->count('a.id');
+            }
+
+            $result['rows'] = $list;
+            return json($result);
+        }else{
+            $addressList  = Db::name('address')
+                ->field('id,title')
+                ->where('enable',1)
+                ->where('del',0)
+                ->where('org_id',$this->orgId)
+                ->where('find_in_set(2,types)')
+                ->select();
+            $this->assign('addressList',$addressList);
+            $this->assign('start',$start);
+            $this->assign('end',$end);
+            $this->assign('addressVal',$address?explode(',',$address):[]);
+            $this->assign('address',$address);
+            return $this->fetch();
+        }
+    }
+
+    public function conveyOrderExport(){
+        $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';
+        $address = input('address');
+
+        $map = [];
+        if(!empty($address)){
+            $ids = explode(',',$address);
+            $map[] = ['id','in',$ids];
+        }
+        $list  = Db::name('address')
+            ->field('id,title')
+            ->where('enable',1)
+            ->where('del',0)
+            ->where($map)
+            ->where('org_id',$this->orgId)
+            ->where('find_in_set(2,types)')
+            ->select();
+
+        foreach ($list as $k=>$v){
+            $list[$k]['nums'] = Db::name('orders')
+                ->alias('a')
+                ->join('order_convey b','a.id=b.order_id')
+                ->where('a.org_id',$this->orgId)
+                ->where('a.del',0)
+                ->where('a.work_type_mode',3)
+                ->where('a.order_mode','in',[5,6])
+                ->where('b.start',$v['id'])
+                ->where('a.create_time','>=',$sTime)
+                ->where('a.create_time','<=',$eTime)
+                ->count('a.id');
+        }
+
+        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($list); $i++) {
+            $objPHPExcel->getActiveSheet()->setCellValue('A' . ($i + 2), $list[$i]['title']);
+            $objPHPExcel->getActiveSheet()->setCellValue('B' . ($i + 2), $list[$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');
+    }
 }

+ 124 - 0
application/admin/view/convey_statistics/convey_order.html

@@ -0,0 +1,124 @@
+{extend name="common/common2" /}
+{block name="main"}
+
+<style>
+    .combined{
+        width: 100%;
+        height: auto;
+        font-size: 22px;
+        padding: 10px;
+        background: #fff;
+    }
+</style>
+
+<div class="ibox">
+    <div class="ibox-content">
+        <div class="row">
+            <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>&nbsp;&nbsp;
+                    <a href="javascript:;" 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;">
+                <form class="form-inline" id="form-search" action="{:url('conveyOrder')}">
+
+                    <div class="input-group">
+                        <input class="form-control" value="{$start}" id="start" readonly placeholder="开始时间" name="start" >
+                    </div>
+                    <div class="input-group">
+                        <input class="form-control" value="{$end}" id="end" readonly placeholder="结束时间" name="end" >
+                    </div>
+                    <div class="input-group" style="width: 200px">
+                        <span class="input-group-addon">选择科室</span>
+                        {:widget_view('common/multiselect',['name'=>'address','lists' =>$addressList, 'val' => $addressVal])}
+                    </div>
+                    <div class="input-group">
+                        <span class="input-group-btn">
+                        <button class="btn-sm btn-primary" type="button" id ="search-btn" ><i class="fa fa-search"></i></button>
+                    </span> &nbsp;
+                        <span class="input-group-btn">
+                        <button class="btn-sm btn-warning" type="button" id="search-clear_cur"><i class="fa fa-undo"></i></button>
+                    </span>
+                    </div>
+                </form>
+            </div>
+        </div>
+    </div>
+    <div class="ibox-content">
+        <div class="jqGrid_wrapper" id="printer">
+            <table id="table" style="border-collapse: collapse"></table>
+            <div id="pager"></div>
+        </div>
+        <!--        <div class="combined">合计:</div>-->
+    </div>
+</div>
+{/block}
+{block name="script"}
+<script src="/static/layDate-v5.0.9/laydate.js"></script>
+<script src="/static/browser.js"></script>
+<script src="/static/jquery.jqprint-0.3.js"></script>
+
+<script>
+    $('#exportBtn').click(function (){
+        var param = $('#form-search').serialize();
+        window.location.href = "{:url('conveyOrderExport')}?"+param;
+    })
+    $('#search-clear_cur').click(function () {
+        $("input[name=address]").val('');
+        $("input[name=start]").val('');
+        $("input[name=end]").val('');
+      window.location.href="{:url('conveyOrder')}";
+    })
+    $(function () {
+        laydate.render({
+            elem: '#start',
+            trigger: 'click' ,
+            theme: '#6eb7ff'
+        });
+        laydate.render({
+            elem: '#end',
+            trigger: 'click' ,
+            theme: '#6eb7ff'
+        });
+
+    });
+    function printer(){
+        $('#printer').jqprint();
+    }
+
+    $(function () {
+        $(window).bind("resize",function(){
+            var width=$(".jqGrid_wrapper").width();
+            $("#table").setGridWidth(width);
+        });
+
+        $.jgrid.defaults.styleUI="Bootstrap";
+        $("#table").jqGrid({
+            url:"{:url('conveyOrder')}",
+            datatype: "json",
+            colModel:[
+                {label:'运送地点',name:'title',index:'title', width:80,sortable: false},
+                {label:'单量',name:'nums',index:'nums', width:80,sortable: false},
+            ],
+            rowNum:10000,
+            sortname: 'id',
+            viewrecords: true,
+            autowidth:true,
+            mtype: 'post',
+            height: 'auto',
+            emptyrecords: "暂无数据",
+            sortorder: "asc",
+            caption:"科室运送单量统计",
+            loadComplete: function (xhr) {
+                if(xhr.code==0){
+                    layer.msg(xhr.msg);
+                    return false;
+                }
+            },
+        });
+    });
+
+
+</script>
+{/block}