diff --git a/app/Http/Controllers/Banking/Accounts.php b/app/Http/Controllers/Banking/Accounts.php
index 51dc40d81..3ed5689c8 100644
--- a/app/Http/Controllers/Banking/Accounts.php
+++ b/app/Http/Controllers/Banking/Accounts.php
@@ -9,6 +9,7 @@ use App\Jobs\Banking\DeleteAccount;
use App\Jobs\Banking\UpdateAccount;
use App\Models\Banking\Account;
use App\Models\Banking\Transaction;
+use App\Models\Banking\Transfer;
use App\Models\Setting\Currency;
class Accounts extends Controller
@@ -32,16 +33,25 @@ class Accounts extends Controller
*/
public function show(Account $account)
{
- $amounts = [
- 'incoming' => 0,
- 'outgoing' => 0,
- 'balance' => 0,
- ];
+ $limit = (int) request('limit', setting('default.list_limit', '25'));
- $transactions = $account->transactions;
+ // Handle transactions
+ $transactions = Transaction::with('account', 'category')->where('account_id', $account->id)->collect('paid_at');
- return view('banking.accounts.show', compact('account', 'amounts', 'transactions'));
-
+ $transfers = Transfer::with('transaction')->all()->filter(function ($transfer) use($account) {
+ if ($transfer->expense_account->id == $account->id || $transfer->income_account->id == $account->id) {
+ return true;
+ }
+
+ return false;
+ })->sortByDesc(function ($transfer) {
+ return $transfer->expense_transaction->paid_at;
+ });
+
+ $limit = (int) request('limit', setting('default.list_limit', '25'));
+ $transfers = $this->paginate($transfers, $limit);
+
+ return view('banking.accounts.show', compact('account', 'transactions', 'transfers'));
}
/**
* Show the form for creating a new resource.
diff --git a/app/Models/Banking/Account.php b/app/Models/Banking/Account.php
index e3019e296..41199c0f1 100644
--- a/app/Models/Banking/Account.php
+++ b/app/Models/Banking/Account.php
@@ -93,6 +93,41 @@ class Account extends Model
return $total;
}
+ /**
+ * Get the current balance.
+ *
+ * @return string
+ */
+ public function getIncomeBalanceAttribute()
+ {
+ // Opening Balance
+ //$total = $this->opening_balance;
+ $total = 0;
+
+ // Sum Incomes
+ $total += $this->income_transactions->sum('amount');
+
+ return $total;
+ }
+
+ /**
+ * Get the current balance.
+ *
+ * @return string
+ */
+ public function getExpenseBalanceAttribute()
+ {
+ // Opening Balance
+ //$total = $this->opening_balance;
+ $total = 0;
+
+ // Subtract Expenses
+ $total += $this->expense_transactions->sum('amount');
+
+ return $total;
+ }
+
+
/**
* Create a new factory instance for the model.
*
diff --git a/resources/assets/js/views/banking/accounts.js b/resources/assets/js/views/banking/accounts.js
index 4b566ddee..2adf76615 100644
--- a/resources/assets/js/views/banking/accounts.js
+++ b/resources/assets/js/views/banking/accounts.js
@@ -29,46 +29,6 @@ const app = new Vue({
return {
form: new Form('account'),
bulk_action: new BulkAction('accounts'),
- template: {
- modal: false,
- title: '',
- message: '',
- html: '',
- errors: new Error()
- },
}
},
-
- methods: {
- onTemplate() {
- this.template.modal = true;
-
- this.transfer_form = new Form('template');
-
- this.transfer_form.template = this.transfer_form._template;
- },
-
- addTemplate() {
- if (this.transfer_form.template != 1) {
-
- this.transfer_form.submit();
-
- this.template.errors = this.transfer_form.errors;
- }
-
- this.form.loading = true;
-
- this.$emit("confirm");
- },
-
- closeTemplate() {
- this.template = {
- modal: false,
- title: '',
- message: '',
- errors: this.transfer_form.errors
- };
- },
- },
-
});
diff --git a/resources/views/banking/accounts/show.blade.php b/resources/views/banking/accounts/show.blade.php
index ea52c907e..c1c4e73dc 100644
--- a/resources/views/banking/accounts/show.blade.php
+++ b/resources/views/banking/accounts/show.blade.php
@@ -21,26 +21,36 @@
- @stack('transaction_button_start')
- @can('create-account-transactions')
-
- CREATE TRANSACTION
+ @stack('revenue_button_start')
+ @can('create-sales-revenues')
+
+ {{ trans('general.add_income')}}
@endcan
- @stack('transaction_button_end')
+ @stack('revenue_button_end')
+
+ @stack('revenue_button_start')
+ @can('create-sales-revenues')
+
+ {{ trans('general.add_expense') }}
+
+ @endcan
+ @stack('revenue_button_end')
@stack('transfer_button_start')
- @can('show-performance')
-
- create_transfer
+ @can('create-banking-transfers')
+
+ Add Transfer
@endcan
@stack('transfer_button_end')
+
+
@stack('performance_button_start')
- @can('show-performance')
-
- performance
+ @can('read-banking-accounts')
+
+ See Performance
@endcan
@stack('performance_button_end')
@@ -48,22 +58,21 @@
@stack('delete_button_start')
- @can('delete-banking-accounts')
+ @can('delete-sales-customers')
{!! Form::deleteLink($account, 'accounts.destroy') !!}
@endcan
@stack('delete_button_end')
@stack('button_dropdown_end')
+ @stack('edit_button_start')
+ @can('update-sales-customers')
+
+ {{ trans('general.edit') }}
+
+ @endcan
+ @stack('edit_button_end')
-
- @stack('account_edit_button_start')
- @can('update-banking-account')
-
- {{ trans('general.edit') }}
-
- @endcan
- @stack('account_edit_button_end')
@endsection
@section('content')
@@ -71,23 +80,23 @@
@stack('account_number_start')
- -
- {{ trans_choice('general.account_number', 2) }}
- {{ }}
+
-
+ {{ trans_choice('general.accounts', 1) }} {{ trans_choice('accounts.number', 2) }}
+ {{ $account -> number}}
@stack('account_number_end')
@stack('account_currency_start')
- -
- {{ trans_choice('general.transactions', 2) }}
- {{ $ }}
+
-
+ {{ trans_choice('general.currencies', 2) }}
+ {{ $account -> currency -> name}}
@stack('account_currency_end')
@stack('account_starting_balance_start')
- -
- {{ trans_choice('banking.starting_balance', 2) }}
- {{ }}
+
-
+ {{ trans_choice('accounts.opening_balance', 2) }}
+ @money($account -> opening_balance, $account -> currency -> currency_code, true)
@stack('account_starting_balance_end')
@@ -95,28 +104,25 @@
@stack('bank_name_start')
-
-
{{ trans('') }}
- {{ $account->name }}
+ {{ trans('accounts.bank_name') }}
+ {{ $account->bank_name }}
@stack('bank_name_end')
@stack('account_phone_start')
-
-
{{ trans('general.phone') }}
- {{ $account->phone }}
+ {{ trans('accounts.bank_phone') }}
+ {{ $account->bank_phone }}
@stack('account_phone_end')
@stack('account_address_start')
-
-
{{ trans('general.address') }}
- {{ $account->address }}
+ {{ trans('accounts.bank_address') }}
+ {{ $account->bank_address }}
@stack('account_address_end')
-
- @stack('account_edit_button_start')
- @stack('account_edit_button_end')
@@ -129,7 +135,7 @@
{{ trans('general.incoming') }}
-
@money($amounts['incoming'], setting('default.currency'), true)
+
@money($account->income_balance, $account->currency_code, true)
@@ -145,7 +151,7 @@
{{ trans('widgets.outgoing') }}
-
@money($amounts['outgoing'], setting('default.currency'), true)
+
@money($account->expense_balance, $account->currency_code, true)
@@ -159,9 +165,9 @@
-
{{ trans('widgets.balance') }}
+
{{ trans('widgets.account_balance') }}
-
@money($amounts['balance'], setting('default.currency'), true)
+
@money($account->balance, $account->currency_code, true)
@@ -176,16 +182,16 @@
@stack('account_transactions_tab_start')
-
-
- {{ trans_choice('general.invoices', 2) }}
+
+ {{ trans_choice('general.transactions', 2) }}
@stack('account_transactions_tab_end')
@stack('account_transfers_tab_start')
-
-
- {{ trans_choice('general.transactions', 2) }}
+
+ {{ trans_choice('general.transfers', 2) }}
@stack('account_transfers_tab_end')
@@ -197,23 +203,23 @@
@stack('account_transactions_content_start')
-
+
- {{ trans_choice('general.date', 1) }} |
- {{ trans('general.amount') }} |
- {{ trans('general.type') }} |
- {{ trans('general.category') }} |
+ {{ trans_choice('general.date', 1) }} |
+ {{ trans('general.amount') }} |
+ {{ trans_choice('general.types', 1) }} |
+ {{ trans_choice('general.categories', 1) }} |
@foreach($transactions as $item)
- @date($item->issued_at) |
- @money($item->amount, $item->currency_code, true) |
- {{ $item->type }} |
- $item->category |
+ @date($item->issued_at) |
+ @money($item->amount, $item->currency_code, true) |
+ {{ $item->type_title }} |
+ {{ $item->category->name }} |
@endforeach
@@ -228,39 +234,39 @@
@stack('account_transactions_content_end')
- @stack('customer_transactions_content_start')
-
+ @stack('account_transfers_content_start')
+
-
+
- {{ trans('general.date') }} |
- {{ trans('general.amount') }} |
- {{ trans_choice('general.categories', 1) }} |
- {{ trans_choice('general.accounts', 1) }} |
+ {{ trans('general.date') }} |
+ {{ trans('general.amount') }} |
+ {{ trans_choice('transfers.from_account', 1) }} |
+ {{ trans_choice('transfers.to_account', 1) }} |
- @foreach($transactions as $item)
+ @foreach($transfers as $item)
- @date($item->paid_at) |
- @money($item->amount, $item->currency_code, true) |
- {{ $item->category->name }} |
- {{ $item->account->name }} |
+ @date($item->expense_transaction->paid_at) |
+ @money($item->expense_transaction->amount, $item->expense_transaction->currency_code, true) |
+ {{ $item->expense_transaction->account->name }} |
+ {{ $item->income_transaction->account->name }} |
@endforeach
-
+
- @stack('customer_transactions_content_end')
+ @stack('account_transfers_content_end')
@@ -271,5 +277,5 @@
@push('scripts_start')
-
+
@endpush
diff --git a/routes/admin.php b/routes/admin.php
index c9c77f7fe..971f9f90a 100644
--- a/routes/admin.php
+++ b/routes/admin.php
@@ -128,11 +128,9 @@ Route::group(['prefix' => 'purchases'], function () {
Route::group(['prefix' => 'banking'], function () {
Route::get('accounts/currency', 'Banking\Accounts@currency')->name('accounts.currency');
- Route::get('accounts/{account}/create-transaction', 'Banking\Accounts@createTransaction')->name('accounts.create-transaction');
Route::get('accounts/{account}/enable', 'Banking\Accounts@enable')->name('accounts.enable');
Route::get('accounts/{account}/disable', 'Banking\Accounts@disable')->name('accounts.disable');
- Route::get('accounts/{account}/duplicate', 'Banking\Accounts@duplicate')->name('accounts.duplicate');
- Route::get('accounts/{account}/edit', 'Banking\Accounts@edit')->name('account.edit');
+ Route::get('accounts/{account}/duplicate', 'Banking\Accounts@duplicate')->name('accounts.duplicate');
Route::resource('accounts', 'Banking\Accounts', ['middleware' => ['date.format', 'money']]);
Route::post('transactions/import', 'Banking\Transactions@import')->name('transactions.import');
@@ -140,7 +138,6 @@ Route::group(['prefix' => 'banking'], function () {
Route::resource('transactions', 'Banking\Transactions');
-
Route::get('transfers/{transfer}/print', 'Banking\Transfers@printTransfer')->name('transfers.print');
Route::get('transfers/{transfer}/pdf', 'Banking\Transfers@pdfTransfer')->name('transfers.pdf');
Route::get('transfers/{transfer}/duplicate', 'Banking\Transfers@duplicate')->name('transfers.duplicate');