Exemplo n.º 1
0
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     parent::preProcess();
     //Set up prevalue
     $bookingAmount = CRM_Booking_BAO_Booking::getBookingAmount($this->_id);
     $this->_values['resource_fee'] = CRM_Utils_Array::value('resource_fees', $bookingAmount);
     $this->_values['sub_resource_fee'] = CRM_Utils_Array::value('sub_resource_fees', $bookingAmount);
     $this->_values['adhoc_charges'] = CRM_Utils_Array::value('adhoc_charges_fees', $bookingAmount);
     $this->_values['discount_amount'] = CRM_Utils_Array::value('discount_amount', $bookingAmount);
     $this->_values['booking_total'] = CRM_Utils_Array::value('total_amount', $bookingAmount);
     $this->assign('booking', $this->_values);
     self::registerScripts();
 }
Exemplo n.º 2
0
 /**
  * Process that send e-mails
  *
  * @return void
  * @access public
  */
 static function sendMail($contactID, &$values, $isTest = FALSE, $returnMessageText = FALSE)
 {
     //TODO:: check if from email address is entered
     $config = CRM_Booking_BAO_BookingConfig::getConfig();
     $template = CRM_Core_Smarty::singleton();
     list($displayName, $email) = CRM_Contact_BAO_Contact_Location::getEmailDetails($contactID);
     //send email only when email is present
     if ($email) {
         $bookingId = $values['booking_id'];
         //get latest booking status
         $params = array('id' => $bookingId);
         $bookingLatest = civicrm_api3('Booking', 'get', $params);
         $bookingStatusValueItems = CRM_Booking_BAO_Booking::buildOptions('status_id', 'create');
         //get booking status option values
         $bookingLatestStatus = $bookingStatusValueItems[$bookingLatest['values'][$bookingId]['status_id']];
         //get booking detail
         $bookingDetail = CRM_Booking_BAO_Booking::getBookingDetails($values['booking_id']);
         $slots = CRM_Utils_Array::value('slots', $bookingDetail);
         $subSlots = CRM_Utils_Array::value('sub_slots', $bookingDetail);
         $adhocCharges = CRM_Utils_Array::value('adhoc_charges', $bookingDetail);
         $cancellationCharges = CRM_Utils_Array::value('cancellation_charges', $bookingDetail);
         //get contacts associating with booking
         $contactIds = array();
         $contactIds['primary_contact'] = CRM_Utils_Array::value('primary_contact_id', $values);
         $contactIds['secondary_contact'] = CRM_Utils_Array::value('secondary_contact_id', $values);
         $contactsDetail = array();
         foreach (array_filter($contactIds) as $k => $contactIdItem) {
             //get contact detail
             $contactDetail = array();
             $params = array('contact_id' => $contactIdItem);
             $contactDetailResult = civicrm_api3('Contact', 'get', $params);
             $contactValues = CRM_Utils_Array::value($contactDetailResult['id'], $contactDetailResult['values']);
             foreach ($contactValues as $key => $contactItem) {
                 $contactDetail[$key] = $contactItem;
             }
             $contactsDetail[$k] = $contactDetail;
         }
         //get Price elements(Subtotal, Discount, Total)
         $booking_amount = CRM_Booking_BAO_Booking::getBookingAmount($values['booking_id']);
         //get date booking made
         $dateBookingMade = new DateTime($values['booking_date']);
         $tplParams = array('email' => $email, 'today_date' => date('d.m.Y'), 'receipt_header_message' => $values['receipt_header_message'], 'receipt_footer_message' => $values['receipt_footer_message'], 'booking_id' => $bookingId, 'booking_title' => $values['booking_title'], 'booking_status' => $bookingLatestStatus, 'booking_date_made' => $values['booking_date'], 'booking_start_date' => $values['booking_start_date'], 'booking_end_date' => $values['booking_end_date'], 'booking_event_day' => $dateBookingMade->format('l'), 'booking_subtotal' => number_format($booking_amount['total_amount'] + $booking_amount['discount_amount'], 2, '.', ''), 'booking_total' => number_format($booking_amount['total_amount'], 2, '.', ''), 'booking_discount' => number_format($booking_amount['discount_amount'], 2, '.', ''), 'participants_estimate' => $values['participants_estimate'], 'participants_actual' => $values['participants_actual'], 'contacts' => $contactsDetail, 'slots' => $slots, 'sub_slots' => $subSlots, 'adhoc_charges' => $adhocCharges, 'cancellation_charges' => $cancellationCharges);
         $sendTemplateParams = array('groupName' => 'msg_tpl_workflow_booking', 'valueName' => 'booking_offline_receipt', 'contactId' => $contactID, 'isTest' => $isTest, 'tplParams' => $tplParams, 'PDFFilename' => 'bookingReceipt.pdf');
         //get include payment check box
         //if(CRM_Utils_Array::value('include_payment_info', $values)){
         if (CRM_Utils_Array::value('contribution', $bookingDetail)) {
             //get contribution record
             $contribution = array();
             $contributionResult = CRM_Utils_Array::value('contribution', $bookingDetail);
             foreach ($contributionResult as $kx => $ctbItem) {
                 $contribution = $ctbItem;
             }
             $sendTemplateParams['tplParams']['contribution'] = $contribution;
             //calculate Amount outstanding
             $sendTemplateParams['tplParams']['amount_outstanding'] = number_format($booking_amount['total_amount'] - $contribution['total_amount'], 2, '.', '');
         }
         //TODO:: add line item tpl params
         if ($lineItem = CRM_Utils_Array::value('lineItem', $values)) {
             $sendTemplateParams['tplParams']['lineItem'] = $lineItem;
         }
         $sendTemplateParams['from'] = $values['from_email_address'];
         $sendTemplateParams['toName'] = $displayName;
         $sendTemplateParams['toEmail'] = $email;
         //$sendTemplateParams['autoSubmitted'] = TRUE;
         $cc = CRM_Utils_Array::value('cc_email_address', $config);
         if ($cc) {
             $sendTemplateParams['cc'] = $cc;
         }
         $bcc = CRM_Utils_Array::value('bcc_email_address', $config);
         if ($bcc) {
             $sendTemplateParams['bcc'] = $bcc;
         }
         list($sent, $subject, $message, $html) = CRM_Core_BAO_MessageTemplate::sendTemplate($sendTemplateParams);
         if ($sent && CRM_Utils_Array::value('log_confirmation_email', $config)) {
             //check log_email_confirmaiton
             $session =& CRM_Core_Session::singleton();
             $userId = $session->get('userID');
             // which is contact id of the user
             //create activity for sending email
             $params = array('option_group_name' => 'activity_type', 'name' => CRM_Booking_Utils_Constants::ACTIVITY_TYPE_SEND_EMAIL);
             $optionValue = civicrm_api3('OptionValue', 'get', $params);
             $activityTypeId = $optionValue['values'][$optionValue['id']]['value'];
             $params = array('source_contact_id' => $userId, 'activity_type_id' => $activityTypeId, 'subject' => ts('Send Booking Confirmation Email'), 'activity_date_time' => date('YmdHis'), 'target_contact_id' => $contactID, 'details' => $message, 'status_id' => 2, 'priority_id' => 2);
             $result = civicrm_api3('Activity', 'create', $params);
         }
         if ($returnMessageText) {
             return array('subject' => $subject, 'body' => $message, 'to' => $displayName, 'html' => $html);
         }
     }
 }