diff --git a/app/Http/Controllers/Settings/Categories.php b/app/Http/Controllers/Settings/Categories.php index 12163d94c..e8986fced 100644 --- a/app/Http/Controllers/Settings/Categories.php +++ b/app/Http/Controllers/Settings/Categories.php @@ -26,11 +26,9 @@ class Categories extends Controller { $categories = Category::with('sub_categories')->collect(); - $transfer_id = Category::transfer(); - $types = $this->getCategoryTypes(); - return $this->response('settings.categories.index', compact('categories', 'types', 'transfer_id')); + return $this->response('settings.categories.index', compact('categories', 'types')); } /** diff --git a/app/Imports/Banking/Transfers.php b/app/Imports/Banking/Transfers.php index a64747696..2770a8100 100644 --- a/app/Imports/Banking/Transfers.php +++ b/app/Imports/Banking/Transfers.php @@ -4,8 +4,9 @@ namespace App\Imports\Banking; use App\Abstracts\Import; use App\Jobs\Banking\CreateTransaction; +use App\Models\Banking\Transaction; use App\Models\Banking\Transfer as Model; -use App\Models\Setting\Category; +use App\Traits\Categories; use App\Traits\Currencies; use App\Traits\Jobs; use App\Traits\Transactions; @@ -13,7 +14,7 @@ use App\Utilities\Date; class Transfers extends Import { - use Currencies, Jobs, Transactions; + use Categories, Currencies, Jobs, Transactions; public function model(array $row) { @@ -31,7 +32,7 @@ class Transfers extends Import $row['to_currency_code'] = $this->getToCurrencyCode($row); $row['expense_transaction_id'] = $this->getExpenseTransactionId($row); $row['income_transaction_id'] = $this->getIncomeTransactionId($row); - + return $row; } @@ -55,7 +56,7 @@ class Transfers extends Import $expense_transaction = $this->dispatch(new CreateTransaction([ 'company_id' => $row['company_id'], 'number' => $this->getNextTransactionNumber(), - 'type' => 'expense', + 'type' => Transaction::EXPENSE_TRANSFER_TYPE, 'account_id' => $row['from_account_id'], 'paid_at' => $row['transferred_at'], 'currency_code' => $row['from_currency_code'], @@ -63,7 +64,7 @@ class Transfers extends Import 'amount' => $row['amount'], 'contact_id' => 0, 'description' => $row['description'], - 'category_id' => Category::transfer(), // Transfer Category ID + 'category_id' => $this->getTransferCategoryId(), 'payment_method' => $row['payment_method'], 'reference' => $row['reference'], 'created_by' => $row['created_by'], @@ -90,7 +91,7 @@ class Transfers extends Import $income_transaction = $this->dispatch(new CreateTransaction([ 'company_id' => $row['company_id'], 'number' => $this->getNextTransactionNumber(), - 'type' => 'income', + 'type' => Transaction::INCOME_TRANSFER_TYPE, 'account_id' => $row['to_account_id'], 'paid_at' => $row['transferred_at'], 'currency_code' => $row['to_currency_code'], @@ -98,7 +99,7 @@ class Transfers extends Import 'amount' => $amount, 'contact_id' => 0, 'description' => $row['description'], - 'category_id' => Category::transfer(), // Transfer Category ID + 'category_id' => $this->getTransferCategoryId(), 'payment_method' => $row['payment_method'], 'reference' => $row['reference'], 'created_by' => $row['created_by'], diff --git a/app/Jobs/Banking/CreateTransfer.php b/app/Jobs/Banking/CreateTransfer.php index ad19373ce..c8d094c6a 100644 --- a/app/Jobs/Banking/CreateTransfer.php +++ b/app/Jobs/Banking/CreateTransfer.php @@ -9,13 +9,14 @@ use App\Interfaces\Job\ShouldCreate; use App\Jobs\Banking\CreateTransaction; use App\Models\Banking\Account; use App\Models\Banking\Transfer; -use App\Models\Setting\Category; +use App\Models\Banking\Transaction; +use App\Traits\Categories; use App\Traits\Currencies; use App\Traits\Transactions; class CreateTransfer extends Job implements HasOwner, HasSource, ShouldCreate { - use Currencies, Transactions; + use Categories, Currencies, Transactions; public function handle(): Transfer { @@ -28,7 +29,7 @@ class CreateTransfer extends Job implements HasOwner, HasSource, ShouldCreate $expense_transaction = $this->dispatch(new CreateTransaction([ 'company_id' => $this->request['company_id'], - 'type' => 'expense', + 'type' => Transaction::EXPENSE_TRANSFER_TYPE, 'number' => $this->getNextTransactionNumber(), 'account_id' => $this->request->get('from_account_id'), 'paid_at' => $this->request->get('transferred_at'), @@ -37,7 +38,7 @@ class CreateTransfer extends Job implements HasOwner, HasSource, ShouldCreate 'amount' => $this->request->get('amount'), 'contact_id' => 0, 'description' => $this->request->get('description'), - 'category_id' => Category::transfer(), // Transfer Category ID + 'category_id' => $this->getTransferCategoryId(), 'payment_method' => $this->request->get('payment_method'), 'reference' => $this->request->get('reference'), 'created_by' => $this->request->get('created_by'), @@ -52,7 +53,7 @@ class CreateTransfer extends Job implements HasOwner, HasSource, ShouldCreate $income_transaction = $this->dispatch(new CreateTransaction([ 'company_id' => $this->request['company_id'], - 'type' => 'income', + 'type' => Transaction::INCOME_TRANSFER_TYPE, 'number' => $this->getNextTransactionNumber(), 'account_id' => $this->request->get('to_account_id'), 'paid_at' => $this->request->get('transferred_at'), @@ -61,7 +62,7 @@ class CreateTransfer extends Job implements HasOwner, HasSource, ShouldCreate 'amount' => $amount, 'contact_id' => 0, 'description' => $this->request->get('description'), - 'category_id' => Category::transfer(), // Transfer Category ID + 'category_id' => $this->getTransferCategoryId(), 'payment_method' => $this->request->get('payment_method'), 'reference' => $this->request->get('reference'), 'created_by' => $this->request->get('created_by'), diff --git a/app/Jobs/Banking/DeleteTransaction.php b/app/Jobs/Banking/DeleteTransaction.php index b5beac0fd..7561d0a3d 100644 --- a/app/Jobs/Banking/DeleteTransaction.php +++ b/app/Jobs/Banking/DeleteTransaction.php @@ -4,7 +4,6 @@ namespace App\Jobs\Banking; use App\Abstracts\Job; use App\Interfaces\Job\ShouldDelete; -use App\Models\Setting\Category; class DeleteTransaction extends Job implements ShouldDelete { @@ -31,7 +30,7 @@ class DeleteTransaction extends Job implements ShouldDelete throw new \Exception($message); } - if ($this->model->category->id == Category::transfer()) { + if ($this->model->isTransferTransaction()) { throw new \Exception('Unauthorized'); } } diff --git a/app/Jobs/Banking/UpdateTransfer.php b/app/Jobs/Banking/UpdateTransfer.php index 2d49be9b3..6836c8574 100644 --- a/app/Jobs/Banking/UpdateTransfer.php +++ b/app/Jobs/Banking/UpdateTransfer.php @@ -7,12 +7,12 @@ use App\Interfaces\Job\ShouldUpdate; use App\Models\Banking\Account; use App\Models\Banking\Transaction; use App\Models\Banking\Transfer; -use App\Models\Setting\Category; +use App\Traits\Categories; use App\Traits\Currencies; class UpdateTransfer extends Job implements ShouldUpdate { - use Currencies; + use Categories, Currencies; public function handle(): Transfer { @@ -41,7 +41,7 @@ class UpdateTransfer extends Job implements ShouldUpdate $expense_transaction->update([ 'company_id' => $this->request['company_id'], - 'type' => 'expense', + 'type' => Transaction::EXPENSE_TRANSFER_TYPE, 'account_id' => $this->request->get('from_account_id'), 'paid_at' => $this->request->get('transferred_at'), 'currency_code' => $expense_currency_code, @@ -49,7 +49,7 @@ class UpdateTransfer extends Job implements ShouldUpdate 'amount' => $this->request->get('amount'), 'contact_id' => 0, 'description' => $this->request->get('description'), - 'category_id' => Category::transfer(), // Transfer Category ID + 'category_id' => $this->getTransferCategoryId(), 'payment_method' => $this->request->get('payment_method'), 'reference' => $this->request->get('reference'), ]); @@ -63,7 +63,7 @@ class UpdateTransfer extends Job implements ShouldUpdate $income_transaction->update([ 'company_id' => $this->request['company_id'], - 'type' => 'income', + 'type' => Transaction::INCOME_TRANSFER_TYPE, 'account_id' => $this->request->get('to_account_id'), 'paid_at' => $this->request->get('transferred_at'), 'currency_code' => $income_currency_code, @@ -71,7 +71,7 @@ class UpdateTransfer extends Job implements ShouldUpdate 'amount' => $amount, 'contact_id' => 0, 'description' => $this->request->get('description'), - 'category_id' => Category::transfer(), // Transfer Category ID + 'category_id' => $this->getTransferCategoryId(), 'payment_method' => $this->request->get('payment_method'), 'reference' => $this->request->get('reference'), ]); diff --git a/app/Listeners/Update/V30/Version305.php b/app/Listeners/Update/V30/Version305.php new file mode 100644 index 000000000..6c4a3b3b7 --- /dev/null +++ b/app/Listeners/Update/V30/Version305.php @@ -0,0 +1,95 @@ +skipThisUpdate($event)) { + return; + } + + Log::channel('stdout')->info('Updating to 3.0.5 version...'); + + $this->updateDatabase(); + + $this->updateSettings(); + + $this->updateTransfers(); + + Log::channel('stdout')->info('Done!'); + } + + public function updateDatabase(): void + { + Log::channel('stdout')->info('Updating database...'); + + Artisan::call('migrate', ['--force' => true]); + + Log::channel('stdout')->info('Database updated.'); + } + + public function updateSettings(): void + { + Log::channel('stdout')->info('Updating settings...'); + + DB::table('settings')->where('key', 'transaction.type.income')->get()->each(function ($setting) { + DB::table('settings')->where('id', $setting->id)->update([ + 'value' => $setting->value . ',' . Transaction::INCOME_TRANSFER_TYPE, + ]); + }); + + DB::table('settings')->where('key', 'transaction.type.expense')->get()->each(function ($setting) { + DB::table('settings')->where('id', $setting->id)->update([ + 'value' => $setting->value . ',' . Transaction::EXPENSE_TRANSFER_TYPE, + ]); + }); + + Log::channel('stdout')->info('Settings updated.'); + } + + public function updateTransfers(): void + { + Log::channel('stdout')->info('Updating transfers...'); + + DB::table('transfers')->get()->each(function ($transfer) { + Log::channel('stdout')->info('Updating transfer: ' . $transfer->id); + + try { + DB::table('transactions')->where('id', $transfer->income_transaction_id)->update([ + 'type' => Transaction::INCOME_TRANSFER_TYPE, + ]); + } catch (\Exception $e) { + Log::channel('stdout')->error('Error updating transaction: ' . $transfer->income_transaction_id); + } + + try { + DB::table('transactions')->where('id', $transfer->expense_transaction_id)->update([ + 'type' => Transaction::EXPENSE_TRANSFER_TYPE, + ]); + } catch (\Exception $e) { + Log::channel('stdout')->error('Error updating transaction: ' . $transfer->expense_transaction_id); + } + }); + + Log::channel('stdout')->info('Transfers updated.'); + } +} diff --git a/app/Models/Banking/Transaction.php b/app/Models/Banking/Transaction.php index 20c0b80a8..11223408c 100644 --- a/app/Models/Banking/Transaction.php +++ b/app/Models/Banking/Transaction.php @@ -21,13 +21,13 @@ class Transaction extends Model use Cloneable, Currencies, DateTime, HasFactory, Media, Recurring, Transactions; public const INCOME_TYPE = 'income'; + public const INCOME_TRANSFER_TYPE = 'income-transfer'; public const INCOME_SPLIT_TYPE = 'income-split'; public const INCOME_RECURRING_TYPE = 'income-recurring'; - public const INCOME_TRANSFER_TYPE = 'income-transfer'; // TODO - convert transfer from category to type public const EXPENSE_TYPE = 'expense'; + public const EXPENSE_TRANSFER_TYPE = 'expense-transfer'; public const EXPENSE_SPLIT_TYPE = 'expense-split'; public const EXPENSE_RECURRING_TYPE = 'expense-recurring'; - public const EXPENSE_TRANSFER_TYPE = 'expense-transfer'; // TODO - convert transfer from category to type protected $table = 'transactions'; @@ -145,11 +145,11 @@ class Transaction extends Model public function transfer() { - if ($this->type == self::INCOME_TYPE) { + if ($this->type == static::INCOME_TRANSFER_TYPE) { return $this->belongsTo('App\Models\Banking\Transfer', 'id', 'income_transaction_id'); } - if ($this->type == self::EXPENSE_TYPE) { + if ($this->type == static::EXPENSE_TRANSFER_TYPE) { return $this->belongsTo('App\Models\Banking\Transfer', 'id', 'expense_transaction_id'); } @@ -180,6 +180,11 @@ class Transaction extends Model return $query->whereIn($this->qualifyColumn('type'), (array) $this->getIncomeTypes()); } + public function scopeIncomeTransfer(Builder $query): Builder + { + return $query->where($this->qualifyColumn('type'), '=', self::INCOME_TRANSFER_TYPE); + } + public function scopeIncomeRecurring(Builder $query): Builder { return $query->where($this->qualifyColumn('type'), '=', self::INCOME_RECURRING_TYPE); @@ -190,11 +195,26 @@ class Transaction extends Model return $query->whereIn($this->qualifyColumn('type'), (array) $this->getExpenseTypes()); } + public function scopeExpenseTransfer(Builder $query): Builder + { + return $query->where($this->qualifyColumn('type'), '=', self::EXPENSE_TRANSFER_TYPE); + } + public function scopeExpenseRecurring(Builder $query): Builder { return $query->where($this->qualifyColumn('type'), '=', self::EXPENSE_RECURRING_TYPE); } + public function scopeIsTransfer(Builder $query): Builder + { + return $query->where($this->qualifyColumn('type'), 'like', '%-transfer'); + } + + public function scopeIsNotTransfer(Builder $query): Builder + { + return $query->where($this->qualifyColumn('type'), 'not like', '%-transfer'); + } + public function scopeIsRecurring(Builder $query): Builder { return $query->where($this->qualifyColumn('type'), 'like', '%-recurring'); @@ -215,16 +235,6 @@ class Transaction extends Model return $query->where($this->qualifyColumn('type'), 'not like', '%-split'); } - public function scopeIsTransfer(Builder $query): Builder - { - return $query->where('category_id', '=', Category::transfer()); - } - - public function scopeIsNotTransfer(Builder $query): Builder - { - return $query->where('category_id', '<>', Category::transfer()); - } - public function scopeIsDocument(Builder $query): Builder { return $query->whereNotNull('document_id'); @@ -346,16 +356,6 @@ class Transaction extends Model } } - /** - * Check if the record is attached to a transfer. - * - * @return bool - */ - public function getHasTransferRelationAttribute() - { - return (bool) ($this->category?->id == $this->category?->transfer()); - } - /** * Get the title of type. * @@ -364,6 +364,9 @@ class Transaction extends Model public function getTypeTitleAttribute($value) { $type = $this->getRealTypeOfRecurringTransaction($this->type); + $type = $this->getRealTypeOfTransferTransaction($type); + + $type = str_replace('-', '_', $type); return $value ?? trans_choice('general.' . Str::plural($type), 1); } @@ -459,7 +462,7 @@ class Transaction extends Model } catch (\Exception $e) {} try { - if (! $this->reconciled && ! $this->hasTransferRelation) { + if (! $this->reconciled && $this->isNotTransferTransaction()) { $actions[] = [ 'title' => trans('general.edit'), 'icon' => 'edit', @@ -473,7 +476,7 @@ class Transaction extends Model } catch (\Exception $e) {} try { - if (empty($this->document_id) && ! $this->hasTransferRelation) { + if (empty($this->document_id) && $this->isNotTransferTransaction()) { $actions[] = [ 'title' => trans('general.duplicate'), 'icon' => 'file_copy', @@ -487,7 +490,7 @@ class Transaction extends Model } catch (\Exception $e) {} try { - if ($this->is_splittable && empty($this->document_id) && empty($this->recurring) && ! $this->hasTransferRelation) { + if ($this->is_splittable && empty($this->document_id) && empty($this->recurring) && $this->isNotTransferTransaction()) { $connect = [ 'type' => 'button', 'title' => trans('general.connect'), @@ -534,7 +537,7 @@ class Transaction extends Model } catch (\Exception $e) {} if ($prefix != 'recurring-transactions') { - if (! $this->hasTransferRelation) { + if ($this->isNotTransferTransaction()) { $actions[] = [ 'type' => 'divider', ]; diff --git a/app/Models/Setting/Category.php b/app/Models/Setting/Category.php index 962e4e795..b899e534a 100644 --- a/app/Models/Setting/Category.php +++ b/app/Models/Setting/Category.php @@ -7,6 +7,7 @@ use App\Builders\Category as Builder; use App\Models\Document\Document; use App\Relations\HasMany\Category as HasMany; use App\Scopes\Category as Scope; +use App\Traits\Categories; use App\Traits\Transactions; use Illuminate\Database\Eloquent\Builder as EloquentBuilder; use Illuminate\Database\Eloquent\Factories\HasFactory; @@ -14,7 +15,7 @@ use Illuminate\Database\Eloquent\Model as EloquentModel; class Category extends Model { - use HasFactory, Transactions; + use Categories, HasFactory, Transactions; public const INCOME_TYPE = 'income'; public const EXPENSE_TYPE = 'expense'; @@ -205,17 +206,6 @@ class Category extends Model return $query->where('name', '=', $name); } - /** - * Scope transfer category. - * - * @param \Illuminate\Database\Eloquent\Builder $query - * @return \Illuminate\Database\Eloquent\Builder - */ - public function scopeTransfer($query) - { - return (int) $query->other()->pluck('id')->first(); - } - /** * Scope gets only parent categories. * @@ -243,9 +233,7 @@ class Category extends Model 'permission' => 'update-settings-categories', ]; - $transfer_id = Category::transfer(); - - if ($this->id == $transfer_id) { + if ($this->isTransferCategory()) { return $actions; } diff --git a/app/Providers/Event.php b/app/Providers/Event.php index 05ad6759e..56bec2104 100644 --- a/app/Providers/Event.php +++ b/app/Providers/Event.php @@ -18,6 +18,7 @@ class Event extends Provider 'App\Listeners\Update\V30\Version300', 'App\Listeners\Update\V30\Version303', 'App\Listeners\Update\V30\Version304', + 'App\Listeners\Update\V30\Version305', ], 'Illuminate\Auth\Events\Login' => [ 'App\Listeners\Auth\Login', diff --git a/app/Traits/Categories.php b/app/Traits/Categories.php index 8f44a0fa1..dc2696259 100644 --- a/app/Traits/Categories.php +++ b/app/Traits/Categories.php @@ -7,7 +7,7 @@ use Illuminate\Support\Str; trait Categories { - public function getCategoryTypes() + public function getCategoryTypes(): array { $types = []; $configs = config('type.category'); @@ -27,8 +27,20 @@ trait Categories return $types; } - public function getCategoryWithoutChildren($id) + public function getCategoryWithoutChildren(int $id): mixed { - return Category::getWithoutChildren()->find($id);; + return Category::getWithoutChildren()->find($id); + } + + public function getTransferCategoryId(): mixed + { + return Category::other()->pluck('id')->first(); + } + + public function isTransferCategory(): bool + { + $id = $this->id ?? $this->category->id ?? $this->model->id ?? 0; + + return $id == $this->getTransferCategoryId(); } } diff --git a/app/Traits/Transactions.php b/app/Traits/Transactions.php index e53abae77..4f2b33853 100644 --- a/app/Traits/Transactions.php +++ b/app/Traits/Transactions.php @@ -4,14 +4,13 @@ namespace App\Traits; use App\Events\Banking\TransactionPrinting; use App\Models\Banking\Transaction; -use App\Models\Setting\Category; use Illuminate\Support\Str; trait Transactions { public function isIncome(): bool { - $type = $this->type ?? $this->transaction->type ?? $this->model->type ?? 'income'; + $type = $this->type ?? $this->transaction->type ?? $this->model->type ?? Transaction::INCOME_TYPE; return in_array($type, $this->getIncomeTypes()); } @@ -23,7 +22,7 @@ trait Transactions public function isExpense(): bool { - $type = $this->type ?? $this->transaction->type ?? $this->model->type ?? 'expense'; + $type = $this->type ?? $this->transaction->type ?? $this->model->type ?? Transaction::EXPENSE_TYPE; return in_array($type, $this->getExpenseTypes()); } @@ -35,7 +34,7 @@ trait Transactions public function isRecurringTransaction(): bool { - $type = $this->type ?? $this->transaction->type ?? $this->model->type ?? 'income'; + $type = $this->type ?? $this->transaction->type ?? $this->model->type ?? Transaction::INCOME_TYPE; return Str::endsWith($type, '-recurring'); } @@ -47,44 +46,44 @@ trait Transactions public function isTransferTransaction(): bool { - $category_id = $this->category_id ?? $this->transaction->category_id ?? $this->model->category_id ?? 0; + $type = $this->type ?? $this->transaction->type ?? $this->model->type ?? Transaction::INCOME_TYPE; - return $category_id == Category::transfer(); + return Str::endsWith($type, '-transfer'); } public function isNotTransferTransaction(): bool { - return ! $this->isTransfer(); + return ! $this->isTransferTransaction(); } - public function getIncomeTypes($return = 'array') + public function getIncomeTypes(string $return = 'array'): string|array { - return $this->getTransactionTypes('income', $return); + return $this->getTransactionTypes(Transaction::INCOME_TYPE, $return); } - public function getExpenseTypes($return = 'array') + public function getExpenseTypes(string $return = 'array'): string|array { - return $this->getTransactionTypes('expense', $return); + return $this->getTransactionTypes(Transaction::EXPENSE_TYPE, $return); } - public function getTransactionTypes($index, $return = 'array') + public function getTransactionTypes(string $index, string $return = 'array'): string|array { $types = (string) setting('transaction.type.' . $index); return ($return == 'array') ? explode(',', $types) : $types; } - public function addIncomeType($new_type) + public function addIncomeType(string $new_type): void { - $this->addTransactionType($new_type, 'income'); + $this->addTransactionType($new_type, Transaction::INCOME_TYPE); } - public function addExpenseType($new_type) + public function addExpenseType(string $new_type): void { - $this->addTransactionType($new_type, 'expense'); + $this->addTransactionType($new_type, Transaction::EXPENSE_TYPE); } - public function addTransactionType($new_type, $index) + public function addTransactionType(string $new_type, string $index): void { $types = explode(',', setting('transaction.type.' . $index)); @@ -109,7 +108,7 @@ trait Transactions return Str::slug($transaction->id, $separator, language()->getShortCode()); } - protected function getSettingKey($type, $setting_key) + protected function getSettingKey(string $type, string $setting_key): string { $key = ''; $alias = config('type.transaction.' . $type . '.alias'); @@ -125,7 +124,7 @@ trait Transactions return $key; } - public function storeTransactionPdfAndGetPath($transaction) + public function storeTransactionPdfAndGetPath(Transaction $transaction): string { event(new TransactionPrinting($transaction)); @@ -145,7 +144,7 @@ trait Transactions return $pdf_path; } - public function getTranslationsForConnect($type = 'income') + public function getTranslationsForConnect(string $type = Transaction::INCOME_TYPE): array { $document_type = config('type.transaction.' . $type . '.document_type'); $contact_type = config('type.transaction.' . $type . '.contact_type'); @@ -171,7 +170,7 @@ trait Transactions ]; } - public function getTransactionFormRoutesOfType($type) + public function getTransactionFormRoutesOfType(string $type): array { return [ 'contact_index' => route(Str::plural(config('type.transaction.' . $type . '.contact_type')) . '.index'), @@ -186,6 +185,11 @@ trait Transactions return Str::replace('-recurring', '', $recurring_type); } + public function getRealTypeOfTransferTransaction(string $transfer_type): string + { + return Str::replace('-transfer', '', $transfer_type); + } + public function getNextTransactionNumber($suffix = ''): string { $prefix = setting('transaction' . $suffix . '.number_prefix'); diff --git a/config/search-string.php b/config/search-string.php index d1f4690d2..56689d91d 100644 --- a/config/search-string.php +++ b/config/search-string.php @@ -109,6 +109,8 @@ return [ 'values' => [ 'income' => 'general.incomes', 'expense' => 'general.expenses', + //'income-transfer' => 'general.income_transfers', + //'expense-transfer' => 'general.expense_transfers', ], ], 'account_id' => [ diff --git a/config/setting.php b/config/setting.php index e94112ad7..2741bcdaf 100644 --- a/config/setting.php +++ b/config/setting.php @@ -1,5 +1,8 @@ [ 'type' => [ - 'customer' => env('SETTING_FALLBACK_CONTACT_TYPE_CUSTOMER', 'customer'), - 'vendor' => env('SETTING_FALLBACK_CONTACT_TYPE_VENDOR', 'vendor'), + 'customer' => env('SETTING_FALLBACK_CONTACT_TYPE_CUSTOMER', Contact::CUSTOMER_TYPE), + 'vendor' => env('SETTING_FALLBACK_CONTACT_TYPE_VENDOR', Contact::VENDOR_TYPE), ], ], 'transaction' => [ @@ -175,8 +178,8 @@ return [ 'number_digit' => env('SETTING_FALLBACK_TRANSACTION_NUMBER_DIGIT', '5'), 'number_next' => env('SETTING_FALLBACK_TRANSACTION_NUMBER_NEXT', '1'), 'type' => [ - 'income' => env('SETTING_FALLBACK_TRANSACTION_TYPE_INCOME', 'income'), - 'expense' => env('SETTING_FALLBACK_TRANSACTION_TYPE_EXPENSE', 'expense'), + 'income' => env('SETTING_FALLBACK_TRANSACTION_TYPE_INCOME', Transaction::INCOME_TYPE . ',' . Transaction::INCOME_TRANSFER_TYPE), + 'expense' => env('SETTING_FALLBACK_TRANSACTION_TYPE_EXPENSE', Transaction::EXPENSE_TYPE . ',' . Transaction::EXPENSE_TRANSFER_TYPE), ], ], 'transaction-recurring' => [ diff --git a/database/factories/Transfer.php b/database/factories/Transfer.php index 643ae77c6..fce6ce92c 100644 --- a/database/factories/Transfer.php +++ b/database/factories/Transfer.php @@ -7,9 +7,12 @@ use App\Models\Banking\Account; use App\Models\Banking\Transaction; use App\Models\Banking\Transfer as Model; use App\Models\Setting\Category; +use App\Traits\Categories; class Transfer extends Factory { + use Categories; + /** * The name of the factory's corresponding model. * @@ -40,19 +43,19 @@ class Transfer extends Factory $request = [ 'amount' => $this->faker->randomFloat(2, 1, 1000), 'paid_at' => $this->faker->dateTimeBetween(now()->startOfYear(), now()->endOfYear())->format('Y-m-d'), - 'category_id' => Category::transfer(), + 'category_id' => $this->getTransferCategoryId(), 'description' => $this->faker->text(20), 'reference' => $this->faker->text(20), 'created_from' => 'core::factory', ]; $expense_transaction = Transaction::factory()->create(array_merge($request, [ - 'type' => 'expense', + 'type' => Transaction::EXPENSE_TRANSFER_TYPE, 'account_id' => $expense_account->id, ])); $income_transaction = Transaction::factory()->create(array_merge($request, [ - 'type' => 'income', + 'type' => Transaction::INCOME_TRANSFER_TYPE, 'account_id' => $income_account->id, ])); diff --git a/resources/lang/en-GB/general.php b/resources/lang/en-GB/general.php index 9d025c80a..3eaf7196d 100644 --- a/resources/lang/en-GB/general.php +++ b/resources/lang/en-GB/general.php @@ -16,6 +16,8 @@ return [ 'vendors' => 'Vendor|Vendors', 'accounts' => 'Account|Accounts', 'transfers' => 'Transfer|Transfers', + 'income_transfers' => 'Income Transfer|Income Transfers', + 'expense_transfers' => 'Expense Transfer|Expense Transfers', 'transactions' => 'Transaction|Transactions', 'payments' => 'Payment|Payments', 'recurring_transactions'=> 'Recurring Transaction|Recurring Transactions', diff --git a/resources/views/components/transactions/show/buttons.blade.php b/resources/views/components/transactions/show/buttons.blade.php index d9f389ea2..5735884b0 100644 --- a/resources/views/components/transactions/show/buttons.blade.php +++ b/resources/views/components/transactions/show/buttons.blade.php @@ -10,7 +10,7 @@ @stack('edit_button_start') -@if (! $transaction->reconciled && ! $transaction->hasTransferRelation) +@if (! $transaction->reconciled && $transaction->isNotTransferTransaction()) @if (! $hideButtonEdit) @can($permissionUpdate) diff --git a/resources/views/components/transactions/show/more-buttons.blade.php b/resources/views/components/transactions/show/more-buttons.blade.php index 93529b01c..d14606933 100644 --- a/resources/views/components/transactions/show/more-buttons.blade.php +++ b/resources/views/components/transactions/show/more-buttons.blade.php @@ -8,7 +8,7 @@ @stack('duplicate_button_start') - @if (empty($transaction->document_id) && ! $transaction->hasTransferRelation) + @if (empty($transaction->document_id) && $transaction->isNotTransferTransaction()) @if (! $hideButtonDuplicate) @can($permissionCreate) @@ -22,7 +22,7 @@ @stack('connect_button_start') - @if ($transaction->is_splittable && empty($transaction->document_id) && empty($transaction->recurring) && ! $transaction->hasTransferRelation) + @if ($transaction->is_splittable && empty($transaction->document_id) && empty($transaction->recurring) && $transaction->isNotTransferTransaction()) @if (! $hideButtonConnect) @can($permissionCreate)