Beispiel #1
0
 /**
  * Execute the job.
  *
  * @return bool
  */
 public function handle()
 {
     // Get the requested quantity to return
     $quantity = $this->request->input('quantity');
     // We'll double check that the stock model we've been given contains
     // the pivot attribute, indicating it's been retrieved
     // from the work order.
     if ($this->stock->pivot instanceof Pivot) {
         if ($quantity > $this->stock->pivot->quantity) {
             // If the quantity entered is greater than the
             // taken stock, we'll return all of the stock.
             $returnQuantity = $this->stock->pivot->quantity;
         } else {
             // Otherwise we can use the users quantity input.
             $returnQuantity = $quantity;
         }
         // Set the stock put reason.
         $reason = link_to_route('maintenance.work-orders.show', 'Put Back from Work Order', [$this->workOrder->getKey()]);
         // Return the specified quantity.
         $this->stock->put($returnQuantity, $reason);
         // Retrieve the left over quantity for the work order.
         $newQuantity = $this->stock->pivot->quantity - $returnQuantity;
         if ($newQuantity == 0) {
             // If the new quantity is zero, we'll detach the
             // stock record from the work order parts.
             $this->workOrder->parts()->detach($this->stock->getKey());
         } else {
             // Otherwise we'll update the quantity on the pivot record.
             $this->workOrder->parts()->updateExistingPivot($this->stock->getKey(), ['quantity' => $newQuantity]);
         }
         return true;
     }
     return false;
 }
Beispiel #2
0
 /**
  * Execute the job.
  *
  * @return bool
  */
 public function handle()
 {
     $this->stock->location_id = $this->request->input('location', $this->stock->location_id);
     $this->stock->quantity = $this->request->input('quantity', $this->stock->quantity);
     $this->stock->cost = $this->request->input('cost');
     $this->stock->reason = $this->request->input('reason');
     return $this->stock->save();
 }
 /**
  * Captures the Inventory Stock models restored event
  * and cascades the restore to all of it's movements.
  *
  * @param InventoryStock $stock
  */
 public function restored(InventoryStock $stock)
 {
     $movements = $stock->movements()->onlyTrashed()->get();
     if (count($movements) > 0) {
         foreach ($movements as $movement) {
             $movement->restore();
         }
     }
 }
Beispiel #4
0
 /**
  * Execute the job.
  *
  * @return bool
  */
 public function handle()
 {
     $this->stock->user_id = auth()->id();
     $this->stock->inventory_id = $this->inventory->getKey();
     $this->stock->location_id = $this->request->input('location');
     $this->stock->quantity = $this->request->input('quantity');
     $this->stock->cost = $this->request->input('cost');
     $this->stock->reason = $this->request->input('reason');
     return $this->stock->save();
 }
Beispiel #5
0
 /**
  * Execute the job.
  *
  * @return bool
  */
 public function handle()
 {
     $quantity = $this->request->input('quantity');
     $reason = link_to_route('maintenance.work-orders.show', 'Used for Work Order', [$this->workOrder->getKey()]);
     $this->stock->take($quantity, $reason);
     // We'll check if the work order currently has the stock already attached.
     $stock = $this->workOrder->parts()->find($this->stock->getKey());
     if ($stock instanceof InventoryStock) {
         // Add on the quantity inputted to the existing record quantity.
         $newQuantity = $stock->pivot->quantity + $quantity;
         $this->workOrder->parts()->updateExistingPivot($stock->getKey(), ['quantity' => $newQuantity]);
         return true;
     }
     // It looks like the part isn't yet attached to
     // the work order. We'll attach it now.
     $this->workOrder->parts()->attach($this->stock->getKey(), compact('quantity'));
     return true;
 }
Beispiel #6
0
 public function getTotalInventoryValue()
 {
     $stocks = InventoryStock::where('quantity', '>', 0)->get();
     $value = 0;
     foreach ($stocks as $stock) {
         $pivot = $stock->item->getCurrentSupplierPivot();
         if ($pivot->supplier_id == $this->id) {
             $value += $stock->quantity * $pivot->cost;
         }
     }
     return $value;
 }
 public function getTotalInventory()
 {
     $stocks = InventoryStock::all();
     return view('report.total-inventory', compact('stocks'));
 }
 /**
  * Take specified quantity from stock
  *
  * @param InventoryTransaction      $request
  *
  * @return redirect
  */
 public function take(InventoryStock $stock, Request $request)
 {
     $stock->take($request->quantity, 'taken by user');
     return redirect()->back()->with('message', $request->quantity . ' stk has been taken!');
 }
 /**
  * Returns a new form of the specified inventory stock.
  *
  * @param Inventory      $item
  * @param InventoryStock $stock
  *
  * @return \Orchestra\Contracts\Html\Builder
  */
 public function form(Inventory $item, InventoryStock $stock)
 {
     return $this->form->of('inventory.stocks', function (FormGrid $form) use($item, $stock) {
         if ($stock->exists) {
             $method = 'PATCH';
             $url = route('maintenance.inventory.stocks.update', [$item->getKey(), $stock->getKey()]);
             $form->submit = 'Save';
         } else {
             $method = 'POST';
             $url = route('maintenance.inventory.stocks.store', [$item->getKey()]);
             $form->submit = 'Create';
         }
         $locations = Location::getSelectHierarchy();
         $form->with($stock);
         $form->attributes(compact('method', 'url'));
         $form->fieldset(function (Fieldset $fieldset) use($locations) {
             $fieldset->control('select', 'location')->value(function (InventoryStock $stock) {
                 return $stock->location_id;
             })->options($locations);
             $fieldset->control('input:text', 'quantity')->attributes(['placeholder' => 'ex. 45']);
             $fieldset->control('input:text', 'reason')->attributes(['placeholder' => 'ex. Stock Update']);
             $fieldset->control('input:text', 'cost')->attributes(['placeholder' => 'ex. 15.00']);
         });
     });
 }
 /**
  * Returns a new form for putting the stock from the
  * specified work order back into inventory.
  *
  * @param WorkOrder      $workOrder
  * @param Inventory      $inventory
  * @param InventoryStock $stock
  *
  * @return \Orchestra\Contracts\Html\Builder
  */
 public function formPut(WorkOrder $workOrder, Inventory $inventory, InventoryStock $stock)
 {
     return $this->form->of('work-orders.parts.stocks.put', function (FormGrid $form) use($workOrder, $inventory, $stock) {
         $form->attributes(['method' => 'POST', 'url' => route('maintenance.work-orders.parts.stocks.put', [$workOrder->getKey(), $inventory->getKey(), $stock->getKey()])]);
         $form->submit = 'Save';
         $form->fieldset(function (Fieldset $fieldset) use($inventory, $stock) {
             $metric = $inventory->getMetricSymbol();
             $fieldset->control('input:text', 'quantity', function (Field $field) {
                 $field->label = 'Return Quantity';
             })->value($stock->pivot->quantity)->attribute(['placeholder' => "Enter Quantity in {$metric}"]);
         });
     });
 }