@php use Illuminate\Support\Str; $totalItems = collect(); foreach ($sales as $sale) { foreach ($sale->itemTransaction as $transaction) { $totalItems->push([ 'sale' => $sale, 'transaction' => $transaction, ]); } } $subtotal = $sales->sum(fn($sale) => $sale->itemTransaction->sum('total')); $discount = $sales->sum(fn($sale) => $sale->itemTransaction->sum('discount_amount')); $taxAmount = $sales->sum(fn($sale) => $sale->itemTransaction->sum('tax_amount')); $grandTotal = $sales->sum('grand_total'); $paidAmount = $sales->sum('paid_amount'); $roundOff = $sales->sum('round_off'); $balance = $grandTotal - $paidAmount; @endphp {{ $invoiceData['name'] }}
@php if($isPdf){ //Default logo path $defaultLogo = 'app/public/images/noimages/no-image-found.jpg'; //Company logo path $companyLogoPath = 'app/public/images/company/'; $companyLogo = storage_path( !empty(app('company')['colored_logo']) && file_exists(storage_path($companyLogoPath . app('company')['colored_logo'])) ? $companyLogoPath . app('company')['colored_logo'] : $defaultLogo ); }else{ //Routing or direct view $companyLogo = url('/company/getimage/'.app('company')['colored_logo']); } @endphp

--------{{ $invoiceData['name'] }}--------

{{ __('app.name') }}: {{ $sale->party->first_name.' '. $sale->party->last_name }}
{{ __('sale.invoice') }}: #SL0040
{{ __('app.date') }}: {{ $sale->formatted_sale_date }}
{{ __('app.time') }}: {{ $sale->format_created_time }}
@php $i = 1; @endphp @foreach($totalItems as $row) @php $sale = $row['sale']; $transaction = $row['transaction']; $item = $transaction->item; @endphp {{-- Note: Calculate Total = (Unit Price - Discount) + Tax Here we are showing only Total, in below destriburted the discount and Tax --}} @endforeach @php $totalQty = $sale->itemTransaction->sum(function ($transaction) { return $transaction->quantity; }); @endphp
{{ __('app.description') }} {{ __('app.price_per_unit') }} {{ __('app.total') }}
{{ $transaction->item->name }}
{!! $transaction->description !!}
{{ $formatNumber->formatWithPrecision($transaction->unit_price) }}
{{ $transaction->unit->name }}
{{ $formatNumber->formatWithPrecision($transaction->total) }}
{{ __('app.total') }} {{ $formatNumber->formatWithPrecision($subtotal) }} درهم
{{ __('app.subtotal') }}
{{ $formatNumber->formatWithPrecision($subtotal) }} درهم
{{ __('app.discount') }}
{{ $formatNumber->formatWithPrecision(-$discount) }} درهم
@if(app('company')['tax_type'] != 'no-tax')
{{ __('tax.tax') }}
{{ $formatNumber->formatWithPrecision($taxAmount) }} درهم
@endif
{{ __('app.round_off') }}
{{ $formatNumber->formatWithPrecision($roundOff) }}
{{ __('app.grand_total') }}
{{ $formatNumber->formatWithPrecision($grandTotal) }} درهم
المدفوع
{{ $formatNumber->formatWithPrecision($paidAmount) }} درهم
{{ __('payment.balance') }}
{{ $formatNumber->formatWithPrecision($grandTotal - $paidAmount) }} درهم
@if(app('company')['show_mrp']) @php $savedAmount = $sale->itemTransaction->sum(function ($transaction) { if($transaction->mrp > 0){ return ($transaction->mrp * $transaction->quantity) - $transaction->total; }else{ return 0; } }); @endphp
{{ __('app.you_saved') }}
{{ $formatNumber->formatWithPrecision($savedAmount) }}
@endif @if(app('company')['show_party_due_payment']) @php $partyTotalDue = $sale->party->getPartyTotalDueBalance(); $partyTotalDueBalance = $partyTotalDue['status']=='you_pay' ? (-1 * $partyTotalDue['balance']) : $partyTotalDue['balance']; @endphp
{{ __('app.total_due_balance') }}
{{ $formatNumber->formatWithPrecision($partyTotalDueBalance) }}
@endif
@if(app('company')['show_tax_summary'] && app('company')['tax_type'] != 'no-tax') @if(app('company')['tax_type'] == 'tax') @else {{-- GST --}} @endif @php if(app('company')['tax_type'] == 'tax'){ $taxSummary = $sale->itemTransaction ->groupBy('tax_id') ->map(function ($group) { $firstItem = $group->first(); $totalTaxableAmount = $group->sum(function ($item) use ($firstItem) { $totalOfEachItem = ($item->unit_price-$item->discount_amount) * $item->quantity; if ($item->tax_type == 'inclusive') { return calculatePrice($totalOfEachItem, $firstItem->tax->rate, needInclusive: true); } else { return calculatePrice($totalOfEachItem, $firstItem->tax->rate, needInclusive: false); } }); return [ 'tax_id' => $firstItem->tax_id, 'tax_name' => $firstItem->tax->name, 'tax_rate' => $firstItem->tax->rate, 'total_taxable_amount' => $totalTaxableAmount, 'total_tax' => $group->sum('tax_amount') ]; }) ->values(); } else{ //GST $taxSummary = $sale->itemTransaction ->groupBy('item.hsn') // First group by HSN ->map(function ($hsnGroup) { return $hsnGroup->groupBy('tax_id') // Then group by tax_id within each HSN group ->map(function ($group) { $firstItem = $group->first(); $totalTaxableAmount = $group->sum(function ($item) { $totalOfEachItem = ($item->unit_price - $item->discount_amount) * $item->quantity; if ($item->tax_type == 'inclusive') { return calculatePrice($totalOfEachItem, $item->tax->rate, needInclusive: true); } else { return calculatePrice($totalOfEachItem, $item->tax->rate, needInclusive: false); } }); return [ 'hsn' => $firstItem->item->hsn, 'tax_id' => $firstItem->tax_id, 'tax_name' => $firstItem->tax->name, 'tax_rate' => $firstItem->tax->rate, 'total_taxable_amount' => $totalTaxableAmount, 'total_tax' => $group->sum('tax_amount') ]; }); }) ->flatMap(function ($hsnGroup) { return $hsnGroup; }) ->values(); } @endphp @foreach($taxSummary as $summary) @if(app('company')['tax_type'] == 'tax') @else @php $isCSGST = (empty($sale->state_id) || app('company')['state_id'] == $sale->state_id) ? true:false; @endphp @php $cs_gst = $i_gst = ''; $cs_gst_amt = $i_gst_amt = ''; if($isCSGST){ $cs_gst = ($summary['tax_rate']/2).'%'; $cs_gst_amt = $formatNumber->formatWithPrecision($summary['total_tax']/2); }else{ $i_gst = ($summary['tax_rate']).'%'; $i_gst_amt = $formatNumber->formatWithPrecision($summary['total_tax']); } @endphp @if($isCSGST) @else @endif @endif @endforeach
{{ __('tax.tax') }} {{ __('tax.taxable_amount') }} {{ __('tax.rate') }} {{ __('tax.tax_amount') }}
{{ __('item.hsn') }} {{ __('tax.taxable_amount') }} {{ __('tax.gst') }} {{ __('tax.tax_amount') }}
{{ __('tax.rate') }}% {{ __('app.amount') }}
{{ $summary['tax_name'] }} {{ $formatNumber->formatWithPrecision($summary['total_taxable_amount']) }} {{ $summary['tax_rate'] }}% {{ $formatNumber->formatWithPrecision($summary['total_tax']) }}
{{ $summary['hsn'] }} {{ $formatNumber->formatWithPrecision($summary['total_taxable_amount']) }} {{ $cs_gst }} {{ $cs_gst_amt }} {{ $i_gst }} {{ $i_gst_amt }}{{ $formatNumber->formatWithPrecision($summary['total_tax']) }}
@endif