 DELIMITER $$

/* ************************************************************************************************************************************************************************
	XI 2021 r. 
	Uniwersalne sql-ki dla przeliczen pozycji i do cen i rabatow
	xxng i xxpo
	swiat zwykly	opng zmng oppo zmpo etc
	E	 			opng_e zmng_e oppo_e zmpo_e etc
	TE				TE_opng TE_zmng TE_oppo TE_zmpo etc
************************************************************************************************************************************************************************ */	

DROP PROCEDURE IF EXISTS `C_HT_xxng_vat`$$
CREATE DEFINER=`root`@`localhost` PROCEDURE `C_HT_xxng_vat`(
	IN _MODE VARCHAR(250),
	IN _FROM VARCHAR(250),
	IN _WORLD VARCHAR(250),		--	"TE" czyli tabele `TE_xxxx` lub "E" czyli `xxxx_e` lub "" czyli xxxx
	IN _IdnOper VARCHAR(38),	--	IdnOper/IdnNg
	IN _Param_A VARCHAR(255),
	IN _Param_B VARCHAR(255),
	IN _Param_C VARCHAR(255),
	IN _Param_D VARCHAR(255),
	IN _Param_E TEXT
)
SC_HT_xxng_vat: BEGIN 

	DECLARE _Key VARCHAR(38);
	set @._IdnOper = _IdnOper;
	SET _Key = _IdnOper;
	
	IF _MODE = '`Inf_vat`.Create' THEN
	--	Tworzenie `Inf_vat` ale !!! IF NOT EXISTS potem badam ....
		CREATE TEMPORARY TABLE IF NOT EXISTS `Inf_vat` (
		  `_FROM` VARCHAR(100) NOT NULL DEFAULT '',
		  `_Swiat` VARCHAR(100) NOT NULL DEFAULT '',
		  `_Params` VARCHAR(255) NOT NULL DEFAULT '',
		  `GUID` VARCHAR(38) NOT NULL DEFAULT '',
		  `Rodzaj` INT(11) NOT NULL DEFAULT '0',
		  `rodzaj_typ` INT(11) DEFAULT NULL,
		  `Calc_Ver` INT(11) NOT NULL DEFAULT '0',
		  `Kurs` DOUBLE(16,4) NOT NULL DEFAULT '1.0000',
		  `koszt_nabycia_coeff` DOUBLE(16,4) NOT NULL DEFAULT '1.0000',
		  `blokada_przeliczenia_tab_vat` INT(11) DEFAULT '0',
		  `przeliczenie_B_N` INT(11) NOT NULL DEFAULT '0',
		  `Netto_do_Brutto` BOOLEAN NOT NULL DEFAULT '0',
		  `IS_Korekta` BOOLEAN NOT NULL DEFAULT '0',
		  `IS_Kancelaria` BOOLEAN NOT NULL DEFAULT '0',
		  `IS_PodlegaVAT` BOOLEAN NOT NULL DEFAULT '0',
		  `IS_PozycjeVisible` BOOLEAN NOT NULL DEFAULT '0',
		  `_Clear_Fixed` BOOLEAN NOT NULL DEFAULT '0',
		  -- `_ExtFlags` VARCHAR(250),
		  `_xxng_TableName` VARCHAR(200) NOT NULL DEFAULT '',
		  `_xxng_vat_TableName` VARCHAR(200) NOT NULL DEFAULT '',
		  `_xxpo_TableName` VARCHAR(200) NOT NULL DEFAULT '',
		  `_SQLText` MEDIUMTEXT
		)
		;
	END IF;
	
	
	IF _MODE = '`Inf_vat`<-`xxNg`' THEN
		IF IFNULL(_Key, '') = '' THEN
			LEAVE SC_HT_xxng_vat;
		END IF;

		SET 
			@.xxng_vat.OP = (_FROM != 'ZM'),	-- stare
			@.Inf_vat.IsKorekta = NULL,
			@.Inf_vat.FROM = _FROM,
			@.Inf_vat.WORLD = _WORLD
		;
		
		
		TRUNCATE `Inf_vat`;
		INSERT INTO `Inf_vat` 
		(_FROM, _Swiat, _Params, GUID, _xxng_TableName, _xxng_vat_TableName, _xxpo_TableName, koszt_nabycia_coeff, _Clear_Fixed)
		VALUES
		(_FROM, _WORLD, _Params, _Key, _xxng_TableName, _xxng_vat_TableName, _xxpo_TableName, @.xxng_vat.koszt_nabycia.coeff := 0, _Clear_Fixed)
		;
		SET 
		@.SQLText.Inf_vat.INIT = 
		"
		UPDATE `Inf_vat` i, `#xxng#` n, `operdoc` od, `operdoc` od2
		SET
			i.Rodzaj = (@.xxng_vat.Rodzaj := n.Rodzaj), 
			i.rodzaj_typ = (@.xxng_vat.Rodzaj_typ := n.rodzaj_typ), 
			i.Calc_Ver = n.Calc_Ver,
			i.IS_Korekta = (@.Inf_vat.IsKorekta := od.IsKorekta), 
			i.IS_PodlegaVAT = od.IsPodlegaVAT OR od2.IsPodlegaVAT,
			-- i.IS_TabelkaVatEditable = od.IsTabelkaVatEditable,
			i.IS_PozycjeVisible = od.IsPozycjeVisible,
			i.IS_Kancelaria = #IS_Kancelaria#,
			i.blokada_przeliczenia_tab_vat = #blokada_przeliczenia_tab_vat#, 
			
			i.przeliczenie_B_N = n.przeliczenie_B_N, 
			i.Netto_do_Brutto = (@.xxng_vat._Netto_do_Brutto := NOT n.przeliczenie_B_N),
			i.Kurs = n.Kurs,	-- było zakomentowane
			i._Params = IFNULL(CONCAT_WS('&', NULLIF(i._Params, ''), NULLIF(n.ExtFlags, '')), '')
		WHERE
			#n.GUID#
			AND od.Rodzaj = n.Rodzaj
			AND od2.Rodzaj = IFNULL(n.rodzaj2, n.Rodzaj)
		; 		
		"
		;
		SET @.SQLText.Inf_vat.INIT = REPLACE(@.SQLText.Inf_vat.INIT, '#IS_Kancelaria#', IF(@.xxng_vat.OP, "(IFNULL(n.lp_ks_podawcza_str, '') != '')", FALSE));
		SET @.SQLText.Inf_vat.INIT = REPLACE(@.SQLText.Inf_vat.INIT, '#blokada_przeliczenia_tab_vat#', IF(@.xxng_vat.OP, "n.blokada_przeliczenia_tab_vat", FALSE));
		CALL _ExecuteCmd_xxNgPo('', _FROM, _WORLD, _IdnOper, NULL, _Param_A, _Param_B, _Param_C, _Param_D, @.SQLText.Inf_vat.INIT);
		/*
		IF _FROM = 'OP' THEN
			SET 
			@.SQLText.Inf_vat.INITxx = 
			"
			aaa; 		
			"
			;
		ELSE
			SET 
			@.SQLText.Inf_vat.INITyy = 
			"
			; 		
			"
			;
		END IF;
		*/
	END IF;
	
	IF _MODE = '`t_xxng_vat_poz`<-`xxpo`' THEN
		DROP TEMPORARY TABLE IF EXISTS `t_xxng_vat_poz_WE`;
		CREATE TEMPORARY TABLE `t_xxng_vat_poz_WE` (
		  `IdnOper` VARCHAR(38) NOT NULL DEFAULT '' COMMENT 'GUID operacji',
		  `Jest` INT(11) NOT NULL DEFAULT '1' COMMENT '0 - bylo 1 jest',
		  `IdVat` INT(11) NOT NULL DEFAULT '0' COMMENT 'ID stawki VAT',
		  `kurs` DOUBLE(16,4) NOT NULL DEFAULT '1.0000' COMMENT 'kurs',
		  `Netto` DOUBLE(16,4) NOT NULL DEFAULT '0.0000' COMMENT 'Wart. Netto',
		  `Vat` DOUBLE(16,4) NOT NULL DEFAULT '0.0000' COMMENT 'Wart. Vat',
		  `Brutto` DOUBLE(16,4) NOT NULL DEFAULT '0.0000' COMMENT 'Wart. Brutto',
		  `NettoWal` DOUBLE(16,4) NOT NULL DEFAULT '0.0000' COMMENT 'Wart. Netto w walucie',
		  `VatWal` DOUBLE(16,4) NOT NULL DEFAULT '0.0000' COMMENT 'Wart. Vat w walucie',
		  `BruttoWal` DOUBLE(16,4) NOT NULL DEFAULT '0.0000' COMMENT 'Wart. Brutto w walucie',
		  `OperCount` INT(11) NOT NULL DEFAULT '0' COMMENT 'Ile operacji',
		  `Fixed` INT(11) NOT NULL DEFAULT '0' COMMENT '0 - normalnie naliczony rekord, 1 - ustalony/skorygowany przez uzytkownika',
		  KEY `IdnOper` (`IdnOper`),
		  KEY `IdVat`(`IdVat`),
		  KEY `kurs`(`kurs`)
		)
		;
		IF @.Inf_vat.IsKorekta THEN
			CALL C_HT_xxNgPo_Corr('Tool.`#oppo_corr#`.CALC', _FROM, _WORLD, _IdnOper, '', '', '', '', '', '');
		
			SET @.SQLText.t_xxng_vat_z_poz_N.Kor.J = 
				'\n
				INSERT IGNORE INTO `t_xxng_vat_poz_WE` 
				(
					SELECT
					--	IdnOper
						#_IdnOper# AS IdnOper,			--	IdnOper
					--	Było/jest
						1 AS Jest,
					--	idnvat
						p.j_idnvat AS IdVat,		--	IdVat
					--	kurs
						p.j_kurs,
					--	Netto	
						_Rnd2(SUM(p.j_WartNet)) AS Netto,		
					--	Vat
						_Rnd2(0) AS Vat,		
					--	Brutto
						_Rnd2(SUM(p.j_WartBrt)) AS Brutto,	
					--	NettoWal
						_Rnd2(SUM(p.j_WartNetWal)) AS NettoWal,		
					--	VatWal
						_Rnd2(SUM(p.j_WartBrtWal - p.j_WartNetWal)) AS VatWal,		
					--	BruttoWal
						_Rnd2(SUM(p.j_WartBrtWal)) AS BruttoWal,
					--	OperCount
						_VarInt(Count(*))  AS OperCount,
					--	Fixed	
						0 AS Fixed	
					FROM `#oppo_corr#` p, `Inf_vat` i
					WHERE
						i.IS_Korekta
						AND i.IS_PozycjeVisible
						AND p.IdnOper_corr = #_IdnOper#
						AND p.Temporary = 0
						AND p.Fixed = 0
					GROUP BY 
						p.j_idnvat, p.j_kurs
				)
				;
			';
			CALL _ExecuteCmd_xxNgPo('', _FROM, _WORLD, _IdnOper, NULL, _Param_A, _Param_B, _Param_C, _Param_D, @.SQLText.t_xxng_vat_z_poz_N.Kor.J);
			SET @.SQLText.t_xxng_vat_z_poz_N.Kor.B = 
				'\n
				INSERT IGNORE INTO `t_xxng_vat_poz_WE`
				(
					SELECT
					--	IdnOper
						#_IdnOper# AS IdnOper,			--	IdnOper
					--	Było/jest
						0 AS Jest, 
					--	idnvat
						p.b_idnvat AS IdVat,		--	IdVat
					--	kurs
						p.b_kurs,
					--	Netto	
						_Rnd2(SUM(-p.b_WartNet)) AS Netto,		
					--	Vat
						_Rnd2(0) AS Vat,	
					--	Brutto
						_Rnd2(SUM(-p.b_WartBrt)) AS Brutto,	
					--	NettoWal
						_Rnd2(SUM(-p.b_WartNetWal)) AS NettoWal,		
					--	VatWal
						_Rnd2(SUM(-p.b_WartBrtWal + p.b_WartNetWal)) AS VatWal,		
					--	BruttoWal
						_Rnd2(SUM(-p.b_WartBrtWal)) AS BruttoWal,
					--	OperCount
						_VarInt(Count(*)) AS OperCount,
					--	Fixed	
						0 AS Fixed	
					FROM `#oppo_corr#` p, `Inf_vat` i
					WHERE
						i.IS_Korekta
						AND i.IS_PozycjeVisible
						AND p.IdnOper_corr = #_IdnOper#
						AND p.Temporary = 0
						AND p.Fixed = 0
					GROUP BY 
						p.b_idnvat, p.b_kurs
				)
				;
			';
			CALL _ExecuteCmd_xxNgPo('', _FROM, _WORLD, _IdnOper, NULL, _Param_A, _Param_B, _Param_C, _Param_D, @.SQLText.t_xxng_vat_z_poz_N.Kor.B);
		/*
		SET @.SQLText.t_xxng_vat_z_poz_N = 
			'\n
			INSERT IGNORE INTO `t_xxng_vat_poz_WE`
			(
				SELECT
					#_IdnOper# AS IdnOper,			--	IdnOper
					p.j_idnvat AS IdVat,		--	IdVat
				--	Netto	
					_Rnd2(SUM(p.j_WartNet)) AS Netto,		
				--	Vat
					_Rnd2(0) AS Vat,		
				--	Brutto
					_Rnd2(SUM(p.j_WartBrt)) AS Brutto,	
				--	NettoWal
					_Rnd2(SUM(p.j_WartNetWal)) AS NettoWal,		
				--	VatWal
					_Rnd2(SUM(p.j_WartBrtWal - p.j_WartNetWal)) AS VatWal,		
				--	BruttoWal
					_Rnd2(SUM(p.j_WartBrtWal)) AS BruttoWal,
				--	OperCount
					_VarInt(Count(*))  AS OperCount
				FROM `#oppo_corr#` p
				WHERE
					p.IdnOper_corr = #_IdnOper#
					AND p.Temporary = 0
					AND p.Fixed = 0
				GROUP BY 
					p.j_idnvat	
			)
		;
			UNION 		--	HAHA
			(
				SELECT
					_Key AS IdnOper,			--	IdnOper
					p.b_idnvat AS IdVat,		--	IdVat
				--	Netto	
					_Rnd2(SUM(-p.b_WartNet)) AS Netto,		
				--	Vat
					_Rnd2(0) AS Vat,	
				--	Brutto
					_Rnd2(SUM(-p.b_WartBrt)) AS Brutto,	
				--	NettoWal
					_Rnd2(SUM(-p.b_WartNetWal)) AS NettoWal,		
				--	VatWal
					_Rnd2(SUM(-p.b_WartBrtWal + p.b_WartNetWal)) AS VatWal,		
				--	BruttoWal
					_Rnd2(SUM(-p.b_WartBrtWal)) AS BruttoWal,
				--	OperCount
					_VarInt(Count(*)) AS OperCount
				FROM `#_xxpo_TableName_b#` p
				WHERE
					p.IdnOper_corr = _Key
					AND p.Temporary = 0
					AND p.Fixed = 0
				GROUP BY 
					p.b_idnvat	
			)
			;
		';
		*/
		-- set @_SQLText_Korekta = _SQLText_Korekta;
		END IF;
		SET @.SQLText.t_xxng_vat_z_poz_N.Poz = 
			'\n
			INSERT IGNORE INTO `t_xxng_vat_poz_WE`
				SELECT
				--	IdnOper
					#_IdnOper# AS IdnOper,			
				--	Było/jest
					1 AS Jest, 
				--	idnvat
					p.idnvat AS IdVat,		
				--	kurs
					p.kurs,
				--	Netto	// gdy włączone jest odejmowanie kosztów naby cia to @Session.vat.koszt_nabycia.coeff = 1 ?????? APRO się zastanowi
				--	UWAGA SPR i zapytaj apro po co to???? 	_Rnd2(SUM(p.WartNet) - #koszt_nabycia#) AS Netto,		
					_Rnd2(SUM(p.WartNet)) AS Netto,		
				--	Vat
					_Rnd2(SUM(p.WartVat)) AS Vat,		
				--	Brutto
					_Rnd2(SUM(p.WartBrt)) AS Brutto,		
				--	NettoWal
					_Rnd2(SUM(p.WartNetWal)) AS NettoWal,		
				--	VatWal
					_Rnd2(SUM(p.WartBrtWal - p.WartNetWal)) AS VatWal,		
				--	BruttoWal
					_Rnd2(SUM(p.WartBrtWal)) AS BruttoWal,
				--	OperCount
					_VarInt(Count(*)) AS OperCount,
				--	Fixed	
					0 AS Fixed	
				FROM `#xxpo#` p, `Inf_vat` i
				WHERE
					NOT i.IS_Korekta
					AND i.IS_PozycjeVisible
					AND (p.#IdnOper# = #_IdnOper# OR p.#IdnOperFin# = #_IdnOper#)
					AND 
					(p.Ilosc <> 0 OR p.WartVat <> 0)
				GROUP BY 
					p.idnvat, p.kurs
			;
		';
		CALL _ExecuteCmd_xxNgPo('', _FROM, _WORLD, _IdnOper, NULL, _Param_A, _Param_B, _Param_C, _Param_D, @.SQLText.t_xxng_vat_z_poz_N.Poz);
		
	--	GDY Netto -> Brutto
		UPDATE `t_xxng_vat_poz_WE` v, v_erp_vat ev, `Inf_vat` i
		SET
			v.VatWal = _Rnd2(v.NettoWal*(ev.`value`)),
			v.BruttoWal = _Rnd2(v.NettoWal + _Rnd2(v.NettoWal*(ev.`value`))),
			v.Vat = _Rnd2(v.Netto*(ev.`value`)),
			v.Brutto = _Rnd2(v.Netto+ _Rnd2(v.Netto*(ev.`value`)))
			/*
			Wariant przy edycji tabelki w walucie czyli Calc_ver > 1
			do dalszych badań kwestie zaokrągleń gdyż PLN będą inaczej liczone 
								v.Vat = _Rnd2(v.VatWal*kurs?),
								v.Netto = _Rnd2(v.NettoWal*kurs?)),
								v.Brutto = _Rnd2(v.VatWal*kurs?) + _Rnd2(v.NettoWal*kurs?))
			*/
		WHERE
			v.IdnOper = _Key
			AND i.Netto_do_Brutto	--	GDY Netto -> Brutto
			AND ev.id = v.IdVat 
		;
	--	GDY Brutto -> Netto
		UPDATE `t_xxng_vat_poz_WE` v, v_erp_vat ev, `Inf_vat` i
		SET
			v.NettoWal = _Rnd2(v.BruttoWal/(1 + ev.`value`)),
			v.VatWal = v.BruttoWal - _Rnd2(v.BruttoWal/(1 + ev.`value`)),
			v.Netto = _Rnd2(v.Brutto/(1 + ev.`value`)),
			v.Vat = v.Brutto - _Rnd2(v.Brutto/(1 + ev.`value`))
		WHERE
			v.IdnOper = _Key
			AND NOT i.Netto_do_Brutto	--	GDY Brutto -> Netto
			AND ev.id = v.IdVat 
		;
		
	--	UWAGA bywa np. dla korekt że mamy zmiany tylko w xxxWal a w xxx sa wartosci nie naliczone
	--	Dla Calc_Ver >= 3
	--	Tutaj także dwa wariany w zalezności od Netto_do_Brutto
		UPDATE `t_xxng_vat_poz_WE` v, `Inf_vat` i
		SET 
			v.Netto = (@.v.Netto := IF(i.IS_Korekta AND v.NettoWal = 0 AND v.Netto != 0, v.Netto, _Rnd2(v.NettoWal*v.Kurs))), 
			v.Vat = (@.v.Vat := IF(i.IS_Korekta AND v.NettoWal = 0 AND v.Netto != 0, v.Vat, _Rnd2(v.VatWal*v.Kurs))),
			v.Brutto = (@.v.Netto + @.v.Vat)
		WHERE 
			TRUE
			-- and v.IdnOper = _Key
			AND i.Netto_do_Brutto	--	GDY Netto -> Brutto
			AND
			i.Calc_Ver >= 3
		;
		UPDATE `t_xxng_vat_poz_WE` v, `Inf_vat` i
		SET 
			v.Brutto = (@.v.Brutto := IF(i.IS_Korekta AND v.BruttoWal = 0 AND v.Brutto != 0, v.Brutto, _Rnd2(v.BruttoWal*v.Kurs))), 
			v.Vat = (@.v.Vat := IF(i.IS_Korekta AND v.BruttoWal = 0 AND v.Brutto != 0, v.Vat, _Rnd2(v.VatWal*v.Kurs))),
			v.Netto = (@.v.Brutto - @.v.Vat)
		WHERE 
			TRUE
			-- and v.IdnOper = _Key
			AND NOT i.Netto_do_Brutto	--	GDY Brutto -> Netto
			AND
			i.Calc_Ver >= 3
		;
	
	--	Dla Calc_Ver < 3
		UPDATE `t_xxng_vat_poz_WE` v, `Inf_vat` i 
		SET 
			v.NettoWal = IF(i.IS_Korekta AND v.Netto = 0 AND v.NettoWal != 0, v.NettoWal, _Rnd2(v.Netto/v.Kurs)), 
			v.BruttoWal = IF(i.IS_Korekta AND v.Brutto = 0 AND v.BruttoWal != 0, v.BruttoWal, _Rnd2(v.Brutto/v.Kurs)), 
			v.VatWal = IF(v.Vat = 0 AND v.VatWal != 0, v.VatWal, _Rnd2(v.Brutto/v.Kurs) - _Rnd2(v.Netto/v.Kurs)) 
		WHERE 
			TRUE
			-- and v.IdnOper = _Key
			AND
			i.Calc_Ver < 3
		;
	--	gotowa quasi tabelka
		DROP TEMPORARY TABLE IF EXISTS `t_xxng_vat_poz`;
		CREATE TEMPORARY TABLE `t_xxng_vat_poz` LIKE `opng_vat`;
		INSERT  INTO `t_xxng_vat_poz` 
			(IdnOper, IdVat, Netto, Vat, Brutto, NettoWal, VatWal, BruttoWal, OperCount)
		SELECT
			v.IdnOper, 
			v.IdVat,
			SUM(Netto) AS Netto,
			SUM(Vat) AS Vat,
			SUM(Brutto) AS Brutto,
			SUM(NettoWal) AS NettoWal,
			SUM(VatWal) AS VatWal,
			-- SUM(BruttoWal) - SUM(NettoWal) AS VatWal,
			SUM(BruttoWal) AS BruttoWal,
			_VarInt(MAX(OperCount)) AS OperCount
		FROM `t_xxng_vat_poz_WE` v 
		GROUP BY IdVat
		HAVING Netto != 0 OR Vat != 0 OR NettoWal != 0 OR VatWal != 0
		;	
	END IF;

	IF _MODE = '`t_xxng_vat`<-`xxpo`' THEN
	/* ******************************************************************************************************************************
		Przygotowuje tabelke vat ze zrodlowej i `t_xxng_vat_z_poz`  pozycji wg `t_xxng_vat_INF`
		CALL C_HT_xxng_vat('`t_xxng_vat`<-`xxpo`', 'OP', 'R', @_IdnOper, '', '', '', '', '');
	*********************************************************************************************************************************/
	set @xxxx = 20;
	--	UWAGA sa dok. np. zakup pozostaly ktory nie ma pozycji ma tabelke VAT ALE BEZ FIXED !!! A poniewaz nie maja pozycji to sa potem zerowane !!! I co wtedy ??? 
	-- 	Wtedy trzeba wstawic fixed i umozliwic zachowanie tych stawek
		CALL C_HT_xxng_vat('`xxng_vat`.make.fixed.bezpozycyjne.niezerowe', _FROM, _WORLD, _IdnOper, _Param_A, _Param_B, _Param_C, _Param_D, _Param_E);
	
		DROP TEMPORARY TABLE IF EXISTS `t_xxng_vat`;
		CREATE TEMPORARY TABLE `t_xxng_vat` LIKE `opng_vat`;

		SET @.SQLText.t_xxng_vat.INS = 
			"
			INSERT IGNORE INTO `t_xxng_vat`
			SELECT
				v.* 
			FROM `#xxng_vat#` v
			WHERE
				v.IdnOper = #_IdnOper#
				AND
				v.Fixed != 0
			;			
			"
		;
		CALL _ExecuteCmd_xxNgPo('', _FROM, _WORLD, _IdnOper, NULL, _Param_A, _Param_B, _Param_C, _Param_D, @.SQLText.t_xxng_vat.INS);
		-- CALL xxng_vat_TOOLS('SQLTEXT.Execute', '', '', '', _SQLText, '', '', ''); 
		-- SET @.SQL.t_xxng_vat := @_SQLTextX1;
	
	/*
		Usun wszystkie czyli te nie fixed ORAZ fixed gdy tylko flaga _Clear_Fixed = TRUE
	*/
		DELETE v FROM `t_xxng_vat` v, `Inf_vat` i
		WHERE 
			i._Clear_Fixed -- OR v.Fixed = 0
		;
	 /*	UWAGA
		z wyjatkiem Zakupu inwestycyjnego oraz pochodzacego z kancelarii ...
		GDY jest to dok. mający pozycje i z tych pozycji wynika że nie ma jakiejs stawki która w tabelce jest jako Fixed to oznacza
		że w `t_ng_vat_calc` nie ma danej stawki i należy ją usunąć z tabelki nawet jeśli jest Fixed!!!
	 */
		DELETE v FROM `t_xxng_vat` v, `Inf_vat` i
		WHERE 
			NOT (v.IdVat IN (SELECT IdVat FROM `t_xxng_vat_poz_WE`))
			AND i.IS_PodlegaVAT 
			AND i.IS_PozycjeVisible 
			AND (i.Rodzaj != 75) 
			AND (NOT i.IS_Kancelaria)
			AND NOT(i._Params LIKE '%<VAT.FIXED>%')
		;
		
	--	Dla Calc_Ver >= 3 i Fixed = 1 ...
	--	pozostawiamy xxWal - nie zmianiamy ich - natomiast PLNowe (Netto/Vat/Brutto) naliczamy - edytowac 
	--	owszem można ale częśc walutową 
	--	ale dla Fixed = 2 niczego nie zmieniamy i całośc jest zamrożona
		UPDATE `t_xxng_vat` v, `Inf_vat` i 
		SET 
			v.Netto = IF(v.NettoWal = 0 AND v.Netto != 0, v.Netto, _Rnd2(v.NettoWal*i.Kurs)), 
			v.Brutto = IF(v.BruttoWal = 0 AND v.Brutto != 0, v.Brutto, _Rnd2(v.BruttoWal*i.Kurs)), 
			v.Vat = IF(v.BruttoWal = 0 AND v.Brutto != 0, v.Vat, _Rnd2(v.BruttoWal*i.Kurs) - _Rnd2(v.NettoWal*i.Kurs))
		WHERE 
			TRUE
			-- and v.IdnOper = _Key
			AND
			v.Fixed = 1		--	Gdy Fixed = 2 to mozemy sobie edytowac PLN też
			AND
			i.Calc_Ver >= 3
		;
	--	Dla Calc_Ver < 3
		UPDATE `t_xxng_vat` v, `Inf_vat` i 
		SET 
			v.NettoWal = IF(v.Netto = 0 AND v.NettoWal != 0, v.NettoWal, _Rnd2(v.Netto/i.Kurs)), 
			v.BruttoWal = IF(v.Brutto = 0 AND v.BruttoWal != 0, v.BruttoWal, _Rnd2(v.Brutto/i.Kurs)), 
			v.VatWal = IF(v.Vat = 0 AND v.VatWal != 0, v.VatWal, _Rnd2(v.Brutto/i.Kurs) - _Rnd2(v.Netto/i.Kurs)) 
		WHERE 
			TRUE
			-- and v.IdnOper = _Key
			AND
			v.Fixed = 1		
			AND
			i.Calc_Ver < 3
		;
	--	ale NIEZALEŻNIE jakie Fixed <> 0 czyli 1 czy 2 to ZERUJEMY!!! złotówki gdy Waluta zała zerowa!!! apro 13 VIII 2024 
		UPDATE `t_xxng_vat` v, `Inf_vat` i 
		SET 
			v.Netto = 0, v.Brutto = 0, v.Vat = 0
		WHERE 
			TRUE
			AND v.NettoWal = 0
			AND v.VatWal = 0
			AND v.BruttoWal = 0
			-- and v.IdnOper = _Key
			AND v.Fixed <> 0		--	Gdy Fixed = 1/2 
			-- AND i.Calc_Ver >= 3
		;
	END IF;
	
	IF _MODE = '`t_xxng_vat`<-`t_xxng_vat_poz`' THEN
	/* ******************************************************************************************************************************
		Wstaw do `t_xxng_vat` tabelke z pozycji `t_xxng_vat_z_poz`
		CALL C_HT_xxng_vat('`t_xxng_vat`<-`t_xxng_vat_poz`', _FROM, _WORLD, _IdnOper, _Param_A, _Param_B, _Param_C, _Param_D, _Param_E);
	*********************************************************************************************************************************/
	set @xxxx = 40;
		INSERT IGNORE INTO `t_xxng_vat` SELECT * FROM `t_xxng_vat_poz`;
	END IF;
	
	IF _MODE IN ('`xxng_vat`<-`t_xxng_vat`') THEN
	/* ******************************************************************************************************************************
		Wstaw nap do `zmng_vat_e` z `t_xxng_vat`
		CALL C_HT_xxng_vat('`xxng_vat`<-`t_xxng_vat`', _FROM, _WORLD, _IdnOper, _Param_A, _Param_B, _Param_C, _Param_D, _Param_E);
	*********************************************************************************************************************************/
	set @xxxx = 50;
    
        SET @.xxng.KSEF := (_IdnOper LIKE 'KSEF_%');
        SET @.xxng.ReadOnly := @.xxng.KSEF AND _WORLD IN ('E', 'M');
        SET @.xxng.ReadOnly := FALSE;
        IF NOT @.xxng.ReadOnly THEN
            SET @.SQLText.xxng_vat.DELETE = 
                "
                DELETE FROM `#xxng_vat#` 
                WHERE
                    IdnOper = #_IdnOper#
                ;			
                "
            ;
            CALL _ExecuteCmd_xxNgPo('', _FROM, _WORLD, _IdnOper, NULL, _Param_A, _Param_B, _Param_C, _Param_D, @.SQLText.xxng_vat.DELETE);
            SET @.SQLText.xxng_vat.INSERT = 
                "
                INSERT IGNORE INTO `#xxng_vat#`
                    SELECT * FROM `t_xxng_vat`
                ;			
                "
            ;
            CALL _ExecuteCmd_xxNgPo('', _FROM, _WORLD, _IdnOper, NULL, _Param_A, _Param_B, _Param_C, _Param_D, @.SQLText.xxng_vat.INSERT);
        END IF;

	END IF;

	IF _MODE = '`xxng`<-`xxng_vat`' THEN
	/* ******************************************************************************************************************************
		Przepisz zagregowane wartowsci tabelki VAT `xxng_vat` do naglowka `xxng`
		CALL C_HT_xxng_vat('`xxng`<-`xxng_vat`', 'OP', 'TE', @_IdnOper, '', '', '', '', '');
	*********************************************************************************************************************************/
	--	Przepisz zagregowane wartowsci tabelki VAT do naglowka
	--	`xxng` <- `xxng_vat`
	set @xxxx = 70;
		-- CALL xxng_vat_TOOLS('PREPRATE.`t_xxng_vat_INF` IF NOT EXISTS OR INVALID', _FROM, _Swiat, _Key, _Params, _Param_A, _Param_B, _Param_C); 
		DROP TEMPORARY TABLE IF EXISTS `t_xxng_vat_AGG`;
		SET
			@.SQLText.t_xxng_vat_AGG = 
		"
		CREATE TEMPORARY TABLE `t_xxng_vat_AGG` (
			SELECT 
				SUM(IF(v.work_FieldName=1,o.netto,0)) AS tabwartnetto1,
				SUM(IF(v.work_FieldName=2,o.netto,0)) AS tabwartnetto2,
				SUM(IF(v.work_FieldName=3,o.netto,0)) AS tabwartnetto3,
				SUM(IF(v.work_FieldName=4,o.netto,0)) AS tabwartnetto4,
				SUM(IF(v.work_FieldName=5,o.netto,0)) AS tabwartnetto5,
				SUM(IF(v.work_FieldName=6,o.netto,0)) AS tabwartnetto6,
				SUM(IF(v.work_FieldName=7,o.netto,0)) AS tabwartnetto7,
				SUM(IF(v.work_FieldName=8,o.netto,0)) AS tabwartnetto8,
				SUM(IF(v.work_FieldName=9,o.netto,0)) AS tabwartnetto9,
				SUM(IF(v.work_FieldName=10,o.netto,0)) AS tabwartnetto10,
				SUM(IF(v.work_FieldName=11,o.netto,0)) AS tabwartnetto11,
				SUM(IF(v.work_FieldName=12,o.netto,0)) AS tabwartnetto12,
				SUM(IF(v.work_FieldName=13,o.netto,0)) AS tabwartnetto13,
				SUM(IF(v.work_FieldName=14,o.netto,0)) AS tabwartnetto14,

				SUM(IF(v.work_FieldName=1,o.vat,0)) AS tabwartvat1,
				SUM(IF(v.work_FieldName=2,o.vat,0)) AS tabwartvat2,
				SUM(IF(v.work_FieldName=3,o.vat,0)) AS tabwartvat3,
				SUM(IF(v.work_FieldName=4,o.vat,0)) AS tabwartvat4,
				SUM(IF(v.work_FieldName=5,o.vat,0)) AS tabwartvat5,
				SUM(IF(v.work_FieldName=6,o.vat,0)) AS tabwartvat6,
				SUM(IF(v.work_FieldName=7,o.vat,0)) AS tabwartvat7,
				SUM(IF(v.work_FieldName=8,o.vat,0)) AS tabwartvat8,
				SUM(IF(v.work_FieldName=9,o.vat,0)) AS tabwartvat9,
				SUM(IF(v.work_FieldName=10,o.vat,0)) AS tabwartvat10,
				SUM(IF(v.work_FieldName=11,o.vat,0)) AS tabwartvat11,
				SUM(IF(v.work_FieldName=12,o.vat,0)) AS tabwartvat12,
				SUM(IF(v.work_FieldName=13,o.vat,0)) AS tabwartvat13,
				SUM(IF(v.work_FieldName=14,o.vat,0)) AS tabwartvat14,

				SUM(IF(v.work_FieldName=1,o.brutto,0)) AS tabwartbrutto1,
				SUM(IF(v.work_FieldName=2,o.brutto,0)) AS tabwartbrutto2,
				SUM(IF(v.work_FieldName=3,o.brutto,0)) AS tabwartbrutto3,
				SUM(IF(v.work_FieldName=4,o.brutto,0)) AS tabwartbrutto4,
				SUM(IF(v.work_FieldName=5,o.brutto,0)) AS tabwartbrutto5,
				SUM(IF(v.work_FieldName=6,o.brutto,0)) AS tabwartbrutto6,
				SUM(IF(v.work_FieldName=7,o.brutto,0)) AS tabwartbrutto7,
				SUM(IF(v.work_FieldName=8,o.brutto,0)) AS tabwartbrutto8,
				SUM(IF(v.work_FieldName=9,o.brutto,0)) AS tabwartbrutto9,
				SUM(IF(v.work_FieldName=10,o.brutto,0)) AS tabwartbrutto10,
				SUM(IF(v.work_FieldName=11,o.brutto,0)) AS tabwartbrutto11,
				SUM(IF(v.work_FieldName=12,o.brutto,0)) AS tabwartbrutto12,
				SUM(IF(v.work_FieldName=13,o.brutto,0)) AS tabwartbrutto13,
				SUM(IF(v.work_FieldName=14,o.brutto,0)) AS tabwartbrutto14,
				
				SUM(o.Netto) AS Netto, 
				SUM(o.Vat) AS Vat,  
				SUM(o.Brutto) AS Brutto,
				SUM(o.NettoWal) AS NettoWal, 
				SUM(o.VatWal) AS VatWal,  
				SUM(o.BruttoWal) AS BruttoWal

			FROM `#xxng_vat#` o
			INNER JOIN `v_erp_vat` v ON o.idvat = v.ID
			WHERE 
				o.IdnOper = #_IdnOper#
			-- GROUP BY o.idnoper
		)	
		;
		"
		;   
		CALL _ExecuteCmd_xxNgPo('', _FROM, _WORLD, _IdnOper, NULL, _Param_A, _Param_B, _Param_C, _Param_D, @.SQLText.t_xxng_vat_AGG);
		-- set @xxx = _SQLText;
		-- CALL xxng_vat_TOOLS('SQLTEXT.Execute', '', '', '', _SQLText, '', '', ''); 
		
		IF _FROM = 'OP' THEN
	--	Operacje	
			SET
				@.SQLText.xxng.UPDATE = 
			"
			UPDATE `#xxng#` n, `t_xxng_vat_AGG` tw
			SET
				n.tabwartnetto1 = IFNULL(tw.tabwartnetto1, 0),
				n.tabwartnetto2 = IFNULL(tw.tabwartnetto2, 0),
				n.tabwartnetto3 = IFNULL(tw.tabwartnetto3, 0),
				n.tabwartnetto4 = IFNULL(tw.tabwartnetto4, 0),
				n.tabwartnetto5 = IFNULL(tw.tabwartnetto5, 0),
				n.tabwartnetto6 = IFNULL(tw.tabwartnetto6, 0),
				n.tabwartnetto7 = IFNULL(tw.tabwartnetto7, 0),
				n.tabwartnetto8 = IFNULL(tw.tabwartnetto8, 0),
				n.tabwartnetto9 = IFNULL(tw.tabwartnetto9, 0),
				n.tabwartnetto10 = IFNULL(tw.tabwartnetto10, 0),
				n.tabwartnetto11 = IFNULL(tw.tabwartnetto11, 0),
				n.tabwartnetto12 = IFNULL(tw.tabwartnetto12, 0),
				n.tabwartnetto13 = IFNULL(tw.tabwartnetto13, 0),
				n.tabwartnetto14 = IFNULL(tw.tabwartnetto14, 0),
				
				n.tabwartvat1 = IFNULL(tw.tabwartvat1, 0),
				n.tabwartvat2 = IFNULL(tw.tabwartvat2, 0),
				n.tabwartvat3 = IFNULL(tw.tabwartvat3, 0),
				n.tabwartvat4 = IFNULL(tw.tabwartvat4, 0),
				n.tabwartvat7 = IFNULL(tw.tabwartvat7, 0),
				n.tabwartvat8 = IFNULL(tw.tabwartvat8, 0),
				n.tabwartvat9 = IFNULL(tw.tabwartvat9, 0),
				n.tabwartvat10 = IFNULL(tw.tabwartvat10, 0),
				n.tabwartvat11 = IFNULL(tw.tabwartvat11, 0),
				n.tabwartvat12 = IFNULL(tw.tabwartvat12, 0),
				
				n.tabwartBrutto1 = IFNULL(tw.tabwartBrutto1, 0),
				n.tabwartBrutto2 = IFNULL(tw.tabwartBrutto2, 0),
				n.tabwartBrutto3 = IFNULL(tw.tabwartBrutto3, 0),
				n.tabwartBrutto4 = IFNULL(tw.tabwartBrutto4, 0),
				n.tabwartBrutto7 = IFNULL(tw.tabwartBrutto7, 0),
				n.tabwartBrutto8 = IFNULL(tw.tabwartBrutto8, 0),
				n.tabwartBrutto9 = IFNULL(tw.tabwartBrutto9, 0),
				n.tabwartBrutto10 = IFNULL(tw.tabwartBrutto10, 0),
				n.tabwartBrutto11 = IFNULL(tw.tabwartBrutto11, 0),
				n.tabwartBrutto12 = IFNULL(tw.tabwartBrutto12, 0),
				
				n.Netto = IFNULL(tw.Netto, 0), 
				n.Vat = IFNULL(tw.Vat, 0),
				n.Brutto = IFNULL(tw.Brutto, 0),
				n.NettoWal = IFNULL(tw.NettoWal, 0), 	--	Gdy Rachunek zakup-rach uproszczony i kurs=1 a kurs_rozliczen <> 1
				-- n.VatWal = IFNULL(tw.VatWal, 0),
				n.BruttoWal = IFNULL(tw.BruttoWal, 0),
				n.ExtFlags = _ExtFlags('ADD', n.ExtFlags, CONCAT('VAT.Ver=', @session.globals.CALC.VAT.Ver), '', '')
			WHERE 
				n.GUID = #_IdnOper#
			;
			";
		ELSE
	--	Zamowienia
			SET
				@.SQLText.xxng.UPDATE = 
			"
			UPDATE `#xxng#` n, `t_xxng_vat_AGG` tw
			SET
				n.Netto = IFNULL(tw.Netto, 0), 
				--	n.Vat = IFNULL(tw.Vat, 0),
				n.Brutto = IFNULL(tw.Brutto, 0),
				n.NettoWal = IFNULL(tw.NettoWal, 0), 	
				n.BruttoWal = IFNULL(tw.BruttoWal, 0),
				n.ExtFlags = _ExtFlags('ADD', n.ExtFlags, CONCAT('VAT.Ver=', @session.globals.CALC.VAT.Ver), '', '')
			WHERE 
				n.GUID = #_IdnOper#
			;
			";
		END IF;
		CALL _ExecuteCmd_xxNgPo('', _FROM, _WORLD, _IdnOper, NULL, _Param_A, _Param_B, _Param_C, _Param_D, @.SQLText.xxng.UPDATE);
		-- CALL xxng_vat_TOOLS('SQLTEXT.Execute', '', '', '', _SQLText, '', '', ''); 
		-- SET @.t_xxng_vat_AGG.SQLText = @_SQLText;
		-- DROP TEMPORARY TABLE IF EXISTS `t_xxng_vat_AGG`;
	END IF;
	
	IF _MODE LIKE '`xxng_vat`.%' THEN
	/* ******************************************************************************************************************************
		np. wstaw brakujace stawki lub
		usun zerowe
	*********************************************************************************************************************************/
	set @xxxx = 80;
		-- CALL xxng_vat_TOOLS('PREPRATE.`t_xxng_vat_INF` IF NOT EXISTS OR INVALID', _FROM, _Swiat, _Key, _Params, _Param_A, _Param_B, _Param_C); 
		
		IF _MODE = '`xxng_vat`.fill.brakujace.stawki' THEN
		--	WSTAWIANIE Brakujących
			SET @.SQLText.xxng_vat.INSERT.Braki = 
				"
				INSERT IGNORE INTO `#xxng_vat#`
				(IdnOper, IdVat)
					SELECT 
						#_IdnOper# AS IdnOper, 
						ev.ID AS IdVat
					FROM `erp_vat` ev 
					WHERE 
						ev.visible 
						AND NOT ev.not_used
				;			
				"
			;
			CALL _ExecuteCmd_xxNgPo('', _FROM, _WORLD, _IdnOper, NULL, _Param_A, _Param_B, _Param_C, _Param_D, @.SQLText.xxng_vat.INSERT.Braki);
		END IF;
		
		IF _MODE = '`xxng_vat`.delete.zerowe' THEN
		--	USUWANIE zerowych
			SET @.SQLText.xxng_vat.DELETE.Zerowe = 
				"
				DELETE FROM `#xxng_vat#` 
				WHERE
					IdnOper = #_IdnOper#
					AND (Netto = 0) AND (Brutto = 0) AND (Vat = 0) 
					AND (NettoWal = 0) AND (BruttoWal = 0) AND (VatWal = 0) 
					AND (Fixed = 0)
				;			
				"
			;
			CALL _ExecuteCmd_xxNgPo('', _FROM, _WORLD, _IdnOper, NULL, _Param_A, _Param_B, _Param_C, _Param_D, @.SQLText.xxng_vat.DELETE.Zerowe);
		END IF;
		
		IF _MODE = '`xxng_vat`.make.fixed.bezpozycyjne.niezerowe' THEN
		--	UWAGA są takie dok. np. zakup pozostaly ktory nie ma pozycji ale ma tabelke VAT często jednak BEZ FIXED !!! 
		--	A poniewaz nie mają pozycji to są potem zerowane !!! I co wtedy ??? 
		-- 	Wtedy trzeba wstawic fixed i umozliwic zachowanie tych stawek
			/*
			było
			SET @.SQLText.xxng_vat.UPDATE.Fixed = 
				"
				UPDATE `#xxng_vat#` v, `Inf_vat` i
				SET
					v.Fixed = GREATEST(v.Fixed, 1)
				WHERE 
					v.IdnOper = #_IdnOper#
					AND 
					NOT i.IS_PozycjeVisible 	-- dla tych bezpozycyjnych
					AND i.IS_PodlegaVAT 		-- z tabelka VAT
				-- 	AND i.IS_TabelkaVatEditable -- z edytowalną tabelka VAT
					AND 
					(v.Netto != 0 OR v.Brutto != 0 OR v.NettoWal != 0 OR v.BruttoWal != 0) 	-- z niezerowymi wpisami
				;			
				"
			;
			*/
			SET @.SQLText.xxng_vat.UPDATE.Fixed = 
			"
					UPDATE `#xxng_vat#` v, `#xxng#` n, `operdoc` od, `operdoc` od2, v_erp_vat ev
					SET
						v.Fixed = GREATEST(v.Fixed, 1),
						v.BruttoWal = 
							IF(v.BruttoWal = 0 AND v.NettoWal > 0,
								_Rnd2(v.NettoWal + _Rnd2(v.NettoWal*(ev.`value`))),
								v.BruttoWal
							)
					WHERE 
						#n.GUID#
						AND v.IdnOper = n.GUID -- = '{69330BA5-BB06-464A-9BF7-49B8CAFAE1CD}'
						AND od.Rodzaj = n.Rodzaj
						AND od2.Rodzaj = IFNULL(n.rodzaj2, n.Rodzaj)
						AND od.IsPozycjeVisible = 0 								-- dla tych bezpozycyjnych
						AND GREATEST(od.IsPodlegaVAT, od2.IsPodlegaVAT) > 0 		-- z tabelka VAT
						AND od.ISTabelkaVatEditable = 1 							-- z edytowalną tabelka VAT
						AND 
						(
						v.Netto != 0 OR v.Brutto != 0 OR v.NettoWal != 0 OR v.BruttoWal != 0
						) 	-- z niezerowymi wpisami
						AND ev.id = v.IdVat 
					;			
			"
			;	
			CALL _ExecuteCmd_xxNgPo('', _FROM, _WORLD, _IdnOper, NULL, _Param_A, _Param_B, _Param_C, _Param_D, @.SQLText.xxng_vat.UPDATE.Fixed);
		END IF;
	END IF;
		
	IF 
	_MODE LIKE 'Oper.Nalicz.Tabelke%' 
	OR
	_MODE LIKE 'Oper.Nalicz.`xxng_vat`%'
	THEN
set @.debug = concat_WS(' / ', @.debug, _MODE);
	/* ******************************************************************************************************************************
		np. wstaw brakujace stawki lub
		usun zerowe
		CALL C_HT_xxng_vat('Oper.Nalicz.`xxng_vat`', 'OP', 'TE', @_IdnOper, '', '', '', '', '');
		CALL C_HT_xxng_vat('Oper.Nalicz.`xxng_vat`+`xxng`', 'OP', 'TE', @_IdnOper, '', '', '', '', '');
		CALL C_HT_xxng_vat('Oper.Nalicz.`xxng_vat`+`xxng`+prepare.do.Edycji', 'OP', 'TE', @_IdnOper, '', '', '', '', '');
		CALL C_HT_xxng_vat('Oper.Nalicz.Tabelke', 'OP', 'TE', @_IdnOper, '', '', '', '', '');
		CALL C_HT_xxng_vat('Oper.Nalicz.Tabelke+`xxng`', 'OP', 'TE', @_IdnOper, '', '', '', '', '');
	*********************************************************************************************************************************/
	--	IF _MODE LIKE 'Oper.Nalicz.Tabelke' THEN
		CALL C_HT_xxng_vat('`Inf_vat`.Create', _FROM, _WORLD, _IdnOper, _Param_A, _Param_B, _Param_C, _Param_D, _Param_E);
		CALL C_HT_xxng_vat('`Inf_vat`<-`xxNg`', _FROM, _WORLD, _IdnOper, _Param_A, _Param_B, _Param_C, _Param_D, _Param_E);
		CALL C_HT_xxng_vat('`t_xxng_vat_poz`<-`xxpo`', _FROM, _WORLD, _IdnOper, _Param_A, _Param_B, _Param_C, _Param_D, _Param_E);
		CALL C_HT_xxng_vat('`t_xxng_vat`<-`xxpo`', _FROM, _WORLD, _IdnOper, _Param_A, _Param_B, _Param_C, _Param_D, _Param_E);
		CALL C_HT_xxng_vat('`t_xxng_vat`<-`t_xxng_vat_poz`', _FROM, _WORLD, _IdnOper, _Param_A, _Param_B, _Param_C, _Param_D, _Param_E);
		CALL C_HT_xxng_vat('`xxng_vat`<-`t_xxng_vat`', _FROM, _WORLD, _IdnOper, _Param_A, _Param_B, _Param_C, _Param_D, _Param_E);
		IF _MODE LIKE 'Oper.Nalicz.%+`xxng`%' THEN
			CALL C_HT_xxng_vat('`xxng`<-`xxng_vat`', _FROM, _WORLD, _IdnOper, _Param_A, _Param_B, _Param_C, _Param_D, _Param_E);
		END IF;
		IF _MODE LIKE 'Oper.Nalicz.%+prepare.do.Edycji%' AND (_WORLD IN ('E', 'M')) THEN
			CALL C_HT_xxng_vat('`xxng_vat`.fill.brakujace.stawki', _FROM, _WORLD, _IdnOper, '', '', '', '', _Param_E);
		END IF;
	END IF;
	
END$$

DELIMITER ;

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

/*
$Log: C_HT_xxng_vat.sql,v $
Revision 1.11  2026/03/03 10:21:56  jmam
KSEF - blokada ale ost. nie jest wykorzyst.

Revision 1.10  2025/02/26 11:10:29  jmam
$send$ Kosmetyka

Revision 1.9  2024/09/02 10:41:47  jmam
$SEND$ koment. + NIEZALEZNIE jakie Fixed <> 0 czyli 1 czy 2 to ZERUJEMY!!! zlotowki gdy Waluta cala zerowa!!! apro 13 VIII 2024

Revision 1.8  2024/09/02 10:37:34  jmam
$SEND$ Aliasy, zgranie popr. : NIEZALEZNIE jakie Fixed <> 0 czyli 1 czy 2 to ZERUJEMY!!! zlotowki gdy Waluta cala zerowa!!! apro 13 VIII 2024

*/
