diff --git a/doc/databases/报表中心.sql b/doc/databases/报表中心.sql index fc65409564..8ba08a7e2d 100644 --- a/doc/databases/报表中心.sql +++ b/doc/databases/报表中心.sql @@ -905,38 +905,109 @@ where DATE_FORMAT(createTime, '%Y-%m-%d') = CURDATE(); -- 金融未放款数量--- 截止当日贷款业务已出库且融资放款未认款的台数 update daily_report r inner join ( - select count(bv.id) as scount, bo.useOrgSid, bm.modelSid, bm.modelConfigSid, fd.reveivableMoney - 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_fin.fin_uncollected_receivables_detailed fd on fd.busVinSid = bv.sid - left join anrui_fin.fin_selected_receivables_detailed fs on fs.receivablesSid = fd.sid - where bo.payTypeKey = 2 - and fd.receivablesName = '融资放款' - and bbv.vehicleState = '0002' - group by bv.sid, bo.useOrgSid, bm.modelSid, bm.modelConfigSid - having fd.reveivableMoney > ifnull(sum(fs.subscriptionMoney), 0)) as s on - r.useOrgSid = s.useOrgSid AND r.vehModelSid = s.modelSid AND r.vehMConfigSid = s.modelConfigSid + 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 + ) 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.useOrgSid, + a.vehMConfigSid, + a.vehModelSid) 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(fd.reveivableMoney) as scount, bo.useOrgSid, bm.modelSid, bm.modelConfigSid, fd.reveivableMoney - 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_fin.fin_uncollected_receivables_detailed fd on fd.busVinSid = bv.sid - left join anrui_fin.fin_selected_receivables_detailed fs on fs.receivablesSid = fd.sid - where bo.payTypeKey = 2 - and fd.receivablesName = '融资放款' - and bbv.vehicleState = '0002' - group by bv.sid, bo.useOrgSid, bm.modelSid, bm.modelConfigSid - having fd.reveivableMoney > ifnull(sum(fs.subscriptionMoney), 0)) as s on - r.useOrgSid = s.useOrgSid AND r.vehModelSid = s.modelSid AND r.vehMConfigSid = s.modelConfigSid + 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 + ) 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.useOrgSid, + a.vehMConfigSid, + a.vehModelSid) 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();