SELECT m2_ft.faktura, m2_hfakt.ico, m2_hfakt.zavod, m2_hfakt.dat_odesl, m2_hfakt.dat_splat, m2_hfakt.sleva, {} as dat_zap, 000000000.00 as zap_cel, 000.00 as zad_sleva, SUM (m2_hfakt.kurz * (m2_ft.kcs + m2_ft.dan_rad) * (1 - m2_hfakt.sleva /100)) AS celkem_kc, SUM ((m2_ft.kcs + m2_ft.dan_rad) * m2_hfakt.kurz) AS Bez_slevy, m2_ft.sek_ident AS jkpov, 'O' as puvod, 000000000.00 as cisty_obr, 000000000.00 as bonus, m2_ft.dan FROM m2_ft, m2_hfakt WHERE m2_ft.faktura = m2_hfakt.faktura AND inlist (m2_hfakt.stav_fakt,"4", "5", "6") AND m2_hfakt.dat_fakt BETWEEN odobd .and. doobd AND INLIST (m2_ft.kod, 'X', 'S') AND (SIGN (m2_ft.ks) * SIGN (m2_ft.kcs) = 1 or m2_ft.ks > 0 and empty (m2_ft.kcs) ) AND &podm1 GROUP BY 1 INTO TABLE c21
SELECT m2_ft.faktura, m2_hfakt.ico, m2_hfakt.zavod, m2_hfakt.dat_odesl, m2_hfakt.dat_splat, m2_hfakt.sleva, {} as dat_zap, 000000000.00 as zap_cel, 000.00 as zad_sleva, SUM (m2_hfakt.kurz * (m2_ft.kcs + m2_ft.dan_rad) * (1 - m2_hfakt.sleva /100)) AS celkem_kc, SUM ((m2_ft.kcs + m2_ft.dan_rad) * m2_hfakt.kurz) AS Bez_slevy, m2_ft.sek_ident AS jkpov, 'O' as puvod, 000000000.00 as cisty_obr, 000000000.00 as bonus, m2_ft.dan FROM m2_ft, m2_hfakt WHERE m2_ft.faktura = m2_hfakt.faktura AND inlist (m2_hfakt.stav_fakt,"4", "5", "6") AND m2_hfakt.dat_fakt BETWEEN odobd .and. doobd AND INLIST (m2_ft.kod, 'X', 'S') AND (SIGN (m2_ft.ks) * SIGN (m2_ft.kcs) = 1 or m2_ft.ks > 0 and empty (m2_ft.kcs) ) AND not &podm1 GROUP BY 1 INTO TABLE c21