 SET NAMES utf8;

DELIMITER $$

/*************************************************************************************************************************************************************************
    system
************************************************************************************************************************************************************************ */    
DROP FUNCTION IF EXISTS `_Birth_System`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_Birth_System`() RETURNS VARCHAR(20)
    DETERMINISTIC
--  COMMENT 'narodziny swiata - ustawienie kilku kluczowych zmiennych'
BEGIN
/*
    narodziny swiata - ustawienie kilku kluczowych zmiennych gdy zmienna narodzin = NULL
    Kilka uwag dot. @session.LOGON.Ver
        1.0        stare i starsze logowania
        2.0        ustawiana jest na 1 zmienna do zapisu w `_erp_external_process_log` zmian w tabeli logowań `_sys_db_logons_ad`    
        >  2.0
        >= 2.15    np. KONKOL nowe procedury logowania (od 2021-01-13)
        >= 2.20    przeróbka świata E ng_e_rec itp
        UWAGA XI 2022 -> musze dodać VER dla obsługi samego `_sys_db_logons` (przynajmniej triggery)
*/
--  Zmienne Systemowe
    IF (@session.Birth IS NULL) OR (@session.Birth < (NOW() - INTERVAL 30 MINUTE)) THEN
        SET 
            -- @session.Birth = IFNULL(@session.Birth, NOW()),    -- moze byc <> NULL (patrz warunek wyżej))!!!.. i  wtedy nie wstawiaj nowego czasu
            @session.Birth = NOW(),    -- (patrz warunek wyżej))!!!
            @session.Delfinek = IFNULL(@session.Delfinek, FALSE),
            @session.AllTriggerDisabled = (_GetVer() = '5.1.30'),
            @session.LOGON.Ver = _Globals_Get_Only_IFNULL('LOGON.Ver', @session.LOGON.Ver),
            @session.globals.sdl.LOG.Ver = _Globals_Get_Only_IFNULL('sdl.LOG.Ver', @session.globals.sdl.LOG.Ver),

            @session.LOGON.user_accounts_Mode = _Globals_Get_Only_IFNULL('LOGON.user_accounts_Mode', @session.LOGON.user_accounts_Mode),
            @session.globals.Owner = _Globals_Get_Only_IFNULL('Owner', @session.globals.Owner),
            @session.globals.Owner_kontrguid = _Globals_Get_Only_IFNULL('Owner_kontrguid', @session.globals.Owner_kontrguid),
            @session.globals.INPUT_SALT_Hash = _Globals_Get_Only_IFNULL('_SLT_#', @session.globals.INPUT_SALT_Hash),
            @session.globals.APPLY.LOG.Active = _Globals_Get_Only_IFNULL('APPLY.LOG.Active', @session.globals.APPLY.LOG.Active),
            @session.LOCK.Ver = _Globals_Get_Only_IFNULL('LOCK.Ver', @session.LOCK.Ver),
            @session.globals.APPLY.LOG.Active = _Globals_Get_Only_IFNULL('APPLY.LOG.Active', @session.globals.APPLY.LOG.Active)
        ;
        SET @_INPUT_SALT_Hash = @session.globals.INPUT_SALT_Hash;
        SET @session.globals.APPLY.LOG.Active = IF(@session.globals.APPLY.LOG.Active = '', 'OFF', @session.globals.APPLY.LOG.Active);
    --  ExecuteCmd - czy z transakcją?    
        SET @session.ExecuteCmd.with.TRANSACTION.Default = IF(@session.globals.Owner IN ('KONKOL','TRANSBUD','SIMEX','CDG'), 0, 1);
        SET @session.ExecuteCmd.with.TRANSACTION = @session.ExecuteCmd.with.TRANSACTION.Default;
    --  Zmienna do zapisu w `_erp_external_process_log` zmian w tabeli logowań `_sys_db_logons_ad`    
        SET 
            @.NEW._sys_db_logons.DETAL = IFNULL(@.NEW._sys_db_logons.DETAL, (@session.LOGON.Ver >= '2')),
            @.C_Ext_Flag_PROGRAMISTA = 'SUPERVISOR'
        ;
    --  Inicjowanie płacowych zmiennych czasowych
        DO _var_Time_PL_init('');
        --  UWAGA!!!!!!!!!!Za Niedługo wywal to poniżej
        SET @session.globals.sdl.LOG.Ver = IF(@session.globals.Owner IN ('CDG'), 'info', @session.globals.sdl.LOG.Ver);
        SET @session.LOGON.Ver = 
            IF(@session.globals.Owner IN (
                'PLISZKAX', 
                'AXIS', 
                'JARZEBINSCY', 
                'AMICUS', 
                'BALTIMA', 
                'INT'
                ), '2.15', @session.LOGON.Ver)
        ;
        /*    WYWAL
        IF @session.globals.Owner = 'SIMEX' AND SCHEMA() = 'httest' THEN 
            SET @session.LOGON.Ver = '3.20';
        END IF;
        */
    END IF;
    
--  Zmienne connection     
    IF 
    @.SYSTEM.CURRENT.con.USER IS NULL  
    OR
    @.SYSTEM.CURRENT.con.HOST IS NULL  
    OR
    @.SYSTEM.CURRENT.con.DB IS NULL  
    THEN
        SELECT 
            p.USER AS _USER, 
            p.HOST AS _HOST,
            p.DB AS _DB 
        FROM information_schema.PROCESSLIST p
        WHERE 
            p.ID = CONNECTION_ID()
            AND
            p.DB = Database()
        INTO
            @.SYSTEM.CURRENT.con.USER,
            @.SYSTEM.CURRENT.con.HOST,
            @.SYSTEM.CURRENT.con.DB
        ;
    END IF;
    
    IF 
    @.IReg_FN.STRING IS NULL  
    THEN
        SET @._DataType = 'STRING';
        SELECT dtm.IReg_FieldName, dtm.DataKey, dtm.Data_type_delphi FROM `_data_type_maps` dtm WHERE dtm.DataKey = @._DataType LIMIT 1
        INTO @.IReg_FN.STRING, @.DataKey.STRING, @.Data_type_delphi.STRING
        ;
        SET @._DataType = 'BOOLEAN';
        SELECT dtm.IReg_FieldName, dtm.DataKey, dtm.Data_type_delphi FROM `_data_type_maps` dtm WHERE dtm.DataKey = @._DataType LIMIT 1
        INTO @.IReg_FN.BOOLEAN, @.DataKey.BOOLEAN, @.Data_type_delphi.BOOLEAN
        ;
        SET @._DataType = 'INTEGER';
        SELECT dtm.IReg_FieldName, dtm.DataKey, dtm.Data_type_delphi FROM `_data_type_maps` dtm WHERE dtm.DataKey = @._DataType LIMIT 1
        INTO @.IReg_FN.INTEGER, @.DataKey.INTEGER, @.Data_type_delphi.INTEGER
        ;
        SET @._DataType = 'FLOAT';
        SELECT dtm.IReg_FieldName, dtm.DataKey, dtm.Data_type_delphi FROM `_data_type_maps` dtm WHERE dtm.DataKey = @._DataType LIMIT 1
        INTO @.IReg_FN.FLOAT, @.DataKey.FLOAT, @.Data_type_delphi.FLOAT
        ;
        SET @._DataType = 'DATE';
        SELECT dtm.IReg_FieldName, dtm.DataKey, dtm.Data_type_delphi FROM `_data_type_maps` dtm WHERE dtm.DataKey = @._DataType LIMIT 1
        INTO @.IReg_FN.DATE, @.DataKey.DATE, @.Data_type_delphi.DATE
        ;
        SET @._DataType = 'TIME';
        SELECT dtm.IReg_FieldName, dtm.DataKey, dtm.Data_type_delphi FROM `_data_type_maps` dtm WHERE dtm.DataKey = @._DataType LIMIT 1
        INTO @.IReg_FN.TIME, @.DataKey.TIME, @.Data_type_delphi.TIME
        ;
        SET @._DataType = 'MEMO';
        SELECT dtm.IReg_FieldName, dtm.DataKey, dtm.Data_type_delphi FROM `_data_type_maps` dtm WHERE dtm.DataKey = @._DataType LIMIT 1
        INTO @.IReg_FN.MEMO, @.DataKey.MEMO, @.Data_type_delphi.MEMO
        ;
        SET @._DataType = 'BLOB';
        SELECT dtm.IReg_FieldName, dtm.DataKey, dtm.Data_type_delphi FROM `_data_type_maps` dtm WHERE dtm.DataKey = @._DataType LIMIT 1
        INTO @.IReg_FN.BLOB, @.DataKey.BLOB, @.Data_type_delphi.BLOB
        ;
    
    /*
        SET
            @.IReg_FN.STRING = (SELECT dtm.IReg_FieldName FROM `_data_type_maps` dtm WHERE dtm.DataKey = 'STRING' LIMIT 1),
            @.IReg_FN.INTEGER = (SELECT dtm.IReg_FieldName FROM `_data_type_maps` dtm WHERE dtm.DataKey = 'INTEGER' LIMIT 1),
            @.IReg_FN.BOOLEAN = (SELECT dtm.IReg_FieldName FROM `_data_type_maps` dtm WHERE dtm.DataKey = 'BOOLEAN' LIMIT 1),
            @.IReg_FN.FLOAT = (SELECT dtm.IReg_FieldName FROM `_data_type_maps` dtm WHERE dtm.DataKey = 'FLOAT' LIMIT 1),
            @.IReg_FN.DATE = (SELECT dtm.IReg_FieldName FROM `_data_type_maps` dtm WHERE dtm.DataKey = 'DATE' LIMIT 1),
            @.IReg_FN.TIME = (SELECT dtm.IReg_FieldName FROM `_data_type_maps` dtm WHERE dtm.DataKey = 'TIME' LIMIT 1)
        ;
    */
    END IF;
    /*
    są trzy poziomy małp:
        @.VAR.LEVEL.1    - systemowe
        @.VAR.LEVEL.2    - Sesyjne dot. sesji, użytkownika etc
        @.VAR.LEVEL.3    - dbGlobal Variables i IReg
        @.VAR.LEVEL.4    - HT i reszta
    */
    SET 
    --   systemowe
        @.VAR.LEVEL.1 = TRUE,
    --  a pozostale ustaw wg istnienia zmiennych
    --  Sesyjne dot. sesji, użytkownika etc    
        @.VAR.LEVEL.2 =  IFNULL(@.VAR.LEVEL.2,
            (@SYSTEM.Client.Session.Kind IS NOT NULL)
            ),
    --  Sesyjne dot. dbGlobal Variables i IReg
        @.VAR.LEVEL.3 = IFNULL(@.VAR.LEVEL.3,
            (@_Session_Refresh_Variables.alocaltime IS NOT NULL)
            OR
            (@_Setting_Variables.alocaltime IS NOT NULL)
            OR
            (@_Setting_Variables.alocaltime.2 IS NOT NULL)
        ),
    --  Sesyjne dot. HT i reszty
        @.VAR.LEVEL.4 = IFNULL(@.VAR.LEVEL.3,
            (@SYSTEM.Client.Session.Kind IS NOT NULL)        
        )
    ;

--  Zmienne czasu zalezne od dziś!!!!    WYWAL - mamy VIEW
    IF !(@.Date.D.Curr <=> DATE(CURRENT_DATE()))
    THEN
    --  Ustaw zmienną do płac do koniecznych updatów na tabelach w płacach
    --  SET @.pl_PYXX_range.NeedUpdate = (@.Date.D.Curr IS NOT NULL);    -- ustaw tylko gdy się zmieniła a nie gdy
    --  Wstęp zmienne brzegowe
    --  do kontrolowania czy gdy nie pracował a ma rekordy YM > @.CURR.YM dawac Delete = 2    
        SET @.Date.D.Curr := DATE(CURRENT_DATE());
        SET @.Date.M.Curr := MONTH(@.Date.D.Curr);
        SET @.Date.Y.Curr := YEAR(@.Date.D.Curr);
        SET @.Date.YM.Curr := @.Date.Y.Curr * 100 + @.Date.M.Curr;

        SET @.Date.D.Prev := @.Date.D.Curr - INTERVAL 1 DAY;
        SET @.Date.M.Prev := MONTH(@.Date.D.PrevM := (@.Date.D.Curr - INTERVAL 1 MONTH));
        SET @.Date.Y.Prev := @.Date.Y.Curr - 1;
        SET @.Date.YM.Prev := YEAR(@.Date.D.PrevM) * 100 + @.Date.M.Prev;
        
        SET @.Date.D.Next := @.Date.D.Curr + INTERVAL 1 DAY;
        SET @.Date.M.Next := MONTH(@.Date.D.NextM := (@.Date.D.Curr + INTERVAL 1 MONTH));
        SET @.Date.Y.Next := @.Date.Y.Curr + 1;
        SET @.Date.YM.Next := YEAR(@.Date.D.NextM) * 100 + @.Date.M.Next;
        /*    select zmienne
            SELECT
                @.Date.D.Curr, @.Date.M.Curr,  @.Date.Y.Curr, @.Date.YM.Curr, 
                @.Date.D.Prev, @.Date.M.Prev,  @.Date.Y.Prev, @.Date.YM.Prev, 
                @.Date.D.Next, @.Date.M.Next,  @.Date.Y.Next, @.Date.YM.Next 
            ;
        */
        SET
            @.Date.PL.MIN.Valid.YM = 
                IF(@.Date.M.Curr <= 6,
                    (@.Date.Y.Curr - 1)*100 + 7,    -- poprz. rok ale od połowy - od lip.
                    (@.Date.Y.Curr + 0)*100 + 1        -- tylko biezacy rok - od sty
                ),
            @.Date.PL.MAX.Valid.YM = 
                IF(@.Date.M.Curr <= 6,
                    (@.Date.Y.Curr + 0)*100 + 12,    -- do konca roku
                    (@.Date.Y.Curr + 1)*100 + 6        -- nast. rok ale tylko do połowy - do cze.
                )
        ;
    END IF;
    
    RETURN @session.Birth;
END
$$

DROP FUNCTION IF EXISTS `_GetVer`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_GetVer`() RETURNS VARCHAR(20)
    DETERMINISTIC
    COMMENT 'Zwraca wersje MySQL'
BEGIN
    RETURN LEFT(@@version, 6);
END
$$

DROP FUNCTION IF EXISTS `_TriggerDisabled`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_TriggerDisabled`() RETURNS BOOLEAN
    DETERMINISTIC
    COMMENT 'Zwraca TRUE gdy triggery nie maja byc uzywane lub '
BEGIN
--  wartosc @session.trigger_lock rowna TRUE blokuje wykonanie triggera
    DO _Birth_System();    --  teraz to tutaj wszystkie zmiene są aktywowane/pobierane
    SET
        @_TriggerDisabled = 
            @session.AllTriggerDisabled
            OR
            IFNULL(@session.trigger_lock, FALSE)
    ;    
    RETURN @_TriggerDisabled;
END
$$

/* ************************************************************************************************************************************************************************
    Err
************************************************************************************************************************************************************************ */	
--  _Report_Error - przeniesiony do _Errors.sql
--  _Report_Err - przeniesiony do _Errors.sql
-- ZGRAJ _Errors.sql i usuń

/* ************************************************************************************************************************************************************************
    KeepID
    @.SYS.KeepID
    IF @.PxH.KeepID IS NULL THEN SET @.PxH.KeepID = CONNECTION_ID(); END IF;
************************************************************************************************************************************************************************ */	
DROP FUNCTION IF EXISTS `_KeepID`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_KeepID`(
    _MODE  VARCHAR(50),
    _Param_A VARCHAR(150)
    ) 
