| | |
| | | sm.supplier_name, |
| | | T1.contractAmounts, |
| | | IFNULL(T2.paymentAmount, 0) AS paymentAmount, |
| | | IFNULL(T3.InboundAmount, 0) - IFNULL(T4.returnAmount, 0) AS payableAmount |
| | | case when IFNULL(T3.InboundAmount, 0) - IFNULL(T4.returnAmount, 0) <![CDATA[ > ]]> T1.contractAmounts |
| | | then T1.contractAmounts - IFNULL(T4.returnAmount, 0) |
| | | else IFNULL(T3.InboundAmount, 0) - IFNULL(T4.returnAmount, 0) |
| | | end AS payableAmount |
| | | from (select supplier_id, sum(COALESCE(net_contract_amount, contract_amount)) as contractAmounts from purchase_ledger group by supplier_id) T1 |
| | | left join (select supplier_id, sum(payment_amount) as paymentAmount from account_purchase_payment group by supplier_id) T2 on T1.supplier_id = T2.supplier_id |
| | | left join ( |
| | |
| | | pl.execution_date, |
| | | COALESCE(pl.net_contract_amount, pl.contract_amount) AS contract_amount, |
| | | IFNULL(T1.paymentAmount, 0) AS paymentAmount, |
| | | IFNULL(T2.InboundAmount, 0) - IFNULL(T3.returnAmount, 0) AS payableAmount |
| | | case when IFNULL(T2.InboundAmount, 0) - IFNULL(T3.returnAmount, 0) <![CDATA[ > ]]> COALESCE(pl.net_contract_amount, pl.contract_amount) |
| | | then COALESCE(pl.net_contract_amount, pl.contract_amount) - IFNULL(T3.returnAmount, 0) |
| | | else IFNULL(T2.InboundAmount, 0) - IFNULL(T3.returnAmount, 0) |
| | | end AS payableAmount |
| | | from purchase_ledger pl |
| | | left join ( |
| | | select |