Franchise Payroll

@if (session()->has('success')) @endif @if (session()->has('error')) @endif
Leave empty to show all offices
@if(!empty($global_totals) && $global_totals['total_invoice_amount'] > 0) @endif
@foreach($franchiseGroups as $fullName => $offices)

{{ $fullName }}

{{-- Loop through each office location for this franchisee group --}} @foreach ($offices as $officeKey => $officeFranchises) @php // Sum invoice totals from all franchises in this office $total_inv_amnt = 0; $officeFranchise = null; // Keep one franchise for display info foreach ($officeFranchises as $franchise) { $total_inv_amnt += $invoice_totals[$franchise->id] ?? 0; if (!$officeFranchise) { $officeFranchise = $franchise; // Use first franchise for office display info } } // Skip this office if it has no invoice data (shouldn't happen if filtering is correct, but safety check) if ($total_inv_amnt == 0 && (!empty($selected_offices) && is_array($selected_offices) && count($selected_offices) > 0)) { continue; } $oneperc = $total_inv_amnt / 100; // Use per-franchise fees if set, otherwise fallback to global fees $curr_fees = $this->getFranchiseFees($officeFranchise->id); $marketing_fee = $oneperc * $curr_fees['marketing_fee']; $tech_fee = $oneperc * $curr_fees['technology_fee']; $royalty_fee = $oneperc * $curr_fees['royalty_fee']; $insurance_fee = $oneperc * $curr_fees['insurance_fee']; $factoring_fee = $oneperc * $curr_fees['factoring_fee']; $ccc_fee = 0; // your placeholder $franchise_fee = 0; $total_fee = $marketing_fee + $tech_fee + $royalty_fee + $insurance_fee + $factoring_fee + $ccc_fee + $franchise_fee; @endphp

Office: {{ $officeFranchise->franchisecode }} - {{ $officeFranchise->company_name }}

@if(count($officeFranchises) > 1)

(Combined payroll for {{ count($officeFranchises) }} franchise{{ count($officeFranchises) > 1 ? 's' : '' }})

@endif
@if($canViewFees)
{{-- Editable fees for users with permission --}}
%
${{ number_format($tech_fee, 2) }}
%
${{ number_format($marketing_fee, 2) }}
%
${{ number_format($royalty_fee, 2) }}
%
${{ number_format($insurance_fee, 2) }}
%
${{ number_format($factoring_fee, 2) }}
@endif

Total Amount (Before Fees): ${{ number_format($total_inv_amnt, 2) }}

Total Fees: ${{ number_format($total_fee, 2) }}

Total Payable Amount (After Fees): ${{ number_format($total_inv_amnt - $total_fee, 2) }}

@endforeach @endforeach {{-- GLOBAL TOTALS BOX --}} @if(!empty($global_totals) && $global_totals['total_invoice_amount'] > 0)

GLOBAL TOTALS

Global Summary

(All franchises combined)

@if($canViewFees)

Technology Fee: ${{ number_format($global_totals['technology_fee'], 2) }}

Marketing Fee: ${{ number_format($global_totals['marketing_fee'], 2) }}

Royalty Fee: ${{ number_format($global_totals['royalty_fee'], 2) }}

Insurance Fee: ${{ number_format($global_totals['insurance_fee'], 2) }}

Factoring Fee: ${{ number_format($global_totals['factoring_fee'], 2) }}

(Fees may vary per franchise)
@else

Fee details are restricted. Contact your administrator for access.

@endif

Total Amount (Before Fees): ${{ number_format($global_totals['total_invoice_amount'], 2) }}

Total Fees: ${{ number_format($global_totals['total_fees'], 2) }}

Total Payable Amount (After Fees): ${{ number_format($global_totals['total_payable_amount'], 2) }}

@endif