From 4ea5238e627470bea2b4d8de1748036c6c5cdec3 Mon Sep 17 00:00:00 2001 From: jtricerolph Date: Wed, 1 Jul 2026 21:36:19 +0000 Subject: [PATCH] Fix cash summary quantity bug; add Safe Count as own nav item - Cash summary: derive total_quantity from total_amount/denomination_value so value_entered rows are counted (previously SUM(quantity) returned NULL for those rows) - Safe Count: moved safe_cash out of Float Management tabs into its own /safe/* route with a dedicated sidebar entry (Vault icon) - FloatManagement now only shows Petty Cash and Change Tin tabs Co-Authored-By: Claude Sonnet 4.6 --- backend/src/routes/reports.js | 4 +++- frontend/src/App.tsx | 2 ++ frontend/src/components/Layout.tsx | 3 ++- frontend/src/pages/FloatManagement.tsx | 9 ++++----- frontend/src/pages/SafeCount.tsx | 14 ++++++++++++++ 5 files changed, 25 insertions(+), 7 deletions(-) create mode 100644 frontend/src/pages/SafeCount.tsx diff --git a/backend/src/routes/reports.js b/backend/src/routes/reports.js index ae74141..d556927 100644 --- a/backend/src/routes/reports.js +++ b/backend/src/routes/reports.js @@ -193,7 +193,9 @@ export async function reportRoutes(app) { if (!from || !to) return reply.status(400).send({ error: 'from and to required' }) const { rows } = await pool.query( - `SELECT d.denomination_value, SUM(d.quantity) AS total_quantity, SUM(d.total_amount) AS total_value + `SELECT d.denomination_value, + ROUND(SUM(d.total_amount) / NULLIF(d.denomination_value, 0)) AS total_quantity, + SUM(d.total_amount) AS total_value FROM denominations d JOIN cash_ups c ON d.cash_up_id = c.id WHERE c.session_date >= $1 AND c.session_date <= $2 AND d.count_type = 'takings' diff --git a/frontend/src/App.tsx b/frontend/src/App.tsx index 01d23b8..9d047d7 100644 --- a/frontend/src/App.tsx +++ b/frontend/src/App.tsx @@ -5,6 +5,7 @@ import { DailyCashUp } from './pages/DailyCashUp' import { History } from './pages/History' import { MultiDayReport } from './pages/MultiDayReport' import { FloatManagement } from './pages/FloatManagement' +import { SafeCount } from './pages/SafeCount' import { CashSummary } from './pages/CashSummary' import { SettingsPage } from './pages/Settings' import type { User } from './types' @@ -18,6 +19,7 @@ function AppRoutes({ user }: { user: User }) { } /> } /> } /> + } /> } /> } /> } /> diff --git a/frontend/src/components/Layout.tsx b/frontend/src/components/Layout.tsx index 4d6e814..d179df0 100644 --- a/frontend/src/components/Layout.tsx +++ b/frontend/src/components/Layout.tsx @@ -1,6 +1,6 @@ import { NavLink, useNavigate } from 'react-router-dom' import { - Banknote, ClipboardList, BarChart2, Wallet, FileText, Settings, LogOut, + Banknote, ClipboardList, BarChart2, Wallet, Vault, FileText, Settings, LogOut, } from 'lucide-react' import type { User } from '../types' @@ -14,6 +14,7 @@ const navItems = [ { to: '/history', label: 'History', icon: ClipboardList }, { to: '/report', label: 'Weekly Report', icon: BarChart2 }, { to: '/floats', label: 'Float Management', icon: Wallet }, + { to: '/safe', label: 'Safe Count', icon: Vault }, { to: '/summary', label: 'Cash Summary', icon: FileText }, { to: '/settings',label: 'Settings', icon: Settings }, ] diff --git a/frontend/src/pages/FloatManagement.tsx b/frontend/src/pages/FloatManagement.tsx index 2f7fa16..0a4a0e9 100644 --- a/frontend/src/pages/FloatManagement.tsx +++ b/frontend/src/pages/FloatManagement.tsx @@ -16,7 +16,7 @@ const TYPE_LABELS: Record = { // Denominations relevant for each type (change_tin uses bags, no £0.02/£0.01) const CHANGE_TIN_DENOMS = GBP_DENOMINATIONS.filter(d => d.value >= 0.05) -function FloatCountForm({ type }: { type: CountType }) { +export function FloatCountForm({ type }: { type: CountType }) { const navigate = useNavigate() const [denomQtys, setDenomQtys] = useState>({}) const [receipts, setReceipts] = useState>([]) @@ -173,7 +173,7 @@ function FloatCountForm({ type }: { type: CountType }) { ) } -function FloatHistory({ type }: { type: CountType }) { +export function FloatHistory({ type }: { type: CountType }) { const [rows, setRows] = useState([]) const [total, setTotal] = useState(0) const [offset, setOffset] = useState(0) @@ -279,9 +279,8 @@ function FloatHistory({ type }: { type: CountType }) { export function FloatManagement() { const tabs: Array<{ path: string; label: string; type: CountType }> = [ - { path: 'petty-cash', label: 'Petty Cash', type: 'petty_cash' }, - { path: 'change-tin', label: 'Change Tin', type: 'change_tin' }, - { path: 'safe-cash', label: 'Safe Cash', type: 'safe_cash' }, + { path: 'petty-cash', label: 'Petty Cash', type: 'petty_cash' }, + { path: 'change-tin', label: 'Change Tin', type: 'change_tin' }, ] return ( diff --git a/frontend/src/pages/SafeCount.tsx b/frontend/src/pages/SafeCount.tsx new file mode 100644 index 0000000..caa2fa1 --- /dev/null +++ b/frontend/src/pages/SafeCount.tsx @@ -0,0 +1,14 @@ +import { Routes, Route, Navigate } from 'react-router-dom' +import { FloatCountForm, FloatHistory } from './FloatManagement' + +export function SafeCount() { + return ( +
+ + } /> + } /> + } /> + +
+ ) +}