?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Http\Requests\BatchEditRequest; use App\Http\Requests\Brewingstore2Request; use App\Productgroup; use App\Productsubgroup; use App\Brewingdata; use App\Hopboil; use App\Centrifuge; use App\Dryhop; use App\Alginex; use App\Productionuser; use App\Productsort; use App\Batch; use App\Brand; use App\Stock; use DB; use App\Http\Requests; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\Session; use Illuminate\Support\Facades\Redirect; class BrewingdataController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index($batchidhead) { // return $batchidhead; // $hopinfo2 = Hopboil::leftjoin('stocks', 'stocks.id', '=', 'hopboils.hop_type')->select( 'hopboils.batchid', 'batchnumber', 'hop_type', 'hop_amount', 'time_added', 'boil_end_time', 'stocks.productname' )->orderBy('time_added')->get(); $hopinfoA = $hopinfo2->where('batchid', $batchidhead)->where('batchnumber', 'A'); $brewingdatasA = Brewingdata::where('batchid', $batchidhead)->where('batchnumber', 'A')->get(); $hopinfoB = $hopinfo2->where('batchid', $batchidhead)->where('batchnumber', 'B'); $brewingdatasB = Brewingdata::where('batchid', $batchidhead)->where('batchnumber', 'B')->get(); $hopinfoC = $hopinfo2->where('batchid', $batchidhead)->where('batchnumber', 'C'); $brewingdatasC = Brewingdata::where('batchid', $batchidhead)->where('batchnumber', 'C')->get(); // return $hopinfoA.' '.$hopinfoB.' '.$hopinfoC; Session::set('batchid', $batchidhead); // return $brewingdatasA; if(empty($brewingdatasA)){ return "No data regstered!"; } $hops = Stock::where('productgroup', '2')->where('sub_group', '5')->pluck('productname', 'id'); $centrifuges = Centrifuge::where('batchidhead', $batchidhead)->get()->first(); $centrifugecount = count($centrifuges); if($centrifugecount == 0){ $input['batchidhead'] = $batchidhead; DB::table('centrifuges')->insert($input); } $centrifuges = Centrifuge::where('batchidhead', $batchidhead)->leftjoin('users', 'users.id', '=', 'centrifuges.centri_spun_by')->select( 'centri_date', 'centrifuge', 'centri_fvph', 'centri_totank', 'centri_ph_new_tank', 'centri_turbididy', 'centri_finalvolume', 'centri_do', 'users.name' )->get(); $productionusers = Productionuser::all()->pluck('produsername', 'id'); $dryhops = Dryhop::where('batchidhead', $batchidhead)->get()->first(); $dryhopcount = count($dryhops); if($dryhopcount == 0){ $input['batchidhead'] = $batchidhead; DB::table('dryhops')->insert($input); } $stockids = Hopboil::where('stockid', NULL)->get(); //return $stockids; foreach($stockids as $stockid){ $hopid = $stockid->hop_type; // return $hopid; $oldstockid2 = Productsort::where('id', $hopid)->get()->first(); if(!empty($oldstockid2)){ $oldstockid = $oldstockid2->subgroup; $input22['stockid'] = $oldstockid; } DB::table('hopboils')->where('hop_type', $hopid)->update($input22); } // return $hopid; $dryhops = Dryhop::where('batchidhead', $batchidhead)->leftjoin('stocks', 'stocks.id', '=', 'dryhops.stockid')->select( 'dry_hop_type', 'dry_hop_amount', 'dry_hop_date', 'stocks.productname' )->get(); $hops = Stock::where('sub_group', '5')->orWhere('sub_group', '4')->orWhere('sub_group', '13')->pluck('productname', 'id'); $alginex = Alginex::where('batchidhead', $batchidhead)->get()->first(); $alginexcount = count($alginex); if($alginexcount == 0){ $input['batchidhead'] = $batchidhead; DB::table('alginexes')->insert($input); } $alginex = Alginex::where('batchidhead', $batchidhead)->get(); $hopname = Productsort::pluck('productnames', 'id'); return view('admin.brewingdata.index', compact('brewingdatasA', 'brewingdatasB', 'brewingdatasC', 'batchidhead', 'hopinfoA', 'hopinfoB', 'hopinfoC','hops', 'centrifuges', 'productionusers', 'dryhops', 'alginex', 'hopname')); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create($batchidhead) { DB::table('productsorts')->truncate(); $inputstart['productnames'] = "---"; $inputstart['recipe'] = 0; $inputstart['subgroup'] = 1000; DB::table('productsorts')->insert($inputstart); $inputstart['productnames'] = "Hops"; $inputstart['recipe'] = 0; $inputstart['subgroup'] = 1000; DB::table('productsorts')->insert($inputstart); $hops = Stock::where('sub_group', 5)->get()->sortBy('productname'); foreach($hops as $hop){ $hopprod = $hop->productname; $gristexclude = $hop->gristbill_exclude; $input['gristbill_exclude'] = $gristexclude; $input['productnames'] = $hopprod; $input['subgroup'] = $hop->id; $input['recipe'] = 0; DB::table('productsorts')->insert($input); } $inputstart2['productnames'] = "---"; $inputstart2['recipe'] = 0; $inputstart2['subgroup'] = 1000; DB::table('productsorts')->insert($inputstart2); $inputstart2['productnames'] = "Spices"; $inputstart2['recipe'] = 0; $inputstart2['subgroup'] = 1000; DB::table('productsorts')->insert($inputstart2); $spices = Stock::where('sub_group', 13)->get()->sortBy('productname'); foreach($spices as $spice){ $spiceprod = $spice->productname; $gristexclude = $spice->gristbill_exclude; $input2['gristbill_exclude'] = $gristexclude; $input2['productnames'] = $spiceprod; $input2['subgroup'] = $spice->id; $input2['recipe'] = 0; DB::table('productsorts')->insert($input2); } $inputstart3['productnames'] = "---"; $inputstart3['recipe'] = 0; $inputstart3['subgroup'] = 1000; DB::table('productsorts')->insert($inputstart3); $inputstart3['productnames'] = "Fruit and Berries"; $inputstart3['recipe'] = 0; $inputstart3['subgroup'] = 1000; DB::table('productsorts')->insert($inputstart3); $fruits = Stock::where('sub_group', 4)->get()->sortBy('productname'); foreach($fruits as $fruit){ $fruitprod = $fruit->productname; $gristexclude = $fruit->gristbill_exclude; $input3['gristbill_exclude'] = $gristexclude; $input3['productnames'] = $fruitprod; $input3['subgroup'] = $fruit->id; $input3['recipe'] = 0; DB::table('productsorts')->insert($input3); } $inputstart32['productnames'] = "---"; $inputstart32['recipe'] = 1; $inputstart32['subgroup'] = 1000; DB::table('productsorts')->insert($inputstart32); $inputstart32['productnames'] = "Chems"; $inputstart32['recipe'] = 1; $inputstart32['subgroup'] = 1000; DB::table('productsorts')->insert($inputstart32); $chems = Stock::where('sub_group', 2)->get()->sortBy('productname'); foreach($chems as $chem){ $chemprod = $chem->productname; $gristexclude = $chem->gristbill_exclude; $input32['gristbill_exclude'] = $gristexclude; $input32['productnames'] = $chemprod; $input32['subgroup'] = $chem->id; $input32['recipe'] = 1; DB::table('productsorts')->insert($input32); } $inputstart33['productnames'] = "---"; $inputstart33['recipe'] = 1; $inputstart33['subgroup'] = 1000; DB::table('productsorts')->insert($inputstart33); $inputstart33['productnames'] = "Other fermentables"; $inputstart33['recipe'] = 1; $inputstart33['subgroup'] = 1000; DB::table('productsorts')->insert($inputstart33); $others = Stock::where('sub_group', 11)->get()->sortBy('productname'); foreach($others as $other){ $otherprod = $other->productname; $gristexclude = $other->gristbill_exclude; $input33['gristbill_exclude'] = $gristexclude; $input33['productnames'] = $otherprod; $input33['subgroup'] = $other->id; $input33['recipe'] = 1; DB::table('productsorts')->insert($input33); } $backurl = url()->current(); Session::set('backurl', $backurl); $hopinfoA = Hopboil::where('batchid', $batchidhead)->where('batchnumber', 'A')->get(); $hopinfoB = Hopboil::where('batchid', $batchidhead)->where('batchnumber', 'B')->get(); $hopinfoC = Hopboil::where('batchid', $batchidhead)->where('batchnumber', 'C')->get(); $brandname = substr($batchidhead, -3); $brewingdatasA = Brewingdata::where('batchid', $batchidhead)->where('batchnumber', 'A')->get()->first(); $brewingdatasB = Brewingdata::where('batchid', $batchidhead)->where('batchnumber', 'B')->get()->first(); $brewingdatasC = Brewingdata::where('batchid', $batchidhead)->where('batchnumber', 'C')->get()->first(); $brewdatacount = count($brewingdatasA); if($brewdatacount == 0){ $inputA['batchid'] = $batchidhead; $inputA['batchnumber'] = 'A'; $inputB['batchid'] = $batchidhead; $inputB['batchnumber'] = 'B'; $inputC['batchid'] = $batchidhead; $inputC['batchnumber'] = 'C'; DB::table('brewingdatas')->insert($inputA); DB::table('brewingdatas')->insert($inputB); DB::table('brewingdatas')->insert($inputC); } //return $brewdatacount; $brewingdatasA = Brewingdata::where('batchid', $batchidhead)->where('batchnumber', 'A')->get()->first(); $brewingdatasB = Brewingdata::where('batchid', $batchidhead)->where('batchnumber', 'B')->get()->first(); $brewingdatasC = Brewingdata::where('batchid', $batchidhead)->where('batchnumber', 'C')->get()->first(); $hopinfoA = Hopboil::where('hopboils.batchid', $batchidhead)->where('batchnumber', 'A')->leftjoin('stocks', 'stocks.id', '=', 'hopboils.hop_type')->select( 'hopboils.batchid', 'batchnumber', 'hop_type', 'hop_amount', 'time_added', 'boil_end_time', 'stocks.productname' )->orderBy('time_added')->get(); $hopinfoB = Hopboil::where('hopboils.batchid', $batchidhead)->where('batchnumber', 'B')->leftjoin('stocks', 'stocks.id', '=', 'hopboils.hop_type')->select( 'hopboils.batchid', 'batchnumber', 'hop_type', 'hop_amount', 'time_added', 'boil_end_time', 'stocks.productname' )->orderBy('time_added')->get(); $hopinfoC = Hopboil::where('hopboils.batchid', $batchidhead)->where('batchnumber', 'C')->leftjoin('stocks', 'stocks.id', '=', 'hopboils.hop_type')->select( 'hopboils.batchid', 'batchnumber', 'hop_type', 'hop_amount', 'time_added', 'boil_end_time', 'stocks.productname' )->orderBy('time_added')->get(); // return $hopinfoA; // return $brewingdatasA; // $batchnumberA = $hopinfoA->batchnumber; // $batchnumberB = $hopinfoB->batchnumber; // $batchnumberC = $hopinfoC->batchnumber; // return $batchnumber; $hops = Productsort::where('recipe', 0)->pluck('productnames', 'id'); // return $hops; // return $brewingdatasA.' '.$brewingdatasB.' '.$brewingdatasC.' '.$batchidhead.' '.$hopinfoA.' '.$hopinfoB.' '.$hopinfoC.' '.$hops.' '.$brandname; return view('admin.brewingdata.create', compact('brewingdatasA', 'brewingdatasB', 'brewingdatasC','batchidhead', 'hopinfoA', 'hopinfoB', 'hopinfoC', 'hops', 'brandname')); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // return $request->all(); $batchid2 = $request->batchid; $batchnumber = $request->batchnumber; $hoptype = $request->hop_type; if(!empty($hoptype)){ $newhoptype2 = Productsort::where('id', $hoptype)->get()->first(); $newhoptype = $newhoptype2->subgroup; } $input = $request->all(); // return $newhoptype; Brewingdata::updateOrCreate(['batchid' => $batchid2, 'batchnumber' => $batchnumber], $input); // $input2['hop_type'] = $newhoptype; // DB::table('hopboils')->where('hop_type', $hoptype)->update($input2); $hopcheck = $request->hop_type; if(!empty($hopcheck)){ $batchinfo = Brewingdata::where('batchid', $batchid2)->where('batchnumber', $batchnumber)->get()->first(); $batchnumber = $batchinfo->batchnumber; $brand = $batchinfo->brand; $input1['batchid'] = $batchid2; $input1['batchnumber'] = $batchnumber; $input1['brand'] = trim($brand); $input1['hop_type'] = $newhoptype; $input1['hop_amount'] = $request->hop_amount; $input1['time_added'] = $request->time_added; $input1['boil_end_time'] = $request->boil_end_time; // return $input1; DB::table('hopboils')->insert($input1); /* if(!empty($hoptype)){ $input2['hop_type'] = $newhoptype; DB::table('hopboils')->where('batchid', $batchid2)->where('batchnumber', $batchnumber)->where('hop_type', $hoptype)->update($input2); } */ } return redirect()->back(); } public function create2($batchidhead) { $hopinfo = Hopboil::where('batchid', $batchidhead)->where('batchnumber', 'B')->get(); $brandname = substr($batchidhead, -3); $brewingdatas = Brewingdata::where('batchid', $batchidhead)->where('batchnumber', 'B')->get(); $brewdatacount = count($brewingdatas); if($brewdatacount == 0){ $inputA['batchid'] = $batchidhead; $inputA['batchnumber'] = 'A'; $inputB['batchid'] = $batchidhead; $inputB['batchnumber'] = 'B'; $inputC['batchid'] = $batchidhead; $inputC['batchnumber'] = 'C'; DB::table('brewingdatas')->insert($inputA); DB::table('brewingdatas')->insert($inputB); DB::table('brewingdatas')->insert($inputC); } //return $brewdatacount; $brewingdatas = Brewingdata::where('batchid', $batchidhead)->where('batchnumber', 'B')->get()->first(); $hopinfo = Hopboil::where('hopboils.batchid', $batchidhead)->where('batchnumber', 'B')->leftjoin('stocks', 'stocks.id', '=', 'hopboils.hop_type')->select( 'hopboils.batchid', 'batchnumber', 'hop_type', 'hop_amount', 'time_added', 'boil_end_time', 'stocks.productname' )->get(); // $hopinfo = $hopinfo2->where('batchid', $batchidhead)->where('batchnumber', 'A')->get(); $batchnumber = $brewingdatas->batchnumber; // return $batchnumber; $hops = Stock::where('productgroup', '2')->where('sub_group', '5')->pluck('productname', 'id'); return view('admin.brewingdata.create', compact('brewingdatas', 'batchidhead', 'hopinfo','hops', 'brandname', 'batchnumber')); } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store2(Request $request) { // return $request->all(); $batchid2 = $request->batchid; $batchnumber = $request->batchnumber; $hoptype = $request->hop_type; if(!empty($hoptype)){ $newhoptype2 = Productsort::where('id', $hoptype)->get()->first(); $newhoptype = $newhoptype2->subgroup; } $input = $request->all(); // return $input; Brewingdata::updateOrCreate(['batchid' => $batchid2, 'batchnumber' => $batchnumber], $input); // DB::table('brewingdatas')->insert([$request]); $hopcheck = $request->hop_type; if(!empty($hopcheck)){ $batchinfo = Brewingdata::where('batchid', $batchid2)->where('batchnumber', $batchnumber)->get()->first(); $batchnumber = $batchinfo->batchnumber; $brand = $batchinfo->brand; $input1['batchid'] = $batchid2; $input1['batchnumber'] = $batchnumber; $input1['brand'] = $brand; $input1['hop_type'] = $newhoptype; $input1['hop_amount'] = $request->hop_amount; $input1['time_added'] = $request->time_added; $input1['boil_end_time'] = $request->boil_end_time; // return $input; DB::table('hopboils')->insert($input1); /* if(!empty($hoptype)){ $input2['hop_type'] = $newhoptype; //return $hoptype; DB::table('hopboils')->where('hop_type', $hoptype)->update($input2); } */ } return redirect()->back(); } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function create3($batchidhead) { $hopinfoC = Hopboil::where('batchid', $batchidhead)->where('batchnumber', 'C')->get(); // return $hopinfoC; $brandnameC = substr($batchidhead, -3); $brewingdatasC2 = Brewingdata::where('batchid', $batchidhead)->where('batchnumber', 'C')->get(); $brewdatacountC = count($brewingdatasC2); if($brewdatacountC == 0){ $inputA['batchid'] = $batchidhead; $inputA['batchnumber'] = 'A'; $inputB['batchid'] = $batchidhead; $inputB['batchnumber'] = 'B'; $inputC['batchid'] = $batchidhead; $inputC['batchnumber'] = 'C'; DB::table('brewingdatas')->insert($inputA); DB::table('brewingdatas')->insert($inputB); DB::table('brewingdatas')->insert($inputC); } //return $brewdatacount; $brewingdatasC = Brewingdata::where('batchid', $batchidhead)->where('batchnumber', 'C')->get(); $hopinfoC = Hopboil::where('hopboils.batchid', $batchidhead)->where('batchnumber', 'C')->leftjoin('stocks', 'stocks.id', '=', 'hopboils.hop_type')->select( 'hopboils.batchid', 'batchnumber', 'hop_type', 'hop_amount', 'time_added', 'boil_end_time', 'stocks.productname' )->get(); // $hopinfo = $hopinfo2->where('batchid', $batchidhead)->where('batchnumber', 'A')->get(); $batchnumberC = $brewingdatasC->batchnumber; // return $batchnumber; $hopsC = Stock::where('productgroup', '2')->where('sub_group', '5')->pluck('productname', 'id'); return view('admin.brewingdata.create', compact('brewingdatasC', 'batchidheadC', 'hopinfoC','hopsC', 'brandnameC', 'batchnumberC')); } public function store3(Request $request) { // return $request->all(); $batchid2 = $request->batchid; $batchnumber = $request->batchnumber; $hoptype = $request->hop_type; if(!empty($hoptype)){ $newhoptype2 = Productsort::where('id', $hoptype)->get()->first(); $newhoptype = $newhoptype2->subgroup; } $input = $request->all(); // return $input; Brewingdata::updateOrCreate(['batchid' => $batchid2, 'batchnumber' => $batchnumber], $input); // DB::table('brewingdatas')->insert([$request]); $hopcheck = $request->hop_type; if(!empty($hopcheck)){ $batchinfo = Brewingdata::where('batchid', $batchid2)->where('batchnumber', $batchnumber)->get()->first(); $batchnumber = $batchinfo->batchnumber; Session::set('batchnumber', $batchnumber); $brand = $batchinfo->brand; $input1['batchid'] = $batchid2; $input1['batchnumber'] = $batchnumber; $input1['brand'] = $brand; $input1['hop_type'] = $newhoptype; $input1['hop_amount'] = $request->hop_amount; $input1['time_added'] = $request->time_added; $input1['boil_end_time'] = $request->boil_end_time; // return $input; DB::table('hopboils')->insert($input1); /* if(!empty($hoptype)){ $input2['hop_type'] = $newhoptype; //return $hoptype; DB::table('hopboils')->where('hop_type', $hoptype)->update($input2); } */ } return redirect()->back(); } public function show() { // } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($batchidhead) { $batchnumber = Session::get('batchnumber'); $brewingdatas = Brewingdata::where('batchid', $batchidhead)->get()->first(); $hopdata = Hopboil::where('hopboils.batchid', $batchidhead)->leftjoin('stocks', 'stocks.id', '=', 'hopboils.hop_type')->select( 'hopboils.batchid', 'hopboils.id', 'batchnumber', 'hop_type', 'hop_amount', 'time_added', 'boil_end_time', 'stocks.productname' )->orderBy('batchnumber')->orderBy('time_added')->get(); return view('admin.brewingdata.edit', compact('batchidhead', 'hopdata')); } public function edit2($id) { $brewingdatas = Hopboil::where('id', $id)->get()->first(); // return $brewingdatas; $hopdata = Hopboil::where('hopboils.id', $id)->leftjoin('stocks', 'stocks.id', '=', 'hopboils.hop_type')->select( 'hopboils.batchid', 'hopboils.id', 'batchnumber', 'hop_type', 'hop_amount', 'time_added', 'boil_end_time', 'stocks.productname' )->get(); return view('admin.brewingdata.edit2', compact('hopdata', 'brewingdatas')); } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request) { // // return $request->all(); $hopid = $request->hopboils_id; $hopboils = Hopboil::where('id', $hopid)->get()->first(); // return $hopboils; $input['hop_amount'] = $request->hop_amount; $input['time_added'] = $request->time_added; $hopboils->where('id', $hopid)->update($input); $hopdata = Hopboil::where('hopboils.id', $hopid)->leftjoin('stocks', 'stocks.id', '=', 'hopboils.hop_type')->select( 'hopboils.batchid', 'hopboils.id', 'batchnumber', 'hop_type', 'hop_amount', 'time_added', 'boil_end_time', 'stocks.productname' )->get(); $backurl = Session::get('backurl'); return Redirect::to($backurl); } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { // $batchid = Session::get('batchid'); // return $batchid; $hopdata2 = Hopboil::where('id', $id)->delete(); $hopdata = Hopboil::where('hopboils.batchid', $batchid)->leftjoin('stocks', 'stocks.id', '=', 'hopboils.hop_type')->select( 'hopboils.batchid', 'hopboils.id', 'batchnumber', 'hop_type', 'hop_amount', 'time_added', 'boil_end_time', 'stocks.productname' )->get(); $backurl = Session::get('backurl'); return Redirect::to($backurl); } }