[ADD] tax to customer refund

Needed to change debit/credit/balance formatting to account for
imprecise sub-unit floats
This commit is contained in:
Xavier Morel 2015-03-13 17:00:15 +01:00
parent dff31b5bd2
commit e52f5f5e8f

View File

@ -81,15 +81,15 @@
React.DOM.td({className: React.addons.classSet({ React.DOM.td({className: React.addons.classSet({
'text-right': true, 'text-right': true,
'highlight-op': highlight === 'debit' 'highlight-op': highlight === 'debit'
})}, data.get('debit') || ''), })}, format(data.get('debit'))),
React.DOM.td({className: React.addons.classSet({ React.DOM.td({className: React.addons.classSet({
'text-right': true, 'text-right': true,
'highlight-op': highlight === 'credit' 'highlight-op': highlight === 'credit'
})}, data.get('credit') || ''), })}, format(data.get('credit'))),
React.DOM.td( React.DOM.td(
{className: 'text-right'}, {className: 'text-right'},
((data.get('debit') || data.get('credit')) ((data.get('debit') || data.get('credit'))
? data.get('debit') - data.get('credit') ? format(data.get('debit') - data.get('credit'), 0)
: '') : '')
) )
); );
@ -203,6 +203,7 @@
tax = sale * 0.09, tax = sale * 0.09,
total = sale + tax, total = sale + tax,
refund = sale * 0.1, refund = sale * 0.1,
refund_tax = refund * 0.09,
purchase = 80; purchase = 80;
var operations = Immutable.fromJS([{ var operations = Immutable.fromJS([{
label: "Company Incorporation (Initial Capital $1,000)", label: "Company Incorporation (Initial Capital $1,000)",
@ -223,19 +224,26 @@
label: "Customer Refund 10%", label: "Customer Refund 10%",
operations: [ operations: [
{account: REVENUE.SALES.code, debit: constant(refund)}, {account: REVENUE.SALES.code, debit: constant(refund)},
{account: ASSETS.ACCOUNTS_RECEIVABLE.code, credit: constant(refund)} {account: LIABILITIES.TAXES_PAYABLE.code, debit: constant(refund_tax)},
{account: ASSETS.ACCOUNTS_RECEIVABLE.code, credit: constant(refund + refund_tax)}
] ]
}, { }, {
label: "Customer Payment", label: "Customer Payment",
operations: [ operations: [
{account: ASSETS.CASH.code, debit: function (ops) { {account: ASSETS.CASH.code, debit: function (ops) {
return ops.contains(operations.getIn(['customer_refund', 'operations'])) var refund_op = operations.find(function (op) {
? total - refund return !!op.get('label').match(/refund/i);
});
return ops.contains(refund_op.get('operations'))
? total - (refund + refund_tax)
: total; : total;
}}, }},
{account: ASSETS.ACCOUNTS_RECEIVABLE.code, credit: function (ops) { {account: ASSETS.ACCOUNTS_RECEIVABLE.code, credit: function (ops) {
return ops.contains(operations.getIn(['customer_refund', 'operations'])) var refund_op = operations.find(function (op) {
? total - refund return !!op.get('label').match(/refund/i);
});
return ops.contains(refund_op.get('operations'))
? total - (refund + refund_tax)
: total; : total;
}} }}
] ]
@ -273,4 +281,9 @@
} }
]); ]);
function constant(val) {return function () { return val; };} function constant(val) {return function () { return val; };}
function format(val, def) {
if (!val) { return def === undefined ? '' : def; }
if (val % 1 === 0) { return val; }
return val.toFixed(2);
}
})(); })();