/**
  * Creates attachment records, attaches them to the asset images pivot table,
  * and moves the uploaded file into it's stationary position (out of the temp folder).
  *
  * @return array|bool
  */
 public function create()
 {
     $this->dbStartTransaction();
     try {
         // Find the work order
         $workOrder = $this->workOrder->find($this->getInput('work_order_id'));
         $uploadDir = $this->getInput('file_path');
         // Check if any files have been uploaded
         $files = $this->getInput('files');
         if ($uploadDir && $files) {
             $records = [];
             // For each file, create the attachment record, and sync asset image pivot table
             foreach ($files as $file) {
                 $insert = ['file_name' => $file, 'file_path' => $uploadDir . $file, 'user_id' => $this->sentry->getCurrentUserId()];
                 // Create the attachment record
                 $attachment = $this->attachment->setInput($insert)->create();
                 // Attach the attachment record to the work order attachments
                 $workOrder->attachments()->attach($attachment);
                 $records[] = $attachment;
             }
             $this->dbCommitTransaction();
             // Return attachment record on success
             return $records;
         }
     } catch (\Exception $e) {
         $this->dbRollbackTransaction();
     }
     return false;
 }
Esempio n. 2
0
 /**
  * Creates a new work order session.
  *
  * @return bool|WorkOrderSession
  */
 public function create()
 {
     $this->dbStartTransaction();
     try {
         $workOrder = $this->workOrder->find($this->getInput('work_order_id'));
         $now = Carbon::now()->toDateTimeString();
         /*
          * If this is the first session that is being created on
          * the work order, set the started at property to now
          */
         if ($workOrder->sessions->count() === 0) {
             $update = ['started_at' => $now];
             $this->workOrder->setInput($update)->update($workOrder->id);
         }
         $insert = ['user_id' => $this->sentry->getCurrentUserId(), 'work_order_id' => $workOrder->id, 'in' => $now];
         $record = $this->model->create($insert);
         if ($record) {
             $this->dbCommitTransaction();
             return $record;
         }
     } catch (\Exception $e) {
         $this->dbRollbackTransaction();
     }
     return false;
 }
 /**
  * Creates a new work order for the specified
  * request.
  *
  * @param string|int $requestId
  *
  * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
  */
 public function store($requestId)
 {
     $workRequest = $this->workRequest->find($requestId);
     /*
      * If a work order already exists for this request, we'll return
      * an error and let the user know
      */
     if ($workRequest->workOrder) {
         $link = link_to_route('maintenance.work-orders.show', 'Show Work Order', [$workRequest->workOrder->id]);
         $this->message = "A work order already exists for this work request. {$link}";
         $this->messageType = 'warning';
         $this->redirect = routeBack('maintenance.work-requests.index');
         return $this->response();
     }
     $workOrder = $this->workOrder->createFromWorkRequest($workRequest);
     if ($workOrder) {
         $link = link_to_route('maintenance.work-orders.show', 'Show', [$workOrder->id]);
         $this->message = "Successfully generated work order. {$link}";
         $this->messageType = 'success';
         $this->redirect = routeBack('maintenance.work-orders.show', [$workOrder->id]);
     } else {
         $message = 'There was an issue trying to generate a work order for this request.
         If a work order was deleted that was attached to this request, it will have to be removed/recovered by
         an administrator before generating another work order.';
         $this->message = $message;
         $this->messageType = 'danger';
         $this->redirect = routeBack('maintenance.work-orders.requests.create', [$requestId]);
     }
     return $this->response();
 }
 /**
  * Validates that work order only contains one report.
  *
  * @param string     $attribute
  * @param int|string $locationId
  * @param $parameters
  *
  * @return bool
  */
 public function validateUniqueReport($attribute, $locationId, $parameters)
 {
     $workOrderId = Route::getCurrentRoute()->getParameter('work_orders');
     if ($workOrder = $this->workOrder->find($workOrderId)) {
         if ($workOrder->report) {
             return false;
         }
         return true;
     }
     return false;
 }
