Merge pull request #2408 from sevannerse/connect-split-transaction

Connect split transaction
This commit is contained in:
Denis Duliçi 2022-06-05 03:13:34 +03:00 committed by GitHub
commit 3ac8186d4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 104 additions and 37 deletions

View File

@ -35,7 +35,7 @@ class Transactions extends Controller
*/ */
public function index() 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 = [ $totals = [
'income' => 0, 'income' => 0,
@ -325,6 +325,45 @@ class Transactions extends Controller
return $pdf->download($file_name); 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) public function connect(Transaction $transaction, TransactionConnect $request)
{ {
$total_items = count($request->data['items']); $total_items = count($request->data['items']);

View File

@ -190,6 +190,16 @@ class Transaction extends Model
return $query->where($this->qualifyColumn('type'), 'not like', '%-recurring'); 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 public function scopeIsTransfer(Builder $query): Builder
{ {
return $query->where('category_id', '=', Category::transfer()); return $query->where('category_id', '=', Category::transfer());
@ -470,22 +480,10 @@ class Transaction extends Model
'permission' => 'create-banking-transactions', 'permission' => 'create-banking-transactions',
'attributes' => [ 'attributes' => [
'id' => 'index-transactions-more-actions-connect-' . $this->id, '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[] = $connect;
$actions[] = [ $actions[] = [

View File

@ -32,7 +32,7 @@
@click="onItemSelected(item)" @click="onItemSelected(item)"
> >
<div class="w-full flex items-center justify-between"> <div class="w-full flex items-center justify-between">
<span>{{ item.name }}</span> <span class="w-9/12">{{ item.name }}</span>
<money <money
:name="'item-id-' + item.id" :name="'item-id-' + item.id"
@ -40,7 +40,25 @@
v-bind="money" v-bind="money"
masked masked
disabled disabled
class="text-right disabled-money text-gray" class="w-1/12 text-right disabled-money text-gray"
></money>
-
<money
:name="'item-id-' + item.id"
:value="item.paid"
v-bind="money"
masked
disabled
class="w-1/12 text-right disabled-money text-gray"
></money>
=
<money
:name="'item-id-' + item.id"
:value="item.open"
v-bind="money"
masked
disabled
class="w-1/12 text-right disabled-money text-gray"
></money> ></money>
</div> </div>
</div> </div>
@ -180,6 +198,8 @@ export default {
id: item.id, id: item.id,
name: item.document_number + ' | ' + item.contact_name + (item.notes ? ' | ' + item.notes : ''), name: item.document_number + ' | ' + item.contact_name + (item.notes ? ' | ' + item.notes : ''),
amount: item.amount, amount: item.amount,
paid: item.paid,
open: item.amount - item.paid,
}); });
}, this); }, this);
} }

View File

@ -38,20 +38,31 @@ const app = new Vue({
}, },
methods: { methods: {
onConnect(transaction, currency, documents) { onConnect(route) {
this.connect.show = true; let dial_promise = Promise.resolve(window.axios.get(route));
this.connect.transaction = transaction; dial_promise.then(response => {
this.connect.show = true;
this.connect.currency = { this.connect.transaction = JSON.parse(response.data.transaction);
decimal_mark: currency.decimal_mark,
precision: currency.precision,
symbol: currency.symbol,
symbol_first: currency.symbol_first,
thousands_separator: currency.thousands_separator,
};
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) { async onEmail(route) {

View File

@ -22,18 +22,16 @@
@stack('connect_button_start') @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) @if (! $hideButtonConnect)
@can($permissionCreate) @can($permissionCreate)
@if ($type == 'income' && $transaction->contact->exists) <button
<button type="button" class="w-full flex items-center text-purple px-2 h-9 leading-9 whitespace-nowrap" title="{{ trans('general.connect') }}" @click="onConnect({{ $transaction->load('account')->toJson() }}, {{ $transaction->currency->toJson() }}, {{ $transaction->contact->invoices()->notPaid()->where('currency_code', $transaction->currency_code)->with(['media', 'totals', 'transactions'])->get()->toJson() }})"><span class="w-full h-full flex items-center rounded-md px-2 text-sm hover:bg-lilac-100">{{ trans('general.connect') }}</span></button> type="button"
@elseif ($type == 'income' && ! $transaction->contact->exists) class="w-full flex items-center text-purple px-2 h-9 leading-9 whitespace-nowrap"
<button type="button" class="w-full flex items-center text-purple px-2 h-9 leading-9 whitespace-nowrap" title="{{ trans('general.connect') }}" @click="onConnect({{ $transaction->load('account')->toJson() }}, {{ $transaction->currency->toJson() }}, {{ App\Models\Document\Document::invoice()->notPaid()->where('currency_code', $transaction->currency_code)->with(['media', 'totals', 'transactions'])->get()->toJson() }})"><span class="w-full h-full flex items-center rounded-md px-2 text-sm hover:bg-lilac-100">{{ trans('general.connect') }}</span></button> title="{{ trans('general.connect') }}"
@elseif ($type == 'expense' && $transaction->contact->exists) @click="onConnect('{{ route('transactions.dial', $transaction->id) }}')">
<button type="button" class="w-full flex items-center text-purple px-2 h-9 leading-9 whitespace-nowrap" title="{{ trans('general.connect') }}" @click="onConnect({{ $transaction->load('account')->toJson() }}, {{ $transaction->currency->toJson() }}, {{ $transaction->contact->bills()->notPaid()->where('currency_code', $transaction->currency_code)->with(['media', 'totals', 'transactions'])->get()->toJson() }})"><span class="w-full h-full flex items-center rounded-md px-2 text-sm hover:bg-lilac-100">{{ trans('general.connect') }}</span></button> <span class="w-full h-full flex items-center rounded-md px-2 text-sm hover:bg-lilac-100">{{ trans('general.connect') }}</span>
@elseif ($type == 'expense' && ! $transaction->contact->exists) </button>
<button type="button" class="w-full flex items-center text-purple px-2 h-9 leading-9 whitespace-nowrap" title="{{ trans('general.connect') }}" @click="onConnect({{ $transaction->load('account')->toJson() }}, {{ $transaction->currency->toJson() }}, {{ App\Models\Document\Document::bill()->notPaid()->where('currency_code', $transaction->currency_code)->with(['media', 'totals', 'transactions'])->get()->toJson() }})"><span class="w-full h-full flex items-center rounded-md px-2 text-sm hover:bg-lilac-100">{{ trans('general.connect') }}</span></button>
@endif
@endcan @endcan
@endif @endif
@endif @endif

View File

@ -130,6 +130,7 @@ Route::group(['prefix' => 'banking'], function () {
Route::get('transactions/{transaction}/print', 'Banking\Transactions@printTransaction')->name('transactions.print'); 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}/pdf', 'Banking\Transactions@pdfTransaction')->name('transactions.pdf');
Route::get('transactions/{transaction}/duplicate', 'Banking\Transactions@duplicate')->name('transactions.duplicate'); 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/{transaction}/connect', 'Banking\Transactions@connect')->name('transactions.connect');
Route::post('transactions/import', 'Banking\Transactions@import')->middleware('import')->name('transactions.import'); Route::post('transactions/import', 'Banking\Transactions@import')->middleware('import')->name('transactions.import');
Route::get('transactions/export', 'Banking\Transactions@export')->name('transactions.export'); Route::get('transactions/export', 'Banking\Transactions@export')->name('transactions.export');