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);