public static function allForContact($contactId)
 {
     $statusNames = CRM_Core_OptionGroup::values("pcp_status", FALSE, FALSE, FALSE, NULL, 'name');
     $query = "SELECT\r\n           pcp.id,\r\n           pcp.title,\r\n           pcp.status_id,\r\n           pcp.page_id,\r\n           count(cc.total_amount) as contribution_count,\r\n           sum(cc.total_amount) as amount_raised,\r\n           pcp.goal_amount,\r\n           pcp.currency\r\n      FROM civicrm_pcp pcp\r\n      LEFT JOIN civicrm_contribution_soft cs ON ( pcp.id = cs.pcp_id )\r\n      LEFT JOIN civicrm_contribution cc ON ( cs.contribution_id = cc.id)\r\n      WHERE pcp.contact_id = %1\r\n      GROUP BY pcp.id";
     $cpages = CRM_Core_DAO::executeQuery($query, array(1 => array($contactId, 'Integer')));
     $pages = array();
     while ($cpages->fetch()) {
         $pages[] = array('id' => $cpages->id, 'title' => $cpages->title, 'status' => $statusNames[$cpages->status_id], 'page' => CRM_PCP_BAO_PCP::getPcpPageTitle($cpages->page_id, 'contribute'), 'contribution_count' => $cpages->contribution_count, 'amount_raised' => $cpages->amount_raised, 'goal_amount' => $cpages->goal_amount, 'currency' => $cpages->currency);
     }
     return $pages;
 }
