/*ALIAS>prop_db*/

/*SQLStart>1540*/
ALTER TABLE INDETAIL
ADD ID_FACTOR NUMERIC(15,2)
/*SQLStop>1540*/

/*SQLStart>1541*/
CREATE PROCEDURE FILLINDETAILVALUES
AS
declare variable in_id integer ;
declare variable factor numeric(15,2) ;
begin
  for select in_id, in_factor from invoices
      into :in_id, :factor
  do
    begin
       update indetail set id_factor = :factor where id_id = :in_id;
    end
  suspend;
end
/*SQLStop>1541*/

/*SQLStart>1542*/
execute procedure FillIndetailValues;
/*SQLStop>1542*/

/*SQLStart>1543*/
drop procedure FillIndetailValues;
/*SQLStop>1543*/

/*SQLStart>1544*/
ALTER PROCEDURE INDETAILADD(
    ID_ID INTEGER,
    ID_VID INTEGER,
    ID_SUM NUMERIC(15,2),
    ID_DDS NUMERIC(15,2),
    ID_DDSPERCENT NUMERIC(15,2),
    ID_LIHVI NUMERIC(15,2),
    ID_ALL NUMERIC(15,2),
    ID_TEXT VARCHAR(250),
    ID_ACCNO VARCHAR(8),
    ID_PARTNO VARCHAR(18),
    ID_BIN VARCHAR(10),
    ID_ACCNO_D VARCHAR(8),
    ID_PARTNO_D VARCHAR(18),
    ID_BIN_D VARCHAR(10),
    ID_ACCNO_L VARCHAR(8),
    ID_PARTNO_L VARCHAR(18),
    ID_BIN_L VARCHAR(10),
    ID_DTSTART DATE,
    ID_DTSTOP DATE,
    ID_VID2 INTEGER,
    ID_PAYTYPE CHAR(1),
    ID_SUBTYPE CHAR(1),
    ID_MEASURE VARCHAR(6),
    ID_SINGLEPRICE NUMERIC(15,3),
    ID_QUANTITY NUMERIC(15,3),
    ID_UNITID INTEGER,
    ID_UNITID_L INTEGER,
    ID_UNITID_D INTEGER,
    ID_FACTOR NUMERIC(15, 2))
AS
declare variable ID_No integer;
begin
  /* wzima sledwasht nomer za element ot taq faktura */
  select max(ID_No) from InDetail
  where ID_ID = :ID_ID into :ID_No;
  if (ID_No is null) then
    ID_No = 1;
  else
    ID_No = ID_No + 1;

  insert into InDetail (ID_ID, ID_NO, ID_VID, ID_SUM, ID_DDS,
                        ID_DDSPercent, ID_LIHVI, ID_ALL, ID_TEXT, ID_ACCNO,
                        ID_PARTNO, ID_BIN, ID_ACCNO_D, ID_PARTNO_D, ID_BIN_D,
                        ID_ACCNO_L, ID_PARTNO_L, ID_BIN_L,
                        ID_DTSTART, ID_DTSTOP, ID_REAL,
                        ID_VID2, ID_PayType, ID_Anul, ID_SubType,
                        ID_Measure, ID_SINGLEPRICE, ID_QUANTITY,ID_UNITID,ID_UNITID_L,ID_UNITID_D,
                        ID_FACTOR)
  values               (:ID_ID, :ID_NO, :ID_VID, :ID_SUM, :ID_DDS,
                        :ID_DDSPercent, :ID_LIHVI, :ID_ALL, :ID_TEXT, :ID_ACCNO,
                        :ID_PARTNO, :ID_BIN, :ID_ACCNO_D, :ID_PARTNO_D, :ID_BIN_D,
                        :ID_ACCNO_L, :ID_PARTNO_L, :ID_BIN_L,
                        :ID_DTSTART, :ID_DTSTOP, "F",
                        :ID_VID2, :ID_PayType, "A", :ID_SubType,
                        :ID_Measure, :ID_SINGLEPRICE, :ID_QUANTITY,:ID_UNITID,:ID_UNITID_L,:ID_UNITID_D,
                        :ID_FACTOR);
  exit;
end
/*SQLStop>1544*/


/*SQLStart>1545*/
ALTER TABLE CHARACTERISTICS_DOC
ADD CD_CHECKED VARCHAR(1)
DEFAULT 'F' 

/*SQLStop>1545*/

/*SQLStart>1546*/
DROP TRIGGER INCOMETRIGGERINS;
/*SQLStop>1546*/

/*SQLStart>1547*/
DROP TRIGGER INCOMETRIGGERUPD;
/*SQLStop>1547*/

/*SQLStart>1548*/
DROP TRIGGER SET_ANECS1
/*SQLStop>1548*/

/*SQLStart>1549*/
update values_calc set vc_for = 2 where vc_for = 3;
/*SQLStop>1549*/

