示例#1
0
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     parent::preProcess();
     $details = CRM_Booking_BAO_Booking::getBookingDetails($this->_id);
     $this->_values['slots'] = CRM_Utils_Array::value('slots', $details);
     $this->_values['sub_slots'] = CRM_Utils_Array::value('sub_slots', $details);
     $this->_values['adhoc_charges'] = CRM_Utils_Array::value('adhoc_charges', $details);
     $this->_values['cancellation_charges'] = CRM_Utils_Array::value('cancellation_charges', $details);
     $this->_values['contribution'] = CRM_Utils_Array::value('contribution', $details);
     $this->_values['sub_total'] = CRM_Utils_Array::value('total_amount', $this->_values) + CRM_Utils_Array::value('discount_amount', $this->_values);
     //total_amount has been deducted from discount
     $this->assign($this->_values);
     $displayName = CRM_Contact_BAO_Contact::displayName($this->_values['primary_contact_id']);
     $secondaryContactDisplayName = CRM_Contact_BAO_Contact::displayName(CRM_Utils_Array::value('secondary_contact_id', $this->_values));
     $this->assign('displayName', $displayName);
     $this->assign('secondaryContactDisplayName', $secondaryContactDisplayName);
     $this->assign('contact_id', $this->_cid);
     $params = array('option_group_name' => CRM_Booking_Utils_Constants::OPTION_BOOKING_STATUS, 'name' => CRM_Booking_Utils_Constants::OPTION_VALUE_CANCELLED);
     $result = civicrm_api3('OptionValue', 'get', $params);
     $this->_cancelStatusId = $cancelStatus = CRM_Utils_Array::value('value', CRM_Utils_Array::value($result['id'], $result['values']));
     if ($this->_values['status_id'] == $cancelStatus) {
         $this->assign('is_cancelled', TRUE);
     }
     // 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 Booking for') . ' ' . $displayName);
     self::registerScripts($this);
 }
示例#2
0
/**
 * Implementation of hook_civicrm_tabs()
 *
 * Display a booking tab listing booking belong to that contact.
 */
function booking_civicrm_tabs(&$tabs, $cid)
{
    $count = CRM_Booking_BAO_Booking::getBookingContactCount($cid);
    //TODO Count number of booking and show on the tab
    $tab = array('id' => 'booking', 'count' => $count, 'title' => 'Bookings', 'weight' => 0);
    $tab['url'] = CRM_Utils_System::url('civicrm/contact/view/booking', "reset=1&cid={$cid}&snippet=1&force=1", false, null, false);
    $tabs[] = $tab;
}
示例#3
0
/**
 * Booking.Delete API
 *
 * @param array $params
 * @return array API result descriptor
 * @see civicrm_api3_create_success
 * @see civicrm_api3_create_error
 * @throws API_Exception
 */
function civicrm_api3_Booking_delete($params)
{
    if (CRM_Booking_BAO_Booking::del($params['id'])) {
        return civicrm_api3_create_success($params, $params, 'booking', 'delete');
    } else {
        return civicrm_api3_create_error('Could not delete booking.');
    }
}
示例#4
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();
 }
示例#5
0
 /**
  * This function is called when action is browse
  *
  * return null
  * @access public
  */
 function browse()
 {
     $controller = new CRM_Core_Controller_Simple('CRM_Booking_Form_Search', ts('Booking'), $this->_action);
     $controller->setEmbedded(TRUE);
     $controller->reset();
     $controller->set('cid', $this->_contactId);
     $controller->set('context', 'booking');
     $controller->process();
     $controller->run();
     if ($this->_contactId) {
         $displayName = CRM_Contact_BAO_Contact::displayName($this->_contactId);
         $this->assign('displayName', $displayName);
     }
     $bookings = CRM_Booking_BAO_Booking::getContactAssociatedBooking($this->_contactId);
     $this->assign('associatedBooking', $bookings);
 }
