INSERT INTO EAC_APP_VERSION (DB_VERSION, BIN_VERSION, UPGRADE_DATE, USER_NAME, IS_FINISHED) VALUES (5, '1.0.0.0', CURRENT_TIMESTAMP, 'ADMIN', 0);
^
@COMMENT:Dodanie tabeli konfiguracji ksef
^
CREATE TABLE EAC_KSEF_CERT (
	ID_UZYTKOWNIKA	 INTEGER NOT NULL,	
	CERTYFIKAT		 BLOB SUB_TYPE 0,
	KLUCZ			 BLOB SUB_TYPE 0,
	HASLO			 VARCHAR(50)
);
^
ALTER TABLE EAC_KSEF_CERT ADD CONSTRAINT PK_EAC_KSEF_CERT PRIMARY KEY (ID_UZYTKOWNIKA);
^
@COMMENT:Dodanie tabeli nagłówków faktur ksef
^
CREATE TABLE EAC_KSEF_FAKT_NAG (
	ID						INTEGER NOT NULL,
	issueDate				DATE,	
	permanentStorageDate	TIMESTAMP,
	invoicingDate			TIMESTAMP,
	acquisitionDate			TIMESTAMP,
	ksefNumber				VARCHAR(50),
	invoiceNumber			VARCHAR(30),
	seller_nip				VARCHAR(20),
	seller_name				VARCHAR(250),
	buyer_identifier_type	VARCHAR(20),
	buyer_identifier_value	VARCHAR(50),
	buyer_name				VARCHAR(250),		
	netAmount				DECIMAL(18, 4),
	grossAmount				DECIMAL(18, 4),
	vatAmount				DECIMAL(18, 4),
	currency				VARCHAR(3),
	invoicingMode			VARCHAR(20),
	invoiceType				VARCHAR(20),
	formCode_systemCode		VARCHAR(20),
	formCode_schemaVersion	VARCHAR(20),
	formCode_value			VARCHAR(20),
	isSelfInvoicing			SMALLINT,
	hasAttachment			SMALLINT,
	invoiceHash				VARCHAR(100),
	internalStatus			SMALLINT,
	internalStatusDate		TIMESTAMP,
	internalStatusUser		VARCHAR(40),
	internalError			VARCHAR(500)
);
^
ALTER TABLE EAC_KSEF_FAKT_NAG ADD CONSTRAINT PK_EAC_KSEF_FAKT_NAG PRIMARY KEY (ID);
^
ALTER TABLE EAC_KSEF_FAKT_NAG ADD CONSTRAINT UQ_EAC_KSEF_FAKT_NAG UNIQUE (ksefNumber);
^
CREATE GENERATOR EAC_KSEF_FAKT_NAG_ID_GEN;
^
CREATE TRIGGER BI_EAC_KSEF_FAKT_NAG_ID FOR EAC_KSEF_FAKT_NAG
ACTIVE BEFORE INSERT
POSITION 0
AS
BEGIN
  IF (NEW.ID IS NULL) THEN
      NEW.ID = GEN_ID(EAC_KSEF_FAKT_NAG_ID_GEN, 1);
END
^
@COMMENT:Dodanie tabeli podmiotów trzecich faktur ksef
^
CREATE TABLE EAC_KSEF_FAKT_NAG_PDT (
	ID						INTEGER NOT NULL,
	ID_KSEF_FAKT_NAG		INTEGER NOT NULL,
	identifier_type			VARCHAR(20),
	identifier_value		VARCHAR(20),
	sName					VARCHAR(250),
	sRrole					SMALLINT
);
^
ALTER TABLE EAC_KSEF_FAKT_NAG_PDT ADD CONSTRAINT PK_EAC_KSEF_FAKT_NAG_PDT PRIMARY KEY (ID);
^
CREATE INDEX EAC_KSEF_FAKT_NAG_PDT_IDX1 ON EAC_KSEF_FAKT_NAG_PDT(ID_KSEF_FAKT_NAG);
^
CREATE GENERATOR EAC_KSEF_FAKT_NAG_PDT_ID_GEN;
^
CREATE TRIGGER BI_EAC_KSEF_FAKT_NAG_PDT_ID FOR EAC_KSEF_FAKT_NAG_PDT
ACTIVE BEFORE INSERT
POSITION 0
AS
BEGIN
  IF (NEW.ID IS NULL) THEN
      NEW.ID = GEN_ID(EAC_KSEF_FAKT_NAG_PDT_ID_GEN, 1);
END
^
@COMMENT:Dodanie tabeli danych faktur ksef
^
CREATE TABLE EAC_KSEF_FAKT_DANE (
	ID		INTEGER NOT NULL,
	DANE	BLOB SUB_TYPE 0
);
^
ALTER TABLE EAC_KSEF_FAKT_DANE ADD CONSTRAINT PK_EAC_KSEF_FAKT_DANE PRIMARY KEY (ID);
^
@COMMENT:Odblokowanie bazy danych
^
UPDATE EAC_APP_VERSION SET IS_FINISHED = 1 WHERE DB_VERSION = 5;