/** * 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; }
/** * 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; }
/** * Returns a new table of all parts attached to the specified work order. * * @param WorkOrder $workOrder * * @return \Orchestra\Contracts\Html\Builder */ public function table(WorkOrder $workOrder) { $parts = $workOrder->parts(); return $this->table->of('work-orders.parts', function (TableGrid $table) use($workOrder, $parts) { $table->with($parts)->paginate($this->perPage); $table->pageName = 'page-parts'; $table->column('ID', 'id'); $table->column('SKU', function (Column $column) { $column->value = function (InventoryStock $stock) { return $stock->item->getSku(); }; }); $table->column('name', function (Column $column) { $column->value = function (InventoryStock $stock) { return $stock->item->name; }; }); $table->column('location', function (Column $column) { $column->value = function (InventoryStock $stock) { return $stock->location->trail; }; }); $table->column('taken', function (Column $column) { $column->value = function (InventoryStock $stock) { return $stock->quantity; }; }); $table->column('return', function (Column $column) use($workOrder) { $column->label = 'Return Stock'; $column->value = function (InventoryStock $stock) use($workOrder) { $route = 'maintenance.work-orders.parts.stocks.put'; $params = [$workOrder->getKey(), $stock->item->getKey(), $stock->getKey()]; $attributes = ['class' => 'btn btn-default btn-sm']; return link_to_route($route, 'Return', $params, $attributes); }; }); }); }