示例#6
0
 /**
  * Function to build the form
  *
  * @return None
  * @access public
  */
 public function buildQuickForm()
 {
     parent::buildQuickForm();
     if ($this->_action & CRM_Core_Action::UPDATE) {
         $bookingStatus = CRM_Booking_BAO_Booking::buildOptions('status_id', 'create');
         if ($this->_values['status_id'] == $this->_cancelStatusId) {
             $this->assign('cancel_status_id', $this->_cancelStatusId);
             $this->add('hidden', 'booking_status', $this->_values['status_id']);
         } else {
             unset($bookingStatus[$this->_cancelStatusId]);
             //remove cancelled option
             $this->add('select', 'booking_status', ts('Booking status'), array('' => ts('- select -')) + $bookingStatus, TRUE, array());
         }
     }
     $this->addFormRule(array('CRM_Booking_Form_Booking_Update', 'formRule'), $this);
 }
示例#7
0
 /**
  * takes an associative array and creates a cancellation object
  *
  * the function extract all the params it needs to initialize the create a
  * resource object. the params array could contain additional unused name/value
  * pairs
  *
  * @param array $params (reference ) an assoc array of name/value pairs
  * @param array $ids    the array that holds all the db ids
  *
  * @return object CRM_Booking_BAO_Cancellation object
  * @access public
  * @static
  */
 static function create(&$values)
 {
     $bookingID = CRM_Utils_Array::value('booking_id', $values);
     if (!$bookingID) {
         return;
     } else {
         $transaction = new CRM_Core_Transaction();
         try {
             $params = array('option_group_name' => CRM_Booking_Utils_Constants::OPTION_BOOKING_STATUS, 'name' => CRM_Booking_Utils_Constants::OPTION_VALUE_CANCELLED);
             $result = civicrm_api3('OptionValue', 'get', $params);
             $params = array();
             $params['id'] = $bookingID;
             $params['status_id'] = CRM_Utils_Array::value('value', CRM_Utils_Array::value($result['id'], $result['values']));
             $booking = CRM_Booking_BAO_Booking::create($params);
             $params = array();
             $params['booking_id'] = $bookingID;
             $percentage = CRM_Utils_Array::value('cancellation_percentage', $values);
             $bookingTotal = CRM_Utils_Array::value('booking_total', $values);
             $cancellationFee = $bookingTotal * $percentage / 100;
             $additionalCharge = CRM_Utils_Array::value('additional_charge', $values);
             if (is_numeric($additionalCharge)) {
                 $cancellationFee += $additionalCharge;
                 $params['additional_fee'] = $additionalCharge;
             }
             $params['cancellation_date'] = CRM_Utils_Date::processDate(CRM_Utils_Array::value('cancellation_date', $values));
             $params['comment'] = CRM_Utils_Array::value('comment', $values);
             $params['cancellation_fee'] = $cancellationFee;
             self::add($params);
             $slots = CRM_Booking_BAO_Slot::getBookingSlot($bookingID);
             foreach ($slots as $slotId => $slots) {
                 $subSlots = CRM_Booking_BAO_SubSlot::getSubSlotSlot($slotId);
                 foreach ($subSlots as $subSlotId => $subSlot) {
                     CRM_Booking_BAO_SubSlot::cancel($subSlotId);
                 }
                 CRM_Booking_BAO_Slot::cancel($slotId);
             }
             // return TRUE;
         } catch (Exception $e) {
             $transaction->rollback();
             CRM_Core_Error::fatal($e->getMessage());
         }
     }
 }
