|
@@ -16,33 +16,34 @@
|
|
|
(t1.sumClaimMoney - t1.invoiceAmount) as unInvoiceAmount,
|
|
|
(CASE WHEN t1.sumClaimMoney < t1.outboundAmount THEN 1 ELSE 0 END) AS isSpecialOutbound
|
|
|
FROM (SELECT t1.*,
|
|
|
- c.name customerName,
|
|
|
+ c.name customerName,
|
|
|
(SELECT IFNULL(SUM(cc.contract_money), 0)
|
|
|
FROM claim_contract cc
|
|
|
JOIN claim cl ON cc.claim_id = cl.id
|
|
|
WHERE cl.confirm_status = 1
|
|
|
- and cc.contract_id = t1.id) AS sumClaimMoney,
|
|
|
+ and cc.contract_id = t1.id) AS sumClaimMoney,
|
|
|
po.produce_status,
|
|
|
- IFNULL(t3.quantity, 0) AS waitStockQuantity,
|
|
|
- IFNULL(t3.receipt_quantity, 0) AS receiptStockQuantity,
|
|
|
+ IFNULL(t3.quantity, 0) AS waitStockQuantity,
|
|
|
+ IFNULL(t3.receipt_quantity, 0) AS receiptStockQuantity,
|
|
|
IFNULL(
|
|
|
(SELECT sum(pod.finish_quantity * cp.price)
|
|
|
FROM contract_product cp
|
|
|
JOIN production_order_detail pod ON pod.contract_detail_id = cp.id
|
|
|
WHERE cp.contract_id = t1.id)
|
|
|
,
|
|
|
- 0) AS settledAmount,
|
|
|
- po.delivery_period as prodDeliveryPeriod,
|
|
|
- IFNULL(t4.deliverQuantity, 0) as deliverQuantity,
|
|
|
- IFNULL(t4.notDeliverQuantity, 0) as notDeliverQuantity,
|
|
|
+ 0) AS settledAmount,
|
|
|
+ po.delivery_period as prodDeliveryPeriod,
|
|
|
+ IFNULL(t4.deliverQuantity, 0) as deliverQuantity,
|
|
|
+ IFNULL(t4.notDeliverQuantity, 0) as notDeliverQuantity,
|
|
|
(SELECT IFNULL(sum(iacd.amount), 0)
|
|
|
FROM invoice_apply_contract_detail iacd
|
|
|
JOIN invoice_apply ia ON iacd.invoice_apply_id = ia.id
|
|
|
WHERE ia.`status` IN (10, 30, 60)
|
|
|
- AND iacd.contract_id = c.id) AS invoiceAmount,
|
|
|
- IFNULL(cor_1.outbound_amount, 0) AS outboundAmount,
|
|
|
+ AND iacd.contract_id = c.id) AS invoiceAmount,
|
|
|
+ IFNULL(cor_1.outbound_amount, 0) AS outboundAmount,
|
|
|
TIMESTAMPDIFF(MINUTE, t1.review_begin_time, IFNULL(t1.review_end_time, now())) /
|
|
|
- 24 AS reviewElapsedTime
|
|
|
+ 24 AS reviewElapsedTime,
|
|
|
+ IF(sc1.scheduling_count > 0, 1, 0) AS is_scheduling
|
|
|
FROM contract t1
|
|
|
left join customer c on t1.buy_corporation_id = c.id
|
|
|
LEFT JOIN production_order po ON po.contract_id = t1.id
|
|
@@ -68,7 +69,12 @@
|
|
|
left join (SELECT cor.contract_id,
|
|
|
sum(cor.price * cor.truck_quantity) AS outbound_amount
|
|
|
FROM contract_outbound_records cor
|
|
|
- GROUP BY cor.contract_id) cor_1 on cor_1.contract_id = t1.id) t1
|
|
|
+ GROUP BY cor.contract_id) cor_1 on cor_1.contract_id = t1.id
|
|
|
+ LEFT JOIN (SELECT count(1) AS scheduling_count,
|
|
|
+ pod.contract_id
|
|
|
+ FROM production_scheduling ps
|
|
|
+ JOIN production_order_detail pod ON ps.task_id = pod.id
|
|
|
+ GROUP BY pod.contract_id) sc1 ON sc1.contract_id = t1.id) t1
|
|
|
GROUP BY t1.id) t1
|
|
|
</sql>
|
|
|
|