# Property Rates Integration

This document describes how property and rate records move through the system and how invoices are posted to the finance module.

## Data Flow
1. **Property creation** – A new property is created via `POST /api/properties`. The model is defined in `models/Properties.php` and includes value fields like `UCV` and `RatesStrick`.
2. **Link to ratepayer** – Use `POST /api/ratepayers` to create the owner record and update the property with the `RatepayerID`.
3. **Set rates tables** – `POST /api/propertyrates` defines zone, category and percentage values applied during billing.
4. **Generate invoice** – Call `POST /api/ratesbilling/generateInvoice/{propertyId}`. The controller inserts a record in `RateInvoices` with the calculated charges.
5. **Record payment** – `POST /api/ratepayments/recordPayment/{invoiceId}` stores the receipt and updates the invoice balance.

## Posting to the General Ledger
`api/services/RatesService.php` calculates the amount, inserts the invoice and writes the corresponding journal entries. When `createInvoice()` is called it posts AR and revenue lines in `GL_Journal_Entries` so the invoice immediately appears in financial reports.

## Offline Behaviour
Front‑end modules `Properties.js` and `Rates.js` use `LocalSyncManager` to cache tables like `properties`, `property_rates`, `rate_invoices` and `rate_payments` in IndexedDB. Records created while offline are flagged with `pendingSync` and pushed to the API once connectivity returns, similar to the pattern documented for permits.

## Required Endpoints
- `POST /api/properties` – create property records
- `POST /api/ratepayers` – create ratepayer records
- `POST /api/propertyrates` – maintain rate tables
- `POST /api/ratesbilling/generateInvoice/{propertyId}` – create an invoice
- `POST /api/ratepayments/recordPayment/{invoiceId}` – record a payment
- `GET /api/ratesbilling/billingInfo/{propertyId}` – retrieve invoice history

Refer to [RoleMapping.md](RoleMapping.md) for which roles may call these endpoints and [FinanceModule.md](FinanceModule.md) for how transactions flow through the GL.
