connect details read from dial route #2znd43c

This commit is contained in:
Sevan Nerse 2022-06-02 00:12:48 +03:00
parent 8cc8fcfd92
commit 05b2fec17c
5 changed files with 70 additions and 33 deletions

View File

@ -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

@ -470,22 +470,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

@ -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

@ -39,15 +39,13 @@
@if ($transaction->is_splittable && empty($transaction->document_id) && empty($transaction->recurring)) @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');