Implement revised retention workflow, overdue late penalty calculation, payment proof verification, and dynamic ledger reconciliation

This commit is contained in:
Ajjj
2026-08-14 15:29:55 +08:00
parent ccbd23d474
commit 1ca1d286cd
39 changed files with 4103 additions and 573 deletions

View File

@@ -391,8 +391,21 @@ class DashboardController extends Controller
$invoicesQuery->whereIn('project_id', $visibleProjectIds);
}
$totalBilled = (float) $invoicesQuery->sum('subtotal');
$totalPaid = (float) $invoicesQuery->sum('paid_amount');
$totalRetention = (float) $invoicesQuery->sum('retention_amount');
$totalPaid = (float) (clone $invoicesQuery)->where('status', 'paid')->sum('paid_amount');
$retentionLedgerQuery = \Modules\FinancialManagement\Models\RetentionEntry::query();
if ($project) {
$retentionLedgerQuery->where('project_id', $project->id);
} else {
$retentionLedgerQuery->whereIn('project_id', $visibleProjectIds);
}
$heldDebit = (float) (clone $retentionLedgerQuery)->where('type', 'debit')->sum('amount');
$releasedCredit = (float) (clone $retentionLedgerQuery)->where('type', 'credit')->whereIn('status', ['posted', 'paid'])->sum('amount');
$totalRetention = max(0, $heldDebit - $releasedCredit);
if ($totalRetention == 0 && (clone $invoicesQuery)->whereIn('status', ['approved', 'sent', 'payment_sent', 'paid'])->exists()) {
$totalRetention = (float) (clone $invoicesQuery)->whereIn('status', ['approved', 'sent', 'payment_sent', 'paid'])->sum('retention_amount');
}
$pendingApprovalsCount = \Modules\ApprovalWorkflow\Models\ApprovalChain::where('status', 'in_review')->count();
$projectsAnalyticsQuery = Project::query();