Ejemplo n.º 2
0
 /**
  * Function used to set defaults for soft credit block.
  *
  * @param $defaults
  * @param $form
  */
 public static function setDefaultValues(&$defaults, &$form)
 {
     //Used to hide/unhide PCP and/or Soft-credit Panes
     $noPCP = $noSoftCredit = TRUE;
     if (!empty($form->_softCreditInfo['soft_credit'])) {
         $noSoftCredit = FALSE;
         foreach ($form->_softCreditInfo['soft_credit'] as $key => $value) {
             $defaults["soft_credit_amount[{$key}]"] = CRM_Utils_Money::format($value['amount'], NULL, '%a');
             $defaults["soft_credit_contact_id[{$key}]"] = $value['contact_id'];
             $defaults["soft_credit_type[{$key}]"] = $value['soft_credit_type'];
         }
     }
     if (!empty($form->_softCreditInfo['pcp_id'])) {
         $noPCP = FALSE;
         $pcpInfo = $form->_softCreditInfo;
         $pcpId = CRM_Utils_Array::value('pcp_id', $pcpInfo);
         $pcpTitle = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcpId, 'title');
         $contributionPageTitle = CRM_PCP_BAO_PCP::getPcpPageTitle($pcpId, 'contribute');
         $defaults['pcp_made_through'] = CRM_Utils_Array::value('sort_name', $pcpInfo) . " :: " . $pcpTitle . " :: " . $contributionPageTitle;
         $defaults['pcp_made_through_id'] = CRM_Utils_Array::value('pcp_id', $pcpInfo);
         $defaults['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $pcpInfo);
         $defaults['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $pcpInfo);
         $defaults['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $pcpInfo);
     }
     $form->assign('noSoftCredit', $noSoftCredit);
     $form->assign('noPCP', $noPCP);
 }
Ejemplo n.º 3
0
 /**
  * Function used to set defaults for soft credit block
  */
 static function setDefaultValues(&$defaults, &$form)
 {
     if (!empty($form->_softCreditInfo['soft_credit'])) {
         foreach ($form->_softCreditInfo['soft_credit'] as $key => $value) {
             $defaults["soft_credit_amount[{$key}]"] = CRM_Utils_Money::format($value['amount'], NULL, '%a');
             $defaults["soft_credit_contact_select_id[{$key}]"] = $value['contact_id'];
             $defaults["soft_credit_type[{$key}]"] = $value['soft_credit_type'];
         }
     } elseif (!empty($form->_softCreditInfo['pcp_id'])) {
         $pcpInfo = $form->_softCreditInfo;
         $pcpId = CRM_Utils_Array::value('pcp_id', $pcpInfo);
         $pcpTitle = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcpId, 'title');
         $contributionPageTitle = CRM_PCP_BAO_PCP::getPcpPageTitle($pcpId, 'contribute');
         $defaults['pcp_made_through'] = CRM_Utils_Array::value('sort_name', $pcpInfo) . " :: " . $pcpTitle . " :: " . $contributionPageTitle;
         $defaults['pcp_made_through_id'] = CRM_Utils_Array::value('pcp_id', $pcpInfo);
         $defaults['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $pcpInfo);
         $defaults['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $pcpInfo);
         $defaults['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $pcpInfo);
     }
 }
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     //check permission for action.
     if (!CRM_Core_Permission::checkActionPermission('CiviContribute', $this->_action)) {
         CRM_Core_Error::fatal(ts('You do not have permission to access this page'));
     }
     $this->_cdType = CRM_Utils_Array::value('type', $_GET);
     $this->assign('cdType', FALSE);
     if ($this->_cdType) {
         $this->assign('cdType', TRUE);
         return CRM_Custom_Form_CustomData::preProcess($this);
     }
     $this->_formType = CRM_Utils_Array::value('formType', $_GET);
     // get price set id.
     $this->_priceSetId = CRM_Utils_Array::value('priceSetId', $_GET);
     $this->set('priceSetId', $this->_priceSetId);
     $this->assign('priceSetId', $this->_priceSetId);
     //get the pledge payment id
     $this->_ppID = CRM_Utils_Request::retrieve('ppid', 'Positive', $this);
     //get the contact id
     $this->_contactID = CRM_Utils_Request::retrieve('cid', 'Positive', $this);
     //get the action.
     $this->_action = CRM_Utils_Request::retrieve('action', 'String', $this, FALSE, 'add');
     $this->assign('action', $this->_action);
     //get the contribution id if update
     $this->_id = CRM_Utils_Request::retrieve('id', 'Positive', $this);
     $this->_context = CRM_Utils_Request::retrieve('context', 'String', $this);
     $this->assign('context', $this->_context);
     $this->_compId = CRM_Utils_Request::retrieve('compId', 'Positive', $this);
     //set the contribution mode.
     $this->_mode = CRM_Utils_Request::retrieve('mode', 'String', $this);
     $this->assign('contributionMode', $this->_mode);
     $this->_paymentProcessor = array('billing_mode' => 1);
     $this->assign('showCheckNumber', FALSE);
     $this->_fromEmails = CRM_Core_BAO_Email::getFromEmail();
     //ensure that processor has a valid config
     //only valid processors get display to user
     if ($this->_mode) {
         $validProcessors = array();
         $processors = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, "billing_mode IN ( 1, 3 )");
         foreach ($processors as $ppID => $label) {
             $paymentProcessor = CRM_Core_BAO_PaymentProcessor::getPayment($ppID, $this->_mode);
             // at this stage only Authorize.net has been tested to support future start dates so if it's enabled let the template know
             // to show receive date
             $processorsSupportingFutureStartDate = array('AuthNet');
             if (in_array($paymentProcessor['payment_processor_type'], $processorsSupportingFutureStartDate)) {
                 $this->assign('processorSupportsFutureStartDate', TRUE);
             }
             if ($paymentProcessor['payment_processor_type'] == 'PayPal' && !$paymentProcessor['user_name']) {
                 continue;
             } elseif ($paymentProcessor['payment_processor_type'] == 'Dummy' && $this->_mode == 'live') {
                 continue;
             } else {
                 $paymentObject = CRM_Core_Payment::singleton($this->_mode, $paymentProcessor, $this);
                 $error = $paymentObject->checkConfig();
                 if (empty($error)) {
                     $validProcessors[$ppID] = $label;
                 }
                 $paymentObject = NULL;
             }
         }
         if (empty($validProcessors)) {
             CRM_Core_Error::fatal(ts('You will need to configure the %1 settings for your Payment Processor before you can submit credit card transactions.', array(1 => $this->_mode)));
         } else {
             $this->_processors = $validProcessors;
         }
         //get the valid recurring processors.
         $recurring = CRM_Core_PseudoConstant::paymentProcessor(FALSE, FALSE, 'is_recur = 1');
         $this->_recurPaymentProcessors = array_intersect_assoc($this->_processors, $recurring);
     }
     $this->assign('recurringPaymentProcessorIds', empty($this->_recurPaymentProcessors) ? '' : implode(',', array_keys($this->_recurPaymentProcessors)));
     // this required to show billing block
     $this->assign_by_ref('paymentProcessor', $paymentProcessor);
     $this->assign('hidePayPalExpress', TRUE);
     if ($this->_contactID) {
         list($this->userDisplayName, $this->userEmail) = CRM_Contact_BAO_Contact_Location::getEmailDetails($this->_contactID);
         $this->assign('displayName', $this->userDisplayName);
     }
     // also check for billing information
     // get the billing location type
     $locationTypes = CRM_Core_PseudoConstant::locationType();
     $this->_bltID = array_search('Billing', $locationTypes);
     if (!$this->_bltID) {
         CRM_Core_Error::fatal(ts('Please set a location type of %1', array(1 => 'Billing')));
     }
     $this->set('bltID', $this->_bltID);
     $this->assign('bltID', $this->_bltID);
     $this->_fields = array();
     // payment fields are depending on payment type
     if (CRM_Utils_Array::value('payment_type', $this->_processors) & CRM_Core_Payment::PAYMENT_TYPE_DIRECT_DEBIT) {
         CRM_Core_Payment_Form::setDirectDebitFields($this);
     } else {
         CRM_Core_Payment_Form::setCreditCardFields($this);
     }
     if ($this->_action & CRM_Core_Action::DELETE) {
         return;
     }
     $config = CRM_Core_Config::singleton();
     if (in_array('CiviPledge', $config->enableComponents) && !$this->_formType) {
         //get the payment values associated with given pledge payment id OR check for payments due.
         $this->_pledgeValues = array();
         if ($this->_ppID) {
             $payParams = array('id' => $this->_ppID);
             CRM_Pledge_BAO_PledgePayment::retrieve($payParams, $this->_pledgeValues['pledgePayment']);
             $this->_pledgeID = CRM_Utils_Array::value('pledge_id', $this->_pledgeValues['pledgePayment']);
             $paymentStatusID = CRM_Utils_Array::value('status_id', $this->_pledgeValues['pledgePayment']);
             $this->_id = CRM_Utils_Array::value('contribution_id', $this->_pledgeValues['pledgePayment']);
             //get all status
             $allStatus = CRM_Contribute_PseudoConstant::contributionStatus(NULL, 'name');
             if (!($paymentStatusID == array_search('Pending', $allStatus) || $paymentStatusID == array_search('Overdue', $allStatus))) {
                 CRM_Core_Error::fatal(ts("Pledge payment status should be 'Pending' or  'Overdue'."));
             }
             //get the pledge values associated with given pledge payment.
             $ids = array();
             $pledgeParams = array('id' => $this->_pledgeID);
             CRM_Pledge_BAO_Pledge::getValues($pledgeParams, $this->_pledgeValues, $ids);
             $this->assign('ppID', $this->_ppID);
         } else {
             // Not making a pledge payment, so if adding a new contribution we should check if pledge payment(s) are due for this contact so we can alert the user. CRM-5206
             if (isset($this->_contactID)) {
                 $contactPledges = array();
                 $contactPledges = CRM_Pledge_BAO_Pledge::getContactPledges($this->_contactID);
                 if (!empty($contactPledges)) {
                     $payments = $paymentsDue = NULL;
                     $multipleDue = FALSE;
                     foreach ($contactPledges as $key => $pledgeId) {
                         $payments = CRM_Pledge_BAO_PledgePayment::getOldestPledgePayment($pledgeId);
                         if ($payments) {
                             if ($paymentsDue) {
                                 $multipleDue = TRUE;
                                 break;
                             } else {
                                 $paymentsDue = $payments;
                             }
                         }
                     }
                     if ($multipleDue) {
                         // Show link to pledge tab since more than one pledge has a payment due
                         $pledgeTab = CRM_Utils_System::url('civicrm/contact/view', "reset=1&force=1&cid={$this->_contactID}&selectedChild=pledge");
                         CRM_Core_Session::setStatus(ts('This contact has pending or overdue pledge payments. <a href="%1">Click here to view their Pledges tab</a> and verify whether this contribution should be applied as a pledge payment.', array(1 => $pledgeTab)));
                     } elseif ($paymentsDue) {
                         // Show user link to oldest Pending or Overdue pledge payment
                         $ppAmountDue = CRM_Utils_Money::format($payments['amount'], $payments['currency']);
                         $ppSchedDate = CRM_Utils_Date::customFormat(CRM_Core_DAO::getFieldValue('CRM_Pledge_DAO_PledgePayment', $payments['id'], 'scheduled_date'));
                         if ($this->_mode) {
                             $ppUrl = CRM_Utils_System::url('civicrm/contact/view/contribution', "reset=1&action=add&cid={$this->_contactID}&ppid={$payments['id']}&context=pledge&mode=live");
                         } else {
                             $ppUrl = CRM_Utils_System::url('civicrm/contact/view/contribution', "reset=1&action=add&cid={$this->_contactID}&ppid={$payments['id']}&context=pledge");
                         }
                         CRM_Core_Session::setStatus(ts('This contact has a pending or overdue pledge payment of %2 which is scheduled for %3. <a href="%1">Click here to enter a pledge payment</a>.', array(1 => $ppUrl, 2 => $ppAmountDue, 3 => $ppSchedDate)));
                     }
                 }
             }
         }
     }
     $this->_values = array();
     // current contribution id
     if ($this->_id) {
         //to get Premium id
         $sql = "\nSELECT *\nFROM   civicrm_contribution_product\nWHERE  contribution_id = {$this->_id}\n";
         $dao = CRM_Core_DAO::executeQuery($sql, CRM_Core_DAO::$_nullArray);
         if ($dao->fetch()) {
             $this->_premiumID = $dao->id;
             $this->_productDAO = $dao;
         }
         $dao->free();
         $ids = array();
         $params = array('id' => $this->_id);
         CRM_Contribute_BAO_Contribution::getValues($params, $this->_values, $ids);
         //do check for online / recurring contributions
         $fids = CRM_Core_BAO_FinancialTrxn::getFinancialTrxnIds($this->_id, 'civicrm_contribution');
         $this->_online = CRM_Utils_Array::value('entityFinancialTrxnId', $fids);
         //don't allow to update all fields for recuring contribution.
         if (!$this->_online) {
             $this->_online = CRM_Utils_Array::value('contribution_recur_id', $this->_values);
         }
         $this->assign('isOnline', $this->_online ? TRUE : FALSE);
         //unset the honor type id:when delete the honor_contact_id
         //and edit the contribution, honoree infomation pane open
         //since honor_type_id is present
         if (!CRM_Utils_Array::value('honor_contact_id', $this->_values)) {
             unset($this->_values['honor_type_id']);
         }
         //to get note id
         $daoNote = new CRM_Core_BAO_Note();
         $daoNote->entity_table = 'civicrm_contribution';
         $daoNote->entity_id = $this->_id;
         if ($daoNote->find(TRUE)) {
             $this->_noteID = $daoNote->id;
             $this->_values['note'] = $daoNote->note;
         }
         $this->_contributionType = $this->_values['contribution_type_id'];
         $csParams = array('contribution_id' => $this->_id);
         $softCredit = CRM_Contribute_BAO_Contribution::getSoftContribution($csParams, TRUE);
         if (CRM_Utils_Array::value('soft_credit_to', $softCredit)) {
             $softCredit['sort_name'] = CRM_Core_DAO::getFieldValue('CRM_Contact_DAO_Contact', $softCredit['soft_credit_to'], 'sort_name');
         }
         $this->_values['soft_credit_to'] = CRM_Utils_Array::value('sort_name', $softCredit);
         $this->_values['softID'] = CRM_Utils_Array::value('soft_credit_id', $softCredit);
         $this->_values['soft_contact_id'] = CRM_Utils_Array::value('soft_credit_to', $softCredit);
         if (CRM_Utils_Array::value('pcp_id', $softCredit)) {
             $pcpId = CRM_Utils_Array::value('pcp_id', $softCredit);
             $pcpTitle = CRM_Core_DAO::getFieldValue('CRM_PCP_DAO_PCP', $pcpId, 'title');
             $contributionPageTitle = CRM_PCP_BAO_PCP::getPcpPageTitle($pcpId, 'contribute');
             $this->_values['pcp_made_through'] = CRM_Utils_Array::value('sort_name', $softCredit) . " :: " . $pcpTitle . " :: " . $contributionPageTitle;
             $this->_values['pcp_made_through_id'] = CRM_Utils_Array::value('pcp_id', $softCredit);
             $this->_values['pcp_display_in_roll'] = CRM_Utils_Array::value('pcp_display_in_roll', $softCredit);
             $this->_values['pcp_roll_nickname'] = CRM_Utils_Array::value('pcp_roll_nickname', $softCredit);
             $this->_values['pcp_personal_note'] = CRM_Utils_Array::value('pcp_personal_note', $softCredit);
         }
         //display check number field only if its having value or its offline mode.
         if (CRM_Utils_Array::value('payment_instrument_id', $this->_values) == CRM_Core_OptionGroup::getValue('payment_instrument', 'Check', 'name') || CRM_Utils_Array::value('check_number', $this->_values)) {
             $this->assign('showCheckNumber', TRUE);
         }
     }
     // when custom data is included in this page
     if (CRM_Utils_Array::value('hidden_custom', $_POST)) {
         $this->set('type', 'Contribution');
         $this->set('subType', CRM_Utils_Array::value('contribution_type_id', $_POST));
         $this->set('entityId', $this->_id);
         CRM_Custom_Form_CustomData::preProcess($this);
         CRM_Custom_Form_CustomData::buildQuickForm($this);
         CRM_Custom_Form_CustomData::setDefaultValues($this);
     }
     $this->_lineItems = array();
     if ($this->_id) {
         $lineItem = CRM_Price_BAO_LineItem::getLineItems($this->_id, 'contribution', 1);
         empty($lineItem) ? null : ($this->_lineItems[] = $lineItem);
     }
     $this->assign('lineItem', empty($this->_lineItems) ? FALSE : $this->_lineItems);
 }