Пример #1
0
 /**
  * Creates a new entry in the database.
  *
  * @param array $params
  *   (reference) an assoc array of name/value pairs.
  *
  * @return CRM_Price_DAO_LineItem
  */
 public static function create(&$params)
 {
     $id = CRM_Utils_Array::value('id', $params);
     if ($id) {
         CRM_Utils_Hook::pre('edit', 'LineItem', $id, $params);
         $op = CRM_Core_Action::UPDATE;
     } else {
         CRM_Utils_Hook::pre('create', 'LineItem', $params['entity_id'], $params);
         $op = CRM_Core_Action::ADD;
     }
     // unset entity table and entity id in $params
     // we never update the entity table and entity id during update mode
     if ($id) {
         unset($params['entity_id'], $params['entity_table']);
     }
     if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && CRM_Utils_Array::value('check_permissions', $params)) {
         if (empty($params['financial_type_id'])) {
             throw new Exception('Mandatory key(s) missing from params array: financial_type_id');
         }
         CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types, $op);
         if (!in_array($params['financial_type_id'], array_keys($types))) {
             throw new Exception('You do not have permission to create this line item');
         }
     }
     $lineItemBAO = new CRM_Price_BAO_LineItem();
     $lineItemBAO->copyValues($params);
     $return = $lineItemBAO->save();
     if ($id) {
         CRM_Utils_Hook::post('edit', 'LineItem', $id, $lineItemBAO);
     } else {
         CRM_Utils_Hook::post('create', 'LineItem', $lineItemBAO->id, $lineItemBAO);
     }
     return $return;
 }
Пример #2
0
 /**
  * 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');
     }
 }
Пример #3
0
 /**
  * Set variables up before form is built.
  */
 public function preProcess()
 {
     // Check permission for Financial Type when ACL-FT is enabled
     if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('administer CiviCRM Financial Types')) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
     }
     parent::preProcess();
 }
Пример #4
0
 /**
  * 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;
 }
Пример #5
0
 /**
  * Set variables up before form is built.
  *
  * @return void
  */
 public function preProcess()
 {
     $values = array();
     $id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     // Make sure context is assigned to template for condition where we come here view civicrm/membership/view
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $context);
     if ($id) {
         $params = array('id' => $id);
         CRM_Member_BAO_Membership::retrieve($params, $values);
         if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
             $finTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $values['membership_type_id'], 'financial_type_id');
             $finType = CRM_Contribute_PseudoConstant::financialType($finTypeId);
             if (!CRM_Core_Permission::check('view contributions of type ' . $finType)) {
                 CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
             }
         } else {
             $this->assign('noACL', TRUE);
         }
         $membershipType = CRM_Member_BAO_MembershipType::getMembershipTypeDetails($values['membership_type_id']);
         // Do the action on related Membership if needed
         $relAction = CRM_Utils_Request::retrieve('relAction', 'String', $this);
         if ($relAction) {
             $this->relAction($relAction, $values);
         }
         // build associated contributions
         $this->assign('accessContribution', FALSE);
         if (CRM_Core_Permission::access('CiviContribute')) {
             $this->assign('accessContribution', TRUE);
             CRM_Member_Page_Tab::associatedContribution($values['contact_id'], $id);
         }
         //Provide information about membership source when it is the result of a relationship (CRM-1901)
         $values['owner_membership_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $id, 'owner_membership_id');
         if (isset($values['owner_membership_id'])) {
             $values['owner_contact_id'] = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $values['owner_membership_id'], 'contact_id', 'id');
             $values['owner_display_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $values['owner_contact_id'], 'display_name', 'id');
             $direction = strrev($membershipType['relationship_direction']);
             // To display relationship type in view membership page
             $relTypeIds = str_replace(CRM_Core_DAO::VALUE_SEPARATOR, ",", $membershipType['relationship_type_id']);
             $sql = "\nSELECT relationship_type_id,\n  CASE\n  WHEN  contact_id_a = {$values['owner_contact_id']} AND contact_id_b = {$values['contact_id']} THEN 'b_a'\n  WHEN  contact_id_b = {$values['owner_contact_id']} AND contact_id_a = {$values['contact_id']} THEN 'a_b'\nEND AS 'relType'\n  FROM civicrm_relationship\n WHERE relationship_type_id IN ({$relTypeIds})";
             $dao = CRM_Core_DAO::executeQuery($sql);
             $values['relationship'] = NULL;
             while ($dao->fetch()) {
                 $typeId = $dao->relationship_type_id;
                 $direction = $dao->relType;
                 if ($direction && $typeId) {
                     if ($values['relationship']) {
                         $values['relationship'] .= ',';
                     }
                     $values['relationship'] .= CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $typeId, "name_{$direction}", 'id');
                 }
             }
         }
         $this->assign('has_related', FALSE);
         // if membership can be granted, and we are the owner of the membership
         if (!empty($membershipType['relationship_type_id']) && empty($values['owner_membership_id'])) {
             // display related contacts/membership block
             $this->assign('has_related', TRUE);
             $this->assign('max_related', CRM_Utils_Array::value('max_related', $values, ts('Unlimited')));
             // split the relations in 2 arrays based on direction
             $relTypeId = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_type_id']);
             $relDirection = explode(CRM_Core_DAO::VALUE_SEPARATOR, $membershipType['relationship_direction']);
             foreach ($relTypeId as $rid) {
                 $dir = each($relDirection);
                 $relTypeDir[substr($dir['value'], 0, 1)][] = $rid;
             }
             // build query in 2 parts with a UNION if necessary
             // _x and _y are replaced with _a and _b first, then vice-versa
             // comment is a qualifier for the relationship - now just job_title
             $select = "\nSELECT r.id, c.id as cid, c.display_name as name, c.job_title as comment,\n       rt.name_x_y as relation, r.start_date, r.end_date,\n       m.id as mid, ms.is_current_member, ms.label as status\n  FROM civicrm_relationship r\n  LEFT JOIN civicrm_relationship_type rt ON rt.id = r.relationship_type_id\n  LEFT JOIN civicrm_contact c ON c.id = r.contact_id_x\n  LEFT JOIN civicrm_membership m ON (m.owner_membership_id = {$values['id']}\n  AND m.contact_id = r.contact_id_x AND m.is_test = 0)\n  LEFT JOIN civicrm_membership_status ms ON ms.id = m.status_id\n WHERE r.contact_id_y = {$values['contact_id']} AND r.is_active = 1  AND c.is_deleted = 0";
             $query = '';
             foreach (array('a', 'b') as $dir) {
                 if (isset($relTypeDir[$dir])) {
                     $query .= ($query ? ' UNION ' : '') . str_replace('_y', '_' . $dir, str_replace('_x', '_' . ($dir == 'a' ? 'b' : 'a'), $select)) . ' AND r.relationship_type_id IN (' . implode(',', $relTypeDir[$dir]) . ')';
                 }
             }
             $query .= " ORDER BY is_current_member DESC";
             $dao = CRM_Core_DAO::executeQuery($query);
             $related = array();
             $relatedRemaining = CRM_Utils_Array::value('max_related', $values, PHP_INT_MAX);
             $rowElememts = array('id', 'cid', 'name', 'comment', 'relation', 'mid', 'start_date', 'end_date', 'is_current_member', 'status');
             while ($dao->fetch()) {
                 $row = array();
                 foreach ($rowElememts as $field) {
                     $row[$field] = $dao->{$field};
                 }
                 if ($row['mid'] && $row['is_current_member'] == 1) {
                     $relatedRemaining--;
                     $row['action'] = CRM_Core_Action::formLink(self::links(), CRM_Core_Action::DELETE, array('id' => CRM_Utils_Request::retrieve('id', 'Positive', $this), 'cid' => $row['cid'], 'mid' => $row['mid']), ts('more'), FALSE, 'membership.relationship.action', 'Relationship', CRM_Utils_Request::retrieve('id', 'Positive', $this));
                 } else {
                     if ($relatedRemaining > 0) {
                         $row['action'] = CRM_Core_Action::formLink(self::links(), CRM_Core_Action::ADD, array('id' => CRM_Utils_Request::retrieve('id', 'Positive', $this), 'cid' => $row['cid'], 'rid' => $row['cid']), ts('more'), FALSE, 'membership.relationship.action', 'Relationship', CRM_Utils_Request::retrieve('id', 'Positive', $this));
                     }
                 }
                 $related[] = $row;
             }
             $this->assign('related', $related);
             if ($relatedRemaining <= 0) {
                 $this->assign('related_text', ts('None available'));
             } else {
                 if ($relatedRemaining < 100000) {
                     $this->assign('related_text', ts('%1 available', array(1 => $relatedRemaining)));
                 } else {
                     $this->assign('related_text', ts('Unlimited', array(1 => $relatedRemaining)));
                 }
             }
         }
         $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']);
         $this->assign('displayName', $displayName);
         // Check if this is default domain contact CRM-10482
         if (CRM_Contact_BAO_Contact::checkDomainContact($values['contact_id'])) {
             $displayName .= ' (' . ts('default organization') . ')';
         }
         // omitting contactImage from title for now since the summary overlay css doesn't work outside crm-container
         CRM_Utils_System::setTitle(ts('View Membership for') . ' ' . $displayName);
         // add viewed membership to recent items list
         $recentTitle = $displayName . ' - ' . ts('Membership Type:') . ' ' . $values['membership_type'];
         $url = CRM_Utils_System::url('civicrm/contact/view/membership', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
         $recentOther = array();
         if (CRM_Core_Permission::checkActionPermission('CiviMember', CRM_Core_Action::UPDATE)) {
             $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
         }
         if (CRM_Core_Permission::checkActionPermission('CiviMember', CRM_Core_Action::DELETE)) {
             $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/membership', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
         }
         CRM_Utils_Recent::add($recentTitle, $url, $values['id'], 'Membership', $values['contact_id'], NULL, $recentOther);
         CRM_Member_Page_Tab::setContext($this, $values['contact_id']);
         $memType = CRM_Core_DAO::getFieldValue("CRM_Member_DAO_Membership", $id, "membership_type_id");
         $groupTree = CRM_Core_BAO_CustomGroup::getTree('Membership', $this, $id, 0, $memType);
         CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $id);
         $isRecur = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $id, 'contribution_recur_id');
         $autoRenew = $isRecur ? TRUE : FALSE;
     }
     if (!empty($values['is_test'])) {
         $values['membership_type'] .= ' (test) ';
     }
     $subscriptionCancelled = CRM_Member_BAO_Membership::isSubscriptionCancelled($id);
     $values['auto_renew'] = $autoRenew && !$subscriptionCancelled ? 'Yes' : 'No';
     //do check for campaigns
     if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) {
         $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
         $values['campaign'] = $campaigns[$campaignId];
     }
     $this->assign($values);
 }
Пример #6
0
 /**
  * Browse all financial types.
  */
 public function browse()
 {
     // Check permission for Financial Type when ACL-FT is enabled
     if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('administer CiviCRM Financial Types')) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
     }
     // get all financial types sorted by weight
     $financialType = array();
     $dao = new CRM_Financial_DAO_FinancialType();
     $dao->orderBy('name');
     $dao->find();
     while ($dao->fetch()) {
         $financialType[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $financialType[$dao->id]);
         $defaults = $financialAccountId = array();
         $financialAccounts = CRM_Contribute_PseudoConstant::financialAccount();
         $financialAccountIds = array();
         $params['entity_id'] = $dao->id;
         $params['entity_table'] = 'civicrm_financial_type';
         CRM_Financial_BAO_FinancialTypeAccount::retrieve($params, CRM_Core_DAO::$_nullArray, $financialAccountIds);
         foreach ($financialAccountIds as $key => $values) {
             if (!empty($financialAccounts[$values['financial_account_id']])) {
                 $financialAccountId[$values['financial_account_id']] = CRM_Utils_Array::value($values['financial_account_id'], $financialAccounts);
             }
         }
         if (!empty($financialAccountId)) {
             $financialType[$dao->id]['financial_account'] = implode(',', $financialAccountId);
         }
         // form all action links
         $action = array_sum(array_keys($this->links()));
         // update enable/disable links depending on if it is is_reserved or is_active
         if ($dao->is_reserved) {
             $action -= CRM_Core_Action::ENABLE;
             $action -= CRM_Core_Action::DISABLE;
             $action -= CRM_Core_Action::DELETE;
         } else {
             if ($dao->is_active) {
                 $action -= CRM_Core_Action::ENABLE;
             } else {
                 $action -= CRM_Core_Action::DISABLE;
             }
         }
         $financialType[$dao->id]['action'] = CRM_Core_Action::formLink(self::links(), $action, array('id' => $dao->id), ts('more'), FALSE, 'financialType.manage.action', 'FinancialType', $dao->id);
     }
     $this->assign('rows', $financialType);
 }
