Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dev/core#1558 retrieve setting credit_notes_prefix as a 'real' setting. #16397

Merged
merged 1 commit into from
Feb 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions CRM/Contribute/BAO/Contribution.php
Original file line number Diff line number Diff line change
Expand Up @@ -4693,16 +4693,17 @@ public static function generateFromEmailAndName($input, $contribution) {
*
* @return string
* Credit Note Id.
*
* @throws \CiviCRM_API3_Exception
*/
public static function createCreditNoteId() {
$prefixValue = Civi::settings()->get('contribution_invoice_settings');

$creditNoteNum = CRM_Core_DAO::singleValueQuery("SELECT count(creditnote_id) as creditnote_number FROM civicrm_contribution WHERE creditnote_id IS NOT NULL");
$creditNoteId = NULL;

do {
$creditNoteNum++;
$creditNoteId = CRM_Utils_Array::value('credit_notes_prefix', $prefixValue) . "" . $creditNoteNum;
$creditNoteId = Civi::settings()->get('credit_notes_prefix') . '' . $creditNoteNum;
$result = civicrm_api3('Contribution', 'getcount', [
'sequential' => 1,
'creditnote_id' => $creditNoteId,
Expand Down
1 change: 0 additions & 1 deletion api/v3/examples/Setting/GetFields.ex.php
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,6 @@ function setting_getfields_expectedresult() {
'type' => 'Array',
'default' => [
'invoice_prefix' => 'INV_',
'credit_notes_prefix' => 'CN_',
'due_date' => '10',
'due_date_period' => 'days',
'notes' => '',
Expand Down
1 change: 0 additions & 1 deletion tests/phpunit/CiviTest/CiviUnitTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -3025,7 +3025,6 @@ protected function enableTaxAndInvoicing($params = []) {
[
'invoicing' => 1,
'invoice_prefix' => 'INV_',
'credit_notes_prefix' => 'CN_',
'due_date' => 10,
'due_date_period' => 'days',
'notes' => '',
Expand Down
8 changes: 3 additions & 5 deletions tests/phpunit/api/v3/ContributionTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1645,12 +1645,11 @@ public function testCreateUpdateContributionInValidStatusChange() {

/**
* Function tests that financial records are added when Pending Contribution is Canceled.
*
* @throws \CRM_Core_Exception
*/
public function testCreateUpdateContributionCancelPending() {
// Enable & disable invoicing just to standardise the credit note id setting.
// Longer term we want to separate that setting from 'taxAndInvoicing'.
// and / or remove from core.
$this->enableTaxAndInvoicing();
Civi::settings()->set('credit_notes_prefix', 'CN_');
$contribParams = [
'contact_id' => $this->_individualId,
'receive_date' => '2012-01-01',
Expand All @@ -1675,7 +1674,6 @@ public function testCreateUpdateContributionCancelPending() {
$this->_checkFinancialTrxn($contribution, 'cancelPending', NULL, $checkTrxnDate);
$this->_checkFinancialItem($contribution['id'], 'cancelPending');
$this->assertEquals('CN_1', $contribution['values'][$contribution['id']]['creditnote_id']);
$this->disableTaxAndInvoicing();
}

/**
Expand Down