SILGOLD Loan Approval Workflow Fix V2
=====================================

IMPORTANT DEPLOYMENT NOTE
-------------------------
This ZIP is intentionally packaged with `app/` and `resources/` at the archive root.
Extract it INSIDE the Laravel project root (the folder that contains artisan, app,
resources, routes, vendor, etc.). It should overwrite the three live files below.

Files replaced
--------------
app/Services/SilgoldPolicyLoanService.php
app/Http/Controllers/SilgoldPolicyLoanController.php
resources/views/loan/policy_show.blade.php

What V2 fixes
-------------
1. Existing recorded approvals are reconciled automatically on loan view. If the
   required quorum was already reached but the loan was left Pending, opening the
   loan will move it to Approved without asking the officer to approve again.
2. An officer who has already approved a still-pending multi-approval loan no
   longer sees the approval form again. The page shows "Your approval is recorded"
   and how many other approvers are still required.
3. The approval page shows a visible approval progress/history table.
4. Review & Approve is a 4-step workflow with Next and Back:
   Decision -> Affordability -> Verification & Risk -> Final Confirmation.
5. A successfully approved loan shows a clear Approved banner and moves to the
   Disbursement stage.
6. The controller returns specific approval status messages instead of generic
   "Saved.".
7. The earlier JavaScript escaping fix is included.

After upload
------------
If terminal access is available:
  php artisan view:clear
  php artisan cache:clear
  php artisan config:clear

If there is no terminal access, clear compiled Blade files in:
  storage/framework/views/
Do not remove .gitignore.

Verification
------------
Open a policy loan. The HTML for the approval workflow contains:
  data-workflow-version="2.1"

If the old one-page approval form or a generic "Saved." message is still shown,
the live files were not overwritten. Check that the files were extracted into the
Laravel project root rather than into a nested patch folder.

Optional DB check for loan 40
-----------------------------
SELECT id, status, approved_amount, approved_by_id, approved_date
FROM loans WHERE id = 40;

SELECT loan_id, actor_id, review_revision, amount, created_at
FROM silgold_policy_approvals WHERE loan_id = 40
ORDER BY review_revision, created_at;

SELECT setting_key, setting_value
FROM settings
WHERE setting_key IN (
  'silgold_policy_approval_quorum',
  'silgold_policy_insider_quorum',
  'silgold_policy_authority_matrix'
);
