public function __invoke($apartmentId) { $bookingDao = new Booking($this->getServiceLocator(), 'ArrayObject'); $response = $bookingDao->getCurrentReservationByAcc($apartmentId, date('Y-m-d')); if ($response && $response['res_number']) { return '<a href="/booking/edit/' . $response['res_number'] . '" class="action-item label label-info pull-right" target="blank">Current reservation <span class="glyphicon glyphicon-share"></span></a>'; } }
/** * Process Cancel * @param string $resNumber * @param int $bookingStatus * @return boolean */ public function applyCancelation($resNumber, $bookingStatus) { /** @var Inventory $inventoryService */ $inventoryService = $this->getServiceLocator()->get('service_apartment_inventory'); $bookingDao = new Booking($this->getServiceLocator(), '\\DDD\\Domain\\Booking\\ResId'); $bookingDomain = $bookingDao->getBookingTicketByReservationNumber($resNumber); $bookingStatus = $bookingDomain->getFundsConfirmed() == BookingTicket::CC_STATUS_INVALID ? BookingService::BOOKING_STATUS_CANCELLED_INVALID : $bookingStatus; return $inventoryService->processCancellation($resNumber, false, false, $bookingStatus); }
public function indexAction() { /** * @var \DDD\Service\Apartment\General $apartmentGeneralService * @var \DDD\Service\Apartment\Main $apartmentMainService * @var \DDD\Service\Apartment\OTADistribution $apartmentOTAService * @var $taskService \DDD\Service\Task * @var $bookingTicketService \DDD\Service\Booking\BookingTicket */ $apartmentGeneralService = $this->getServiceLocator()->get('service_apartment_general'); $apartmentMainService = $this->getServiceLocator()->get('service_apartment_main'); $apartmentOTAService = $this->getServiceLocator()->get('service_apartment_ota_distribution'); $taskService = $this->getServiceLocator()->get('service_task'); $bookingTicketService = $this->getServiceLocator()->get('service_booking_booking_ticket'); $apartmentTasks = $taskService->getFrontierTasksOnApartment($this->apartmentId); $apartmentOTAList = $apartmentOTAService->getOTAList($this->apartmentId); $building = $apartmentMainService->getApartmentBuilding($this->apartmentId); $apartels = $apartmentMainService->getApartmentApartels($this->apartmentId); $bookingDao = new Booking($this->getServiceLocator(), 'ArrayObject'); $mediaDao = new Media($this->getServiceLocator(), 'ArrayObject'); $dateDisabled = $currentReservation = $nextReservation = false; $apartmentDates = $apartmentMainService->getApartmentDates($this->apartmentId); $generalInfo = $apartmentGeneralService->getApartmentGeneral($this->apartmentId); if ($this->apartmentStatus == Objects::PRODUCT_STATUS_DISABLED) { $dateDisabled = $apartmentDates['disable_date']; } else { $currentReservation = $bookingDao->getCurrentReservationByAcc($this->apartmentId, date('Y-m-d')); $resId = $currentReservation['id']; $pin = $currentReservation['pin']; $current = true; if (!$currentReservation) { $nextReservation = $bookingDao->getNextReservationByAcc($this->apartmentId, date('Y-m-d')); $resId = $nextReservation['id']; $pin = $nextReservation['pin']; $current = false; } if ($resId && $pin) { $lockDatas = $bookingTicketService->getLockByReservation($resId, $pin, [LockService::USAGE_APARTMENT_TYPE]); foreach ($lockDatas as $key => $lockData) { switch ($key) { case LockService::USAGE_APARTMENT_TYPE: if ($current) { $currentReservation['pin'] = $lockData['code']; } else { $nextReservation['pin'] = $lockData['code']; } break; } } } } $img = $mediaDao->getFirstImage($this->apartmentId)['img1']; $viewModel = new \Zend\View\Model\ViewModel(); $viewModel->setVariables(['apartmentId' => $this->apartmentId, 'apartmentStatus' => $this->apartmentStatus, 'currentReservation' => $currentReservation, 'nextReservation' => $nextReservation, 'dateCreated' => $apartmentDates['create_date'], 'dateDisabled' => $dateDisabled, 'img' => str_replace('orig', 445, $img), 'OTAList' => $apartmentOTAList, 'building' => $building, 'apartels' => $apartels, 'apartment' => $generalInfo, 'apartmentTasks' => $apartmentTasks]); $viewModel->setTemplate('apartment/main/index'); return $viewModel; }
/** * @param int $productRateId * @param array $dates * @param int $roomCount * @param float $price * @see \DDD\Service\ChannelManager::getDates() * @return array * <pre> * array( * 'cancel' => $cancel, * 'penalty' => $penalty, * 'currency_rate' => $currencyRate, * 'penalty_fixed_amount' => $penaltyAmount, * 'refundable_before_hours' => $refBeforeHours, * 'penalty_val' => $penaltyValue, * ) * </pre> */ public function getPenalty($productRateId, $dates, $roomCount, $price, $resNumber = false) { if ($resNumber) { // for charging $bookingDao = new BookingForPenalty($this->getServiceLocator(), 'DDD\\Domain\\Apartment\\ProductRate\\Penalty'); $productRateDomain = $bookingDao->getRateDataForReservation($resNumber); } else { // for reservation /** @var \DDD\Dao\Apartment\Rate $productRateDao */ $productRateDao = $this->getServiceLocator()->get('dao_apartment_rate'); $productRateDomain = $productRateDao->getRateById($productRateId); } $dayCount = $this->dateDiff($dates['date_from'], $dates['date_to']); $penaltyValue = $this->getPenaltyValue($productRateDomain, $dayCount); if ($productRateDomain->getPenaltyType() == Rate::APARTMENT_RATE_NON_REFUNDABLE) { $penaltyValue *= $roomCount; } else { } return ['is_refundable' => $productRateDomain->getIsRefundable(), 'penalty' => $productRateDomain->getPenaltyType(), 'penalty_fixed_amount' => $productRateDomain->getIsRefundable() == Rate::APARTMENT_RATE_NON_REFUNDABLE ? $price : $this->calculatePenalty($productRateDomain, $dayCount, $price, $roomCount), 'refundable_before_hours' => $productRateDomain->getIsRefundable() == Rate::APARTMENT_RATE_REFUNDABLE ? $productRateDomain->getRefundableBeforeHours() : 0, 'penalty_val' => $penaltyValue]; }
/** * @param int $apartment_id * @param float $sale * @param date $startDate * @param date $endDate * @var ginosiColl ginosiCollectTransactionsSummaryInApartmentCurrency * @var partnerColl partnerCollectTransactionsSummaryInApartmentCurrency * @return Array */ private function _getSaleArray($apartment_id, $sale, $startDate, $endDate, $passYear = false) { $sale['all_bookings'] = $sale['all_cancelations'] = $sale['all_cancelations'] = $sale['highest_sold_price'] = $sale['long_stay'] = $sale['stay_period']['long'] = 0; $sale['stay_period'] = []; $notUsedStatus = [ForBookingStatus::BOOKING_STATUS_CANCELLED_INVALID, ForBookingStatus::BOOKING_STATUS_CANCELLED_EXCEPTION, ForBookingStatus::BOOKING_STATUS_CANCELLED_TEST_BOOKING, ForBookingStatus::BOOKING_STATUS_CANCELLED_MOVED]; /** * @var $bankTransactionService \DDD\Service\Booking\BankTransaction * @var \DDD\Dao\Booking\ReservationNightly $reservationNightlyDao */ $bookingDao = new Booking($this->getServiceLocator(), 'DDD\\Domain\\Apartment\\Statistics\\ForBasicDataBooking'); $userManagerDao = $this->getServiceLocator()->get('dao_user_user_manager'); $reservationNightlyDao = $this->getServiceLocator()->get('dao_booking_reservation_nightly'); $inventoryDao = new Inventory($this->getServiceLocator(), '\\ArrayObject'); $bankTransactionService = $this->getServiceLocator()->get('service_booking_bank_transaction'); $expenseDao = new ExpenseStatistics($this->getServiceLocator()); $bookings = $bookingDao->getBookingsForYear($apartment_id, $startDate, $endDate, $notUsedStatus); $monthlyConst = $expenseDao->getMonthlyCost($apartment_id, $startDate, $endDate); // calculate with nightly data $fistDate = $startDate; $i = 0; while ($i <= 12) { $nextDate = date('Y-m-01', strtotime('+1 month', strtotime($fistDate))); $monthDays = cal_days_in_month(CAL_GREGORIAN, date('m', strtotime($fistDate)), date('Y', strtotime($fistDate))); // reservation day count $monthlyData = $reservationNightlyDao->getBookedMonthlyData($apartment_id, $fistDate, $nextDate); $bookedDayCount = $monthlyData['count']; $monthlySum = $monthlyData['sum']; // closed days $totalClosed = $inventoryDao->getClosedAv($apartment_id, $fistDate, $nextDate); $selectedMonth = date("M_Y", strtotime($fistDate)); $sale['close_out'][$selectedMonth] = $totalClosed - $bookedDayCount; $sale['unsold_days'][$selectedMonth] = $monthDays - $bookedDayCount; $sale['monthly_av_price'][$selectedMonth] = number_format($bookedDayCount ? $monthlySum / $bookedDayCount : 0, 2, '.', ''); // get highest and lowest sold prices if ($passYear) { // get highest price if ($sale['highest_sold_price'] < $monthlyData['max']) { $sale['highest_sold_price'] = $monthlyData['max']; } // get lowest price if (!array_key_exists('lowest_sold_price', $sale) && $monthlyData['min']) { $sale['lowest_sold_price'] = $monthlyData['min']; } elseif (isset($sale['lowest_sold_price']) && $sale['lowest_sold_price'] > $monthlyData['min'] && $monthlyData['min']) { $sale['lowest_sold_price'] = $monthlyData['min']; } } $fistDate = $nextDate; $i++; } // Monthly Booking And Cancelations And Margin foreach ($bookings as $book) { $month = date("M_Y", strtotime($book->getDate_to())); /* @var $ginosiColl $ginosiCollectTransactionsSummaryDomain \DDD\Domain\Booking\TransactionSummary */ $ginosiColl = $bankTransactionService->getTransactionsSummary($book->getId(), BankTransaction::TRANSACTION_MONEY_DIRECTION_GINOSI_COLLECT, [BankTransaction::BANK_TRANSACTION_TYPE_PAY]); $ginosiCollCurrency = $ginosiColl->getSummaryInApartmentCurrency(); /* @var $partnerCollectTransactionsSummaryDomain \DDD\Domain\Booking\TransactionSummary */ $partnerColl = $bankTransactionService->getTransactionsSummary($book->getId(), BankTransaction::TRANSACTION_MONEY_DIRECTION_PARTNER_COLLECT, [BankTransaction::BANK_TRANSACTION_TYPE_PAY]); $partnerCollCurrency = $partnerColl->getSummaryInApartmentCurrency(); $transactionsSummary = $ginosiCollCurrency + $partnerCollCurrency; if (ForBookingStatus::BOOKING_STATUS_BOOKED == $book->getStatus()) { $sale['all_bookings'] += 1; $sale['monthly_bookings'][$month] += 1; $ginosiksRes = $userManagerDao->getGinosiksReservation($book->getGuestEmail()); if ($ginosiksRes) { $sale['free_sold'][$month] += 1; } $date_diff = Helper::getDaysFromTwoDate($book->getDate_to(), $book->getDate_from()); if ($sale['long_stay'] < $date_diff) { $sale['long_stay'] = $date_diff; } } elseif (ForBookingStatus::BOOKING_STATUS_CANCELLED_BY_CUSTOMER == $book->getStatus()) { $sale['all_cancelations'] += 1; $month = date("M_Y", strtotime($book->getDate_to())); $sale['monthly_cancalations'][$month] += 1; } $sale = $this->_setMonthlyCost($book, $month, $sale, $transactionsSummary); } //Calculate final monthly cost foreach ($monthlyConst as $month => $cost) { if (isset($sale['monthly_cost'][$month])) { $sale['monthly_cost'][$month] += $cost; $sale['monthly_cost_total'] += $cost; $sale['profit'][$month] = $sale['monthly_revenue'][$month] - $sale['monthly_cost'][$month]; } } // Cancellation score $total_reservations = ($sale['all_cancelations'] + $sale['all_bookings']) * 100; if (0 != $total_reservations) { $sale['cancelation_score'] = $sale['all_cancelations'] / ($sale['all_cancelations'] + $sale['all_bookings']) * 100; $sale['cancelation_score'] = number_format($sale['cancelation_score'], 1); } else { $sale['cancelation_score'] = 0; } // Monthly Occupancy $bookingReservationData = $bookingDao->getReservationForAccOnDate($apartment_id, $startDate, $endDate); $reservationDates = []; foreach ($bookingReservationData as $reservation) { $reservationDates = array_merge($reservationDates, Helper::getDateListInRange($reservation->getDate_from(), date('Y-m-d', strtotime('-1 day', strtotime($reservation->getDate_to()))))); } //Get Extremes $inventoryDao = new Inventory($this->getServiceLocator(), 'DDD\\Domain\\Apartment\\Statistics\\ForBasicDataInventory'); $extremums = $inventoryDao->getExtremums($apartment_id, $startDate, $endDate); $sale['max_avilability'] = $extremums->getMax_availability(); $sale['max_price'] = $extremums->getMax_price(); $sale['min_price'] = $extremums->getMin_price(); //Get Review $apartmentReview = $this->getServiceLocator()->get('service_apartment_review'); $apartmentGeneralDao = $this->getServiceLocator()->get('dao_apartment_general'); $reviewScore = $apartmentGeneralDao->getReviewScore($apartment_id)['score']; $sale['review'] = $reviewScore; return $sale; //Set All Times Statistics }
public function removeReservationCreditCardsFromBlackList($reservationId) { /** * @var $creditCardService Card */ $reservationsDao = new BookingDAO($this->getServiceLocator(), '\\ArrayObject'); $creditCardService = $this->getServiceLocator()->get('service_card'); $customerId = $reservationsDao->getCustomerIdByReservationId($reservationId); // When reservation was removed from blacklist manually, all credit cards should take status "Unknown" $creditCardService->changeCustomerCardStatuses($customerId, Card::CC_STATUS_UNKNOWN); }
public function checkDisablePossibilityAction() { $bookingDao = new Booking($this->getServiceLocator(), 'ArrayObject'); $currentReservation = $bookingDao->getCurrentReservationByAcc($this->apartmentId, date('Y-m-d')); $nextReservation = false; if (!$currentReservation) { $nextReservation = $bookingDao->getNextReservationByAcc($this->apartmentId, date('Y-m-d')); } return new JsonModel(['isPossible' => !$currentReservation && !$nextReservation]); }
/** * @param int $reservationId * @return bool */ public function isFraudReservation($reservationId) { $reservationsDao = new BookingDao($this->getServiceLocator(), '\\ArrayObject'); $customerId = $reservationsDao->getCustomerIdByReservationId($reservationId); /** * @var Token $tokenDao */ $tokenDao = $this->getServiceLocator()->get('dao_cc_token'); $customerFraudCreditCards = $tokenDao->fetchAll(['customer_id' => $customerId, 'status' => CardService::CC_STATUS_FRAUD], ['id']); /** * @var $blackListDao BlackList */ $blackListDao = $this->getServiceLocator()->get('dao_booking_black_list'); $data = $this->getFraudCombinationAndData($reservationId); $blackListResult = $blackListDao->getBlackList(['fullName' => $data['fullName'], 'fullNamePhone' => $data['fullNamePhone'], 'fullNameAddress' => $data['fullNameAddress'], 'email' => $data['guest_email'], 'phone' => $data['phone']]); if ($customerFraudCreditCards->count() || $blackListResult->count()) { return true; } return false; }