RETURNS BOOLEAN
    NO SQL
    DETERMINISTIC
BEGIN
    DECLARE _KeepID VARCHAR(38);
    IF _MODE IN ('', 'Any', 'RESET', 'SSID') THEN
        SET _KeepID = IFNULL(NULLIF(@SYSTEM.Client.Session.GUID, ''), CONNECTION_ID());
    END IF;
    /*
    IF _MODE = 'SSID' THEN
        SET _KeepID = IFNULL(NULLIF(@SYSTEM.Client.Session.GUID, ''), CONNECTION_ID());
    END IF;
    */
    IF _MODE = 'CON_ID' THEN
        SET _KeepID = CONNECTION_ID();
	END IF;

    IF _MODE = 'SET' THEN
    --  przypisz do _KeepID
        SET _KeepID = _Param_A;
        SET @.SYS.KeepID := _KeepID;
    END IF;

    IF _MODE = 'RESET' THEN
    --  wyżej już przypisano do _KeepID
        SET @.SYS.KeepID := _KeepID;
    END IF;
    RETURN _KeepID;
END$$

/* ************************************************************************************************************************************************************************
    Control Values 
************************************************************************************************************************************************************************ */    
DROP FUNCTION IF EXISTS `_varIsNullEmpty`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_varIsNullEmpty`(
    _Value VARCHAR(65532)
    ) 
RETURNS BOOLEAN
    NO SQL
    DETERMINISTIC
BEGIN
    RETURN (NULLIF(_Value, '') IS NULL);
END$$

DROP FUNCTION IF EXISTS `_varIsNullZero`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_varIsNullZero`(
    _Value VARCHAR(65532)
    ) 
RETURNS BOOLEAN
    NO SQL
    DETERMINISTIC
BEGIN
    RETURN (NULLIF(_Value, 0) IS NULL);
END$$

DROP FUNCTION IF EXISTS `IFNULLEmpty`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `IFNULLEmpty`(
    _Value VARCHAR(65532),
    _ValueThen VARCHAR(65532)
    ) 
RETURNS VARCHAR(65532)
    NO SQL
    DETERMINISTIC
BEGIN
    RETURN 
        IF(NULLIF(_Value, '') IS NULL,
            _ValueThen,
            _Value
        )
    ;
END$$


/* ************************************************************************************************************************************************************************
    compare
************************************************************************************************************************************************************************ */    
DROP FUNCTION IF EXISTS `_IsDiff_C`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_IsDiff_C`(
    _ValueA VARCHAR(256),
    _ValueB VARCHAR(256)
    ) 
RETURNS BOOLEAN
    NO SQL
    DETERMINISTIC
BEGIN
    RETURN (IFNULL(_ValueA, '') != IFNULL(_ValueB, ''));
END$$

DROP FUNCTION IF EXISTS `_IsDiff_N`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_IsDiff_N`(
    _ValueA DECIMAL(16,4),
    _ValueB DECIMAL(16,4)
    ) 
RETURNS BOOLEAN
    NO SQL
    DETERMINISTIC
BEGIN
    DECLARE _Is_EQU BOOLEAN;
    SET _Is_EQU = (_ValueA IS NULL AND _ValueB IS NULL);
    IF NOT _Is_EQU THEN
    --  na pewno A i B nie są jednoczesnie null
        IF _ValueA IS NULL OR _ValueB IS NULL  THEN
        --  Jeden A lub B moze byc null zatem drugi nie jest -> oznacza to ze sa na pewno rozne
            SET _Is_EQU = FALSE;
        ELSE    
        --  zade z A i B nie są null
            SET _Is_EQU = (_ValueA = _ValueB);
        END IF;
    END IF;    
    RETURN NOT _Is_EQU;
END$$

/* ************************************************************************************************************************************************************************
    UID-y
************************************************************************************************************************************************************************ */    
DROP FUNCTION IF EXISTS `NewGUID`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `NewGUID`() RETURNS VARCHAR(38) CHARSET cp1250
    DETERMINISTIC
    COMMENT 'Generuje GUID w stylu Delphi'
BEGIN
    -- DECLARE _UUID VARCHAR(38) DEFAULT UPPER(UUID());
    RETURN CONCAT(UUID(), '*');
END$$

DROP FUNCTION IF EXISTS `_Get_ID_xxxxx`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_Get_ID_xxxxx`(
    _MODE VARCHAR(200),
    _Length INTEGER,
    _Prefix VARCHAR(38),
    _Key_A VARCHAR(38),
    _Key_B VARCHAR(38),
    _Key_C VARCHAR(38),
    _Key_D VARCHAR(38),
    _Key_E TEXT
) RETURNS VARCHAR(38)
    NO SQL
    DETERMINISTIC
BEGIN
    IF _MODE = 'SHORT' THEN
        SET
            @_Get_ID_xxxxx = 
            CONCAT_WS('',
                _Prefix, _Key_A, _Key_B, _Key_C, _Key_D, _Key_E, UUID_SHORT()
            )
        ;
    ELSEIF _MODE = 'CONCAT' THEN
        SET
            @_Get_ID_xxxxx = 
            CONCAT_WS('',
                _Prefix, _Key_A, _Key_B, _Key_C, _Key_D, _Key_E
            )
        ;
    ELSEIF _MODE = 'TIMESTAMP.CON_ID' THEN    
        SET @._Get_ID_xxxxx.CC = IF(@._Prefix <=> _Prefix, @._Get_ID_xxxxx.CC + 1, 0); 
        SET
            @._Prefix = _Prefix,
            @_Get_ID_xxxxx = 
            CONCAT_WS('',
                _Prefix, 
                '',
                REPLACE(_VarStr(CURRENT_DATE()), '-', ''), 
                '_', REPLACE(_VarStr(CURRENT_TIME(3)), ':', ''),
                ':', _VarStr(CONNECTION_ID()),
                ':', @._Get_ID_xxxxx.CC
            )
        ;
    ELSE
        SET
            @_Get_ID_xxxxx = 
            CONCAT_WS('',
                _Prefix, 
                MD5(
                    CONCAT_WS('', 
                        _Key_A, _Key_B, _Key_C, _Key_D, _Key_E
                    )
                )
            ) 
        ;
    END IF;
    SET @_Get_ID_xxxxx = IF(_Length > 0, RIGHT(@_Get_ID_xxxxx, _Length), @_Get_ID_xxxxx);
    RETURN @_Get_ID_xxxxx;
END$$

DROP FUNCTION IF EXISTS `_Get_GUID_xxx`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_Get_GUID_xxx`(
    _MODE VARCHAR(200),
    _Key_A VARCHAR(38),
    _Key_B VARCHAR(38),
    _Key_C VARCHAR(38),
    _Key_D VARCHAR(38),
    _Key_E VARCHAR(38),
    _Key_F TEXT
) RETURNS VARCHAR(38)
    NO SQL
    DETERMINISTIC
BEGIN
    IF _MODE IN ('N.GUID') THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('N.GUID', _FROM, _Prefix, '', '', '', '');
    ****************************************************************************************************************************************************************/
        RETURN (@New.M.p.GUID := 
            _Get_ID_xxxxx('SHORT', 38, LEFT(_Key_A, 2), ".N.", _Key_B, '', '', '')
        );
    END IF;

    IF _MODE IN ('P.GUID') THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('P.GUID', _FROM, _Prefix, '', '', '', '');
    ****************************************************************************************************************************************************************/
        RETURN (@New.M.p.GUID := 
            _Get_ID_xxxxx('SHORT', 38, LEFT(_Key_A, 2), ".P.", _Key_B, '', '', '')
        );
    END IF;

    IF _MODE LIKE 'M.p.GUID%' THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('M.p.GUID', _FROM, '', '', '', '', '');
        _Get_GUID_xxx('M.p.GUID<-IdnOper,IdnTowr,Tekst,Seria', IdnOper, IdnTowr, 'GUID_Dostawy/nr seryjny', '', '', 'Komentarz');        
    ****************************************************************************************************************************************************************/
        IF _MODE = 'M.p.GUID' THEN
            RETURN (@New.M.p.GUID := 
                -- bylo LEFT(CONCAT("m.p.", LEFT(_Key_A, 2),':', UUID_SHORT()), 38)
                _Get_ID_xxxxx('SHORT', 38, "m.p.", LEFT(_Key_A, 2),':', '', '', '')
            );
        ELSEIF _MODE = 'M.p.GUID<-IdnOper,IdnTowr,Tekst,Seria' THEN
        /*    bylo
            RETURN (@NEW.oppoGUID := CONCAT(
                'm.p.X:', 
                MD5(CONCAT_WS('', 
                    (@New.G.IdnOper := _Key_A), 
                    (@New.G.IdnTowr := _Key_B), 
                    (@New.G.IdSeryjny := _Key_C),     --  GUID_Dostawy/nr seryjny
                    IFNULL(_Key_F, '')                --  Komentarz
                )) 
            ));
        */
            RETURN (@NEW.oppoGUID := _Get_ID_xxxxx('', 38, 'm.p.X:', 
                (@New.G.IdnOper := _Key_A), 
                (@New.G.IdnTowr := _Key_B), 
                (@New.G.IdSeryjny := _Key_C),     --  GUID_Dostawy/nr seryjny
                IFNULL(_Key_F, ''),                --  Komentarz
                ''
            ));
        ELSE
            RETURN (@New.M.p.GUID := 
                _Get_ID_xxxxx('SHORT', 38, "m.p.", LEFT(_Key_A, 2),':', '', '', '')
            );
        END IF;
    END IF;

    IF _MODE IN ('M.n.GUID') THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('M.n.GUID', _FROM, '', '', '', '', '');
    ****************************************************************************************************************************************************************/
        RETURN (@New.M.p.GUID := 
            -- LEFT(CONCAT("m.n.", LEFT(_Key_A, 2),':', UUID_SHORT()), 38)
            _Get_ID_xxxxx('SHORT', 38, "m.n.", LEFT(_Key_A, 2),':', '', '', '')
        );
    END IF;


    IF _MODE IN ('TE.p.GUID') THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('TE.p.GUID', _FROM, '', '', '', '', '');
    ****************************************************************************************************************************************************************/
        RETURN (@New.TE.p.GUID := 
            -- LEFT(CONCAT("TE.", LEFT(_Key_A, 2),'po:', UUID_SHORT()), 38)
            _Get_ID_xxxxx('SHORT', 38, "TE.", LEFT(_Key_A, 2),'po:', '', '', '')
        );
    END IF;

    IF _MODE IN ('TE.n.GUID') THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('TE.n.GUID', _FROM, '', '', '', '', '');
    ****************************************************************************************************************************************************************/
        RETURN (@New.TE.p.GUID := 
            -- LEFT(CONCAT("TE.", LEFT(_Key_A, 2),'ng:', UUID_SHORT()), 38)
            _Get_ID_xxxxx('SHORT', 38, "TE.", LEFT(_Key_A, 2),'ng:', '', '', '')
        );
    END IF;

