PageSourceSearch

https://www.beeboxsystems.co.uk/wp-content/plugins/smart-forms/js/formBuilder/formula/formula.js?ver=5

js beeboxsystems.co.uk collected 2026-10-07 03:54:38 UTC 9,015 bytes, 240 lines download raw bytes

1var RedNaoFormula = /** @class */ (function () {
2    function RedNaoFormula(formElement, formula) {
3        this.FormElement = formElement;
4        this.Formula = formula;
5    }
6    RedNaoFormula.prototype.GetRemote = function () {
7        if (this._remote == null)
8            this._remote = new SmartFormsRemote();
9        return this._remote;
10    };
11    RedNaoFormula.prototype.FieldUsedInFormula = function (fieldName) {
12        if (this.FormElement._parentId == fieldName)
13            return false;
14        for (var i = 0; i < this.Formula.FieldsUsed.length; i++) {
15            if (fieldName == this.Formula.FieldsUsed[i])
16                return true;
17        }
18        if (this.FormElement.FieldContainer != null && typeof this.Formula.SubFieldsUsed != 'undefined')
19            for (var i = 0; i < this.Formula.SubFieldsUsed.length; i++) {
20                var subField = this.Formula.SubFieldsUsed[i];
21                var index = subField.Index.toString().trim();
22                if (index == 'current')
23                    index = this.FormElement.RowIndex;
24                if (fieldName == subField.Id + '_row_' + index)
25                    return true;
26            }
27        return false;
28    };
29    ;
30    RedNaoFormula.prototype.UpdateFieldWithValue = function (value) {
31        var _this = this;
32        try {
33            var calculatedValue = this.GetValueFromFormula(value);
34            if (calculatedValue instanceof Promise) {
35                this.FormElement.ShowLoadingBox();
36                calculatedValue.then(function (result) { _this.FormElement.HideLoadingBox(); _this.ProcessResult(result); });
37            }
38            else {
39                this.ProcessResult(calculatedValue);
40            }
41        }
42        catch (exception) {
43        }
44    };
45    ;
46    RedNaoFormula.prototype.GetValueFromFormula = function (values) {
47        return RedNaoEventManager.Publish('CalculateFormula', { FormulaInstance: this, Formula: this.Formula, Values: values });
48    };
49    RedNaoFormula.prototype.ProcessResult = function (calculatedValue) {
50        if (typeof calculatedValue == 'number' && isNaN(calculatedValue))
51            calculatedValue = 0;
52        var previousValue = RedNaoBasicManipulatorInstance.GetValue(this.FormElement.Options, this.Formula.PropertyName, this.Formula.additionalInformation);
53        RedNaoBasicManipulatorInstance.SetValue(this.FormElement.Options, this.Formula.PropertyName, calculatedValue, this.Formula.additionalInformation);
54        this.FormElement.RefreshElement(this.Formula.PropertyName, previousValue);
55        this.FormElement.FirePropertyChanged();
56    };
57    return RedNaoFormula;
58}());
59function RNFRound(value, decimals) {
60    return value.toFixed(decimals);
61}
62function RNUserName() {
63    return smartFormsUserName;
64}
65function RNFirstName() {
66    return smartFormsFirstName;
67}
68function RNLastName() {
69    return smartFormsLastName;
70}
71function RNEmail() {
72    return smartFormsEmail;
73}
74function RNIf(condition, trueValue, falseValue) {
75    if (condition)
76        return trueValue;
77    return falseValue;
78}
79function RNMinutesDiff(timePicker1, timePicker2) {
80    if (typeof (timePicker1.numericalValue) != 'undefined' && typeof timePicker2 != 'undefined') {
81        var time1 = timePicker1.numericalValue;
82        var time2 = timePicker2.numericalValue;
83        var timeDif = time2 - time1;
84        return timeDif / 60 / 1000;
85    }
86    return 0;
87}
88function RNDateDiff(date1, date2) {
89    var value1 = date1.numericalValue;
90    var value2 = date2.numericalValue;
91    if (value1 == 0 || value2 == 0)
92        return 0;
93    date1 = new Date(value1);
94    date2 = new Date(value2);
95    var result = date2 - date1;
96    if (result == 0)
97        return 0;
98    return Math.round(result / 1000 / 60 / 60 / 24);
99}
100var SmartFormsRemote = /** @class */ (function () {
101    function SmartFormsRemote() {
102    }
103    SmartFormsRemote.prototype.Post = function (url, args) {
104        return this.Execute('post', url, args);
105    };
106    SmartFormsRemote.prototype.Get = function (url, args) {
107        return this.Execute('get', url, args);
108    };
109    SmartFormsRemote.prototype.Execute = function (name, url, args) {
110        var _this = this;
111        if (args instanceof window.SmartFormBasicDataStore) {
112            args = Object.assign({}, args);
113        }
114        var createdPromise = new Promise(function (resolve) {
115            var id = _this.GenerateRequestId(url, args);
116            var cachedResult = SmartFormsRemote.cache.find(function (x) { return x.Id == id; });
117            if (cachedResult != null && cachedResult.Result != undefined) {
118                resolve(cachedResult.Result);
119            }
120            else {
121                if (cachedResult != null) {
122                    cachedResult.Pending.push(resolve);
123                }
124                else {
125                    cachedResult = { Result: undefined, Id: id, Pending: [] };
126                    cachedResult.Pending.push(resolve);
127                    SmartFormsRemote.cache.push(cachedResult);
128                    SmartFormsRemote.cache.push({ Id: id, Result: undefined, Pending: [resolve] });
129                    rnJQuery[name](url, args)
130                        .done(function (result) {
131                        if (_this.lastPromise != createdPromise)
132                            return;
133                        try {
134                            result = JSON.parse(result);
135                        }
136                        catch (exception) {
137                        }
138                        var cachedResult = SmartFormsRemote.cache.find(function (x) { return x.Id == id; });
139                        cachedResult.Result = result;
140                        var callback = cachedResult.Pending.pop();
141                        while (callback != null) {
142                            callback(cachedResult.Result);
143                            callback = cachedResult.Pending.pop();
144                        }
145                    })
146                        .fail(function (e) {
147                        console.log('An error ocurred processing the json request', e);
148                    });
149                }
150            }
151        });
152        return this.lastPromise = createdPromise;
153    };
154    SmartFormsRemote.prototype.GenerateRequestId = function (url, args) {
155        var parsedArgs = '';
156        if (args != null) {
157            try {
158                parsedArgs = JSON.stringify(args);
159            }
160            catch (ex) {
161                parsedArgs = args.toString();
162            }
163        }
164        return url + '@@' + parsedArgs;
165    };
166    SmartFormsRemote.cache = [];
167    return SmartFormsRemote;
168}());
169function RNPMT(rate, nper, pv, fv, type) { if (!fv)
170    fv = 0; if (!type)
171    type = 0; if (rate == 0)
172    return -(pv + fv) / nper; var pvif = Math.pow(1 + rate, nper); var pmt = rate / (pvif - 1) * -(pv * pvif + fv); if (type == 1) {
173    pmt /= (1 + rate);
174} ; return pmt; }
175;
176function RNIPMT(pv, pmt, rate, per) { var tmp = Math.pow(1 + rate, per); return 0 - (pv * tmp * rate + pmt * (tmp - 1)); }
177;
178function RNPPMT(rate, per, nper, pv, fv, type) { if (per < 1 || (per >= nper + 1))
179    return null; var pmt = RNPMT(rate, nper, pv, fv, type); var ipmt = RNIPMT(pv, pmt, rate, per - 1); return pmt - ipmt; }
180function RNXNPV(rate, values, dates) {
181    var result = 0;
182    for (var i = 0; i < values.length; i++) {
183        result += values[i] / Math.pow(1 + rate, RNDateDiff(dates[i], dates[0]) / 365);
184    }
185    return result;
186}
187;
188function RNXIRR(values, guess) {
189    if (!guess)
190        guess = 0.1;
191    var x1 = 0.0;
192    var x2 = guess;
193    var f1 = RNXNPV(x1, values, null);
194    var f2 = RNXNPV(x2, values, null);
195    for (var i = 0; i < 100; i++) {
196        if ((f1 * f2) < 0.0)
197            break;
198        if (Math.abs(f1) < Math.abs(f2)) {
199            f1 = RNXNPV(x1 += 1.6 * (x1 - x2), values, null);
200        }
201        else {
202            f2 = RNXNPV(x2 += 1.6 * (x2 - x1), values, null);
203        }
204    }
205    ;
206    if ((f1 * f2) > 0.0)
207        return null;
208    var f = RNXNPV(x1, values, null);
209    if (f < 0.0) {
210        var rtb = x1;
211        var dx = x2 - x1;
212    }
213    else {
214        var rtb = x2;
215        var dx = x1 - x2;
216    }
217    ;
218    for (var i = 0; i < 100; i++) {
219        dx *= 0.5;
220        var x_mid = rtb + dx;
221        var f_mid = RNXNPV(x_mid, values, null);
222        if (f_mid <= 0.0)
223            rtb = x_mid;
224        if ((Math.abs(f_mid) < 1.0e-6) || (Math.abs(dx) < 1.0e-6))
225            return x_mid;
226    }
227    ;
228    return null;
229}
230function RNFV(rate, nper, pmt, pv, type) {
231    var pow = Math.pow(1 + rate, nper), fv;
232    if (rate) {
233        fv = (pmt * (1 + rate * type) * (1 - pow) / rate) - pv * pow;
234    }
235    else {
236        fv = -1 * (pv + pmt * nper);
237    }
238    return fv.toFixed(2);
239}
240//# sourceMappingURL=formula.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.