From 7eb74d3d593830664c70064ae7980da6e38cd385 Mon Sep 17 00:00:00 2001 From: Vimal Joseph Date: Mon, 29 Dec 2014 00:15:34 +0530 Subject: [PATCH] Feature to create progress bar based on the financial type. Add financial type to the progress bar interface. Now it is possible to create progress bar which pull data from the contribution table based on the financial types available in the system. The contribution pages as well as financial types work together. Need to add validation on the progress bar creation interface to make the user either select a financial type or a contribution page. --- CRM/Wci/BAO/ProgressBar.php | 1 + CRM/Wci/Form/ProgressBar.php | 81 +++++++++++++++++++++++++----------- CRM/Wci/Upgrader.php | 16 +++++++ js/addmore.js | 14 +++++++ sql/install.sql | 5 ++- wci-helper-functions.php | 12 ++++++ 6 files changed, 103 insertions(+), 26 deletions(-) diff --git a/CRM/Wci/BAO/ProgressBar.php b/CRM/Wci/BAO/ProgressBar.php index bff02bc..44dd430 100644 --- a/CRM/Wci/BAO/ProgressBar.php +++ b/CRM/Wci/BAO/ProgressBar.php @@ -65,6 +65,7 @@ class CRM_Wci_BAO_ProgressBar extends CRM_Wci_DAO_ProgressBar { FROM civicrm_wci_progress_bar_formula wcipb JOIN civicrm_contribution civicontrib ON wcipb.contribution_page_id = civicontrib.contribution_page_id + OR wcipb.financial_type_id = civicontrib.financial_type_id WHERE civicontrib.contribution_status_id = 1 AND (DATE(civicontrib.receive_date) >= if(wcipb.start_date is not NULL, wcipb.start_date, '0000-00-00') diff --git a/CRM/Wci/Form/ProgressBar.php b/CRM/Wci/Form/ProgressBar.php index 4c3da1f..3bc41bf 100644 --- a/CRM/Wci/Form/ProgressBar.php +++ b/CRM/Wci/Form/ProgressBar.php @@ -70,6 +70,13 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form { getContributionPageOptions(), // list of options false // is required ); + $this->add( + 'select', // field type + 'financial_type_'.$count, // field name + 'Financial type', // field label + getFinancialTypes(), // list of options + false // is required + ); $this->add( 'text', 'contribution_start_date_' . $count , @@ -91,6 +98,8 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form { $this->setDefaults(array( 'contribution_page_'.$count => $dao->contribution_page_id)); + $this->setDefaults(array( + 'financial_type_'.$count => $dao->financial_type_id)); $this->setDefaults(array( 'percentage_'.$count => $dao->percentage)); $this->setDefaults(array( @@ -112,6 +121,13 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form { getContributionPageOptions(), // list of options true // is required ); + $this->add( + 'select', // field type + 'financial_type_'.$count, // field name + 'Financial type', // field label + getFinancialTypes(), // list of options + false // is required + ); $this->add( 'text', 'contribution_start_date_1', @@ -194,27 +210,30 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form { for($i = 1; $i <= (int)$_REQUEST['contrib_count']; $i++) { $page = 'contribution_page_' . (string)$i; + $type = 'financial_type_' . (string)$i; $perc = 'percentage_' . (string)$i; $sdate = 'contribution_start_date_' . (string)$i; $edate = 'contribution_end_date_' . (string)$i; $sql = "INSERT INTO civicrm_wci_progress_bar_formula - (contribution_page_id, progress_bar_id, start_date, end_date, percentage) - VALUES (%1, %2, %3, %4, %5)"; - $start = NULL; - $end = NULL; - if (!empty($_REQUEST[$sdate])) { - $start = CRM_Utils_Date::processDate($_REQUEST[$sdate], NULL, FALSE, "Ymd"); - } - if (!empty($_REQUEST[$edate])) { - $end = CRM_Utils_Date::processDate($_REQUEST[$edate], NULL, FALSE, "Ymd"); - } + (contribution_page_id, financial_type_id, progress_bar_id, start_date, end_date, percentage) + VALUES (%1, %2, %3, %4, %5, %6)"; + $start = NULL; + $end = NULL; + if (!empty($_REQUEST[$sdate])) { + $start = CRM_Utils_Date::processDate($_REQUEST[$sdate], NULL, FALSE, "Ymd"); + } + if (!empty($_REQUEST[$edate])) { + $end = CRM_Utils_Date::processDate($_REQUEST[$edate], NULL, FALSE, "Ymd"); + } CRM_Core_DAO::executeQuery($sql, - array(1 => array($_REQUEST[$page], 'Integer'), - 2 => array($this->_id, 'Integer'), - 3 => array($start, 'Date'), - 4 => array($end, 'Date'), - 5 => array($_REQUEST[$perc], 'Float') + array( + 1 => array($_REQUEST[$page], 'Integer'), + 2 => array($_REQUEST[$type], 'Integer'), + 3 => array($this->_id, 'Integer'), + 4 => array($start, 'Date'), + 5 => array($end, 'Date'), + 6 => array($_REQUEST[$perc], 'Float') )); } $transaction->commit(); @@ -239,20 +258,34 @@ class CRM_Wci_Form_ProgressBar extends CRM_Core_Form { 3=>array($_REQUEST['goal_amount'], 'Float'), )); $progressbar_id = CRM_Core_DAO::singleValueQuery('SELECT LAST_INSERT_ID()'); - for($i = 1; $i <= (int)$_REQUEST['contrib_count']; $i++): + for($i = 1; $i <= (int)$_REQUEST['contrib_count']; $i++) { $page = 'contribution_page_' . (string)$i; + $type = 'financial_type_' . (string)$i; $perc = 'percentage_' . (string)$i; + $sdate = 'contribution_start_date_' . (string)$i; + $edate = 'contribution_end_date_' . (string)$i; $sql = "INSERT INTO civicrm_wci_progress_bar_formula - (contribution_page_id, progress_bar_id, percentage) - VALUES (%1, %2, %3)"; - + (contribution_page_id, financial_type_id, progress_bar_id, start_date, end_date, percentage) + VALUES (%1, %2, %3, %4, %5, %6)"; + $start = NULL; + $end = NULL; + if (!empty($_REQUEST[$sdate])) { + $start = CRM_Utils_Date::processDate($_REQUEST[$sdate], NULL, FALSE, "Ymd"); + } + if (!empty($_REQUEST[$edate])) { + $end = CRM_Utils_Date::processDate($_REQUEST[$edate], NULL, FALSE, "Ymd"); + } CRM_Core_DAO::executeQuery($sql, - array(1 => array($_REQUEST[$page], 'Integer'), - 2 => array($progressbar_id, 'Integer'), - 3 => array($_REQUEST[$perc], 'Float'), - )); - endfor; + array( + 1 => array($_REQUEST[$page], 'Integer'), + 2 => array($_REQUEST[$type], 'Integer'), + 3 => array($progressbar_id, 'Integer'), + 4 => array($start, 'Date'), + 5 => array($end, 'Date'), + 6 => array($_REQUEST[$perc], 'Float') + )); + } $transaction->commit(); CRM_Utils_System::redirect('civicrm/wci/progress-bar?reset=1'); } diff --git a/CRM/Wci/Upgrader.php b/CRM/Wci/Upgrader.php index 43c3b61..b56d35e 100644 --- a/CRM/Wci/Upgrader.php +++ b/CRM/Wci/Upgrader.php @@ -122,4 +122,20 @@ class CRM_Wci_Upgrader extends CRM_Wci_Upgrader_Base { ); return TRUE; } + + public function upgrade_1004() { + $this->ctx->log->info('Applying update to add financial type to progress bar'); + CRM_Core_DAO::executeQuery(' + ALTER TABLE `civicrm_wci_progress_bar_formula` + ADD `financial_type_id` INT NULL DEFAULT NULL + COMMENT "Financial type" + AFTER `contribution_page_id` + '); + CRM_Core_DAO::executeQuery(' + ALTER TABLE `civicrm_wci_progress_bar_formula` + CHANGE `contribution_page_id` `contribution_page_id` INT NULL DEFAULT NULL + COMMENT "Contribution page id" + '); + return TRUE; + } } diff --git a/js/addmore.js b/js/addmore.js index c1252fa..36e4c28 100644 --- a/js/addmore.js +++ b/js/addmore.js @@ -29,6 +29,7 @@ cj(function ( $ ) { $('#' + "contribution_page_" + i).after( ' Remove'); $('#' + "contribution_page_" + i).parent().parent().attr("id", "crm-section-con-" + i); + $('#' + "financial_type_" + i).parent().parent().attr("id", "crm-section-type-" + i); $('#' + "percentage_" + i).parent().parent().attr("id", 'crm-section-per-' + i); $('#' + "contribution_start_date_" + i).parent().parent().attr("id", 'crm-section-startdate-' + i); $('#' + "contribution_end_date_" + i).parent().parent().attr("id", 'crm-section-enddate-' + i); @@ -77,6 +78,18 @@ cj(function ( $ ) { $('#' + id_content).append(' Remove'); $('#' + id_section).append(""); + var f_type_sel = $('select[name=financial_type_1]').clone().attr('id', "financial_type_" + count); + f_type_sel.attr("name", "financial_type_" + count); + + var id_section = "crm-section-type-" + count; + var sect_tag = "
"; + $('#addmore_link').parent().parent().before(sect_tag); + + var id_content = "content_type-" + count; + $('#' + id_section).append("
"); + $('#' + id_content).append(f_type_sel); + $('#' + id_section).append("
"); + id_section = "crm-section-startdate-" + count; sect_tag = "
"; $('#addmore_link').parent().parent().before(sect_tag); @@ -128,6 +141,7 @@ cj(function ( $ ) { var rem_name_ar = rem_name.split('-'); var contri_page = "\"#percentage_" + rem_name_ar[1] + "\""; $('#crm-section-con-'+ rem_name_ar[1] +'').remove(); + $('#crm-section-type-'+ rem_name_ar[1] +'').remove(); $('#crm-section-per-'+ rem_name_ar[1] +'').remove(); $('#crm-section-startdate-'+ rem_name_ar[1] +'').remove(); $('#crm-section-enddate-'+ rem_name_ar[1] +'').remove(); diff --git a/sql/install.sql b/sql/install.sql index c20c27f..80572ee 100644 --- a/sql/install.sql +++ b/sql/install.sql @@ -11,7 +11,8 @@ CREATE TABLE IF NOT EXISTS civicrm_wci_progress_bar ( -- WCI progress bar formula CREATE TABLE IF NOT EXISTS civicrm_wci_progress_bar_formula ( id int(10) unsigned NOT NULL AUTO_INCREMENT COMMENT 'Formula entry Id.', - contribution_page_id int(10) unsigned NOT NULL COMMENT 'Reference contribution page id.', + contribution_page_id int(10) NULL DEFAULT NULL COMMENT 'Reference contribution page id.', + financial_type_id int(10) NULL DEFAULT NULL COMMENT 'Reference financial_type_id.', progress_bar_id int(10) unsigned DEFAULT NULL COMMENT 'Custom Progress bar reference id.', start_date DATE NULL DEFAULT NULL COMMENT 'Contribtuion start date.', end_date DATE NULL DEFAULT NULL COMMENT 'Contribtuion end date.', @@ -52,7 +53,7 @@ CREATE TABLE IF NOT EXISTS civicrm_wci_widget ( color_btn_newsletter_bg varchar(10) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Newsletter Button color', newsletter_text varchar(64) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Newsletter text', color_newsletter_text varchar(10) COLLATE utf8_unicode_ci NOT NULL COMMENT 'Newsletter text color', - + PRIMARY KEY (`id`), UNIQUE KEY `unique_wci_title` (`title`), CONSTRAINT FK_civicrm_wci_widget_progress_bar_id FOREIGN KEY (`progress_bar_id`) REFERENCES `civicrm_wci_progress_bar`(`id`) ON DELETE RESTRICT diff --git a/wci-helper-functions.php b/wci-helper-functions.php index b2c021b..0f538a8 100644 --- a/wci-helper-functions.php +++ b/wci-helper-functions.php @@ -35,6 +35,18 @@ return $options; } + function getFinancialTypes() { + $query = "SELECT id, name FROM civicrm_financial_type"; + $dao = CRM_Core_DAO::executeQuery($query); + $options = array( + 0 => ts('- select -'), + ); + + while ($dao->fetch()) { + $options[$dao->id] = $dao->name; + } + return $options; + } function getWciWidgetTemplatePath() { $widget_tpl_path = __DIR__ . '/templates/CRM/Wci/Page'; -- 2.25.1