Пример #7
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     $this->addYesNo('is_monetary', ts('Paid Event'), NULL, NULL, array('onclick' => "return showHideByValue('is_monetary','0','event-fees','block','radio',false);"));
     //add currency element.
     $this->addCurrency('currency', ts('Currency'), FALSE);
     $paymentProcessor = CRM_Core_PseudoConstant::paymentProcessor();
     $this->assign('paymentProcessor', $paymentProcessor);
     $this->addEntityRef('payment_processor', ts('Payment Processor'), array('entity' => 'PaymentProcessor', 'multiple' => TRUE, 'select' => array('minimumInputLength' => 0)));
     // financial type
     if (!CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() || CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && CRM_Core_Permission::check('administer CiviCRM Financial Types')) {
         $this->addSelect('financial_type_id');
     } else {
         CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, CRM_Core_Action::ADD);
         $this->addSelect('financial_type_id', array('context' => 'search', 'options' => $financialTypes));
     }
     // add pay later options
     $this->addElement('checkbox', 'is_pay_later', ts('Enable Pay Later option?'), NULL, array('onclick' => "return showHideByValue('is_pay_later','','payLaterOptions','block','radio',false);"));
     $this->addElement('textarea', 'pay_later_text', ts('Pay Later Label'), CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'pay_later_text'), FALSE);
     $this->add('wysiwyg', 'pay_later_receipt', ts('Pay Later Instructions'), CRM_Core_DAO::getAttribute('CRM_Event_DAO_Event', 'pay_later_receipt'));
     $this->addElement('checkbox', 'is_billing_required', ts('Billing address required'));
     $this->add('text', 'fee_label', ts('Fee Label'));
     $price = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviEvent');
     if (CRM_Utils_System::isNull($price)) {
         $this->assign('price', FALSE);
     } else {
         $this->assign('price', TRUE);
     }
     $this->add('select', 'price_set_id', ts('Price Set'), array('' => ts('- none -')) + $price, NULL, array('onchange' => "return showHideByValue('price_set_id', '', 'map-field', 'block', 'select', false);"));
     $default = array($this->createElement('radio', NULL, NULL, NULL, 0));
     $this->add('hidden', 'price_field_id', '', array('id' => 'price_field_id'));
     for ($i = 1; $i <= self::NUM_OPTION; $i++) {
         // label
         $this->add('text', "label[{$i}]", ts('Label'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'label'));
         $this->add('hidden', "price_field_value[{$i}]", '', array('id' => "price_field_value[{$i}]"));
         // value
         $this->add('text', "value[{$i}]", ts('Value'), CRM_Core_DAO::getAttribute('CRM_Core_DAO_OptionValue', 'value'));
         $this->addRule("value[{$i}]", ts('Please enter a valid money value for this field (e.g. %1).', array(1 => CRM_Utils_Money::format('99.99', ' '))), 'money');
         // default
         $default[] = $this->createElement('radio', NULL, NULL, NULL, $i);
     }
     $this->addGroup($default, 'default');
     $this->addElement('checkbox', 'is_discount', ts('Discounts by Signup Date?'), NULL, array('onclick' => "warnDiscountDel(); return showHideByValue('is_discount','','discount','block','radio',false);"));
     $discountSection = $this->get('discountSection');
     $this->assign('discountSection', $discountSection);
     // form fields of Discount sets
     $defaultOption = array();
     $_showHide = new CRM_Core_ShowHideBlocks('', '');
     for ($i = 1; $i <= self::NUM_DISCOUNT; $i++) {
         //the show hide blocks
         $showBlocks = 'discount_' . $i;
         if ($i > 2) {
             $_showHide->addHide($showBlocks);
         } else {
             $_showHide->addShow($showBlocks);
         }
         //Increment by 1 of start date of previous end date.
         if (is_array($this->_submitValues) && !empty($this->_submitValues['discount_name'][$i]) && !empty($this->_submitValues['discount_name'][$i + 1]) && isset($this->_submitValues['discount_end_date']) && isset($this->_submitValues['discount_end_date'][$i]) && $i < self::NUM_DISCOUNT - 1) {
             $end_date = CRM_Utils_Date::processDate($this->_submitValues['discount_end_date'][$i]);
             if (!empty($this->_submitValues['discount_end_date'][$i + 1]) && empty($this->_submitValues['discount_start_date'][$i + 1])) {
                 list($this->_submitValues['discount_start_date'][$i + 1]) = CRM_Utils_Date::setDateDefaults(date('Y-m-d', strtotime("+1 days {$end_date}")));
             }
         }
         //Decrement by 1 of end date from next start date.
         if ($i > 1 && is_array($this->_submitValues) && !empty($this->_submitValues['discount_name'][$i]) && !empty($this->_submitValues['discount_name'][$i - 1]) && isset($this->_submitValues['discount_start_date']) && isset($this->_submitValues['discount_start_date'][$i])) {
             $start_date = CRM_Utils_Date::processDate($this->_submitValues['discount_start_date'][$i]);
             if (!empty($this->_submitValues['discount_start_date'][$i]) && empty($this->_submitValues['discount_end_date'][$i - 1])) {
                 list($this->_submitValues['discount_end_date'][$i - 1]) = CRM_Utils_Date::setDateDefaults(date('Y-m-d', strtotime("-1 days {$start_date}")));
             }
         }
         //discount name
         $this->add('text', 'discount_name[' . $i . ']', ts('Discount Name'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceSet', 'title'));
         $this->add('hidden', "discount_price_set[{$i}]", '', array('id' => "discount_price_set[{$i}]"));
         //discount start date
         $this->addDate('discount_start_date[' . $i . ']', ts('Discount Start Date'), FALSE, array('formatType' => 'activityDate'));
         //discount end date
         $this->addDate('discount_end_date[' . $i . ']', ts('Discount End Date'), FALSE, array('formatType' => 'activityDate'));
     }
     $_showHide->addToTemplate();
     $this->addElement('submit', $this->getButtonName('submit'), ts('Add Discount Set to Fee Table'), array('class' => 'crm-form-submit cancel'));
     $this->buildAmountLabel();
     parent::buildQuickForm();
 }
Пример #8
0
 /**
  * Does the recurring contribution support financial type change.
  *
  * This is conditional on there being only one line item or if there are no contributions as yet.
  *
  * (This second is a bit of an unusual condition but might occur in the context of a
  *
  * @param int $id
  *
  * @return bool
  */
 public static function supportsFinancialTypeChange($id)
 {
     // At this stage only sites with no Financial ACLs will have the opportunity to edit the financial type.
     // this is to limit the scope of the change and because financial ACLs are still fairly new & settling down.
     if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
         return FALSE;
     }
     $contribution = self::getTemplateContribution($id);
     return CRM_Contribute_BAO_Contribution::isSingleLineItem($contribution['id']);
 }
Пример #9
0
 /**
  * Set variables up before form is built.
  *
  * @throws \CRM_Contribute_Exception_InactiveContributionPageException
  * @throws \Exception
  */
 public function preProcess()
 {
     // current contribution page id
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     if (!$this->_id) {
         // seems like the session is corrupted and/or we lost the id trail
         // lets just bump this to a regular session error and redirect user to main page
         $this->controller->invalidKeyRedirect();
     }
     // this was used prior to the cleverer this_>getContactID - unsure now
     $this->_userID = CRM_Core_Session::singleton()->get('userID');
     $this->_contactID = $this->_membershipContactID = $this->getContactID();
     $this->_mid = NULL;
     if ($this->_contactID) {
         $this->_mid = CRM_Utils_Request::retrieve('mid', 'Positive', $this);
         if ($this->_mid) {
             $membership = new CRM_Member_DAO_Membership();
             $membership->id = $this->_mid;
             if ($membership->find(TRUE)) {
                 $this->_defaultMemTypeId = $membership->membership_type_id;
                 if ($membership->contact_id != $this->_contactID) {
                     $validMembership = FALSE;
                     $organizations = CRM_Contact_BAO_Relationship::getPermissionedContacts($this->_userID, NULL, NULL, 'Organization');
                     if (!empty($organizations) && array_key_exists($membership->contact_id, $organizations)) {
                         $this->_membershipContactID = $membership->contact_id;
                         $this->assign('membershipContactID', $this->_membershipContactID);
                         $this->assign('membershipContactName', $organizations[$this->_membershipContactID]['name']);
                         $validMembership = TRUE;
                     } else {
                         $membershipType = new CRM_Member_BAO_MembershipType();
                         $membershipType->id = $membership->membership_type_id;
                         if ($membershipType->find(TRUE)) {
                             // CRM-14051 - membership_type.relationship_type_id is a CTRL-A padded string w one or more ID values.
                             // Convert to comma separated list.
                             $inheritedRelTypes = implode(CRM_Utils_Array::explodePadded($membershipType->relationship_type_id), ',');
                             $permContacts = CRM_Contact_BAO_Relationship::getPermissionedContacts($this->_userID, $membershipType->relationship_type_id);
                             if (array_key_exists($membership->contact_id, $permContacts)) {
                                 $this->_membershipContactID = $membership->contact_id;
                                 $validMembership = TRUE;
                             }
                         }
                     }
                     if (!$validMembership) {
                         CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."), ts('Membership Invalid'), 'alert');
                     }
                 }
             } else {
                 CRM_Core_Session::setStatus(ts("Oops. The membership you're trying to renew appears to be invalid. Contact your site administrator if you need assistance. If you continue, you will be issued a new membership."), ts('Membership Invalid'), 'alert');
             }
             unset($membership);
         }
     }
     // we do not want to display recently viewed items, so turn off
     $this->assign('displayRecent', FALSE);
     // Contribution page values are cleared from session, so can't use normal Printer Friendly view.
     // Use Browser Print instead.
     $this->assign('browserPrint', TRUE);
     // action
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
     $this->assign('action', $this->_action);
     // current mode
     $this->_mode = $this->_action == 1024 ? 'test' : 'live';
     $this->_values = $this->get('values');
     $this->_fields = $this->get('fields');
     $this->_bltID = $this->get('bltID');
     $this->_paymentProcessor = $this->get('paymentProcessor');
     $this->_priceSetId = $this->get('priceSetId');
     $this->_priceSet = $this->get('priceSet');
     if (!$this->_values) {
         // get all the values from the dao object
         $this->_values = array();
         $this->_fields = array();
         CRM_Contribute_BAO_ContributionPage::setValues($this->_id, $this->_values);
         if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('add contributions of type ' . CRM_Contribute_PseudoConstant::financialType($this->_values['financial_type_id']))) {
             CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
         }
         if (empty($this->_values['is_active'])) {
             throw new CRM_Contribute_Exception_InactiveContributionPageException(ts('The page you requested is currently unavailable.'), $this->_id);
         }
         $this->assignBillingType();
         // check for is_monetary status
         $isMonetary = CRM_Utils_Array::value('is_monetary', $this->_values);
         $isPayLater = CRM_Utils_Array::value('is_pay_later', $this->_values);
         if ($isMonetary && (!$isPayLater || !empty($this->_values['payment_processor']))) {
             $this->_paymentProcessorIDs = explode(CRM_Core_DAO::VALUE_SEPARATOR, CRM_Utils_Array::value('payment_processor', $this->_values));
             $this->assignPaymentProcessor();
         }
         // get price info
         // CRM-5095
         CRM_Price_BAO_PriceSet::initSet($this, $this->_id, 'civicrm_contribution_page');
         // this avoids getting E_NOTICE errors in php
         $setNullFields = array('amount_block_is_active', 'is_allow_other_amount', 'footer_text');
         foreach ($setNullFields as $f) {
             if (!isset($this->_values[$f])) {
                 $this->_values[$f] = NULL;
             }
         }
         //check if Membership Block is enabled, if Membership Fields are included in profile
         //get membership section for this contribution page
         $this->_membershipBlock = CRM_Member_BAO_Membership::getMembershipBlock($this->_id);
         $this->set('membershipBlock', $this->_membershipBlock);
         if (!empty($this->_values['custom_pre_id'])) {
             $preProfileType = CRM_Core_BAO_UFField::getProfileType($this->_values['custom_pre_id']);
         }
         if (!empty($this->_values['custom_post_id'])) {
             $postProfileType = CRM_Core_BAO_UFField::getProfileType($this->_values['custom_post_id']);
         }
         if ((isset($postProfileType) && $postProfileType == 'Membership' || isset($preProfileType) && $preProfileType == 'Membership') && !$this->_membershipBlock['is_active']) {
             CRM_Core_Error::fatal(ts('This page includes a Profile with Membership fields - but the Membership Block is NOT enabled. Please notify the site administrator.'));
         }
         $pledgeBlock = CRM_Pledge_BAO_PledgeBlock::getPledgeBlock($this->_id);
         if ($pledgeBlock) {
             $this->_values['pledge_block_id'] = CRM_Utils_Array::value('id', $pledgeBlock);
             $this->_values['max_reminders'] = CRM_Utils_Array::value('max_reminders', $pledgeBlock);
             $this->_values['initial_reminder_day'] = CRM_Utils_Array::value('initial_reminder_day', $pledgeBlock);
             $this->_values['additional_reminder_day'] = CRM_Utils_Array::value('additional_reminder_day', $pledgeBlock);
             //set pledge id in values
             $pledgeId = CRM_Utils_Request::retrieve('pledgeId', 'Positive', $this);
             //authenticate pledge user for pledge payment.
             if ($pledgeId) {
                 $this->_values['pledge_id'] = $pledgeId;
                 //lets override w/ pledge campaign.
                 $this->_values['campaign_id'] = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_Pledge', $pledgeId, 'campaign_id');
                 self::authenticatePledgeUser();
             }
         }
         $this->set('values', $this->_values);
         $this->set('fields', $this->_fields);
     }
     // Handle PCP
     $pcpId = CRM_Utils_Request::retrieve('pcpId', 'Positive', $this);
     if ($pcpId) {
         $pcp = CRM_PCP_BAO_PCP::handlePcp($pcpId, 'contribute', $this->_values);
         $this->_pcpId = $pcp['pcpId'];
         $this->_pcpBlock = $pcp['pcpBlock'];
         $this->_pcpInfo = $pcp['pcpInfo'];
     }
     // Link (button) for users to create their own Personal Campaign page
     if ($linkText = CRM_PCP_BAO_PCP::getPcpBlockStatus($this->_id, 'contribute')) {
         $linkTextUrl = CRM_Utils_System::url('civicrm/contribute/campaign', "action=add&reset=1&pageId={$this->_id}&component=contribute", FALSE, NULL, TRUE);
         $this->assign('linkTextUrl', $linkTextUrl);
         $this->assign('linkText', $linkText);
     }
     //set pledge block if block id is set
     if (!empty($this->_values['pledge_block_id'])) {
         $this->assign('pledgeBlock', TRUE);
     }
     // check if one of the (amount , membership)  blocks is active or not.
     $this->_membershipBlock = $this->get('membershipBlock');
     if (!$this->_values['amount_block_is_active'] && !$this->_membershipBlock['is_active'] && !$this->_priceSetId) {
         CRM_Core_Error::fatal(ts('The requested online contribution page is missing a required Contribution Amount section or Membership section or Price Set. Please check with the site administrator for assistance.'));
     }
     if ($this->_values['amount_block_is_active']) {
         $this->set('amount_block_is_active', $this->_values['amount_block_is_active']);
     }
     $this->_contributeMode = $this->get('contributeMode');
     $this->assign('contributeMode', $this->_contributeMode);
     //assigning is_monetary and is_email_receipt to template
     $this->assign('is_monetary', $this->_values['is_monetary']);
     $this->assign('is_email_receipt', $this->_values['is_email_receipt']);
     $this->assign('bltID', $this->_bltID);
     //assign cancelSubscription URL to templates
     $this->assign('cancelSubscriptionUrl', CRM_Utils_Array::value('cancelSubscriptionUrl', $this->_values));
     // assigning title to template in case someone wants to use it, also setting CMS page title
     if ($this->_pcpId) {
         $this->assign('title', $this->_pcpInfo['title']);
         CRM_Utils_System::setTitle($this->_pcpInfo['title']);
     } else {
         $this->assign('title', $this->_values['title']);
         CRM_Utils_System::setTitle($this->_values['title']);
     }
     $this->_defaults = array();
     $this->_amount = $this->get('amount');
     //CRM-6907
     $config = CRM_Core_Config::singleton();
     $config->defaultCurrency = CRM_Utils_Array::value('currency', $this->_values, $config->defaultCurrency);
     //lets allow user to override campaign.
     $campID = CRM_Utils_Request::retrieve('campID', 'Positive', $this);
     if ($campID && CRM_Core_DAO::getFieldValue('CRM_Campaign_DAO_Campaign', $campID)) {
         $this->_values['campaign_id'] = $campID;
     }
     //do check for cancel recurring and clean db, CRM-7696
     if (CRM_Utils_Request::retrieve('cancel', 'Boolean', CRM_Core_DAO::$_nullObject)) {
         self::cancelRecurring();
     }
     // check if billing block is required for pay later
     if (CRM_Utils_Array::value('is_pay_later', $this->_values)) {
         $this->_isBillingAddressRequiredForPayLater = CRM_Utils_Array::value('is_billing_required', $this->_values);
         $this->assign('isBillingAddressRequiredForPayLater', $this->_isBillingAddressRequiredForPayLater);
     }
 }
