/**
  * Creates a new inventory stock record.
  *
  * @return bool|static
  */
 public function create()
 {
     $this->dbStartTransaction();
     try {
         $insert = ['user_id' => $this->sentry->getCurrentUserId(), 'stock_id' => $this->getInput('stock_id'), 'before' => $this->getInput('before'), 'after' => $this->getInput('after'), 'cost' => $this->getInput('cost'), 'reason' => $this->getInput('reason', 'Stock Adjustment', true)];
         /*
          * Only create a record if the before and after quantity differ
          * if enabled in config
          */
         if ($this->config->setPrefix('inventory')->get('allow_duplicate_movements')) {
             if ($insert['before'] != $insert['after']) {
                 $record = $this->model->create($insert);
                 $this->dbCommitTransaction();
                 return $record;
             } else {
                 /*
                  * Return true if before and after quantity are the same
                  * and prevent duplicate movements is enabled
                  */
                 return true;
             }
         } else {
             /*
              * Prevent duplicate movements is disabled, create the record
              */
             $record = $this->model->create($insert);
             $this->dbCommitTransaction();
             return $record;
         }
     } catch (\Exception $e) {
         $this->dbRollbackTransaction();
     }
     return false;
 }
Пример #2
0
 /**
  * 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;
 }
Пример #3
0
 /**
  * Creates a new status.
  *
  * @param StatusRequest $request
  *
  * @return bool|Status
  */
 public function create(StatusRequest $request)
 {
     $status = $this->model();
     $status->user_id = $this->sentry->getCurrentUserId();
     $status->name = $request->input('name');
     $status->color = $request->input('color');
     if ($status->save()) {
         return $status;
     }
     return false;
 }
Пример #4
0
 /**
  * Creates a new status.
  *
  * @param PriorityRequest $request
  *
  * @return bool|Priority
  */
 public function create(PriorityRequest $request)
 {
     $priority = $this->model();
     $priority->user_id = $this->sentry->getCurrentUserId();
     $priority->name = $request->input('name');
     $priority->color = $request->input('color');
     if ($priority->save()) {
         return $priority;
     }
     return false;
 }
Пример #5
0
 /**
  * Creates a new work order report.
  *
  * @param ReportRequest $request
  * @param int|string    $workOrderId
  *
  * @return bool|WorkOrderReport
  */
 public function create(ReportRequest $request, $workOrderId)
 {
     $report = $this->model();
     $report->user_id = $this->sentry->getCurrentUserId();
     $report->work_order_id = $workOrderId;
     $report->description = $request->clean($request->input('description'));
     if ($report->save()) {
         return $report;
     }
     return false;
 }
Пример #6
0
 /**
  * Creates a new metric.
  *
  * @param MetricRequest $request
  *
  * @return bool|Metric
  */
 public function create(MetricRequest $request)
 {
     $metric = $this->model();
     $metric->name = $request->input('name');
     $metric->symbol = $request->input('symbol');
     $metric->user_id = $this->sentry->getCurrentUserId();
     if ($metric->save()) {
         return $metric;
     }
     return false;
 }
Пример #7
0
 /**
  * Creates a notification record for a user
  * indicating what they would like to be notified
  * about.
  *
  * @return bool|static
  */
 public function create()
 {
     $this->dbStartTransaction();
     try {
         $insert = ['user_id' => $this->sentry->getCurrentUserId(), 'work_order_id' => $this->getInput('work_order_id'), 'status' => $this->getInput('status', 0), 'priority' => $this->getInput('priority', 0), 'parts' => $this->getInput('parts', 0), 'customer_updates' => $this->getInput('customer_updates', 0), 'technician_updates' => $this->getInput('technician_updates', 0), 'completion_report' => $this->getInput('completion_report', 0)];
         $record = $this->model->create($insert);
         $this->dbCommitTransaction();
         return $record;
     } catch (\Exception $e) {
         $this->dbRollbackTransaction();
         return false;
     }
 }
