diff --git a/src/routes/account/grand-exchange.js b/src/routes/account/grand-exchange.js index cd4f72e274..37ccb024df 100644 --- a/src/routes/account/grand-exchange.js +++ b/src/routes/account/grand-exchange.js @@ -1,6 +1,6 @@ import { h, Fragment } from 'preact' import ago from 's-ago' -import { numberWithCommas } from '../../util' +import { numberWithCommas, determineTax } from '../../util' import { connect } from 'react-redux' import { fetchGe, @@ -42,8 +42,11 @@ const buildRecord = record => (

{record.buy ? 'Bought' : 'Sold'} for{' '} - {numberWithCommas(record.price * record.quantity)} gp ( - {numberWithCommas(record.price)} gp/ea) + + {' '} + {numberWithCommas(record.price * record.quantity)} + {' '} + gp ({numberWithCommas(record.price)} gp/ea)

diff --git a/src/util.js b/src/util.js index 8c64080b35..196cee9040 100644 --- a/src/util.js +++ b/src/util.js @@ -42,7 +42,7 @@ export const flattenMap = map => { export const toMMSS = s => { const minutes = Math.floor(s / 60) // Weird arithmetic is needed here to prevent rounding errors due to JS's floating point math - const seconds = Math.round(s % 60 * 10) / 10 + const seconds = Math.round((s % 60) * 10) / 10 const minutesStr = String(minutes).padStart(2, '0') const secondsStr = String(seconds).padStart(2, '0') return minutesStr + ':' + secondsStr @@ -124,3 +124,39 @@ export const digest = (data, callback) => { }) } } + +export const determineTax = item => { + if (item.buy) return '' + + const exemptMessage = 'Item is exempt from tax' + + const exemptItems = [ + 1755, // chisel + 5343, // dibber + 5325, // gardening trowel + 1785, // glassblowing pipe + 2347, // hammer + 1733, // needle + 233, // pestle and mortar + 5341, // rake + 8794, // saw + 5329, // secateurs + 1735, // shears + 952, // spade + 5331 // watering can (0) + ] + const foundExemptItem = exemptItems.includes(item.itemId) + if (foundExemptItem) return exemptMessage + + if (item.price < 100) return exemptMessage + if (item.price > 499999999) return numberWithCommas(5000000) + + const tax = Math.floor(item.price * 0.01) * item.quantity + const gross = item.price * item.quantity + const net = gross - tax + const netEach = Math.floor(net / item.quantity) + + return `Net of ${numberWithCommas(net)} gp = ${numberWithCommas( + gross + )} - ${numberWithCommas(tax)} (${numberWithCommas(netEach)} gp/ea)` +}