Пример #10
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     // lets trim all the whitespace
     $this->applyFilter('__ALL__', 'trim');
     // add a hidden field to remember the price set id
     // this get around the browser tab issue
     $this->add('hidden', 'sid', $this->_sid);
     $this->add('hidden', 'fid', $this->_fid);
     // label
     $this->add('text', 'label', ts('Field Label'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceField', 'label'), TRUE);
     // html_type
     $javascript = 'onchange="option_html_type(this.form)";';
     $htmlTypes = CRM_Price_BAO_PriceField::htmlTypes();
     // Text box for Participant Count for a field
     // Financial Type
     $financialType = CRM_Financial_BAO_FinancialType::getIncomeFinancialType();
     foreach ($financialType as $finTypeId => $type) {
         if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('add contributions of type ' . $type)) {
             unset($financialType[$finTypeId]);
         }
     }
     if (count($financialType)) {
         $this->assign('financialType', $financialType);
     }
     $enabledComponents = CRM_Core_Component::getEnabledComponents();
     $eventComponentId = $memberComponentId = NULL;
     if (array_key_exists('CiviEvent', $enabledComponents)) {
         $eventComponentId = CRM_Core_Component::getComponentID('CiviEvent');
     }
     if (array_key_exists('CiviMember', $enabledComponents)) {
         $memberComponentId = CRM_Core_Component::getComponentID('CiviMember');
     }
     $attributes = CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceFieldValue');
     $this->add('select', 'financial_type_id', ts('Financial Type'), array(' ' => ts('- select -')) + $financialType);
     $this->assign('useForMember', FALSE);
     if (in_array($eventComponentId, $this->_extendComponentId)) {
         $this->add('text', 'count', ts('Participant Count'), $attributes['count']);
         $this->addRule('count', ts('Participant Count should be a positive number'), 'positiveInteger');
         $this->add('text', 'max_value', ts('Max Participants'), $attributes['max_value']);
         $this->addRule('max_value', ts('Please enter a valid Max Participants.'), 'positiveInteger');
         $this->assign('useForEvent', TRUE);
     } else {
         if (in_array($memberComponentId, $this->_extendComponentId)) {
             $this->_useForMember = 1;
             $this->assign('useForMember', $this->_useForMember);
         }
         $this->assign('useForEvent', FALSE);
     }
     $sel = $this->add('select', 'html_type', ts('Input Field Type'), $htmlTypes, TRUE, $javascript);
     // price (for text inputs)
     $this->add('text', 'price', ts('Price'));
     $this->registerRule('price', 'callback', 'money', 'CRM_Utils_Rule');
     $this->addRule('price', ts('must be a monetary value'), 'money');
     if ($this->_action == CRM_Core_Action::UPDATE) {
         $this->freeze('html_type');
     }
     // form fields of Custom Option rows
     $_showHide = new CRM_Core_ShowHideBlocks('', '');
     for ($i = 1; $i <= self::NUM_OPTION; $i++) {
         //the show hide blocks
         $showBlocks = 'optionField_' . $i;
         if ($i > 2) {
             $_showHide->addHide($showBlocks);
             if ($i == self::NUM_OPTION) {
                 $_showHide->addHide('additionalOption');
             }
         } else {
             $_showHide->addShow($showBlocks);
         }
         // label
         $attributes['label']['size'] = 25;
         $this->add('text', 'option_label[' . $i . ']', ts('Label'), $attributes['label']);
         // amount
         $this->add('text', 'option_amount[' . $i . ']', ts('Amount'), $attributes['amount']);
         $this->addRule('option_amount[' . $i . ']', ts('Please enter a valid amount for this field.'), 'money');
         //Financial Type
         $this->add('select', 'option_financial_type_id[' . $i . ']', ts('Financial Type'), array('' => ts('- select -')) + $financialType);
         if (in_array($eventComponentId, $this->_extendComponentId)) {
             // count
             $this->add('text', 'option_count[' . $i . ']', ts('Participant Count'), $attributes['count']);
             $this->addRule('option_count[' . $i . ']', ts('Please enter a valid Participants Count.'), 'positiveInteger');
             // max_value
             $this->add('text', 'option_max_value[' . $i . ']', ts('Max Participants'), $attributes['max_value']);
             $this->addRule('option_max_value[' . $i . ']', ts('Please enter a valid Max Participants.'), 'positiveInteger');
             // description
             //$this->add('textArea', 'option_description['.$i.']', ts('Description'), array('rows' => 1, 'cols' => 40 ));
         } elseif (in_array($memberComponentId, $this->_extendComponentId)) {
             $membershipTypes = CRM_Member_PseudoConstant::membershipType();
             $js = array('onchange' => "calculateRowValues( {$i} );");
             $this->add('select', 'membership_type_id[' . $i . ']', ts('Membership Type'), array('' => ' ') + $membershipTypes, FALSE, $js);
             $this->add('text', 'membership_num_terms[' . $i . ']', ts('Number of Terms'), CRM_Utils_Array::value('membership_num_terms', $attributes));
         }
         // weight
         $this->add('text', 'option_weight[' . $i . ']', ts('Order'), $attributes['weight']);
         // is active ?
         $this->add('checkbox', 'option_status[' . $i . ']', ts('Active?'));
         $defaultOption[$i] = $this->createElement('radio', NULL, NULL, NULL, $i);
         //for checkbox handling of default option
         $this->add('checkbox', "default_checkbox_option[{$i}]", NULL);
     }
     //default option selection
     $this->addGroup($defaultOption, 'default_option');
     $_showHide->addToTemplate();
     // is_display_amounts
     $this->add('checkbox', 'is_display_amounts', ts('Display Amount?'));
     // weight
     $this->add('text', 'weight', ts('Order'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceField', 'weight'), TRUE);
     $this->addRule('weight', ts('is a numeric field'), 'numeric');
     // checkbox / radio options per line
     $this->add('text', 'options_per_line', ts('Options Per Line'));
     $this->addRule('options_per_line', ts('must be a numeric value'), 'numeric');
     // help post, mask, attributes, javascript ?
     $this->add('textarea', 'help_post', ts('Field Help'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceField', 'help_post'));
     // active_on
     $date_options = array('format' => 'dmY His', 'minYear' => date('Y') - 1, 'maxYear' => date('Y') + 5, 'addEmptyOption' => TRUE);
     $this->addDateTime('active_on', ts('Active On'), FALSE, array('formatType' => 'activityDateTime'));
     // expire_on
     $this->addDateTime('expire_on', ts('Expire On'), FALSE, array('formatType' => 'activityDateTime'));
     // is required ?
     $this->add('checkbox', 'is_required', ts('Required?'));
     // is active ?
     $this->add('checkbox', 'is_active', ts('Active?'));
     // add buttons
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'isDefault' => TRUE), array('type' => 'next', 'name' => ts('Save and New'), 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel'))));
     // is public?
     $this->add('select', 'visibility_id', ts('Visibility'), CRM_Core_PseudoConstant::visibility());
     // add a form rule to check default value
     $this->addFormRule(array('CRM_Price_Form_Field', 'formRule'), $this);
     // if view mode pls freeze it with the done button.
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
         $url = CRM_Utils_System::url('civicrm/admin/price/field', 'reset=1&action=browse&sid=' . $this->_sid);
         $this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='{$url}'"));
     }
 }
Пример #11
0
 /**
  * Set variables up before form is built.
  */
 public function preProcess()
 {
     // current contribution page id
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this, FALSE, NULL, 'REQUEST');
     $this->assign('contributionPageID', $this->_id);
     // get the requested action
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'browse');
     // setting title and 3rd level breadcrumb for html page if contrib page exists
     if ($this->_id) {
         $title = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_ContributionPage', $this->_id, 'title');
         if ($this->_action == CRM_Core_Action::UPDATE) {
             $this->_single = TRUE;
         }
     }
     // CRM-16776 - show edit/copy/create buttons on Profiles Tab if user has required permission.
     if (CRM_Core_Permission::check('administer CiviCRM')) {
         $this->assign('perm', TRUE);
     }
     // set up tabs
     CRM_Contribute_Form_ContributionPage_TabHeader::build($this);
     if ($this->_action == CRM_Core_Action::UPDATE) {
         CRM_Utils_System::setTitle(ts('Configure Page - %1', array(1 => $title)));
     } elseif ($this->_action == CRM_Core_Action::VIEW) {
         CRM_Utils_System::setTitle(ts('Preview Page - %1', array(1 => $title)));
     } elseif ($this->_action == CRM_Core_Action::DELETE) {
         CRM_Utils_System::setTitle(ts('Delete Page - %1', array(1 => $title)));
     }
     //cache values.
     $this->_values = $this->get('values');
     if (!is_array($this->_values)) {
         $this->_values = array();
         if (isset($this->_id) && $this->_id) {
             $params = array('id' => $this->_id);
             CRM_Core_DAO::commonRetrieve('CRM_Contribute_DAO_ContributionPage', $params, $this->_values);
             CRM_Contribute_BAO_ContributionPage::setValues($this->_id, $this->_values);
         }
         $this->set('values', $this->_values);
     }
     // Check permission to edit contribution page
     if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && $this->_action & CRM_Core_Action::UPDATE) {
         $financialTypeID = CRM_Contribute_PseudoConstant::financialType($this->_values['financial_type_id']);
         if (!CRM_Core_Permission::check('edit contributions of type ' . $financialTypeID)) {
             CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
         }
     }
     // Preload libraries required by the "Profiles" tab
     $schemas = array('IndividualModel', 'OrganizationModel', 'ContributionModel');
     if (in_array('CiviMember', CRM_Core_Config::singleton()->enableComponents)) {
         $schemas[] = 'MembershipModel';
     }
     CRM_UF_Page_ProfileEditor::registerProfileScripts();
     CRM_UF_Page_ProfileEditor::registerSchemas($schemas);
 }
