Пример #1
0
 static function getSlots()
 {
     $config = CRM_Booking_BAO_BookingConfig::getConfig();
     $bookedColour = CRM_Utils_Array::value('slot_booked_colour', $config);
     $provisionalColour = CRM_Utils_Array::value('slot_provisional_colour', $config);
     $booking = NULL;
     if (!empty($_GET['booking_id'])) {
         $bookingId = CRM_Utils_Type::escape($_GET['booking_id'], 'String');
     }
     $timeshift = CRM_Utils_Type::escape($_GET['timeshift'], 'String');
     $from = CRM_Utils_Type::escape($_GET['from'], 'String');
     $to = CRM_Utils_Type::escape($_GET['to'], 'String');
     $slots = array("data" => array());
     $results = CRM_Booking_BAO_Slot::getSlotBetweenDate($from, $to);
     foreach ($results as $key => $slot) {
         if ($bookingId != CRM_Utils_Array::value('booking_id', $slot)) {
             //do not thing
             $params = array('id' => CRM_Utils_Array::value('booking_id', $slot));
             CRM_Booking_BAO_Booking::retrieve($params, $booking);
             $bookingStatus = CRM_Utils_Array::value('status_id', $booking);
             $displayName = CRM_Contact_BAO_Contact::displayName(CRM_Utils_Array::value('primary_contact_id', $booking));
             $data = array("id" => $key, "start_date" => CRM_Utils_Array::value('start', $slot), "end_date" => CRM_Utils_Array::value('end', $slot), "text" => CRM_Utils_Array::value('booking_id', $slot) . ' : ' . $displayName, "resource_id" => CRM_Utils_Array::value('resource_id', $slot), "configuration_id" => CRM_Utils_Array::value('config_id', $slot), "price" => CRM_Booking_BAO_Slot::calulatePrice($slot['config_id'], $slot['quantity']), "quantity" => CRM_Utils_Array::value('quantity', $slot), "note" => CRM_Utils_Array::value('note', $slot), "readonly" => true, "booking_id" => CRM_Utils_Array::value('booking_id', $slot));
             if ($bookingStatus == 1) {
                 //Provisional, TODO: Fixed to get the value from the name i.e provisional
                 $data['color'] = $provisionalColour;
             } else {
                 $data['color'] = $bookedColour;
             }
             array_push($slots['data'], $data);
         }
     }
     echo json_encode($slots);
     CRM_Utils_System::civiExit();
 }
Пример #2
0
 function preProcess()
 {
     $this->_id = $this->get('id');
     $config = CRM_Core_Config::singleton();
     $currencySymbols = "";
     if (!empty($config->currencySymbols)) {
         $currencySymbols = $config->currencySymbols;
     } else {
         $currencySymbols = $config->defaultCurrencySymbol;
     }
     $this->assign('currencySymbols', $currencySymbols);
     //Control the flexibility of time configuration for unlimited resource
     $bookingConfig = CRM_Booking_BAO_BookingConfig::getConfig();
     $this->assign('timeconfig', CRM_Utils_Array::value('unlimited_resource_time_config', $bookingConfig));
     $selectResourcePage = $this->controller->exportValues('SelectResource');
     $selectedResources = json_decode($selectResourcePage['resources'], true);
     $this->assign('resources', $selectedResources);
     foreach ($selectedResources as $key => $resource) {
         $this->_subTotal += $resource['price'];
         $this->_resourcesPrice[$key] = $resource['price'];
         $this->_discountAmount = 0;
     }
     $this->_total = $this->_subTotal;
     require_once 'CRM/Booking/Utils/DateTime.php';
     $this->assign('timeOptions', CRM_Booking_Utils_DateTime::getTimeRange());
     // get all custom groups sorted by weight
     $items = array();
     $bao = new CRM_Booking_BAO_AdhocChargesItem();
     $bao->orderBy('weight');
     $bao->is_active = 1;
     $bao->is_deleted = 0;
     $bao->find();
     while ($bao->fetch()) {
         $items[$bao->id] = array();
         CRM_Core_DAO::storeValues($bao, $items[$bao->id]);
         $items[$bao->id]['name'] = preg_replace('/[^\\p{L}\\p{N}\\s]/u', '_', $items[$bao->id]['name']);
     }
     //$days = CRM_Booking_Utils_DateTime::getDays();
     //$months = CRM_Utils_Date::getFullMonthNames();
     //$years = CRM_Booking_Utils_DateTime::getYears();
     $this->assign('items', $items);
     if ($this->_id && $this->_action == CRM_Core_Action::UPDATE) {
         $title = CRM_Core_DAO::getFieldValue('CRM_Booking_BAO_Booking', $this->_id, 'title', 'id');
         CRM_Utils_System::setTitle(ts('Edit Booking') . " - {$title}");
     } else {
         CRM_Utils_System::setTitle(ts('New Booking'));
     }
     /**
      * [dateformatDatetime] => %B %E%f, %Y %l:%M %P
      * [dateformatFull] => %B %E%f, %Y
      * [dateformatPartial] => %B %Y
      * [dateformatYear] => %Y
      * [dateformatTime] => %l:%M %P
      */
     $this->crmDateFormat = $config->dateformatDatetime;
     //retrieve crmDateFormat
     $this->assign('dateFormat', $this->crmDateFormat);
     self::registerScripts();
 }