Пример #8
0
 public function create()
 {
     $this->dbStartTransaction();
     try {
         $insert = ['user_id' => $this->sentry->getCurrentUserId(), 'name' => $this->getInput('name'), 'color' => $this->getInput('color')];
         $record = $this->model->create($insert);
         $this->dbCommitTransaction();
         return $record;
     } catch (\Exception $e) {
         $this->dbRollbackTransaction();
         return false;
     }
 }
Пример #9
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;
     }
 }
Пример #10
0
 /**
  * Updates an asset meter.
  *
  * @param MeterRequest $request
  * @param int|string   $id
  * @param int|string   $meterId
  *
  * @return bool|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|null
  */
 public function update(MeterRequest $request, $id, $meterId)
 {
     $asset = $this->asset->model()->findOrFail($id);
     $meter = $asset->meters()->findOrFail($meterId);
     if ($meter) {
         $meter->metric_id = $request->input('metric');
         $meter->name = $request->input('name');
         if ($meter->save()) {
             $reading = ['user_id' => $this->sentry->getCurrentUserId(), 'reading' => $request->input('reading'), 'comment' => $request->input('comment')];
             $meter->readings()->create($reading);
             return $meter;
         }
     }
     return false;
 }
Пример #11
0
 /**
  * Creates a note.
  *
  * @return bool|static
  */
 public function create()
 {
     $this->dbStartTransaction();
     try {
         $insert = ['user_id' => $this->sentry->getCurrentUserId(), 'content' => $this->getInput('content', null, true)];
         $record = $this->model->create($insert);
         if ($record) {
             $this->dbCommitTransaction();
             return $record;
         }
     } catch (\Exception $e) {
         $this->dbRollbackTransaction();
     }
     return false;
 }
Пример #12
0
 /**
  * Creates an asset.
  *
  * @return bool|Asset
  */
 public function create()
 {
     $this->dbStartTransaction();
     try {
         /*
          * Set insert data
          */
         $insert = ['user_id' => $this->sentry->getCurrentUserId(), 'category_id' => $this->getInput('category_id'), 'location_id' => $this->getInput('location_id'), 'name' => $this->getInput('name', null, true), 'condition' => $this->getInput('condition'), 'vendor' => $this->getInput('vendor', null, true), 'make' => $this->getInput('make', null, true), 'model' => $this->getInput('model', null, true), 'size' => $this->getInput('size', null, true), 'weight' => $this->getInput('weight', null, true), 'serial' => $this->getInput('serial', null, true), 'acquired_at' => $this->formatDateWithTime($this->getInput('acquired_at')), 'end_of_life' => $this->formatDateWithTime($this->getInput('end_of_life'))];
         /*
          * Create the record and return it upon success
          */
         $record = $this->model->create($insert);
         if ($record) {
             $this->fireEvent('maintenance.assets.created', ['asset' => $record]);
             $this->dbCommitTransaction();
             return $record;
         }
         $this->dbRollbackTransaction();
         /*
          * Failed to create record, return false
          */
         return false;
     } catch (\Exception $e) {
         $this->dbRollbackTransaction();
         return false;
     }
 }
Пример #13
0
 /**
  * Creates a new work request.
  *
  * @param Request $request
  *
  * @return bool|WorkRequest
  */
 public function create(Request $request)
 {
     $workRequest = $this->model();
     $workRequest->user_id = $this->sentry->getCurrentUserId();
     $workRequest->subject = $request->input('subject');
     $workRequest->best_time = $request->input('best_time');
     $workRequest->description = $request->clean($request->input('description'));
     if ($workRequest->save()) {
         $autoGenerate = $this->config->setPrefix('maintenance')->get('rules.work-orders.auto_generate_from_request', true);
         if ($autoGenerate) {
             $this->workOrder->createFromWorkRequest($workRequest);
         }
         return $workRequest;
     }
     return false;
 }