Пример #12
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     $this->assign('taxRates', json_encode(CRM_Core_PseudoConstant::getTaxRates()));
     $this->assign('currency', CRM_Core_Config::singleton()->defaultCurrencySymbol);
     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
     if (isset($invoicing)) {
         $this->assign('taxTerm', CRM_Utils_Array::value('tax_term', $invoiceSettings));
     }
     // build price set form.
     $buildPriceSet = FALSE;
     if ($this->_priceSetId || !empty($_POST['price_set_id'])) {
         if (!empty($_POST['price_set_id'])) {
             $buildPriceSet = TRUE;
         }
         $getOnlyPriceSetElements = TRUE;
         if (!$this->_priceSetId) {
             $this->_priceSetId = $_POST['price_set_id'];
             $getOnlyPriceSetElements = FALSE;
         }
         $this->set('priceSetId', $this->_priceSetId);
         CRM_Price_BAO_PriceSet::buildPriceSet($this);
         $optionsMembershipTypes = array();
         foreach ($this->_priceSet['fields'] as $pField) {
             if (empty($pField['options'])) {
                 continue;
             }
             foreach ($pField['options'] as $opId => $opValues) {
                 $optionsMembershipTypes[$opId] = CRM_Utils_Array::value('membership_type_id', $opValues, 0);
             }
         }
         $this->assign('autoRenewOption', CRM_Price_BAO_PriceSet::checkAutoRenewForPriceSet($this->_priceSetId));
         $this->assign('optionsMembershipTypes', $optionsMembershipTypes);
         $this->assign('contributionType', CRM_Utils_Array::value('financial_type_id', $this->_priceSet));
         // get only price set form elements.
         if ($getOnlyPriceSetElements) {
             return;
         }
     }
     // use to build form during form rule.
     $this->assign('buildPriceSet', $buildPriceSet);
     if ($this->_action & CRM_Core_Action::ADD) {
         $buildPriceSet = FALSE;
         $priceSets = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviMember');
         if (!empty($priceSets)) {
             $buildPriceSet = TRUE;
         }
         if ($buildPriceSet) {
             $this->add('select', 'price_set_id', ts('Choose price set'), array('' => ts('Choose price set')) + $priceSets, NULL, array('onchange' => "buildAmount( this.value );"));
         }
         $this->assign('hasPriceSets', $buildPriceSet);
     }
     //need to assign custom data type and subtype to the template
     $this->assign('customDataType', 'Membership');
     $this->assign('customDataSubType', $this->_memType);
     $this->assign('entityID', $this->_id);
     if ($this->_action & CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     if ($this->_context == 'standalone') {
         $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE, 'api' => array('extra' => array('email'))), TRUE);
     }
     $selOrgMemType[0][0] = $selMemTypeOrg[0] = ts('- select -');
     // Throw status bounce when no Membership type or priceset is present
     if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && empty($this->allMembershipTypeDetails) && empty($priceSets)) {
         CRM_Core_Error::statusBounce(ts('You do not have all the permissions needed for this page.'));
     }
     // retrieve all memberships
     $allMembershipInfo = array();
     foreach ($this->allMembershipTypeDetails as $key => $values) {
         if ($this->_mode && empty($values['minimum_fee'])) {
             continue;
         } else {
             $memberOfContactId = CRM_Utils_Array::value('member_of_contact_id', $values);
             if (empty($selMemTypeOrg[$memberOfContactId])) {
                 $selMemTypeOrg[$memberOfContactId] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $memberOfContactId, 'display_name', 'id');
                 $selOrgMemType[$memberOfContactId][0] = ts('- select -');
             }
             if (empty($selOrgMemType[$memberOfContactId][$key])) {
                 $selOrgMemType[$memberOfContactId][$key] = CRM_Utils_Array::value('name', $values);
             }
         }
         $totalAmount = CRM_Utils_Array::value('minimum_fee', $values);
         //CRM-18827 - override the default value if total_amount is submitted
         if (!empty($this->_submitValues['total_amount'])) {
             $totalAmount = $this->_submitValues['total_amount'];
         }
         // build membership info array, which is used when membership type is selected to:
         // - set the payment information block
         // - set the max related block
         $allMembershipInfo[$key] = array('financial_type_id' => CRM_Utils_Array::value('financial_type_id', $values), 'total_amount' => CRM_Utils_Money::format($totalAmount, NULL, '%a'), 'total_amount_numeric' => $totalAmount, 'auto_renew' => CRM_Utils_Array::value('auto_renew', $values), 'has_related' => isset($values['relationship_type_id']), 'max_related' => CRM_Utils_Array::value('max_related', $values));
     }
     $this->assign('allMembershipInfo', json_encode($allMembershipInfo));
     // show organization by default, if only one organization in
     // the list
     if (count($selMemTypeOrg) == 2) {
         unset($selMemTypeOrg[0], $selOrgMemType[0][0]);
     }
     //sort membership organization and type, CRM-6099
     natcasesort($selMemTypeOrg);
     foreach ($selOrgMemType as $index => $orgMembershipType) {
         natcasesort($orgMembershipType);
         $selOrgMemType[$index] = $orgMembershipType;
     }
     $memTypeJs = array('onChange' => "buildMaxRelated(this.value,true); CRM.buildCustomData('Membership', this.value);");
     if (!empty($this->_recurPaymentProcessors)) {
         $memTypeJs['onChange'] = "" . $memTypeJs['onChange'] . "buildAutoRenew(this.value, null, '{$this->_mode}');";
     }
     $this->add('text', 'max_related', ts('Max related'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_Membership', 'max_related'));
     $sel =& $this->addElement('hierselect', 'membership_type_id', ts('Membership Organization and Type'), $memTypeJs);
     $sel->setOptions(array($selMemTypeOrg, $selOrgMemType));
     $elements = array();
     if ($sel) {
         $elements[] = $sel;
     }
     $this->applyFilter('__ALL__', 'trim');
     if ($this->_action & CRM_Core_Action::ADD) {
         $this->add('text', 'num_terms', ts('Number of Terms'), array('size' => 6));
     }
     $this->addDate('join_date', ts('Member Since'), FALSE, array('formatType' => 'activityDate'));
     $this->addDate('start_date', ts('Start Date'), FALSE, array('formatType' => 'activityDate'));
     $endDate = $this->addDate('end_date', ts('End Date'), FALSE, array('formatType' => 'activityDate'));
     if ($endDate) {
         $elements[] = $endDate;
     }
     $this->add('text', 'source', ts('Source'), CRM_Core_DAO::getAttribute('CRM_Member_DAO_Membership', 'source'));
     //CRM-7362 --add campaigns.
     $campaignId = NULL;
     if ($this->_id) {
         $campaignId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'campaign_id');
     }
     CRM_Campaign_BAO_Campaign::addCampaign($this, $campaignId);
     if (!$this->_mode) {
         $this->add('select', 'status_id', ts('Membership Status'), array('' => ts('- select -')) + CRM_Member_PseudoConstant::membershipStatus(NULL, NULL, 'label'));
         $statusOverride = $this->addElement('checkbox', 'is_override', ts('Status Override?'), NULL, array('onClick' => 'showHideMemberStatus()'));
         if ($statusOverride) {
             $elements[] = $statusOverride;
         }
         $this->addElement('checkbox', 'record_contribution', ts('Record Membership Payment?'));
         $this->add('text', 'total_amount', ts('Amount'));
         $this->addRule('total_amount', ts('Please enter a valid amount.'), 'money');
         $this->addDate('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
         $this->add('select', 'payment_instrument_id', ts('Payment Method'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), FALSE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"));
         $this->add('text', 'trxn_id', ts('Transaction ID'));
         $this->addRule('trxn_id', ts('Transaction ID already exists in Database.'), 'objectExists', array('CRM_Contribute_DAO_Contribution', $this->_id, 'trxn_id'));
         $allowStatuses = array();
         $statuses = CRM_Contribute_PseudoConstant::contributionStatus();
         if ($this->_onlinePendingContributionId) {
             $statusNames = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
             foreach ($statusNames as $val => $name) {
                 if (in_array($name, array('In Progress', 'Overdue'))) {
                     continue;
                 }
                 $allowStatuses[$val] = $statuses[$val];
             }
         } else {
             $allowStatuses = $statuses;
         }
         $this->add('select', 'contribution_status_id', ts('Payment Status'), $allowStatuses);
         $this->add('text', 'check_number', ts('Check Number'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number'));
     } else {
         //add field for amount to allow an amount to be entered that differs from minimum
         $this->add('text', 'total_amount', ts('Amount'));
     }
     $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $this->_action));
     $this->addElement('checkbox', 'is_different_contribution_contact', ts('Record Payment from a Different Contact?'));
     $this->addSelect('soft_credit_type_id', array('entity' => 'contribution_soft'));
     $this->addEntityRef('soft_credit_contact_id', ts('Payment From'), array('create' => TRUE));
     $this->addElement('checkbox', 'send_receipt', ts('Send Confirmation and Receipt?'), NULL, array('onclick' => "showEmailOptions()"));
     $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
     $this->add('textarea', 'receipt_text', ts('Receipt Message'));
     // Retrieve the name and email of the contact - this will be the TO for receipt email
     if ($this->_contactID) {
         list($this->_memberDisplayName, $this->_memberEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
         $this->assign('emailExists', $this->_memberEmail);
         $this->assign('displayName', $this->_memberDisplayName);
     }
     $isRecur = FALSE;
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $recurContributionId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_Membership', $this->_id, 'contribution_recur_id');
         if ($recurContributionId && !CRM_Member_BAO_Membership::isSubscriptionCancelled($this->_id)) {
             $isRecur = TRUE;
             if (CRM_Member_BAO_Membership::isCancelSubscriptionSupported($this->_id)) {
                 $this->assign('cancelAutoRenew', CRM_Utils_System::url('civicrm/contribute/unsubscribe', "reset=1&mid={$this->_id}"));
             }
             foreach ($elements as $elem) {
                 $elem->freeze();
             }
         }
     }
     $this->assign('isRecur', $isRecur);
     $this->addFormRule(array('CRM_Member_Form_Membership', 'formRule'), $this);
     $mailingInfo = Civi::settings()->get('mailing_backend');
     $this->assign('isEmailEnabledForSite', $mailingInfo['outBound_option'] != 2);
     parent::buildQuickForm();
 }
Пример #13
0
 /**
  * Get a list of links based on permissioned FTs.
  *
  * @param int $memTypeID
  *   membership type ID
  * @param int $links
  *   (reference ) action links
  */
 public static function getPermissionedLinks($memTypeID, &$links)
 {
     if (!CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
         return FALSE;
     }
     $finTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $memTypeID, 'financial_type_id');
     $finType = CRM_Contribute_PseudoConstant::financialType($finTypeId);
     if (!CRM_Core_Permission::check('edit contributions of type ' . $finType)) {
         unset($links[CRM_Core_Action::UPDATE]);
         unset($links[CRM_Core_Action::RENEW]);
         unset($links[CRM_Core_Action::FOLLOWUP]);
     }
     if (!CRM_Core_Permission::check('delete contributions of type ' . $finType)) {
         unset($links[CRM_Core_Action::DELETE]);
     }
 }
Пример #14
0
 /**
  * Build the price set form.
  *
  * @param CRM_Core_Form $form
  *
  * @return void
  */
 public static function buildPriceSet(&$form)
 {
     $priceSetId = $form->get('priceSetId');
     if (!$priceSetId) {
         return;
     }
     $validFieldsOnly = TRUE;
     $className = CRM_Utils_System::getClassName($form);
     if (in_array($className, array('CRM_Contribute_Form_Contribution', 'CRM_Member_Form_Membership'))) {
         $validFieldsOnly = FALSE;
     }
     $priceSet = self::getSetDetail($priceSetId, TRUE, $validFieldsOnly);
     $form->_priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
     $validPriceFieldIds = array_keys($form->_priceSet['fields']);
     $form->_quickConfig = $quickConfig = 0;
     if (CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'is_quick_config')) {
         $quickConfig = 1;
     }
     $form->assign('quickConfig', $quickConfig);
     if ($className == 'CRM_Contribute_Form_Contribution_Main') {
         $form->_quickConfig = $quickConfig;
     }
     // Mark which field should have the auto-renew checkbox, if any. CRM-18305
     if (!empty($form->_membershipTypeValues) && is_array($form->_membershipTypeValues)) {
         $autoRenewMembershipTypes = array();
         foreach ($form->_membershipTypeValues as $membershiptTypeValue) {
             if ($membershiptTypeValue['auto_renew']) {
                 $autoRenewMembershipTypes[] = $membershiptTypeValue['id'];
             }
         }
         foreach ($form->_priceSet['fields'] as &$field) {
             if (array_key_exists('options', $field) && is_array($field['options'])) {
                 foreach ($field['options'] as $option) {
                     if (!empty($option['membership_type_id'])) {
                         if (in_array($option['membership_type_id'], $autoRenewMembershipTypes)) {
                             $form->_priceSet['auto_renew_membership_field'] = $field['id'];
                             // Only one field can offer auto_renew memberships, so break here.
                             break;
                         }
                     }
                 }
             }
         }
     }
     $form->assign('priceSet', $form->_priceSet);
     $component = 'contribution';
     if ($className == 'CRM_Member_Form_Membership') {
         $component = 'membership';
     }
     if ($className == 'CRM_Contribute_Form_Contribution_Main') {
         $feeBlock =& $form->_values['fee'];
         if (!empty($form->_useForMember)) {
             $component = 'membership';
         }
     } else {
         $feeBlock =& $form->_priceSet['fields'];
     }
     if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
         foreach ($feeBlock as $key => $value) {
             foreach ($value['options'] as $k => $options) {
                 if (!CRM_Core_Permission::check('add contributions of type ' . CRM_Contribute_PseudoConstant::financialType($options['financial_type_id']))) {
                     unset($feeBlock[$key]['options'][$k]);
                 }
             }
             if (empty($feeBlock[$key]['options'])) {
                 unset($feeBlock[$key]);
             }
         }
     }
     // call the hook.
     CRM_Utils_Hook::buildAmount($component, $form, $feeBlock);
     // CRM-14492 Admin price fields should show up on event registration if user has 'administer CiviCRM' permissions
     $adminFieldVisible = FALSE;
     if (CRM_Core_Permission::check('administer CiviCRM')) {
         $adminFieldVisible = TRUE;
     }
     foreach ($feeBlock as $id => $field) {
         if (CRM_Utils_Array::value('visibility', $field) == 'public' || CRM_Utils_Array::value('visibility', $field) == 'admin' && $adminFieldVisible == TRUE || !$validFieldsOnly) {
             $options = CRM_Utils_Array::value('options', $field);
             if ($className == 'CRM_Contribute_Form_Contribution_Main' && ($component = 'membership')) {
                 $userid = $form->getVar('_membershipContactID');
                 $checklifetime = self::checkCurrentMembership($options, $userid);
                 if ($checklifetime) {
                     $form->assign('ispricelifetime', TRUE);
                 }
             }
             if (!is_array($options) || !in_array($id, $validPriceFieldIds)) {
                 continue;
             }
             CRM_Price_BAO_PriceField::addQuickFormElement($form, 'price_' . $field['id'], $field['id'], FALSE, CRM_Utils_Array::value('is_required', $field, FALSE), NULL, $options);
         }
     }
 }
