diff --git a/app/Http/Controllers/Banking/Transactions.php b/app/Http/Controllers/Banking/Transactions.php index 1e8ab4709..dee840e17 100644 --- a/app/Http/Controllers/Banking/Transactions.php +++ b/app/Http/Controllers/Banking/Transactions.php @@ -35,7 +35,7 @@ class Transactions extends Controller */ public function index() { - $transactions = Transaction::with('account', 'category', 'contact')->isNotRecurring()->collect(['paid_at'=> 'desc']); + $transactions = Transaction::with('account', 'category', 'contact')->isNotRecurring()->isNotSplit()->collect(['paid_at'=> 'desc']); $totals = [ 'income' => 0, @@ -325,6 +325,45 @@ class Transactions extends Controller return $pdf->download($file_name); } + public function dial(Transaction $transaction) + { + $documents = collect([]); + + if ($transaction->type == Transaction::INCOME_TYPE && $transaction->contact->exists) { + $builder = $transaction->contact + ->invoices(); + } + + if ($transaction->type == Transaction::INCOME_TYPE && ! $transaction->contact->exists) { + $builder = Document::invoice(); + } + + if ($transaction->type == Transaction::EXPENSE_TYPE && $transaction->contact->exists) { + $builder = $transaction->contact + ->bills(); + } + + if ($transaction->type == Transaction::EXPENSE_TYPE && ! $transaction->contact->exists) { + $builder = Document::bill(); + } + + if (isset($builder)) { + $documents = $builder->notPaid() + ->where('currency_code', $transaction->currency_code) + ->with(['media', 'totals', 'transactions']) + ->get() + ->toJson(); + } + + $data = [ + 'transaction' => $transaction->load(['account', 'category'])->toJson(), + 'currency' => $transaction->currency->toJson(), + 'documents' => $documents, + ]; + + return response()->json($data); + } + public function connect(Transaction $transaction, TransactionConnect $request) { $total_items = count($request->data['items']); diff --git a/app/Models/Banking/Transaction.php b/app/Models/Banking/Transaction.php index 5b8cd940e..c99b9be18 100644 --- a/app/Models/Banking/Transaction.php +++ b/app/Models/Banking/Transaction.php @@ -190,6 +190,16 @@ class Transaction extends Model return $query->where($this->qualifyColumn('type'), 'not like', '%-recurring'); } + public function scopeIsSplit(Builder $query): Builder + { + return $query->where($this->qualifyColumn('type'), 'like', '%-split'); + } + + public function scopeIsNotSplit(Builder $query): Builder + { + return $query->where($this->qualifyColumn('type'), 'not like', '%-split'); + } + public function scopeIsTransfer(Builder $query): Builder { return $query->where('category_id', '=', Category::transfer()); @@ -470,22 +480,10 @@ class Transaction extends Model 'permission' => 'create-banking-transactions', 'attributes' => [ 'id' => 'index-transactions-more-actions-connect-' . $this->id, + '@click' => 'onConnect(\'' . route('transactions.dial', $this->id) . '\')', ], ]; - $transaction = $this->load('account')->toJson(); - $currency = $this->currency->toJson(); - - if ($this->contact->exists) { - $document = $this->contact->invoices()->notPaid()->where('currency_code', $this->currency_code)->with(['media', 'totals', 'transactions'])->get()->toJson(); - - $connect['attributes']['@click'] = 'onConnect()'; - } else { - $document = \App\Models\Document\Document::invoice()->notPaid()->where('currency_code', $this->currency_code)->with(['media', 'totals', 'transactions'])->get()->toJson(); - - $connect['attributes']['@click'] = 'onConnect()'; - } - $actions[] = $connect; $actions[] = [ diff --git a/resources/assets/js/components/AkauntingDocumentButton.vue b/resources/assets/js/components/AkauntingDocumentButton.vue index 16b180766..a31b12c2c 100644 --- a/resources/assets/js/components/AkauntingDocumentButton.vue +++ b/resources/assets/js/components/AkauntingDocumentButton.vue @@ -32,7 +32,7 @@ @click="onItemSelected(item)" >
- {{ item.name }} + {{ item.name }} + - + + = +
@@ -180,6 +198,8 @@ export default { id: item.id, name: item.document_number + ' | ' + item.contact_name + (item.notes ? ' | ' + item.notes : ''), amount: item.amount, + paid: item.paid, + open: item.amount - item.paid, }); }, this); } diff --git a/resources/assets/js/views/banking/transactions.js b/resources/assets/js/views/banking/transactions.js index b43d767f4..6556f6745 100644 --- a/resources/assets/js/views/banking/transactions.js +++ b/resources/assets/js/views/banking/transactions.js @@ -38,20 +38,31 @@ const app = new Vue({ }, methods: { - onConnect(transaction, currency, documents) { - this.connect.show = true; + onConnect(route) { + let dial_promise = Promise.resolve(window.axios.get(route)); - this.connect.transaction = transaction; + dial_promise.then(response => { + this.connect.show = true; - this.connect.currency = { - decimal_mark: currency.decimal_mark, - precision: currency.precision, - symbol: currency.symbol, - symbol_first: currency.symbol_first, - thousands_separator: currency.thousands_separator, - }; + this.connect.transaction = JSON.parse(response.data.transaction); - this.connect.documents = documents; + let currency = JSON.parse(response.data.currency); + + this.connect.currency = { + decimal_mark: currency.decimal_mark, + precision: currency.precision, + symbol: currency.symbol, + symbol_first: currency.symbol_first, + thousands_separator: currency.thousands_separator, + }; + + this.connect.documents = JSON.parse(response.data.documents); + }) + .catch(error => { + }) + .finally(function () { + // always executed + }); }, async onEmail(route) { diff --git a/resources/views/components/transactions/show/more-buttons.blade.php b/resources/views/components/transactions/show/more-buttons.blade.php index 3617dfd48..3a69517ef 100644 --- a/resources/views/components/transactions/show/more-buttons.blade.php +++ b/resources/views/components/transactions/show/more-buttons.blade.php @@ -22,18 +22,16 @@ @stack('connect_button_start') - @if ($transaction->is_splittable && empty($transaction->document_id)) + @if ($transaction->is_splittable && empty($transaction->document_id) && empty($transaction->recurring)) @if (! $hideButtonConnect) @can($permissionCreate) - @if ($type == 'income' && $transaction->contact->exists) - - @elseif ($type == 'income' && ! $transaction->contact->exists) - - @elseif ($type == 'expense' && $transaction->contact->exists) - - @elseif ($type == 'expense' && ! $transaction->contact->exists) - - @endif + @endcan @endif @endif diff --git a/routes/admin.php b/routes/admin.php index 058d7f11b..0016193af 100644 --- a/routes/admin.php +++ b/routes/admin.php @@ -130,6 +130,7 @@ Route::group(['prefix' => 'banking'], function () { Route::get('transactions/{transaction}/print', 'Banking\Transactions@printTransaction')->name('transactions.print'); Route::get('transactions/{transaction}/pdf', 'Banking\Transactions@pdfTransaction')->name('transactions.pdf'); Route::get('transactions/{transaction}/duplicate', 'Banking\Transactions@duplicate')->name('transactions.duplicate'); + Route::get('transactions/{transaction}/dial', 'Banking\Transactions@dial')->name('transactions.dial'); Route::post('transactions/{transaction}/connect', 'Banking\Transactions@connect')->name('transactions.connect'); Route::post('transactions/import', 'Banking\Transactions@import')->middleware('import')->name('transactions.import'); Route::get('transactions/export', 'Banking\Transactions@export')->name('transactions.export');