public function destroyPhoto($equipmentId, $photoId)
 {
     $equipment = $this->equipmentRepository->findBySlug($equipmentId);
     $photo = $equipment->photos[$photoId];
     $equipment->removePhoto($photoId);
     Storage::delete($equipment->getPhotoBasePath() . $photo['path']);
     \Notification::success("Image deleted");
     return \Redirect::route('equipment.edit', $equipmentId);
 }
 /**
  * Store a manual payment
  *
  * @param $userId
  * @throws \BB\Exceptions\AuthenticationException
  * @throws \BB\Exceptions\FormValidationException
  * @throws \BB\Exceptions\NotImplementedException
  * @return Illuminate\Http\RedirectResponse
  * @deprecated
  */
 public function store($userId)
 {
     $user = User::findWithPermission($userId);
     if (!\Auth::user()->hasRole('admin') && !\Auth::user()->hasRole('finance')) {
         throw new \BB\Exceptions\AuthenticationException();
     }
     \Log::debug('Manual payment endpoint getting hit. account/{id}/payment. paymentController@store ' . json_encode(\Input::all()));
     $reason = \Input::get('reason');
     if ($reason == 'subscription') {
         $payment = new Payment(['reason' => $reason, 'source' => \Input::get('source'), 'source_id' => '', 'amount' => $user->monthly_subscription, 'amount_minus_fee' => $user->monthly_subscription, 'status' => 'paid']);
         $user->payments()->save($payment);
         $user->extendMembership(\Input::get('source'), \Carbon\Carbon::now()->addMonth());
     } elseif ($reason == 'induction') {
         if (\Input::get('source') == 'manual') {
             $ref = \Input::get('induction_key');
             ($item = $this->equipmentRepository->findBySlug($ref)) || App::abort(404);
             $payment = new Payment(['reason' => $reason, 'source' => 'manual', 'source_id' => '', 'amount' => $item->cost, 'amount_minus_fee' => $item->cost, 'status' => 'paid']);
             $payment = $user->payments()->save($payment);
             Induction::create(['user_id' => $user->id, 'key' => $ref, 'paid' => true, 'payment_id' => $payment->id]);
         } else {
             throw new \BB\Exceptions\NotImplementedException();
         }
     } elseif ($reason == 'door-key') {
         $payment = new Payment(['reason' => $reason, 'source' => \Input::get('source'), 'source_id' => '', 'amount' => 10, 'amount_minus_fee' => 10, 'status' => 'paid']);
         $user->payments()->save($payment);
         $user->key_deposit_payment_id = $payment->id;
         $user->save();
     } elseif ($reason == 'storage-box') {
         $payment = new Payment(['reason' => $reason, 'source' => \Input::get('source'), 'source_id' => '', 'amount' => 5, 'amount_minus_fee' => 5, 'status' => 'paid']);
         $user->payments()->save($payment);
         $user->storage_box_payment_id = $payment->id;
         $user->save();
     } elseif ($reason == 'balance') {
         $amount = \Input::get('amount') * 1;
         //convert the users amount into a number
         if (!is_numeric($amount)) {
             $exceptionErrors = new \Illuminate\Support\MessageBag(['amount' => 'Invalid amount']);
             throw new \BB\Exceptions\FormValidationException('Not a valid amount', $exceptionErrors);
         }
         $payment = new Payment(['reason' => 'balance', 'source' => \Input::get('source'), 'source_id' => '', 'amount' => $amount, 'amount_minus_fee' => $amount, 'status' => 'paid']);
         $user->payments()->save($payment);
         $memberCreditService = \App::make('\\BB\\Services\\Credit');
         $memberCreditService->setUserId($user->id);
         $memberCreditService->recalculate();
         //This needs to be improved
         \Notification::success('Payment recorded');
         return \Redirect::route('account.bbcredit.index', $user->id);
     } else {
         throw new \BB\Exceptions\NotImplementedException();
     }
     \Notification::success('Payment recorded');
     return \Redirect::route('account.show', [$user->id]);
 }
 public function calculatePendingFees()
 {
     $records = $this->equipmentLogRepository->getFinishedUnbilledRecords();
     foreach ($records as $record) {
         $equipment = $this->equipmentRepository->findBySlug($record->device);
         if ($equipment->hasUsageCharge()) {
             $feePerSecond = $this->costPerSecond($equipment->usageCost);
             //How may seconds was the device in use
             $secondsActive = $record->finished->diffInSeconds($record->started);
             //Charges are for a minimum of 15 minutes
             $secondsActive = $this->roundUpSecondsActive($secondsActive);
             $incurredFee = $this->sessionFee($feePerSecond, $secondsActive);
             //If the reason is empty then its not a special case and should be billed
             if (empty($record->reason)) {
                 //Create a payment against the user
                 $this->paymentRepository->recordPayment('equipment-fee', $record->user_id, 'balance', '', $incurredFee, 'paid', 0, $record->id . ':' . $record->device);
             }
         }
         //Mark this log as being billed and complete
         $record->billed = true;
         $record->save();
     }
 }
 /**
  * Display the specified resource.
  *
  * @param  int  $id
  * @return Response
  */
 public function show($id)
 {
     $user = User::findWithPermission($id);
     $inductions = $this->equipmentRepository->getRequiresInduction();
     $userInductions = $user->inductions()->get();
     foreach ($inductions as $i => $induction) {
         $inductions[$i]->userInduction = false;
         foreach ($userInductions as $userInduction) {
             if ($userInduction->key == $induction->induction_category) {
                 $inductions[$i]->userInduction = $userInduction;
             }
         }
     }
     //get pending address if any
     $newAddress = $this->addressRepository->getNewUserAddress($id);
     //Get the member subscription payments
     $subscriptionCharges = $this->subscriptionChargeRepository->getMemberChargesPaginated($id);
     return \View::make('account.show')->with('user', $user)->with('inductions', $inductions)->with('newAddress', $newAddress)->with('subscriptionCharges', $subscriptionCharges);
 }