/*ALIAS>prop_db*/
/*Hist_TBL>SQL_UPDATES_INCOMES*/

/*ManyStart>7038*/
CREATE INDEX TAKING_IDX_STATE
ON TAKING (T_STATE);

CREATE INDEX TAKING_IDX_REASONDATE
ON TAKING (T_ReasonDate);

CREATE INDEX TAKING_IDX_VALIDTODATE
ON TAKING (T_VALIDTODATE);

CREATE INDEX TAKING_IDX_TT_ID
ON TAKING (T_TTID);

CREATE INDEX NUMKIND_NOM_IDX1
ON NUMKIND_NOM (NUMKIND_ACTIVE);
/*ManyStop>7038*/

/*SQLStart>7039*/
CREATE OR ALTER trigger takingbi for taking
active before insert position 0
as
begin
  if ((NEW.T_ID is null) or (NEW.T_ID = 0) ) then
    NEW.T_ID = GEN_ID(TakingID_GEN, 1);
  NEW.T_GenerateDate = CURRENT_TIMESTAMP;
  if (NEW.T_ReasonDate < "01.01.1900") then
    NEW.T_ReasonDate =  CURRENT_TIMESTAMP;
  if (NEW.T_MustPayDate < "01.01.1900") then
    NEW.T_MustPayDate =  "01.01.2100";
  if (NEW.T_ValidToDate < "01.01.1900") then
    NEW.T_ValidToDate =  "01.01.2100";

  if ((NEW.T_APPID1 = 0) and (NEW.T_APPID2 = 0) and (NEW.T_APPID3 = 0) and (NEW.T_APPID3 = 0)) then
    NEW.T_APPID1 = NEW.T_ID;
end
/*SQLStop>*/