|
1
|
|
|
<?php namespace BB\Http\Controllers; |
|
2
|
|
|
|
|
3
|
|
|
use BB\Entities\User; |
|
4
|
|
|
use BB\Exceptions\AuthenticationException; |
|
5
|
|
|
use BB\Exceptions\ValidationException; |
|
6
|
|
|
use BB\Repo\PaymentRepository; |
|
7
|
|
|
use Illuminate\Http\Request; |
|
8
|
|
|
|
|
9
|
|
|
class BalanceController extends Controller |
|
10
|
|
|
{ |
|
11
|
|
|
|
|
12
|
|
|
/** |
|
13
|
|
|
* @var \BB\Repo\UserRepository |
|
14
|
|
|
*/ |
|
15
|
|
|
private $userRepository; |
|
16
|
|
|
/** |
|
17
|
|
|
* @var \BB\Services\Credit |
|
18
|
|
|
*/ |
|
19
|
|
|
private $bbCredit; |
|
20
|
|
|
/** |
|
21
|
|
|
* @var PaymentRepository |
|
22
|
|
|
*/ |
|
23
|
|
|
private $paymentRepository; |
|
24
|
|
|
|
|
25
|
|
|
public function __construct(\BB\Repo\UserRepository $userRepository, \BB\Services\Credit $bbCredit, PaymentRepository $paymentRepository) |
|
26
|
|
|
{ |
|
27
|
|
|
$this->userRepository = $userRepository; |
|
28
|
|
|
$this->bbCredit = $bbCredit; |
|
29
|
|
|
$this->paymentRepository = $paymentRepository; |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
public function index($userId) |
|
33
|
|
|
{ |
|
34
|
|
|
//Verify the user can access this user record |
|
35
|
|
|
$user = User::findWithPermission($userId); |
|
36
|
|
|
$this->bbCredit->setUserId($user->id); |
|
37
|
|
|
|
|
38
|
|
|
$userBalance = $this->bbCredit->getBalanceFormatted(); |
|
39
|
|
|
|
|
40
|
|
|
$payments = $this->bbCredit->getBalancePaymentsPaginated(); |
|
41
|
|
|
|
|
42
|
|
|
$memberList = $this->userRepository->getAllAsDropdown(); |
|
43
|
|
|
|
|
44
|
|
|
return \View::make('account.bbcredit.index') |
|
45
|
|
|
->with('user', $user) |
|
46
|
|
|
->with('payments', $payments) |
|
47
|
|
|
->with('userBalance', $userBalance) |
|
48
|
|
|
->with('memberList', $memberList); |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* This is a basic method for recording a payment transfer between two people |
|
53
|
|
|
* This should not exist and the normal balance payment controller should be used |
|
54
|
|
|
* If any more work is needed here please take the time and move it over! |
|
55
|
|
|
* |
|
56
|
|
|
* @param Request $request |
|
57
|
|
|
* @param integer $userId |
|
58
|
|
|
* |
|
59
|
|
|
* @return mixed |
|
60
|
|
|
* @throws ValidationException |
|
61
|
|
|
* @throws AuthenticationException |
|
62
|
|
|
*/ |
|
63
|
|
|
public function recordTransfer(Request $request, $userId) |
|
64
|
|
|
{ |
|
65
|
|
|
$user = User::findWithPermission($userId); |
|
66
|
|
|
$this->bbCredit->setUserId($user->id); |
|
67
|
|
|
|
|
68
|
|
|
$amount = $request->get('amount'); |
|
69
|
|
|
$targetUserId = $request->get('target_user_id'); |
|
70
|
|
|
$targetUser = $this->userRepository->getById($targetUserId); |
|
71
|
|
|
|
|
72
|
|
|
if ($targetUserId === $userId) { |
|
73
|
|
|
throw new ValidationException('Your\'e trying to send money to yourself, no!'); |
|
74
|
|
|
} |
|
75
|
|
|
|
|
76
|
|
|
//What is the users balance |
|
77
|
|
|
$userBalance = $this->bbCredit->getBalance(); |
|
78
|
|
|
|
|
79
|
|
|
//With this payment will the users balance go to low? |
|
80
|
|
|
if (($userBalance - $amount) < 0) { |
|
81
|
|
|
|
|
82
|
|
|
\Notification::error("You don't have the money for this"); |
|
83
|
|
|
return \Redirect::route('account.balance.index', $user->id); |
|
|
|
|
|
|
84
|
|
|
} |
|
85
|
|
|
|
|
86
|
|
|
$this->paymentRepository->recordBalanceTransfer($user->id, $targetUser->id, $amount); |
|
87
|
|
|
|
|
88
|
|
|
\Notification::success("Transfer made"); |
|
|
|
|
|
|
89
|
|
|
return \Redirect::route('account.balance.index', $user->id); |
|
|
|
|
|
|
90
|
|
|
} |
|
91
|
|
|
|
|
92
|
|
|
} |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.