@if (isset($groupedDates))
@forelse($groupedDates as $key => $data)
@php
$sale_amount = App\Models\Invoice::whereMonth(
'date',
'=',
date('m', strtotime($key)),
)
->whereYear('date', '=', date('Y', strtotime($key)))
->sum('total_amount');
$invoiceItem = App\Models\InvoiceItem::with('invoice')
->whereHas('invoice', function ($query) use ($key) {
$query
->whereMonth('date', '=', date('m', strtotime($key)))
->whereYear('date', '=', date('Y', strtotime($key)));
})
->get();
$p_price = 0;
$profit = 0;
foreach ($invoiceItem as $invoice) {
$product = App\Models\Product::with('unit.related_unit')
->where('id', $invoice->product_id)
->first();
if ($product->unit->related_unit == null) {
$inv_stock = $invoice->main_qty;
$purchase_price = $inv_stock * $product->purchase_price;
$selling_price = $inv_stock * $product->selling_price;
$profits = $selling_price - $purchase_price;
} else {
//invoice
$inv_stock_main = $invoice->main_qty;
$inv_total_main =
(float) ($inv_stock_main * $product->unit->related_value);
$inv_total_sub = $invoice->sub_qty;
$inv_total_stock = (float) ($inv_total_main + $inv_total_sub);
$total_stock = $inv_total_stock;
$p_value = $product->purchase_price / $product->unit->related_value;
$s_value = $product->selling_price / $product->unit->related_value;
$purchase_price = $total_stock * $p_value;
$selling_price = $total_stock * $s_value;
$profits = $selling_price - $purchase_price;
}
$p_price += $purchase_price;
$profit += $profits;
}
$expense = App\Models\Expense::whereMonth(
'date',
'=',
date('m', strtotime($key)),
)
->whereYear('date', '=', date('Y', strtotime($key)))
->sum('amount');
$net_profit = (float) ($profit - $expense);
@endphp
| {{ date('F Y', strtotime($key)) }} |
{{ number_format($sale_amount, 2) }} TK |
{{ number_format($p_price, 2) }} TK |
{{ number_format($profit, 2) }} TK |
{{ number_format($expense, 2) }} TK |
{{ $net_profit >= 0 ? number_format($net_profit, 2) : '(' . number_format(abs($net_profit), 2) . ')' }}
TK |
@empty
| No Data Found |
@endforelse
@else
Please Select Start and End
Month
@endif