converted transfer check from category to type
This commit is contained in:
parent
16c645b4a0
commit
5a7697f741
@ -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'));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -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)
|
||||
{
|
||||
@ -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'],
|
||||
|
@ -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'),
|
||||
|
@ -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');
|
||||
}
|
||||
}
|
||||
|
@ -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'),
|
||||
]);
|
||||
|
95
app/Listeners/Update/V30/Version305.php
Normal file
95
app/Listeners/Update/V30/Version305.php
Normal file
@ -0,0 +1,95 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Update\V30;
|
||||
|
||||
use App\Abstracts\Listeners\Update as Listener;
|
||||
use App\Events\Install\UpdateFinished as Event;
|
||||
use App\Models\Banking\Transaction;
|
||||
use Illuminate\Support\Facades\Artisan;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class Version305 extends Listener
|
||||
{
|
||||
const ALIAS = 'core';
|
||||
|
||||
const VERSION = '3.0.5';
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle(Event $event)
|
||||
{
|
||||
if ($this->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.');
|
||||
}
|
||||
}
|
@ -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',
|
||||
];
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -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',
|
||||
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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');
|
||||
|
@ -109,6 +109,8 @@ return [
|
||||
'values' => [
|
||||
'income' => 'general.incomes',
|
||||
'expense' => 'general.expenses',
|
||||
//'income-transfer' => 'general.income_transfers',
|
||||
//'expense-transfer' => 'general.expense_transfers',
|
||||
],
|
||||
],
|
||||
'account_id' => [
|
||||
|
@ -1,5 +1,8 @@
|
||||
<?php
|
||||
|
||||
use App\Models\Common\Contact;
|
||||
use App\Models\Banking\Transaction;
|
||||
|
||||
return [
|
||||
|
||||
/*
|
||||
@ -166,8 +169,8 @@ return [
|
||||
],
|
||||
'contact' => [
|
||||
'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' => [
|
||||
|
@ -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,
|
||||
]));
|
||||
|
||||
|
@ -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',
|
||||
|
@ -10,7 +10,7 @@
|
||||
|
||||
@stack('edit_button_start')
|
||||
|
||||
@if (! $transaction->reconciled && ! $transaction->hasTransferRelation)
|
||||
@if (! $transaction->reconciled && $transaction->isNotTransferTransaction())
|
||||
@if (! $hideButtonEdit)
|
||||
@can($permissionUpdate)
|
||||
<x-link href="{{ route($routeButtonEdit, [$transaction->id, 'type' => $type]) }}">
|
||||
|
@ -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)
|
||||
<x-dropdown.link href="{{ route($routeButtonDuplicate, [$transaction->id, 'type' => $type]) }}">
|
||||
@ -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)
|
||||
<button
|
||||
@ -38,7 +38,7 @@
|
||||
|
||||
@stack('connect_button_end')
|
||||
|
||||
@if (! $hideDivider1 && ! $transaction->hasTransferRelation)
|
||||
@if (! $hideDivider1 && $transaction->isNotTransferTransaction())
|
||||
<x-dropdown.divider />
|
||||
@endif
|
||||
|
||||
@ -62,13 +62,13 @@
|
||||
|
||||
@stack('button_pdf_end')
|
||||
|
||||
@if (! $hideDivider2 && ! $transaction->hasTransferRelation)
|
||||
@if (! $hideDivider2 && $transaction->isNotTransferTransaction())
|
||||
<x-dropdown.divider />
|
||||
@endif
|
||||
|
||||
@stack('share_button_start')
|
||||
|
||||
@if (! $transaction->hasTransferRelation)
|
||||
@if ($transaction->isNotTransferTransaction())
|
||||
@if (! $hideButtonShare)
|
||||
<x-dropdown.button @click="onShareLink('{{ route($shareRoute, $transaction->id) }}')">
|
||||
{{ trans('general.share_link') }}
|
||||
@ -80,7 +80,7 @@
|
||||
|
||||
@stack('email_button_start')
|
||||
|
||||
@if (! $transaction->hasTransferRelation)
|
||||
@if ($transaction->isNotTransferTransaction())
|
||||
@if (! $hideButtonEmail)
|
||||
@if (! empty($transaction->contact) && $transaction->contact->email)
|
||||
<x-dropdown.button @click="onEmail('{{ route($routeButtonEmail, $transaction->id) }}')">
|
||||
@ -98,7 +98,7 @@
|
||||
|
||||
@stack('email_button_end')
|
||||
|
||||
@if (! $hideDivider3 && ! $transaction->hasTransferRelation)
|
||||
@if (! $hideDivider3 && $transaction->isNotTransferTransaction())
|
||||
<x-dropdown.divider />
|
||||
@endif
|
||||
|
||||
@ -112,13 +112,13 @@
|
||||
|
||||
@stack('button_end_end')
|
||||
|
||||
@if (! $hideDivider4 && ! $transaction->hasTransferRelation)
|
||||
@if (! $hideDivider4 && $transaction->isNotTransferTransaction())
|
||||
<x-dropdown.divider />
|
||||
@endif
|
||||
|
||||
@stack('delete_button_start')
|
||||
|
||||
@if (! $transaction->hasTransferRelation)
|
||||
@if ($transaction->isNotTransferTransaction())
|
||||
@if (! $hideButtonDelete)
|
||||
@can($permissionDelete)
|
||||
@if ($checkButtonReconciled)
|
||||
|
@ -1,4 +1,4 @@
|
||||
@if ($transaction->hasTransferRelation)
|
||||
@if ($transaction->isTransferTransaction())
|
||||
@php
|
||||
$from_account = '<span class="font-medium">' . $transaction->transfer->expense_account->title . '</span>';
|
||||
$to_account = '<span class="font-medium">' . $transaction->transfer->income_account->title . '</span>';
|
||||
|
Loading…
x
Reference in New Issue
Block a user