From 3fa7fbd2500ed6ffa9569d2b2a6e8aea4c66322e Mon Sep 17 00:00:00 2001 From: eileen Date: Tue, 29 Dec 2020 14:22:18 +1300 Subject: [PATCH] Add v4 api for financial type, financial account --- Civi/Api4/FinancialAccount.php | 32 +++++++++++++++ Civi/Api4/FinancialType.php | 32 +++++++++++++++ .../Financial/BAO/FinancialAccountTest.php | 40 ++++++++++--------- 3 files changed, 86 insertions(+), 18 deletions(-) create mode 100644 Civi/Api4/FinancialAccount.php create mode 100644 Civi/Api4/FinancialType.php diff --git a/Civi/Api4/FinancialAccount.php b/Civi/Api4/FinancialAccount.php new file mode 100644 index 0000000000..53bb3af33f --- /dev/null +++ b/Civi/Api4/FinancialAccount.php @@ -0,0 +1,32 @@ +setValues([ 'name' => 'Donation Test', - 'is_active' => 1, - 'is_deductible' => 1, 'is_reserved' => 1, - ]; - $financialType = CRM_Financial_BAO_FinancialType::add($params); - $defaults = []; - $params = [ - 'name' => 'Donation Test', - 'is_active' => 1, - ]; - $result = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults); + ])->execute()->first(); + + $financialAccount = FinancialAccount::get(FALSE)->setWhere([ + ['name', '=', 'Donation Test'], + ['is_active', '=', TRUE], + ])->setSelect(['id'])->execute()->first(); $contactId = $this->individualCreate(); $contributionParams = [ 'total_amount' => 300, 'currency' => 'USD', 'contact_id' => $contactId, - 'financial_type_id' => $financialType->id, + 'financial_type_id' => $financialType['id'], 'contribution_status_id' => 1, ]; $this->callAPISuccess('Contribution', 'create', $contributionParams); - CRM_Financial_BAO_FinancialAccount::del($result->id); - $params = ['id' => $result->id]; - $result = CRM_Financial_BAO_FinancialAccount::retrieve($params, $defaults); - $this->assertEquals(empty($result), FALSE, 'Verify financial account record deletion.'); + CRM_Financial_BAO_FinancialAccount::del($financialAccount['id']); + + $this->assertCount(1, FinancialAccount::get(FALSE)->setWhere([ + ['id', '=', $financialAccount['id']], + ])->selectRowCount()->execute(), 'Financial account should not be deleted as it is in use.'); } /** -- 2.25.1