示例#8
0
 function buildQuickForm()
 {
     parent::buildQuickForm();
     $this->addEntityRef("primary_contact_id", ts('Primary contact'), array('create' => TRUE), TRUE);
     $this->addEntityRef("secondary_contact_id", ts('Secondary contact'), array('create' => TRUE));
     $this->add('text', 'po_no', ts('Purchase order number'));
     $bookingStatus = CRM_Booking_BAO_Booking::buildOptions('status_id', 'create');
     $result = civicrm_api3('OptionValue', 'get', array('option_group_name' => CRM_Booking_Utils_Constants::OPTION_BOOKING_STATUS, 'name' => CRM_Booking_Utils_Constants::OPTION_VALUE_CANCELLED));
     $this->_cancelStatusId = CRM_Utils_Array::value('value', CRM_Utils_Array::value($result['id'], $result['values']));
     unset($bookingStatus[$this->_cancelStatusId]);
     $this->add('select', 'booking_status', ts('Booking status'), array('' => ts('- select -')) + $bookingStatus, TRUE, array());
     $this->add('text', 'title', ts('Title'), array('size' => 80, 'maxlength' => 255), TRUE);
     $this->addDate('event_start_date', ts('Date booking made'), TRUE, array('formatType' => 'activityDateTime'));
     $this->add('textarea', 'description', ts('Description'));
     $this->add('textarea', 'note', ts('Note'));
     $this->add('text', 'enp', ts('Estimate number of participants'));
     $this->add('text', 'fnp', ts('Final number of participants'));
     $this->addElement('hidden', "resources");
     $buttons = array(array('type' => 'back', 'name' => ts('<< Back')), array('type' => 'submit', 'name' => ts('Complete and Save')));
     $this->addButtons($buttons);
     $this->addFormRule(array('CRM_Booking_Form_Booking_Info', 'formRule'), $this);
 }
示例#9
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);
         }
     }
 }
示例#10
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();
 }
示例#11
0
 function postProcess()
 {
     //CRM_Utils_System::flushCache();
     if ($this->_action & CRM_Core_Action::ADD || $this->_action & CRM_Core_Action::UPDATE || $this->_action & CRM_Core_Action::CLOSE) {
         $bookingInfo = $this->exportValues();
         if (CRM_Utils_Array::value('record_contribution', $bookingInfo)) {
             //TODO:: Check if contribution exist
             $values = array();
             if ($this->_action & CRM_Core_Action::ADD) {
                 if (CRM_Utils_Array::value('select_payment_contact', $bookingInfo) == 1) {
                     $values['payment_contact'] = CRM_Utils_Array::value('primary_contact_id', $bookingInfo);
                 } else {
                     if (CRM_Utils_Array::value('select_payment_contact', $bookingInfo) == 2) {
                         $values['payment_contact'] = CRM_Utils_Array::value('secondary_contact_id', $bookingInfo);
                     } else {
                         $values['payment_contact'] = CRM_Utils_Array::value('primary_contact_id', $bookingInfo);
                     }
                 }
             } else {
                 $values['payment_contact'] = CRM_Utils_Array::value('select_payment_contact', $bookingInfo);
             }
             $values['total_amount'] = CRM_Utils_Array::value('total_amount', $bookingInfo);
             $values['booking_id'] = $this->_id;
             $values['receive_date'] = CRM_Utils_Date::processDate(CRM_Utils_Array::value('receive_date', $bookingInfo));
             $values['financial_type_id'] = CRM_Utils_Array::value('financial_type_id', $bookingInfo);
             $values['payment_instrument_id'] = CRM_Utils_Array::value('payment_instrument_id', $bookingInfo);
             $values['trxn_id'] = CRM_Utils_Array::value('trxn_id', $bookingInfo);
             //Payment status is a contribution status
             $values['contribution_status_id'] = CRM_Utils_Array::value('contribution_status_id', $bookingInfo);
             $values['booking_title'] = CRM_Utils_Array::value('title', $this->_values);
             CRM_Booking_BAO_Booking::recordContribution($values);
         }
         $sendConfirmation = CRM_Utils_Array::value('send_confirmation', $bookingInfo);
         if ($sendConfirmation) {
             //check sending email parameter
             $values = array();
             $fromEmailAddress = CRM_Core_OptionGroup::values('from_email_address');
             $values['from_email_address'] = CRM_Utils_Array::value(CRM_Utils_Array::value('from_email_address', $bookingInfo), $fromEmailAddress);
             $values['booking_id'] = $this->_id;
             $values['primary_contact_id'] = CRM_Utils_Array::value('primary_contact_id', $this->_values);
             $values['secondary_contact_id'] = CRM_Utils_Array::value('secondary_contact_id', $this->_values);
             $values['booking_title'] = $this->_values['title'];
             $values['booking_status'] = CRM_Utils_Array::value('status', $this->_values);
             $values['booking_date'] = $this->_values['booking_date'];
             $values['booking_start_date'] = $this->_values['start_date'];
             $values['booking_end_date'] = $this->_values['end_date'];
             $values['participants_estimate'] = CRM_Utils_Array::value('participants_estimate', $this->_values);
             $values['participants_actual'] = CRM_Utils_Array::value('participants_actual', $this->_values);
             $values['receipt_header_message'] = CRM_Utils_Array::value('receipt_header_message', $bookingInfo);
             $values['receipt_footer_message'] = CRM_Utils_Array::value('receipt_footer_message', $bookingInfo);
             $values['include_payment_info'] = CRM_Utils_Array::value('include_payment_information', $bookingInfo);
             $emailTo = CRM_Utils_Array::value('email_to', $bookingInfo);
             //retrieve value from 'Email to' selectbox
             $contactIds = array();
             if ($this->_action & CRM_Core_Action::ADD) {
                 if ($emailTo == 1) {
                     array_push($contactIds, CRM_Utils_Array::value('primary_contact_id', $bookingInfo));
                 } elseif ($emailTo == 2) {
                     array_push($contactIds, CRM_Utils_Array::value('secondary_contact_id', $bookingInfo));
                 } else {
                     array_push($contactIds, CRM_Utils_Array::value('primary_contact_id', $bookingInfo));
                     array_push($contactIds, CRM_Utils_Array::value('secondary_contact_id', $bookingInfo));
                 }
             } else {
                 if ($emailTo == CRM_Booking_Utils_Constants::OPTION_BOTH_CONTACTS) {
                     array_push($contactIds, CRM_Utils_Array::value('primary_contact_id', $this->_values));
                     array_push($contactIds, CRM_Utils_Array::value('secondary_contact_id', $this->_values));
                 } else {
                     array_push($contactIds, $emailTo);
                 }
             }
             foreach ($contactIds as $key => $cid) {
                 $return = CRM_Booking_BAO_Booking::sendMail($cid, $values);
                 //send email
             }
         }
         $params = array('id' => $this->_id, 'target_contact_id' => CRM_Utils_Array::value('primary_contact_id', $bookingInfo), 'subject' => ts("Booking ID: {$this->_id}"));
         //Finally add booking activity
         CRM_Booking_BAO_Booking::createActivity($params);
     }
 }
