/* Server version: WI-V6.3.3.18185 Firebird 2.1 
   SQLDialect: 3. ODS: 11.0. Forced writes: On. Sweep inteval: 20000.
   Page size: 4096. Cache pages: 9500 (38000 Kb). Read-only: False. */
SET SQL DIALECT 3;

/* Create Table... */
CREATE TABLE SMETKA_LINE_COMPLETE(ID_SMETKA_LINE ID_TYPE NOT NULL,
DT_COMPLETE DATE_TIME DEFAULT current_timestamp);


/* Create Procedure... */
SET TERM ^ ;

CREATE PROCEDURE SMETKA_LINE_COMPLETE_MODIFY(ID_SMETKA_LINE INTEGER,
IS_COMPLETE SMALLINT)
 AS
 BEGIN EXIT; END
^


/* Create Primary Key... */
SET TERM ; ^

ALTER TABLE SMETKA_LINE_COMPLETE ADD CONSTRAINT PK_SMETKA_LINE_COMPLETE PRIMARY KEY (ID_SMETKA_LINE);

/* Create Foreign Key... */
RECONNECT;

ALTER TABLE SMETKA_LINE_COMPLETE ADD CONSTRAINT FK_SMETKA_LINE_COMPLETE FOREIGN KEY (ID_SMETKA_LINE) REFERENCES SMETKA_LINE (ID_SMETKA_LINE) ON UPDATE CASCADE ON DELETE CASCADE;

/* Alter Procedure... */
/* empty dependent procedure body */
/* Clear: BILL_POST_ADD$PDA for: BILL_POST_ADD */
SET TERM ^ ;


/* Restore proc. body: SMETKA_LINE_COMPLETE_MODIFY */
ALTER PROCEDURE SMETKA_LINE_COMPLETE_MODIFY(ID_SMETKA_LINE INTEGER,
IS_COMPLETE SMALLINT)
 AS
begin
  if (:is_complete = 1) then begin
    if (not exists(select * from SMETKA_LINE_COMPLETE where ID_SMETKA_LINE = :id_smetka_line)) then
      insert into SMETKA_LINE_COMPLETE (ID_SMETKA_LINE) values (:id_smetka_line);
  end else if (:is_complete = 0) then begin
    delete from SMETKA_LINE_COMPLETE
    where ID_SMETKA_LINE = :id_smetka_line;
  end
end
^

/* Alter Procedure... */
SET TERM ; ^

