| | |
| | | c.customer_name, |
| | | T1.contractAmounts AS contractAmounts, |
| | | IFNULL(T2.receiptPaymentAmount, 0) AS receiptPaymentAmount, |
| | | T1.contractAmounts - (IFNULL(T2.receiptPaymentAmount, 0) - IFNULL(T4.returnAmount, 0)) AS receiptableAmount, |
| | | IFNULL(T5.receiptRecordAmount, 0) AS receiptRecordAmount, |
| | | T1.contractAmounts - IFNULL(T2.receiptPaymentAmount, 0) - IFNULL(T4.returnAmount, 0) AS receiptableAmount, |
| | | IFNULL(T4.returnAmount, 0) AS returnAmount |
| | | from (select customer_id, sum(contract_amount) as contractAmounts from sales_ledger group by customer_id) T1 |
| | | left join (select customer_id, sum(collection_amount) as receiptPaymentAmount from account_sales_collection group by customer_id) T2 on T1.customer_id = T2.customer_id |
| | | left join (select party_id, sum(amount) as receiptRecordAmount from payment_record where party_type = 1 and direction = 1 group by party_id) T5 on T5.party_id = T1.customer_id |
| | | left join ( |
| | | select |
| | | sl.customer_id, |
| | |
| | | where rm.status=1 |
| | | group by sl.customer_id |
| | | ) T4 on T4.customer_id=T1.customer_id |
| | | left join customer c on T1.customer_id = c.id |
| | | inner join customer c on T1.customer_id = c.id |
| | | <where> |
| | | <if test="customerName!=null and customerName!=''"> |
| | | AND c.customer_name LIKE CONCAT('%', #{customerName}, '%') |
| | |
| | | sl.execution_date, |
| | | sl.contract_amount AS contract_amount, |
| | | IFNULL(T1.receiptPaymentAmount, 0) AS receiptPaymentAmount, |
| | | sl.contract_amount - (IFNULL(T1.receiptPaymentAmount, 0) - IFNULL(T3.returnAmount, 0)) AS receiptableAmount, |
| | | IFNULL(T5.receiptRecordAmount, 0) AS receiptRecordAmount, |
| | | sl.contract_amount - IFNULL(T1.receiptPaymentAmount, 0) - IFNULL(T3.returnAmount, 0) AS receiptableAmount, |
| | | IFNULL(T3.returnAmount, 0) AS returnAmount |
| | | from sales_ledger sl |
| | | left join ( |
| | | select |
| | | sl.id, |
| | | sum(ascc.collection_amount) as receiptPaymentAmount |
| | | from account_sales_collection ascc |
| | | left join stock_out_record sor on FIND_IN_SET(sor.id, ascc.stock_out_record_ids) > 0 |
| | | left join shipping_info s on sor.record_id = s.id |
| | | LEFT JOIN sales_ledger sl ON s.sales_ledger_id = sl.id |
| | | WHERE sor.record_type='13' |
| | | and sor.approval_status=1 |
| | | group by sl.id |
| | | select x.id, sum(x.receiptPaymentAmount) as receiptPaymentAmount |
| | | from ( |
| | | <!-- 手工发货单出库:收款单按 stock_out_record_ids 关联出库单,再经 shipping_info 找到销售台账 --> |
| | | select |
| | | sl.id, |
| | | sum(ascc.collection_amount) as receiptPaymentAmount |
| | | from account_sales_collection ascc |
| | | left join stock_out_record sor on FIND_IN_SET(sor.id, ascc.stock_out_record_ids) > 0 |
| | | left join shipping_info s on sor.record_id = s.id |
| | | LEFT JOIN sales_ledger sl ON s.sales_ledger_id = sl.id |
| | | WHERE sor.record_type='13' |
| | | and sor.approval_status=1 |
| | | group by sl.id |
| | | |
| | | UNION ALL |
| | | |
| | | <!-- 油品出库:收款单存的是绑定行 id,台账直接从绑定行上取(一个出库单可能拆给多个台账) --> |
| | | select |
| | | slb.id, |
| | | sum(ascc.collection_amount) as receiptPaymentAmount |
| | | from account_sales_collection ascc |
| | | inner join stock_out_record_sales_ledger b on FIND_IN_SET(b.id, ascc.stock_out_binding_ids) > 0 |
| | | inner join stock_out_record sor on sor.id = b.stock_out_record_id |
| | | and sor.approval_status = 1 |
| | | and (sor.type is null or sor.type = '') |
| | | inner join sales_ledger slb on slb.id = b.sales_ledger_id |
| | | group by slb.id |
| | | ) x |
| | | group by x.id |
| | | )T1 on T1.id = sl.id |
| | | left join ( |
| | | select sl.id, |
| | |
| | | where rm.status=1 |
| | | group by sl.id |
| | | )T3 on T3.id = sl.id |
| | | left join ( |
| | | select party_id, sum(amount) as receiptRecordAmount |
| | | from payment_record |
| | | where party_type = 1 and direction = 1 |
| | | group by party_id |
| | | )T5 on T5.party_id = sl.customer_id |
| | | where sl.customer_id = #{customerId} |
| | | order by sl.id desc |
| | | </select> |