@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'), 2) }} {{ number_format($total_sales->where('transaction_type', 4)->sum('total'), 2) }} {{ number_format($totalSalesAmount, 2) }}
@foreach ($cash_bank as $cashBank) @php $beforeFirstDateDebit = 0; if (isset($cashBank->child) && $cashBank->type == 1) { $beforeFirstDateDebit = array_sum( $cashBank->child ->map(function ($q) use ($startDate, $endDate) { return $q->journals ->where('type', 0) ->where('date', '<', $startDate) ->sum('amount'); }) ->toArray(), ); } else { $beforeFirstDateDebit = $cashBank->journals ->where('type', 0) ->where('date', '<', $startDate) ->sum('amount'); } $beforeFirstDateCredit = 0; if (isset($cashBank->child) && $cashBank->type == 1) { $beforeFirstDateCredit = array_sum( $cashBank->child ->map(function ($q) use ($startDate, $endDate) { return $q->journals ->where('type', 1) ->where('date', '<', $startDate) ->sum('amount'); }) ->toArray(), ); } else { $beforeFirstDateCredit = $cashBank->journals ->where('type', 1) ->where('date', '<', $startDate) ->sum('amount'); } $debit = 0; if (isset($cashBank->child) && $cashBank->type == 1) { $debit = array_sum( $cashBank->child ->map(function ($q) use ($startDate, $endDate) { return $q->journals ->where('type', 0) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); }) ->toArray(), ); } else { $debit = $cashBank->journals ->where('type', 0) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); } $credit = 0; if (isset($cashBank->child) && $cashBank->type == 1) { $credit = array_sum( $cashBank->child ->map(function ($q) use ($startDate, $endDate) { return $q->journals ->where('type', 1) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); }) ->toArray(), ); } else { $credit = $cashBank->journals ->where('type', 1) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); } $opening = $beforeFirstDateDebit - $beforeFirstDateCredit; $closingBalance = floatval($opening) + (floatval($debit) - floatval($credit)); $startingWith2or4 = $cashBank->auto_code ?? ''; if ($startingWith2or4[0] == 2 || $startingWith2or4[0] == 4) { $closingBalance = $closingBalance * -1; } @endphp @if ($closingBalance == 0) @continue @endif @php $params = []; $params['info'] = $cashBank; $params['start_date'] = $startDate; $params['end_date'] = $endDate; $params['block_type'] = 'cashbank'; $params = json_encode($params); @endphp @endforeach
Cash Bank
Ledger Debit Credit Closing Balance
{{ $cashBank->name }} {{ number_format($debit, 2) }} {{ number_format($credit, 2) }} {{ number_format($closingBalance, 2) }}
@foreach ($supplier_balance as $supplier) @php $beforeFirstDateDebit = 0; if (isset($supplier->child) && $supplier->type == 1) { $beforeFirstDateDebit = array_sum( $supplier->child ->map(function ($q) use ($startDate, $endDate) { return $q->journals ->where('type', 0) ->where('date', '<', $startDate) ->sum('amount'); }) ->toArray(), ); } else { $beforeFirstDateDebit = $supplier->journals ->where('type', 0) ->where('date', '<', $startDate) ->sum('amount'); } $beforeFirstDateCredit = 0; if (isset($supplier->child) && $supplier->type == 1) { $beforeFirstDateCredit = array_sum( $supplier->child ->map(function ($q) use ($startDate, $endDate) { return $q->journals ->where('type', 1) ->where('date', '<', $startDate) ->sum('amount'); }) ->toArray(), ); } else { $beforeFirstDateCredit = $supplier->journals ->where('type', 1) ->where('date', '<', $startDate) ->sum('amount'); } $debit = 0; if (isset($supplier->child) && $supplier->type == 1) { $debit = array_sum( $supplier->child ->map(function ($q) use ($startDate, $endDate) { return $q->journals ->where('type', 0) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); }) ->toArray(), ); } else { $debit = $supplier->journals ->where('type', 0) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); } $credit = 0; if (isset($supplier->child) && $supplier->type == 1) { $credit = array_sum( $supplier->child ->map(function ($q) use ($startDate, $endDate) { return $q->journals ->where('type', 1) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); }) ->toArray(), ); } else { $credit = $supplier->journals ->where('type', 1) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); } $opening = $beforeFirstDateDebit - $beforeFirstDateCredit; $closingBalance = floatval($opening) + floatval($debit) - floatval($credit); $startingWith2or4 = $supplier->auto_code ?? ''; if ($startingWith2or4[0] == 2 || $startingWith2or4[0] == 4) { $closingBalance = $closingBalance * -1; } @endphp @if ($closingBalance == 0) @continue @endif @php $params = []; $params['info'] = $supplier; $params['start_date'] = $startDate; $params['end_date'] = $endDate; $params['block_type'] = 'supplier'; $params = json_encode($params); @endphp @endforeach
Supplier Balance
Group Debit Credit Closing Balance
{{ $supplier->name }} {{ number_format($debit, 2) }} {{ number_format($credit, 2) }} {{ number_format($closingBalance, 2) }}
@foreach ($payable as $pay) @php $beforeFirstDateDebit = 0; if (isset($cashBank->child) && $pay->type == 1) { $beforeFirstDateDebit = array_sum( $pay->child ->map(function ($q) use ($startDate, $endDate) { return $q->journals ->where('type', 0) ->where('date', '<', $startDate) ->sum('amount'); }) ->toArray(), ); } else { $beforeFirstDateDebit = $pay->journals ->where('type', 0) ->where('date', '<', $startDate) ->sum('amount'); } $beforeFirstDateCredit = 0; if (isset($pay->child) && $pay->type == 1) { $beforeFirstDateCredit = array_sum( $pay->child ->map(function ($q) use ($startDate, $endDate) { return $q->journals ->where('type', 1) ->where('date', '<', $startDate) ->sum('amount'); }) ->toArray(), ); } else { $beforeFirstDateCredit = $pay->journals ->where('type', 1) ->where('date', '<', $startDate) ->sum('amount'); } $debit = 0; if (isset($pay->child) && $pay->type == 1) { $debit = array_sum( $pay->child ->map(function ($q) use ($startDate, $endDate) { return $q->journals ->where('type', 0) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); }) ->toArray(), ); } else { $debit = $pay->journals ->where('type', 0) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); } $credit = 0; if (isset($pay->child) && $pay->type == 1) { $credit = array_sum( $pay->child ->map(function ($q) use ($startDate, $endDate) { return $q->journals ->where('type', 1) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); }) ->toArray(), ); } else { $credit = $pay->journals ->where('type', 1) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); } $opening = $beforeFirstDateDebit - $beforeFirstDateCredit; $closingBalance = floatval($opening) + floatval($debit) - floatval($credit); $startingWith2or4 = $pay->auto_code ?? ''; if ($startingWith2or4[0] == 2 || $startingWith2or4[0] == 4) { $closingBalance = $closingBalance * -1; } @endphp @if ($closingBalance == 0) @continue @endif @php $params = []; $params['info'] = $pay; $params['start_date'] = $startDate; $params['end_date'] = $endDate; $params['block_type'] = 'payable'; $params = json_encode($params); @endphp @endforeach
Payable
Ledger Debit Credit Closing Balance
{{ $pay->name }} {{ number_format($debit, 2) }} {{ number_format($credit, 2) }} {{ number_format($closingBalance, 2) }}
@foreach ($customer_balance as $customer) @php $beforeFirstDateDebit = 0; if (isset($customer->child) && $customer->type == 1) { $beforeFirstDateDebit = array_sum( $customer->child ->map(function ($q) use ($startDate, $endDate) { return $q->journals ->where('type', 0) ->where('date', '<', $startDate) ->sum('amount'); }) ->toArray(), ); } else { $beforeFirstDateDebit = $customer->journals ->where('type', 0) ->where('date', '<', $startDate) ->sum('amount'); } $beforeFirstDateCredit = 0; if (isset($customer->child) && $customer->type == 1) { $beforeFirstDateCredit = array_sum( $customer->child ->map(function ($q) use ($startDate, $endDate) { return $q->journals ->where('type', 1) ->where('date', '<', $startDate) ->sum('amount'); }) ->toArray(), ); } else { $beforeFirstDateCredit = $customer->journals ->where('type', 1) ->where('date', '<', $startDate) ->sum('amount'); } $debit = 0; if (isset($customer->child) && $customer->type == 1) { $debit = array_sum( $customer->child ->map(function ($q) use ($startDate, $endDate) { return $q->journals ->where('type', 0) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); }) ->toArray(), ); } else { $debit = $customer->journals ->where('type', 0) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); } $credit = 0; if (isset($customer->child) && $customer->type == 1) { $credit = array_sum( $customer->child ->map(function ($q) use ($startDate, $endDate) { return $q->journals ->where('type', 1) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); }) ->toArray(), ); } else { $credit = $customer->journals ->where('type', 1) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); } $opening = $beforeFirstDateDebit - $beforeFirstDateCredit; $closingBalance = floatval($opening) + (floatval($debit) - floatval($credit)); $startingWith2or4 = $customer->auto_code ?? ''; if ($startingWith2or4[0] == 2 || $startingWith2or4[0] == 4) { $closingBalance = $closingBalance * -1; } @endphp @if ($closingBalance == 0) @continue @endif @php $params = []; $params['info'] = $customer; $params['start_date'] = $startDate; $params['end_date'] = $endDate; $params['block_type'] = 'customer'; $params = json_encode($params); @endphp @endforeach
Customer Balance
Group Debit Credit Closing Balance
{{ $customer->name }} {{ number_format($debit, 2) }} {{ number_format($credit, 2) }} {{ number_format($closingBalance, 2) }}
@foreach ($daily_expense as $dailyExpense) @php $debit = 0; if (isset($dailyExpense->child) && $dailyExpense->type == 1) { $debit = array_sum( $dailyExpense->child ->map(function ($q) use ($startDate, $endDate) { return $q->journals ->where('type', 0) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); }) ->toArray(), ); } else { $debit = $dailyExpense->journals ->where('type', 0) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); } $credit = 0; if (isset($dailyExpense->child) && $dailyExpense->type == 1) { $credit = array_sum( $dailyExpense->child ->map(function ($q) use ($startDate, $endDate) { return $q->journals ->where('type', 1) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); }) ->toArray(), ); } else { $credit = $dailyExpense->journals ->where('type', 1) ->where('date', '>=', $startDate) ->where('date', '<=', $endDate) ->sum('amount'); } $closingBalance = floatval($debit) - floatval($credit); $amountContainer['total_expense'] += $closingBalance; @endphp @if ($closingBalance == 0) @continue @endif @endforeach
Daily Expenses
Ledger Closing Balance
{{ $dailyExpense->name }} {{ number_format($closingBalance, 2) }}
@php foreach ($cost_of_goods 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) }}