/** * Build the form object. */ public function buildQuickForm() { $count = 0; if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) { foreach ($this->_contributionIds as $key => $id) { $finTypeID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $id, 'financial_type_id'); if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($finTypeID))) { unset($this->_contributionIds[$key]); $count++; } // Now check for lineItems if ($lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($id)) { foreach ($lineItems as $items) { if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) { unset($this->_contributionIds[$key]); $count++; break; } } } } } if ($count && empty($this->_contributionIds)) { CRM_Core_Session::setStatus(ts('1 contribution could not be deleted.', array('plural' => '%count contributions could not be deleted.', 'count' => $count)), ts('Error'), 'error'); $this->addButtons(array(array('type' => 'back', 'name' => ts('Cancel')))); } elseif ($count && !empty($this->_contributionIds)) { CRM_Core_Session::setStatus(ts('1 contribution will not be deleted.', array('plural' => '%count contributions will not be deleted.', 'count' => $count)), ts('Warning'), 'warning'); $this->addDefaultButtons(ts('Delete Contributions'), 'done'); } else { $this->addDefaultButtons(ts('Delete Contributions'), 'done'); } }
/** * Set variables up before form is built. */ public function preProcess() { parent::preProcess(); $this->_paymentProcessors = $this->get('paymentProcessors'); $this->preProcessPaymentOptions(); if (!empty($this->_ccid)) { $payment = CRM_Contribute_BAO_Contribution::getPaymentInfo($this->_ccid, 'contribution'); //bounce if the contribution is not pending. if (empty($payment['balance'])) { CRM_Core_Error::statusBounce(ts("Returning since contribution has already been handled.")); } if (!empty($payment['total'])) { $this->_pendingAmount = $payment['total']; $this->assign('pendingAmount', $this->_pendingAmount); } $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($this->_ccid); foreach (array_keys($lineItems) as $id) { $lineItems[$id]['id'] = $id; } $itemId = key($lineItems); if ($itemId && !empty($lineItems[$itemId]['price_field_id'])) { $this->_priceSetId = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceField', $lineItems[$itemId]['price_field_id'], 'price_set_id'); } if (!empty($lineItems[$itemId]['price_field_id'])) { $this->_lineItem[$this->_priceSetId] = $lineItems; } $isQuickConfig = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $this->_priceSetId, 'is_quick_config'); $this->assign('lineItem', $this->_lineItem); $this->assign('is_quick_config', $isQuickConfig); $this->assign('priceSetID', $this->_priceSetId); } // Make the contributionPageID available to the template $this->assign('contributionPageID', $this->_id); $this->assign('ccid', $this->_ccid); $this->assign('isShare', CRM_Utils_Array::value('is_share', $this->_values)); $this->assign('isConfirmEnabled', CRM_Utils_Array::value('is_confirm_enabled', $this->_values)); $this->assign('reset', CRM_Utils_Request::retrieve('reset', 'Boolean', CRM_Core_DAO::$_nullObject)); $this->assign('mainDisplay', CRM_Utils_Request::retrieve('_qf_Main_display', 'Boolean', CRM_Core_DAO::$_nullObject)); if (!empty($this->_pcpInfo['id']) && !empty($this->_pcpInfo['intro_text'])) { $this->assign('intro_text', $this->_pcpInfo['intro_text']); } elseif (!empty($this->_values['intro_text'])) { $this->assign('intro_text', $this->_values['intro_text']); } $qParams = "reset=1&id={$this->_id}"; if ($pcpId = CRM_Utils_Array::value('pcp_id', $this->_pcpInfo)) { $qParams .= "&pcpId={$pcpId}"; } $this->assign('qParams', $qParams); if (!empty($this->_values['footer_text'])) { $this->assign('footer_text', $this->_values['footer_text']); } }
/** * @param $recurId * @param $contribution * * @internal param $contributionId * * @return array */ function addRecurLineItems($recurId, $contribution) { $lineSets = array(); $originalContributionID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $recurId, 'id', 'contribution_recur_id'); $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($originalContributionID); if (count($lineItems) == 1) { foreach ($lineItems as $index => $lineItem) { if ($lineItem['line_total'] != $contribution->total_amount) { // We are dealing with a changed amount! Per CRM-16397 we can work out what to do with these // if there is only one line item, and the UI should prevent this situation for those with more than one. $lineItems[$index]['line_total'] = $contribution->total_amount; $lineItems[$index]['unit_price'] = round($contribution->total_amount / $lineItems[$index]['qty'], 2); } } } if (!empty($lineItems)) { foreach ($lineItems as $key => $value) { $priceField = new CRM_Price_DAO_PriceField(); $priceField->id = $value['price_field_id']; $priceField->find(TRUE); $lineSets[$priceField->price_set_id][] = $value; } } else { CRM_Price_BAO_LineItem::processPriceSet($contribution->id, $lineSets, $contribution); } return $lineSets; }
/** * Calculate line items for the relevant recurring calculation. * * @param int $recurId * @param string $total_amount * @param int $financial_type_id * * @return array */ public static function calculateRecurLineItems($recurId, $total_amount, $financial_type_id) { $originalContributionID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $recurId, 'id', 'contribution_recur_id'); $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($originalContributionID); $lineSets = array(); if (count($lineItems) == 1) { foreach ($lineItems as $index => $lineItem) { if ($financial_type_id) { // CRM-17718 allow for possibility of changed financial type ID having been set prior to calling this. $lineItem['financial_type_id'] = $financial_type_id; } if ($lineItem['line_total'] != $total_amount) { // We are dealing with a changed amount! Per CRM-16397 we can work out what to do with these // if there is only one line item, and the UI should prevent this situation for those with more than one. $lineItem['line_total'] = $total_amount; $lineItem['unit_price'] = round($total_amount / $lineItem['qty'], 2); } $priceField = new CRM_Price_DAO_PriceField(); $priceField->id = $lineItem['price_field_id']; $priceField->find(TRUE); $lineSets[$priceField->price_set_id][] = $lineItem; } } elseif (count($lineItems) > 1) { foreach ($lineItems as $index => $lineItem) { $lineSets[$index][] = $lineItem; } } return $lineSets; }
/** * Returns all the rows in the given offset and rowCount. * * @param string $action * The action being performed. * @param int $offset * The row number to start from. * @param int $rowCount * The number of rows to return. * @param string $sort * The sql string that describes the sort order. * @param string $output * What should the result set include (web/email/csv). * * @return int * the total number of rows for this action */ public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) { if ($this->_includeSoftCredits) { // especial sort order when rows include soft credits $sort = $sort->orderBy() . ", civicrm_contribution.id, civicrm_contribution_soft.id"; } $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_contributionClause); // process the result of the query $rows = array(); //CRM-4418 check for view/edit/delete $permissions = array(CRM_Core_Permission::VIEW); if (CRM_Core_Permission::check('edit contributions')) { $permissions[] = CRM_Core_Permission::EDIT; } if (CRM_Core_Permission::check('delete in CiviContribute')) { $permissions[] = CRM_Core_Permission::DELETE; } $mask = CRM_Core_Action::mask($permissions); $qfKey = $this->_key; $componentId = $componentContext = NULL; if ($this->_context != 'contribute') { // @todo explain the significance of context & why we do not get these i that context. $qfKey = CRM_Utils_Request::retrieve('key', 'String', CRM_Core_DAO::$_nullObject); $componentId = CRM_Utils_Request::retrieve('id', 'Positive', CRM_Core_DAO::$_nullObject); $componentAction = CRM_Utils_Request::retrieve('action', 'String', CRM_Core_DAO::$_nullObject); $componentContext = CRM_Utils_Request::retrieve('compContext', 'String', CRM_Core_DAO::$_nullObject); if (!$componentContext && $this->_compContext) { // @todo explain when this condition might occur. $componentContext = $this->_compContext; $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject, NULL, FALSE, 'REQUEST'); } // CRM-17628 for some reason qfKey is not always set when searching from contribution search. // as a result if the edit link is opened using right-click + open in new tab // then the browser is not returned to the search results on save. // This is an effort to getting the qfKey without, sadly, understanding the intent of those who came before me. if (empty($qfKey)) { $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject, NULL, FALSE, 'REQUEST'); } } // get all contribution status $contributionStatuses = CRM_Core_OptionGroup::values('contribution_status', FALSE, FALSE, FALSE, NULL, 'name', FALSE); //get all campaigns. $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); while ($result->fetch()) { $links = self::links($componentId, $componentAction, $qfKey, $componentContext); $checkLineItem = FALSE; $row = array(); // Now check for lineItems if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) { $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($result->id); foreach ($lineItems as $items) { if (!CRM_Core_Permission::check('view contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) { $checkLineItem = TRUE; break; } if (!CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) { unset($links[CRM_Core_Action::UPDATE]); } if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) { unset($links[CRM_Core_Action::DELETE]); } } if ($checkLineItem) { continue; } if (!CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($result->financial_type_id))) { unset($links[CRM_Core_Action::UPDATE]); } if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($result->financial_type_id))) { unset($links[CRM_Core_Action::DELETE]); } } // the columns we are interested in foreach (self::$_properties as $property) { if (property_exists($result, $property)) { $row[$property] = $result->{$property}; } } //carry campaign on selectors. // @todo - I can't find any evidence that 'carrying' the campaign on selectors actually // results in it being displayed anywhere so why do we do this??? $row['campaign'] = CRM_Utils_Array::value($result->contribution_campaign_id, $allCampaigns); $row['campaign_id'] = $result->contribution_campaign_id; // add contribution status name $row['contribution_status_name'] = CRM_Utils_Array::value($row['contribution_status_id'], $contributionStatuses); if ($result->is_pay_later && CRM_Utils_Array::value('contribution_status_name', $row) == 'Pending') { $row['contribution_status'] .= ' (' . ts('Pay Later') . ')'; $links[CRM_Core_Action::ADD] = array('name' => ts('Pay with Credit Card'), 'url' => 'civicrm/contact/view/contribution', 'qs' => 'reset=1&action=update&id=%%id%%&cid=%%cid%%&context=%%cxt%%&mode=live', 'title' => ts('Pay with Credit Card')); } elseif (CRM_Utils_Array::value('contribution_status_name', $row) == 'Pending') { $row['contribution_status'] .= ' (' . ts('Incomplete Transaction') . ')'; } if ($row['is_test']) { $row['financial_type'] = $row['financial_type'] . ' (' . ts('test') . ')'; } $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->contribution_id; $actions = array('id' => $result->contribution_id, 'cid' => $result->contact_id, 'cxt' => $this->_context); $row['action'] = CRM_Core_Action::formLink($links, $mask, $actions, ts('more'), FALSE, 'contribution.selector.row', 'Contribution', $result->contribution_id); $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id); if (!empty($row['amount_level'])) { CRM_Event_BAO_Participant::fixEventLevel($row['amount_level']); } $rows[] = $row; } return $rows; }
/** * Function use to store line item proportionaly in * in entity financial trxn table * * @param array $params * array of contribution params. * @param object $trxn * CRM_Financial_DAO_FinancialTrxn object * @param array $contribution * */ public static function assignProportionalLineItems($params, $trxn, $contribution) { $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($params['contribution_id']); if (!empty($lineItems)) { // get financial item $sql = "SELECT fi.id, li.price_field_value_id\n FROM civicrm_financial_item fi\n INNER JOIN civicrm_line_item li ON li.id = fi.entity_id\n WHERE li.contribution_id = %1"; $dao = CRM_Core_DAO::executeQuery($sql, array(1 => array($params['contribution_id'], 'Integer'))); while ($dao->fetch()) { $ftIds[$dao->price_field_value_id] = $dao->id; } $eftParams = array('entity_table' => 'civicrm_financial_item', 'financial_trxn_id' => $trxn->id); foreach ($lineItems as $key => $value) { $paid = $value['line_total'] * ($params['total_amount'] / $contribution['total_amount']); // Record Entity Financial Trxn $eftParams['amount'] = round($paid, 2); $eftParams['entity_id'] = $ftIds[$value['price_field_value_id']]; civicrm_api3('EntityFinancialTrxn', 'create', $eftParams); } } }
/** * Returns all the rows in the given offset and rowCount. * * @param string $action * The action being performed. * @param int $offset * The row number to start from. * @param int $rowCount * The number of rows to return. * @param string $sort * The sql string that describes the sort order. * @param string $output * What should the result set include (web/email/csv). * * @return int * the total number of rows for this action */ public function &getRows($action, $offset, $rowCount, $sort, $output = NULL) { if ($this->_includeSoftCredits) { // especial sort order when rows include soft credits $sort = "civicrm_contribution.receive_date DESC, civicrm_contribution.id, civicrm_contribution_soft.id"; } $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_contributionClause); // process the result of the query $rows = array(); //CRM-4418 check for view/edit/delete $permissions = array(CRM_Core_Permission::VIEW); if (CRM_Core_Permission::check('edit contributions')) { $permissions[] = CRM_Core_Permission::EDIT; } if (CRM_Core_Permission::check('delete in CiviContribute')) { $permissions[] = CRM_Core_Permission::DELETE; } $mask = CRM_Core_Action::mask($permissions); $qfKey = $this->_key; $componentId = $componentContext = NULL; if ($this->_context != 'contribute') { $qfKey = CRM_Utils_Request::retrieve('key', 'String', CRM_Core_DAO::$_nullObject); $componentId = CRM_Utils_Request::retrieve('id', 'Positive', CRM_Core_DAO::$_nullObject); $componentAction = CRM_Utils_Request::retrieve('action', 'String', CRM_Core_DAO::$_nullObject); $componentContext = CRM_Utils_Request::retrieve('compContext', 'String', CRM_Core_DAO::$_nullObject); if (!$componentContext && $this->_compContext) { $componentContext = $this->_compContext; $qfKey = CRM_Utils_Request::retrieve('qfKey', 'String', CRM_Core_DAO::$_nullObject, NULL, FALSE, 'REQUEST'); } } // get all contribution status $contributionStatuses = CRM_Core_OptionGroup::values('contribution_status', FALSE, FALSE, FALSE, NULL, 'name', FALSE); //get all campaigns. $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE); while ($result->fetch()) { $links = self::links($componentId, $componentAction, $qfKey, $componentContext); $checkLineItem = FALSE; $row = array(); // Now check for lineItems if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) { $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($result->id); foreach ($lineItems as $items) { if (!CRM_Core_Permission::check('view contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) { $checkLineItem = TRUE; break; } if (!CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) { unset($links[CRM_Core_Action::UPDATE]); } if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) { unset($links[CRM_Core_Action::DELETE]); } } if ($checkLineItem) { continue; } if (!CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($result->financial_type_id))) { unset($links[CRM_Core_Action::UPDATE]); } if (!CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($result->financial_type_id))) { unset($links[CRM_Core_Action::DELETE]); } } // the columns we are interested in foreach (self::$_properties as $property) { if (property_exists($result, $property)) { $row[$property] = $result->{$property}; } } //carry campaign on selectors. $row['campaign'] = CRM_Utils_Array::value($result->contribution_campaign_id, $allCampaigns); $row['campaign_id'] = $result->contribution_campaign_id; // add contribution status name $row['contribution_status_name'] = CRM_Utils_Array::value($row['contribution_status_id'], $contributionStatuses); if ($result->is_pay_later && CRM_Utils_Array::value('contribution_status_name', $row) == 'Pending') { $row['contribution_status'] .= ' (' . ts('Pay Later') . ')'; } elseif (CRM_Utils_Array::value('contribution_status_name', $row) == 'Pending') { $row['contribution_status'] .= ' (' . ts('Incomplete Transaction') . ')'; } if ($row['is_test']) { $row['financial_type'] = $row['financial_type'] . ' (' . ts('test') . ')'; } $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->contribution_id; $actions = array('id' => $result->contribution_id, 'cid' => $result->contact_id, 'cxt' => $this->_context); $row['action'] = CRM_Core_Action::formLink($links, $mask, $actions, ts('more'), FALSE, 'contribution.selector.row', 'Contribution', $result->contribution_id); $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id); if (!empty($row['amount_level'])) { CRM_Event_BAO_Participant::fixEventLevel($row['amount_level']); } $rows[] = $row; } return $rows; }
public function postProcess() { $participantId = NULL; if ($this->_component == 'event') { $participantId = $this->_id; } $submittedValues = $this->controller->exportValues($this->_name); $submittedValues['confirm_email_text'] = CRM_Utils_Array::value('receipt_text', $submittedValues); $submittedValues['trxn_date'] = CRM_Utils_Date::processDate($submittedValues['trxn_date'], $submittedValues['trxn_date_time']); if ($this->_mode) { // process credit card $this->assign('contributeMode', 'direct'); $this->processCreditCard($submittedValues); } else { $defaults = array(); $contribution = civicrm_api3('Contribution', 'getsingle', array('return' => array("contribution_status_id"), 'id' => $this->_contributionId)); $contributionStatusId = CRM_Utils_Array::value('contribution_status_id', $contribution); $result = CRM_Contribute_BAO_Contribution::recordAdditionalPayment($this->_contributionId, $submittedValues, $this->_paymentType, $participantId); // Fetch the contribution & do proportional line item assignment $params = array('id' => $this->_contributionId); $contribution = CRM_Contribute_BAO_Contribution::retrieve($params, $defaults, $params); $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($this->_contributionId); if (!empty($lineItems)) { CRM_Contribute_BAO_Contribution::addPayments($lineItems, array($contribution), $contributionStatusId); } // email sending if (!empty($result) && !empty($submittedValues['is_email_receipt'])) { $submittedValues['contact_id'] = $this->_contactId; $submittedValues['contribution_id'] = $this->_contributionId; // to get 'from email id' for send receipt $this->fromEmailId = $submittedValues['from_email_address']; $sendReceipt = $this->emailReceipt($submittedValues); } $statusMsg = ts('The payment record has been processed.'); if (!empty($submittedValues['is_email_receipt']) && $sendReceipt) { $statusMsg .= ' ' . ts('A receipt has been emailed to the contributor.'); } CRM_Core_Session::setStatus($statusMsg, ts('Saved'), 'success'); $session = CRM_Core_Session::singleton(); $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactId}&selectedChild=participant")); } }
/** * Add line items for recurring contribution. * * @param int $recurId * @param $contribution * * @return array */ public static function addRecurLineItems($recurId, $contribution) { $lineSets = array(); $originalContributionID = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $recurId, 'id', 'contribution_recur_id'); $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($originalContributionID); if (count($lineItems) == 1) { foreach ($lineItems as $index => $lineItem) { if (isset($contribution->financial_type_id)) { // CRM-17718 allow for possibility of changed financial type ID having been set prior to calling this. $lineItems[$index]['financial_type_id'] = $contribution->financial_type_id; } if ($lineItem['line_total'] != $contribution->total_amount) { // We are dealing with a changed amount! Per CRM-16397 we can work out what to do with these // if there is only one line item, and the UI should prevent this situation for those with more than one. $lineItems[$index]['line_total'] = $contribution->total_amount; $lineItems[$index]['unit_price'] = round($contribution->total_amount / $lineItems[$index]['qty'], 2); } } } if (!empty($lineItems)) { foreach ($lineItems as $key => $value) { $priceField = new CRM_Price_DAO_PriceField(); $priceField->id = $value['price_field_id']; $priceField->find(TRUE); $lineSets[$priceField->price_set_id][] = $value; if ($value['entity_table'] == 'civicrm_membership') { try { civicrm_api3('membership_payment', 'create', array('membership_id' => $value['entity_id'], 'contribution_id' => $contribution->id)); } catch (CiviCRM_API3_Exception $e) { // we are catching & ignoring errors as an extra precaution since lost IPNs may be more serious that lost membership_payment data // this fn is unit-tested so risk of changes elsewhere breaking it are otherwise mitigated } } } } else { CRM_Price_BAO_LineItem::processPriceSet($contribution->id, $lineSets, $contribution); } return $lineSets; }
/** * Function to check if lineitems present in a contribution have permissioned FTs. * * @param int $id * contribution id * @param string $op * the mode of operation, can be add, view, edit, delete * @param bool $force * */ public static function checkPermissionedLineItems($id, $op, $force = TRUE) { if (!self::isACLFinancialTypeStatus()) { return TRUE; } $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($id); $flag = FALSE; foreach ($lineItems as $items) { if (!CRM_Core_Permission::check($op . ' contributions of type ' . CRM_Contribute_PseudoConstant::financialType($items['financial_type_id']))) { if ($force) { CRM_Core_Error::fatal(ts('You do not have permission to access this page.')); break; } $flag = FALSE; break; } else { $flag = TRUE; } } return $flag; }
/** * Actually build the components of the form. */ public function buildQuickForm() { // CRM-16398: If current recurring contribution got > 1 lineitems then make amount field readonly $amtAttr = array('size' => 20); $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($this->_coid); if (count($lineItems) > 1) { $amtAttr += array('readonly' => TRUE); } $this->addMoney('amount', ts('Recurring Contribution Amount'), TRUE, $amtAttr, TRUE, 'currency', $this->_subscriptionDetails->currency, TRUE); $this->add('text', 'installments', ts('Number of Installments'), array('size' => 20), TRUE); if ($this->_donorEmail) { $this->add('checkbox', 'is_notify', ts('Notify Contributor?')); } $type = 'next'; if ($this->_selfService) { $type = 'submit'; } // define the buttons $this->addButtons(array(array('type' => $type, 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); }
/** * Actually build the components of the form. */ public function buildQuickForm() { // CRM-16398: If current recurring contribution got > 1 lineitems then make amount field readonly $amtAttr = array('size' => 20); $lineItems = CRM_Price_BAO_LineItem::getLineItemsByContributionID($this->_coid); if (count($lineItems) > 1) { $amtAttr += array('readonly' => TRUE); } $this->addMoney('amount', ts('Recurring Contribution Amount'), TRUE, $amtAttr, TRUE, 'currency', $this->_subscriptionDetails->currency, TRUE); $this->add('text', 'installments', ts('Number of Installments'), array('size' => 20), FALSE); if ($this->_donorEmail) { $this->add('checkbox', 'is_notify', ts('Notify Contributor?')); } if (CRM_Core_Permission::check('edit contributions')) { CRM_Campaign_BAO_Campaign::addCampaign($this, $this->_subscriptionDetails->campaign_id); } if (CRM_Contribute_BAO_ContributionRecur::supportsFinancialTypeChange($this->contributionRecurID)) { $this->addEntityRef('financial_type_id', ts('Financial Type'), array('entity' => 'FinancialType'), TRUE); } $type = 'next'; if ($this->_selfService) { $type = 'submit'; } // define the buttons $this->addButtons(array(array('type' => $type, 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel')))); }
/** * Test for createDeferredTrxn(). */ public function testCreateDeferredTrxn() { Civi::settings()->set('contribution_invoice_settings', array('deferred_revenue_enabled' => '1')); $cid = $this->individualCreate(); $params = array('contact_id' => $cid, 'receive_date' => '2016-01-20', 'total_amount' => 622, 'financial_type_id' => 4, 'line_items' => array(array('line_item' => array(array('entity_table' => 'civicrm_contribution', 'price_field_id' => 8, 'price_field_value_id' => 16, 'label' => 'test 1', 'qty' => 1, 'unit_price' => 100, 'line_total' => 100, 'financial_type_id' => 4)), 'params' => array()))); $contribution = CRM_Contribute_BAO_Contribution::create($params); $lineItems[1] = CRM_Price_BAO_LineItem::getLineItemsByContributionID($contribution->id); $lineItemId = key($lineItems[1]); $lineItems[1][$lineItemId]['financial_item_id'] = CRM_Core_DAO::singleValueQuery("SELECT id FROM civicrm_financial_item WHERE entity_table = 'civicrm_line_item' AND entity_id = {$lineItemId}"); // Get financial trxns for contribution $trxn = $this->callAPISuccess("FinancialTrxn", "get", array('total_amount' => 622)); $this->assertEquals(date('Ymd', strtotime($trxn['values'][$trxn['id']]['trxn_date'])), date('Ymd', strtotime('2016-01-20'))); $contribution->revenue_recognition_date = date('Ymd', strtotime("+1 month")); CRM_Core_BAO_FinancialTrxn::createDeferredTrxn($lineItems, $contribution); $trxn = $this->callAPISuccess("FinancialTrxn", "get", array('total_amount' => 622, 'id' => array("NOT IN" => array($trxn['id'])))); $this->assertEquals(date('Ymd', strtotime($trxn['values'][$trxn['id']]['trxn_date'])), date('Ymd', strtotime("+1 month"))); }