Esempio n. 5
0
 /**
  * Creates a work order report.
  *
  * @return bool|static
  */
 public function create()
 {
     $this->dbStartTransaction();
     try {
         /*
          * Find the work order
          */
         $workOrder = $this->workOrder->find($this->getInput('work_order_id'));
         /*
          * Set the insert data for the work order report
          */
         $insert = ['user_id' => $this->sentry->getCurrentUserId(), 'work_order_id' => $workOrder->id, 'description' => $this->getInput('description', null, true)];
         /*
          * Create the work order report
          */
         $record = $this->model->create($insert);
         /*
          * Get the current time to update the work order
          */
         $now = Carbon::now()->toDateTimeString();
         /*
          * Update the work order with the completed at time since a work order
          * would be complete once a report has been filled out. If a started_at time exists
          * then we'll throw null inside so it isn't updated, otherwise we'll throw in today's time
          */
         $update = ['started_at' => $workOrder->started_at ? null : $now, 'completed_at' => $now];
         /*
          * Update the work order
          */
         $workOrder = $this->workOrder->setInput($update)->update($workOrder->id);
         /*
          * Close any open sessions that may be open on the work order
          */
         $workOrder->closeSessions();
         /*
          * Fire the work order report created event
          */
         $this->fireEvent('maintenance.work-orders.reports.created', ['report' => $record]);
         /*
          * Commit the database transaction
          */
         $this->dbCommitTransaction();
         /*
          * Return the created report
          */
         return $record;
     } catch (\Exception $e) {
         $this->dbRollbackTransaction();
         return false;
     }
 }
Esempio n. 6
0
 /**
  * Deletes a work order update.
  *
  * @param string|int $workOrderId
  * @param string|int $updateId
  *
  * @return \Illuminate\Http\JsonResponse|mixed
  */
 public function destroy($workOrderId, $updateId)
 {
     $workOrder = $this->workOrder->find($workOrderId);
     if ($this->update->destroy($updateId)) {
         $this->message = 'Successfully deleted update';
         $this->messageType = 'success';
         $this->redirect = route('maintenance.work-orders.show', [$workOrder->id, '#tab_updates']);
     } else {
         $this->message = 'There was an error trying to delete this update. Please try again.';
         $this->messageType = 'danger';
         $this->redirect = route('maintenance.work-orders.show', [$workOrder->id, '#tab_updates']);
     }
     return $this->response();
 }
 /**
  * Updates the specified notification for the specified work order.
  *
  * @param string|int $workOrderId
  * @param string|int $notificationId
  *
  * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
  */
 public function update($workOrderId, $notificationId)
 {
     if ($this->workOrderNotificationValidator->passes()) {
         $workOrder = $this->workOrder->find($workOrderId);
         $notifications = $this->workOrderNotification->find($notificationId);
         $data = $this->inputAll();
         $data['work_order_id'] = $workOrder->id;
         $this->workOrderNotification->setInput($data)->update($notifications->id);
         $this->message = 'Successfully updated notifications';
         $this->messageType = 'success';
         $this->redirect = route('maintenance.work-orders.show', [$workOrder->id]);
     } else {
         $this->errors = $this->workOrderNotificationValidator->getErrors();
         $this->redirect = route('maintenance.work-orders.show', [$workOrderId]);
     }
     return $this->response();
 }
 /**
  * Assigns workers to the specified work order ID.
  *
  * @param string|int $workOrder_id
  *
  * @return \Illuminate\Http\JsonResponse|\Illuminate\Http\RedirectResponse
  */
 public function store($workOrder_id)
 {
     if ($this->assignmentValidator->passes()) {
         $workOrder = $this->workOrder->find($workOrder_id);
         $data = $this->inputAll();
         $data['work_order_id'] = $workOrder->id;
         $records = $this->assignment->setInput($data)->create();
         if ($records) {
             $this->message = 'Successfully assigned worker(s)';
             $this->messageType = 'success';
             $this->redirect = route('maintenance.work-orders.show', [$workOrder->id]);
         } else {
             $this->message = 'There was an error trying to assign workers to this work order. Please try again.';
             $this->messageType = 'danger';
             $this->redirect = route('maintenance.work-orders.show', [$workOrder->id]);
         }
     } else {
         $this->errors = $this->assignmentValidator->getErrors();
         $this->redirect = route('maintenance.work-orders.show', [$workOrder_id]);
     }
     return $this->response();
 }
 /**
  * Creates a work request.
  *
  * @return bool|WorkRequest
  */
 public function create()
 {
     $this->dbStartTransaction();
     try {
         $workRequest = new $this->model();
         $workRequest->user_id = $this->sentry->getCurrentUserId();
         $workRequest->subject = $this->getInput('subject', null, true);
         $workRequest->best_time = $this->getInput('best_time', null, true);
         $workRequest->description = $this->getInput('description', null, true);
         if ($workRequest->save()) {
             $autoGenerate = $this->config->setPrefix('maintenance')->get('rules.work-orders.auto_generate_from_request', true);
             if ($autoGenerate) {
                 $this->workOrder->createFromWorkRequest($workRequest);
             }
             $this->dbCommitTransaction();
             return $workRequest;
         }
     } catch (\Exception $e) {
         $this->dbRollbackTransaction();
     }
     return false;
 }
 /**
  * @param $view
  *
  * @return mixed
  */
 public function compose(View $view)
 {
     $allWorkOrders = $this->workOrder->get()->lists('subject', 'id');
     return $view->with('allWorkOrders', $allWorkOrders);
 }