migrate to gtea from bistbucket
This commit is contained in:
60
Modules/Business/App/Exports/ExportBalanceSheet.php
Normal file
60
Modules/Business/App/Exports/ExportBalanceSheet.php
Normal file
@@ -0,0 +1,60 @@
|
||||
<?php
|
||||
|
||||
namespace Modules\Business\App\Exports;
|
||||
|
||||
use App\Models\PaymentType;
|
||||
use App\Models\Product;
|
||||
use Illuminate\Contracts\View\View;
|
||||
use Maatwebsite\Excel\Concerns\FromView;
|
||||
|
||||
class ExportBalanceSheet implements FromView
|
||||
{
|
||||
public function view(): View
|
||||
{
|
||||
$businessId = auth()->user()->business_id;
|
||||
|
||||
// PRODUCT
|
||||
$productQuery = Product::select('id', 'business_id', 'productName', 'product_type', 'created_at')
|
||||
->with(['stocks:id,business_id,product_id,productStock,productPurchasePrice', 'combo_products.stock'])
|
||||
->where('business_id', $businessId);
|
||||
$products = $productQuery->get()
|
||||
->map(function ($item) {
|
||||
$item->source = 'product';
|
||||
return $item;
|
||||
});
|
||||
|
||||
// BANK
|
||||
$bankQuery = PaymentType::where('business_id', $businessId);
|
||||
$banks = $bankQuery->get()
|
||||
->map(function ($item) {
|
||||
$item->source = 'bank';
|
||||
return $item;
|
||||
});
|
||||
|
||||
$asset_datas = $products->merge($banks);
|
||||
|
||||
// TOTAL STOCK VALUE
|
||||
$total_stock_value = 0;
|
||||
foreach ($products as $product) {
|
||||
if (in_array($product->product_type, ['single', 'variant'])) {
|
||||
foreach ($product->stocks as $stock) {
|
||||
$total_stock_value += $stock->productStock * $stock->productPurchasePrice;
|
||||
}
|
||||
}
|
||||
|
||||
if ($product->product_type === 'combo') {
|
||||
foreach ($product->combo_products as $combo) {
|
||||
$childStock = $combo->stock;
|
||||
if ($childStock) {
|
||||
$total_stock_value += ($childStock->productStock / $combo->quantity) * $combo->purchase_price;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
$totalBankBalance = $banks->sum('balance');
|
||||
$total_asset = $total_stock_value + $totalBankBalance;
|
||||
|
||||
return view('business::balance-sheets.excel-csv', compact('asset_datas', 'total_asset'));
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user