SHYNAZ V9 - LIFETIME LOYALTY & HISTORICAL INVOICES
Brand: SHYNAZ Beauty Lounge. Owner: Jitesh.

INSTALL ON YOUR EXISTING WEBSITE
1. Back up the live website and database together.
2. Extract this ZIP in the EXISTING website folder and overwrite supplied files.
   Keep config.php, uploads and storage contents. Do not delete the folder.
3. Sign in with your EXISTING Supreme Admin login.
4. Click APPLY V9 UPDATE. It adds the database tables/columns automatically.
   DO NOT reinstall or manually import SQL into phpMyAdmin.
5. Refresh with Ctrl+F5; reopen an installed app if necessary.
6. Set free-service rewards and configure phone recovery before using those features.
Existing accounts/passwords, invoices, certificates, staff/student records, manual
loyalty entries and uploads are retained. Existing numbers are not changed.
Repeating activation does not re-award points. Roll back with matching database
AND website backups, not just earlier application files.

WHAT CHANGES FROM V8
- Public self-registration and public invoice creation remain disabled.
- Reception/admin still create all service invoices directly.
- The first invoice now automatically CREATES OR LINKS the client login.
- Eligible service payments earn lifetime points; admin assigns free-service rewards.
- Historical salon invoices have a preview/import workflow and distinct numbering.
- Registered client/student phones can receive recovery codes when configured.

AUTOMATIC LOYALTY RULE
1 POINT FOR EVERY INR 5 PAID FOR COMPLETED SALON SERVICES.
- Use the service amount AFTER discounts and EXCLUDING GST.
- Unpaid balances, course fees and INR 0 reward services earn no points.
- Deposits do not earn until the services are marked completed.
- Later part/final payments earn only their additional eligible amount.
- Fractions carry across visits: INR 4 followed by INR 1 earns one point.
- INR 1,000 eligible paid services earns 200 points.
- Both salons share the same client's balance and canonical client ID.
- Points NEVER expire. There is no age-based deduction.
- Repeated invoice/payment submissions do not award or spend points twice.
- Prior manual/opening balances remain in the ledger.
Pre-V9 invoices are not automatically credited retrospectively. Earlier paid
amounts are retained as an excluded opening baseline; NEW payments on completed
older invoices still earn their additional points. Import historical points only
when they are not already covered by an opening balance/prior rewards.

RECEPTION - INVOICE, ACCOUNT & POINTS
1. Invoices & payments -> Create invoice -> choose salon.
2. Enter client name and phone OR email. Matching normalised phone/email reuses
   the client/account. Contradictory identities are rejected for admin review.
3. Select services/quantities, discount, GST and actually received payment/mode.
4. Assign artists now or later from the saved invoice.
5. Tick SERVICES COMPLETED only for a completed visit. For an advance/future booking
   leave it unticked. Later open the invoice -> MARK SERVICES COMPLETED.
6. Create invoice. It is confirmed immediately; no extra approval step is needed.
7. A first invoice creates a client account if none exists. The invoice shows its
   client ID, account ID, login and lifetime points in the admin tools.
8. A new TEMPORARY password is shown ONCE in this admin session. Copy login details
   or prepare a private WhatsApp login message. Client chooses a DIFFERENT private
   password at portal sign-in. Passwords do not appear in invoice PDFs/messages.
9. Print/download/share the A4 invoice through the existing tools.

SHARE LOGIN DETAILS AGAIN
Open the client's invoice -> Generate new temporary login -> verify identity and
confirm. This generates a NEW password and invalidates the old password/sessions.
The password is shown once for private sharing. Existing private passwords cannot
be retrieved from their hashes. Inactive accounts need Supreme Admin review.

ASSIGN AND REDEEM FREE SERVICES
ADMIN: Loyalty & referrals -> Assign a free service reward -> select salon service
and set the whole POINT COST for ONE free service. Publish. Close old rewards and
publish a new one if the cost/offer changes; previous redemptions retain their cost.
RECEPTION: Create invoice -> choose existing client -> Redeem points for a free
service -> choose reward and quantity. It can be reward-only or mixed with paid
services. The server checks the CURRENT balance before awarding current-invoice
points. It adds an INR 0 line and deducts points once. Insufficient points or a
reward from another salon are rejected. Assign performing artists from the invoice.
A reward-only invoice shows SETTLED WITH POINTS; no cash payment is required.
CLIENT: Portal -> Loyalty & referrals shows balance, earning progress, ledger,
referral ID and available service rewards. Contact reception to redeem.
Points are not cash: the INR 5 EARNING rule does not automatically create an INR 5
cash-discount value per point. Admin sets each free service's POINT COST.

CORRECTIONS / REVERSALS
- Only authorised admin/incharge can edit invoices; only Supreme Admin can delete.
- A redeemed service retains its zero price and original quantity.
- Deleting its reward invoice restores the spent points once.
- Editing/deleting an earning invoice reconciles its points. If those points were
  already spent and reversal would make the balance negative, the change is blocked
  until admin resolves the related reward/ledger record.
- Ledger reasons, invoice links and audit records are retained.

HISTORICAL SALON INVOICE IMPORT
Your old records have NOT been imported by this package.
1. Supreme Admin -> Historical invoice import -> download the blank CSV headers.
2. The screen lists salon IDs for Nakodar/Dasuya/future salons.
3. Export UTF-8 CSV, up to 500 invoice rows and 8 MB per file.
4. Use ONE STABLE source name, e.g. old-register, for ALL files from that old system.
5. Fill the original references, dates, clients, services and paid amounts.
6. Choose historical points ONLY if that spending has not already been rewarded.
7. Validate & preview first; this writes no invoices/accounts/payments/points.
8. Review dates, totals and possible existing matches; then Confirm import.
9. The whole batch commits or none is saved if a conflict is found.
Same source + salon + original invoice ID identifies a historical invoice.
Unchanged repeated rows are skipped; changed repeats are rejected, not overwritten.
Possible overlaps by client/date/amount need explicit review before import.
Historical imports do NOT send old email/WhatsApp invoice messages automatically.

