Exemplo n.º 1
0
 /**
  * Function to set variables up before form is built
  *
  * @return void
  * @access public
  */
 public function preProcess()
 {
     $this->_id = $this->get('id');
     $this->_cid = $this->get('cid');
     $params = array('id' => $this->_id);
     CRM_Booking_BAO_Booking::retrieve($params, $this->_values);
     if (empty($this->_values)) {
         CRM_Core_Error::statusBounce(ts('The requested booking record does not exist (possibly the record was deleted).'));
     }
     $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->_action != CRM_Core_Action::DELETE & $this->_action != CRM_Core_Action::VIEW)) {
         $bookingPayment = civicrm_api3('BookingPayment', 'get', array('booking_id' => $this->_id));
         if ($bookingPayment['count'] > 0) {
             CRM_Core_Error::statusBounce(ts('The requested booking record has already been cancelled'));
         }
     }
     $this->_values['payment_status'] = CRM_Booking_BAO_Booking::getPaymentStatus($this->_id);
     $paymentStatus = $this->_values['payment_status'];
     $this->assign('booking', $this->_values);
     //ResoveDefault
     CRM_Booking_BAO_Booking::resolveDefaults($this->_values);
     $title = $this->_values['title'];
     CRM_Utils_System::setTitle(ts('Update Booking') . " - {$title}");
     //get contribution record
     $this->associatedContribution($this->_id);
 }
Exemplo n.º 2
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();
 }
Exemplo n.º 3
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;
 }