@extends('layout.app') @push('styles') @endpush @php // Resolved once for the whole page. A @can costs ~1 ms (Spatie rebuilds the user's // permission set on each check) and checkSettings() a cache lookup — inside a loop // over hundreds of managers that alone was seconds of render time. $u = auth()->user(); $canResellerType = $u->canany(['reseller_type', 'specific_management_services']); $canRemarkView = $u->can('manager-remark-view'); $canUniqueCode = $u->can('manager_unique_code'); $canViewCommission = $u->can('view-commission'); $canRecharge = $u->can('reseller-recharge'); $canSecurityAmount = $u->can('security-amount-entry'); $canPackagePermission = $u->canany(['package-permission', 'specific_management_services']); $canEditReseller = $u->can('reseller_edit') || $u->can('manager-accounts-edit'); $canViewHistory = $u->can('view-reseller-history'); $canSmsGateway = $u->can('reseller-sms-getway'); $canDeleteOnline = $u->can('delete-online-client-from-pop-manager'); $cannotSpecificMgmt = ! $u->can('specific_management_services'); $isSuperAdmin = $u->id == 1; $setOnlineRecharge = checkSettings('reseller-online-recharge') == 'enable'; $setPaidOption = checkSettings('reseller-recharge-paid-option') == 'enable'; $setManagerStatus = checkSettings('manager_status') == 'enable'; $setSecurityAmount = checkSettings('securityAmountManagement') == 'enable'; $setClientOnlineRech = checkSettings('ResellerClientOnlineRecharge') == 'enable'; $setVatCommission = globalPermission('commission_from_manager_pop') && checkSettings('vat_deduct_from_payment_for_commission_calculation') === 'enable'; $setCustomSmsGateway = globalPermission('customResellerSmsGatewaySetup'); $apiInUse = checkAPI(); // Manager Miscellaneous Expense (resellers.commission_percentage) — shown and // searchable only where the feature is switched on and the user holds the permission. $setMiscExpense = checkSettings('manager-commission-percentage') == 'enable'; $canMiscExpense = $u->can('manager-miscellaneous-expense-search'); $showMiscExpense = $setMiscExpense && $canMiscExpense; // Manager approval: a new manager is added inactive and goes live only once someone // with manager-approve signs it off. Off by default, so nothing shows up until the // manager_approval setting is switched on. $setApproval = checkSettings('manager_approval') == 'enable'; $canApprove = $setApproval && $u->can('manager-approve'); // Approval states and the badge each one wears, both in the filter summary and in // the Approval column. Rejected managers are only visible via the filter. $approvalLabels = \App\Models\Reseller::APPROVAL_STATUSES; $approvalBadges = [ \App\Models\Reseller::APPROVAL_PENDING => 'badge-warning', \App\Models\Reseller::APPROVAL_MODIFICATION => 'badge-info', \App\Models\Reseller::APPROVAL_APPROVED => 'badge-success', \App\Models\Reseller::APPROVAL_REJECTED => 'badge-danger', ]; // Total Due is a per-manager lookup; keying it once beats scanning the whole // collection inside every row. $dueByReseller = collect($due)->keyBy('reseller_id'); @endphp @section('content')
{{-- Everything above the table on a single line: the total, the approval counts (only for a user who adds managers and approves them, and only while the manager_approval setting is on), the filters this user may use, and the two action buttons. It wraps rather than overflows on a narrow screen. --}}
Total Manager: {{ $resellersCount }} @if ($approvalCounts) @foreach ([\App\Models\Reseller::APPROVAL_PENDING, \App\Models\Reseller::APPROVAL_MODIFICATION, \App\Models\Reseller::APPROVAL_REJECTED] as $state) {{ $approvalLabels[$state] }}: {{ $approvalCounts[$state] }} @endforeach @endif {{-- Whichever filters this user is allowed to use: Miscellaneous Expense needs manager-miscellaneous-expense-search, Approval Status needs manager-approve. Plain selects, not .select2 — three or four options each, and Select2 does not hold its width on an inline bar. --}} @if ($showMiscExpense || $canApprove)
@if ($showMiscExpense) @endif @if ($canApprove) @endif @if ($miscExpense || $approvalStatus) Reset @endif
@else @endif @if (checkSettings('reseller-can-recharge-from-commission') == 'enable') @can('can_recharge_from_manager_commission') @endcan @endif @can('reseller-recharge') @endcan
@if ($canResellerType) @endif @if ($showMiscExpense) @endif @if ($setVatCommission) @endif @if ($setPaidOption) @endif @if ($canRemarkView) @endif @if ($setManagerStatus) @endif @if ($setApproval) @endif @if ($canUniqueCode) @endif @foreach ($resellers as $r) {{-- @dd($resellers) --}} @if ($canResellerType) @endif @if ($showMiscExpense) @endif @if ($setVatCommission) @endif @if ($setPaidOption) @endif @if ($canRemarkView) @endif @if ($setManagerStatus) @endif @if ($setApproval) @endif @if ($canUniqueCode) @endif @endforeach
ID Manager Name Reseller Type Address Contact No Balance Manager Miscellaneous Expense VAT % Commission % Total Due Remark Status Approval Unique Code
{{ $r->id }} {{ $r->name }} @if ($cannotSpecificMgmt && $setOnlineRecharge && $r->enable_online_recharge) Online Recharge @endif {{ $r->reseller_type }} {{ $r->address }} {{ $r->contact }} {{ $r->balance[0]['amount'] ?? 0 }} @if ($r->commission_percentage > 0) {{ rtrim(rtrim(number_format($r->commission_percentage, 2), '0'), '.') }}% @else — @endif {{ $r->vat ?? 0 }}% {{ $r->commission_percentage ?? 0 }}% @if ($d = $dueByReseller->get($r->id)) {{ $d->tamount - $d->tpaid }} @endif {{ $r->remark ?? '' }} {{ $r->status == 'active' ? 'Active' : 'Inactive' }} @php $rStatus = $r->approval_status ?: \App\Models\Reseller::APPROVAL_APPROVED; @endphp {{ $approvalLabels[$rStatus] ?? $rStatus }} @if ($r->approval_remark && $rStatus !== \App\Models\Reseller::APPROVAL_APPROVED) @endif {{ $r->manager_unique_code ?? '' }}
@if ($canApprove) {{-- One modal for both "not approved" decisions — they only differ in the wording and in where the form posts. Both demand a reason. --}} @endif @endsection @unlessrole('Reseller') @section('ajax') @endsection @endunlessrole @push('js') @endpush