TEST of Web Calculator
Appizy
(function ($, Formula) { window.APY = window.APY || {}; APY.formulas = {}; APY.formulas.s0r5c3 = function() { APY.set('s0r5c3',RANGE([0,5,2])/RANGE([0,14,2])) } APY.formulas.s0r6c3 = function() { APY.set('s0r6c3',RANGE([0,6,2])/RANGE([0,14,2])) } APY.formulas.s0r7c3 = function() { APY.set('s0r7c3',RANGE([0,7,2])/RANGE([0,14,2])) } APY.formulas.s0r8c3 = function() { APY.set('s0r8c3',RANGE([0,8,2])/RANGE([0,14,2])) } APY.formulas.s0r9c3 = function() { APY.set('s0r9c3',RANGE([0,9,2])/RANGE([0,14,2])) } APY.formulas.s0r10c3 = function() { APY.set('s0r10c3',RANGE([0,10,2])/RANGE([0,14,2])) } APY.formulas.s0r11c3 = function() { APY.set('s0r11c3',RANGE([0,11,2])/RANGE([0,14,2])) } APY.formulas.s0r12c3 = function() { APY.set('s0r12c3',RANGE([0,12,2])/RANGE([0,14,2])) } APY.formulas.s0r13c3 = function() { APY.set('s0r13c3',RANGE([0,13,2])/RANGE([0,14,2])) } APY.formulas.s0r14c2 = function() { APY.set('s0r14c2',Formula.SUM(RANGE([0,5,2],[0,13,2]))) } APY.formulas.s0r14c3 = function() { APY.set('s0r14c3',Formula.SUM(RANGE([0,5,3],[0,13,3]))) } APY.formulas.s0r20c2 = function() { APY.set('s0r20c2',Formula.IF(RANGE([0,20,1])=="","",RANGE([0,20,1])*3)) } APY.formulas.s0r20c3 = function() { APY.set('s0r20c3',RANGE([0,20,2])/RANGE([0,34,2])) } APY.formulas.s0r21c2 = function() { APY.set('s0r21c2',Formula.IF(RANGE([0,21,1])=="","",RANGE([0,21,1])*3)) } APY.formulas.s0r21c3 = function() { APY.set('s0r21c3',RANGE([0,21,2])/RANGE([0,34,2])) } APY.formulas.s0r22c2 = function() { APY.set('s0r22c2',Formula.IF(RANGE([0,22,1])=="","",RANGE([0,22,1])*3)) } APY.formulas.s0r22c3 = function() { APY.set('s0r22c3',RANGE([0,22,2])/RANGE([0,34,2])) } APY.formulas.s0r23c2 = function() { APY.set('s0r23c2',Formula.IF(RANGE([0,23,1])=="","",RANGE([0,23,1])*3)) } APY.formulas.s0r23c3 = function() { APY.set('s0r23c3',RANGE([0,23,2])/RANGE([0,34,2])) } APY.formulas.s0r24c2 = function() { APY.set('s0r24c2',Formula.IF(RANGE([0,24,1])=="","",RANGE([0,24,1])*3)) } APY.formulas.s0r24c3 = function() { APY.set('s0r24c3',RANGE([0,24,2])/RANGE([0,34,2])) } APY.formulas.s0r25c2 = function() { APY.set('s0r25c2',Formula.IF(RANGE([0,25,1])=="","",RANGE([0,25,1])*3)) } APY.formulas.s0r25c3 = function() { APY.set('s0r25c3',RANGE([0,25,2])/RANGE([0,34,2])) } APY.formulas.s0r26c2 = function() { APY.set('s0r26c2',Formula.IF(RANGE([0,26,1])=="","",RANGE([0,26,1])*3)) } APY.formulas.s0r26c3 = function() { APY.set('s0r26c3',RANGE([0,26,2])/RANGE([0,34,2])) } APY.formulas.s0r27c2 = function() { APY.set('s0r27c2',Formula.IF(RANGE([0,27,1])=="","",RANGE([0,27,1])*3)) } APY.formulas.s0r27c3 = function() { APY.set('s0r27c3',RANGE([0,27,2])/RANGE([0,34,2])) } APY.formulas.s0r28c2 = function() { APY.set('s0r28c2',Formula.IF(RANGE([0,28,1])=="","",RANGE([0,28,1])*3)) } APY.formulas.s0r28c3 = function() { APY.set('s0r28c3',RANGE([0,28,2])/RANGE([0,34,2])) } APY.formulas.s0r29c2 = function() { APY.set('s0r29c2',Formula.IF(RANGE([0,29,1])=="","",RANGE([0,29,1])*3)) } APY.formulas.s0r29c3 = function() { APY.set('s0r29c3',RANGE([0,29,2])/RANGE([0,34,2])) } APY.formulas.s0r30c2 = function() { APY.set('s0r30c2',Formula.IF(RANGE([0,30,1])=="","",RANGE([0,30,1])*3)) } APY.formulas.s0r30c3 = function() { APY.set('s0r30c3',RANGE([0,30,2])/RANGE([0,34,2])) } APY.formulas.s0r31c2 = function() { APY.set('s0r31c2',Formula.IF(RANGE([0,31,1])=="","",RANGE([0,31,1])*3)) } APY.formulas.s0r31c3 = function() { APY.set('s0r31c3',RANGE([0,31,2])/RANGE([0,34,2])) } APY.formulas.s0r32c2 = function() { APY.set('s0r32c2',Formula.IF(RANGE([0,32,1])=="","",RANGE([0,32,1])*3)) } APY.formulas.s0r32c3 = function() { APY.set('s0r32c3',RANGE([0,32,2])/RANGE([0,34,2])) } APY.formulas.s0r33c2 = function() { APY.set('s0r33c2',Formula.IF(RANGE([0,33,1])=="","",RANGE([0,33,1])*3)) } APY.formulas.s0r33c3 = function() { APY.set('s0r33c3',RANGE([0,33,2])/RANGE([0,34,2])) } APY.formulas.s0r34c1 = function() { APY.set('s0r34c1',Formula.SUM(RANGE([0,20,1],[0,33,1]))) } APY.formulas.s0r34c2 = function() { APY.set('s0r34c2',Formula.SUM(RANGE([0,20,2],[0,33,2]))) } APY.formulas.s0r34c3 = function() { APY.set('s0r34c3',Formula.SUM(RANGE([0,20,3],[0,33,3]))) } APY.formulas.s0r36c2 = function() { APY.set('s0r36c2',RANGE([0,34,2])+RANGE([0,14,2])) } function step0() { APY.formulas.s0r14c2();APY.formulas.s0r20c2();APY.formulas.s0r21c2();APY.formulas.s0r22c2();APY.formulas.s0r23c2();APY.formulas.s0r24c2();APY.formulas.s0r25c2();APY.formulas.s0r26c2();APY.formulas.s0r27c2();APY.formulas.s0r28c2();APY.formulas.s0r29c2();APY.formulas.s0r30c2();APY.formulas.s0r31c2();APY.formulas.s0r32c2();APY.formulas.s0r33c2();APY.formulas.s0r34c1(); } function step1() { APY.formulas.s0r5c3();APY.formulas.s0r6c3();APY.formulas.s0r7c3();APY.formulas.s0r8c3();APY.formulas.s0r9c3();APY.formulas.s0r10c3();APY.formulas.s0r11c3();APY.formulas.s0r12c3();APY.formulas.s0r13c3();APY.formulas.s0r34c2(); } function step2() { APY.formulas.s0r14c3();APY.formulas.s0r20c3();APY.formulas.s0r21c3();APY.formulas.s0r22c3();APY.formulas.s0r23c3();APY.formulas.s0r24c3();APY.formulas.s0r25c3();APY.formulas.s0r26c3();APY.formulas.s0r27c3();APY.formulas.s0r28c3();APY.formulas.s0r29c3();APY.formulas.s0r30c3();APY.formulas.s0r31c3();APY.formulas.s0r32c3();APY.formulas.s0r33c3();APY.formulas.s0r36c2(); } function step3() { APY.formulas.s0r34c3(); } function run_calc(){ step0();step1();step2();step3()} window.onload = function () { $('input, select').on('change', function () { $(this).setFormattedValue(); run_calc(); });
$('input:enabled').each(function () { $(this).setFormattedValue(); }); run_calc(); };
$.fn.setFormattedValue = function () { var value = $(this).val(); var valueType = $(this).attr('data-value-type'); var valueFormat = $(this).attr('data-format');
var formattedValue = APY.formatValue(value, valueType, valueFormat); this.val(formattedValue); };
APY.getInput = function (value, type) { if (typeof type === 'undefined') type = 'string';
if (type == 'boolean') { value = (value == 'true'); } else if (value.length === 0) { value = ''; } else if (type == 'string') {
if (!isNaN(value) && isFinite(value)) { value = parseFloat(value); } else {
}
} else { old_format = value; value = numeral().unformat(value); } return value; };
APY.set = function (output_name, value, type) { if (window.APY.cells && window.APY.cells.hasOwnProperty(output_name)) { window.APY.cells[output_name] = value; } else { // Set default type if necessary if (typeof type === "undefined") { type = (typeof value === "undefined") ? "string" : typeof value; }
var element = $('[name=' + output_name + ']'); var formats = $(element).data('format');
element.attr('data-value-type', type);
// Format allowed for number, float and percentage if ((type == 'number' || type == 'float' || type == 'percentage' || type == 'currency') && (typeof formats != "undefined")) {
var formats_array = formats.toString().split(";", 3); var nb_format = formats_array.length; if (value == 0 && nb_format == 3) { myformat = formats_array[1]; } else if (value < 0) { myformat = formats_array[0]; } else { myformat = formats_array[nb_format - 1]; } element.val(numeral(value).format(myformat)); } else { element.val(value); } } }; APY.formatValue = function (value, type, formats) { var formattedValue = value; if ((type == 'number' || type == 'float' || type == 'percentage' || type == 'currency') && (typeof formats != "undefined")) { var formats_array = formats.toString().split(";", 3); var nb_format = formats_array.length; if (value == 0 && nb_format == 3) { myformat = formats_array[1]; } else if (value < 0) { myformat = formats_array[0]; } else { myformat = formats_array[nb_format - 1]; } formattedValue = numeral(value).format(myformat); } return formattedValue; }; window.RANGE = function () { var item, value; if (arguments.length == 1) { var cell_ref = 's' + arguments[0][0] + 'r' + arguments[0][1] + 'c' + arguments[0][2]; if (window.APY.cells && window.APY.cells.hasOwnProperty(cell_ref)) { value = window.APY.cells[cell_ref]; } else { item = $('[name=' + cell_ref + ']'); value = item.length > 0 ? APY.getInput(item.val(), item.attr('data-value-type')) : null; }
return value;
} else if (arguments.length == 2) { var head = arguments[0]; var tail = arguments[1]; var values = [];
for (var i = 0; i <= (tail[1] - head[1]); i++) { var row = []; for (var j = 0; j <= tail[2] - head[2]; j++) { cell_ref = 's' + head[0] + 'r' + (head[1] + i) + 'c' + (head[2] + j); if (window.APY.cells && window.APY.cells.hasOwnProperty(cell_ref)) { value = window.APY.cells[cell_ref]; } else { item = $('[name=' + cell_ref + ']'); value = item.length > 0 ? APY.getInput(item.val(), item.attr('data-value-type')) : null; } row.push(value); } values.push(row); } return values; } };
APY.calculate = run_calc;
})(jQuery, formulajs);