CSV FIELDS
legacy_invoice_id: Original invoice/paper reference; required and stable.
legacy_client_id: Original client ID if known; retained as a source/salon alias.
date: Original invoice date, YYYY-MM-DD.
branch_id: Salon ID shown in the importer.
name: Client name.
phone/email: At least one, for reliable client matching.
service_name, quantity, unit_price: Simple service line; whole quantity 1-1000.
discount: Original invoice discount; 0 if none.
gst_rate: Original GST percentage; 0 if none.
paid: Original recorded received amount; 0 if unpaid.
payment_date: Actual received date when known; blank uses original invoice date.
payment_method: Cash, UPI, Card, Bank transfer, Cheque, Other; blank uses Other.
status: confirmed, pending or cancelled; blank uses confirmed.
payment_reference/notes: Original transaction/reference and details, if known.
services_json: OPTIONAL alternative for multiple services on one original invoice.
For multiple services, put an array in one CSV cell (spreadsheet exports quote it):
[{"title":"Bridal Makeup","quantity":1,"unit_price":5000},{"title":"Hair Styling","quantity":2,"unit_price":500}]
Use services_json instead of the simple service_name/quantity/unit_price cells.
Original spreadsheets can be reviewed/mapped to this format before upload.
Paid historical rows must be confirmed and paid cannot exceed total. Cancellations
or refunds involving money need reconciliation rather than inventing refund data.

OLD / NEW DATES & REFERENCES
- Historical numbers: SBL-OLD-YYYY-xxxxxx. Original invoice/client references stay
  separate and appear in notes. New live SBL-YYYY-xxxxxx numbering continues.
- Original dates are retained. Unknown appointment times are not invented.
  Date-only internal timestamps use midnight. imported_at records the upload time.
- Matching phone/email reuses the SAME canonical client/account ID across branches.
- A conflicting contact for an already mapped old client ID requires verification,
  rather than silently creating another identity.
- Admin filters invoices by live/legacy/existing origin, date and original reference.
  Client portal lists old/new invoices chronologically with pagination.

UNIQUE IDs / CONTACT CORRECTIONS
Linked records have distinct identifiers, for example:
Client: SHY-CL-000001       Account: SBL-ACC-000001
Staff: SHY-EMP-000001      Student: SHY-ST-000001
Invoice: SBL-2026-000001   Certificate: SBL-CERT-2026-000001
Existing earlier invoice/certificate numbers remain unchanged. Having an account
ID and linked client/student/staff ID does not mean duplicate login accounts.
Admin -> Clients, IDs & visits shows canonical IDs, earliest service record,
original references, repeat service records and lifetime points.
If phone/email changes, use Update verified contact with identity verification and
a reason. Client ID, account ID and points stay the same. Old invoices retain their
original contact snapshots. Old recovery tokens/sessions are invalidated.
Do not create a replacement account simply because the number changed.

REGISTERED-PHONE PASSWORD RESET
CLIENT / STUDENT:
1. Account login -> Reset with registered phone (or enter phone on Forgot password).
2. Enter the registered number, receive the six-digit WhatsApp code, and enter it
   with a new matching password of at least 10 characters.
3. Sign in with that registered phone and new password.
Codes last five minutes, work once and lock after five wrong attempts. New requests
invalidate earlier codes. Phone/IP rate limits apply. Codes/hashes never appear in
public pages or admin logs. A number alone cannot reset a password. Unconfigured or
failed delivery produces no usable code and the public response remains generic.

SUPREME ADMIN - PHONE DELIVERY SETUP
1. Configure each salon's registered Meta sender phone ID/access token in WhatsApp.
2. Obtain an APPROVED Copy Code AUTHENTICATION template for recovery codes. This is
   separate from the document template used for invoice PDFs.
3. Phone password recovery -> salon -> template name and exact language, e.g. en_US.
4. Confirm the sender/template mapping and enable recovery.
5. HTTPS and PHP cURL are required. The code is supplied in both the template body
   and its copy-code button. Recent recovery requests show failed/sent status;
   accepted/sent does not independently prove handset delivery.
6. Until configured, reception verifies identity and generates a temporary login.
This is WhatsApp recovery, not an SMS integration. Staff/admin recovery continues
through authorised management or the existing email reset process.
Meta reference:
https://developers.facebook.com/documentation/business-messaging/whatsapp/templates/authentication-templates/copy-code-button-authentication-templates

OTHER FEATURES RETAINED
Staff salary/proof, attendance/breaks, leave and NOC; student admissions, study plans,
PDF permissions/quizzes; course/service certificates and templates; expenses,
inventory/transfers; reporting, articles, gallery, reviews, offers; invoice print,
PDF, email/WhatsApp tools; artist portraits; public salon/service selection.
Offline drafts still require authenticated server sync. Reward redemption, import,
certificates and phone verification require an online connection.

VALIDATION
Development checks use PHP 8.3 and a disposable SQLite copy of the supplied schema.
They cover accounts, carry-forward earning, repeated payments, reward redemption,
reversals, identity conflicts, import/rollback, aliases, phone recovery limits and
V8 compatibility. Free-service and historical A4 PDFs were rendered/inspected.
Live MySQL hosting, physical printing and real handset delivery were not exercised.
No actual client emails, WhatsApp codes or messages were sent during development.
