|
|
@@ -365,10 +365,26 @@ class OrderSuperLoss extends Api
|
|
|
$this->error('参数错误');
|
|
|
}
|
|
|
$order = $params['order'];
|
|
|
- $field = 'Gd_gdbh,rtrim(成品代号) as 成品代号,rtrim(成品名称) as 成品名称,rtrim(销售订单号) as 销售订单号,订单数量,实际投料';
|
|
|
- $data =db('工单_基本资料')->where('Gd_Gdbh',$order)->where('行号',1)->field($field)->find();
|
|
|
+ $field = 'a.Gd_gdbh,rtrim(a.成品代号) as 成品代号,rtrim(a.成品名称) as 成品名称,rtrim(a.销售订单号) as 销售订单号,a.订单数量,c.yj_ls as ls,c.yj_ks as ks,b.st_sl as 投料';
|
|
|
+ $data =db('工单_基本资料')
|
|
|
+ ->alias('a')
|
|
|
+ ->join('物料_收发记录 b','a.Gd_cpdh = b.cpdh')
|
|
|
+ ->join('工单_印件资料 c','c.Yj_Gdbh = a.Gd_gdbh')
|
|
|
+ ->where('a.Gd_Gdbh',$order)
|
|
|
+ ->where('a.行号',$params['yjno'])
|
|
|
+ ->where('c.yj_Yjno',$params['yjno'])
|
|
|
+ ->where('b.仓库编号','Y101')
|
|
|
+ ->field($field)
|
|
|
+ ->find();
|
|
|
+ if ($data['ls'] == 0){
|
|
|
+ $data['ls'] === 1;
|
|
|
+ }
|
|
|
+ if ($data['ks'] == 0){
|
|
|
+ $data['ks'] === 1;
|
|
|
+ }
|
|
|
+ $data['实际投料'] = number_format($data['投料']*$data['ls']*$data['ks']/10000,4);
|
|
|
//查出成品数量及日期
|
|
|
- $cp_sql = "SELECT SUM(jjcp_sl) as cp_sl,MAX(jjcp_sj) as jjcp_sj FROM `成品入仓` WHERE jjcp_gdbh = '{$order}' GROUP BY jjcp_gdbh";
|
|
|
+ $cp_sql = "SELECT SUM(jjcp_sl) as cp_sl,MAX(jjcp_sj) as jjcp_sj FROM `成品入仓` WHERE jjcp_gdbh = '{$order}' AND jjcp_yjno = '{$params['yjno']}' GROUP BY jjcp_gdbh,jjcp_yjno";
|
|
|
$cp_data = Db::query($cp_sql);
|
|
|
if (empty($cp_data)){
|
|
|
$this->success('此工单未查询到成品入库信息,请核查该工单是否已进入超节损');
|
|
|
@@ -377,8 +393,8 @@ class OrderSuperLoss extends Api
|
|
|
$data['warehousing_date'] = substr($cp_data[0]['jjcp_sj'],0,10);
|
|
|
//查出进入超节损的工序,有上报产量的工序就进入超节损
|
|
|
$gxh_sql = "SELECT sczl_gxh FROM
|
|
|
- (SELECT sczl_gxh FROM 设备_产量计酬 WHERE sczl_gdbh = '{$order}'
|
|
|
- UNION SELECT sczl_gxh FROM db_sczl WHERE sczl_gdbh = '{$order}') AS combined_result";
|
|
|
+ (SELECT sczl_gxh FROM 设备_产量计酬 WHERE sczl_gdbh = '{$order}' AND sczl_yjno = '{$params['yjno']}'
|
|
|
+ UNION SELECT sczl_gxh FROM db_sczl WHERE sczl_gdbh = '{$order}' AND sczl_yjno = '{$params['yjno']}') AS combined_result";
|
|
|
$gxh_arr = Db::query($gxh_sql);
|
|
|
$gxh_values = array_column($gxh_arr, 'sczl_gxh');
|
|
|
$gy_data =db('工单_工艺资料')
|
|
|
@@ -387,13 +403,14 @@ class OrderSuperLoss extends Api
|
|
|
'a.Gy0_yjno', 'a.Gy0_gxh', 'RTRIM(a.Gy0_gxmc) as Gy0_gxmc','RTRIM(a.Add_gxmc) as Add_gxmc', 'a.Gy0_ls', 'a.Gy0_计划接货数',
|
|
|
'a.Gy0_计划损耗', 'a.超节损承担比例','SUM(b.sczl_zcfp) as total_fp','SUM(b.sczl_cl) as total_cl','SUM(c.sczl_cl) as cl','SUM(c.sczl_fp) as fp',
|
|
|
])
|
|
|
- ->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')
|
|
|
+ ->join('设备_产量计酬 b', 'a.Gy0_gdbh = b.sczl_gdbh AND a.Gy0_yjno = b.sczl_yjno AND a.Gy0_gxh = b.sczl_gxh','left')
|
|
|
+ ->join('db_sczl c', 'a.Gy0_gdbh = c.sczl_gdbh AND a.Gy0_yjno = c.sczl_yjno AND a.Gy0_gxh = c.sczl_gxh','left')
|
|
|
->where([
|
|
|
'a.Gy0_gdbh' => $order,
|
|
|
+ 'a.Gy0_yjno' => $params['yjno'],
|
|
|
'a.Gy0_gxh' => ['in', $gxh_values]
|
|
|
])
|
|
|
- ->group('a.Gy0_gxh')
|
|
|
+ ->group('a.Gy0_yjno,a.Gy0_gxh')
|
|
|
->select();
|
|
|
$arr = [];
|
|
|
$plan_loss = [];//工单计划损耗
|
|
|
@@ -407,11 +424,11 @@ class OrderSuperLoss extends Api
|
|
|
$real_rate = $cp_data[0]['cp_sl'] / ($data['实际投料'] * 10000) *100;
|
|
|
$data['real_rate'] = number_format($real_rate,2) . '%';//实际合格率
|
|
|
//制程废品
|
|
|
- $zzfp_data =db('设备_产量计酬')->where('sczl_gdbh',$order)->field('SUM(sczl_zcfp) as sczl_zcfp')->select();
|
|
|
+ $zzfp_data =db('设备_产量计酬')->where('sczl_gdbh',$order)->where('sczl_yjno',$params['yjno'])->field('SUM(sczl_zcfp) as sczl_zcfp')->select();
|
|
|
//联数
|
|
|
- $ls =db('工单_工艺资料')->where('Gy0_gdbh',$order)->field('Gy0_ls')->find();
|
|
|
+ $ls =db('工单_工艺资料')->where('Gy0_gdbh',$order)->field('Gy0_ls,Gy0_ks')->find();
|
|
|
//制程废品*ls
|
|
|
- $data['zcfp'] = $zzfp_data[0]['sczl_zcfp'] * $ls['Gy0_ls'];
|
|
|
+ $data['zcfp'] = $zzfp_data[0]['sczl_zcfp'] * $ls['Gy0_ls'] * $ls['Gy0_ks'];
|
|
|
//废品数量
|
|
|
$wasteTotal = db('db_qczl')->where('qczl_gdbh',$order)->sum('qczl_fp');
|
|
|
if (empty($wasteTotal)){
|
|
|
@@ -469,7 +486,7 @@ class OrderSuperLoss extends Api
|
|
|
$data['外发废'] = array_sum($list);//外发废
|
|
|
$data['工单质检废'] = array_sum($quality);//质检废
|
|
|
// $data['分摊废'] = '';//分摊废
|
|
|
- $plan_total =db('工单_工艺资料')->where(['Gy0_gdbh' => $order, 'Gy0_gxh' => ['in', $gxh_values]])->value('SUM(Gy0_计划损耗)');
|
|
|
+ $plan_total =db('工单_工艺资料')->where(['Gy0_gdbh' => $order,'Gy0_yjno' => $params['yjno'], 'Gy0_gxh' => ['in', $gxh_values]])->value('SUM(Gy0_计划损耗)');
|
|
|
//单据列表最后统计
|
|
|
$total = [];
|
|
|
$total['plan_loss'] = 0;
|
|
|
@@ -543,10 +560,11 @@ class OrderSuperLoss extends Api
|
|
|
//总产量数据
|
|
|
$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')
|
|
|
+ ->join('设备_产量计酬 b', 'a.Gy0_gdbh = b.sczl_gdbh AND a.Gy0_yjno = b.sczl_yjno AND a.Gy0_gxh = b.sczl_gxh','left')
|
|
|
+ ->join('db_sczl c', 'a.Gy0_gdbh = c.sczl_gdbh AND a.Gy0_yjno = c.sczl_yjno AND a.Gy0_gxh = c.sczl_gxh','left')
|
|
|
->where([
|
|
|
'a.Gy0_gdbh' => $order,
|
|
|
+ 'a.Gy0_yjno' => $params['yjno'],
|
|
|
'a.Gy0_gxh' => ['IN', $gxh_values],
|
|
|
'b.sczl_cl|c.sczl_cl' => ['>', 0]
|
|
|
])
|
|
|
@@ -563,10 +581,11 @@ class OrderSuperLoss extends Api
|
|
|
'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')
|
|
|
+ ->join('设备_产量计酬 b', 'a.Gy0_gdbh = b.sczl_gdbh AND a.Gy0_yjno = b.sczl_yjno AND a.Gy0_gxh = b.sczl_gxh','left')
|
|
|
+ ->join('db_sczl c', 'a.Gy0_gdbh = c.sczl_gdbh AND a.Gy0_yjno = c.sczl_yjno AND a.Gy0_gxh = c.sczl_gxh','left')
|
|
|
->where([
|
|
|
'a.Gy0_gdbh' => $order,
|
|
|
+ 'a.Gy0_yjno' => $params['yjno'],
|
|
|
'a.Gy0_gxh' => ['in', $gxh_values],
|
|
|
'b.sczl_cl|c.sczl_cl' => ['>', 0]
|
|
|
])
|