Implement revised retention workflow, overdue late penalty calculation, payment proof verification, and dynamic ledger reconciliation
This commit is contained in:
@@ -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();
|
||||
|
||||
Reference in New Issue
Block a user