ðÒÉ ÐÏÐÙÔËÅ ÕÄÁÌÅÎÉÑ ÚÁÐÉÓÉ ÐÏÌÕÞÁÀ ÏÛÉÂËÕ: attempted update of read-only
column. (×ÏÏÂÝÅ ÎÅ ÐÏÎÉÍÁÀ, ÏÔËÕÄÁ Õ ÍÅÎÑ × ÂÁÚÅ ÒÉÄÏÎÌÉ ÐÏÌÑ)
ðÒÉ ÜÔÏÍ ÜÔÁ ÖÅ ÂÁÚÁ ÂÅÚ ÐÒÏÂÌÅÍ ÒÁÂÏÔÁÅÔ ÎÁ FB1.5.3, ÐÏÍÏÇÉÔÅ ÒÁÚÏÂÒÁÔØÓÑ.
îÁ ÔÁÂÌÉÃÕ ÎÁ×ÅÛÁÎ ÔÒÉÇÇÅÒ:
CREATE TRIGGER DOCUM_ACCOUNTS_BD FOR DOCUM_ACCOUNTS
ACTIVE BEFORE DELETE POSITION 0
as
declare variable id_firm integer;
declare variable date_docum date;
declare variable id_store integer;
begin
select ID_Firm, Date_Docum, ID_Store from Documents where
ID_Docum=old.ID_Docum into :ID_Firm, :Date_Docum, :ID_Store;
execute procedure sp_Update_Result_Analist
(old.ID_Debit,old.ID_DebitAnalist,:Date_Docum,:ID_Firm,:ID_Store,null,-old.Sum_Up,0);
If (old.ID_Currency is not null) then
execute procedure sp_Update_Result_Analist
(old.ID_Debit,old.ID_DebitAnalist,:Date_Docum,:ID_Firm,:ID_Store,old.ID_Currency,-old.Sum_Up,0);
execute procedure sp_Update_Result_Analist
(old.ID_Credit,old.ID_CreditAnalist,:Date_Docum,:ID_Firm,:ID_Store,null,0,-old.Sum_Up);
If (old.ID_Currency is not null) then
execute procedure sp_Update_Result_Analist
(old.ID_Credit,old.ID_CreditAnalist,:Date_Docum,:ID_Firm,:ID_Store,old.ID_Currency,0,-old.Sum_Up);
end
CREATE PROCEDURE SP_UPDATE_RESULT_ANALIST(
ID_ACCOUNT INTEGER,
ID_ANALISTITEM INTEGER,
DATE_DOCUM DATE,
ID_FIRM INTEGER,
ID_STORE INTEGER,
ID_CURRENCY INTEGER,
SUMDEBITREAL NUMERIC(11,4),
SUMCREDITREAL NUMERIC(11,4))
AS
declare variable M integer;
declare variable Period date;
declare variable Saldo numeric(11,4);
declare variable TempDate date;
declare variable FlagQuit smallint;
declare variable SumDebit numeric(11,4);
declare variable SumCredit numeric(11,4);
declare variable State_Analist integer;
begin
If (:ID_Account is not null) then begin
SumDebit=SumDebitReal;
SumCredit=SumCreditReal;
Saldo=0;
M=0;
FlagQuit=1;
select State_Analist from Balance_Accounts where ID_Account=:ID_Account
into :State_Analist;
TempDate=Date_Docum;
If (State_Analist<>1) then ID_Firm=null;
If (State_Analist<>2) then Date_Docum=null;
If (State_Analist<>3) then ID_AnalistItem=null;
If (State_Analist<>4) then ID_Store=null;
While (FlagQuit>0) do begin
If (M=1) then begin
Saldo=Z(SumDebit)-Z(SumCredit);
SumDebit=0;
SumCredit=0;
Date_Docum=null;
end
if (M>0) then TempDate = IncDate(:TempDate, 0, :m, 0);
IF (DaysBetween(:TempDate,current_date)<0) then break;
Period=DateToPeriodDate(:TempDate); /* ×ÒÅÍÅÎÎÏ Datepart(yy,@TempDate)
*100+ datepart(mm,@TempDate) */
If (Exists (SELECT Period from Result_Analist
where (ID_Account=:ID_Account) and (Period=:Period) and
((ID_Firm=:Id_Firm) or ((:Id_Firm is null) and (Id_Firm
is null))) and
((ID_Store=:Id_Store) or ((:Id_Store is null) and
(Id_Store is null))) and
((Date_Docum=:Date_Docum) or ((:Date_Docum is null) and
(Date_Docum is null))) and
((ID_Currency=:ID_Currency) or ((:Id_Currency is null)
and (Id_Currency is null)))and
((ID_Analist_Item=:ID_AnalistItem) or ((:ID_AnalistItem is
null) and (ID_Analist_Item is null))))) then
Update Result_Analist set COB=COB+:SumCredit,
DOB=DOB+:SumDebit , Saldo=Saldo+:Saldo
where (ID_Account=:ID_Account) and (Period=:Period) and
((ID_Currency=:ID_Currency) or ((:Id_Currency is null)
and (Id_Currency is null)))and
((ID_Firm=:Id_Firm) or ((:Id_Firm is null) and (Id_Firm
is null))) and
((ID_Store=:Id_Store) or ((:Id_Store is null) and (Id_Store
is null))) and
((Date_Docum=:Date_Docum) or ((:Date_Docum is null) and
(Date_Docum is null))) and
((ID_Analist_Item=:ID_AnalistItem) or ((:ID_AnalistItem is
null) and (ID_Analist_Item is null)));
else begin
IF (State_Analist=2) /* áÎÁÌÉÔÉËÁ ÐÏ äÁÔÅ äÏËÕÍÅÎÔÁ */ then
select first 1 Saldo_Debit-Saldo_Credit+DOB-COB from Result_Main
where (ID_Account=:ID_Account) and (Period<:Period)
and ((ID_Currency=:ID_Currency) or ((:Id_Currency is null) and
(Id_Currency is null)))
order by period desc
into :Saldo;
else
select first 1 /* äÒÕÇÁÑ ÁÎÁÌÉÔÉËÁ */ Saldo+DOB-COB from
Result_Analist
where (ID_Account=:ID_Account) and (Period<:Period) and
((ID_Firm=:Id_Firm) or ((:Id_Firm is null) and (Id_Firm is
null))) and
((ID_Store=:Id_Store) or ((:Id_Store is null) and (Id_Store
is null))) and
((ID_Currency=:ID_Currency) or ((:Id_Currency is null) and
(Id_Currency is null))) and
((Date_Docum=:Date_Docum) or ((:Date_Docum is null) and
(Date_Docum is null))) and
((ID_Analist_Item=:ID_AnalistItem) or ((:ID_AnalistItem is
null) and (ID_Analist_Item is null)))
order by period DESC
into :Saldo;
If (Saldo is null) then saldo=0;
If (Not((Saldo=0) and (SumDebit=0) and (SumCredit=0))) then
Insert into Result_Analist
(Period, ID_Account, ID_Firm, ID_Store, ID_Currency,
ID_Analist_Item ,Date_Docum, DOB, COB, Saldo)
Values(:Period, :ID_Account, :ID_Firm, :ID_Store,
:ID_Currency, :ID_AnalistItem, :Date_Docum, :SumDebit, :SumCredit, :Saldo);
end
M=M+1;
end /* end While @FlagQuit>0 */
end /* If ID_Account is null */
end