Пример #14
0
 /**
  * Creates a new Asset.
  *
  * @param Request $request
  *
  * @return bool|Asset
  */
 public function create(Request $request)
 {
     $asset = $this->model();
     $asset->user_id = $this->sentry->getCurrentUserId();
     $asset->location_id = $request->input('location_id');
     $asset->category_id = $request->input('category_id');
     $asset->tag = $request->input('tag');
     $asset->name = $request->input('name');
     $asset->description = $request->clean($request->input('description'));
     $asset->condition = $request->input('condition');
     $asset->size = $request->input('size');
     $asset->weight = $request->input('weight');
     $asset->vendor = $request->input('vendor');
     $asset->make = $request->input('make');
     $asset->model = $request->input('model');
     $asset->serial = $request->input('serial');
     $asset->price = $request->input('price');
     if ($request->input('acquired_at')) {
         $asset->acquired_at = $this->strToDate($request->input('acquired_at'));
     }
     if ($request->input('end_of_life')) {
         $asset->end_of_life = $this->strToDate($request->input('end_of_life'));
     }
     if ($asset->save()) {
         return $asset;
     }
     return false;
 }
Пример #15
0
 /**
  * Creates a work order.
  *
  * @return \Stevebauman\Maintenance\Models\WorkOrder|bool
  */
 public function create()
 {
     $this->dbStartTransaction();
     try {
         $insert = ['user_id' => $this->sentry->getCurrentUserId(), 'category_id' => $this->getInput('category_id'), 'location_id' => $this->getInput('location_id'), 'status_id' => $this->getInput('status'), 'priority_id' => $this->getInput('priority'), 'subject' => $this->getInput('subject', null, true), 'description' => $this->getInput('description', null, true), 'started_at' => $this->getInput('started_at'), 'completed_at' => $this->getInput('completed_at')];
         $record = $this->model->create($insert);
         $assets = $this->getInput('assets');
         if ($assets) {
             $record->assets()->attach($assets);
         }
         $this->fireEvent('maintenance.work-orders.created', ['workOrder' => $record]);
         $this->dbCommitTransaction();
         return $record;
     } catch (\Exception $e) {
         $this->dbRollbackTransaction();
     }
     return false;
 }
Пример #16
0
 /**
  * Creates a note for the specified inventory.
  *
  * @param NoteRequest $request
  * @param int|string  $id
  *
  * @return bool|\Stevebauman\Maintenance\Models\Note;
  */
 public function createNote(NoteRequest $request, $id)
 {
     $inventory = $this->model()->findOrFail($id);
     $attributes = ['user_id' => $this->sentry->getCurrentUserId(), 'content' => $request->clean($request->input('content'))];
     $note = $inventory->notes()->create($attributes);
     if ($note) {
         return $note;
     }
     return false;
 }
Пример #17
0
 /**
  * Creates an item record.
  *
  * @return Inventory
  */
 public function create()
 {
     $this->dbStartTransaction();
     try {
         // Set insert data
         $insert = ['category_id' => $this->getInput('category_id'), 'user_id' => $this->sentry->getCurrentUserId(), 'metric_id' => $this->getInput('metric'), 'name' => $this->getInput('name', null, true), 'description' => $this->getInput('description', null, true)];
         // If the record is created, return it, otherwise return false
         $record = $this->model->create($insert);
         if ($record) {
             // Fire created event
             $this->fireEvent('maintenance.inventory.created', ['item' => $record]);
             $this->dbCommitTransaction();
             return $record;
         }
     } catch (\Exception $e) {
         $this->dbRollbackTransaction();
     }
     return false;
 }
Пример #18
0
 /**
  * @return array|bool
  */
 public function create()
 {
     $this->dbStartTransaction();
     try {
         $users = $this->getInput('users');
         if ($users) {
             $records = [];
             foreach ($users as $user) {
                 $insert = ['work_order_id' => $this->getInput('work_order_id'), 'by_user_id' => $this->sentry->getCurrentUserId(), 'to_user_id' => $user];
                 $records[] = $this->model->create($insert);
             }
             $this->dbCommitTransaction();
             return $records;
         }
         return false;
     } catch (\Exception $e) {
         $this->dbRollbackTransaction();
         return false;
     }
 }
