INSERT INTO penzeszkoz_iktato (datum, partner_kod, osszeg, bizonylatszam, raktar_mozgas_fej_kod,
       forras_penzeszkoz, cel_penzeszkoz, deviza_nev, c_userid, c_date, c_time) 
(SELECT rmf.kelte as datum, rmf.partner_kod, rmf.brutto_arbevetel_vegosszeg_huf as osszeg, rmf.bizonylatszam, rmf.kod as raktar_mozgas_fej_kod,
       0 as forras_penzeszkoz, rmf.penzeszkoz_kod as cel_penzeszkoz, rmf.deviza_nev, 'automata' as c_userid, current_date as c_date, now()::timestamp as c_time
   FROM (SELECT * FROM raktar_mozgas_fej WHERE bizonylat_fajta in (3,5) AND fizetesmod_kod = 1 AND c_date >= current_date) rmf
  LEFT JOIN penzeszkoz_iktato pi ON pi.raktar_mozgas_fej_kod = rmf.kod
  WHERE pi.kod is null
 order by rmf.kod)