Now the progressbar can fetch values with in a date range.
It will only consider completed contributions.
It fetch values from the net amount.
* @access public
*/
public static function getPBCollectedAmount($pbId) {
- $bp = 0;
- $query = "SELECT * FROM civicrm_wci_progress_bar_formula WHERE progress_bar_id =" . $pbId;
+ $amount = 0;
+ $query = "SELECT sum((civicontrib.net_amount * wcipb.percentage) / 100) as amount
+ FROM civicrm_wci_progress_bar_formula wcipb
+ JOIN civicrm_contribution civicontrib
+ ON wcipb.contribution_page_id = civicontrib.contribution_page_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')
+ AND DATE(civicontrib.receive_date) <= if(wcipb.end_date is not NULL, wcipb.end_date, DATE(now())))
+ AND wcipb.progress_bar_id =" . $pbId;
$params = array();
-
- $daoPbf = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_ProgressBarFormula');
- while ($daoPbf->fetch()) {
- $for_page[$daoPbf->id] = array();
- CRM_Core_DAO::storeValues($daoPbf, $for_page[$daoPbf->id]);
- $px = $for_page[$daoPbf->id]['percentage'];
-
- $query = "SELECT * FROM civicrm_contribution where contribution_page_id =" . $for_page[$daoPbf->id]['contribution_page_id'];
- $params = array();
-
- $daoCon = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Contribute_DAO_Contribution');
-
- while ($daoCon->fetch()) {
- $contributions[$daoCon->id] = array();
- CRM_Core_DAO::storeValues($daoCon, $contributions[$daoCon->id]);
- $bx = $contributions[$daoCon->id]['total_amount'];
-
- $bp += $bx * $px / 100;
- }
- }
- return floor($bp);
+ $daoPbf = CRM_Core_DAO::executeQuery($query, $params);
+ if ($daoPbf->fetch()) {
+ $amount = $daoPbf->amount;
+ }
+ return round($amount);
}
public static function getProgressbarInfo($pbId) {
* @var float
*/
public $percentage;
+
+ public $start_date;
+
+ public $end_date;
function __construct()
{
$this->__table = 'civicrm_wci_progress_bar_formula';
'title' => ts('Progress Bar Reference Id', array('domain' => 'com.zyxware.civiwci')) ,
'required' => true,
) ,
+ 'start_date' => array(
+ 'name' => 'start_date',
+ 'type' => CRM_Utils_Type::T_DATE,
+ 'title' => ts('Start date', array('domain' => 'com.zyxware.civiwci'))
+ ),
+ 'end_date' => array(
+ 'name' => 'end_date',
+ 'type' => CRM_Utils_Type::T_DATE,
+ 'title' => ts('End date', array('domain' => 'com.zyxware.civiwci'))
+ ),
'percentage' => array(
'name' => 'percentage',
'type' => CRM_Utils_Type::T_FLOAT,
'title' => ts('Percentage Amount', array('domain' => 'com.zyxware.civiwci')) ,
'required' => true,
- ) ,
+ )
);
}
return self::$_fields;
'id' => 'progress_bar_formula_id',
'contribution_page_id' => 'contribution_page_id',
'progress_bar_id' => 'progress_bar_id',
- 'percentage' => 'percentage',
+ 'start_date' => 'start_date',
+ 'end_date' => 'end_date',
+ 'percentage' => 'percentage'
);
}
return self::$_fieldKeys;
$params = array(1 => array($this->_id, 'Integer'));
$dao = CRM_Core_DAO::executeQuery($query, $params, TRUE, 'CRM_Wci_DAO_ProgressBarFormula');
-
while ($dao->fetch()) {
- $for_page[$dao->id] = array();
- CRM_Core_DAO::storeValues($dao, $for_page[$dao->id]);
-
$this->add(
'select', // field type
'contribution_page_'.$count, // field name
getContributionPageOptions(), // list of options
false // is required
);
+ $this->add(
+ 'text',
+ 'contribution_start_date_' . $count ,
+ ts('Start Date')
+ );
+ $this->add(
+ 'text',
+ 'contribution_end_date_' . $count,
+ ts('End Date')
+ );
$this->add(
'text', // field type
'percentage_'.$count, // field name
false // is required
);
//save formula id
- $this->addElement('hidden', 'contrib_elem_'.$count , $for_page[$dao->id]['id']);
+ $this->addElement('hidden', 'contrib_elem_'.$count , $dao->id);
$this->setDefaults(array(
- 'contribution_page_'.$count => $for_page[$dao->id]['contribution_page_id']));
+ 'contribution_page_'.$count => $dao->contribution_page_id));
$this->setDefaults(array(
- 'percentage_'.$count => $for_page[$dao->id]['percentage']));
-
+ 'percentage_'.$count => $dao->percentage));
+ $this->setDefaults(array(
+ 'contribution_start_date_'.$count => $dao->start_date));
+ $this->setDefaults(array(
+ 'contribution_end_date_'.$count => $dao->end_date));
+ //set default for start date and end date.
$count++;
}
CRM_Utils_System::setTitle(ts('Edit Progress Bar'));
getContributionPageOptions(), // list of options
true // is required
);
+ $this->add(
+ 'text',
+ 'contribution_start_date_1',
+ ts('Start Date')
+ );
+ $this->add(
+ 'text',
+ 'contribution_end_date_1',
+ ts('End Date')
+ );
$this->add(
'text', // field type
'percentage_1', // field name
for($i = 1; $i <= (int)$_REQUEST['contrib_count']; $i++) {
$page = 'contribution_page_' . (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, 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");
+ }
CRM_Core_DAO::executeQuery($sql,
array(1 => array($_REQUEST[$page], 'Integer'),
- 2 => array($this->_id, 'Integer'),
- 3 => array($_REQUEST[$perc], 'Float'),
- ));
+ 2 => array($this->_id, 'Integer'),
+ 3 => array($start, 'Date'),
+ 4 => array($end, 'Date'),
+ 5 => array($_REQUEST[$perc], 'Float')
+ ));
}
-
$transaction->commit();
CRM_Wci_BAO_WidgetCache::deleteWidgetCacheByProgressbar($this->_id);
CRM_Core_Session::setStatus(ts('Progress bar created successfully'), '', 'success');
return TRUE;
}
+ public function upgrade_1002() {
+ $this->ctx->log->info('Applying update 1002');
+ CRM_Core_DAO::executeQuery('
+ ALTER TABLE `civicrm_wci_progress_bar_formula`
+ ADD `start_date` DATE NULL DEFAULT NULL
+ COMMENT "Contribtuion start date"
+ AFTER `progress_bar_id`
+ ');
+ CRM_Core_DAO::executeQuery('
+ ALTER TABLE `civicrm_wci_progress_bar_formula`
+ ADD `end_date` DATE NULL DEFAULT NULL
+ COMMENT "Contribtuion end date"
+ AFTER `start_date`
+ ');
+ return TRUE;
+ }
+
}
'<a id=\"remove_link\" class=\"form-link\" href=\"remove\" name=\"remove_link-' + i + '\"> Remove</a>');
$('#' + "contribution_page_" + i).parent().parent().attr("id", "crm-section-con-" + 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);
}
$('#goal_amount').parent().after('<div class="crm-wci-pb"><hr></div><label><SMALL>Progressbar shows the sum of each percentage of contributions done on each selected contribution page</SMALL></label>');
});
$('#' + id_content).append('<a id=\"remove_link\" class=\"form-link\" href=\"remove\" name=\"remove_link-' + count + '\"> Remove</a>');
$('#' + id_section).append("</div>");
+ id_section = "crm-section-startdate-" + count;
+ sect_tag = "<div class=\"crm-section\" id=" + id_section + "> <div class=\"label\"><label>Start Date</label>";
+ $('#addmore_link').parent().parent().before(sect_tag);
+
+ id_content = "content_startdate-" + count;
+ $('#' + id_section).append("<div class=\"content\" id="+ id_content + ">");
+ $('#' + id_content).append('<input type="text" size="20" id = "startdate_' + count + '" name="startdate_' + count +'" value="" />');
+ $('#' + id_content).append('<span class=\"description\">(Format YYYY-MM-DD)</span><br><span class=\"description\">Date from which contributions to be added to this progress bar. Keep it empty to select contributions from the beginning.</span>');
+ $('#' + id_section).append("</div");
+
+ id_section = "crm-section-enddate-" + count;
+ sect_tag = "<div class=\"crm-section\" id=" + id_section + "> <div class=\"label\"><label>End Date</label>";
+ $('#addmore_link').parent().parent().before(sect_tag);
+
+ id_content = "content_enddate-" + count;
+ $('#' + id_section).append("<div class=\"content\" id="+ id_content + ">");
+ $('#' + id_content).append('<input type="text" size="20" id = "enddate_' + count + '" name="enddate_' + count +'" value="" />');
+ $('#' + id_content).append('<span class=\"description\">(Format YYYY-MM-DD)</span><br><span class=\"description\">Date to which contributions to be added to this progress bar. Keep it empty to select contributions up to today</span>');
+ $('#' + id_section).append("</div");
+
id_section = "crm-section-per-" + count;
sect_tag = "<div class=\"crm-section\" id=" + id_section + "> <div class=\"label\"><label>Percentage</label>";
$('#addmore_link').parent().parent().before(sect_tag);
var contri_page = "\"#percentage_" + rem_name_ar[1] + "\"";
$('#crm-section-con-'+ 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();
var count = parseInt($('input[name=contrib_count]').val());
count--;
$('input[name=contrib_count]').val(count);
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.',
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.',
percentage float unsigned NULL COMMENT 'Percentage amount.',
PRIMARY KEY (`id`),
CONSTRAINT FK_civicrm_wci_progress_bar_formula_progress_bar_id FOREIGN KEY (`progress_bar_id`) REFERENCES `civicrm_wci_progress_bar`(`id`) ON DELETE SET NULL
{include file="CRM/common/formButtons.tpl" location="top"}
</div>
- {* FIELD EXAMPLE: OPTION 1 (AUTOMATIC LAYOUT) *}
-
{foreach from=$elementNames item=elementName}
<div class="crm-section">
<div class="label">{$form.$elementName.label}</div>
- <div class="content">{$form.$elementName.html}</div>
+ {if substr($elementName, 0, 23) eq 'contribution_start_date'}
+ <div class="content">{$form.$elementName.html}
+ <span class="description">(Format YYYY-MM-DD)</span>
+ <br>
+ <span class="description">{ts}Date from which contributions to be added to this progressbar. Keep it empty to select contributions from the beginning.{/ts}</span>
+ </div>
+ {elseif substr($elementName, 0, 21) eq 'contribution_end_date'}
+ <div class="content">{$form.$elementName.html}
+ <span class="description">(Format YYYY-MM-DD)</span>
+ <br>
+ <span class="description">{ts}Date to which contributions to be added to this progressbar. Keep it empty to select contributions up to today{/ts}</span>
+ </div>
+ {else}
+ <div class="content">{$form.$elementName.html}</div>
+ {/if}
<div class="clear"></div>
</div>
{/foreach}
- {* FIELD EXAMPLE: OPTION 2 (MANUAL LAYOUT)
-
- <div>
- <span>{$form.favorite_color.label}</span>
- <span>{$form.favorite_color.html}</span>
- </div>
{* FOOTER *}
<div class="crm-submit-buttons">