#ldxscripta
#DESC FLX040100F
#COD_PRODUTO 80
#COD_BANCO 3
#COD_CLIENTE 0
#DATA 25/10/2012 16:45
#LINGUAGEM A
#MARCO 0
#DISTRIBUICAO 04.01.00
#TITULO CREATE TABLE FIREBIRD
#BEGIN
CREATE TABLE TAFFAIXADESC ( CDATIV VARCHAR(25) DEFAULT '0' NOT NULL, NRININ DECIMAL(15,4) DEFAULT 0 NOT NULL, NRFIIN DECIMAL(15,4) DEFAULT 0 NOT NULL, PCDESC DECIMAL(15,4) DEFAULT 0 NOT NULL, CONSTRAINT fk_CDFRMATIVCDATIV FOREIGN KEY (CDATIV) REFERENCES TAFRMATIV (CDATIV), PRIMARY KEY (CDATIV,NRININ,NRFIIN) )
#@# 
CREATE TABLE TAFTABPRECO ( CDTAB VARCHAR(25) DEFAULT '0' NOT NULL, DSTAB VARCHAR(50), PRIMARY KEY (CDTAB) ) 
#@# 
CREATE TABLE TAFTABEQP ( CDTAB VARCHAR(25) DEFAULT '0' NOT NULL, CDEQP VARCHAR(25) DEFAULT '0' NOT NULL, CONSTRAINT fk_CDFRTABPRECOCDTAB FOREIGN KEY (CDTAB) REFERENCES TAFTABPRECO (CDTAB), PRIMARY KEY (CDTAB,CDEQP) )
#@#
CREATE TABLE TAFTRANSP ( CDTRAN VARCHAR(25) DEFAULT '0' NOT NULL, DSTRAN VARCHAR(50), PRIMARY KEY (CDTRAN) )
#@#
CREATE TABLE TAFFRETE ( CDTRAN VARCHAR(25) DEFAULT '0' NOT NULL, IDFRTE CHAR(1) DEFAULT '0' NOT NULL, VLMIVE DECIMAL(15,4) DEFAULT 0 NOT NULL, VLMIFR DECIMAL(15,4) DEFAULT 0 NOT NULL, PCMIFR DECIMAL(15,4) DEFAULT 0 NOT NULL, CONSTRAINT fk_CDFRTAFFRETECDTRAN FOREIGN KEY (CDTRAN) REFERENCES TAFTRANSP (CDTRAN), PRIMARY KEY (CDTRAN) )
#@#
#END
#LINGUAGEM A
#MARCO 0
#DISTRIBUICAO 04.01.00
#TITULO ALTER TABLE COMUNS
#BEGIN
ALTER TABLE TMVSPARAM ADD IDCOFO CHAR(1) DEFAULT '0' NOT NULL
#@#

ALTER TABLE TMVSPARAM ADD IDPZMD CHAR(1) DEFAULT '0' NOT NULL
#@#

ALTER TABLE TMVSPARAM ADD IDVLVD CHAR(1) DEFAULT '0' NOT NULL
#@#

ALTER TABLE TMVSPARAM ADD PCADPM DECIMAL(15,4) DEFAULT 0 NOT NULL
#@#

ALTER TABLE TMVSPARAMGL ADD IDVOLT CHAR(1) DEFAULT '0' NOT NULL
#@#

ALTER TABLE TMVSPARAMGL ADD IDDESP CHAR(1) DEFAULT '0' NOT NULL
#@#

ALTER TABLE TMVSPARAM ADD IDCOIN CHAR(1) DEFAULT '0' NOT NULL
#@#

ALTER TABLE TMVSCAB ADD IDCOIN CHAR(1) DEFAULT '0' NOT NULL
#@#

ALTER TABLE TAFCAB ADD IDF_CONSINTERNO CHAR(1) DEFAULT '0' NOT NULL
#@#

ALTER TABLE TMVSPARAM ADD IDTBPR CHAR(1) DEFAULT '0' NOT NULL
#@#

ALTER TABLE TMVSPARAM ADD IDTRAN CHAR(1) DEFAULT '0' NOT NULL
#@#

ALTER TABLE TAFFILIAL ADD IDIPI CHAR(1) DEFAULT '0' NOT NULL
#@#
#END
#LINGUAGEM A
#MARCO 0
#DISTRIBUICAO 04.01.00
#TITULO ALTER TABLE FIREBIRD
#BEGIN
ALTER TABLE TMVSITE ADD CDTAB VARCHAR(25) DEFAULT '0' NOT NULL
#@#

ALTER TABLE TAFITE ADD COD_TABELA VARCHAR(25) DEFAULT '0' NOT NULL
#@#

ALTER TABLE TMVSEQP ADD CDTRAN VARCHAR(25) DEFAULT '0'
#@#

ALTER TABLE TMVSCAB ADD CDTRAN VARCHAR(25) DEFAULT '0' NOT NULL
#@#

ALTER TABLE TAFCAB ADD COD_TRANSPORTADORA VARCHAR(25) DEFAULT '0' NOT NULL
#@#

#END
#LINGUAGEM A
#MARCO 0
#DISTRIBUICAO 04.01.00
#TITULO UPDATE COMUNS
#BEGIN
UPDATE TMVSRESPMW SET RESP_TMVSRESPMW = 'FF' , DESC_TMVSRESPMW = 'SIM, CALCULA VALOR DE FRETE FOB COMO ACRÉSCIMO' WHERE RESP_TMVSRESPMW = 'FF' AND COD_TMVSRESPMW = '1' 
#@#

UPDATE TMVSRESPMW SET RESP_TMVSRESPMW = 'FF', DESC_TMVSRESPMW = 'SIM, CALCULA VALOR DE FRETE FOB COMO DESCONTO' WHERE RESP_TMVSRESPMW = 'FF' AND COD_TMVSRESPMW = '2' 
#@#

UPDATE TMVSTABMW SET DESC_TMVSTABMW = 'Sistema permite informar o valor de frete para o pedido:' WHERE TABLE_TMVSTABMW = 'TMVSPARAMGL' AND CAMPO_TMVSTABMW = 'IDPCFR'
#@#

UPDATE TMVSTABMW SET DESC_HINT = 'Identifica se o Sistema disponibiliza opção para informar o valor frete para o pedido (FOB ou CIF).' WHERE TABLE_TMVSTABMW = 'TMVSPARAMGL' AND CAMPO_TMVSTABMW = 'IDPCFR'
#@#

UPDATE TMVSTABMW SET TABGRID_TMVSTABMW = '09 - Middleware (Integração Padrão)', ORDER_TMVSTABMW = 1 WHERE  TABLE_TMVSTABMW = 'TMVSPARAMGL' AND CAMPO_TMVSTABMW = 'IDPRVE' 
#@#

UPDATE TMVSTABMW SET TABGRID_TMVSTABMW = '08 - Middleware (Integração PC)' WHERE TABLE_TMVSTABMW = 'TMVSPARAMGL' AND TABGRID_TMVSTABMW = '09 - Middleware (Integração PC)'
#@#

UPDATE TMVSTABMW SET TABGRID_TMVSTABMW = '09 - Middleware (Integração PC)' WHERE TABLE_TMVSTABMW = 'TMVSPARAM' AND TABGRID_TMVSTABMW = '10 - Middleware (Integração PC)'
#@#

UPDATE TMVSTABMW SET DESC_TMVSTABMW = 'Taxas de acréscimo/desconto para o desconto por quantidade:'
WHERE TABLE_TMVSTABMW = 'TMVSPARAMGL' AND CAMPO_TMVSTABMW = 'NUDADQ'
#@#

UPDATE TMVSTABMW
SET DESC_HINT = 'Determina como são enviadas as taxas de desconto e acréscimo para o desconto por quantidade.'
WHERE TABLE_TMVSTABMW = 'TMVSPARAMGL' AND CAMPO_TMVSTABMW = 'NUDADQ'
#@#

UPDATE TMVSTABMW SET VLRGRID_TMVSTABMW = 'Acréscimo > 0, Desconto < 0'
WHERE TABLE_TMVSTABMW = 'TMVSPARAMGL' AND CAMPO_TMVSTABMW = 'NUDADQ'
#@#