--  INWENTARYZACJA
    IF _MODE IN ('INW.n.GUID') THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('INW.n.GUID', Magazyn, '', '', '', '', '');
    ****************************************************************************************************************************************************************/
        RETURN 
            RIGHT(
                CONCAT_WS(':',
                    'INW', 
                    IFNULL(NULLIF(_Key_A, ''), UUID_SHORT()),     --  jako magazyn - ale gdy pusty to daj short UID
                    LEFT(REPLACE(REPLACE(REPLACE(NOW(), '-', ''), ' ', '.'), ':', ''), 15)
                ), 
            38)
        ;
        -- WHAT???? RETURN @.SYSTEM.Session.GUID.Default;
        
    END IF;

    IF _MODE IN ('INW.p.GUID') THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('INW.p.GUID', IdnOper, IdnTowr, IN_GUID_Dostawy, IN_NrSeryjny, '', '');
        bylo w C_HT_oppo_e CONCAT('INW', MD5(CONCAT(t.IdnOper, t.IdnTowr, t.IN_GUID_Dostawy, t.IN_NrSeryjny))) AS GUID,
    ****************************************************************************************************************************************************************/
        RETURN
            (@NEW.oppoGUID := 
                _Get_ID_xxxxx('', 38, 'INW:', (@New.G.IdnOper := _Key_A), (@New.G.IdnTowr := _Key_B), _Key_C, _Key_D, '')
        );
    END IF;


    IF _MODE IN ('IdnNg', 'zmngGUID') THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('zmngGUID', KontrGUID, transza_sped, TerminRealizacji, '', '', '');
    ****************************************************************************************************************************************************************/
        /*
        RETURN (@New.IdnNg := CONCAT(
            'DxK', 
            MD5(CONCAT(
                (@New.G.KontrGUID := _Key_A), 
                IFNULL(@New.G.transza_sped := _Key_B, 0), 
                (@New.G.TerminRealizacji := _Key_C)
            )) 
        ));
        */
        RETURN (@NEW.IdnNg := 
            _Get_ID_xxxxx('', 38, 'DxK', 
                (@New.G.KontrGUID := _Key_A), 
                IFNULL(@New.G.transza_sped := _Key_B, 0), 
                (@New.G.TerminRealizacji := _Key_C),
                (@New.G.Extra := _Key_D),     --  zwykle nie wystepuje alo moze zawierać słowo "Extra"
                ''
            )
        );
    END IF;

    IF _MODE IN ('IdnNg<-KLON.IdnNg.transza_sped.TerminRealizacji', 'zmngGUID<-KLON.IdnNg.transza_sped.TerminRealizacji') THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('IdnNg<-KLON.IdnNg.transza_sped.TerminRealizacji', IdnNg, transza_sped, TerminRealizacji, '', '', '');
    ****************************************************************************************************************************************************************/
        /*
        RETURN (@New.IdnNg := CONCAT(
            'CLD', 
            MD5(CONCAT(
                (@New.IdnNg := _Key_A), 
                IFNULL(@New.G.transza_sped := _Key_B, 0),
                (@New.G.TerminRealizacji := _Key_C)
            )) 
        ));
        */
        RETURN (@NEW.IdnNg := 
            _Get_ID_xxxxx('', 38, 'CLD', 
                (@New.IdnNg := _Key_A), 
                IFNULL(@New.G.transza_sped := _Key_B, 0),
                (@New.G.TerminRealizacji := _Key_C),
                '', 
                ''
            )
        );
    END IF;

    IF _MODE IN ('IdnNg<-IdnNg', 'IdnNg<-zmpoGUID') THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('IdnNg<-IdnNg', IdnNg, Rodzaj, PodRodzaj, '', '', '');
        _Get_GUID_xxx('IdnNg<-zmpoGUID', zmpoGUID, Rodzaj, PodRodzaj, '', '', '');
    ****************************************************************************************************************************************************************/
        /*
        RETURN (@New.IdnNg := CONCAT(
            'DxK', 
            MD5(CONCAT(
                (@New.G.WyjazdGUID := _Key_A), 
                (@New.G.KontrGUID := _Key_B)
            )) 
        ));
        */
        RETURN (@NEW.IdnNg := 
            _Get_ID_xxxxx('', 38, 'ZM:', 
                (@New.G.GUID := _Key_A), 
                (@New.G.Rodzaj := _Key_B),
                (@New.G.PodRodzaj := _Key_C),
                '', 
                ''
            )
        );
    END IF;

    IF _MODE IN ('IdnNg.OLD', 'zmngGUID.OLD', 'IdnNg<-Wyjazd,Kontrah') THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('zmngGUID.OLD', WyjazdGUID, KontrGUID, '', '', '', '');
        _Get_GUID_xxx('IdnNg<-Wyjazd,Kontrah', WyjazdGUID, KontrGUID, '', '', '', '');
    ****************************************************************************************************************************************************************/
        /*
        RETURN (@New.IdnNg := CONCAT(
            'DxK', 
            MD5(CONCAT(
                (@New.G.WyjazdGUID := _Key_A), 
                (@New.G.KontrGUID := _Key_B)
            )) 
        ));
        */
        RETURN (@NEW.IdnNg := 
            _Get_ID_xxxxx('', 38, 'DxK', 
                (@New.G.WyjazdGUID := _Key_A), 
                (@New.G.KontrGUID := _Key_B),
                '',
                '', 
                ''
            )
        );
    END IF;

    IF _MODE LIKE 'zmpoGUID<-%' THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('zmpoGUID<-IdnNg,IdnTowr,Receptura,Tekst', IdnNg, IdnTowr, RecepturaGUID , '', '', 'Komentarz');
    ****************************************************************************************************************************************************************/
        IF _MODE IN ('zmpoGUID<-IdnNg,IdnTowr,Receptura,Tekst') THEN
            /*
            RETURN (@NEW.zmpoGUID := CONCAT(
                'DxKT', 
                MD5(CONCAT(
                    (@New.G.IdnNg := _Key_A), 
                    (@New.G.IdnTowr := _Key_B), 
                    IFNULL(_Key_C, ''),        --  RecepturaGUID
                    IFNULL(_Key_F, '')        --  Komentarz
                )) 
            ));
            */
            RETURN (@NEW.zmpoGUID := 
                _Get_ID_xxxxx('', 38, 'DxKT', 
                    (@New.G.IdnNg := _Key_A), 
                    (@New.G.IdnTowr := _Key_B), 
                    IFNULL(_Key_C, ''),        --  RecepturaGUID
                    IFNULL(_Key_F, ''),        --  Komentarz
                    ''
                )
            );
        ELSE
            RETURN UUID();
        END IF;

    END IF;

    IF _MODE IN ('IdnOper<-IdnNg.old', 'IdnOper<-IdnNg.old') THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('IdnOper<-IdnNg', IdnNg, '', '', '', '', '');
    ****************************************************************************************************************************************************************/
        /*
        RETURN (@New.IdnOper := CONCAT(
            'DxK', 
            MD5(CONCAT(
                (@New.G.IdnNg := _Key_A)
            ))
        ));
        */
        RETURN (@NEW.IdnOper := 
            _Get_ID_xxxxx('', 38, 'DxK',         
                (@New.G.IdnNg := _Key_A), 
                '',
                '',
                '', 
                ''
            )
        );
    END IF;
    
    IF _MODE IN ('IdnOper<-IdnNg', 'IdnOper<-IdnNg.new') THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('IdnOper<-IdnNg', IdnNg, '', '', '', '', '');
        _Get_GUID_xxx('IdnOper<-IdnNg', IdnNg, 'data', '', '', '', '');
    ****************************************************************************************************************************************************************/
        /*
        RETURN (@New.IdnOper := CONCAT(
            'DxK', 
            MD5(CONCAT(
                (@New.G.IdnNg := _Key_A)
            ))
        ));
        */
        RETURN (@NEW.IdnOper := 
            _Get_ID_xxxxx('', 38, 'zmng->',         --  bylo 'DxK'
                (@New.G.IdnNg := _Key_A), 
                _Key_B,    --  na wszelki wypadek np. data - najwyzej i tak bedzie pusty
                '',
                '', 
                ''
            )
        );
    END IF;

    IF _MODE IN ('IdnOper<-NxIdnNg', 'IdnOper<-Short.IdnNg') THEN
    /****************************************************************************************************************************************************************
        Gdy realizujemy pozycje z wielu n > 1 zamowien to nie mozemy brac GUID z konkr. zam. tak jak w "IdnOper<-IdnNg" - musimy dac short UID
        _Get_GUID_xxx('IdnOper<-NxIdnNg', '', '', '', '', '', '');
        _Get_GUID_xxx('IdnOper<-Short.IdnNg', '', '', '', '', '', '');
    ****************************************************************************************************************************************************************/
        RETURN (@NEW.IdnOper := 
            _Get_ID_xxxxx('SHORT', 38, 'n_x_zmng->opng:', 
                NULL,
                NULL,
                NULL, 
                NULL, 
                NULL
            )
        );
    END IF;
    
    IF _MODE IN ('IdnOper<-SHORT.Ctx.Rodzaj') THEN  
    /****************************************************************************************************************************************************************
        np.
        _Get_GUID_xxx('IdnOper<-SHORT.Ctx.Rodzaj', 'WAGA', Rodzaj, '', '', '', '');
    ****************************************************************************************************************************************************************/
        RETURN (@NEW.IdnOper := 
            _Get_ID_xxxxx('SHORT', 38, '', 
                _Key_A,
                (SELECT REPLACE(od.Nazwa, ' ', '_') FROM `operdoc` od WHERE od.Rodzaj = _Key_B), 
                ':', '', ''
            )
        );
    END IF;
    
    
    IF _MODE LIKE 'IdnOper.%' THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('IdnOper.ZWR', WyjazdGUID, KontrGUID, '', '', '', '');
        _Get_GUID_xxx('IdnOper.Kosze', WyjazdGUID, KontrGUID, '', '', '', '');
        _Get_GUID_xxx('IdnOper.ZAL', WyjazdGUID, KontrGUID, '', '', '', '');    --  MM zaladunek    
        _Get_GUID_xxx('IdnOper.WYL', WyjazdGUID, KontrGUID, '', '', '', '');    --  MM wyladunek
    ****************************************************************************************************************************************************************/
        /*
        RETURN (@New.IdnOper := CONCAT(
            REPLACE(_MODE, 'IdnOper.', ''), 
            MD5(CONCAT(
                @New.G.WyjazdGUID := _Key_A, 
                @New.G.KontrGUID := _Key_B
            ))
        ));
        */
        RETURN (@NEW.IdnOper := 
            _Get_ID_xxxxx('', 38, REPLACE(_MODE, 'IdnOper.', ''), 
                (@New.G.WyjazdGUID := _Key_A), 
                (@New.G.KontrGUID := _Key_B),
                (_Key_C),
                '', 
                ''
            )
        );
    END IF;
    
    IF _MODE LIKE 'oppoGUID%' THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('oppoGUID<-IdnOper,IdnTowr,Tekst', IdnOper, IdnTowr, '', '', '', 'Komentarz');
        _Get_GUID_xxx('oppoGUID<-zmpoGUID', zmpoGUID, '', '', '', '', '');
    ****************************************************************************************************************************************************************/
        IF _MODE IN ('oppoGUID<-IdnOper,IdnTowr,Tekst') THEN
            /*
            RETURN (@NEW.oppoGUID := CONCAT(
                'DxKT', 
                MD5(CONCAT(
                    (@New.G.IdnOper := _Key_A), 
                    (@New.G.IdnTowr := _Key_B), 
                    IFNULL(_Key_F, '')
                )) 
            ));
            */
            RETURN (@NEW.oppoGUID := 
                _Get_ID_xxxxx('', 38, 'DxKT', 
                    (@New.G.IdnOper := _Key_A), 
                    (@New.G.IdnTowr := _Key_B), 
                    IFNULL(_Key_F, ''),
                    '',
                    ''
                )
            );
        ELSEIF _MODE IN ('oppoGUID<-zmpoGUID') THEN
            /*
            RETURN (@NEW.oppoGUID := CONCAT(
                MD5(
                    (@New.G.zmpoGUID := _Key_A) 
                ) 
            ));
            */
            RETURN (@NEW.oppoGUID := 
                _Get_ID_xxxxx('', 38, 'zmpo->', 
                    (@New.G.zmpoGUID := _Key_A), 
                    '', 
                    '',
                    '',
                    ''
                )
            );
        ELSE
            RETURN UUID();
        END IF;
    END IF;

    IF _MODE LIKE 'GUID_MM+%' THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('GUID_MM+', WyjazdGUID, IdnTowr, 'typ_pakowania', '', '', '');
    ****************************************************************************************************************************************************************/
        /*
        RETURN (@NEW.xxpo.GUID := CONCAT(
                'DxMM', 
                MD5(CONCAT(
                    (@New.G.WyjazdGUID := _Key_A), 
                    (@New.G.IdnTowr := _Key_B), 
                    (@New.G.typ_pakowania := _Key_C), 
                    '+'
                )) 
            ));
        */
        RETURN (@NEW.xxpo.GUID := 
            _Get_ID_xxxxx('', 38, 'DxMM', 
                (@New.G.WyjazdGUID := _Key_A), 
                (@New.G.IdnTowr := _Key_B), 
                (@New.G.typ_pakowania := _Key_C), 
                '+', 
                ''
            )
        );
    END IF;

    IF _MODE = 'WyjazdGUID' THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('WyjazdGUID', TrasaRewirGUID, TerminRealizacji, transza_sped, '', '', '');
    ****************************************************************************************************************************************************************/
        /*
        RETURN (@New.G.WyjazdGUID := CONCAT(
            'SPED:', 
            MD5(CONCAT(
                (@New.G.RewirGUID := _Key_A), 
                (@New.G.TerminRealizacji := _Key_B), 
                IFNULL(@New.G.transza_sped := _Key_C, 0)
            ))
        ));
        */
        RETURN (@NEW.G.WyjazdGUID := 
            _Get_ID_xxxxx('', 38, 'SPED:', 
                (@New.G.RewirGUID := _Key_A), 
                (@New.G.TerminRealizacji := _Key_B), 
                IFNULL(@New.G.transza_sped := _Key_C, 0),
                NULL, 
                NULL
            )
        );
    END IF;

    IF _MODE = 'WyjazdGUID.z.akwizytora' THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('WyjazdGUID.z.akwizytora', AkwizytorGUID, TerminRealizacji, transza_sped, '', '', '');
    ****************************************************************************************************************************************************************/
        /*
        RETURN (@New.G.WyjazdGUID := CONCAT(
            'SPED:', 
            MD5(CONCAT(
                (@New.G.AkwizytorGUID := _Key_A), 
                (@New.G.TerminRealizacji := _Key_B), 
                IFNULL(@New.G.transza_sped := _Key_C, 0)
            ))
        ));
        */
        RETURN (@NEW.G.WyjazdGUID := 
            _Get_ID_xxxxx('', 38, 'SPED:', 
                (@New.G.AkwizytorGUID := _Key_A), 
                (@New.G.TerminRealizacji := _Key_B), 
                IFNULL(@New.G.transza_sped := _Key_C, 0),
                '', 
                ''
            )
        );
    END IF;

    IF _MODE = 'WyjazdGUID<-GUIDNg,IdnTowr,Data' THEN
    /****************************************************************************************************************************************************************
        Glownie chodzi o wyjazdy z dokladnoscia do pozycji - czyli GUID naglowka + Towar a ze moze
        ktos realizowac kilka wyjazdow to dodajemy date choc pewnie nie bedzie potrzebna
        _Get_GUID_xxx('WyjazdGUID<-GUIDNg,IdnTowr,Data', GUID naglowka, IdnTowr, Data/TerminRealizacji, '', '', '');
    ****************************************************************************************************************************************************************/
        RETURN (@NEW.G.WyjazdGUID := 
            _Get_ID_xxxxx('', 38, 'SPEDP:', 
                (@New.G.Ng := _Key_A), 
                (@New.G.IdnTowr := _Key_B), 
                DATE(_Key_C),        --  Data/TerminRealizacji  - UWAGA Date(_Key_C) zwraca NULL zawsze gdy _Key_C nie jest pełna datą!!!
                '', 
                ''
            )
        );
    END IF;

    IF _MODE = 'WyjazdGUID<-GUIDPo,Data' THEN
    /****************************************************************************************************************************************************************
        Glownie chodzi o wyjazdy z dokladnoscia do konkrentej pozycji - czyli GUID pozycji a jesli
        ktos chce realizowac kilka wyjazdow do pozycji to dodajemy date choc pewnie nie bedzie potrzebna
        UWAGA - ten tryb jest bezpieczniejszy niz 'WyjazdGUID<-Ng,IdnTowr,Data' bowiem zawsze do wyjazdy wchodzi GUID pozycji.
        Czyli jesli mamy kilka IdnTowr powtorzonych to system stworzy tylko tyle wyjazdow ile roznych IdnTowr a;e jesli 
        chcemy rozne wyjazdy dla kazdej pozycji to stosujemy ten tryb : 'WyjazdGUID<-GUIDPo,Data'
        _Get_GUID_xxx('WyjazdGUID<-GUIDPo,Data', GUID pozycji, Data/TerminRealizacji, '', '', '', '');
    ****************************************************************************************************************************************************************/
        RETURN (@NEW.G.WyjazdGUID := 
            _Get_ID_xxxxx('', 38, 'SPEDP:', 
                (@New.G.Po := _Key_A), 
                DATE(_Key_B),        --  Data/TerminRealizacji  - UWAGA Date(_Key_B) zwraca NULL zawsze gdy _Key_B nie jest pełna datą!!!
                NULL, 
                NULL, 
                NULL
            )
        );

    END IF;

    IF _MODE = 'WyjazdGUID<-CONCAT(GUIDNg)' THEN
    /****************************************************************************************************************************************************************
        Na przykłd TRANSBU gdy 1 wyjazd dla 1 zamowienia
        Idnng = "ZM.N.na.1.WYJ:314690206135484499" 
        a wyjazd: "SPED<-ZM.N.na.1.WYJ:314690206135484499"
        _Get_GUID_xxx('WyjazdGUID<-CONCAT(GUIDNg)', GUID naglowka, '', '', '', '', '');
    ****************************************************************************************************************************************************************/
        RETURN (@NEW.G.WyjazdGUID := 
            _Get_ID_xxxxx('CONCAT', 38, 'SPED<-', 
                (@New.G.Ng := _Key_A),
                NULL, 
                NULL, 
                NULL, 
                NULL
            )
        );

    END IF;

    IF _MODE IN ('WyjazdGUID<-SHORT', 'WyjazdGUID<-SHORT|Data') THEN
    /****************************************************************************************************************************************************************
        Prosta wersja GUIDa wyjazdu 
        SPED:20200108:98504169165422593
        SPED:data:shortUID
        _Get_GUID_xxx('WyjazdGUID<-SHORT', 'null/data', '', '', '', '', '');
    ****************************************************************************************************************************************************************/
        RETURN (@NEW.G.WyjazdGUID := 
            _Get_ID_xxxxx('SHORT', 38, 'SPED:', 
                REPLACE(IFNULL(DATE(_Key_A), CURRENT_DATE()), '-', ''),
                ':', 
                NULL, 
                NULL, 
                NULL
            )
        );

    END IF;


    IF _MODE = 'IdnNg<-CONCAT(WyjazdGUID)' THEN
    /****************************************************************************************************************************************************************
        Na przykłd TRANSBU gdy 1 wyjazd dla 1 zamowienia
        Jest to wersja że Zamówienie powstaje z Wyjazdu
        Idnng = "ZM<-SPED:20190124:314690206135484565" 
        czyli guid zamowienia powstał z wyjazdu = "SPED:20190124:314690206135484565"
        IF _MODE = 'WyjazdGUID<-CONCAT(GUIDNg)' THEN
        _Get_GUID_xxx('IdnNg<-CONCAT(WyjazdGUID)', 'WyjazdGUID', '', '', '', '', '');
    ****************************************************************************************************************************************************************/
        RETURN (@NEW.G.WyjazdGUID := 
            _Get_ID_xxxxx('CONCAT', 38, 'ZM<-', 
                _Key_A,
                NULL, 
                NULL, 
                NULL, 
                NULL
            )
        );

    END IF;

    IF _MODE IN ('Ekspedycja<-Template+Data') THEN
    /****************************************************************************************************************************************************************
        Prosta wersja GUIDa wyjazdu 
        SPED:20200108:98504169165422593
        SPED:data:shortUID
        _Get_GUID_xxx('Ekspedycja<-Template+Data', 'szablon', 'null/data', '', '', '', '');
    ****************************************************************************************************************************************************************/
        RETURN (@NEW.G.WyjazdGUID := 
            _Get_ID_xxxxx('CONCAT', 38, _Key_A, 
                NULL, 
                '.', 
                REPLACE(IFNULL(DATE(_Key_B), CURRENT_DATE()), '-', ''),
                NULL, 
                NULL
            )
        );

    END IF;

    IF _MODE IN ('Ekspedycja.Template<-Kind+Transza+LP') THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('Ekspedycja.Template<-Kind+Transza+LP', 'Kind', 'Transza', 'LP', '', '', '', '');
    ****************************************************************************************************************************************************************/
        RETURN (@NEW.G.WyjazdGUID := 
            _Get_ID_xxxxx('CONCAT', 38, 
                _Key_A, 
                '.', 
                _ConcatPre('TRAN:', _Key_B),    -- transza, 
                '.', 
                _Key_C,
                NULL
            )
        );

    END IF;


    IF _MODE = 'Route.ID.jako.WyjazdKontrGUID' THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('Route.ID.jako.WyjazdKontrGUID', NEW.wyjazdGUID, NEW.Point, NEW.KontrGUID, 
            IF(IFNULL(NEW.adr_link, '') != '', NEW.adr_link, CONCAT(NEW.longitude, ' ', NEW.latitude)),
            NEW.next_time, ''
            );
    ****************************************************************************************************************************************************************/
        /*
        RETURN (@New.WyjazdGUID := CONCAT(
            'WK:', 
            MD5(CONCAT(
                _Key_A,    --  wyjazdGUID, 
                _Key_B,    --  Point, 
                _Key_C,    --  KontrGUID, 
                _Key_D,    --  IF(IFNULL(NEW.adr_link, '') != '', NEW.adr_link, CONCAT(NEW.longitude, ' ', NEW.latitude)), 
                _Key_E    --  next_time
            ))
        ));
        */
        RETURN (@NEW.G.WyjazdGUID := 
            _Get_ID_xxxxx('', 38, 'WK:', 
                _Key_A,    --  wyjazdGUID, 
                _Key_B,    --  Point, 
                _Key_C,    --  KontrGUID, 
                _Key_D,    --  IF(IFNULL(NEW.adr_link, '') != '', NEW.adr_link, CONCAT(NEW.longitude, ' ', NEW.latitude)), 
                _Key_E    --  next_time
            )
        );
    END IF;

    IF _MODE IN ('EVENT.WORK.from.frekw_po') THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('EVENT.WORK.from.frekw_po', FrekwPoGUID, '', '', '', '', '');
    ****************************************************************************************************************************************************************/
        /*
        RETURN (@New.Event := CONCAT(
            'frkw.', 
            MD5(CONCAT(
                'frkw.', 
                _Key_A    --  FrekwPoGUID, 
            )) 
        ));
        */
        RETURN (@NEW.Event := 
            _Get_ID_xxxxx('', 38, 'frkw.', 
                'frkw.', 
                _Key_A,    --  FrekwPoGUID, 
                '',
                '',
                ''
            )
        );
    END IF;


    IF _MODE LIKE ('Session.GUID.%') THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('Session.GUID.Default', Param, '', '', '', '', '');
        dla 
        @.SYSTEM.Session.GUID.Default
        oraz
        @.SYSTEM.Session.GUID.Event
    ****************************************************************************************************************************************************************/
        RETURN Get_Var_Connection(_MODE, _Key_A, '', '');
    END IF;


    IF _MODE LIKE 'Osoba.REPR<-Kontrah%' THEN
    /****************************************************************************************************************************************************************
        GUID osoby do kontrahenta
        tymczasowy (do baseników www)
        _Get_GUID_xxx('Osoba.REPR<-Kontrah.Temp', KontrIDN, '', '', '', '', '');
        _Get_GUID_xxx('Osoba.REPR<-Kontrah', KontrIDN, '', '', '', '', '');
    ****************************************************************************************************************************************************************/
        IF _MODE = 'Osoba.REPR<-Kontrah.TEMP' THEN
            RETURN (@NEW.G.OsobaGUID := 
                _Get_ID_xxxxx('CONCAT', 38, 'REPREZENTANT:IDN=', 
                    _VarStr(_Key_A),    --  IDN kontrahenta
                    NULL, 
                    NULL, 
                    NULL, 
                    NULL
                )
            );
        ELSE
            RETURN (@NEW.G.OsobaGUID := 
                -- było _Get_ID_xxxxx('SHORT', 38, 'O<-K:IDN=', _VarStr(_Key_A), ':', '', '', '')
                _Get_ID_xxxxx('CONCAT', 38, 'O<-K:IDN=', _VarStr(_Key_A), '', '', '', '')
            );
        END IF;
    END IF;

    IF _MODE LIKE 'Osoba.Short' THEN
    /****************************************************************************************************************************************************************
        GUID osoby w wizardzie
        _Get_GUID_xxx('Osoba.Short', '', '', '', '', '', '');
    ****************************************************************************************************************************************************************/
        RETURN (@NEW.G.OsobaGUID := 
            _Get_ID_xxxxx('SHORT', 38, 'OSOB.WIZ:', '', '', '', '', '')
        );
    END IF;

    IF _MODE LIKE 'Kontrah.Short' THEN
    /****************************************************************************************************************************************************************
        GUID osoby w wizardzie
        _Get_GUID_xxx('Osoba.Short', '', '', '', '', '', '');
    ****************************************************************************************************************************************************************/
        RETURN (@NEW.G.OsobaGUID := 
            _Get_ID_xxxxx('SHORT', 38, 'KONTR.WIZ:', '', '', '', '', '')
        );
    END IF;

    IF _MODE LIKE 'Wniosek.PF' THEN
    /****************************************************************************************************************************************************************
        GUID osoby w wizardzie
        _Get_GUID_xxx('Wniosek.PF', '', '', '', '', '', '');
    ****************************************************************************************************************************************************************/
        RETURN (@NEW.G.OsobaGUID := 
            _Get_ID_xxxxx('SHORT', 38, 'WNIOS.PF:', '', '', '', '', '')
        );
    END IF;
    
    IF _MODE IN ('Wniosek.PF.XXX', 'Wniosek.PF.DELEG', 'Wniosek.PF.SZKOL') THEN
    /****************************************************************************************************************************************************************
        _Get_GUID_xxx('N.GUID', _FROM, _Prefix, '', '', '', '');
    ****************************************************************************************************************************************************************/
        RETURN (@New.M.p.GUID := 
            _Get_ID_xxxxx('SHORT', 38, 'WNIOS.', _Key_A, ':', '', '', '')
        );
    END IF;

    

    IF _MODE LIKE 'Wazenie' THEN
    /****************************************************************************************************************************************************************
        GUID osoby w wizardzie
        _Get_GUID_xxx('Wazenie', '', '', '', '', '', '');
    ****************************************************************************************************************************************************************/
        RETURN (@NEW.G.WazenieGUID := 
            _Get_ID_xxxxx('TIMESTAMP.CON_ID', 38, 'WAGA:', '', '', '', '', '')
        );
    END IF;


    
