So I’m not sure what all this “reducedTax”, “reducedNet”, “reducedGross” jargon is about, however, this is what I would be interested in seeing…
taxName taxRate taxable tax total
T1 15.00 10.43 1.57 12.00
T2 18.00 2.54 0.46 3.00
- - 12.98 2.02 15.00
Background:
- Tax “T1” is 15%
- Tax “T2” is 18%
My prices include the Tax already, so I need to “backout” the tax to get the Taxable Amount.
Test Data:
Sell 2 items:
-
$12 item which includes 15% tax, so the Taxable Amount is actually 10.43
and the applied Tax Amount is 1.57
(which is 15% of 10.43
), which totals 12.00
-
$3 item which includes 18% tax, so the Taxable Amount is actually 2.54
and the applied Tax Amount is 0.46
(which is 18% of 2.54
), which totals 3.00
Final Output:
taxName taxRate taxable tax total
T1 15.00 10.43 1.57 12.00
T2 18.00 2.54 0.46 3.00
- - 12.98 2.02 15.00
Not sure if that is the same as what you want, but here it is:
Name: Taxes
Handler: taxes
Script:
function taxTable(ta1,ta2) {
// validate input parms
ta1 = typeof(ta1)==='undefined' || ta1=='' ? '0' : ta1;
ta2 = typeof(ta2)==='undefined' || ta2=='' ? '0' : ta2;
dlg.ShowMessage("PARMS\r\nTA1:"+ta1 +"\r\nTA2:"+ta2);
// convert parms from String to Number
ta1 = Helper.ToNumber(ta1);
ta2 = Helper.ToNumber(ta2);
dlg.ShowMessage("ToNumber()\r\nTA1:"+ta1 +"\r\nTA2:"+ta2);
// load parms Array
var parms = [];
parms.push(ta1);
parms.push(ta2);
// load taxes Array (rates will be updated later via SQL)
var taxes = [];
taxes.push({"name":"T1","rate":"1"});
taxes.push({"name":"T2","rate":"1"});
var taxmsg = 'TAXDATA';
// use SQL to update Tax Rates in the taxes Array
for (var t=0; t<taxes.length; t++) {
var taxName = taxes[t].name;
var SQL = "SELECT [Id],[Name],[Rate],[Rate],[Rounding],[AccountTransactionType_Id] FROM [TaxTemplates] WHERE [Name]='"+taxName+"'";
var res = sql.Exec(SQL);
var taxdata = res[0].split(',');
taxes[t].name = taxdata[1];
taxes[t].rate = Helper.ToNumber(taxdata[2]);
taxmsg += "\r\n"+taxes[t].name + ":" + taxes[t].rate;
}
dlg.ShowMessage(taxmsg);
// load taxTable Array
var taxTable = [];
for (var t=0; t<taxes.length; t++) {
var taxableAmount = parms[t] / (1 + (taxes[t].rate/100));
var tax = parms[t] - taxableAmount;
taxTable.push({"name":taxes[t].name,"rate":taxes[t].rate,"taxableAmount":taxableAmount,"tax":tax,"total":parms[t]});
}
// initialize total vars
var taxableTotal = 0.00;
var taxTotal = 0.00;
var total = 0.00;
// build output
var text = "<J00>taxName|taxRate|taxable|tax|total" + "\n";
for (var t=0; t<taxTable.length; t++) {
text += "<J00>"+taxTable[t].name + "|";
text += Helper.Format(taxTable[t].rate) + "|";
text += Helper.Format(taxTable[t].taxableAmount) + "|";
text += Helper.Format(taxTable[t].tax) + "|";
text += Helper.Format(taxTable[t].total) + "\n";
taxableTotal += taxTable[t].taxableAmount;
taxTotal += taxTable[t].tax;
total += taxTable[t].total;
}
text += "<J00>-|-|"+Helper.Format(taxableTotal)+"|"+Helper.Format(taxTotal)+"|"+Helper.Format(total);
return text;
}
Sample Call:
{CALL:taxes.taxTable('{TICKET ORDER EXACT TOTAL EXP:O.Taxes.Contains("T1")}','{TICKET ORDER EXACT TOTAL EXP:O.Taxes.Contains("T2")}')}
That script uses Arrays and Objects so that I can reduce the code by using loops. All Arrays actually only contain 2 indices ([0]
and [1]
) because I have only 2 Taxes. If you have more (or less) than that, you would adjust the parameter list to accommodate, and the first pushes for parms[]
and taxes[]
. Then the rest of the script will just “auto-magically” work without the need to add more code or variables.