 DELIMITER $$
/*****************************************************
REWIZJE
******************************************************
$Log: osoby.sql,v $
Revision 1.18  2025/04/01 09:33:21  jmam
Tymcz. przed zgraniem

Revision 1.17  2021/06/15 08:58:44  waliant
Poprawka bledu w v_wyjazdy_kierowcy $SEND$

Revision 1.16  2021/03/22 12:13:37  jmam
$SEND$

Revision 1.15  2020/01/29 09:40:31  jmam
no message

Revision 1.14  2018/07/11 11:04:32  jmam
$SEND$

Revision 1.13  2017/08/14 09:20:02  jmam
$SEND$

Revision 1.12  2017/07/12 12:55:26  jmam
$SEND$

Revision 1.11  2017/03/29 10:55:16  jmam
$SEND$

Revision 1.10  2016/08/31 12:14:11  max
[crm: 42524] ASTE

Revision 1.9  2016/07/28 10:23:51  apro
poprawka BOMBY usuwającej osoby z grupy ALL

*/


/* ************************************************************************************************************************************************************************
	BI
************************************************************************************************************************************************************************ */	
DROP TRIGGER IF EXISTS `osoby_bi`$$
CREATE DEFINER=`root`@`localhost` TRIGGER `osoby_bi` BEFORE INSERT ON `osoby` FOR EACH ROW 
A: BEGIN
	IF _TriggerDisabled() THEN LEAVE A; END IF;
	
	SET NEW.Imiona = CONCAT(NEW.Imie1, ' ', NEW.Imie2);		

	SET @.NEW.Update_status = NEW.Update_status;
	
	IF @.NEW.Update_status = 'ADD.AS.Akwizytor' THEN
		SET NEW.EditInfo = 'Akwizytor';
		IF NEW.IdnUser = '' THEN
			SET NEW.IdnUser = CONCAT(NEW.Imie1, '.', SUBSTR(NEW.Nazwisko, 1, 1));
		END IF;
	END IF;
	
	SET NEW.Update_status = '';
	
	IF @session.globals.Owner = 'ASTE' THEN  -- #42524
		SET NEW.last_shown_zest = CURDATE();
	END IF;
	
END;
$$

/* ************************************************************************************************************************************************************************
	AI
************************************************************************************************************************************************************************ */	
DROP TRIGGER IF EXISTS `osoby_ai`$$
CREATE DEFINER=`root`@`localhost` TRIGGER `osoby_ai` AFTER INSERT ON `osoby` FOR EACH ROW 
A: BEGIN
	IF _TriggerDisabled() THEN LEAVE A; END IF;
	--
	IF IFNULL(@session.trigger.osoby, FALSE) THEN 
		LEAVE A; 
	END IF;
	SET @session.trigger.osoby = TRUE;
set @X = '1.1';		
	
	--	Osoby do grupy sa z soba
	CALL AddOsobaToGrupyOsob(NEW.GUID, NEW.rodzaj);
set @X = '1.2';		
	
	--	Osoby jako resources
	IF @session.globals.hr.HR_TOWR_RES_ACTIVE THEN LEAVE A; 
		CALL _res_aiu(0, NEW.IsRes, NEW.GUID, 'HR', 'osoby', NEW.stawka_h, NEW.idnuser, 0, 100.0, -1);
	END IF;
set @X = '1.3';		
	
	--	Czy zakladac grupe jako ugrp dla oddzialu
	/*
	nie dokończone !!!!
	SET @C_UGRP_SYNC_DIVISION = 0;
	CALL _Globals_Get('UGRP_SYNC_DIVISION', @C_UGRP_SYNC_DIVISION, @C_UGRP_SYNC_DIVISION);
	IF @C_UGRP_SYNC_DIVISION != 0 THEN
	--	Na razie NIC nie rob
		SET @C_UGRP_SYNC_DIVISION = @C_UGRP_SYNC_DIVISION;
		-- tutaj powinienem zrobic INSERT INTO erp_division_schema itd
	END IF;
	*/
	IF IFNULL(NEW.Rodzaj, 0) != 0 THEN
set @X = '1.3.1';		
		IF IFNULL(NEW.NrSeriaDowoduOsobistego, '') != '' THEN
set @X = '1.3.2';		
			CALL hr_cards_from_osoby_trigger('INSERT', NEW.NrSeriaDowoduOsobistego, 'ID', NEW.GUID, '', '', '');		
