Firefly III: a personal finances manager
PHP accountingbudgetbudgetingbudgetscash-flowcashflowcredit-carddockerexpensesfinancefinancesfinanciallinuxmoneypaycheckpersonal-financephpphp7
Update / create methods can handle order #3200
James Cole74247c292ff6
diff --git a/app/Factory/AccountFactory.php b/app/Factory/AccountFactory.phpindex c5a1d4bdff..d7cf4e2665 100644--- a/app/Factory/AccountFactory.php+++ b/app/Factory/AccountFactory.php@@ -43,17 +43,12 @@ class AccountFactoryuse AccountServiceTrait, LocationServiceTrait;/** @var AccountRepositoryInterface */- protected $accountRepository;- /** @var array */- protected $validAssetFields = ['account_role', 'account_number', 'currency_id', 'BIC', 'include_net_worth'];- /** @var array */- protected $validCCFields = ['account_role', 'cc_monthly_payment_date', 'cc_type', 'account_number', 'currency_id', 'BIC', 'include_net_worth'];- /** @var array */- protected $validFields = ['account_number', 'currency_id', 'BIC', 'interest', 'interest_period', 'include_net_worth'];- /** @var array */- private $canHaveVirtual;- /** @var User */- private $user;+ protected $accountRepository;+ protected array $validAssetFields;+ protected array $validCCFields;+ protected array $validFields;+ private array $canHaveVirtual;+ private User $user;/*** AccountFactory constructor.@@ -67,6 +62,10 @@ class AccountFactory}$this->canHaveVirtual = [AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD];$this->accountRepository = app(AccountRepositoryInterface::class);+ $this->validAssetFields = ['account_role', 'account_number', 'currency_id', 'BIC', 'include_net_worth'];+ $this->validCCFields = ['account_role', 'cc_monthly_payment_date', 'cc_type', 'account_number', 'currency_id', 'BIC', 'include_net_worth'];+ $this->validFields = ['account_number', 'currency_id', 'BIC', 'interest', 'interest_period', 'include_net_worth'];+}/**@@ -98,6 +97,7 @@ class AccountFactory'user_id' => $this->user->id,'account_type_id' => $type->id,'name' => $data['name'],+ 'order' => $data['order'] ?? 0,'virtual_balance' => $data['virtual_balance'] ?? null,'active' => true === $data['active'],'iban' => $data['iban'],diff --git a/app/Repositories/Account/AccountRepository.php b/app/Repositories/Account/AccountRepository.phpindex 24e499ae20..06f6aef7aa 100644--- a/app/Repositories/Account/AccountRepository.php+++ b/app/Repositories/Account/AccountRepository.php@@ -274,12 +274,11 @@ class AccountRepository implements AccountRepositoryInterfaceif (count($accountIds) > 0) {$query->whereIn('accounts.id', $accountIds);}+ $query->orderBy('accounts.order', 'ASC');$query->orderBy('accounts.active', 'DESC');$query->orderBy('accounts.name', 'ASC');- $result = $query->get(['accounts.*']);-- return $result;+ return $query->get(['accounts.*']);}/**@@ -294,12 +293,12 @@ class AccountRepository implements AccountRepositoryInterfaceif (count($types) > 0) {$query->accountTypeIn($types);}+ $query->orderBy('accounts.order', 'ASC');$query->orderBy('accounts.active', 'DESC');$query->orderBy('accounts.name', 'ASC');- $result = $query->get(['accounts.*']);+ return $query->get(['accounts.*']);- return $result;}/**@@ -320,6 +319,7 @@ class AccountRepository implements AccountRepositoryInterface}$query->where('active', 1);$query->orderBy('accounts.account_type_id', 'ASC');+ $query->orderBy('accounts.order', 'ASC');$query->orderBy('accounts.name', 'ASC');return $query->get(['accounts.*']);@@ -567,6 +567,7 @@ class AccountRepository implements AccountRepositoryInterface{$dbQuery = $this->user->accounts()->where('active', 1)+ ->orderBy('accounts.order', 'ASC')->orderBy('accounts.name', 'ASC')->with(['accountType']);if ('' !== $query) {@@ -643,6 +644,7 @@ class AccountRepository implements AccountRepositoryInterface}$query->where('active', 0);$query->orderBy('accounts.account_type_id', 'ASC');+ $query->orderBy('accounts.order', 'ASC');$query->orderBy('accounts.name', 'ASC');return $query->get(['accounts.*']);diff --git a/app/Services/Internal/Update/AccountUpdateService.php b/app/Services/Internal/Update/AccountUpdateService.phpindex f8a88c3b87..98ac40418c 100644--- a/app/Services/Internal/Update/AccountUpdateService.php+++ b/app/Services/Internal/Update/AccountUpdateService.php@@ -38,18 +38,12 @@ class AccountUpdateService{use AccountServiceTrait;- /** @var AccountRepositoryInterface */- protected $accountRepository;- /** @var array */- protected $validAssetFields = ['account_role', 'account_number', 'currency_id', 'BIC', 'include_net_worth'];- /** @var array */- protected $validCCFields = ['account_role', 'cc_monthly_payment_date', 'cc_type', 'account_number', 'currency_id', 'BIC', 'include_net_worth'];- /** @var array */- protected $validFields = ['account_number', 'currency_id', 'BIC', 'interest', 'interest_period', 'include_net_worth'];- /** @var array */- private $canHaveVirtual;- /** @var User */- private $user;+ protected AccountRepositoryInterface $accountRepository;+ protected array $validAssetFields;+ protected array $validCCFields;+ protected array $validFields;+ private array $canHaveVirtual;+ private User $user;/*** Constructor.@@ -62,6 +56,9 @@ class AccountUpdateService// TODO move to configuration.$this->canHaveVirtual = [AccountType::ASSET, AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD];$this->accountRepository = app(AccountRepositoryInterface::class);+ $this->validAssetFields = ['account_role', 'account_number', 'currency_id', 'BIC', 'include_net_worth'];+ $this->validCCFields = ['account_role', 'cc_monthly_payment_date', 'cc_type', 'account_number', 'currency_id', 'BIC', 'include_net_worth'];+ $this->validFields = ['account_number', 'currency_id', 'BIC', 'interest', 'interest_period', 'include_net_worth'];}/**@@ -174,6 +171,7 @@ class AccountUpdateService$account->name = $data['name'] ?? $account->name;$account->active = $data['active'] ?? $account->active;$account->iban = $data['iban'] ?? $account->iban;+ $account->order = $data['order'] ?? $account->order;// if account type is a liability, the liability type (account type)// can be updated to another one.diff --git a/app/Transformers/AccountTransformer.php b/app/Transformers/AccountTransformer.phpindex dd46dd8b75..6b4fa49009 100644--- a/app/Transformers/AccountTransformer.php+++ b/app/Transformers/AccountTransformer.php@@ -96,10 +96,11 @@ class AccountTransformer extends AbstractTransformer$zoomLevel = $location->zoom_level;}return [- 'id' => (int)$account->id,+ 'id' => (int) $account->id,'created_at' => $account->created_at->toAtomString(),'updated_at' => $account->updated_at->toAtomString(),'active' => $account->active,+ 'order' => $account->order,'name' => $account->name,'type' => $accountType,'account_role' => $accountRole,