|
|
@ -11,13 +11,16 @@ UPDATE daily_report r |
|
|
|
and LENGTH(offlineDate) > 0 |
|
|
|
and bo.sid not in (select bbbbo.linkSid from anrui_buscenter.bus_sales_vehicle_order bbbbo) |
|
|
|
group by bo.createOrgSid |
|
|
|
union all |
|
|
|
select ifnull(sum(bo.platformNo), 0) as scount, bo.useOrgSid, bd.vehicleSid, bd.configSid modelConfigSid |
|
|
|
union all |
|
|
|
select ifnull(sum(bo.platformNo), 0) as scount, |
|
|
|
bo.useOrgSid, |
|
|
|
bd.vehicleSid, |
|
|
|
bd.configSid modelConfigSid |
|
|
|
from anrui_base.bus_vehicle_order bo |
|
|
|
left join anrui_base.bus_vehicle_apply_detail bd on bd.sid = bo.purchaseApplyMediumModelSid |
|
|
|
where |
|
|
|
bo.isDelete <> 1 |
|
|
|
and LENGTH(offlineDate) = 0 and bo.orderStatus != '已作废' |
|
|
|
left join anrui_base.bus_vehicle_apply_detail bd on bd.sid = bo.purchaseApplyMediumModelSid |
|
|
|
where bo.isDelete <> 1 |
|
|
|
and LENGTH(offlineDate) = 0 |
|
|
|
and bo.orderStatus != '已作废' |
|
|
|
and bo.sid not in (select bbbbo.linkSid from anrui_buscenter.bus_sales_vehicle_order bbbbo) |
|
|
|
group by bo.createOrgSid |
|
|
|
) as v |
|
|
@ -36,22 +39,42 @@ UPDATE daily_report r |
|
|
|
INNER JOIN ( |
|
|
|
select sum(v.scount) as scount, v.useOrgSid, v.modelSid, v.modelConfigSid |
|
|
|
from ( |
|
|
|
select ifnull(sum(si.num), 0) as scount, si.useOrgSid, si.modelSid, si.configSid modelConfigSid |
|
|
|
from anrui_base.bus_vehicle_order bo |
|
|
|
left join anrui_scm.scm_apply_inbound si on bo.purchaseRequisitionSid = si.vehicleOrderSid |
|
|
|
where (si.nodeState != '已办结' and si.nodeState != '终止') |
|
|
|
and bo.isDelete <> 1 |
|
|
|
and LENGTH(offlineDate) > 0 |
|
|
|
and bo.sid in (select bbbbo.linkSid from anrui_buscenter.bus_sales_vehicle_order bbbbo) |
|
|
|
group by bo.createOrgSid |
|
|
|
union all |
|
|
|
select ifnull(sum(bo.id), 0) as scount, bo.useOrgSid, bd.vehicleSid, bd.configSid modelConfigSid |
|
|
|
from anrui_base.bus_vehicle_order bo |
|
|
|
left join anrui_base.bus_vehicle_apply_detail bd on bd.sid = bo.purchaseApplyMediumModelSid |
|
|
|
where |
|
|
|
bo.isDelete <> 1 |
|
|
|
and LENGTH(offlineDate) >0 |
|
|
|
and bo.sid in (select bbbbo.linkSid from anrui_buscenter.bus_sales_vehicle_order bbbbo) |
|
|
|
/* select ifnull(sum(si.num), 0) as scount, si.useOrgSid, si.modelSid, si.configSid modelConfigSid |
|
|
|
from anrui_base.bus_vehicle_order bo |
|
|
|
left join anrui_scm.scm_apply_inbound si on bo.purchaseRequisitionSid = si.vehicleOrderSid |
|
|
|
where (si.nodeState != '已办结' and si.nodeState != '终止') |
|
|
|
and bo.isDelete <> 1 |
|
|
|
and LENGTH(offlineDate) > 0 |
|
|
|
and bo.sid in (select bbbbo.linkSid from anrui_buscenter.bus_sales_vehicle_order bbbbo) |
|
|
|
group by bo.createOrgSid |
|
|
|
union all |
|
|
|
select ifnull(sum(bo.platformNo), 0) as scount, bo.useOrgSid, bd.vehicleSid, bd.configSid modelConfigSid |
|
|
|
from anrui_base.bus_vehicle_order bo |
|
|
|
left join anrui_base.bus_vehicle_apply_detail bd on bd.sid = bo.purchaseApplyMediumModelSid |
|
|
|
where |
|
|
|
bo.isDelete <> 1 |
|
|
|
and LENGTH(offlineDate) >0 |
|
|
|
and bo.sid in (select bbbbo.linkSid from anrui_buscenter.bus_sales_vehicle_order bbbbo) |
|
|
|
group by bo.createOrgSid*/ |
|
|
|
SELECT si.useOrgSid, |
|
|
|
si.modelSid, |
|
|
|
si.configSid modelConfigSid, |
|
|
|
bo.sid, |
|
|
|
ifnull(ab.counts, 0) as scount |
|
|
|
FROM anrui_base.bus_vehicle_order bo |
|
|
|
LEFT JOIN anrui_scm.scm_apply_inbound si ON bo.purchaseRequisitionSid = si.vehicleOrderSid |
|
|
|
LEFT JOIN ( |
|
|
|
SELECT bbbbo.linkSid, |
|
|
|
ifnull(count(bbbbo.linkSid), 0) as counts |
|
|
|
FROM anrui_buscenter.bus_sales_vehicle_order bbbbo |
|
|
|
LEFT JOIN anrui_buscenter.bus_sales_order bb ON bb.sid = bbbbo.salesOrderSid |
|
|
|
WHERE LENGTH(bb.nodeState) > 0 |
|
|
|
AND bb.nodeState != '终止' |
|
|
|
group by bbbbo.linkSid |
|
|
|
) ab ON ab.linkSid = bo.sid |
|
|
|
WHERE (si.nodeState != '已办结' AND si.nodeState != '终止') |
|
|
|
AND bo.isDelete <> 1 |
|
|
|
AND LENGTH(offlineDate) > 0 |
|
|
|
group by bo.createOrgSid |
|
|
|
) as v |
|
|
|
GROUP BY v.`useOrgSid`, |
|
|
@ -253,7 +276,9 @@ UPDATE daily_report r |
|
|
|
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.materialTypeKey = '001' or bvo.materialTypeValue is null or length(bvo.materialTypeValue) = 0) |
|
|
|
and bvoa.saleTypeKey = '001' |
|
|
|
and (bvo.materialTypeKey = '001' or bvo.materialTypeValue is null or |
|
|
|
length(bvo.materialTypeValue) = 0) |
|
|
|
group by bv.useOrgSid, bv.modelSid, bv.modelConfigSid) ss |
|
|
|
group by ss.useOrgSid, ss.modelSid, ss.modelConfigSid |
|
|
|
) AS s ON r.useOrgSid = s.useOrgSid |
|
|
@ -269,7 +294,9 @@ UPDATE daily_report r |
|
|
|
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.materialTypeKey = '001' or bvo.materialTypeValue is null or length(bvo.materialTypeValue) = 0) |
|
|
|
and bvoa.saleTypeKey = '002' |
|
|
|
and (bvo.materialTypeKey = '001' or bvo.materialTypeValue is null or |
|
|
|
length(bvo.materialTypeValue) = 0) |
|
|
|
group by bv.useOrgSid, bv.modelSid, bv.modelConfigSid) ss |
|
|
|
group by ss.useOrgSid, ss.modelSid, ss.modelConfigSid |
|
|
|
) AS s ON r.useOrgSid = s.useOrgSid |
|
|
@ -302,7 +329,9 @@ UPDATE daily_report r |
|
|
|
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.materialTypeKey = '001' or bvo.materialTypeValue is null or length(bvo.materialTypeValue) = 0) |
|
|
|
and bvoa.saleTypeKey = '001' |
|
|
|
and (bvo.materialTypeKey = '001' or bvo.materialTypeValue is null or |
|
|
|
length(bvo.materialTypeValue) = 0) |
|
|
|
group by bv.useOrgSid, bv.modelSid, bv.modelConfigSid) ss |
|
|
|
group by ss.useOrgSid, ss.modelSid, ss.modelConfigSid |
|
|
|
) AS s ON r.useOrgSid = s.useOrgSid |
|
|
@ -318,7 +347,9 @@ UPDATE daily_report r |
|
|
|
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.materialTypeKey = '001' or bvo.materialTypeValue is null or length(bvo.materialTypeValue) = 0) |
|
|
|
and bvoa.saleTypeKey = '002' |
|
|
|
and (bvo.materialTypeKey = '001' or bvo.materialTypeValue is null or |
|
|
|
length(bvo.materialTypeValue) = 0) |
|
|
|
group by bv.useOrgSid, bv.modelSid, bv.modelConfigSid) ss |
|
|
|
group by ss.useOrgSid, ss.modelSid, ss.modelConfigSid |
|
|
|
) AS s ON r.useOrgSid = s.useOrgSid |
|
|
@ -351,7 +382,9 @@ UPDATE daily_report r |
|
|
|
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.materialTypeKey = '001' or bvo.materialTypeValue is null or length(bvo.materialTypeValue) = 0) |
|
|
|
and bvoa.saleTypeKey = '001' |
|
|
|
and (bvo.materialTypeKey = '001' or bvo.materialTypeValue is null or |
|
|
|
length(bvo.materialTypeValue) = 0) |
|
|
|
group by bv.useOrgSid, bv.modelSid, bv.modelConfigSid) ss |
|
|
|
group by ss.useOrgSid, ss.modelSid, ss.modelConfigSid |
|
|
|
) AS s ON r.useOrgSid = s.useOrgSid |
|
|
@ -367,7 +400,9 @@ UPDATE daily_report r |
|
|
|
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.materialTypeKey = '001' or bvo.materialTypeValue is null or length(bvo.materialTypeValue) = 0) |
|
|
|
and bvoa.saleTypeKey = '002' |
|
|
|
and (bvo.materialTypeKey = '001' or bvo.materialTypeValue is null or |
|
|
|
length(bvo.materialTypeValue) = 0) |
|
|
|
group by bv.useOrgSid, bv.modelSid, bv.modelConfigSid) ss |
|
|
|
group by ss.useOrgSid, ss.modelSid, ss.modelConfigSid |
|
|
|
) AS s ON r.useOrgSid = s.useOrgSid |
|
|
@ -635,46 +670,98 @@ where DATE_FORMAT(createTime, '%Y-%m-%d') = CURDATE(); |
|
|
|
-- ============================================== |
|
|
|
-- 欠款出库数量、欠款出库金额万元、金融未放款数量、金融未放款金额(万元) |
|
|
|
-- 欠款出库数量--截止当日欠款出库申请通过且未回清款的台数 |
|
|
|
update daily_report r inner join (select sum(cc.scount) as scount, cc.useOrgSid, cc.vehMConfigSid, cc.vehModelSid |
|
|
|
from ( |
|
|
|
select count(bdad.id) as scount, |
|
|
|
ba.useOrgSid, |
|
|
|
bm.modelConfigSid as vehMConfigSid, |
|
|
|
bm.modelSid as vehModelSid |
|
|
|
from anrui_buscenter.bus_delivered_apply_details bdad |
|
|
|
left join anrui_buscenter.bus_delivered_apply ba on ba.sid = bdad.applySid |
|
|
|
left join anrui_buscenter.bus_sales_order_vehicle bv on bv.sid = bdad.busVinSid |
|
|
|
left join anrui_buscenter.bus_sales_order bo on bo.sid = bv.salesOrderSid |
|
|
|
left join anrui_buscenter.bus_sales_order_model bm on bm.salesOrderSid = bo.sid |
|
|
|
left join anrui_fin.fin_uncollected_receivables_detailed fd |
|
|
|
on fd.busVinSid = bdad.busVinSid |
|
|
|
left join anrui_fin.fin_selected_receivables_detailed fs |
|
|
|
on fs.receivablesSid = fd.sid |
|
|
|
where ba.nodeState = '已办结' |
|
|
|
and ba.typeState = 1 |
|
|
|
group by bdad.busVinSid, ba.useOrgSid, bm.modelSid, bm.modelConfigSid |
|
|
|
having sum(fd.reveivableMoney) > ifnull(sum(fs.subscriptionMoney), 0) |
|
|
|
union all |
|
|
|
select count(bdad.id) as scount, |
|
|
|
ba.useOrgSid, |
|
|
|
bm.modelConfigSid as vehMConfigSid, |
|
|
|
bm.modelSid as vehModelSid |
|
|
|
from anrui_buscenter.bus_arrears_carry_vehicle_details bdad |
|
|
|
left join anrui_buscenter.bus_arrears_carry_vehicle_apply ba |
|
|
|
on ba.sid = bdad.applySid |
|
|
|
left join anrui_buscenter.bus_sales_order_vehicle bv on bv.linkSid = bdad.vinSid |
|
|
|
left join anrui_buscenter.bus_sales_order bo on bo.sid = bv.salesOrderSid |
|
|
|
left join anrui_buscenter.bus_sales_order_model bm on bm.salesOrderSid = bo.sid |
|
|
|
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 |
|
|
|
left join anrui_base.base_vehicle bbv on bbv.sid = bv.linkSid |
|
|
|
where ba.nodeState = '已办结' |
|
|
|
and ba.paymentMethodKey = 1 |
|
|
|
and bbv.vehicleState = '0002' |
|
|
|
group by bv.sid, ba.useOrgSid, bm.modelSid, bm.modelConfigSid |
|
|
|
having sum(fd.reveivableMoney) > ifnull(sum(fs.subscriptionMoney), 0)) cc |
|
|
|
update daily_report r inner join (SELECT SUM(cc.scount) AS scount, |
|
|
|
cc.useOrgSid, |
|
|
|
cc.vehMConfigSid, |
|
|
|
cc.vehModelSid |
|
|
|
FROM ( |
|
|
|
SELECT COUNT(a.id) AS scount, |
|
|
|
a.useOrgSid, |
|
|
|
a.NAME, |
|
|
|
a.contractNo, |
|
|
|
a.vehMConfigSid, |
|
|
|
a.vehModelSid |
|
|
|
FROM ( |
|
|
|
SELECT bdad.id, |
|
|
|
ba.useOrgSid, |
|
|
|
bm.modelConfigSid AS vehMConfigSid, |
|
|
|
bm.modelSid AS vehModelSid, |
|
|
|
so.NAME, |
|
|
|
SUM(s.reveivableMoney), |
|
|
|
SUM(s.subscriptionMoney), |
|
|
|
bo.contractNo |
|
|
|
FROM anrui_buscenter.bus_delivered_apply_details bdad |
|
|
|
LEFT JOIN anrui_buscenter.bus_delivered_apply ba ON ba.sid = bdad.applySid |
|
|
|
LEFT JOIN anrui_buscenter.bus_sales_order_vehicle bv ON bv.sid = bdad.busVinSid |
|
|
|
LEFT JOIN anrui_buscenter.bus_sales_order bo ON bo.sid = bv.salesOrderSid |
|
|
|
LEFT JOIN anrui_buscenter.bus_sales_order_model bm ON bm.salesOrderSid = bo.sid |
|
|
|
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 |
|
|
|
GROUP BY fd.sid |
|
|
|
) s ON s.busVinSid = bv.sid |
|
|
|
LEFT JOIN anrui_portal.sys_organization so ON so.sid = ba.useOrgSid |
|
|
|
WHERE ba.nodeState = '已办结' |
|
|
|
AND ba.typeState = 1 |
|
|
|
GROUP BY bv.sid, |
|
|
|
ba.useOrgSid, |
|
|
|
bm.modelSid, |
|
|
|
bm.modelConfigSid |
|
|
|
HAVING SUM(s.reveivableMoney) > SUM(s.subscriptionMoney)) a |
|
|
|
GROUP BY 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 bdad.id, |
|
|
|
ba.useOrgSid, |
|
|
|
bm.modelConfigSid AS vehMConfigSid, |
|
|
|
bm.modelSid AS vehModelSid, |
|
|
|
so.name, |
|
|
|
SUM(s.reveivableMoney), |
|
|
|
SUM(s.subscriptionMoney), |
|
|
|
bo.contractNo |
|
|
|
FROM anrui_buscenter.bus_arrears_carry_vehicle_details bdad |
|
|
|
LEFT JOIN anrui_buscenter.bus_arrears_carry_vehicle_apply ba |
|
|
|
ON ba.sid = bdad.applySid |
|
|
|
LEFT JOIN anrui_buscenter.bus_sales_order_vehicle bv ON bv.linkSid = bdad.vinSid |
|
|
|
LEFT JOIN anrui_buscenter.bus_sales_order bo ON bo.sid = bv.salesOrderSid |
|
|
|
LEFT JOIN anrui_buscenter.bus_sales_order_model bm ON bm.salesOrderSid = bo.sid |
|
|
|
LEFT JOIN anrui_base.base_vehicle bbv ON bbv.sid = bv.linkSid |
|
|
|
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 |
|
|
|
GROUP BY fd.sid) s ON s.busVinSid = bv.sid |
|
|
|
LEFT JOIN anrui_portal.sys_organization so ON so.sid = ba.useOrgSid |
|
|
|
WHERE ba.nodeState = '已办结' |
|
|
|
AND ba.paymentMethodKey = 1 |
|
|
|
AND bbv.vehicleState = '0002' |
|
|
|
GROUP BY bv.sid, |
|
|
|
ba.useOrgSid, |
|
|
|
bm.modelSid, |
|
|
|
bm.modelConfigSid |
|
|
|
HAVING SUM(s.reveivableMoney) > SUM(s.subscriptionMoney)) a |
|
|
|
GROUP BY a.useOrgSid, |
|
|
|
a.vehMConfigSid, a.vehModelSid) cc |
|
|
|
GROUP BY cc.useOrgSid, |
|
|
|
cc.vehMConfigSid, |
|
|
|
cc.vehModelSid |
|
|
|
) s |
|
|
|
on r.useOrgSid = s.useOrgSid |
|
|
|
and r.vehModelSid = s.vehModelSid |
|
|
@ -684,46 +771,130 @@ where DATE_FORMAT(createTime, '%Y-%m-%d') = CURDATE(); |
|
|
|
|
|
|
|
|
|
|
|
-- 欠款出库金融--截止当日欠款出库申请通过且未回清款的台数欠款总额 |
|
|
|
update daily_report r inner join (select sum(cc.scount) as scount, cc.useOrgSid, cc.vehMConfigSid, cc.vehModelSid |
|
|
|
from ( |
|
|
|
select (sum(fd.reveivableMoney) - sum(fs.subscriptionMoney)) as scount, |
|
|
|
ba.useOrgSid, |
|
|
|
bm.modelConfigSid as vehMConfigSid, |
|
|
|
bm.modelSid as vehModelSid |
|
|
|
from anrui_buscenter.bus_delivered_apply_details bdad |
|
|
|
left join anrui_buscenter.bus_delivered_apply ba on ba.sid = bdad.applySid |
|
|
|
left join anrui_buscenter.bus_sales_order_vehicle bv on bv.sid = bdad.busVinSid |
|
|
|
left join anrui_buscenter.bus_sales_order bo on bo.sid = bv.salesOrderSid |
|
|
|
left join anrui_buscenter.bus_sales_order_model bm on bm.salesOrderSid = bo.sid |
|
|
|
left join anrui_fin.fin_uncollected_receivables_detailed fd |
|
|
|
on fd.busVinSid = bdad.busVinSid |
|
|
|
left join anrui_fin.fin_selected_receivables_detailed fs |
|
|
|
on fs.receivablesSid = fd.sid |
|
|
|
where ba.nodeState = '已办结' |
|
|
|
and ba.typeState = 1 |
|
|
|
group by bdad.busVinSid, ba.useOrgSid, bm.modelSid, bm.modelConfigSid |
|
|
|
having sum(fd.reveivableMoney) > ifnull(sum(fs.subscriptionMoney), 0) |
|
|
|
union all |
|
|
|
select (sum(fd.reveivableMoney) - sum(fs.subscriptionMoney)) as scount, |
|
|
|
ba.useOrgSid, |
|
|
|
bm.modelConfigSid as vehMConfigSid, |
|
|
|
bm.modelSid as vehModelSid |
|
|
|
from anrui_buscenter.bus_arrears_carry_vehicle_details bdad |
|
|
|
left join anrui_buscenter.bus_arrears_carry_vehicle_apply ba |
|
|
|
on ba.sid = bdad.applySid |
|
|
|
left join anrui_buscenter.bus_sales_order_vehicle bv on bv.linkSid = bdad.vinSid |
|
|
|
left join anrui_buscenter.bus_sales_order bo on bo.sid = bv.salesOrderSid |
|
|
|
left join anrui_buscenter.bus_sales_order_model bm on bm.salesOrderSid = bo.sid |
|
|
|
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 |
|
|
|
left join anrui_base.base_vehicle bbv on bbv.sid = bv.linkSid |
|
|
|
where ba.nodeState = '已办结' |
|
|
|
and ba.paymentMethodKey = 1 |
|
|
|
and bbv.vehicleState = '0002' |
|
|
|
group by bv.sid, ba.useOrgSid, bm.modelSid, bm.modelConfigSid |
|
|
|
having sum(fd.reveivableMoney) > ifnull(sum(fs.subscriptionMoney), 0)) cc |
|
|
|
update daily_report r inner join (SELECT |
|
|
|
sum( cc.scount ) AS scount, |
|
|
|
cc.useOrgSid, |
|
|
|
cc.vehMConfigSid, |
|
|
|
cc.vehModelSid |
|
|
|
FROM |
|
|
|
( |
|
|
|
SELECT |
|
|
|
SUM( a.scount ) AS scount, |
|
|
|
a.useOrgSid, |
|
|
|
a.NAME, |
|
|
|
a.contractNo, |
|
|
|
a.vehMConfigSid, |
|
|
|
a.vehModelSid |
|
|
|
FROM |
|
|
|
( |
|
|
|
SELECT |
|
|
|
bdad.id, |
|
|
|
ba.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_delivered_apply_details bdad |
|
|
|
LEFT JOIN anrui_buscenter.bus_delivered_apply ba ON ba.sid = bdad.applySid |
|
|
|
LEFT JOIN anrui_buscenter.bus_sales_order_vehicle bv ON bv.sid = bdad.busVinSid |
|
|
|
LEFT JOIN anrui_buscenter.bus_sales_order bo ON bo.sid = bv.salesOrderSid |
|
|
|
LEFT JOIN anrui_buscenter.bus_sales_order_model bm ON bm.salesOrderSid = bo.sid |
|
|
|
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 |
|
|
|
GROUP BY |
|
|
|
fd.sid |
|
|
|
) s ON s.busVinSid = bv.sid |
|
|
|
LEFT JOIN anrui_portal.sys_organization so ON so.sid = ba.useOrgSid |
|
|
|
WHERE |
|
|
|
ba.nodeState = '已办结' |
|
|
|
AND ba.typeState = 1 |
|
|
|
GROUP BY |
|
|
|
bv.sid, |
|
|
|
ba.useOrgSid, |
|
|
|
bm.modelSid, |
|
|
|
bm.modelConfigSid |
|
|
|
HAVING |
|
|
|
SUM( s.reveivableMoney ) > SUM( s.subscriptionMoney )) a |
|
|
|
GROUP BY |
|
|
|
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 |
|
|
|
bdad.id, |
|
|
|
ba.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_arrears_carry_vehicle_details bdad |
|
|
|
LEFT JOIN anrui_buscenter.bus_arrears_carry_vehicle_apply ba ON ba.sid = bdad.applySid |
|
|
|
LEFT JOIN anrui_buscenter.bus_sales_order_vehicle bv ON bv.linkSid = bdad.vinSid |
|
|
|
LEFT JOIN anrui_buscenter.bus_sales_order bo ON bo.sid = bv.salesOrderSid |
|
|
|
LEFT JOIN anrui_buscenter.bus_sales_order_model bm ON bm.salesOrderSid = bo.sid |
|
|
|
LEFT JOIN anrui_base.base_vehicle bbv ON bbv.sid = bv.linkSid |
|
|
|
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 |
|
|
|
GROUP BY |
|
|
|
fd.sid |
|
|
|
) s ON s.busVinSid = bv.sid |
|
|
|
LEFT JOIN anrui_portal.sys_organization so ON so.sid = ba.useOrgSid |
|
|
|
WHERE |
|
|
|
ba.nodeState = '已办结' |
|
|
|
AND ba.paymentMethodKey = 1 |
|
|
|
AND bbv.vehicleState = '0002' |
|
|
|
GROUP BY |
|
|
|
bv.sid, |
|
|
|
ba.useOrgSid, |
|
|
|
bm.modelSid, |
|
|
|
bm.modelConfigSid |
|
|
|
HAVING |
|
|
|
SUM( s.reveivableMoney ) > SUM( s.subscriptionMoney )) a |
|
|
|
GROUP BY |
|
|
|
a.useOrgSid, |
|
|
|
a.vehMConfigSid, |
|
|
|
a.vehModelSid |
|
|
|
) cc |
|
|
|
GROUP BY |
|
|
|
cc.useOrgSid, |
|
|
|
cc.vehMConfigSid, |
|
|
|
cc.vehModelSid |
|
|
|
) s |
|
|
|
on r.useOrgSid = s.useOrgSid |
|
|
|
and r.vehModelSid = s.vehModelSid |
|
|
|