--получить код собственного контрагента для приходной накладной или номер С/Ф или номер накладной поставщика.
--MyWhat=1 - код собственного контрагента, 2 - номер накладной поставщика, 3 - номер С/Ф поставщика, 4 - сумма по документу поставщика
--=5 - дата накладной поставщика
create or replace function supermag.get_SMWAYBILLSIN(
ADocType in supermag.smdocuments.doctype%type,
ADocID in supermag.smdocuments.id%type,myWhat in NUMBER) return varchar2 is
res varchar2(255);
res2 NUMBER;
begin
IF (MyWhat=3) THEN
select dd.SUPPLIERINVOICE into res from supermag.SMWayBillsIn dd where dd.ID=ADocID and dd.DOCTYPE=ADocType;
ELSIF (MyWhat=2) THEN
select dd.SUPPLIERDOC into res from supermag.SMWayBillsIn dd where dd.ID=ADocID and dd.DOCTYPE=ADocType;
ELSIF (MyWhat=4) THEN
select dd.SupplDocSum into res from supermag.SMWayBillsIn dd where dd.ID=ADocID and dd.DOCTYPE=ADocType;
ELSIF (MyWhat=5) THEN
select to_char(dd.SUPPLIERDOCCREATE,'DD.MM.YYYY') into res from supermag.SMWayBillsIn dd where dd.ID=ADocID and dd.DOCTYPE=ADocType;
ELSE
IF (ADocType='WI') THEN
select dd.OURSELFCLIENT into res from supermag.SMWayBillsIn dd where dd.ID=ADocID and dd.DOCTYPE=ADocType;
ELSE
select dd.OURSELFCLIENT into res from supermag.SMWayBillsOut dd where dd.ID=ADocID and dd.DOCTYPE=ADocType;
END IF;
END IF;
return res;
end get_SMWAYBILLSIN;
/
commit;
--Получить инфу по фин. обязательству
-- (AWhat=1 - cумма обязательства =2 - достоверно/недостоверно =3 - сумма док. основания )
create or replace function supermag.get_FIN_INFO(
ADocType in supermag.smdocuments.doctype%type,
ADocID in supermag.smdocuments.id%type,AWhat in integer) return number
is
res NUMBER;
res2 NUMBER;
begin
if AWhat = 1 then -- сумма обязательства
select sum(ACCEPTSUM) into res from supermag.SMFINOBLIGATION FF where FF.DOCID=ADocID and FF.DOCTYPE=ADocType;
elsif AWhat = 2 then -- признак достоверности
select IsAdmitted into res from supermag.SMFINOBLIGATION FF where FF.DOCID=ADocID and FF.DOCTYPE=ADocType;
else -- сумма документа-основания
select sum(BASESUM) into res from supermag.SMFINOBLIGATION FF where FF.DOCID=ADocID and FF.DOCTYPE=ADocType;
end if;
return res;
end get_FIN_INFO;
/
commit;