private function newBatch($dbId, $userId) { $expiresAt = Carbon::now()->subDay(2); \DebugBar::warning('New Batch'); $ownBatch = \App\Batch::where('user_id', $userId)->where('remain_count', '>', 0)->first(); if ($ownBatch != null) { \DebugBar::warning('You own a batch'); return $ownBatch; // if a batch is still owns by a user, give it to our user. } $expireBatch = \App\Batch::where('updated_at', '<=', $expiresAt)->first(); $db = \App\Dataset::find($dbId); if ($expireBatch == null) { \DebugBar::warning('if($expireBatch == null)'); $current_standard_id = $db->current_standard_id; if ($current_standard_id == 0) { // no standard id \DebugBar::warning('if($current_standard_id == 0)'); return null; } $current_standard = \App\StandardItem::find($current_standard_id); $batches = \App\Batch::where('user_id', $userId)->orderBy('standard_item_id', 'desc')->first(); if ($current_standard->batch_count == 3) { // all dispatched \DebugBar::warning('if( $current_standard->batch_count == 3 )'); $current_standard = \App\StandardItem::where('id', '>', $current_standard_id)->first(); if ($current_standard == null) { return null; } $current_standard_id = $current_standard->id; $db->current_standard_id = $current_standard_id; $db->save(); } if ($batches) { $max_standard_id = max($batches->standard_item_id + 1, $current_standard_id); } else { $max_standard_id = $current_standard_id; } $current_standard = \App\StandardItem::where("id", ">=", $max_standard_id)->first(); \DebugBar::warning('$current_standard:' . $current_standard); if ($current_standard == null) { return null; } $newBatch = new \App\Batch(); $newBatch->fill(['standard_item_id' => $current_standard->id, 'user_id' => $userId, 'remain_count' => count($current_standard->Items)]); $newBatch->save(); $current_standard->batch_count++; $current_standard->save(); \DebugBar::warning('$newBatch:' . $newBatch); return $newBatch; } else { $expiredUserId = $expireBatch->user_id; $expiredUser = \App\User::where("user_id", $expiredUserId); $expiredUser->batch_id = -1; $expiredUser->save(); $expireBatch->user_id = $userId; $expireBatch->save(); return $expireBatch; } }
/** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create(Request $request) { $circle = Circle::findOrFail($request->circle_id); $batch = Batch::where('circle_id', $request->circle_id)->orderBy('seqno', 'DESC')->first(); $seqno = 1; if (isset($batch)) { $seqno = $batch->seqno + 1; } return view('batch.create', ['circle' => $circle, 'seqno' => $seqno]); }
public function create() { $iSet = IndexSet::lists('name', 'id'); $iAll = IndexSet::all(); $i7 = I7Index::lists('index', 'id'); $i5 = I5Index::lists('index', 'id'); $pg = ProjectGroup::lists('name', 'id'); $user = Auth::user(); $batches = Batch::where('user_id', $user->id)->orderBy('created_at', 'desc')->lists('batch_name', 'id'); return view('samples.create', ['iSet' => $iSet, 'iAll' => $iAll, 'i7' => $i7, 'i5' => $i5, 'pg' => $pg, 'user' => $user, 'batches' => $batches]); }
/** * Bootstrap any application services. * * @return void */ public function boot(Guard $auth) { view()->composer('*', function ($view) { $pages = Page::orderBy('position', 'asc')->get(); $view->with('pages', $pages); }); view()->composer('*', function ($view) { $view->with('currentUser', Auth::user()); }); view()->composer('sidebar.special', function ($view) { $specialProduct = Product::where('special', 1)->get(); $view->with('specialProduct', $specialProduct); }); view()->composer('sidebar.admin', function ($view) { $today = \Carbon\Carbon::today(); $orders = DB::table('orders')->where('dateOrdered', '=', $today)->where('status_id', '>', 1)->count('id'); $view->with('orders', $orders); }); view()->composer('sidebar.admin', function ($view) { $today = date('l'); $hours = DB::table('hours')->where('day', $today)->value('hours'); $view->with('hours', $hours); }); view()->composer('sidebar.admin', function ($view) { $batches = Batch::where('proddate', \Carbon\Carbon::today())->count(); $view->with('batches', $batches); }); view()->composer('sidebar.admin', function ($view) { $date = date('Y-m-d'); $shift = Shift::where('date', $date)->pluck('id'); $employeees = Shift::find($shift)->users()->count(); $view->with('employeees', $employeees); }); view()->composer('sidebar.special', function ($view) { $categories = Category::all(); $view->with('categories', $categories); }); view()->composer('*', function ($view) use($auth) { $user = Auth::user(); if (Auth::user()) { $cart = DB::table('orders')->select('id')->where('status_id', '=', 1)->where('user_id', '=', $user->id)->value('id'); $cartItems = DB::table('order_products')->where('order_id', '=', $cart)->sum('quantity'); $view->with('cartItems', $cartItems); } }); }
/** * Display a listing of the resource. * * @return Response */ public function index() { $user = Auth::user(); $batches = Batch::where('user_id', $user->id)->orderBy('created_at', 'desc')->lists('batch_name', 'id'); return view('import.index', ['user' => $user, 'batches' => $batches]); }