Expand API to accept liability accounts.

This commit is contained in:
James Cole 2018-08-26 21:29:46 +02:00
parent c4bbbc49b4
commit 3764499714
4 changed files with 82 additions and 40 deletions

View File

@ -221,6 +221,11 @@ class AccountController extends Controller
'special' => [AccountType::CASH, AccountType::INITIAL_BALANCE, AccountType::IMPORT, AccountType::RECONCILIATION, 'special' => [AccountType::CASH, AccountType::INITIAL_BALANCE, AccountType::IMPORT, AccountType::RECONCILIATION,
AccountType::LOAN,], AccountType::LOAN,],
'hidden' => [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::DEFAULT => [AccountType::DEFAULT],
AccountType::CASH => [AccountType::CASH], AccountType::CASH => [AccountType::CASH],
AccountType::ASSET => [AccountType::ASSET], AccountType::ASSET => [AccountType::ASSET],
@ -231,6 +236,10 @@ class AccountController extends Controller
AccountType::IMPORT => [AccountType::IMPORT], AccountType::IMPORT => [AccountType::IMPORT],
AccountType::RECONCILIATION => [AccountType::RECONCILIATION], AccountType::RECONCILIATION => [AccountType::RECONCILIATION],
AccountType::LOAN => [AccountType::LOAN], AccountType::LOAN => [AccountType::LOAN],
AccountType::MORTGAGE => [AccountType::MORTGAGE],
AccountType::DEBT => [AccountType::DEBT],
AccountType::CREDITCARD => [AccountType::CREDITCARD],
]; ];
$return = $types['all']; $return = $types['all'];
if (isset($types[$type])) { if (isset($types[$type])) {

View File

@ -50,6 +50,7 @@ class AccountRequest extends Request
$data = [ $data = [
'name' => $this->string('name'), 'name' => $this->string('name'),
'active' => $this->boolean('active'), 'active' => $this->boolean('active'),
'include_net_worth' => $this->boolean('include_net_worth'),
'accountType' => $this->string('type'), 'accountType' => $this->string('type'),
'account_type_id' => null, 'account_type_id' => null,
'currency_id' => $this->integer('currency_id'), 'currency_id' => $this->integer('currency_id'),
@ -64,7 +65,21 @@ class AccountRequest extends Request
'ccType' => $this->string('cc_type'), 'ccType' => $this->string('cc_type'),
'ccMonthlyPaymentDate' => $this->string('cc_monthly_payment_date'), 'ccMonthlyPaymentDate' => $this->string('cc_monthly_payment_date'),
'notes' => $this->string('notes'), '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; return $data;
} }
@ -91,10 +106,18 @@ class AccountRequest extends Request
'account_number' => 'between:1,255|nullable|uniqueAccountNumberForUser', 'account_number' => 'between:1,255|nullable|uniqueAccountNumberForUser',
'account_role' => 'in:' . $accountRoles . '|required_if:type,asset', 'account_role' => 'in:' . $accountRoles . '|required_if:type,asset',
'active' => 'required|boolean', 'active' => 'required|boolean',
'include_net_worth' => 'required|boolean',
'cc_type' => 'in:' . $ccPaymentTypes . '|required_if:account_role,ccAsset', 'cc_type' => 'in:' . $ccPaymentTypes . '|required_if:account_role,ccAsset',
'cc_monthly_payment_date' => 'date' . '|required_if:account_role,ccAsset|required_if:cc_type,monthlyFull', 'cc_monthly_payment_date' => 'date' . '|required_if:account_role,ccAsset|required_if:cc_type,monthlyFull',
'type' => 'required|in:' . $types, 'type' => 'required|in:' . $types,
'notes' => 'min:0|max:65536', '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()) { switch ($this->method()) {
default: default:

View File

@ -181,6 +181,7 @@ return [
'revenue' => 'Revenue accounts', 'revenue' => 'Revenue accounts',
'cash' => 'Cash accounts', 'cash' => 'Cash accounts',
'liabilities' => 'Liabilities', 'liabilities' => 'Liabilities',
'liability' => 'Liabilities',
], ],
'subIconsByIdentifier' => 'subIconsByIdentifier' =>
[ [
@ -215,6 +216,7 @@ return [
'import' => ['Import account'], 'import' => ['Import account'],
'reconcile' => ['Reconciliation account'], 'reconcile' => ['Reconciliation account'],
'liabilities' => ['Loan', 'Debt', 'Mortgage', 'Credit card'], 'liabilities' => ['Loan', 'Debt', 'Mortgage', 'Credit card'],
'liability' => ['Loan', 'Debt', 'Mortgage', 'Credit card'],
], ],
'shortNamesByFullName' => 'shortNamesByFullName' =>
[ [

View File

@ -129,6 +129,7 @@ class AccountControllerTest extends TestCase
'currency_id' => 1, 'currency_id' => 1,
'type' => 'asset', 'type' => 'asset',
'active' => 1, 'active' => 1,
'include_net_worth' => 1,
'account_role' => 'defaultAsset', 'account_role' => 'defaultAsset',
'opening_balance' => '123.45', 'opening_balance' => '123.45',
]; ];
@ -168,6 +169,7 @@ class AccountControllerTest extends TestCase
'name' => 'Some new asset account #' . random_int(1, 10000), 'name' => 'Some new asset account #' . random_int(1, 10000),
'type' => 'asset', 'type' => 'asset',
'active' => 1, 'active' => 1,
'include_net_worth' => 1,
'account_role' => 'ccAsset', 'account_role' => 'ccAsset',
'currency_id' => 1, 'currency_id' => 1,
]; ];
@ -208,6 +210,7 @@ class AccountControllerTest extends TestCase
'name' => 'Some new asset account #' . random_int(1, 10000), 'name' => 'Some new asset account #' . random_int(1, 10000),
'type' => 'asset', 'type' => 'asset',
'active' => 1, 'active' => 1,
'include_net_worth' => 1,
'account_role' => 'defaultAsset', 'account_role' => 'defaultAsset',
]; ];
@ -284,6 +287,7 @@ class AccountControllerTest extends TestCase
'currency_id' => 1, 'currency_id' => 1,
'type' => 'asset', 'type' => 'asset',
'active' => 1, 'active' => 1,
'include_net_worth' => 1,
'account_role' => 'defaultAsset', 'account_role' => 'defaultAsset',
]; ];
@ -332,6 +336,7 @@ class AccountControllerTest extends TestCase
'currency_id' => 1, 'currency_id' => 1,
'type' => 'asset', 'type' => 'asset',
'active' => 1, 'active' => 1,
'include_net_worth' => 1,
'account_role' => 'defaultAsset', 'account_role' => 'defaultAsset',
]; ];
@ -378,6 +383,7 @@ class AccountControllerTest extends TestCase
'currency_code' => 'EUR', 'currency_code' => 'EUR',
'type' => 'asset', 'type' => 'asset',
'active' => 1, 'active' => 1,
'include_net_worth' => 1,
'account_role' => 'defaultAsset', 'account_role' => 'defaultAsset',
]; ];
@ -421,6 +427,7 @@ class AccountControllerTest extends TestCase
'currency_id' => 1, 'currency_id' => 1,
'type' => 'asset', 'type' => 'asset',
'active' => 1, 'active' => 1,
'include_net_worth' => 1,
'account_role' => 'defaultAsset', 'account_role' => 'defaultAsset',
]; ];
@ -465,6 +472,7 @@ class AccountControllerTest extends TestCase
'currency_code' => 'EUR', 'currency_code' => 'EUR',
'type' => 'asset', 'type' => 'asset',
'active' => 1, 'active' => 1,
'include_net_worth' => 1,
'account_role' => 'defaultAsset', 'account_role' => 'defaultAsset',
]; ];