diff --git a/app/Api/V1/Controllers/AccountController.php b/app/Api/V1/Controllers/AccountController.php index 9fef764538..bf3213cbd2 100644 --- a/app/Api/V1/Controllers/AccountController.php +++ b/app/Api/V1/Controllers/AccountController.php @@ -221,6 +221,11 @@ class AccountController extends Controller 'special' => [AccountType::CASH, AccountType::INITIAL_BALANCE, AccountType::IMPORT, AccountType::RECONCILIATION, AccountType::LOAN,], 'hidden' => [AccountType::INITIAL_BALANCE, AccountType::IMPORT, AccountType::RECONCILIATION, AccountType::LOAN,], + 'liability' => [AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD], + 'liabilities' => [AccountType::DEBT, AccountType::LOAN, AccountType::MORTGAGE, AccountType::CREDITCARD], + 'cc' => [AccountType::CREDITCARD], + 'creditcard' => [AccountType::CREDITCARD], + 'credit_card' => [AccountType::CREDITCARD], AccountType::DEFAULT => [AccountType::DEFAULT], AccountType::CASH => [AccountType::CASH], AccountType::ASSET => [AccountType::ASSET], @@ -231,6 +236,10 @@ class AccountController extends Controller AccountType::IMPORT => [AccountType::IMPORT], AccountType::RECONCILIATION => [AccountType::RECONCILIATION], AccountType::LOAN => [AccountType::LOAN], + AccountType::MORTGAGE => [AccountType::MORTGAGE], + AccountType::DEBT => [AccountType::DEBT], + AccountType::CREDITCARD => [AccountType::CREDITCARD], + ]; $return = $types['all']; if (isset($types[$type])) { diff --git a/app/Api/V1/Requests/AccountRequest.php b/app/Api/V1/Requests/AccountRequest.php index db0feadf7e..52d1db7726 100644 --- a/app/Api/V1/Requests/AccountRequest.php +++ b/app/Api/V1/Requests/AccountRequest.php @@ -50,6 +50,7 @@ class AccountRequest extends Request $data = [ 'name' => $this->string('name'), 'active' => $this->boolean('active'), + 'include_net_worth' => $this->boolean('include_net_worth'), 'accountType' => $this->string('type'), 'account_type_id' => null, 'currency_id' => $this->integer('currency_id'), @@ -64,7 +65,21 @@ class AccountRequest extends Request 'ccType' => $this->string('cc_type'), 'ccMonthlyPaymentDate' => $this->string('cc_monthly_payment_date'), 'notes' => $this->string('notes'), + 'interest' => $this->string('interest'), + 'interest_period' => $this->string('interest_period'), ]; + // new fields for liabilities + // 'liability_type' => $this->string('liability_type'), + // 'liability_start_date' => $this->date('liability_start_date'), + + + //]; + if ('liability' === $data['accountType']) { + $data['openingBalance'] = bcmul($this->string('liability_amount'), '-1'); + $data['openingBalanceDate'] = $this->date('liability_start_date'); + $data['accountType'] = $this->string('liability_type'); + $data['account_type_id'] = null; + } return $data; } @@ -91,10 +106,18 @@ class AccountRequest extends Request 'account_number' => 'between:1,255|nullable|uniqueAccountNumberForUser', 'account_role' => 'in:' . $accountRoles . '|required_if:type,asset', 'active' => 'required|boolean', + 'include_net_worth' => 'required|boolean', 'cc_type' => 'in:' . $ccPaymentTypes . '|required_if:account_role,ccAsset', 'cc_monthly_payment_date' => 'date' . '|required_if:account_role,ccAsset|required_if:cc_type,monthlyFull', 'type' => 'required|in:' . $types, 'notes' => 'min:0|max:65536', + // required fields for liabilities: + 'liability_type' => 'required_if:type,liability|in:loan,debt,mortgage,credit card', + 'liability_amount' => 'required_if:type,liability|min:0|numeric', + 'liability_start_date' => 'required_if:type,liability|date', + 'interest' => 'required_if:type,liability|between:0,100|numeric', + 'interest_period' => 'required_if:type,liability|in:daily,monthly,yearly', + ]; switch ($this->method()) { default: diff --git a/config/firefly.php b/config/firefly.php index ab4dfec039..c182081c1e 100644 --- a/config/firefly.php +++ b/config/firefly.php @@ -181,6 +181,7 @@ return [ 'revenue' => 'Revenue accounts', 'cash' => 'Cash accounts', 'liabilities' => 'Liabilities', + 'liability' => 'Liabilities', ], 'subIconsByIdentifier' => [ @@ -215,6 +216,7 @@ return [ 'import' => ['Import account'], 'reconcile' => ['Reconciliation account'], 'liabilities' => ['Loan', 'Debt', 'Mortgage', 'Credit card'], + 'liability' => ['Loan', 'Debt', 'Mortgage', 'Credit card'], ], 'shortNamesByFullName' => [ diff --git a/tests/Api/V1/Controllers/AccountControllerTest.php b/tests/Api/V1/Controllers/AccountControllerTest.php index a35fbd0def..d2d92c1dc2 100644 --- a/tests/Api/V1/Controllers/AccountControllerTest.php +++ b/tests/Api/V1/Controllers/AccountControllerTest.php @@ -125,12 +125,13 @@ class AccountControllerTest extends TestCase // data to submit $data = [ - 'name' => 'Some new asset account #' . random_int(1, 10000), - 'currency_id' => 1, - 'type' => 'asset', - 'active' => 1, - 'account_role' => 'defaultAsset', - 'opening_balance' => '123.45', + 'name' => 'Some new asset account #' . random_int(1, 10000), + 'currency_id' => 1, + 'type' => 'asset', + 'active' => 1, + 'include_net_worth' => 1, + 'account_role' => 'defaultAsset', + 'opening_balance' => '123.45', ]; // test API @@ -165,11 +166,12 @@ class AccountControllerTest extends TestCase // data to submit $data = [ - 'name' => 'Some new asset account #' . random_int(1, 10000), - 'type' => 'asset', - 'active' => 1, - 'account_role' => 'ccAsset', - 'currency_id' => 1, + 'name' => 'Some new asset account #' . random_int(1, 10000), + 'type' => 'asset', + 'active' => 1, + 'include_net_worth' => 1, + 'account_role' => 'ccAsset', + 'currency_id' => 1, ]; // test API @@ -205,10 +207,11 @@ class AccountControllerTest extends TestCase // data to submit $data = [ - 'name' => 'Some new asset account #' . random_int(1, 10000), - 'type' => 'asset', - 'active' => 1, - 'account_role' => 'defaultAsset', + 'name' => 'Some new asset account #' . random_int(1, 10000), + 'type' => 'asset', + 'active' => 1, + 'include_net_worth' => 1, + 'account_role' => 'defaultAsset', ]; // test API @@ -280,11 +283,12 @@ class AccountControllerTest extends TestCase $account = $this->user()->accounts()->where('account_type_id', 3)->first(); // data to submit $data = [ - 'name' => $account->name, - 'currency_id' => 1, - 'type' => 'asset', - 'active' => 1, - 'account_role' => 'defaultAsset', + 'name' => $account->name, + 'currency_id' => 1, + 'type' => 'asset', + 'active' => 1, + 'include_net_worth' => 1, + 'account_role' => 'defaultAsset', ]; // test API @@ -328,11 +332,12 @@ class AccountControllerTest extends TestCase // data to submit $data = [ - 'name' => 'Some new asset account #' . random_int(1, 10000), - 'currency_id' => 1, - 'type' => 'asset', - 'active' => 1, - 'account_role' => 'defaultAsset', + 'name' => 'Some new asset account #' . random_int(1, 10000), + 'currency_id' => 1, + 'type' => 'asset', + 'active' => 1, + 'include_net_worth' => 1, + 'account_role' => 'defaultAsset', ]; // test API @@ -374,11 +379,12 @@ class AccountControllerTest extends TestCase // data to submit $data = [ - 'name' => 'Some new asset account #' . random_int(1, 10000), - 'currency_code' => 'EUR', - 'type' => 'asset', - 'active' => 1, - 'account_role' => 'defaultAsset', + 'name' => 'Some new asset account #' . random_int(1, 10000), + 'currency_code' => 'EUR', + 'type' => 'asset', + 'active' => 1, + 'include_net_worth' => 1, + 'account_role' => 'defaultAsset', ]; // test API @@ -417,11 +423,12 @@ class AccountControllerTest extends TestCase $account = $this->user()->accounts()->first(); // data to submit $data = [ - 'name' => $account->name, - 'currency_id' => 1, - 'type' => 'asset', - 'active' => 1, - 'account_role' => 'defaultAsset', + 'name' => $account->name, + 'currency_id' => 1, + 'type' => 'asset', + 'active' => 1, + 'include_net_worth' => 1, + 'account_role' => 'defaultAsset', ]; // test API @@ -461,11 +468,12 @@ class AccountControllerTest extends TestCase $account = $this->user()->accounts()->first(); // data to submit $data = [ - 'name' => $account->name, - 'currency_code' => 'EUR', - 'type' => 'asset', - 'active' => 1, - 'account_role' => 'defaultAsset', + 'name' => $account->name, + 'currency_code' => 'EUR', + 'type' => 'asset', + 'active' => 1, + 'include_net_worth' => 1, + 'account_role' => 'defaultAsset', ]; // test API