END$$

/* ************************************************************************************************************************************************************************
    Zmienne sesyjne systemowe - nie wpisujemy do db_Globals!!! TYLKO odczyt
    Jeśli sa NULL i w dodatku nie ma ich w bazie to sa NULL i juz trudno :( 
    Takich zmiennych jest niezwykle mało
************************************************************************************************************************************************************************ *    
DROP FUNCTION IF EXISTS `Get_System_Var`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `Get_Var_Connection`(
    _MODE VARCHAR(250),
    _Key_A VARCHAR(50),
    _Key_B VARCHAR(50)
) RETURNS VARCHAR(255)
    NO SQL
    DETERMINISTIC
BEGIN

--  IF @session.LOGON.Ver IS NULL THEN
--  CALL _Globals_Get('LOGON.Ver', @session.LOGON.Ver, '1.0');
--  END IF;
    IF _MODE IN ('', 'LOGON.Ver') THEN
        RETURN @session.LOGON.Ver;
    END IF;
    
END$$

/* ************************************************************************************************************************************************************************
    Connection / Schema
************************************************************************************************************************************************************************ */    

DROP PROCEDURE IF EXISTS `_system_select`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `_system_select`(
    IN _MODE VARCHAR(150),
    IN _PARAM_A VARCHAR(250),
    IN _PARAM_B VARCHAR(250)
) 
S_system_select: BEGIN 
    DO _Birth_System();
    
    IF _MODE IN ('', 'INIT') THEN
        SELECT
            @session.Birth AS Sys_Birth_AT,
            @session.LOGON.Ver AS Sys_Logon_Ver,
            @session.globals.INPUT_SALT_Hash AS Sys_INPUT_SALT_Hash,
            @session.globals.Owner AS Sys_Owner,
            @session.LOGON.user_accounts_Mode AS Sys_User_accounts_Mode,
            @session.globals.Owner_kontrguid AS Sys_Owner_kontrguid,
            @session.globals.APPLY.LOG.Active AS Sys_Apply_Log_Active
        ;
    END IF;
END$$

DROP FUNCTION IF EXISTS `Get_Var_Connection`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `Get_Var_Connection`(
    _MODE VARCHAR(250),
    _Key_A VARCHAR(50),
    _Key_B VARCHAR(50),
    _Key_C TEXT
) RETURNS VARCHAR(255)
    NO SQL
    DETERMINISTIC
BEGIN
    IF (@session.Birth IS NULL) THEN DO _Birth_System(); END IF;    
    
    IF _MODE = 'Connection.USER' THEN
        RETURN @.SYSTEM.CURRENT.con.USER;
    END IF;
    
    IF _MODE = 'Connection.HOST' THEN
        RETURN @.SYSTEM.CURRENT.con.HOST;
    END IF;
    
    IF _MODE = 'Connection.DB' THEN
        RETURN @.SYSTEM.CURRENT.con.DB;
    END IF;
    
    IF _MODE IN ('Get.Session.GUID.or.New.If.NULL', 'Session.GUID') THEN
    --  _Key_A to wej. GUID sesji ale gdy NULL/"" to idziemy do "Session.GUID.Default"
    --  _Key_B nie obowiazkowy
        IF NULLIF(_Key_A, '') IS NOT NULL THEN
            RETURN _Key_A;
        ELSE
        --  Uwaga!!!!! zmieniamy _MODE na "Session.GUID.Default"
            SET _MODE = 'Session.GUID.Default';
        END IF;
    END IF;
    
    IF _MODE = 'Session.GUID.Default' THEN
    --  _Key_B nie obowiazkowy
        IF NULLIF(@.SYSTEM.Session.GUID.Default, '') IS NULL THEN
            SET @.SYSTEM.Session.GUID.Default = 
                    (@._ID := 
                --  !!! odwracamy kolejnosc było CON: + conncection_ID + dzien i czas ...
                --  _Get_ID_xxxxx('CONCAT', 38, 'CON:', _VarStr(CONNECTION_ID()), ':', REPLACE(REPLACE(REPLACE(_VarStr(NOW()), '-', ''), ' ', '.'), ':', ''), '', '')
                --  a teraz jest odwrotnie i chronologiczne czyli CON: + dzien i czas + conncection_ID
                    /* do IV 2025 _Get_ID_xxxxx('CONCAT', 38, 'CON:', REPLACE(REPLACE(REPLACE(_VarStr(NOW()), '-', ''), ' ', '.'), ':', ''), ':', _VarStr(CONNECTION_ID()), '', '') */
                    _Get_ID_xxxxx('SHORT', 38, 'CON:', NULL, NULL, NULL, NULL, NULL)
                    )
            ;
        END IF;
        RETURN @.SYSTEM.Session.GUID.Default;
    END IF;
    
    IF _MODE = 'Session.Clone.GUID' THEN
        IF _Key_A LIKE 'CON%' THEN
            SET @.CLON.Session.GUID = REPLACE(_Key_A, 'CON', 'CLON');
        ELSE
            SET @.CLON.Session.GUID = _MD5_CHARSET('', _Key_A, '', '', '', '');
        END IF;
        RETURN @.CLON.Session.GUID;
    END IF;
    
    IF _MODE = 'Session.GUID.Event' THEN
        IF NULLIF(@.SYSTEM.Session.GUID.Event, '') IS NULL THEN
            SET @.SYSTEM.Session.GUID.Event = 
                    (@._ID := 
                --  za długie łańcuchy nie potrzebny localhost ...    
                --  ... _Get_ID_xxxxx('CONCAT', 38, 'EVENT:', _VarStr(CONNECTION_ID()), ':', REPLACE(_VarStr(CURRENT_DATE()), '-', ''), ':', @.SYSTEM.CURRENT.con.HOST)
                --  + odwracamy kolejnosc było EVENT: + conncection_ID + dzien ...
                --  _Get_ID_xxxxx('CONCAT', 38, 'EVENT:', _VarStr(CONNECTION_ID()), ':', REPLACE(_VarStr(CURRENT_DATE()), '-', ''), '', '')
                --  a teraz jest odwrotnie i chronologiczne czyli EVENT: + dzien + conncection_ID
                    -- _Get_ID_xxxxx('CONCAT', 38, 'EVENT:', REPLACE(_VarStr(CURRENT_DATE()), '-', ''), ':', _VarStr(CONNECTION_ID()), '', '') 
                    /* do IV 2025 _Get_ID_xxxxx('CONCAT', 38, 'EVENT:', REPLACE(REPLACE(REPLACE(_VarStr(FROM_UNIXTIME(@@TimeStamp)), ' ', ''), '-', ''), ':', ''), ':', _VarStr(CONNECTION_ID()), '', '')*/
                    _Get_ID_xxxxx('SHORT', 38, 'EVENT:', NULL, NULL, NULL, NULL, NULL)
                    )
            ;
        END IF;
        RETURN @.SYSTEM.Session.GUID.Event;
    END IF;
    
    IF _MODE = 'Session.GUID.Posolony' THEN
        RETURN _MD5_CHARSET('', @session.globals.INPUT_SALT_Hash, @.SYSTEM.Session.GUID.Default, '', '', '');
    END IF;
    
    IF _MODE IN ('', 'LOGON.Ver') THEN
        RETURN @session.LOGON.Ver;
    END IF;
END$$
    
DROP FUNCTION IF EXISTS `Get_Session_GUID`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `Get_Session_GUID`(
    _MODE VARCHAR(250),
    _IN_Session_GUID VARCHAR(50),
    _Key_A VARCHAR(50),
    _Key_B TEXT
) RETURNS VARCHAR(255)
    NO SQL
    DETERMINISTIC
