/* TaxSplitAll ( _total ; _rateCity ; _rateCounty ; _rateSpecial ; _rateState ; _taxExempt ; _outsideCity ; _nonTaxable ) Calculates City, County, Special, and State taxes and returns both inclusive and exclusive totals as a single JSON object. Parameters: _total = Total amount (may include tax if inclusive) _rateCity = City tax rate (%) _rateCounty = County tax rate (%) _rateSpecial = Special tax rate (%) _rateState = State tax rate (%) _taxExempt = 1 to zero taxes, 0 for normal _outsideCity = 1 to remove city tax, 0 to include _nonTaxable = Portion excluded from tax calculations Returns JSON: { "inclusive": { "taxCity": ..., "taxCounty": ..., "taxSpecial": ..., "taxState": ..., "totalTax": ..., "grandTotal": ... }, "exclusive": { same keys as above... } } */ Let ([ _total = _total ; _nonTaxable = _nonTaxable ; _taxable = _total - _nonTaxable ; _rateCity = If ( _outsideCity ; 0 ; _rateCity ) ; _rateCounty = _rateCounty ; _rateSpecial = _rateSpecial ; _rateState = _rateState ; _taxExempt = _taxExempt ; _totalRate = _rateCity + _rateCounty + _rateSpecial + _rateState ; // Sub-let for each mode. _jsonForMode = Case ( _taxExempt or _totalRate = 0 ; JSONSetElement ( "{}" ; [ [ "taxCity" ; 0 ; 1 ] ; [ "taxCounty" ; 0 ; 1 ] ; [ "taxSpecial" ; 0 ; 1 ] ; [ "taxState" ; 0 ; 1 ] ; [ "totalTax" ; 0 ; 1 ] ; [ "grandTotal" ; _total ; 1 ] ] ) ; // Inclusive mode Let ([ _totalTaxInc = _taxable - ( _taxable / ( 1 + ( _totalRate / 100 ) ) ) ; _taxCityInc = _totalTaxInc * ( _rateCity / _totalRate ) ; _taxCountyInc = _totalTaxInc * ( _rateCounty / _totalRate ) ; _taxSpecialInc = _totalTaxInc * ( _rateSpecial / _totalRate ) ; _taxStateInc = _totalTaxInc * ( _rateState / _totalRate ) ; _grandInc = _total ]; JSONSetElement ( "{}" ; [ [ "taxCity" ; Round ( _taxCityInc ; 2 ) ; 1 ] ; [ "taxCounty" ; Round ( _taxCountyInc ; 2 ) ; 1 ] ; [ "taxSpecial" ; Round ( _taxSpecialInc ; 2 ) ; 1 ] ; [ "taxState" ; Round ( _taxStateInc ; 2 ) ; 1 ] ; [ "totalTax" ; Round ( _totalTaxInc ; 2 ) ; 1 ] ; [ "grandTotal" ; Round ( _grandInc ; 2 ) ; 1 ] ] )) ) ]; JSONSetElement ( "{}" ; [ ["inclusive" ; Evaluate ( _jsonForMode ) ; JSONRaw] ; ["exclusive" ; If ( _taxExempt or _totalRate = 0 ; _jsonForMode ; Let ([ _totalTaxEx = _taxable * ( _totalRate / 100 ) ; _taxCityEx = _totalTaxEx * ( _rateCity / _totalRate ) ; _taxCountyEx = _totalTaxEx * ( _rateCounty / _totalRate ) ; _taxSpecialEx = _totalTaxEx * ( _rateSpecial / _totalRate ) ; _taxStateEx = _totalTaxEx * ( _rateState / _totalRate ) ; _grandEx = _total + _totalTaxEx ]; JSONSetElement ( "{}" ; [ [ "taxCity" ; Round ( _taxCityEx ; 2 ) ; 1 ] ; [ "taxCounty" ; Round ( _taxCountyEx ; 2 ) ; 1 ] ; [ "taxSpecial" ; Round ( _taxSpecialEx ; 2 ) ; 1 ] ; [ "taxState" ; Round ( _taxStateEx ; 2 ) ; 1 ] ; [ "totalTax" ; Round ( _totalTaxEx ; 2 ) ; 1 ] ; [ "grandTotal" ; Round ( _grandEx ; 2 ) ; 1 ] ] )) ) ; JSONRaw ] ] ) )