fix(admin): cash close report uses cash payments only for expected cash

- expectedCash now = openingCash + cash payments (not total sales)
- difference = actualCash - realExpectedCash
- Closes ADMIN-CLOSURES
This commit is contained in:
chattie
2026-08-24 16:40:49 +02:00
parent 92e8dfc984
commit b16fce3243
7 changed files with 17 additions and 7 deletions

View File

@@ -796,9 +796,14 @@ export async function registerPosRoutes(app: FastifyInstance, deps: PosRouteDeps
const completedTotal = salesByState['COMPLETED']?.totalCents ?? 0;
const openingCash = session.openingCashCents;
const expectedCash = completedTotal; // simplified: cash payments only
const actualCash = session.actualCashCents ?? 0;
const closingCash = session.closingCashCents ?? 0;
// Expected cash = opening + cash payments only (not total sales)
const cashPaymentsTotal = paymentResult.rows
.filter(p => p.method_code === 'cash' || p.method_code === 'efectivo')
.reduce((sum, p) => sum + parseInt(p.total, 10), 0);
const realExpectedCash = openingCash + cashPaymentsTotal;
const difference = actualCash - realExpectedCash;
return reply.send({
session: {
@@ -814,8 +819,8 @@ export async function registerPosRoutes(app: FastifyInstance, deps: PosRouteDeps
openingCashCents: openingCash,
closingCashCents: closingCash,
actualCashCents: actualCash,
expectedCashCents: expectedCash,
differenceCents: (actualCash - closingCash),
expectedCashCents: realExpectedCash,
differenceCents: difference,
},
sales: {
totalCount: Object.values(salesByState).reduce((s, v) => s + v.count, 0),