Skip to content

Commit

Permalink
check account currency
Browse files Browse the repository at this point in the history
  • Loading branch information
denisdulici committed Nov 29, 2018
1 parent 9934ebd commit 8467209
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 4 deletions.
13 changes: 10 additions & 3 deletions app/Http/Controllers/Banking/Accounts.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,8 +98,15 @@ public function edit(Account $account)
*/
public function update(Account $account, Request $request)
{
// Check if we can disable it
if (!$request['enabled']) {
// Check if we can disable or change the code
if (!$request['enabled'] || ($account->currency_code != $request['currency_code'])) {
$relationships = $this->countRelationships($account, [
'invoice_payments' => 'invoices',
'revenues' => 'revenues',
'bill_payments' => 'bills',
'payments' => 'payments',
]);

if ($account->id == setting('general.default_account')) {
$relationships[] = strtolower(trans_choice('general.companies', 1));
}
Expand All @@ -120,7 +127,7 @@ public function update(Account $account, Request $request)

return redirect('banking/accounts');
} else {
$message = trans('messages.warning.disabled', ['name' => $account->name, 'text' => implode(', ', $relationships)]);
$message = trans('messages.warning.disable_code', ['name' => $account->name, 'text' => implode(', ', $relationships)]);

flash($message)->warning();

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Settings/Currencies.php
Original file line number Diff line number Diff line change
Expand Up @@ -162,7 +162,7 @@ public function update(Currency $currency, Request $request)

return redirect('settings/currencies');
} else {
$message = trans('messages.warning.disabled', ['name' => $currency->name, 'text' => implode(', ', $relationships)]);
$message = trans('messages.warning.disable_code', ['name' => $currency->name, 'text' => implode(', ', $relationships)]);

flash($message)->warning();

Expand Down
3 changes: 3 additions & 0 deletions resources/lang/en-GB/messages.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
'enabled' => ':type enabled!',
'disabled' => ':type disabled!',
],

'error' => [
'over_payment' => 'Error: Payment not added! The amount you entered passes the total: :amount',
'not_user_company' => 'Error: You are not allowed to manage this company!',
Expand All @@ -21,9 +22,11 @@
'import_column' => 'Error: :message Sheet name: :sheet. Line number: :line.',
'import_sheet' => 'Error: Sheet name is not valid. Please, check the sample file.',
],

'warning' => [
'deleted' => 'Warning: You are not allowed to delete <b>:name</b> because it has :text related.',
'disabled' => 'Warning: You are not allowed to disable <b>:name</b> because it has :text related.',
'disable_code' => 'Warning: You are not allowed to disable or change the currency of <b>:name</b> because it has :text related.',
],

];

0 comments on commit 8467209

Please sign in to comment.