UPDATE TMVSTABMW
SET VLRDFT_TMVSTABMW = '-1'
WHERE TABLE_TMVSTABMW = 'TMVSPARAMGL' AND CAMPO_TMVSTABMW = 'NUDADQ'
#@#

UPDATE TMVSESTAPL
SET DSEST = 'Produto em promoção para o cliente'
WHERE CDEST = 301
#@#

UPDATE TMVSESTAPL
SET DSEST = 'Produto vendido'
WHERE CDEST = 302
#@#
#END
#LINGUAGEM A
#MARCO 0
#DISTRIBUICAO 04.01.00
#TITULO DELETE COMUNS
#BEGIN
DELETE FROM TMVSRESPMW WHERE RESP_TMVSRESPMW = 'AT'
#@#

DELETE FROM TMVSTABMW WHERE TABLE_TMVSTABMW = 'TMVSPARAMGL' AND CAMPO_TMVSTABMW = 'DSTPAU'
#@#

DELETE FROM TMVSTABMW WHERE TABLE_TMVSTABMW = 'TMVSPARAMGL' AND CAMPO_TMVSTABMW = 'DSSMTP'
#@#

DELETE FROM TMVSTABMW WHERE TABLE_TMVSTABMW = 'TMVSPARAMGL' AND CAMPO_TMVSTABMW = 'DSEMUS'
#@#

DELETE FROM TMVSTABMW WHERE TABLE_TMVSTABMW = 'TMVSPARAMGL' AND CAMPO_TMVSTABMW = 'DSEMTI'
#@#

DELETE FROM TMVSTABMW WHERE TABLE_TMVSTABMW = 'TMVSPARAMGL' AND CAMPO_TMVSTABMW = 'DSEMSN'
#@#

DELETE FROM TMVSTABMW WHERE TABLE_TMVSTABMW = 'TMVSPARAMGL' AND CAMPO_TMVSTABMW = 'DSEMRT'
#@#

DELETE FROM TMVSTABMW WHERE TABLE_TMVSTABMW = 'TMVSPARAMGL' AND CAMPO_TMVSTABMW = 'DSEMCF'
#@#
#END
#LINGUAGEM A
#MARCO 0
#DISTRIBUICAO 04.01.00
#TITULO INSERT COMUNS
#BEGIN
INSERT INTO TMVSRESPMW (RESP_TMVSRESPMW, COD_TMVSRESPMW, DESC_TMVSRESPMW, IDFIX_TMVSRESPMW, SELECT_TMVSRESPMW, KEYVALUE_TMVSRESPMW, KEYLIST_TMVSRESPMW) VALUES ('CB', '0', 'EXIBIR OPÇÕES PADRÕES', 1, NULL, NULL, NULL)
#@#

INSERT INTO TMVSRESPMW (RESP_TMVSRESPMW, COD_TMVSRESPMW, DESC_TMVSRESPMW, IDFIX_TMVSRESPMW, SELECT_TMVSRESPMW, KEYVALUE_TMVSRESPMW, KEYLIST_TMVSRESPMW)VALUES ('CB', '1', 'EXIBIR OPÇÕES EM BRANCO', 1, NULL, NULL, NULL)
#@#

INSERT INTO TMVSRESPMW (RESP_TMVSRESPMW, COD_TMVSRESPMW, DESC_TMVSRESPMW, IDFIX_TMVSRESPMW, SELECT_TMVSRESPMW, KEYVALUE_TMVSRESPMW, KEYLIST_TMVSRESPMW)
VALUES ('VT', '0', 'VALOR DE TABELA', 1, NULL, NULL, NULL)
#@#

INSERT INTO TMVSRESPMW (RESP_TMVSRESPMW, COD_TMVSRESPMW, DESC_TMVSRESPMW, IDFIX_TMVSRESPMW, SELECT_TMVSRESPMW, KEYVALUE_TMVSRESPMW, KEYLIST_TMVSRESPMW)
VALUES ('VT', '1', 'VALOR DE TABELA MÁXIMO E ACRÉSCIMO MÁXIMO', 1, NULL, NULL, NULL)
#@#

INSERT INTO TMVSRESPMW (RESP_TMVSRESPMW, COD_TMVSRESPMW, DESC_TMVSRESPMW, IDFIX_TMVSRESPMW, SELECT_TMVSRESPMW, KEYVALUE_TMVSRESPMW, KEYLIST_TMVSRESPMW)
VALUES ('VT', '2', 'VALOR DE TABELA MÍNIMO E DESCONTO MÁXIMO', 1, NULL, NULL, NULL)
#@#

INSERT INTO TMVSESTAPL (CDEST, CDAPL, DSEST, CDRGBR, CDRGBG, CDRGBB, CDRGFR, CDRGFG, CDRGFB, IDPRIO)
VALUES (303, 3, 'Desconto por quantidade', 255, 221, 187, 20, 20, 20, 4)
#@#

INSERT INTO TMVSMOD (CDMODL, DSMODL, DSTECN, IDMWPD, IDLOG)
VALUES ('1058', 'Itens com desconto por quantidade', 'ITENS_DESC_QUANT', 'P', '1')
#@#

INSERT INTO TMVSTABMW ( TABLE_TMVSTABMW, CAMPO_TMVSTABMW, TYPE_TMVSTABMW, NULL_TMVSTABMW, PRK_TMVSTABMW, PREC_TMVSTABMW, SCALE_TMVSTABMW, SIZE_TMVSTABMW, VLRDFT_TMVSTABMW, DESC_TMVSTABMW, RESP_TMVSRESPMW, NRCS_TMVSTABMW, MXLG_TMVSTABMW, ORDER_TMVSTABMW, VLRGRID_TMVSTABMW, TABGRID_TMVSTABMW, TABMASK_TMVSTABMW, TABCRYPT_TMVSTABMW, IDFEXIBE_TMVSTABMW, DESC_HINT, READONLY_TMVSTABMW ) VALUES ( 'TMVSPARAM', 'IDCOFO', 'CHAR', '0', '0', NULL, NULL, '1', '0', 'Seleção inicial opções condição/forma pagamento do pedido:', 'CB', '0', '1', 84, 'EXIBIR OPÇÕES PADRÕES', '04 - Mod. Ped. 1 Negociação', NULL, NULL, NULL, 'Identifica a seleção inicial das opções condição de pagamento e forma de pagamento do pedido', '0' )
#@#

INSERT INTO TMVSTABMW ( TABLE_TMVSTABMW, CAMPO_TMVSTABMW, TYPE_TMVSTABMW, NULL_TMVSTABMW, PRK_TMVSTABMW, PREC_TMVSTABMW, SCALE_TMVSTABMW, SIZE_TMVSTABMW, VLRDFT_TMVSTABMW, DESC_TMVSTABMW, RESP_TMVSRESPMW, NRCS_TMVSTABMW, MXLG_TMVSTABMW, ORDER_TMVSTABMW, VLRGRID_TMVSTABMW, TABGRID_TMVSTABMW, TABMASK_TMVSTABMW, TABCRYPT_TMVSTABMW, IDFEXIBE_TMVSTABMW, DESC_HINT, READONLY_TMVSTABMW ) VALUES ( 'TMVSPARAM', 'IDPZMD', 'CHAR', '0', '0', NULL, NULL, '1', '0', 'Verifica o prazo médio de produtos e condições de pagamento?', 'SN', '0', '1', 85, 'NÃO', '04 - Mod. Ped. 1 Negociação', NULL, NULL, NULL, 'Este campo identificará se o sistema deve comparar o prazo médio do item e da condição de pagamento do pedido', '0' )
#@#

INSERT INTO TMVSTABMW ( TABLE_TMVSTABMW, CAMPO_TMVSTABMW, TYPE_TMVSTABMW, NULL_TMVSTABMW, PRK_TMVSTABMW, PREC_TMVSTABMW, SCALE_TMVSTABMW, SIZE_TMVSTABMW, VLRDFT_TMVSTABMW, DESC_TMVSTABMW, RESP_TMVSRESPMW, NRCS_TMVSTABMW, MXLG_TMVSTABMW, ORDER_TMVSTABMW, VLRGRID_TMVSTABMW, TABGRID_TMVSTABMW, TABMASK_TMVSTABMW, TABCRYPT_TMVSTABMW, IDFEXIBE_TMVSTABMW, DESC_HINT, READONLY_TMVSTABMW ) VALUES ( 'TMVSPARAM', 'IDVLVD', 'CHAR', '0', '0', NULL, NULL, '1', '0', 'Valor de venda e percentual inicial para o item:', 'VT', '0', '1', 86, 'VALOR DE TABELA', '04 - Mod. Ped. 1 Negociação', NULL, NULL, NULL, 'Identifica qual deve ser o valor de venda inicial para o item', '0' )
#@#

