@extends('layouts.app') @section('content')
{{-- Card Header with Action Buttons (Hidden on Print) --}}
Invoice: {{ $sale->invoice_no }}
Edit Invoice Print Invoice Back to List
@if (session('success')) @endif
Invoice Details

Invoice No: {{ $sale->invoice_no }}

Salesman: {{ $sale->salesman->name ?? 'N/A' }}

Date & Time

{{ $sale->created_at->format('F d, Y - h:i A') }}

{{-- --}} @php $originalSubtotal = 0; @endphp @foreach ($sale->details as $index => $detail) @php $lineOriginalTotal = $detail->total_price; $originalSubtotal += $lineOriginalTotal; // Calculate cumulative returned quantities for paid and free items separately. $totalReturnedQty = optional($detail->returnDetails)->sum('returned_qty') ?? 0; $totalFreeReturnedQty = optional($detail->returnDetails)->sum('free_returned_qty') ?? 0; @endphp {{-- --}} @endforeach @php $totalRefunds = optional($sale->returns)->sum('refund_total') ?? 0; $totalCommissions = $sale->details->sum('commission'); @endphp {{-- Original Sales Amount --}} {{-- --}} {{-- Returns & Refund Deduction (if applicable) --}} @if ($totalRefunds > 0) @endif {{-- Final Net Payable Grand Total --}}
# Product Company Batch No Sold Qty Returned Free Qty Free Returned Unit Price Commission Total PriceTotal Profit
{{ $index + 1 }} {{ $detail->medicine->name ?? 'N/A' }} {{ $detail->company->company_name ?? ($detail->company->name ?? 'N/A') }} {{ $detail->batch_no }} {{ $detail->medicine?->formatQuantity($detail->quantity) ?? $detail->quantity }} @if ($totalReturnedQty > 0) Ret: {{ $detail->medicine?->formatQuantity($totalReturnedQty) ?? $totalReturnedQty }} @else - @endif @if ($detail->free_quantity > 0) {{ $detail->medicine?->formatQuantity($detail->free_quantity) ?? $detail->free_quantity }} @else - @endif @if ($totalFreeReturnedQty > 0) {{ $detail->medicine?->formatQuantity($totalFreeReturnedQty) ?? $totalFreeReturnedQty }} @else - @endif {{ number_format($detail->selling_price, 2) }} {{ number_format($detail->commission ?? 0, 2) }} {{ number_format($lineOriginalTotal, 2) }}{{ number_format($detail->profit, 2) }}
Original Total: {{ number_format($originalSubtotal, 2) }} Tk
Less Commission: -{{ number_format($totalCommissions, 2) }} Tk
Total Profit: {{ ($sale->details->sum('profit') ?? 'n/a') }} Tk
Less Returns & Adjustments: -{{ number_format($totalRefunds, 2) }} Tk
Net Total: {{ number_format($sale->grand_total, 2) }} Tk
{{-- Return Summary History --}} @if ($sale->returns && $sale->returns->count() > 0)
Return Summary History
    @foreach ($sale->returns as $return)
  • {{ $return->return_no }} ({{ $return->created_at->format('M d, Y') }}) : Refunded {{ number_format($return->refund_total, 2) }} Tk @if ($return->note) — "{{ $return->note }}" @endif
  • @endforeach
@endif
{{-- Print Styles --}} @endsection