*    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *    *
*
* program generuje konzumace stravniku do CSV
* ceny jidel jsou stanoveny natvrdo, neberou se z dat
*
*
* 2023-01-30 - pred exportem se smazou soubory z minula
* 2024-01-24 - zmeneny ceny a dotace
*
*    *    *    *    *    *    *    *    *    *    *    *      #> ver. 2024-01-24 <#       *    *    *    *    *    *    *    *    *    *    *    *    *


WAIT PROGRAM() WINDOW AT 22,22 NOWAIT 

DO clos_data
ACTIVATE SCREEN 
CLEAR 

STORE "" TO datsk1, datsk2, mesicek, s_trz_dat1, s_trz_dat2
nastav_obdobi()


DO ppgm_http 
SET PROCEDURE TO ppgm_stravnici ADDITIVE 

DO get_courses      IN stravovani_ppgm
DO get_clients      IN stravovani_ppgm

DO get_meals        IN stravovani_ppgm
DO get_orders       IN stravovani_ppgm

SELECT 0

SELECT client_id, LEFT(clientname, 44) as clientname, firma, date as cas_odberu, course, name, ordered as pocet, eaten, ;
       00000.00 as dotovana, 00000.00 as plna, 00000.00 as dotace ;
       WHERE ATC("lunch_main", course) + ATC("dinner", course) > 0 .and. ordered # 0 ORDER BY clientname, date, course, number ;
       FROM orders INTO TABLE (m.gcexportpath + "velim")

*REPLACE FOR ATC("M1", name) > 0 plna WITH  98, dotace WITH 68
*REPLACE FOR ATC("M2", name) > 0 plna WITH  98, dotace WITH 68
*REPLACE FOR ATC("M3", name) > 0 plna WITH  98, dotace WITH 61
*REPLACE FOR ATC("M4", name) > 0 plna WITH 114, dotace WITH 65
*REPLACE FOR ATC("M5", name) > 0 plna WITH 131, dotace WITH 72
*REPLACE FOR ATC("M6", name) > 0 plna WITH  98, dotace WITH 61
*REPLACE FOR ATC("M7", name) > 0 plna WITH  98, dotace WITH 61
*REPLACE FOR ATC("M8", name) > 0 plna WITH  98, dotace WITH 61

REPLACE FOR ATC("M1", name) > 0 plna WITH 100, dotace WITH 70
REPLACE FOR ATC("M2", name) > 0 plna WITH 100, dotace WITH 70
REPLACE FOR ATC("M3", name) > 0 plna WITH 100, dotace WITH 63
REPLACE FOR ATC("M4", name) > 0 plna WITH 116, dotace WITH 67
REPLACE FOR ATC("M5", name) > 0 plna WITH 133, dotace WITH 74
REPLACE FOR ATC("M6", name) > 0 plna WITH 100, dotace WITH 63
REPLACE FOR ATC("M7", name) > 0 plna WITH 100, dotace WITH 63
REPLACE FOR ATC("M8", name) > 0 plna WITH 100, dotace WITH 63
REPLACE all dotovana WITH plna - dotace

REPLACE ALL firma WITH alpha_digit_only(firma)

ERASE                                       (m.gcexportpath + "velim_*.*")
SELECT disti firma FROM velim INTO CURSOR firmy 
SCAN
    SCATTER MEMVAR 
    ? m.gcexportpath + "velim_" + ALLTRIM(m.firma)
    SELECT * FROM (m.gcexportpath + "velim") ;
           WHERE firma = m.firma INTO TABLE (m.gcexportpath + "velim_" + ALLTRIM(m.firma))
    SET POINT TO "."
    dbf2csv()
    USE 
ENDSCAN 

DO clos_data
WAIT CLEAR 


*     *     *     *     *     *     *     *     *     *     *     *     *     *     *     *     *     *     *     *     *     *     
PROCEDURE nastav_obdobi
IF DAY(DATE()) < 20
    s_trz_dat2 = DATE(YEAR(DATE()   ), MONTH(DATE()   ), 1) - 1
ELSE
    s_trz_dat2 = DATE(YEAR(DATE()+27), MONTH(DATE()+27), 1) - 1
ENDIF
s_trz_dat1     = DATE(YEAR(m.s_trz_dat2), MONTH(m.s_trz_dat2), 1)

datsk1 = LEFT(TTOC(m.s_trz_dat1, 3), 10)
datsk2 = LEFT(TTOC(m.s_trz_dat2, 3), 10)

mesicek = SUBSTR(datsk1, 3, 2) + SUBSTR(datsk1, 6, 2)                     && "2108", cili ctyrmistne RRMM

ACTIVATE SCREEN 
?    "exportuje se obdobi: " + m.datsk1 + " - " + m.datsk2 + "  ( " + m.mesicek + " )"