INSERT INTO TMVSTABMW ( TABLE_TMVSTABMW, CAMPO_TMVSTABMW, TYPE_TMVSTABMW, NULL_TMVSTABMW, PRK_TMVSTABMW, PREC_TMVSTABMW, SCALE_TMVSTABMW, SIZE_TMVSTABMW, VLRDFT_TMVSTABMW, DESC_TMVSTABMW, RESP_TMVSRESPMW, NRCS_TMVSTABMW, MXLG_TMVSTABMW, ORDER_TMVSTABMW, VLRGRID_TMVSTABMW, TABGRID_TMVSTABMW, TABMASK_TMVSTABMW, TABCRYPT_TMVSTABMW, IDFEXIBE_TMVSTABMW, DESC_HINT, READONLY_TMVSTABMW ) VALUES ( 'TMVSPARAM', 'PCADPM', 'NUMBER', '0', '0', '15', '4', '15', '0', 'Percentual adicional de desconto/acréscimo máximo para PM:', 'F', '4', '15',  84, '0', '05 - Mod. Ped. 1 Desc/Acréscimo', NULL, NULL, NULL, 'Este campo define o percentual adicional de desconto/acréscimo máximo para produtos médio', '0' )
#@#

INSERT INTO TMVSTABMW ( TABLE_TMVSTABMW, CAMPO_TMVSTABMW, TYPE_TMVSTABMW, NULL_TMVSTABMW, PRK_TMVSTABMW, PREC_TMVSTABMW, SCALE_TMVSTABMW, SIZE_TMVSTABMW, VLRDFT_TMVSTABMW, DESC_TMVSTABMW, RESP_TMVSRESPMW, NRCS_TMVSTABMW, MXLG_TMVSTABMW, ORDER_TMVSTABMW, VLRGRID_TMVSTABMW, TABGRID_TMVSTABMW, TABMASK_TMVSTABMW, TABCRYPT_TMVSTABMW, IDFEXIBE_TMVSTABMW, DESC_HINT, READONLY_TMVSTABMW ) VALUES ( 'TMVSPARAMGL', 'IDVOLT', 'CHAR', '0', '0', NULL, NULL, '1', '0', 'Exibe "Volume total de itens" no resumo do pedido?', 'SN', '0', '1', 71, 'NÃO', '03 - SSM Módulo Pedido 1', NULL, NULL, NULL, 'Identifica se exibe o campo "Volume total de itens" no resumo do pedido', '0' )
#@#

INSERT INTO TMVSTABMW ( TABLE_TMVSTABMW, CAMPO_TMVSTABMW, TYPE_TMVSTABMW, NULL_TMVSTABMW, PRK_TMVSTABMW, PREC_TMVSTABMW, SCALE_TMVSTABMW, SIZE_TMVSTABMW, VLRDFT_TMVSTABMW, DESC_TMVSTABMW, RESP_TMVSRESPMW, NRCS_TMVSTABMW, MXLG_TMVSTABMW, ORDER_TMVSTABMW, VLRGRID_TMVSTABMW, TABGRID_TMVSTABMW, TABMASK_TMVSTABMW, TABCRYPT_TMVSTABMW, IDFEXIBE_TMVSTABMW, DESC_HINT, READONLY_TMVSTABMW ) VALUES ( 'TMVSPARAMGL', 'IDDESP', 'CHAR', '0', '0', NULL, NULL, '1', '0', 'Ratear desc. pé do ped. nos relatórios Resumo e Status ped.?', 'SN', '0', '1', 46, 'NÃO', '03 - SSM Módulo Pedido 1', NULL, NULL, NULL, 'Identifica se deve ratear (ilustrativamente) o desconto no pé do pedido nos relatórios "Resumo do pedido" e "Status do pedido"', '0' )
#@#

INSERT INTO TMVSTABMW ( TABLE_TMVSTABMW, CAMPO_TMVSTABMW, TYPE_TMVSTABMW, NULL_TMVSTABMW, PRK_TMVSTABMW, PREC_TMVSTABMW, SCALE_TMVSTABMW, SIZE_TMVSTABMW, VLRDFT_TMVSTABMW, DESC_TMVSTABMW, RESP_TMVSRESPMW, NRCS_TMVSTABMW, MXLG_TMVSTABMW, ORDER_TMVSTABMW, VLRGRID_TMVSTABMW, TABGRID_TMVSTABMW, TABMASK_TMVSTABMW, TABCRYPT_TMVSTABMW, IDFEXIBE_TMVSTABMW, DESC_HINT, READONLY_TMVSTABMW ) VALUES ( 'TMVSPARAM', 'IDCOIN', 'CHAR', '0', '0', NULL, NULL, '1', '0', 'Exibe a opção Consumo Interno no cabeçalho do pedido?', 'SN', '0', '1', 47, 'NÃO', '08 - Mod. Ped. 1 Exibição', NULL, NULL, NULL, 'Identifica se exibe a opção Consumo Interno no cabeçalho do pedido', '0' )
#@#

INSERT INTO TMVSRESPMW ( RESP_TMVSRESPMW, COD_TMVSRESPMW, DESC_TMVSRESPMW, IDFIX_TMVSRESPMW, SELECT_TMVSRESPMW, KEYVALUE_TMVSRESPMW, KEYLIST_TMVSRESPMW ) VALUES ( 'CT', '3', 'VENDEDOR', 1, NULL, NULL, NULL )
#@#

INSERT INTO TMVSRESPMW ( RESP_TMVSRESPMW, COD_TMVSRESPMW, DESC_TMVSRESPMW, IDFIX_TMVSRESPMW, SELECT_TMVSRESPMW, KEYVALUE_TMVSRESPMW, KEYLIST_TMVSRESPMW ) VALUES ( 'SP', '0', 'POR PEDIDO', 1, NULL, NULL, NULL )
#@#

INSERT INTO TMVSRESPMW ( RESP_TMVSRESPMW, COD_TMVSRESPMW, DESC_TMVSRESPMW, IDFIX_TMVSRESPMW, SELECT_TMVSRESPMW, KEYVALUE_TMVSRESPMW, KEYLIST_TMVSRESPMW ) VALUES ( 'SP', '1', 'POR ITENS', 1, NULL, NULL, NULL )
#@#

INSERT INTO TMVSTABMW ( TABLE_TMVSTABMW, CAMPO_TMVSTABMW, TYPE_TMVSTABMW, NULL_TMVSTABMW, PRK_TMVSTABMW, PREC_TMVSTABMW, SCALE_TMVSTABMW, SIZE_TMVSTABMW, VLRDFT_TMVSTABMW, DESC_TMVSTABMW, RESP_TMVSRESPMW, NRCS_TMVSTABMW, MXLG_TMVSTABMW, ORDER_TMVSTABMW, VLRGRID_TMVSTABMW, TABGRID_TMVSTABMW, TABMASK_TMVSTABMW, TABCRYPT_TMVSTABMW, IDFEXIBE_TMVSTABMW, DESC_HINT, READONLY_TMVSTABMW ) VALUES ( 'TMVSPARAM', 'IDTBPR', 'CHAR', '0', '0', NULL, NULL, '1', '0', 'Local da seleção da tabela de preços:', 'SP', '0', '1', 48, 'POR PEDIDO', '08 - Mod. Ped. 1 Exibição', NULL, NULL, NULL, 'Identifica o local da seleção da tabela de preços', '0' )
#@#

