/******************************************************************************/
/***               Generated by IBExpert 12/03/2019 15:42:04                ***/
/******************************************************************************/

/******************************************************************************/
/***      Following SET SQL DIALECT is just for the Database Comparer       ***/
/******************************************************************************/
SET SQL DIALECT 3;

CREATE GENERATOR PQ_PD_PRODUTOS_HISTORICO;

/******************************************************************************/
/***                                 Tables                                 ***/
/******************************************************************************/



CREATE TABLE PD_PRODUTOS_HISTORICO (
    SEQPEDIDO     INTEGER NOT NULL,
    DTEMISSAO     DATE,
    NRDOC         VARCHAR(11) NOT NULL,
    PRODUTO       VARCHAR(14) CHARACTER SET WIN1252,
    CODPROD       INTEGER,
    DESCRPROD     VARCHAR(50),
    QUANTIDADE    NUMERIC(15,6),
    UNITARIO      NUMERIC(14,4),
    PRCTOTAL      NUMERIC(14,4),
    DESCONTO      NUMERIC(14,4),
    PRCCUSTODIA   NUMERIC(14,4),
    TERMINAL      INTEGER NOT NULL,
    DEVOLUCAO     VARCHAR(5) CHARACTER SET WIN1252,
    ID            INTEGER DEFAULT 0 NOT NULL,
    EMPRESA       INTEGER,
    COMPLEMENTO   VARCHAR(20),
    NCM           VARCHAR(8),
    CFOP          VARCHAR(5),
    PIS           NUMERIC(12,4) default 0,
    COFINS        NUMERIC(12,4) default 0,
    ICMS          NUMERIC(12,4) default 0,
    CST           VARCHAR(3),
    UNIDADE       VARCHAR(15),
    CSOSN         VARCHAR(5),
    BICO          INTEGER default 0,
    CEST          VARCHAR(10),
    DESCONTOPORC  NUMERIC(14,4),
    LANCDESC      VARCHAR(1) DEFAULT 'A' NOT NULL,
    ACRESCIMO     NUMERIC(14,2)
);




/******************************************************************************/
/***                              Primary Keys                              ***/
/******************************************************************************/

ALTER TABLE PD_PRODUTOS_HISTORICO ADD CONSTRAINT PK_PD_PRODUTOS_HISTORICO_ID PRIMARY KEY (ID);



/******************************************************************************/
/***                                Triggers                                ***/
/******************************************************************************/


SET TERM ^ ;



/******************************************************************************/
/***                          Triggers for tables                           ***/
/******************************************************************************/



/* Trigger: PEDPROD_BI */
CREATE OR ALTER TRIGGER INSPD_PRODUTOS_HISTORICO FOR PD_PRODUTOS_HISTORICO
ACTIVE BEFORE INSERT POSITION 0
AS
begin
   NEW.ID=GEN_ID(PQ_PD_PRODUTOS_HISTORICO,1);
end
^


SET TERM ; ^



/******************************************************************************/
/***                               Privileges                               ***/
/******************************************************************************/