set @X = '1.3.4';		
		END IF;
set @X = '1.3.5';		
		IF IFNULL(NEW.NrPaszportu, '') != '' THEN
set @X = '1.3.6';		
			CALL hr_cards_from_osoby_trigger('INSERT', NEW.NrPaszportu, 'PASSPORT', NEW.GUID, '', '', '');		
set @X = '1.3.7';		
		END IF;
set @X = '1.3.8';		

		IF IFNULL(NEW.KontrGUID, '') != '' THEN
set @X = '1.3.9';		
			INSERT IGNORE INTO `hr_kontrah_links`
			(osobaGUID, kontrGUID, typ, kontekst)
			SELECT
				NEW.GUID, NEW.KontrGUID, 0, '(CRM)'
			FROM `kontrah` k
			WHERE
				k.GUID = NEW.KontrGUID
			;
set @X = '1.3.10';		
		END IF;
		
			/*
			NIE używamy tego w triggerze!!!  bo gdy ktoś ma view zamiat osób to mamy problem zakładania osoby ciagle w 1 miejscu
		IF IFNULL(NEW.user_type, 0) != 0 THEN
			CALL _user_accounts_create_from_osoba('PARAMS', NEW.GUID, NEW.IDN, NEW.IdnUser, NEW.datas, NEW.user_type, NEW.administrator, '', ''); 
		END IF;
			*/
	END IF;

	IF @.NEW.Update_status = 'ADD.AS.Akwizytor' THEN
	--	Czy jest kontrah
		INSERT IGNORE INTO `kontrah`
			(GUID, symbol, Nazwa, nip, regon, pesel, Uwagi, akwizytor)
			SELECT
				NEW.GUID, NEW.IdnUser, CONCAT(NEW.Nazwisko, ' ', NEW.Imiona), NEW.NrNIP, '', NEW.NrPesel, '', 1
		ON DUPLICATE KEY
		UPDATE
			`kontrah`.akwizytor = 1
		;
		INSERT IGNORE INTO `hr_kontrah_links`
		(osobaGUID, kontrGUID, typ, kontekst)
		SELECT
			NEW.GUID, NEW.GUID, 0, '(AKW)'
		;
		IF @session.globals.Owner = 'TRANSBUD' THEN
			INSERT IGNORE INTO `katcols`
			(colnr, typ, Klucz, ValueX, GUIDlink)
			SELECT
				1 AS colnr, 
				0 AS typ,
				1 + (SELECT MAX(kl.Klucz) FROM `katcols` kl WHERE kl.colnr = 1 AND kl.typ =0),
				CONCAT(NEW.Nazwisko, ' ', NEW.Imiona),
				NEW.GUID
			;
			
		END IF;
		
	END IF;


	SET @.NEW.Update_status = '';
	
		
	SET @session.trigger.osoby = FALSE;
END;
$$

/* ************************************************************************************************************************************************************************
	BU
************************************************************************************************************************************************************************ */	
DROP TRIGGER IF EXISTS `osoby_bu`$$
CREATE DEFINER=`root`@`localhost` TRIGGER `osoby_bu` BEFORE UPDATE ON `osoby` FOR EACH ROW 
A: BEGIN
	IF _TriggerDisabled() THEN LEAVE A; END IF;
	
	IF IFNULL(@session.trigger.osoby, FALSE) THEN 
		LEAVE A; 
	END IF;
	SET @session.trigger.osoby = TRUE;
