---
description: All amounts stored as integers in piasters. Zero tolerance for floats.
globs: ["app/**/*.php", "database/migrations/**", "resources/views/**"]
---

# Money — Piasters Only

## Storage

- ALL money columns: `$table->bigInteger('column_name')` — NEVER decimal, float, or double
- Value represents piasters (1 EGP = 100 piasters)
- 150.00 EGP is stored as `15000`
- Negative amounts: ONLY for credits, refunds, adjustments
- Zero: valid (free trial, 100% discount)

## Display (Blade ONLY)

```php
// format_money() helper — the ONLY place conversion happens
function format_money(int $piasters): string {
    return number_format($piasters / 100, 2) . ' ج.م';
}
```

## Input (from forms)

```php
// Convert user input (pounds) to storage (piasters)
$piasters = (int) round((float) $request->amount * 100);
```

## Arithmetic

- Always work with integers
- Division/splitting: round DOWN, assign remainder to last item
- NEVER do math on formatted strings
- Comparison: use integer comparison (`$balance >= $amount`), never float comparison

## Column Names for Money

These are ALL bigint piasters:
`total_amount`, `subtotal`, `discount_amount`, `tax_amount`, `paid_amount`, `balance_due`,
`unit_price`, `unit_cost`, `line_total`, `base_cost`, `selling_price`, `fee_amount`,
`opening_balance`, `closing_balance`, `wallet_balance`, `frozen_amount`,
`late_fee_amount`, `installment_amount`, `refunded_amount`, `variance`,
`total_purchases`, `total_sales`, `shipping_cost`, `rental_cost_per_hour`,
`component_cost`, `discrepancy_value`, `total_variance_value`
