====== pears.GetTempMargin ======
Generated schema reference. Regenerate this page from the SQL unload; keep hand-maintained business notes in the narrative namespace.
===== Original SQL =====
create function "pears"."GetTempMargin"(
/* Application Maintained Function / Procedure - DO NOT EDIT*/
in "chargerate" double,in "payrate" double,in "temp" smallint,in "taxmethod" smallint,in "directengagement" smallint,
in "actualNotPercent" smallint,in "holpayPercent" double,in "NIPercent" double,in "NIonHolpay" smallint )
returns char(10)
deterministic
begin
declare "margin" double;
declare "HolidayCost" double;
declare "NICost" double;
if "isnull"("temp",0) = 0 then
return null
end if;
set "margin" = "chargerate"-"isnull"("payrate",0.0);
if "isnull"("taxmethod",1) = 1 and "isnull"("directengagement",0) = 0 and "payrate" is not null then
set "HolidayCost" = "isnull"("holpayPercent",0)*"PayRate"/100;
set "NICost" = "isnull"("NIPercent",0)*(if "isnull"("NIonHolPay",0) = 1 then "PayRate"+"HolidayCost" else "PayRate" endif)/100;
set "margin" = "margin"-("HolidayCost"+"NICost")
end if;
if "isnull"("actualNotPercent",0) = 1 or "isnull"("Margin",0) = 0 or "isnull"("chargerate",0) = 0 then
return "str"("Margin",10,2)
else
return "string"("str"(("Margin"/"ChargeRate")*100,8,2),' %')
end if
end