/*
*/
	IF _IsDiff_C(NEW.Imie1, OLD.Imie1) OR _IsDiff_C(NEW.Imie2, OLD.Imie2) THEN
		SET NEW.Imiona = CONCAT(NEW.Imie1, ' ', NEW.Imie2);
	END IF;
	
	SET @.NEW.Update_status = NEW.Update_status;

	IF @.NEW.Update_status = 'ADD.AS.Akwizytor' THEN
		SET NEW.EditInfo = 'Akwizytor';
		IF NEW.IdnUser = '' THEN
			SET NEW.IdnUser = CONCAT(NEW.Imie1, '.', SUBSTR(NEW.Nazwisko, 1, 1));
		END IF;
	END IF;

	IF (NEW.IdnUser = '' AND NEW.user_type > 0) THEN	--	OR NEW.Update_status = 'user_accounts' 
		SET NEW.IdnUser = NEW.IDN;
	END IF;
	/*	
	jmam 11 sty 2023 - 
		Dla grup deaktywacja  w IntNet.EXE ustawia user_inactive podczas gdy w IntNet WEB mamy tylko 
		usuwanie (deleted = 1) - Aga postuluje by zachowywało sie identycznie ale Grzes nie ma jak 
		skomplikować EXE-ka! :(
		Zatem ustawiam tu Deleted na 1 gdy user_inactive = 1 i ??? na odwrót!!!
	*/
	IF 
		NEW.Rodzaj = 0 AND 	-- dla grup
		!(NEW.user_inactive <=> OLD.user_inactive) AND  -- gdy zmieniło się aktywnośc grupy
		(NEW.Deleted <=> OLD.Deleted) 	-- a nie zmieniło sie deleted ...
	THEN
		SET NEW.Deleted = NEW.user_inactive;
	END IF;
	
	SET NEW.Update_status = '';
	SET @session.trigger.osoby = FALSE;
END;
$$

