@php $amountContainer = [ 'total_expense' => 0, 'cost_of_goods_sold' => 0, ]; $startDate = date('Y-m-d 00:00:00', strtotime(request()->date_from)); $endDate = date('Y-m-d 23:59:59', strtotime(request()->date_to)); @endphp
{!! $print['head'] !!}
@php $totalSalesAmount = floatval($total_sales->where('transaction_type', 3)->sum('total')); $totalSalesAmount = floatval($totalSalesAmount) - floatval($total_sales->where('transaction_type', 4)->sum('total')); @endphp
Sales
Sales Discount Return Total Sales
{{ number_format($total_sales->where('transaction_type', 3)->sum('sub_total') + $total_sales->where('transaction_type', 3)->sum('vat_amount'), 2) }} {{ number_format($total_sales->where('transaction_type', 3)->sum('manual_dc') - $total_sales->where('transaction_type', 4)->sum('manual_dc'), 2) }} {{ number_format($total_sales->where('transaction_type', 4)->sum('total'), 2) }} {{ number_format($totalSalesAmount, 2) }}
@foreach ($config as $key => $configItem) @if ($key == 'dscostofgoods') @continue @endif
@if ($configItem['dc_show'] == 1) @endif @php $groupLedger = $configItem['type'] == 1 ? 1 : 0; @endphp @foreach ($ledger_data->where('type', $groupLedger)->whereIn('auto_code', explode(',', $configItem['codes'])) as $item) @php $beforeFirstDateDebit = 0; if ($key != "dsexpenses") { if (isset($item->child) && $item->type == 1) { $beforeFirstDateDebit = array_sum( $item->child ->map(function ($q) use ($startDate, $endDate) { return $q->journalsForOpening ->where('type', 0) ->where('date', '<', $startDate) ->sum('amount'); }) ->toArray(), ); } else { $beforeFirstDateDebit = $item->journalsForOpening ->where('type', 0) ->where('date', '<', $startDate) ->sum('amount'); } } $beforeFirstDateCredit = 0; if ($key != "dsexpenses") { if (isset($item->child) && $item->type == 1) { $beforeFirstDateCredit = array_sum( $item->child ->map(function ($q) use ($startDate, $endDate) { return $q->journalsForOpening ->where('type', 1) ->where('date', '<', $startDate) ->sum('amount'); }) ->toArray(), ); } else { $beforeFirstDateCredit = $item->journalsForOpening ->where('type', 1) ->where('date', '<', $startDate) ->sum('amount'); } } $debit = 0; if (isset($item->child) && $item->type == 1) { $debit = array_sum( $item->child ->map(function ($q) use ($startDate, $endDate) { return $q->journals ->where('type', 0) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); }) ->toArray(), ); } else { $debit = $item->journals ->where('type', 0) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); } $credit = 0; if (isset($item->child) && $item->type == 1) { $credit = array_sum( $item->child ->map(function ($q) use ($startDate, $endDate) { return $q->journals ->where('type', 1) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); }) ->toArray(), ); } else { $credit = $item->journals ->where('type', 1) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); } $opening = $beforeFirstDateDebit - $beforeFirstDateCredit; $closingBalance = floatval($opening) + (floatval($debit) - floatval($credit)); if($key == "dsexpenses"){ $amountContainer['total_expense'] += $closingBalance; } $startingWith2or4 = $item->auto_code ?? ''; if ($startingWith2or4[0] == 2 || $startingWith2or4[0] == 4) { $closingBalance = $closingBalance * -1; } @endphp @if ($closingBalance == 0) @continue @endif @php $params = []; $params['info'] = $item; $params['start_date'] = $startDate; $params['end_date'] = $endDate; $params['block_type'] = $key; $params = json_encode($params); @endphp @if ($configItem['dc_show'] == 1) @endif @endforeach
{{ $configItem['title'] ?? '' }}
LedgerDebit CreditClosing Balance
{{ $item->name }}{{ number_format($debit, 2) }} {{ number_format($credit, 2) }}{{ number_format($closingBalance, 2) }}
@endforeach
@php $ledgerType = 1; if (isset($config['dscostofgoods']['type'])) { $ledgerType = $config['dscostofgoods']['type'] == 1 ? 1 : 0; } foreach ($ledger_data->where('type', $ledgerType)->whereIn('auto_code', explode(',', $config['dscostofgoods']['codes'] ?? ''))as $key => $cgs) { if (isset($cgs->child) && $cgs->type == 1) { $amountContainer['cost_of_goods_sold'] += array_sum( $cgs->child ->map(function ($q) use ($startDate, $endDate) { return $q->journals ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); }) ->toArray(), ); } else { $cgsVal = $cgs->journals ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); $amountContainer['cost_of_goods_sold'] += floatval($cgsVal); } } @endphp
Profit
Total Sales {{ number_format($totalSalesAmount, 2) }}
(-) Cost Of Goods Sold {{ number_format(floatval($amountContainer['cost_of_goods_sold']), 2) }}
(-) Expenses {{ number_format(floatval($amountContainer['total_expense']), 2) }}
Profit = @php $minusCostFromTotalSales = floatval($totalSalesAmount) - floatval($amountContainer['cost_of_goods_sold']); @endphp {{ number_format($minusCostFromTotalSales - $amountContainer['total_expense'], 2) }}