INSERT INTO TMVSTABMW (TABLE_TMVSTABMW, CAMPO_TMVSTABMW, TYPE_TMVSTABMW, NULL_TMVSTABMW, PRK_TMVSTABMW, PREC_TMVSTABMW, SCALE_TMVSTABMW, SIZE_TMVSTABMW, VLRDFT_TMVSTABMW, DESC_TMVSTABMW, RESP_TMVSRESPMW, NRCS_TMVSTABMW, MXLG_TMVSTABMW, ORDER_TMVSTABMW, VLRGRID_TMVSTABMW, TABGRID_TMVSTABMW, TABMASK_TMVSTABMW, TABCRYPT_TMVSTABMW, IDFEXIBE_TMVSTABMW, DESC_HINT, READONLY_TMVSTABMW) VALUES ('TMVSPARAM', 'IDTRAN', 'CHAR', '0', '0', NULL, NULL, '1', '0', 'Exibe a opção transportadora no cabeçalho do pedido?', 'SN', '0', '1', 49, 'NÃO', '08 - Mod. Ped. 1 Exibição', NULL, NULL, NULL, 'Identifica se exibe a opção transportadora no cabeçalho do pedido', '0')
#@#

INSERT INTO TMVSTABMW (TABLE_TMVSTABMW, CAMPO_TMVSTABMW, TYPE_TMVSTABMW, NULL_TMVSTABMW, PRK_TMVSTABMW, PREC_TMVSTABMW, SCALE_TMVSTABMW, SIZE_TMVSTABMW, VLRDFT_TMVSTABMW, DESC_TMVSTABMW, RESP_TMVSRESPMW, NRCS_TMVSTABMW, MXLG_TMVSTABMW, ORDER_TMVSTABMW, VLRGRID_TMVSTABMW, TABGRID_TMVSTABMW, TABMASK_TMVSTABMW, TABCRYPT_TMVSTABMW, IDFEXIBE_TMVSTABMW, DESC_HINT, READONLY_TMVSTABMW) VALUES ('TMVSEQP', 'CDTRAN', 'VARCHAR', '0', '0', NULL, NULL, '25', '0', 'Código da transportadora padrão do vendedor:', 'S', NULL, '25', 11, NULL, 'Cadastro de equipes', NULL, NULL, NULL, 'Este campo é usado quando o módulo de pedidos utilizado pelo cliente é o Módulo 1 (campo IDMOPE da tabela TMVSPARAMGL)', '0')
#@#