/* ************************************************************************************************************************************************************************
	AU
************************************************************************************************************************************************************************ */	
DROP TRIGGER IF EXISTS `osoby_au`$$
CREATE DEFINER=`root`@`localhost` TRIGGER `osoby_au` AFTER UPDATE ON `osoby` FOR EACH ROW 
A: BEGIN
	IF _TriggerDisabled() THEN LEAVE A; END IF;
	--
		set @Bylemtu = 'A0';
	IF IFNULL(@session.trigger.osoby, FALSE) THEN 
		SET @.NEW.Update_status = '';
		LEAVE A; 
	END IF;
	SET @session.trigger.osoby = TRUE;
	
		set @Bylemtu = 'A01';
	IF @session.globals.hr.HR_TOWR_RES_ACTIVE THEN 
	--
		CALL _res_aiu(OLD.IsRes, NEW.IsRes, NEW.GUID, 'HR', 'osoby', NEW.stawka_h, NEW.idnuser, 0, 100.0, -1);
	END IF;

		set @Bylemtu = 'A1';
	
	IF _IsDiff_C(NEW.NrSeriaDowoduOsobistego, OLD.NrSeriaDowoduOsobistego) THEN
		CALL hr_cards_from_osoby_trigger('UPDATE', OLD.NrSeriaDowoduOsobistego, 'ID', NEW.GUID, '', '', '');		
		CALL hr_cards_from_osoby_trigger('INSERT', NEW.NrSeriaDowoduOsobistego, 'ID', NEW.GUID, '', '', '');		
	END IF;

	IF NOT(NEW.NrPaszportu <=> OLD.NrPaszportu) THEN
		CALL hr_cards_from_osoby_trigger('UPDATE', OLD.NrPaszportu, 'PASSPORT', NEW.GUID, '', '', '');		
		CALL hr_cards_from_osoby_trigger('INSERT', NEW.NrPaszportu, 'PASSPORT', NEW.GUID, '', '', '');		
	END IF;


		set @Bylemtu = 'A2';
	IF NOT(NEW.user_type <=> OLD.user_type) OR NOT(NEW.administrator <=> OLD.administrator) OR NOT(NEW.Datas <=> OLD.Datas) OR NOT(NEW.IdnUser <=> OLD.IdnUser) OR NOT(NEW.user_inactive <=> OLD.user_inactive) THEN
        SET 
            @.os.Log.IDN := NULL,
            @.os.Log.Opis := 'Zmiana ust. uzytkownika',
            @.os.Log.GUIDLink := NEW.GUID,
            @.os.Log.Miejsce := 100, @.os.Log.Czynnosc := 3
        ;
        CALL log_Ins('Trigger.logpo.Prepare.Clear', @.os.Log.IDN, @.os.Log.Miejsce, @.os.Log.Czynnosc, @.os.Log.GUIDLink, '_user_accounts', @.os.Log.Opis, '', '', '', '', '', '');
        CALL log_Ins('Trigger.logpo.UPDATE', @.os.Log.IDN, '', '', '', '', '', 'Typ konta', '', OLD.user_type, NEW.user_type, '', '');
        CALL log_Ins('Trigger.logpo.UPDATE', @.os.Log.IDN, '', '', '', '', '', 'Administr.', '', OLD.administrator, NEW.administrator, '', '');
        CALL log_Ins('Trigger.logpo.UPDATE', @.os.Log.IDN, '', '', '', '', '', 'Hasło', '', OLD.Datas, NEW.Datas, '', '');
        CALL log_Ins('Trigger.logpo.UPDATE', @.os.Log.IDN, '', '', '', '', '', 'Login', '', OLD.IdnUser, NEW.IdnUser, '', '');
        CALL log_Ins('Trigger.logpo.UPDATE', @.ua.Log.IDN, '', '', '', '', '', 'Stan konta', '', OLD.user_inactive, NEW.user_inactive, '', '');
    /*  1 IV 2025
		SET @_IDN_Log = NULL;
		IF NOT(NEW.user_type <=> OLD.user_type) THEN
			CALL osoby_AddToLog('INSERT', @_IDN_Log, NEW.GUID, 3, 'user_type', OLD.user_type, NEW.user_type, 'zmiana ust. uzytkownika');	
		END IF;
		IF NOT(NEW.administrator <=> OLD.administrator) THEN
			CALL osoby_AddToLog('INSERT', @_IDN_Log, NEW.GUID, 3, 'administrator', OLD.administrator, NEW.administrator, 'zmiana ust. uzytkownika');	
		END IF;
		IF NOT(NEW.Datas <=> OLD.Datas) THEN
			CALL osoby_AddToLog('INSERT', @_IDN_Log, NEW.GUID, 3, 'Datas', OLD.Datas, NEW.Datas, 'zmiana ust. uzytkownika');	
		END IF;
		IF NOT(NEW.IdnUser <=> OLD.IdnUser) THEN
set @X = '2.1.1';		
			CALL osoby_AddToLog('INSERT', @_IDN_Log, NEW.GUID, 3, 'IdnUser', OLD.IdnUser, NEW.IdnUser, 'zmiana ust. uzytkownika');	
set @X = '2.1.2';		
		END IF;
		IF NOT(NEW.user_inactive <=> OLD.user_inactive) THEN
			CALL osoby_AddToLog('INSERT', @_IDN_Log, NEW.GUID, 3, 'user_inactive', OLD.user_inactive, NEW.user_inactive, 'zmiana ust. uzytkownika');	
		END IF;
		*/
	END IF;

	SET	
		@.NEW.datas.Changed = NOT (NEW.datas <=> OLD.datas),
		@.NEW.administrator.Changed = NOT (NEW.administrator <=> OLD.administrator),
		@.NEW.user_type.Changed = NOT (NEW.user_type <=> OLD.user_type)
	;



	IF @.NEW.Update_status LIKE '%.AS.Akwizytor' THEN
	--	Czy jest kontrah
		IF 
		@.NEW.Update_status = 'ADD.AS.Akwizytor' 
		AND
		NOT EXISTS(SELECT * FROM `hr_kontrah_links` kl WHERE kl.OsobaGUID = NEW.GUID AND kl.Kontekst LIKE '%(AKW)%') THEN
			INSERT IGNORE INTO `kontrah`
				(GUID, symbol, Nazwa, nip, regon, pesel, Uwagi)
				SELECT
					NEW.GUID, NEW.IdnUser, CONCAT(NEW.Nazwisko, ' ', NEW.Imiona), NEW.NrNIP, '', NEW.NrPesel, ''
			;
			INSERT IGNORE INTO `hr_kontrah_links`
			(osobaGUID, kontrGUID, typ, kontekst)
			SELECT
				NEW.GUID, NEW.GUID, 0, '(AKW)'
			;
		END IF;
		
		UPDATE `kontrah` k, `hr_kontrah_links` kl
		SET
			k.pesel = NEW.NrPesel,
			k.akwizytor = (@.NEW.Update_status = 'ADD.AS.Akwizytor')
		WHERE
			kl.OsobaGUID = NEW.GUID
			AND kl.Kontekst LIKE '%(AKW)%'
			AND k.GUID = kl.kontrGUID
		;
		IF @session.globals.Owner = 'TRANSBUD' THEN
			IF 
			@.NEW.Update_status = 'ADD.AS.Akwizytor' 
			AND 
			NOT EXISTS(SELECT * FROM `katcols` kl WHERE kl.GUIDlink = NEW.GUID) THEN
				INSERT IGNORE INTO `katcols`
				(colnr, typ, Klucz, ValueX, GUIDlink)
				SELECT
					1 AS colnr, 
					0 AS typ,
					1 + (SELECT MAX(kl.Klucz) FROM `katcols` kl WHERE kl.colnr = 1 AND kl.typ =0),
					CONCAT(NEW.Nazwisko, ' ', NEW.Imiona),
					NEW.GUID
				;
			END IF;

			UPDATE `katcols` kl 
			SET
				kl.Nieaktywna = (@.NEW.Update_status = 'DELETE.AS.Akwizytor')
			WHERE 
				kl.GUIDlink = NEW.GUID
			;
			
		END IF;
	--	GDY USUWANIE 	
		IF @.NEW.Update_status = 'DELETE.AS.Akwizytor' THEN
			DELETE FROM `hr_kontrah_links` WHERE osobaGUID = NEW.GUID AND Kontekst LIKE '%(AKW)%';
		END IF;
		
	END IF;
	
	
	IF @.NEW.Update_status LIKE 'CHANGE.Akwizytor%' THEN
		SET @.NEW.CHANGE.AkwizytorGUID = REPLACE(@.NEW.Update_status, 'CHANGE.Akwizytor', ''); -- to co pozostanie to GUID Akwizytora (kontrahenta)
		IF @.NEW.CHANGE.AkwizytorGUID <> '' THEN
			REPLACE `hr_kontrah_links`
			(osobaGUID, kontrGUID, typ, kontekst)
			SELECT
				NEW.GUID, @.NEW.CHANGE.AkwizytorGUID, 0, '(AKW)'
			;
			IF @session.globals.Owner = 'TRANSBUD' THEN
				INSERT IGNORE INTO `katcols`
				(colnr, typ, Klucz, ValueX, GUIDlink)
				SELECT
					1 AS colnr, 
					0 AS typ,
					1 + (SELECT MAX(kl.Klucz) FROM `katcols` kl WHERE kl.colnr = 1 AND kl.typ =0),
					CONCAT(NEW.Nazwisko, ' ', NEW.Imiona),
					NEW.GUID
				;
			END IF;
			
		END IF;
		
	END IF;

	
	
	
	IF !(NEW.NrPesel <=> OLD.NrPesel) THEN -- OR @(NEW.NrNIP <=> OLD.NrNIP) CHYBA NIE!!!
		UPDATE `kontrah` k, `hr_kontrah_links` kl
		SET
			k.pesel = NEW.NrPesel
		WHERE
			kl.OsobaGUID = NEW.GUID
			AND kl.Kontekst LIKE '%(AKW)%'
			AND k.GUID = kl.kontrGUID
		;
		
	END IF;
	SET @.NEW.Update_status = '';
	SET @session.trigger.osoby = FALSE;
