Browse Source

医废科室月统计

zgg 4 months ago
parent
commit
dd26731372

+ 250 - 0
application/admin/controller/WasteStatistics.php

@@ -1285,6 +1285,256 @@ class WasteStatistics extends Auth {
         echo $res;
     }
 
+    //科室月统计
+    public function wasteDeviceMonth() {
+        $month = input('start',date('Y-m'));
+        $addr_id = input('addr_id','');
+        $type_id = input('type_id','');
+
+        $addressList = (new \app\common\model\Address())->getListByType(7,$this->orgId);
+
+        $tMap[] = ['del','=',0];
+        $tMap[] = ['enable','=',1];
+        //$tMap[] = ['org_id','=',$this->orgId];
+        $typeList1 = Db::name('waste_type')
+            ->where($tMap)
+            ->field('id,title')
+            ->select();
+        if($type_id!=''){
+            $tMap[] = ['id','in',explode(',',$type_id)];
+            $typeList = Db::name('waste_type')
+                ->where($tMap)
+                ->field('id,title,type')
+                ->select();
+
+        }else{
+            $typeList = Db::name('waste_type')
+                ->where($tMap)
+                ->field('id,title,type')
+                ->select();
+
+        }
+
+        $data = $this->wasteDeviceMonthData($month,$addr_id,$type_id);
+
+        $this->assign('data',$data['list']);
+        $this->assign('typeList',$typeList);
+        $this->assign('typeList1',$typeList1);
+        $this->assign('addressList',$addressList);
+        $this->assign('start',$month);
+        $this->assign('addr_id',$addr_id?explode(',',$addr_id):[]);
+        $this->assign('type_id',$type_id?explode(',',$type_id):[]);
+        return $this->fetch();
+    }
+
+    public function wasteDeviceMonthData($month,$addr_id,$type_id){
+
+        $org_id = $this->orgId;
+        $aMap = [];
+        if($addr_id!=''){
+            $aMap[] = ['id','in',explode(',',$addr_id)];
+        }
+        $aMap[]=['','exp',Db::raw("FIND_IN_SET(7,types)")];
+        $dep = Db::name('address')
+            ->where('org_id',$org_id)
+            ->where('enable',1)
+            ->where('del',0)
+            ->where($aMap)
+            ->select();
+
+        $tMap = [];
+        if($type_id!=''){
+            $tMap[] = ['id','in',explode(',',$type_id)];
+        }
+
+        $type = Db::name('waste_type')
+            ->where($tMap)
+            ->where('enable',1)
+            ->where('del',0)
+            ->select();
+
+
+        $date = date('Ym',strtotime($month));
+        $tnum = $tkg = 0;
+
+        $records = Db::name('waste_record')
+            ->where('org_id',$org_id)
+            ->where('del',0)
+            ->where('create_yyyymm',$date)
+            ->field('waste_device_id,cateid,weight,num')
+            ->select();
+
+        foreach ($dep as $k=>$v){
+            $ttkg = $ttnums = 0;
+            foreach ($type as $k1=>$v1){
+
+                $datas = 0;
+                $totals = 0;
+                $weight = 0;
+                $weight2 = 0;
+                $ttnums = 0;
+                $totalkg = 0;
+                $num = '';
+                $totalNum = 0;
+                $num2 = '';
+                $totalNum2 = 0;
+                foreach ($records as $rk=>$rv){
+                    if($rv['waste_device_id'] == $v['id'] && $rv['cateid'] == $v1['id']){
+                        $datas++;
+                        $weight += $rv['weight'];
+//                        $weight2 += $rv['weight'];
+
+                        if($v1['type'] == 1){
+                            $totalNum += $rv['num'];
+                        }
+                    }
+
+                    if($rv['cateid'] == $v1['id']){
+                        if($addr_id!=''){
+                            $addr_ids = explode(',',$addr_id);
+                            if(in_array($rv['waste_device_id'],$addr_ids)){
+                                $totals++;
+                                $weight2 += $rv['weight'];
+                                if($v1['type'] == 1){
+                                    $totalNum2 += $rv['num'];
+                                }
+                            }
+                        }else{
+                            $totals++;
+                            $weight2 += $rv['weight'];
+                            if($v1['type'] == 1){
+                                $totalNum2 += $rv['num'];
+                            }
+                        }
+                    }
+
+                    if($rv['waste_device_id'] == $v['id']){
+                        if($addr_id!=''){
+                            $addr_ids = explode(',',$addr_id);
+                            if(in_array($rv['waste_device_id'],$addr_ids)){
+                                $ttnums++;
+                                $totalkg += $rv['weight'];
+                                if($v1['type'] == 1){
+                                    $totalNum2 += $rv['num'];
+                                }
+                            }
+                        }else{
+                            $ttnums++;
+                            $totalkg += $rv['weight'];
+                            if($v1['type'] == 1){
+                                $totalNum2 += $rv['num'];
+                            }
+                        }
+                    }
+                }
+
+                $dep[$k]['data'][] = $datas;
+                $dep[$k]['total'][] = $totals;
+//                $dep[$k]['data'][] = $weight?round($weight/1000,2):0;
+//                $dep[$k]['total'][] = $weight2?round($weight2/1000,2):0;
+                $dep[$k]['nums']  = $ttnums;
+                $ttkg = $totalkg?round($totalkg/1000,3):0;
+                $dep[$k]['totalkg'] = $ttkg;
+
+                $we =  $weight?round($weight/1000,3):0;
+
+                if($totalNum > 0){
+                    $num = '('.$totalNum.$v1['unit'].')';
+                }
+                $dep[$k]['data'][] = $we.$num;
+
+                $we2 =  $weight2?round($weight2/1000,3):0;
+                if($totalNum2 > 0){
+                    $num2 = '('.$totalNum2.$v1['unit'].')';
+                }
+                $dep[$k]['total'][] =$we2.$num2;
+
+            }
+            $tnum += $ttnums;
+            $tkg += $ttkg;
+        }
+
+        $data = [
+            'list'=>$dep,
+            'tnum'=>$tnum,
+            'tkg'=>$tkg,
+        ];
+
+        return $data;
+    }
+
+    public function wasteDeviceMonthExport()
+    {
+        set_time_limit(0);
+        ini_set("memory_limit", "1024M");
+        $month = input('start',date('Y-m-d'));
+        $addr_id = input('addr_id','');
+        $type_id = input('type_id','');
+        $data = $this->wasteDeviceMonthData($month,$addr_id,$type_id);
+        $data = $data['list'];
+        $tMap[] = ['del','=',0];
+        $tMap[] = ['enable','=',1];
+        if($type_id!=''){
+            $tMap[] = ['id','in',explode(',',$type_id)];
+            $type = Db::name('waste_type')
+                ->where($tMap)
+                ->field('id,title,type')
+                ->select();
+
+        }else{
+            $type = Db::name('waste_type')
+                ->where($tMap)
+                ->field('id,title,type')
+                ->select();
+        }
+
+        $title = '科室月统计';
+        if(!empty($month)){
+            $title = $month.'科室月统计';
+
+        }
+        header("Content-type: application/vnd.ms-excel");
+        header("Content-Type: application/force-download");
+        header("Content-Disposition: attachment; filename=".$title.".xls");
+        header('Expires:0');
+        header('Pragma:public');
+        $res = '';
+        $res.='<table style="border-top: 1px solid #ddd;border-left: 1px solid #ddd;border-spacing: 0;">';
+        $res.='<tr style="background: #ffffff;">
+          <th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" rowspan="2">地点</th>';
+        foreach ($type as $k=>$v){
+            $res.='  <th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" colspan="2">'.$v['title'].'</th>';
+
+        }
+        $res.='<th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd" rowspan="2">备注</th>';
+        $res.='<tr style="background: #ffffff;">';
+        foreach ($type as $v){
+            $res.=' <th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">件数/包</th>
+            <th style="text-align: center;background: #ffffff;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">重量kg</th>';
+        }
+        foreach ($data as $k=>$v){
+            $res.='<tr style="background: #ffffff;">';
+            $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v['title'].'</td>';
+            foreach ($v['data'] as $k1=>$v1){
+                $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1.'</td>';
+            }
+            $res.='<td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd"></td>';
+            $res.='</tr>';
+
+        }
+        $res.='<tr style="background: #ffffff;">
+               <td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">共计:</td>';
+        if(!empty($data)){
+            foreach ($data[0]['total'] as $k1=>$v1){
+                $res.=' <td style="text-align: center;border-bottom: 1px solid #ddd;border-right: 1px solid #ddd">'.$v1.'</td>';
+            }
+        }
+        $res.='<td style="border-bottom: 1px solid #ddd;border-right: 1px solid #ddd"></td>
+       </tr>';
+        echo $res;
+
+    }
+
     // 医废年统计
     public function wasteYears() {
         $month = input('start',date('Y'));

+ 132 - 0
application/admin/view/waste_statistics/waste_device_month.html

@@ -0,0 +1,132 @@
+{extend name="common/common2" /}
+{block name="main"}
+<style>
+    .table th{
+        text-align: center;
+        background: #ffffff;
+    }
+    .table tr{
+        background: #ffffff;
+    }
+    .table td{
+        text-align: center;
+    }
+</style>
+<div class="ibox-content">
+    <div class="ibox">
+
+        <div class="alert">
+            <form action="wasteDeviceMonth" method="GET" id='search_form' class="form-inline">
+                <div class="input-group" style="width: 200px">
+                    <span class="input-group-addon">选择日期</span>
+                    <input class="form-control dialog-datetime" id="startTime" name="start" type="text" data-date-format="yyyy-mm" value="{$start}" placeholder="" readonly/>
+                </div>
+
+                <div class="input-group" style="width: 200px">
+                    <span class="input-group-addon">选择类型</span>
+                    {:widget_view('common/multiselect',['name'=>'type_id','lists' =>$typeList1, 'val' => $type_id])}
+                </div>
+                <div class="input-group" style="width: 200px">
+                    <span class="input-group-addon">选择地点</span>
+                    {:widget_view('common/multiselect',['name'=>'addr_id','lists' =>$addressList, 'val' => $addr_id])}
+                </div>
+                <div class="input-group">
+            <span class="input-group-btn">
+                <button class="btn-sm btn-primary" type="submit"  ><i class="fa fa-search"></i></button>
+			</span>&nbsp;
+                    <span class="input-group-btn">
+                     <button class="btn-sm btn-warning" type="reset" onclick="empty_search()"><i class="fa fa-undo"></i></button>
+            </span>
+                </div>
+            </form>
+        </div>
+
+        <div class="panel-group">
+            <div class="panel panel-default">
+                <div class="panel-heading clearfix">
+                    <div class="btn-group pull-left">
+                        科室月统计
+                    </div>
+                    <div class="btn-group pull-right">
+                        <a href="javascript:;" onclick="printer()" class="btn btn-sm btn btn-primary"><i class="glyphicon glyphicon-print"></i>打印</a>
+                        <a href="javascript:;" onclick="exportExcel()" class="btn btn-success btn-sm"><i class="glyphicon glyphicon-download"></i>导出</a>
+                    </div>
+                </div>
+                <div class="panel-body" id="printer">
+                    <table class="table table-bordered">
+                        <thead>
+                        <tr>
+                            <th rowspan="2">科室</th>
+                            {foreach $typeList as $k=>$v}
+                            <th colspan="2">{$v['title']}</th>
+                            {/foreach}
+                            <th rowspan="2">备注</th>
+                        </tr>
+                        <tr>
+                            {foreach $typeList as $k=>$v}
+                            <th>件数/包</th>
+                            <th>重量kg</th>
+                            {/foreach}
+                        </tr>
+
+                        </thead>
+                        <tbody>
+                        {foreach $data as $k=>$v}
+                        <tr>
+                            <td>{$v['title']}</td>
+                            {if !empty($v['data'])}
+                            {foreach $v['data'] as $k1=>$v1}
+                            <td>{$v1}</td>
+                            {/foreach}
+                            {/if}
+                            <td></td>
+                        </tr>
+                        {/foreach}
+                        <tr>
+                            <td>共计:</td>
+                            {if !empty($data) && isset($data[0]['total'])}
+                            {foreach $data[0]['total'] as $k1=>$v1}
+                            <td>{$v1}</td>
+                            {/foreach}
+                            {/if}
+                            <td></td>
+                        </tr>
+                        </tbody>
+                    </table>
+                </div>
+            </div>
+        </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>
+    $(function () {
+        laydate.render({
+            elem: '#startTime',
+            trigger: 'click',
+            theme: '#148d8f',
+            type:'month'
+        });
+        laydate.render({
+            elem: '#endTime',
+            trigger: 'click',
+            theme: '#148d8f'
+        });
+    });
+    function empty_search(){
+        window.location.href = 'wasteDeviceMonth';
+    }
+    function printer(){
+        $('#printer').jqprint();
+    }
+
+    function exportExcel() {
+        window.location.href = "wasteDeviceMonthExport?"+$('#search_form').serialize();
+    }
+
+</script>
+{/block}