facilidades_de_pago/VERIFICAR EN OLYMPO/002 DIVIDENDOS CONVENIOS.sql

24 lines
1.1 KiB
MySQL
Raw Normal View History

2024-11-15 12:22:39 -05:00
--select * from cll_agreement where code = '002463'
select collection_dividend_id,
min(collection_id) collection_id,
min(cvl.tax_id) tax_id,
cll_c.code,
cll_c.description,
max(tax_value) tax_value,
max(cdl.vat) tax_vat,
coalesce(max(value_increase),0.00) value_increase,
coalesce(sum(agreement_increase),0.00) agreement_increase,
coalesce(max(value_surcharge),0.00) value_surcharge,
coalesce(sum(agreement_surcharge),0.00) agreement_surcharge,
coalesce(sum(case when vouchers_id is null then penalty_fee else 0.00 end ),0.00) penalty_fee,
coalesce(sum(case when not vouchers_id is null then penalty_fee else 0.00 end ),0.00) agreement_penalty_fee,
coalesce(max(value_discount),0.00) value_discount,
coalesce(sum(agreement_discount),0.00) agreement_discount,
min(cdl.date_due) as date_due
from cll_vouchers_line cvl
inner join cll_dividend_line cdl on cdl.id = cvl.collection_dividend_id
inner join cll_collection cll_c on cll_c.id = cvl.collection_id
where cvl.agreement_id = 2761
group by cvl.collection_dividend_id, cll_c.id
order by cvl.collection_dividend_id