END;
$$

DROP TRIGGER IF EXISTS `osoby_ad`$$

/* ************************************************************************************************************************************************************************
	AD

	DYWERSJA!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

CREATE DEFINER = `root`@`localhost` TRIGGER `osoby_ad` AFTER DELETE ON `osoby` FOR EACH ROW 
A: BEGIN
	IF _TriggerDisabled() THEN LEAVE A; END IF;
--	INIT Lock trigger zmienna @session.trigger.xxx
	--	IF IFNULL(@session.trigger.osoby, FALSE) THEN LEAVE A; END IF;
	--	SET @session.trigger.osoby = TRUE;

	DELETE FROM `grupy_osob` WHERE osobaguid = OLD.GUID;
	DELETE FROM `grupy_osob` WHERE grupaguid = OLD.GUID;
	
	DELETE FROM `hr_kontrah_links` WHERE osobaGUID = OLD.GUID;

--	FINAL UnLock trigger zmienna @session.trigger.xxx
	--	SET @session.trigger.osoby = FALSE;
END;
$$

*/


/* ************************************************************************************************************************************************************************
	Narzędzia 
************************************************************************************************************************************************************************ */	

DROP PROCEDURE IF EXISTS `osoby_AddToLog`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `osoby_AddToLog`(
	IN _MODE VARCHAR(150),
	INOUT _IDN_Log INTEGER,
	IN _Key VARCHAR(38),
	IN _Czynnosc VARCHAR(38),
	IN _FieldName VARCHAR(250),
	IN _OldValue VARCHAR(250),
	IN _NewValue VARCHAR(250),
	IN _Info VARCHAR(250)
)
/*
	CALL osoby_AddToLog('INSERT', 0, _Key, _Czynnosc, 'User_type', _OldValue, _NewValue, 'zmiana ust. uzytkownika');
*/
S_osoby_AddToLog: BEGIN

