#DEFINE ODD          ";"
#DEFINE CRLF         CHR(13)+CHR(10)

o_set_point = SET("POINT")

*HTTP_READ_ONLY_MODE = .T.

* altopraha izg65-HUZH


DO (LOWER(JUSTPATH(sys(16))) + "\http_ppgm_leo") WITH "https://api-dev.le.cz/api/v1/"

http_auth_token = "altoA4alxcSx6asd95asjf652"

json = http_get("catering/products?append=apk")

json = http_get("catering/categories?append=apk")

json = http_get("rides?date=2019-06-30&type=0")


RETURN 
RETURN 
RETURN 

*= apetee_get( 'connection_ping' )
*= apetee_get( 'get_restaurant_orders_list_from_last_id&username=eevvzzeenn&password=EEvvzzeenn1&last_id=1' )
*= apetee_get( 'get_order_details&id=1243&type=0' )

*= apetee_get( 'table_available&date=18.6.2019&hourmin=18:30&people=4' )
*= apetee_get( 'table_available&date=18.6.2019&hourmin=17:30&people=3&id_table=1' )
*= apetee_get( 'get_orders_list' )
*= apetee_get( '' )
*= apetee_get( '' )


*!*    ? apetee_get( 'change_status&status_id=1&ids[]=3')
*!*    ? apetee_get( 'change_status&status_id=2&ids[]=3')
*!*    ? apetee_get( 'change_status&status_id=3&ids[]=3')
*!*    ? apetee_get( 'change_status&status_id=9&ids[]=3')

*!*    ? apetee_get( 'change_status_to_paid&status_id=7&ids[]=3&payments[]=1234')



date_from = LEFT(TTOC(DATE()-33, 3), 10)
date_to   = LEFT(TTOC(DATE()+44, 3), 10)

*json = apetee_get( 'get_orders_list_from_date_to_date_confirmed&from_date=' + m.date_from+ '&to_date=' + m.date_to)
json = apetee_get( 'get_orders_list_from_date_to_date&from_date=' + m.date_from+ '&to_date=' + m.date_to)

IF FILE(m.gccen_path + "apetee.dbf")
    USE (m.gccen_path + "apetee") IN 0
ELSE
    CREATE TABLE (m.gccen_path + "apetee") FREE ;
           (id I, sid C(22), stul N(7,1), zakaznik C(55), email C(55), status I, status_nam C(33), zacatek T, konec T, stravniku N(2), cas_usazen T, cas_platby T, trzba Y)
ENDIF 

FOR ii = 1 TO 999
   id         = VAL(get_string_item  (m.json, "id_reserv"    , ii))
   sid        =     get_string_item  (m.json, "sid_reserv"   , ii)
   stul       = VAL(get_string_item  (m.json, "table_id"     , ii))
   zakaznik   =     get_string_item  (m.json, "user_name"    , ii)
   datum      =     get_string_item  (m.json, "date"         , ii)
   cas        =     get_string_item  (m.json, "time"         , ii)
   duration   = VAL(get_string_item (m.json, "duration"      , ii))
   stravniku  = VAL(get_string_item (m.json, "for"           , ii))
   email      =     get_string_item  (m.json, "user_mail"    , ii)
   status     = VAL(get_string_item  (m.json, "status"       , ii))
   status_nam =     get_string_item  (m.json, "status_name"  , ii)
   IF m.id # 0
      zacatek = DATETIME(VAL(LEFT(datum,4)), VAL(SUBSTR(datum,6,2)), VAL(SUBSTR(datum,9,2)), VAL(LEFT(cas,2)), VAL(SUBSTR(cas,4,2))  )
      konec   = m.zacatek + 60 * m.duration
      LOCATE FOR id = m.id
      IF FOUND()
          IF status # m.status
              REPLACE status_nam WITH ALLTRIM(STR(status)) + " " + status_nam, status WITH m.status
          ENDIF 
      ELSE
          INSERT INTO apetee FROM MEMVAR
      ENDIF 
   ELSE 
      EXIT  
   ENDIF 
ENDFOR 


ACTIVATE SCREEN 
BROWSE 

SCAN && FOR status = 1
    DO CASE  
    CASE .not. EMPTY(cas_platby)
        send_status (id, 11)
*= apetee_get( '' )

    CASE .not. EMPTY(cas_usazen)
        send_status (id, 9)
        ? id
        ? apetee_get( 'change_status&status_id=9&ids[]=' + ALLTRIM(STR(id, 9)))

    ENDCASE 
ENDSCAN 





*!* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
FUNCTION apetee_get(retezec)
RETURN http_get( 'index.php?option=com_vikrestaurants&tmpl=component&task=apis&event=' + m.retezec + '&username=eevvzzeenn&password=EEvvzzeenn1')


*!* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
FUNCTION send_status(id, status)



*!* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*!*   01   APETEE_STATUS_CONFIRMED                                             Potvrzeno (restaurace)
*!*   02   APETEE_STATUS_CANCELLED                                              Zrušeno (restaurace)
*!*   03   APETEE_STATUS_PENDING                                    Čeká na potvrzení (restaurace)
*!*   04   APETEE_STATUS_CONFIRMED_TK                     Potvrzeno (Take-Away)
*!*   05   APETEE_STATUS_REMOVED_TK                          Smazáno (Take-Away)
*!*   06   APETEE_STATUS_PENDING_TK                            Čeká na potvrzení (Take-Away)
*!*   07   APETEE_STATUS_REGISTERED                            Zapsáno (restaurace)
*!*   08   APETEE_STATUS_REMOVED                                  Smazáno (restaurace)
*!*   09   APETEE_STATUS_SEATED                                      Usazeni (restaurace)
*!*   10   APETEE_STATUS_PAYMENT_PENDING                            Čeká na zaplacení zálohy online (restaurace)
*!*   11   APETEE_STATUS_PAID                                             Zaplaceno (restaurace)
*!*   12   APETEE_STATUS_CANCELLED_TK                      Zrušeno (Take-Away)
*!*   13   APETEE_STATUS_PAYMENT_PENDING_TK    Čeká na zaplacení objednávky/zálohy online (Take-Away)
*!*   14   APETEE_STATUS_PAID_TK                                     Zaplaceno (Take-Away)

*!*    Zaplacení zálohy = APETEE_STATUS_REGISTERED
*!*    Zaplacení celé částky  = APETEE_STATUS_PAID

 