Esempio n. 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);
 }
Esempio n. 2
0
 function postProcess()
 {
     CRM_Utils_System::flushCache();
     if ($this->_action & CRM_Core_Action::DELETE) {
         civicrm_api3('Booking', 'delete', array('id' => $this->_id));
         CRM_Core_Session::setStatus(ts('Selected booking has been deleted.'), ts('Record Deleted'), 'success');
     } else {
         $values = $this->exportValues();
         $params['id'] = $this->_id;
         $params['status_id'] = $values['booking_status'];
         $booking = civicrm_api3('Booking', 'create', $params);
         parent::postProcess();
         CRM_Core_Session::setStatus(ts('The booking \'%1\' has been saved.', array(1 => $this->_values['title'])), ts('Saved'), 'success');
     }
 }
Esempio n. 3
0
 function postProcess()
 {
     $bookingInfo = $this->exportValues();
     $selectResource = $this->controller->exportValues('SelectResource');
     $addSubResource = $this->controller->exportValues('AddSubResource');
     $resourcesValue = json_decode($selectResource['resources'], true);
     $subResourcesValue = json_decode($addSubResource['sub_resources'], true);
     $subResources = $subResourcesValue['sub_resources'];
     //Build resources array for passing to Booking APIs
     $resources = array();
     foreach ($resourcesValue as $key => $resource) {
         //Remove element that used in DTHMLX as we do not need them.
         unset($resource['id']);
         unset($resource['label']);
         unset($resource['text']);
         unset($resource['readonly']);
         $resource['start_date'] = $resource['start_date'];
         $resource['end_date'] = $resource['end_date'];
         $resource['sub_resources'] = array();
         if (isset($subResources)) {
             foreach ($subResources as $subKey => $subResource) {
                 if ($key == $subResource['parent_ref_id']) {
                     $subResourceTmp['resource_id'] = $subResource['resource']['id'];
                     $subResourceTmp['configuration_id'] = $subResource['configuration']['id'];
                     $subResourceTmp['quantity'] = $subResource['quantity'];
                     $subResourceTmp['time_required'] = $subResource['time_required'];
                     $subResourceTmp['note'] = $subResource['note'];
                     $subResourceTmp['price_estimate'] = $subResource['price_estimate'];
                     array_push($resource['sub_resources'], $subResourceTmp);
                     unset($subResources[$subKey]);
                 }
             }
         }
         array_push($resources, $resource);
     }
     $adhocCharges = CRM_Utils_Array::value('adhoc_charges', $subResourcesValue);
     $booking = array();
     if ($this->_id && $this->_action == CRM_Core_Action::UPDATE) {
         $booking['id'] = $this->_id;
     }
     $booking['primary_contact_id'] = CRM_Utils_Array::value('primary_contact_id', $bookingInfo);
     $booking['secondary_contact_id'] = CRM_Utils_Array::value('secondary_contact_id', $bookingInfo);
     $booking['po_number'] = CRM_Utils_Array::value('po_no', $bookingInfo);
     $booking['status_id'] = CRM_Utils_Array::value('booking_status', $bookingInfo);
     $booking['title'] = CRM_Utils_Array::value('title', $bookingInfo);
     $booking['description'] = CRM_Utils_Array::value('description', $bookingInfo);
     $booking['note'] = CRM_Utils_Array::value('note', $bookingInfo);
     $booking['booking_date'] = CRM_Utils_Date::processDate(CRM_Utils_Array::value('event_start_date', $bookingInfo), CRM_Utils_Array::value('event_start_date_time', $bookingInfo));
     $booking['discount_amount'] = CRM_Utils_Array::value('discount_amount', $addSubResource);
     $booking['total_amount'] = CRM_Utils_Array::value('total_price', $addSubResource);
     $amountToFloat = floatval($booking['total_amount']);
     $booking['total_amount'] = round($amountToFloat, 2, PHP_ROUND_HALF_UP);
     //add adhoc charge
     $booking['adhoc_charges_note'] = CRM_Utils_Array::value('note', $adhocCharges);
     $booking['participants_estimate'] = CRM_Utils_Array::value('enp', $bookingInfo);
     $booking['participants_actual'] = CRM_Utils_Array::value('fnp', $bookingInfo);
     $now = date('YmdHis');
     $session =& CRM_Core_Session::singleton();
     $booking['created_by'] = $session->get('userID');
     $booking['created_date'] = $now;
     $booking['updated_by'] = $session->get('userID');
     $booking['updated_date'] = $now;
     //retrieve booking_start_date, booking_end_date from all slots
     $dates = array();
     foreach ($resources as $key => $slot) {
         array_push($dates, CRM_Utils_Array::value('start_date', $slot));
         array_push($dates, CRM_Utils_Array::value('end_date', $slot));
     }
     sort($dates);
     $bookingStartDate = $dates[0];
     $bookingEndDate = $dates[count($dates) - 1];
     $booking['booking_start_date'] = CRM_Utils_Date::processDate($bookingStartDate);
     $booking['booking_end_date'] = CRM_Utils_Date::processDate($bookingEndDate);
     //make sure we create everything in one transaction, not too nice but it does the job
     $transaction = new CRM_Core_Transaction();
     try {
         $result = civicrm_api3('Booking', 'Create', $booking);
         $bookingID = CRM_Utils_Array::value('id', $result);
         $booking = CRM_Utils_Array::value($bookingID, CRM_Utils_Array::value('values', $result));
         $this->_id = $bookingID;
         //make sure we have the id on create mode
         $this->_values = $booking;
         //Now we process slots/subslots and adhoc charges
         if ($this->_action == CRM_Core_Action::UPDATE) {
             //booking id was passed from the form so we are on edit mode
             $currentSlots = CRM_Booking_BAO_Slot::getBookingSlot($bookingID);
         }
         $newSlotIds = array();
         $newSubSlotIds = array();
         foreach ($resources as $key => $resource) {
             $slot = array('booking_id' => $bookingID, 'config_id' => CRM_Utils_Array::value('configuration_id', $resource), 'start' => CRM_Utils_Date::processDate(CRM_Utils_Array::value('start_date', $resource)), 'end' => CRM_Utils_Date::processDate(CRM_Utils_Array::value('end_date', $resource)), 'resource_id' => CRM_Utils_Array::value('resource_id', $resource), 'quantity' => CRM_Utils_Array::value('quantity', $resource), 'note' => CRM_Utils_Array::value('note', $resource));
             if ($this->_action == CRM_Core_Action::UPDATE) {
                 list($isExist, $currentID) = CRM_Booking_BAO_Slot::findExistingSlot($slot, $currentSlots);
                 if ($isExist) {
                     $slot['id'] = $currentID;
                 }
             }
             $slotResult = civicrm_api3('Slot', 'create', $slot);
             $slotID = CRM_Utils_Array::value('id', $slotResult);
             array_push($newSlotIds, $slotID);
             if ($this->_action == CRM_Core_Action::UPDATE) {
                 $currentSubSlots = CRM_Booking_BAO_SubSlot::getSubSlotSlot($slotID);
             }
             $subResources = $resource['sub_resources'];
             foreach ($subResources as $subKey => $subResource) {
                 $subSlot = array('resource_id' => CRM_Utils_Array::value('resource_id', $subResource), 'slot_id' => $slotID, 'config_id' => CRM_Utils_Array::value('configuration_id', $subResource), 'time_required' => CRM_Utils_Date::processDate(CRM_Utils_Array::value('time_required', $subResource)), 'quantity' => CRM_Utils_Array::value('quantity', $subResource), 'note' => CRM_Utils_Array::value('note', $subResource));
                 if ($this->_action == CRM_Core_Action::UPDATE) {
                     list($isExist, $currentSubSlotId) = CRM_Booking_BAO_SubSlot::findExistingSubSlot($subSlot, $currentSubSlots);
                     if ($isExist) {
                         $subSlot['id'] = $currentSubSlotId;
                     }
                 }
                 $subSlotResult = civicrm_api3('SubSlot', 'Create', $subSlot);
                 $subSlotID = CRM_Utils_Array::value('id', $subSlotResult);
                 array_push($newSubSlotIds, $subSlotID);
             }
             if ($this->_action == CRM_Core_Action::UPDATE) {
                 //remove subslots that have been removed
                 $subSlotsToBeRemoved = array();
                 foreach ($currentSubSlots as $key => $currentSubSlot) {
                     if (!in_array($key, $newSubSlotIds)) {
                         $subSlotsToBeRemoved[$key] = $currentSubSlot;
                     }
                 }
                 if (!empty($subSlotsToBeRemoved)) {
                     foreach ($subSlotsToBeRemoved as $key => $slot) {
                         civicrm_api3('SubSlot', 'delete', array('id' => $key));
                     }
                 }
             }
         }
         if ($this->_action == CRM_Core_Action::UPDATE) {
             //remove all slots that have been removed
             $slotsToBeRemoved = array();
             foreach ($currentSlots as $key => $currentSlot) {
                 if (!in_array($key, $newSlotIds)) {
                     $slotsToBeRemoved[$key] = $currentSlot;
                 }
             }
             if (!empty($slotsToBeRemoved)) {
                 foreach ($slotsToBeRemoved as $key => $slot) {
                     civicrm_api3('Slot', 'delete', array('id' => $key));
                 }
             }
         }
         if ($adhocCharges) {
             if ($this->_action == CRM_Core_Action::UPDATE) {
                 $result = civicrm_api3('AdhocCharges', 'get', array('booking_id' => $bookingID, 'is_deleted' => 0));
                 $currentAdhocCharges = $result['values'];
             }
             // fixed bug of CVB-94
             // Ad-hoc charges - cannot save
             if (!is_null(CRM_Utils_Array::value('items', $adhocCharges))) {
                 $items = array_filter(CRM_Utils_Array::value('items', $adhocCharges));
                 $newAdhocChargesIds = array();
                 foreach ($items as $key => $item) {
                     $params = array('booking_id' => $bookingID, 'item_id' => CRM_Utils_Array::value('item_id', $item), 'quantity' => CRM_Utils_Array::value('quantity', $item));
                     if ($this->_action == CRM_Core_Action::UPDATE) {
                         list($isExist, $currentAdhocChargesId) = CRM_Booking_BAO_AdhocCharges::findExistingAdhocCharges($params, $currentAdhocCharges);
                         if ($isExist) {
                             $params['id'] = $currentAdhocChargesId;
                         }
                     }
                     $result = civicrm_api3('AdhocCharges', 'create', $params);
                     $adhocChargesId = CRM_Utils_Array::value('id', $result);
                     array_push($newAdhocChargesIds, $adhocChargesId);
                 }
             }
             if ($this->_action == CRM_Core_Action::UPDATE) {
                 //remove  adhoc charges that have been removed
                 $adhocChargesToBeRemoved = array();
                 foreach ($currentAdhocCharges as $key => $adc) {
                     if (!in_array($key, $newAdhocChargesIds)) {
                         $adhocChargesToBeRemoved[$key] = $adc;
                     }
                 }
                 if (!empty($adhocChargesToBeRemoved)) {
                     foreach ($adhocChargesToBeRemoved as $key => $adc) {
                         civicrm_api3('AdhocCharges', 'delete', array('id' => $key));
                     }
                 }
             }
         }
         //End process
         parent::postProcess();
         $cid = CRM_Utils_Array::value('primary_contact_id', $bookingInfo);
         // user context
         $url = CRM_Utils_System::url('civicrm/contact/view/booking', "reset=1&id={$bookingID}&cid={$cid}&action=view");
         CRM_Core_Session::setStatus($booking['title'], ts('Saved'), 'success');
         CRM_Utils_System::redirect($url);
     } catch (CiviCRM_API3_Exception $e) {
         $transaction->rollback();
         CRM_Core_Error::fatal($e->getMessage());
     } catch (Exception $e) {
         $transaction->rollback();
         CRM_Core_Error::fatal($e->getMessage());
     }
 }
Esempio n. 4
0
 function postProcess()
 {
     CRM_Utils_System::flushCache();
     $values = $this->exportValues();
     $params['booking_id'] = $this->_id;
     $params['cancellation_date'] = $values['cancellation_date'];
     $params['cancellation_percentage'] = $values['cancellations'];
     $params['booking_total'] = $values['booking_total'];
     $params['cancellation_fee'] = $params['cancellation_percentage'] / 100 * $params['booking_total'];
     $params['additional_charge'] = $values['adjustment'];
     $params['comment'] = $values['comment'];
     CRM_Booking_BAO_Cancellation::create($params);
     parent::postProcess();
     CRM_Core_Session::setStatus(ts('The booking \'%1\' has been cancelled.', array(1 => $this->_values['title'])), ts('Saved'), 'success');
 }