Beispiel #1
0
 /**
  * create honor-contact method 
  * createHonorContact();
  */
 function testcreateAndGetHonorContact()
 {
     $this->markTestSkipped('throws fatals');
     $honorId = null;
     $params = array('honor_type_id' => 1, 'honor_prefix_id' => 3, 'honor_first_name' => 'John', 'honor_last_name' => 'Smith', 'honor_email' => '*****@*****.**');
     $contact = CRM_Contribute_BAO_Contribution::createHonorContact($params, $honorId);
     $this->assertDBCompareValue('CRM_Contact_DAO_Contact', $contact, 'first_name', 'id', 'John', 'Database check for created honor contact record.');
     //create contribution on behalf of honary.
     $contactId = Contact::createIndividual();
     $ids = array('contribution' => null);
     $param = array('contact_id' => $contactId, 'currency' => 'USD', 'contribution_type_id' => 4, 'contribution_status_id' => 1, 'receive_date' => date('Ymd'), 'total_amount' => 66, 'honor_type_id' => 1, 'honor_contact_id' => $contact);
     require_once 'CRM/Contribute/BAO/Contribution.php';
     $contribution = CRM_Contribute_BAO_Contribution::create($param, $ids);
     $id = $contribution->id;
     $this->assertDBCompareValue('CRM_Contribute_DAO_Contribution', $id, 'honor_contact_id', 'id', $contact, 'Check DB for honor contact of the contribution');
     //get honory information
     $getHonorContact = CRM_Contribute_BAO_Contribution::getHonorContacts($contact);
     $this->assertDBCompareValue('CRM_Contact_DAO_Contact', $contact, 'first_name', 'id', 'John', 'Database check for created honor contact record.');
     //get annual contribution information
     $annual = CRM_Contribute_BAO_Contribution::annual($contactId);
     require_once 'CRM/Core/DAO.php';
     $config =& CRM_Core_Config::singleton();
     $currencySymbol = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_Currency', $config->defaultCurrency, 'symbol', 'name');
     $this->assertDBCompareValue('CRM_Contribute_DAO_Contribution', $id, 'total_amount', 'id', ltrim($annual[2], $currencySymbol), 'Check DB for total amount of the contribution');
     //Delete honor contact
     Contact::delete($contact);
     //Delete contributor contact
     Contact::delete($contactId);
 }
