Exemple #1
0
 public static function updateInventory()
 {
     foreach (Bullet::all() as $bullet) {
         $rounds_purchased = DB::table('inventories')->where('bullet_id', $bullet->id)->sum('rounds');
         $rounds_fired = DB::table('shoots')->where('bullet_id', $bullet->id)->sum('rounds');
         $bullet->inventory = $rounds_purchased - $rounds_fired;
         $bullet->save();
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $orderID, $id)
 {
     // create the new Order
     $inventory = Inventory::find($id);
     $order = Order::find($orderID);
     $bullet = Bullet::find($request->bullet_id);
     // Get the data
     $inventory->boxes = $request->boxes;
     $inventory->rounds_per_box = $request->rounds_per_box;
     $inventory->rounds = $request->rounds_per_box * $request->boxes;
     $inventory->cost_per_box = $request->cost_per_box;
     $inventory->cost = $request->cost_per_box * $request->boxes;
     $inventory->notes = $request->notes;
     // Make relationships
     $inventory->bullet()->associate($bullet);
     $inventory->order()->associate($order);
     // Update the totals
     $inventory->order->updateCost();
     $inventory->order->updateRounds();
     $inventory->order->save();
     // Save the Order
     $inventory->save();
     // Update inventory for all Bullets
     Bullet::updateInventory();
     session()->flash('message', 'Inventory has been Saved');
     session()->flash('message-type', 'success');
     return redirect()->action('InventoryController@show', [$order->id, $inventory->id]);
 }
Exemple #3
0
 public function scopePurposes()
 {
     foreach (Purpose::all() as $purpose) {
     }
     $inventory = Bullet::where('cartridge_id', $this->id)->select(DB::raw('SUM(`inventory`) as inventory, purpose_id'))->groupBy('purpose_id')->get();
 }
Exemple #4
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $tripID, $id)
 {
     // create the new Order
     $shoot = Shoot::find($id);
     $trip = Trip::find($tripID);
     $bullet = Bullet::find($request->bullet_id);
     // Get the data
     $shoot->rounds = $request->rounds;
     $shoot->firearm_id = $request->firearm_id;
     $shoot->notes = $request->notes;
     $shoot->trip()->associate($trip);
     $shoot->bullet()->associate($bullet);
     // Save the Order
     $shoot->save();
     // Update inventory for all Bullets
     Bullet::updateInventory();
     session()->flash('message', 'Shoot has been Saved');
     session()->flash('message-type', 'success');
     return redirect()->action('ShootController@show', [$trip->id, $shoot->id]);
 }
Exemple #5
0
 public function showManufacturers($manufacturer)
 {
     return view('bullets.index', ['cartridges' => Cartridge::all(), 'bullets' => Bullet::where('manufacturer', $manufacturer)->get(), 'sort' => 'inventory']);
 }
Exemple #6
0
 /**
  * Update the specified resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @param  int  $id
  * @return \Illuminate\Http\Response
  */
 public function update(Request $request, $id)
 {
     // Find the Order
     $order = Order::find($id);
     // Update the data
     $order->store_id = $request->store_id;
     $order->order_date = $request->order_date;
     $order->notes = $request->notes;
     // Update the totals
     $order->updateCost();
     $order->updateRounds();
     // Save it
     $order->save();
     // Update inventory for all Bullets
     Bullet::updateInventory();
     session()->flash('message', 'Order has been saved');
     session()->flash('message-type', 'success');
     return redirect()->action('OrderController@show', [$order->id]);
 }