BEGIN
--  spr. czy _IN_Session_GUID = "NEW" bo jeśli tak to pobieramy zupełnie nowy a nie z @.SYSTEM.Session.GUID.Default !!!!!
    IF _IN_Session_GUID = 'NEW' THEN
    --  czyść połączenie domyślne i _GUID
        SET 
            @.SYSTEM.Session.GUID.Default = NULL,
            _IN_Session_GUID = NULL
        ;
    END IF;
    SET _IN_Session_GUID = NULLIF(_IN_Session_GUID, '');
    IF _MODE LIKE 'rec.%INSERT.for.UserGUID.from.@.auth.Final' THEN
    /*  czy używana ???  */
        RETURN @.auth.Final.Session_GUID;     -- zmienna z nowej autoryzacji
    ELSEIF _MODE LIKE '%INSERT.%for.EVENT%' THEN
    /*  dla EVENTów ???  */
        RETURN IFNULL(_IN_Session_GUID, Get_Var_Connection('Session.GUID.EVENT', '', '', ''));
    ELSEIF _MODE LIKE '%INSERT.CLONE.FROM%' THEN
    /*  dla klonowanych z ... ???  */
        RETURN IFNULL(_IN_Session_GUID, Get_Var_Connection('Session.Clone.GUID', _Key_A, '', ''));
    ELSE
    /*  dla pozostałych w np. starych
        rec.INSERT.UPDATE.for.authorization, rec.INSERT.for.[#]UserGUID, etc.
        i nowych (2022)
        INSERT, INSERT.for.authorization, INSERT.for.UserLogin, INSERT.for.UserGUID, INSERT.for.#UserGUID, etc.
    */
        
        RETURN IFNULL(_IN_Session_GUID, Get_Var_Connection('Session.GUID', _IN_Session_GUID, @ParamWe123 := '', ''));
    END IF;
    
END$$


/* ************************************************************************************************************************************************************************
    REG/GLOBALS
************************************************************************************************************************************************************************ */    
DROP FUNCTION IF EXISTS `_Globals_Get_Only_IFNULL`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_Globals_Get_Only_IFNULL`(
    _Key VARCHAR(38), 
    _Current_Value VARCHAR(250)
) RETURNS VARCHAR(250)
    DETERMINISTIC
/*
    Zwraca _Current_Value gdy nie jest NULL - gdy jest NULL to pobiera z bazy - ale nie zapisuje
*/    
BEGIN
    SET @_Value = _Current_Value;
    IF (@_Value IS NULL) THEN
        SELECT 
            `Value` 
        FROM `_db_globals`
        WHERE 
            `Key` = _Key
        INTO 
            @_Value 
        ;
    END IF;
    
    RETURN @_Value;
END$$

DROP FUNCTION IF EXISTS `GetGlobal`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `GetGlobal`(_KEY VARCHAR(38), _DEFAULT VARCHAR(250)) RETURNS VARCHAR(250)
    DETERMINISTIC
    COMMENT 'Zwraca wartosc zmiennej globalnej z _db_globals'
BEGIN
    DECLARE _VALUE VARCHAR(250) DEFAULT NULL;
    SELECT `value` INTO _VALUE FROM `_db_globals` WHERE `key` = _KEY;
    IF ISNULL(_VALUE) AND NOT ISNULL(_DEFAULT) THEN
        INSERT INTO `_db_globals`
        SET
            `key` = _KEY,
            `value` = _DEFAULT
        ;
        RETURN _DEFAULT;
    ELSE
        RETURN IFNULL(_VALUE, '');
    END IF;
END$$

DROP PROCEDURE IF EXISTS `_Globals_Set`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `_Globals_Set`(
    _Key VARCHAR(250),
    _Value VARCHAR(250)
    )
    COMMENT 'Inicjuje zmienna globalna'
BEGIN
    INSERT INTO `_db_globals`
    SET
        `Key` = _Key,
        `Value` = _Value
    ON DUPLICATE KEY UPDATE 
        `Value` = _Value
    ;
END$$


DROP PROCEDURE IF EXISTS `_Globals_Get_2`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `_Globals_Get_2`(
    IN _Key VARCHAR(250),
    OUT _Value VARCHAR(250),
    IN _DefaultValue VARCHAR(250),
    IN _VariableName VARCHAR(250)
    )
    COMMENT 'Inicjuje zmienna globalna'
BEGIN
    SET @_Value = NULL, @_VariableName = NULL;
    SELECT 
        `Value`, VariableName 
    INTO 
        @_Value, @_VariableName 
    FROM `_db_globals`
    WHERE 
        `Key` = _Key
    ;
    IF (@_Value IS NOT NULL) THEN
    --  Jest wpis o wartosci <> NULL
        SET 
            _Value = @_Value
        ;
    --  jeszcze gdy @_VariableName jest NULL a wejściowe <> NULL to uzupełnij
        IF @_VariableName IS NULL AND IFNULL(_VariableName, '') <> '' THEN
            UPDATE `_db_globals` 
            SET 
                VariableName = 
                    IF(_VariableName IN ('?', '@session.globals'),
                        CONCAT('@session.globals.', _Key),
                        NULLIF(_VariableName, '') 
                    )
            WHERE `Key` = _Key
            ;
        END IF;
        
    ELSE
    --  Brak wpisu
        IF (_DefaultValue IS NOT NULL) THEN
            SET _Value = _DefaultValue;
            INSERT INTO `_db_globals`
            SET
                `Key` = _Key,
                `Value` = _Value,
                `VariableName` = NULLIF(_VariableName, '')
            ON DUPLICATE KEY UPDATE 
                `Value` = _Value
            ;
        END IF;
    END IF;
END$$

DROP PROCEDURE IF EXISTS `_Globals_Get`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `_Globals_Get`(
    IN _Key VARCHAR(250),
    OUT _Value VARCHAR(250),
    IN _DefaultValue VARCHAR(250)
    )
    COMMENT 'Inicjuje zmienna globalna'
BEGIN
    SET @_Value = NULL;
    SELECT 
        `Value` 
    INTO 
        @_Value 
    FROM `_db_globals`
    WHERE 
        `Key` = _Key
    ;
    IF (@_Value IS NOT NULL) THEN
        SET _Value = @_Value;
    ELSE
        IF (_DefaultValue IS NOT NULL) THEN
            SET _Value = _DefaultValue;
            INSERT INTO _db_globals
            SET
                `Key` = _Key,
                `Value` = _Value
            ON DUPLICATE KEY UPDATE 
                `Value` = _Value
            ;
        END IF;
    END IF;
END$$



DROP PROCEDURE IF EXISTS `_ExistsTempTable`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `_ExistsTempTable`(
    IN _TableName VARCHAR(250),
    OUT _Exists BOOLEAN
    )
BEGIN
    SET 
        @._ExistsTempTable.Return = FALSE,
        @._ExistsTempTable.SQL = 
        "
        SET @._ExistsTempTable.Return = EXISTS(SELECT * FROM `#TableName#` LIMIT 1);  
        "
    ;
    SET @._ExistsTempTable.SQL = REPLACE(@._ExistsTempTable.SQL, '#TableName#', _TableName);
    CALL _ExecuteCmd(@._ExistsTempTable.SQL, @Error);
    SET _Exists = @._ExistsTempTable.Return;
END$$

DROP FUNCTION IF EXISTS `_GetAppOwner`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_GetAppOwner`() RETURNS VARCHAR(100)
    DETERMINISTIC
BEGIN
    IF @session.globals.Owner IS NULL THEN
            CALL _Globals_Get('Owner', @session.globals.Owner, NULL);
    END IF;
    RETURN @session.globals.Owner;
END$$



DROP FUNCTION IF EXISTS `_IReg_Set_Value`$$

DROP FUNCTION IF EXISTS `_IReg_Get_Value`$$

DROP PROCEDURE IF EXISTS `_IReg_Get_2`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `_IReg_Get_2`(
    IN _IdPath VARCHAR(250),
    IN _IdKey VARCHAR(250),
    IN _Rok INTEGER,
    IN _DataType VARCHAR(100),
    OUT _Value VARCHAR(250),
    IN _DefaultValue VARCHAR(250),
    IN _VariableName VARCHAR(250)
    )
    COMMENT 'Pobiera z IRega'
S_IReg_Get: BEGIN
    CALL _IntReg_Get(IFNULL(_VariableName, ''), _IdPath, _IdKey, _Rok, _DataType, _Value, _DefaultValue);
END$$

DROP PROCEDURE IF EXISTS `_IReg_Get`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `_IReg_Get`(
    IN _IdPath VARCHAR(250),
    IN _IdKey VARCHAR(250),
    IN _Rok INTEGER,
    IN _DataType VARCHAR(100),
    OUT _Value VARCHAR(250),
    IN _DefaultValue VARCHAR(250)
    )
    COMMENT 'Pobiera z IRega'
S_IReg_Get: BEGIN
    CALL _IntReg_Get('', _IdPath, _IdKey, _Rok, _DataType, _Value, _DefaultValue);
END$$

DROP PROCEDURE IF EXISTS `_IntReg_Get`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `_IntReg_Get`(
    IN _MODE VARCHAR(250),
    IN _IdPath VARCHAR(250),
    IN _IdKey VARCHAR(250),
    IN _Period VARCHAR(250),
    IN _DataType VARCHAR(100),
    OUT _Value VARCHAR(5250),
    IN _DefaultValue VARCHAR(5250)
    )
    COMMENT 'Pobiera z IRega'
_intreg_get: BEGIN
    DECLARE _SQL TEXT;
    
    IF _MODE = 'select' THEN
        SELECT i.* FROM IReg i WHERE IF(_Period != '', i.Rok = _Period, TRUE) ORDER BY IdKey;
        LEAVE _intreg_get;
    END IF;

    SET @_Value = NULL;
    /*****************************************************************************
        SPR.. @._IntReg_Get.NEW
    *****************************************************************************/
    IF IFNULL(@._IntReg_Get.NEW, FALSE) THEN
    --  Nowy odczyt (funkcja)    
        SET @_Value = _IReg_Get_Value('', '', _IdPath, _IdKey, _Period, _DataType);
        -- CALL _IReg_Get_VAR_2('', '', 'Zakupy_YYY', 0, 'BOOLEAN', @session.HT.IR.Zakupy_YYY, FALSE, '@session.HT.IR.');
    ELSE
        --  Po staremu
        IF _IdPath = '' THEN
            SET _IdPath = 'INT\\SYSTEM\\MOTLAWA';
        ELSE
            SET _IdPath = CONCAT('INT\\SYSTEM\\MOTLAWA\\', _IdPath);
        END IF;

        SET _DataType = UPPER(_DataType);
        CASE
            WHEN _DataType IN ('STRING', 'TEXT', 'STR', 'TXT') THEN 
                SET _DataType = 'STRING';
            WHEN _DataType IN ('BOOL', 'BOOLEAN') THEN 
                SET _DataType = 'BOOLEAN';
            WHEN _DataType IN ('INT', 'INTEGER', 'SMALLINT', 'WORD', 'LARGEINT') THEN 
                SET _DataType = 'INTEGER';
            WHEN _DataType IN ('FLOAT', 'DOUBLE') THEN 
                SET _DataType = 'FLOAT';
            WHEN _DataType IN ('DATE', 'DATETIME') THEN 
                SET _DataType = 'date';
            WHEN _DataType IN ('TIME') THEN 
                SET _DataType = 'time';
            ELSE    
                SET _DataType = _DataType;
        END CASE;
        
        SET _DataType = LOWER(_DataType);
        SET @_DataType = _DataType;
        SELECT
            DataKey, Data_type_delphi, IReg_FieldName
        INTO    
            @_DataType, @Data_type_delphi, @IReg_FieldName
        FROM `_data_type_maps`
        WHERE
            DataKey = @_DataType
        ;
            
        SET _SQL = '
            SELECT 
                r.#FN, r.GUID
            INTO 
                @_Value, @.IReg.GUID 
            FROM `IReg` r
            WHERE
                IdPath = ''_IdPath'' AND 
                IdKey = ''_IdKey'' AND 
                Rok = _Period
            LIMIT 1
            ;'
        ;    
        SET _SQL = REPLACE(_SQL, '#FN', @IReg_FieldName);
        SET _SQL = REPLACE(_SQL, '_IdPath', _IdPath);
        SET _SQL = REPLACE(_SQL, '_IdKey', _IdKey);
        SET _SQL = REPLACE(_SQL, '_Period', _Period);
        SET _SQL = REPLACE(_SQL, '\\', '\\\\');
        
        
        SET @_SQL1 = _SQL;
        SET @_IdPath = _IdPath;
        CALL _ExecuteCmd(_SQL, @Error);

    END IF;    --  IF IFNULL(@._IntReg_Get.NEW, FALSE) THEN
    /*****************************************************************************
        KONIEC spr. @._IntReg_Get.NEW
    *****************************************************************************/
    IF (@_Value IS NOT NULL) THEN
        SET _Value = @_Value;
    ELSE
        IF (_DefaultValue IS NOT NULL) THEN
            SET _Value = _DefaultValue;
            SET @IRegNewGUID = NewGUID();
            SET @.IReg.GUID = @IRegNewGUID;
            INSERT IGNORE INTO `IReg`
                (IdKey, IdPath, Rok, GUID, IdVal)
                SELECT
                    _IdKey,
                    _IdPath,
                    _Period,
                    @IRegNewGUID,
                    @Data_type_delphi
            ;
            SET @_Value = _Value;
            CASE
                WHEN @IReg_FieldName IN ('ValueA', 'ValueD', 'ValueT', 'ValueX', 'ValueBlob') THEN 
                    SET @_Value = CONCAT('''', @_Value, '''');
                WHEN @IReg_FieldName IN ('ValueB') THEN 
                    SET @_Value = CONCAT('(', @_Value, ' = TRUE)');
                ELSE    
                    SET @_Value = @_Value;
            END CASE;
            
            SET _SQL = '
                UPDATE    `IReg` 
                SET
                    #FN = #FV
                WHERE
                    GUID = ''#GUID''
                ;'
            ;    
            SET _SQL = REPLACE(_SQL, '#FN', @IReg_FieldName);
            SET _SQL = REPLACE(_SQL, '#FV', @_Value);
            -- SET _SQL = REPLACE(_SQL, '#IdVal', @Data_type_delphi);
            SET _SQL = REPLACE(_SQL, '#GUID', @IRegNewGUID);
            
            SET @_SQL = _SQL;
            CALL _ExecuteCmd(_SQL, @Error);
            
        END IF;
    END IF;
    
    IF _MODE LIKE '@session.%' THEN
        IF _MODE LIKE '@session.%.IR.' THEN
        --  jesli podaje tylko "@session.HT.IR." albo "@session.PL.IR." to łączek key z tym przedrostkiem
            SET @.IReg.VariableName = CONCAT(_MODE, _IdKey); 
        ELSE
            SET @.IReg.VariableName = _MODE; 
        END IF;
        UPDATE    `IReg` 
        SET
            VariableName = @.IReg.VariableName
        WHERE
            GUID = @.IReg.GUID
        ;
    END IF;

END$$

DROP PROCEDURE IF EXISTS `_IntReg_Set`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `_IntReg_Set`(
    IN _MODE VARCHAR(250),
    IN _IdPath VARCHAR(250),
    IN _IdKey VARCHAR(250),
    IN _Period VARCHAR(250),
    IN _DataType VARCHAR(100),
    IN _Value VARCHAR(5250)
    )
    COMMENT 'Zapis do IRega'
BEGIN
    DECLARE _SQL TEXT;
    
    SET @_Value = NULL;
    IF _IdPath = '' THEN
        SET _IdPath = 'INT\\SYSTEM\\MOTLAWA';
    ELSE
        IF _IdPath LIKE 'INT%' THEN
            SET _IdPath = _IdPath;
        ELSE
            SET _IdPath = CONCAT('INT\\SYSTEM\\MOTLAWA\\', _IdPath);
        END IF;
    END IF;

    SET _DataType = UPPER(_DataType);
    CASE
        WHEN _DataType IN ('STRING', 'TEXT', 'STR', 'TXT') THEN 
            SET _DataType = 'STRING';
        WHEN _DataType IN ('BOOL', 'BOOLEAN') THEN 
            SET _DataType = 'BOOLEAN';
        WHEN _DataType IN ('INT', 'INTEGER', 'SMALLINT', 'WORD', 'LARGEINT') THEN 
            SET _DataType = 'INTEGER';
        WHEN _DataType IN ('FLOAT', 'DOUBLE') THEN 
            SET _DataType = 'FLOAT';
        WHEN _DataType IN ('DATE', 'DATETIME') THEN 
            SET _DataType = 'date';
        WHEN _DataType IN ('TIME') THEN 
            SET _DataType = 'time';
        ELSE    
            SET _DataType = _DataType;
    END CASE;
    
    SET _DataType = LOWER(_DataType);
    SET @_DataType = _DataType;
    
    SELECT
        DataKey, Data_type_delphi, IReg_FieldName
    INTO    
        @_DataType, @Data_type_delphi, @IReg_FieldName
    FROM `_data_type_maps`
    WHERE
        DataKey = @_DataType
    ;
    
    IF (_Value IS NOT NULL) THEN
        SET @IRegNewGUID = NewGUID();
                SET @_IdPath = _IdPath;
        INSERT IGNORE INTO `IReg`
            (IdKey, IdPath, Rok, GUID, IdVal)
            SELECT
                _IdKey,
                _IdPath,
                _Period,
                @IRegNewGUID,
                @Data_type_delphi
        ON DUPLICATE KEY
        UPDATE
            GUID = (@IRegNewGUID := GUID)
        ;
        SET @_Value = _Value;
        CASE
            WHEN @IReg_FieldName IN ('ValueA', 'ValueD', 'ValueT', 'ValueX', 'ValueBlob') THEN 
                SET @_Value = CONCAT('''', @_Value, '''');
            WHEN @IReg_FieldName IN ('ValueB') THEN 
                SET @_Value = CONCAT('(', @_Value, ' = TRUE)');
            ELSE    
                SET @_Value = @_Value;
        END CASE;
        
        SET _SQL = '
            UPDATE    `IReg` 
            SET
                #FN = #FV
            WHERE
                GUID = ''#GUID''
            ;'
        ;    
        SET _SQL = REPLACE(_SQL, '#FN', @IReg_FieldName);
        SET _SQL = REPLACE(_SQL, '#FV', @_Value);
        -- SET _SQL = REPLACE(_SQL, '#IdVal', @Data_type_delphi);
        SET _SQL = REPLACE(_SQL, '#GUID', @IRegNewGUID);
        
        SET @_SQL = _SQL;
        CALL _ExecuteCmd(_SQL, @Error);
        
    END IF;
    
END$$



/* ************************************************************************************************************************************************************************
    MIME
************************************************************************************************************************************************************************ */    
DROP FUNCTION IF EXISTS `_GetExtFromMIME`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_GetExtFromMIME`(_Name VARCHAR(256), _MIME VARCHAR(50)) RETURNS VARCHAR(10)
    DETERMINISTIC
