/** * 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; }
/** * Returns a new form of the specified work order report. * * @param WorkOrder $workOrder * @param WorkOrderReport $report * * @return \Orchestra\Contracts\Html\Builder */ public function form(WorkOrder $workOrder, WorkOrderReport $report) { return $this->form->of('work-orders.report', function (FormGrid $form) use($workOrder, $report) { if ($report->exists) { $method = 'PATCH'; $url = route('maintenance.work-orders.report.update', [$workOrder->getKey(), $report->getKey()]); $form->submit = 'Save'; } else { $method = 'POST'; $url = route('maintenance.work-orders.report.store', [$workOrder->getKey()]); $form->submit = 'Create'; } $form->attributes(compact('method', 'url')); $form->with($report); $form->fieldset(function (Fieldset $fieldset) use($workOrder) { $fieldset->control('select', 'status')->options(function () { $statuses = Status::all()->pluck('name', 'id'); $statuses[0] = 'None'; return $statuses; })->value(function () use($workOrder) { if ($workOrder->status instanceof Status) { return $workOrder->status->getKey(); } })->attributes(['class' => 'select2']); $fieldset->control('input:textarea', 'description'); }); }); }
/** * Returns a new form for the specified work order attachment. * * @param WorkOrder $workOrder * @param Attachment $attachment * * @return \Orchestra\Contracts\Html\Builder */ public function form(WorkOrder $workOrder, Attachment $attachment) { return $this->form->of('work-orders.attachments', function (FormGrid $form) use($workOrder, $attachment) { $files = true; if ($attachment->exists) { $url = route('maintenance.work-orders.attachments.update', [$workOrder->getKey(), $attachment->getKey()]); $method = 'PATCH'; $form->submit = 'Save'; $form->with($attachment); } else { $url = route('maintenance.work-orders.attachments.store', [$workOrder->getKey()]); $method = 'POST'; $form->submit = 'Upload'; } $form->attributes(compact('url', 'method', 'files')); $form->fieldset(function (Fieldset $fieldset) use($attachment) { if ($attachment->exists) { // If the attachment exists we'll provide the ability // to only change the attachments name. $fieldset->control('input:text', 'name')->label('Attachment Name'); } else { // Otherwise we'll allow the user to upload multiple // attachments at once for the specified work order. $fieldset->control('input:file', 'files[]')->label('Files')->attributes(['multiple' => true]); } }); }); }
/** * Execute the job. * * @return bool */ public function handle() { $this->report->user_id = auth()->id(); $this->report->work_order_id = $this->workOrder->getKey(); $this->report->description = $this->request->clean($this->request->input('description')); if ($this->report->save()) { $this->workOrder->complete($this->request->input('status')); 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 form for the specified comment. * * @param WorkOrder $workOrder * @param Comment $comment * * @return \Orchestra\Contracts\Html\Builder */ public function form(WorkOrder $workOrder, Comment $comment) { return $this->form->of('work-orders.comments', function (FormGrid $form) use($workOrder, $comment) { if ($comment->exists) { $method = 'PATCH'; $url = route('work-orders.comments.update', [$workOrder->getKey(), $comment->getKey()]); $form->submit = 'Save'; } else { $method = 'POST'; $url = route('work-orders.comments.store', [$workOrder->getKey()]); $form->submit = 'Create'; } $form->attributes(compact('method', 'url')); $form->with($comment); $form->fieldset(function (Fieldset $fieldset) { $fieldset->control('input:text', 'content'); }); }); }
/** * Returns a new form for work orders. * * @param WorkOrder $workOrder * * @return \Orchestra\Contracts\Html\Builder */ public function form(WorkOrder $workOrder) { return $this->form->of('work-orders', function (FormGrid $form) use($workOrder) { if ($workOrder->exists) { $method = 'PATCH'; $url = route('maintenance.work-orders.update', [$workOrder->getKey()]); $form->submit = 'Save'; } else { $method = 'POST'; $url = route('maintenance.work-orders.store'); $form->submit = 'Create'; } $form->with($workOrder); $form->attributes(compact('method', 'url')); $form->fieldset(function (Fieldset $fieldset) { $fieldset->control('select', 'category')->value(function (WorkOrder $workOrder) { return $workOrder->category_id; })->options(function () { return Category::getSelectHierarchy('work-orders'); }); $fieldset->control('select', 'location')->value(function (WorkOrder $workOrder) { return $workOrder->location_id; })->options(function () { return Location::getSelectHierarchy(); }); $fieldset->control('select', 'status')->options(function () { $statuses = Status::all()->pluck('name', 'id'); $statuses[0] = 'None'; return $statuses; }); $fieldset->control('select', 'priority')->value(function (WorkOrder $workOrder) { return $workOrder->priority_id; })->options(function () { $priorities = Priority::all()->pluck('name', 'id'); $priorities[0] = 'None'; return $priorities; }); $fieldset->control('select', 'assets[]')->label('Assets')->options(function () { return Asset::all()->pluck('name', 'id'); })->attributes(['class' => 'select2', 'multiple' => true]); $fieldset->control('input:text', 'subject')->attributes(['placeholder' => 'ex. Worked on HVAC']); $fieldset->control('input:textarea', 'description'); }); }); }
/** * Returns a new navbar for the work order parts table. * * @param WorkOrder $workOrder * * @return \Illuminate\Support\Fluent */ public function navbarParts(WorkOrder $workOrder) { return $this->fluent(['id' => 'work-orders-parts', 'title' => 'Parts Added', 'url' => route('maintenance.work-orders.parts.index', [$workOrder->getKey()]), 'menu' => view('work-orders.parts._nav', compact('workOrder')), 'attributes' => ['class' => 'navbar-default']]); }
/** * 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}"]); }); }); }