Пример #15
0
 /**
  * Browse all membership types.
  *
  *
  * @return void
  */
 public function browse()
 {
     // get all membership types sorted by weight
     $membershipType = array();
     $dao = new CRM_Member_DAO_MembershipType();
     $dao->orderBy('weight');
     $dao->find();
     while ($dao->fetch()) {
         if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('view contributions of type ' . CRM_Contribute_PseudoConstant::financialType($dao->financial_type_id))) {
             continue;
         }
         $links = self::links();
         $membershipType[$dao->id] = array();
         CRM_Core_DAO::storeValues($dao, $membershipType[$dao->id]);
         $membershipType[$dao->id]['period_type'] = CRM_Utils_Array::value($dao->period_type, CRM_Core_SelectValues::periodType(), '');
         $membershipType[$dao->id]['visibility'] = CRM_Utils_Array::value($dao->visibility, CRM_Core_SelectValues::memberVisibility(), '');
         //adding column for relationship type label. CRM-4178.
         if ($dao->relationship_type_id) {
             //If membership associated with 2 or more relationship then display all relationship with comma separated
             $relTypeIds = explode(CRM_Core_DAO::VALUE_SEPARATOR, $dao->relationship_type_id);
             $relTypeNames = explode(CRM_Core_DAO::VALUE_SEPARATOR, $dao->relationship_direction);
             $membershipType[$dao->id]['relationshipTypeName'] = NULL;
             foreach ($relTypeIds as $key => $value) {
                 $relationshipName = 'label_' . $relTypeNames[$key];
                 if ($membershipType[$dao->id]['relationshipTypeName']) {
                     $membershipType[$dao->id]['relationshipTypeName'] .= ", ";
                 }
                 $membershipType[$dao->id]['relationshipTypeName'] .= CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_RelationshipType', $value, $relationshipName);
             }
             $membershipType[$dao->id]['maxRelated'] = CRM_Utils_Array::value('max_related', $membershipType[$dao->id]);
         }
         if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('edit contributions of type ' . CRM_Contribute_PseudoConstant::financialType($dao->financial_type_id))) {
             unset($links[CRM_Core_Action::UPDATE], $links[CRM_Core_Action::ENABLE], $links[CRM_Core_Action::DISABLE]);
         }
         if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($dao->financial_type_id))) {
             unset($links[CRM_Core_Action::DELETE]);
         }
         // form all action links
         $action = array_sum(array_keys($this->links()));
         // update enable/disable links depending on if it is is_reserved or is_active
         if (!isset($dao->is_reserved)) {
             if ($dao->is_active) {
                 $action -= CRM_Core_Action::ENABLE;
             } else {
                 $action -= CRM_Core_Action::DISABLE;
             }
             $membershipType[$dao->id]['order'] = $membershipType[$dao->id]['weight'];
             $membershipType[$dao->id]['action'] = CRM_Core_Action::formLink($links, $action, array('id' => $dao->id), ts('more'), FALSE, 'membershipType.manage.action', 'MembershipType', $dao->id);
         }
     }
     $returnURL = CRM_Utils_System::url('civicrm/admin/member/membershipType', "reset=1&action=browse");
     CRM_Utils_Weight::addOrder($membershipType, 'CRM_Member_DAO_MembershipType', 'id', $returnURL);
     CRM_Member_BAO_MembershipType::convertDayFormat($membershipType);
     $this->assign('rows', $membershipType);
 }
Пример #16
0
 /**
  * fetch financial type having relationship as Income Account is.
  *
  *
  * @return array
  *   all financial type with income account is relationship
  */
 public static function getIncomeFinancialType()
 {
     // Financial Type
     $financialType = CRM_Contribute_PseudoConstant::financialType();
     $revenueFinancialType = array();
     $relationTypeId = key(CRM_Core_PseudoConstant::accountOptionValues('account_relationship', NULL, " AND v.name LIKE 'Income Account is' "));
     CRM_Core_PseudoConstant::populate($revenueFinancialType, 'CRM_Financial_DAO_EntityFinancialAccount', $all = TRUE, $retrieve = 'entity_id', $filter = NULL, "account_relationship = {$relationTypeId} AND entity_table = 'civicrm_financial_type' ");
     foreach ($financialType as $key => $financialTypeName) {
         if (!in_array($key, $revenueFinancialType) || CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('add contributions of type ' . $financialTypeName)) {
             unset($financialType[$key]);
         }
     }
     return $financialType;
 }
Пример #17
0
/**
 * Delete a Contribution.
 *
 * @param array $params
 *   Input parameters.
 *
 * @return array
 */