Пример #19
0
 /**
  * Updates a work order session.
  *
  * @param int|string $workOrderId
  *
  * @return bool|WorkOrderSession
  */
 public function update($workOrderId)
 {
     $session = $this->workOrder->findLastUserSession($workOrderId);
     if ($session && $session->user_id === $this->sentry->getCurrentUserId()) {
         $now = Carbon::now()->toDateTimeString();
         $session->out = $now;
         if ($session->save()) {
             return $session;
         }
     }
     return false;
 }
Пример #20
0
 /**
  * Creates a new report for the specified event.
  *
  * @param ReportRequest $request
  * @param int|string $id
  *
  * @return bool
  */
 public function createReport(ReportRequest $request, $id)
 {
     $event = $this->find($id);
     if ($event) {
         $insert = ['user_id' => $this->sentry->getCurrentUserId(), 'description' => $request->clean($request->input('description'))];
         $report = $event->report()->create($insert);
         if ($report) {
             return $report;
         }
     }
     return false;
 }
Пример #21
0
 /**
  * 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;
 }
Пример #22
0
 /**
  * Updates the specified work order session.
  *
  * @param int|string $id
  *
  * @return bool|WorkOrderSession
  */
 public function update($id)
 {
     $this->dbStartTransaction();
     $record = $this->find($id);
     // Validate that the current user is the session holder
     if ($record->user_id === $this->sentry->getCurrentUserId()) {
         try {
             $insert = ['out' => Carbon::now()->toDateTimeString()];
             if ($record->update($insert)) {
                 $this->dbCommitTransaction();
                 return $record;
             }
         } catch (\Exception $e) {
             $this->dbRollbackTransaction();
         }
     }
     return false;
 }
Пример #23
0
 /**
  * Creates a new work order.
  *
  * @param Request $request
  *
  * @return bool|WorkOrder
  */
 public function create(Request $request)
 {
     $workOrder = $this->model();
     $workOrder->category_id = $request->input('category_id');
     $workOrder->location_id = $request->input('location_id');
     $workOrder->status_id = $request->input('status', $this->status->createDefaultRequested()->getKey());
     $workOrder->priority_id = $request->input('priority', $this->priority->createDefaultRequested()->getKey());
     $workOrder->user_id = $this->sentry->getCurrentUserId();
     $workOrder->subject = $request->input('subject');
     $workOrder->description = $request->clean($request->input('description'));
     $workOrder->started_at = $request->input('started_at');
     $workOrder->completed_at = $request->input('completed_at');
     if ($workOrder->save()) {
         $assets = $request->input('assets');
         if (count($assets) > 0) {
             $workOrder->assets()->sync($assets);
         }
         return $workOrder;
     }
     return false;
 }
Пример #24
0
 /**
  * Creates a google event and then creates a local database record
  * attaching it to whatever created it along with inserting
  * the google event ID.
  *
  * @return mixed
  */
 public function create()
 {
     $data = $this->input;
     /*
      * Find the location and pass the trail into the
      * google event service so it can be seen on google calendar
      */
     if ($this->getInput('location_id')) {
         $location = $this->location->find($this->getInput('location_id'));
         $location_id = $location->id;
         /*
          * Were stripping the tags from the trial because it contains HTML formatting,
          * and google does not display HTML formatting on their calendar
          */
         $data['location'] = strip_tags($location->trail);
     } else {
         // No location was given, set it to null
         $location_id = null;
     }
     /*
      * Pass the input along to the google
      * event service and create google event
      */
     $event = $this->eventApi->setInput($data)->create();
     /*
      * If the event was created successfully, we now have to attach
      * the specified assets / inventories / work orders to the event
      */
     if ($event) {
         // Create the main event
         $insert = ['user_id' => $this->sentry->getCurrentUserId(), 'location_id' => $location_id, 'api_id' => $event->id];
         $this->model->create($insert);
         return $event;
     }
     return false;
 }
 /**
  * @param $view
  */
 public function compose(View $view)
 {
     $notifications = $this->notification->where('user_id', $this->sentry->getCurrentUserId())->where('read', 0)->orderBy('created_at', 'DESC')->get();
     $view->with('notifications', $notifications);
 }