Browse Source

优化超节损班组产量为零时数据不准

huangsanjia 1 năm trước cách đây
mục cha
commit
fd7422929b
1 tập tin đã thay đổi với 13 bổ sung4 xóa
  1. 13 4
      application/api/controller/OrderSuperLoss.php

+ 13 - 4
application/api/controller/OrderSuperLoss.php

@@ -371,7 +371,7 @@ class OrderSuperLoss extends Api
         //废品合计
         $waste_total = $data['zcfp'] + $wasteTotal;
         //工单无形损
-        $data['intangible_loss'] = $data['实际投料'] *10000 - $cp_data[0]['cp_sl'] - $waste_total;
+        $data['intangible_loss'] = (int)($data['实际投料'] *10000 - $cp_data[0]['cp_sl'] - $waste_total);
         $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,
@@ -485,7 +485,8 @@ class OrderSuperLoss extends Api
                 ->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]
+                    'a.Gy0_gxh' => ['IN', $gxh_values],
+                    'b.sczl_cl|c.sczl_cl' => ['>', 0]
                 ])
                 ->group('b.sczl_gxh')
                 ->order('a.Gy0_gxh')
@@ -504,12 +505,15 @@ class OrderSuperLoss extends Api
                 ->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]
+                    'a.Gy0_gxh' => ['in', $gxh_values],
+                    'b.sczl_cl|c.sczl_cl' => ['>', 0]
                 ])
                 ->group('b.sczl_gxh, b.sczl_bh1, CASE WHEN b.sczl_bh2 = "000000" THEN "" ELSE b.sczl_bh2 END, b.sczl_bh3, 
                          b.sczl_bh4, b.sczl_bh5, b.sczl_bh6, b.sczl_bh7, b.sczl_bh8, b.sczl_bh9, c.sczl_bh1')
                 ->order('a.Gy0_gxh asc, b.开工时间 asc, c.sczl_rq desc')
+//                ->fetchSql(true)
                 ->select();
+//            halt($gy_data);
             foreach ($gy_data as $key=>$value){
                 $gy_data[$key]['Gy0_yjno'] = $value['Gy0_yjno'] > 10 ? $value['Gy0_yjno'] : '0'.$value['Gy0_yjno'];
                 //每道工序的产量(按班组分)
@@ -574,6 +578,7 @@ class OrderSuperLoss extends Api
                 unset($gy_data[$key]['sczl_bh']);
 
             }
+//            halt($gy_data);
             //重新计算多班组同组长的质检废,质检废 = 班组产量 / 总产量 * 质检废
             $totals = [];
             foreach ($gy_data as $item) {
@@ -596,7 +601,11 @@ class OrderSuperLoss extends Api
                     $item['质检废'] = round($total_cl / $totals[$sczl_bh1]['total'] * $item['质检废']);
                 }
                 //节损数量
-                $total_waste = $item['质检废']  +  $item['sczl_zcfp'];
+                if ($item['无形损分摊'] > 0){
+                    $total_waste = $item['质检废']  +  $item['sczl_zcfp'] + $item['无形损分摊'];
+                }else{
+                    $total_waste = $item['质检废']  +  $item['sczl_zcfp'];
+                }
                 $gy_data[$i]['节损数量'] = $item['计划损耗'] - $total_waste;
                 $i++;
                 $total['plan_loss'] += $item['计划损耗'];