*       *       *       *       *       *       *       *       *       *       *       *       *       *       *       *       *
*
*   ucetni export pro hlobikovy pivovary
*   zatim neni vyber obdobi ani exportniho adresare, to dodelam, az vyzkousi format souboru
*
*  2022-01-21
*
*       *       *         #> ver. 2022-01-21 <#         *       *       *       *       *       *       *       *       *       *


USE (m.gcdat_path + "partneri") IN 0 ORDER c_partner
USE (m.gcdat_path + "obraty")   IN 0
USE (m.gcdat_path + "doklady")  IN 0

SELECT c_dokl as cislo, datum_dokl as datum, datum_dokl as datum2, datum_dokl as datum_dph, datum_dokl as datum_uct, doklad, pz2 as doklad3, c_partner as cis, ;
       " " as text, $0 as kcs, $0 as zn, $0 as z0, $0 as z5, $0 as d5, $0 as z2, $0 as d2, $0 as z23, $0 as d23,  ;
       " " as stred, " " as stred_naz, " " as stred2, " " as stred2_naz, " " as stred3, " " as stred3_naz, " " as stred4," " as stred4_naz, ;
       " " as druh, " " as rada, {} as datspl, " " as konsym, 0.0 as cm, " " as mena, 0 as kurs, 0 as kurs2, 0 as euro_kurs, " " as foruhr, " " as typdokl, " " as kod_eu, ;
       SPACE(30) as odb_naz, " " as odb_naz2, " " as odb_uli, " " as odb_obe, " " as odb_psc, " " as odb_uli2, " " as odb_obe2, " " as odb_psc2, SPACE(11) as odb_ico, " " as odb_pob, ;
       SPACE(11) as odb_dic, " " as odb_ucet, " " as odb_smkod, " " as odb_tel, " " as odb_tel2, " " as odb_gsm, " " as odb_fax, " " as odb_email, " " as odb_www, " " as odb_stat, " " as odb_iban, ;
       " " as poznamka, " " as parznak, " " as zpriznak, 0 as zcislo, .F. as eet_evid ;
       FROM doklady WHERE operace = "VE" AND datum_dokl > DATE() - 55 INTO TABLE vydfak

SET RELATION TO cis INTO partneri
REPLACE ALL odb_naz WITH partneri.partner, odb_ico WITH partneri.ico, odb_dic WITH partneri.dic

SELECT c_dokl as p_cislo, "zbozi " + STR(dan*100-100) as p_text, - mnozstvi*cena_part as p_celkem, dan as p_procento, - mnozstvi as p_mnozstvi ;
       WHERE c_dokl IN (SELECT cislo FROM vydfak) FROM obraty INTO TABLE oo_1
DELETE FOR p_celkem = 0
       
SELECT p_cislo, p_text, SUM(p_celkem) as p_celkem, 0000 as p_typ, 0.0 as p_cm, $0 as p_zaklad, p_procento, $0 as p_dan, ;
       " " as p_stred, " " as p_stred_n, " " as p_stred2, " " as p_stred2_n, " " as p_stred3, " " as p_stred3_n, " " as p_stred4," " as p_stred4_n, ;
       .F. as p_rozpoc, {} as p_datum3, " " as p_parznak, 0 as p_zcislo, 0 as p_rpdp, SUM(p_mnozstvi) as p_mnozstvi, 0 as p_ztyp, 0 as p_rezim ;
       GROUP BY 1,2 FROM oo_1 INTO TABLE vydpol
       
REPLACE FOR EMPTY(p_procento) p_procento WITH 1
REPLACE ALL p_zaklad WITH ROUND(p_celkem / p_procento, 2), p_dan WITH p_celkem - p_zaklad
