Skip to content

Commit

Permalink
Fixed transaction missing type issue and fixed recurring vue exception..
Browse files Browse the repository at this point in the history
  • Loading branch information
cuneytsenturk committed Jun 16, 2023
1 parent a411107 commit 1d12f11
Show file tree
Hide file tree
Showing 10 changed files with 40 additions and 14 deletions.
10 changes: 5 additions & 5 deletions app/Http/Controllers/Banking/RecurringTransactions.php
Expand Up @@ -63,9 +63,9 @@ public function show(Transaction $recurring_transaction)
*/
public function create()
{
$type = request()->get('type', 'income-recurring');
$real_type = request()->get('real_type', $this->getRealTypeOfRecurringTransaction($type));
$contact_type = config('type.transaction.' . $real_type . '.contact_type');
$type = $this->getTypeRecurringTransaction(request()->get('type', 'income-recurring'));
$real_type = $this->getTypeTransaction(request()->get('real_type', $this->getRealTypeOfRecurringTransaction($type)));
$contact_type = config('type.transaction.' . $real_type . '.contact_type', 'customer');

$number = $this->getNextTransactionNumber('-recurring');

Expand Down Expand Up @@ -139,8 +139,8 @@ public function duplicate(Transaction $recurring_transaction)
public function edit(Transaction $recurring_transaction)
{
$type = $recurring_transaction->type;
$real_type = request()->get('real_type', $this->getRealTypeOfRecurringTransaction($type));
$contact_type = config('type.transaction.' . $real_type . '.contact_type');
$real_type = $this->getTypeTransaction(request()->get('real_type', $this->getRealTypeOfRecurringTransaction($type)));
$contact_type = config('type.transaction.' . $real_type . '.contact_type', 'customer');

$number = $this->getNextTransactionNumber('-recurring');

Expand Down
2 changes: 1 addition & 1 deletion app/Http/Controllers/Banking/Transactions.php
Expand Up @@ -98,7 +98,7 @@ public function show(Transaction $transaction)
*/
public function create()
{
$type = request()->get('type', 'income');
$type = $this->getTypeTransaction(request()->get('type', 'income'));
$real_type = $this->getRealTypeTransaction($type);

$number = $this->getNextTransactionNumber($type);
Expand Down
6 changes: 6 additions & 0 deletions app/Jobs/Banking/CreateTransaction.php
Expand Up @@ -16,6 +16,12 @@ public function handle(): Transaction
{
event(new TransactionCreating($this->request));

if (! array_key_exists($this->request->get('type'), config('type.transaction'))) {
$type = (empty($this->request->get('recurring_frequency')) || ($this->request->get('recurring_frequency') == 'no')) ? Transaction::INCOME_TYPE : Transaction::INCOME_RECURRING_TYPE;

$this->request->merge(['type' => $type]);
}

\DB::transaction(function () {
$this->model = Transaction::create($this->request->all());

Expand Down
6 changes: 6 additions & 0 deletions app/Jobs/Banking/UpdateTransaction.php
Expand Up @@ -16,6 +16,12 @@ public function handle(): Transaction

event(new TransactionUpdating($this->model, $this->request));

if (! array_key_exists($this->request->get('type'), config('type.transaction'))) {
$type = (empty($this->request->get('recurring_frequency')) || ($this->request->get('recurring_frequency') == 'no')) ? Transaction::INCOME_TYPE : Transaction::INCOME_RECURRING_TYPE;

$this->request->merge(['type' => $type]);
}

\DB::transaction(function () {
$this->model->update($this->request->all());

Expand Down
14 changes: 14 additions & 0 deletions app/Traits/Transactions.php
Expand Up @@ -205,6 +205,11 @@ public function getTransactionFormRoutesOfType(string $type): array
];
}

public function getTypeTransaction(string $type = Transaction::INCOME_TYPE): string
{
return array_key_exists($type, config('type.transaction')) ? $type : Transaction::INCOME_TYPE;
}

public function getRealTypeTransaction(string $type): string
{
$type = $this->getRealTypeOfRecurringTransaction($type);
Expand All @@ -214,6 +219,15 @@ public function getRealTypeTransaction(string $type): string
return $type;
}

public function getTypeRecurringTransaction(string $type = Transaction::INCOME_RECURRING_TYPE): string
{
if (! Str::contains($type, '-recurring')) {
return Transaction::INCOME_RECURRING_TYPE;
}

return array_key_exists($type, config('type.transaction')) ? $type : Transaction::INCOME_RECURRING_TYPE;
}

public function getRealTypeOfRecurringTransaction(string $recurring_type): string
{
return Str::replace('-recurring', '', $recurring_type);
Expand Down
4 changes: 2 additions & 2 deletions resources/assets/js/components/AkauntingRecurring.vue
Expand Up @@ -264,8 +264,8 @@ export default {
},
sendEmailShow: {
type: Number,
default: 1,
type: [String, Number, Array, Object, Boolean],
default: '1',
description: "Created recurring model send automatically option"
},
sendEmailText: {
Expand Down
Expand Up @@ -54,7 +54,7 @@
<x-slot name="body">
<x-form.group.category type="{{ $real_type }}" :selected="setting('default.' . $real_type . '_category')" />

<x-form.group.contact type="{{ config('type.transaction.' . $real_type . '.contact_type') }}" not-required />
<x-form.group.contact :type="$contact_type" not-required />
</x-slot>
</x-form.section>

Expand Down
Expand Up @@ -47,7 +47,7 @@
<x-slot name="body">
<x-form.group.category type="{{ $real_type }}" />

<x-form.group.contact type="{{ config('type.transaction.' . $real_type . '.contact_type') }}" not-required />
<x-form.group.contact :type="$contact_type" not-required />
</x-slot>
</x-form.section>

Expand Down
4 changes: 2 additions & 2 deletions resources/views/banking/transactions/create.blade.php
Expand Up @@ -40,9 +40,9 @@
</x-slot>

<x-slot name="body">
<x-form.group.category type="{{ $real_type }}" :selected="setting('default.' . $real_type . '_category')" />
<x-form.group.category :type="$real_type" :selected="setting('default.' . $real_type . '_category')" />

<x-form.group.contact type="{{ config('type.transaction.' . $real_type . '.contact_type') }}" not-required />
<x-form.group.contact :type="$contact_type" not-required />
</x-slot>
</x-form.section>

Expand Down
4 changes: 2 additions & 2 deletions resources/views/banking/transactions/edit.blade.php
Expand Up @@ -56,9 +56,9 @@
</x-slot>

<x-slot name="body">
<x-form.group.category type="{{ $type }}" />
<x-form.group.category :type="$type" />

<x-form.group.contact type="{{ config('type.transaction.' . $type . '.contact_type') }}" not-required />
<x-form.group.contact :type="$contact_type" not-required />

@if ($transaction->document)
<x-form.group.text name="document" label="{{ trans_choice('general.' . Str::plural(config('type.transaction.' . $type . '.document_type')), 1) }}" not-required disabled value="{{ $transaction->document->document_number }}" />
Expand Down

0 comments on commit 1d12f11

Please sign in to comment.