Пример #3
0
 static function getCalendarTime()
 {
     $config = CRM_Booking_BAO_BookingConfig::getConfig();
     $start = strtotime(CRM_Utils_Array::value('day_start_at', $config));
     $end = strtotime(CRM_Utils_Array::value('day_end_at', $config));
     $periodTime = 30;
     //fixed the period time
     $startHour = 8;
     $startMinutes = 30;
     $endHour = 22;
     $endMinutes = 30;
     $xStart = $startHour * (60 / $startMinutes) + $startMinutes / $periodTime;
     $xSize = $endHour * (60 / $periodTime) + $endMinutes / $periodTime - ($startHour * (60 / $periodTime) + $startMinutes / $periodTime - 1);
     return array($xStart, $xSize, $periodTime);
 }
Пример #4
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);
         }
     }
 }
Пример #5
0
 /**
  * Function to process the form
  *
  * @access public
  *
  * @return None
  */
 public function postProcess()
 {
     CRM_Utils_System::flushCache();
     // get values from form
     $params = $this->exportValues();
     $params['id'] = $this->_config['id'];
     //$params['day_start_at'] = date('His', strtotime($params['day_start_at']));
     //$params['day_end_at'] = date('His', strtotime($params['day_end_at']));
     if (!isset($params['log_confirmation_email'])) {
         $params['log_confirmation_email'] = 0;
     }
     if (!isset($params['unlimited_resource_time_config'])) {
         $params['unlimited_resource_time_config'] = 0;
     }
     // submit to BAO for updating
     $set = CRM_Booking_BAO_BookingConfig::create($params);
     $url = CRM_Utils_System::url('civicrm/admin/setting/preferences/booking', 'reset=1');
     // show message
     CRM_Core_Session::setStatus(ts('The Booking configuration has been saved.'), ts('Saved'), 'success');
     $session = CRM_Core_Session::singleton();
     $session->replaceUserContext($url);
 }
Пример #6
0
 /**
  * This function sets the default values for the form.
  * the default values are retrieved from the database
  *
  * @access public
  *
  * @return None
  */
 function setDefaultValues()
 {
     $defaults = array();
     if ($this->_id) {
         $params = array('id' => $this->_id);
         CRM_Booking_BAO_Booking::retrieve($params, $booking);
         $result = civicrm_api3('Slot', 'get', array('booking_id' => $this->_id, 'is_deleted' => 0));
         $config = CRM_Booking_BAO_BookingConfig::getConfig();
         $slots = array();
         foreach ($result['values'] as $key => $value) {
             $displayName = CRM_Contact_BAO_Contact::displayName(CRM_Utils_Array::value('primary_contact_id', $booking));
             $configOptItem = $this->getConfigOptionById(CRM_Utils_Array::value('config_id', $value));
             //manipulate quantity to display in basket with "quantity" x "configuration (with price)", ie, "3 x People (30) = 90"
             $displayQuantity = CRM_Utils_Array::value('quantity', $value) . ' x ' . CRM_Utils_Array::value('unit_id', $configOptItem) . ' (' . CRM_Utils_Array::value('price', $configOptItem) . ')';
             $slots[$key] = array('id' => CRM_Utils_Array::value('id', $value), 'resource_id' => CRM_Utils_Array::value('resource_id', $value), 'start_date' => CRM_Utils_Array::value('start', $value), 'end_date' => CRM_Utils_Array::value('end', $value), 'label' => CRM_Core_DAO::getFieldValue('CRM_Booking_BAO_Resource', CRM_Utils_Array::value('resource_id', $value), 'label', 'id'), 'text' => CRM_Utils_Array::value('booking_id', $value) . ' : ' . $displayName, 'configuration_id' => CRM_Utils_Array::value('config_id', $value), 'quantity' => CRM_Utils_Array::value('quantity', $value), 'quantity_display' => $displayQuantity, 'price' => CRM_Utils_Array::value('quantity', $value) * floatval(CRM_Core_DAO::getFieldValue('CRM_Booking_BAO_ResourceConfigOption', CRM_Utils_Array::value('config_id', $value), 'price', 'id')), 'note' => CRM_Utils_Array::value('note', $value), 'color' => CRM_Utils_Array::value('slot_being_edited_colour', $config), 'is_updated' => TRUE, 'booking_id' => CRM_Utils_Array::value('booking_id', $value));
         }
         $firstSlot = reset($slots);
         if ($firstSlot) {
             $slotStartDate = $firstSlot['start_date'];
             $this->assign('bookingSlotDate', $slotStartDate);
         }
         $this->assign('bookingId', $this->_id);
         $defaults['resources'] = json_encode($slots);
     }
     return $defaults;
 }