@php $b2cVoucherIds = $b2cVouchers->pluck('id'); $b2bVoucherIds = $b2bVouchers->pluck('id'); $b2bHsnCodes = \App\Models\AccountingVoucherItem::whereIn('accounting_voucher_id', $b2bVoucherIds) ->join('stock_items', 'accounting_voucher_items.stock_item_id', '=', 'stock_items.id') ->groupBy('stock_items.hsn_code') ->select('stock_items.hsn_code') ->orderBy('stock_items.hsn_code') ->get(); $b2cHsnCodes = \App\Models\AccountingVoucherItem::whereIn('accounting_voucher_id', $b2cVoucherIds) ->join('stock_items', 'accounting_voucher_items.stock_item_id', '=', 'stock_items.id') ->groupBy('stock_items.hsn_code') ->select('stock_items.hsn_code') ->orderBy('stock_items.hsn_code') ->get(); $bsbItems = \App\Models\AccountingVoucherItem::whereIn('accounting_voucher_id', $b2bVoucherIds->pluck('id')); $b2cItems = \App\Models\AccountingVoucherItem::whereIn( 'accounting_voucher_id', $b2cVouchers->pluck('id'), ); @endphp @foreach ($b2bHsnCodes as $hsnCode) @php $itemIds = \App\Models\StockItem::where('business_key', auth()->user()->business_key) ->where('hsn_code', $hsnCode->hsn_code) ->pluck('id') ->toArray(); $gstPercentages = [null,0,5,12,18,28]; @endphp @foreach ($gstPercentages as $gstPercentage) @php $acVoucherItems = (clone $bsbItems) ->WhereHas('stockItem', function ($query) use ($hsnCode, $gstPercentage) { $query->where('stock_items.hsn_code', $hsnCode->hsn_code); }) ->where('gst_per', $gstPercentage) ->select( 'accounting_voucher_id', DB::raw('SUM(quantity) as quantity'), DB::raw('SUM(taxable_value) as taxable_value'), DB::raw('SUM(cgst) as cgst'), DB::raw('SUM(sgst) as sgst'), DB::raw('SUM(igst) as igst'), DB::raw('SUM(cess) as cess'), DB::raw('SUM(total) as total'), ) ->groupBy('accounting_voucher_id') ->get(); @endphp @if ($acVoucherItems->count() > 0) @foreach ($acVoucherItems as $acVoucherItem) @php $acVoucher = \App\Models\AccountingVoucher::find($acVoucherItem->accounting_voucher_id); @endphp @if ($is_from == 'sales') @else @endif @endforeach @endif @endforeach @endforeach @foreach ($b2cHsnCodes as $hsnCode) @php $itemIds = \App\Models\StockItem::where('business_key', auth()->user()->business_key) ->where('hsn_code', $hsnCode->hsn_code) ->pluck('id') ->toArray(); $gstPercentages = [null,0,5,12,18,28]; @endphp @foreach ($gstPercentages as $gstPercentage) @php $acVoucherItems = (clone $b2cItems) ->WhereHas('stockItem', function ($query) use ($hsnCode, $gstPercentage) { $query->where('stock_items.hsn_code', $hsnCode->hsn_code); }) ->where('gst_per', $gstPercentage) ->select( 'accounting_voucher_id', DB::raw('SUM(quantity) as quantity'), DB::raw('SUM(taxable_value) as taxable_value'), DB::raw('SUM(cgst) as cgst'), DB::raw('SUM(sgst) as sgst'), DB::raw('SUM(igst) as igst'), DB::raw('SUM(cess) as cess'), DB::raw('SUM(total) as total'), ) ->groupBy('accounting_voucher_id') ->get(); @endphp @if ($acVoucherItems->count() > 0) @foreach ($acVoucherItems as $acVoucherItem) @php $acVoucher = \App\Models\AccountingVoucher::find($acVoucherItem->accounting_voucher_id); @endphp @endforeach @endif @endforeach @endforeach
Type Date Party GSTIN State Code State BillNo HSNCode Tax% QTY Taxable Amount CGST SGST IGST Cess Total Amount
GST B2B - {{ $hsnCode->hsn_code }} {{ $acVoucher->voucher_date }}{{ $acVoucher->debitLedger->name }} {{ $acVoucher->debitLedger->gst }} {{ $acVoucher->debitLedger->state_code }} {{ $acVoucher->debitLedger->state }}{{ $acVoucher->creditLedger->name }} {{ $acVoucher->creditLedger->gst }} {{ $acVoucher->creditLedger->state_code }} {{ $acVoucher->creditLedger->state }}{{ $acVoucher->voucher_number }} {{ $hsnCode->hsn_code }} {{ $gstPercentage }} {{ $acVoucherItem->quantity }} {{ $acVoucherItem->taxable_value }} {{ $acVoucherItem->cgst }} {{ $acVoucherItem->sgst }} {{ $acVoucherItem->igst }} {{ $acVoucherItem->cess }} {{ $acVoucherItem->total }}
Total GST B2B - {{ $hsnCode->hsn_code }} {{ $acVoucherItems->sum('quantity') }} {{ $acVoucherItems->sum('taxable_value') }} {{ $acVoucherItems->sum('cgst') }} {{ $acVoucherItems->sum('sgst') }} {{ $acVoucherItems->sum('igst') }} {{ $acVoucherItems->sum('cess') }} {{ $acVoucherItems->sum('total') }}
GST B2C - {{ $hsnCode->hsn_code }} {{ $acVoucher->voucher_date }} {{ $acVoucher->debitLedger->name }} {{ $acVoucher->debitLedger->gst }} {{ $acVoucher->debitLedger->state_code }} {{ $acVoucher->debitLedger->state }} {{ $acVoucher->voucher_number }} {{ $hsnCode->hsn_code }} {{ $gstPercentage }} {{ $acVoucherItem->quantity }} {{ $acVoucherItem->taxable_value }} {{ $acVoucherItem->cgst }} {{ $acVoucherItem->sgst }} {{ $acVoucherItem->igst }} {{ $acVoucherItem->cess }} {{ $acVoucherItem->total }}
Total GST B2C - {{ $hsnCode->hsn_code }} {{ $acVoucherItems->sum('quantity') }} {{ $acVoucherItems->sum('taxable_value') }} {{ $acVoucherItems->sum('cgst') }} {{ $acVoucherItems->sum('sgst') }} {{ $acVoucherItems->sum('igst') }} {{ $acVoucherItems->sum('cess') }} {{ $acVoucherItems->sum('total') }}