Входные параметры
Параметр | Тип | Описание |
---|---|---|
BEGDATE |
DATE |
|
ENDDATE |
DATE |
|
STORAGEID |
INTEGER |
|
REPORTTYPE |
INTEGER |
|
RECIPEID |
INTEGER |
|
Выходные параметры
Параметр | Тип | Описание |
---|---|---|
COLUMN0 |
VARCHAR(50) |
|
COLUMN1 |
VARCHAR(50) |
|
TROWS |
VARCHAR(50) |
|
CELLS |
DOUBLE PRECISION |
|
Описание
(Нет описания для процедуры FORM117_TOP_TEST)
Определение
CREATE PROCEDURE FORM117_TOP_TEST(
BEGDATE DATE,
ENDDATE DATE,
STORAGEID INTEGER,
REPORTTYPE INTEGER,
RECIPEID INTEGER)
RETURNS (
COLUMN0 VARCHAR(50),
COLUMN1 VARCHAR(50),
TROWS VARCHAR(50),
CELLS DOUBLE PRECISION)
AS
declare variable cropid integer;
declare variable croptypeid integer;
declare variable crop_sum double precision;
declare variable acolumn0 varchar(50);
declare variable acolumn1 varchar(50);
declare variable acells double precision;
declare variable qualitytypeid integer;
declare variable factorvalue double precision;
declare variable factorsource double precision;
declare variable bpcount integer;
declare variable bp0 double precision;
declare variable bp1 double precision;
declare variable bp2 double precision;
declare variable bp3 double precision;
declare variable bp4 double precision;
declare variable bp5 double precision;
declare variable bp6 double precision;
declare variable bp7 double precision;
declare variable bp8 double precision;
declare variable bp9 double precision;
declare variable bpsum double precision;
declare variable column0_p0 varchar(50);
declare variable column0_p1 varchar(50);
declare variable column0_p2 varchar(50);
declare variable column0_p3 varchar(50);
declare variable column0_p4 varchar(50);
declare variable column0_p5 varchar(50);
declare variable column0_p6 varchar(50);
declare variable column0_p7 varchar(50);
declare variable column0_p8 varchar(50);
declare variable column0_p9 varchar(50);
declare variable column1_p0 varchar(50);
declare variable column1_p1 varchar(50);
declare variable column1_p2 varchar(50);
declare variable column1_p3 varchar(50);
declare variable column1_p4 varchar(50);
declare variable column1_p5 varchar(50);
declare variable column1_p6 varchar(50);
declare variable column1_p7 varchar(50);
declare variable column1_p8 varchar(50);
declare variable column1_p9 varchar(50);
declare variable column0_w0 varchar(50);
declare variable column0_w1 varchar(50);
declare variable column0_w2 varchar(50);
declare variable column0_w3 varchar(50);
declare variable column0_w4 varchar(50);
declare variable column0_w5 varchar(50);
declare variable column0_w6 varchar(50);
declare variable column0_w7 varchar(50);
declare variable column0_w8 varchar(50);
declare variable column0_w9 varchar(50);
declare variable column1_w0 varchar(50);
declare variable column1_w1 varchar(50);
declare variable column1_w2 varchar(50);
declare variable column1_w3 varchar(50);
declare variable column1_w4 varchar(50);
declare variable column1_w5 varchar(50);
declare variable column1_w6 varchar(50);
declare variable column1_w7 varchar(50);
declare variable column1_w8 varchar(50);
declare variable column1_w9 varchar(50);
declare variable bwcount integer;
declare variable bw0 double precision;
declare variable bw1 double precision;
declare variable bw2 double precision;
declare variable bw3 double precision;
declare variable bw4 double precision;
declare variable bw5 double precision;
declare variable bw6 double precision;
declare variable bw7 double precision;
declare variable bw8 double precision;
declare variable bw9 double precision;
declare variable bwsum double precision;
declare variable a0 double precision;
declare variable a1 double precision;
declare variable a2 double precision;
declare variable a3 double precision;
declare variable a4 double precision;
declare variable a5 double precision;
declare variable a6 double precision;
declare variable a7 double precision;
declare variable a8 double precision;
declare variable a9 double precision;
declare variable asum double precision;
declare variable apsum double precision;
declare variable awsum double precision;
begin
------------------------ Базисы
TRows = 'Базисный вых.';
Column0 = 'Факт.
кач.';
Column1 = Null;
Cells = Null;
suspend;
Column0 = 'Расч.
влия';
suspend;
crop_sum = 0;
BPCount = -1;
bwcount = -1;
bwsum = 0;
for
select crop.shortcropname, class.shortclassname, gradebasisclass.basisvalue, crop.croptypeid, class.cropid
from gradebasis
left join gradebasisclass on gradebasis.gradebasisid = gradebasisclass.gradebasisid
left join class on gradebasisclass.classid = class.classid
left join crop on crop.cropid = class.cropid
where gradebasis.storageid = :StorageID and gradebasis.state = 1
into :acolumn0, :acolumn1, :acells, :croptypeid, :cropid
do begin
if (:croptypeid = 2) then begin
crop_sum = crop_sum + :acells;
BPCount = :BPCount + 1;
end
else begin
BWCount = :BWCount + 1;
bwsum = bwsum + :acells;
if (:crop_sum is not null) then begin
column0 = 'Продук-
ции';
column1 = Null;
cells = :crop_sum;
bpsum = :crop_sum;
suspend;
crop_sum = Null;
end
end
column0 = :acolumn0;
column1 = :acolumn1;
cells = :acells;
suspend;
if (:bwcount > -1) then begin
if (:bwcount = 0) then begin
bw0 = :cells;
column0_w0 = :column0;
column1_w0 = :column1;
end
else if (:bwcount = 1) then begin
bw1 = :cells;
column0_w1 = :column0;
column1_w1 = :column1;
end
else if (:bwcount = 2) then begin
bw2 = :cells;
column0_w2 = :column0;
column1_w2 = :column1;
end
else if (:bwcount = 3) then begin
bw3 = :cells;
column0_w3 = :column0;
column1_w3 = :column1;
end
else if (:bwcount = 4) then begin
bw4 = :cells;
column0_w4 = :column0;
column1_w4 = :column1;
end
else if (:bwcount = 5) then begin
bw5 = :cells;
column0_w5 = :column0;
column1_w5 = :column1;
end
else if (:bwcount = 6) then begin
bw6 = :cells;
column0_w6 = :column0;
column1_w6 = :column1;
end
else if (:bwcount = 7) then begin
bw7 = :cells;
column0_w7 = :column0;
column1_w7 = :column1;
end
else if (:bwcount = 8) then begin
bw8 = :cells;
column0_w8 = :column0;
column1_w8 = :column1;
end
else if (:bwcount = 9) then begin
bw9 = :cells;
column0_w9 = :column0;
column1_w9 = :column1;
end
end
else begin
if (:bpcount = 0) then begin
bp0 = :cells;
column0_p0 = :column0;
column1_p0 = :column1;
end
else if (:bpcount = 1) then begin
bp1 = :cells;
column0_p1 = :column0;
column1_p1 = :column1;
end
else if (:bpcount = 2) then begin
bp2 = :cells;
column0_p2 = :column0;
column1_p2 = :column1;
end
else if (:bpcount = 3) then begin
bp3 = :cells;
column0_p3 = :column0;
column1_p3 = :column1;
end
else if (:bpcount = 4) then begin
bp4 = :cells;
column0_p4 = :column0;
column1_p4 = :column1;
end
else if (:bpcount = 5) then begin
bp5 = :cells;
column0_p5 = :column0;
column1_p5 = :column1;
end
else if (:bpcount = 6) then begin
bp6 = :cells;
column0_p6 = :column0;
column1_p6 = :column1;
end
else if (:bpcount = 7) then begin
bp7 = :cells;
column0_p7 = :column0;
column1_p7 = :column1;
end
else if (:bpcount = 8) then begin
bp8 = :cells;
column0_p8 = :column0;
column1_p8 = :column1;
end
else if (:bpcount = 9) then begin
bp9 = :cells;
column0_p9 = :column0;
column1_p9 = :column1;
end
end
end
Column0 = 'Итого';
Column1 = Null;
Cells = 100;
suspend;
------------------------ Признаки качества
for
select
qualitydata.qualitytypeid,
min(qualitytypes.qualityshortname),
cast(Sum(qualitydata.qualityvalue * uwoutacts.weight) / Sum(nullif(uwoutacts.weight, 0) + qualitydata.qualityvalue - qualitydata.qualityvalue) as numeric(9,2)),
case
when qualitydata.qualitytypeid = 14 then
cast(
coalesce(
Sum((select qualityvalue from qualitydata where qualityid = uwoutacts.afterqualityid and qualitytypeid = 16) * uwoutacts.weight)
/ Sum(uwoutacts.weight + (select qualityvalue from qualitydata where qualityid = uwoutacts.afterqualityid and qualitytypeid = 16) - (select qualityvalue from qualitydata where qualityid = uwoutacts.afterqualityid and qualitytypeid = 16)),
0) +
Sum(qualitydata.qualityvalue * uwoutacts.weight) / Sum(nullif(uwoutacts.weight, 0) + qualitydata.qualityvalue - qualitydata.qualityvalue)
as numeric(9,2))
when qualitydata.qualitytypeid = 16 then
cast(
coalesce(
Sum((select qualityvalue from qualitydata where qualityid = uwoutacts.afterqualityid and qualitytypeid = 14) * uwoutacts.weight)
/ Sum(uwoutacts.weight + (select qualityvalue from qualitydata where qualityid = uwoutacts.afterqualityid and qualitytypeid = 14) - (select qualityvalue from qualitydata where qualityid = uwoutacts.afterqualityid and qualitytypeid = 14)),
0) +
Sum(qualitydata.qualityvalue * uwoutacts.weight) / Sum(nullif(uwoutacts.weight, 0) + qualitydata.qualityvalue - qualitydata.qualityvalue)
as numeric(9,2))
else cast(Sum(qualitydata.qualityvalue * uwoutacts.weight) / Sum(nullif(uwoutacts.weight, 0) + qualitydata.qualityvalue - qualitydata.qualityvalue) as numeric(9,2))
end
from uwoutacts
left join recipes on (recipes.recipeid = uwoutacts.recipeid)
left join qualitydata on uwoutacts.afterqualityid = qualitydata.qualityid
left join qualitytypes on qualitytypes.qualitytypeid = qualitydata.qualitytypeid
left join quality_get_collection(26, null, null) on qualitydata.qualitytypeid = quality_get_collection.qualitytypeid
where uwoutacts.workingdate between :begdate and :enddate
and uwoutacts.state > -1
and (:reporttype <> 2 or :recipeid = uwoutacts.recipeid)
and recipes.storageid = :storageid
and uwoutacts.afterqualityid is not null
and quality_get_collection.qualitytypeid is not null
group by qualitydata.qualitytypeid, quality_get_collection.sortindex
order by quality_get_collection.sortindex
into :qualitytypeid, :Trows, :cells, :factorsource
do begin
Column0 = 'Факт.
кач.';
column1 = Null;
suspend;
------ Находим коэфициент влияния
factorvalue = Null;
if (:qualitytypeid = 2) then begin
if (:factorsource < 12) then factorvalue = 1.46;
else factorvalue = cast((((14.5 - :factorsource) * 100) / 85.5) * 0.5 as numeric(9,2));
end
else if (:qualitytypeid = 11) then begin
if (:factorsource > 1.85) then factorvalue = cast((factorsource - 1.85) * 18 as numeric(9,2));
end
else if (:qualitytypeid = 7) then begin
if (:cropid = 3) then begin
if (:factorsource < 700) then factorvalue = cast((700 - :factorsource) * 0.05 as numeric(9,2));
end
else begin
if (:factorsource < 775) then factorvalue = cast((775 - :factorsource) * 0.05 as numeric(9,2));
end
end
else if (:qualitytypeid = 12) then begin
if (:factorsource < 50) then factorvalue = cast((50 - :factorsource) * 0.05 as numeric(9,2));
end
else if (:qualitytypeid = 13) then begin
if (:factorsource > 1) then factorvalue = cast(:factorsource - 1 as numeric(9,2));
end
else if (:qualitytypeid = 14) then begin
if (:factorsource > 1) then factorvalue = cast((:factorsource - 1) * 0.35 as numeric(9,2));
end
else if (:qualitytypeid = 16) then begin
if (:factorsource > 1) then factorvalue = cast((:factorsource - 1) * 0.18 as numeric(9,2));
end
else factorvalue = :factorsource;
Column0 = 'Расч.
влия';
column1 = Null;
Cells = factorvalue;
suspend;
---------- Распределяем коэфициент влияния на продукцию
if (:bpsum = 0) then bpsum = Null;
apsum = cast((:factorvalue * :bpsum / 100) as numeric(9,2));
if (:bp0 is not null) then a0 = cast(:apsum * :bp0 / (:bpsum) as numeric(9,2));
else a0 = null;
if (:bp1 is not null) then a1 = cast(:apsum * :bp1 / (:bpsum) as numeric(9,2));
else a1 = null;
if (:bp2 is not null) then a2 = cast(:apsum * :bp2 / (:bpsum) as numeric(9,2));
else a2 = null;
if (:bp3 is not null) then a3 = cast(:apsum * :bp3 / (:bpsum) as numeric(9,2));
else a3 = null;
if (:bp4 is not null) then a4 = cast(:apsum * :bp4 / (:bpsum) as numeric(9,2));
else a4 = null;
if (:bp5 is not null) then a5 = cast(:apsum * :bp5 / (:bpsum) as numeric(9,2));
else a5 = null;
if (:bp6 is not null) then a6 = cast(:apsum * :bp6 / (:bpsum) as numeric(9,2));
else a6 = null;
if (:bp7 is not null) then a7 = cast(:apsum * :bp7 / (:bpsum) as numeric(9,2));
else a7 = null;
if (:bp8 is not null) then a8 = cast(:apsum * :bp8 / (:bpsum) as numeric(9,2));
else a8 = null;
if (:bp9 is not null) then a9 = cast(:apsum * :bp9 / (:bpsum) as numeric(9,2));
else a9 = null;
if (:apsum <> coalesce(:a0, 0) + coalesce(:a1, 0) + coalesce(:a2, 0) + coalesce(:a3, 0) + coalesce(:a4, 0) + coalesce(:a5, 0) + coalesce(:a6, 0) + coalesce(:a7, 0) + coalesce(:a8, 0) + coalesce(:a9, 0)) then begin
apsum = :factorvalue * :bpsum / 100;
if (:bp0 is not null) then a0 = cast(:apsum * :bp0 / (:bpsum) as numeric(9,2));
if (:bp1 is not null) then a1 = cast(:apsum * :bp1 / (:bpsum) as numeric(9,2));
if (:bp2 is not null) then a2 = cast(:apsum * :bp2 / (:bpsum) as numeric(9,2));
if (:bp3 is not null) then a3 = cast(:apsum * :bp3 / (:bpsum) as numeric(9,2));
if (:bp4 is not null) then a4 = cast(:apsum * :bp4 / (:bpsum) as numeric(9,2));
if (:bp5 is not null) then a5 = cast(:apsum * :bp5 / (:bpsum) as numeric(9,2));
if (:bp6 is not null) then a6 = cast(:apsum * :bp6 / (:bpsum) as numeric(9,2));
if (:bp7 is not null) then a7 = cast(:apsum * :bp7 / (:bpsum) as numeric(9,2));
if (:bp8 is not null) then a8 = cast(:apsum * :bp8 / (:bpsum) as numeric(9,2));
if (:bp9 is not null) then a9 = cast(:apsum * :bp9 / (:bpsum) as numeric(9,2));
apsum = cast(:apsum as numeric(9,2));
end
if (:apsum <> coalesce(:a0, 0) + coalesce(:a1, 0) + coalesce(:a2, 0) + coalesce(:a3, 0) + coalesce(:a4, 0) + coalesce(:a5, 0) + coalesce(:a6, 0) + coalesce(:a7, 0) + coalesce(:a8, 0) + coalesce(:a9, 0)) then begin
if (coalesce(:a0, 0) > coalesce(:a1, 0) and coalesce(:a0, 0) > coalesce(:a2, 0) and coalesce(:a0, 0) > coalesce(:a3, 0) and coalesce(:a0, 0) > coalesce(:a4, 0) and coalesce(:a0, 0) > coalesce(:a5, 0) and coalesce(:a0, 0) > coalesce(:a6, 0) and coalesce(:a0, 0) > coalesce(:a7, 0) and coalesce(:a0, 0) > coalesce(:a8, 0) and coalesce(:a0, 0) > coalesce(:a9, 0))
then execute procedure form117_calc(:apsum, :a0, :a1, :a2, :a3, :a4, :a5, :a6, :a7, :a8, :a9, null) returning_values :a0;
if (coalesce(:a1, 0) > coalesce(:a0, 0) and coalesce(:a1, 0) > coalesce(:a2, 0) and coalesce(:a1, 0) > coalesce(:a3, 0) and coalesce(:a1, 0) > coalesce(:a4, 0) and coalesce(:a1, 0) > coalesce(:a5, 0) and coalesce(:a1, 0) > coalesce(:a6, 0) and coalesce(:a1, 0) > coalesce(:a7, 0) and coalesce(:a1, 0) > coalesce(:a8, 0) and coalesce(:a1, 0) > coalesce(:a9, 0))
then execute procedure form117_calc(:apsum, :a0, :a1, :a2, :a3, :a4, :a5, :a6, :a7, :a8, :a9, null) returning_values :a1;
if (coalesce(:a2, 0) > coalesce(:a0, 0) and coalesce(:a2, 0) > coalesce(:a1, 0) and coalesce(:a2, 0) > coalesce(:a3, 0) and coalesce(:a2, 0) > coalesce(:a4, 0) and coalesce(:a2, 0) > coalesce(:a5, 0) and coalesce(:a2, 0) > coalesce(:a6, 0) and coalesce(:a2, 0) > coalesce(:a7, 0) and coalesce(:a2, 0) > coalesce(:a8, 0) and coalesce(:a2, 0) > coalesce(:a9, 0))
then execute procedure form117_calc(:apsum, :a0, :a1, :a2, :a3, :a4, :a5, :a6, :a7, :a8, :a9, null) returning_values :a2;
if (coalesce(:a3, 0) > coalesce(:a0, 0) and coalesce(:a3, 0) > coalesce(:a1, 0) and coalesce(:a3, 0) > coalesce(:a2, 0) and coalesce(:a3, 0) > coalesce(:a4, 0) and coalesce(:a3, 0) > coalesce(:a5, 0) and coalesce(:a3, 0) > coalesce(:a6, 0) and coalesce(:a3, 0) > coalesce(:a7, 0) and coalesce(:a3, 0) > coalesce(:a8, 0) and coalesce(:a3, 0) > coalesce(:a9, 0))
then execute procedure form117_calc(:apsum, :a0, :a1, :a2, :a3, :a4, :a5, :a6, :a7, :a8, :a9, null) returning_values :a3;
if (coalesce(:a4, 0) > coalesce(:a0, 0) and coalesce(:a4, 0) > coalesce(:a2, 0) and coalesce(:a4, 0) > coalesce(:a3, 0) and coalesce(:a4, 0) > coalesce(:a1, 0) and coalesce(:a4, 0) > coalesce(:a5, 0) and coalesce(:a4, 0) > coalesce(:a6, 0) and coalesce(:a4, 0) > coalesce(:a7, 0) and coalesce(:a4, 0) > coalesce(:a8, 0) and coalesce(:a4, 0) > coalesce(:a9, 0))
then execute procedure form117_calc(:apsum, :a0, :a1, :a2, :a3, :a4, :a5, :a6, :a7, :a8, :a9, null) returning_values :a4;
if (coalesce(:a5, 0) > coalesce(:a0, 0) and coalesce(:a5, 0) > coalesce(:a2, 0) and coalesce(:a5, 0) > coalesce(:a3, 0) and coalesce(:a5, 0) > coalesce(:a4, 0) and coalesce(:a5, 0) > coalesce(:a1, 0) and coalesce(:a5, 0) > coalesce(:a6, 0) and coalesce(:a5, 0) > coalesce(:a7, 0) and coalesce(:a5, 0) > coalesce(:a8, 0) and coalesce(:a5, 0) > coalesce(:a9, 0))
then execute procedure form117_calc(:apsum, :a0, :a1, :a2, :a3, :a4, :a5, :a6, :a7, :a8, :a9, null) returning_values :a5;
if (coalesce(:a6, 0) > coalesce(:a0, 0) and coalesce(:a6, 0) > coalesce(:a2, 0) and coalesce(:a6, 0) > coalesce(:a3, 0) and coalesce(:a6, 0) > coalesce(:a4, 0) and coalesce(:a6, 0) > coalesce(:a5, 0) and coalesce(:a6, 0) > coalesce(:a1, 0) and coalesce(:a6, 0) > coalesce(:a7, 0) and coalesce(:a6, 0) > coalesce(:a8, 0) and coalesce(:a6, 0) > coalesce(:a9, 0))
then execute procedure form117_calc(:apsum, :a0, :a1, :a2, :a3, :a4, :a5, :a6, :a7, :a8, :a9, null) returning_values :a6;
if (coalesce(:a7, 0) > coalesce(:a0, 0) and coalesce(:a7, 0) > coalesce(:a2, 0) and coalesce(:a7, 0) > coalesce(:a3, 0) and coalesce(:a7, 0) > coalesce(:a4, 0) and coalesce(:a7, 0) > coalesce(:a5, 0) and coalesce(:a7, 0) > coalesce(:a6, 0) and coalesce(:a7, 0) > coalesce(:a1, 0) and coalesce(:a7, 0) > coalesce(:a8, 0) and coalesce(:a7, 0) > coalesce(:a9, 0))
then execute procedure form117_calc(:apsum, :a0, :a1, :a2, :a3, :a4, :a5, :a6, :a7, :a8, :a9, null) returning_values :a7;
if (coalesce(:a8, 0) > coalesce(:a0, 0) and coalesce(:a8, 0) > coalesce(:a2, 0) and coalesce(:a8, 0) > coalesce(:a3, 0) and coalesce(:a8, 0) > coalesce(:a4, 0) and coalesce(:a8, 0) > coalesce(:a5, 0) and coalesce(:a8, 0) > coalesce(:a6, 0) and coalesce(:a8, 0) > coalesce(:a7, 0) and coalesce(:a8, 0) > coalesce(:a1, 0) and coalesce(:a8, 0) > coalesce(:a9, 0))
then execute procedure form117_calc(:apsum, :a0, :a1, :a2, :a3, :a4, :a5, :a6, :a7, :a8, :a9, null) returning_values :a8;
if (coalesce(:a9, 0) > coalesce(:a0, 0) and coalesce(:a9, 0) > coalesce(:a2, 0) and coalesce(:a9, 0) > coalesce(:a3, 0) and coalesce(:a9, 0) > coalesce(:a4, 0) and coalesce(:a9, 0) > coalesce(:a5, 0) and coalesce(:a9, 0) > coalesce(:a6, 0) and coalesce(:a9, 0) > coalesce(:a7, 0) and coalesce(:a9, 0) > coalesce(:a8, 0) and coalesce(:a9, 0) > coalesce(:a1, 0))
then execute procedure form117_calc(:apsum, :a0, :a1, :a2, :a3, :a4, :a5, :a6, :a7, :a8, :a9, null) returning_values :a9;
end
if (:a0 is not null) then begin
column0 = :column0_p0;
column1 = :column1_p0;
Cells = :a0;
suspend;
end
if (:a1 is not null) then begin
column0 = :column0_p1;
column1 = :column1_p1;
Cells = :a1;
suspend;
end
if (:a2 is not null) then begin
column0 = :column0_p2;
column1 = :column1_p2;
Cells = :a2;
suspend;
end
if (:a3 is not null) then begin
column0 = :column0_p3;
column1 = :column1_p3;
Cells = :a3;
suspend;
end
if (:a4 is not null) then begin
column0 = :column0_p4;
column1 = :column1_p4;
Cells = :a4;
suspend;
end
if (:a5 is not null) then begin
column0 = :column0_p5;
column1 = :column1_p5;
Cells = :a5;
suspend;
end
if (:a6 is not null) then begin
column0 = :column0_p6;
column1 = :column1_p6;
Cells = :a6;
suspend;
end
if (:a7 is not null) then begin
column0 = :column0_p7;
column1 = :column1_p7;
Cells = :a7;
suspend;
end
if (:a8 is not null) then begin
column0 = :column0_p8;
column1 = :column1_p8;
Cells = :a8;
suspend;
end
if (:a9 is not null) then begin
column0 = :column0_p9;
column1 = :column1_p9;
Cells = :a9;
suspend;
end
if (:apsum is not null) then begin
column0 = 'Продук-
ции';
column1 = null;
Cells = :apsum;
suspend;
end
---------- Распределяем коэфициент влияния на Отходную продукцию
if (:bwsum = 0) then bwsum = Null;
awsum = cast((:factorvalue * :bwsum / 100) as numeric(9,2));
if (:bw0 is not null) then a0 = cast(:awsum * :bw0 / (:bwsum) as numeric(9,2));
else a0 = null;
if (:bw1 is not null) then a1 = cast(:awsum * :bw1 / (:bwsum) as numeric(9,2));
else a1 = null;
if (:bw2 is not null) then a2 = cast(:awsum * :bw2 / (:bwsum) as numeric(9,2));
else a2 = null;
if (:bw3 is not null) then a3 = cast(:awsum * :bw3 / (:bwsum) as numeric(9,2));
else a3 = null;
if (:bw4 is not null) then a4 = cast(:awsum * :bw4 / (:bwsum) as numeric(9,2));
else a4 = null;
if (:bw5 is not null) then a5 = cast(:awsum * :bw5 / (:bwsum) as numeric(9,2));
else a5 = null;
if (:bw6 is not null) then a6 = cast(:awsum * :bw6 / (:bwsum) as numeric(9,2));
else a6 = null;
if (:bw7 is not null) then a7 = cast(:awsum * :bw7 / (:bwsum) as numeric(9,2));
else a7 = null;
if (:bw8 is not null) then a8 = cast(:awsum * :bw8 / (:bwsum) as numeric(9,2));
else a8 = null;
if (:bw9 is not null) then a9 = cast(:awsum * :bw9 / (:bwsum) as numeric(9,2));
else a9 = null;
if (:awsum <> coalesce(:a0, 0) + coalesce(:a1, 0) + coalesce(:a2, 0) + coalesce(:a3, 0) + coalesce(:a4, 0) + coalesce(:a5, 0) + coalesce(:a6, 0) + coalesce(:a7, 0) + coalesce(:a8, 0) + coalesce(:a9, 0)) then begin
awsum = :factorvalue * :bwsum / 100;
if (:bw0 is not null) then a0 = cast(:awsum * :bw0 / (:bwsum) as numeric(9,2));
if (:bw1 is not null) then a1 = cast(:awsum * :bw1 / (:bwsum) as numeric(9,2));
if (:bw2 is not null) then a2 = cast(:awsum * :bw2 / (:bwsum) as numeric(9,2));
if (:bw3 is not null) then a3 = cast(:awsum * :bw3 / (:bwsum) as numeric(9,2));
if (:bw4 is not null) then a4 = cast(:awsum * :bw4 / (:bwsum) as numeric(9,2));
if (:bw5 is not null) then a5 = cast(:awsum * :bw5 / (:bwsum) as numeric(9,2));
if (:bw6 is not null) then a6 = cast(:awsum * :bw6 / (:bwsum) as numeric(9,2));
if (:bw7 is not null) then a7 = cast(:awsum * :bw7 / (:bwsum) as numeric(9,2));
if (:bw8 is not null) then a8 = cast(:awsum * :bw8 / (:bwsum) as numeric(9,2));
if (:bw9 is not null) then a9 = cast(:awsum * :bw9 / (:bwsum) as numeric(9,2));
awsum = cast(:awsum as numeric(9,2));
end
if (:awsum <> coalesce(:a0, 0) + coalesce(:a1, 0) + coalesce(:a2, 0) + coalesce(:a3, 0) + coalesce(:a4, 0) + coalesce(:a5, 0) + coalesce(:a6, 0) + coalesce(:a7, 0) + coalesce(:a8, 0) + coalesce(:a9, 0)) then begin
if (coalesce(:a0, 0) > coalesce(:a1, 0) and coalesce(:a0, 0) > coalesce(:a2, 0) and coalesce(:a0, 0) > coalesce(:a3, 0) and coalesce(:a0, 0) > coalesce(:a4, 0) and coalesce(:a0, 0) > coalesce(:a5, 0) and coalesce(:a0, 0) > coalesce(:a6, 0) and coalesce(:a0, 0) > coalesce(:a7, 0) and coalesce(:a0, 0) > coalesce(:a8, 0) and coalesce(:a0, 0) > coalesce(:a9, 0))
then execute procedure form117_calc(:awsum, :a0, :a1, :a2, :a3, :a4, :a5, :a6, :a7, :a8, :a9, null) returning_values :a0;
if (coalesce(:a1, 0) > coalesce(:a0, 0) and coalesce(:a1, 0) > coalesce(:a2, 0) and coalesce(:a1, 0) > coalesce(:a3, 0) and coalesce(:a1, 0) > coalesce(:a4, 0) and coalesce(:a1, 0) > coalesce(:a5, 0) and coalesce(:a1, 0) > coalesce(:a6, 0) and coalesce(:a1, 0) > coalesce(:a7, 0) and coalesce(:a1, 0) > coalesce(:a8, 0) and coalesce(:a1, 0) > coalesce(:a9, 0))
then execute procedure form117_calc(:awsum, :a0, :a1, :a2, :a3, :a4, :a5, :a6, :a7, :a8, :a9, null) returning_values :a1;
if (coalesce(:a2, 0) > coalesce(:a0, 0) and coalesce(:a2, 0) > coalesce(:a1, 0) and coalesce(:a2, 0) > coalesce(:a3, 0) and coalesce(:a2, 0) > coalesce(:a4, 0) and coalesce(:a2, 0) > coalesce(:a5, 0) and coalesce(:a2, 0) > coalesce(:a6, 0) and coalesce(:a2, 0) > coalesce(:a7, 0) and coalesce(:a2, 0) > coalesce(:a8, 0) and coalesce(:a2, 0) > coalesce(:a9, 0))
then execute procedure form117_calc(:awsum, :a0, :a1, :a2, :a3, :a4, :a5, :a6, :a7, :a8, :a9, null) returning_values :a2;
if (coalesce(:a3, 0) > coalesce(:a0, 0) and coalesce(:a3, 0) > coalesce(:a1, 0) and coalesce(:a3, 0) > coalesce(:a2, 0) and coalesce(:a3, 0) > coalesce(:a4, 0) and coalesce(:a3, 0) > coalesce(:a5, 0) and coalesce(:a3, 0) > coalesce(:a6, 0) and coalesce(:a3, 0) > coalesce(:a7, 0) and coalesce(:a3, 0) > coalesce(:a8, 0) and coalesce(:a3, 0) > coalesce(:a9, 0))
then execute procedure form117_calc(:awsum, :a0, :a1, :a2, :a3, :a4, :a5, :a6, :a7, :a8, :a9, null) returning_values :a3;
if (coalesce(:a4, 0) > coalesce(:a0, 0) and coalesce(:a4, 0) > coalesce(:a2, 0) and coalesce(:a4, 0) > coalesce(:a3, 0) and coalesce(:a4, 0) > coalesce(:a1, 0) and coalesce(:a4, 0) > coalesce(:a5, 0) and coalesce(:a4, 0) > coalesce(:a6, 0) and coalesce(:a4, 0) > coalesce(:a7, 0) and coalesce(:a4, 0) > coalesce(:a8, 0) and coalesce(:a4, 0) > coalesce(:a9, 0))
then execute procedure form117_calc(:awsum, :a0, :a1, :a2, :a3, :a4, :a5, :a6, :a7, :a8, :a9, null) returning_values :a4;
if (coalesce(:a5, 0) > coalesce(:a0, 0) and coalesce(:a5, 0) > coalesce(:a2, 0) and coalesce(:a5, 0) > coalesce(:a3, 0) and coalesce(:a5, 0) > coalesce(:a4, 0) and coalesce(:a5, 0) > coalesce(:a1, 0) and coalesce(:a5, 0) > coalesce(:a6, 0) and coalesce(:a5, 0) > coalesce(:a7, 0) and coalesce(:a5, 0) > coalesce(:a8, 0) and coalesce(:a5, 0) > coalesce(:a9, 0))
then execute procedure form117_calc(:awsum, :a0, :a1, :a2, :a3, :a4, :a5, :a6, :a7, :a8, :a9, null) returning_values :a5;
if (coalesce(:a6, 0) > coalesce(:a0, 0) and coalesce(:a6, 0) > coalesce(:a2, 0) and coalesce(:a6, 0) > coalesce(:a3, 0) and coalesce(:a6, 0) > coalesce(:a4, 0) and coalesce(:a6, 0) > coalesce(:a5, 0) and coalesce(:a6, 0) > coalesce(:a1, 0) and coalesce(:a6, 0) > coalesce(:a7, 0) and coalesce(:a6, 0) > coalesce(:a8, 0) and coalesce(:a6, 0) > coalesce(:a9, 0))
then execute procedure form117_calc(:awsum, :a0, :a1, :a2, :a3, :a4, :a5, :a6, :a7, :a8, :a9, null) returning_values :a6;
if (coalesce(:a7, 0) > coalesce(:a0, 0) and coalesce(:a7, 0) > coalesce(:a2, 0) and coalesce(:a7, 0) > coalesce(:a3, 0) and coalesce(:a7, 0) > coalesce(:a4, 0) and coalesce(:a7, 0) > coalesce(:a5, 0) and coalesce(:a7, 0) > coalesce(:a6, 0) and coalesce(:a7, 0) > coalesce(:a1, 0) and coalesce(:a7, 0) > coalesce(:a8, 0) and coalesce(:a7, 0) > coalesce(:a9, 0))
then execute procedure form117_calc(:awsum, :a0, :a1, :a2, :a3, :a4, :a5, :a6, :a7, :a8, :a9, null) returning_values :a7;
if (coalesce(:a8, 0) > coalesce(:a0, 0) and coalesce(:a8, 0) > coalesce(:a2, 0) and coalesce(:a8, 0) > coalesce(:a3, 0) and coalesce(:a8, 0) > coalesce(:a4, 0) and coalesce(:a8, 0) > coalesce(:a5, 0) and coalesce(:a8, 0) > coalesce(:a6, 0) and coalesce(:a8, 0) > coalesce(:a7, 0) and coalesce(:a8, 0) > coalesce(:a1, 0) and coalesce(:a8, 0) > coalesce(:a9, 0))
then execute procedure form117_calc(:awsum, :a0, :a1, :a2, :a3, :a4, :a5, :a6, :a7, :a8, :a9, null) returning_values :a8;
if (coalesce(:a9, 0) > coalesce(:a0, 0) and coalesce(:a9, 0) > coalesce(:a2, 0) and coalesce(:a9, 0) > coalesce(:a3, 0) and coalesce(:a9, 0) > coalesce(:a4, 0) and coalesce(:a9, 0) > coalesce(:a5, 0) and coalesce(:a9, 0) > coalesce(:a6, 0) and coalesce(:a9, 0) > coalesce(:a7, 0) and coalesce(:a9, 0) > coalesce(:a8, 0) and coalesce(:a9, 0) > coalesce(:a1, 0))
then execute procedure form117_calc(:awsum, :a0, :a1, :a2, :a3, :a4, :a5, :a6, :a7, :a8, :a9, null) returning_values :a9;
end
if (:a0 is not null) then begin
column0 = :column0_w0;
column1 = :column1_w0;
Cells = :a0;
suspend;
end
if (:a1 is not null) then begin
column0 = :column0_w1;
column1 = :column1_w1;
Cells = :a1;
suspend;
end
if (:a2 is not null) then begin
column0 = :column0_w2;
column1 = :column1_w2;
Cells = :a2;
suspend;
end
if (:a3 is not null) then begin
column0 = :column0_w3;
column1 = :column1_w3;
Cells = :a3;
suspend;
end
if (:a4 is not null) then begin
column0 = :column0_w4;
column1 = :column1_w4;
Cells = :a4;
suspend;
end
if (:a5 is not null) then begin
column0 = :column0_w5;
column1 = :column1_w5;
Cells = :a5;
suspend;
end
if (:a6 is not null) then begin
column0 = :column0_w6;
column1 = :column1_w6;
Cells = :a6;
suspend;
end
if (:a7 is not null) then begin
column0 = :column0_w7;
column1 = :column1_w7;
Cells = :a7;
suspend;
end
if (:a8 is not null) then begin
column0 = :column0_w8;
column1 = :column1_w8;
Cells = :a8;
suspend;
end
if (:a9 is not null) then begin
column0 = :column0_w9;
column1 = :column1_w9;
Cells = :a9;
suspend;
end
end
end