INSERT INTO TMVSRESPMW (RESP_TMVSRESPMW, COD_TMVSRESPMW, DESC_TMVSRESPMW, IDFIX_TMVSRESPMW, SELECT_TMVSRESPMW, KEYVALUE_TMVSRESPMW, KEYLIST_TMVSRESPMW) VALUES ('FF', '3', 'SIM, CALCULA VALOR DE FRETE CIF', 1, NULL, NULL, NULL)
#@#
#END
#LINGUAGEM A
#MARCO 0
#DISTRIBUICAO 04.01.00
#TITULO ALTER PROCEDURE LDX_EXP_TMVS_TAF_FIREBIRD
#BEGIN
ALTER PROCEDURE LDX_EXP_TMVS_TAF ( NUM_PROCESSAMENTO VARCHAR (25) CHARACTER SET NONE)
AS
 DECLARE CDPED VARCHAR(25);
 DECLARE CDFRM VARCHAR(25);
 DECLARE CDCL VARCHAR(25);
 DECLARE CDCNPG VARCHAR(25);
 DECLARE CDEQP VARCHAR(25);
 DECLARE DTPED TIMESTAMP;
 DECLARE DTFAT TIMESTAMP;
 DECLARE VLPED DECIMAL(15,4);
 DECLARE DSOBS VARCHAR(100);
 DECLARE DTPROC TIMESTAMP;
 DECLARE NUPROC VARCHAR(25);
 DECLARE IDEXP CHAR(1);
 DECLARE DSMSEX VARCHAR(4000);
 DECLARE CDMW VARCHAR(39);
 DECLARE DSOBSN VARCHAR(100);
 DECLARE CDPRIO VARCHAR(25);
 DECLARE IDSTS CHAR(1);
 DECLARE CDEMP VARCHAR(25);
 DECLARE CDFILI VARCHAR(25);
 DECLARE NUM_PEDIDO VARCHAR(25);
 DECLARE CDPROD VARCHAR(25);
 DECLARE QTDVND DECIMAL(15,4);
 DECLARE VLTAB DECIMAL(15,4);
 DECLARE VLVEND DECIMAL(15,4);
 DECLARE PCDSAC DECIMAL(15,4);
 DECLARE VLTOT DECIMAL (15,4);
 DECLARE DSUNID CHAR(3);
 DECLARE PCDSMX DECIMAL (15,4);
 DECLARE VLTBDC DECIMAL (15,4);
 DECLARE IDPROM CHAR (1);
 DECLARE CDDRPR VARCHAR(25);
 DECLARE DTFABR TIMESTAMP;
 DECLARE CDMTTR VARCHAR(25);
 DECLARE VLST DECIMAL (15,4);
 DECLARE MNV_CDINC INT;
 DECLARE MNV_CDCL VARCHAR(25);
 DECLARE MNV_CDMOT VARCHAR(25);
 DECLARE MNV_CDEQP VARCHAR(25);
 DECLARE MNV_DTMNV TIMESTAMP;
 DECLARE MNV_DTPROC TIMESTAMP;
 DECLARE MNV_NUPROC VARCHAR(25);
 DECLARE MNV_DSMSEX VARCHAR(4000);
 DECLARE IDEXP2 VARCHAR(10);
 DECLARE MNV_MTV_NV VARCHAR(25);
 DECLARE CDATIV VARCHAR(25);
 DECLARE CDTAB  VARCHAR(25);
 DECLARE DSRAZ  VARCHAR(40);
 DECLARE DSFAN  VARCHAR(40);
 DECLARE DSCGCP VARCHAR(20);
 DECLARE DSIERG VARCHAR(20);
 DECLARE VLCRED DECIMAL(15,4);
 DECLARE IDPFPJ CHAR(1);
 DECLARE IDBLQ  CHAR(1);
 DECLARE DSMTBL VARCHAR(40);
 DECLARE IDLMCR CHAR(1);
 DECLARE IDTITV CHAR(1);
 DECLARE DSNCTT VARCHAR(40);
 DECLARE DSACTT VARCHAR(20);
 DECLARE DSCRCT VARCHAR(20);
 DECLARE DSTCTT VARCHAR(15);
 DECLARE DSRML  VARCHAR(10);
 DECLARE IDFREQ CHAR(1);
 DECLARE IDVIP  CHAR(1);
 DECLARE PCVIP  DECIMAL(15,4);
 DECLARE CDREG  VARCHAR(25);
 DECLARE CDPRAC VARCHAR(25);
 DECLARE DSCP01 VARCHAR(50);
 DECLARE DSCP02 VARCHAR(50);
 DECLARE DSCP03 VARCHAR(50);
 DECLARE DSCP04 VARCHAR(50);
 DECLARE DSENDP VARCHAR(40);
 DECLARE DSBAIP VARCHAR(40);
 DECLARE DSCEPP VARCHAR(10);
 DECLARE DSCIDP VARCHAR(20);
 DECLARE DSUFP  CHAR(2);
 DECLARE DSTLPR VARCHAR(15);
 DECLARE DSFAXP VARCHAR(15);
 DECLARE DSENDC VARCHAR(40);
 DECLARE DSBAIC VARCHAR(40);
 DECLARE DSCEPC VARCHAR(10);
 DECLARE DSCIDC varchar(20);
 DECLARE DSUFC  CHAR(2);
 DECLARE DSTLCB VARCHAR(15);
 DECLARE DSFAXC VARCHAR(15);
 DECLARE IDIAE  CHAR(1);
 declare res  integer;
 DECLARE IDDIA  integer;
 DECLARE SEMANA CHAR(1);
 DECLARE SEQDIA integer;
 DECLARE CDINC INTEGER;
 DECLARE CDMOT VARCHAR (25);
 DECLARE DTMEXC TIMESTAMP;
 DECLARE VLLAT  DECIMAL(15,4);
 DECLARE VLLONG  DECIMAL(15,4);
 DECLARE NRORCP VARCHAR (12);
 DECLARE CDPDOR VARCHAR (25);

 DECLARE IDFRET CHAR(1);
 DECLARE QTITPD DECIMAL(15,4);


 DECLARE DTDESE TIMESTAMP;
 DECLARE CDORVE VARCHAR(25);
 DECLARE CDCANA VARCHAR(25);
 DECLARE CDSET VARCHAR(25);
 DECLARE CDINCO VARCHAR(25);
 DECLARE CDLIST VARCHAR(25);
 DECLARE CDESVE VARCHAR(25);
 DECLARE CDGRPC VARCHAR(25);
 DECLARE CDTPDO VARCHAR(25);
 DECLARE CDCEN VARCHAR(25);
 DECLARE CDCLRE VARCHAR(25);
 DECLARE IDTPPE CHAR(1);
 DECLARE IDFTDE CHAR(1);

 DECLARE CDGRPR varchar(25);
 DECLARE CDGRMA varchar(25);
 /*020000*/
 DECLARE CDBLOQ VARCHAR(25);
 DECLARE CDGRCL VARCHAR(25);
 DECLARE UFDOFI char(3);
 DECLARE CDZONI VARCHAR(25);
 DECLARE CDCIDP VARCHAR(25);
 DECLARE CDCIDC VARCHAR(25);
 DECLARE IDTPCL CHAR(1);
 DECLARE DSOBOB VARCHAR(120);
 DECLARE DSMAIL VARCHAR(50);

 DECLARE DTLEV TIMESTAMP;
 DECLARE QTDEST INTEGER;
 DECLARE CDDRV VARCHAR(25);
 DECLARE DTVIS TIMESTAMP;
 DECLARE QTDCL	Integer;
 DECLARE QTDPED Integer;
 DECLARE QTDCNV Integer;
 DECLARE INATEN Decimal (15,4);
 DECLARE DTNCO TIMESTAMP;

 DECLARE CDTPPD VARCHAR(25);
 
 DECLARE PCDCI1 Decimal (15,4);
 DECLARE PCDCI2 Decimal (15,4);
 DECLARE PCDCI3 Decimal (15,4);
 DECLARE PCDCI4 Decimal (15,4);
 DECLARE PCDCI5 Decimal (15,4);
 DECLARE VLTABF Decimal (15,4);

 DECLARE VLDSPP Decimal (15,4);
 DECLARE PCDCP1 Decimal (15,4);
 DECLARE PCDCP2 Decimal (15,4);
 DECLARE PCDCP3 Decimal (15,4);
 DECLARE PCDCP4 Decimal (15,4);
 DECLARE PCDCP5 Decimal (15,4); 
 DECLARE VLFRPD Decimal (15,4);
 DECLARE VLIPI  Decimal (15,4);
 DECLARE VLFINA Decimal (15,4);
 DECLARE IDDCQT CHAR(1);
 
 DECLARE CDITE  VARCHAR (25);
 DECLARE DTPESQ TIMESTAMP;
 DECLARE VLITE  DECIMAL(15,4);
 DECLARE CDDRIT VARCHAR(25);
 DECLARE VLCOMP DECIMAL(15,4);
 DECLARE CDMARC VARCHAR(25);

 DECLARE DTATUA TIMESTAMP;
 DECLARE VLSLIN Decimal(15,4);
 DECLARE VLSLAT Decimal(15,4);
 DECLARE VLSLVE Decimal(15,4);
 
 DECLARE NUPRPC Integer;
 
 DECLARE CDCLPR Integer;
 DECLARE DSOBS2 VARCHAR(100);
 DECLARE IDCOIN CHAR(1);
 DECLARE CDTRAN VARCHAR(25);
 
 BEGIN
    FOR   SELECT    CAST(CDPED AS INTEGER),
                    CDCL,
                    CDFRM,
                    CDCNPG,
                    CDEQP,
                    CDPRIO,
                    DTPED,
                    DTFAT,
                    VLPED,
                    DSOBSI,
                    DSOBSN,
                    DTPROC,
                    NUPROC,
                    IDEXP,
                    DSMSEX,
                    IDSTS,
                    CDMW ,
                    cdemp,
                    cdfili,
					NRORCP,
					CDPDOR,
					IDFRET,
					QTITPD,

                    DTDESE,
                    CDORVE,
                    CDCANA,
                    CDSET,
                    CDINCO,
                    CDLIST,
                    CDESVE,
                    CDGRPC,
                    CDTPDO,
                    CDCEN,
                    CDCLRE,
                    IDTPPE,
                    IDFTDE,
					
					CDTPPD, 
					CDTAB,
					
					VLDSPP,
					PCDCP1,
					PCDCP2,
					PCDCP3,
					PCDCP4,
					PCDCP5,
					VLFRPD,
				    VLFINA,
					CDCLPR,
					IDCOIN,
					CDTRAN,
					DSOBS2
          FROM     TMVSCAB
          WHERE     NUPROC = :NUM_PROCESSAMENTO
            AND IDEXP = 0
          INTO     :CDPED,
                   :CDCL,
                   :CDFRM,
                   :CDCNPG,
                   :CDEQP,
                   :CDPRIO,
                   :DTPED,
                   :DTFAT,
                   :VLPED,
                   :DSOBS,
                   :DSOBSN,
                   :DTPROC,
                   :NUPROC,
                   :IDEXP,
                   :DSMSEX,
                   :IDSTS,
                   :CDMW ,
                   :cdemp,
                   :cdfili,
				   :NRORCP,
				   :CDPDOR,
				   :IDFRET,
				   :QTITPD,
				   :DTDESE,
				   :CDORVE,
				   :CDCANA,
				   :CDSET ,
				   :CDINCO,
				   :CDLIST,
				   :CDESVE,
				   :CDGRPC,
				   :CDTPDO,
				   :CDCEN ,
				   :CDCLRE,
				   :IDTPPE,
				   :IDFTDE,
				   
				   :CDTPPD, 
				   :CDTAB,
				   :VLDSPP,
				   :PCDCP1,
				   :PCDCP2,
				   :PCDCP3,
				   :PCDCP4,
				   :PCDCP5,
				   :VLFRPD,
				   :VLFINA,
				   :CDCLPR,
				   :IDCOIN,
				   :CDTRAN,
				   :DSOBS2

 DO BEGIN
          INSERT INTO TAFCAB (NUM_PEDIDO,
          					  COD_VENDEDOR,
          					  COD_CLIENTE,
          					  COD_FORMAPAGTO,
          					  COD_CONDPGTO,
          					  TIPO_VENDA,
          					  DAT_PEDIDO,
          					  DAT_EXTRA,
          					  VLR_TOTALPEDIDO,
          					  DES_OBSINT,
          					  DES_OBSNF,
          					  IMPORTADO,
          					  DTPROC,
          					  DAT_RETATUAL,
          					  NUPROC,
          					  MSG_IMPORTACAO,
          					  CDMW,
          					  COD_EMPRESA,
          					  COD_FILIAL,
          					  SITUACAO_PEDIDO,
							  NUM_ORDCOMPRA,
							  COD_PEDORIG,
							  IDF_TIPFRETE,
							  QTD_ITEPED,

							  DATA_DESEJADA,
							  COD_ORGVEND,
							  COD_CANAL,
							  COD_SETOR,
							  COD_INCOTERM,
							  COD_LISTA,
							  COD_ESCRVENDAS,
							  COD_GRUPOPRE,
							  COD_TIPODOCTO,
							  COD_CENTRO,
							  COD_RECEBEDOR,
							  IDF_TIPOPEDIDO,
							  IDF_FATDATADESE,

							  COD_TIPPED,
							  COD_TABPRE,
							  
							  VLR_DESCPEPED,
							  PER_DESCASPED1,
							  PER_DESCASPED2,
							  PER_DESCASPED3,
							  PER_DESCASPED4,
							  PER_DESCASPED5,
							  VLR_FRETEPED,
							  VLR_FINAL,
							  NUM_COLPRECO,
							  IDF_CONSINTERNO,
							  COD_TRANSPORTADORA,
							  DES_OBSINT2
							  )
          VALUES (:cdped,
                  :CDEQP,
                  :CDCL,
                  :CDFRM,
                  :CDCNPG,
                  :CDPRIO,
                  :DTPED,
                  :DTFAT,
                  :VLPED,
                  :DSOBS,
                  :DSOBSN,
                  '1',
                  :DTPROC,
                  :DTPROC,
                  :NUPROC,
                  'Pedido incluído na base de dados de mobilidade!',
                  :CDMW,
                  :cdemp,
                  :cdfili,
                  'G',
				  :NRORCP,
				  :CDPDOR,
				  :IDFRET,
				  :QTITPD,

				  :DTDESE,
                  :CDORVE,
                  :CDCANA,
                  :CDSET ,
                  :CDINCO,
                  :CDLIST,
                  :CDESVE,
                  :CDGRPC,
                  :CDTPDO,
                  :CDCEN ,
                  :CDCLRE,
                  :IDTPPE,
                  :IDFTDE,
				  :CDTPPD, 
				  :CDTAB,
				  :VLDSPP,
				  :PCDCP1,
				  :PCDCP2,
				  :PCDCP3,
				  :PCDCP4,
				  :PCDCP5,
				  :VLFRPD,
				  :VLFINA,
				  :CDCLPR,
				  :IDCOIN,
				  :CDTRAN,
				  :DSOBS2
				  );
				  
				  
          UPDATE TMVSCAB 		SET IDEXP = '1'
          WHERE CDPED = :cdped;

          FOR 	  SELECT CAST(ITE.CDPED AS INTEGER),
                         ITE.CDPROD,
                         ITE.QTDVND,
                         ITE.VLTAB,
                         ITE.VLVEND,
                         ITE.PCDSAC,
                         ITE.VLTOT,
                         ITE.DSUNID,
                         ITE.PCDSMX,
                         ITE.VLTBDC,
                         ITE.IDPROM,
                         ITE.CDEMP,
                         ITE.CDFILI,
                         ITE.CDDRPR,
                         ITE.DTFABR,
                         ITE.CDMTTR,
                         ITE.VLST,
						 ITE.CDGRPR,
						 ITE.CDGRMA,
						 ITE.CDDRV,
						 ITE.PCDCI1,
						 ITE.PCDCI2,
						 ITE.PCDCI3,
						 ITE.PCDCI4,
						 ITE.PCDCI5,
						 ITE.VLTABF,
						 ITE.VLIPI,
						 ITE.CDTAB,
						 ITE.IDDCQT
                  FROM TMVSITE ITE , TMVSCAB CAB
                  WHERE ITE.CDPED = CAB.CDPED
                    AND CAB.CDPED =  :CDPED
                  INTO  :CDPED,
                        :CDPROD,
                        :QTDVND,
                        :VLTAB,
                        :VLVEND,
                        :PCDSAC,
                        :VLTOT,
                        :DSUNID,
                        :PCDSMX,
                        :VLTBDC,
                        :IDPROM,
                        :CDEMP,
                        :CDFILI,
                        :CDDRPR,
						:DTFABR,
						:CDMTTR,
						:VLST,
						:CDGRPR,
						:CDGRMA,
						:CDDRV,
						:PCDCI1,
						:PCDCI2,
						:PCDCI3,
						:PCDCI4,
						:PCDCI5,
						:VLTABF,
						:VLIPI,
						:CDTAB,
						:IDDCQT
						
	DO BEGIN
          INSERT INTO TAFITE (NUM_PEDIDO,
                              COD_PRODUTO,
                              QTDE_VENDA,
                              VLR_TABELA,
                              VLR_VENDA,
                              PER_DESCACRES,
                              VLR_TOTAL_ITEM,
                              DES_UNIDADE,
                              MSG_IMPORTACAO,
                              COD_EMPRESA,
                              COD_FILIAL,
                              COD_DERPRODUTO,
							  DAT_FABRICACAO,
							  COD_MOTTROCA,
							  VLR_SUBST,
					          COD_GRUPOPROD,
							  COD_GRUPOMAT,
							  COD_DERIVACAO,
							  PER_DESCASITE1,
							  PER_DESCASITE2,
							  PER_DESCASITE3,
							  PER_DESCASITE4,
							  PER_DESCASITE5,
							  VLR_TABELA_FOB,
							  VLR_IPI,
							  COD_TABELA,
							  IDDCQT
						    )
          VALUES (:CDPED,
                  :CDPROD,
                  :QTDVND,
                  :VLTAB,
                  :VLVEND,
                  :PCDSAC,
                  :VLTOT,
                  :DSUNID,
                  'Itens incluídos na base de dados de mobilidade!',
                  :CDEMP,
                  :CDFILI,
                  :CDDRPR,
				  :DTFABR,
				  :CDMTTR,
				  :VLST,
				  :CDGRPR,
				  :CDGRMA,
				  :CDDRV,
				  :PCDCI1,
				  :PCDCI2,
				  :PCDCI3,
				  :PCDCI4,
				  :PCDCI5,
				  :VLTABF,
				  :VLIPI,
				  :CDTAB,
				  :IDDCQT
				  );
				  
     END
	 
	FOR
		SELECT 
			CDPED,
			NUPRPC
		FROM 
			TMVSPRAZOS 
		WHERE 
			CDPED = :CDPED
	    INTO 
			:CDPED,
			:NUPRPC
	DO 
	BEGIN
		INSERT INTO TAFPRAZOS
		(
			NUM_PEDIDO,
			NUM_PRZPARC
		)
		VALUES 
		(
			:CDPED,
			:NUPRPC
		); 	  
	END
 END
