@extends('backEnd.layouts.master')
@section('title','Order Invoice')
@section('content')
Payment Method:
{{$order->payment?$order->payment->payment_method:''}}
Payment Gateway: {{ ucfirst($order->payment_gateway ?? 'N/A') }}
Payment Status:
Order Status:
{{ $order->status ? $order->status->name : 'N/A' }}
@if(isset($orderstatus))
@if($order->courier_type)
Courier: {{ ucfirst($order->courier_type) }}
@if($order->courier_tracking_id)
| Tracking: {{ $order->courier_tracking_id }}
@endif
(Auto-update from courier every 10 minutes)
@endif
@endif
|
Invoice ID : #{{$order->invoice_id}}
Invoice Date: {{$order->created_at->format('d-m-y')}}
Invoice To:
{{$order->shipping?$order->shipping->name:''}}
{{$order->shipping?$order->shipping->phone:''}}
{{$order->shipping?$order->shipping->address:''}}
{{$order->shipping?$order->shipping->area:''}}
|
| SL |
Product |
Price |
Qty |
Total |
@php
// Check if this is a reseller order (once, outside loop)
// Reseller orders ALWAYS have customer_payable_amount field set
$isResellerOrderItem = !empty($order->customer_payable_amount);
// For reseller orders: calculate custom_price from customer_payable_amount
$customPrice = null;
$totalProductValue = 0;
if ($isResellerOrderItem && $order->customer_payable_amount) {
$customPrice = $order->customer_payable_amount - $order->shipping_charge;
// Calculate total of all products (sum of sale_price * qty)
foreach ($order->orderdetails as $od) {
$totalProductValue += ($od->sale_price * $od->qty);
}
}
@endphp
@foreach($order->orderdetails as $key=>$value)
@php
// For reseller orders: Calculate price from customer_payable_amount proportionally
// customer_payable_amount = custom_price + shipping
// custom_price = reseller যে দামে sell করেছে (total)
// For normal orders: show sale_price (main price)
if ($isResellerOrderItem && $customPrice && $totalProductValue > 0) {
// Reseller order: Calculate per product price from customer_payable_amount
// This product's share = (this product's value / total value) * custom_price
$thisProductValue = $value->sale_price * $value->qty;
$thisProductShare = ($thisProductValue / $totalProductValue) * $customPrice;
$displayPrice = $thisProductShare / $value->qty; // Per unit price
} else {
// Normal order: show sale_price (main price)
$displayPrice = $value->sale_price;
}
@endphp
| {{$loop->iteration}} |
{{$value->product_name}}
@php
$sizeDisplay = null;
if ($value->size) {
$sizeDisplay = $value->size->sizeName ?? $value->size->size_name ?? $value->size->name ?? null;
} elseif ($value->product_size) {
// If product_size is an ID, fetch the Size model
$s = \App\Models\Size::find($value->product_size);
$sizeDisplay = $s ? ($s->sizeName ?? $s->size_name ?? null) : null;
// If still null, it might be a direct size name string
if (!$sizeDisplay && !is_numeric($value->product_size)) {
$sizeDisplay = $value->product_size;
}
}
@endphp
@if($sizeDisplay)
Size: {{ $sizeDisplay }}
@endif
@php
$displayColor = ($value->color && $value->color->name) ? $value->color->name : ($value->product_color ?: null);
@endphp
@if($displayColor)
Color: {{ $displayColor }}
@endif
|
৳{{ number_format($displayPrice, 2) }} |
{{$value->qty}} |
৳{{ number_format($displayPrice * $value->qty, 2) }} |
@endforeach
@php
// Check if this is a reseller order
// Reseller orders ALWAYS have customer_payable_amount field set
$isResellerOrder = !empty($order->customer_payable_amount);
// Calculate subtotal - for reseller orders, calculate from customer_payable_amount
if ($isResellerOrder && $order->customer_payable_amount) {
// customer_payable_amount = custom_price + shipping
// custom_price = reseller যে দামে sell করেছে (total)
// So subtotal = customer_payable_amount - shipping
$subtotal = $order->customer_payable_amount - $order->shipping_charge;
} else {
// Normal order: calculate from sale_price
$subtotal = 0;
foreach ($order->orderdetails as $item) {
$subtotal += ($item->sale_price * $item->qty);
}
}
$shipping = $order->shipping_charge;
$discount = $order->discount;
// If reseller order, use customer_payable_amount, otherwise use amount
$finalTotal = $isResellerOrder ? $order->customer_payable_amount : $order->amount;
// Payment Table থেকে নেওয়া Paid/Advance Amount
$advancePaid = \App\Models\Payment::where('order_id', $order->id)->sum('amount');
// Due Amount
$dueAmount = $finalTotal - $advancePaid;
@endphp
@if($isResellerOrder)
| Reseller Order |
|
@endif
| SubTotal |
৳{{ number_format($subtotal, 2) }} |
| Shipping(+) |
৳{{ number_format($shipping, 2) }} |
| Discount(-) |
৳{{ number_format($discount, 2) }} |
| {{ $isResellerOrder ? 'Customer Payable Amount' : 'Final Total' }} |
৳{{ number_format($finalTotal, 2) }} |
{{-- 🔥 যদি Advance Payment থাকে --}}
@if($advancePaid > 0 && $advancePaid < $finalTotal)
| Advance Paid |
৳{{ number_format($advancePaid, 2) }} |
| Due Amount |
৳{{ number_format($dueAmount, 2) }} |
@endif
* This is a computer generated invoice, does not require any signature.
{{-- ══ POS RECEIPT (print only) ══ --}}
@php
$isRes = !empty($order->customer_payable_amount);
$sub = 0;
foreach ($order->orderdetails as $od) { $sub += ($od->sale_price * $od->qty); }
if ($isRes && $order->customer_payable_amount) { $sub = $order->customer_payable_amount - $order->shipping_charge; }
$ftotal = $isRes ? $order->customer_payable_amount : $order->amount;
$tqty = $order->orderdetails->sum('qty');
$pmethod = strtoupper($order->payment_gateway ?? ($order->payment ? $order->payment->payment_method : 'N/A'));
$pstatus = $order->payment_status ?? ($order->payment ? $order->payment->payment_status : 'pending');
$adv = \App\Models\Payment::where('order_id',$order->id)->sum('amount');
$due = $ftotal - $adv;
$trkId = $order->courier_tracking_id ?? $order->consignment_id ?? null;
$courier = $order->courier_type ?? ($trkId ? 'steadfast' : null);
@endphp
{{ $generalsetting->name }}
@if($contact->address)
{{ $contact->address }}
@endif
@if($contact->phone)
Phone: {{ $contact->phone }}
@endif
@if($contact->email)
{{ $contact->email }}
@endif
POS Invoice
Bill No. : {{ $order->invoice_id }}
{{ $order->created_at->format('H:i') }} hrs
Date : {{ $order->created_at->format('d-m-Y') }}
@if($order->shipping && $order->shipping->name)
Buyer : {{ $order->shipping->name }}
@endif
@if($order->shipping && $order->shipping->phone)
Phone : {{ $order->shipping->phone }}
@endif
@if($order->shipping && ($order->shipping->address || $order->shipping->area))
Address : {{ $order->shipping->address }}{{ $order->shipping->area ? ', '.$order->shipping->area : '' }}
@endif
| # |
Product |
Qty |
Rate |
Total |
@foreach($order->orderdetails as $key => $value)
@php
if ($isRes && $order->customer_payable_amount && $sub > 0) {
$tv = $value->sale_price * $value->qty;
$dp = (($tv / ($sub + $order->discount)) * $sub) / $value->qty;
} else { $dp = $value->sale_price; }
$szd = null;
if ($value->size) { $szd = $value->size->sizeName ?? null; }
elseif ($value->product_size) {
$sm = \App\Models\Size::find($value->product_size);
$szd = $sm ? ($sm->sizeName ?? null) : (is_numeric($value->product_size) ? null : $value->product_size);
}
$cld = ($value->color && $value->color->colorName) ? $value->color->colorName : ((!is_numeric($value->product_color) && $value->product_color) ? $value->product_color : null);
@endphp
| {{ $loop->iteration }} |
{{ $value->product_name }}
@if($szd || $cld) @if($szd)Sz:{{ $szd }}@endif @if($szd&&$cld)| @endif @if($cld){{ $cld }}@endif@endif
|
{{ $value->qty }} |
{{ number_format($dp,2) }} |
{{ number_format($dp*$value->qty,2) }} |
@endforeach
Subtotal{{ number_format($sub,2) }}
@if($order->discount > 0)
Discount (–){{ number_format($order->discount,2) }}
@endif
@if($order->shipping_charge > 0)
Delivery (+){{ number_format($order->shipping_charge,2) }}
@endif
Total {{ $tqty }} {{ $tqty>1?'Nos':'No' }}
৳ {{ number_format($ftotal,2) }}
Method :{{ $pmethod }}
Pay Status :{{ strtoupper($pstatus) }}
@if($adv > 0 && $adv < $ftotal)
Advance :৳ {{ number_format($adv,2) }}
Due :৳ {{ number_format($due,2) }}
@endif
@if($courier)
Courier :{{ ucfirst($courier) }}
@if($trkId)
Tracking :{{ $trkId }}
@endif
@if($order->courier_sent_at)
Sent :{{ \Carbon\Carbon::parse($order->courier_sent_at)->format('d M Y') }}
@endif
@endif
Total Paid৳ {{ number_format($ftotal,2) }}
Order Status :{{ $order->status ? $order->status->name : 'Processing' }}
Thank You!
Visit Again!
* Computer generated invoice. No signature required.
{{-- ══ END POS RECEIPT ══ --}}