function civicrm_api3_contribution_delete($params)
{
    $contributionID = !empty($params['contribution_id']) ? $params['contribution_id'] : $params['id'];
    // First check contribution financial type
    $financialType = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $contributionID, 'financial_type_id');
    // Now check permissioned lineitems & permissioned contribution
    if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('delete contributions of type ' . CRM_Contribute_PseudoConstant::financialType($financialType)) || !CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($contributionID, 'delete', FALSE)) {
        return civicrm_api3_create_error('You do not have permission to delete this contribution');
    }
    if (CRM_Contribute_BAO_Contribution::deleteContribution($contributionID)) {
        return civicrm_api3_create_success(array($contributionID => 1));
    } else {
        return civicrm_api3_create_error('Could not delete contribution');
    }
}
Пример #18
0
 /**
  * Set variables up before form is built.
  */
 public function preProcess()
 {
     $id = $this->get('id');
     $params = array('id' => $id);
     $context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $context);
     $values = CRM_Contribute_BAO_Contribution::getValuesWithMappings($params);
     if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && $this->_action & CRM_Core_Action::VIEW) {
         $financialTypeID = CRM_Contribute_PseudoConstant::financialType($values['financial_type_id']);
         CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($id, 'view');
         if (CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($id, 'edit', FALSE)) {
             $this->assign('canEdit', TRUE);
         }
         if (CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($id, 'delete', FALSE)) {
             $this->assign('canDelete', TRUE);
         }
         if (!CRM_Core_Permission::check('view contributions of type ' . $financialTypeID)) {
             CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
         }
     } elseif ($this->_action & CRM_Core_Action::VIEW) {
         $this->assign('noACL', TRUE);
     }
     CRM_Contribute_BAO_Contribution::resolveDefaults($values);
     // @todo - I believe this cancelledStatus is unused - if someone reaches the same conclusion
     // by grepping then the next few lines can go.
     $cancelledStatus = TRUE;
     $status = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     if (CRM_Utils_Array::value('contribution_status_id', $values) == array_search('Cancelled', $status)) {
         $cancelledStatus = FALSE;
     }
     $this->assign('cancelledStatus', $cancelledStatus);
     if (!empty($values['contribution_page_id'])) {
         $contribPages = CRM_Contribute_PseudoConstant::contributionPage(NULL, TRUE);
         $values['contribution_page_title'] = CRM_Utils_Array::value(CRM_Utils_Array::value('contribution_page_id', $values), $contribPages);
     }
     // get received into i.e to_financial_account_id from last trxn
     $financialTrxnId = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnId($values['contribution_id'], 'DESC');
     $values['to_financial_account'] = '';
     if (!empty($financialTrxnId['financialTrxnId'])) {
         $values['to_financial_account_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $financialTrxnId['financialTrxnId'], 'to_financial_account_id');
         if ($values['to_financial_account_id']) {
             $values['to_financial_account'] = CRM_Contribute_PseudoConstant::financialAccount($values['to_financial_account_id']);
         }
         $values['payment_processor_id'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_FinancialTrxn', $financialTrxnId['financialTrxnId'], 'payment_processor_id');
         if ($values['payment_processor_id']) {
             $values['payment_processor_name'] = CRM_Core_DAO::getFieldValue('CRM_Financial_DAO_PaymentProcessor', $values['payment_processor_id'], 'name');
         }
     }
     if (!empty($values['contribution_recur_id'])) {
         $sql = "SELECT  installments, frequency_interval, frequency_unit FROM civicrm_contribution_recur WHERE id = %1";
         $params = array(1 => array($values['contribution_recur_id'], 'Integer'));
         $dao = CRM_Core_DAO::executeQuery($sql, $params);
         if ($dao->fetch()) {
             $values['recur_installments'] = $dao->installments;
             $values['recur_frequency_unit'] = $dao->frequency_unit;
             $values['recur_frequency_interval'] = $dao->frequency_interval;
         }
     }
     $groupTree = CRM_Core_BAO_CustomGroup::getTree('Contribution', $this, $id, 0, CRM_Utils_Array::value('financial_type_id', $values));
     CRM_Core_BAO_CustomGroup::buildCustomDataView($this, $groupTree, FALSE, NULL, NULL, NULL, $id);
     $premiumId = NULL;
     if ($id) {
         $dao = new CRM_Contribute_DAO_ContributionProduct();
         $dao->contribution_id = $id;
         if ($dao->find(TRUE)) {
             $premiumId = $dao->id;
             $productID = $dao->product_id;
         }
     }
     if ($premiumId) {
         $productDAO = new CRM_Contribute_DAO_Product();
         $productDAO->id = $productID;
         $productDAO->find(TRUE);
         $this->assign('premium', $productDAO->name);
         $this->assign('option', $dao->product_option);
         $this->assign('fulfilled', $dao->fulfilled_date);
     }
     // Get Note
     $noteValue = CRM_Core_BAO_Note::getNote(CRM_Utils_Array::value('id', $values), 'civicrm_contribution');
     $values['note'] = array_values($noteValue);
     // show billing address location details, if exists
     if (!empty($values['address_id'])) {
         $addressParams = array('id' => CRM_Utils_Array::value('address_id', $values));
         $addressDetails = CRM_Core_BAO_Address::getValues($addressParams, FALSE, 'id');
         $addressDetails = array_values($addressDetails);
         $values['billing_address'] = $addressDetails[0]['display'];
     }
     //assign soft credit record if exists.
     $SCRecords = CRM_Contribute_BAO_ContributionSoft::getSoftContribution($values['contribution_id'], TRUE);
     if (!empty($SCRecords['soft_credit'])) {
         $this->assign('softContributions', $SCRecords['soft_credit']);
         unset($SCRecords['soft_credit']);
     }
     //assign pcp record if exists
     foreach ($SCRecords as $name => $value) {
         $this->assign($name, $value);
     }
     $lineItems = array();
     if ($id) {
         $lineItem = CRM_Price_BAO_LineItem::getLineItems($id, 'contribution', 1, TRUE, TRUE);
         if (!empty($lineItem)) {
             $lineItems[] = $lineItem;
         }
     }
     $this->assign('lineItem', empty($lineItems) ? FALSE : $lineItems);
     $values['totalAmount'] = $values['total_amount'];
     //do check for campaigns
     if ($campaignId = CRM_Utils_Array::value('campaign_id', $values)) {
         $campaigns = CRM_Campaign_BAO_Campaign::getCampaigns($campaignId);
         $values['campaign'] = $campaigns[$campaignId];
     }
     if ($values['contribution_status'] == 'Refunded') {
         $this->assign('refund_trxn_id', CRM_Core_BAO_FinancialTrxn::getRefundTransactionTrxnID($id));
     }
     // assign values to the template
     $this->assign($values);
     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
     $this->assign('invoicing', $invoicing);
     $this->assign('isDeferred', CRM_Utils_Array::value('deferred_revenue_enabled', $invoiceSettings));
     if ($invoicing && isset($values['tax_amount'])) {
         $this->assign('totalTaxAmount', $values['tax_amount']);
     }
     $displayName = CRM_Contact_BAO_Contact::displayName($values['contact_id']);
     $this->assign('displayName', $displayName);
     // Check if this is default domain contact CRM-10482
     if (CRM_Contact_BAO_Contact::checkDomainContact($values['contact_id'])) {
         $displayName .= ' (' . ts('default organization') . ')';
     }
     // omitting contactImage from title for now since the summary overlay css doesn't work outside of our crm-container
     CRM_Utils_System::setTitle(ts('View Contribution from') . ' ' . $displayName);
     // add viewed contribution to recent items list
     $url = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=view&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     $title = $displayName . ' - (' . CRM_Utils_Money::format($values['total_amount']) . ' ' . ' - ' . $values['financial_type'] . ')';
     $recentOther = array();
     if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::UPDATE)) {
         $recentOther['editUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=update&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     }
     if (CRM_Core_Permission::checkActionPermission('CiviContribute', CRM_Core_Action::DELETE)) {
         $recentOther['deleteUrl'] = CRM_Utils_System::url('civicrm/contact/view/contribution', "action=delete&reset=1&id={$values['id']}&cid={$values['contact_id']}&context=home");
     }
     CRM_Utils_Recent::add($title, $url, $values['id'], 'Contribution', $values['contact_id'], NULL, $recentOther);
 }
Пример #19
0
 /**
  * Generate temporary table to hold all contributions with permissioned FTs.
  *
  * @param object $query
  * @param string $alias
  * @param bool $return
  */
 public function getPermissionedFTQuery(&$query, $alias = NULL, $return = FALSE)
 {
     if (!CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
         return FALSE;
     }
     $financialTypes = NULL;
     CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes);
     if (empty($financialTypes)) {
         $contFTs = "0";
         $liFTs = implode(',', array_keys(CRM_Contribute_Pseudoconstant::financialType()));
     } else {
         $contFTs = $liFTs = implode(',', array_keys($financialTypes));
     }
     if ($alias) {
         $temp = CRM_Utils_Array::value('civicrm_line_item', $query->_aliases);
         $query->_aliases['civicrm_line_item'] = $alias;
     }
     if (empty($query->_where)) {
         $query->_where = "WHERE {$query->_aliases['civicrm_contribution']}.id IS NOT NULL ";
     }
     CRM_Core_DAO::executeQuery("DROP TEMPORARY TABLE IF EXISTS civicrm_contribution_temp");
     $sql = "CREATE TEMPORARY TABLE civicrm_contribution_temp AS SELECT {$query->_aliases['civicrm_contribution']}.id {$query->_from}\n              LEFT JOIN civicrm_line_item   {$query->_aliases['civicrm_line_item']}\n                      ON {$query->_aliases['civicrm_contribution']}.id = {$query->_aliases['civicrm_line_item']}.contribution_id AND\n                         {$query->_aliases['civicrm_line_item']}.entity_table = 'civicrm_contribution'\n                      AND {$query->_aliases['civicrm_line_item']}.financial_type_id NOT IN (" . $liFTs . ")\n              {$query->_where}\n                      AND {$query->_aliases['civicrm_contribution']}.financial_type_id IN (" . $contFTs . ")\n                      AND {$query->_aliases['civicrm_line_item']}.id IS NULL\n              GROUP BY {$query->_aliases['civicrm_contribution']}.id";
     CRM_Core_DAO::executeQuery($sql);
     if (isset($temp)) {
         $query->_aliases['civicrm_line_item'] = $temp;
     }
     $from = " INNER JOIN civicrm_contribution_temp temp ON {$query->_aliases['civicrm_contribution']}.id = temp.id ";
     if ($return) {
         return $from;
     }
     $query->_from .= $from;
 }
