/
home
/
sjslayjy
/
public_html
/
mosaram
/
app
/
Http
/
Controllers
/
Upload File
HOME
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use Session; use DatePeriod; use DateInterval; use DateTime; use Illuminate\Support\Facades\DB; class StockController extends Controller { public function productCompanyRegister(Request $request) { $startTime = microtime(true); set_time_limit(180); // $currentMaxExecutionTime = ini_get('max_execution_time'); // echo "Current Maximum Execution Time: " . $currentMaxExecutionTime . " seconds"; // exit; $data = array(); $data['products'] = \App\Product::where('is_active', 1)->get(); $data['product_companies'] = \App\ProductCompany::where('is_active', 1)->get(); if ($request->isMethod('post')) { $validator = \Validator::make( $request->all(), array( 'product_company_id' => 'required', 'product_id' => 'required', ) ); if ($validator->fails()) { return redirect('user/party-register') ->withErrors($validator) ->withInput(); } else { $registers = array(); $period = new DatePeriod( new DateTime('2019-09-01'), new DateInterval('P1D'), new DateTime(date('Y-m-d', strtotime("tomorrow"))) ); $opening_stock = \App\OpeningInventory::where('product_company_id', $request->product_company_id)->where('product_id', $request->product_id)->sum('quantity'); $balance = $opening_stock; $total_rake = 0; $total_rake_shortage = 0; $total_loading = 0; $total_unloading = 0; $standard_open = 0; $standard_closed = 0; $total_out_warehouse_di = 0; $total_company_di = 0; foreach ($period as $key => $value) { $date = $value->format('Y-m-d'); /*------in------*/ $master_rakes = \App\MasterRake::where('product_company_id', $request->product_company_id)->whereDate('created_at', '=', $date)->get(); if (!is_null($master_rakes) && count($master_rakes) > 0) { foreach ($master_rakes as $master_rake) { $master_rake_products = \App\MasterRakeProduct::where('master_rake_id', $master_rake->id)->get(); if (!is_null($master_rake_products) && count($master_rake_products) > 0) { foreach ($master_rake_products as $master_rake_product) { if ($master_rake_product->product_id == $request->product_id) { $temp = array(); $temp['source'] = "Rake Arrived"; $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', 24)->name; $temp['party'] = getModelById('ProductCompany', $request->product_company_id)->name; $temp['product'] = getModelById('Product', $request->product_id)->name; $temp['truck_number'] = ""; $temp['in'] = $master_rake_product->quantity; $temp['out'] = 0; $balance += $master_rake_product->quantity; $temp['balance'] = $balance; array_push($registers, $temp); $total_rake += $master_rake_product->quantity; if ($master_rake_product->shortage_from_company > 0) { $temp = array(); $temp['source'] = "Rake Shortage"; $temp['date'] = $date; $temp['godown'] = 'R/H'; $temp['party'] = getModelById('ProductCompany', $request->product_company_id)->name; $temp['product'] = getModelById('Product', $request->product_id)->name; $temp['truck_number'] = ""; $temp['in'] = 0; $temp['out'] = $master_rake_product->shortage_from_company; $balance -= $master_rake_product->shortage_from_company; $temp['balance'] = $balance; array_push($registers, $temp); $total_rake_shortage += $master_rake_product->shortage_from_company; } } } } } } /*------in------*/ /*------out------*/ // $loading_query = \App\ProductLoading::query(); // $product_loadings = $loading_query->whereDate('created_at','=',$date)->where('product_company_id',$request->product_company_id)->where('product_id',$request->product_id)->where('loading_slip_type',2)->get(); // if(!is_null($product_loadings) && count($product_loadings) > 0){ // foreach ($product_loadings as $product_loading) { // $temp = array(); // $temp['source'] = "Product Loading<br><b>Loading# ".$product_loading->id."</b>"; // $temp['date'] = $date; // if(is_null($product_loading->master_rake_id)){ // $temp['godown'] = getModelById('Warehouse',$product_loading->from_warehouse_id)->name; // }else{ // $temp['godown'] = 'R/H'; // } // $temp['party'] = getModelById('ProductCompany',$request->product_company_id)->name; // $temp['product'] = $product_loading->product_name; // $temp['truck_number'] = $product_loading->truck_number; // $temp['in'] = 0; // $temp['out'] = $product_loading->quantity; // $balance -= $product_loading->quantity; // $temp['balance'] = $balance; // array_push($registers, $temp); // $total_loading += $product_loading->quantity; // } // } $company_di_query = \App\CompanyDi::query(); $company_dis = $company_di_query->whereDate('invoice_date', '=', $date)->where('product_company_id', $request->product_company_id)->where('product_id', $request->product_id)->get(); if (!is_null($company_dis) && count($company_dis) > 0) { foreach ($company_dis as $company_di) { $temp = array(); $temp['date'] = $date; $temp['source'] = "Company DI <br><b>" . getModelById('Dealer', $company_di->dealer_id)->name . '(' . getModelById('Dealer', $company_di->dealer_id)->address1 . ')' . "</b>"; $temp['godown'] = 'R/H'; $temp['party'] = getModelById('ProductCompany', $request->product_company_id)->name; $temp['truck_number'] = ""; $temp['product'] = getModelById('Product', $company_di->product_id)->name; $temp['in'] = 0; $temp['out'] = $company_di->quantity; $balance -= $company_di->quantity; $temp['balance'] = $balance; array_push($registers, $temp); $total_company_di += $company_di->quantity; } } $warehouse_di_query = \App\WarehouseDi::query(); $warehouse_dis = $warehouse_di_query->where('product_company_id', $request->product_company_id)->whereDate('invoice_date', '=', $date)->where('product_id', $request->product_id)->get(); if (!is_null($warehouse_dis) && count($warehouse_dis) > 0) { foreach ($warehouse_dis as $warehouse_di) { $temp = array(); $temp['date'] = $date; $temp['source'] = "Warehouse DI(Out) <br><b>" . getModelById('Dealer', $warehouse_di->dealer_id)->name . '(' . getModelById('Dealer', $warehouse_di->dealer_id)->address1 . ')' . "</b>"; $temp['godown'] = getModelById('Warehouse', $warehouse_di->warehouse_id)->name; $temp['party'] = getModelById('ProductCompany', $request->product_company_id)->name; $temp['product'] = getModelById('Product', $warehouse_di->product_id)->name; $temp['truck_number'] = ""; $temp['in'] = 0; $temp['out'] = $warehouse_di->quantity; $balance -= $warehouse_di->quantity; $temp['balance'] = $balance; array_push($registers, $temp); $total_out_warehouse_di += $warehouse_di->quantity; } } $standardization_query = \App\Standardization::query(); $standardizations = $standardization_query->where('open_product_brand_id', $request->product_company_id)->whereDate('created_at', '=', $date)->where('product_company_id', $request->product_company_id)->where('open_product_id', $request->product_id)->get(); if (!is_null($standardizations) && count($standardizations) > 0) { foreach ($standardizations as $standardization) { $temp = array(); $temp['source'] = "Standardization"; $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', $standardization->warehouse_id)->name; $temp['party'] = getModelById('ProductCompany', $request->product_company_id)->name; $temp['product'] = getModelById('Product', $standardization->closed_product_id)->name; $temp['truck_number'] = ""; $temp['in'] = 0; $temp['out'] = $standardization->open_quantity; $balance -= $standardization->open_quantity; $temp['balance'] = $balance; array_push($registers, $temp); $standard_open += $standardization->open_quantity; } } $StockAdjustment_query = \App\StockAdjustment::query(); $stock_adjustments = $StockAdjustment_query->whereDate('created_at', '=', $date)->where('company_id', $request->product_company_id)->where('adjust_type', 2)->where('product_id', $request->product_id)->get(); if (!is_null($stock_adjustments) && count($stock_adjustments) > 0) { foreach ($stock_adjustments as $stock_adjustment) { $temp['source'] = "Adjustment (Stock out)"; $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', $stock_adjustment->warehouse_id)->name; $temp['party'] = getModelById('ProductCompany', $stock_adjustment->company_id)->name; $temp['product'] = getModelById('Product', $stock_adjustment->product_id)->name; $temp['truck_number'] = ""; $temp['in'] = 0; $temp['out'] = $stock_adjustment->quantity; $balance -= $stock_adjustment->quantity; $temp['balance'] = $balance; array_push($registers, $temp); } } /*------out------*/ /*------in------*/ $direct_unloading_query = \App\ProductUnloading::query(); $product_unloadings = $direct_unloading_query->where('product_company_id', $request->product_company_id)->whereDate('created_at', '=', $date)->where('product_id', $request->product_id)->where('loading_slip_type', 0)->get(); if (!is_null($product_unloadings) && count($product_unloadings) > 0) { foreach ($product_unloadings as $product_unloading) { if ($product_unloading->loading_slip_type == 0) { $source = "<b>Direct</b>"; } else { $source = "<b>From R/H</b>"; } $temp['source'] = "Product Unloading <br>" . $source; $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', $product_unloading->warehouse_id)->name; $temp['party'] = getModelById('ProductCompany', $product_unloading->product_company_id)->name; $temp['product'] = $product_unloading->product_name; $temp['truck_number'] = $product_unloading->truck_number; $temp['in'] = $product_unloading->quantity; $temp['out'] = 0; $balance += $product_unloading->quantity; $temp['balance'] = $balance; array_push($registers, $temp); $total_unloading += $product_unloading->quantity; } } $standardization_query = \App\Standardization::query(); $standardizations = $standardization_query->where('closed_product_brand_id', $request->product_company_id)->whereDate('created_at', '=', $date)->where('product_company_id', $request->product_company_id)->where('closed_product_id', $request->product_id)->get(); if (!is_null($standardizations) && count($standardizations) > 0) { foreach ($standardizations as $standardization) { $temp = array(); $temp['source'] = "Standardization"; $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', $standardization->warehouse_id)->name; $temp['party'] = getModelById('ProductCompany', $product_unloading->product_company_id)->name; $temp['product'] = getModelById('Product', $standardization->closed_product_id)->name; $temp['truck_number'] = ""; $temp['in'] = $standardization->packed_quantity; $temp['out'] = 0; $balance += $standardization->packed_quantity; $temp['balance'] = $balance; array_push($registers, $temp); $standard_closed += $standardization->packed_quantity; } } $StockAdjustment_query = \App\StockAdjustment::query(); $stock_adjustments = $StockAdjustment_query->whereDate('created_at', '=', $date)->where('company_id', $request->product_company_id)->where('adjust_type', 1)->where('product_id', $request->product_id)->get(); if (!is_null($stock_adjustments) && count($stock_adjustments) > 0) { foreach ($stock_adjustments as $stock_adjustment) { $temp['source'] = "Adjustment (Stock in)"; $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', $stock_adjustment->warehouse_id)->name; $temp['party'] = getModelById('ProductCompany', $stock_adjustment->company_id)->name; $temp['product'] = getModelById('Product', $stock_adjustment->product_id)->name; $temp['truck_number'] = ""; $temp['in'] = $stock_adjustment->quantity; $temp['out'] = 0; $balance += $stock_adjustment->quantity; $temp['balance'] = $balance; array_push($registers, $temp); } } /*------in------*/ } // echo "<pre>"; // print_r($registers); // exit; $data['total_rake'] = $total_rake; $data['total_rake_shortage'] = $total_rake_shortage; $data['total_loading'] = $total_loading; $data['total_unloading'] = $total_unloading; $data['standard_open'] = $standard_open; $data['standard_closed'] = $standard_closed; $data['total_company_di'] = $total_company_di; $data['total_out_warehouse_di'] = $total_out_warehouse_di; $data['product_company_id'] = $request->product_company_id; $data['product_id'] = $request->product_id; $data['opening_stock'] = $opening_stock; $data['registers'] = $registers; } } else { $data['total_rake'] = 0; $data['total_rake_shortage'] = 0; $data['total_loading'] = 0; $data['total_unloading'] = 0; $data['standard_open'] = 0; $data['standard_closed'] = 0; $data['total_out_warehouse_di'] = 0; $data['total_company_di'] = 0; } $totalExecutionTime = microtime(true) - $startTime; // Check if the total elapsed time exceeds 180 seconds if ($totalExecutionTime > 180) { // Pass the message and time to the view $data['message'] = 'The operation is taking longer than expected! Please check your internet connection & try again.'; $data['executionTime'] = $totalExecutionTime; } return view('dashboard.inventory.product-company-register', $data); } public function partyRegister(Request $request) { $startTime = microtime(true); set_time_limit(180); $data = array(); $data['dealers'] = \App\Dealer::where('is_active', 1)->get(); $data['warehouses'] = \App\Warehouse::where('is_active', 1)->get(); $data['products'] = \App\Product::where('is_active', 1)->get(); $data['product_companies'] = \App\ProductCompany::where('is_active', 1)->get(); if ($request->isMethod('post')) { $validator = \Validator::make( $request->all(), array( 'dealer_id' => 'required', 'product_id' => 'required', ) ); if ($validator->fails()) { return redirect('user/party-register') ->withErrors($validator) ->withInput(); } else { $registers = array(); $period = new DatePeriod( new DateTime('2019-09-01'), new DateInterval('P1D'), new DateTime(date('Y-m-d', strtotime("tomorrow"))) ); if ($request->product_brand_id) { $opening_stock = \App\OpeningInventory::where('dealer_id', $request->dealer_id)->where('product_brand_id', $request->product_brand_id)->where('product_id', $request->product_id)->sum('quantity'); } else { $opening_stock = \App\OpeningInventory::where('dealer_id', $request->dealer_id)->where('product_id', $request->product_id)->sum('quantity'); } $balance = $opening_stock; $total_loading = 0; $standard_open = 0; $standard_closed = 0; $total_dealer_returned = 0; $total_retailer_returned = 0; $total_company_di = 0; $total_warehouse_di = 0; $total_out_warehouse_di = 0; $adjust_stock_in = 0; $adjust_stock_out = 0; foreach ($period as $key => $value) { $temp = array(); $date = $value->format('Y-m-d'); /*------out------*/ $loading_query = \App\ProductLoading::query(); if ($request->product_brand_id) { $loading_query->where('product_company_id', $request->product_brand_id); $data['product_brand_id'] = $request->product_brand_id; } $product_loadings = $loading_query->whereDate('created_at', '=', $date)->where('dealer_id', $request->dealer_id)->where('product_id', $request->product_id)->get(); if (!is_null($product_loadings) && count($product_loadings) > 0) { foreach ($product_loadings as $product_loading) { $temp['source'] = "Product Loading"; $temp['date'] = $date; if (is_null($product_loading->master_rake_id)) { $temp['godown'] = getModelById('Warehouse', $product_loading->from_warehouse_id)->name; } else { $temp['godown'] = 'R/H'; } $temp['party'] = getModelById('Dealer', $product_loading->dealer_id)->name . '(' . getModelById('Dealer', $product_loading->dealer_id)->address1 . ')'; $temp['product'] = $product_loading->product_name; $temp['truck_number'] = $product_loading->truck_number; $temp['in'] = 0; $temp['out'] = $product_loading->quantity; $balance -= $product_loading->quantity; $temp['balance'] = $balance; array_push($registers, $temp); $total_loading += $product_loading->quantity; } } $warehouse_di_query = \App\WarehouseDi::query(); if ($request->product_brand_id) { $warehouse_di_query->where('product_brand_id', $request->product_brand_id); $data['product_brand_id'] = $request->product_brand_id; } $warehouse_dis = $warehouse_di_query->whereDate('invoice_date', '=', $date)->where('from_dealer_id', $request->dealer_id)->where('product_id', $request->product_id)->get(); if (!is_null($warehouse_dis) && count($warehouse_dis) > 0) { foreach ($warehouse_dis as $warehouse_di) { $temp['date'] = $date; $temp['source'] = "Warehouse DI"; $temp['godown'] = getModelById('Warehouse', $warehouse_di->warehouse_id)->name; $temp['party'] = getModelById('Dealer', $warehouse_di->dealer_id)->name . '(' . getModelById('Dealer', $warehouse_di->dealer_id)->address1 . ')'; $temp['product'] = getModelById('Product', $warehouse_di->product_id)->name; $temp['truck_number'] = ""; $temp['in'] = 0; $temp['out'] = $warehouse_di->quantity; $balance -= $warehouse_di->quantity; $temp['balance'] = $balance; array_push($registers, $temp); $total_out_warehouse_di += $warehouse_di->quantity; } } $standardization_query = \App\Standardization::query(); if ($request->product_brand_id) { $standardization_query->where('open_product_brand_id', $request->product_brand_id); $data['product_brand_id'] = $request->product_brand_id; } $standardizations = $standardization_query->whereDate('created_at', '=', $date)->where('dealer_id', $request->dealer_id)->where('open_product_id', $request->product_id)->get(); if (!is_null($standardizations) && count($standardizations) > 0) { foreach ($standardizations as $standardization) { $temp['source'] = "Standardization"; $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', $standardization->warehouse_id)->name; $temp['party'] = getModelById('Dealer', $standardization->dealer_id)->name . '(' . getModelById('Dealer', $standardization->dealer_id)->address1 . ')'; $temp['product'] = getModelById('Product', $standardization->closed_product_id)->name; $temp['truck_number'] = ""; $temp['in'] = 0; $temp['out'] = $standardization->open_quantity; $balance -= $standardization->open_quantity; $temp['balance'] = $balance; array_push($registers, $temp); $standard_open += $standardization->open_quantity; } } $StockAdjustment_query = \App\StockAdjustment::query(); if ($request->product_brand_id) { $StockAdjustment_query->where('product_brand_id', $request->product_brand_id); } $stock_adjustments = $StockAdjustment_query->whereDate('created_at', '=', $date)->where('dealer_id', $request->dealer_id)->where('adjust_type', 2)->where('product_id', $request->product_id)->get(); if (!is_null($stock_adjustments) && count($stock_adjustments) > 0) { foreach ($stock_adjustments as $stock_adjustment) { $temp['source'] = "Adjustment (Stock out)"; $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', $stock_adjustment->warehouse_id)->name; if (!is_null($stock_adjustment->dealer_id)) { $temp['party'] = getModelById('Dealer', $stock_adjustment->dealer_id)->name . '(' . getModelById('Dealer', $stock_adjustment->dealer_id)->address1 . ')'; } else { $temp['party'] = getModelById('ProductCompany', $stock_adjustment->company_id)->name;; } $temp['product'] = getModelById('Product', $stock_adjustment->product_id)->name; $temp['truck_number'] = ""; $temp['in'] = 0; $temp['out'] = $stock_adjustment->quantity; $balance -= $stock_adjustment->quantity; $temp['balance'] = $balance; array_push($registers, $temp); $adjust_stock_in += $stock_adjustment->quantity; } } /*------out------*/ /*------in------*/ $excess_query = \App\RakeExcessShortage::query(); if ($request->product_brand_id) { $excess_query->where('product_brand_id', $request->product_brand_id); $data['product_brand_id'] = $request->product_brand_id; } $excesses = $excess_query->whereDate('created_at', '=', $date)->where('dealer_id', $request->dealer_id)->where('product_id', $request->product_id)->get(); if (!is_null($excesses) && count($excesses) > 0) { foreach ($excesses as $excess) { if ($excess->type == 1) { $temp['source'] = "Rake Excess <br><b>" . getModelById('MasterRake', $excess->master_rake_id)->name . "</b>"; } else { $temp['source'] = "Rake Shortage <br><b>" . getModelById('MasterRake', $excess->master_rake_id)->name . "</b>"; } $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', $excess->warehouse_id)->name; $temp['party'] = getModelById('Dealer', $excess->dealer_id)->name . '(' . getModelById('Dealer', $excess->dealer_id)->address1 . ')'; $temp['product'] = getModelById('Product', $excess->product_id)->name; $temp['truck_number'] = 'N/A'; $temp['in'] = $excess->quantity; $temp['out'] = 0; $balance += $excess->quantity; $temp['balance'] = $balance; array_push($registers, $temp); } } $unloading_query = \App\ProductUnloading::query(); if ($request->product_brand_id) { $unloading_query->where('product_company_id', $request->product_brand_id); $data['product_brand_id'] = $request->product_brand_id; } $product_unloadings = $unloading_query->whereDate('created_at', '=', $date)->where('dealer_id', $request->dealer_id)->where('product_id', $request->product_id)->get(); if (!is_null($product_unloadings) && count($product_unloadings) > 0) { foreach ($product_unloadings as $product_unloading) { $temp['source'] = "Dealer Returned"; $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', $product_unloading->warehouse_id)->name; $temp['party'] = getModelById('Dealer', $product_unloading->dealer_id)->name . '(' . getModelById('Dealer', $product_unloading->dealer_id)->address1 . ')'; $temp['product'] = $product_unloading->product_name; $temp['truck_number'] = $product_unloading->truck_number; $temp['in'] = $product_unloading->quantity; $temp['out'] = 0; $balance += $product_unloading->quantity; $temp['balance'] = $balance; array_push($registers, $temp); $total_dealer_returned += $product_unloading->quantity; } } $standardization_query = \App\Standardization::query(); if ($request->product_brand_id) { $standardization_query->where('closed_product_brand_id', $request->product_brand_id); } $standardizations = $standardization_query->whereDate('created_at', '=', $date)->where('dealer_id', $request->dealer_id)->where('closed_product_id', $request->product_id)->get(); if (!is_null($standardizations) && count($standardizations) > 0) { foreach ($standardizations as $standardization) { $temp['source'] = "Standardization"; $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', $standardization->warehouse_id)->name; $temp['party'] = getModelById('Dealer', $standardization->dealer_id)->name . '(' . getModelById('Dealer', $standardization->dealer_id)->address1 . ')'; $temp['product'] = getModelById('Product', $standardization->closed_product_id)->name; $temp['truck_number'] = ""; $temp['in'] = $standardization->packed_quantity; $temp['out'] = 0; $balance += $standardization->packed_quantity; $temp['balance'] = $balance; array_push($registers, $temp); $standard_closed += $standardization->packed_quantity; } } $return_query = \App\ReturnedProduct::query(); if ($request->product_brand_id) { $return_query->where('product_brand_id', $request->product_brand_id); $data['product_brand_id'] = $request->product_brand_id; } $returns = $return_query->whereDate('created_at', '=', $date)->where('dealer_id', $request->dealer_id)->where('product_id', $request->product_id)->get(); if (!is_null($returns) && count($returns) > 0) { foreach ($returns as $return) { $temp['source'] = "Retailer Returned"; $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', $return->warehouse_id)->name; $temp['party'] = getModelById('Dealer', $return->dealer_id)->name . '(' . getModelById('Dealer', $return->dealer_id)->address1 . ')'; $temp['product'] = getModelById('Product', $request->product_id)->name; $temp['truck_number'] = $return->vehicle_number; $temp['in'] = $return->returned_quantity; $temp['out'] = 0; $balance += $return->returned_quantity; $temp['balance'] = $balance; array_push($registers, $temp); $total_retailer_returned += $return->returned_quantity; } } $company_di_query = \App\CompanyDi::query(); if ($request->product_brand_id) { $company_di_query->where('product_company_id', $request->product_brand_id); $data['product_brand_id'] = $request->product_brand_id; } $company_dis = $company_di_query->whereDate('invoice_date', '=', $date)->where('dealer_id', $request->dealer_id)->where('product_id', $request->product_id)->get(); if (!is_null($company_dis) && count($company_dis) > 0) { foreach ($company_dis as $company_di) { $temp['date'] = $date; $product_company = "<br><b>" . getModelById('ProductCompany', $company_di->product_company_id)->name . "</b>"; $temp['source'] = "Company DI" . $product_company; $temp['godown'] = 'R/H'; $temp['party'] = getModelById('Dealer', $company_di->dealer_id)->name . '(' . getModelById('Dealer', $company_di->dealer_id)->address1 . ')'; $temp['truck_number'] = ""; $temp['product'] = getModelById('Product', $company_di->product_id)->name; $temp['in'] = $company_di->quantity; $temp['out'] = 0; $balance += $company_di->quantity; $temp['balance'] = $balance; array_push($registers, $temp); $total_company_di += $company_di->quantity; } } $warehouse_di_query = \App\WarehouseDi::query(); if ($request->product_brand_id) { $warehouse_di_query->where('product_brand_id', $request->product_brand_id); $data['product_brand_id'] = $request->product_brand_id; } $warehouse_dis = $warehouse_di_query->whereDate('invoice_date', '=', $date)->where('dealer_id', $request->dealer_id)->where('product_id', $request->product_id)->get(); if (!is_null($warehouse_dis) && count($warehouse_dis) > 0) { foreach ($warehouse_dis as $warehouse_di) { $temp['date'] = $date; $temp['source'] = "Warehouse DI"; $temp['godown'] = getModelById('Warehouse', $warehouse_di->warehouse_id)->name; $temp['party'] = getModelById('Dealer', $warehouse_di->dealer_id)->name . '(' . getModelById('Dealer', $warehouse_di->dealer_id)->address1 . ')'; $temp['product'] = getModelById('Product', $warehouse_di->product_id)->name; $temp['truck_number'] = ""; $temp['in'] = $warehouse_di->quantity; $temp['out'] = 0; $balance += $warehouse_di->quantity; $temp['balance'] = $balance; array_push($registers, $temp); $total_warehouse_di += $warehouse_di->quantity; } } $StockAdjustment_query = \App\StockAdjustment::query(); if ($request->product_brand_id) { $StockAdjustment_query->where('product_brand_id', $request->product_brand_id); } $stock_adjustments = $StockAdjustment_query->whereDate('created_at', '=', $date)->where('dealer_id', $request->dealer_id)->where('adjust_type', 1)->where('product_id', $request->product_id)->get(); if (!is_null($stock_adjustments) && count($stock_adjustments) > 0) { foreach ($stock_adjustments as $stock_adjustment) { $temp['source'] = "Adjustment (Stock in)"; $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', $stock_adjustment->warehouse_id)->name; if (!is_null($stock_adjustment->dealer_id)) { $temp['party'] = getModelById('Dealer', $stock_adjustment->dealer_id)->name . '(' . getModelById('Dealer', $stock_adjustment->dealer_id)->address1 . ')'; } else { $temp['party'] = getModelById('ProductCompany', $stock_adjustment->company_id)->name;; } $temp['product'] = getModelById('Product', $stock_adjustment->product_id)->name; $temp['truck_number'] = ""; $temp['in'] = $stock_adjustment->quantity; $temp['out'] = 0; $balance += $stock_adjustment->quantity; $temp['balance'] = $balance; array_push($registers, $temp); $adjust_stock_in += $stock_adjustment->quantity; } } /*------in------*/ } // echo "<pre>"; // print_r($registers); // exit; $data['total_loading'] = $total_loading; $data['standard_open'] = $standard_open; $data['standard_closed'] = $standard_closed; $data['total_dealer_returned'] = $total_dealer_returned; $data['total_retailer_returned'] = $total_retailer_returned; $data['total_company_di'] = $total_company_di; $data['total_warehouse_di'] = $total_warehouse_di; $data['total_out_warehouse_di'] = $total_out_warehouse_di; $data['dealer_id'] = $request->dealer_id; $data['product_id'] = $request->product_id; $data['opening_stock'] = $opening_stock; $data['registers'] = $registers; } } else { $data['total_loading'] = 0; $data['standard_open'] = 0; $data['standard_closed'] = 0; $data['total_dealer_returned'] = 0; $data['total_retailer_returned'] = 0; $data['total_company_di'] = 0; $data['total_warehouse_di'] = 0; $data['total_out_warehouse_di'] = 0; } $totalExecutionTime = microtime(true) - $startTime; // Check if the total elapsed time exceeds 180 seconds if ($totalExecutionTime > 180) { // Pass the message and time to the view $data['message'] = 'The operation is taking longer than expected! Please check your internet connection & try again.'; $data['executionTime'] = $totalExecutionTime; } return view('dashboard.inventory.party-register', $data); } public function godownRegister(Request $request) { $startTime = microtime(true); set_time_limit(180); $data = array(); $data['product_companies'] = \App\ProductCompany::where('is_active', 1)->get(); $data['warehouses'] = \App\Warehouse::where('is_active', 1)->get(); $data['products'] = \App\Product::where('is_active', 1)->get(); if ($request->isMethod('post')) { $validator = \Validator::make( $request->all(), array( 'product_brand_id' => 'required', 'product_id' => 'required', 'warehouse_id' => 'required', ) ); if ($validator->fails()) { return redirect('user/godown-register') ->withErrors($validator) ->withInput(); } else { $registers = array(); $opening_stock = \App\OpeningInventory::where('warehouse_id', $request->warehouse_id)->where('product_brand_id', $request->product_brand_id)->where('product_id', $request->product_id)->sum('quantity'); $period = new DatePeriod( new DateTime('2019-09-01'), new DateInterval('P1D'), new DateTime(date('Y-m-d', strtotime("tomorrow"))) ); $balance = $opening_stock; $total_loading = 0; $total_unloading = 0; $total_in_warehouse_di = 0; $total_out_warehouse_di = 0; $standard_closed = 0; $standard_open = 0; $total_dealer_returned = 0; $total_retailer_returned = 0; $total_wt_loading = 0; $total_wt_unloading = 0; $adjust_stock_out = 0; $adjust_stock_in = 0; foreach ($period as $key => $value) { $temp = array(); $date = $value->format('Y-m-d'); /*------in------*/ $unloading_query = \App\ProductUnloading::query(); $product_unloadings = $unloading_query->where('product_company_id', $request->product_brand_id)->whereDate('created_at', '=', $date)->where('product_id', $request->product_id)->where('loading_slip_type', '!=', 1)->where('warehouse_id', $request->warehouse_id)->get(); if (!is_null($product_unloadings) && count($product_unloadings) > 0) { foreach ($product_unloadings as $product_unloading) { if ($product_unloading->loading_slip_type == 0) { $source = "(Direct)"; } else if ($product_unloading->loading_slip_type == 1) { $source = "(Token)"; } else if ($product_unloading->loading_slip_type == 2) { $source = "(Without Token from R/H)"; } $temp['source'] = "Product Unloading " . $source; $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', $product_unloading->warehouse_id)->name; if (!is_null($product_unloading->dealer_id)) { $temp['party'] = getModelById('Dealer', $product_unloading->dealer_id)->name . '(' . getModelById('Dealer', $product_unloading->dealer_id)->address1 . ')'; } else { $temp['party'] = getModelById('ProductCompany', $product_unloading->product_company_id)->name; } $temp['product'] = $product_unloading->product_name; $temp['truck_number'] = $product_unloading->truck_number; $temp['in'] = $product_unloading->quantity; $temp['out'] = 0; $balance += $product_unloading->quantity; $temp['balance'] = $balance; array_push($registers, $temp); $total_unloading += $product_unloading->quantity; } } /*-------------------unloaded without unloading system-----------------------*/ $loading_query = \App\ProductLoading::query(); $product_loadings = $loading_query->where('product_company_id', $request->product_brand_id)->whereDate('created_at', '=', $date)->where('product_id', $request->product_id)->where('loading_slip_type', 2)->where('is_approved', 1)->where('recieved_quantity', 0)->where('warehouse_id', $request->warehouse_id)->get(); if (!is_null($product_loadings) && count($product_loadings) > 0) { foreach ($product_loadings as $product_loading) { $unloading = \App\ProductUnloading::where('product_loading_id', $product_loading->id)->first(); if (is_null($unloading)) { $temp['source'] = "Product Unloading (Without Token from R/H)"; $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', $product_loading->warehouse_id)->name; if (!is_null($product_loading->dealer_id)) { $temp['party'] = getModelById('Dealer', $product_loading->dealer_id)->name . '(' . getModelById('Dealer', $product_loading->dealer_id)->address1 . ')'; } else { $temp['party'] = getModelById('ProductCompany', $product_loading->product_company_id)->name; } $temp['product'] = $product_loading->product_name; $temp['truck_number'] = $product_loading->truck_number; $temp['in'] = $product_loading->quantity; $temp['out'] = 0; $balance += $product_loading->quantity; $temp['balance'] = $balance; array_push($registers, $temp); $total_unloading += $product_loading->quantity; } } } /*-------------------unloaded without unloading system-----------------------*/ $StockAdjustment_query = \App\StockAdjustment::query(); if ($request->product_brand_id) { $StockAdjustment_query->where('product_brand_id', $request->product_brand_id); } $stock_adjustments = $StockAdjustment_query->whereDate('created_at', '=', $date)->where('warehouse_id', $request->warehouse_id)->where('adjust_type', 1)->where('product_id', $request->product_id)->get(); if (!is_null($stock_adjustments) && count($stock_adjustments) > 0) { foreach ($stock_adjustments as $stock_adjustment) { $temp['source'] = "Adjustment (Stock IN)"; $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', $stock_adjustment->warehouse_id)->name; if (!is_null($stock_adjustment->dealer_id)) { $temp['party'] = getModelById('Dealer', $stock_adjustment->dealer_id)->name . '(' . getModelById('Dealer', $stock_adjustment->dealer_id)->address1 . ')'; } else { $temp['party'] = getModelById('ProductCompany', $stock_adjustment->company_id)->name; } $temp['product'] = getModelById('Product', $stock_adjustment->product_id)->name; $temp['truck_number'] = ""; $temp['in'] = $stock_adjustment->quantity; $temp['out'] = 0; $balance += $stock_adjustment->quantity; $temp['balance'] = $balance; array_push($registers, $temp); // $adjust_stock_in += $stock_adjustment->quantity; } } // $warehouse_di_query = \App\WarehouseDi::query(); // $warehouse_dis = $warehouse_di_query->where('product_brand_id',$request->product_brand_id)->whereDate('invoice_date','=',$date)->where('warehouse_id',$request->warehouse_id)->where('product_id',$request->product_id)->get(); // if(!is_null($warehouse_dis) && count($warehouse_dis) > 0){ // foreach ($warehouse_dis as $warehouse_di) { // $temp['date'] = $date; // if($warehouse_di->transfer_type == 1){ // $transfer_type = "Company To Dealer"; // }else{ // $transfer_type = "Dealer To Dealer"; // } // $temp['source'] = $transfer_type." Warehouse DI (IN)"; // $temp['godown'] = getModelById('Warehouse',$warehouse_di->warehouse_id)->name; // $temp['party'] = getModelById('Dealer',$warehouse_di->dealer_id)->name.'('.getModelById('Dealer',$warehouse_di->dealer_id)->address1.')'; // $temp['product'] = getModelById('Product',$warehouse_di->product_id)->name; // $temp['truck_number'] = ""; // $temp['out'] = 0; // $temp['in'] = $warehouse_di->quantity; // $balance += $warehouse_di->quantity; // $temp['balance'] = $balance; // array_push($registers, $temp); // $total_in_warehouse_di += $warehouse_di->quantity; // } // } $standardization_query = \App\Standardization::query(); $standardizations = $standardization_query->whereDate('created_at', '=', $date)->where('warehouse_id', $request->warehouse_id)->where('closed_product_brand_id', $request->product_brand_id)->where('closed_product_id', $request->product_id)->get(); if (!is_null($standardizations) && count($standardizations) > 0) { foreach ($standardizations as $standardization) { $temp['source'] = "Standardization (Packed)"; $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', $standardization->warehouse_id)->name; if (!is_null($standardization->dealer_id)) { $temp['party'] = getModelById('Dealer', $standardization->dealer_id)->name . '(' . getModelById('Dealer', $standardization->dealer_id)->address1 . ')'; } else { $temp['party'] = getModelById('ProductCompany', $standardization->product_company_id)->name; } $temp['product'] = getModelById('Product', $standardization->closed_product_id)->name; $temp['truck_number'] = ""; $temp['in'] = $standardization->packed_quantity; $temp['out'] = 0; $balance += $standardization->packed_quantity; $temp['balance'] = $balance; array_push($registers, $temp); $standard_closed += $standardization->packed_quantity; } } $return_query = \App\ReturnedProduct::query(); $returns = $return_query->whereDate('created_at', '=', $date)->where('product_brand_id', $request->product_brand_id)->where('warehouse_id', $request->warehouse_id)->where('product_id', $request->product_id)->get(); if (!is_null($returns) && count($returns) > 0) { foreach ($returns as $return) { $temp['source'] = "Retailer Returned <br> <b>(" . getModelById('Retailer', $return->retailer_id)->name . '(' . getModelById('Retailer', $return->retailer_id)->address . ')' . ")</b>"; $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', $return->warehouse_id)->name; $temp['party'] = getModelById('Dealer', $return->dealer_id)->name . '(' . getModelById('Dealer', $return->dealer_id)->address1 . ')'; $temp['product'] = getModelById('Product', $request->product_id)->name; $temp['truck_number'] = $return->vehicle_number; $temp['in'] = $return->returned_quantity; $temp['out'] = 0; $balance += $return->returned_quantity; $temp['balance'] = $balance; array_push($registers, $temp); $total_retailer_returned += $return->returned_quantity; } } $dealer_return_query = \App\ProductLoading::query(); $dealer_returns = $dealer_return_query->whereDate('created_at', '=', $date)->where('warehouse_id', $request->warehouse_id)->where('product_company_id', $request->product_brand_id)->where('product_id', $request->product_id)->whereNotNull('dealer_id')->where('recieved_quantity', '>', 0)->get(); if (!is_null($dealer_returns) && count($dealer_returns) > 0) { foreach ($dealer_returns as $dealer_return) { $unload_record = \App\ProductUnloading::where('product_loading_id', $dealer_return->id)->first(); $temp['source'] = "Dealer Returned"; $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', $unload_record->warehouse_id)->name; $temp['party'] = getModelById('Dealer', $dealer_return->dealer_id)->name . '(' . getModelById('Dealer', $dealer_return->dealer_id)->address1 . ')'; $temp['product'] = $dealer_return->product_name; $temp['truck_number'] = $dealer_return->truck_number; $temp['in'] = $dealer_return->recieved_quantity; $temp['out'] = 0; $balance += $dealer_return->recieved_quantity; $temp['balance'] = $balance; array_push($registers, $temp); $total_dealer_returned += $dealer_return->recieved_quantity; } } $wt_unloading_query = \App\WarehouseTransferUnloading::query(); $wt_unloadings = $wt_unloading_query->whereDate('created_at', '=', $date)->where('to_warehouse_id', $request->warehouse_id)->where('product_brand_id', $request->product_brand_id)->where('product_id', $request->product_id)->get(); if (!is_null($wt_unloadings) && count($wt_unloadings) > 0) { foreach ($wt_unloadings as $wt_unloading) { $temp['source'] = "Warehouse Transfer Unloading"; $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', $wt_unloading->to_warehouse_id)->name; $temp['party'] = ""; $temp['product'] = getModelById('Product', $wt_unloading->product_id)->name; $temp['truck_number'] = ''; $temp['in'] = $wt_unloading->quantity; $temp['out'] = 0; $balance += $wt_unloading->quantity; $temp['balance'] = $balance; array_push($registers, $temp); $total_wt_unloading += $wt_unloading->quantity; } } /*------in------*/ /*------out------*/ $loading_query = \App\ProductLoading::query(); $product_loadings = $loading_query->whereDate('created_at', '=', $date)->where('product_company_id', $request->product_brand_id)->where('from_warehouse_id', $request->warehouse_id)->where('product_id', $request->product_id)->get(); if (!is_null($product_loadings) && count($product_loadings) > 0) { foreach ($product_loadings as $product_loading) { $temp['source'] = "Product Loading"; $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', $product_loading->from_warehouse_id)->name; if (!is_null($product_loading->retailer_id)) { $party = getModelById('Retailer', $product_loading->retailer_id)->name . '(' . getModelById('Retailer', $product_loading->retailer_id)->address . ') <br> <b> ' . getModelById('Dealer', $product_loading->dealer_id)->name . '(' . getModelById('Dealer', $product_loading->dealer_id)->address1 . ')' . '</b>'; } else { $party = getModelById('Dealer', $product_loading->dealer_id)->name . '(' . getModelById('Dealer', $product_loading->dealer_id)->address1 . ')'; } $temp['party'] = $party; $temp['product'] = $product_loading->product_name; $temp['truck_number'] = $product_loading->truck_number; $temp['in'] = 0; $temp['out'] = $product_loading->quantity; $balance -= $product_loading->quantity; $temp['balance'] = $balance; array_push($registers, $temp); $total_loading += $product_loading->quantity; } } $StockAdjustment_query = \App\StockAdjustment::query(); if ($request->product_brand_id) { $StockAdjustment_query->where('product_brand_id', $request->product_brand_id); } $stock_adjustments = $StockAdjustment_query->whereDate('created_at', '=', $date)->where('warehouse_id', $request->warehouse_id)->where('adjust_type', 2)->where('product_id', $request->product_id)->get(); if (!is_null($stock_adjustments) && count($stock_adjustments) > 0) { foreach ($stock_adjustments as $stock_adjustment) { $temp['source'] = "Adjustment (Stock out)"; $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', $stock_adjustment->warehouse_id)->name; if (!is_null($stock_adjustment->dealer_id)) { $temp['party'] = getModelById('Dealer', $stock_adjustment->dealer_id)->name . '(' . getModelById('Dealer', $stock_adjustment->dealer_id)->address1 . ')'; } else { $temp['party'] = getModelById('ProductCompany', $stock_adjustment->company_id)->name;; } $temp['product'] = getModelById('Product', $stock_adjustment->product_id)->name; $temp['truck_number'] = ""; $temp['in'] = 0; $temp['out'] = $stock_adjustment->quantity; $balance -= $stock_adjustment->quantity; $temp['balance'] = $balance; array_push($registers, $temp); // $adjust_stock_out += $stock_adjustment->quantity; } } // $warehouse_di_query = \App\WarehouseDi::query(); // $warehouse_dis = $warehouse_di_query->where('product_brand_id',$request->product_brand_id)->whereDate('invoice_date','=',$date)->where('warehouse_id',$request->warehouse_id)->where('product_id',$request->product_id)->get(); // if(!is_null($warehouse_dis) && count($warehouse_dis) > 0){ // foreach ($warehouse_dis as $warehouse_di) { // $temp['date'] = $date; // if($warehouse_di->transfer_type == 1){ // $transfer_type = "Company To Dealer"; // }else{ // $transfer_type = "Dealer To Dealer"; // } // $temp['source'] = $transfer_type." Warehouse DI (OUT)"; // $temp['godown'] = getModelById('Warehouse',$warehouse_di->warehouse_id)->name; // if($warehouse_di->transfer_type == 1){ // $party = getModelById('ProductCompany',$warehouse_di->product_company_id)->name; // }else{ // $party = getModelById('Dealer',$warehouse_di->from_dealer_id)->name.'('.getModelById('Dealer',$warehouse_di->from_dealer_id)->address1.')'; // } // $temp['party'] = $party; // $temp['product'] = getModelById('Product',$warehouse_di->product_id)->name; // $temp['truck_number'] = ""; // $temp['in'] = 0; // $temp['out'] = $warehouse_di->quantity; // $balance -= $warehouse_di->quantity; // $temp['balance'] = $balance; // array_push($registers, $temp); // $total_out_warehouse_di += $warehouse_di->quantity; // } // } $standardization_query = \App\Standardization::query(); $standardizations = $standardization_query->whereDate('created_at', '=', $date)->where('warehouse_id', $request->warehouse_id)->where('open_product_brand_id', $request->product_brand_id)->where('open_product_id', $request->product_id)->get(); if (!is_null($standardizations) && count($standardizations) > 0) { foreach ($standardizations as $standardization) { $temp['source'] = "Standardization (Open)"; $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', $standardization->warehouse_id)->name; if (!is_null($standardization->dealer_id)) { $temp['party'] = getModelById('Dealer', $standardization->dealer_id)->name . '(' . getModelById('Dealer', $standardization->dealer_id)->address1 . ')'; } else { $temp['party'] = getModelById('ProductCompany', $standardization->product_company_id)->name; } $temp['product'] = getModelById('Product', $standardization->closed_product_id)->name; $temp['truck_number'] = ""; $temp['in'] = 0; $temp['out'] = $standardization->open_quantity; $balance -= $standardization->open_quantity; $temp['balance'] = $balance; array_push($registers, $temp); $standard_open += $standardization->open_quantity; } } $wt_loading_query = \App\WarehouseTransferLoading::query(); $wt_loadings = $wt_loading_query->whereDate('created_at', '=', $date)->where('from_warehouse_id', $request->warehouse_id)->where('product_brand_id', $request->product_brand_id)->where('product_id', $request->product_id)->where('received_quantity', '>', 0)->get(); if (!is_null($wt_loadings) && count($wt_loadings) > 0) { foreach ($wt_loadings as $wt_loading) { $temp['source'] = "Warehouse Transfer Loading"; $temp['date'] = $date; $temp['godown'] = getModelById('Warehouse', $wt_loading->from_warehouse_id)->name; $temp['party'] = ""; $temp['product'] = getModelById('Product', $wt_loading->product_id)->name; $temp['truck_number'] = $wt_loading->truck_number; $temp['in'] = $wt_loading->received_quantity; $temp['out'] = 0; $balance -= $wt_loading->received_quantity; $temp['balance'] = $balance; array_push($registers, $temp); $total_wt_loading += $wt_loading->received_quantity; } } /*------out------*/ } $data['total_loading'] = $total_loading; $data['total_unloading'] = $total_unloading; $data['total_in_warehouse_di'] = $total_in_warehouse_di; $data['total_out_warehouse_di'] = $total_out_warehouse_di; $data['standard_closed'] = $standard_closed; $data['standard_open'] = $standard_open; $data['total_dealer_returned'] = $total_dealer_returned; $data['total_retailer_returned'] = $total_retailer_returned; $data['total_wt_loading'] = $total_wt_loading; $data['total_wt_unloading'] = $total_wt_unloading; $data['product_brand_id'] = $request->product_brand_id; $data['warehouse_id'] = $request->warehouse_id; $data['product_id'] = $request->product_id; $data['opening_stock'] = $opening_stock; $data['registers'] = $registers; } } else { $data['total_loading'] = 0; $data['total_unloading'] = 0; $data['total_in_warehouse_di'] = 0; $data['total_out_warehouse_di'] = 0; $data['standard_closed'] = 0; $data['standard_open'] = 0; $data['total_dealer_returned'] = 0; $data['total_retailer_returned'] = 0; $data['total_wt_loading'] = 0; $data['total_wt_unloading'] = 0; $data['opening_stock'] = 0; $data['registers'] = array(); } $totalExecutionTime = microtime(true) - $startTime; // Check if the total elapsed time exceeds 180 seconds if ($totalExecutionTime > 180) { // Pass the message and time to the view $data['message'] = 'The operation is taking longer than expected! Please check your internet connection & try again.'; $data['executionTime'] = $totalExecutionTime; } return view('dashboard.inventory.godown-register', $data); } /*-----------------Company Godown Stock----------------------*/ public function companyGodownStock(Request $request) { $data = array(); $data['product_companies'] = \App\ProductCompany::where('is_active', 1)->get(); $data['products'] = \App\Product::where('is_active', 1)->get(); $data['warehouses'] = \App\Warehouse::where('is_active', 1)->get(); $data['products'] = \App\Product::where('is_active', 1)->get(); if ($request->isMethod('post')) { $validator = \Validator::make( $request->all(), array( // 'product_company_id' =>'required', // 'warehouse_id' =>'required' ) ); if ($validator->fails()) { return redirect('user/company-godown-stock') ->withErrors($validator) ->withInput(); } else { $stocks = array(); $total = 0; if ($request->product_company_id) { $product_companies = \App\ProductCompany::where('is_active', 1)->where('id', $request->product_company_id)->pluck('id'); } else { $product_companies = \App\ProductCompany::where('is_active', 1)->pluck('id'); } foreach ($product_companies as $product_company) { $request->product_company_id = $product_company; if ($request->warehouse_id) { $warehouse_ids = \App\Warehouse::where('id', $request->warehouse_id)->pluck('id'); } else { $warehouse_ids = \App\Warehouse::pluck('id'); } foreach ($warehouse_ids as $warehouse_id) { $request->warehouse_id = $warehouse_id; $tempArr = array(); if ($request->product_id) { $product_ids = \App\Product::where('id', $request->product_id)->pluck('id'); } else { $product_ids = \App\Product::pluck('id'); } foreach ($product_ids as $product_id) { $opening_stock = \App\OpeningInventory::where('warehouse_id', $request->warehouse_id)->where('product_brand_id', $request->product_company_id)->where('product_id', $product_id)->sum('quantity'); $balance = $opening_stock; /*------in------*/ // $unloading_query = \App\ProductUnloading::query(); $unloading_query = \DB::table('product_unloadings'); $product_unloadings = $unloading_query->where('product_company_id', $request->product_company_id)->where('product_id', $product_id)->where('loading_slip_type', '!=', 1)->where('warehouse_id', $request->warehouse_id)->sum('quantity'); $balance += $product_unloadings; /*-------------------unloaded without unloading system-----------------------*/ // $loading_query = \App\ProductLoading::query(); $loading_query = \DB::table('product_loadings'); $product_loadings = $loading_query->where('product_company_id', $request->product_company_id)->where('product_id', $product_id)->where('loading_slip_type', 2)->where('is_approved', 1)->where('recieved_quantity', 0)->where('warehouse_id', $request->warehouse_id)->get(); if (!is_null($product_loadings) && count($product_loadings) > 0) { foreach ($product_loadings as $product_loading) { $unloading = \App\ProductUnloading::where('product_loading_id', $product_loading->id)->first(); if (is_null($unloading)) { $balance += $product_loading->quantity; } } } /*-------------------unloaded without unloading system-----------------------*/ // $warehouse_di_query = \DB::table('warehouse_dis'); // if($request->product_company_id){ // $warehouse_di_query->where('product_company_id',$request->product_company_id)->where('product_brand_id',$request->product_company_id)->where('warehouse_id',$request->warehouse_id); // } // $warehouse_dis = $warehouse_di_query->where('product_id',$product_id)->sum('quantity'); // $balance += $warehouse_dis; // $StockAdjustment_query = \App\StockAdjustment::query(); $StockAdjustment_query = \DB::table('stock_adjustments'); if ($request->product_company_id) { $StockAdjustment_query->where('product_brand_id', $request->product_company_id); } $stock_adjustments = $StockAdjustment_query->where('warehouse_id', $request->warehouse_id)->where('adjust_type', 1)->where('product_id', $product_id)->sum('quantity'); $balance += $stock_adjustments; // $standardization_query = \App\Standardization::query(); $standardization_query = \DB::table('standardizations'); $standardizations = $standardization_query->where('warehouse_id', $request->warehouse_id)->where('closed_product_brand_id', $request->product_company_id)->where('closed_product_id', $product_id)->sum('packed_quantity'); $balance += $standardizations; // $return_query = \App\ReturnedProduct::query(); $return_query = \DB::table('returned_products'); $returns = $return_query->where('product_brand_id', $request->product_company_id)->where('warehouse_id', $request->warehouse_id)->where('product_id', $product_id)->sum('returned_quantity'); $balance += $returns; // $dealer_return_query = \App\ProductLoading::query(); $dealer_return_query = \DB::table('product_loadings'); $dealer_returns = $dealer_return_query->where('warehouse_id', $request->warehouse_id)->where('product_company_id', $request->product_company_id)->where('product_id', $product_id)->whereNotNull('dealer_id')->where('recieved_quantity', '>', 0)->sum('recieved_quantity'); $balance += $dealer_returns; // $wt_unloading_query = \App\WarehouseTransferUnloading::query(); $wt_unloading_query = \DB::table('warehouse_transfer_unloadings'); $wt_unloadings = $wt_unloading_query->where('to_warehouse_id', $request->warehouse_id)->where('product_brand_id', $request->product_company_id)->where('product_id', $product_id)->sum('quantity'); $balance += $wt_unloadings; /*------in------*/ /*------out------*/ // $loading_query = \App\ProductLoading::query(); $loading_query = \DB::table('product_loadings'); $product_loadings = $loading_query->where('product_company_id', $request->product_company_id)->where('from_warehouse_id', $request->warehouse_id)->where('product_id', $product_id)->sum('quantity'); $balance -= $product_loadings; // $StockAdjustment_query = \App\StockAdjustment::query(); $StockAdjustment_query = \DB::table('stock_adjustments'); if ($request->product_company_id) { $StockAdjustment_query->where('product_brand_id', $request->product_company_id); } $stock_adjustments = $StockAdjustment_query->where('warehouse_id', $request->warehouse_id)->where('adjust_type', 2)->where('product_id', $product_id)->sum('quantity'); $balance -= $stock_adjustments; // $standardization_query = \App\Standardization::query(); $standardization_query = \DB::table('standardizations'); $standardizations = $standardization_query->where('warehouse_id', $request->warehouse_id)->where('open_product_brand_id', $request->product_company_id)->where('open_product_id', $product_id)->sum('open_quantity'); $balance -= $standardizations; // $wt_loading_query = \App\WarehouseTransferLoading::query(); $wt_loading_query = \DB::table('warehouse_transfer_loadings'); $wt_loadings = $wt_loading_query->where('from_warehouse_id', $request->warehouse_id)->where('product_brand_id', $request->product_company_id)->where('product_id', $product_id)->where('received_quantity', '>', 0)->sum('received_quantity'); $balance -= $wt_loadings; /*------out------*/ if ($balance != 0) { $temp = array(); $temp['party'] = getModelById('ProductCompany', $request->product_company_id)->name; $temp['product'] = getModelById('Product', $product_id)->name; $temp['balance'] = $balance; $temp['warehouse'] = getModelById('Warehouse', $request->warehouse_id)->name; array_push($stocks, $temp); if ($request->product_id) { $total = $total + $balance; } } } } } $data['stocks'] = $stocks; $data['total'] = $total; // exit; } } else { $data['stocks'] = array(); } return view('dashboard.inventory.company-godown-stock', $data); } /*-----------------Company Godown Stock----------------------*/ /*-----------------Parties Stock----------------------*/ public function partiesStock(Request $request) { $data = array(); $data['products'] = \App\Product::where('is_active', 1)->get(); $data['product_companies'] = \App\ProductCompany::where('is_active', 1)->get(); if ($request->isMethod('post')) { $validator = \Validator::make( $request->all(), array( 'product_id' => 'required', 'product_brand_id' => 'required', ) ); if ($validator->fails()) { return redirect('user/parties-stock') ->withErrors($validator) ->withInput(); } else { $opening_dealers = \App\OpeningInventory::whereNotNull('dealer_id')->distinct()->pluck('dealer_id')->toArray(); $loading_dealers = \App\ProductLoading::whereNotNull('dealer_id')->distinct()->pluck('dealer_id')->toArray(); $WarehouseDi_from_dealers = \App\WarehouseDi::whereNotNull('from_dealer_id')->distinct()->pluck('from_dealer_id')->toArray(); $WarehouseDi_to_dealers = \App\WarehouseDi::whereNotNull('dealer_id')->distinct()->pluck('dealer_id')->toArray(); $companyDi_dealers = \App\CompanyDi::whereNotNull('dealer_id')->distinct()->pluck('dealer_id')->toArray(); $standard_dealers = \App\Standardization::whereNotNull('dealer_id')->distinct()->pluck('dealer_id')->toArray(); $excess_shortage_dealers = \App\RakeExcessShortage::whereNotNull('dealer_id')->distinct()->pluck('dealer_id')->toArray(); $distincts_dealers = array(); $distincts_dealers = array_unique(array_merge($opening_dealers, $distincts_dealers, $loading_dealers, $WarehouseDi_from_dealers, $WarehouseDi_to_dealers, $companyDi_dealers, $standard_dealers, $excess_shortage_dealers)); $dealers_stock = array(); $total = 0; foreach ($distincts_dealers as $dealer_id) { if ($request->product_brand_id) { $opening_stock = \App\OpeningInventory::where('dealer_id', $dealer_id)->where('product_brand_id', $request->product_brand_id)->where('product_id', $request->product_id)->sum('quantity'); } else { $opening_stock = \App\OpeningInventory::where('dealer_id', $dealer_id)->where('product_id', $request->product_id)->sum('quantity'); } $balance = $opening_stock; /*------out------*/ $loading_query = \App\ProductLoading::query(); if ($request->product_brand_id) { $loading_query->where('product_company_id', $request->product_brand_id); $data['product_brand_id'] = $request->product_brand_id; } $product_loadings = $loading_query->where('dealer_id', $dealer_id)->where('product_id', $request->product_id)->sum('quantity'); $balance -= $product_loadings; $warehouse_di_query = \App\WarehouseDi::query(); if ($request->product_brand_id) { $warehouse_di_query->where('product_brand_id', $request->product_brand_id); $data['product_brand_id'] = $request->product_brand_id; } $warehouse_dis = $warehouse_di_query->where('from_dealer_id', $dealer_id)->where('product_id', $request->product_id)->sum('quantity'); $balance -= $warehouse_dis; $standardization_query = \App\Standardization::query(); if ($request->product_brand_id) { $standardization_query->where('open_product_brand_id', $request->product_brand_id); $data['product_brand_id'] = $request->product_brand_id; } $standardizations = $standardization_query->where('dealer_id', $dealer_id)->where('open_product_id', $request->product_id)->sum('open_quantity'); $balance -= $standardizations; $StockAdjustment_query = \App\StockAdjustment::query(); if ($request->product_brand_id) { $StockAdjustment_query->where('product_brand_id', $request->product_brand_id); } $stock_adjustments = $StockAdjustment_query->where('dealer_id', $dealer_id)->where('adjust_type', 2)->where('product_id', $request->product_id)->sum('quantity'); $balance -= $stock_adjustments; /*------out------*/ /*------in------*/ $excess_query = \App\RakeExcessShortage::query(); if ($request->product_brand_id) { $excess_query->where('product_brand_id', $request->product_brand_id); $data['product_brand_id'] = $request->product_brand_id; } $excesses = $excess_query->where('dealer_id', $dealer_id)->where('product_id', $request->product_id)->sum('quantity'); $balance += $excesses; $unloading_query = \App\ProductUnloading::query(); if ($request->product_brand_id) { $unloading_query->where('product_company_id', $request->product_brand_id); $data['product_brand_id'] = $request->product_brand_id; } $product_unloadings = $unloading_query->where('dealer_id', $dealer_id)->where('product_id', $request->product_id)->sum('quantity'); $balance += $product_unloadings; $standardization_query = \App\Standardization::query(); if ($request->product_brand_id) { $standardization_query->where('closed_product_brand_id', $request->product_brand_id); } $standardizations = $standardization_query->where('dealer_id', $dealer_id)->where('closed_product_id', $request->product_id)->sum('packed_quantity'); $balance += $standardizations; $return_query = \App\ReturnedProduct::query(); if ($request->product_brand_id) { $return_query->where('product_brand_id', $request->product_brand_id); $data['product_brand_id'] = $request->product_brand_id; } $returns = $return_query->where('dealer_id', $dealer_id)->where('product_id', $request->product_id)->sum('returned_quantity'); $balance += $returns; $company_di_query = \App\CompanyDi::query(); if ($request->product_brand_id) { $company_di_query->where('product_company_id', $request->product_brand_id); $data['product_brand_id'] = $request->product_brand_id; } $company_dis = $company_di_query->where('dealer_id', $dealer_id)->where('product_id', $request->product_id)->sum('quantity'); $balance += $company_dis; $warehouse_di_query = \App\WarehouseDi::query(); if ($request->product_brand_id) { $warehouse_di_query->where('product_brand_id', $request->product_brand_id); $data['product_brand_id'] = $request->product_brand_id; } $warehouse_dis = $warehouse_di_query->where('dealer_id', $dealer_id)->where('product_id', $request->product_id)->sum('quantity'); $balance += $warehouse_dis; $StockAdjustment_query = \App\StockAdjustment::query(); if ($request->product_brand_id) { $StockAdjustment_query->where('product_brand_id', $request->product_brand_id); } $stock_adjustments = $StockAdjustment_query->where('dealer_id', $dealer_id)->where('adjust_type', 1)->where('product_id', $request->product_id)->sum('quantity'); $balance += $stock_adjustments; /*------in------*/ if ($balance != 0) { $temp = array(); $temp['party'] = getModelById('Dealer', $dealer_id)->name . '(' . getModelById('Dealer', $dealer_id)->address1 . ')'; $temp['stock'] = $balance; array_push($dealers_stock, $temp); $total = $total + $balance; } } $data['dealers_stock'] = $dealers_stock; $data['product_id'] = $request->product_id; $data['total'] = $total; } } else { $data['dealers_stock'] = array(); } return view('dashboard.inventory.parties-stock', $data); } /*-----------------Parties Stock----------------------*/ public function warehouse_report(Request $request) { $data = array(); $data['warehouses'] = \App\Warehouse::where('is_active', 1)->get(); if ($request->isMethod('post')) { $validator = \Validator::make( $request->all(), array( 'warehouse_id' => 'required', 'from_date' => 'required', ) ); if ($validator->fails()) { return redirect('user/warehouse-report') ->withErrors($validator) ->withInput(); } else { $product_loadings = \App\ProductLoading::whereDate('created_at', '=', date('Y-m-d', strtotime($request->from_date))) ->where(function ($query) use ($request) { $query->where('warehouse_id', $request->warehouse_id) ->orWhere('from_warehouse_id', $request->warehouse_id); }) ->with('token') ->with('loading_slip_invoice') ->get(); $data['warehouse_id'] = $request->warehouse_id; $data['product_loadings'] = $product_loadings; $data['from_date'] = $request->from_date; } } else { $data['from_date'] = date('m/d/Y'); } return view('dashboard.inventory.warehouse-report', $data); } public function warehouse_daywise_report(Request $request) { $data['sessions'] = \App\Session::all(); $data['warehouses'] = \App\Warehouse::where('is_active', 1)->get(); $data['select_warehouses'] = \App\Warehouse::where('is_active', 1)->get(); $data['products'] = array(); if ($request->isMethod('post')) { $validator = \Validator::make( $request->all(), array( 'warehouse_id' => 'required', 'from_date' => 'required', ) ); if ($validator->fails()) { return redirect('user/warehouse-daywise-report') ->withErrors($validator) ->withInput(); } else { $products = array(); $unique_products = \App\ProductLoading::select('product_company_id', 'product_id') ->where('warehouse_id', $request->warehouse_id) ->whereDate('created_at', '=', date('Y-m-d', strtotime($request->from_date))) ->distinct() ->get(); if (count($unique_products) > 0) { foreach ($unique_products as $unique_product) { $product = array(); $product['id'] = $unique_product->product_id; $product['name'] = getModelById('Product', $unique_product->product_id)->name; $product['product_company_id'] = $unique_product->product_company_id; $product['product_company'] = getModelById('ProductCompany', $unique_product->product_company_id)->abbreviation; array_push($products, $product); } $data['products'] = $products; } else { $data['products'] = $products; } $data['warehouses'] = \App\Warehouse::where('is_active', 1)->where('id', $request->warehouse_id)->get(); $data['warehouse_id'] = $request->warehouse_id; $data['from_date'] = $request->from_date; } } else { $data['from_date'] = date('m/d/Y'); } return view('dashboard.inventory.warehouse-daywise-report', $data); } public function stock_report(Request $request) { $data['filter_warehouses'] = \App\Warehouse::where('is_active', 1)->get(); $data['warehouses'] = \App\Warehouse::where('is_active', 1)->get(); $data['product_categories'] = \App\ProductCategory::where('is_active', 1)->get(); $products = array(); $query = \App\Inventory::query(); if ($request->isMethod('post')) { if ($request->warehouse_id) { $query->where('warehouse_id', $request->warehouse_id); $data['warehouse_id'] = $request->warehouse_id; $data['warehouses'] = \App\Warehouse::where('is_active', 1)->where('id', $request->warehouse_id)->get(); } } $unique_products = $query->select('product_brand_id', 'product_id')->distinct()->get(); if (count($unique_products) > 0) { foreach ($unique_products as $unique_product) { $product = array(); $product['id'] = $unique_product->product_id; $product['name'] = getModelById('Product', $unique_product->product_id)->name; $product['product_category_id'] = getModelById('Product', $unique_product->product_id)->product_category_id; $product['product_brand_id'] = $unique_product->product_brand_id; $product['product_company'] = getModelById('ProductCompany', $unique_product->product_brand_id)->abbreviation; array_push($products, $product); } $data['products'] = $products; } else { $data['products'] = $products; } return view('dashboard.inventory.stock-report', $data); } public function buffer_godown_report(Request $request) { $data['sessions'] = \App\Session::all(); $data['product_companies'] = \App\ProductCompany::where('is_active', 1)->get(); $data['warehouses'] = \App\Warehouse::where('is_active', 1)->get(); $inventory_products = \App\Inventory::select('product_id', 'product_brand_id')->where('warehouse_id', 24)->distinct()->get(); if ($request->isMethod('post')) { $query = \App\Inventory::query(); if ($request->product_brand_id) { $query->where('product_brand_id', $request->product_brand_id); $data['product_brand_id'] = $request->product_brand_id; } $inventory_products = $query->select('product_id', 'product_brand_id')->where('warehouse_id', 24)->distinct()->get(); } $data['inventory_products'] = $inventory_products; $inventories = \App\Inventory::select('dealer_id', 'product_company_id')->where('warehouse_id', 24)->distinct()->get(); if ($inventories) { $inventory_data = array(); foreach ($inventories as $inventory) { if ($inventory->dealer_id) { $pary_data = array(); $dealer_name = \App\Dealer::where('id', $inventory->dealer_id)->first(); $pary_data['party_name'] = $dealer_name->name; $pary_data['address'] = $dealer_name->address1; $pary_data['id'] = $dealer_name->id; $pary_data['type'] = 'dealer_id'; array_push($inventory_data, $pary_data); } else if ($inventory->product_company_id) { $pary_data = array(); $product_company_name = \App\ProductCompany::where('id', $inventory->product_company_id)->first(); $pary_data['party_name'] = $product_company_name->name; $pary_data['address'] = $product_company_name->address; $pary_data['id'] = $product_company_name->id; $pary_data['type'] = 'product_company_id'; array_push($inventory_data, $pary_data); } } } $data['parties'] = $inventory_data; return view('dashboard.inventory.buffer-godown-report', $data); } public function buffer_report(Request $request) { $data['sessions'] = \App\Session::all(); $data['product_companies'] = \App\ProductCompany::where('is_active', 1)->get(); $data['warehouses'] = \App\Warehouse::where('is_active', 1)->get(); $inventory_products = \App\Inventory::select('product_id', 'product_brand_id')->distinct()->get(); if ($request->isMethod('post')) { $query = \App\Inventory::query(); if ($request->product_brand_id) { $query->where('product_brand_id', $request->product_brand_id); $data['product_brand_id'] = $request->product_brand_id; } if ($request->warehouse_id) { $query->where('warehouse_id', $request->warehouse_id); $data['warehouse_id'] = $request->warehouse_id; } $inventory_products = $query->select('product_id', 'product_brand_id')->distinct()->get(); } $data['inventory_products'] = $inventory_products; $inventories = \App\Inventory::select('dealer_id', 'product_company_id')->distinct()->get(); if ($inventories) { $inventory_data = array(); foreach ($inventories as $inventory) { if ($inventory->dealer_id) { $pary_data = array(); $dealer_name = \App\Dealer::where('id', $inventory->dealer_id)->first(); $pary_data['party_name'] = $dealer_name->name; $pary_data['address'] = $dealer_name->address1; $pary_data['id'] = $dealer_name->id; $pary_data['type'] = 'dealer_id'; array_push($inventory_data, $pary_data); } else if ($inventory->product_company_id) { $pary_data = array(); $product_company_name = \App\ProductCompany::where('id', $inventory->product_company_id)->first(); $pary_data['party_name'] = $product_company_name->name; $pary_data['address'] = $product_company_name->address; $pary_data['id'] = $product_company_name->id; $pary_data['type'] = 'product_company_id'; array_push($inventory_data, $pary_data); } } } $data['parties'] = $inventory_data; return view('dashboard.inventory.buffer-report', $data); } public function daily_stock_report(Request $request) { \App\Inventory::where('quantity', 0)->delete(); $data = array(); $data['warehouses'] = \App\Warehouse::where('is_active', 1)->get(); $data['product_categories'] = \App\ProductCategory::where('is_active', 1)->get(); $query = \App\Inventory::query(); $unique_products = $query->select('product_brand_id', 'product_id')->distinct()->get(); $unique_warehouses = array_unique(\App\Inventory::pluck('warehouse_id')->toArray()); $unique_product_companies = array_unique(\App\Inventory::pluck('product_company_id')->toArray()); $products = array(); if (count($unique_products) > 0) { foreach ($unique_products as $unique_product) { $inventories = \App\Inventory::select('dealer_id', 'product_company_id')->distinct()->get(); if ($inventories) { $other_parties = array(); $self_parties = array(); $product_companies = array(); foreach ($inventories as $inventory) { if ($inventory->dealer_id) { $pary_data = array(); $dealer_name = \App\Dealer::where('id', $inventory->dealer_id)->first(); $pary_data['party_name'] = $dealer_name->name; $pary_data['address'] = $dealer_name->address1; $pary_data['id'] = $dealer_name->id; $pary_data['type'] = 'dealer_id'; if ($dealer_name->show_separate_report) { array_push($self_parties, $pary_data); } } else if ($inventory->product_company_id) { $pary_data = array(); $product_company_name = \App\ProductCompany::where('id', $inventory->product_company_id)->whereIn('id', $unique_product_companies)->first(); $pary_data['party_name'] = $product_company_name->name; $pary_data['address'] = $product_company_name->address; $pary_data['id'] = $product_company_name->id; $pary_data['type'] = 'product_company_id'; array_push($product_companies, $pary_data); } } } $data['self_parties'] = $self_parties; $data['product_companies'] = $product_companies; $data['warehouses'] = \App\Warehouse::where('is_active', 1)->whereIn('id', $unique_warehouses)->get(); $product = array(); $product['id'] = $unique_product->product_id; $product['name'] = getModelById('Product', $unique_product->product_id)->name; $product['product_brand_id'] = $unique_product->product_brand_id; $product['product_category_id'] = getModelById('Product', $unique_product->product_id)->product_category_id; $product['product_company'] = getModelById('ProductCompany', $unique_product->product_brand_id)->abbreviation; array_push($products, $product); $data['products'] = $products; } } else { $data['products'] = $products; } return view('dashboard.inventory.daily-stock-report', $data); } public function opening_stock(Request $request) { \App\OpeningInventory::where('quantity', 0)->delete(); $data = array(); $data['warehouses'] = \App\Warehouse::where('is_active', 1)->get(); $data['product_categories'] = \App\ProductCategory::where('is_active', 1)->get(); $query = \App\OpeningInventory::query(); if ($request->isMethod('post')) { if ($request->warehouse_id) { $query->where('warehouse_id', $request->warehouse_id); $data['warehouse_id'] = $request->warehouse_id; $data['warehouses'] = \App\Warehouse::where('is_active', 1)->where('id', $request->warehouse_id)->get(); } } $unique_products = $query->select('product_brand_id', 'product_id')->distinct()->get(); $unique_warehouses = array_unique(\App\OpeningInventory::pluck('warehouse_id')->toArray()); $unique_product_companies = array_unique(\App\OpeningInventory::pluck('product_company_id')->toArray()); $products = array(); $query = \App\OpeningInventory::query(); if ($request->isMethod('post')) { if ($request->warehouse_id) { $query->where('warehouse_id', $request->warehouse_id); $data['warehouse_id'] = $request->warehouse_id; $data['warehouses'] = \App\Warehouse::where('is_active', 1)->where('id', $request->warehouse_id)->get(); } } if (count($unique_products) > 0) { foreach ($unique_products as $unique_product) { $inventories = \App\OpeningInventory::select('dealer_id', 'product_company_id')->distinct()->get(); if ($inventories) { $other_parties = array(); $self_parties = array(); $product_companies = array(); foreach ($inventories as $inventory) { if ($inventory->dealer_id) { $pary_data = array(); $dealer_name = \App\Dealer::where('id', $inventory->dealer_id)->first(); $pary_data['party_name'] = $dealer_name->name; $pary_data['address'] = $dealer_name->address1; $pary_data['id'] = $dealer_name->id; $pary_data['type'] = 'dealer_id'; if ($dealer_name->show_separate_report) { array_push($self_parties, $pary_data); } } else if ($inventory->product_company_id) { $pary_data = array(); $product_company_name = \App\ProductCompany::where('id', $inventory->product_company_id)->whereIn('id', $unique_product_companies)->first(); $pary_data['party_name'] = $product_company_name->name; $pary_data['address'] = $product_company_name->address; $pary_data['id'] = $product_company_name->id; $pary_data['type'] = 'product_company_id'; array_push($product_companies, $pary_data); } } } $data['self_parties'] = $self_parties; $data['product_companies'] = $product_companies; $data['warehouses'] = \App\Warehouse::where('is_active', 1)->whereIn('id', $unique_warehouses)->get(); $product = array(); $product['id'] = $unique_product->product_id; $product['name'] = getModelById('Product', $unique_product->product_id)->name; $product['product_brand_id'] = $unique_product->product_brand_id; $product['product_category_id'] = getModelById('Product', $unique_product->product_id)->product_category_id; $product['product_company'] = getModelById('ProductCompany', $unique_product->product_brand_id)->abbreviation; array_push($products, $product); $data['products'] = $products; } } else { $data['products'] = $products; } return view('dashboard.inventory.opening-stock', $data); } public function export_daily_stock_report() { \App\Inventory::where('quantity', 0)->delete(); $data = array(); $data['product_categories'] = $product_categories = \App\ProductCategory::where('is_active', 1)->get(); $query = \App\Inventory::query(); $unique_products = $query->select('product_brand_id', 'product_id')->distinct()->get(); $products = array(); $query = \App\Inventory::query(); $unique_warehouses = array_unique(\App\Inventory::pluck('warehouse_id')->toArray()); $unique_product_companies = array_unique(\App\Inventory::pluck('product_company_id')->toArray()); if (count($unique_products) > 0) { foreach ($unique_products as $unique_product) { $inventories = \App\Inventory::select('dealer_id', 'product_company_id')->distinct()->get(); if ($inventories) { $other_parties = array(); $self_parties = array(); $product_companies = array(); foreach ($inventories as $inventory) { if ($inventory->dealer_id) { $pary_data = array(); $dealer_name = \App\Dealer::where('id', $inventory->dealer_id)->first(); $pary_data['party_name'] = $dealer_name->name; $pary_data['address'] = $dealer_name->address1; $pary_data['id'] = $dealer_name->id; $pary_data['type'] = 'dealer_id'; if ($dealer_name->show_separate_report) { array_push($self_parties, $pary_data); } } else if ($inventory->product_company_id) { $pary_data = array(); $product_company_name = \App\ProductCompany::where('id', $inventory->product_company_id)->whereIn('id', $unique_product_companies)->first(); $pary_data['party_name'] = $product_company_name->brand_name; $pary_data['address'] = $product_company_name->address; $pary_data['id'] = $product_company_name->id; $pary_data['type'] = 'product_company_id'; array_push($product_companies, $pary_data); } } } $data['self_parties'] = $self_parties; $data['product_companies'] = $product_companies; $data['warehouses'] = $warehouses = \App\Warehouse::where('is_active', 1)->whereIn('id', $unique_warehouses)->get(); $product = array(); $product['id'] = $unique_product->product_id; $product['name'] = getModelById('Product', $unique_product->product_id)->name; $product['product_brand_id'] = $unique_product->product_brand_id; $product['product_category_id'] = getModelById('Product', $unique_product->product_id)->product_category_id; $product['product_company'] = getModelById('ProductCompany', $unique_product->product_brand_id)->abbreviation; array_push($products, $product); $data['products'] = $products; } } else { $data['products'] = $products; } $daily_stock_report = array(); $report_header = array(); $product_rows = array(); array_push($report_header, "Product"); foreach ($self_parties as $self_party) { $party_name = implode("\n", explode(' ', $self_party['party_name'])) . "\n" . '(' . implode("\n", explode(' ', $self_party['address'])) . ')'; array_push($report_header, $party_name); } array_push($report_header, "Other \n Party"); foreach ($product_companies as $product_company) { $party_name = implode("\n", explode(' ', $product_company['party_name'])) . "\n" . '(' . $product_company['address'] . ')'; array_push($report_header, $party_name); } array_push($report_header, "Total"); foreach ($warehouses as $warehouse) { array_push($report_header, implode("\n", explode(' ', $warehouse->name))); } array_push($report_header, "Total"); array_push($daily_stock_report, $report_header); foreach ($product_categories as $product_cat) { $category_row = array(); array_push($category_row, $product_cat->category); array_push($daily_stock_report, $category_row); if (count($products) > 0) { foreach ($products as $product) { if ($product['product_category_id'] == $product_cat->id) { $row = array(); array_push($row, $product['name'] . '/' . $product['product_company']); array_push($category_row, ""); $party_total = 0; foreach ($self_parties as $self_party) { if (is_null(getPartyInventoryByProductAndBrand($self_party['id'], $product['id'], $product['product_brand_id'], $self_party['type']))) { array_push($row, '--'); array_push($category_row, ""); } else { array_push($row, getPartyInventoryByProductAndBrand($self_party['id'], $product['id'], $product['product_brand_id'], $self_party['type'])); array_push($category_row, ""); $party_total = $party_total + getPartyInventoryByProductAndBrand($self_party['id'], $product['id'], $product['product_brand_id'], $self_party['type']); } } array_push($row, getOtherPartyInventoryByProductAndBrand($product['id'], $product['product_brand_id'])); array_push($category_row, ""); $party_total = $party_total + getOtherPartyInventoryByProductAndBrand($product['id'], $product['product_brand_id']); foreach ($product_companies as $product_company) { if (is_null(getPartyInventoryByProductAndBrand($product_company['id'], $product['id'], $product['product_brand_id'], $product_company['type']))) { array_push($row, '--'); array_push($category_row, ""); } else { array_push($row, getPartyInventoryByProductAndBrand($product_company['id'], $product['id'], $product['product_brand_id'], $product_company['type'])); array_push($category_row, ""); $party_total = $party_total + getPartyInventoryByProductAndBrand($product_company['id'], $product['id'], $product['product_brand_id'], $product_company['type']); } } array_push($row, $party_total); $warehouse_total = 0; foreach ($warehouses as $warehouse) { if (is_null(getInventory($product['product_brand_id'], $warehouse['id'], $product['id']))) { array_push($row, '--'); array_push($category_row, ""); } else { array_push($row, getInventory($product['product_brand_id'], $warehouse['id'], $product['id'])); array_push($category_row, ""); $warehouse_total = $warehouse_total + getInventory($product['product_brand_id'], $warehouse['id'], $product['id']); } } array_push($row, $warehouse_total); array_push($daily_stock_report, $row); } } } } array_push($daily_stock_report, $product_rows); \Excel::create('Daily Stock Report', function ($excel) use ($daily_stock_report) { $excel->getDefaultStyle() ->getAlignment() ->applyFromArray(array( 'wrap' => TRUE )); $excel->sheet('Daily Stock Report', function ($sheet) use ($daily_stock_report) { $sheet->fromArray($daily_stock_report); $sheet->setFontBold(true); $sheet->setAllBorders('thin'); $sheet->setStyle(array( 'font' => array( 'name' => 'Calibri', 'size' => 16, 'bold' => true ) )); }); })->export('xls'); } public function dateConverter($date) { $temp_date = explode('/', $date); $new_date = $temp_date[2] . '-' . $temp_date[1] . '-' . $temp_date[0]; return $new_date; } public function paymentRebateReport(Request $request) { $data = array(); $data['master_rakes'] = \App\MasterRake::where('is_active', 1)->get(); $data['company_dis'] = array(); if ($request->isMethod('post')) { $validator = \Validator::make( $request->all(), array( 'master_rake_id' => 'required', ) ); if ($validator->fails()) { return redirect('user/payment-rebate-report') ->withErrors($validator) ->withInput(); } else { $companydis = \App\CompanyDi::where('master_rake_id', $request->master_rake_id)->get(); if (count($companydis) > 0) { $data['master_rake_id'] = $request->master_rake_id; $data['company_dis'] = $companydis; } } } return view('dashboard.inventory.payment-rebate-report', $data); } public function arrived_stock(Request $request) { $data = array(); $data['warehouses'] = \App\Warehouse::where('is_active', 1)->get(); $product_loadings = \App\ProductLoading::where('is_approved', 0) ->where('warehouse_id', '!=', null) ->with('token') ->get(); $data['product_loadings'] = $product_loadings; return view('dashboard.warehouse_management.arrived-stock', $data); } public function post_arrived_stock(Request $request) { $validator = \Validator::make( $request->all(), array( 'dealer_id' => 'required', 'product_company_id' => 'required', 'product_id' => 'required', 'quantity' => 'required|integer', 'unit_id' => 'required', ) ); if ($validator->fails()) { $response['flag'] = false; $response['errors'] = $validator->getMessageBag(); } else { $inventory = \App\Inventory::where('dealer_id', $request->dealer_id)->where('warehouse_id', $request->warehouse_id)->where('product_brand_id', $request->product_company_id)->where('product_id', $request->product_id)->first(); $product_loadings = \App\ProductLoading::where('dealer_id', $request->dealer_id)->where('warehouse_id', $request->warehouse_id)->where('product_company_id', $request->product_company_id)->where('product_id', $request->product_id)->where('id', $request->id)->first(); if (!is_null($inventory) && !is_null($product_loadings)) { $inventory->quantity = $inventory->quantity + $request->quantity; } else { $inventory = new \App\Inventory(); $inventory->dealer_id = $request->dealer_id; $inventory->warehouse_id = $request->warehouse_id; $inventory->product_brand_id = $request->product_company_id; $inventory->product_id = $request->product_id; $inventory->quantity = $request->quantity; $inventory->unit_id = $request->unit_id; } $product_loadings->recieved_quantity = $request->quantity; $product_loadings->is_approved = 1; if ($inventory->save() && $product_loadings->save()) { $response['flag'] = true; $response['message'] = "Quantity approved Successfully"; } else { $response['flag'] = false; $response['error'] = "Something Went Wrong"; } } return response()->json($response); } public function warehouseLoadingSlips(Request $request) { ini_set('memory_limit', '-1'); $data = array(); $data['warehouses'] = \App\Warehouse::where('is_active', 1)->get(); $data['invoice_types'] = \App\InvoiceType::where('is_active', 1)->get(); $data['companies'] = \App\Company::where('is_active', 1)->where('for_invoice', 1)->get(); if ($request->isMethod('post')) { $validator = \Validator::make( $request->all(), array( // 'from_Warehouse_id' =>'required', 'from_date' => 'required', ) ); if ($validator->fails()) { return redirect('user/warehouse-loading-slips') ->withErrors($validator) ->withInput(); } else { // if($request->include_non_freight == 1){ // $product_loadings = \App\ProductLoading::where('from_Warehouse_id',$request->from_Warehouse_id) // ->where('freight','>',0) // ->with('token')->get(); // }elseif($request->include_non_freight == 0){ // $product_loadings = \App\ProductLoading::where('from_Warehouse_id',$request->from_Warehouse_id) // ->with('token')->get(); // } $query = \App\ProductLoading::query(); if ($request->from_date != '') { $query->where(DB::raw('date(product_loadings.created_at)'), '=', $request->from_date) ->orWhere(DB::raw('date(product_loadings.freight_pay_date)'), '=', $request->from_date); } if ($request->to_date != '') { $query->where(DB::raw('date(product_loadings.created_at)'), '<=', $request->to_date) ->orWhere(DB::raw('date(product_loadings.freight_pay_date)'), '<=', $request->to_date); } if ($request->from_Warehouse_id != '') { if ($request->include_non_freight == 1) { $query->where('from_Warehouse_id', $request->from_Warehouse_id) ->where('freight', '>', 0) ->with('token'); } elseif ($request->include_non_freight == 0) { $query->where('from_Warehouse_id', $request->from_Warehouse_id) ->with('token'); } } else { $query->where('from_Warehouse_id', '!=', '') ->with('token'); } $product_loadings = $query->get(); $data['include_non_freight'] = $request->include_non_freight; $data['product_loadings'] = $product_loadings; $data['from_Warehouse_id'] = $request->from_Warehouse_id; } } else { // $data['product_loadings'] = array(); // $product_loadings = \App\ProductLoading::where('from_Warehouse_id', '!=', '') // ->with('token')->get(); // $data['product_loadings'] = $product_loadings; } return view('dashboard.warehouse_management.product-loading-list', $data); } public function warehouseLabourSlips(Request $request) { $data = array(); $data['warehouses'] = \App\Warehouse::where('is_active', 1)->get(); if ($request->isMethod('post')) { $validator = \Validator::make( $request->all(), array( 'from_Warehouse_id' => 'required', ) ); if ($validator->fails()) { return redirect('user/warehouse-labour-slips') ->withErrors($validator) ->withInput(); } else { if (isset($request->date)) { $product_loadings = \App\ProductLoading::where('from_Warehouse_id', $request->from_Warehouse_id)->whereDate('created_at', '=', date('Y-m-d', strtotime($request->date)))->with('token', 'labour_payment')->get(); $data['date'] = $request->date; } else { $product_loadings = \App\ProductLoading::where('from_Warehouse_id', $request->from_Warehouse_id)->whereDate('created_at', '=', date('Y-m-d'))->with('token', 'labour_payment')->get(); } $data['product_loadings'] = $product_loadings; $data['from_Warehouse_id'] = $request->from_Warehouse_id; } } else { $data['product_loadings'] = array(); $data['date'] = date('m/d/Y'); } return view('dashboard.warehouse_management.labour-slips', $data); } public function partyInventory(Request $request) { $data = array(); $data['product_companies'] = \App\ProductCompany::where('is_active', 1)->get(); $data['dealers'] = \App\Dealer::where('is_active', 1)->get(); $data['warehouses'] = \App\Warehouse::where('is_active', 1)->get(); $data['products'] = \App\Product::where('is_active', 1)->get(); if ($request->isMethod('post')) { $validator = \Validator::make( $request->all(), array( 'product_id' => 'required', ) ); if ($validator->fails()) { return redirect('user/party-inventory') ->withErrors($validator) ->withInput(); } else { $query = \App\Inventory::query(); if ($request->dealer_id) { $query->where('dealer_id', $request->dealer_id); $data['dealer_id'] = $request->dealer_id; } if ($request->product_company_id) { $query->where('product_company_id', $request->product_company_id); $data['product_company_id'] = $request->product_company_id; } if ($request->product_brand_id) { $query->where('product_brand_id', $request->product_brand_id); $data['product_brand_id'] = $request->product_brand_id; } if ($request->warehouse_id) { $query->where('warehouse_id', $request->warehouse_id); $data['warehouse_id'] = $request->warehouse_id; } $total = $query->where('product_id', $request->product_id)->sum('quantity'); $inventories = $query->where('product_id', $request->product_id)->with('product:id,name', 'dealer:id,name,address1', 'product_company:id,name', 'product_brand:id,name,brand_name', 'warehouse:id,name', 'unit:id,unit')->get(); $data['product_id'] = $request->product_id; $data['inventories'] = $inventories; $data['total'] = $total; } } else { } return view('dashboard.inventory.party-inventory', $data); } public function partyOpeningStock(Request $request) { $data = array(); $data['product_companies'] = \App\ProductCompany::where('is_active', 1)->get(); $data['dealers'] = \App\Dealer::where('is_active', 1)->get(); $data['warehouses'] = \App\Warehouse::where('is_active', 1)->get(); $data['products'] = \App\Product::where('is_active', 1)->get(); if ($request->isMethod('post')) { $validator = \Validator::make( $request->all(), array( // 'product_id' =>'required', ) ); if ($validator->fails()) { return redirect('user/party-opening-stock') ->withErrors($validator) ->withInput(); } else { $query = \App\OpeningInventory::query(); if ($request->dealer_id) { $query->where('dealer_id', $request->dealer_id); $data['dealer_id'] = $request->dealer_id; } if ($request->product_company_id) { $query->where('product_company_id', $request->product_company_id); $data['product_company_id'] = $request->product_company_id; } if ($request->product_brand_id) { $query->where('product_brand_id', $request->product_brand_id); $data['product_brand_id'] = $request->product_brand_id; } if ($request->warehouse_id) { $query->where('warehouse_id', $request->warehouse_id); $data['warehouse_id'] = $request->warehouse_id; } if ($request->product_id) { $query->where('product_id', $request->product_id); $data['product_id'] = $request->product_id; } $total = $query->sum('quantity'); $inventories = $query->with('product:id,name', 'dealer:id,name,address1', 'product_company:id,name', 'product_brand:id,brand_name', 'warehouse:id,name', 'unit:id,unit')->get(); $data['inventories'] = $inventories; $data['total'] = $total; } } else { } return view('dashboard.inventory.party-opening-stock', $data); } public function otherStock(Request $request) { $data = array(); $data['product_companies'] = \App\ProductCompany::where('is_active', 1)->get(); $data['dealers'] = \App\Dealer::where('is_active', 1)->get(); $data['warehouses'] = \App\Warehouse::where('is_active', 1)->get(); $data['products'] = \App\Product::where('is_active', 1)->get(); if ($request->isMethod('post')) { $validator = \Validator::make( $request->all(), array( 'product_id' => 'required', ) ); if ($validator->fails()) { return redirect('user/other-stock') ->withErrors($validator) ->withInput(); } else { $query = \App\OtherInventory::query(); if ($request->dealer_id) { $query->where('dealer_id', $request->dealer_id); $data['dealer_id'] = $request->dealer_id; } if ($request->product_company_id) { $query->where('product_company_id', $request->product_company_id); $data['product_company_id'] = $request->product_company_id; } if ($request->product_brand_id) { $query->where('product_brand_id', $request->product_brand_id); $data['product_brand_id'] = $request->product_brand_id; } if ($request->warehouse_id) { $query->where('warehouse_id', $request->warehouse_id); $data['warehouse_id'] = $request->warehouse_id; } $total = $query->where('product_id', $request->product_id)->sum('quantity'); $inventories = $query->where('product_id', $request->product_id)->with('product:id,name', 'dealer:id,name,address1', 'product_company:id,name', 'product_brand:id,brand_name', 'warehouse:id,name', 'unit:id,unit')->get(); $data['product_id'] = $request->product_id; $data['inventories'] = $inventories; $data['total'] = $total; } } else { $inventories = \App\OtherInventory::with('product:id,name', 'dealer:id,name,address1', 'product_company:id,name', 'product_brand:id,brand_name', 'warehouse:id,name', 'unit:id,unit')->get(); $data['inventories'] = $inventories; } return view('dashboard.inventory.other-stock', $data); } // In this function try, catch(rollback functionality was added on 05-07-2024 public function bankStatementsAdd(Request $request) { $response = array(); if ($request->isMethod('post')) { $validator = \Validator::make( $request->all(), array( 'reference_number' => 'required|unique:bank_statements,reference_number', 'transaction_date' => 'required', 'amount' => 'required|numeric', 'bank' => 'required', 'type' => 'required', 'payment_mode' => 'required', ) ); if ($validator->fails()) { $response['flag'] = false; $response['errors'] = $validator->getMessageBag()->toArray(); } else { DB::beginTransaction(); try { $bank_statement = new \App\BankStatement(); $bank_statement->bank_id = $request->bank; $bank_statement->reference_number = $request->reference_number; if ($request->type == 'credit') { $series = \App\BankStatement::where('type', 'receipt')->orderBy('id', 'desc')->first(); $bank_statement->series = $series ? $series->series + 1 : 1; $bank_statement->type = 'receipt'; } else { $series = \App\BankStatement::where('type', 'payment')->orderBy('id', 'desc')->first(); $bank_statement->series = $series ? $series->series + 1 : 1; $bank_statement->type = 'payment'; } $bank_statement->status = $request->type; $bank_statement->amount = $request->amount; $bank_statement->transaction_date = $this->dateConverter($request->transaction_date); $bank_statement->mode = $request->payment_mode; $bank_statement->particular = $request->particular; if ($bank_statement->save()) { DB::commit(); $response['flag'] = true; $response['message'] = "Statement Added Successfully"; } else { DB::rollBack(); $response['flag'] = false; $response['errors'] = ["Something Went Wrong"]; } } catch (\Exception $e) { DB::rollBack(); $response['flag'] = false; $response['errors'] = [$e->getMessage()]; } } return response()->json($response); } } public function fertiliser_stock_value() { $fertiliser_stocks_data = \DB::table('inventories')->select(\DB::raw("sum(inventories.quantity) as stock_qty"), 'inventories.*', 'products.name as product_name', 'product_categories.category as product_category', 'products.id as product_id') ->join('products', 'products.id', 'inventories.product_id') ->join('product_categories', 'product_categories.id', 'products.product_category_id') ->whereIn('dealer_id', [1, 30, 31])->whereIN('products.product_category_id', [1])->groupBy('inventories.product_id')->get(); $n = 0; $data = []; foreach ($fertiliser_stocks_data as $stock) { $data[$n]['product_name'] = $stock->product_name; $data[$n]['product_category'] = $stock->product_category; $data[$n]['stock_qty'] = $stock->stock_qty; $data[$n]['product_id'] = $stock->product_id; $period = new DatePeriod( new DateTime('2019-09-01'), new DateInterval('P1D'), new DateTime(date('Y-m-d', strtotime("tomorrow"))) ); $date_range = []; $m = 0; foreach ($period as $key => $value) { $date_range[$m] = $value->format('Y-m-d'); $m++; } $periods = array_reverse($date_range); $value = 0; $required = $stock->stock_qty; foreach ($periods as $date) { $warehouse_dis = \DB::table('warehouse_dis')->where('product_id', $stock->product_id)->whereIn('dealer_id', [1, 30, 31])->whereDate('created_at', $date)->get(); foreach ($warehouse_dis as $warehouse) { if ($required >= $warehouse->quantity && $required != 0) { $value = $value + ($warehouse->quantity * $warehouse->rate); $required = $required - $warehouse->quantity; } if ($required < $warehouse->quantity && $required != 0) { $value = $value + ($required * $warehouse->rate); $required = 0; } if ($required == 0) { break; } } $company_dis = \DB::table('company_dis')->where('product_id', $stock->product_id)->whereIn('dealer_id', [1, 30, 31])->whereDate('created_at', $date)->get(); foreach ($company_dis as $warehouse) { if ($required >= $warehouse->quantity && $required != 0) { $value = $value + ($warehouse->quantity * $warehouse->rate); $required = $required - $warehouse->quantity; } if ($required < $warehouse->quantity && $required != 0) { $value = $value + ($required * $warehouse->rate); $required = 0; } if ($required == 0) { break; } } if ($required == 0) { break; } } $data[$n]['value_of_stock'] = $value; $n++; } return view('dashboard.report.get-stock-value', ['data' => $data, 'category' => 'Fertilisers']); } public function cement_stock_value() { $cement_stocks_data = \DB::table('inventories')->select(\DB::raw("sum(inventories.quantity) as stock_qty"), 'inventories.*', 'products.name as product_name', 'product_categories.category as product_category', 'products.id as product_id') ->join('products', 'products.id', 'inventories.product_id') ->join('product_categories', 'product_categories.id', 'products.product_category_id') ->whereIn('dealer_id', [1, 30, 31])->whereIN('products.product_category_id', [2])->groupBy('inventories.product_id')->get(); $n = 0; $data = []; foreach ($cement_stocks_data as $stock) { $data[$n]['product_name'] = $stock->product_name; $data[$n]['product_category'] = $stock->product_category; $data[$n]['stock_qty'] = $stock->stock_qty; $data[$n]['product_id'] = $stock->product_id; $period = new DatePeriod( new DateTime('2019-09-01'), new DateInterval('P1D'), new DateTime(date('Y-m-d', strtotime("tomorrow"))) ); $date_range = []; $m = 0; foreach ($period as $key => $value) { $date_range[$m] = $value->format('Y-m-d'); $m++; } $periods = array_reverse($date_range); $value = 0; $required = $stock->stock_qty; foreach ($periods as $date) { $warehouse_dis = \DB::table('warehouse_dis')->where('product_id', $stock->product_id)->whereIn('dealer_id', [1, 30, 31])->whereDate('created_at', $date)->get(); foreach ($warehouse_dis as $warehouse) { if ($required >= $warehouse->quantity && $required != 0) { $value = $value + ($warehouse->quantity * $warehouse->rate); $required = $required - $warehouse->quantity; } if ($required < $warehouse->quantity && $required != 0) { $value = $value + ($required * $warehouse->rate); $required = 0; } if ($required == 0) { break; } } $company_dis = \DB::table('company_dis')->where('product_id', $stock->product_id)->whereIn('dealer_id', [1, 30, 31])->whereDate('created_at', $date)->get(); foreach ($company_dis as $warehouse) { if ($required >= $warehouse->quantity && $required != 0) { $value = $value + ($warehouse->quantity * $warehouse->rate); $required = $required - $warehouse->quantity; } if ($required < $warehouse->quantity && $required != 0) { $value = $value + ($required * $warehouse->rate); $required = 0; } if ($required == 0) { break; } } if ($required == 0) { break; } } $data[$n]['value_of_stock'] = $value; $n++; } return view('dashboard.report.get-stock-value', ['data' => $data, 'category' => 'Cement']); } public function companyProductWise(Request $request) { $data = []; $data['companies'] = \App\ProductCompany::where('is_active', 1)->get(); $data['products'] = \App\Product::where('is_active', 1)->get(); // dd($request->all()); if ($request->isMethod('post')) { //dd($inventories); // dd($request->all()); if ($request->company_id != "" && $request->product_id != "") { $stock = []; $n = 0; foreach ($request->company_id as $key => $company_id) { if ($n == 0) { $stock[$n]['company_name'] = "Company Name"; foreach ($request->product_id as $key1 => $product_id) { $stock[$n]['products'][$key1] = getModelById('Product', $product_id)->name; } } $n++; } foreach ($request->company_id as $key => $company_id) { $stock[$n]['company_name'] = getModelById('ProductCompany', $company_id)->name; foreach ($request->product_id as $key1 => $product_id) { $stock[$n]['products'][$key1] = \DB::table('inventories')->where('product_company_id', $company_id)->where('product_id', $product_id)->sum('quantity'); } $n++; } $data['stocks'] = $stock; //dd($stock); } } return view('dashboard.inventory.company-product-wise', $data); } public function dealerProductWise(Request $request) { $data = []; $data['dealers'] = \App\Dealer::where('is_active', 1)->get(); $data['products'] = \App\Product::where('is_active', 1)->get(); // dd($request->all()); if ($request->isMethod('post')) { //dd($inventories); // dd($request->all()); if ($request->dealer_id != "" && $request->product_id != "") { $stock = []; $n = 0; foreach ($request->dealer_id as $key => $dealer_id) { if ($n == 0) { $stock[$n]['dealer_name'] = "Dealer Name"; foreach ($request->product_id as $key1 => $product_id) { $stock[$n]['products'][$key1] = getModelById('Product', $product_id)->name; } } $n++; } foreach ($request->dealer_id as $key => $dealer_id) { $stock[$n]['dealer_name'] = getModelById('Dealer', $dealer_id)->name . " (" . getModelById('Dealer', $dealer_id)->address1 . ")"; foreach ($request->product_id as $key1 => $product_id) { $stock[$n]['products'][$key1] = \DB::table('inventories')->where('dealer_id', $dealer_id)->where('product_id', $product_id)->sum('quantity'); } $n++; } $data['stocks'] = $stock; //dd($stock); } } return view('dashboard.inventory.dealer-product-wise', $data); } public function dealerProductCompanyWise(Request $request) { $data = []; $data['dealers'] = \App\Dealer::where('is_active', 1)->get(); $data['products'] = \App\Product::where('is_active', 1)->get(); $data['companies'] = \App\ProductCompany::where('is_active', 1)->get(); // dd($request->all()); if ($request->isMethod('post')) { //dd($inventories); // dd($request->all()); if ($request->dealer_id != "" && $request->product_company_id != "" && $request->product_id != '') { $stock = []; $n = 0; foreach ($request->dealer_id as $key => $dealer_id) { if ($n == 0) { $stock[$n]['dealer_name'] = "Dealer Name"; foreach ($request->product_company_id as $key1 => $product_company_id) { $stock[$n]['product_company'][$key1] = getModelById('ProductCompany', $product_company_id)->name; } } $n++; } foreach ($request->dealer_id as $key => $dealer_id) { $stock[$n]['dealer_name'] = getModelById('Dealer', $dealer_id)->name . " (" . getModelById('Dealer', $dealer_id)->address1 . ")"; foreach ($request->product_company_id as $key1 => $product_company_id) { $stock[$n]['product_company'][$key1] = \DB::table('inventories')->where('dealer_id', $dealer_id)->where('product_id', $request->product_id)->where('product_brand_id', $product_company_id)->sum('quantity'); } $n++; } $data['stocks'] = $stock; // dd($stock); } } return view('dashboard.inventory.dealer-product-company-wise', $data); } }