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 @@
@@ -95,28 +104,25 @@ - - @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 @@