/** * 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() { // 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; }
/** * Displays the specified work orders parts and inventory. * * @param int|string $workOrderId * * @return \Illuminate\View\View */ public function index($workOrderId) { $workOrder = $this->workOrder->findOrFail($workOrderId); $parts = $this->presenter->table($workOrder); $inventory = $this->presenter->tableInventory($workOrder, $this->inventory); $navbarParts = $this->presenter->navbarParts($workOrder); $navbarInventory = $this->presenter->navbarInventory(); return view('work-orders.parts.index', compact('parts', 'inventory', 'workOrder', 'navbarParts', 'navbarInventory')); }
/** * 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() { $session = new WorkOrderSession(); $session->user_id = auth()->id(); $session->work_order_id = $this->workOrder->id; $session->in = $session->freshTimestamp(); if ($this->workOrder->sessions->count() === 0 || is_null($this->workOrder->started_at)) { $this->workOrder->update(['started_at' => $this->workOrder->freshTimestamp()]); } return $session->save(); }
/** * Displays unique sessions per worker and totals their hours. * * @param WorkOrder $workOrder * * @return \Orchestra\Contracts\Html\Builder */ public function tablePerWorker(WorkOrder $workOrder) { $sessions = $workOrder->getUniqueSessions(); return $this->table->of('work-orders.sessions.per-worker', function (TableGrid $table) use($sessions) { $table->with($sessions); $table->attributes(['class' => 'table table-hover table-striped']); $table->column('worker', function (Column $column) { $column->value = function (WorkOrderSession $session) { return $session->user->fullname; }; }); $table->column('total_hours', function (Column $column) { $column->value = function (WorkOrderSession $session) { return $session->total_hours; }; }); }); }
/** * 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; }
/** * Execute the job. * * @return bool */ public function handle() { $this->workOrder->category_id = $this->request->input('category'); $this->workOrder->location_id = $this->request->input('location'); $this->workOrder->status_id = $this->request->input('status'); $this->workOrder->priority_id = $this->request->input('priority'); $this->workOrder->subject = $this->request->input('subject'); $this->workOrder->description = $this->request->clean($this->request->input('description')); $this->workOrder->started_at = $this->request->input('started_at'); $this->workOrder->completed_at = $this->request->input('completed_at'); if ($this->workOrder->save()) { $assets = $this->request->input('assets', []); if (is_array($assets) && count($assets) > 0) { $this->workOrder->assets()->sync($assets); } return true; } return false; }
/** * 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'); }); }); }
/** * Execute the job. * * @return bool */ public function handle() { // We'll make sure the work request doesn't already have a // work order attached to it before we try and create it. if (!$this->workRequest->hasWorkOrder()) { $priority = Priority::findOrCreateRequested(); $status = Status::findOrCreateRequested(); $workOrder = new WorkOrder(); $workOrder->status_id = $status->getKey(); $workOrder->priority_id = $priority->getKey(); $workOrder->request_id = $this->workRequest->getKey(); $workOrder->user_id = $this->workRequest->user_id; $workOrder->subject = $this->workRequest->subject; $workOrder->description = $this->workRequest->description; if ($workOrder->save()) { return $workOrder; } } return false; }
/** * Processes returning stock from the work order back into the specified inventory. * * @param PartReturnRequest $request * @param int|string $workOrderId * @param int|string $itemId * @param int|string $stockId * * @throws \Stevebauman\Inventory\Exceptions\InvalidQuantityException * * @return bool */ public function postPut(PartReturnRequest $request, $workOrderId, $itemId, $stockId) { $workOrder = $this->workOrder->findOrFail($workOrderId); // Even though the inventory item isn't necessary here, we'll // find it anyway so we can check for the requests validity // and ensure the specified stock is actually attached to // the one requested. $item = $this->inventory->findOrFail($itemId); $item->stocks()->findOrFail($stockId); $stock = $workOrder->parts()->findOrFail($stockId); return $this->dispatch(new Put($request, $workOrder, $stock)); }
/** * Execute the job. * * @return bool */ public function handle() { $session = $this->workOrder->getLastUsersSession(auth()->id()); $session->out = $session->freshTimestamp(); return $session->save(); }
public function show($workOrderId, $reportId) { $workOrder = $this->workOrder->findOrFail($workOrderId); $report = $workOrder->report()->findOrFail($reportId); return view('work-orders.report', compact('workOrder', 'report')); }
/** * 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}"]); }); }); }
/** * Prompts the user to download the specified uploaded file. * * @param int|string $workOrderId * @param int|string $attachmentId * * @return \Symfony\Component\HttpFoundation\BinaryFileResponse */ public function download($workOrderId, $attachmentId) { $workOrder = $this->workOrder->findOrFail($workOrderId); $attachment = $workOrder->attachments()->findOrFail($attachmentId); return response()->download($attachment->download_path); }
/** * 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']]); }
/** * Ends the current users session for the specified work order. * * @param int|string $workOrderId * * @return mixed */ public function end($workOrderId) { $workOrder = $this->workOrder->findOrFail($workOrderId); return $this->dispatch(new End($workOrder)); }
/** * Deletes the specified work order. * * @param int|string $id * * @return bool */ public function destroy($id) { $workOrder = $this->workOrder->findOrFail($id); return $workOrder->delete(); }