*/
public $_fields = array();
+ /**
+ * Monetary fields that may be submitted.
+ *
+ * These should get a standardised format in the beginPostProcess function.
+ *
+ * These fields are common to many forms. Some may override this.
+ */
+ protected $submittableMoneyFields = ['total_amount', 'net_amount', 'non_deductible_amount', 'fee_amount'];
+
/**
* Build all the data structures needed to build the form.
*/
*/
private function processContribution(&$params) {
+ foreach ($this->submittableMoneyFields as $moneyField) {
+ foreach ($params['field'] as $index => $fieldValues) {
+ if (isset($fieldValues[$moneyField])) {
+ $params['field'][$index][$moneyField] = CRM_Utils_Rule::cleanMoney($params['field'][$index][$moneyField]);
+ }
+ }
+ }
+ $params['actualBatchTotal'] = CRM_Utils_Rule::cleanMoney($params['actualBatchTotal']);
// get the price set associated with offline contribution record.
$priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', 'default_contribution_amount', 'id', 'name');
$this->_priceSet = current(CRM_Price_BAO_PriceSet::getSetDetail($priceSetId));
}
}
$value['line_item'] = $lineItem;
+ $value['skipCleanMoney'] = TRUE;
//finally call contribution create for all the magic
$contribution = CRM_Contribute_BAO_Contribution::create($value);
$batchTypes = CRM_Core_Pseudoconstant::get('CRM_Batch_DAO_Batch', 'type_id', array('flip' => 1), 'validate');
/**
* Test Contribution Import.
+ *
+ * @param $thousandSeparator
+ *
+ * @dataProvider getThousandSeparators
*/
- public function testProcessContribution() {
+ public function testProcessContribution($thousandSeparator) {
+ $this->setCurrencySeparators($thousandSeparator);
$this->offsetDefaultPriceSet();
$form = new CRM_Batch_Form_Entry();
$params = $this->getContributionData();
}
/**
+ * @param $thousandSeparator
+ *
* @return array
*/
- public function getContributionData() {
+ public function getContributionData($thousandSeparator = '.') {
return array(
//'batch_id' => 4,
'primary_profiles' => array(1 => NULL, 2 => NULL, 3 => NULL),
'field' => array(
1 => array(
'financial_type' => 1,
- 'total_amount' => 15,
+ 'total_amount' => $this->formatMoneyInput(1500.15),
'receive_date' => '2013-07-24',
'receive_date_time' => NULL,
'payment_instrument' => 1,
),
2 => array(
'financial_type' => 1,
- 'total_amount' => 15,
+ 'total_amount' => $this->formatMoneyInput(1500.15),
'receive_date' => '2013-07-24',
'receive_date_time' => NULL,
'payment_instrument' => 1,
'contribution_status_id' => 1,
),
),
- 'actualBatchTotal' => 30,
+ 'actualBatchTotal' => $this->formatMoneyInput(3000.30),
);
}
}
public function restoreDefaultPriceSetConfig() {
- CRM_Core_DAO::executeQuery('DELETE FROM civicrm_price_set WHERE id > 2');
+ CRM_Core_DAO::executeQuery("DELETE FROM civicrm_price_set WHERE name NOT IN('default_contribution_amount', 'default_membership_type_amount')");
+ CRM_Core_DAO::executeQuery("UPDATE civicrm_price_set SET id = 1 WHERE name ='default_contribution_amount'");
CRM_Core_DAO::executeQuery("INSERT INTO `civicrm_price_field` (`id`, `price_set_id`, `name`, `label`, `html_type`, `is_enter_qty`, `help_pre`, `help_post`, `weight`, `is_display_amounts`, `options_per_line`, `is_active`, `is_required`, `active_on`, `expire_on`, `javascript`, `visibility_id`) VALUES (1, 1, 'contribution_amount', 'Contribution Amount', 'Text', 0, NULL, NULL, 1, 1, 1, 1, 1, NULL, NULL, NULL, 1)");
CRM_Core_DAO::executeQuery("INSERT INTO `civicrm_price_field_value` (`id`, `price_field_id`, `name`, `label`, `description`, `amount`, `count`, `max_value`, `weight`, `membership_type_id`, `membership_num_terms`, `is_default`, `is_active`, `financial_type_id`, `non_deductible_amount`) VALUES (1, 1, 'contribution_amount', 'Contribution Amount', NULL, '1', NULL, NULL, 1, NULL, NULL, 0, 1, 1, 0.00)");
}