Преглед изворни кода

Merge branch 'master' of https://git.7in6.com/Minong/mes-server-api

曹鹤洋 пре 1 година
родитељ
комит
57b09ce517
1 измењених фајлова са 114 додато и 8 уклоњено
  1. 114 8
      application/api/controller/OrderSuperLoss.php

+ 114 - 8
application/api/controller/OrderSuperLoss.php

@@ -339,7 +339,7 @@ class OrderSuperLoss extends Api
         $out_sql = "SELECT fp_sl1,fp_sl2,fp_sl3,fp_sl4,fp_sl5,fp_sl6,fp_sl7,fp_sl8,fp_sl9,fp_sl10,fp_sl11,fp_sl12,fp_sl13,
                         fp_lb1,fp_lb2,fp_lb3,fp_lb4,fp_lb5,fp_lb6,fp_lb7,fp_lb8,fp_lb9,fp_lb10,fp_lb11,fp_lb12,fp_lb13, 
                         fp_bh1,fp_bh2,fp_bh3,fp_bh4,fp_bh5,fp_bh6,fp_bh7,fp_bh8,fp_bh9,fp_bh10,fp_bh11,fp_bh12,fp_bh13,
-                        fp_gxmc1,fp_gxmc2,fp_gxmc3,fp_gxmc4,fp_gxmc5,fp_gxmc6,fp_gxmc7,fp_gxmc8,fp_gxmc9,fp_gxmc10,fp_gxmc11,fp_gxmc12,fp_gxmc13 
+                        fp_gxmc1,fp_gxmc2,fp_gxmc3,fp_gxmc4,fp_gxmc5,fp_gxmc6,fp_gxmc7,fp_gxmc8,fp_gxmc9,fp_gxmc10,fp_gxmc11,fp_gxmc12,fp_gxmc13
                         FROM db_qczl WHERE qczl_gdbh = '{$order}'";
         $waste_out = Db::query($out_sql);
         $list = [];
@@ -371,14 +371,14 @@ class OrderSuperLoss extends Api
         //质检废
         $data['waste_quality'] =  array_sum($quality);
         $plan_total =db('工单_工艺资料')->where(['Gy0_gdbh' => $order, 'Gy0_gxh' => ['in', $gxh_values]])->value('SUM(Gy0_计划损耗)');