FOR   SELECT CDINC,
			 CDCL,
			 CDMOT,
			 CDEQP,
			 DTMNV,
			 DTPROC,
			 NUPROC,
			 IDEXP,
			 DSMSEX
	  FROM TMVSMNVCL
	  WHERE     NUPROC = :NUM_PROCESSAMENTO
	    AND IDEXP = 0
	  INTO :MNV_CDINC,
	       :MNV_CDCL,
	       :MNV_CDMOT,
	       :MNV_CDEQP,
	       :MNV_DTMNV,
	       :MNV_DTPROC,
	       :MNV_NUPROC,
	       :IDEXP2,
	       :MNV_DSMSEX
 DO BEGIN
    EXECUTE PROCEDURE LDX_GEN_INCREMENTA 'INC_TAFMNV' RETURNING_VALUES :MNV_MTV_NV;

    INSERT INTO TAFMNV (NUM_MOTNVENDA,
                        COD_VENDEDOR,
                        COD_CLIENTE,
                        DAT_MOTNVENDA,
                        COD_OCORRENCIA,
                        MSG_IMPORTACAO,
                        IMPORTADO,
                        DTPROC,
                        NUPROC)
    VALUES     (:MNV_MTV_NV,
                :MNV_CDEQP,
                :MNV_CDCL,
                :MNV_DTMNV,
                :MNV_CDMOT,
                :MNV_DSMSEX,
                '1',
                :MNV_DTPROC,
                :MNV_NUPROC);
   UPDATE TMVSMNVCL 	SET IDEXP = '1'
   WHERE CDCL = :MNV_CDCL;
 END
 
 for 	SELECT 		CDCL,
  				    CDFRM,
  				    CDCNPG,
  				    CDATIV,
  				    CDTAB,
  				    DSRAZ,
  				    DSFAN,
  				    DSCGCP,
  				    DSIERG,
  				    VLCRED,
  				    IDPFPJ,
  				    IDBLQ,
  				    DSMTBL,
  				    IDLMCR,
  				    IDTITV,
  				    DSNCTT,
  				    DSACTT,
  				    DSCRCT,
  				    DSTCTT,
  				    DSRML,
  				    DSOBS,
  				    IDFREQ,
  				    IDVIP,
  				    PCVIP,
  				    CDREG,
  				    CDPRAC,
  				    DSCP01,
  				    DSCP02,
  				    DSCP03,
  				    DSCP04,
  				    DSENDP,
  				    DSBAIP,
  				    DSCEPP,
  				    DSCIDP,
  				    DSUFP,
  				    DSTLPR,
  				    DSFAXP,
  				    DSENDC,
  				    DSBAIC,
  				    DSCEPC,
  				    DSCIDC,
  				    DSUFC,
  				    DSTLCB,
  				    DSFAXC,
  				    IDIAE,
  				    DTPROC,
  				    NUPROC,
  				    DSMSEX,
  				    IDEXP,
  				    CDEQP,
					VLLAT,
					VLLONG,
					

					CDBLOQ,
					CDGRCL,
					UFDOFI,
					CDZONI,
					CDCIDP,
					CDCIDC,
					IDTPCL,
					DSOBOB,
					DSMAIL

  		FROM TMVSCLIALT
  		where idexp = '0'
  		into 		:CDCL,		    :CDFRM,		:CDCNPG,
  		            :CDATIV,		:CDTAB,		:DSRAZ,
  		            :DSFAN, 		:DSCGCP,	:DSIERG,
  		            :VLCRED,		:IDPFPJ,	:IDBLQ,
  		            :DSMTBL,	    :IDLMCR,	:IDTITV,
  		            :DSNCTT,		:DSACTT,	:DSCRCT,
  		            :DSTCTT,		:DSRML,		:DSOBS,
  		            :IDFREQ,		:IDVIP,		:PCVIP,
  		            :CDREG,		    :CDPRAC,	:DSCP01,
  		            :DSCP02,		:DSCP03, 	:DSCP04,
  		            :DSENDP,		:DSBAIP,	:DSCEPP,
  		            :DSCIDP,		:DSUFP,		:DSTLPR,
  		            :DSFAXP, 		:DSENDC,	:DSBAIC,
  		            :DSCEPC,		:DSCIDC,	:DSUFC,
  		            :DSTLCB,		:DSFAXC,	:IDIAE,
  		            :DTPROC,		:NUPROC,	:DSMSEX,
  		            :IDEXP, 		:CDEQP,     :VLLAT,
					:VLLONG,
					
									:CDBLOQ,    :CDGRCL,
					:UFDOFI,        :CDZONI,    :CDCIDP,
					:CDCIDC,        :IDTPCL,    :DSOBOB,
					:DSMAIL
