Fixed transaction missing type issue and fixed recurring vue exception..

This commit is contained in:
Cüneyt Şentürk 2023-06-16 14:18:52 +03:00
parent a411107a5f
commit 1d12f1115a
10 changed files with 40 additions and 14 deletions

View File

@ -63,9 +63,9 @@ class RecurringTransactions extends Controller
*/
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');
@ -139,8 +139,8 @@ class RecurringTransactions extends Controller
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');

View File

@ -98,7 +98,7 @@ class Transactions extends Controller
*/
public function create()
{
$type = request()->get('type', 'income');
$type = $this->getTypeTransaction(request()->get('type', 'income'));
$real_type = $this->getRealTypeTransaction($type);
$number = $this->getNextTransactionNumber($type);

View File

@ -16,6 +16,12 @@ class CreateTransaction extends Job implements HasOwner, HasSource, ShouldCreate
{
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());

View File

@ -16,6 +16,12 @@ class UpdateTransaction extends Job implements ShouldUpdate
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());

View File

@ -205,6 +205,11 @@ trait Transactions
];
}
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);
@ -214,6 +219,15 @@ trait Transactions
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);

View File

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

View File

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

View File

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

View File

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

View File

@ -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 }}" />