BEGIN
    DECLARE _Ext VARCHAR(10);
    SET _Ext = SUBSTRING_INDEX(_Name, '.', -1);
    IF _Ext = _Name THEN
        SELECT `ext` INTO _Ext FROM `_sys_mime` WHERE `mime` = _MIME;
    END IF;
    RETURN _Ext;
END$$

/* ************************************************************************************************************************************************************************
    ERP
************************************************************************************************************************************************************************ */    
DROP FUNCTION IF EXISTS `_Get_Init_doc_date`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_Get_Init_doc_date`(
    ) 
RETURNS DATE
    NO SQL
    DETERMINISTIC
BEGIN
    RETURN IFNULL(@session.erp.Get_Init_doc_date, CURRENT_DATE());
END$$


DROP PROCEDURE IF EXISTS `_Developer_Check_Malpy`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `_Developer_Check_Malpy`(
    IN _MODE VARCHAR(150),
    IN _Param_A VARCHAR(150),    
    IN _Param_B VARCHAR(150),    
    IN _Param_C VARCHAR(150),    
    IN _Param_D VARCHAR(150)    
    )
    COMMENT 'do testow'
/*
    CALL _Report_Err('Update opng_e set dos = 1 Where GUID = "aa";', 'Exec');
*/    
BEGIN
    /*	20 XII 2023
--  tak na prawdę to wew. wołamy CALL _sessions(_MODE, _ID, _Param_A, _Param_B, _Param_C, _Param_D, _Param_E);
    CALL _sys_authorization('SESSION.SETUP.VAR', '', '', '', '', '', 'GO');
    ale teraz ...
    */
    CALL _sessions_APP('SET.VAR', '', '', '', '', '', '');
    IF _MODE = 'Test 1' THEN
    /*
        CALL _Developer_Check_Malpy('Test 1', '', '', '', '');
    */
        SELECT 
            CONNECTION_ID() AS CONNECTION_ID, 
            _varStr(IFNULL(@session.user.Admin, 'NULL')) AS `@session.user.Admin`,
            _varStr(IFNULL(@session.Registration.Admin, 'NULL')) AS `@session.user.Admin`,
            _varStr(IFNULL(@session.globals.Owner, 'NULL')) AS `@session.globals.Owner`,
            _varStr(IFNULL(@uprDSDisabled, 'NULL')) AS `@uprDSDisabled`,
            _varStr(IFNULL(@SYSTEM.Client.Session.GUID, 'NULL')) AS `@SYSTEM.Client.Session.GUID`,
            _varStr(IFNULL(@session.Registration.UserGUID, 'NULL')) AS `@session.Registration.UserGUID`,
            _varStr(IFNULL(@session.Registration.AppName, 'NULL')) AS `@session.Registration.AppName`
        ;
    END IF;
    
    IF _MODE = 'Test 2' THEN
    /*
        CALL _Developer_Check_Malpy('Test 2', '', '', '', '');
    */
        SELECT 
            CONNECTION_ID() AS CONNECTION_ID, 
            _varStr(IFNULL(@SYSTEM.Client.Session.GUID, 'NULL')) AS `@SYSTEM.Client.Session.GUID`,
            _varStr(@session.INFO.Log.Ver) AS INFO_Log_Ver,
            _varStr(@session.INFO.User_GUID) AS INFO_User_GUID,
            _varStr(@session.INFO.User_Login) AS INFO_User_Login,
            _varStr(@session.INFO.User_user_type) AS INFO_User_user_type,
            _varStr(@session.INFO.User_UgrpGUID) AS INFO_User_UgrpGUID,
            _varStr(@session.INFO.User_Admin) AS INFO_User_Admin,
            _varStr(@session.INFO.Host) AS INFO_Host,
            _varStr(@session.INFO.AppName) AS INFO_AppName,
            _varStr(@session.INFO.MACAddress) AS INFO_MACAddress,
            _varStr(@session.INFO.IP) AS INFO_IP
        ;
    END IF;
    
    IF _MODE = 'Test 3' THEN
    /*
        CALL _Developer_Check_Malpy('Test 3', '', '', '', '');
    */
        SELECT 
            CONNECTION_ID() AS CONNECTION_ID, 
            _varStr(IFNULL(@SYSTEM.Client.Session.GUID, 'NULL')) AS `@SYSTEM.Client.Session.GUID`,
            _varStr(@session.INFO.Log.Ver) AS INFO_Log_Ver,
            _varStr(CONCAT(IFNULL(@session.CurrMyCompNameStr, '?'), ' - ', @session.INFO.Host)) AS CurrMyCompNameStr,
            _varStr(CONCAT(IFNULL(@session.CurrMyIPOnly, '?'), ' - ', @session.INFO.IP)) AS CurrMyIPOnly,
            _varStr(CONCAT(IFNULL(@session.CurrMACAddresses, '?'), ' - ', @session.INFO.MACAddress)) AS CurrMACAddresses,
            _varStr(CONCAT(IFNULL(@session.CheckLogonUserLogin, '?'), ' - ', @session.INFO.User_Login)) AS CheckLogonUserLogin,
            _varStr(IFNULL(@session.Registration.HostName, 'NULL')) AS `@session.Registration.HostName`
        ;
    END IF;
    
END$$


DROP PROCEDURE IF EXISTS `_rozrzucanie_tools`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `_rozrzucanie_tools`(
    IN _MODE VARCHAR(250),
    IN _Value_Rozrzuc DOUBLE,
    IN _Param_A VARCHAR(255),
    IN _Param_B VARCHAR(255)
)
/*
    CALL _rozrzucanie_tools('INIT', 0, '', '');
    CALL _rozrzucanie_tools('CALC', 0, '', '');
    CALL _rozrzucanie_tools('DROP', 0, '', '');
*/
S_t_rozrzucanie: BEGIN 
    DECLARE _SUM_Waga, _SUM_Value, _Nadw DECIMAL(16,6);
    DECLARE _LasLP INTEGER;

    IF _MODE = 'INIT' THEN
        DROP TEMPORARY TABLE IF EXISTS `t_rozrzucanie`;
        CREATE TEMPORARY TABLE `t_rozrzucanie` (
            `ID` VARCHAR(250) NOT NULL DEFAULT '',
            `Lp` INT(11) DEFAULT NULL,
            `Waga` DECIMAL(16,4) DEFAULT NULL,
            `Value` DECIMAL(16,4) DEFAULT NULL,
            `precyzja` INT(11) DEFAULT NULL,
            PRIMARY KEY (`Id`),
            KEY `LP`(`LP`)
        )
        ;
    END IF; --  _MODE = 'INIT'

    IF _MODE = 'CALC' THEN
        
        DELETE FROM `t_rozrzucanie` WHERE Waga = 0;
        
        SET @.t_rozrzucanie.LP = 0;
        UPDATE `t_rozrzucanie` t
        SET
            t.LP = _VarInt(@.t_rozrzucanie.LP := @.t_rozrzucanie.LP + 1)
        ORDER BY t.Waga
        ;
        
        SET 
            _SUM_Waga = 
                IFNULL(_VarDecimal((SELECT SUM(t.Waga) FROM `t_rozrzucanie` t)), 0)
        ;
        -- SELECT _Value_Rozrzuc, _SUM_Waga;
        UPDATE `t_rozrzucanie` t
        SET
            t.Value = _Rnd2(IF(_SUM_Waga = 0, 0, _RND(t.Waga*_Value_Rozrzuc/_SUM_Waga, IFNULL(t.precyzja, 2))))
        ;
        /*
        Do testow
        UPDATE `t_rozrzucanie` t
        SET
            t.RValue2 = _Rnd2(IF(_SUM_Waga = 0, 0, t.Waga*_Value_Rozrzuc/_SUM_Waga))
        ;
        */
        SELECT MAX(Lp), SUM(Value) FROM `t_rozrzucanie` INTO _LasLP, _SUM_Value;
        SET _Nadw = _SUM_Value - _Value_Rozrzuc;
        -- do testow SET @_Nadw = _Nadw, @_SUM_Value = _SUM_Value, @_SUM_Waga = _SUM_Waga;
        UPDATE `t_rozrzucanie`
        SET
            Value = Value - _Nadw
        WHERE
            LP = _LasLP
        ;

    END IF; --  _MODE = 'CALC'
    
    IF _MODE = 'DROP' THEN
        DROP TEMPORARY TABLE IF EXISTS `t_rozrzucanie`;
    END IF; --  _MODE = 'DROP'

END$$

DROP PROCEDURE IF EXISTS `_python_sessions_tools`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `_python_sessions_tools`(
    IN _MODE VARCHAR(150),
    IN _SESSION VARCHAR(150),
    IN _Key VARCHAR(255),    
    IN _PARAM_A VARCHAR(250),
    IN _PARAM_B VARCHAR(250),
    IN _PARAM_C VARCHAR(250),
    IN _PARAM_D VARCHAR(250)
) 
S_python_sessions_tools: BEGIN 
set @A = 1;
    IF _MODE LIKE 'Testy.%' THEN
set @A = 2;
        IF _MODE LIKE 'Testy.temp.%' THEN
set @A = 3;
            IF _MODE = 'Testy.temp.INIT' THEN
set @A = 4;
                DROP TEMPORARY TABLE IF EXISTS `t_kontr_cos`;
                CREATE TEMPORARY TABLE `t_kontr_cos` (
                  `KontrGUID` VARCHAR(38) NOT NULL DEFAULT '',
                  `Napis` VARCHAR(255) NOT NULL DEFAULT '',
                  `last_modified` DATETIME DEFAULT NULL,
                  UNIQUE KEY `KontrGUID` (`KontrGUID`)
                )
                ;
                INSERT IGNORE INTO `t_kontr_cos`
                SELECT
                    k.GUID,
                    '?' AS Napis,
                    NOW() AS last_modified
                FROM `kontrah` k
                WHERE
                    TRUE
                    -- and k.Symbol LIKE '%a%'
                ;
            END IF;
            
            IF _MODE = 'Testy.temp.UPDATE' THEN
                SET @LP = 0;
                UPDATE `t_kontr_cos` t
                SET
                    t.Napis = CONCAT_WS(': ', @LP := @LP + 1, _PARAM_A),
                    t.last_modified = NOW()
                ;
            END IF;
            
            IF _MODE = 'Testy.temp.SELECT' THEN
set @A = 6;
                SELECT * FROM `t_kontr_cos`;
            END IF;
            
        END IF;
    END IF;
END$$

/*************************************************************************************************************************************************************************
    MD5
************************************************************************************************************************************************************************ */    
DROP FUNCTION IF EXISTS `_MD5_CHARSET`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `_MD5_CHARSET`(
    _MODE VARCHAR(200),
    _IN_Par_1 VARCHAR(256),
    _IN_Par_2 VARCHAR(256),
    _IN_Par_3 VARCHAR(256),
    _IN_Par_4 VARCHAR(256),
    _ParamA VARCHAR(256)
) RETURNS VARCHAR(256)
    NO SQL
    DETERMINISTIC
BEGIN
    DECLARE _SQLText TEXT DEFAULT '';
    SET 
        @.MD5_CHARSET = NULL,
        @_IN_Par_1 = _IN_Par_1,
        @_IN_Par_2 = _IN_Par_2,
        @_IN_Par_3 = _IN_Par_3,
        @_IN_Par_4 = _IN_Par_4
    ;
    /*
    Niestety     
    CONVERT(expr,type), CONVERT(expr USING transcoding_name) 
    a transcoding_name jest literałem zatem zwasze 
        CONVERT('abc' USING utf8);
        albo
        CONVERT('abc' USING cp1250);
        a niestety nie można
        CONVERT('abc' USING @Mojzestwa); 
        lub nawet
        CONVERT('abc' USING @@character_set_client);
    */
    SET _MODE = IFNULL(NULLIF(_MODE, ''), @@character_set_client);
    IF _MODE IN ('utf8', 'utf8mb3') THEN
        SET @.MD5_CHARSET =
            MD5(@.concat_ws.pre := CONCAT_WS('',
                CONVERT(NULLIF(@_IN_Par_1, '') USING utf8),
                CONVERT(NULLIF(@_IN_Par_2, '') USING utf8),
                CONVERT(NULLIF(@_IN_Par_3, '') USING utf8),
                CONVERT(NULLIF(@_IN_Par_4, '') USING utf8)
            ))
        ;
                /*
                SET _SQLText = 
                    "        
                    -- SELECT
                    SET @.MD5_CHARSET =
                        MD5(@.concat_ws.pre := CONCAT_WS('',
                            CONVERT(NULLIF(@_IN_Par_1, '') USING #CHARSET#),
                            CONVERT(NULLIF(@_IN_Par_2, '') USING #CHARSET#),
                            CONVERT(NULLIF(@_IN_Par_3, '') USING #CHARSET#),
                            CONVERT(NULLIF(@_IN_Par_4, '') USING #CHARSET#)
                        ))
                    ;
                    "
                ;
                SET _SQLText = REPLACE(_SQLText, '#CHARSET#', @@character_set_client);
                SET @_SQLText = _SQLText;
                CALL _ExecuteCmd(_SQLText, @Error);
                */
    ELSEIF _MODE IN ('', 'cp1250') THEN
        SET @.MD5_CHARSET =
            MD5(@.concat_ws.pre := CONCAT_WS('',
                CONVERT(NULLIF(@_IN_Par_1, '') USING cp1250),
                CONVERT(NULLIF(@_IN_Par_2, '') USING cp1250),
                CONVERT(NULLIF(@_IN_Par_3, '') USING cp1250),
                CONVERT(NULLIF(@_IN_Par_4, '') USING cp1250)
            ))
        ;
    END IF;
    RETURN @.MD5_CHARSET;
END$$

DROP FUNCTION IF EXISTS `MD5_1`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `MD5_1`(
    _IN_Par_1 VARCHAR(256)
) RETURNS VARCHAR(256)
    NO SQL
    DETERMINISTIC
BEGIN
    -- DECLARE _SQLText TEXT DEFAULT '';
    -- DECLARE MODE_SET VARCHAR(200)
    SET 
        @.MD5_CHARSET = NULL,
        @_IN_Par_1 = _IN_Par_1
    ;
    IF @@character_set_client = 'utf8' THEN
        SET @.MD5_CHARSET =
            MD5(@.concat_ws.pre := 
                CONVERT(NULLIF(@_IN_Par_1, '') USING utf8)
            )
        ;
    ELSEIF @@character_set_client IN ('', 'cp1250') THEN
        SET @.MD5_CHARSET =
            MD5(@.concat_ws.pre := 
                CONVERT(NULLIF(@_IN_Par_1, '') USING cp1250)
            )
        ;
    END IF;
    RETURN @.MD5_CHARSET;
END$$

DROP FUNCTION IF EXISTS `MD5_2`$$
CREATE DEFINER=`root`@`localhost` FUNCTION `MD5_2`(
    _IN_Par_1 VARCHAR(256),
    _IN_Par_2 VARCHAR(256)
) RETURNS VARCHAR(256)
    NO SQL
    DETERMINISTIC
BEGIN
    -- DECLARE _SQLText TEXT DEFAULT '';
    -- DECLARE MODE_SET VARCHAR(200)
    SET 
        @.MD5_CHARSET = NULL,
        @_IN_Par_1 = _IN_Par_1,
        @_IN_Par_2 = _IN_Par_2
    ;
    IF @@character_set_client = 'utf8' THEN
        SET @.MD5_CHARSET =
            MD5(@.concat_ws.pre := CONCAT_WS('',
                CONVERT(NULLIF(@_IN_Par_1, '') USING utf8),
                CONVERT(NULLIF(@_IN_Par_2, '') USING utf8)
            ))
        ;
    ELSEIF @@character_set_client IN ('', 'cp1250') THEN
        SET @.MD5_CHARSET =
            MD5(@.concat_ws.pre := CONCAT_WS('',
                CONVERT(NULLIF(@_IN_Par_1, '') USING cp1250),
                CONVERT(NULLIF(@_IN_Par_2, '') USING cp1250)
            ))
        ;
    END IF;
    RETURN @.MD5_CHARSET;
END$$


/* ************************************************************************************************************************************************************************
    Clear_Event
    Event do usuwania "złogów" i wywoływany 1 raz na dobe ok 4:00 (rano)
    W procedurze `_sys_Clear_Event_ProcList` nalezy dopisywac własne call-e lub update/delete do czyszczenia
    
    SHOW VARIABLES LIKE '%event%';
    SET GLOBAL event_scheduler = ON;
    SELECT @@event_scheduler;
    
    zwłaszcza : ....
    LOG_infpiek_dok_po_insert
    infpiek_int_po_log
    oppo_corr_e
    _erp_external_process_log
    
    CALL _sys_Clear_Event_ProcList('ALL', '', '');
************************************************************************************************************************************************************************ */    
DROP PROCEDURE IF EXISTS `_sys_Clear_Event_ProcList`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `_sys_Clear_Event_ProcList`(
    IN _MODE VARCHAR(150),
    IN _PARAM_A VARCHAR(250),
    IN _PARAM_B VARCHAR(250)
) 
S_Clear_Event_ProcList: BEGIN 
    DO _Birth_System();    --  teraz to tutaj wszystkie zmiene są aktywowane/pobierane
    
    -- UPDATE `impt_1b7430a33edbf4d8f97bf521bbcc5e7a` SET `No Gephlue` = `No Gephlue` + 1;
    
    DO _counters_tools('SET', CONCAT_WS('.', '_sys_Clear_Event_ProcList', _MODE), '', '');        -- to tylko Licznik!!!!

    
    /******************************************************************************************************
        KONKOL
        `LOG_infpiek_dok_po_insert` i `infpiek_int_po_log` - starsze niż 3 tygodnie
        `m_xxpo` - starsze niż 14 dni
    ******************************************************************************************************/
    IF _MODE IN ('ALL', 'process_log') AND @session.globals.Owner = 'KONKOL' AND SCHEMA() = 'ht' THEN
    --  usuń starsze niż 3 tyg
        DELETE pr FROM `LOG_infpiek_dok_po_insert` pr
        WHERE
            pr.Create_At < (CURRENT_DATE() - INTERVAL 3 WEEK)
        ;
        DELETE pr FROM `infpiek_int_po_log` pr
        WHERE
            pr.Create_At < (CURRENT_DATE() - INTERVAL 3 WEEK)
        ;
        
        /******************************************************************************
            1 XII 2021 wyczyscilem `m_xxpo` do 5 tyg wstec z UFF!!!
            Teraz czyszcze 
            10 tyg. wstecz wszystko oraz
            5 tyg wlacznie z localtime
        ******************************************************************************/
        DELETE mp 
        FROM `m_xxpo` mp
        WHERE
        TRUE
        -- AND mp.Create_at < (CURRENT_DATE() - INTERVAL 10 WEEK)
        AND mp.Create_at < (CURRENT_DATE() - INTERVAL 1 MONTH)
        ;
        /*
        DELETE mp 
        FROM `m_xxpo` mp
        WHERE
        TRUE
        AND mp.Create_at < (CURRENT_DATE() - INTERVAL 1 MONTH)
        AND mp.localtime < (CURRENT_DATE() - INTERVAL 1 MONTH)
        -- AND mp.Create_at < (CURRENT_DATE() - INTERVAL 5 WEEK)
        -- AND mp.localtime < (CURRENT_DATE() - INTERVAL 5 WEEK)
        ;
        */
        /* *********************************************************************
        DROP TEMPORARY TABLE IF EXISTS `t_delete_m_xxpo`;
        CREATE TEMPORARY TABLE `t_delete_m_xxpo` (
          `IDN` INTEGER NOT NULL DEFAULT 0,
          PRIMARY KEY `IDN`(`IDN`)
        )
        ;
        TRUNCATE `t_delete_m_xxpo`;
        INSERT IGNORE INTO `t_delete_m_xxpo` 
        
        SELECT 
            mp.idn 
            -- , `localtime`, create_At, mp.terminrealizacji, mp.*
        FROM `m_xxpo` mp 
        WHERE 
            TRUE
            AND mp.terminrealizacji < (CURRENT_DATE() - INTERVAL 5 WEEK) 
            -- AND mp.terminrealizacji < '2020-10-09'
        ORDER BY IDN
        -- LIMIT 50000
        ;
        INSERT IGNORE INTO `t_delete_m_xxpo` 
        SELECT 
            mp.idn 
            -- , `localtime`, create_At, mp.terminrealizacji, mp.*
        FROM `m_xxpo` mp 
        WHERE 
            TRUE
            AND mp.terminrealizacji IS NULL
            AND mp.create_At < (CURRENT_DATE() - INTERVAL 5 WEEK) 
            -- AND mp.create_At  < '2020-10-09'
        ORDER BY IDN
        -- LIMIT 50000
        ;
        /* było 
        
        DELETE mp FROM `m_xxpo` mp, `t_delete_m_xxpo` t WHERE mp.IDN = t.idn;        
        
        
        SELECT MAX(mp.idn) FROM `m_xxpo` mp WHERE mp.localtime < (CURRENT_DATE() - INTERVAL 5 WEEK) INTO @.To.idn;
        DELETE FROM `m_xxpo` WHERE IDN <= @.To.idn ORDER BY IDN;
        */
        DELETE mn FROM `m_zmng` mn
        WHERE
            mn.TerminRealizacji < (CURRENT_DATE() - INTERVAL 5 WEEK)
        ;
        -- SET @.MAX.down_hex = IFNULL((SELECT MAX(dn.down_hex) FROM `infpiek_int_ng` dn WHERE dn.down_Dat < CURRENT_DATE() - INTERVAL 100 DAY), 0); 
        SET @.MAX.down_hex = IFNULL((SELECT MAX(dn.down_hex) FROM `infpiek_int_ng` dn WHERE dn.down_Dat < CURRENT_DATE() - INTERVAL 3 MONTH), 0); 
        DELETE dp FROM `infpiek_int_po` dp WHERE dp.down_hex <= @.MAX.down_hex;
        DELETE dn FROM `infpiek_int_ng` dn WHERE dn.down_hex <= @.MAX.down_hex;

        IF SCHEMA() = 'zoo' THEN
            SET @.MAX.down_hex = 0;
        END IF;
    END IF;
    
    /******************************************************************************************************
        Log błędów
        `_db_app_errors` - starsze niż 6 m-ce
    ******************************************************************************************************/
    IF _MODE IN ('ALL', '_db_app_errors') THEN
    --  usuń starsze niż 3 tyg
        DELETE e FROM `_db_app_errors` e
        WHERE
            e.Time < (CURRENT_DATE() - INTERVAL 2 MONTH)
        ;
    END IF;
    
    /******************************************************************************************************
        Log procesów
        `_erp_external_process_log` - starsze niż 3 tygodnie
    ******************************************************************************************************/
    IF _MODE IN ('ALL', '_erp_external_process_log') THEN
    --  usuń starsze niż 1 m-c
        DELETE pr FROM `_erp_external_process_log` pr
        WHERE
            pr.Time < (CURRENT_DATE() - INTERVAL 1 MONTH)
        ;
        DELETE FROM `_erp_external_process_log_GUIDlink` 
        WHERE 
            NOT EXISTS(SELECT pl.ID FROM `_erp_external_process_log` pl WHERE pl.ID = id_log)
        ;
    END IF;
    
    /******************************************************************************************************
        _sys_db_logons
        `_sys_db_logons` - starsze niż 3 m-ce
    ******************************************************************************************************/
    IF _MODE IN ('ALL', '_sys_db_logons') THEN
    --  usuń Eventowe starsze niż 2 tyg
        DELETE sdl FROM `_sys_db_logons` sdl
        WHERE
            sdl.Inactive
            AND sdl.Kind = 'EVENT'
            AND sdl.CONNECT_AT < (CURRENT_DATE() - INTERVAL 2 WEEK)
        ;
    --  usuń starsze niż 2 m-ce
        DELETE sdl FROM `_sys_db_logons` sdl
        WHERE
            sdl.LAST_USED_AT < (CURRENT_DATE() - INTERVAL 2 MONTH)
        ;
    END IF;
    
    /******************************************************************************************************
        stare czyli _db_logons
        `_db_logons` - starsze niż 3 m-ce
    ******************************************************************************************************/
    IF _MODE IN ('ALL', '_db_logons') THEN
    --  usuń starsze niż 3 tyg
        DELETE dl FROM `_db_logons` dl
        WHERE
            dl.LAST_USED_AT < (CURRENT_DATE() - INTERVAL 3 WEEK)
        ;
    END IF;
    
    /******************************************************************************************************
        dziennik importów `imp_diary`
    ******************************************************************************************************/
    IF _MODE IN ('ALL', 'Diary') THEN
    --  usuń importy starsze niż 1 m-c    
        DELETE FROM `imp_diary` WHERE Deleted AND ((GREATEST(Create_At, Imported_At) + INTERVAL 1 MONTH) < CURRENT_DATE());
    END IF;
    
    /******************************************************************************************************
        blokady na dokumenty, etc
    ******************************************************************************************************/
    IF _MODE IN ('ALL', 'LOCKS') THEN
    --  usuń blokady starsze niż 24h dla których sesja nie istnieje lub jest zamknięta 
        DO _sys_locks_do('DELETE_LOCKS_WITH_Inactive_Session', '', '', '', '', '', '7', ''); 
    --  i jeszcze stare ale wciaż używane locki na świat E
        DELETE l FROM `_lock_inf` l 
        WHERE
            l.alocaltime < (NOW() - INTERVAL 3 DAY)
        ;
    END IF;
    
    /******************************************************************************************************
        świat m
    ******************************************************************************************************/
    IF _MODE IN ('ALL', 'xxxx_m') THEN
    --  Usuń starsze blokady niż 1 m-c dla rekordów z tabel 'opng_m' i 'zmng_m'
        DO _sys_locks_do('DELETE_LOCKS_OLDER_THAN.n.Month', '', 'opng_m', 'EDYCJA', '', '', '1', ''); 
        DO _sys_locks_do('DELETE_LOCKS_OLDER_THAN.n.Month', '', 'zmng_m', 'EDYCJA', '', '', '1', ''); 
    --  teraz można usunąć same rekordy z 'opng_m' i 'zmng_m' i oczywiście zaraz potem z powiazanych tabel
        DROP TEMPORARY TABLE IF EXISTS `t_delete_xxng_x`;
        CREATE TEMPORARY TABLE `t_delete_xxng_x` (
          `GUID` VARCHAR(38) NOT NULL DEFAULT '',
          PRIMARY KEY `GUID`(`GUID`)
        )
        ;
    --  tabela `opng_m` i powiazane
        TRUNCATE `t_delete_xxng_x`;
    --  1 wstaw jeszcze nie zapisane (idn = 0) starsze niż ...    
        INSERT IGNORE INTO `t_delete_xxng_x` 
            SELECT
                mn.GUID
            FROM `opng_m` mn
            WHERE
            --  nie zapisane (idn = 0)     
                mn.Idn = 0
            --  starsze niż 1 dzien? a moze więcej ????
                AND mn.LocalTime < (NOW() - INTERVAL 2 DAY)
            --  nie zapisane (bez odpow. w real)     
                AND NOT EXISTS(SELECT n.GUID FROM `opng` n WHERE n.GUID = mn.GUID)
        ;
    --  2 wstaw wczesniej zapisane ale bez blokady i starsze niż ...    
        INSERT IGNORE INTO `t_delete_xxng_x` 
            SELECT
                mn.GUID
            FROM `opng_m` mn, `opng` n
            WHERE
                mn.GUID = n.GUID
            --  starsze niż 1 dzien? a moze więcej ????
                AND mn.LocalTime < (NOW() - INTERVAL 2 DAY)
            --  bez blokady
                AND NOT EXISTS(SELECT dl.Rec_ID FROM `_sys_locks` dl WHERE dl.Rec_ID = n.GUID AND dl.Rec_TableName = 'opng_m')
        ;
    --  Usuwanie    
        DELETE mn FROM `opng_m` mn, `t_delete_xxng_x` t
        WHERE
            mn.GUID = t.GUID
        ;
        DELETE mp FROM `oppo_m` mp, `t_delete_xxng_x` t
        WHERE
            mp.IdnOper = t.GUID
        ;
        DELETE mp FROM `opng_vat_m` mp, `t_delete_xxng_x` t
        WHERE
            mp.IdnOper = t.GUID
        ;
        DELETE mp FROM `oppo_corr_m` mp, `t_delete_xxng_x` t
        WHERE
            mp.IdnOper_corr = t.GUID
        ;
    --  tabela `zmng_m` i powiazane
        TRUNCATE `t_delete_xxng_x`;
    --  1 wstaw jeszcze nie zapisane (idn = 0) starsze niż ...    
        INSERT IGNORE INTO `t_delete_xxng_x` 
            SELECT
                mn.GUID
            FROM `zmng_m` mn
            WHERE
            --  nie zapisane (idn = 0)     
                mn.Idn = 0
            --  starsze niż 1 dzien? a moze więcej ????
                AND mn.LocalTime < (NOW() - INTERVAL 2 DAY)
            --  nie zapisane (bez odpow. w real)     
                AND NOT EXISTS(SELECT n.GUID FROM `zmng` n WHERE n.GUID = mn.GUID)
        ;
    --  2 wstaw wczesniej zapisane ale bez blokady i starsze niż ...    
        INSERT IGNORE INTO `t_delete_xxng_x` 
            SELECT
                mn.GUID
            FROM `zmng_m` mn, `zmng` n
            WHERE
                mn.GUID = n.GUID
            --  starsze niż 1 dzien? a moze więcej ????
                AND mn.LocalTime < (NOW() - INTERVAL 2 DAY)
            --  bez blokady
                AND NOT EXISTS(SELECT dl.Rec_ID FROM `_sys_locks` dl WHERE dl.Rec_ID = n.GUID AND dl.Rec_TableName = 'zmng_m')
        ;
    --  Usuwanie    
        DELETE mn FROM `zmng_m` mn, `t_delete_xxng_x` t
        WHERE
            mn.GUID = t.GUID
        ;
        DELETE mp FROM `zmpo_m` mp, `t_delete_xxng_x` t
        WHERE
            mp.IdnNg = t.GUID
        ;
        DELETE mp FROM `opng_vat_m` mp, `t_delete_xxng_x` t
        WHERE
            mp.IdnOper = t.GUID
        ;
        /*
        DELETE mp FROM `zmng_vat_m` mp, `t_delete_xxng_x` t
        WHERE
            mp.IdnOper = t.GUID
        ;
        */
    END IF;

    /******************************************************************************************************
        świat e
    ******************************************************************************************************/
    IF _MODE IN ('ALL', 'xxxx_e') THEN
    --  usuwanie rekordow z 'opng_e' i 'zmng_e' i oczywiście zaraz potem z powiazanych tabel
        DROP TEMPORARY TABLE IF EXISTS `t_delete_xxng_x`;
        CREATE TEMPORARY TABLE `t_delete_xxng_x` (
          `GUID` VARCHAR(38) NOT NULL DEFAULT '',
          PRIMARY KEY `GUID`(`GUID`)
        )
        ;
    --  tabela `opng_e` i powiazane
        TRUNCATE `t_delete_xxng_x` ;
    --  1 wstaw jeszcze nie zapisane (idn = 0) starsze niż ...    
        INSERT IGNORE INTO `t_delete_xxng_x` 
            SELECT
                mn.GUID
            FROM `opng_e` mn
            WHERE
            --  nie zapisane (idn = 0)     
                mn.Idn = 0
            --  starsze niż 1 dzien? a moze więcej ????
                AND mn.LocalTime < (NOW() - INTERVAL 7 DAY)
            --  nie zapisane (bez odpow. w real)     
                AND NOT EXISTS(SELECT n.GUID FROM `opng` n WHERE n.GUID = mn.GUID)
        ;
    --  2 wstaw wczesniej zapisane ale bez rekordu w `ng_e_rec` i starsze niż ...    
        INSERT IGNORE INTO `t_delete_xxng_x` 
            SELECT
                mn.GUID
            FROM `opng_e` mn, `opng` n
            WHERE
                mn.GUID = n.GUID
            --  starsze niż 1 m-c? a moze więcej ????
                AND mn.LocalTime < (NOW() - INTERVAL 1 MONTH)
            --  bez rekordu w `ng_e_rec`
                AND NOT EXISTS(SELECT dl.GUID FROM `ng_e_rec` dl WHERE dl.GUID = n.GUID)
        ;
    --  Usuwanie    
        DELETE mn FROM `opng_e` mn, `t_delete_xxng_x` t
        WHERE
            mn.GUID = t.GUID
        ;
        DELETE mp FROM `oppo_e` mp, `t_delete_xxng_x` t
        WHERE
            mp.IdnOper = t.GUID
        ;
        DELETE mp FROM `opng_vat_e` mp, `t_delete_xxng_x` t
        WHERE
            mp.IdnOper = t.GUID
        ;
        DELETE mp FROM `oppo_corr_e` mp, `t_delete_xxng_x` t
        WHERE
            mp.IdnOper_corr = t.GUID
        ;
    --  tabela `zmng_e` i powiazane
        TRUNCATE `t_delete_xxng_x` ;
    --  1 wstaw jeszcze nie zapisane (idn = 0) starsze niż ...    
        INSERT IGNORE INTO `t_delete_xxng_x` 
            SELECT
                mn.GUID
            FROM `zmng_e` mn
            WHERE
            --  nie zapisane (idn = 0)     
                mn.Idn = 0
            --  starsze niż 1 dzien? a moze więcej ????
                AND mn.LocalTime < (NOW() - INTERVAL 2 DAY)
            --  nie zapisane (bez odpow. w real)     
                AND NOT EXISTS(SELECT n.GUID FROM `zmng` n WHERE n.GUID = mn.GUID)
        ;
    --  2 wstaw wczesniej zapisane ale bez rekordu w `ng_e_rec` i starsze niż ...        
        INSERT IGNORE INTO `t_delete_xxng_x` 
            SELECT
                mn.GUID
            FROM `zmng_e` mn, `zmng` n
            WHERE
                mn.GUID = n.GUID
            --  starsze niż 1 m-c? a moze więcej ????
                AND mn.LocalTime < (NOW() - INTERVAL 1 MONTH)
            --  bez rekordu w `ng_e_rec`
                AND NOT EXISTS(SELECT dl.GUID FROM `ng_e_rec` dl WHERE dl.GUID = n.GUID)
        ;
    --  Usuwanie    
        DELETE mn FROM `zmng_e` mn, `t_delete_xxng_x` t
        WHERE
            mn.GUID = t.GUID
        ;
        DELETE mp FROM `zmpo_e` mp, `t_delete_xxng_x` t
        WHERE
            mp.IdnNg = t.GUID
        ;
        DELETE mp FROM `zmng_vat_e` mp, `t_delete_xxng_x` t
        WHERE
            mp.IdnOper = t.GUID
        ;
        
    END IF;
    
    
    
END$$

DROP EVENT IF EXISTS `_sys_Clear_Event`$$
CREATE EVENT IF NOT EXISTS `_sys_Clear_Event`
    ON SCHEDULE 
    -- EVERY 1 MINUTE STARTS CURRENT_TIMESTAMP + INTERVAL 10 SECOND
    EVERY 1 DAY STARTS CURRENT_DATE + INTERVAL 1 DAY + INTERVAL 65 MINUTE
    DO
    BEGIN    
        DECLARE CONTINUE HANDLER FOR SQLEXCEPTION    
        BEGIN
            CALL _Report_Error('_sys_Clear_Event', 'EVENT', 'CALL _sys_Clear_Event_ProcList(''ALL'', '''', '''');', '', '');
        END;
        /*
        zwłaszcza 
        LOG_infpiek_dok_po_insert
        infpiek_int_po_log
        oppo_corr_e
        _erp_external_process_log
        */
            CALL _sys_Clear_Event_ProcList('ALL', '', '');
    END;
;    
$$


/* ************************************************************************************************************************************************************************
    Test BLOKAD
************************************************************************************************************************************************************************ */    
DROP PROCEDURE IF EXISTS `_TEST_Blokad`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `_TEST_Blokad`(
    IN _MODE VARCHAR(150),
    IN _PARAM_A VARCHAR(200),
    IN _PARAM_B VARCHAR(200),
    IN _Params MEDIUMTEXT
)
S_TEST_Blokad: BEGIN
    IF _MODE IN ('SELECT.1') THEN
        SELECT 
            p.Localtime,p.Ilosc, p.iloscdo, p.spakowano, p.ExtFlags, 
            p.info4,
                                    n.WyjazdGUID, 
                                    n.KontrGUID, 
                                    IdnTowr, 
                                    komentarz, 

            p.* 
            FROM zmpo p , zmng n
            WHERE 
            TRUE
            AND n.wyjazdGUID = 'SPED:a4767011be06d9f874fa8080a1a26b12'
            -- AND n.GUID = '{5B5B759B-7882-4732-BF1F-AB381227EB21}'
            AND p.idnng = n.GUID
            -- and p.idnng = '{5B5B759B-7882-4732-BF1F-AB381227EB21}'
        ;    
        -- select k.Nume from kontrah where k.GUID = 'asdfklasdf';
    END IF;
    
    IF _MODE IN ('SELECT.2') THEN
        CALL _log_select('select', '', _PARAM_A, '', '', '', 'czas=czas>"2021-05-21"&');
    END IF;
    
    
    IF _MODE IN ('LET.SELECT.1') THEN
        IF _LOCK('IS_Used_By_ME', CONCAT(_MODE, _PARAM_A), 20, '') OR _LOCK('GET_LOCK', CONCAT(_MODE, _PARAM_A), 10, '') THEN
            CALL _TEST_Blokad('SELECT.1', _PARAM_A, _PARAM_B, _Params);
            DO _LOCK('RELEASE_LOCK', CONCAT(_MODE, _PARAM_A), 0, '');
        END IF;
        DO _LOCK('RELEASE_LOCK', CONCAT(_MODE, _PARAM_A), 0, '');
    END IF;
    
    IF _MODE IN ('LET.SELECT.2') THEN
        IF _LOCK('IS_Used_By_ME', CONCAT(_MODE, _PARAM_A), 20, '') OR _LOCK('GET_LOCK', CONCAT(_MODE, _PARAM_A), 10, '') THEN
            CALL _TEST_Blokad('SELECT.2', _PARAM_A, _PARAM_B, _Params);
            DO _LOCK('RELEASE_LOCK', CONCAT(_MODE, _PARAM_A), 0, '');
        END IF;
        DO _LOCK('RELEASE_LOCK', CONCAT(_MODE, _PARAM_A), 0, '');
    END IF;
    
    
END$$

DELIMITER ;

/*
$Log: _system.sql,v $
Revision 1.86  2024/10/29 18:12:52  jmam
$SEND$ Po zmianach redakcyjnych

Revision 1.85  2024/10/29 18:11:37  jmam
Zmiany redakcyjne

Revision 1.84  2024/08/12 12:34:43  apro
porządki c.d.

Revision 1.83  2024/08/12 11:32:52  apro
reformat - tabs

Revision 1.82  2023/09/08 05:23:43  jmam
$SEND$ zgrywanie 5 IX

Revision 1.81  2023/06/12 12:09:50  jmam
$SEND$  func. do MD5

Revision 1.80  2023/02/08 07:18:34  jmam
$SEND$ Values w Params

Revision 1.79  2023/01/18 14:08:19  jmam
$SEND$

Revision 1.78  2022/12/15 11:32:24  jmam
$SEND$ mod.tworzenia GUID-a sesji

Revision 1.77  2022/12/08 16:29:40  jmam
$SEND$

Revision 1.76  2022/11/08 08:38:42  jmam
$SEND$

Revision 1.75  2022/04/11 11:14:14  jmam
$SEND$  nowe GUIDy dla delegacji i wniosk?
Revision 1.74  2022/02/01 14:52:29  jmam
$SEND$

Revision 1.73  2021/10/19 19:18:23  jmam
$SEND$

Revision 1.72  2021/10/07 13:18:48  jmam
$SEND$

Revision 1.71  2021/08/19 18:45:22  jmam
$SEND$

Revision 1.70  2021/05/17 13:19:45  jmam
$SEND$

Revision 1.69  2021/04/26 08:12:18  jmam
$SEND$

Revision 1.68  2021/04/26 08:10:25  jmam
$SEND$

Revision 1.67  2021/04/22 07:06:58  jmam
$SEND$

Revision 1.66  2021/04/19 11:47:58  jmam
$SEND$

Revision 1.65  2021/03/22 12:01:20  jmam
$SEND$

Revision 1.64  2021/01/19 13:51:14  jmam
$SEND$

Revision 1.63  2021/01/17 20:28:26  jmam
$SEND$

Revision 1.62  2021/01/14 14:30:50  jmam
$SEND$

Revision 1.61  2021/01/13 08:10:22  jmam
$SEND$

Revision 1.60  2021/01/13 08:08:45  slon
$SEND$

Revision 1.59  2021/01/12 13:21:04  jmam
$SEND$

Revision 1.58  2020/12/30 13:11:41  jmam
$SEND$

Revision 1.57  2020/11/26 13:43:40  jmam
$SEND$

Revision 1.56  2020/11/04 15:51:31  jmam
$SEND$

Revision 1.55  2020/10/12 11:43:20  jmam
$SEND$

Revision 1.54  2020/07/02 11:49:47  jmam
$SEND$

Revision 1.53  2020/06/30 13:25:06  jmam
$SEND$

Revision 1.52  2020/04/16 12:30:19  jmam
$SEND$

Revision 1.51  2020/02/06 09:21:01  jmam
$SEND$

Revision 1.50  2020/01/29 14:33:11  jmam
$SEND$

Revision 1.49  2020/01/27 11:53:38  jmam
$SEND$

Revision 1.48  2020/01/22 08:23:23  jmam
$SEND$

Revision 1.47  2020/01/21 12:51:55  jmam
$SEND$

Revision 1.46  2020/01/20 14:08:44  jmam
$SEND$

Revision 1.45  2019/11/18 14:54:49  jmam
$SEND$

Revision 1.44  2019/11/12 10:04:19  jmam
$SEND$

Revision 1.43  2019/10/15 11:50:01  jmam
$SEND$

Revision 1.42  2019/09/19 09:25:23  jmam
$SEND$

Revision 1.41  2019/09/16 08:34:00  jmam
$SEND$

Revision 1.40  2019/08/08 12:29:37  jmam
$SEND$

Revision 1.39  2019/07/01 11:16:44  jmam
$SEND$

Revision 1.38  2019/06/17 11:39:00  jmam
$SEND$

Revision 1.37  2019/04/01 13:03:45  jmam
no message

Revision 1.36  2019/03/19 13:30:27  jmam
$SEND$

Revision 1.35  2019/02/11 12:51:23  jmam
$SEND$

Revision 1.34  2018/11/15 12:05:25  jmam
$SEND$

Revision 1.33  2018/10/31 09:28:32  waliant
Zmiana wielkosci varchar(65532) $SEND$

Revision 1.32  2018/10/23 08:25:48  apro
$SEND$
Jmam zapominiał o sqlzmianach...

*/

