Subject | Firebird 1.5 RC7 Procedure |
---|---|
Author | cpis20022002 |
Post date | 2003-11-20T09:23:49Z |
here is my procedure
CREATE PROCEDURE SP_REPLANEAR_OF
AS
DECLARE VARIABLE idplano INTEGER;
DECLARE VARIABLE idplanoaux INTEGER;
DECLARE VARIABLE idplanoaux1 INTEGER;
DECLARE VARIABLE idenc INTEGER;
DECLARE VARIABLE nreg INTEGER;
DECLARE VARIABLE idgrupo INTEGER;
DECLARE VARIABLE codmaq VARCHAR(6);
DECLARE VARIABLE ordem INTEGER;
DECLARE VARIABLE inicioprev TIMESTAMP;
DECLARE VARIABLE qtd NUMERIC (18,2);
DECLARE VARIABLE comprimento NUMERIC (18,2);
DECLARE VARIABLE tempoprev INTEGER;
DECLARE VARIABLE fimprev TIMESTAMP;
DECLARE VARIABLE taxasalarialprev NUMERIC (18,4);
DECLARE VARIABLE taxamaquinaprev NUMERIC (18,4);
DECLARE VARIABLE taxageralprev NUMERIC (18,4);
DECLARE VARIABLE taxasalarial NUMERIC (18,4);
DECLARE VARIABLE taxamaquina NUMERIC (18,4);
DECLARE VARIABLE taxageral NUMERIC (18,4);
DECLARE VARIABLE tempo INTEGER;
DECLARE VARIABLE funcao SMALLINT;
DECLARE VARIABLE codtipmal VARCHAR(10);
DECLARE VARIABLE codcor VARCHAR(10);
DECLARE VARIABLE ordemplano INTEGER;
DECLARE VARIABLE idencl INTEGER;
DECLARE VARIABLE razban NUMERIC(18,2);
DECLARE VARIABLE kgmin NUMERIC(18,2);
DECLARE VARIABLE kgmax NUMERIC(18,2);
DECLARE VARIABLE razbanmin NUMERIC(18,2);
DECLARE VARIABLE volume INTEGER;
BEGIN
DELETE FROM ordensfabricoplanoaux;
/* coloca os registos numa tabela auxiliar */
INSERT INTO ordensfabricoplanoaux
(ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,TAXAGER
ALPREV,
TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,CODTIPMAL,CODCOMP,CODCL
I,
CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,ORDEMPLANO,JAINICIOU,COMPRIMENTO
,
TEMPOOPE,TINGIMENTO)
SELECT ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,TAXAGER
ALPREV,
TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,CODTIPMAL,CODCOMP,CODCL
I,
CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,ORDEMPLANO,JAINICIOU,COMPRIMENTO
,
TEMPOOPE,TINGIMENTO FROM ordensfabricoplano WHERE jainiciou=0 ;
DELETE FROM ordensfabricoplano WHERE jainiciou=0;
/* preparação mecânica */
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo=0
ORDER BY ordemplano
INTO :idplano;
/* conta o nº de registos de preparação mecânica */
SELECT COUNT(*) FROM ordensfabricoplanoaux
WHERE tipo=0 INTO nreg;
WHILE (nreg > 0) DO
BEGIN
SELECT idenc,ordem FROM ordensfabricoplanoaux
WHERE id=:idplano
INTO :idenc, :ordem;
/* verifica se existe uma operação da mesma OF por planear */
idplanoaux = null;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo=0 AND idenc=:idenc AND ordem < :ordem AND
id<>:idplano
ORDER BY ordemplano
INTO :idplanoaux;
IF (:idplanoaux IS NOT NULL) THEN
BEGIN
idplano = :idplanoaux;
/* selecciona a máquina */
SELECT codmaq, ordemplano FROM ordensfabricoplanoaux
WHERE id=:idplano
INTO :codmaq, :ordemplano;
/* verifica se a máquina tem outra operação antes */
idplanoaux1 = null;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo = 0 AND codmaq = :codmaq AND ordemplano
< :ordemplano
AND id<>:idplano
ORDER BY ordemplano
INTO :idplanoaux1;
IF (:idplanoaux1 IS NULL) THEN
BEGIN
-- idplano = :idplanoaux;
SELECT idencl, ordem, qtd, comprimento, tempoope,
codtipmal FROM ordensfabricoplanoaux
WHERE id = :idplano
INTO :idencl, :ordem, :qtd, :comprimento, :tempo, :codtipmal;
SELECT inicioprev, fimprev, tempoprev FROM
sp_selmaq_pre_replan(:idencl,:ordem,
:codmaq, :qtd, :comprimento, :tempo, :codtipmal)
INTO :inicioprev, :fimprev, :tempoprev;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial,
centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao FROM
maquinas
INNER JOIN centrostrabalho ON (maquinas.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON
(centrostrabalho.codcencus = centroscusto.codcencus)
WHERE maquinas.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
IF (:funcao = 1) THEN /* função tempo (hora) */
BEGIN
taxasalarialprev = :taxasalarial*:tempoprev/60.00;
taxamaquinaprev = :taxamaquina*:tempoprev/60.00;
taxageralprev = :taxageral*:tempoprev/60.00;
END
ELSE IF (:funcao = 2) THEN /* fixo */
BEGIN
taxasalarialprev = :taxasalarial;
taxamaquinaprev = :taxamaquina;
taxageralprev = :taxageral;
END
ELSE IF (:funcao = 3) THEN /* Peso */
BEGIN
taxasalarialprev = :taxasalarial*:qtd;
taxamaquinaprev = :taxamaquina*:qtd;
taxageralprev = :taxageral*:qtd;
END
ELSE IF (:funcao = 4) THEN /* Comprimento */
BEGIN
taxasalarialprev = :taxasalarial*:comprimento;
taxamaquinaprev = :taxamaquina*:comprimento;
taxageralprev = :taxageral*:comprimento;
END
/* insere registos no planeamento */
INSERT INTO ordensfabricoplano
(ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO)
SELECT ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO
FROM ordensfabricoplanoaux
WHERE id = :idplano;
UPDATE ordensfabricoplano
SET inicioprev=:inicioprev,
fimprev=:fimprev,tempoprev=:tempoprev,
codmaq=:codmaq,
taxasalarialprev=:taxasalarialprev,
taxamaquinaprev=:taxamaquinaprev,
datof=current_date,
taxageralprev=:taxageralprev, ordemplano=NULL
WHERE id = :idplano;
DELETE FROM ordensfabricoplanoaux WHERE id = :idplano;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo=0
ORDER BY ordemplano
INTO :idplano;
END
END
ELSE
BEGIN
SELECT idencl, ordem, qtd, comprimento, tempoope,
codtipmal,codmaq FROM ordensfabricoplanoaux
WHERE id = :idplano
INTO :idencl, :ordem, :qtd, :comprimento, :tempo, :codtipmal,:codmaq;
SELECT inicioprev, fimprev, tempoprev FROM
sp_selmaq_pre_replan(:idencl,:ordem,
:codmaq, :qtd, :comprimento, :tempo, :codtipmal)
INTO :inicioprev, :fimprev, :tempoprev;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial, centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao FROM maquinas
INNER JOIN centrostrabalho ON (maquinas.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON (centrostrabalho.codcencus =
centroscusto.codcencus)
WHERE maquinas.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
IF (:funcao = 1) THEN /* função tempo (hora) */
BEGIN
taxasalarialprev = :taxasalarial*:tempoprev/60.00;
taxamaquinaprev = :taxamaquina*:tempoprev/60.00;
taxageralprev = :taxageral*:tempoprev/60.00;
END
ELSE IF (:funcao = 2) THEN /* fixo */
BEGIN
taxasalarialprev = :taxasalarial;
taxamaquinaprev = :taxamaquina;
taxageralprev = :taxageral;
END
ELSE IF (:funcao = 3) THEN /* Peso */
BEGIN
taxasalarialprev = :taxasalarial*:qtd;
taxamaquinaprev = :taxamaquina*:qtd;
taxageralprev = :taxageral*:qtd;
END
ELSE IF (:funcao = 4) THEN /* Comprimento */
BEGIN
taxasalarialprev = :taxasalarial*:comprimento;
taxamaquinaprev = :taxamaquina*:comprimento;
taxageralprev = :taxageral*:comprimento;
END
/* insere registos no planeamento */
INSERT INTO ordensfabricoplano
(ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO)
SELECT ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO
FROM ordensfabricoplanoaux
WHERE id = :idplano;
UPDATE ordensfabricoplano
SET inicioprev=:inicioprev,
fimprev=:fimprev,tempoprev=:tempoprev,
codmaq=:codmaq, taxasalarialprev=:taxasalarialprev,
taxamaquinaprev=:taxamaquinaprev, datof =
current_date,
taxageralprev=:taxageralprev, ordemplano=NULL
WHERE id = :idplano;
DELETE FROM ordensfabricoplanoaux WHERE id = :idplano;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo=0
ORDER BY ordemplano
INTO :idplano;
END
SELECT COUNT(*) FROM ordensfabricoplanoaux WHERE tipo=0 INTO
nreg;
END
/* tingimento tipo = 1*/
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =1
ORDER BY ordemplano
INTO :idplano;
/* conta o nº de registos de tingimento */
SELECT COUNT(*) FROM ordensfabricoplanoaux
WHERE tipo =1 INTO nreg;
WHILE (nreg > 0) DO
BEGIN
SELECT idenc,ordem FROM ordensfabricoplanoaux
WHERE id=:idplano
INTO :idenc, :ordem;
/* verifica se existe uma operação da mesma OF por planear */
idplanoaux = null;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =1 AND idenc=:idenc AND ordem < :ordem AND
id<>:idplano
ORDER BY ordemplano
INTO :idplanoaux;
IF (:idplanoaux IS NOT NULL) THEN
BEGIN
idplano = :idplanoaux;
/* selecciona a máquina */
SELECT codmaq, ordemplano FROM ordensfabricoplanoaux
WHERE id=:idplano
INTO :codmaq, :ordemplano;
/* verifica se a máquina tem outra operação antes */
idplanoaux1 = null;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =1 AND codmaq = :codmaq AND ordemplano
< :ordemplano
AND id<>:idplano
ORDER BY ordemplano
INTO :idplanoaux1;
IF (:idplanoaux1 IS NULL) THEN
BEGIN
-- idplano = :idplanoaux;
SELECT idencl, ordem, qtd, comprimento, tempoope,
codtipmal, idgrupo, codcor
FROM ordensfabricoplanoaux
WHERE id = :idplano
INTO :idencl, :ordem, :qtd, :comprimento, :tempo, :codtipmal, :idgrup
o,
:codcor;
/* determina a capacidade da máquina */
SELECT maquinastin.kgmin, maquinastin.kgmax FROM
maquinastin
WHERE maquinastin.codmaq=:codmaq
INTO :kgmin, :kgmax;
IF (:qtd < :kgmin ) THEN
EXCEPTION maquinatin 'Máquina com capacidade minima
superior à qtd. da encomenda.';
IF (:qtd > :kgmax ) THEN
EXCEPTION maquinatin 'Máquina com capacidade máxima
inferior à qtd. da encomenda.';
/* determina o razao de banho minima */
SELECT processosting.razbanmin
FROM cores
INNER JOIN processosting ON (cores.codprotin =
processosting.codprotin)
WHERE cores.codcor = :codcor
INTO :razbanmin;
SELECT inicioprev, fimprev, volumeh2o, razban FROM
sp_selmaq_tin_replan(:idenc,:codmaq,
:qtd, :tempo, :razbanmin,:idgrupo)
INTO :inicioprev, :fimprev, :volume, :razban;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial,
centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao FROM
maquinas
INNER JOIN centrostrabalho ON (maquinas.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON
(centrostrabalho.codcencus = centroscusto.codcencus)
WHERE maquinas.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial,
centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao
FROM maquinastin
INNER JOIN centrostrabalho ON (maquinastin.codcentra
= centrostrabalho.codcentra)
INNER JOIN centroscusto ON
(centrostrabalho.codcencus = centroscusto.codcencus)
WHERE maquinastin.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
IF (:funcao = 1) THEN /* função tempo (hora) */
BEGIN
taxasalarialprev = :taxasalarial*:tempoprev/60.00;
taxamaquinaprev = :taxamaquina*:tempoprev/60.00;
taxageralprev = :taxageral*:tempoprev/60.00;
END
ELSE IF (:funcao = 2) THEN /* fixo */
BEGIN
taxasalarialprev = :taxasalarial;
taxamaquinaprev = :taxamaquina;
taxageralprev = :taxageral;
END
ELSE IF (:funcao = 3) THEN /* Peso */
BEGIN
taxasalarialprev = :taxasalarial*:qtd;
taxamaquinaprev = :taxamaquina*:qtd;
taxageralprev = :taxageral*:qtd;
END
ELSE IF (:funcao = 4) THEN /* Comprimento */
BEGIN
taxasalarialprev = :taxasalarial*:comprimento;
taxamaquinaprev = :taxamaquina*:comprimento;
taxageralprev = :taxageral*:comprimento;
END
/* insere registos no planeamento */
INSERT INTO ordensfabricoplano
(ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO)
SELECT ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO
FROM ordensfabricoplanoaux
WHERE id = :idplano;
UPDATE ordensfabricoplano
SET inicioprev=:inicioprev,
fimprev=:fimprev,tempoprev=:tempoprev,
codmaq=:codmaq,
taxasalarialprev=:taxasalarialprev,
taxamaquinaprev=:taxamaquinaprev,
volume=:volume,razban=:razban,
taxageralprev=:taxageralprev,
datof=current_date, ordemplano=NULL
WHERE id = :idplano;
DELETE FROM ordensfabricoplanoaux WHERE id = :idplano;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =1
ORDER BY ordemplano
INTO :idplano;
END
END
ELSE
BEGIN
SELECT idencl, ordem, qtd, comprimento, tempoope, codtipmal,
idgrupo, codcor, codmaq
FROM ordensfabricoplanoaux
WHERE id = :idplano
INTO :idencl, :ordem, :qtd, :comprimento, :tempo, :codtipmal, :idgrup
o, :codcor, :codmaq;
/* determina a capacidade da máquina */
SELECT maquinastin.kgmin, maquinastin.kgmax FROM maquinastin
WHERE maquinastin.codmaq=:codmaq
INTO :kgmin, :kgmax;
IF (:qtd < :kgmin ) THEN
EXCEPTION maquinatin 'Máquina com capacidade minima
superior à qtd. da encomenda.';
IF (:qtd > :kgmax ) THEN
EXCEPTION maquinatin 'Máquina com capacidade máxima
inferior à qtd. da encomenda.';
/* determina o razao de banho minima */
SELECT processosting.razbanmin FROM cores
INNER JOIN processosting ON (cores.codprotin =
processosting.codprotin)
WHERE cores.codcor = :codcor
INTO :razbanmin;
SELECT inicioprev, fimprev, volumeh2o, razban
FROM sp_selmaq_tin_replan
(:idenc,:codmaq, :qtd, :tempo, :razbanmin,:idgrupo)
INTO :inicioprev, :fimprev, :volume, :razban;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial, centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao FROM maquinas
INNER JOIN centrostrabalho ON (maquinas.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON (centrostrabalho.codcencus =
centroscusto.codcencus)
WHERE maquinas.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial, centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao
FROM maquinastin
INNER JOIN centrostrabalho ON (maquinastin.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON (centrostrabalho.codcencus =
centroscusto.codcencus)
WHERE maquinastin.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
IF (:funcao = 1) THEN /* função tempo (hora) */
BEGIN
taxasalarialprev = :taxasalarial*:tempoprev/60.00;
taxamaquinaprev = :taxamaquina*:tempoprev/60.00;
taxageralprev = :taxageral*:tempoprev/60.00;
END
ELSE IF (:funcao = 2) THEN /* fixo */
BEGIN
taxasalarialprev = :taxasalarial;
taxamaquinaprev = :taxamaquina;
taxageralprev = :taxageral;
END
ELSE IF (:funcao = 3) THEN /* Peso */
BEGIN
taxasalarialprev = :taxasalarial*:qtd;
taxamaquinaprev = :taxamaquina*:qtd;
taxageralprev = :taxageral*:qtd;
END
ELSE IF (:funcao = 4) THEN /* Comprimento */
BEGIN
taxasalarialprev = :taxasalarial*:comprimento;
taxamaquinaprev = :taxamaquina*:comprimento;
taxageralprev = :taxageral*:comprimento;
END
/* insere registos no planeamento */
INSERT INTO ordensfabricoplano
(ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO)
SELECT ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO
FROM ordensfabricoplanoaux
WHERE id = :idplano;
UPDATE ordensfabricoplano
SET inicioprev=:inicioprev,
fimprev=:fimprev,tempoprev=:tempoprev,
codmaq=:codmaq, taxasalarialprev=:taxasalarialprev,
taxamaquinaprev=:taxamaquinaprev,
volume=:volume,razban=:razban,
taxageralprev=:taxageralprev, datof=current_date,
ordemplano=NULL
WHERE id = :idplano;
DELETE FROM ordensfabricoplanoaux WHERE id = :idplano;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =1
ORDER BY ordemplano
INTO :idplano;
END
SELECT COUNT(*) FROM ordensfabricoplanoaux WHERE tipo =1 INTO
nreg;
END
/* tingimento tipo = 2*/
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =2
ORDER BY ordemplano
INTO :idplano;
/* conta o nº de registos de tingimento */
SELECT COUNT(*) FROM ordensfabricoplanoaux
WHERE tipo =2 INTO nreg;
WHILE (nreg > 0) DO
BEGIN
SELECT idenc,ordem FROM ordensfabricoplanoaux
WHERE id=:idplano
INTO :idenc, :ordem;
/* verifica se existe uma operação da mesma OF por planear */
idplanoaux = null;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =2 AND idenc=:idenc AND ordem < :ordem AND
id<>:idplano
ORDER BY ordemplano
INTO :idplanoaux;
IF (:idplanoaux IS NOT NULL) THEN
BEGIN
idplano = :idplanoaux;
/* selecciona a máquina */
SELECT codmaq, ordemplano FROM ordensfabricoplanoaux
WHERE id=:idplano
INTO :codmaq, :ordemplano;
/* verifica se a máquina tem outra operação antes */
idplanoaux1 = null;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =2 AND codmaq = :codmaq AND ordemplano
< :ordemplano
AND id<>:idplano
ORDER BY ordemplano
INTO :idplanoaux1;
IF (:idplanoaux1 IS NULL) THEN
BEGIN
-- idplano = :idplanoaux;
SELECT idencl, ordem, qtd, comprimento, tempoope,
codtipmal, idgrupo, codcor
FROM ordensfabricoplanoaux
WHERE id = :idplano
INTO :idencl, :ordem, :qtd, :comprimento, :tempo, :codtipmal, :idgrup
o,
:codcor;
/* determina a capacidade da máquina */
SELECT maquinastin.kgmin, maquinastin.kgmax FROM
maquinastin
WHERE maquinastin.codmaq=:codmaq
INTO :kgmin, :kgmax;
IF (:qtd < :kgmin ) THEN
EXCEPTION maquinatin 'Máquina com capacidade minima
superior à qtd. da encomenda.';
IF (:qtd > :kgmax ) THEN
EXCEPTION maquinatin 'Máquina com capacidade máxima
inferior à qtd. da encomenda.';
/* determina o razao de banho minima */
SELECT processosting.razbanmin
FROM cores
INNER JOIN processosting ON (cores.codprotin =
processosting.codprotin)
WHERE cores.codcor = :codcor
INTO :razbanmin;
SELECT inicioprev, fimprev, volumeh2o, razban FROM
sp_selmaq_tin_replan(:idenc,:codmaq,
:qtd, :tempo, :razbanmin,:idgrupo)
INTO :inicioprev, :fimprev, :volume, :razban;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial,
centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao FROM
maquinas
INNER JOIN centrostrabalho ON (maquinas.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON
(centrostrabalho.codcencus = centroscusto.codcencus)
WHERE maquinas.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial,
centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao
FROM maquinastin
INNER JOIN centrostrabalho ON (maquinastin.codcentra
= centrostrabalho.codcentra)
INNER JOIN centroscusto ON
(centrostrabalho.codcencus = centroscusto.codcencus)
WHERE maquinastin.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
IF (:funcao = 1) THEN /* função tempo (hora) */
BEGIN
taxasalarialprev = :taxasalarial*:tempoprev/60.00;
taxamaquinaprev = :taxamaquina*:tempoprev/60.00;
taxageralprev = :taxageral*:tempoprev/60.00;
END
ELSE IF (:funcao = 2) THEN /* fixo */
BEGIN
taxasalarialprev = :taxasalarial;
taxamaquinaprev = :taxamaquina;
taxageralprev = :taxageral;
END
ELSE IF (:funcao = 3) THEN /* Peso */
BEGIN
taxasalarialprev = :taxasalarial*:qtd;
taxamaquinaprev = :taxamaquina*:qtd;
taxageralprev = :taxageral*:qtd;
END
ELSE IF (:funcao = 4) THEN /* Comprimento */
BEGIN
taxasalarialprev = :taxasalarial*:comprimento;
taxamaquinaprev = :taxamaquina*:comprimento;
taxageralprev = :taxageral*:comprimento;
END
/* insere registos no planeamento */
INSERT INTO ordensfabricoplano
(ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO)
SELECT ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO
FROM ordensfabricoplanoaux
WHERE id = :idplano;
UPDATE ordensfabricoplano
SET inicioprev=:inicioprev,
fimprev=:fimprev,tempoprev=:tempoprev,
codmaq=:codmaq,
taxasalarialprev=:taxasalarialprev,
taxamaquinaprev=:taxamaquinaprev,
volume=:volume,razban=:razban,
taxageralprev=:taxageralprev,
datof=current_date, ordemplano=NULL
WHERE id = :idplano;
DELETE FROM ordensfabricoplanoaux WHERE id = :idplano;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =2
ORDER BY ordemplano
INTO :idplano;
END
END
ELSE
BEGIN
SELECT idencl, ordem, qtd, comprimento, tempoope, codtipmal,
idgrupo, codcor, codmaq
FROM ordensfabricoplanoaux
WHERE id = :idplano
INTO :idencl, :ordem, :qtd, :comprimento, :tempo, :codtipmal, :idgrup
o, :codcor, :codmaq;
/* determina a capacidade da máquina */
SELECT maquinastin.kgmin, maquinastin.kgmax FROM maquinastin
WHERE maquinastin.codmaq=:codmaq
INTO :kgmin, :kgmax;
IF (:qtd < :kgmin ) THEN
EXCEPTION maquinatin 'Máquina com capacidade minima
superior à qtd. da encomenda.';
IF (:qtd > :kgmax ) THEN
EXCEPTION maquinatin 'Máquina com capacidade máxima
inferior à qtd. da encomenda.';
/* determina o razao de banho minima */
SELECT processosting.razbanmin FROM cores
INNER JOIN processosting ON (cores.codprotin =
processosting.codprotin)
WHERE cores.codcor = :codcor
INTO :razbanmin;
SELECT inicioprev, fimprev, volumeh2o, razban
FROM sp_selmaq_tin_replan
(:idenc,:codmaq, :qtd, :tempo, :razbanmin,:idgrupo)
INTO :inicioprev, :fimprev, :volume, :razban;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial, centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao FROM maquinas
INNER JOIN centrostrabalho ON (maquinas.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON (centrostrabalho.codcencus =
centroscusto.codcencus)
WHERE maquinas.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial, centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao
FROM maquinastin
INNER JOIN centrostrabalho ON (maquinastin.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON (centrostrabalho.codcencus =
centroscusto.codcencus)
WHERE maquinastin.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
IF (:funcao = 1) THEN /* função tempo (hora) */
BEGIN
taxasalarialprev = :taxasalarial*:tempoprev/60.00;
taxamaquinaprev = :taxamaquina*:tempoprev/60.00;
taxageralprev = :taxageral*:tempoprev/60.00;
END
ELSE IF (:funcao = 2) THEN /* fixo */
BEGIN
taxasalarialprev = :taxasalarial;
taxamaquinaprev = :taxamaquina;
taxageralprev = :taxageral;
END
ELSE IF (:funcao = 3) THEN /* Peso */
BEGIN
taxasalarialprev = :taxasalarial*:qtd;
taxamaquinaprev = :taxamaquina*:qtd;
taxageralprev = :taxageral*:qtd;
END
ELSE IF (:funcao = 4) THEN /* Comprimento */
BEGIN
taxasalarialprev = :taxasalarial*:comprimento;
taxamaquinaprev = :taxamaquina*:comprimento;
taxageralprev = :taxageral*:comprimento;
END
/* insere registos no planeamento */
INSERT INTO ordensfabricoplano
(ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO)
SELECT ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO
FROM ordensfabricoplanoaux
WHERE id = :idplano;
UPDATE ordensfabricoplano
SET inicioprev=:inicioprev,
fimprev=:fimprev,tempoprev=:tempoprev,
codmaq=:codmaq, taxasalarialprev=:taxasalarialprev,
taxamaquinaprev=:taxamaquinaprev,
volume=:volume,razban=:razban,
taxageralprev=:taxageralprev, datof=current_date,
ordemplano=NULL
WHERE id = :idplano;
DELETE FROM ordensfabricoplanoaux WHERE id = :idplano;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =2
ORDER BY ordemplano
INTO :idplano;
END
SELECT COUNT(*) FROM ordensfabricoplanoaux WHERE tipo =2 INTO
nreg;
END
/* tingimento tipo = 3*/
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo = 3
ORDER BY ordemplano
INTO :idplano;
/* conta o nº de registos de tingimento */
SELECT COUNT(*) FROM ordensfabricoplanoaux
WHERE tipo =3 INTO nreg;
WHILE (nreg > 0) DO
BEGIN
SELECT idenc,ordem FROM ordensfabricoplanoaux
WHERE id=:idplano
INTO :idenc, :ordem;
/* verifica se existe uma operação da mesma OF por planear */
idplanoaux = null;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =3 AND idenc=:idenc AND ordem < :ordem AND
id<>:idplano
ORDER BY ordemplano
INTO :idplanoaux;
IF (:idplanoaux IS NOT NULL) THEN
BEGIN
idplano = :idplanoaux;
/* selecciona a máquina */
SELECT codmaq, ordemplano FROM ordensfabricoplanoaux
WHERE id=:idplano
INTO :codmaq, :ordemplano;
/* verifica se a máquina tem outra operação antes */
idplanoaux1 = null;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =3 AND codmaq = :codmaq AND ordemplano
< :ordemplano
AND id<>:idplano
ORDER BY ordemplano
INTO :idplanoaux1;
IF (:idplanoaux1 IS NULL) THEN
BEGIN
-- idplano = :idplanoaux;
SELECT idencl, ordem, qtd, comprimento, tempoope,
codtipmal, idgrupo, codcor
FROM ordensfabricoplanoaux
WHERE id = :idplano
INTO :idencl, :ordem, :qtd, :comprimento, :tempo, :codtipmal, :idgrup
o,
:codcor;
/* determina a capacidade da máquina */
SELECT maquinastin.kgmin, maquinastin.kgmax FROM
maquinastin
WHERE maquinastin.codmaq=:codmaq
INTO :kgmin, :kgmax;
IF (:qtd < :kgmin ) THEN
EXCEPTION maquinatin 'Máquina com capacidade minima
superior à qtd. da encomenda.';
IF (:qtd > :kgmax ) THEN
EXCEPTION maquinatin 'Máquina com capacidade máxima
inferior à qtd. da encomenda.';
/* determina o razao de banho minima */
SELECT processosting.razbanmin
FROM cores
INNER JOIN processosting ON (cores.codprotin =
processosting.codprotin)
WHERE cores.codcor = :codcor
INTO :razbanmin;
SELECT inicioprev, fimprev, volumeh2o, razban FROM
sp_selmaq_tin_replan(:idenc,:codmaq,
:qtd, :tempo, :razbanmin,:idgrupo)
INTO :inicioprev, :fimprev, :volume, :razban;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial,
centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao FROM
maquinas
INNER JOIN centrostrabalho ON (maquinas.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON
(centrostrabalho.codcencus = centroscusto.codcencus)
WHERE maquinas.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial,
centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao
FROM maquinastin
INNER JOIN centrostrabalho ON (maquinastin.codcentra
= centrostrabalho.codcentra)
INNER JOIN centroscusto ON
(centrostrabalho.codcencus = centroscusto.codcencus)
WHERE maquinastin.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
IF (:funcao = 1) THEN /* função tempo (hora) */
BEGIN
taxasalarialprev = :taxasalarial*:tempoprev/60.00;
taxamaquinaprev = :taxamaquina*:tempoprev/60.00;
taxageralprev = :taxageral*:tempoprev/60.00;
END
ELSE IF (:funcao = 2) THEN /* fixo */
BEGIN
taxasalarialprev = :taxasalarial;
taxamaquinaprev = :taxamaquina;
taxageralprev = :taxageral;
END
ELSE IF (:funcao = 3) THEN /* Peso */
BEGIN
taxasalarialprev = :taxasalarial*:qtd;
taxamaquinaprev = :taxamaquina*:qtd;
taxageralprev = :taxageral*:qtd;
END
ELSE IF (:funcao = 4) THEN /* Comprimento */
BEGIN
taxasalarialprev = :taxasalarial*:comprimento;
taxamaquinaprev = :taxamaquina*:comprimento;
taxageralprev = :taxageral*:comprimento;
END
/* insere registos no planeamento */
INSERT INTO ordensfabricoplano
(ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO)
SELECT ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO
FROM ordensfabricoplanoaux
WHERE id = :idplano;
UPDATE ordensfabricoplano
SET inicioprev=:inicioprev,
fimprev=:fimprev,tempoprev=:tempoprev,
codmaq=:codmaq,
taxasalarialprev=:taxasalarialprev,
taxamaquinaprev=:taxamaquinaprev,
volume=:volume,razban=:razban,
taxageralprev=:taxageralprev,
datof=current_date, ordemplano=NULL
WHERE id = :idplano;
DELETE FROM ordensfabricoplanoaux WHERE id = :idplano;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =3
ORDER BY ordemplano
INTO :idplano;
END
END
ELSE
BEGIN
SELECT idencl, ordem, qtd, comprimento, tempoope, codtipmal,
idgrupo, codcor, codmaq
FROM ordensfabricoplanoaux
WHERE id = :idplano
INTO :idencl, :ordem, :qtd, :comprimento, :tempo, :codtipmal, :idgrup
o, :codcor, :codmaq;
/* determina a capacidade da máquina */
SELECT maquinastin.kgmin, maquinastin.kgmax FROM maquinastin
WHERE maquinastin.codmaq=:codmaq
INTO :kgmin, :kgmax;
IF (:qtd < :kgmin ) THEN
EXCEPTION maquinatin 'Máquina com capacidade minima
superior à qtd. da encomenda.';
IF (:qtd > :kgmax ) THEN
EXCEPTION maquinatin 'Máquina com capacidade máxima
inferior à qtd. da encomenda.';
/* determina o razao de banho minima */
SELECT processosting.razbanmin FROM cores
INNER JOIN processosting ON (cores.codprotin =
processosting.codprotin)
WHERE cores.codcor = :codcor
INTO :razbanmin;
SELECT inicioprev, fimprev, volumeh2o, razban
FROM sp_selmaq_tin_replan
(:idenc,:codmaq, :qtd, :tempo, :razbanmin,:idgrupo)
INTO :inicioprev, :fimprev, :volume, :razban;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial, centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao FROM maquinas
INNER JOIN centrostrabalho ON (maquinas.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON (centrostrabalho.codcencus =
centroscusto.codcencus)
WHERE maquinas.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial, centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao
FROM maquinastin
INNER JOIN centrostrabalho ON (maquinastin.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON (centrostrabalho.codcencus =
centroscusto.codcencus)
WHERE maquinastin.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
IF (:funcao = 1) THEN /* função tempo (hora) */
BEGIN
taxasalarialprev = :taxasalarial*:tempoprev/60.00;
taxamaquinaprev = :taxamaquina*:tempoprev/60.00;
taxageralprev = :taxageral*:tempoprev/60.00;
END
ELSE IF (:funcao = 2) THEN /* fixo */
BEGIN
taxasalarialprev = :taxasalarial;
taxamaquinaprev = :taxamaquina;
taxageralprev = :taxageral;
END
ELSE IF (:funcao = 3) THEN /* Peso */
BEGIN
taxasalarialprev = :taxasalarial*:qtd;
taxamaquinaprev = :taxamaquina*:qtd;
taxageralprev = :taxageral*:qtd;
END
ELSE IF (:funcao = 4) THEN /* Comprimento */
BEGIN
taxasalarialprev = :taxasalarial*:comprimento;
taxamaquinaprev = :taxamaquina*:comprimento;
taxageralprev = :taxageral*:comprimento;
END
/* insere registos no planeamento */
INSERT INTO ordensfabricoplano
(ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO)
SELECT ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO
FROM ordensfabricoplanoaux
WHERE id = :idplano;
UPDATE ordensfabricoplano
SET inicioprev=:inicioprev,
fimprev=:fimprev,tempoprev=:tempoprev,
codmaq=:codmaq, taxasalarialprev=:taxasalarialprev,
taxamaquinaprev=:taxamaquinaprev,
volume=:volume,razban=:razban,
taxageralprev=:taxageralprev, datof=current_date,
ordemplano=NULL
WHERE id = :idplano;
DELETE FROM ordensfabricoplanoaux WHERE id = :idplano;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =3
ORDER BY ordemplano
INTO :idplano;
END
SELECT COUNT(*) FROM ordensfabricoplanoaux WHERE tipo =3 INTO
nreg;
END
/* acabamento mecânico */
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo=4
ORDER BY ordemplano
INTO :idplano;
/* conta o nº de registos de acabamento mecânica */
SELECT COUNT(*) FROM ordensfabricoplanoaux
WHERE tipo=4 INTO nreg;
WHILE (nreg > 0) DO
BEGIN
SELECT idenc,ordem FROM ordensfabricoplanoaux
WHERE id=:idplano
INTO :idenc, :ordem;
/* verifica se existe uma operação da mesma OF por planear */
idplanoaux = null;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo=4 AND idenc=:idenc AND ordem < :ordem AND
id<>:idplano
ORDER BY ordemplano
INTO :idplanoaux;
IF (:idplanoaux IS NOT NULL) THEN
BEGIN
idplano = :idplanoaux;
/* selecciona a máquina */
SELECT codmaq, ordemplano FROM ordensfabricoplanoaux
WHERE id=:idplano
INTO :codmaq, :ordemplano;
/* verifica se a máquina tem outra operação antes */
idplanoaux1 = null;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo = 4 AND codmaq = :codmaq AND ordemplano
< :ordemplano
AND id<>:idplano
ORDER BY ordemplano
INTO :idplanoaux1;
IF (:idplanoaux1 IS NULL) THEN
BEGIN
-- idplano = :idplanoaux;
SELECT idenc,idencl, ordem, qtd, comprimento, tempoope,
codtipmal, idgrupo
FROM ordensfabricoplanoaux
WHERE id = :idplano
INTO :idenc, :idencl, :ordem, :qtd, :comprimento, :tempo, :codtipmal,
:idgrupo;
SELECT inicioprev, fimprev, tempoprev FROM
sp_selmaq_pos_replan(:idenc,:idencl,
:ordem, :codmaq, :qtd, :comprimento, :tempo, :codtipm
al,:idgrupo)
INTO :inicioprev, :fimprev, :tempoprev;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial,
centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao FROM
maquinas
INNER JOIN centrostrabalho ON (maquinas.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON
(centrostrabalho.codcencus = centroscusto.codcencus)
WHERE maquinas.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
IF (:funcao = 1) THEN /* função tempo (hora) */
BEGIN
taxasalarialprev = :taxasalarial*:tempoprev/60.00;
taxamaquinaprev = :taxamaquina*:tempoprev/60.00;
taxageralprev = :taxageral*:tempoprev/60.00;
END
ELSE IF (:funcao = 2) THEN /* fixo */
BEGIN
taxasalarialprev = :taxasalarial;
taxamaquinaprev = :taxamaquina;
taxageralprev = :taxageral;
END
ELSE IF (:funcao = 3) THEN /* Peso */
BEGIN
taxasalarialprev = :taxasalarial*:qtd;
taxamaquinaprev = :taxamaquina*:qtd;
taxageralprev = :taxageral*:qtd;
END
ELSE IF (:funcao = 4) THEN /* Comprimento */
BEGIN
taxasalarialprev = :taxasalarial*:comprimento;
taxamaquinaprev = :taxamaquina*:comprimento;
taxageralprev = :taxageral*:comprimento;
END
/* insere registos no planeamento */
INSERT INTO ordensfabricoplano
(ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO)
SELECT ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO
FROM ordensfabricoplanoaux
WHERE id = :idplano;
UPDATE ordensfabricoplano
SET inicioprev=:inicioprev,
fimprev=:fimprev,tempoprev=:tempoprev,
codmaq=:codmaq,
taxasalarialprev=:taxasalarialprev,
taxamaquinaprev=:taxamaquinaprev,
datof=current_date,
taxageralprev=:taxageralprev, ordemplano=NULL
WHERE id = :idplano;
DELETE FROM ordensfabricoplanoaux WHERE id = :idplano;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo=4
ORDER BY ordemplano
INTO :idplano;
END
END
ELSE
BEGIN
SELECT idenc, idencl, ordem, qtd, comprimento, tempoope,
codtipmal, codmaq FROM ordensfabricoplanoaux
WHERE id = :idplano
INTO :idenc, :idencl, :ordem, :qtd, :comprimento, :tempo, :codtipmal,
:codmaq;
SELECT inicioprev, fimprev, tempoprev FROM
sp_selmaq_pos_replan(:idenc,:idencl,
:ordem, :codmaq, :qtd, :comprimento, :tempo, :codtipm
al,:idgrupo)
INTO :inicioprev, :fimprev, :tempoprev;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial, centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao FROM maquinas
INNER JOIN centrostrabalho ON (maquinas.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON (centrostrabalho.codcencus =
centroscusto.codcencus)
WHERE maquinas.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
IF (:funcao = 1) THEN /* função tempo (hora) */
BEGIN
taxasalarialprev = :taxasalarial*:tempoprev/60.00;
taxamaquinaprev = :taxamaquina*:tempoprev/60.00;
taxageralprev = :taxageral*:tempoprev/60.00;
END
ELSE IF (:funcao = 2) THEN /* fixo */
BEGIN
taxasalarialprev = :taxasalarial;
taxamaquinaprev = :taxamaquina;
taxageralprev = :taxageral;
END
ELSE IF (:funcao = 3) THEN /* Peso */
BEGIN
taxasalarialprev = :taxasalarial*:qtd;
taxamaquinaprev = :taxamaquina*:qtd;
taxageralprev = :taxageral*:qtd;
END
ELSE IF (:funcao = 4) THEN /* Comprimento */
BEGIN
taxasalarialprev = :taxasalarial*:comprimento;
taxamaquinaprev = :taxamaquina*:comprimento;
taxageralprev = :taxageral*:comprimento;
END
/* insere registos no planeamento */
INSERT INTO ordensfabricoplano
(ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO)
SELECT ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO
FROM ordensfabricoplanoaux
WHERE id = :idplano;
UPDATE ordensfabricoplano
SET inicioprev=:inicioprev,
fimprev=:fimprev,tempoprev=:tempoprev,
codmaq=:codmaq, taxasalarialprev=:taxasalarialprev,
taxamaquinaprev=:taxamaquinaprev, datof =
current_date,
taxageralprev=:taxageralprev, ordemplano=NULL
WHERE id = :idplano;
DELETE FROM ordensfabricoplanoaux WHERE id = :idplano;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo=4
ORDER BY ordemplano
INTO :idplano;
END
SELECT COUNT(*) FROM ordensfabricoplanoaux WHERE tipo=4 INTO
nreg;
END
SUSPEND;
END
CREATE PROCEDURE SP_REPLANEAR_OF
AS
DECLARE VARIABLE idplano INTEGER;
DECLARE VARIABLE idplanoaux INTEGER;
DECLARE VARIABLE idplanoaux1 INTEGER;
DECLARE VARIABLE idenc INTEGER;
DECLARE VARIABLE nreg INTEGER;
DECLARE VARIABLE idgrupo INTEGER;
DECLARE VARIABLE codmaq VARCHAR(6);
DECLARE VARIABLE ordem INTEGER;
DECLARE VARIABLE inicioprev TIMESTAMP;
DECLARE VARIABLE qtd NUMERIC (18,2);
DECLARE VARIABLE comprimento NUMERIC (18,2);
DECLARE VARIABLE tempoprev INTEGER;
DECLARE VARIABLE fimprev TIMESTAMP;
DECLARE VARIABLE taxasalarialprev NUMERIC (18,4);
DECLARE VARIABLE taxamaquinaprev NUMERIC (18,4);
DECLARE VARIABLE taxageralprev NUMERIC (18,4);
DECLARE VARIABLE taxasalarial NUMERIC (18,4);
DECLARE VARIABLE taxamaquina NUMERIC (18,4);
DECLARE VARIABLE taxageral NUMERIC (18,4);
DECLARE VARIABLE tempo INTEGER;
DECLARE VARIABLE funcao SMALLINT;
DECLARE VARIABLE codtipmal VARCHAR(10);
DECLARE VARIABLE codcor VARCHAR(10);
DECLARE VARIABLE ordemplano INTEGER;
DECLARE VARIABLE idencl INTEGER;
DECLARE VARIABLE razban NUMERIC(18,2);
DECLARE VARIABLE kgmin NUMERIC(18,2);
DECLARE VARIABLE kgmax NUMERIC(18,2);
DECLARE VARIABLE razbanmin NUMERIC(18,2);
DECLARE VARIABLE volume INTEGER;
BEGIN
DELETE FROM ordensfabricoplanoaux;
/* coloca os registos numa tabela auxiliar */
INSERT INTO ordensfabricoplanoaux
(ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,TAXAGER
ALPREV,
TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,CODTIPMAL,CODCOMP,CODCL
I,
CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,ORDEMPLANO,JAINICIOU,COMPRIMENTO
,
TEMPOOPE,TINGIMENTO)
SELECT ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,TAXAGER
ALPREV,
TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,CODTIPMAL,CODCOMP,CODCL
I,
CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,ORDEMPLANO,JAINICIOU,COMPRIMENTO
,
TEMPOOPE,TINGIMENTO FROM ordensfabricoplano WHERE jainiciou=0 ;
DELETE FROM ordensfabricoplano WHERE jainiciou=0;
/* preparação mecânica */
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo=0
ORDER BY ordemplano
INTO :idplano;
/* conta o nº de registos de preparação mecânica */
SELECT COUNT(*) FROM ordensfabricoplanoaux
WHERE tipo=0 INTO nreg;
WHILE (nreg > 0) DO
BEGIN
SELECT idenc,ordem FROM ordensfabricoplanoaux
WHERE id=:idplano
INTO :idenc, :ordem;
/* verifica se existe uma operação da mesma OF por planear */
idplanoaux = null;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo=0 AND idenc=:idenc AND ordem < :ordem AND
id<>:idplano
ORDER BY ordemplano
INTO :idplanoaux;
IF (:idplanoaux IS NOT NULL) THEN
BEGIN
idplano = :idplanoaux;
/* selecciona a máquina */
SELECT codmaq, ordemplano FROM ordensfabricoplanoaux
WHERE id=:idplano
INTO :codmaq, :ordemplano;
/* verifica se a máquina tem outra operação antes */
idplanoaux1 = null;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo = 0 AND codmaq = :codmaq AND ordemplano
< :ordemplano
AND id<>:idplano
ORDER BY ordemplano
INTO :idplanoaux1;
IF (:idplanoaux1 IS NULL) THEN
BEGIN
-- idplano = :idplanoaux;
SELECT idencl, ordem, qtd, comprimento, tempoope,
codtipmal FROM ordensfabricoplanoaux
WHERE id = :idplano
INTO :idencl, :ordem, :qtd, :comprimento, :tempo, :codtipmal;
SELECT inicioprev, fimprev, tempoprev FROM
sp_selmaq_pre_replan(:idencl,:ordem,
:codmaq, :qtd, :comprimento, :tempo, :codtipmal)
INTO :inicioprev, :fimprev, :tempoprev;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial,
centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao FROM
maquinas
INNER JOIN centrostrabalho ON (maquinas.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON
(centrostrabalho.codcencus = centroscusto.codcencus)
WHERE maquinas.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
IF (:funcao = 1) THEN /* função tempo (hora) */
BEGIN
taxasalarialprev = :taxasalarial*:tempoprev/60.00;
taxamaquinaprev = :taxamaquina*:tempoprev/60.00;
taxageralprev = :taxageral*:tempoprev/60.00;
END
ELSE IF (:funcao = 2) THEN /* fixo */
BEGIN
taxasalarialprev = :taxasalarial;
taxamaquinaprev = :taxamaquina;
taxageralprev = :taxageral;
END
ELSE IF (:funcao = 3) THEN /* Peso */
BEGIN
taxasalarialprev = :taxasalarial*:qtd;
taxamaquinaprev = :taxamaquina*:qtd;
taxageralprev = :taxageral*:qtd;
END
ELSE IF (:funcao = 4) THEN /* Comprimento */
BEGIN
taxasalarialprev = :taxasalarial*:comprimento;
taxamaquinaprev = :taxamaquina*:comprimento;
taxageralprev = :taxageral*:comprimento;
END
/* insere registos no planeamento */
INSERT INTO ordensfabricoplano
(ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO)
SELECT ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO
FROM ordensfabricoplanoaux
WHERE id = :idplano;
UPDATE ordensfabricoplano
SET inicioprev=:inicioprev,
fimprev=:fimprev,tempoprev=:tempoprev,
codmaq=:codmaq,
taxasalarialprev=:taxasalarialprev,
taxamaquinaprev=:taxamaquinaprev,
datof=current_date,
taxageralprev=:taxageralprev, ordemplano=NULL
WHERE id = :idplano;
DELETE FROM ordensfabricoplanoaux WHERE id = :idplano;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo=0
ORDER BY ordemplano
INTO :idplano;
END
END
ELSE
BEGIN
SELECT idencl, ordem, qtd, comprimento, tempoope,
codtipmal,codmaq FROM ordensfabricoplanoaux
WHERE id = :idplano
INTO :idencl, :ordem, :qtd, :comprimento, :tempo, :codtipmal,:codmaq;
SELECT inicioprev, fimprev, tempoprev FROM
sp_selmaq_pre_replan(:idencl,:ordem,
:codmaq, :qtd, :comprimento, :tempo, :codtipmal)
INTO :inicioprev, :fimprev, :tempoprev;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial, centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao FROM maquinas
INNER JOIN centrostrabalho ON (maquinas.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON (centrostrabalho.codcencus =
centroscusto.codcencus)
WHERE maquinas.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
IF (:funcao = 1) THEN /* função tempo (hora) */
BEGIN
taxasalarialprev = :taxasalarial*:tempoprev/60.00;
taxamaquinaprev = :taxamaquina*:tempoprev/60.00;
taxageralprev = :taxageral*:tempoprev/60.00;
END
ELSE IF (:funcao = 2) THEN /* fixo */
BEGIN
taxasalarialprev = :taxasalarial;
taxamaquinaprev = :taxamaquina;
taxageralprev = :taxageral;
END
ELSE IF (:funcao = 3) THEN /* Peso */
BEGIN
taxasalarialprev = :taxasalarial*:qtd;
taxamaquinaprev = :taxamaquina*:qtd;
taxageralprev = :taxageral*:qtd;
END
ELSE IF (:funcao = 4) THEN /* Comprimento */
BEGIN
taxasalarialprev = :taxasalarial*:comprimento;
taxamaquinaprev = :taxamaquina*:comprimento;
taxageralprev = :taxageral*:comprimento;
END
/* insere registos no planeamento */
INSERT INTO ordensfabricoplano
(ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO)
SELECT ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO
FROM ordensfabricoplanoaux
WHERE id = :idplano;
UPDATE ordensfabricoplano
SET inicioprev=:inicioprev,
fimprev=:fimprev,tempoprev=:tempoprev,
codmaq=:codmaq, taxasalarialprev=:taxasalarialprev,
taxamaquinaprev=:taxamaquinaprev, datof =
current_date,
taxageralprev=:taxageralprev, ordemplano=NULL
WHERE id = :idplano;
DELETE FROM ordensfabricoplanoaux WHERE id = :idplano;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo=0
ORDER BY ordemplano
INTO :idplano;
END
SELECT COUNT(*) FROM ordensfabricoplanoaux WHERE tipo=0 INTO
nreg;
END
/* tingimento tipo = 1*/
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =1
ORDER BY ordemplano
INTO :idplano;
/* conta o nº de registos de tingimento */
SELECT COUNT(*) FROM ordensfabricoplanoaux
WHERE tipo =1 INTO nreg;
WHILE (nreg > 0) DO
BEGIN
SELECT idenc,ordem FROM ordensfabricoplanoaux
WHERE id=:idplano
INTO :idenc, :ordem;
/* verifica se existe uma operação da mesma OF por planear */
idplanoaux = null;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =1 AND idenc=:idenc AND ordem < :ordem AND
id<>:idplano
ORDER BY ordemplano
INTO :idplanoaux;
IF (:idplanoaux IS NOT NULL) THEN
BEGIN
idplano = :idplanoaux;
/* selecciona a máquina */
SELECT codmaq, ordemplano FROM ordensfabricoplanoaux
WHERE id=:idplano
INTO :codmaq, :ordemplano;
/* verifica se a máquina tem outra operação antes */
idplanoaux1 = null;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =1 AND codmaq = :codmaq AND ordemplano
< :ordemplano
AND id<>:idplano
ORDER BY ordemplano
INTO :idplanoaux1;
IF (:idplanoaux1 IS NULL) THEN
BEGIN
-- idplano = :idplanoaux;
SELECT idencl, ordem, qtd, comprimento, tempoope,
codtipmal, idgrupo, codcor
FROM ordensfabricoplanoaux
WHERE id = :idplano
INTO :idencl, :ordem, :qtd, :comprimento, :tempo, :codtipmal, :idgrup
o,
:codcor;
/* determina a capacidade da máquina */
SELECT maquinastin.kgmin, maquinastin.kgmax FROM
maquinastin
WHERE maquinastin.codmaq=:codmaq
INTO :kgmin, :kgmax;
IF (:qtd < :kgmin ) THEN
EXCEPTION maquinatin 'Máquina com capacidade minima
superior à qtd. da encomenda.';
IF (:qtd > :kgmax ) THEN
EXCEPTION maquinatin 'Máquina com capacidade máxima
inferior à qtd. da encomenda.';
/* determina o razao de banho minima */
SELECT processosting.razbanmin
FROM cores
INNER JOIN processosting ON (cores.codprotin =
processosting.codprotin)
WHERE cores.codcor = :codcor
INTO :razbanmin;
SELECT inicioprev, fimprev, volumeh2o, razban FROM
sp_selmaq_tin_replan(:idenc,:codmaq,
:qtd, :tempo, :razbanmin,:idgrupo)
INTO :inicioprev, :fimprev, :volume, :razban;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial,
centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao FROM
maquinas
INNER JOIN centrostrabalho ON (maquinas.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON
(centrostrabalho.codcencus = centroscusto.codcencus)
WHERE maquinas.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial,
centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao
FROM maquinastin
INNER JOIN centrostrabalho ON (maquinastin.codcentra
= centrostrabalho.codcentra)
INNER JOIN centroscusto ON
(centrostrabalho.codcencus = centroscusto.codcencus)
WHERE maquinastin.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
IF (:funcao = 1) THEN /* função tempo (hora) */
BEGIN
taxasalarialprev = :taxasalarial*:tempoprev/60.00;
taxamaquinaprev = :taxamaquina*:tempoprev/60.00;
taxageralprev = :taxageral*:tempoprev/60.00;
END
ELSE IF (:funcao = 2) THEN /* fixo */
BEGIN
taxasalarialprev = :taxasalarial;
taxamaquinaprev = :taxamaquina;
taxageralprev = :taxageral;
END
ELSE IF (:funcao = 3) THEN /* Peso */
BEGIN
taxasalarialprev = :taxasalarial*:qtd;
taxamaquinaprev = :taxamaquina*:qtd;
taxageralprev = :taxageral*:qtd;
END
ELSE IF (:funcao = 4) THEN /* Comprimento */
BEGIN
taxasalarialprev = :taxasalarial*:comprimento;
taxamaquinaprev = :taxamaquina*:comprimento;
taxageralprev = :taxageral*:comprimento;
END
/* insere registos no planeamento */
INSERT INTO ordensfabricoplano
(ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO)
SELECT ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO
FROM ordensfabricoplanoaux
WHERE id = :idplano;
UPDATE ordensfabricoplano
SET inicioprev=:inicioprev,
fimprev=:fimprev,tempoprev=:tempoprev,
codmaq=:codmaq,
taxasalarialprev=:taxasalarialprev,
taxamaquinaprev=:taxamaquinaprev,
volume=:volume,razban=:razban,
taxageralprev=:taxageralprev,
datof=current_date, ordemplano=NULL
WHERE id = :idplano;
DELETE FROM ordensfabricoplanoaux WHERE id = :idplano;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =1
ORDER BY ordemplano
INTO :idplano;
END
END
ELSE
BEGIN
SELECT idencl, ordem, qtd, comprimento, tempoope, codtipmal,
idgrupo, codcor, codmaq
FROM ordensfabricoplanoaux
WHERE id = :idplano
INTO :idencl, :ordem, :qtd, :comprimento, :tempo, :codtipmal, :idgrup
o, :codcor, :codmaq;
/* determina a capacidade da máquina */
SELECT maquinastin.kgmin, maquinastin.kgmax FROM maquinastin
WHERE maquinastin.codmaq=:codmaq
INTO :kgmin, :kgmax;
IF (:qtd < :kgmin ) THEN
EXCEPTION maquinatin 'Máquina com capacidade minima
superior à qtd. da encomenda.';
IF (:qtd > :kgmax ) THEN
EXCEPTION maquinatin 'Máquina com capacidade máxima
inferior à qtd. da encomenda.';
/* determina o razao de banho minima */
SELECT processosting.razbanmin FROM cores
INNER JOIN processosting ON (cores.codprotin =
processosting.codprotin)
WHERE cores.codcor = :codcor
INTO :razbanmin;
SELECT inicioprev, fimprev, volumeh2o, razban
FROM sp_selmaq_tin_replan
(:idenc,:codmaq, :qtd, :tempo, :razbanmin,:idgrupo)
INTO :inicioprev, :fimprev, :volume, :razban;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial, centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao FROM maquinas
INNER JOIN centrostrabalho ON (maquinas.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON (centrostrabalho.codcencus =
centroscusto.codcencus)
WHERE maquinas.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial, centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao
FROM maquinastin
INNER JOIN centrostrabalho ON (maquinastin.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON (centrostrabalho.codcencus =
centroscusto.codcencus)
WHERE maquinastin.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
IF (:funcao = 1) THEN /* função tempo (hora) */
BEGIN
taxasalarialprev = :taxasalarial*:tempoprev/60.00;
taxamaquinaprev = :taxamaquina*:tempoprev/60.00;
taxageralprev = :taxageral*:tempoprev/60.00;
END
ELSE IF (:funcao = 2) THEN /* fixo */
BEGIN
taxasalarialprev = :taxasalarial;
taxamaquinaprev = :taxamaquina;
taxageralprev = :taxageral;
END
ELSE IF (:funcao = 3) THEN /* Peso */
BEGIN
taxasalarialprev = :taxasalarial*:qtd;
taxamaquinaprev = :taxamaquina*:qtd;
taxageralprev = :taxageral*:qtd;
END
ELSE IF (:funcao = 4) THEN /* Comprimento */
BEGIN
taxasalarialprev = :taxasalarial*:comprimento;
taxamaquinaprev = :taxamaquina*:comprimento;
taxageralprev = :taxageral*:comprimento;
END
/* insere registos no planeamento */
INSERT INTO ordensfabricoplano
(ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO)
SELECT ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO
FROM ordensfabricoplanoaux
WHERE id = :idplano;
UPDATE ordensfabricoplano
SET inicioprev=:inicioprev,
fimprev=:fimprev,tempoprev=:tempoprev,
codmaq=:codmaq, taxasalarialprev=:taxasalarialprev,
taxamaquinaprev=:taxamaquinaprev,
volume=:volume,razban=:razban,
taxageralprev=:taxageralprev, datof=current_date,
ordemplano=NULL
WHERE id = :idplano;
DELETE FROM ordensfabricoplanoaux WHERE id = :idplano;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =1
ORDER BY ordemplano
INTO :idplano;
END
SELECT COUNT(*) FROM ordensfabricoplanoaux WHERE tipo =1 INTO
nreg;
END
/* tingimento tipo = 2*/
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =2
ORDER BY ordemplano
INTO :idplano;
/* conta o nº de registos de tingimento */
SELECT COUNT(*) FROM ordensfabricoplanoaux
WHERE tipo =2 INTO nreg;
WHILE (nreg > 0) DO
BEGIN
SELECT idenc,ordem FROM ordensfabricoplanoaux
WHERE id=:idplano
INTO :idenc, :ordem;
/* verifica se existe uma operação da mesma OF por planear */
idplanoaux = null;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =2 AND idenc=:idenc AND ordem < :ordem AND
id<>:idplano
ORDER BY ordemplano
INTO :idplanoaux;
IF (:idplanoaux IS NOT NULL) THEN
BEGIN
idplano = :idplanoaux;
/* selecciona a máquina */
SELECT codmaq, ordemplano FROM ordensfabricoplanoaux
WHERE id=:idplano
INTO :codmaq, :ordemplano;
/* verifica se a máquina tem outra operação antes */
idplanoaux1 = null;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =2 AND codmaq = :codmaq AND ordemplano
< :ordemplano
AND id<>:idplano
ORDER BY ordemplano
INTO :idplanoaux1;
IF (:idplanoaux1 IS NULL) THEN
BEGIN
-- idplano = :idplanoaux;
SELECT idencl, ordem, qtd, comprimento, tempoope,
codtipmal, idgrupo, codcor
FROM ordensfabricoplanoaux
WHERE id = :idplano
INTO :idencl, :ordem, :qtd, :comprimento, :tempo, :codtipmal, :idgrup
o,
:codcor;
/* determina a capacidade da máquina */
SELECT maquinastin.kgmin, maquinastin.kgmax FROM
maquinastin
WHERE maquinastin.codmaq=:codmaq
INTO :kgmin, :kgmax;
IF (:qtd < :kgmin ) THEN
EXCEPTION maquinatin 'Máquina com capacidade minima
superior à qtd. da encomenda.';
IF (:qtd > :kgmax ) THEN
EXCEPTION maquinatin 'Máquina com capacidade máxima
inferior à qtd. da encomenda.';
/* determina o razao de banho minima */
SELECT processosting.razbanmin
FROM cores
INNER JOIN processosting ON (cores.codprotin =
processosting.codprotin)
WHERE cores.codcor = :codcor
INTO :razbanmin;
SELECT inicioprev, fimprev, volumeh2o, razban FROM
sp_selmaq_tin_replan(:idenc,:codmaq,
:qtd, :tempo, :razbanmin,:idgrupo)
INTO :inicioprev, :fimprev, :volume, :razban;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial,
centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao FROM
maquinas
INNER JOIN centrostrabalho ON (maquinas.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON
(centrostrabalho.codcencus = centroscusto.codcencus)
WHERE maquinas.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial,
centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao
FROM maquinastin
INNER JOIN centrostrabalho ON (maquinastin.codcentra
= centrostrabalho.codcentra)
INNER JOIN centroscusto ON
(centrostrabalho.codcencus = centroscusto.codcencus)
WHERE maquinastin.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
IF (:funcao = 1) THEN /* função tempo (hora) */
BEGIN
taxasalarialprev = :taxasalarial*:tempoprev/60.00;
taxamaquinaprev = :taxamaquina*:tempoprev/60.00;
taxageralprev = :taxageral*:tempoprev/60.00;
END
ELSE IF (:funcao = 2) THEN /* fixo */
BEGIN
taxasalarialprev = :taxasalarial;
taxamaquinaprev = :taxamaquina;
taxageralprev = :taxageral;
END
ELSE IF (:funcao = 3) THEN /* Peso */
BEGIN
taxasalarialprev = :taxasalarial*:qtd;
taxamaquinaprev = :taxamaquina*:qtd;
taxageralprev = :taxageral*:qtd;
END
ELSE IF (:funcao = 4) THEN /* Comprimento */
BEGIN
taxasalarialprev = :taxasalarial*:comprimento;
taxamaquinaprev = :taxamaquina*:comprimento;
taxageralprev = :taxageral*:comprimento;
END
/* insere registos no planeamento */
INSERT INTO ordensfabricoplano
(ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO)
SELECT ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO
FROM ordensfabricoplanoaux
WHERE id = :idplano;
UPDATE ordensfabricoplano
SET inicioprev=:inicioprev,
fimprev=:fimprev,tempoprev=:tempoprev,
codmaq=:codmaq,
taxasalarialprev=:taxasalarialprev,
taxamaquinaprev=:taxamaquinaprev,
volume=:volume,razban=:razban,
taxageralprev=:taxageralprev,
datof=current_date, ordemplano=NULL
WHERE id = :idplano;
DELETE FROM ordensfabricoplanoaux WHERE id = :idplano;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =2
ORDER BY ordemplano
INTO :idplano;
END
END
ELSE
BEGIN
SELECT idencl, ordem, qtd, comprimento, tempoope, codtipmal,
idgrupo, codcor, codmaq
FROM ordensfabricoplanoaux
WHERE id = :idplano
INTO :idencl, :ordem, :qtd, :comprimento, :tempo, :codtipmal, :idgrup
o, :codcor, :codmaq;
/* determina a capacidade da máquina */
SELECT maquinastin.kgmin, maquinastin.kgmax FROM maquinastin
WHERE maquinastin.codmaq=:codmaq
INTO :kgmin, :kgmax;
IF (:qtd < :kgmin ) THEN
EXCEPTION maquinatin 'Máquina com capacidade minima
superior à qtd. da encomenda.';
IF (:qtd > :kgmax ) THEN
EXCEPTION maquinatin 'Máquina com capacidade máxima
inferior à qtd. da encomenda.';
/* determina o razao de banho minima */
SELECT processosting.razbanmin FROM cores
INNER JOIN processosting ON (cores.codprotin =
processosting.codprotin)
WHERE cores.codcor = :codcor
INTO :razbanmin;
SELECT inicioprev, fimprev, volumeh2o, razban
FROM sp_selmaq_tin_replan
(:idenc,:codmaq, :qtd, :tempo, :razbanmin,:idgrupo)
INTO :inicioprev, :fimprev, :volume, :razban;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial, centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao FROM maquinas
INNER JOIN centrostrabalho ON (maquinas.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON (centrostrabalho.codcencus =
centroscusto.codcencus)
WHERE maquinas.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial, centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao
FROM maquinastin
INNER JOIN centrostrabalho ON (maquinastin.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON (centrostrabalho.codcencus =
centroscusto.codcencus)
WHERE maquinastin.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
IF (:funcao = 1) THEN /* função tempo (hora) */
BEGIN
taxasalarialprev = :taxasalarial*:tempoprev/60.00;
taxamaquinaprev = :taxamaquina*:tempoprev/60.00;
taxageralprev = :taxageral*:tempoprev/60.00;
END
ELSE IF (:funcao = 2) THEN /* fixo */
BEGIN
taxasalarialprev = :taxasalarial;
taxamaquinaprev = :taxamaquina;
taxageralprev = :taxageral;
END
ELSE IF (:funcao = 3) THEN /* Peso */
BEGIN
taxasalarialprev = :taxasalarial*:qtd;
taxamaquinaprev = :taxamaquina*:qtd;
taxageralprev = :taxageral*:qtd;
END
ELSE IF (:funcao = 4) THEN /* Comprimento */
BEGIN
taxasalarialprev = :taxasalarial*:comprimento;
taxamaquinaprev = :taxamaquina*:comprimento;
taxageralprev = :taxageral*:comprimento;
END
/* insere registos no planeamento */
INSERT INTO ordensfabricoplano
(ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO)
SELECT ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO
FROM ordensfabricoplanoaux
WHERE id = :idplano;
UPDATE ordensfabricoplano
SET inicioprev=:inicioprev,
fimprev=:fimprev,tempoprev=:tempoprev,
codmaq=:codmaq, taxasalarialprev=:taxasalarialprev,
taxamaquinaprev=:taxamaquinaprev,
volume=:volume,razban=:razban,
taxageralprev=:taxageralprev, datof=current_date,
ordemplano=NULL
WHERE id = :idplano;
DELETE FROM ordensfabricoplanoaux WHERE id = :idplano;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =2
ORDER BY ordemplano
INTO :idplano;
END
SELECT COUNT(*) FROM ordensfabricoplanoaux WHERE tipo =2 INTO
nreg;
END
/* tingimento tipo = 3*/
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo = 3
ORDER BY ordemplano
INTO :idplano;
/* conta o nº de registos de tingimento */
SELECT COUNT(*) FROM ordensfabricoplanoaux
WHERE tipo =3 INTO nreg;
WHILE (nreg > 0) DO
BEGIN
SELECT idenc,ordem FROM ordensfabricoplanoaux
WHERE id=:idplano
INTO :idenc, :ordem;
/* verifica se existe uma operação da mesma OF por planear */
idplanoaux = null;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =3 AND idenc=:idenc AND ordem < :ordem AND
id<>:idplano
ORDER BY ordemplano
INTO :idplanoaux;
IF (:idplanoaux IS NOT NULL) THEN
BEGIN
idplano = :idplanoaux;
/* selecciona a máquina */
SELECT codmaq, ordemplano FROM ordensfabricoplanoaux
WHERE id=:idplano
INTO :codmaq, :ordemplano;
/* verifica se a máquina tem outra operação antes */
idplanoaux1 = null;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =3 AND codmaq = :codmaq AND ordemplano
< :ordemplano
AND id<>:idplano
ORDER BY ordemplano
INTO :idplanoaux1;
IF (:idplanoaux1 IS NULL) THEN
BEGIN
-- idplano = :idplanoaux;
SELECT idencl, ordem, qtd, comprimento, tempoope,
codtipmal, idgrupo, codcor
FROM ordensfabricoplanoaux
WHERE id = :idplano
INTO :idencl, :ordem, :qtd, :comprimento, :tempo, :codtipmal, :idgrup
o,
:codcor;
/* determina a capacidade da máquina */
SELECT maquinastin.kgmin, maquinastin.kgmax FROM
maquinastin
WHERE maquinastin.codmaq=:codmaq
INTO :kgmin, :kgmax;
IF (:qtd < :kgmin ) THEN
EXCEPTION maquinatin 'Máquina com capacidade minima
superior à qtd. da encomenda.';
IF (:qtd > :kgmax ) THEN
EXCEPTION maquinatin 'Máquina com capacidade máxima
inferior à qtd. da encomenda.';
/* determina o razao de banho minima */
SELECT processosting.razbanmin
FROM cores
INNER JOIN processosting ON (cores.codprotin =
processosting.codprotin)
WHERE cores.codcor = :codcor
INTO :razbanmin;
SELECT inicioprev, fimprev, volumeh2o, razban FROM
sp_selmaq_tin_replan(:idenc,:codmaq,
:qtd, :tempo, :razbanmin,:idgrupo)
INTO :inicioprev, :fimprev, :volume, :razban;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial,
centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao FROM
maquinas
INNER JOIN centrostrabalho ON (maquinas.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON
(centrostrabalho.codcencus = centroscusto.codcencus)
WHERE maquinas.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial,
centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao
FROM maquinastin
INNER JOIN centrostrabalho ON (maquinastin.codcentra
= centrostrabalho.codcentra)
INNER JOIN centroscusto ON
(centrostrabalho.codcencus = centroscusto.codcencus)
WHERE maquinastin.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
IF (:funcao = 1) THEN /* função tempo (hora) */
BEGIN
taxasalarialprev = :taxasalarial*:tempoprev/60.00;
taxamaquinaprev = :taxamaquina*:tempoprev/60.00;
taxageralprev = :taxageral*:tempoprev/60.00;
END
ELSE IF (:funcao = 2) THEN /* fixo */
BEGIN
taxasalarialprev = :taxasalarial;
taxamaquinaprev = :taxamaquina;
taxageralprev = :taxageral;
END
ELSE IF (:funcao = 3) THEN /* Peso */
BEGIN
taxasalarialprev = :taxasalarial*:qtd;
taxamaquinaprev = :taxamaquina*:qtd;
taxageralprev = :taxageral*:qtd;
END
ELSE IF (:funcao = 4) THEN /* Comprimento */
BEGIN
taxasalarialprev = :taxasalarial*:comprimento;
taxamaquinaprev = :taxamaquina*:comprimento;
taxageralprev = :taxageral*:comprimento;
END
/* insere registos no planeamento */
INSERT INTO ordensfabricoplano
(ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO)
SELECT ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO
FROM ordensfabricoplanoaux
WHERE id = :idplano;
UPDATE ordensfabricoplano
SET inicioprev=:inicioprev,
fimprev=:fimprev,tempoprev=:tempoprev,
codmaq=:codmaq,
taxasalarialprev=:taxasalarialprev,
taxamaquinaprev=:taxamaquinaprev,
volume=:volume,razban=:razban,
taxageralprev=:taxageralprev,
datof=current_date, ordemplano=NULL
WHERE id = :idplano;
DELETE FROM ordensfabricoplanoaux WHERE id = :idplano;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =3
ORDER BY ordemplano
INTO :idplano;
END
END
ELSE
BEGIN
SELECT idencl, ordem, qtd, comprimento, tempoope, codtipmal,
idgrupo, codcor, codmaq
FROM ordensfabricoplanoaux
WHERE id = :idplano
INTO :idencl, :ordem, :qtd, :comprimento, :tempo, :codtipmal, :idgrup
o, :codcor, :codmaq;
/* determina a capacidade da máquina */
SELECT maquinastin.kgmin, maquinastin.kgmax FROM maquinastin
WHERE maquinastin.codmaq=:codmaq
INTO :kgmin, :kgmax;
IF (:qtd < :kgmin ) THEN
EXCEPTION maquinatin 'Máquina com capacidade minima
superior à qtd. da encomenda.';
IF (:qtd > :kgmax ) THEN
EXCEPTION maquinatin 'Máquina com capacidade máxima
inferior à qtd. da encomenda.';
/* determina o razao de banho minima */
SELECT processosting.razbanmin FROM cores
INNER JOIN processosting ON (cores.codprotin =
processosting.codprotin)
WHERE cores.codcor = :codcor
INTO :razbanmin;
SELECT inicioprev, fimprev, volumeh2o, razban
FROM sp_selmaq_tin_replan
(:idenc,:codmaq, :qtd, :tempo, :razbanmin,:idgrupo)
INTO :inicioprev, :fimprev, :volume, :razban;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial, centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao FROM maquinas
INNER JOIN centrostrabalho ON (maquinas.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON (centrostrabalho.codcencus =
centroscusto.codcencus)
WHERE maquinas.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial, centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao
FROM maquinastin
INNER JOIN centrostrabalho ON (maquinastin.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON (centrostrabalho.codcencus =
centroscusto.codcencus)
WHERE maquinastin.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
IF (:funcao = 1) THEN /* função tempo (hora) */
BEGIN
taxasalarialprev = :taxasalarial*:tempoprev/60.00;
taxamaquinaprev = :taxamaquina*:tempoprev/60.00;
taxageralprev = :taxageral*:tempoprev/60.00;
END
ELSE IF (:funcao = 2) THEN /* fixo */
BEGIN
taxasalarialprev = :taxasalarial;
taxamaquinaprev = :taxamaquina;
taxageralprev = :taxageral;
END
ELSE IF (:funcao = 3) THEN /* Peso */
BEGIN
taxasalarialprev = :taxasalarial*:qtd;
taxamaquinaprev = :taxamaquina*:qtd;
taxageralprev = :taxageral*:qtd;
END
ELSE IF (:funcao = 4) THEN /* Comprimento */
BEGIN
taxasalarialprev = :taxasalarial*:comprimento;
taxamaquinaprev = :taxamaquina*:comprimento;
taxageralprev = :taxageral*:comprimento;
END
/* insere registos no planeamento */
INSERT INTO ordensfabricoplano
(ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO)
SELECT ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO
FROM ordensfabricoplanoaux
WHERE id = :idplano;
UPDATE ordensfabricoplano
SET inicioprev=:inicioprev,
fimprev=:fimprev,tempoprev=:tempoprev,
codmaq=:codmaq, taxasalarialprev=:taxasalarialprev,
taxamaquinaprev=:taxamaquinaprev,
volume=:volume,razban=:razban,
taxageralprev=:taxageralprev, datof=current_date,
ordemplano=NULL
WHERE id = :idplano;
DELETE FROM ordensfabricoplanoaux WHERE id = :idplano;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo =3
ORDER BY ordemplano
INTO :idplano;
END
SELECT COUNT(*) FROM ordensfabricoplanoaux WHERE tipo =3 INTO
nreg;
END
/* acabamento mecânico */
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo=4
ORDER BY ordemplano
INTO :idplano;
/* conta o nº de registos de acabamento mecânica */
SELECT COUNT(*) FROM ordensfabricoplanoaux
WHERE tipo=4 INTO nreg;
WHILE (nreg > 0) DO
BEGIN
SELECT idenc,ordem FROM ordensfabricoplanoaux
WHERE id=:idplano
INTO :idenc, :ordem;
/* verifica se existe uma operação da mesma OF por planear */
idplanoaux = null;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo=4 AND idenc=:idenc AND ordem < :ordem AND
id<>:idplano
ORDER BY ordemplano
INTO :idplanoaux;
IF (:idplanoaux IS NOT NULL) THEN
BEGIN
idplano = :idplanoaux;
/* selecciona a máquina */
SELECT codmaq, ordemplano FROM ordensfabricoplanoaux
WHERE id=:idplano
INTO :codmaq, :ordemplano;
/* verifica se a máquina tem outra operação antes */
idplanoaux1 = null;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo = 4 AND codmaq = :codmaq AND ordemplano
< :ordemplano
AND id<>:idplano
ORDER BY ordemplano
INTO :idplanoaux1;
IF (:idplanoaux1 IS NULL) THEN
BEGIN
-- idplano = :idplanoaux;
SELECT idenc,idencl, ordem, qtd, comprimento, tempoope,
codtipmal, idgrupo
FROM ordensfabricoplanoaux
WHERE id = :idplano
INTO :idenc, :idencl, :ordem, :qtd, :comprimento, :tempo, :codtipmal,
:idgrupo;
SELECT inicioprev, fimprev, tempoprev FROM
sp_selmaq_pos_replan(:idenc,:idencl,
:ordem, :codmaq, :qtd, :comprimento, :tempo, :codtipm
al,:idgrupo)
INTO :inicioprev, :fimprev, :tempoprev;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial,
centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao FROM
maquinas
INNER JOIN centrostrabalho ON (maquinas.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON
(centrostrabalho.codcencus = centroscusto.codcencus)
WHERE maquinas.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
IF (:funcao = 1) THEN /* função tempo (hora) */
BEGIN
taxasalarialprev = :taxasalarial*:tempoprev/60.00;
taxamaquinaprev = :taxamaquina*:tempoprev/60.00;
taxageralprev = :taxageral*:tempoprev/60.00;
END
ELSE IF (:funcao = 2) THEN /* fixo */
BEGIN
taxasalarialprev = :taxasalarial;
taxamaquinaprev = :taxamaquina;
taxageralprev = :taxageral;
END
ELSE IF (:funcao = 3) THEN /* Peso */
BEGIN
taxasalarialprev = :taxasalarial*:qtd;
taxamaquinaprev = :taxamaquina*:qtd;
taxageralprev = :taxageral*:qtd;
END
ELSE IF (:funcao = 4) THEN /* Comprimento */
BEGIN
taxasalarialprev = :taxasalarial*:comprimento;
taxamaquinaprev = :taxamaquina*:comprimento;
taxageralprev = :taxageral*:comprimento;
END
/* insere registos no planeamento */
INSERT INTO ordensfabricoplano
(ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO)
SELECT ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO
FROM ordensfabricoplanoaux
WHERE id = :idplano;
UPDATE ordensfabricoplano
SET inicioprev=:inicioprev,
fimprev=:fimprev,tempoprev=:tempoprev,
codmaq=:codmaq,
taxasalarialprev=:taxasalarialprev,
taxamaquinaprev=:taxamaquinaprev,
datof=current_date,
taxageralprev=:taxageralprev, ordemplano=NULL
WHERE id = :idplano;
DELETE FROM ordensfabricoplanoaux WHERE id = :idplano;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo=4
ORDER BY ordemplano
INTO :idplano;
END
END
ELSE
BEGIN
SELECT idenc, idencl, ordem, qtd, comprimento, tempoope,
codtipmal, codmaq FROM ordensfabricoplanoaux
WHERE id = :idplano
INTO :idenc, :idencl, :ordem, :qtd, :comprimento, :tempo, :codtipmal,
:codmaq;
SELECT inicioprev, fimprev, tempoprev FROM
sp_selmaq_pos_replan(:idenc,:idencl,
:ordem, :codmaq, :qtd, :comprimento, :tempo, :codtipm
al,:idgrupo)
INTO :inicioprev, :fimprev, :tempoprev;
taxasalarialprev=0;
taxamaquinaprev=0;
taxageralprev=0;
/* calcula as taxas */
SELECT centroscusto.taxasalarial, centroscusto.taxamaquina,
centroscusto.taxageral, centroscusto.funcao FROM maquinas
INNER JOIN centrostrabalho ON (maquinas.codcentra =
centrostrabalho.codcentra)
INNER JOIN centroscusto ON (centrostrabalho.codcencus =
centroscusto.codcencus)
WHERE maquinas.codmaq=:codmaq
INTO :taxasalarial, :taxamaquina, :taxageral, :funcao;
IF (:funcao = 1) THEN /* função tempo (hora) */
BEGIN
taxasalarialprev = :taxasalarial*:tempoprev/60.00;
taxamaquinaprev = :taxamaquina*:tempoprev/60.00;
taxageralprev = :taxageral*:tempoprev/60.00;
END
ELSE IF (:funcao = 2) THEN /* fixo */
BEGIN
taxasalarialprev = :taxasalarial;
taxamaquinaprev = :taxamaquina;
taxageralprev = :taxageral;
END
ELSE IF (:funcao = 3) THEN /* Peso */
BEGIN
taxasalarialprev = :taxasalarial*:qtd;
taxamaquinaprev = :taxamaquina*:qtd;
taxageralprev = :taxageral*:qtd;
END
ELSE IF (:funcao = 4) THEN /* Comprimento */
BEGIN
taxasalarialprev = :taxasalarial*:comprimento;
taxamaquinaprev = :taxamaquina*:comprimento;
taxageralprev = :taxageral*:comprimento;
END
/* insere registos no planeamento */
INSERT INTO ordensfabricoplano
(ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO)
SELECT ID,DATOF,IDENC,IDENCL,TIPO,ORDEM,CODMAQ,
TEMPOPREV,INICIOPREV,FIMPREV,TAXASALARIALPREV,TAXAMAQUINAPREV,
TAXAGERALPREV,TAXATINGPREV,RAZBAN,VOLUME,IDGRUPO,QTD,CODCOR,
CODTIPMAL,CODCOMP,CODCLI,CODOPE,VALIDAR,TALAOCLI,PECAS,CODPRO,
ORDEMPLANO,JAINICIOU,COMPRIMENTO,TEMPOOPE,TINGIMENTO
FROM ordensfabricoplanoaux
WHERE id = :idplano;
UPDATE ordensfabricoplano
SET inicioprev=:inicioprev,
fimprev=:fimprev,tempoprev=:tempoprev,
codmaq=:codmaq, taxasalarialprev=:taxasalarialprev,
taxamaquinaprev=:taxamaquinaprev, datof =
current_date,
taxageralprev=:taxageralprev, ordemplano=NULL
WHERE id = :idplano;
DELETE FROM ordensfabricoplanoaux WHERE id = :idplano;
SELECT FIRST 1 id FROM ordensfabricoplanoaux
WHERE tipo=4
ORDER BY ordemplano
INTO :idplano;
END
SELECT COUNT(*) FROM ordensfabricoplanoaux WHERE tipo=4 INTO
nreg;
END
SUSPEND;
END