diff --git a/doc/databases/统计报表更新.sql b/doc/databases/统计报表更新.sql index 62334033f7..d57813d944 100644 --- a/doc/databases/统计报表更新.sql +++ b/doc/databases/统计报表更新.sql @@ -413,7 +413,8 @@ BEGIN left join anrui_buscenter.bus_sales_order_price bp on bp.salesOrderSid = bo.sid left join anrui_scm.scm_purchase_channel scc on scc.saleOrderSid = bo.sid WHERE bo.nodeState = '已办结' - and bo.type = 3 and scc.state = 2 + and bo.type = 3 + and scc.state = 2 GROUP BY bo.useOrgSid, bm.modelSid, bm.modelConfigSid, @@ -428,14 +429,17 @@ BEGIN LEFT JOIN anrui_buscenter.bus_sales_order_model bm ON bm.salesOrderSid = bo.sid left join anrui_buscenter.bus_sales_order_price bp on bp.salesOrderSid = bo.sid left join anrui_scm.scm_purchase_channel scc on scc.saleOrderSid = bo.sid - left join anrui_buscenter.bus_sales_order_vehicle bvvv on bvvv.salesOrderSid = bo.sid + left join anrui_buscenter.bus_sales_order_vehicle bvvv + on bvvv.salesOrderSid = bo.sid WHERE bo.nodeState = '已办结' - and bo.type = 3 and scc.state is null and length(bvvv.linkSid)>0 + and bo.type = 3 + and scc.state is null + and length(bvvv.linkSid) > 0 GROUP BY bo.useOrgSid, bm.modelSid, bm.modelConfigSid, bo.contractNo - ) d + ) d group by d.useOrgSid, d.modelSid, d.modelConfigSid, @@ -456,7 +460,8 @@ BEGIN left join anrui_base.base_vehicle_out bvo on bv.sid = bvo.vinSid left join anrui_base.base_vehicle_out_apply bvoa on bvoa.sid = bvo.mainSid where bv.salesDate like concat('%', CURDATE(), '%') - and bvoa.saleTypeKey = '001' and bvo.isDelete = 0 + and bvoa.saleTypeKey = '001' + and bvo.isDelete = 0 and (bvo.materialTypeKey = '001' or bvo.materialTypeValue is null or length(bvo.materialTypeValue) = 0) group by bv.useOrgSid, bv.modelSid, bv.modelConfigSid) ss @@ -474,7 +479,8 @@ BEGIN left join anrui_base.base_vehicle_out bvo on bv.sid = bvo.vinSid left join anrui_base.base_vehicle_out_apply bvoa on bvoa.sid = bvo.mainSid where bv.salesDate like concat('%', CURDATE(), '%') - and bvoa.saleTypeKey = '002' and bvo.isDelete = 0 + and bvoa.saleTypeKey = '002' + and bvo.isDelete = 0 and (bvo.materialTypeKey = '001' or bvo.materialTypeValue is null or length(bvo.materialTypeValue) = 0) group by bv.useOrgSid, bv.modelSid, bv.modelConfigSid) ss @@ -499,7 +505,8 @@ BEGIN left join anrui_base.base_vehicle_out bvo on bv.sid = bvo.vinSid left join anrui_base.base_vehicle_out_apply bvoa on bvoa.sid = bvo.mainSid where bv.salesDate like concat('%', DATE_FORMAT(CURDATE(), '%Y-%m'), '%') - and bvoa.saleTypeKey = '001' and bvo.isDelete = 0 + and bvoa.saleTypeKey = '001' + and bvo.isDelete = 0 and (bvo.materialTypeKey = '001' or bvo.materialTypeValue is null or length(bvo.materialTypeValue) = 0) group by bv.useOrgSid, bv.modelSid, bv.modelConfigSid) ss @@ -517,7 +524,8 @@ BEGIN left join anrui_base.base_vehicle_out bvo on bv.sid = bvo.vinSid left join anrui_base.base_vehicle_out_apply bvoa on bvoa.sid = bvo.mainSid where bv.salesDate like concat('%', DATE_FORMAT(CURDATE(), '%Y-%m'), '%') - and bvoa.saleTypeKey = '002' and bvo.isDelete = 0 + and bvoa.saleTypeKey = '002' + and bvo.isDelete = 0 and (bvo.materialTypeKey = '001' or bvo.materialTypeValue is null or length(bvo.materialTypeValue) = 0) group by bv.useOrgSid, bv.modelSid, bv.modelConfigSid) ss @@ -542,7 +550,8 @@ BEGIN left join anrui_base.base_vehicle_out bvo on bv.sid = bvo.vinSid left join anrui_base.base_vehicle_out_apply bvoa on bvoa.sid = bvo.mainSid where bv.salesDate like concat('%', DATE_FORMAT(CURDATE(), '%Y'), '%') - and bvoa.saleTypeKey = '001' and bvo.isDelete = 0 + and bvoa.saleTypeKey = '001' + and bvo.isDelete = 0 and (bvo.materialTypeKey = '001' or bvo.materialTypeValue is null or length(bvo.materialTypeValue) = 0) group by bv.useOrgSid, bv.modelSid, bv.modelConfigSid) ss @@ -560,7 +569,8 @@ BEGIN left join anrui_base.base_vehicle_out bvo on bv.sid = bvo.vinSid left join anrui_base.base_vehicle_out_apply bvoa on bvoa.sid = bvo.mainSid where bv.salesDate like concat('%', DATE_FORMAT(CURDATE(), '%Y'), '%') - and bvoa.saleTypeKey = '002' and bvo.isDelete = 0 + and bvoa.saleTypeKey = '002' + and bvo.isDelete = 0 and (bvo.materialTypeKey = '001' or bvo.materialTypeValue is null or length(bvo.materialTypeValue) = 0) group by bv.useOrgSid, bv.modelSid, bv.modelConfigSid) ss @@ -1060,236 +1070,7 @@ BEGIN set arrears_carry_veh_amount = ROUND(s.scount / 10000, 2) where DATE_FORMAT(createTime, '%Y-%m-%d') = CURDATE(); - --- 金融未放款数量--- 截止当日贷款业务已出库且融资放款未认款的台数。 - update daily_report r inner join ( - SELECT sum(b.scount) AS scount, - b.useOrgSid, - b.NAME, - b.contractNo, - b.vehMConfigSid, - b.vehModelSid - from (SELECT count(a.id) AS scount, - a.useOrgSid, - a.NAME, - a.contractNo, - a.vehMConfigSid, - a.vehModelSid - FROM ( - SELECT bv.id, - bo.useOrgSid, - bm.modelConfigSid AS vehMConfigSid, - bm.modelSid AS vehModelSid, - so.NAME, - SUM(s.reveivableMoney), - SUM(s.subscriptionMoney), - bo.contractNo - FROM anrui_buscenter.bus_sales_order_vehicle bv - LEFT JOIN anrui_buscenter.bus_sales_order bo ON bo.sid = bv.salesOrderSid - LEFT JOIN anrui_base.base_vehicle bbv ON bbv.sid = bv.linkSid - LEFT JOIN anrui_buscenter.bus_sales_order_model bm - ON bm.salesOrderSid = bv.salesOrderSid - LEFT JOIN ( - SELECT fd.reveivableMoney, - fd.busVinSid, - IFNULL(SUM(fs.subscriptionMoney), 0) AS subscriptionMoney - FROM anrui_fin.fin_uncollected_receivables_detailed fd - LEFT JOIN anrui_fin.fin_selected_receivables_detailed fs - ON fs.receivablesSid = fd.sid - WHERE fd.kxState = '01' - AND fs.auditState = 3 - AND fd.receivablesName = '融资放款' - GROUP BY fd.sid - UNION ALL - SELECT fd.reveivableMoney, - fd.busVinSid, - 0 AS subscriptionMoney - FROM anrui_fin.fin_uncollected_receivables_detailed fd - WHERE fd.kxState = '01' - AND fd.receivablesName = '融资放款' - AND fd.sid NOT IN (SELECT fs.`receivablesSid` - FROM anrui_fin.fin_selected_receivables_detailed fs - WHERE fs.`auditState` = 3 - AND fs.`receivablesName` = '融资放款') - GROUP BY fd.sid - ) s ON s.busVinSid = bv.sid - LEFT JOIN anrui_portal.sys_organization so ON so.sid = bo.useOrgSid - WHERE bo.payTypeKey = 2 - AND bbv.vehicleState = '0002' - GROUP BY bv.sid, - bo.useOrgSid, - bm.modelSid, - bm.modelConfigSid - HAVING SUM(s.reveivableMoney) > SUM(s.subscriptionMoney)) a - GROUP BY a.contractNo, - a.useOrgSid, - a.vehMConfigSid, - a.vehModelSid - union all - SELECT count(a.id) AS scount, - a.useOrgSid, - a.NAME, - a.contractNo, - a.vehMConfigSid, - a.vehModelSid - FROM ( - SELECT bv.id, - bo.useOrgSid, - bm.modelConfigSid AS vehMConfigSid, - bm.modelSid AS vehModelSid, - so.NAME, - bo.contractNo, - IFNULL(sss.money, '0') as money - FROM anrui_buscenter.bus_sales_order_vehicle bv - LEFT JOIN anrui_buscenter.bus_sales_order bo ON bo.sid = bv.salesOrderSid - LEFT JOIN anrui_base.base_vehicle bbv ON bbv.sid = bv.linkSid - LEFT JOIN anrui_buscenter.bus_sales_order_model bm - ON bm.salesOrderSid = bv.salesOrderSid - LEFT JOIN anrui_portal.sys_organization so ON so.sid = bo.useOrgSid - LEFT JOIN (SELECT furd.busVinSid - FROM anrui_fin.fin_uncollected_receivables_detailed furd - WHERE furd.receivablesName = '融资放款' - group by furd.busVinSid) ss ON ss.busVinSid = bv.sid - LEFT JOIN ( - SELECT (ls.loanTotal - lo.loanDownPay) AS money, - ls.salesOrderSid - FROM anrui_riskcenter.loan_solutions ls - LEFT JOIN anrui_riskcenter.loan_solutions_otherpolicy lo ON lo.solutionsSid = ls.sid - ) sss ON sss.salesOrderSid = bv.salesOrderSid - WHERE bo.payTypeKey = 2 - and ss.busVinSid is null - AND bbv.vehicleState = '0002' - and bo.nodeState = '已办结' - and bo.contractNo NOT LIKE '%2023%' - GROUP BY bv.sid, - bo.useOrgSid, - bm.modelSid, - bm.modelConfigSid - having money > 0 - ) a - GROUP BY a.contractNo, - a.useOrgSid, - a.vehMConfigSid, - a.vehModelSid) b - group by b.useOrgSid, b.vehModelSid, b.vehMConfigSid) as s on - r.useOrgSid = s.useOrgSid AND r.vehModelSid = s.vehModelSid AND r.vehMConfigSid = s.vehMConfigSid - SET r.`loan_not_count`=s.scount - WHERE DATE_FORMAT(createTime, '%Y-%m-%d') = CURDATE(); - --- 金融未放款金额-- 截止当日贷款业务已出库且融资放款未认款的台数融资放款金额之和 - - update daily_report r inner join ( - select SUM(b.scount) AS scount, - b.useOrgSid, - b.NAME, - b.contractNo, - b.vehMConfigSid, - b.vehModelSid - from (SELECT SUM(a.scount) AS scount, - a.useOrgSid, - a.NAME, - a.contractNo, - a.vehMConfigSid, - a.vehModelSid - FROM (SELECT bv.id, - bo.useOrgSid, - bm.modelConfigSid AS vehMConfigSid, - bm.modelSid AS vehModelSid, - so.NAME, - SUM(s.reveivableMoney), - SUM(s.subscriptionMoney), - bo.contractNo, - ( - SUM(s.reveivableMoney) - SUM(s.subscriptionMoney)) AS scount - FROM anrui_buscenter.bus_sales_order_vehicle bv - LEFT JOIN anrui_buscenter.bus_sales_order bo ON bo.sid = bv.salesOrderSid - LEFT JOIN anrui_base.base_vehicle bbv ON bbv.sid = bv.linkSid - LEFT JOIN anrui_buscenter.bus_sales_order_model bm ON bm.salesOrderSid = bv.salesOrderSid - LEFT JOIN ( - SELECT fd.reveivableMoney, - fd.busVinSid, - IFNULL(SUM(fs.subscriptionMoney), 0) AS subscriptionMoney - FROM anrui_fin.fin_uncollected_receivables_detailed fd - LEFT JOIN anrui_fin.fin_selected_receivables_detailed fs ON fs.receivablesSid = fd.sid - WHERE fd.kxState = '01' - AND fs.auditState = 3 - AND fd.receivablesName = '融资放款' - GROUP BY fd.sid - UNION ALL - SELECT fd.reveivableMoney, - fd.busVinSid, - 0 AS subscriptionMoney - FROM anrui_fin.fin_uncollected_receivables_detailed fd - WHERE fd.kxState = '01' - AND fd.receivablesName = '融资放款' - AND fd.sid NOT IN (SELECT fs.`receivablesSid` - FROM anrui_fin.fin_selected_receivables_detailed fs - WHERE fs.`auditState` = 3 - AND fs.`receivablesName` = '融资放款') - GROUP BY fd.sid - ) s ON s.busVinSid = bv.sid - LEFT JOIN anrui_portal.sys_organization so ON so.sid = bo.useOrgSid - WHERE bo.payTypeKey = 2 - - AND bbv.vehicleState = '0002' - GROUP BY bv.sid, bo.useOrgSid, bm.modelSid, bm.modelConfigSid - HAVING SUM(s.reveivableMoney) > SUM(s.subscriptionMoney)) a - GROUP BY a.contractNo, a.useOrgSid, - a.vehMConfigSid, - a.vehModelSid - union all - - SELECT sum(a.money) AS scount, - a.useOrgSid, - a.NAME, - a.contractNo, - a.vehMConfigSid, - a.vehModelSid - FROM ( - SELECT bo.useOrgSid, - bm.modelConfigSid AS vehMConfigSid, - bm.modelSid AS vehModelSid, - so.NAME, - bo.contractNo, - IFNULL(sss.money, '0') as money - FROM anrui_buscenter.bus_sales_order_vehicle bv - LEFT JOIN anrui_buscenter.bus_sales_order bo ON bo.sid = bv.salesOrderSid - LEFT JOIN anrui_base.base_vehicle bbv ON bbv.sid = bv.linkSid - LEFT JOIN anrui_buscenter.bus_sales_order_model bm - ON bm.salesOrderSid = bv.salesOrderSid - LEFT JOIN anrui_portal.sys_organization so ON so.sid = bo.useOrgSid - LEFT JOIN (SELECT furd.busVinSid - FROM anrui_fin.fin_uncollected_receivables_detailed furd - WHERE furd.receivablesName = '融资放款' - group by furd.busVinSid) ss ON ss.busVinSid = bv.sid - LEFT JOIN ( - SELECT (ls.loanTotal - lo.loanDownPay) AS money, - ls.salesOrderSid - FROM anrui_riskcenter.loan_solutions ls - LEFT JOIN anrui_riskcenter.loan_solutions_otherpolicy lo ON lo.solutionsSid = ls.sid - ) sss ON sss.salesOrderSid = bv.salesOrderSid - WHERE bo.payTypeKey = 2 - and ss.busVinSid is null - AND bbv.vehicleState = '0002' - and bo.nodeState = '已办结' - and bo.contractNo NOT LIKE '%2023%' - GROUP BY bv.sid, - bo.useOrgSid, - bm.modelSid, - bm.modelConfigSid - having money > 0 - ) a - GROUP BY a.contractNo, - a.useOrgSid, - a.vehMConfigSid, - a.vehModelSid) b - group by b.useOrgSid, b.vehModelSid, b.vehMConfigSid) as s on - r.useOrgSid = s.useOrgSid AND r.vehModelSid = s.vehModelSid AND r.vehMConfigSid = s.vehMConfigSid - SET r.`loan_not_amount`=ROUND(s.scount / 10000, 2) - WHERE DATE_FORMAT(createTime, '%Y-%m-%d') = CURDATE(); - - --- 全年厂家开票数 + -- 全年厂家开票数 UPDATE daily_report r INNER JOIN (SELECT COUNT(id) AS scount, `useOrgSid`, `modelSid`, `modelConfigSid` FROM anrui_base.`base_vehicle` WHERE manDate like concat('%', DATE_FORMAT(CURDATE(), '%Y'), '%') @@ -1298,8 +1079,238 @@ BEGIN SET r.`manufacturer_invoicing_year`=s.scount WHERE DATE_FORMAT(createTime, '%Y-%m-%d') = CURDATE(); + + -- 金融未放款数量--- 截止当日贷款业务已出库且融资放款未认款的台数。 + /* update daily_report r inner join ( + SELECT sum(b.scount) AS scount, + b.useOrgSid, + b.NAME, + b.contractNo, + b.vehMConfigSid, + b.vehModelSid + from (SELECT count(a.id) AS scount, + a.useOrgSid, + a.NAME, + a.contractNo, + a.vehMConfigSid, + a.vehModelSid + FROM ( + SELECT bv.id, + bo.useOrgSid, + bm.modelConfigSid AS vehMConfigSid, + bm.modelSid AS vehModelSid, + so.NAME, + SUM(s.reveivableMoney), + SUM(s.subscriptionMoney), + bo.contractNo + FROM anrui_buscenter.bus_sales_order_vehicle bv + LEFT JOIN anrui_buscenter.bus_sales_order bo ON bo.sid = bv.salesOrderSid + LEFT JOIN anrui_base.base_vehicle bbv ON bbv.sid = bv.linkSid + LEFT JOIN anrui_buscenter.bus_sales_order_model bm + ON bm.salesOrderSid = bv.salesOrderSid + LEFT JOIN ( + SELECT fd.reveivableMoney, + fd.busVinSid, + IFNULL(SUM(fs.subscriptionMoney), 0) AS subscriptionMoney + FROM anrui_fin.fin_uncollected_receivables_detailed fd + LEFT JOIN anrui_fin.fin_selected_receivables_detailed fs + ON fs.receivablesSid = fd.sid + WHERE fd.kxState = '01' + AND fs.auditState = 3 + AND fd.receivablesName = '融资放款' + GROUP BY fd.sid + UNION ALL + SELECT fd.reveivableMoney, + fd.busVinSid, + 0 AS subscriptionMoney + FROM anrui_fin.fin_uncollected_receivables_detailed fd + WHERE fd.kxState = '01' + AND fd.receivablesName = '融资放款' + AND fd.sid NOT IN (SELECT fs.`receivablesSid` + FROM anrui_fin.fin_selected_receivables_detailed fs + WHERE fs.`auditState` = 3 + AND fs.`receivablesName` = '融资放款') + GROUP BY fd.sid + ) s ON s.busVinSid = bv.sid + LEFT JOIN anrui_portal.sys_organization so ON so.sid = bo.useOrgSid + WHERE bo.payTypeKey = 2 + AND bbv.vehicleState = '0002' + GROUP BY bv.sid, + bo.useOrgSid, + bm.modelSid, + bm.modelConfigSid + HAVING SUM(s.reveivableMoney) > SUM(s.subscriptionMoney)) a + GROUP BY a.contractNo, + a.useOrgSid, + a.vehMConfigSid, + a.vehModelSid + union all + SELECT count(a.id) AS scount, + a.useOrgSid, + a.NAME, + a.contractNo, + a.vehMConfigSid, + a.vehModelSid + FROM ( + SELECT bv.id, + bo.useOrgSid, + bm.modelConfigSid AS vehMConfigSid, + bm.modelSid AS vehModelSid, + so.NAME, + bo.contractNo, + IFNULL(sss.money, '0') as money + FROM anrui_buscenter.bus_sales_order_vehicle bv + LEFT JOIN anrui_buscenter.bus_sales_order bo ON bo.sid = bv.salesOrderSid + LEFT JOIN anrui_base.base_vehicle bbv ON bbv.sid = bv.linkSid + LEFT JOIN anrui_buscenter.bus_sales_order_model bm + ON bm.salesOrderSid = bv.salesOrderSid + LEFT JOIN anrui_portal.sys_organization so ON so.sid = bo.useOrgSid + LEFT JOIN (SELECT furd.busVinSid + FROM anrui_fin.fin_uncollected_receivables_detailed furd + WHERE furd.receivablesName = '融资放款' + group by furd.busVinSid) ss ON ss.busVinSid = bv.sid + LEFT JOIN ( + SELECT (ls.loanTotal - lo.loanDownPay) AS money, + ls.salesOrderSid + FROM anrui_riskcenter.loan_solutions ls + LEFT JOIN anrui_riskcenter.loan_solutions_otherpolicy lo ON lo.solutionsSid = ls.sid + ) sss ON sss.salesOrderSid = bv.salesOrderSid + WHERE bo.payTypeKey = 2 + and ss.busVinSid is null + AND bbv.vehicleState = '0002' + and bo.nodeState = '已办结' + and bo.contractNo NOT LIKE '%2023%' + GROUP BY bv.sid, + bo.useOrgSid, + bm.modelSid, + bm.modelConfigSid + having money > 0 + ) a + GROUP BY a.contractNo, + a.useOrgSid, + a.vehMConfigSid, + a.vehModelSid) b + group by b.useOrgSid, b.vehModelSid, b.vehMConfigSid) as s on + r.useOrgSid = s.useOrgSid AND r.vehModelSid = s.vehModelSid AND r.vehMConfigSid = s.vehMConfigSid + SET r.`loan_not_count`=s.scount + WHERE DATE_FORMAT(createTime, '%Y-%m-%d') = CURDATE();*/ + + +-- 金融未放款金额-- 截止当日贷款业务已出库且融资放款未认款的台数融资放款金额之和 + + /* update daily_report r inner join ( + select SUM(b.scount) AS scount, + b.useOrgSid, + b.NAME, + b.contractNo, + b.vehMConfigSid, + b.vehModelSid + from (SELECT SUM(a.scount) AS scount, + a.useOrgSid, + a.NAME, + a.contractNo, + a.vehMConfigSid, + a.vehModelSid + FROM (SELECT bv.id, + bo.useOrgSid, + bm.modelConfigSid AS vehMConfigSid, + bm.modelSid AS vehModelSid, + so.NAME, + SUM(s.reveivableMoney), + SUM(s.subscriptionMoney), + bo.contractNo, + ( + SUM(s.reveivableMoney) - SUM(s.subscriptionMoney)) AS scount + FROM anrui_buscenter.bus_sales_order_vehicle bv + LEFT JOIN anrui_buscenter.bus_sales_order bo ON bo.sid = bv.salesOrderSid + LEFT JOIN anrui_base.base_vehicle bbv ON bbv.sid = bv.linkSid + LEFT JOIN anrui_buscenter.bus_sales_order_model bm ON bm.salesOrderSid = bv.salesOrderSid + LEFT JOIN ( + SELECT fd.reveivableMoney, + fd.busVinSid, + IFNULL(SUM(fs.subscriptionMoney), 0) AS subscriptionMoney + FROM anrui_fin.fin_uncollected_receivables_detailed fd + LEFT JOIN anrui_fin.fin_selected_receivables_detailed fs ON fs.receivablesSid = fd.sid + WHERE fd.kxState = '01' + AND fs.auditState = 3 + AND fd.receivablesName = '融资放款' + GROUP BY fd.sid + UNION ALL + SELECT fd.reveivableMoney, + fd.busVinSid, + 0 AS subscriptionMoney + FROM anrui_fin.fin_uncollected_receivables_detailed fd + WHERE fd.kxState = '01' + AND fd.receivablesName = '融资放款' + AND fd.sid NOT IN (SELECT fs.`receivablesSid` + FROM anrui_fin.fin_selected_receivables_detailed fs + WHERE fs.`auditState` = 3 + AND fs.`receivablesName` = '融资放款') + GROUP BY fd.sid + ) s ON s.busVinSid = bv.sid + LEFT JOIN anrui_portal.sys_organization so ON so.sid = bo.useOrgSid + WHERE bo.payTypeKey = 2 + + AND bbv.vehicleState = '0002' + GROUP BY bv.sid, bo.useOrgSid, bm.modelSid, bm.modelConfigSid + HAVING SUM(s.reveivableMoney) > SUM(s.subscriptionMoney)) a + GROUP BY a.contractNo, a.useOrgSid, + a.vehMConfigSid, + a.vehModelSid + union all + + SELECT sum(a.money) AS scount, + a.useOrgSid, + a.NAME, + a.contractNo, + a.vehMConfigSid, + a.vehModelSid + FROM ( + SELECT bo.useOrgSid, + bm.modelConfigSid AS vehMConfigSid, + bm.modelSid AS vehModelSid, + so.NAME, + bo.contractNo, + IFNULL(sss.money, '0') as money + FROM anrui_buscenter.bus_sales_order_vehicle bv + LEFT JOIN anrui_buscenter.bus_sales_order bo ON bo.sid = bv.salesOrderSid + LEFT JOIN anrui_base.base_vehicle bbv ON bbv.sid = bv.linkSid + LEFT JOIN anrui_buscenter.bus_sales_order_model bm + ON bm.salesOrderSid = bv.salesOrderSid + LEFT JOIN anrui_portal.sys_organization so ON so.sid = bo.useOrgSid + LEFT JOIN (SELECT furd.busVinSid + FROM anrui_fin.fin_uncollected_receivables_detailed furd + WHERE furd.receivablesName = '融资放款' + group by furd.busVinSid) ss ON ss.busVinSid = bv.sid + LEFT JOIN ( + SELECT (ls.loanTotal - lo.loanDownPay) AS money, + ls.salesOrderSid + FROM anrui_riskcenter.loan_solutions ls + LEFT JOIN anrui_riskcenter.loan_solutions_otherpolicy lo ON lo.solutionsSid = ls.sid + ) sss ON sss.salesOrderSid = bv.salesOrderSid + WHERE bo.payTypeKey = 2 + and ss.busVinSid is null + AND bbv.vehicleState = '0002' + and bo.nodeState = '已办结' + and bo.contractNo NOT LIKE '%2023%' + GROUP BY bv.sid, + bo.useOrgSid, + bm.modelSid, + bm.modelConfigSid + having money > 0 + ) a + GROUP BY a.contractNo, + a.useOrgSid, + a.vehMConfigSid, + a.vehModelSid) b + group by b.useOrgSid, b.vehModelSid, b.vehMConfigSid) as s on + r.useOrgSid = s.useOrgSid AND r.vehModelSid = s.vehModelSid AND r.vehMConfigSid = s.vehMConfigSid + SET r.`loan_not_amount`=ROUND(s.scount / 10000, 2) + WHERE DATE_FORMAT(createTime, '%Y-%m-%d') = CURDATE(); + */ + -- 金融未放款数量已信审终审--- 截止当日贷款业务已信审终审且融资放款未认款的台数。 - update daily_report r inner join ( + /*update daily_report r inner join ( select sum(b.scount) AS scount, b.useOrgSid, b.NAME, @@ -1424,142 +1435,146 @@ BEGIN group by b.useOrgSid, b.vehModelSid, b.vehMConfigSid) as s on r.useOrgSid = s.useOrgSid AND r.vehModelSid = s.vehModelSid AND r.vehMConfigSid = s.vehMConfigSid SET r.`loan_not_counts`=s.scount - WHERE DATE_FORMAT(createTime, '%Y-%m-%d') = CURDATE(); + WHERE DATE_FORMAT(createTime, '%Y-%m-%d') = CURDATE();*/ -- 金融未放款金额已信审终审-- 截止当日贷款业务已信审终审且融资放款未认款的台数融资放款金额之和 - update daily_report r inner join ( - SELECT SUM(b.scount) AS scount, - b.useOrgSid, - b.NAME, - b.contractNo, - b.vehMConfigSid, - b.vehModelSid - from ( - SELECT SUM(a.scount) AS scount, - a.useOrgSid, - a.NAME, - a.contractNo, - a.vehMConfigSid, - a.vehModelSid - FROM ( - SELECT bv.id, - bo.useOrgSid, - bm.modelConfigSid AS vehMConfigSid, - bm.modelSid AS vehModelSid, - so.NAME, - SUM(s.reveivableMoney), - SUM(s.subscriptionMoney), - bo.contractNo, - ( - SUM(s.reveivableMoney) - SUM(s.subscriptionMoney)) AS scount - FROM anrui_buscenter.bus_sales_order_vehicle bv - LEFT JOIN anrui_buscenter.bus_sales_order bo ON bo.sid = bv.salesOrderSid - LEFT JOIN anrui_base.base_vehicle bbv ON bbv.sid = bv.linkSid - LEFT JOIN anrui_buscenter.bus_sales_order_model bm - ON bm.salesOrderSid = bv.salesOrderSid - LEFT JOIN ( - SELECT fd.reveivableMoney, - fd.busVinSid, - IFNULL(SUM(fs.subscriptionMoney), 0) AS subscriptionMoney - FROM anrui_fin.fin_uncollected_receivables_detailed fd - LEFT JOIN anrui_fin.fin_selected_receivables_detailed fs - ON fs.receivablesSid = fd.sid - WHERE fd.kxState = '01' - AND fs.auditState = 3 - AND fd.receivablesName = '融资放款' - GROUP BY fd.sid - UNION ALL - SELECT fd.reveivableMoney, - fd.busVinSid, - 0 AS subscriptionMoney - FROM anrui_fin.fin_uncollected_receivables_detailed fd - WHERE fd.kxState = '01' - AND fd.receivablesName = '融资放款' - AND fd.sid NOT IN (SELECT fs.`receivablesSid` - FROM anrui_fin.fin_selected_receivables_detailed fs - WHERE fs.`auditState` = 3 - AND fs.`receivablesName` = '融资放款') - GROUP BY fd.sid - ) s ON s.busVinSid = bv.sid - LEFT JOIN anrui_portal.sys_organization so ON so.sid = bo.useOrgSid - LEFT JOIN anrui_riskcenter.loan_capital_credit_result lr - ON lr.loanContractSid = bv.loanContractSid - WHERE bo.payTypeKey = 2 - AND lr.capCarefulResult = '通过' - GROUP BY bv.sid, - bo.useOrgSid, - bm.modelSid, - bm.modelConfigSid - HAVING SUM(s.reveivableMoney) > SUM(s.subscriptionMoney)) a - GROUP BY a.contractNo, a.useOrgSid, - a.vehMConfigSid, - a.vehModelSid - UNION ALL - SELECT SUM(a.scount) AS scount, - a.useOrgSid, - a.NAME, - a.contractNo, - a.vehMConfigSid, - a.vehModelSid - FROM ( - SELECT bv.id, - bo.useOrgSid, - bm.modelConfigSid AS vehMConfigSid, - bm.modelSid AS vehModelSid, - so.NAME, - SUM(s.reveivableMoney), - SUM(s.subscriptionMoney), - bo.contractNo, - ( - SUM(s.reveivableMoney) - SUM(s.subscriptionMoney)) AS scount - FROM anrui_buscenter.bus_sales_order_vehicle bv - LEFT JOIN anrui_buscenter.bus_sales_order bo ON bo.sid = bv.salesOrderSid - LEFT JOIN anrui_base.base_vehicle bbv ON bbv.sid = bv.linkSid - LEFT JOIN anrui_buscenter.bus_sales_order_model bm - ON bm.salesOrderSid = bv.salesOrderSid - LEFT JOIN ( - SELECT fd.reveivableMoney, - fd.busVinSid, - IFNULL(SUM(fs.subscriptionMoney), 0) AS subscriptionMoney - FROM anrui_fin.fin_uncollected_receivables_detailed fd - LEFT JOIN anrui_fin.fin_selected_receivables_detailed fs - ON fs.receivablesSid = fd.sid - WHERE fd.kxState = '01' - AND fs.auditState = 3 - AND fd.receivablesName = '融资放款' - GROUP BY fd.sid - UNION ALL - SELECT fd.reveivableMoney, - fd.busVinSid, - 0 AS subscriptionMoney - FROM anrui_fin.fin_uncollected_receivables_detailed fd - WHERE fd.kxState = '01' - AND fd.receivablesName = '融资放款' - AND fd.sid NOT IN (SELECT fs.`receivablesSid` - FROM anrui_fin.fin_selected_receivables_detailed fs - WHERE fs.`auditState` = 3 - AND fs.`receivablesName` = '融资放款') - GROUP BY fd.sid - ) s ON s.busVinSid = bv.sid - LEFT JOIN anrui_portal.sys_organization so ON so.sid = bo.useOrgSid - LEFT JOIN anrui_riskcenter.loan_noguarantee_credit_review lr - ON lr.borrowerSid = bv.borrowerSid - WHERE bo.payTypeKey = 2 - AND lr.creditReview = '通过' - GROUP BY bv.sid, - bo.useOrgSid, - bm.modelSid, - bm.modelConfigSid - HAVING SUM(s.reveivableMoney) > SUM(s.subscriptionMoney)) a - GROUP BY a.contractNo, a.useOrgSid, - a.vehMConfigSid, - a.vehModelSid) b - group by b.useOrgSid, b.vehModelSid - , b.vehMConfigSid) as s on - r.useOrgSid = s.useOrgSid AND r.vehModelSid = s.vehModelSid AND r.vehMConfigSid = s.vehMConfigSid - SET r.`loan_not_amounts`=ROUND(s.scount / 10000, 2) - WHERE DATE_FORMAT(createTime, '%Y-%m-%d') = CURDATE(); + /* update daily_report r inner join ( + SELECT SUM(b.scount) AS scount, + b.useOrgSid, + b.NAME, + b.contractNo, + b.vehMConfigSid, + b.vehModelSid + from ( + SELECT SUM(a.scount) AS scount, + a.useOrgSid, + a.NAME, + a.contractNo, + a.vehMConfigSid, + a.vehModelSid + FROM ( + SELECT bv.id, + bo.useOrgSid, + bm.modelConfigSid AS vehMConfigSid, + bm.modelSid AS vehModelSid, + so.NAME, + SUM(s.reveivableMoney), + SUM(s.subscriptionMoney), + bo.contractNo, + ( + SUM(s.reveivableMoney) - SUM(s.subscriptionMoney)) AS scount + FROM anrui_buscenter.bus_sales_order_vehicle bv + LEFT JOIN anrui_buscenter.bus_sales_order bo ON bo.sid = bv.salesOrderSid + LEFT JOIN anrui_base.base_vehicle bbv ON bbv.sid = bv.linkSid + LEFT JOIN anrui_buscenter.bus_sales_order_model bm + ON bm.salesOrderSid = bv.salesOrderSid + LEFT JOIN ( + SELECT fd.reveivableMoney, + fd.busVinSid, + IFNULL(SUM(fs.subscriptionMoney), 0) AS subscriptionMoney + FROM anrui_fin.fin_uncollected_receivables_detailed fd + LEFT JOIN anrui_fin.fin_selected_receivables_detailed fs + ON fs.receivablesSid = fd.sid + WHERE fd.kxState = '01' + AND fs.auditState = 3 + AND fd.receivablesName = '融资放款' + GROUP BY fd.sid + UNION ALL + SELECT fd.reveivableMoney, + fd.busVinSid, + 0 AS subscriptionMoney + FROM anrui_fin.fin_uncollected_receivables_detailed fd + WHERE fd.kxState = '01' + AND fd.receivablesName = '融资放款' + AND fd.sid NOT IN (SELECT fs.`receivablesSid` + FROM anrui_fin.fin_selected_receivables_detailed fs + WHERE fs.`auditState` = 3 + AND fs.`receivablesName` = '融资放款') + GROUP BY fd.sid + ) s ON s.busVinSid = bv.sid + LEFT JOIN anrui_portal.sys_organization so ON so.sid = bo.useOrgSid + LEFT JOIN anrui_riskcenter.loan_capital_credit_result lr + ON lr.loanContractSid = bv.loanContractSid + WHERE bo.payTypeKey = 2 + AND lr.capCarefulResult = '通过' + GROUP BY bv.sid, + bo.useOrgSid, + bm.modelSid, + bm.modelConfigSid + HAVING SUM(s.reveivableMoney) > SUM(s.subscriptionMoney)) a + GROUP BY a.contractNo, a.useOrgSid, + a.vehMConfigSid, + a.vehModelSid + UNION ALL + SELECT SUM(a.scount) AS scount, + a.useOrgSid, + a.NAME, + a.contractNo, + a.vehMConfigSid, + a.vehModelSid + FROM ( + SELECT bv.id, + bo.useOrgSid, + bm.modelConfigSid AS vehMConfigSid, + bm.modelSid AS vehModelSid, + so.NAME, + SUM(s.reveivableMoney), + SUM(s.subscriptionMoney), + bo.contractNo, + ( + SUM(s.reveivableMoney) - SUM(s.subscriptionMoney)) AS scount + FROM anrui_buscenter.bus_sales_order_vehicle bv + LEFT JOIN anrui_buscenter.bus_sales_order bo ON bo.sid = bv.salesOrderSid + LEFT JOIN anrui_base.base_vehicle bbv ON bbv.sid = bv.linkSid + LEFT JOIN anrui_buscenter.bus_sales_order_model bm + ON bm.salesOrderSid = bv.salesOrderSid + LEFT JOIN ( + SELECT fd.reveivableMoney, + fd.busVinSid, + IFNULL(SUM(fs.subscriptionMoney), 0) AS subscriptionMoney + FROM anrui_fin.fin_uncollected_receivables_detailed fd + LEFT JOIN anrui_fin.fin_selected_receivables_detailed fs + ON fs.receivablesSid = fd.sid + WHERE fd.kxState = '01' + AND fs.auditState = 3 + AND fd.receivablesName = '融资放款' + GROUP BY fd.sid + UNION ALL + SELECT fd.reveivableMoney, + fd.busVinSid, + 0 AS subscriptionMoney + FROM anrui_fin.fin_uncollected_receivables_detailed fd + WHERE fd.kxState = '01' + AND fd.receivablesName = '融资放款' + AND fd.sid NOT IN (SELECT fs.`receivablesSid` + FROM anrui_fin.fin_selected_receivables_detailed fs + WHERE fs.`auditState` = 3 + AND fs.`receivablesName` = '融资放款') + GROUP BY fd.sid + ) s ON s.busVinSid = bv.sid + LEFT JOIN anrui_portal.sys_organization so ON so.sid = bo.useOrgSid + LEFT JOIN anrui_riskcenter.loan_noguarantee_credit_review lr + ON lr.borrowerSid = bv.borrowerSid + WHERE bo.payTypeKey = 2 + AND lr.creditReview = '通过' + GROUP BY bv.sid, + bo.useOrgSid, + bm.modelSid, + bm.modelConfigSid + HAVING SUM(s.reveivableMoney) > SUM(s.subscriptionMoney)) a + GROUP BY a.contractNo, a.useOrgSid, + a.vehMConfigSid, + a.vehModelSid) b + group by b.useOrgSid, b.vehModelSid + , b.vehMConfigSid) as s on + r.useOrgSid = s.useOrgSid AND r.vehModelSid = s.vehModelSid AND r.vehMConfigSid = s.vehMConfigSid + SET r.`loan_not_amounts`=ROUND(s.scount / 10000, 2) + WHERE DATE_FORMAT(createTime, '%Y-%m-%d') = CURDATE();*/ + + +-- 金融未放款 统计规则调整:包含担保和非担保。 金融未放款(已开票):截止当日贷款业务已开票的,融资放款应收未认款金额+未生成融资放款的总贷款金额。 +-- 金融未放款(已终审):截止当日贷款业务的已开票且信审终审已通过,统计融资放款未认款金额。 END \ No newline at end of file