Пример #20
0
 /**
  * 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)
 {
     // check if we can process credit card registration
     $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )");
     if (count($processors) > 0) {
         $this->_isPaymentProcessor = TRUE;
     } else {
         $this->_isPaymentProcessor = FALSE;
     }
     // Only show credit card membership signup and renewal if user has CiviContribute permission
     if (CRM_Core_Permission::access('CiviContribute')) {
         $this->_accessContribution = TRUE;
     } else {
         $this->_accessContribution = FALSE;
     }
     //get all campaigns.
     $allCampaigns = CRM_Campaign_BAO_Campaign::getCampaigns(NULL, NULL, FALSE, FALSE, FALSE, TRUE);
     $result = $this->_query->searchQuery($offset, $rowCount, $sort, FALSE, FALSE, FALSE, FALSE, FALSE, $this->_memberClause);
     // 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 memberships')) {
         $permissions[] = CRM_Core_Permission::EDIT;
     }
     if (CRM_Core_Permission::check('delete in CiviMember')) {
         $permissions[] = CRM_Core_Permission::DELETE;
     }
     $mask = CRM_Core_Action::mask($permissions);
     while ($result->fetch()) {
         $row = array();
         // 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->member_campaign_id, $allCampaigns);
         $row['campaign_id'] = $result->member_campaign_id;
         if (!empty($row['member_is_test'])) {
             $row['membership_type'] = $row['membership_type'] . " (test)";
         }
         $row['checkbox'] = CRM_Core_Form::CB_PREFIX . $result->membership_id;
         if (!isset($result->owner_membership_id)) {
             // unset renew and followup link for deceased membership
             $currentMask = $mask;
             if ($result->membership_status == 'Deceased') {
                 $currentMask = $currentMask & ~CRM_Core_Action::RENEW & ~CRM_Core_Action::FOLLOWUP;
             }
             $isCancelSupported = CRM_Member_BAO_Membership::isCancelSubscriptionSupported($row['membership_id']);
             $links = self::links('all', $this->_isPaymentProcessor, $this->_accessContribution, $this->_key, $this->_context, $isCancelSupported);
             // check permissions
             $finTypeId = CRM_Core_DAO::getFieldValue('CRM_Member_DAO_MembershipType', $result->membership_type_id, 'financial_type_id');
             $finType = CRM_Contribute_PseudoConstant::financialType($finTypeId);
             if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('edit contributions of type ' . $finType)) {
                 unset($links[CRM_Core_Action::UPDATE]);
             }
             if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('delete contributions of type ' . $finType)) {
                 unset($links[CRM_Core_Action::DELETE]);
             }
             $row['action'] = CRM_Core_Action::formLink($links, $currentMask, array('id' => $result->membership_id, 'cid' => $result->contact_id, 'cxt' => $this->_context), ts('Renew') . '...', FALSE, 'membership.selector.row', 'Membership', $result->membership_id);
         } else {
             $links = self::links('view');
             $row['action'] = CRM_Core_Action::formLink($links, $mask, array('id' => $result->membership_id, 'cid' => $result->contact_id, 'cxt' => $this->_context), ts('more'), FALSE, 'membership.selector.row', 'Membership', $result->membership_id);
         }
         //does membership have auto renew CRM-7137.
         $autoRenew = FALSE;
         if (isset($result->membership_recur_id) && $result->membership_recur_id && !CRM_Member_BAO_Membership::isSubscriptionCancelled($row['membership_id'])) {
             $autoRenew = TRUE;
         }
         $row['auto_renew'] = $autoRenew;
         $row['contact_type'] = CRM_Contact_BAO_Contact_Utils::getImage($result->contact_sub_type ? $result->contact_sub_type : $result->contact_type, FALSE, $result->contact_id);
         $rows[] = $row;
     }
     return $rows;
 }
Пример #21
0
 /**
  * Build the form object.
  *
  * @param CRM_Core_Form $form
  */
 public static function buildQuickForm(&$form)
 {
     if ($form->_eventId) {
         $form->_isPaidEvent = CRM_Core_DAO::getFieldValue('CRM_Event_DAO_Event', $form->_eventId, 'is_monetary');
         if ($form->_isPaidEvent) {
             $form->addElement('hidden', 'hidden_feeblock', 1);
         }
         // make sure this is for backoffice registration.
         if ($form->getName() == 'Participant') {
             $eventfullMsg = CRM_Event_BAO_Participant::eventFullMessage($form->_eventId, $form->_pId);
             $form->addElement('hidden', 'hidden_eventFullMsg', $eventfullMsg, array('id' => 'hidden_eventFullMsg'));
         }
     }
     if ($form->_pId) {
         if (CRM_Core_DAO::getFieldValue('CRM_Event_DAO_ParticipantPayment', $form->_pId, 'contribution_id', 'participant_id')) {
             $form->_online = TRUE;
         }
     }
     if ($form->_isPaidEvent) {
         $params = array('id' => $form->_eventId);
         CRM_Event_BAO_Event::retrieve($params, $event);
         //retrieve custom information
         $form->_values = array();
         CRM_Event_Form_Registration::initEventFee($form, $event['id']);
         CRM_Event_Form_Registration_Register::buildAmount($form, TRUE, $form->_discountId);
         $lineItem = array();
         $invoiceSettings = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::CONTRIBUTE_PREFERENCES_NAME, 'contribution_invoice_settings');
         $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
         $totalTaxAmount = 0;
         if (!CRM_Utils_System::isNull(CRM_Utils_Array::value('line_items', $form->_values))) {
             $lineItem[] = $form->_values['line_items'];
             foreach ($form->_values['line_items'] as $key => $value) {
                 $totalTaxAmount = $value['tax_amount'] + $totalTaxAmount;
             }
         }
         if ($invoicing) {
             $form->assign('totalTaxAmount', $totalTaxAmount);
         }
         $form->assign('lineItem', empty($lineItem) ? FALSE : $lineItem);
         $discounts = array();
         if (!empty($form->_values['discount'])) {
             foreach ($form->_values['discount'] as $key => $value) {
                 $value = current($value);
                 $discounts[$key] = $value['name'];
             }
             $element = $form->add('select', 'discount_id', ts('Discount Set'), array(0 => ts('- select -')) + $discounts, FALSE, array('class' => "crm-select2"));
             if ($form->_online) {
                 $element->freeze();
             }
         }
         if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Utils_Array::value('fee', $form->_values) && CRM_Utils_Array::value('snippet', $_REQUEST) == CRM_Core_Smarty::PRINT_NOFORM) {
             $form->assign('isFTPermissionDenied', TRUE);
             return FALSE;
         }
         if ($form->_mode) {
             CRM_Core_Payment_Form::buildPaymentForm($form, $form->_paymentProcessor, FALSE, TRUE);
         } elseif (!$form->_mode) {
             $form->addElement('checkbox', 'record_contribution', ts('Record Payment?'), NULL, array('onclick' => "return showHideByValue('record_contribution','','payment_information','table-row','radio',false);"));
             // Check permissions for financial type first
             if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus()) {
                 CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $form->_action);
             } else {
                 $financialTypes = CRM_Contribute_PseudoConstant::financialType();
             }
             $form->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + $financialTypes);
             $form->addDateTime('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
             $form->add('select', 'payment_instrument_id', ts('Payment Method'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), FALSE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"));
             // don't show transaction id in batch update mode
             $path = CRM_Utils_System::currentPath();
             $form->assign('showTransactionId', FALSE);
             if ($path != 'civicrm/contact/search/basic') {
                 $form->add('text', 'trxn_id', ts('Transaction ID'));
                 $form->addRule('trxn_id', ts('Transaction ID already exists in Database.'), 'objectExists', array('CRM_Contribute_DAO_Contribution', $form->_eventId, 'trxn_id'));
                 $form->assign('showTransactionId', TRUE);
             }
             $status = CRM_Contribute_PseudoConstant::contributionStatus();
             // CRM-14417 suppressing contribution statuses that are NOT relevant to new participant registrations
             $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
             foreach (array('Cancelled', 'Failed', 'In Progress', 'Overdue', 'Refunded', 'Pending refund') as $suppress) {
                 unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
             }
             $form->add('select', 'contribution_status_id', ts('Payment Status'), $status);
             $form->add('text', 'check_number', ts('Check Number'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'check_number'));
             $form->add('text', 'total_amount', ts('Amount'), CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution', 'total_amount'));
         }
     } else {
         $form->add('text', 'amount', ts('Event Fee(s)'));
     }
     $form->assign('onlinePendingContributionId', $form->get('onlinePendingContributionId'));
     $form->assign('paid', $form->_isPaidEvent);
     $form->addElement('checkbox', 'send_receipt', ts('Send Confirmation?'), NULL, array('onclick' => "showHideByValue('send_receipt','','notice','table-row','radio',false); showHideByValue('send_receipt','','from-email','table-row','radio',false);"));
     $form->add('select', 'from_email_address', ts('Receipt From'), $form->_fromEmails['from_email_id']);
     $form->add('textarea', 'receipt_text', ts('Confirmation Message'));
     // Retrieve the name and email of the contact - form will be the TO for receipt email ( only if context is not standalone)
     if ($form->_context != 'standalone') {
         if ($form->_contactId) {
             list($form->_contributorDisplayName, $form->_contributorEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($form->_contactId);
             $form->assign('email', $form->_contributorEmail);
         } else {
             //show email block for batch update for event
             $form->assign('batchEmail', TRUE);
         }
     }
     $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');
     $form->assign('outBound_option', $mailingInfo['outBound_option']);
     $form->assign('hasPayment', $form->_paymentId);
 }
Пример #22
0
 /**
  * Build the form object.
  *
  * @return void
  */
 public function buildQuickForm()
 {
     $this->applyFilter('__ALL__', 'trim');
     $this->assign('sid', $this->_sid);
     // title
     $this->add('text', 'title', ts('Set Name'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceSet', 'title'), TRUE);
     $this->addRule('title', ts('Name already exists in Database.'), 'objectExists', array('CRM_Price_DAO_PriceSet', $this->_sid, 'title'));
     $priceSetUsedTables = $extends = array();
     if ($this->_action == CRM_Core_Action::UPDATE && $this->_sid) {
         $priceSetUsedTables = CRM_Price_BAO_PriceSet::getUsedBy($this->_sid, 'table');
     }
     $config = CRM_Core_Config::singleton();
     $showContribution = FALSE;
     $enabledComponents = CRM_Core_Component::getEnabledComponents();
     foreach ($enabledComponents as $name => $compObj) {
         switch ($name) {
             case 'CiviEvent':
                 $option = $this->createElement('checkbox', $compObj->componentID, NULL, ts('Event'));
                 if (!empty($priceSetUsedTables)) {
                     foreach (array('civicrm_event', 'civicrm_participant') as $table) {
                         if (in_array($table, $priceSetUsedTables)) {
                             $option->freeze();
                             break;
                         }
                     }
                 }
                 $extends[] = $option;
                 break;
             case 'CiviContribute':
                 $option = $this->createElement('checkbox', $compObj->componentID, NULL, ts('Contribution'));
                 if (!empty($priceSetUsedTables)) {
                     foreach (array('civicrm_contribution', 'civicrm_contribution_page') as $table) {
                         if (in_array($table, $priceSetUsedTables)) {
                             $option->freeze();
                             break;
                         }
                     }
                 }
                 $extends[] = $option;
                 break;
             case 'CiviMember':
                 $option = $this->createElement('checkbox', $compObj->componentID, NULL, ts('Membership'));
                 if (!empty($priceSetUsedTables)) {
                     foreach (array('civicrm_membership', 'civicrm_contribution_page') as $table) {
                         if (in_array($table, $priceSetUsedTables)) {
                             $option->freeze();
                             break;
                         }
                     }
                 }
                 $extends[] = $option;
                 break;
         }
     }
     if (CRM_Utils_System::isNull($extends)) {
         $this->assign('extends', FALSE);
     } else {
         $this->assign('extends', TRUE);
     }
     $this->addGroup($extends, 'extends', ts('Used For'), '&nbsp;', TRUE);
     $this->addRule('extends', ts('%1 is a required field.', array(1 => ts('Used For'))), 'required');
     // financial type
     $financialType = CRM_Financial_BAO_FinancialType::getIncomeFinancialType();
     foreach ($financialType as $finTypeId => $type) {
         if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !CRM_Core_Permission::check('add contributions of type ' . $type)) {
             unset($financialType[$finTypeId]);
         }
     }
     $this->add('select', 'financial_type_id', ts('Default Financial Type'), array('' => ts('- select -')) + $financialType, 'required');
     // help text
     $this->add('textarea', 'help_pre', ts('Pre-form Help'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceSet', 'help_pre'));
     $this->add('textarea', 'help_post', ts('Post-form Help'), CRM_Core_DAO::getAttribute('CRM_Price_DAO_PriceSet', 'help_post'));
     // is this set active ?
     $this->addElement('checkbox', 'is_active', ts('Is this Price Set active?'));
     $this->addButtons(array(array('type' => 'next', 'name' => ts('Save'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
     $this->addFormRule(array('CRM_Price_Form_Set', 'formRule'));
     // views are implemented as frozen form
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
         //$this->addElement('button', 'done', ts('Done'), array('onclick' => "location.href='civicrm/admin/price?reset=1&action=browse'"));
     }
 }
Пример #23
0
 /**
  * Build the form object.
  */
 public function buildQuickForm()
 {
     // FIXME: This probably needs to be done in preprocess
     if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && $this->_action & CRM_Core_Action::UPDATE && CRM_Utils_Array::value('financial_type_id', $this->_values)) {
         $financialTypeID = CRM_Contribute_PseudoConstant::financialType($this->_values['financial_type_id']);
         CRM_Financial_BAO_FinancialType::checkPermissionedLineItems($this->_id, 'edit');
         if (!CRM_Core_Permission::check('edit contributions of type ' . $financialTypeID)) {
             CRM_Core_Error::fatal(ts('You do not have permission to access this page.'));
         }
     }
     $allPanes = array();
     $recurJs = NULL;
     //tax rate from financialType
     $this->assign('taxRates', json_encode(CRM_Core_PseudoConstant::getTaxRates()));
     $this->assign('currencies', json_encode(CRM_Core_OptionGroup::values('currencies_enabled')));
     // build price set form.
     $buildPriceSet = FALSE;
     $invoiceSettings = Civi::settings()->get('contribution_invoice_settings');
     $invoicing = CRM_Utils_Array::value('invoicing', $invoiceSettings);
     $this->assign('invoicing', $invoicing);
     // display tax amount on edit contribution page
     if ($invoicing && $this->_action & CRM_Core_Action::UPDATE && isset($this->_values['tax_amount'])) {
         $this->assign('totalTaxAmount', $this->_values['tax_amount']);
     }
     if (empty($this->_lineItems) && ($this->_priceSetId || !empty($_POST['price_set_id']))) {
         $buildPriceSet = TRUE;
         $getOnlyPriceSetElements = TRUE;
         if (!$this->_priceSetId) {
             $this->_priceSetId = $_POST['price_set_id'];
             $getOnlyPriceSetElements = FALSE;
         }
         $this->set('priceSetId', $this->_priceSetId);
         CRM_Price_BAO_PriceSet::buildPriceSet($this);
         // get only price set form elements.
         if ($getOnlyPriceSetElements) {
             return;
         }
     }
     // use to build form during form rule.
     $this->assign('buildPriceSet', $buildPriceSet);
     $defaults = $this->_values;
     $additionalDetailFields = array('note', 'thankyou_date', 'invoice_id', 'non_deductible_amount', 'fee_amount', 'net_amount');
     foreach ($additionalDetailFields as $key) {
         if (!empty($defaults[$key])) {
             $defaults['hidden_AdditionalDetail'] = 1;
             break;
         }
     }
     if ($this->_productDAO) {
         if ($this->_productDAO->product_id) {
             $defaults['hidden_Premium'] = 1;
         }
     }
     if ($this->_noteID && isset($this->_values['note'])) {
         $defaults['hidden_AdditionalDetail'] = 1;
     }
     $paneNames = array(ts('Additional Details') => 'AdditionalDetail');
     //Add Premium pane only if Premium is exists.
     $dao = new CRM_Contribute_DAO_Product();
     $dao->is_active = 1;
     if ($dao->find(TRUE)) {
         $paneNames[ts('Premium Information')] = 'Premium';
     }
     if ($this->_mode) {
         if (CRM_Core_Payment_Form::buildPaymentForm($this, $this->_paymentProcessor, FALSE, TRUE) == TRUE) {
             if (!empty($this->_recurPaymentProcessors)) {
                 $buildRecurBlock = TRUE;
                 if ($this->_ppID) {
                     // ppID denotes a pledge payment.
                     foreach ($this->_paymentProcessors as $processor) {
                         if (!empty($processor['is_recur']) && !empty($processor['object']) && $processor['object']->supports('recurContributionsForPledges')) {
                             $buildRecurBlock = TRUE;
                             break;
                         }
                         $buildRecurBlock = FALSE;
                     }
                 }
                 if ($buildRecurBlock) {
                     CRM_Contribute_Form_Contribution_Main::buildRecur($this);
                     $this->setDefaults(array('is_recur' => 0));
                     $this->assign('buildRecurBlock', TRUE);
                     $recurJs = array('onChange' => "buildRecurBlock( this.value ); return false;");
                 }
             }
         }
     }
     foreach ($paneNames as $name => $type) {
         $allPanes[$name] = $this->generatePane($type, $defaults);
     }
     $qfKey = $this->controller->_key;
     $this->assign('qfKey', $qfKey);
     $this->assign('allPanes', $allPanes);
     $this->addFormRule(array('CRM_Contribute_Form_Contribution', 'formRule'), $this);
     if ($this->_formType) {
         $this->assign('formType', $this->_formType);
         return;
     }
     $this->applyFilter('__ALL__', 'trim');
     if ($this->_action & CRM_Core_Action::DELETE) {
         $this->addButtons(array(array('type' => 'next', 'name' => ts('Delete'), 'spacing' => '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;', 'isDefault' => TRUE), array('type' => 'cancel', 'name' => ts('Cancel'))));
         return;
     }
     //need to assign custom data type and subtype to the template
     $this->assign('customDataType', 'Contribution');
     $this->assign('customDataSubType', $this->_contributionType);
     $this->assign('entityID', $this->_id);
     if ($this->_context == 'standalone') {
         $this->addEntityRef('contact_id', ts('Contact'), array('create' => TRUE, 'api' => array('extra' => array('email'))), TRUE);
     }
     $attributes = CRM_Core_DAO::getAttribute('CRM_Contribute_DAO_Contribution');
     // Check permissions for financial type first
     CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($financialTypes, $this->_action);
     if (empty($financialTypes)) {
         CRM_Core_Error::statusBounce(ts('You do not have all the permissions needed for this page.'));
     }
     $financialType = $this->add('select', 'financial_type_id', ts('Financial Type'), array('' => ts('- select -')) + $financialTypes, TRUE, array('onChange' => "CRM.buildCustomData( 'Contribution', this.value );"));
     $paymentInstrument = FALSE;
     if (!$this->_mode) {
         $paymentInstrument = $this->add('select', 'payment_instrument_id', ts('Payment Method'), array('' => ts('- select -')) + CRM_Contribute_PseudoConstant::paymentInstrument(), TRUE, array('onChange' => "return showHideByValue('payment_instrument_id','4','checkNumber','table-row','select',false);"));
     }
     $trxnId = $this->add('text', 'trxn_id', ts('Transaction ID'), array('class' => 'twelve') + $attributes['trxn_id']);
     //add receipt for offline contribution
     $this->addElement('checkbox', 'is_email_receipt', ts('Send Receipt?'));
     $this->add('select', 'from_email_address', ts('Receipt From'), $this->_fromEmails);
     $status = CRM_Contribute_PseudoConstant::contributionStatus();
     // suppressing contribution statuses that are NOT relevant to pledges (CRM-5169)
     $statusName = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
     if ($this->_ppID) {
         foreach (array('Cancelled', 'Failed', 'In Progress') as $suppress) {
             unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
         }
     } elseif (!$this->_ppID && $this->_id || !$this->_id) {
         $suppressFlag = FALSE;
         if ($this->_id) {
             $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
             if (CRM_Utils_Array::value('membership', $componentDetails) || CRM_Utils_Array::value('participant', $componentDetails)) {
                 $suppressFlag = TRUE;
             }
         }
         if (!$suppressFlag) {
             foreach (array('Overdue', 'In Progress') as $suppress) {
                 unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
             }
         } else {
             unset($status[CRM_Utils_Array::key('Overdue', $statusName)]);
         }
     }
     if ($this->_id) {
         $contributionStatus = CRM_Core_DAO::getFieldValue('CRM_Contribute_DAO_Contribution', $this->_id, 'contribution_status_id');
         $name = CRM_Utils_Array::value($contributionStatus, $statusName);
         switch ($name) {
             case 'Completed':
             case 'Cancelled':
             case 'Refunded':
                 unset($status[CRM_Utils_Array::key('In Progress', $statusName)]);
                 unset($status[CRM_Utils_Array::key('Pending', $statusName)]);
                 unset($status[CRM_Utils_Array::key('Failed', $statusName)]);
                 break;
             case 'Pending':
             case 'In Progress':
                 unset($status[CRM_Utils_Array::key('Refunded', $statusName)]);
                 break;
             case 'Failed':
                 foreach (array('Pending', 'Refunded', 'Completed', 'In Progress', 'Cancelled') as $suppress) {
                     unset($status[CRM_Utils_Array::key($suppress, $statusName)]);
                 }
                 break;
         }
     } else {
         unset($status[CRM_Utils_Array::key('Refunded', $statusName)]);
     }
     $this->add('select', 'contribution_status_id', ts('Contribution Status'), $status, FALSE);
     // add various dates
     $this->addDateTime('receive_date', ts('Received'), FALSE, array('formatType' => 'activityDateTime'));
     if ($this->_online) {
         $this->assign('hideCalender', TRUE);
     }
     $checkNumber = $this->add('text', 'check_number', ts('Check Number'), $attributes['check_number']);
     $this->addDateTime('receipt_date', ts('Receipt Date'), FALSE, array('formatType' => 'activityDateTime'));
     $this->addDateTime('cancel_date', ts('Cancelled / Refunded Date'), FALSE, array('formatType' => 'activityDateTime'));
     $this->add('textarea', 'cancel_reason', ts('Cancellation / Refund Reason'), $attributes['cancel_reason']);
     $element = $this->add('select', 'payment_processor_id', ts('Payment Processor'), $this->_processors, NULL, $recurJs);
     if ($this->_online) {
         $element->freeze();
     }
     $totalAmount = NULL;
     if (empty($this->_lineItems)) {
         $buildPriceSet = FALSE;
         $priceSets = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviContribute');
         if (!empty($priceSets) && !$this->_ppID) {
             $buildPriceSet = TRUE;
         }
         // don't allow price set for contribution if it is related to participant, or if it is a pledge payment
         // and if we already have line items for that participant. CRM-5095
         if ($buildPriceSet && $this->_id) {
             $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
             $pledgePaymentId = CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $this->_id, 'id', 'contribution_id');
             if ($pledgePaymentId) {
                 $buildPriceSet = FALSE;
             }
             if ($participantID = CRM_Utils_Array::value('participant', $componentDetails)) {
                 $participantLI = CRM_Price_BAO_LineItem::getLineItems($participantID);
                 if (!CRM_Utils_System::isNull($participantLI)) {
                     $buildPriceSet = FALSE;
                 }
             }
         }
         $hasPriceSets = FALSE;
         if ($buildPriceSet) {
             $hasPriceSets = TRUE;
             // CRM-16451: set financial type of 'Price Set' in back office contribution
             // instead of selecting manually
             $financialTypeIds = CRM_Price_BAO_PriceSet::getAssoc(FALSE, 'CiviContribute', 'financial_type_id');
             $element = $this->add('select', 'price_set_id', ts('Choose price set'), array('' => ts('Choose price set')) + $priceSets, NULL, array('onchange' => "buildAmount( this.value, " . json_encode($financialTypeIds) . ");"));
             if ($this->_online && !($this->_action & CRM_Core_Action::UPDATE)) {
                 $element->freeze();
             }
         }
         $this->assign('hasPriceSets', $hasPriceSets);
         $currencyFreeze = FALSE;
         if (!($this->_action & CRM_Core_Action::UPDATE)) {
             if ($this->_online || $this->_ppID) {
                 $attributes['total_amount'] = array_merge($attributes['total_amount'], array('READONLY' => TRUE, 'style' => "background-color:#EBECE4"));
                 $optionTypes = array('1' => ts('Adjust Pledge Payment Schedule?'), '2' => ts('Adjust Total Pledge Amount?'));
                 $this->addRadio('option_type', NULL, $optionTypes, array(), '<br/>');
                 $currencyFreeze = TRUE;
             }
         }
         $totalAmount = $this->addMoney('total_amount', ts('Total Amount'), $hasPriceSets ? FALSE : TRUE, $attributes['total_amount'], TRUE, 'currency', NULL, $currencyFreeze);
     }
     $this->add('text', 'source', ts('Source'), CRM_Utils_Array::value('source', $attributes));
     // CRM-7362 --add campaigns.
     CRM_Campaign_BAO_Campaign::addCampaign($this, CRM_Utils_Array::value('campaign_id', $this->_values));
     CRM_Contribute_Form_SoftCredit::buildQuickForm($this);
     $js = NULL;
     if (!$this->_mode) {
         $js = array('onclick' => "return verify( );");
     }
     $mailingInfo = Civi::settings()->get('mailing_backend');
     $this->assign('outBound_option', $mailingInfo['outBound_option']);
     $this->addButtons(array(array('type' => 'upload', 'name' => ts('Save'), 'js' => $js, 'isDefault' => TRUE), array('type' => 'upload', 'name' => ts('Save and New'), 'js' => $js, 'subName' => 'new'), array('type' => 'cancel', 'name' => ts('Cancel'))));
     // if status is Cancelled freeze Amount, Payment Instrument, Check #, Financial Type,
     // Net and Fee Amounts are frozen in AdditionalInfo::buildAdditionalDetail
     if ($this->_id && $this->_values['contribution_status_id'] == array_search('Cancelled', $statusName)) {
         if ($totalAmount) {
             $totalAmount->freeze();
         }
         $checkNumber->freeze();
         $paymentInstrument->freeze();
         $trxnId->freeze();
         $financialType->freeze();
     }
     // if contribution is related to membership or participant freeze Financial Type, Amount
     if ($this->_id && isset($this->_values['tax_amount'])) {
         $componentDetails = CRM_Contribute_BAO_Contribution::getComponentDetails($this->_id);
         if (CRM_Utils_Array::value('membership', $componentDetails) || CRM_Utils_Array::value('participant', $componentDetails)) {
             if ($totalAmount) {
                 $totalAmount->freeze();
             }
             $financialType->freeze();
             $this->assign('freezeFinancialType', TRUE);
         }
     }
     if ($this->_action & CRM_Core_Action::VIEW) {
         $this->freeze();
     }
 }
Пример #24
0
 /**
  * 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;
 }
Пример #25
0
 /**
  * Initiate event fee.
  *
  * @param CRM_Core_Form $form
  * @param int $eventID
  *
  * @throws Exception
  */
 public static function initEventFee(&$form, $eventID)
 {
     // get price info
     // retrive all active price set fields.
     $discountId = CRM_Core_BAO_Discount::findSet($eventID, 'civicrm_event');
     if (property_exists($form, '_discountId') && $form->_discountId) {
         $discountId = $form->_discountId;
     }
     //CRM-16456 get all price field including expired one.
     $getAllPriceField = TRUE;
     $className = CRM_Utils_System::getClassName($form);
     if ($className == 'CRM_Event_Form_ParticipantFeeSelection' && $form->_action == CRM_Core_Action::UPDATE) {
         $getAllPriceField = FALSE;
     }
     if ($discountId) {
         $priceSetId = CRM_Core_DAO::getFieldValue('CRM_Core_BAO_Discount', $discountId, 'price_set_id');
         $price = CRM_Price_BAO_PriceSet::initSet($form, $eventID, 'civicrm_event', $getAllPriceField, $priceSetId);
     } else {
         $price = CRM_Price_BAO_PriceSet::initSet($form, $eventID, 'civicrm_event', $getAllPriceField);
     }
     if (property_exists($form, '_context') && ($form->_context == 'standalone' || $form->_context == 'participant')) {
         $discountedEvent = CRM_Core_BAO_Discount::getOptionGroup($eventID, 'civicrm_event');
         if (is_array($discountedEvent)) {
             foreach ($discountedEvent as $key => $priceSetId) {
                 $priceSet = CRM_Price_BAO_PriceSet::getSetDetail($priceSetId);
                 $priceSet = CRM_Utils_Array::value($priceSetId, $priceSet);
                 $form->_values['discount'][$key] = CRM_Utils_Array::value('fields', $priceSet);
                 $fieldID = key($form->_values['discount'][$key]);
                 $form->_values['discount'][$key][$fieldID]['name'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_PriceSet', $priceSetId, 'title');
             }
         }
     }
     $eventFee = CRM_Utils_Array::value('fee', $form->_values);
     if (!is_array($eventFee) || empty($eventFee)) {
         $form->_values['fee'] = array();
     }
     //fix for non-upgraded price sets.CRM-4256.
     if (isset($form->_isPaidEvent)) {
         $isPaidEvent = $form->_isPaidEvent;
     } else {
         $isPaidEvent = CRM_Utils_Array::value('is_monetary', $form->_values['event']);
     }
     if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && !empty($form->_values['fee'])) {
         foreach ($form->_values['fee'] as $k => $fees) {
             foreach ($fees['options'] as $options) {
                 if (!CRM_Core_Permission::check('add contributions of type ' . CRM_Contribute_PseudoConstant::financialType($options['financial_type_id']))) {
                     unset($form->_values['fee'][$k]);
                 }
             }
         }
     }
     if ($isPaidEvent && empty($form->_values['fee'])) {
         if (CRM_Utils_System::getClassName($form) != 'CRM_Event_Form_Participant') {
             CRM_Core_Error::fatal(ts('No Fee Level(s) or Price Set is configured for this event.<br />Click <a href=\'%1\'>CiviEvent >> Manage Event >> Configure >> Event Fees</a> to configure the Fee Level(s) or Price Set for this event.', array(1 => CRM_Utils_System::url('civicrm/event/manage/fee', 'reset=1&action=update&id=' . $form->_eventId))));
         }
     }
 }
Пример #26
0
/**
 * Delete an existing LineItem.
 *
 * This method is used to delete any existing LineItem given its id.
 *
 * @param array $params
 *   Array containing id of the group to be deleted.
 *
 * @return array
 *   API result array
 */
function civicrm_api3_line_item_delete($params)
{
    if (CRM_Financial_BAO_FinancialType::isACLFinancialTypeStatus() && CRM_Utils_Array::value('check_permissions', $params)) {
        CRM_Financial_BAO_FinancialType::getAvailableFinancialTypes($types, CRM_Core_Action::DELETE);
        if (empty($params['financial_type_id'])) {
            $params['financial_type_id'] = CRM_Core_DAO::getFieldValue('CRM_Price_DAO_LineItem', $params['id'], 'financial_type_id');
        }
        if (!in_array($params['financial_type_id'], array_keys($types))) {
            throw new API_Exception('You do not have permission to delete this line item');
        }
    }
    return _civicrm_api3_basic_delete(_civicrm_api3_get_BAO(__FUNCTION__), $params);
}