Storing Mathematical Formulas
Posted in 1995
I am looking for a way to store mathematical formulas in a database so that
a user can edit them whenever necessary, without having to get into the
code. Following is an example of a formula that we would like to be able
to store.
******************************************************************************
#############CALCULATE ENERGY COST##################
IF mnbill.type2_use IS NOT NULL OR mnbill.type3_use IS NOT NULL THEN
let ecost2 = mnbill.type2_use * pr_rate.demnd_chg1
if ecost2 is null then
let ecost2 = 0
end if
if mnbill.type3_use is not null then
let tmpuse3 = (((mnbill.type3_use/mnbill.type1_use)
- .4843) * mnbill.type2_use)
if tmpuse3 > 0 then
let ecost3 = tmpuse3 * pr_rate.reactive_chg
else
let ecost3 = 0
end if
end if
let buse1 = (mnbill.type1_use * (mnbill.type2_use/buse2))
if buse1 < (buse2 * pr_rate.energy_us1) then
let ecost1 = buse1 * pr_rate.energy_chg1
else
let tmpuse = buse2 * pr_rate.energy_us1
let ecost1 = ecost1 + (tmpuse * pr_rate.energy_chg1)
let buse1 = buse1 - tmpuse
if buse1 > buse2 * pr_rate.energy_us2 then
let tmpuse = buse2 * pr_rate.energy_us2
let ecost1 = ecost1 + (tmpuse * pr_rate.energy_chg2)
let buse1 = buse1 - tmpuse
else
let ecost1 = ecost1 + (buse1 * pr_rate.energy_chg2)
let buse1 = buse1 - (buse2 * pr_rate.energy_us2)
let buse1 = 0
end if
if buse1 > 0 then
let ecost1 = ecost1 + (buse1 * pr_rate.energy_chg3)
end if
end if
let ecost1 = ecost1 + (seasonal * pr_rate.energy_chg3)
else
if mnbill.type1_use > pr_rate.energy_us2 then
let tmpuse = mnbill.type1_use - pr_rate.energy_us2
let ecost1 = tmpuse * pr_rate.energy_chg3
end if
if mnbill.type1_use > pr_rate.energy_us1 then
if mnbill.type1_use > pr_rate.energy_us2 then
let tmpuse = pr_rate.energy_us2 - pr_rate.energy_us1
else
let tmpuse = mnbill.type1_use - pr_rate.energy_us1
end if
let ecost1 = ecost1 + (tmpuse * pr_rate.energy_chg2)
end if
let ecost1 = ecost1 + (pr_rate.energy_chg1 * pr_rate.energy_us1)
let tmpuse = mnbill.type1_use - buse1
let ecost1 = ecost1 + (seasonal * pr_rate.energy_chg3)
end if
if mnbill.util_type = "W" then
let secost = ecost1 + ecost2 + mnbill.mtr_rental
else
let secost = ecost1 + ecost2 + ecost3
end if
let secost = secost + pr_rate.cust_chrg
let tcost = secost
if tcost is null then
let tcost = 0
end if
#############calculate Taxes ############################
FOREACH tax_cur INTO pr_bldgrate.*
SELECT * INTO pr_tax.* FROM taxtable a
WHERE a.tax_code = pr_bldgrate.rate_code
let tcost = tcost + (secost * (pr_tax.tax_rate/100))
END FOREACH
###############ADD SPECIAL NON TAXABLE ITEMS##############
let tcost = tcost + mnbill.spcl_facility
let tcost = tcost + mnbill.substat_equip
let tcost = tcost + mnbill.mtr_rental
******************************************************************************
Any help would greatly be appreciated.
Thank You,
--
============================================================================
David Schnardthorst System Administrator * Phone: (314)838-6839
Stryder Communications, Inc. * Fax: (314)838-8527
869 St. Francois * E-Mail: ds3721@strydr.com