DO BEGIN
   select count(cdcl) from tafclialt where cdcl = :cdcl into :res;
   if (:res = 0)  then
      begin
         insert into tafclialt 	(CDEQP,    CDCL,	 CDFRM,
         						 CDCNPG,   CDATIV,   CDTAB,
         						 DSRAZ,	   DSFAN,	 DSCGCP,
         						 DSIERG,   VLCRED,	 IDPFPJ,
         						 IDBLQ,	   DSMTBL,	 IDLMCR,
         						 IDTITV,   DSNCTT, 	 DSACTT,
         						 DSCRCT,   DSTCTT,	 DSRML,
         						 DSOBS,	   IDFREQ,	 IDVIP,
         						 PCVIP,    CDREG,	 CDPRAC,
         						 DSCP01,   DSCP02,	 DSCP03,
         						 DSCP04,   DSENDP,	 DSBAIP,
         						 DSCEPP,   DSCIDP,	 DSUFP,
         						 DSTLPR,   DSFAXP,	 DSENDC,
         						 DSBAIC,   DSCEPC, 	 DSCIDC,
         						 DSUFC,	   DSTLCB,	 DSFAXC,
         						 IDIAE,	   DTPROC,	 NUPROC,
         						 IMPORTADO, VLLAT,   VLLONG,
								 
							     CDBLOQ, CDGRCL,    UFDOFI,
					             CDZONI, CDCIDP,    CDCIDC,
					             IDTPCL, DSOBOB,    DSMAIL					 
								 )
         values ( :CDEQP,   :CDCL,	    :CDFRM,
                  :CDCNPG,	:CDATIV,	:CDTAB,
                  :DSRAZ,	:DSFAN,	    :DSCGCP,
                  :DSIERG, 	:VLCRED,	:IDPFPJ,
                  :IDBLQ, 	:DSMTBL,	:IDLMCR,
                  :IDTITV,	:DSNCTT,	:DSACTT,
                  :DSCRCT,	:DSTCTT,	:DSRML,
                  :DSOBS, 	:IDFREQ,	:IDVIP,
                  :PCVIP, 	:CDREG, 	:CDPRAC,
                  :DSCP01,	:DSCP02,	:DSCP03,
                  :DSCP04,	:DSENDP,	:DSBAIP,
                  :DSCEPP, 	:DSCIDP,	:DSUFP,
                  :DSTLPR,	:DSFAXP,	:DSENDC,
                  :DSBAIC,	:DSCEPC,	:DSCIDC,
                  :DSUFC, 	:DSTLCB,	:DSFAXC,
                  :IDIAE, 	:DTPROC,	:NUPROC,
                  '1',		:VLLAT,     :VLLONG,
				  
				  :CDBLOQ,  :CDGRCL,    :UFDOFI,
				  :CDZONI,  :CDCIDP,    :CDCIDC,
				  :IDTPCL,  :DSOBOB,    :DSMAIL);
         UPDATE tmvsclialt 		SET IDEXP = '1'
         WHERE CDCL = :CDCL ;
      end
   else
      begin
         update tafclialt set CDEQP  = :CDEQP ,       CDCL   = :CDCL,	    CDFRM  = :CDFRM,
                              CDCNPG = :CDCNPG,			CDATIV = :CDATIV,	 		CDTAB  = :CDTAB,
                              DSRAZ  = :DSRAZ,			DSFAN  = :DSFAN,			DSCGCP = :DSCGCP,
                              DSIERG = :DSIERG,		VLCRED = :VLCRED,			IDPFPJ = :IDPFPJ,
                              IDBLQ  = :IDBLQ, 	 		DSMTBL = :DSMTBL,			IDLMCR = :IDLMCR,
                              IDTITV = :IDTITV,			DSNCTT = :DSNCTT,	 		DSACTT = :DSACTT,
                              DSCRCT = :DSCRCT,			DSTCTT = :DSTCTT,			DSRML  = :DSRML,
                              DSOBS  = :DSOBS, 			IDFREQ = :IDFREQ,			IDVIP  = :IDVIP,
                              PCVIP  = :PCVIP, 	 		CDREG  = :CDREG,		CDPRAC = :CDPRAC,
                              DSCP01 = :DSCP01,			DSCP02 = :DSCP02,	 		DSCP03 = :DSCP03,
                              DSCP04 = :DSCP04,			DSENDP = :DSENDP,			DSBAIP = :DSBAIP,
                              DSCEPP = :DSCEPP,		DSCIDP = :DSCIDP,			DSUFP  = :DSUFP,
                              DSTLPR = :DSTLPR,	 		DSFAXP = :DSFAXP,			DSENDC = :DSENDC,
                              DSBAIC = :DSBAIC,			DSCEPC = :DSCEPC,	 		DSCIDC = :DSCIDC,
                              DSUFC  = :DSUFC, 			DSTLCB = :DSTLCB,			DSFAXC = :DSFAXC,
                              IDIAE  = :IDIAE, 			DTPROC = :DTPROC,			NUPROC = :NUPROC,
                              IMPORTADO  = '1',         VLLAT  = :VLLAT,            VLLONG = :VLLONG,
							  CDBLOQ = :CDBLOQ,       CDGRCL = :CDGRCL,         UFDOFI = :UFDOFI,
							  CDZONI = :CDZONI,       CDCIDP = :CDCIDP,         CDCIDC = :CDCIDC,
							  IDTPCL = :IDTPCL,       DSOBOB = :DSOBOB,         DSMAIL = :DSMAIL

         where cdcl = :cdcl;

         UPDATE tmvsclialt 		SET IDEXP = '1'
         WHERE CDCL = :CDCL;
      end
 END
  
for    select 	CDCL, 	CDEQP,	IDDIA,
                SEMANA,	SEQDIA, 	IDIAE,
                DTPROC,	NUPROC,	IDEXP,	DSMSEX, CDINC
            from Tmvsvis
            where idexp = '0'
            into 	:CDCL,	  :CDEQP,	:IDDIA,
            		:SEMANA,	:SEQDIA, 	:IDIAE,
            		:DTPROC,	:NUPROC,  :IDEXP,
            		:DSMSEX,    :CDINC
 do begin 	select count(cdcl) from Tafvisalt where cdcl = :cdcl and cdeqp = :cdeqp and iddia = :iddia into :res;
 	if (:res = 0) then
 	   begin
 	      insert Into tafvisalt ( CDCL, CDEQP,	IDDIA,
 	      						  SEMANA,	SEQDIA, IDIAE,
 	      						  DTPROC,	NUPROC,	IMPORTADO, NUM_VISALT )
 	      values ( :CDCL,	  :CDEQP,	:IDDIA,
 	               :SEMANA,	:SEQDIA, 		:IDIAE,
 	               :DTPROC,	:NUPROC,  '1', 	:CDINC	);
 	      UPDATE Tmvsvis 		SET IDEXP = '1'
 	      WHERE cdcl = :cdcl
			    and cdeqp = :cdeqp
			    and iddia = :iddia;
 	   end
 	else
 	   begin
 	        update tafvisalt set CDCL   = :CDCL,		CDEQP  = :CDEQP,		IDDIA  = :IDDIA,
 	        					 SEMANA = :SEMANA,		SEQDIA = :SEQDIA,		IDIAE  = :IDIAE,
 	        					 DTPROC = :DTPROC,		NUPROC = :NUPROC,		IMPORTADO  = '1',  
								 NUM_VISALT = :CDINC
 	        where cdcl = :cdcl
 	        and cdeqp = :cdeqp
 	        and iddia = :iddia;

 	        UPDATE Tmvsvis 		SET IDEXP = '1'
 	        WHERE cdcl = :cdcl
			  and cdeqp = :cdeqp
			  and iddia = :iddia;
 	   end
	end

