CREATE DEFINER=`root`@`%` PROCEDURE `pro_as_daily_report_update`()
BEGIN
    -- 更新维修开单本日开单台数
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(id) as scount,createOrgSid,deptSid as useOrgSid  FROM yxt_4sas.as_busrepair_bill WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE() GROUP BY `deptSid`,`createOrgSid`) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`busrepairOrder_day`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新维修开单本日保内开单台数
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(id) as scount,createOrgSid,deptSid as useOrgSid,`subject` FROM yxt_4sas.as_busrepair_bill WHERE `subject` = '保内' AND DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE() GROUP BY `deptSid`,`createOrgSid`) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`busrepairOrder_day_inside`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新维修开单本日保外开单台数
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(id) as scount,createOrgSid,deptSid as useOrgSid,`subject` FROM yxt_4sas.as_busrepair_bill WHERE `subject` = '保外' AND DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE() GROUP BY `deptSid`,`createOrgSid`) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`busrepairOrder_day_out`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 更新维修开单本月开单台数
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(id) as scount,createOrgSid,deptSid as useOrgSid  FROM yxt_4sas.as_busrepair_bill WHERE DATE_FORMAT(createTime,'%Y-%m-%d') >= date_add(curdate(), interval - day(curdate()) + 1 day)  AND DATE_FORMAT(createTime,'%Y-%m-%d') <= last_day(curdate()) GROUP BY `deptSid`,`createOrgSid`) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`busrepairOrder_month`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新维修开单本月保内开单台数
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(id) as scount,createOrgSid,deptSid as useOrgSid,`subject` FROM yxt_4sas.as_busrepair_bill WHERE `subject` = '保内' AND DATE_FORMAT(createTime,'%Y-%m-%d') >= date_add(curdate(), interval - day(curdate()) + 1 day)  AND DATE_FORMAT(createTime,'%Y-%m-%d') <= last_day(curdate()) GROUP BY `deptSid`,`createOrgSid`) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`busrepairOrder_month_inside`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新维修开单本月保外开单台数
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(id) as scount,createOrgSid,deptSid as useOrgSid,`subject` FROM yxt_4sas.as_busrepair_bill WHERE `subject` = '保外' AND DATE_FORMAT(createTime,'%Y-%m-%d') >= date_add(curdate(), interval - day(curdate()) + 1 day)  AND DATE_FORMAT(createTime,'%Y-%m-%d') <= last_day(curdate()) GROUP BY `deptSid`,`createOrgSid`) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`busrepairOrder_month_out`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 更新维修开单本年开单台数
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(id) as scount,createOrgSid,deptSid as useOrgSid  FROM yxt_4sas.as_busrepair_bill WHERE DATE_FORMAT(createTime,'%Y-%m-%d') >= date_sub(curdate(), interval dayofyear(curdate())-1 day)  AND DATE_FORMAT(createTime,'%Y-%m-%d') <= concat(year(curdate()),'-12-31') GROUP BY `deptSid`,`createOrgSid`) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`busrepairOrder_year`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新维修开单本年保内开单台数
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(id) as scount,createOrgSid,deptSid as useOrgSid,`subject` FROM yxt_4sas.as_busrepair_bill WHERE `subject` = '保内' AND DATE_FORMAT(createTime,'%Y-%m-%d') >= date_sub(curdate(), interval dayofyear(curdate())-1 day)  AND DATE_FORMAT(createTime,'%Y-%m-%d') <= concat(year(curdate()),'-12-31') GROUP BY `deptSid`,`createOrgSid`) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`busrepairOrder_year_inside`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新维修开单本年保外开单台数
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(id) as scount,createOrgSid,deptSid as useOrgSid,`subject` FROM yxt_4sas.as_busrepair_bill WHERE `subject` = '保外' AND DATE_FORMAT(createTime,'%Y-%m-%d') >= date_sub(curdate(), interval dayofyear(curdate())-1 day)  AND DATE_FORMAT(createTime,'%Y-%m-%d') <= concat(year(curdate()),'-12-31') GROUP BY `deptSid`,`createOrgSid`) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`busrepairOrder_year_out`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新在修车辆
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(id) as scount,createOrgSid,deptSid as useOrgSid,`subject` FROM yxt_4sas.as_busrepair_bill WHERE nodeCode < 4 GROUP BY `deptSid`,`createOrgSid`) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`repair_veh`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新在修保内车辆
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(id) as scount,createOrgSid,deptSid as useOrgSid,`subject` FROM yxt_4sas.as_busrepair_bill WHERE nodeCode < 4 AND `subject` = '保内' GROUP BY `deptSid`,`createOrgSid`) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`repair_veh_inside`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新在修保外车辆
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(id) as scount,createOrgSid,deptSid as useOrgSid,`subject` FROM yxt_4sas.as_busrepair_bill WHERE nodeCode < 4 AND `subject` = '保外' GROUP BY `deptSid`,`createOrgSid`) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`repair_veh_out`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 更新索赔单提报-累计已竣工未提报数量
    UPDATE as_daily_report r INNER JOIN ( SELECT COUNT(*) as scount,deptSid as useOrgSid,createOrgSid FROM
        (SELECT id,deptSid,createOrgSid,receivableAmount FROM
            (SELECT b.*,a.sid claimSid FROM yxt_4sas.as_busrepair_bill as b LEFT JOIN yxt_4sas.as_busclaim_bill as a ON b.sid = a.repairBillSid ) c
         WHERE (c.claimSid IS NULL OR c.claimSid = '') AND c.nodeCode > 4) d GROUP BY d.deptSid,createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`claim_form_noReporting_num`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 更新索赔单提报-累计已竣工未提报金额
    UPDATE as_daily_report r INNER JOIN ( SELECT IFNULL(SUM(receivableAmount),0) as scount,deptSid as useOrgSid,createOrgSid FROM
        (SELECT id,deptSid,createOrgSid,receivableAmount FROM
            (SELECT b.*,a.sid claimSid FROM yxt_4sas.as_busrepair_bill as b LEFT JOIN yxt_4sas.as_busclaim_bill as a ON b.sid = a.repairBillSid ) c
         WHERE (c.claimSid IS NULL OR c.claimSid = '') AND c.nodeCode > 4) d GROUP BY d.deptSid,createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`claim_form_noReporting_amount`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 更新索赔单提报-累计已提报未生效数量
    UPDATE as_daily_report r INNER JOIN ( SELECT COUNT(id) as scount,deptSid as useOrgSid,createOrgSid FROM
        (SELECT id,deptSid,createOrgSid,claimHourAmount,claimGoodsAmount,claimOutAmount,claimSubsidyAmount,claimRescueAmount,claimOtherAmount FROM
            (SELECT b.*,a.sid claimSid,a.isEnable cIsEnable,IFNULL(a.claimHourAmount,0) as claimHourAmount,IFNULL(a.claimGoodsAmount,0) as claimGoodsAmount,
                    IFNULL(a.claimOutAmount,0) as claimOutAmount,IFNULL(a.claimSubsidyAmount,0) as claimSubsidyAmount,IFNULL(a.claimRescueAmount,0) as claimRescueAmount,IFNULL(a.claimOtherAmount,0) as claimOtherAmount FROM yxt_4sas.as_busrepair_bill as b LEFT JOIN yxt_4sas.as_busclaim_bill as a ON b.sid = a.repairBillSid) c WHERE c.claimSid IS NOT NULL AND c.cIsEnable != '1') d GROUP BY d.deptSid,createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`claim_form_reporting_num`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 更新索赔单提报-累计已提报未生效金额
    UPDATE as_daily_report r INNER JOIN ( SELECT (SUM(claimHourAmount) + SUM(claimGoodsAmount) +SUM(claimOutAmount) +SUM(claimSubsidyAmount) +SUM(claimRescueAmount) +SUM(claimOtherAmount)) as scount,deptSid as useOrgSid,createOrgSid FROM
        (SELECT id,deptSid,createOrgSid,claimHourAmount,claimGoodsAmount,claimOutAmount,claimSubsidyAmount,claimRescueAmount,claimOtherAmount FROM
            (SELECT b.*,a.sid claimSid,a.isEnable cIsEnable,IFNULL(a.claimHourAmount,0) as claimHourAmount,IFNULL(a.claimGoodsAmount,0) as claimGoodsAmount,
                    IFNULL(a.claimOutAmount,0) as claimOutAmount,IFNULL(a.claimSubsidyAmount,0) as claimSubsidyAmount,IFNULL(a.claimRescueAmount,0) as claimRescueAmount,IFNULL(a.claimOtherAmount,0) as claimOtherAmount FROM yxt_4sas.as_busrepair_bill as b LEFT JOIN yxt_4sas.as_busclaim_bill as a ON b.sid = a.repairBillSid) c WHERE c.claimSid IS NOT NULL AND c.cIsEnable != '1') d GROUP BY d.deptSid,createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`claim_form_reporting_amount`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 更新营业收入-维修业务本日结算台数
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(*) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_4sas.as_busrepair_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d')=CURDATE()
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`repair_bus_veh_day`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新营业收入-维修业务本日结算金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(settleAmount),0) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_4sas.as_busrepair_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d')=CURDATE()
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`repair_bus_veh_amount_day`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新营业收入-维修业务本日保内结算台数
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(*) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_4sas.as_busrepair_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE b.`subject` = '保内' AND f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d')=CURDATE()
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`repair_bus_veh_inside_day`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新营业收入-维修业务本日保内结算金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(settleAmount),0) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_4sas.as_busrepair_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE b.`subject` = '保内' AND f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d')=CURDATE()
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`repair_bus_veh_inside_amount_day`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新营业收入-维修业务本日保外结算台数
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(*) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_4sas.as_busrepair_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE b.`subject` = '保外' AND f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d')=CURDATE()
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`repair_bus_veh_out_day`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新营业收入-维修业务本日保外结算金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(settleAmount),0) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_4sas.as_busrepair_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE b.`subject` = '保外' AND f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d')=CURDATE()
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`repair_bus_veh_out_amount_day`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新营业收入-配件销售业务本日结算台数
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(*) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_sms.sms_sales_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d')=CURDATE()
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`sales_bus_veh_day`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新营业收入-配件销售业务本日结算金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(settleAmount),0) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_sms.sms_sales_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d')=CURDATE()
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`sales_bus_veh_amount_day`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();


    -- 更新营业收入-维修业务本月结算台数
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(*) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_4sas.as_busrepair_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') >= date_add(curdate(), interval - day(curdate()) + 1 day)  AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') <= last_day(curdate())
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`repair_bus_veh_month`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新营业收入-维修业务本月结算金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(settleAmount),0) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_4sas.as_busrepair_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') >= date_add(curdate(), interval - day(curdate()) + 1 day)  AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') <= last_day(curdate())
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`repair_bus_veh_amount_month`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新营业收入-维修业务本月保内结算台数
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(*) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_4sas.as_busrepair_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE b.`subject` = '保内' AND f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') >= date_add(curdate(), interval - day(curdate()) + 1 day)  AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') <= last_day(curdate())
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`repair_bus_veh_inside_month`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新营业收入-维修业务本月保内结算金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(settleAmount),0) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_4sas.as_busrepair_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE b.`subject` = '保内' AND f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') >= date_add(curdate(), interval - day(curdate()) + 1 day)  AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') <= last_day(curdate())
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`repair_bus_veh_inside_amount_month`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新营业收入-维修业务本月保外结算台数
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(*) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_4sas.as_busrepair_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE b.`subject` = '保外' AND f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') >= date_add(curdate(), interval - day(curdate()) + 1 day)  AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') <= last_day(curdate())
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`repair_bus_veh_out_month`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新营业收入-维修业务本月保外结算金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(settleAmount),0) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_4sas.as_busrepair_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE b.`subject` = '保外' AND f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') >= date_add(curdate(), interval - day(curdate()) + 1 day)  AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') <= last_day(curdate())
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`repair_bus_veh_out_amount_month`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新营业收入-配件销售业务本月结算台数
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(*) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_sms.sms_sales_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') >= date_add(curdate(), interval - day(curdate()) + 1 day)  AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') <= last_day(curdate())
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`sales_bus_veh_month`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新营业收入-配件销售业务本月结算金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(settleAmount),0) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_sms.sms_sales_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') >= date_add(curdate(), interval - day(curdate()) + 1 day)  AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') <= last_day(curdate())
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`sales_bus_veh_amount_month`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();


    -- 更新营业收入-维修业务本年结算台数
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(*) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_4sas.as_busrepair_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') >= date_sub(curdate(), interval dayofyear(curdate())-1 day)  AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') <= concat(year(curdate()),'-12-31')
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`repair_bus_veh_year`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新营业收入-维修业务本年结算金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(settleAmount),0) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_4sas.as_busrepair_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') >= date_sub(curdate(), interval dayofyear(curdate())-1 day)  AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') <= concat(year(curdate()),'-12-31')
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`repair_bus_veh_amount_year`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新营业收入-维修业务本年保内结算台数
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(*) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_4sas.as_busrepair_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE b.`subject` = '保内' AND f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') >= date_sub(curdate(), interval dayofyear(curdate())-1 day)  AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') <= concat(year(curdate()),'-12-31')
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`repair_bus_veh_inside_year`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新营业收入-维修业务本年保内结算金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(settleAmount),0) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_4sas.as_busrepair_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE b.`subject` = '保内' AND f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') >= date_sub(curdate(), interval dayofyear(curdate())-1 day)  AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') <= concat(year(curdate()),'-12-31')
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`repair_bus_veh_inside_amount_year`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新营业收入-维修业务本年保外结算台数
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(*) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_4sas.as_busrepair_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE b.`subject` = '保外' AND f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') >= date_sub(curdate(), interval dayofyear(curdate())-1 day)  AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') <= concat(year(curdate()),'-12-31')
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`repair_bus_veh_out_year`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新营业收入-维修业务本年保外结算金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(settleAmount),0) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_4sas.as_busrepair_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE b.`subject` = '保外' AND f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') >= date_sub(curdate(), interval dayofyear(curdate())-1 day)  AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') <= concat(year(curdate()),'-12-31')
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`repair_bus_veh_out_amount_year`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新营业收入-配件销售业务本年结算台数
    UPDATE as_daily_report r INNER JOIN (SELECT COUNT(*) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_sms.sms_sales_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') >= date_sub(curdate(), interval dayofyear(curdate())-1 day)  AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') <= concat(year(curdate()),'-12-31')
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`sales_bus_veh_year`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 更新营业收入-配件销售业务本年结算金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(settleAmount),0) as scount, deptSid as useOrgSid ,createOrgSid FROM
        (SELECT b.`subject`,b.deptSid,b.createOrgSid,f.settleTime AS createTime,f.settleAmount FROM yxt_sms.sms_sales_bill AS b LEFT JOIN yxt_fms.fms_receivesettle AS f ON b.sid = f.sourceBillSid WHERE f.settleTime IS NOT NULL AND f.settleTime != '' AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') >= date_sub(curdate(), interval dayofyear(curdate())-1 day)  AND DATE_FORMAT(f.settleTime,'%Y-%m-%d') <= concat(year(curdate()),'-12-31')
        ) c GROUP BY c.deptSid,c.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`sales_bus_veh_amount_year`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();


    -- 采购订单-本日数量
    UPDATE as_daily_report r INNER JOIN (	SELECT IFNULL(SUM(d.count),0) as scount,b.deptSid useOrgSid,b.createOrgSid FROM yxt_pms.pms_purchase_bill as b LEFT JOIN yxt_pms.pms_purchase_bill_detail as d ON b.sid = d.billSid WHERE b.nodeState = '已办结' AND DATE_FORMAT(b.createTime,'%Y-%m-%d')=CURDATE() GROUP BY b.deptSid,b.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`purchase_order_day`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 采购订单-本日金额
    UPDATE as_daily_report r INNER JOIN (	SELECT IFNULL(SUM(d.taxPrice),0) as scount,b.deptSid useOrgSid,b.createOrgSid FROM yxt_pms.pms_purchase_bill as b LEFT JOIN yxt_pms.pms_purchase_bill_detail as d ON b.sid = d.billSid WHERE b.nodeState = '已办结' AND DATE_FORMAT(b.createTime,'%Y-%m-%d')=CURDATE() GROUP BY b.deptSid,b.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`purchase_order_amount_day`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 采购订单-本日数量
    UPDATE as_daily_report r INNER JOIN (	SELECT IFNULL(SUM(d.count),0) as scount,b.deptSid useOrgSid,b.createOrgSid FROM yxt_pms.pms_purchase_bill as b LEFT JOIN yxt_pms.pms_purchase_bill_detail as d ON b.sid = d.billSid WHERE b.nodeState = '已办结' AND DATE_FORMAT(b.createTime,'%Y-%m-%d')=CURDATE() GROUP BY b.deptSid,b.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`purchase_order_day`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 采购订单-本日金额
    UPDATE as_daily_report r INNER JOIN (	SELECT IFNULL(SUM(d.amount),0) as scount,b.deptSid useOrgSid,b.createOrgSid FROM yxt_pms.pms_purchase_bill as b LEFT JOIN yxt_pms.pms_purchase_bill_detail as d ON b.sid = d.billSid WHERE b.nodeState = '已办结' AND DATE_FORMAT(b.createTime,'%Y-%m-%d')=CURDATE() GROUP BY b.deptSid,b.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`purchase_order_amount_day`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 采购订单-本月数量
    UPDATE as_daily_report r INNER JOIN (	SELECT IFNULL(SUM(d.count),0) as scount,b.deptSid useOrgSid,b.createOrgSid FROM yxt_pms.pms_purchase_bill as b LEFT JOIN yxt_pms.pms_purchase_bill_detail as d ON b.sid = d.billSid WHERE b.nodeState = '已办结' AND DATE_FORMAT(b.createTime,'%Y-%m-%d') >= date_add(curdate(), interval - day(curdate()) + 1 day)  AND DATE_FORMAT(b.createTime,'%Y-%m-%d') <= last_day(curdate()) GROUP BY b.deptSid,b.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`purchase_order_month`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 采购订单-本月金额
    UPDATE as_daily_report r INNER JOIN (	SELECT IFNULL(SUM(d.amount),0) as scount,b.deptSid useOrgSid,b.createOrgSid FROM yxt_pms.pms_purchase_bill as b LEFT JOIN yxt_pms.pms_purchase_bill_detail as d ON b.sid = d.billSid WHERE b.nodeState = '已办结' AND DATE_FORMAT(b.createTime,'%Y-%m-%d') >= date_add(curdate(), interval - day(curdate()) + 1 day)  AND DATE_FORMAT(b.createTime,'%Y-%m-%d') <= last_day(curdate()) GROUP BY b.deptSid,b.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`purchase_order_amount_month`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 采购订单-本年数量
    UPDATE as_daily_report r INNER JOIN (	SELECT IFNULL(SUM(d.count),0) as scount,b.deptSid useOrgSid,b.createOrgSid FROM yxt_pms.pms_purchase_bill as b LEFT JOIN yxt_pms.pms_purchase_bill_detail as d ON b.sid = d.billSid WHERE b.nodeState = '已办结' AND DATE_FORMAT(b.createTime,'%Y-%m-%d') >= date_sub(curdate(), interval dayofyear(curdate())-1 day)  AND DATE_FORMAT(b.createTime,'%Y-%m-%d') <= concat(year(curdate()),'-12-31') GROUP BY b.deptSid,b.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`purchase_order_year`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 采购订单-本年金额
    UPDATE as_daily_report r INNER JOIN (	SELECT IFNULL(SUM(d.amount),0) as scount,b.deptSid useOrgSid,b.createOrgSid FROM yxt_pms.pms_purchase_bill as b LEFT JOIN yxt_pms.pms_purchase_bill_detail as d ON b.sid = d.billSid WHERE b.nodeState = '已办结' AND DATE_FORMAT(b.createTime,'%Y-%m-%d') >= date_sub(curdate(), interval dayofyear(curdate())-1 day)  AND DATE_FORMAT(b.createTime,'%Y-%m-%d') <= concat(year(curdate()),'-12-31') GROUP BY b.deptSid,b.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`purchase_order_amount_year`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 配件库存-数量
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.count),0) as scount,w.useOrgSid,w.createOrgSid FROM yxt_wms.wms_inventory as w LEFT JOIN  yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid WHERE i.warehouseTypeValue = '配件库' GROUP BY w.useOrgSid,w.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_counts`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 配件库存-金额
    UPDATE as_daily_report r INNER JOIN (SELECT SUM(IFNULL(w.cost,0)*IFNULL(w.count,0)) as scount,w.useOrgSid,w.createOrgSid FROM yxt_wms.wms_inventory as w LEFT JOIN  yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid WHERE i.warehouseTypeValue = '配件库' GROUP BY w.useOrgSid,w.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_amount`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 配件库存-（1-90天）数量
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.count),0) as scount,w.useOrgSid,w.createOrgSid FROM yxt_wms.wms_inventory as w LEFT JOIN  yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid WHERE ( DATEDIFF( NOW(), w.firstInDate ))>= 1 AND ( DATEDIFF( NOW(), w.firstInDate )) <= 90 AND i.warehouseTypeValue = '配件库' GROUP BY w.useOrgSid,w.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_normal`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 配件库存-（1-90天）金额
    UPDATE as_daily_report r INNER JOIN (SELECT SUM(IFNULL(w.cost,0)*IFNULL(w.count,0)) as scount,w.useOrgSid,w.createOrgSid FROM yxt_wms.wms_inventory as w LEFT JOIN  yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid WHERE ( DATEDIFF( NOW(), w.firstInDate ))>= 1 AND ( DATEDIFF( NOW(), w.firstInDate )) <= 90 AND i.warehouseTypeValue = '配件库' GROUP BY w.useOrgSid,w.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_normal_amount`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 配件库存-（91-180天）数量
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.count),0) as scount,w.useOrgSid,w.createOrgSid FROM yxt_wms.wms_inventory as w LEFT JOIN  yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid WHERE ( DATEDIFF( NOW(), w.firstInDate ))>= 91 AND ( DATEDIFF( NOW(), w.firstInDate )) <= 180 AND i.warehouseTypeValue = '配件库' GROUP BY w.useOrgSid,w.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_unsalable`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 配件库存-（91-180天）金额
    UPDATE as_daily_report r INNER JOIN (SELECT SUM(IFNULL(w.cost,0)*IFNULL(w.count,0)) as scount,w.useOrgSid,w.createOrgSid FROM yxt_wms.wms_inventory as w LEFT JOIN  yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid WHERE ( DATEDIFF( NOW(), w.firstInDate ))>= 91 AND ( DATEDIFF( NOW(), w.firstInDate )) <= 180 AND i.warehouseTypeValue = '配件库' GROUP BY w.useOrgSid,w.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_unsalable_amount`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 配件库存-（181-270天）数量
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.count),0) as scount,w.useOrgSid,w.createOrgSid FROM yxt_wms.wms_inventory as w LEFT JOIN  yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid WHERE ( DATEDIFF( NOW(), w.firstInDate ))>= 181 AND ( DATEDIFF( NOW(), w.firstInDate )) <= 270 AND i.warehouseTypeValue = '配件库' GROUP BY w.useOrgSid,w.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_backlog_one`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 配件库存-（181-270天）金额
    UPDATE as_daily_report r INNER JOIN (SELECT SUM(IFNULL(w.cost,0)*IFNULL(w.count,0)) as scount,w.useOrgSid,w.createOrgSid FROM yxt_wms.wms_inventory as w LEFT JOIN  yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid WHERE ( DATEDIFF( NOW(), w.firstInDate ))>= 181 AND ( DATEDIFF( NOW(), w.firstInDate )) <= 270 AND i.warehouseTypeValue = '配件库' GROUP BY w.useOrgSid,w.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_backlog_one_amount`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 配件库存-（271-360天）数量
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.count),0) as scount,w.useOrgSid,w.createOrgSid FROM yxt_wms.wms_inventory as w LEFT JOIN  yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid WHERE ( DATEDIFF( NOW(), w.firstInDate ))>= 271 AND ( DATEDIFF( NOW(), w.firstInDate )) <= 360 AND i.warehouseTypeValue = '配件库' GROUP BY w.useOrgSid,w.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_backlog_two`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 配件库存-（271-360天）金额
    UPDATE as_daily_report r INNER JOIN (SELECT SUM(IFNULL(w.cost,0)*IFNULL(w.count,0)) as scount,w.useOrgSid,w.createOrgSid FROM yxt_wms.wms_inventory as w LEFT JOIN  yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid WHERE ( DATEDIFF( NOW(), w.firstInDate ))>= 271 AND ( DATEDIFF( NOW(), w.firstInDate )) <= 360 AND i.warehouseTypeValue = '配件库' GROUP BY w.useOrgSid,w.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_backlog_two_amount`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 配件库存-（361-720天）数量
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.count),0) as scount,w.useOrgSid,w.createOrgSid FROM yxt_wms.wms_inventory as w LEFT JOIN  yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid WHERE ( DATEDIFF( NOW(), w.firstInDate ))>= 361 AND ( DATEDIFF( NOW(), w.firstInDate )) <= 720 AND i.warehouseTypeValue = '配件库' GROUP BY w.useOrgSid,w.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_backlog_three`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 配件库存-（361-720天）金额
    UPDATE as_daily_report r INNER JOIN (SELECT SUM(IFNULL(w.cost,0)*IFNULL(w.count,0)) as scount,w.useOrgSid,w.createOrgSid FROM yxt_wms.wms_inventory as w LEFT JOIN  yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid WHERE ( DATEDIFF( NOW(), w.firstInDate ))>= 361 AND ( DATEDIFF( NOW(), w.firstInDate )) <= 720 AND i.warehouseTypeValue = '配件库' GROUP BY w.useOrgSid,w.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_backlog_three_amount`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 配件库存-（720以上）数量
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.count),0) as scount,w.useOrgSid,w.createOrgSid FROM yxt_wms.wms_inventory as w LEFT JOIN  yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid WHERE ( DATEDIFF( NOW(), w.firstInDate ))>= 720  AND i.warehouseTypeValue = '配件库' GROUP BY w.useOrgSid,w.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_backlog_four`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 配件库存-（720以上）金额
    UPDATE as_daily_report r INNER JOIN (SELECT SUM(IFNULL(w.cost,0)*IFNULL(w.count,0)) as scount,w.useOrgSid,w.createOrgSid FROM yxt_wms.wms_inventory as w LEFT JOIN  yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid WHERE ( DATEDIFF( NOW(), w.firstInDate ))>= 720 AND i.warehouseTypeValue = '配件库' GROUP BY w.useOrgSid,w.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_backlog_four_amount`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 配件流转-本日入库数量
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.count),0) scount,wi.useOrgSid,wi.createOrgSid FROM yxt_wms.wms_inventory_record as w LEFT JOIN yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid LEFT JOIN yxt_wms.wms_inventory as wi ON w.inventorySid = wi.sid WHERE i.warehouseTypeValue = '配件库' AND w.busTypeKey = 1 AND DATE_FORMAT(w.createTime,'%Y-%m-%d')=CURDATE() GROUP BY wi.useOrgSid,wi.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_in_counts_day`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 配件流转-本日入库金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.amount),0) scount,wi.useOrgSid,wi.createOrgSid FROM yxt_wms.wms_inventory_record as w LEFT JOIN yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid LEFT JOIN yxt_wms.wms_inventory as wi ON w.inventorySid = wi.sid WHERE i.warehouseTypeValue = '配件库' AND w.busTypeKey = 1 AND DATE_FORMAT(w.createTime,'%Y-%m-%d')=CURDATE() GROUP BY wi.useOrgSid,wi.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_in_amount_day`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 配件流转-本月入库数量
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.count),0) scount,wi.useOrgSid,wi.createOrgSid FROM yxt_wms.wms_inventory_record as w LEFT JOIN yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid LEFT JOIN yxt_wms.wms_inventory as wi ON w.inventorySid = wi.sid WHERE i.warehouseTypeValue = '配件库' AND w.busTypeKey = 1 AND DATE_FORMAT(w.createTime,'%Y-%m-%d') >= date_add(curdate(), interval - day(curdate()) + 1 day)  AND DATE_FORMAT(w.createTime,'%Y-%m-%d') <= last_day(curdate()) GROUP BY wi.useOrgSid,wi.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_in_counts_month`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 配件流转-本月入库金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.amount),0) scount,wi.useOrgSid,wi.createOrgSid FROM yxt_wms.wms_inventory_record as w LEFT JOIN yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid LEFT JOIN yxt_wms.wms_inventory as wi ON w.inventorySid = wi.sid WHERE i.warehouseTypeValue = '配件库' AND w.busTypeKey = 1 AND DATE_FORMAT(w.createTime,'%Y-%m-%d') >= date_add(curdate(), interval - day(curdate()) + 1 day)  AND DATE_FORMAT(w.createTime,'%Y-%m-%d') <= last_day(curdate()) GROUP BY wi.useOrgSid,wi.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_in_amount_month`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 配件流转-本年入库数量
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.count),0) scount,wi.useOrgSid,wi.createOrgSid FROM yxt_wms.wms_inventory_record as w LEFT JOIN yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid LEFT JOIN yxt_wms.wms_inventory as wi ON w.inventorySid = wi.sid WHERE i.warehouseTypeValue = '配件库' AND w.busTypeKey = 1 AND DATE_FORMAT(w.createTime,'%Y-%m-%d') >= date_sub(curdate(), interval dayofyear(curdate())-1 day)  AND DATE_FORMAT(w.createTime,'%Y-%m-%d') <= concat(year(curdate()),'-12-31') GROUP BY wi.useOrgSid,wi.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_in_counts_year`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 配件流转-本年入库金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.amount),0) scount,wi.useOrgSid,wi.createOrgSid FROM yxt_wms.wms_inventory_record as w LEFT JOIN yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid LEFT JOIN yxt_wms.wms_inventory as wi ON w.inventorySid = wi.sid WHERE i.warehouseTypeValue = '配件库' AND w.busTypeKey = 1 AND DATE_FORMAT(w.createTime,'%Y-%m-%d') >= date_sub(curdate(), interval dayofyear(curdate())-1 day)  AND DATE_FORMAT(w.createTime,'%Y-%m-%d') <= concat(year(curdate()),'-12-31') GROUP BY wi.useOrgSid,wi.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_in_amount_year`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 配件流转-本日出库数量
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.count),0) scount,wi.useOrgSid,wi.createOrgSid FROM yxt_wms.wms_inventory_record as w LEFT JOIN yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid LEFT JOIN yxt_wms.wms_inventory as wi ON w.inventorySid = wi.sid WHERE i.warehouseTypeValue = '配件库' AND w.busTypeKey = 0 AND DATE_FORMAT(w.createTime,'%Y-%m-%d')=CURDATE() GROUP BY wi.useOrgSid,wi.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_out_counts_day`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 配件流转-本日出库金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.amount),0) scount,wi.useOrgSid,wi.createOrgSid FROM yxt_wms.wms_inventory_record as w LEFT JOIN yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid LEFT JOIN yxt_wms.wms_inventory as wi ON w.inventorySid = wi.sid WHERE i.warehouseTypeValue = '配件库' AND w.busTypeKey = 0 AND DATE_FORMAT(w.createTime,'%Y-%m-%d')=CURDATE() GROUP BY wi.useOrgSid,wi.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_out_amount_day`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 配件流转-本月出库数量
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.count),0) scount,wi.useOrgSid,wi.createOrgSid FROM yxt_wms.wms_inventory_record as w LEFT JOIN yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid LEFT JOIN yxt_wms.wms_inventory as wi ON w.inventorySid = wi.sid WHERE i.warehouseTypeValue = '配件库' AND w.busTypeKey = 0 AND DATE_FORMAT(w.createTime,'%Y-%m-%d') >= date_add(curdate(), interval - day(curdate()) + 1 day)  AND DATE_FORMAT(w.createTime,'%Y-%m-%d') <= last_day(curdate()) GROUP BY wi.useOrgSid,wi.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_out_counts_month`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 配件流转-本月出库金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.amount),0) scount,wi.useOrgSid,wi.createOrgSid FROM yxt_wms.wms_inventory_record as w LEFT JOIN yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid LEFT JOIN yxt_wms.wms_inventory as wi ON w.inventorySid = wi.sid WHERE i.warehouseTypeValue = '配件库' AND w.busTypeKey = 0 AND DATE_FORMAT(w.createTime,'%Y-%m-%d') >= date_add(curdate(), interval - day(curdate()) + 1 day)  AND DATE_FORMAT(w.createTime,'%Y-%m-%d') <= last_day(curdate()) GROUP BY wi.useOrgSid,wi.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_out_amount_month`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 配件流转-本年出库数量
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.count),0) scount,wi.useOrgSid,wi.createOrgSid FROM yxt_wms.wms_inventory_record as w LEFT JOIN yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid LEFT JOIN yxt_wms.wms_inventory as wi ON w.inventorySid = wi.sid WHERE i.warehouseTypeValue = '配件库' AND w.busTypeKey = 0 AND DATE_FORMAT(w.createTime,'%Y-%m-%d') >= date_sub(curdate(), interval dayofyear(curdate())-1 day)  AND DATE_FORMAT(w.createTime,'%Y-%m-%d') <= concat(year(curdate()),'-12-31') GROUP BY wi.useOrgSid,wi.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_out_counts_year`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 配件流转-本年出库金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.amount),0) scount,wi.useOrgSid,wi.createOrgSid FROM yxt_wms.wms_inventory_record as w LEFT JOIN yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid LEFT JOIN yxt_wms.wms_inventory as wi ON w.inventorySid = wi.sid WHERE i.warehouseTypeValue = '配件库' AND w.busTypeKey = 0 AND DATE_FORMAT(w.createTime,'%Y-%m-%d') >= date_sub(curdate(), interval dayofyear(curdate())-1 day)  AND DATE_FORMAT(w.createTime,'%Y-%m-%d') <= concat(year(curdate()),'-12-31') GROUP BY wi.useOrgSid,wi.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`fittings_out_amount_year`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 旧件库存-总数
    UPDATE as_daily_report r INNER JOIN (SELECT SUM(scount) as scount,useOrgSid,createOrgSid  FROM
        (SELECT DISTINCT w.sid,IFNULL(w.count,0) as scount,w.useOrgSid,w.createOrgSid FROM yxt_wms.wms_inventory as w LEFT JOIN  yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid LEFT JOIN yxt_4sas.as_busrepair_inventorybill_detail as d ON w.sid = d.oldInventorySid LEFT JOIN
                                                                                           yxt_4sas.as_busrepair_inventorybill as ab ON d.billSid = ab.sid LEFT JOIN yxt_4sas.as_busrepair_bill as bb ON ab.sourceBillSid = bb.sid WHERE i.warehouseTypeValue = '旧件库' GROUP BY w.useOrgSid,w.createOrgSid) as c) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`old_fittings_all_counts`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 旧件库存-保内总数
    UPDATE as_daily_report r INNER JOIN (SELECT SUM(scount) as scount,useOrgSid,createOrgSid  FROM
        (SELECT DISTINCT w.sid,IFNULL(w.count,0) as scount,w.useOrgSid,w.createOrgSid FROM yxt_wms.wms_inventory as w LEFT JOIN  yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid LEFT JOIN yxt_4sas.as_busrepair_inventorybill_detail as d ON w.sid = d.oldInventorySid LEFT JOIN
                                                                                           yxt_4sas.as_busrepair_inventorybill as ab ON d.billSid = ab.sid LEFT JOIN yxt_4sas.as_busrepair_bill as bb ON ab.sourceBillSid = bb.sid WHERE i.warehouseTypeValue = '旧件库' AND bb.`subject`  = '保内' GROUP BY w.useOrgSid,w.createOrgSid) as c) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`old_fittings_in_counts`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 旧件库存-保外总数
    UPDATE as_daily_report r INNER JOIN (SELECT SUM(scount) as scount,useOrgSid,createOrgSid  FROM
        (SELECT DISTINCT w.sid,IFNULL(w.count,0) as scount,w.useOrgSid,w.createOrgSid FROM yxt_wms.wms_inventory as w LEFT JOIN  yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid LEFT JOIN yxt_4sas.as_busrepair_inventorybill_detail as d ON w.sid = d.oldInventorySid LEFT JOIN
                                                                                           yxt_4sas.as_busrepair_inventorybill as ab ON d.billSid = ab.sid LEFT JOIN yxt_4sas.as_busrepair_bill as bb ON ab.sourceBillSid = bb.sid WHERE i.warehouseTypeValue = '旧件库' AND bb.`subject`  = '保外' GROUP BY w.useOrgSid,w.createOrgSid) as c) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`old_fittings_out_counts`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();


    -- 旧件流转-本日入库数量
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.count),0) scount,wi.useOrgSid,wi.createOrgSid FROM yxt_wms.wms_inventory_record as w LEFT JOIN yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid LEFT JOIN yxt_wms.wms_inventory as wi ON w.inventorySid = wi.sid WHERE i.warehouseTypeValue = '旧件库' AND w.busTypeKey = 1 AND DATE_FORMAT(w.createTime,'%Y-%m-%d')=CURDATE() GROUP BY wi.useOrgSid,wi.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`old_fittings_in_day`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 旧件流转-本月入库数量
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.count),0) scount,wi.useOrgSid,wi.createOrgSid FROM yxt_wms.wms_inventory_record as w LEFT JOIN yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid LEFT JOIN yxt_wms.wms_inventory as wi ON w.inventorySid = wi.sid WHERE i.warehouseTypeValue = '旧件库' AND w.busTypeKey = 1 AND DATE_FORMAT(w.createTime,'%Y-%m-%d') >= date_add(curdate(), interval - day(curdate()) + 1 day)  AND DATE_FORMAT(w.createTime,'%Y-%m-%d') <= last_day(curdate()) GROUP BY wi.useOrgSid,wi.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`old_fittings_in_month`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 旧件流转-本年入库数量
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.count),0) scount,wi.useOrgSid,wi.createOrgSid FROM yxt_wms.wms_inventory_record as w LEFT JOIN yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid LEFT JOIN yxt_wms.wms_inventory as wi ON w.inventorySid = wi.sid WHERE i.warehouseTypeValue = '旧件库' AND w.busTypeKey = 1 AND DATE_FORMAT(w.createTime,'%Y-%m-%d') >= date_sub(curdate(), interval dayofyear(curdate())-1 day)  AND DATE_FORMAT(w.createTime,'%Y-%m-%d') <= concat(year(curdate()),'-12-31') GROUP BY wi.useOrgSid,wi.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`old_fittings_in_year`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 旧件流转-本日出库数量
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.count),0) scount,wi.useOrgSid,wi.createOrgSid FROM yxt_wms.wms_inventory_record as w LEFT JOIN yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid LEFT JOIN yxt_wms.wms_inventory as wi ON w.inventorySid = wi.sid WHERE i.warehouseTypeValue = '旧件库' AND w.busTypeKey = 0 AND DATE_FORMAT(w.createTime,'%Y-%m-%d')=CURDATE() GROUP BY wi.useOrgSid,wi.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`old_fittings_out_day`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 旧件流转-本月出库数量
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.count),0) scount,wi.useOrgSid,wi.createOrgSid FROM yxt_wms.wms_inventory_record as w LEFT JOIN yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid LEFT JOIN yxt_wms.wms_inventory as wi ON w.inventorySid = wi.sid WHERE i.warehouseTypeValue = '旧件库' AND w.busTypeKey = 0 AND DATE_FORMAT(w.createTime,'%Y-%m-%d') >= date_add(curdate(), interval - day(curdate()) + 1 day)  AND DATE_FORMAT(w.createTime,'%Y-%m-%d') <= last_day(curdate()) GROUP BY wi.useOrgSid,wi.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`old_fittings_out_month`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 旧件流转-本年出库数量
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(w.count),0) scount,wi.useOrgSid,wi.createOrgSid FROM yxt_wms.wms_inventory_record as w LEFT JOIN yxt_wms.wms_warehouse_info as i ON w.warehouseSid = i.sid LEFT JOIN yxt_wms.wms_inventory as wi ON w.inventorySid = wi.sid WHERE i.warehouseTypeValue = '旧件库' AND w.busTypeKey = 0 AND DATE_FORMAT(w.createTime,'%Y-%m-%d') >= date_sub(curdate(), interval dayofyear(curdate())-1 day)  AND DATE_FORMAT(w.createTime,'%Y-%m-%d') <= concat(year(curdate()),'-12-31') GROUP BY wi.useOrgSid,wi.createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`old_fittings_out_year`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 旧件流转-本日其中返件
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(d.actualReturnCount),0) scount,c.deptSid as useOrgSid,c.useOrgSid as createOrgSid  FROM yxt_4sas.as_oldpartreturn_confirm_detail as d LEFT JOIN yxt_4sas.as_oldpartreturn_confirm as c ON d.mainSid = c.sid WHERE DATE_FORMAT(c.createTime,'%Y-%m-%d')=CURDATE() GROUP BY c.deptSid,c.useOrgSid
    ) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`old_fittings_out_day`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 旧件流转-本月其中返件
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(d.actualReturnCount),0) scount,c.deptSid as useOrgSid,c.useOrgSid as createOrgSid  FROM yxt_4sas.as_oldpartreturn_confirm_detail as d LEFT JOIN yxt_4sas.as_oldpartreturn_confirm as c ON d.mainSid = c.sid WHERE DATE_FORMAT(c.createTime,'%Y-%m-%d') >= date_add(curdate(), interval - day(curdate()) + 1 day)  AND DATE_FORMAT(c.createTime,'%Y-%m-%d') <= last_day(curdate()) GROUP BY c.deptSid,c.useOrgSid ) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`old_fittings_out_month`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();
    -- 旧件流转-本年其中返件
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(d.actualReturnCount),0) scount,c.deptSid as useOrgSid,c.useOrgSid as createOrgSid  FROM yxt_4sas.as_oldpartreturn_confirm_detail as d LEFT JOIN yxt_4sas.as_oldpartreturn_confirm as c ON d.mainSid = c.sid WHERE DATE_FORMAT(c.createTime,'%Y-%m-%d') >= date_sub(curdate(), interval dayofyear(curdate())-1 day)  AND DATE_FORMAT(c.createTime,'%Y-%m-%d') <= concat(year(curdate()),'-12-31')  GROUP BY c.deptSid,c.useOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`old_fittings_out_year`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 保外未回款-台数
    UPDATE as_daily_report r INNER JOIN (SELECT count(*) as scount,useOrgSid,createOrgSid FROM
        (SELECT * FROM
            (SELECT
                 b.deptSid as useOrgSid,
                 b.createOrgSid,
                 ((SELECT IFNULL(SUM(reveivableMoney),0) FROM anrui_fin.fin_uncollected_receivables_detailed as d WHERE d.contractSid = b.sid)
                     - (SELECT IFNULL(SUM(sd.subscriptionMoney),0) FROM anrui_fin.fin_selected_receivables_detailed as sd LEFT JOIN anrui_fin.fin_uncollected_receivables_detailed as fd ON sd.receivablesSid
                         = fd.sid WHERE sd.auditState = '3' AND fd.contractSid = b.sid)) noMoney
             FROM
                 yxt_4sas.as_busrepair_bill AS b
             WHERE
                     b.outDoorState = 1 AND b.`subject` = '保外') as e WHERE e.noMoney > 0) as m GROUP BY useOrgSid,createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`insurance_out_Payment_counts`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 保外未回款-金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(noMoney),0) as scount,useOrgSid,createOrgSid FROM
        (SELECT * FROM
            (SELECT
                 b.deptSid as useOrgSid,
                 b.createOrgSid,
                 ((SELECT IFNULL(SUM(reveivableMoney),0) FROM anrui_fin.fin_uncollected_receivables_detailed as d WHERE d.contractSid = b.sid)
                     - (SELECT IFNULL(SUM(sd.subscriptionMoney),0) FROM anrui_fin.fin_selected_receivables_detailed as sd LEFT JOIN anrui_fin.fin_uncollected_receivables_detailed as fd ON sd.receivablesSid
                         = fd.sid WHERE sd.auditState = '3' AND fd.contractSid = b.sid)) noMoney
             FROM
                 yxt_4sas.as_busrepair_bill AS b
             WHERE
                     b.outDoorState = 1 AND b.`subject` = '保外') as e WHERE e.noMoney > 0) as m GROUP BY useOrgSid,createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`insurance_out_Payment_amount`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();


    -- 保外未回款-保险欠款台数
    UPDATE as_daily_report r INNER JOIN (SELECT count(*) as scount,useOrgSid,createOrgSid FROM
        (SELECT * FROM
            (SELECT
                 b.deptSid as useOrgSid,
                 b.createOrgSid,
                 ((SELECT IFNULL(SUM(reveivableMoney),0) FROM anrui_fin.fin_uncollected_receivables_detailed as d WHERE d.contractSid = b.sid)
                     - (SELECT IFNULL(SUM(sd.subscriptionMoney),0) FROM anrui_fin.fin_selected_receivables_detailed as sd LEFT JOIN anrui_fin.fin_uncollected_receivables_detailed as fd ON sd.receivablesSid
                         = fd.sid WHERE sd.auditState = '3' AND fd.contractSid = b.sid)) noMoney
             FROM
                 yxt_4sas.as_busrepair_bill AS b
             WHERE
                     b.outDoorState = 1 AND b.`subject` = '保外'
               AND ( SELECT id FROM as_busrepair_bill_insurance AS bi WHERE bi.billSid = b.sid AND bi.claimBillNo IS NOT NULL AND bi.claimBillNo != '') IS NOT NULL
            ) as e WHERE e.noMoney > 0) as m GROUP BY useOrgSid,createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`out_Payment_insurance_counts`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 保外未回款-保险欠款金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(noMoney),0) as scount,useOrgSid,createOrgSid FROM
        (SELECT * FROM
            (SELECT
                 b.deptSid as useOrgSid,
                 b.createOrgSid,
                 ((SELECT IFNULL(SUM(reveivableMoney),0) FROM anrui_fin.fin_uncollected_receivables_detailed as d WHERE d.contractSid = b.sid)
                     - (SELECT IFNULL(SUM(sd.subscriptionMoney),0) FROM anrui_fin.fin_selected_receivables_detailed as sd LEFT JOIN anrui_fin.fin_uncollected_receivables_detailed as fd ON sd.receivablesSid
                         = fd.sid WHERE sd.auditState = '3' AND fd.contractSid = b.sid)) noMoney
             FROM
                 yxt_4sas.as_busrepair_bill AS b
             WHERE
                     b.outDoorState = 1 AND b.`subject` = '保外'
               AND ( SELECT id FROM as_busrepair_bill_insurance AS bi WHERE bi.billSid = b.sid AND bi.claimBillNo IS NOT NULL AND bi.claimBillNo != '') IS NOT NULL
            ) as e WHERE e.noMoney > 0) as m GROUP BY useOrgSid,createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`out_Payment_insurance_debt`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 保外未回款-客户欠款台数
    UPDATE as_daily_report r INNER JOIN (SELECT count(*) as scount,useOrgSid,createOrgSid FROM
        (SELECT * FROM
            (SELECT
                 b.deptSid as useOrgSid,
                 b.createOrgSid,
                 ((SELECT IFNULL(SUM(reveivableMoney),0) FROM anrui_fin.fin_uncollected_receivables_detailed as d WHERE d.contractSid = b.sid)
                     - (SELECT IFNULL(SUM(sd.subscriptionMoney),0) FROM anrui_fin.fin_selected_receivables_detailed as sd LEFT JOIN anrui_fin.fin_uncollected_receivables_detailed as fd ON sd.receivablesSid
                         = fd.sid WHERE sd.auditState = '3' AND fd.contractSid = b.sid)) noMoney
             FROM
                 yxt_4sas.as_busrepair_bill AS b
             WHERE
                     b.outDoorState = 1 AND b.`subject` = '保外'
               AND ( SELECT id FROM as_busrepair_bill_insurance AS bi WHERE bi.billSid = b.sid AND bi.claimBillNo IS NOT NULL AND bi.claimBillNo != '') IS NULL
            ) as e WHERE e.noMoney > 0) as m GROUP BY useOrgSid,createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`out_Payment_customer_counts`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 保外未回款-客户欠款金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(noMoney),0) as scount,useOrgSid,createOrgSid FROM
        (SELECT * FROM
            (SELECT
                 b.deptSid as useOrgSid,
                 b.createOrgSid,
                 ((SELECT IFNULL(SUM(reveivableMoney),0) FROM anrui_fin.fin_uncollected_receivables_detailed as d WHERE d.contractSid = b.sid)
                     - (SELECT IFNULL(SUM(sd.subscriptionMoney),0) FROM anrui_fin.fin_selected_receivables_detailed as sd LEFT JOIN anrui_fin.fin_uncollected_receivables_detailed as fd ON sd.receivablesSid
                         = fd.sid WHERE sd.auditState = '3' AND fd.contractSid = b.sid)) noMoney
             FROM
                 yxt_4sas.as_busrepair_bill AS b
             WHERE
                     b.outDoorState = 1 AND b.`subject` = '保外'
               AND ( SELECT id FROM as_busrepair_bill_insurance AS bi WHERE bi.billSid = b.sid AND bi.claimBillNo IS NOT NULL AND bi.claimBillNo != '') IS NULL
            ) as e WHERE e.noMoney > 0) as m GROUP BY useOrgSid,createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`out_Payment_customer_debt`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 保内未回款-台数
    UPDATE as_daily_report r INNER JOIN (SELECT count(*) as scount,useOrgSid,createOrgSid FROM
        (SELECT * FROM
            (SELECT
                 b.deptSid as useOrgSid,
                 b.createOrgSid,
                 ((SELECT IFNULL(SUM(reveivableMoney),0) FROM anrui_fin.fin_uncollected_receivables_detailed as d WHERE d.contractSid = b.sid)
                     - (SELECT IFNULL(SUM(sd.subscriptionMoney),0) FROM anrui_fin.fin_selected_receivables_detailed as sd LEFT JOIN anrui_fin.fin_uncollected_receivables_detailed as fd ON sd.receivablesSid
                         = fd.sid WHERE sd.auditState = '3' AND fd.contractSid = b.sid)) noMoney
             FROM
                 yxt_4sas.as_busrepair_bill AS b
             WHERE
                     b.outDoorState = 1 AND b.`subject` = '保内') as e WHERE e.noMoney > 0) as m GROUP BY useOrgSid,createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`insurance_in_Payment_counts`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 保内未回款-金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(noMoney),0) as scount,useOrgSid,createOrgSid FROM
        (SELECT * FROM
            (SELECT
                 b.deptSid as useOrgSid,
                 b.createOrgSid,
                 ((SELECT IFNULL(SUM(reveivableMoney),0) FROM anrui_fin.fin_uncollected_receivables_detailed as d WHERE d.contractSid = b.sid)
                     - (SELECT IFNULL(SUM(sd.subscriptionMoney),0) FROM anrui_fin.fin_selected_receivables_detailed as sd LEFT JOIN anrui_fin.fin_uncollected_receivables_detailed as fd ON sd.receivablesSid
                         = fd.sid WHERE sd.auditState = '3' AND fd.contractSid = b.sid)) noMoney
             FROM
                 yxt_4sas.as_busrepair_bill AS b
             WHERE
                     b.outDoorState = 1 AND b.`subject` = '保内') as e WHERE e.noMoney > 0) as m GROUP BY useOrgSid,createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`insurance_in_Payment_amount`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();


    -- 保内未回款-其中已开票台数
    UPDATE as_daily_report r INNER JOIN (SELECT count(*) as scount,useOrgSid,createOrgSid FROM
        (SELECT * FROM
            (SELECT
                 b.deptSid as useOrgSid,
                 b.createOrgSid,
                 ((SELECT IFNULL(SUM(reveivableMoney),0) FROM anrui_fin.fin_uncollected_receivables_detailed as d WHERE d.contractSid = b.sid)
                     - (SELECT IFNULL(SUM(sd.subscriptionMoney),0) FROM anrui_fin.fin_selected_receivables_detailed as sd LEFT JOIN anrui_fin.fin_uncollected_receivables_detailed as fd ON sd.receivablesSid
                         = fd.sid WHERE sd.auditState = '3' AND fd.contractSid = b.sid)) noMoney
             FROM
                 yxt_4sas.as_busrepair_bill AS b
             WHERE
                     b.outDoorState = 1 AND b.`subject` = '保内'
               AND ( SELECT id FROM as_busrepair_bill_invoice AS bi WHERE bi.billSid = b.sid AND bi.isInvoicing = '1') IS NOT NULL
            ) as e WHERE e.noMoney > 0) as m GROUP BY useOrgSid,createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`in_Payment_invoice_counts`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 保内未回款-其中已开票金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(noMoney),0) as scount,useOrgSid,createOrgSid FROM
        (SELECT * FROM
            (SELECT
                 b.deptSid as useOrgSid,
                 b.createOrgSid,
                 ((SELECT IFNULL(SUM(reveivableMoney),0) FROM anrui_fin.fin_uncollected_receivables_detailed as d WHERE d.contractSid = b.sid)
                     - (SELECT IFNULL(SUM(sd.subscriptionMoney),0) FROM anrui_fin.fin_selected_receivables_detailed as sd LEFT JOIN anrui_fin.fin_uncollected_receivables_detailed as fd ON sd.receivablesSid
                         = fd.sid WHERE sd.auditState = '3' AND fd.contractSid = b.sid)) noMoney
             FROM
                 yxt_4sas.as_busrepair_bill AS b
             WHERE
                     b.outDoorState = 1 AND b.`subject` = '保内'
               AND ( SELECT id FROM as_busrepair_bill_invoice AS bi WHERE bi.billSid = b.sid AND bi.isInvoicing = '1') IS NOT NULL
            ) as e WHERE e.noMoney > 0) as m GROUP BY useOrgSid,createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`in_Payment_invoice_amount`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();


    -- 保内未回款-其中未开票台数
    UPDATE as_daily_report r INNER JOIN (SELECT count(*) as scount,useOrgSid,createOrgSid FROM
        (SELECT * FROM
            (SELECT
                 b.deptSid as useOrgSid,
                 b.createOrgSid,
                 ((SELECT IFNULL(SUM(reveivableMoney),0) FROM anrui_fin.fin_uncollected_receivables_detailed as d WHERE d.contractSid = b.sid)
                     - (SELECT IFNULL(SUM(sd.subscriptionMoney),0) FROM anrui_fin.fin_selected_receivables_detailed as sd LEFT JOIN anrui_fin.fin_uncollected_receivables_detailed as fd ON sd.receivablesSid
                         = fd.sid WHERE sd.auditState = '3' AND fd.contractSid = b.sid)) noMoney
             FROM
                 yxt_4sas.as_busrepair_bill AS b
             WHERE
                     b.outDoorState = 1 AND b.`subject` = '保内'
               AND ( SELECT id FROM as_busrepair_bill_invoice AS bi WHERE bi.billSid = b.sid AND bi.isInvoicing = '1') IS NULL
            ) as e WHERE e.noMoney > 0) as m GROUP BY useOrgSid,createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`in_Payment_no_invoice_counts`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

    -- 保内未回款-其中未开票金额
    UPDATE as_daily_report r INNER JOIN (SELECT IFNULL(SUM(noMoney),0) as scount,useOrgSid,createOrgSid FROM
        (SELECT * FROM
            (SELECT
                 b.deptSid as useOrgSid,
                 b.createOrgSid,
                 ((SELECT IFNULL(SUM(reveivableMoney),0) FROM anrui_fin.fin_uncollected_receivables_detailed as d WHERE d.contractSid = b.sid)
                     - (SELECT IFNULL(SUM(sd.subscriptionMoney),0) FROM anrui_fin.fin_selected_receivables_detailed as sd LEFT JOIN anrui_fin.fin_uncollected_receivables_detailed as fd ON sd.receivablesSid
                         = fd.sid WHERE sd.auditState = '3' AND fd.contractSid = b.sid)) noMoney
             FROM
                 yxt_4sas.as_busrepair_bill AS b
             WHERE
                     b.outDoorState = 1 AND b.`subject` = '保内'
               AND ( SELECT id FROM as_busrepair_bill_invoice AS bi WHERE bi.billSid = b.sid AND bi.isInvoicing = '1') IS NULL
            ) as e WHERE e.noMoney > 0) as m GROUP BY useOrgSid,createOrgSid) AS s ON r.useOrgSid=s.useOrgSid AND r.createOrgSid=s.createOrgSid SET r.`in_Payment_no_invoice_amount`=s.scount WHERE DATE_FORMAT(createTime,'%Y-%m-%d')=CURDATE();

END