From dca192a8d9f22c5eea4187c086fd2d5d439d6550 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Thu, 27 Oct 2022 14:12:17 -0700 Subject: [PATCH 1/2] Add net price tooltip to GE records shows net = gross - tax when hovering over total --- src/routes/account/grand-exchange.js | 9 ++++--- src/util.js | 37 +++++++++++++++++++++++++++- 2 files changed, 42 insertions(+), 4 deletions(-) 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..c85fb7bd92 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,38 @@ 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 = numberWithCommas(gross - tax) + + return `Net of ${net} gp = ${numberWithCommas(gross)} - ${numberWithCommas( + tax + )}` +} From 6fdb98c2b9c37c9e9576f02ff88d44cf6796b465 Mon Sep 17 00:00:00 2001 From: Erick Velez Date: Thu, 27 Oct 2022 14:49:44 -0700 Subject: [PATCH 2/2] add net price per item to GE records --- src/util.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/util.js b/src/util.js index c85fb7bd92..196cee9040 100644 --- a/src/util.js +++ b/src/util.js @@ -153,9 +153,10 @@ export const determineTax = item => { const tax = Math.floor(item.price * 0.01) * item.quantity const gross = item.price * item.quantity - const net = numberWithCommas(gross - tax) + const net = gross - tax + const netEach = Math.floor(net / item.quantity) - return `Net of ${net} gp = ${numberWithCommas(gross)} - ${numberWithCommas( - tax - )}` + return `Net of ${numberWithCommas(net)} gp = ${numberWithCommas( + gross + )} - ${numberWithCommas(tax)} (${numberWithCommas(netEach)} gp/ea)` }