public function update($logEntryId) { $reason = \Request::get('reason'); if (!in_array($reason, ['training', 'testing'])) { throw new \BB\Exceptions\ValidationException("Not a valid reason"); } $equipmentLog = $this->equipmentLogRepository->getById($logEntryId); /* if ($equipmentLog->user_id == \Auth::user()->id) { throw new \BB\Exceptions\ValidationException("You can't update your own record"); } */ if (!\Auth::user()->hasRole($equipmentLog->device) && !\Auth::user()->isAdmin()) { throw new \BB\Exceptions\ValidationException("You don't have permission to alter this record"); } if (!empty($equipmentLog->reason)) { throw new \BB\Exceptions\ValidationException("Reason already set"); } $billedStatus = $equipmentLog->billed; if ($equipmentLog->billed) { //the user has been billed, we need to undo this. $payments = $this->paymentRepository->getPaymentsByReference($equipmentLog->id . ':' . $equipmentLog->device); if ($payments->count() == 1) { $this->paymentRepository->delete($payments->first()->id); $billedStatus = false; } else { throw new \BB\Exceptions\ValidationException("Unable to locate related payment, please contact an admin"); } } $this->equipmentLogRepository->update($logEntryId, ['reason' => $reason, 'billed' => $billedStatus]); \Notification::success("Record Updated"); return \Redirect::back(); }
/** * Remove the specified payment * * @param int $id * @return Illuminate\Http\RedirectResponse * @throws \BB\Exceptions\ValidationException */ public function destroy($id) { $payment = $this->paymentRepository->getById($id); //we can only allow some records to get deleted, only cash payments can be removed, everything else must be refunded off if ($payment->source != 'cash') { throw new \BB\Exceptions\ValidationException('Only cash payments can be deleted'); } if ($payment->reason != 'balance') { throw new \BB\Exceptions\ValidationException('Currently only payments to the members balance can be deleted'); } //The delete event will broadcast an event and allow related actions to occur $this->paymentRepository->delete($id); \Notification::success('Payment deleted'); return \Redirect::back(); }