public function itemAction() { /** * @var $auth \Library\Authentication\BackofficeAuthenticationService */ $id = (int) $this->params()->fromRoute('id', 0); $service = $this->getConcierge(); if (!$id || !($rowObj = $service->getConciergeByGroupId($id))) { Helper::setFlashMessage(['error' => TextConstants::ERROR_NO_ITEM]); return $this->redirect()->toRoute('backoffice/default', ['controller' => 'concierge', 'action' => 'view']); } $auth = $this->getServiceLocator()->get('library_backoffice_auth'); $authId = (int) $auth->getIdentity()->id; $external = (int) $auth->getIdentity()->external; $usermanagerDao = $this->getServiceLocator()->get('dao_user_user_manager'); $userInfo = $usermanagerDao->fetchOne(['id' => $authId]); $currentDate = time(); if (!is_null($userInfo->getTimezone())) { $currentDate = Helper::getCurrenctDateByTimezone($userInfo->getTimezone()); } if ($auth->hasRole(Roles::ROLE_GLOBAL_APARTMENT_GROUP_MANAGER)) { $userId = false; } elseif ($auth->hasRole(Roles::ROLE_CONCIERGE_DASHBOARD) || $auth->hasRole(Roles::ROLE_APARTMENT_GROUP_MANAGEMENT)) { $userId = $authId; } else { return ['errorPage' => 'error']; } $isBookingManager = false; if ($auth->hasRole(Roles::ROLE_BOOKING_MANAGEMENT)) { $isBookingManager = true; } $hasFronterCharg = false; if ($auth->hasRole(Roles::ROLE_FRONTIER_CHARGE)) { $hasFronterCharg = true; } $hasFrontierCard = false; if ($auth->hasRole(Roles::ROLE_FRONTIER_MANAGEMENT)) { $hasFrontierCard = true; } $hasCurrentStayView = false; if ($auth->hasRole(Roles::ROLE_CONCIERGE_CURRENT_STAYS)) { $hasCurrentStayView = true; } $checkID = $service->checkGroupForUser($id, $userId); if (!$checkID) { return ['errorPage' => 'error']; } $timezone = 'UTC'; $group_name = ''; $accommodationList = $service->getApartmentGroupItems($id); if (is_object($rowObj)) { $timezone = $rowObj->getTimezone(); $group_name = $rowObj->getName(); } $conciergeView = $service->getConciergeView($accommodationList, $timezone); // get bad email list $getBadEmail = BookingTicket::getBadEmail(); return ['currentStays' => $conciergeView['currentStays'], 'arrivalsYesterday' => $conciergeView['arrivalsYesterday'], 'arrivalsToday' => $conciergeView['arrivalsToday'], 'arrivalsTomorrow' => $conciergeView['arrivalsTomorrow'], 'checkoutsToday' => $conciergeView['checkoutsToday'], 'checkoutsTomorrow' => $conciergeView['checkoutsTomorrow'], 'checkoutsYesterday' => $conciergeView['checkoutsYesterday'], 'dateInTimezone' => $conciergeView['dateInTimezone'], 'groupId' => $id, 'groupName' => $group_name, 'isBookingManager' => $isBookingManager, 'hasFronterCharg' => $hasFronterCharg, 'hasCurrentStayView' => $hasCurrentStayView, 'currentDate' => $currentDate, 'hasFrontierCard' => $hasFrontierCard, 'getBadEmail' => json_encode($getBadEmail), 'userIsExternal' => $external]; }
/** * Test filter reservation data action */ public function testFilterReservationData() { // check services and dao`s $websiteSearchService = $this->getApplicationServiceLocator()->get('service_website_search'); $this->assertInstanceOf('\\DDD\\Service\\Website\\Search', $websiteSearchService); $cityDao = new City($this->getApplicationServiceLocator(), 'ArrayObject'); $this->assertInstanceOf('\\DDD\\Dao\\Location\\City', $cityDao); $cityName = 'Yerevan'; $apartmentTitle = 'hollywood-al-pacino'; $cityResponse = $cityDao->getCityByName($cityName); $this->assertTrue(ClassicValidator::checkCityName($cityName), "City Name Validator haven't correct regex"); $this->assertTrue(ClassicValidator::checkApartmentTitle($apartmentTitle), "Apartment Name Validator haven't correct regex"); $this->assertArrayHasKey('timezone', $cityResponse); // check current date $diffHours = 0; $boDiffHours = -24; $currentDate = Helper::getCurrenctDateByTimezone($cityResponse['timezone'], 'd-m-Y', $diffHours); $currentDateForBo = Helper::getCurrenctDateByTimezone($cityResponse['timezone'], 'd-m-Y', $boDiffHours); $dateCurrent = new \DateTime("now"); $dateBoCurrent = new \DateTime("yesterday"); $this->assertEquals($currentDate, $dateCurrent->format('d-m-Y'), 'Guest timezone logic is not correct'); $this->assertEquals($currentDateForBo, $dateBoCurrent->format('d-m-Y'), 'Bo User timezone logic is not correct'); }
/** * @param $ratesData * @param $reservationId * @param bool $isGetInfo * @param bool $isOverbooking * @param bool $apartel * @return array */ public function changeDateForModification($ratesData, $reservationId, $isGetInfo = false, $apartel = false, $isOverbooking = false) { /** * @var Booking $bookingDao * @var BookingTicket $reservationTicketService * @var ReservationNightly $reservationNightlyDao * @var WorstCXLPolicySelector $policyService * @var PenaltyCalculation $penaltyService * @var Logger $logger * @var \DDD\Service\Booking\Charge $chargeService * @var \DDD\Service\Availability $availabilityService */ if (empty($ratesData) || !$reservationId) { $this->gr2err("Bad situation while modifying date part: Bad Data for modification date", ['cron' => 'ChannelManager', 'reservation_id' => $reservationId]); return ['status' => 'error']; } $bookingDao = $this->getServiceLocator()->get('dao_booking_booking'); $reservationNightlyDao = $this->getServiceLocator()->get('dao_booking_reservation_nightly'); $policyService = $this->getServiceLocator()->get('service_reservation_worst_cxl_policy_selector'); $logger = $this->getServiceLocator()->get('ActionLogger'); $chargeService = $this->getServiceLocator()->get('service_booking_charge'); $reservationTicketService = $this->getServiceLocator()->get('service_booking_booking_ticket'); $availabilityService = $this->getServiceLocator()->get('service_availability'); $update = $insert = $delete = $rateIds = []; // Reservation Data $reservationData = $bookingDao->getReservationPolicyData($reservationId); $resNightlyData = $reservationNightlyDao->fetchAll(['reservation_id' => $reservationId, 'status' => self::STATUS_BOOKED]); $isFlexible = $reservationData['penalty_hours'] > $reservationData['refundable_before_hours'] ? true : false; $today = Helper::getCurrenctDateByTimezone($reservationData['timezone']); $reservationSetParams = []; $ratesDateKey = array_keys($ratesData); sort($ratesDateKey); $newReservationNightCount = count($ratesDateKey); $priceAllRefundable = 0; foreach ($resNightlyData as $row) { if (in_array($row['date'], $ratesDateKey) || strtotime($today) > strtotime($row['date'])) { unset($ratesData[$row['date']]); } else { if ($reservationData['is_refundable'] == Rate::APARTMENT_RATE_REFUNDABLE && $isFlexible) { // Refundable flexible period, Nothing change, apply what has $delete[$row['date']] = ['id' => $row['id'], 'price' => $row['price'], 'apartment_id' => $row['apartment_id'], 'room_id' => $row['room_id'], 'rate_id' => $row['rate_id'], 'date' => $row['date'], 'capacity' => $row['capacity'], 'rate_name' => $row['rate_name'], 'is_refundable' => Rate::APARTMENT_RATE_REFUNDABLE, 'revers' => true, 'update_price' => false]; } elseif ($reservationData['is_refundable'] == Rate::APARTMENT_RATE_REFUNDABLE) { // Refundable penalty period $priceAllRefundable += $row['price']; $update[$row['date']] = ['id' => $row['id'], 'price' => $row['price'], 'apartment_id' => $row['apartment_id'], 'room_id' => $row['room_id'], 'rate_id' => $row['rate_id'], 'date' => $row['date'], 'capacity' => $row['capacity'], 'rate_name' => $row['rate_name'], 'is_refundable' => Rate::APARTMENT_RATE_REFUNDABLE, 'revers' => false, 'update_price' => false]; } elseif ($reservationData['is_refundable'] == Rate::APARTMENT_RATE_NON_REFUNDABLE) { // Non Refundable $update[$row['date']] = ['id' => $row['id'], 'price' => $row['price'], 'apartment_id' => $row['apartment_id'], 'room_id' => $row['room_id'], 'rate_id' => $row['rate_id'], 'date' => $row['date'], 'capacity' => $row['capacity'], 'rate_name' => $row['rate_name'], 'is_refundable' => Rate::APARTMENT_RATE_NON_REFUNDABLE, 'revers' => false, 'update_price' => false]; } //open parking spot availability $chargeService->openParkingSpotAvailability($row['id']); } } // calculate refundable and penalty period price $updateDayCount = count($update); foreach ($update as $key => $row) { if ($row['is_refundable'] == Rate::APARTMENT_RATE_REFUNDABLE) { if ($reservationData['penalty'] == Rate::PENALTY_TYPE_PERCENT) { $update[$key]['revers'] = true; $update[$key]['update_price'] = true; $update[$key]['price'] = $row['price'] * $reservationData['penalty_val'] / 100; } elseif ($reservationData['penalty'] == Rate::PENALTY_TYPE_FIXED_AMOUNT || $reservationData['penalty'] == Rate::PENALTY_TYPE_NIGHTS) { if ($priceAllRefundable >= $reservationData['penalty_fixed_amount']) { $penaltyPricePerNight = $reservationData['penalty_fixed_amount'] / $updateDayCount; $update[$key]['price'] = $penaltyPricePerNight; $update[$key]['revers'] = true; $update[$key]['update_price'] = true; } else { $update[$key]['revers'] = false; $update[$key]['update_price'] = false; } } } } $insert = $ratesData; $addedNightCount = count($insert); // Save and sync Nightly Data $nightlyData = ['insert' => ['data' => $insert, 'availability' => 0], 'update' => ['data' => $update, 'availability' => 1], 'delete' => ['data' => $delete, 'availability' => 1]]; if ($isGetInfo) { return $chargeService->chargeForModifyDate($nightlyData, $reservationId, true); } // if became overbooking change overbooking status if ($isOverbooking && $reservationData['overbooking_status'] != BookingTicket::OVERBOOKING_STATUS_OVERBOOKED) { $updateAvailabilityBit = strtotime($today) < strtotime($reservationData['date_from']); $changeStatus = $reservationTicketService->changeOverbookingStatus($reservationId, BookingTicket::OVERBOOKING_STATUS_OVERBOOKED, $updateAvailabilityBit); if (!$changeStatus) { return ['status' => 'error']; } } $modifyDateLog = $availabilitySyncDays = []; $addedPrice = 0; foreach ($nightlyData as $keyType => $data) { foreach ($data['data'] as $keyNight => $night) { if ($keyType == 'insert') { // Save nightly data $nightlyInsertId = $reservationNightlyDao->save(['reservation_id' => $reservationId, 'apartment_id' => $night['apartment_id'], 'room_id' => $night['room_id'], 'rate_id' => $night['rate_id'], 'rate_name' => $night['rate_name'], 'price' => $night['price'], 'date' => $night['date'], 'capacity' => $night['capacity'], 'status' => self::STATUS_BOOKED]); $nightlyData['insert']['data'][$night['date']]['id'] = $nightlyInsertId; $addedPrice += $night['price']; $modifyDateLog[] = 'Date modified: Added date ' . $night['date']; } if ($keyType == 'update') { // Update nightly data $updateChange = ['status' => self::STATUS_CANCELED]; if ($night['is_refundable'] == Rate::APARTMENT_RATE_REFUNDABLE && $night['update_price']) { $updateChange['price'] = $night['price']; } $reservationNightlyDao->save($updateChange, ['reservation_id' => $reservationId, 'date' => $keyNight]); $modifyDateLog[] = 'Date modified: Updated with penalty and opened availability ' . $night['date']; } if ($keyType == 'delete') { // Delete nightly data $reservationNightlyDao->delete(['reservation_id' => $reservationId, 'date' => $keyNight]); $modifyDateLog[] = 'Date modified: Removed date ' . $night['date']; } $availabilitySyncDays[] = ['apartment_id' => $night['apartment_id'], 'date' => $night['date'], 'availability' => $data['availability']]; } } // update availability if not overbooking if (!$isOverbooking && $reservationData['overbooking_status'] != BookingTicket::OVERBOOKING_STATUS_OVERBOOKED && !empty($availabilitySyncDays)) { // change apartment availability and sync cubilis $availabilityService->updateAvailabilityApartmentByNight($availabilitySyncDays, $reservationId); // change apartel availability and sync cubilis if this apartment is apartel $availabilityService->updateAvailabilityApartelByNight($availabilitySyncDays, $reservationId); } // Action Log foreach ($modifyDateLog as $log) { $logger->save(Logger::MODULE_BOOKING, $reservationId, Logger::ACTION_BOOKING_MODIFY, $log); } // Get Good policy foreach ($insert as $row) { if (!in_array($row['rate_id'], $rateIds)) { $rateIds[] = $row['rate_id']; } } // Get best penalty policy $reservationPrice = $reservationNightlyDao->getReservationPrice($reservationId); $policyData = $policyService->select($rateIds, $reservationPrice, $reservationId, false, $apartel); // calculate penalty amount if ($reservationData['is_refundable'] == Rate::APARTMENT_RATE_REFUNDABLE && $isFlexible) { $penaltyAmount = $policyData['penalty_fixed_amount']; } else { $addedDataPenalty = 0; if ($addedPrice && $addedNightCount) { if ($policyData['is_refundable'] == Rate::APARTMENT_RATE_NON_REFUNDABLE) { $addedDataPenalty = $addedPrice; } else { $addedDataPenalty = $policyData['penalty_fixed_amount'] / $newReservationNightCount * $addedNightCount; } } $penaltyAmount = $reservationData['penalty_fixed_amount'] + $addedDataPenalty; } // get rate names and capacity $getRateNameCapacity = $reservationNightlyDao->getRatesNameCapacity($reservationId); // Set price, penalty policy, capacity, rate_name, change date $dateTo = date('Y-m-d', strtotime('+1 day', strtotime(end($ratesDateKey)))); $reservationSetParams = $reservationSetParams + ['price' => $reservationPrice, 'is_refundable' => $policyData['is_refundable'], 'penalty' => $policyData['penalty'], 'penalty_fixed_amount' => $penaltyAmount, 'refundable_before_hours' => $policyData['refundable_before_hours'], 'penalty_val' => $policyData['penalty_val'], 'man_count' => $getRateNameCapacity['capacity'], 'rate_name' => $getRateNameCapacity['rates_name'], 'date_from' => $ratesDateKey[0], 'date_to' => $dateTo]; $bookingDao->save($reservationSetParams, ['id' => $reservationId]); // update availability if before change date reservation is overbooking, but after change not overbooking if (!$isOverbooking && $reservationData['overbooking_status'] == BookingTicket::OVERBOOKING_STATUS_OVERBOOKED) { $changeStatus = $reservationTicketService->changeOverbookingStatus($reservationId, BookingTicket::OVERBOOKING_STATUS_RESOLVED); if (!$changeStatus) { return ['status' => 'error']; } } // set charge if not has charge if ($reservationData['check_charged']) { $chargeService->chargeForModifyDate($nightlyData, $reservationId, false, true); } /** * @var \DDD\Service\Task $taskService */ $taskService = $this->getServiceLocator()->get('service_task'); $taskService->deleteTask(['extra_inspection' => Task::TASK_EXTRA_INSPECTION, 'res_id' => $reservationId]); return ['status' => 'success']; }
/** * checks if last reservation keys are set right, if not, * creates an extra task for next reservation's checkin * @param $lastReservation * @param $nextReservation * @return bool */ public function createExtraAutoTaskForKeyChange($lastReservation, $nextReservation) { if ($nextReservation['no_refresh'] == 1) { return false; } $taskDao = $this->getTaskDao(); $lastReservationTask = $this->getReservationAutoCreatedTask($lastReservation['id'], self::TYPE_CLEANING, $lastReservation['apartment_id_assigned']); if (is_null($lastReservationTask) || !$lastReservationTask) { return false; } $taskType = self::TYPE_APT_SERVICE; $nextReservationExtraTask = $this->getReservationAutoCreatedTask($lastReservation['id'], $taskType); if (!is_null($nextReservationExtraTask) && $nextReservationExtraTask) { //extra task is already created return false; } $taskSubtaskDao = $this->getTaskSubtasksDao(); $setCodeToSubtask = $taskSubtaskDao->getSubtaskLike($lastReservationTask['id'], $nextReservation['pin'] . ' for next check-in'); $occupancySubtask = $taskSubtaskDao->getSubtaskLike($lastReservationTask['id'], 'Occupancy: ' . $nextReservation['occupancy']); if (!$setCodeToSubtask && !in_array($nextReservation['lock_type'], LockGeneral::$typeWithoutCode) || !$occupancySubtask) { //it means that originally the task was been created for another reservation and we have got a new reservation in a middle $taskName = 'Inspect the apartment for new occupants'; $bookingTicketService = $this->getServiceLocator()->get('service_booking_booking_ticket'); $bookingTicket = $bookingTicketService->getBookingThicketByReservationId($nextReservation['id']); $apartmentId = $bookingTicket->getApartmentIdAssigned(); $buildingId = $bookingTicket->getApartmentAssignedBuildingId(); $checkInDate = $bookingTicket->getDate_from(); $checkInTime = is_null($bookingTicket->getApartmentCheckInTime()) ? '13:00:00' : $bookingTicket->getApartmentCheckInTime(); $checkInDateTime = $checkInDate . ' ' . $checkInTime; $checkinDateTimeMinus1Hour = date('Y-m-d H:i:s', strtotime($checkInDateTime) - 3600); $teamId = $this->getTeamBasedOnType($taskType, $apartmentId, $buildingId); $actionsSet = [self::ACTION_CHANGE_DETAILS => 1, self::ACTION_CHANGE_STATUS => 1, self::ACTION_MANAGE_STAFF => 1, self::ACTION_MANAGE_SUBTASKS => 1]; $occupancySubtaskOfLastReservation = $taskSubtaskDao->getSubtaskLike($lastReservationTask['id'], 'Occupancy: '); if (is_null($occupancySubtaskOfLastReservation['description']) || strpos(false === $occupancySubtaskOfLastReservation['description'], 'Occupancy: ')) { return false; } $alreadySetOccupancy = substr($occupancySubtaskOfLastReservation['description'], strlen('Occupancy: ')); $subtaskDescription = []; if (in_array($nextReservation['lock_type'], LockGeneral::$typeWithoutCode) && $alreadySetOccupancy == $nextReservation['occupancy']) { return false; } $occupancySubtaskOfCreatingTask = 'Occupancy: ' . $nextReservation['occupancy']; if ($alreadySetOccupancy != $nextReservation['occupancy']) { $occupancySubtaskOfCreatingTask .= ' (old occupancy: ' . $alreadySetOccupancy . ')'; } array_push($subtaskDescription, $occupancySubtaskOfCreatingTask); if ($lastReservation['outside_door_code']) { array_push($subtaskDescription, 'Enter to building with ' . $lastReservation['outside_door_code']); } $setCodeToSubtaskSet = $taskSubtaskDao->getSubtaskLike($lastReservationTask['id'], ' for next check-in'); if ($setCodeToSubtaskSet) { $SubTaskArray = explode(' for next check-in', $setCodeToSubtaskSet['description']); $subTaskFirstPart = $SubTaskArray[0]; $subTaskFirstPartArray = explode('Set', $subTaskFirstPart); $EnterCode = $subTaskFirstPartArray[1]; } else { $EnterCode = 'Mechanical Key'; } array_push($subtaskDescription, 'Enter to apartment with ' . $EnterCode); if ($nextReservation['next_pin']) { array_push($subtaskDescription, 'Set ' . $nextReservation['next_pin'] . ' for next check-in'); } /* @var $apartmentDao \DDD\Dao\Apartment\General */ $apartmentDao = $this->getServiceLocator()->get('dao_apartment_general'); $apartmentData = $apartmentDao->getApartmentGeneralInfo($apartmentId); $apartmentToday = Helper::getCurrenctDateByTimezone($apartmentData['timezone']); $taskPriority = self::TASK_PRIORITY_NORMAL; if ($nextReservation['date_from'] <= $apartmentToday) { $taskPriority = self::TASK_PRIORITY_CRITICAL; } $startDateTime = $checkinDateTimeMinus1Hour; $endDateTime = $checkInDateTime; $deleteDate = date("Y-m-d", strtotime($endDateTime)); $taskData = ['title' => $taskName, 'task_type' => $taskType, 'team_id' => $teamId, 'following_team_id' => TeamService::TEAM_CONTACT_CENTER, 'start_date' => $startDateTime, 'end_date' => $endDateTime, 'task_status' => self::STATUS_NEW, 'creator_id' => UserMain::SYSTEM_USER_ID, 'task_priority' => $taskPriority, 'description' => 'Prepare For The Next Guest', 'res_id' => $lastReservation['id'], 'property_id' => $apartmentId, 'building_id' => $buildingId, 'verifier_id' => UserService::AUTO_VERIFY_USER_ID, 'is_hk' => self::TASK_IS_HOUSEKEEPING, 'subtask_description' => $subtaskDescription]; $id = $this->taskSave($taskData, $actionsSet, true); //delete All other extra Key Fob tasks for today on this apartment $taskDao->deleteAllSameDayAutoGeneratedTasks($id, $deleteDate, $apartmentId, $taskType); echo 'extra task created, id = ' . $id . "[0m\n\r"; } }
/** * @param array $data * @return string */ private function filterReservationData($data) { $currentDate = date('Y-m-d'); $cityDao = new City($this->getServiceLocator(), 'ArrayObject'); if (isset($data['city']) && ClassicValidator::checkCityName($data['city'])) { $cityResp = $cityDao->getCityByName(Helper::urlForSearch($data['city'])); if ($cityResp) { /* @var $websiteSearchService \DDD\Service\Website\Search */ $websiteSearchService = $this->getServiceLocator()->get('service_website_search'); $diffHours = $websiteSearchService->getDiffHoursForDate(); $currentDate = Helper::getCurrenctDateByTimezone($cityResp['timezone'], 'd-m-Y', $diffHours); } } if (!isset($data['city']) || !ClassicValidator::checkCityName($data['city']) || !isset($data['apartment']) || !ClassicValidator::checkApartmentTitle($data['apartment']) || !isset($data['guest']) || !is_numeric($data['guest']) || !isset($data['apartment_id']) || !is_numeric($data['apartment_id']) || !isset($data['arrival']) || !ClassicValidator::validateDate($data['arrival'], 'd M Y') || !isset($data['departure']) || !ClassicValidator::validateDate($data['departure'], 'd M Y') || strtotime($data['arrival']) >= strtotime($data['departure']) || strtotime($currentDate) - strtotime($data['arrival']) > 129600 || !isset($data['rate-for-booking']) || !is_numeric($data['rate-for-booking']) || isset($data['apartel_id']) && !is_numeric($data['apartel_id'])) { return false; } return true; }
/** * @param $reservationId * @param $dateFrom * @param $dateTo * @param bool $isGetInfo * @return array */ public function changeReservationDate($reservationId, $dateFrom, $dateTo, $isGetInfo = false) { /** * @var ReservationNightly $reservationNightlyDao * @var \DDD\Service\Reservation\Main $reservationService * @var \DDD\Service\Reservation\RateSelector $rateSelector * @var \DDD\Dao\Apartment\Inventory $inventoryDao * @var \DDD\Dao\Booking\Booking $bookingDao */ $inventoryDao = $this->getServiceLocator()->get('dao_apartment_inventory'); $reservationNightlyDao = $this->getServiceLocator()->get('dao_booking_reservation_nightly'); $reservationService = $this->getServiceLocator()->get('service_reservation_main'); $rateSelector = $this->getServiceLocator()->get('service_reservation_rate_selector'); $bookingDao = $this->getServiceLocator()->get('dao_booking_booking'); $reservationData = $bookingDao->getReservationDataForChangeDate($reservationId); $today = Helper::getCurrenctDateByTimezone($reservationData['timezone']); $bookingDao->setEntity(new \ArrayObject()); // Data check if (!$reservationData || !$dateFrom || !ClassicValidator::validateDate($dateFrom, 'Y-m-d') || !$dateTo || !ClassicValidator::validateDate($dateTo, 'Y-m-d') || strtotime($dateFrom) >= strtotime($dateTo)) { return ['status' => 'error', 'msg' => TextConstants::MODIFICATION_BAD_DATA_FOR_CHANGE]; } $error = ''; if ($reservationData['date_from'] != $dateFrom && strtotime($today) > strtotime($dateFrom)) { $error .= TextConstants::MODIFICATION_DATE_NOT_PAST; } if ($reservationData['status'] != BookingService::BOOKING_STATUS_BOOKED) { $error .= TextConstants::MODIFICATION_STATUS_BOOKED; } if ($reservationData['date_from'] == $dateFrom && $reservationData['date_to'] == $dateTo) { $error .= TextConstants::MODIFICATION_NO_INDICATED; } if (strtotime($today) > strtotime($dateTo)) { $error .= TextConstants::MODIFICATION_DATE_SHOULD_FUTURE; } if ($error) { return ['status' => 'error', 'msg' => $error]; } // check is apartel $apartel = $reservationData['apartel_id'] && $reservationData['channel_res_id'] > 0 ? $reservationData['apartel_id'] : false; // New Date generation $resNightlyData = $reservationNightlyDao->fetchAll(['reservation_id' => $reservationId, 'status' => ReservationMainService::STATUS_BOOKED], [], 'date ASC'); $existingNightlyData = $startRateApartment = $lastRateApartment = $existingDate = $newNightlyData = []; $existingNightCount = $resNightlyData->count(); if (!$existingNightCount) { return ['status' => 'error', 'msg' => TextConstants::MODIFICATION_BAD_DATA_FOR_CHANGE]; } foreach ($resNightlyData as $key => $night) { $existingNightlyData[$night['date']] = $night; } // existing date array $existingDate = array_keys($existingNightlyData); $startRateApartment = $existingNightlyData[current($existingDate)]; $lastRateApartment = $existingNightlyData[end($existingDate)]; $dateFromTime = strtotime($dateFrom); $dateToTime = strtotime($dateTo); while ($dateFromTime < $dateToTime) { $date = date('Y-m-d', $dateFromTime); if (in_array($date, $existingDate)) { // existing date $newFromData = $existingNightlyData[$date]; } else { if (strtotime($date) < strtotime($reservationData['date_from'])) { // get rate data from start date $newFromData = $startRateApartment; $rateIdForChangeDate = $startRateApartment['rate_id']; } else { // get rate data from last date $rateIdForChangeDate = $lastRateApartment['rate_id']; $newFromData = $lastRateApartment; } if ($apartel) { /** * @var \DDD\Dao\Apartel\Rate $apartelRateDao * @var \DDD\Dao\Apartel\Inventory $apartelInventoryDao */ $apartelRateDao = $this->getServiceLocator()->get('dao_apartel_rate'); $apartelInventoryDao = $this->getServiceLocator()->get('dao_apartel_inventory'); // rate exist and active if not use fuzzy logic if (!$apartelRateDao->checkRateExistAndActive($rateIdForChangeDate)) { $newFromData = $rateSelector->getSelectorRate($reservationId, $date, $isGetInfo, $apartel); $rateIdForChangeDate = $newFromData['rate_id']; } // check apartment availability if (!$inventoryDao->checkApartmentAvailabilityApartmentDateList($newFromData['apartment_id'], [$date])) { return ['status' => 'error', 'msg' => TextConstants::ERROR_NO_AVAILABILITY]; } // check apartel availability and get price $priceApartel = $apartelInventoryDao->getPriceByRateIdDate($rateIdForChangeDate, $date); $newPrice = $priceApartel['price']; } else { /** @var \DDD\Dao\Apartment\Rate $rateDao */ $rateDao = $this->getServiceLocator()->get('dao_apartment_rate'); // rate exist and active if not use fuzzy logic if (!$rateDao->checkRateExistAndActive($rateIdForChangeDate)) { $newFromData = $rateSelector->getSelectorRate($reservationId, $date, $isGetInfo); $rateIdForChangeDate = $newFromData['rate_id']; } $changeDatePrice = $inventoryDao->fetchOne(['rate_id' => $rateIdForChangeDate, 'date' => $date, 'availability' => 1], ['price']); if (!$changeDatePrice) { return ['status' => 'error', 'msg' => TextConstants::ERROR_NO_AVAILABILITY]; } $newPrice = $changeDatePrice->getPrice(); } $newFromData['price'] = $newPrice; } $newNightlyData[$date] = ['apartment_id' => $newFromData['apartment_id'], 'room_id' => $newFromData['room_id'], 'rate_id' => $newFromData['rate_id'], 'rate_name' => $newFromData['rate_name'], 'price' => $newFromData['price'], 'date' => $date, 'capacity' => $newFromData['capacity']]; $dateFromTime = strtotime('+1 day', $dateFromTime); } if (empty($newNightlyData)) { return ['status' => 'error', 'msg' => 'Bad Data for change Date']; } $changeDateProcess = $reservationService->changeDateForModification($newNightlyData, $reservationId, $isGetInfo, $apartel); // for view if ($isGetInfo && $changeDateProcess['status'] == 'success') { $addonDao = $this->getServiceLocator()->get('dao_booking_addons'); $forViewInfo = []; $type = 'Other'; foreach ($changeDateProcess['data'] as $date => $chargeType) { foreach ($chargeType['data'] as $row) { if (isset($row['view_charge_name'])) { $type = $row['view_charge_name']; } elseif (isset($row['addons_type'])) { $addonName = $addonDao->fetchOne(['id' => $row['addons_type']], ['name']); if ($addonName) { $type = $addonName->getName(); } } $forViewInfo[] = ['date' => $date, 'rate_name' => isset($row['rate_name']) ? $row['rate_name'] : '', 'price' => $chargeType['type'] == 'insert' ? $row['acc_amount'] : -1 * $row['acc_amount'], 'type' => $type]; } } return ['status' => 'success', 'data' => $forViewInfo]; } return $changeDateProcess; }
/** * * @param array $data * @return array */ public function getFixedDate($data) { $currentDate = date('Y-m-d'); $cityDao = new City($this->getServiceLocator(), 'ArrayObject'); if (isset($data['city']) && ClassicValidator::checkCityName($data['city'])) { $cityResp = $cityDao->getCityBySlug($data['city']); if ($cityResp) { $diffHousr = $this->getDiffHoursForDate(); $currentDate = Helper::getCurrenctDateByTimezone($cityResp['timezone'], 'd-m-Y', $diffHousr); } } $arrival = isset($data['arrival']) && $data['arrival'] && ClassicValidator::validateDate($data['arrival']) ? date('Y-m-d', strtotime($data['arrival'])) : ''; $departure = isset($data['departure']) && $data['departure'] && ClassicValidator::validateDate($data['departure']) ? date('Y-m-d', strtotime($data['departure'])) : ''; if ($arrival && $departure && strtotime($arrival) > strtotime($departure)) { $arrival = $departure = ''; } elseif ($arrival && strtotime($currentDate) > strtotime($arrival) || $departure && strtotime($currentDate) > strtotime($departure)) { $arrival = $departure = ''; } elseif (!$arrival && $departure) { $departure = ''; } elseif ($arrival && !$departure) { $departure = date('Y-m-d', strtotime($arrival . '+1 day')); } return ['arrival' => $arrival, 'departure' => $departure]; }
/** * * @return array */ public function getOptions($data) { /* @var $websiteSearchService \DDD\Service\Website\Search */ $websiteSearchService = $this->getServiceLocator()->get('service_website_search'); $diffHours = $websiteSearchService->getDiffHoursForDate(); $options['current_date'] = Helper::getCurrenctDateByTimezone($data['city_data']['timezone'], 'd-m-Y', $diffHours); $router = $this->getServiceLocator()->get('router'); $url = $router->assemble([], ['name' => 'search']); $options['url'] = $url; $guest = Objects::getGuestList(['guest' => $this->getTextLineSite(1455), 'guests' => $this->getTextLineSite(1456)]); $options['guest'] = $guest; return $options; }
public function getCurrentDateCity($cityId) { $cityDao = new \DDD\Dao\Geolocation\Cities($this->getServiceLocator(), 'ArrayObject'); $city = $cityDao->fetchOne(['id' => $cityId], ['timezone']); if ($city && $city['timezone']) { return Helper::getCurrenctDateByTimezone($city['timezone'], 'Y-m-d H:i:s'); } return date('Y-m-d H:i:s'); }
/** * @param int $id * @param ControllerBase $controller * @return array | bool */ public function getReservationCard($id, ControllerBase $controller) { /** * @var \DDD\Dao\Booking\Booking $reservationDao */ $card = false; /** * @var $reservationDao \DDD\Dao\Booking\Booking * @var $cccaDao \DDD\Dao\Finance\Ccca */ $reservationDao = $this->getServiceLocator()->get('dao_booking_booking'); $cccaDao = $this->getServiceLocator()->get('dao_finance_ccca'); $result = $reservationDao->getTheCard($id); // check has frontier charge permission $auth = $this->getServiceLocator()->get('library_backoffice_auth'); $router = $controller->getEvent()->getRouter(); if ($result) { $card = ['id' => $result->getId(), 'bookingStatus' => $result->getBookingStatus(), 'resNumber' => $result->getResNumber(), 'name' => $result->getResNumber(), 'guest' => $result->getGuest(), 'apartmentAssignedId' => $result->getApartmentAssignedId(), 'apartmentAssigned' => $result->getApartmentAssigned(), 'building' => $result->getBuilding(), 'buildingId' => $result->getBuildingId(), 'unitNumber' => $result->getUnitNumber(), 'guest_phone' => $result->getGuestPhone(), 'travelPhone' => $result->getGuestTravelPhone(), 'dateFrom' => $result->getDateFrom() ? date(Constants::GLOBAL_DATE_FORMAT, strtotime($result->getDateFrom())) : '', 'dateTo' => $result->getDateTo() ? date(Constants::GLOBAL_DATE_FORMAT, strtotime($result->getDateTo())) : '', 'arrivalDate' => $result->getArrivalDate() ? date(Constants::GLOBAL_DATE_FORMAT . ' H:i', strtotime($result->getArrivalDate())) : '', 'departureDate' => $result->getDepartureDate() ? date(Constants::GLOBAL_DATE_FORMAT . ' H:i', strtotime($result->getDepartureDate())) : '', 'now' => Helper::getCurrenctDateByTimezone($result->getTimezone()), 'arrivalStatus' => $result->getArrivalStatus(), 'occupancy' => $result->getOccupancy(), 'guestBalance' => $result->getGuestBalance(), 'housekeepingComments' => $result->getHousekeepingComments(), 'cccaVerified' => $result->getCccaVerified(), 'parking' => $result->getParking(), 'parking_url' => $router->assemble(['res_num' => $result->getResNumber()], ['name' => 'frontier/print-parking-permits']), 'key_task' => $result->getKeyTask(), 'keyTask' => $result->getKeyTask(), 'guestEmail' => $result->getGuestEmail(), 'cccaPageStatus' => $result->getCccaPageStatus(), 'cccaPageToken' => $result->getCccaPageToken(), 'apartmentCurrencyCode' => $result->getApartmentCurrencyCode(), 'cccaPageLink' => '']; if (strtotime($card['now']) <= strtotime($card['dateTo']) && $result->getKiPageStatus() == ReservationTicketService::SEND_KI_PAGE_STATUS && $result->getKiPageHash()) { $card['keyUrl'] = 'https://' . DomainConstants::WS_SECURE_DOMAIN_NAME . '/key?code=' . $result->getKiPageHash() . '&view=0' . '&bo=' . $result->getKiPageGodModeCode(); } if ($auth->hasRole(Roles::ROLE_FRONTIER_CHARGE)) { $card['frontierCharge'] = '/frontier/charge/' . $result->getId() . '/0/' . Helper::hashForFrontierCharge($result->getId()); } if (is_null($result->getArrivalTime())) { $card['arrivalTime'] = date('H:i', strtotime($result->getApartmentCheckInTime())); } else { $card['arrivalTime'] = date('H:i', strtotime($result->getArrivalTime())); } /* @var $chargeAuthorizationService \DDD\Service\Reservation\ChargeAuthorization */ $chargeAuthorizationService = $this->getServiceLocator()->get('service_reservation_charge_authorization'); $card['creditCardsForAuthorization'] = $chargeAuthorizationService->getCreditCardsForAuthorization($id); // CCCA page link $cccaData = $cccaDao->getAllSentCcca($id); if ($cccaData) { foreach ($cccaData as $index => $row) { $lastDigit = 0; foreach ($card['creditCardsForAuthorization'] as $cardInfo) { if ($cardInfo->getId() == $row->getCcId()) { $lastDigit = $cardInfo->getLast4Digits(); break; } } $card['cccaPageLink'][$index] = ['link' => 'https://' . DomainConstants::WS_SECURE_DOMAIN_NAME . '/ccca-page?token=' . $row->getPageToken(), 'lastDigit' => $lastDigit]; } } $card['hasMoreCards'] = false; if (count($card['creditCardsForAuthorization']) > $cccaData->count()) { $card['hasMoreCards'] = true; } } return $card; }
/** * @param array $data * @return string */ public function filterQueryData($data) { $currentDate = date('Y-m-d'); $cityDao = new City($this->getServiceLocator(), 'ArrayObject'); if (!isset($data['city'])) { $pageSlugExp = explode('--', $data['slug']); $citySlug = $pageSlugExp[1]; } else { $citySlug = $data['city']; } if (isset($citySlug) && ClassicValidator::checkCityName($citySlug)) { $cityResp = $cityDao->getCityBySlug(Helper::urlForSearch($citySlug, TRUE)); if ($cityResp) { /* @var $websiteSearchService \DDD\Service\Website\Search */ $websiteSearchService = $this->getServiceLocator()->get('service_website_search'); $diffHours = $websiteSearchService->getDiffHoursForDate(); $currentDate = Helper::getCurrenctDateByTimezone($cityResp['timezone'], 'd-m-Y', $diffHours); } } if (!isset($data['arrival']) || !ClassicValidator::validateDate($data['arrival']) || !isset($data['departure']) || !ClassicValidator::validateDate($data['departure']) || strtotime($data['arrival']) < strtotime($currentDate) || strtotime($data['arrival']) >= strtotime($data['departure'])) { return false; } return true; }
public function ajaxReportIncidentAction() { /** * @var \DDD\Dao\Booking\Booking $reservationDao * @var \DDD\Service\Task $taskService */ $user = $this->getServiceLocator()->get('library_backoffice_auth'); $taskService = $this->getServiceLocator()->get('service_task'); $request = $this->getRequest(); $result = ['status' => 'success', 'msg' => 'Incident report has been created.', 'title' => '', 'taskId' => 0]; $taskId = (int) $request->getPost('task_id', 0); try { if ($request->isXmlHttpRequest() && $taskId) { $task = $taskService->getTaskDao()->getTaskById($taskId); $apartmentId = $task->getProperty_id(); $buildingId = $task->getBuildingId(); $resId = $task->getResId(); $timezone = $task->getTimezone(); $currentDateCity = Helper::getCurrenctDateByTimezone($timezone, 'Y-m-d H:i:s'); $ninetySixHoursLaterDateCity = Helper::incrementDateByTimezone($timezone, 96, 'Y-m-d H:i:s'); $userId = $user->getIdentity()->id; $creator = $user->getIdentity()->id; switch ((int) $request->getPost('incident_type', 0)) { case HouseKeeping::INCIDENT_REPORT_EVIDENCE_OF_SMOKING: $damageType = 'There was evidence of smoking'; break; case HouseKeeping::INCIDENT_REPORT_KEYS_WERE_NOT_RETURNED: $damageType = 'The keys were not returned'; break; case HouseKeeping::INCIDENT_REPORT_DIRTY_HOUSE: $damageType = 'The house was left in a unusually dirty condition'; break; case HouseKeeping::INCIDENT_REPORT_BROKEN_FURNITURE: $damageType = 'There was broken furniture'; break; case HouseKeeping::INCIDENT_REPORT_OTHER: $damageType = $request->getPost('description', 'Incident Report'); break; } $title = $damageType; $description = ''; $incidentTaskId = $taskService->createReportIncidentTask($resId, $apartmentId, $buildingId, $currentDateCity, $ninetySixHoursLaterDateCity, $title, $creator, $description, $userId, $taskId); $result['title'] = $title; $result['taskId'] = $incidentTaskId; } } catch (\Exception $e) { $result['status'] = 'error'; $result['msg'] = TextConstants::SERVER_ERROR; } return new JsonModel($result); }
/** * @param $resDateFrom * @param $apartmentId * @return bool|string */ public function getMoveStartDate($resDateFrom, $apartmentId) { /** * @var \DDD\Dao\Apartment\General $apartmentDao */ $apartmentDao = $this->getServiceLocator()->get('dao_apartment_general'); $apartmentData = $apartmentDao->getApartmentDataForReservationMove($apartmentId); $today = Helper::getCurrenctDateByTimezone($apartmentData['timezone']); // $time = Helper::getCurrenctDateByTimezone($apartmentData['timezone'], 'H:i:s'); // if ($resDateFrom > $today) { // return $resDateFrom; // } else if ($time >= $apartmentData['check_in']) { // return $today; // } else { // return Helper::getDateByTimeZone('-1 days', $apartmentData['timezone']); // } if ($resDateFrom >= $today) { return $resDateFrom; } else { return $today; } }