*     *     *     *     *     *     *     *     *     *     *     *     *     *     *     *     *     *     *     *     
*
*  tisk prijemek od CELEHO SPOJE (tedy se stejnym cislem rajdy)
*
*     *     *     *     *     *     *     *     *     *  *BEZ HADA*     *     *     *     *     *     *     *     *

PARAMETERS rajda_id

menostrediska = "Hlavni sklad"
fn_rides      = "i:\d_leo\data\rides"

USE (m.fn_doklady)  IN 0 ALIAS leo_doklady  NOUPDATE AGAIN 
USE (m.fn_obraty)   IN 0 ALIAS leo_obraty   NOUPDATE AGAIN
USE (m.fn_karty)    IN 0 ALIAS leo_karty    NOUPDATE AGAIN
USE (m.fn_partneri) IN 0 ALIAS leo_partneri NOUPDATE AGAIN
USE (m.fn_rides)    IN 0 ALIAS leo_rides    NOUPDATE AGAIN


IF EMPTY(m.rajda_id)

    SELECT line_name, date, id FROM leo_rides INTO CURSOR rajdy_s_vydejem  WHERE id in (SELECT VAL(pz2) FROM leo_doklady)

    SELECT disti line_name FROM rajdy_s_vydejem INTO CURSOR jmena_rajd
    DEFINE POPUP nabidka PROMPT FIELD line_name FROM 1,22 TITLE "Vyber název linky"
    ON SELECTION POPUP nabidka deacti popup
    ACTIVATE SCREEN
    ACTIVATE POPUP nabidka
    IF .not. EMPTY(PROMPT())
        line_name = PROMPT()
        SELECT disti date, id FROM rajdy_s_vydejem INTO CURSOR datumy_rajd WHERE line_name = m.line_name
        DEFINE POPUP nabidka PROMPT FIELD date FROM 1,22 TITLE "Vyber datum linky " + ALLTRIM(m.line_name) 
        ON SELECTION POPUP nabidka deacti popup
        ACTIVATE SCREEN
        ACTIVATE POPUP nabidka
        IF .not. EMPTY(PROMPT())
            rajda_id = datumy_rajd.id
            leo_tisk_2()
        ENDIF 
    ENDIF 
    RELEASE POPUP nabidka

ELSE
    leo_tisk_2()
ENDIF 

DO pozavirej WITH "leo_obraty, leo_doklady, leo_karty, leo_partneri, leo_rides"


*     *     *     *     *     *     *     *     *     *     *     *     *     *     *     *     *     *     *     *     
PROCEDURE leo_tisk_2

SELECT leo_rides
LOCATE FOR id = m.rajda_id
IF FOUND()
    SCATTER FIELDS date, line_name memvar
ELSE
    date      = {^1111-11-11}
    line_name = "## " + ALLTRIM(STR(m.rajda_id, 12)) + " ##"
ENDIF 

SELECT d.*, p.partner ;
       WHERE operace = "PE" .and. d.c_partner < 0 .and. d.platba = "Leo  " .and. VAL(pz2) = rajda_id ;
       FROM leo_doklady d LEFT JOIN leo_partneri p ON d.c_partner = p.c_partner INTO CURSOR rajda_dokl

SELECT o.*, rd.c_partner, rd.pz1, rd.pz2, rd.doklad, rd.datum_dokl, rd.provedl, rd.kdy, rd.c_dokl_x, partner ;
       WHERE o.c_karty # 0 FROM leo_obraty o RIGHT JOIN rajda_dokl rd ON o.c_dokl = rd.c_dokl INTO CURSOR r1

SELECT r1.*, k.nazev, k.druh, m.date as line_date, m.line_name as line_name ;
       ORDER BY partner, c_dokl, poradi ;
       FROM r1 LEFT JOIN leo_karty k ON r1.c_karty = k.c_karty INTO CURSOR r2

DO pr_report WITH "obr_leo"

DO pozavirej WITH "r1, r2"
