(IFNULL(SUM(d.count),0) - (SELECT IFNULL(SUM(de.count),0) FROM as_busrepair_inventorybill_detail as de LEFT JOIN as_busrepair_inventorybill as be ON de.billSid = be.sid WHERE de.inventorySid = d.inventorySid AND be.sourceBillSid = a.sid AND b.busTypeKey = '1') ) as num,
(IFNULL(SUM(d.count),0) - (SELECT IFNULL(SUM(de.count),0) FROM as_busrepair_inventorybill_detail as de LEFT JOIN
(IFNULL(SUM(d.amount),0) - (SELECT IFNULL(SUM(de.amount),0) FROM as_busrepair_inventorybill_detail as de LEFT JOIN as_busrepair_inventorybill as be ON de.billSid = be.sid WHERE de.inventorySid = d.inventorySid AND be.sourceBillSid = a.sid AND b.busTypeKey = '1') ) as discountAmount,
as_busrepair_inventorybill as be ON de.billSid = be.sid WHERE de.inventorySid = d.inventorySid AND
(IFNULL(SUM(d.costTotal),0) - (SELECT IFNULL(SUM(de.costTotal),0) FROM as_busrepair_inventorybill_detail as de LEFT JOIN as_busrepair_inventorybill as be ON de.billSid = be.sid WHERE de.inventorySid = d.inventorySid AND be.sourceBillSid = a.sid AND b.busTypeKey = '1') ) as costTotal,
be.sourceBillSid = a.sid AND b.busTypeKey = '1') ) as num,
((IFNULL(SUM(d.amount),0) - (SELECT IFNULL(SUM(de.amount),0) FROM as_busrepair_inventorybill_detail as de LEFT JOIN as_busrepair_inventorybill as be ON de.billSid = be.sid WHERE de.inventorySid = d.inventorySid AND be.sourceBillSid = a.sid AND b.busTypeKey = '1') ) - (IFNULL(SUM(d.costTotal),0) - (SELECT IFNULL(SUM(de.costTotal),0) FROM as_busrepair_inventorybill_detail as de LEFT JOIN as_busrepair_inventorybill as be ON de.billSid = be.sid WHERE de.inventorySid = d.inventorySid AND be.sourceBillSid = a.sid AND b.busTypeKey = '1') ) ) as profit
(IFNULL(SUM(d.amount),0) - (SELECT IFNULL(SUM(de.amount),0) FROM as_busrepair_inventorybill_detail as de LEFT
JOIN as_busrepair_inventorybill as be ON de.billSid = be.sid WHERE de.inventorySid = d.inventorySid AND
be.sourceBillSid = a.sid AND b.busTypeKey = '1') ) as discountAmount,
(IFNULL(SUM(d.costTotal),0) - (SELECT IFNULL(SUM(de.costTotal),0) FROM as_busrepair_inventorybill_detail as de
LEFT JOIN as_busrepair_inventorybill as be ON de.billSid = be.sid WHERE de.inventorySid = d.inventorySid AND
be.sourceBillSid = a.sid AND b.busTypeKey = '1') ) as costTotal,
((IFNULL(SUM(d.amount),0) - (SELECT IFNULL(SUM(de.amount),0) FROM as_busrepair_inventorybill_detail as de LEFT
JOIN as_busrepair_inventorybill as be ON de.billSid = be.sid WHERE de.inventorySid = d.inventorySid AND
(IFNULL(SUM(d.count),0) - (SELECT IFNULL(SUM(de.count),0) FROM as_busrepair_inventorybill_detail as de LEFT JOIN as_busrepair_inventorybill as be ON de.billSid = be.sid WHERE de.inventorySid = d.inventorySid AND be.sourceBillSid = a.sid AND b.busTypeKey = '1') ) as num,
(IFNULL(SUM(d.count),0) - (SELECT IFNULL(SUM(de.count),0) FROM as_busrepair_inventorybill_detail as de LEFT JOIN
as_busrepair_inventorybill as be ON de.billSid = be.sid WHERE de.inventorySid = d.inventorySid AND
be.sourceBillSid = a.sid AND b.busTypeKey = '1') ) as num,
d.discount,
d.discount,
(IFNULL(SUM(d.amount),0) - (SELECT IFNULL(SUM(de.amount),0) FROM as_busrepair_inventorybill_detail as de LEFT JOIN as_busrepair_inventorybill as be ON de.billSid = be.sid WHERE de.inventorySid = d.inventorySid AND be.sourceBillSid = a.sid AND b.busTypeKey = '1') ) as discountAmount,
(IFNULL(SUM(d.amount),0) - (SELECT IFNULL(SUM(de.amount),0) FROM as_busrepair_inventorybill_detail as de LEFT
JOIN as_busrepair_inventorybill as be ON de.billSid = be.sid WHERE de.inventorySid = d.inventorySid AND
be.sourceBillSid = a.sid AND b.busTypeKey = '1') ) as discountAmount,
d.cost,
d.cost,
(IFNULL(SUM(d.costTotal),0) - (SELECT IFNULL(SUM(de.costTotal),0) FROM as_busrepair_inventorybill_detail as de LEFT JOIN as_busrepair_inventorybill as be ON de.billSid = be.sid WHERE de.inventorySid = d.inventorySid AND be.sourceBillSid = a.sid AND b.busTypeKey = '1') ) as costTotal,
(IFNULL(SUM(d.costTotal),0) - (SELECT IFNULL(SUM(de.costTotal),0) FROM as_busrepair_inventorybill_detail as de
((IFNULL(SUM(d.amount),0) - (SELECT IFNULL(SUM(de.amount),0) FROM as_busrepair_inventorybill_detail as de LEFT JOIN as_busrepair_inventorybill as be ON de.billSid = be.sid WHERE de.inventorySid = d.inventorySid AND be.sourceBillSid = a.sid AND b.busTypeKey = '1') ) - (IFNULL(SUM(d.costTotal),0) - (SELECT IFNULL(SUM(de.costTotal),0) FROM as_busrepair_inventorybill_detail as de LEFT JOIN as_busrepair_inventorybill as be ON de.billSid = be.sid WHERE de.inventorySid = d.inventorySid AND be.sourceBillSid = a.sid AND b.busTypeKey = '1') ) ) as profit,
LEFT JOIN as_busrepair_inventorybill as be ON de.billSid = be.sid WHERE de.inventorySid = d.inventorySid AND
be.sourceBillSid = a.sid AND b.busTypeKey = '1') ) as costTotal,
((IFNULL(SUM(d.amount),0) - (SELECT IFNULL(SUM(de.amount),0) FROM as_busrepair_inventorybill_detail as de LEFT
JOIN as_busrepair_inventorybill as be ON de.billSid = be.sid WHERE de.inventorySid = d.inventorySid AND
(SELECT GROUP_CONCAT( r.repairerName SEPARATOR ',' ) FROM as_busrepair_bill_sitem_repairer as r WHERE r.billSid = a.sid and r.repairitemSid = d.serviceItemSid) as repairerName,
(SELECT GROUP_CONCAT( r.repairerName SEPARATOR ',' ) FROM as_busrepair_bill_sitem_repairer as r WHERE r.billSid
= a.sid and r.repairitemSid = d.serviceItemSid) as repairerName,
a.customerName,
a.customerName,
v.vinNo,
v.vinNo,
v.vehMark,
v.vehMark,
@ -655,7 +705,8 @@
v.vinNo,
v.vinNo,
v.vehMark,
v.vehMark,
v.vehModel
v.vehModel
FROM as_busrepair_bill_aitem as d LEFT JOIN as_busrepair_bill as a ON d.billSid = a.sid LEFT JOIN as_busrepair_bill_vech as v ON v.billSid = a.sid
FROM as_busrepair_bill_aitem as d LEFT JOIN as_busrepair_bill as a ON d.billSid = a.sid LEFT JOIN
as_busrepair_bill_vech as v ON v.billSid = a.sid
UNION ALL
UNION ALL
SELECT
SELECT
a.orgSidPath,
a.orgSidPath,
@ -688,7 +739,8 @@
v.vinNo,
v.vinNo,
v.vehMark,
v.vehMark,
v.vehModel
v.vehModel
FROM as_busrepair_bill_aitemspec as d LEFT JOIN as_busrepair_bill as a ON d.billSid = a.sid LEFT JOIN as_busrepair_bill_vech as v ON v.billSid = a.sid
FROM as_busrepair_bill_aitemspec as d LEFT JOIN as_busrepair_bill as a ON d.billSid = a.sid LEFT JOIN
(SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN as_busrepair_inventorybill as ab ON d.billSid = ab.sid LEFT JOIN as_busrepair_bill AS b ON ab.sourceBillSid = b.sid WHERE b.deptSid = a.deptSid and date_format ( b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime, '%Y-%m-%d' ) and ab.busTypeKey = 0) as goodsAmount,
(SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN
as_busrepair_inventorybill as ab ON d.billSid = ab.sid LEFT JOIN as_busrepair_bill AS b ON ab.sourceBillSid =
b.sid WHERE b.deptSid = a.deptSid and date_format ( b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime,
'%Y-%m-%d' ) and ab.busTypeKey = 0) as goodsAmount,
(SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN as_busrepair_inventorybill as ab ON d.billSid = ab.sid LEFT JOIN as_busrepair_bill AS b ON ab.sourceBillSid = b.sid WHERE b.deptSid = a.deptSid and date_format ( b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime, '%Y-%m-%d' ) and ab.busTypeKey = 1) as backAmount,
IFNULL(SUM(IFNULL(rescueAmount,0)),0)) addAmount,
(SELECT IFNULL(SUM(IFNULL(s.costTotal,0)),0) FROM as_busrepair_bill_sitem as s LEFT JOIN as_busrepair_bill as b ON s.billSid = b.sid WHERE
(SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN
b.deptSid = a.deptSid and date_format ( b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime, '%Y-%m-%d' )) as hourAmountCost,
as_busrepair_inventorybill as ab ON d.billSid = ab.sid LEFT JOIN as_busrepair_bill AS b ON ab.sourceBillSid =
( (SELECT IFNULL(SUM(IFNULL(d.costTotal,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN as_busrepair_inventorybill as ab ON d.billSid = ab.sid LEFT JOIN as_busrepair_bill AS b ON ab.sourceBillSid = b.sid WHERE b.deptSid = a.deptSid and date_format ( b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime, '%Y-%m-%d' ) and ab.busTypeKey = 0) - (SELECT IFNULL(SUM(IFNULL(d.costTotal,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN as_busrepair_inventorybill as ab ON d.billSid = ab.sid LEFT JOIN as_busrepair_bill AS b ON ab.sourceBillSid = b.sid WHERE b.deptSid = a.deptSid and date_format ( b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime, '%Y-%m-%d' ) and ab.busTypeKey = 1) ) goodsAmountCost,
b.sid WHERE b.deptSid = a.deptSid and date_format ( b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime,
((SELECT IFNULL(SUM(IFNULL(s.costTotal,0)),0) FROM as_busrepair_bill_aitem as s LEFT JOIN as_busrepair_bill as b ON s.billSid = b.sid WHERE
'%Y-%m-%d' ) and ab.busTypeKey = 1) as backAmount,
b.deptSid = a.deptSid and date_format ( b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime, '%Y-%m-%d' )) + (SELECT IFNULL(SUM(IFNULL(s.costTotal,0)),0) FROM as_busrepair_bill_aitemspec as s LEFT JOIN as_busrepair_bill as b ON s.billSid = b.sid WHERE
(SELECT IFNULL(SUM(IFNULL(s.costTotal,0)),0) FROM as_busrepair_bill_sitem as s LEFT JOIN as_busrepair_bill as b
( (SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN as_busrepair_inventorybill as ab ON d.billSid = ab.sid LEFT JOIN as_busrepair_bill AS b ON ab.sourceBillSid = b.sid WHERE b.deptSid = a.deptSid and date_format ( b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime, '%Y-%m-%d' ) and ab.busTypeKey = 0 and b.`subject` = '保内') - (SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN as_busrepair_inventorybill as ab ON d.billSid = ab.sid LEFT JOIN as_busrepair_bill AS b ON ab.sourceBillSid = b.sid WHERE b.deptSid = a.deptSid and date_format ( b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime, '%Y-%m-%d' ) and ab.busTypeKey = 1 and b.`subject` = '保内') ) packsGoodsAmount,
and b.`subject` = '保内') as packsHourAmount,
(SELECT IFNULL(SUM(IFNULL(addAmount,0)),0) + IFNULL(SUM(IFNULL(outAmount,0)),0) + IFNULL(SUM(IFNULL(subsidyAmount,0)),0) + IFNULL(SUM(IFNULL(rescueAmount,0)),0) FROM as_busrepair_bill as b WHERE
( (SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN
b.deptSid = a.deptSid and date_format (b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime, '%Y-%m-%d' ) and b.`subject` = '保内') as packsOtherAmount,
as_busrepair_inventorybill as ab ON d.billSid = ab.sid LEFT JOIN as_busrepair_bill AS b ON ab.sourceBillSid =
b.sid WHERE b.deptSid = a.deptSid and date_format ( b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime,
'%Y-%m-%d' ) and ab.busTypeKey = 0 and b.`subject` = '保内') - (SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM
as_busrepair_inventorybill_detail as d LEFT JOIN as_busrepair_inventorybill as ab ON d.billSid = ab.sid LEFT
JOIN as_busrepair_bill AS b ON ab.sourceBillSid = b.sid WHERE b.deptSid = a.deptSid and date_format (
b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime, '%Y-%m-%d' ) and ab.busTypeKey = 1 and b.`subject` =
( (SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN as_busrepair_inventorybill as ab ON d.billSid = ab.sid LEFT JOIN as_busrepair_bill AS b ON ab.sourceBillSid = b.sid WHERE b.deptSid = a.deptSid and date_format ( b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime, '%Y-%m-%d' ) and ab.busTypeKey = 0 and b.`subject` = '保外') - (SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN as_busrepair_inventorybill as ab ON d.billSid = ab.sid LEFT JOIN as_busrepair_bill AS b ON ab.sourceBillSid = b.sid WHERE b.deptSid = a.deptSid and date_format ( b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime, '%Y-%m-%d' ) and ab.busTypeKey = 1 and b.`subject` = '保外') ) outGoodsAmount,
and b.`subject` = '保外') as outHourAmount,
(SELECT IFNULL(SUM(IFNULL(addAmount,0)),0) + IFNULL(SUM(IFNULL(outAmount,0)),0) + IFNULL(SUM(IFNULL(subsidyAmount,0)),0) + IFNULL(SUM(IFNULL(rescueAmount,0)),0) FROM as_busrepair_bill as b WHERE
( (SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN
b.deptSid = a.deptSid and date_format (b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime, '%Y-%m-%d' ) and b.`subject` = '保外') as outOtherAmount,
as_busrepair_inventorybill as ab ON d.billSid = ab.sid LEFT JOIN as_busrepair_bill AS b ON ab.sourceBillSid =
b.sid WHERE b.deptSid = a.deptSid and date_format ( b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime,
'%Y-%m-%d' ) and ab.busTypeKey = 0 and b.`subject` = '保外') - (SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM
as_busrepair_inventorybill_detail as d LEFT JOIN as_busrepair_inventorybill as ab ON d.billSid = ab.sid LEFT
JOIN as_busrepair_bill AS b ON ab.sourceBillSid = b.sid WHERE b.deptSid = a.deptSid and date_format (
b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime, '%Y-%m-%d' ) and ab.busTypeKey = 1 and b.`subject` =
( (SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN as_busrepair_inventorybill as ab ON d.billSid = ab.sid LEFT JOIN as_busrepair_bill AS b ON ab.sourceBillSid = b.sid WHERE b.deptSid = a.deptSid and date_format ( b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime, '%Y-%m-%d' ) and ab.busTypeKey = 0) - (SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN as_busrepair_inventorybill as ab ON d.billSid = ab.sid LEFT JOIN as_busrepair_bill AS b ON ab.sourceBillSid = b.sid WHERE b.deptSid = a.deptSid and date_format ( b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime, '%Y-%m-%d' ) and ab.busTypeKey = 1) ) goodsAmount,
( (SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN
as_busrepair_inventorybill as ab ON d.billSid = ab.sid LEFT JOIN as_busrepair_bill AS b ON ab.sourceBillSid =
b.sid WHERE b.deptSid = a.deptSid and date_format ( b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime,
'%Y-%m-%d' ) and ab.busTypeKey = 0) - (SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM
as_busrepair_inventorybill_detail as d LEFT JOIN as_busrepair_inventorybill as ab ON d.billSid = ab.sid LEFT
JOIN as_busrepair_bill AS b ON ab.sourceBillSid = b.sid WHERE b.deptSid = a.deptSid and date_format (
(SELECT IFNULL(SUM(IFNULL(s.costTotal,0)),0) FROM as_busrepair_bill_sitem as s LEFT JOIN as_busrepair_bill as b ON s.billSid = b.sid WHERE
IFNULL(SUM(IFNULL(rescueAmount,0)),0)) addAmount,
b.deptSid = a.deptSid and date_format ( b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime, '%Y-%m-%d' )) as hourAmountCost,
(SELECT IFNULL(SUM(IFNULL(s.costTotal,0)),0) FROM as_busrepair_bill_sitem as s LEFT JOIN as_busrepair_bill as b
( (SELECT IFNULL(SUM(IFNULL(d.costTotal,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN as_busrepair_inventorybill as ab ON d.billSid = ab.sid LEFT JOIN as_busrepair_bill AS b ON ab.sourceBillSid = b.sid WHERE b.deptSid = a.deptSid and date_format ( b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime, '%Y-%m-%d' ) and ab.busTypeKey = 0) - (SELECT IFNULL(SUM(IFNULL(d.costTotal,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN as_busrepair_inventorybill as ab ON d.billSid = ab.sid LEFT JOIN as_busrepair_bill AS b ON ab.sourceBillSid = b.sid WHERE b.deptSid = a.deptSid and date_format ( b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime, '%Y-%m-%d' ) and ab.busTypeKey = 1) ) goodsAmountCost,
ON s.billSid = b.sid WHERE
((SELECT IFNULL(SUM(IFNULL(s.costTotal,0)),0) FROM as_busrepair_bill_aitem as s LEFT JOIN as_busrepair_bill as b ON s.billSid = b.sid WHERE
b.deptSid = a.deptSid and date_format ( b.settleTime, '%Y-%m-%d' ) = date_format ( a.settleTime, '%Y-%m-%d' )) + (SELECT IFNULL(SUM(IFNULL(s.costTotal,0)),0) FROM as_busrepair_bill_aitemspec as s LEFT JOIN as_busrepair_bill as b ON s.billSid = b.sid WHERE
((SELECT IFNULL(SUM(reveivableMoney),0) FROM anrui_fin.fin_uncollected_receivables_detailed as d WHERE d.contractSid = a.sid)
((SELECT IFNULL(SUM(reveivableMoney),0) FROM anrui_fin.fin_uncollected_receivables_detailed as d WHERE
- (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
d.contractSid = a.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 = a.sid)) noMoney,
= fd.sid WHERE sd.auditState = '3' AND fd.contractSid = a.sid)) noMoney,
IFNULL(a.hourAmount,0) hourAmount,
IFNULL(a.hourAmount,0) hourAmount,
((SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN as_busrepair_inventorybill as ab ON d.billSid = ab.sid WHERE ab.sourceBillSid = a.sid and ab.busTypeKey = 0) - (SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN as_busrepair_inventorybill as ab ON d.billSid = ab.sid WHERE ab.sourceBillSid = a.sid and ab.busTypeKey = 1)) goodsAmount,
((SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN
as_busrepair_inventorybill as ab ON d.billSid = ab.sid WHERE ab.sourceBillSid = a.sid and ab.busTypeKey = 0) -
(SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN
as_busrepair_inventorybill as ab ON d.billSid = ab.sid WHERE ab.sourceBillSid = a.sid and ab.busTypeKey = 1))
(SELECT IFNULL(SUM(IFNULL(s.costTotal,0)),0) FROM as_busrepair_bill_sitem as s WHERE s.billSid = a.sid) as hourAmountCost,
(SELECT IFNULL(SUM(IFNULL(s.costTotal,0)),0) FROM as_busrepair_bill_sitem as s WHERE s.billSid = a.sid) as
((SELECT IFNULL(SUM(IFNULL(d.costTotal,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN as_busrepair_inventorybill as ab ON d.billSid = ab.sid WHERE ab.sourceBillSid = a.sid and ab.busTypeKey = 0) - (SELECT IFNULL(SUM(IFNULL(d.costTotal,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN as_busrepair_inventorybill as ab ON d.billSid = ab.sid WHERE ab.sourceBillSid = a.sid and ab.busTypeKey = 1)) goodsAmountCost
hourAmountCost,
((SELECT IFNULL(SUM(IFNULL(d.costTotal,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN
as_busrepair_inventorybill as ab ON d.billSid = ab.sid WHERE ab.sourceBillSid = a.sid and ab.busTypeKey = 0) -
(SELECT IFNULL(SUM(IFNULL(d.costTotal,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN
as_busrepair_inventorybill as ab ON d.billSid = ab.sid WHERE ab.sourceBillSid = a.sid and ab.busTypeKey = 1))
goodsAmountCost
FROM
FROM
as_busrepair_bill AS a
as_busrepair_bill AS a
LEFT JOIN as_arrearsout_apply as sa ON a.sid = sa.pairBillSid
LEFT JOIN as_arrearsout_apply as sa ON a.sid = sa.pairBillSid
((SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN as_busrepair_inventorybill as ab ON d.billSid = ab.sid WHERE ab.sourceBillSid = a.sid and ab.busTypeKey = 0) - (SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN as_busrepair_inventorybill as ab ON d.billSid = ab.sid WHERE ab.sourceBillSid = a.sid and ab.busTypeKey = 1)) goodsAmount,
((SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN
as_busrepair_inventorybill as ab ON d.billSid = ab.sid WHERE ab.sourceBillSid = a.sid and ab.busTypeKey = 0) -
(SELECT IFNULL(SUM(IFNULL(d.amount,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN
as_busrepair_inventorybill as ab ON d.billSid = ab.sid WHERE ab.sourceBillSid = a.sid and ab.busTypeKey = 1))
(SELECT IFNULL(SUM(IFNULL(s.costTotal,0)),0) FROM as_busrepair_bill_sitem as s WHERE s.billSid = a.sid) as hourAmountCost,
(SELECT IFNULL(SUM(IFNULL(s.costTotal,0)),0) FROM as_busrepair_bill_sitem as s WHERE s.billSid = a.sid) as
((SELECT IFNULL(SUM(IFNULL(d.costTotal,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN as_busrepair_inventorybill as ab ON d.billSid = ab.sid WHERE ab.sourceBillSid = a.sid and ab.busTypeKey = 0) - (SELECT IFNULL(SUM(IFNULL(d.costTotal,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN as_busrepair_inventorybill as ab ON d.billSid = ab.sid WHERE ab.sourceBillSid = a.sid and ab.busTypeKey = 1)) goodsAmountCost,
hourAmountCost,
((SELECT IFNULL(SUM(IFNULL(s.costTotal,0)),0) FROM as_busrepair_bill_aitem as s WHERE s.billSid = a.sid) + (SELECT IFNULL(SUM(IFNULL(s.costTotal,0)),0) FROM as_busrepair_bill_aitemspec as s WHERE s.billSid = a.sid)) otherAmountCost,
((SELECT IFNULL(SUM(IFNULL(d.costTotal,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN
(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
as_busrepair_inventorybill as ab ON d.billSid = ab.sid WHERE ab.sourceBillSid = a.sid and ab.busTypeKey = 0) -
(SELECT IFNULL(SUM(IFNULL(d.costTotal,0)),0) FROM as_busrepair_inventorybill_detail as d LEFT JOIN
as_busrepair_inventorybill as ab ON d.billSid = ab.sid WHERE ab.sourceBillSid = a.sid and ab.busTypeKey = 1))
goodsAmountCost,
((SELECT IFNULL(SUM(IFNULL(s.costTotal,0)),0) FROM as_busrepair_bill_aitem as s WHERE s.billSid = a.sid) +
(SELECT IFNULL(SUM(IFNULL(s.costTotal,0)),0) FROM as_busrepair_bill_aitemspec as s WHERE s.billSid = a.sid))
otherAmountCost,
(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 = a.sid) receivedAmount,
= fd.sid WHERE sd.auditState = '3' AND fd.contractSid = a.sid) receivedAmount,
((SELECT IFNULL(SUM(reveivableMoney),0) FROM anrui_fin.fin_uncollected_receivables_detailed as d WHERE d.contractSid = a.sid)
((SELECT IFNULL(SUM(reveivableMoney),0) FROM anrui_fin.fin_uncollected_receivables_detailed as d WHERE
- (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
d.contractSid = a.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 = a.sid)) debt,
= fd.sid WHERE sd.auditState = '3' AND fd.contractSid = a.sid)) debt,