Skip to content

Commit

Permalink
Add missing financial type to 'In-kind' fund
Browse files Browse the repository at this point in the history
  • Loading branch information
monishdeb committed Apr 20, 2020
1 parent fa9191a commit b9b1604
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
16 changes: 12 additions & 4 deletions CRM/Cdntaxreceipts/Upgrader.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public function upgrade_1321() {
CRM_Core_DAO::executeQuery('ALTER TABLE cdntaxreceipts_log ADD email_opened datetime NULL');
CRM_Core_DAO::executeQuery('CREATE INDEX contribution_id ON cdntaxreceipts_log_contributions (contribution_id)');
return TRUE;
}
}

public function upgrade_1322() {
$this->ctx->log->info('Applying update 1322: Message Templates');
Expand All @@ -90,7 +90,7 @@ public function upgrade_1410() {
}

public function upgrade_1510() {
$this->ctx->log->info('Applying update 1510: Adding gift advantage description table');
$this->ctx->log->info('Applying update 1510: Adding gift advantage description table and adding missing financial accounts to "In-Kind" fund ');
$sql = "CREATE TABLE IF NOT EXISTS cdntaxreceipts_advantage (
id int(11) UNSIGNED NOT NULL AUTO_INCREMENT,
contribution_id int(10) UNSIGNED NOT NULL,
Expand All @@ -99,10 +99,18 @@ public function upgrade_1510() {
INDEX contribution_id (contribution_id)
)";
CRM_Core_DAO::executeQuery($sql);
return TRUE;
}

// add missing GL account to In-kind fund
require_once 'CRM/Financial/DAO/FinancialType.php';
$financialType = new CRM_Financial_DAO_FinancialType();
$financialType->name = 'In-kind';

if ($financialType->find(TRUE)) {
CRM_Financial_BAO_FinancialTypeAccount::createDefaultFinancialAccounts($financialType);

This comment has been minimized.

Copy link
@JoeMurray

JoeMurray Apr 20, 2020

Member

Creating a Financial Account with same name as 'In-kind' Financial Type, creating relationships to the default Accounts Receivable Account and default Expense Account are all correct. However, we don't want any Cost of Sales Accounts to ever be created by DMS. Maybe deleting after call this core function is an okay work-around.

}

return TRUE;
}

function _create_message_template($email_message, $email_subject) {

Expand Down
20 changes: 6 additions & 14 deletions cdntaxreceipts.functions.inc
Original file line number Diff line number Diff line change
Expand Up @@ -590,20 +590,12 @@ function _cdntaxreceipts_writeReceipt(&$pdf, $pdf_variables) {
*/

function cdntaxreceipts_configure_inkind_fields() {
$financialTypeID = civicrm_api3('FinancialType', 'create', [
'name' => 'In-kind',
'is_deductible' => TRUE,
'is_active' => TRUE,
])['id'];

// check if the In-kind contribution type exists. if not, create it.
require_once 'CRM/Financial/DAO/FinancialType.php';
$dao = new CRM_Financial_DAO_FinancialType();
$dao->name = 'In-kind';

if ( ! $dao->find(true) ) {
$dao->name = 'In-kind';
$dao->is_deductible = TRUE;
$dao->is_active = TRUE;
$dao->save();
}

$contrib_type_id = $dao->id;

// check if the custom group exists. if not, create it.
$params = array(
Expand All @@ -618,7 +610,7 @@ function cdntaxreceipts_configure_inkind_fields() {
$group = array(
'title' => 'In-kind donation fields',
'extends' => array( 'Contribution' ),
'extends_entity_column_value' => array( $contrib_type_id ),
'extends_entity_column_value' => [$financialTypeID],
'collapse_display' => 0,
'style' => 'Inline',
'is_active' => 1,
Expand Down

0 comments on commit b9b1604

Please sign in to comment.