@php
use Carbon\Carbon;
// For Date Formating
function formatDate($date) {
return Carbon::parse($date)->format('d M Y'); // e.g. 09 July 2025
}
// for image print
function imgToBase64($path) {
if (file_exists($path)) {
$type = pathinfo($path, PATHINFO_EXTENSION); // e.g. png, jpg
$data = file_get_contents($path);
$base64 = base64_encode($data);
return "data:image/{$type};base64,{$base64}";
}
return '';
}
$logoData = imgToBase64(public_path('images/obeologo.png'));
//data from controller
$payload = isset($data) ? (is_array($data) ? $data : (array) $data) : [];
$hotel = $payload['hotel'] ?? '';
$hotelAddress = $payload['hotelAddress'] ?? '';
$month = $payload['month'] ?? '';
$downloadType = $payload['downloadType'] ?? '';
// $invoices = $payload['invoices'] ?? [];
$invoices = collect($payload['invoices'] ?? []);
$invoiceNo = $payload['invoiceNo'] ?? '';
$invoiceDate = $payload['invoiceDate'] ?? '';
$monthlyAdjustments = collect($payload['monthlyAdjustments'] ?? []);
// commission calculation
$hotelCollectsCommission = $hotelCollectsCommission ?? 0;
$expediaCollectsCommission = $expediaCollectsCommission ?? 0;
// Booking.com hotel collects section
$bookingInvoices = $invoices->filter(fn($inv) => ($inv['source'] ?? '') === 'Booking.com' &&
($inv['payment_method'] ?? '') === 'Hotel Collect')->values();
$grandTotal = $bookingInvoices->sum(fn($inv) => (float)($inv['total_amount'] ?? 0));
$grandCommission = $bookingInvoices->sum(fn($inv) => (float)($inv['total_amount'] ?? 0) * ((float)($inv['hotelCollectsCommission'] ?? $hotelCollectsCommission)) / 100);
$bookingComHotelCollectsCommission = optional($bookingInvoices->first())['hotelCollectsCommission'] ?? $hotelCollectsCommission;
//Expedia Hotel collects Section
$expediaInvoices = $invoices->filter(fn($inv) => ($inv['source'] ?? '') === 'Expedia' &&
($inv['payment_method'] ?? '') === 'Hotel Collect')->values();
$expediaTotal = $expediaInvoices->sum(fn($inv) => (float)($inv['total_amount'] ?? 0));
$expediaCommission = $expediaInvoices->sum(fn($inv) => (float)($inv['total_amount'] ?? 0) * ((float)($inv['hotelCollectsCommission'] ?? $hotelCollectsCommission)) / 100);
$expediaHotelCollectsCommission = optional($expediaInvoices->first())['hotelCollectsCommission'] ?? $hotelCollectsCommission;
//Expedia Expedia-collects Section
$expediaCollectsInvoices = $invoices->filter(fn($inv) => ($inv['source'] ?? '') === 'Expedia' &&
($inv['payment_method'] ?? '') === 'Expedia Collect')->values();
$expediaCollectsTotal = $expediaCollectsInvoices->sum(fn($inv) => (float)($inv['total_amount'] ?? 0));
$expediaCollectsCommission = $expediaCollectsInvoices->sum(fn($inv) => (float)($inv['total_amount'] ?? 0) * ((float)($inv['expediaCollectsCommission'] ?? $expediaCollectsCommission)) / 100);
$expediaExpediaCollectsCommission = optional($expediaCollectsInvoices->first())['expediaCollectsCommission'] ?? $expediaCollectsCommission;
//booking.com calculation
$finalGrandTotal = 0;
if ($downloadType === "Booking.com" && $bookingInvoices->isNotEmpty()) {
$finalGrandTotal = $grandCommission;
foreach ($monthlyAdjustments as $adjustment) {
if ($adjustment->source === "Booking.com") {
if ($adjustment->type === "Debit") {
$finalGrandTotal -= $adjustment->amount;
} else {
$finalGrandTotal += $adjustment->amount;
}
}
}
}
//Expedia hotel collects calculation
$expediaFinalGrandTotal = 0;
if ($downloadType === "expediaHotelCollects" && $expediaInvoices->isNotEmpty()) {
$expediaFinalGrandTotal = $expediaCommission;
foreach ($monthlyAdjustments as $adjustment) {
if ($adjustment->source === "expediaHotelCollects") {
if ($adjustment->type === "Debit") {
$expediaFinalGrandTotal -= $adjustment->amount;
} else {
$expediaFinalGrandTotal += $adjustment->amount;
}
}
}
}
//Expedia expedia collects calculation
$expediaCollectsFinalGrandTotal = 0;
$expediaCollectsData = [];
if ($downloadType === "expediaCollects" && $expediaCollectsInvoices->isNotEmpty()) {
// Start from total
$expediaCollectsFinalGrandTotal = $expediaCollectsTotal;
// Row 1: Total Expedia Collects Amount
$expediaCollectsData[] = [
'description' => "Total Expedia Collects Amount",
'type' => "Credit",
'amount' => $expediaCollectsTotal,
'total' => $expediaCollectsFinalGrandTotal,
];
// Row 2: Commission
$expediaCollectsFinalGrandTotal -= $expediaCollectsCommission;
$expediaCollectsData[] = [
'description' => "Expedia collects Commission ({$expediaExpediaCollectsCommission}%)",
'type' => "Debit",
'amount' => $expediaCollectsCommission,
'total' => $expediaCollectsFinalGrandTotal,
];
// Row 3+: Dynamic Adjustments
foreach ($monthlyAdjustments as $adjustment) {
if ($adjustment->source === "expediaCollects") {
if ($adjustment->type === "Debit") {
$expediaCollectsFinalGrandTotal -= $adjustment->amount;
} else {
$expediaCollectsFinalGrandTotal += $adjustment->amount;
}
$expediaCollectsData[] = [
'description' => $adjustment->purpose ?? 'Adjustment',
'type' => $adjustment->type,
'amount' => $adjustment->amount,
'total' => $expediaCollectsFinalGrandTotal,
];
}
}
}
//combined
$combinedGrandTotal = 0;
$combinedData = [];
if ($downloadType === "Combined") {
// -------------------------
// Step 1: Expedia Collects (if exists)
// -------------------------
if ($expediaCollectsInvoices->isNotEmpty()) {
// Row 1: Total Expedia Collects Amount
$combinedGrandTotal = $expediaCollectsTotal;
$combinedData[] = [
'description' => "Total Expedia Collects Amount",
'type' => "Credit",
'amount' => $expediaCollectsTotal,
'total' => $combinedGrandTotal,
];
// Row 2: Subtract Expedia Collects Commission
$combinedGrandTotal -= $expediaCollectsCommission;
$combinedData[] = [
'description' => "Expedia Collects Commission ({$expediaExpediaCollectsCommission}%)",
'type' => "Debit",
'amount' => $expediaCollectsCommission,
'total' => $combinedGrandTotal,
];
}
// -------------------------
// Step 2: Expedia Hotel Collects
// -------------------------
if ($expediaInvoices->isNotEmpty()) {
if ($expediaCollectsInvoices->isNotEmpty()) {
// If Expedia Collects exists → subtract
$combinedGrandTotal -= $expediaCommission;
$combinedData[] = [
'description' => "Expedia Hotel Collects Commission ({$expediaHotelCollectsCommission}%)",
'type' => "Debit",
'amount' => $expediaCommission,
'total' => $combinedGrandTotal,
];
} else {
// If no Expedia Collects → treat as Credit
$combinedGrandTotal += $expediaCommission;
$combinedData[] = [
'description' => "Expedia Hotel Collects Commission ({$expediaHotelCollectsCommission}%)",
'type' => "Credit",
'amount' => $expediaCommission,
'total' => $combinedGrandTotal,
];
}
}
// -------------------------
// Step 3: Booking.com
// -------------------------
if ($bookingInvoices->isNotEmpty()) {
if ($expediaCollectsInvoices->isNotEmpty()) {
// If Expedia Collects exists → subtract
$combinedGrandTotal -= $grandCommission;
$combinedData[] = [
'description' => "Booking.com Commission ({$bookingComHotelCollectsCommission}%)",
'type' => "Debit",
'amount' => $grandCommission,
'total' => $combinedGrandTotal,
];
} else {
// If no Expedia Collects → treat as Credit
$combinedGrandTotal += $grandCommission;
$combinedData[] = [
'description' => "Booking.com Commission ({$bookingComHotelCollectsCommission}%)",
'type' => "Credit",
'amount' => $grandCommission,
'total' => $combinedGrandTotal,
];
}
}
// -------------------------
// Step 4: Apply Adjustments
// -------------------------
foreach ($monthlyAdjustments as $adjustment) {
if ($adjustment->source === "Combined") {
if ($adjustment->type === "Debit") {
$combinedGrandTotal -= $adjustment->amount;
} else {
$combinedGrandTotal += $adjustment->amount;
}
$combinedData[] = [
'description' => $adjustment->purpose ?? 'Adjustment',
'type' => $adjustment->type,
'amount' => $adjustment->amount,
'total' => $combinedGrandTotal,
];
}
}
}
@endphp
{{$month}}
|
Invoice
|
|
Bill To
General Manager
{{$hotel}}
{{$hotelAddress}}
|
| Invoice No: |
{{ $invoiceNo }}
|
| Invoice Date: |
{{ $invoiceDate }}
|
| Invoice Month: |
{{ $month }}
|
@if($downloadType === "Booking.com" && $bookingInvoices->isNotEmpty())
| Amount Due: |
{{number_format($finalGrandTotal, 2)}} |
@elseif($downloadType === "expediaHotelCollects" && $expediaInvoices->isNotEmpty())
Amount Due: |
{{number_format($expediaFinalGrandTotal, 2)}} |
@elseif($downloadType === "expediaCollects" && $expediaCollectsInvoices->isNotEmpty())
Payable To Hotel: |
{{number_format($expediaCollectsFinalGrandTotal, 2)}} |
@elseif($downloadType === "Combined" )
Total Amount (Tk): |
{{number_format($combinedGrandTotal, 2)}} |
@endif
|
@if ($downloadType === "Booking.com" && $bookingInvoices->isNotEmpty())
Booking.com (Hotel Collects)
| SN |
C/IN |
C/OUT |
GUEST |
ROOM |
TOTAL |
COMM |
@foreach($bookingInvoices as $invoice)
| {{ sprintf('%02d', $loop->iteration) }} |
{{ formatDate($invoice['check_in'] )}} |
{{ formatDate($invoice['check_out']) }} |
{{ $invoice['guest_name'] ?? '-' }} |
@if(!empty($invoice['hotel_invoice_rooms']))
@foreach($invoice['hotel_invoice_rooms'] as $room)
{{ $room['room_name'] }} (x{{ $room['total_room'] }})
@endforeach
@endif
|
{{ number_format($invoice['total_amount'] ?? 0, 2) }}
|
{{ number_format(($invoice['total_amount'] * $invoice['hotelCollectsCommission']) / 100, 2) }}
|
@endforeach
|
Total
|
{{ number_format($grandTotal, 2) }}
|
{{ number_format($grandCommission, 2) }}
|
@php
// start with commission as base grand total
$finalGrandTotal = $grandCommission;
@endphp
Invoice Summary
| SN |
Description |
Debit / Credit |
Amount (TK) |
Total (TK) |
| 01 |
Booking.com Commission ({{ $bookingComHotelCollectsCommission }}%) |
Credit |
{{ number_format($grandCommission, 2) }} |
{{-- Grand Total--}}
{{ number_format($finalGrandTotal, 2) }} |
@foreach($monthlyAdjustments as $adjustment)
@if($adjustment->source === "Booking.com")
@php
// update running total
if ($adjustment->type === "Debit") {
$finalGrandTotal -= $adjustment->amount;
} else {
$finalGrandTotal += $adjustment->amount;
}
@endphp
| {{ sprintf('%02d', $loop->iteration + 1) }} |
{{ $adjustment->purpose }} |
{{ $adjustment->type }} |
{{ number_format($adjustment->amount, 2) }} |
{{ number_format($finalGrandTotal, 2) }} |
@endif
@endforeach
|
Total Due
|
{{ number_format($finalGrandTotal, 2) }}
|
@endif
@if ($downloadType === "expediaHotelCollects" && $expediaInvoices->isNotEmpty())
Expedia (Hotel Collects)
| SN |
C/IN |
C/OUT |
GUEST |
ROOM |
TOTAL |
COMM |
@foreach($expediaInvoices as $invoice)
| {{ sprintf('%02d', $loop->iteration) }} |
{{ formatDate($invoice['check_in'] )}} |
{{ formatDate($invoice['check_out']) }} |
{{ $invoice['guest_name'] ?? '-' }} |
@if(!empty($invoice['hotel_invoice_rooms']))
@foreach($invoice['hotel_invoice_rooms'] as $room)
{{ $room['room_name'] }} (x{{ $room['total_room'] }})
@endforeach
@endif
|
{{ number_format($invoice['total_amount'] ?? 0, 2) }}
|
{{ number_format(($invoice['total_amount'] * $invoice['hotelCollectsCommission']) / 100, 2) }}
|
@endforeach
|
Total
|
{{ number_format($expediaTotal, 2) }}
|
{{ number_format($expediaCommission, 2) }}
|
@php
// start with commission as base grand total
$expediaFinalGrandTotal = $expediaCommission;
@endphp
Invoice Summary
| SN |
Description |
Debit / Credit |
Amount (TK) |
Total (TK) |
| 01 |
Expedia Hotel collects Commission ({{ $expediaHotelCollectsCommission }}%) |
Credit |
{{ number_format($expediaCommission, 2) }} |
{{-- Grand Total--}}
{{ number_format($expediaFinalGrandTotal, 2) }} |
@foreach($monthlyAdjustments as $adjustment)
@if($adjustment->source === "expediaHotelCollects")
@php
// update running total
if ($adjustment->type === "Debit") {
$expediaFinalGrandTotal -= $adjustment->amount;
} else {
$expediaFinalGrandTotal += $adjustment->amount;
}
@endphp
| {{ sprintf('%02d', $loop->iteration + 1) }} |
{{ $adjustment->purpose }} |
{{ $adjustment->type }} |
{{ number_format($adjustment->amount, 2) }} |
{{ number_format($expediaFinalGrandTotal, 2) }} |
@endif
@endforeach
|
Total Due
|
{{ number_format($expediaFinalGrandTotal, 2) }}
|
@endif
@if ($downloadType === "expediaCollects" && $expediaCollectsInvoices->isNotEmpty())
Expedia (Expedia Collects)
| SN |
C/IN |
C/OUT |
GUEST |
ROOM |
TOTAL |
COMM |
@foreach($expediaCollectsInvoices as $invoice)
| {{ sprintf('%02d', $loop->iteration) }} |
{{ formatDate($invoice['check_in'] )}} |
{{ formatDate($invoice['check_out']) }} |
{{ $invoice['guest_name'] ?? '-' }} |
@if(!empty($invoice['hotel_invoice_rooms']))
@foreach($invoice['hotel_invoice_rooms'] as $room)
{{ $room['room_name'] }} (x{{ $room['total_room'] }})
@endforeach
@endif
|
{{ number_format($invoice['total_amount'] ?? 0, 2) }}
|
{{ number_format(($invoice['total_amount'] * $invoice['expediaCollectsCommission']) / 100, 2) }}
|
@endforeach
|
Total
|
{{ number_format($expediaCollectsTotal, 2) }}
|
{{ number_format($expediaCollectsCommission, 2) }}
|
Invoice Summary
| SN |
Description |
Debit / Credit |
Amount (TK) |
Total (TK) |
@foreach($expediaCollectsData as $index => $row)
| {{ sprintf('%02d', str_pad($index+1, 2, '0', STR_PAD_LEFT) ) }} |
{{ $row['description'] }} |
{{ $row['type'] }} |
{{ number_format($row['amount'], 2) }} |
{{ number_format($row['total'], 2) }} |
@endforeach
|
Total Payable To Hotel
|
{{ number_format($expediaCollectsFinalGrandTotal, 2) }}
|
@endif
@if ($downloadType === "Combined")
@if($bookingInvoices->isNotEmpty())
Booking.com (Hotel Collects)
| SN |
C/IN |
C/OUT |
GUEST |
ROOM |
TOTAL |
COMM |
@foreach($bookingInvoices as $invoice)
| {{ sprintf('%02d', $loop->iteration) }} |
{{ formatDate($invoice['check_in'] )}} |
{{ formatDate($invoice['check_out']) }} |
{{ $invoice['guest_name'] ?? '-' }} |
@if(!empty($invoice['hotel_invoice_rooms']))
@foreach($invoice['hotel_invoice_rooms'] as $room)
{{ $room['room_name'] }} (x{{ $room['total_room'] }})
@endforeach
@endif
|
{{ number_format($invoice['total_amount'] ?? 0, 2) }}
|
{{ number_format(($invoice['total_amount'] * $invoice['hotelCollectsCommission']) / 100, 2) }}
|
@endforeach
|
Total
|
{{ number_format($grandTotal, 2) }}
|
{{ number_format($grandCommission, 2) }}
|
@endif
@if($expediaInvoices->isNotEmpty())
Expedia (Hotel Collects)
| SN |
C/IN |
C/OUT |
GUEST |
ROOM |
TOTAL |
COMM |
@foreach($expediaInvoices as $invoice)
| {{ sprintf('%02d', $loop->iteration) }} |
{{ formatDate($invoice['check_in'] )}} |
{{ formatDate($invoice['check_out']) }} |
{{ $invoice['guest_name'] ?? '-' }} |
@if(!empty($invoice['hotel_invoice_rooms']))
@foreach($invoice['hotel_invoice_rooms'] as $room)
{{ $room['room_name'] }} (x{{ $room['total_room'] }})
@endforeach
@endif
|
{{ number_format($invoice['total_amount'] ?? 0, 2) }}
|
{{ number_format(($invoice['total_amount'] * $invoice['hotelCollectsCommission']) / 100, 2) }}
|
@endforeach
|
Total
|
{{ number_format($expediaTotal, 2) }}
|
{{ number_format($expediaCommission, 2) }}
|
@endif
@if($expediaCollectsInvoices->isNotEmpty())
Expedia (Expedia Collects)
| SN |
C/IN |
C/OUT |
GUEST |
ROOM |
TOTAL |
COMM |
@foreach($expediaCollectsInvoices as $invoice)
| {{ sprintf('%02d', $loop->iteration) }} |
{{ formatDate($invoice['check_in'] )}} |
{{ formatDate($invoice['check_out']) }} |
{{ $invoice['guest_name'] ?? '-' }} |
@if(!empty($invoice['hotel_invoice_rooms']))
@foreach($invoice['hotel_invoice_rooms'] as $room)
{{ $room['room_name'] }} (x{{ $room['total_room'] }})
@endforeach
@endif
|
{{ number_format($invoice['total_amount'] ?? 0, 2) }}
|
{{ number_format(($invoice['total_amount'] * $invoice['expediaCollectsCommission']) / 100, 2) }}
|
@endforeach
|
Total
|
{{ number_format($expediaCollectsTotal, 2) }}
|
{{ number_format($expediaCollectsCommission, 2) }}
|
@endif
Invoice Summary
| SN |
Description |
Debit / Credit |
Amount (TK) |
Total (TK) |
@foreach($combinedData as $index => $row)
| {{ sprintf('%02d', str_pad($index+1, 2, '0', STR_PAD_LEFT) ) }} |
{{ $row['description'] }} |
{{ $row['type'] }} |
{{ number_format($row['amount'], 2) }} |
{{ number_format($row['total'], 2) }} |
@endforeach
|
Total Amount Tk
|
{{ number_format($combinedGrandTotal, 2) }}
|
@endif
© Obeo Limited. All rights reserved.