FOR 	SELECT CDINC,  CDCL,   CDMOT,
			   CDEQP,  DTMEXC, DTPROC,
			   NUPROC, IDSTS,  IDEXP
	    FROM TMVSMECL
	    where idexp = '0'
	    INTO :CDINC,  :CDCL,   :CDMOT,
	         :CDEQP,  :DTMEXC, :DTPROC,
	         :NUPROC, :IDSTS,  :IDEXP
DO    BEGIN
           select count(*) from TAFME where COD_CLIENTE = :cdcl into :res;
           if (:res = 0) then
              begin
              INSERT INTO TAFME ( NUM_MOTEXC, COD_VENDEDOR, COD_CLIENTE,
                                  DAT_MOTEXC, COD_MOTEXC, 	MSG_IMPORTACAO,
                                  IMPORTADO,  DTPROC, 		NUPROC 		)
              VALUES (:CDINC, :CDEQP, :CDCL,
                      :DTMEXC,:CDMOT, 'Exportado com sucesso!',
                      '1', 	:DTPROC, :NUPROC );

              UPDATE TMVSMECL 		SET IDEXP = '1'
              WHERE CDCL = :CDCL;
			end
END

FOR SELECT CDINC,
		   CDITE,
		   CDCL,
		   DTPESQ,
		   CDEQP,
		   VLITE,
		   DTPROC,
		   NUPROC,
		   IDSTS,
		   CDDRIT,
		   CDMARC,
		   VLCOMP
      FROM TMVSCLPESQ	
	 WHERE idexp = '0' 	
	  INTO :CDINC,
	       :CDITE,
		   :CDCL,
		   :DTPESQ,
		   :CDEQP,
		   :VLITE,
		   :DTPROC,
		   :NUPROC,
		   :IDSTS,
		   :CDDRIT,
		   :CDMARC,
		   :VLCOMP
DO
BEGIN
    SElECT COUNT(*) 
	  FROM TAFCLPESQ 
     WHERE NUM_CLPESQ = :CDINC 
      INTO :res;
    
	if(:res = 0) then 	
        INSERT INTO TAFCLPESQ 
		( 
		    NUM_CLPESQ 
            		,CDITE      
			,CDCL       
			,DTPESQ     
			,CDEQP      
			,VLITE      
			,IMPORTADO
			,MSG_IMPORTACAO
			,DTPROC
			,NUPROC
			,CDDRIT
			,CDMARC
		   	,VLCOMP
        )
        VALUES
        (
            :CDINC
            ,:CDITE
            ,:CDCL
            ,:DTPESQ
            ,:CDEQP
            ,:VLITE
            ,'1'
            ,'Exportado com sucesso!'
            ,:DTPROC
            ,:NUPROC
	    ,:CDDRIT
	    ,:CDMARC
	    ,:VLCOMP		
        );

    UPDATE TMVSCLPESQ
	SET
	    IDEXP = '1' 		
    WHERE
	    CDINC = :CDINC ; 	
END

FOR SELECT 
	 		CDINC,  CDCL,   CDPR, 
	 		CDEQP,  DTLEV,  QTDEST, 
	 		DTPROC, NUPROC, CDDRV,
	 		DSMSEX
	 FROM TMVSLVCL	 
     WHERE IDEXP = '0'

	    INTO :CDINC,  :CDCL,   :CDPROD,
			 :CDEQP,  :DTLEV,  :QTDEST,
			 :DTPROC, :NUPROC, :CDDRV,
			 :DSMSEX		
DO    BEGIN
		INSERT INTO TAFLVCL
		(
			NUM_LEVANT,  COD_VENDEDOR,   COD_CLIENTE,
			COD_PRODUTO, DAT_LEVANT,     QTD_ESTOQUE,
			DTPROC, 	  NUPROC,  		  IMPORTADO,   
			MSG_IMPORTACAO, COD_DERIVACAO
		)
		VALUES 
		(
			:CDINC,  :CDEQP, :CDCL,
			:CDPROD, :DTLEV,   :QTDEST,
			:dtproc, :nuproc,  '1',   
			'Exportado com sucesso!', :CDDRV
		);
			
        UPDATE TMVSLVCL	SET IDEXP = '1' WHERE CDINC = :CDINC;
end


FOR 	SELECT 
		 CDINC,  CDEQP,	 DTVIS,
		 QTDCL,	 QTDPED, QTDCNV,
		 INATEN, DTPROC, NUPROC,
	     DSMSEX
     FROM TMVSESTATISTICA 
     WHERE IDEXP = '0'
	    INTO :CDINC,  :CDEQP,  :DTVIS,
		 :QTDCL,  :QTDPED, :QTDCNV,
		 :INATEN, :DTPROC, :NUPROC,
	     :DSMSEX		
DO    BEGIN
		INSERT INTO TAFESTATISTICA
			(
			NUM_ESTATISTICA, COD_VENDEDOR,  DAT_VISITA,
			QTD_CLIENTE,     QTD_PEDIDO,    QTD_CLINCOMPROU,
			IND_ATEND,       DTPROC,        NUPROC,
			IMPORTADO,       MSG_IMPORTACAO
			)
		VALUES 
			(
			:CDINC,  :CDEQP,  :DTVIS,
			:QTDCL,  :QTDPED, :QTDCNV,
			:INATEN, :DTPROC, :NUPROC,
			'1',     'Exportado com sucesso!'
			); 	  
	   UPDATE TMVSESTATISTICA SET IDEXP = '1' WHERE CDINC = :CDINC;
end

FOR 	SELECT	
		 CDINC,  CDCL,	CDEQP,
		 DTNCO,	 IDDIA,	DTPROC,
		 NUPROC, DSMSEX 
	 FROM TMVSCLNCP
     WHERE IDEXP = '0'
	    INTO :CDINC,  :CDCL,  :CDEQP,
		 :DTNCO,  :IDDIA, :DTPROC,
		 :NUPROC, :DSMSEX 
DO    BEGIN
		INSERT INTO TAFCLNCP
			(
			NUM_CLINCOMP, COD_VENDEDOR, COD_CLIENTE,  
			DAT_NCOMPROU, IDF_DIA,   	DTPROC,
			NUPROC,	      IMPORTADO,	MSG_IMPORTACAO
			)
		VALUES 
			(
			:CDINC,	 :CDEQP,  :CDCL,
			:DTNCO,	 :IDDIA,  :DTPROC,
			:NUPROC, '1',     'Exportado com sucesso!'
			);	
	   UPDATE TMVSCLNCP SET IDEXP = '1' WHERE CDINC = :CDINC;
 end
 
 
FOR SELECT	
		CDEQP,  DTATUA, VLSLIN,
		VLSLAT, VLSLVE, DTPROC,
		NUPROC
	FROM
		TMVSSALDOSPOT
	WHERE 
		IDEXP = '0'
	INTO 
		:CDEQP,  :DTATUA, :VLSLIN,
		:VLSLAT, :VLSLVE, :DTPROC,
		:NUPROC
DO
BEGIN
	DELETE FROM TAFSALDOSPOT WHERE CDEQP = :CDEQP;
	
	INSERT INTO TAFSALDOSPOT
	(
		CDEQP,
		VLSLIN,
		VLSLVE,
		DTPROC,
		NUPROC,
		IMPORTADO,
		MSG_IMPORTACAO
	)
	VALUES 
	(
		:CDEQP,  
		:VLSLIN,
		:VLSLVE,
		:DTPROC,
		:NUPROC,
		'1',
		'Exportado com sucesso.'
	);	
	
	UPDATE TMVSSALDOSPOT SET IDEXP = '1' WHERE CDEQP = :CDEQP;
end
 
END;
#@#
#END