示例#12
0
 static function buildSearchForm(&$form)
 {
     $form->add('text', 'booking_po_no', ts('Purchase Order Number'));
     $resourceTypes = CRM_Booking_BAO_Resource::getResourceTypes();
     $resources = array();
     foreach ($resourceTypes as $value) {
         $resources[$value['id']] = $value['label'];
     }
     $form->add('select', 'booking_resource_id', ts('Resource Type'), array('' => ts('- select -')) + $resources, FALSE, array());
     $form->add('text', 'booking_id', ts('Booking ID'));
     $form->add('text', 'booking_title', ts('Booking Title'));
     CRM_Core_Form_Date::buildDateRange($form, 'booking_event_date', 1, '_low', '_high', ts('From'), FALSE);
     CRM_Core_Form_Date::buildDateRange($form, 'booking_start_date', 1, '_low', '_high', ts('From'), FALSE);
     CRM_Core_Form_Date::buildDateRange($form, 'booking_end_date', 1, '_low', '_high', ts('From'), FALSE);
     $bookingStatus = CRM_Booking_BAO_Booking::buildOptions('status_id', 'create');
     foreach ($bookingStatus as $id => $name) {
         $form->_bookingStatus =& $form->addElement('checkbox', "booking_status_id[{$id}]", NULL, $name);
     }
     $paymentStatus = CRM_Contribute_PseudoConstant::contributionStatus();
     foreach ($paymentStatus as $id => $name) {
         $form->_paymentStatus = $form->addElement('checkbox', "booking_payment_status_id[{$id}]", NULL, $name);
     }
 }
示例#13
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;
 }