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:
@@ -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),
|
||||
|
||||
Reference in New Issue
Block a user