@extends('frontEnd.layouts.master') @section('title','Customer Invoice') @section('content') @php // ১. পেমেন্ট ইনফো নেওয়া (Latest payment) $payment = \App\Models\Payment::where('order_id', $order->id)->orderBy('id','desc')->first(); // ২. স্ট্যাটাস লোয়ারকেস করা $gateway_status = $payment ? strtolower(trim($payment->payment_status)) : ''; $payment_method = $payment ? strtolower(trim($payment->payment_method)) : strtolower(trim($order->payment_method ?? '')); $admin_status = strtolower(trim($order->payment_status ?? '')); $order_status = strtolower(trim($order->status ?? '')); // ৩. গ্র্যান্ড টোটাল $grand_total = $order->amount; $paid_amount = 0; // ====================================================== // ⭐ ইনভয়েস ক্যালকুলেশন লজিক (Exact Logic from Account Page) // ====================================================== // ১. পেমেন্ট রেকর্ড থেকে আসল টাকাটা বের করি if ($payment && !in_array($gateway_status, ['failed', 'cancel', 'cancelled', 'rejected'])) { $paid_amount = $payment->amount; } // ২. COD ফিক্স: COD হলে এবং অর্ডার কমপ্লিট না হলে টাকা ০ দেখাবে (ভুল এড়াতে) $is_cod = in_array($payment_method, ['cod', 'cash', 'cash_on_delivery', 'hand cash']); $is_order_completed = in_array($order_status, ['completed', 'delivered']) || in_array($admin_status, ['completed', 'delivered']); if ($is_cod && !$is_order_completed) { if ($paid_amount >= $grand_total) { $paid_amount = 0; } } // ৩. ফোর্স ফুল পেইড (Admin Priority): if ($is_order_completed) { $paid_amount = $grand_total; } elseif (($paid_amount == 0 || !$payment) && in_array($admin_status, ['paid', 'success', 'approved'])) { $paid_amount = $grand_total; } // ৪. ডিউ ক্যালকুলেশন $due_amount = max(0, $grand_total - $paid_amount); // ৫. স্ট্যাটাস চেক (ডিসপ্লে এর জন্য) $is_failed = false; if ($paid_amount == 0 && in_array($gateway_status, ['failed', 'cancel', 'cancelled'])) { $is_failed = true; } @endphp
{{-- ===================== INVOICE HEADER ===================== --}}

Payment Method: {{ $payment_method }}

{{-- পেমেন্ট স্ট্যাটাস ডিসপ্লে --}}

Status: @if($paid_amount >= $grand_total) PAID @elseif($is_failed) FAILED @elseif($paid_amount > 0) PARTIAL PAID @else UNPAID @endif

Invoice From:

{{$generalsetting->name}}

{{$contact->phone}}

{{$contact->email}}

{{$contact->address}}

@if(!empty($order->order_note) || !empty($order->note))

Order Note: {{ $order->order_note ?? $order->note }}

@endif

Invoice

Invoice Date: {{$order->created_at->format('d-m-y')}}


Invoice No: {{$order->invoice_id}}

Invoice To:

{{$order->shipping?$order->shipping->name:''}}

{{$order->shipping?$order->shipping->phone:''}}

{{$order->shipping?$order->shipping->address:''}}

{{$order->shipping?$order->shipping->area:''}}

{{-- ===================== PRODUCTS TABLE ===================== --}} @foreach($order->orderdetails as $value) @endforeach
SL Product Price Qty Total
{{$loop->iteration}} {{$value->product_name}}
@php $sizeDisplay = null; $colorDisplay = null; if ($value->size) { $sizeDisplay = $value->size->sizeName ?? $value->size->size_name ?? $value->size->name ?? null; } elseif ($value->product_size) { $s = \App\Models\Size::find($value->product_size); $sizeDisplay = $s ? ($s->sizeName ?? $s->size_name ?? null) : null; } if ($value->color) { $colorDisplay = $value->color->getDisplayName() ?? $value->color->colorName ?? $value->color->color_name ?? $value->color->name ?? null; } elseif ($value->product_color) { $c = \App\Models\Color::find($value->product_color); $colorDisplay = $c ? ($c->getDisplayName() ?? $c->colorName ?? $c->color_name ?? null) : null; } @endphp @if($sizeDisplay) Size: {{ $sizeDisplay }} @endif @if($colorDisplay) Color: {{ $colorDisplay }} @endif
৳{{$value->sale_price}} {{$value->qty}} ৳{{$value->sale_price * $value->qty}}
{{-- ===================== TOTAL CALCULATION ===================== --}} @php $subtotal = ($order->amount + $order->discount) - $order->shipping_charge; $shipping = $order->shipping_charge; $discount = $order->discount; @endphp
{{-- ========== Paid & Due Display ========== --}} @if($paid_amount > 0 && $due_amount > 0) {{-- পার্শিয়াল পেমেন্ট (Advance) --}} @elseif($paid_amount >= $grand_total) {{-- ফুল পেইড --}} @else {{-- আনপেইড --}} @endif
SubTotal ৳{{$subtotal}}
Shipping(+) ৳{{$shipping}}
Discount(-) ৳{{$discount}}
Total Amount ৳{{$grand_total}}
Paid / Advance ৳{{ number_format($paid_amount, 2) }}
Due Amount ৳{{ number_format($due_amount, 2) }}
Paid Amount ৳{{ number_format($paid_amount, 2) }}
Due Amount ৳0.00
Paid Amount ৳0.00
Due Amount ৳{{ number_format($grand_total, 2) }}
Terms & Conditions

* This is a computer generated invoice.

@endsection