/*ALIAS>prop_db*/

/*SQLStart>1440*/
 ALTER TABLE RENTTYPES
  ADD RT_SMETACCNO_DDS ADM_ACCTYPE,
  ADD RT_SMETPARTNO_DDS ADM_PARTTYPE,
  ADD RT_DEBITSMETACCNO ADM_ACCTYPE,
  ADD RT_DEBITSMETPARTNO ADM_PARTTYPE,
  ADD RT_DEBITSMETACCNO_D ADM_ACCTYPE,
  ADD RT_DEBITSMETPARTNO_D ADM_PARTTYPE,
  ADD RT_TBOTEXT VARCHAR(20) 
/*SQLStop>1440*/

/*SQLStart>1441*/
ALTER TABLE RENTTYPES
ADD RT_SMETDDS CHAR(1)
DEFAULT 'F'
/*SQLStop>1441*/

/*SQLStart>1442*/
ALTER TABLE DOCUMENTS
ADD DOC_SMETDDS CHAR(1)
DEFAULT 'F'
/*SQLStop>1442*/

/*SQLStart>1443*/
ALTER TABLE ANECS
ADD AN_SMETDDS CHAR(1)
DEFAULT 'F'
/*SQLStop>1443*/

/*SQLStart>1444*/
update DOCUMENTS
 set DOC_SMETDDS = "F" where doc_type in (1002, 1004, 1400);
/*SQLStop>1444*/

/*SQLStart>1445*/
UPDATE ANECS set
AN_SMETDDS = "F";
/*SQLStop>1445*/

/*SQLStart>1446*/
ALTER TRIGGER SET_ANECS1
AS
BEGIN
  IF( New.Doc_Type  = 1002) THEN
    BEGIN
      Insert into Anecs (AN_id,An_NUM,AN_Data,AN_Price,AN_DTStart,AN_DTStop,AN_COMENT, 
                        AN_LType, AN_LPercent, AN_LMax, AN_DDS, AN_Valuta, AN_PayDay, AN_FreeDate, AN_SmetPrice, AN_SMETDDS) 
      Values(NEW.DOC_ID,1,NEW.DOC_DATASTART,NEW.Doc_Price,NEW.DOC_DataStart,"1.1.3000","Begin",
             NEW.DA_LType, NEW.DA_LPercent, NEW.DA_RF2, NEW.DA_DDS, NEW.DA_Valuta, NEW.DOC_PayDay, NEW.DOC_DataStart, new.Doc_SmetPrice, new.DOC_SMETDDS); 
    END
END
/*SQLStop>1446*/

/*SQLStart>1448*/
CREATE TABLE WAITPAYMENTS_KONS (
    WP_DOCID   INTEGER NOT NULL,
    WP_YEAR    SMALLINT NOT NULL,
    WP_MONTH   SMALLINT NOT NULL,
    WP_NUM     SMALLINT NOT NULL,
    WP_INID    INTEGER,
    WP_STATE   SMALLINT,
    WP_GENSUM  ACS_DOUBLE,
    WP_GENDDS  ACS_DOUBLE,
    WP_FACTOR  ACS_DOUBLE,
    WP_DATE    DATE,
    WP_ID      INTEGER NOT NULL
);

/*SQLStop>1448*/


/*SQLStart>1449*/
ALTER TABLE WAITPAYMENTS_KONS ADD PRIMARY KEY (WP_DOCID, WP_YEAR, WP_MONTH, WP_NUM);
/*SQLStop>1449*/


/*SQLStart>1450*/
CREATE INDEX WPINID_IDX2 ON WAITPAYMENTS_KONS (WP_INID);
/*SQLStop>1450*/


/*SQLStart>1451*/
CREATE UNIQUE INDEX WP_ID_IDX2 ON WAITPAYMENTS_KONS (WP_ID);
/*SQLStop>1451*/

/*SQLStart>1452*/
GRANT ALL ON WAITPAYMENTS_KONS TO PUBLIC
/*SQLStop>1452*/

/*SQLStart>1453*/
CREATE GENERATOR WP_ID_GEN2;
/*SQLStop>1453*/

/*SQLStart>1454*/
SET GENERATOR WP_ID_GEN2 TO 0;
/*SQLStop>1454*/

/*DLLStart>1455*/
DLLName=upd107.dll
DLLProc=fixinwaitpay
/*DLLStop>1455*/