-- CALL _Setting_Variables('CHECK', '', '');
	IF _MODE = 'INSERT' THEN
	
		IF IFNULL(@session.Registration.UserLogin, '') = '' THEN
			LEAVE S_osoby_AddToLog;
		END IF;
		
		IF _IDN_Log IS NULL THEN
set @X = concat_WS('.', @X, '1');
		
			CALL log_Insert(
				'INSERT', _IDN_Log,
				@session.Registration.UserLogin, 
				100, -- Konto użytkownika - było 303, 
				_Czynnosc, _Key, @session.Registration.IP, 
				_Info, -- Info
				''
			);		
set @X = concat_WS('.', @X, '2');
		END IF;
set @X = concat_WS('.', @X, '3');
		INSERT INTO `logpo`
			(idnng, fld_name, `old`, `new`) 
		VALUES
			(_IDN_Log, _FieldName, IFNULL(_OldValue, ''), IFNULL(_NewValue, ''))
		;
set @X = concat_WS('.', @X, '4');

	END IF;
	
END;
$$

DROP PROCEDURE IF EXISTS `grupy_GrupaExists`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `grupy_GrupaExists`(
	IN _MODE VARCHAR(150),
	IN _GrupaNazwa VARCHAR(38),
	IN _GrupaSymbol VARCHAR(38),
	IN _PARAM_A VARCHAR(200),
	IN _PARAM_B VARCHAR(200)

)
/*
	CALL grupy_GrupaExists('', 'Nazwa Grupy ', '', '', ''); 

*/
BEGIN
		
	IF _MODE = '' THEN
		SET @_grupy_GrupaExists = '';
		SELECT
			o.GUID
		FROM `osoby` o
		WHERE
			(o.Nazwisko = _GrupaNazwa)
		LIMIT 1	
		INTO @_grupy_GrupaExists	
		;	
		SET @_grupy_GrupaExists = IFNULL(@_grupy_GrupaExists, '');
		IF @_grupy_GrupaExists != '' THEN
			INSERT IGNORE INTO `grupy_osob`
				(osobaGUID, grupaGUID)
				VALUES
				(@_grupy_GrupaExists, @_grupy_GrupaExists	)
			;
		END IF;
		-- Na koniec
		SELECT @_grupy_GrupaExists AS GrupaGUID;
	END IF;
END$$




CREATE OR REPLACE VIEW `v_wyjazdy_kierowcy` AS
	SELECT
		o.GUID,
		o.GUID AS OsobaGUID,
		k.GUID AS AkwizytorGUID,
		_ConcatStr(o.Nazwisko, o.Imiona, ' ') AS Kierowca_NazwiskoImie,
		o.Nazwisko, o.Imie1, o.Imie2,
		o.NrNIP, o.NrPesel,
		k.Symbol, k.Nazwa AS AkwizytorNazwa,
		k.AreaGUID,
		_VarStr_NotNull(IFNULL(r.Nazwa, '?')) AS Rewir_Nazwa,
		k.magazyn_akwizytora,
		_VarStr_NotNull(mg.Opis) AS Magazyn_akwizytora_Nazwa,
		k.ugrpguid,
		o.Update_status
		
	FROM `osoby` o
	INNER JOIN `hr_kontrah_links` kl ON kl.osobaGUID = o.GUID 
	INNER JOIN `kontrah` k ON k.GUID = kl.kontrGUID AND k.akwizytor = 1 
	LEFT JOIN `erp_area_nodes` r ON r.GUID = k.AreaGUID
	LEFT JOIN `Magazyny` mg ON mg.IdnMagazynu = k.magazyn_akwizytora
	WHERE
		kl.Kontekst LIKE '%(AKW)%'
		AND o.deleted = 0 
		AND k.deleted = 0
$$

CREATE OR REPLACE VIEW `v_wyjazdy_kierowcy_N` AS
	SELECT
		o.GUID,
		o.Nazwisko, o.Imie1, o.Imie2,
		o.NrNIP, o.NrPesel,
		o.EditInfo,
		o.Update_status
		
	FROM `osoby` o
	WHERE
		TRUE
		AND o.deleted = 0 
		AND o.EditInfo = 'Akwizytor'
$$


DELIMITER ;


/*
====================================================================================================================================================================================
	NOTATNIK
====================================================================================================================================================================================


*/