Beispiel #2
0
 /** 
  * Function to process the form 
  * 
  * @access public 
  * @return None 
  */
 public function postProcess()
 {
     if ($this->_action & CRM_Core_Action::DELETE) {
         require_once 'CRM/Pledge/BAO/Pledge.php';
         CRM_Pledge_BAO_Pledge::deletePledge($this->_id);
         return;
     }
     //get the submitted form values.
     $formValues = $this->controller->exportValues($this->_name);
     // set the contact, when contact is selected
     if (CRM_Utils_Array::value('contact_select_id', $formValues)) {
         $this->_contactID = CRM_Utils_Array::value('contact_select_id', $formValues);
     }
     $config =& CRM_Core_Config::singleton();
     $session =& CRM_Core_Session::singleton();
     //get All Payments status types.
     $paymentStatusTypes = CRM_Contribute_PseudoConstant::contributionStatus();
     $fields = array('frequency_unit', 'frequency_interval', 'frequency_day', 'installments', 'contribution_type_id', 'initial_reminder_day', 'max_reminders', 'additional_reminder_day', 'honor_type_id', 'honor_prefix_id', 'honor_first_name', 'honor_last_name', 'honor_email', 'contribution_page_id');
     foreach ($fields as $f) {
         $params[$f] = CRM_Utils_Array::value($f, $formValues);
     }
     //defaults status is "Pending".
     //if update get status.
     if ($this->_id) {
         $params['pledge_status_id'] = $params['status_id'] = $this->_values['status_id'];
     } else {
         $params['pledge_status_id'] = $params['status_id'] = array_search('Pending', $paymentStatusTypes);
     }
     //format amount
     $params['amount'] = CRM_Utils_Rule::cleanMoney(CRM_Utils_Array::value('amount', $formValues));
     $dates = array('create_date', 'start_date', 'acknowledge_date', 'cancel_date');
     foreach ($dates as $d) {
         if ($this->_id && !$this->_isPending) {
             if ($d == 'start_date') {
                 $params['scheduled_date'] = CRM_Utils_Date::processDate($this->_values[$d]);
             }
             $params[$d] = CRM_Utils_Date::processDate($this->_values[$d]);
         } else {
             if (CRM_Utils_Array::value($d, $formValues) && !CRM_Utils_System::isNull($formValues[$d])) {
                 if ($d == 'start_date') {
                     $params['scheduled_date'] = CRM_Utils_Date::processDate($formValues[$d]);
                 }
                 $params[$d] = CRM_Utils_Date::processDate($formValues[$d]);
             } else {
                 $params[$d] = 'null';
             }
         }
     }
     if (CRM_Utils_Array::value('is_acknowledge', $formValues)) {
         $params['acknowledge_date'] = date("Y-m-d");
     }
     // assign id only in update mode
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $params['id'] = $this->_id;
     }
     $params['contact_id'] = $this->_contactID;
     //handle Honoree contact.
     if (CRM_Utils_Array::value('honor_type_id', $params)) {
         require_once 'CRM/Contribute/BAO/Contribution.php';
         if ($this->_honorID) {
             $honorID = CRM_Contribute_BAO_Contribution::createHonorContact($params, $this->_honorID);
         } else {
             $honorID = CRM_Contribute_BAO_Contribution::createHonorContact($params);
         }
         $params["honor_contact_id"] = $honorID;
     } else {
         $params["honor_contact_id"] = 'null';
     }
     //format custom data
     if (CRM_Utils_Array::value('hidden_custom', $formValues)) {
         $params['hidden_custom'] = 1;
         $customFields = CRM_Core_BAO_CustomField::getFields('Pledge');
         $params['custom'] = CRM_Core_BAO_CustomField::postProcess($formValues, $customFields, $this->_id, 'Pledge');
     }
     //handle pending pledge.
     $params['is_pledge_pending'] = $this->_isPending;
     //create pledge record.
     require_once 'CRM/Pledge/BAO/Pledge.php';
     $pledge =& CRM_Pledge_BAO_Pledge::create($params);
     $statusMsg = null;
     if ($pledge->id) {
         //set the status msg.
         if ($this->_action & CRM_Core_Action::ADD) {
             $statusMsg = ts('Pledge has been recorded and the payment schedule has been created.<br />');
         } else {
             if ($this->_action & CRM_Core_Action::UPDATE) {
                 $statusMsg = ts('Pledge has been updated.<br />');
             }
         }
     }
     //handle Acknowledgment.
     if (CRM_Utils_Array::value('is_acknowledge', $formValues) && $pledge->id) {
         //calculate scheduled amount.
         $params['scheduled_amount'] = round($params['amount'] / $params['installments']);
         $params['total_pledge_amount'] = $params['amount'];
         //get some required pledge values in params.
         $params['id'] = $pledge->id;
         $params['acknowledge_date'] = $pledge->acknowledge_date;
         $params['is_test'] = $pledge->is_test;
         $this->paymentId = null;
         //send Acknowledgment mail.
         require_once 'CRM/Pledge/BAO/Pledge.php';
         CRM_Pledge_BAO_Pledge::sendAcknowledgment($this, $params);
         $statusMsg .= ' ' . ts("An acknowledgment email has been sent to %1.<br />", array(1 => $this->userEmail));
         //build the payment urls.
         if ($this->paymentId) {
             $urlParams = "reset=1&action=add&cid={$this->_contactID}&ppid={$this->paymentId}&context=pledge";
             $contribURL = CRM_Utils_System::url('civicrm/contact/view/contribution', $urlParams);
             $urlParams .= "&mode=live";
             $creditURL = CRM_Utils_System::url('civicrm/contact/view/contribution', $urlParams);
             //check if we can process credit card payment.
             $processors = CRM_Core_PseudoConstant::paymentProcessor(false, false, "billing_mode IN ( 1, 3 )");
             if (count($processors) > 0) {
                 $statusMsg .= ' ' . ts("If a payment is due now, you can record <a href='%1'>a check, EFT, or cash payment for this pledge</a> OR <a href='%2'>submit a credit card payment</a>.", array(1 => $contribURL, 2 => $creditURL));
             } else {
                 $statusMsg .= ' ' . ts("If a payment is due now, you can record <a href='%1'>a check, EFT, or cash payment for this pledge</a>.", array(1 => $contribURL));
             }
         }
     }
     CRM_Core_Session::setStatus($statusMsg);
     $buttonName = $this->controller->getButtonName();
     if ($this->_context == 'standalone') {
         if ($buttonName == $this->getButtonName('upload', 'new')) {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/pledge/add', 'reset=1&action=add&context=standalone'));
         } else {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view', "reset=1&cid={$this->_contactID}&selectedChild=pledge"));
         }
     } else {
         if ($buttonName == $this->getButtonName('upload', 'new')) {
             $session->replaceUserContext(CRM_Utils_System::url('civicrm/contact/view/pledge', "reset=1&action=add&context=pledge&cid={$this->_contactID}"));
         }
     }
 }
