data['title'] = 'Suppliers'; $this->data['suppliers'] = Suppliers::all(); return view('admin.inventory.suppliers', $this->data); } /* | single_supplier |-------------------------------------------------------------------------- */ public function single_supplier(Request $request) { if($request->id){ return response()->json(Suppliers::find($request->id)); } abort(404); } /* | save_supplier |-------------------------------------------------------------------------- */ public function save_supplier(Request $request) { $validator = Validator::make($request->all(), [ 'name'=>'required', 'contact_person'=>'required', 'phone'=>'required', 'address'=>'required' ]); if ($validator->fails()) { return back()->withErrors($validator)->withInput(); }else{ $create = new Suppliers; $create->name = $request->name; $create->contact_person = $request->contact_person; $create->nic = $request->nic; $create->phone = $request->phone; $create->email = $request->email; $create->address = $request->address; $create->description = $request->description; $create->save(); $request->session()->flash('message', 'Task was successful!'); return back(); } } /* | update_supplier |-------------------------------------------------------------------------- */ public function update_supplier(Request $request) { if($request->id){ $validator = Validator::make($request->all(), [ 'name'=>'required', 'contact_person'=>'required', 'phone'=>'required', 'address'=>'required' ]); if ($validator->fails()) { return back()->withErrors($validator)->withInput(); }else{ $update = Suppliers::findorFail($request->id); $update->name = $request->name; $update->contact_person = $request->contact_person; $update->nic = $request->nic; $update->phone = $request->phone; $update->email = $request->email; $update->address = $request->address; $update->description = $request->description; $update->save(); $request->session()->flash('message', 'Task was successful!'); return back(); } } } /* | delete_supplier |-------------------------------------------------------------------------- */ public function delete_supplier(Request $request){ $delete = Suppliers::find($request->id); if($delete){ $delete->delete(); $request->session()->flash('message', 'Task was successful!'); return back(); } abort(404); } //==================================== ingredient_categories ====================================// /* | ingredient_categories |-------------------------------------------------------------------------- */ public function ingredient_categories(Request $request) { $this->data['title'] = 'Ingredient Categories'; $this->data['ingredient_categories'] = IngredientCategories::all(); return view('admin.inventory.ingredient_categories', $this->data); } /* | single_ingredient_category |-------------------------------------------------------------------------- */ public function single_ingredient_category(Request $request) { if($request->id){ return response()->json(IngredientCategories::find($request->id)); } abort(404); } /* | save_ingredient_category |-------------------------------------------------------------------------- */ public function save_ingredient_category(Request $request) { $validator = Validator::make($request->all(), [ 'category_name'=>'required' ]); if ($validator->fails()) { return back()->withErrors($validator)->withInput(); }else{ $create = new IngredientCategories; $create->category_name = $request->category_name; $create->description = $request->description; $create->save(); $request->session()->flash('message', 'Task was successful!'); return back(); } } /* | update_ingredient_category |-------------------------------------------------------------------------- */ public function update_ingredient_category(Request $request) { if($request->id){ $validator = Validator::make($request->all(), [ 'category_name'=>'required' ]); if ($validator->fails()) { return back()->withErrors($validator)->withInput(); }else{ $obj = IngredientCategories::findorFail($request->id); $obj->category_name = $request->category_name; $obj->description = $request->description; $obj->save(); $request->session()->flash('message', 'Task was successful!'); return back(); } } } /* | delete_ingredient_category |-------------------------------------------------------------------------- */ public function delete_ingredient_category(Request $request) { $delete = IngredientCategories::find($request->id); if($delete){ $delete->delete(); $request->session()->flash('message', 'Task was successful!'); return back(); } abort(404); } //==================================== ingredient_units ====================================// /* | ingredient_units |-------------------------------------------------------------------------- */ public function ingredient_units(Request $request) { $this->data['title'] = 'Ingredient Units'; $this->data['ingredient_units'] = IngredientUnits::all(); return view('admin.inventory.ingredient_units', $this->data); } /* | single_ingredient_unit |-------------------------------------------------------------------------- */ public function single_ingredient_unit(Request $request) { return response()->json(IngredientUnits::find($request->id)); } /* | save_ingredient_unit |-------------------------------------------------------------------------- */ public function save_ingredient_unit(Request $request) { $validator = Validator::make($request->all(), [ 'unit_name'=>'required' ]); if ($validator->fails()) { return back()->withErrors($validator)->withInput(); }else{ $create = new IngredientUnits; $create->unit_name = $request->unit_name; $create->description = $request->description; $create->save(); $request->session()->flash('message', 'Task was successful!'); return back(); } } /* | update_ingredient_unit |-------------------------------------------------------------------------- */ public function update_ingredient_unit(Request $request) { if($request->id){ $validator = Validator::make($request->all(), [ 'unit_name'=>'required' ]); if ($validator->fails()) { return back()->withErrors($validator)->withInput(); }else{ $update = IngredientUnits::findorFail($request->id); $update->unit_name = $request->unit_name; $update->description = $request->description; $update->save(); $request->session()->flash('message', 'Task was successful!'); return back(); } } } /* | delete_ingredient_unit |-------------------------------------------------------------------------- */ public function delete_ingredient_unit(Request $request) { $delete = IngredientUnits::find($request->id); if($delete){ $delete->delete(); $request->session()->flash('message', 'Task was successful!'); return back(); } abort(404); } //==================================== ingredients ====================================// /* | ingredients |-------------------------------------------------------------------------- */ public function ingredients(Request $request) { $this->data['title'] = 'Ingredients'; $this->data['ingredient_categories'] = IngredientCategories::all(); $this->data['ingredient_units'] = IngredientUnits::all(); $this->data['ingredients'] = DB::table('ingredients as i') ->leftJoin('ingredient_categories as ic', 'ic.id', '=', 'i.ingredient_category_id') ->leftJoin('ingredient_units as iu', 'iu.id', '=', 'i.ingredient_unit_id') ->select('i.*' ,'ic.category_name as ingredient_category', 'iu.unit_name as ingredient_unit') ->get(); $ingredients = DB::table('ingredients')->select('id')->orderBy('id','desc')->first(); if($ingredients){ $this->data['last_ingredient_id'] = $ingredients->id; }else{ $this->data['last_ingredient_id'] = 1; } return view('admin.inventory.ingredients', $this->data); } /* | single_ingredient |-------------------------------------------------------------------------- */ public function single_ingredient(Request $request) { if($request->id){ return response()->json(Ingredients::find($request->id)); } abort(404); } /* | save_ingredient |-------------------------------------------------------------------------- */ public function save_ingredient(Request $request) { $validator = Validator::make($request->all(), [ 'name'=>'required', 'alert_quantity_amount'=>'required', 'ingredient_category'=>'required', 'ingredient_unit'=>'required' ]); if ($validator->fails()) { return back()->withErrors($validator)->withInput(); }else{ $create = new Ingredients; $create->name = $request->name; $create->alert_quantity_amount = $request->alert_quantity_amount; $create->ingredient_category_id = $request->ingredient_category; $create->ingredient_unit_id = $request->ingredient_unit; $create->code = $request->code; $create->save(); $request->session()->flash('message', 'Task was successful!'); return back(); } } /* | update_ingredient |-------------------------------------------------------------------------- */ public function update_ingredient(Request $request) { if($request->id){ $validator = Validator::make($request->all(), [ 'name'=>'required', 'alert_quantity_amount'=>'required', 'ingredient_category'=>'required', 'ingredient_unit'=>'required' ]); if ($validator->fails()) { return back()->withErrors($validator)->withInput(); }else{ $update = Ingredients::findorFail($request->id); $update->name = $request->name; $update->alert_quantity_amount = $request->alert_quantity_amount; $update->ingredient_category_id = $request->ingredient_category; $update->ingredient_unit_id = $request->ingredient_unit; $update->code = $request->code; $update->save(); $request->session()->flash('message', 'Task was successful!'); return back(); } } } /* | delete_ingredient |-------------------------------------------------------------------------- */ public function delete_ingredient(Request $request) { $delete = Ingredients::find($request->id); if($delete){ $delete->delete(); $request->session()->flash('message', 'Task was successful!'); return back(); } abort(404); } //==================================== purchasing ====================================// /* | purchasing |-------------------------------------------------------------------------- */ public function purchasing(Request $request) { $this->data['title'] = 'Purchasing'; $purchasing = DB::table('purchasings as p')->leftJoin('suppliers as s', 's.id', '=', 'p.supplier_id'); if($request->from_date !='' && $request->to_date){ $purchasing = $purchasing->whereDate('p.created_at','>=', $request->from_date); $purchasing = $purchasing->whereDate('p.created_at','<=', $request->to_date); } if($request->supplier){ $purchasing = $purchasing->where('p.supplier_id',$request->supplier); } if($request->type){ $purchasing = $purchasing->where('p.type',$request->type); } $purchasing = $purchasing->select('p.*' ,'s.name as supplier') ->orderBy('p.id','desc') ->paginate(100); $this->data['purchasing'] = $purchasing; $this->data['total_count'] = $purchasing->count('p.id'); $this->data['total_purchasing'] = $purchasing->sum('total'); $this->data['total_paid'] = $purchasing->sum('paid'); $this->data['total_due'] = $purchasing->sum('due'); $this->data['suppliers'] = Suppliers::all(); return view('admin.inventory.purchasing', $this->data); } /* | add_purchase |-------------------------------------------------------------------------- */ public function add_purchase(Request $request) { $this->data['title'] = 'Purchasing'; $this->data['suppliers'] = Suppliers::all(); $this->data['ingredients'] = DB::table('ingredients as i') ->leftJoin('ingredient_units as iu', 'iu.id', '=', 'i.ingredient_unit_id') ->select('i.*' ,'iu.unit_name as ingredient_unit') ->get(); return view('admin.inventory.purchase_add', $this->data); } /* | purchasing_details |-------------------------------------------------------------------------- */ public function purchasing_details(Request $request) { if($request->id){ $this->data['purchasing'] = DB::table('purchasings as p') ->leftJoin('suppliers as s', 's.id', '=', 'p.supplier_id') ->where('p.id',$request->id) ->first(); $this->data['purchasing_details'] = DB::table('purchasing_details as pd') ->leftJoin('ingredients as i', 'i.id', '=', 'pd.ingredient_id') ->where('pd.purchasing_id',$request->id) ->select('pd.*' ,'i.name as ingredient_name') ->get(); } return view('admin.inventory.purchasing_details', $this->data); } /* | save_purchasing |-------------------------------------------------------------------------- */ public function save_purchasing(Request $request) { $create = new Purchasing; $create->supplier_id = $request->supplier_id; $create->subtotal = $request->subtotal; $create->total = $request->grand_total; $create->paid = $request->paid; $create->due = $request->due; $create->date = $request->date; $create->save(); $purchasing_id = $create->id; $ingredients = $request->ingredient_id; if($ingredients){ foreach ($ingredients as $k => $v) { $pd = new \App\PurchasingDetail; $pd->purchasing_id = $purchasing_id; $pd->ingredient_id = $request->ingredient_id[$k]; $pd->unit_price = $request->unit_price[$k]; $pd->quantity = $request->quantity_amount[$k]; $pd->total = $request->total[$k]; $pd->save(); // stock//////////////////////////// $stock = Stock::find($request->ingredient_id[$k]); (empty($stock)) ? $stock = new Stock : ''; $stock->ingredient_id = $request->ingredient_id[$k]; if($request->type == 'purchase'){ //purchase $stock->quantity = $stock->quantity+$request->quantity_amount[$k]; }else{ //return $stock->quantity = $stock->quantity-$request->quantity_amount[$k]; } $stock->save(); // stock//////////////////////////// } } $request->session()->flash('message', 'Task was successful!'); return redirect()->route('purchasing'); } /* | update_purchasing |-------------------------------------------------------------------------- */ // public function update_purchasing(Request $request){ // $validator = Validator::make($request->all(), [ // 'supplier'=>'required', // 'ingredient'=>'required', // 'quantity'=>'required', // 'price'=>'required' // ]); // if ($validator->fails()) { // return back()->withErrors($validator)->withInput(); // }else{ // $obj = Purchasings::find($request->id); // $obj->type = $request->type; // $obj->supplier_id = $request->supplier; // $obj->ingredient_id = $request->ingredient; // $obj->quantity = $request->quantity; // $obj->price = $request->price; // $obj->save(); // $request->session()->flash('message', 'Task was successful!'); // return back(); // } // } //==================================== recipe ====================================// /* | recipe |-------------------------------------------------------------------------- */ public function recipe(Request $request) { $this->data['title'] = 'Make Recipe / Ingredient Consumptions'; //menu items $MenuItems = \App\MenuItems::where('status',1)->get(); foreach ($MenuItems as $key => $value) { $MenuItems[$key]->prices = \App\MenuItemPrices::where('menu_id',$value->id)->get(); } $this->data['menuitems'] = $MenuItems; //ingredients $ingredient_categories = IngredientCategories::all(); if($ingredient_categories){ foreach ($ingredient_categories as $key => $value) { $ingredient_categories[$key]->ingredients = DB::table('ingredients as i') ->leftJoin('ingredient_units as iu', 'iu.id', '=', 'i.ingredient_unit_id') ->where('i.ingredient_category_id',$value->id) ->select('i.*' ,'iu.unit_name as ingredient_unit') ->get(); } } $this->data['ingredient_categories'] = $ingredient_categories; return view('admin.inventory.recipe', $this->data); } /* | menu_item_recipes |-------------------------------------------------------------------------- */ public function menu_item_recipes(Request $request) { $this->data['title'] = 'Menu Item Recipes'; $MenuItemPrices = DB::table('menu_item_prices as mip') ->leftJoin('menu_items as mi', 'mi.id', '=', 'mip.menu_id') ->leftJoin('menu_categories as mc', 'mc.id', '=', 'mi.category_id') ->select('mip.*' ,'mi.menu_item_name','mc.category_name') ->get(); if($MenuItemPrices){ foreach($MenuItemPrices as $row){ if($row->id != ''){ $row->recipe_ingredients = DB::table('menu_recipe as mr') ->leftJoin('ingredients as i', 'i.id', '=', 'mr.ingredient_id') ->leftJoin('ingredient_units as iu', 'iu.id', '=', 'i.ingredient_unit_id') ->where('menu_item_price_id',$row->id) ->select('mr.*','i.name as ingredient_name','iu.unit_name as ingredient_unit') ->get(); } } } $this->data['recipes'] = $MenuItemPrices; return view('admin.inventory.recipe_ingredient_consumptions', $this->data); } /* | save_recipe |-------------------------------------------------------------------------- */ public function save_recipe(Request $request) { $menu_item_price_id = $request->menu_item_id; $ingredients = $request->ingredient_id; if($ingredients){ foreach ($ingredients as $k => $v) { $create = new MenuRecipe; $create->menu_item_price_id = $menu_item_price_id; $create->ingredient_id = $request->ingredient_id[$k]; $create->consumption = $request->consumption[$k]; $create->save(); } $request->session()->flash('message', 'Task was successful!'); return back(); } abort(404); } /* | delete_recipe |-------------------------------------------------------------------------- */ public function delete_recipe(Request $request) { if($request->id){ $recipe = MenuRecipe::where('menu_item_price_id',$request->id)->get(); if($recipe){ foreach($recipe as $row){ $row->delete(); } $request->session()->flash('message', 'Task was successful!'); return back(); } } abort(404); } //==================================== stock ====================================// /* | stock |-------------------------------------------------------------------------- */ public function stock(Request $request) { $this->data['title'] = 'Stock'; $this->data['stock'] = DB::table('stock as s') ->leftJoin('ingredients as i', 'i.id', '=', 's.ingredient_id') ->leftJoin('ingredient_units as iu', 'iu.id', '=', 'i.ingredient_unit_id') ->select('s.*','i.name as ingredient_name','iu.unit_name as ingredient_unit') ->get(); return view('admin.inventory.stock', $this->data); } //==================================== waste ====================================// /* | waste |-------------------------------------------------------------------------- */ public function waste(Request $request) { $this->data['title'] = 'Waste'; $waste = DB::table('waste'); if($request->from_date !='' && $request->to_date){ $waste = $waste->whereDate('created_at','>=', $request->from_date); $waste = $waste->whereDate('created_at','<=', $request->to_date); } $waste = $waste->orderBy('id','desc')->paginate(100); $this->data['waste'] = $waste; $this->data['total_count'] = $waste->count('id'); $this->data['total_loss'] = $waste->sum('total_loss'); return view('admin.inventory.waste', $this->data); } /* | add_waste |-------------------------------------------------------------------------- */ public function add_waste(Request $request) { $this->data['title'] = 'Waste'; $this->data['suppliers'] = Suppliers::all(); $this->data['ingredients'] = DB::table('ingredients as i') ->leftJoin('purchasing_details as pd', 'pd.ingredient_id', '=', 'i.id') ->leftJoin('ingredient_units as iu', 'iu.id', '=', 'i.ingredient_unit_id') ->where('pd.created_at','>=', Carbon::now()->subMonths(2)) ->select('i.*','pd.unit_price','iu.unit_name as ingredient_unit') ->get(); return view('admin.inventory.waste_add', $this->data); } /* | waste_details |-------------------------------------------------------------------------- */ public function waste_details(Request $request) { if($request->id){ $this->data['waste'] = DB::table('waste')->where('id',$request->id)->first(); $this->data['waste_details'] = DB::table('waste_details as wd') ->leftJoin('ingredients as i', 'i.id', '=', 'wd.ingredient_id') ->where('wd.waste_id',$request->id) ->select('wd.*' ,'i.name as ingredient_name') ->get(); } return view('admin.inventory.waste_details', $this->data); } /* | save_waste |-------------------------------------------------------------------------- */ public function saveWaste(Request $request) { $create = new Waste; $create->total_loss = $request->total_loss; $create->note = $request->note; $create->date = $request->date; $create->save(); $waste_id = $create->id; $ingredients = $request->ingredient_id; foreach ($ingredients as $k => $v) { $pd = new \App\WasteDetails; $pd->waste_id = $waste_id; $pd->ingredient_id = $request->ingredient_id[$k]; $pd->quantity = $request->waste_amount[$k]; $pd->loss_amount = $request->last_purchase_price[$k]; $pd->save(); // stock//////////////////////////// $stock = Stock::find($request->ingredient_id[$k]); if($stock){ $stock->ingredient_id = $request->ingredient_id[$k]; $stock->quantity = $stock->quantity-$request->waste_amount[$k]; $stock->save(); } } $request->session()->flash('message', 'Task was successful!'); return redirect()->route('waste'); } //==================================== consumptions ====================================// /* | consumptions |-------------------------------------------------------------------------- */ public function consumptions(Request $request) { $this->data['title'] = 'Consumptions'; $this->data['consumptions'] = []; if($request->from_date !='' && $request->to_date){ $this->data['consumptions'] = DB::table('consumptions as c') ->leftJoin('ingredients as i', 'i.id', '=', 'c.ingredient_id') ->leftJoin('ingredient_units as iu', 'iu.id', '=', 'i.ingredient_unit_id') ->whereDate('c.created_at','>=', $request->from_date) ->whereDate('c.created_at','<=', $request->to_date) ->select('c.*','i.name as ingredient_name','iu.unit_name as ingredient_unit') ->orderBy('id','desc') ->paginate(100); } return view('admin.inventory.consumptions', $this->data); } //==================================== profit_loss_report ====================================// /* | profit_loss_report |-------------------------------------------------------------------------- */ public function profit_loss_report(Request $request) { $this->data['title'] = 'Profit Loss Report'; $this->data['sale'] = 0; $this->data['tax'] = 0; $this->data['expenses'] = 0; $this->data['waste'] = 0; $this->data['purchase'] = 0; $this->data['supplier_due_payment'] = 0; if($request->from_date !='' && $request->to_date){ $order = \App\TakeawayOrders::where('status',4); $order = $order->whereDate('created_at','>=', $request->from_date); $order = $order->whereDate('created_at','<=', $request->to_date); $order = $order->select('total','tax_rate')->get(); $this->data['sale'] = $order->sum('total'); $this->data['tax'] = $order->sum('tax'); $expense = DB::table('expenses'); $expense = $expense->whereDate('created_at','>=', $request->from_date); $expense = $expense->whereDate('created_at','<=', $request->to_date); $expense = $expense->select('amount')->get(); $this->data['expenses'] = $expense->sum('amount'); $waste = DB::table('waste'); $waste = $waste->whereDate('created_at','>=', $request->from_date); $waste = $waste->whereDate('created_at','<=', $request->to_date); $waste = $waste->select('total_loss')->get(); $this->data['waste'] = $waste->sum('total_loss'); $purchase = DB::table('purchasings'); $purchase = $purchase->whereDate('created_at','>=', $request->from_date); $purchase = $purchase->whereDate('created_at','<=', $request->to_date); $purchase = $purchase->select('due','paid')->get(); $this->data['purchase'] = $purchase->sum('paid'); $this->data['supplier_due_payment'] = $purchase->sum('due'); } return view('admin.inventory.profit_loss_report', $this->data); } //==================================== Inventory Adjustments ====================================// /* | inventory_adjustments |-------------------------------------------------------------------------- */ public function inventory_adjustments(Request $request) { $this->data['title'] = 'Inventory Adjustments'; $adjustments = DB::table('inventory_adjustments'); if($request->from_date !='' && $request->to_date){ $adjustments = $adjustments->whereDate('date','>=', $request->from_date); $adjustments = $adjustments->whereDate('date','<=', $request->to_date); } $adjustments = $adjustments->orderBy('id','desc')->paginate(100); if($adjustments){ foreach($adjustments as $row){ $row->detail = DB::table('inventory_adjustment_details')->where('inventory_adjustment_id',$row->id)->get(); } } $this->data['adjustments'] = $adjustments; return view('admin.inventory.adjustments.list_adjustments', $this->data); } /* | add_adjustments |-------------------------------------------------------------------------- */ public function add_adjustments(Request $request) { $this->data['title'] = 'Add Adjustments'; $this->data['ingredients'] = DB::table('ingredients as i') ->leftJoin('ingredient_units as iu', 'iu.id', '=', 'i.ingredient_unit_id') ->select('i.*' ,'iu.unit_name as ingredient_unit') ->get(); return view('admin.inventory.adjustments.add_adjustments', $this->data); } /* | adjustments_detail |-------------------------------------------------------------------------- */ public function adjustments_detail(Request $request) { if($request->id){ $this->data['inventory_adjustment_details'] = DB::table('inventory_adjustment_details as iad') ->leftJoin('ingredients as i', 'i.id', '=', 'iad.ingredient_id') ->leftJoin('ingredient_units as iu', 'iu.id', '=', 'i.ingredient_unit_id') ->where('iad.inventory_adjustment_id',$request->id) ->select('iad.*' ,'i.name as ingredient_name','iu.unit_name as ingredient_unit') ->get(); $adjustment_details_view = view('inventory.adjustments.view_adjustments',$this->data)->render(); return response()->json(['adjustment_details' => $adjustment_details_view]); } abort(404); } /* | store_adjustments |-------------------------------------------------------------------------- */ public function store_adjustments(Request $request) { $create = new InventoryAdjustment; $create->date = $request->date; $create->note = $request->note; $create->created_by = Auth::user()->name; $create->save(); $inventory_adjusment_id = $create->id; $ingredients = $request->ingredient_id; foreach ($ingredients as $k => $v) { $pd = new InventoryAdjustmentDetail; $pd->inventory_adjusment_id = $inventory_adjusment_id; $pd->ingredient_id = $request->ingredient_id[$k]; $pd->quantity = $request->consumption_amount[$k]; $pd->status = $request->consumption_status[$k]; $pd->save(); // stock//////////////////////////// $stock = Stock::find($request->ingredient_id[$k]); (empty($stock)) ? $stock = new Stock : ''; $stock->ingredient_id = $request->ingredient_id[$k]; if($request->consumption_status[$k] == 'plus'){ $stock->quantity = $stock->quantity+$request->consumption_amount[$k]; }else{ $stock->quantity = $stock->quantity-$request->consumption_amount[$k]; } $stock->save(); } $request->session()->flash('message', 'Task was successful!'); return back(); } }