 ALTER TABLE `pl_kp_Y`   
  CHANGE `EtatM` `EtatM` INT(11) DEFAULT 0 NOT NULL COMMENT 'etat M',
  ADD COLUMN `NCP` DOUBLE(16,2) DEFAULT 480 NOT NULL COMMENT 'NCP po przeliczeniu etatów L/M' AFTER `EtatM`
;
ALTER TABLE `pl_kp`   
  ADD COLUMN `EtatL` INT(11) DEFAULT 1 NOT NULL COMMENT 'etat L' AFTER `Y2`,
  ADD COLUMN `EtatM` INT(11) DEFAULT 1 NOT NULL COMMENT 'etat M' AFTER `EtatL`
;
UPDATE `pl_kp` 
SET 
	EtatL = 
	IF(Symbol = '3/4 etatu', 3, 
	IF(Symbol LIKE '%1/%', 1, 
	1)),
	EtatM = 
	IF(Symbol IN ('3/4 etatu', '1/4 etatu', '1/4 etat'), 4,
	IF(Symbol IN ('1/10 etatu'), 10,
	IF(Symbol IN ('1/2 etatu'), 2,
	IF(Symbol IN ('1/8 etatu'), 8,
	IF(Symbol LIKE '%/4%', 4,
	IF(Symbol LIKE '%/10%', 10,
	IF(Symbol LIKE '%/8%', 8,
	EtatM
	)))))))
;
UPDATE `pl_kp_Y` kpY, `pl_kp` kp 
SET 
	kpY.EtatL = kp.EtatL,
	kpY.EtatM = kp.EtatM,
	kpY.NCP = 480*kp.EtatL/kp.EtatM
WHERE
	kpY.Symbol = kp.Symbol
	AND kpY.Y >= 2024
;
UPDATE `pl_kp_YD` kpYD, `pl_kp_Y` kpY
SET 
	kpYD.MavgNCP = kpY.NCP, 
	kpYD.UpdateStatus = '(CALC.KP)'
WHERE
	kpYD.Symbol = kpY.Symbol
	AND kpYD.Y = kpY.Y
	AND kpY.Y >= 2024
;