Beispiel #3
0
 /**
  * Create the Honor contact
  *
  * @return void
  * @access public
  */
 function createHonorContact()
 {
     $params = $this->controller->exportValues('Main');
     // return if we dont have enough information
     if (empty($params["honor_first_name"]) && empty($params["honor_last_name"]) && empty($params["honor_email"])) {
         return null;
     }
     //assign to template for email reciept
     $honor_block_is_active = $this->get('honor_block_is_active');
     $this->assign('honor_block_is_active', $honor_block_is_active);
     $this->assign("honor_block_title", $this->_values['honor_block_title']);
     require_once "CRM/Core/PseudoConstant.php";
     $prefix = CRM_Core_PseudoConstant::individualPrefix();
     $honorType = CRM_Core_PseudoConstant::honor();
     $this->assign("honor_type", $honorType[$params["honor_type_id"]]);
     $this->assign("honor_prefix", $prefix[$params["honor_prefix_id"]]);
     $this->assign("honor_first_name", $params["honor_first_name"]);
     $this->assign("honor_last_name", $params["honor_last_name"]);
     $this->assign("honor_email", $params["honor_email"]);
     //create honoree contact
     require_once 'CRM/Contribute/BAO/Contribution.php';
     return CRM_Contribute_BAO_Contribution::createHonorContact($params);
 }
 /** 
  * Function to process the Common data 
  *  
  * @access public 
  * @return None 
  */
 function postProcessCommon(&$params, &$formatted)
 {
     $fields = array('non_deductible_amount', 'total_amount', 'fee_amount', 'net_amount', 'trxn_id', 'invoice_id', 'honor_type_id', 'contribution_page_id');
     foreach ($fields as $f) {
         $formatted[$f] = CRM_Utils_Array::value($f, $params);
     }
     if (CRM_Utils_Array::value('thankyou_date', $params) && !CRM_Utils_System::isNull($params['thankyou_date'])) {
         $formatted['thankyou_date'] = CRM_Utils_Date::processDate($params['thankyou_date'], $params['thankyou_date_time']);
     } else {
         $formatted['thankyou_date'] = 'null';
     }
     if (CRM_Utils_Array::value('is_email_receipt', $params)) {
         $params['receipt_date'] = $formatted['receipt_date'] = date('YmdHis');
     }
     if (CRM_Utils_Array::value('honor_type_id', $params)) {
         require_once 'CRM/Contribute/BAO/Contribution.php';
         if ($this->_honorID) {
             $honorId = CRM_Contribute_BAO_Contribution::createHonorContact($params, $this->_honorID);
         } else {
             $honorId = CRM_Contribute_BAO_Contribution::createHonorContact($params);
         }
         $formatted["honor_contact_id"] = $honorId;
     } else {
         $formatted["honor_contact_id"] = 'null';
     }
     //special case to handle if all checkboxes are unchecked
     $customFields = CRM_Core_BAO_CustomField::getFields('Contribution', false, false, CRM_Utils_Array::value('contribution_type_id', $params));
     $formatted['custom'] = CRM_Core_BAO_CustomField::postProcess($params, $customFields, CRM_Utils_Array::value('id', $params, null), 'Contribution');
 }
 /**
  * Create the Honor contact
  *
  * @return void
  * @access public
  */
 function createHonorContact()
 {
     $params = $this->controller->exportValues('Main');
     // email is enough to create a contact
     if (!CRM_Utils_Array::value('honor_email', $params) && (!CRM_Utils_Array::value('honor_first_name', $params) || !CRM_Utils_Array::value('honor_last_name', $params))) {
         //don't create contact - possibly the form was left blank
         return null;
     }
     //assign to template for email receipt
     $honor_block_is_active = $this->get('honor_block_is_active');
     $this->assign('honor_block_is_active', $honor_block_is_active);
     $this->assign('honor_block_title', CRM_Utils_Array::value('honor_block_title', $this->_values));
     $prefix = CRM_Core_PseudoConstant::individualPrefix();
     $honorType = CRM_Core_PseudoConstant::honor();
     $this->assign('honor_type', CRM_Utils_Array::value(CRM_Utils_Array::value('honor_type_id', $params), $honorType));
     $this->assign('honor_prefix', CRM_Utils_Array::value(CRM_Utils_Array::value('honor_prefix_id', $params), $prefix));
     $this->assign('honor_first_name', CRM_Utils_Array::value('honor_first_name', $params));
     $this->assign('honor_last_name', CRM_Utils_Array::value('honor_last_name', $params));
     $this->assign('honor_email', CRM_Utils_Array::value('honor_email', $params));
     //create honoree contact
     return CRM_Contribute_BAO_Contribution::createHonorContact($params);
 }