-//        halt($plan_total);
+        //单据列表最后统计
+        $total = [];
+        $total['plan_loss'] = 0;
+        $total['total_fp'] = 0;
+        $total['waste_quality'] = 0;
+        $total['waste_intangible'] = 0;
         //按工序打印
         if ($params['type'] == 1){
-            $total = [];
-            $total['plan_loss'] = 0;
-            $total['total_fp'] = 0;
-            $total['waste_quality'] = 0;
-            $total['waste_intangible'] = 0;
             $total['total_waste'] = 0;
             $total['loss'] = 0;
             foreach ($gy_data as $k=>$item){
@@ -414,7 +414,113 @@ class OrderSuperLoss extends Api
             $data['total'] = $total;
             $this->success('请求成功',$data);
         }else{ //按班组打印
+//            halt($data);
+            //总产量数据
+            $total_cl_data = \db('工单_工艺资料')->alias('a')
+                ->field(['a.Gy0_yjno', 'a.Gy0_gxh','a.Gy0_ls', 'SUM(b.sczl_cl) as total_cl', 'SUM(c.sczl_cl) as cl'])
+                ->join('设备_产量计酬 b', 'a.Gy0_gdbh = b.sczl_gdbh AND a.Gy0_gxh = b.sczl_gxh','left')
+                ->join('db_sczl c', 'a.Gy0_gdbh = c.sczl_gdbh AND a.Gy0_gxh = c.sczl_gxh','left')
+                ->where([
+                    'a.Gy0_gdbh' => $order,
+                    'a.Gy0_gxh' => ['IN', $gxh_values]
+                ])
+                ->group('b.sczl_gxh')
+                ->order('a.Gy0_gxh')
+                ->select();
+//            halt($total_cl_data);
+            //按班组分的产量数据
+            $gy_data =db('工单_工艺资料')
+                ->alias('a')
+                ->field([
+                    'a.Gy0_yjno', 'a.Gy0_gxh', 'a.Gy0_ls', 'a.Gy0_计划损耗', 'a.超节损承担比例', 'b.sczl_gxmc',
+                    'SUM(b.sczl_zcfp) as sczl_zcfp', 'SUM(b.sczl_cl) as total_cl',
+                    'b.sczl_bh1', 'b.sczl_bh2', 'b.sczl_bh3', 'b.sczl_bh4', 'b.sczl_bh5', 'b.sczl_bh6',
+                    'b.sczl_bh7', 'b.sczl_bh8', 'b.sczl_bh9', 'b.sczl_bh10',
+                    'rtrim(c.sczl_gxmc) as gxmc', 'SUM(c.sczl_cl) as cl', 'SUM(c.sczl_fp) as fp', 'c.sczl_bh1 as sczl_bh'
+                ])
+                ->join('设备_产量计酬 b', 'a.Gy0_gdbh = b.sczl_gdbh AND a.Gy0_gxh = b.sczl_gxh','left')
+                ->join('db_sczl c', 'a.Gy0_gdbh = c.sczl_gdbh AND a.Gy0_gxh = c.sczl_gxh','left')
+                ->where([
+                    'a.Gy0_gdbh' => $order,
+                    'a.Gy0_gxh' => ['in', $gxh_values]
+                ])
+                ->group('b.sczl_gxh, b.sczl_bh1, b.sczl_bh2, b.sczl_bh3, b.sczl_bh4, c.sczl_bh')
+                ->order('a.Gy0_gxh, b.UniqId DESC, c.UniqId DESC')
+                ->select();
+            foreach ($gy_data as $key=>$value){
+                $gy_data[$key]['Gy0_yjno'] = $value['Gy0_yjno'] > 10 ? $value['Gy0_yjno'] : '0'.$value['Gy0_yjno'];
+                //每道工序的产量(按班组分)
+                $gy_data[$key]['total_cl'] = $value['total_cl'] * $value['Gy0_ls'];
+                if (empty($value['total_cl'])){
+                    $gy_data[$key]['total_cl'] = $value['cl'] * $value['Gy0_ls'];
+                }
+                //计算每道工序的计划损耗
+                foreach ($total_cl_data as $k=>$v){
+                    //每道工序的总产量
+                    $cl = $v['total_cl'] * $v['Gy0_ls'];
+                    if (empty($cl)){
+                        $cl = $v['cl'] * $v['Gy0_ls'];
+                    }
+                    if ($value['Gy0_yjno'] == $v['Gy0_yjno'] && $value['Gy0_gxh'] == $v['Gy0_gxh']){
+                        $gy_data[$key]['计划损耗'] = round($gy_data[$key]['total_cl'] / $cl  * $value['Gy0_计划损耗']);
+                    }
+                }
+                //每道工序的制程废品(按班组分)
+                $gy_data[$key]['sczl_zcfp'] = $value['sczl_zcfp'] * $value['Gy0_ls'];
+                if (empty($value['sczl_zcfp'])){
+                    $gy_data[$key]['sczl_zcfp'] = $value['fp'] * $value['Gy0_ls'];
+                }
+                //计算每道工序的质检废(按班组)
+                $gy_data[$key]['sczl_gxmc'] = $value['sczl_gxmc'];
+                if (empty($value['sczl_gxmc'])){
+                    $gy_data[$key]['sczl_gxmc'] = $value['gxmc'];
+                }
+                if (empty($value['sczl_bh1']) || is_null($value['sczl_bh1'])){
+                    $value['sczl_bh1'] = $value['sczl_bh'];
+                }
+                $gy_data[$key]['sczl_bh1'] = $value['sczl_bh1'];
+                $gy_data[$key]['waste_quality'] = 0;
+                foreach ($waste_out as $entry) {
+                    for ($i = 1; $i <= 13; $i++) {
+                        $gxmcKey = "fp_gxmc" . $i;
+                        $slKey = "fp_sl" . $i;
+                        $bhKey = "fp_bh" . $i;
+                        if ((int)substr($entry[$gxmcKey],0,2) == $value['Gy0_gxh'] && $entry[$bhKey] == $value['sczl_bh1']){
+                            $gy_data[$key]['waste_quality'] += $entry[$slKey];
+
+                        }
+                    }
+                }
+                //无形损分摊
+                $gy_data[$key]['intangible_loss'] = round($gy_data[$key]['计划损耗'] / $plan_total * $data['intangible_loss']);
+                //节损数量
+                $total_waste = $gy_data[$key]['waste_quality'] + $gy_data[$key]['intangible_loss'] +  $gy_data[$key]['sczl_zcfp'];
+                $gy_data[$key]['loss'] = $gy_data[$key]['计划损耗'] - $total_waste;
+                $gy_data[$key]['超节损承担比例'] = number_format($value['超节损承担比例'],4) * 100 .'%';
+                //班组成员
+                $nameArr = [];
+                for ($j = 1; $j <= 10; $j++) {
+                    $bhKey = "sczl_bh" . $j;
+                    if (!empty($value[$bhKey])){
+                        $name = \db('人事_基本资料')->where('员工编号',$value[$bhKey])->value('rtrim(员工姓名)');
+                        array_push($nameArr,$name);
+                    }
+                }
 
+                $gy_data[$key]['member'] = implode(' ',$nameArr);
+                unset($gy_data[$key]['Gy0_计划损耗']);
+                unset($gy_data[$key]['gxmc']);
+                unset($gy_data[$key]['cl']);
+                unset($gy_data[$key]['fp']);
+                unset($gy_data[$key]['sczl_bh']);
+                $total['plan_loss'] += $gy_data[$key]['计划损耗'];
+                $total['total_fp'] += $gy_data[$key]['sczl_zcfp'];
+                $total['waste_quality'] += $gy_data[$key]['waste_quality'];
+                $total['waste_intangible'] += $gy_data[$key]['intangible_loss'];
+            }
+            $data['gy_data'] = $gy_data;
+            $data['total'] = $total;
+            $this->success('请求成功',$data);
         }
     }
     /**
@@ -444,7 +550,7 @@ class OrderSuperLoss extends Api
         if (Request::instance()->isPost() == false) {
             $this->error('非法请求');
         }
-        $params = Request::instance()->request();
+        $params = Request::instance()->post();
         if (!isset($params) || !isset($params[0]['UniqId'])){
             $this->error('参数不能为空');
         }