- 20


DECLARE VARIABLE IsLgot SMALLINT;

DECLARE VARIABLE TTime INTEGER;

DECLARE VARIABLE LTime INTEGER;

BEGIN

EXECUTE PROCEDURE TalksGetPay(APhone, ACallDate, ACallTime, AHowLong)

RETURNING_VALUES :APay, :ACalculated, :IsLgot;

SELECT Code FROM TalksPay WHERE (Phone = :APhone) AND (CallDate = :ACallDate)

INTO PayCode;

IF (:ACalculated = 0) THEN EXIT;

IF (:IsLgot = 0) THEN BEGIN

TTime = AHowLong;

LTime = 0;

END

ELSE BEGIN

LTime = AHowLong;

TTime = 0;

END

IF (:PayCode IS NULL) THEN BEGIN

EXECUTE PROCEDURE PrGenTalksPay RETURNING_VALUES :PayCode;

INSERT INTO TalksPay (Code, Phone, CallDate, TotalSum, TotalFullTime, TotalLgotTime)

VALUES (:PayCode, :APhone, :ACallDate, :APay, :TTime, :LTime);

END

ELSE BEGIN

UPDATE TalksPay

SET TotalSum = TotalSum+:APay,

TotalFullTime = TotalFullTime+:TTime,

TotalLgotTime = TotalLgotTime+:LTime

WHERE Code = :PayCode;

END

END ^

CREATE PROCEDURE UslGetOwnerTax(AOwner INTEGER, AUsl INTEGER, ADate DATE)

RETURNS (ATax FLOAT,

AProcNach FLOAT,

ANalog FLOAT)

AS

DECLARE VARIABLE ACategory INTEGER;

BEGIN

SELECT Category FROM PhonesOwners

WHERE (PKey = :AOwner) AND (:ADate BETWEEN BegDate AND EndDate)

INTO :ACategory;

SELECT Tax, NachCoeff, Nalog FROM UslLgots

WHERE (Usl = :AUsl) AND (:ADate BETWEEN BegDate AND EndDate)

INTO :ATax, :AProcNach, :ANalog;

EXIT;

END