Beispiel #1
0
 /**
  * @param \DDD\Domain\Booking\BookingTicket $data
  * @param array $formData
  *
  * @return array
  */
 public function prepareData($data, $formData)
 {
     /**
      * @var ReviewBooking $review
      * @var \DDD\Service\Reservation\PartnerSpecific $partnerSpecificService
      * @var \DDD\Service\Booking\Charge $bookingChargeService
      * @var \DDD\Dao\Booking\Booking $bookingDao
      */
     $partnerSpecificService = $this->getServiceLocator()->get('service_reservation_partner_specific');
     $daoReview = new \DDD\Dao\Accommodation\Review($this->getServiceLocator(), 'DDD\\Domain\\Review\\ReviewBooking');
     $bookingChargeService = $this->getServiceLocator()->get('service_booking_charge');
     $cityService = $this->getServiceLocator()->get('service_location');
     $bookingDao = $this->getServiceLocator()->get('dao_booking_booking');
     $bookingDao->setEntity(new \DDD\Domain\Booking\PrepareData());
     $dataOther = [];
     $reservationId = $data->getId();
     $startDate = $data->getDate_from();
     $endDate = $data->getDate_to();
     $review_res_number = $data->getResNumber();
     $review = $daoReview->fetchOne(['res_number' => $review_res_number]);
     if ($review) {
         $data->setHas_review(true);
     } else {
         $data->setHas_review(false);
     }
     $auth = $this->getServiceLocator()->get('library_backoffice_auth');
     $dataOther['credit_card_view'] = false;
     if ($auth->hasRole(Roles::ROLE_CREDIT_CARD)) {
         $dataOther['credit_card_view'] = true;
         $dataOther['secure_url'] = "https://" . DomainConstants::WS_SECURE_DOMAIN_NAME . "/booking/update-cc-details?code=" . $formData['data']->getProvideCcPageHash();
     }
     if ($auth->hasRole(Roles::ROLE_RESERVATIONS)) {
         $dataOther['reservation_role'] = true;
     } else {
         $bookingService = $this->getServiceLocator()->get('service_booking');
         $part = $bookingService->getPartnerById($data->getPartnerId());
         $dataOther['affiliate'] = $part->getPartnerName();
     }
     $keyPageStatus = '';
     if (!Helper::checkDatesByDaysCount(1, $data->getDate_to())) {
         $keyPageStatus = "Expired";
     } elseif ($data->getKiPageStatus() == 1) {
         $kiPageHash = $data->getKiPageHash();
         $keyPageStatus = "<a target='_blank'  href='https://" . DomainConstants::WS_SECURE_DOMAIN_NAME . '/key?view=0&code=' . $kiPageHash . "' >Key Entry Link</a>";
     } elseif (!$data->getKiPageStatus()) {
         $keyPageStatus = "Not set yet";
     }
     $is_penalty_applied = $this->isPenaltyApplied($data->getDate_from(), $data->getIsRefundable(), $data->getRefundableBeforeHours());
     $penalty_period = $this->calculateCancelationPeriod($data->getStatus(), $data->getCancelation_date(), $data->getDate_to(), $is_penalty_applied);
     $dataOther['keyPageStatus'] = $keyPageStatus;
     $dataOther['penalty_period'] = $penalty_period;
     $penalty_val = number_format(str_replace(",", ".", $data->getPenalty_val()), 2, '.', '');
     $penalty = number_format(str_replace(",", ".", $data->getPenalty()), 2, '.', '');
     if (Rate::APARTMENT_RATE_REFUNDABLE == $data->getIsRefundable()) {
         if ($data->getRefundableBeforeHours() > 48) {
             $dataOther['cancellation'] = "This deal can be canceled for FREE up to " . $data->getRefundableBeforeHours() / 24 . " days before arrival";
         } else {
             $dataOther['cancellation'] = "This deal can be canceled for FREE up to " . $data->getRefundableBeforeHours() . " hours before arrival";
         }
     } else {
         $dataOther['cancellation'] = 'Non refundable';
     }
     $dataOther['panelty_type'] = Helper::getPenalty($penalty, $penalty_val, $data->getApartmentCurrencyCode());
     foreach ($formData['options']['statuses'] as $row) {
         if ($row->getId() == $data->getStatus()) {
             $dataOther['status_name'] = $row->getName();
             break;
         }
     }
     foreach ($formData['options']['partners'] as $row) {
         if ($row->getGid() == $data->getPartnerId()) {
             $dataOther['partner_name'] = $row->getPartnerName();
             $dataOther['partner_id'] = $data->getPartnerId();
             break;
         }
     }
     $customerReservations = $bookingDao->getCustomerReservationsStatuses($data->getGuestEmail());
     $bookedReservationsCount = 0;
     $cancelledReservationsCount = 0;
     $hasDebtBalance = false;
     foreach ($customerReservations as $customerReservation) {
         if (!$hasDebtBalance && $customerReservation->getBalance() < 0 && $data->getResNumber() != $customerReservation->getResNumber()) {
             $hasDebtBalance = true;
         }
         if ($customerReservation->getStatus() == BookingService::BOOKING_STATUS_BOOKED) {
             $bookedReservationsCount++;
         } else {
             $cancelledReservationsCount++;
         }
     }
     $dataOther['pendingCreditCardInQueue'] = false;
     $pendingCreditCardInQueue = $bookingDao->getPendingInQueueCardsByReservationId($reservationId);
     if ($pendingCreditCardInQueue->count()) {
         $dataOther['pendingCreditCardInQueue'] = true;
     }
     /**
      * @var \DDD\Service\Fraud $fraudService
      */
     $fraudService = $this->getServiceLocator()->get('service_fraud');
     $fraud = $fraudService->getFraudForReservation($reservationId);
     $dataOther['terminals'] = Objects::getTerminalList();
     $dataOther['addons'] = $formData['options']['addons'];
     $dataOther['addons_array'] = $formData['options']['addons_array'];
     $dataOther['fraud'] = $fraud;
     $dataOther['psp'] = [];
     $dataOther['curencyRate'] = $formData['options']['curencyRate'];
     $dataOther['charges'] = $formData['options']['charges'];
     $dataOther['charged'] = $formData['options']['charged'];
     $dataOther['chargeType'] = $formData['options']['chargeType'];
     $dataOther['transactions'] = $formData['options']['transactions'];
     $dataOther['ginosiCollectChargesSummaryInApartmentCurrency'] = $formData['options']['balances_and_summaries']['ginosiCollectChargesSummaryInApartmentCurrency'];
     $dataOther['ginosiCollectChargesSummaryInCustomerCurrency'] = $formData['options']['balances_and_summaries']['ginosiCollectChargesSummaryInCustomerCurrency'];
     $dataOther['partnerCollectChargesSummaryInApartmentCurrency'] = $formData['options']['balances_and_summaries']['partnerCollectChargesSummaryInApartmentCurrency'];
     $dataOther['partnerCollectChargesSummaryInCustomerCurrency'] = $formData['options']['balances_and_summaries']['partnerCollectChargesSummaryInCustomerCurrency'];
     $dataOther['ginosiCollectTransactionsSummaryInApartmentCurrency'] = $formData['options']['balances_and_summaries']['ginosiCollectTransactionsSummaryInApartmentCurrency'];
     $dataOther['ginosiCollectTransactionsSummaryInCustomerCurrency'] = $formData['options']['balances_and_summaries']['ginosiCollectTransactionsSummaryInCustomerCurrency'];
     $dataOther['partnerCollectTransactionsSummaryInApartmentCurrency'] = $formData['options']['balances_and_summaries']['partnerCollectTransactionsSummaryInApartmentCurrency'];
     $dataOther['partnerCollectTransactionsSummaryInCustomerCurrency'] = $formData['options']['balances_and_summaries']['partnerCollectTransactionsSummaryInCustomerCurrency'];
     $dataOther['chargesSummaryInApartmentCurrency'] = $formData['options']['balances_and_summaries']['chargesSummaryInApartmentCurrency'];
     $dataOther['chargesSummaryInCustomerCurrency'] = $formData['options']['balances_and_summaries']['chargesSummaryInCustomerCurrency'];
     $dataOther['transactionsSummaryInApartmentCurrency'] = $formData['options']['balances_and_summaries']['transactionsSummaryInApartmentCurrency'];
     $dataOther['transactionsSummaryInCustomerCurrency'] = $formData['options']['balances_and_summaries']['transactionsSummaryInCustomerCurrency'];
     $dataOther['ginosiBalanceInApartmentCurrency'] = $formData['options']['balances_and_summaries']['ginosiBalanceInApartmentCurrency'];
     $dataOther['ginosiBalanceInCustomerCurrency'] = $formData['options']['balances_and_summaries']['ginosiBalanceInCustomerCurrency'];
     $dataOther['partnerBalanceInApartmentCurrency'] = $formData['options']['balances_and_summaries']['partnerBalanceInApartmentCurrency'];
     $dataOther['partnerBalanceInCustomerCurrency'] = $formData['options']['balances_and_summaries']['partnerBalanceInCustomerCurrency'];
     $dataOther['resCount'] = $bookedReservationsCount;
     $dataOther['cancelCount'] = $cancelledReservationsCount;
     $dataOther['hasDebtBalance'] = $hasDebtBalance;
     $dataOther['hasPayableRole'] = $formData['options']['hasPayableRole'];
     $dataOther['hasTransactionVerifierRole'] = $formData['options']['hasTransactionVerifierRole'];
     $dataOther['creditCardsForAuthorization'] = $formData['options']['credit_cards_for_authorization'];
     //Calculate Taxes
     $nightCount = Helper::getDaysFromTwoDate($data->getDate_to(), $data->getDate_from());
     /** @var \DDD\Service\Taxes $taxesService */
     $taxesService = $this->getServiceLocator()->get('service_taxes');
     $taxesParams = ['tot' => $data->getTot(), 'tot_type' => $data->getTotType(), 'tot_included' => $data->getTotIncluded(), 'tot_additional' => $data->getTotAdditional(), 'tot_max_duration' => $data->getTotMaxDuration(), 'vat' => $data->getVat(), 'vat_type' => $data->getVatType(), 'vat_included' => $data->getVatIncluded(), 'vat_additional' => $data->getVatAdditional(), 'vat_max_duration' => $data->getVatMaxDuration(), 'city_tax' => $data->getCity_tax(), 'city_tax_type' => $data->getCityTaxType(), 'city_tax_included' => $data->getCityTaxIncluded(), 'city_tax_additional' => $data->getCityTaxAdditional(), 'city_tax_max_duration' => $data->getCityTaxMaxDuration(), 'sales_tax' => $data->getSales_tax(), 'sales_tax_type' => $data->getSalesTaxType(), 'sales_tax_included' => $data->getSalesTaxIncluded(), 'sales_tax_additional' => $data->getSalesTaxAdditional(), 'sales_tax_max_duration' => $data->getSalesTaxMaxDuration(), 'apartment_currency' => $data->getApartmentCurrencyCode(), 'customer_currency' => $data->getGuestCurrencyCode(), 'country_currency' => $data->getCountryCurrecny(), 'night_count' => $nightCount, 'rate_capacity' => $data->getRateCapacity(), 'occupancy' => $data->getOccupancy()];
     $taxesData = $taxesService->getTaxesForCharge($taxesParams);
     $dataOther += $taxesData;
     /**
      * @var \DDD\Service\Booking\ReservationIssues $reservationIssuesService
      */
     $reservationIssuesService = $this->getServiceLocator()->get('service_booking_reservation_issues');
     $issuesData = $reservationIssuesService->getReservationIssues($reservationId);
     $dataOther['hasIssues'] = false;
     $dataOther['hasIssuesText'] = '';
     if (count($issuesData) > 0) {
         $dataOther['hasIssuesText'] .= '<p>' . TextConstants::ISSUE_DETECTED_FOLLOWING . ':<br>';
         foreach ($issuesData as $issue) {
             $dataOther['hasIssuesText'] .= '<li>' . $issue->getTitle() . '</li>';
         }
         $dataOther['hasIssuesText'] .= '</p>';
         $dataOther['hasIssues'] = true;
     }
     /**
      * @var Card $cardService
      */
     $cardService = $this->getServiceLocator()->get('service_card');
     $customerCreditCards = $cardService->getCustomerCreditCardsForReservationTicket($data->getCustomerId());
     $creditCardsMerge = $customerCreditCards;
     $dataOther['hasValidCard'] = $creditCardsMerge['hasValidCard'];
     foreach ($formData['options']['psp'] as $psp) {
         array_push($dataOther['psp'], $psp);
     }
     /**
      * @var \DDD\Dao\MoneyAccount\MoneyAccount $moneyAccountDao
      */
     $moneyAccountDao = $this->getServiceLocator()->get('dao_money_account_money_account');
     $moneyAccountList = $moneyAccountDao->getActiveBankList();
     $dataOther['money_account_list'] = $moneyAccountList;
     $dataOther['person_account_list'] = $moneyAccountDao->getActivePersonList();
     /**
      * @var \DDD\Dao\Booking\ReservationNightly $reservationNightlyDao
      * @var \DDD\Dao\Apartment\Rate $apartmentRateDao
      */
     $reservationNightlyDao = $this->getServiceLocator()->get('dao_booking_reservation_nightly');
     $apartmentRateDao = $this->getServiceLocator()->get('dao_apartment_rate');
     // get nightly data
     $nightsData = $reservationNightlyDao->getNightsDateWithCharge($reservationId);
     $nightsParse = $dates = $ratesPriceByDateParse = [];
     foreach ($nightsData as $night) {
         $dates[] = $night['date'];
         // if partner specific get specific price
         $priceForNight = $partnerSpecificService->getPartnerDeductedPrice($data->getPartnerId(), $night['price'], $data->getApartmentIdAssigned());
         $nightsParse["_" . $night['id']] = ['reservation_nightly_id' => $night['id'], 'apartment_id' => $night['apartment_id'], 'rate_id' => $night['rate_id'], 'rate_name' => $night['rate_name'], 'price' => $priceForNight, 'date' => $night['date']];
         if ($night['charge_id']) {
             $ratesPriceByDateParse[$night['date']][] = ['id' => $night['rate_id'], 'rate_name' => $night['rate_name'] . ' *', 'price' => $night['price'], 'date' => $night['date']];
         }
     }
     // check is apartel
     $apartel = $bookingDao->checkIsApartel($reservationId);
     // get rate data by date
     if ($apartel) {
         /** @var \DDD\Dao\Apartel\Rate $apartelRateDao */
         $apartelRateDao = $this->getServiceLocator()->get('dao_apartel_rate');
         $ratesPriceByDate = $apartelRateDao->getRatesPriceByDate($data->getRoom_id(), $dates);
     } else {
         $ratesPriceByDate = $apartmentRateDao->getRatesPriceByDate($data->getApartmentIdAssigned(), $dates);
     }
     foreach ($ratesPriceByDate as $rate) {
         $ratesPriceByDateParse[$rate['date']][] = ['id' => $rate['id'], 'rate_name' => $rate['rate_name'], 'price' => $rate['price'], 'date' => $rate['date']];
     }
     // date list
     $current = strtotime($data->getDate_from());
     $last = strtotime($data->getDate_to());
     $dateList = [];
     $k = 1;
     while ($current < $last) {
         $dateList[$k] = date('Y-m-d', $current);
         $current = strtotime('+1 day', $current);
         $k++;
     }
     $dataOther['dateList'] = json_encode($dateList);
     // get near reservation dates
     $usedFrom = $data->getDate_from();
     $usedTo = $data->getDate_to();
     /**
      * @var \DDD\Dao\Apartment\Inventory $inventoryDao
      */
     $beforeDate = date('Y-m-d', strtotime('-10 day', strtotime($usedFrom)));
     $afterDate = date('Y-m-d', strtotime('+10 day', strtotime($usedTo)));
     $inventoryDao = $this->getServiceLocator()->get('dao_apartment_inventory');
     $dateAvListBeforeAfterReservation = $inventoryDao->getDateAvListBeforeAfterReservation($data->getApartmentIdAssigned(), $beforeDate, $afterDate);
     $dateListParseCheckIn = $dateListParseCheckOut = [];
     $classHighlight = '';
     foreach ($dateAvListBeforeAfterReservation as $row) {
         if ($row['availability'] == 1) {
             $classHighlight = 'date-open';
         } else {
             $classHighlight = 'date-closed';
         }
         if ($row['date'] >= $usedFrom && $row['date'] <= $usedTo) {
             $classHighlight = 'date-open date-used';
         }
         $dateListParseCheckIn[$row['date']] = ['date' => $row['date'], 'class' => $classHighlight, 'availability' => $row['availability']];
     }
     foreach ($dateListParseCheckIn as $row) {
         $dateForCheckout = date('Y-m-d', strtotime('-1 day', strtotime($row['date'])));
         if (!isset($dateListParseCheckIn[$dateForCheckout]['availability'])) {
             continue;
         }
         if ($dateListParseCheckIn[$dateForCheckout]['availability'] == 1) {
             $classHighlight = 'date-open';
         } else {
             $classHighlight = 'date-closed';
         }
         if ($dateForCheckout >= $usedFrom && $dateForCheckout < $usedTo) {
             $classHighlight = 'date-open';
         }
         if ($row['date'] >= $usedFrom && $row['date'] <= $usedTo) {
             $classHighlight .= ' date-used';
         }
         $dateListParseCheckOut[$dateForCheckout] = ['date' => $row['date'], 'class' => $classHighlight];
     }
     $dataOther['dateForHighlightsCheckIn'] = json_encode($dateListParseCheckIn);
     $dataOther['dateForHighlightsCheckOut'] = json_encode($dateListParseCheckOut);
     // calculate total apartment and taxes
     $totalApartmentView = [];
     $totalChargeType = [BookingAddon::ADDON_TYPE_ACC, BookingAddon::ADDON_TYPE_TAX_TOT, BookingAddon::ADDON_TYPE_TAX_VAT, BookingAddon::ADDON_TYPE_CITY_TAX, BookingAddon::ADDON_TYPE_SALES_TAX, BookingAddon::ADDON_TYPE_DISCOUNT, BookingAddon::ADDON_TYPE_PARKING];
     $value = '';
     $hasReversedCharges = false;
     /** @var \DDD\Domain\Booking\Charge $row */
     foreach ($dataOther['charged'] as $row) {
         if ($row->getStatus() == ChargesServices::CHARGE_STATUS_DELETED) {
             $hasReversedCharges = true;
         }
         if (in_array($row->getAddons_type(), $totalChargeType) && $row->getAddons_type() != BookingAddon::ADDON_TYPE_PARKING && $row->getStatus() == ChargesServices::CHARGE_STATUS_NORMAL && (int) $row->getReservationNightlyId()) {
             if (($row->getAddons_type() == BookingAddon::ADDON_TYPE_ACC || $row->getAddons_type() == BookingAddon::ADDON_TYPE_ACC) && $row->getRateName()) {
                 $value = $row->getRateName();
             } elseif ($row->getAddons_value() > 0) {
                 $value = $row->getAddons_value();
                 if ($row->getTaxType() == TaxesServices::TAXES_TYPE_PERCENT) {
                     $value .= ' %';
                 } elseif ($row->getTaxType() == TaxesServices::TAXES_TYPE_PER_NIGHT) {
                     $value .= ' p/n';
                 } elseif ($row->getTaxType() == TaxesServices::TAXES_TYPE_PER_PERSON) {
                     $value .= ' p/p';
                 }
             }
             if (!isset($totalApartmentView[$row->getAddons_type()])) {
                 $totalApartmentView[$row->getAddons_type()] = ['name' => $row->getAddon(), 'dateMin' => $row->getReservationNightlyDate(), 'dateMax' => $row->getReservationNightlyDate(), 'value' => $value, 'price' => $row->getAcc_amount(), 'collection' => ChargesServices::$moneyDirectionOptions[$row->getMoneyDirection()], 'commission' => $row->getCommission()];
             } else {
                 $totalApartmentView[$row->getAddons_type()]['price'] += $row->getAcc_amount();
                 if ($totalApartmentView[$row->getAddons_type()]['dateMin'] > $row->getReservationNightlyDate()) {
                     $totalApartmentView[$row->getAddons_type()]['dateMin'] = $row->getReservationNightlyDate();
                 }
                 if ($totalApartmentView[$row->getAddons_type()]['dateMax'] < $row->getReservationNightlyDate()) {
                     $totalApartmentView[$row->getAddons_type()]['dateMax'] = $row->getReservationNightlyDate();
                 }
             }
         }
     }
     //creating an array where spot names are keys
     //and values are arrays with all dates
     //Example :
     //            [spot1] => Array
     //            (
     //                  [0] => 2015-07-22
     //                  [1] => 2015-07-23
     //                  [2] => 2015-07-25
     //                  [3] => 2015-07-26
     //                  [4] => 2015-07-27
     //                  [5] => 2015-07-28
     //                  [6] => 2015-07-29
     //                  [7] => 2015-07-30
     //                  [8] => 2015-07-31
     //                  [9] => 2015-08-01
     //            )
     //             [spot2] => Array
     //            (
     //                  [0] => 2015-07-22
     //                  [1] => 2015-07-23
     //                  [2] => 2015-07-24
     //                  [3] => 2015-08-01
     //            )
     $AllParkingSpotDatesArray = [];
     foreach ($dataOther['charged'] as $row) {
         if ($row->getAddons_type() == BookingAddon::ADDON_TYPE_PARKING && $row->getStatus() == ChargesServices::CHARGE_STATUS_NORMAL && (int) $row->getReservationNightlyId()) {
             if (!isset($AllParkingSpotDatesArray[$row->getRateName()])) {
                 $AllParkingSpotDatesArray[$row->getRateName()] = [];
             }
             array_push($AllParkingSpotDatesArray[$row->getRateName()], $row->getReservationNightlyDate());
         }
     }
     //sorting spot level arrays by date
     foreach ($AllParkingSpotDatesArray as &$singleSpotDatesForSort) {
         sort($singleSpotDatesForSort);
     }
     //creating an array where keys are spot names
     //and the values are array containing arrays of date ranges
     //Example:
     //    [spot1] => Array
     //    (
     //        [0] => Array
     //        (
     //            [0] => 2015-07-22
     //            [1] => 2015-07-23
     //         )
     //        [1] => Array
     //         (
     //            [0] => 2015-07-25
     //            [1] => 2015-07-26
     //            [2] => 2015-07-27
     //            [3] => 2015-07-28
     //            [4] => 2015-07-29
     //            [5] => 2015-07-30
     //            [6] => 2015-07-31
     //            [7] => 2015-08-01
     //          )
     //    )
     //    [spot2] => Array
     //    (
     //        [0] => Array
     //        (
     //            [0] => 2015-07-22
     //            [1] => 2015-07-23
     //            [2] => 2015-07-24
     //        )
     //        [1] => Array
     //        (
     //            [0] => 2015-08-01
     //        )
     //    )
     $allParkingSpotDatesArrayByDateRanges = [];
     $secondsInOneDay = 86400;
     foreach ($AllParkingSpotDatesArray as $rowKey => $singleSpotDates) {
         $i = 0;
         $k = 0;
         $allParkingSpotDatesArrayByDateRanges[$rowKey] = [];
         foreach ($singleSpotDates as $date) {
             if ($i == 0) {
                 $allParkingSpotDatesArrayByDateRanges[$rowKey][$k] = [$date];
             } else {
                 $differenceBetweenDatesInSeconds = strtotime($date) - strtotime($singleSpotDates[$i - 1]);
                 if ($differenceBetweenDatesInSeconds != $secondsInOneDay) {
                     $k++;
                 }
                 if (!isset($allParkingSpotDatesArrayByDateRanges[$rowKey][$k])) {
                     $allParkingSpotDatesArrayByDateRanges[$rowKey][$k] = [];
                 }
                 array_push($allParkingSpotDatesArrayByDateRanges[$rowKey][$k], $date);
             }
             $i++;
         }
     }
     $combinedArray = [];
     foreach ($allParkingSpotDatesArrayByDateRanges as $spotName => $parkingSpotDateRangeItem) {
         foreach ($parkingSpotDateRangeItem as $dateRanges) {
             array_push($combinedArray, ['spot' => $spotName, 'dateStart' => min($dateRanges), 'dateEnd' => max($dateRanges)]);
         }
     }
     foreach ($dataOther['charged'] as $row) {
         if ($row->getAddons_type() == BookingAddon::ADDON_TYPE_PARKING && $row->getStatus() == ChargesServices::CHARGE_STATUS_NORMAL && (int) $row->getReservationNightlyId()) {
             foreach ($combinedArray as &$item) {
                 if ($row->getRateName() == $item['spot'] && $row->getReservationNightlyDate() >= $item['dateStart'] && $row->getReservationNightlyDate() <= $item['dateEnd']) {
                     if (!isset($item['price'])) {
                         $item['price'] = 0;
                     }
                     $item['price'] += $row->getAcc_amount();
                     $item['collection'] = ChargesServices::$moneyDirectionOptions[$row->getMoneyDirection()];
                     $item['commission'] = $row->getCommission();
                     $item['value'] = $item['spot'];
                     $item['name'] = 'Parking';
                     break;
                 }
             }
         }
     }
     foreach ($combinedArray as &$it) {
         $it['date'] = date(Constants::GLOBAL_DATE_WO_YEAR, strtotime($it['dateStart'])) . ' - ' . date(Constants::GLOBAL_DATE_WO_YEAR, strtotime($it['dateEnd'] . ' + 1 day'));
     }
     $dataOther['totalChargeView'] = $totalApartmentView;
     array_push($dataOther['totalChargeView'], $combinedArray);
     $dataOther['totalChargeType'] = $totalChargeType;
     $dataOther['hasReversedCharges'] = $hasReversedCharges;
     $dataOther['penaltyPrice'] = 0;
     if (array_key_exists(0, $dataOther['totalChargeView']) && !$data->getCheckCharged()) {
         $refundLimitDay = $data->getRefundableBeforeHours() / 24;
         $currentCityDate = $cityService->getCurrentDateCity($data->getApartmentCityId());
         $accomodationPrice = $data->getBooker_price();
         $dataOther['penaltyPrice'] = number_format($accomodationPrice, 2, '.', '');
         if ((strtotime($data->getDate_from()) - strtotime(date('Y-m-d', strtotime($currentCityDate)))) / 86400 > $refundLimitDay) {
             $penaltyPercent = $data->getPenalty_val() * 0.01;
             $penaltyPrice = round($data->getBooker_price() * $penaltyPercent, 2);
             $dataOther['penaltyPrice'] = number_format($penaltyPrice, 2, '.', '');
         }
     }
     if (array_key_exists(BookingAddon::ADDON_TYPE_ACC, $dataOther['totalChargeView'])) {
         $accomodationPrice = number_format($dataOther['totalChargeView'][BookingAddon::ADDON_TYPE_ACC]['price'], 2, '.', '');
         $dataOther['penaltyPrice'] = $accomodationPrice;
         if ($data->getPenalty()) {
             $penaltyPrice = $accomodationPrice - $bookingChargeService->recalculatePenalty($reservationId, $accomodationPrice);
             $dataOther['penaltyPrice'] = number_format($penaltyPrice, 2, '.', '');
             $refundLimitDay = $data->getRefundableBeforeHours() / 24;
             $currentCityDate = $cityService->getCurrentDateCity($data->getApartmentCityId());
             if ((strtotime($data->getDate_from()) - strtotime(date('Y-m-d', strtotime($currentCityDate)))) / 86400 < $refundLimitDay) {
                 $dataOther['penaltyPrice'] = $accomodationPrice;
             }
         }
     }
     $bankTransactionList = [];
     $listTransactionType = [BankTransaction::BANK_TRANSACTION_TYPE_VALIDATION => Objects::getChargeType()[BankTransaction::BANK_TRANSACTION_TYPE_VALIDATION], BankTransaction::BANK_TRANSACTION_TYPE_CASH => Objects::getChargeType()[BankTransaction::BANK_TRANSACTION_TYPE_CASH], BankTransaction::BANK_TRANSACTION_TYPE_BANK_DEPOSIT => Objects::getChargeType()[BankTransaction::BANK_TRANSACTION_TYPE_BANK_DEPOSIT], BankTransaction::BANK_TRANSACTION_TYPE_DEDUCTED_SALARY => Objects::getChargeType()[BankTransaction::BANK_TRANSACTION_TYPE_DEDUCTED_SALARY]];
     // collect from card
     if ($dataOther['hasValidCard']) {
         $listTransactionType[BankTransaction::BANK_TRANSACTION_TYPE_COLLECT] = Objects::getChargeType()[BankTransaction::BANK_TRANSACTION_TYPE_COLLECT];
     }
     if ($dataOther['transactions']) {
         foreach ($dataOther['transactions'] as $bank) {
             if (in_array($bank->getStatus(), [BankTransaction::BANK_TRANSACTION_STATUS_APPROVED, BankTransaction::BANK_TRANSACTION_STATUS_PENDING])) {
                 $listTransactionType[BankTransaction::BANK_TRANSACTION_TYPE_CASH_REFUND] = Objects::getChargeType()[BankTransaction::BANK_TRANSACTION_TYPE_CASH_REFUND];
                 if ($bank->getType() == BankTransaction::BANK_TRANSACTION_TYPE_COLLECT) {
                     $listTransactionType[BankTransaction::BANK_TRANSACTION_TYPE_REFUND] = Objects::getChargeType()[BankTransaction::BANK_TRANSACTION_TYPE_REFUND];
                     $listTransactionType[BankTransaction::BANK_TRANSACTION_TYPE_CHARGEBACK_FRAUD] = Objects::getChargeType()[BankTransaction::BANK_TRANSACTION_TYPE_CHARGEBACK_FRAUD];
                     $listTransactionType[BankTransaction::BANK_TRANSACTION_TYPE_CHARGEBACK_OTHER] = Objects::getChargeType()[BankTransaction::BANK_TRANSACTION_TYPE_CHARGEBACK_OTHER];
                     $listTransactionType[BankTransaction::BANK_TRANSACTION_TYPE_CHARGEBACK_DISPUTE] = Objects::getChargeType()[BankTransaction::BANK_TRANSACTION_TYPE_CHARGEBACK_DISPUTE];
                 }
             }
             if ($bank->getMoneyAccountId() > 0 && in_array($bank->getStatus(), [BankTransaction::BANK_TRANSACTION_STATUS_APPROVED, BankTransaction::BANK_TRANSACTION_STATUS_PENDING])) {
                 $bankTransactionList[$bank->getMoneyAccountId()] = ['money_account_name' => $bank->getBank(), 'money_account_currency' => $bank->getMoneyAccountCurrency()];
             }
         }
     }
     asort($listTransactionType);
     $dataOther['listTransactionType'] = $listTransactionType;
     $dataOther['bank_transaction_list'] = $bankTransactionList;
     // partner commission for charge
     $dataOther['partner_commission_charge'] = $partnerSpecificService->getPartnerDeductedCommission($data->getPartnerId(), $data->getPartnerCommission());
     // get apartel reservations bulk if needed
     if ($data->getApartelId() && $data->getChannelResId()) {
         /** @var \DDD\Dao\ChannelManager\ReservationIdentificator $reservationIdentificatorDao */
         $reservationIdentificatorDao = $this->getServiceLocator()->get('dao_channel_manager_reservation_identificator');
         $apartelReservationsBulk = $reservationIdentificatorDao->getReservationsIdentificatorDataByChannelResId($data->getChannelResId(), $data->getId());
         if ($apartelReservationsBulk->count()) {
             $dataOther['apartel_reservations_bulk'] = $apartelReservationsBulk;
         }
     }
     return ['data' => $data, 'otherData' => $dataOther, 'creditCards' => $creditCardsMerge['card_list'], 'nightsData' => $nightsParse, 'ratesByDate' => $ratesPriceByDateParse];
 }
Beispiel #2
0
 /**
  * @param BookingTicket|bool $data
  * @param array $options
  */
 public function __construct($data, $options)
 {
     parent::__construct('booking-form');
     $this->setAttributes(array('action' => 'booking/edit', 'method' => 'post', 'class' => 'form-horizontal', 'id' => 'booking-form'));
     $this->setName('booking-form');
     /**
      * @todo use constants
      */
     $current_finance_booked_state = $data->getArrivalStatus() == 3 ? 2 : $data->getArrivalStatus();
     $this->add(array('name' => 'ginosi_collect_debt_customer_currency', 'attributes' => array('type' => 'hidden', 'id' => 'ginosi_collect_debt_customer_currency')));
     $this->add(array('name' => 'ginosi_collect_debt_apartment_currency', 'attributes' => array('type' => 'hidden', 'id' => 'ginosi_collect_debt_apartment_currency')));
     $this->add(array('name' => 'partner_collect_debt_customer_currency', 'attributes' => array('type' => 'hidden', 'id' => 'partner_collect_debt_customer_currency')));
     $this->add(array('name' => 'partner_collect_debt_apartment_currency', 'attributes' => array('type' => 'hidden', 'id' => 'partner_collect_debt_apartment_currency')));
     $this->add(array('name' => 'guest_name', 'options' => array('label' => ''), 'attributes' => array('type' => 'text', 'class' => 'form-control', 'id' => 'guest_name', 'maxlength' => 150)));
     $this->add(array('name' => 'guest_last_name', 'options' => array('label' => ''), 'attributes' => array('type' => 'text', 'class' => 'form-control', 'id' => 'guest_lastname', 'maxlength' => 150)));
     $this->add(array('name' => 'guest_email', 'options' => array('label' => ''), 'attributes' => array('type' => 'Zend\\Form\\Element\\Email', 'class' => 'form-control', 'id' => 'guest_email', 'maxlength' => 255)));
     $this->add(array('name' => 'second_guest_email', 'options' => array('label' => ''), 'attributes' => array('type' => 'Zend\\Form\\Element\\Email', 'class' => 'form-control', 'id' => 'second_guest_email', 'maxlength' => 255)));
     $this->add(array('name' => 'selected-email', 'attributes' => array('type' => 'hidden', 'id' => 'selected-email', 'value' => $data->getGuestEmail())));
     $countries = array();
     foreach ($options['countries'] as $row) {
         $countries[0] = 'Undetected Country';
         $countries[$row->getId()] = $row->getName();
     }
     $this->add(array('name' => 'guest_country', 'options' => array('label' => '', 'value_options' => $countries), 'type' => 'Zend\\Form\\Element\\Select', 'attributes' => array('id' => 'guest_country', 'class' => 'form-control')));
     $this->add(array('name' => 'guest_city', 'options' => array('label' => ''), 'attributes' => array('type' => 'text', 'class' => 'form-control', 'id' => 'guest_city', 'maxlength' => 150)));
     $this->add(array('name' => 'guest_address', 'options' => array('label' => ''), 'attributes' => array('type' => 'text', 'class' => 'form-control', 'id' => 'guest_address', 'maxlength' => 150)));
     $this->add(array('name' => 'guest_zipcode', 'options' => array('label' => ''), 'attributes' => array('type' => 'text', 'class' => 'form-control', 'id' => 'guest_zipcode', 'maxlength' => 50)));
     $this->add(array('name' => 'guest_phone', 'options' => array('label' => ''), 'attributes' => array('type' => 'text', 'class' => 'form-control', 'id' => 'guest_phone', 'maxlength' => 50)));
     $this->add(array('name' => 'guest_travel_phone', 'options' => array('label' => ''), 'attributes' => array('type' => 'text', 'class' => 'form-control', 'id' => 'guest_travel_phone', 'maxlength' => 50)));
     $partners = array();
     foreach ($options['partners'] as $row) {
         $partners[$row->getGid()] = $row->getPartnerName();
     }
     $this->add(array('name' => 'booking_partners', 'options' => array('label' => '', 'value_options' => $partners), 'type' => 'Zend\\Form\\Element\\Select', 'attributes' => array('id' => 'booking_partners', 'class' => 'form-control')));
     $this->add(array('name' => 'booking_affiliate_reference', 'options' => array('label' => ''), 'attributes' => array('type' => 'text', 'class' => 'form-control', 'id' => 'booking_affiliate_reference', 'maxlength' => 150)));
     $this->add(array('name' => 'overbooking_status', 'options' => array('label' => '', 'value_options' => ReservationTicketService::$overbookingOptions), 'type' => 'Zend\\Form\\Element\\Select', 'attributes' => array('id' => 'overbooking_status', 'class' => 'form-control')));
     $apartels = ['-1' => 'Unknown', '0' => ' Non Apartel'];
     foreach ($options['apartels'] as $row) {
         $apartels[$row->getId()] = $row->getName();
     }
     $this->add(['name' => 'apartel_id', 'options' => ['label' => 'Apartel', 'value_options' => $apartels], 'type' => 'Zend\\Form\\Element\\Select', 'attributes' => ['id' => 'apartel_id', 'class' => 'form-control']]);
     $occupancy = array_combine(range(1, $data->getApartmentCapacity()), range(1, $data->getApartmentCapacity()));
     if ($data->getOccupancy() > $data->getApartmentCapacity()) {
         $occupancy[$data->getOccupancy()] = $data->getOccupancy();
     }
     $this->add(['name' => 'occupancy', 'options' => ['label' => 'Occupancy', 'value_options' => $occupancy], 'type' => 'Zend\\Form\\Element\\Select', 'attributes' => ['id' => 'occupancy', 'class' => 'form-control']]);
     $this->add(array('name' => 'booking_arrival_time', 'type' => 'Zend\\Form\\Element\\Text', 'attributes' => array('id' => 'booking_arrival_time', 'class' => 'form-control')));
     /** @var Statuses|bool $row */
     $statuses = array();
     foreach ($options['statuses'] as $row) {
         // "Canceled Unknown" status can be shown only if ticket status set "Unknown"
         if ($data->getStatus() != \DDD\Service\Booking::BOOKING_STATUS_CANCELLED_PENDING) {
             if ($row->getId() == \DDD\Service\Booking::BOOKING_STATUS_CANCELLED_PENDING) {
                 continue;
             }
         }
         $statuses[$row->getId()] = $row->getName();
     }
     $this->add(array('name' => 'booking_statuses', 'options' => array('label' => '', 'value_options' => $statuses), 'type' => 'Zend\\Form\\Element\\Select', 'attributes' => array('id' => 'booking_statuses', 'value' => 1, 'class' => 'form-control')));
     $this->add(array('name' => 'charge_comment', 'options' => array('label' => ''), 'attributes' => array('type' => 'textarea', 'class' => 'span5', 'rows' => '4', 'id' => 'charge_comment')));
     $this->add(array('name' => 'booking_id', 'attributes' => array('type' => 'hidden', 'id' => 'booking_id')));
     $this->add(array('name' => 'booking_res_number', 'attributes' => array('type' => 'hidden', 'id' => 'booking_res_number')));
     $this->add(array('name' => 'finance_valid_card', 'type' => 'Zend\\Form\\Element\\Select', 'options' => array('label' => '', 'value_options' => Objects::getCreditCardStatuses()), 'attributes' => array('id' => 'finance_valid_card', 'class' => 'form-control', 'value' => $data->getFunds_confirmed(), 'disabled' => isset($options['hasCreditCardViewer']) ? false : true)));
     $key_instructions = array('id' => 'finance_key_instructions', 'use_hidden_element' => false, 'checked_value' => 1, 'unchecked_value' => 0, 'class' => 'margin-top-10');
     if ($data->isKiViewed() == 1) {
         $key_instructions['checked'] = 'checked';
     }
     $this->add(array('name' => 'finance_key_instructions', 'options' => array('label' => ''), 'type' => 'Zend\\Form\\Element\\Checkbox', 'attributes' => $key_instructions));
     $reservation_settled = array('id' => 'finance_reservation_settled', 'use_hidden_element' => false, 'checked_value' => 1, 'unchecked_value' => 0, 'class' => 'margin-top-10');
     if ($data->getPayment_settled() == 1) {
         $reservation_settled['checked'] = 'checked';
     }
     if (!$options['hasFinanceRole']) {
         $reservation_settled['disabled'] = true;
     }
     $this->add(array('name' => 'finance_reservation_settled', 'options' => array('label' => ''), 'type' => 'Zend\\Form\\Element\\Checkbox', 'attributes' => $reservation_settled));
     $cccAVerified = array('id' => 'ccca_verified', 'use_hidden_element' => false, 'checked_value' => 1, 'unchecked_value' => 0, 'class' => 'margin-top-10');
     if ($data->getCccaVerified() == 1) {
         $cccAVerified['checked'] = 'checked';
     }
     $this->add(array('name' => 'ccca_verified', 'options' => array('label' => ''), 'type' => 'Zend\\Form\\Element\\Checkbox', 'attributes' => $cccAVerified));
     $paid_affiliate = array('id' => 'finance_paid_affiliate', 'use_hidden_element' => false, 'checked_value' => 1, 'unchecked_value' => 0, 'class' => 'margin-top-10');
     if ($data->getPartnerId() == 1) {
         $paid_affiliate['disabled'] = 'disabled';
     } elseif ($data->getPartnerSettled() == 1) {
         $paid_affiliate['checked'] = 'checked';
     }
     $this->add(array('name' => 'finance_paid_affiliate', 'options' => array('label' => ''), 'type' => 'Zend\\Form\\Element\\Checkbox', 'attributes' => $paid_affiliate));
     /**
      *
      */
     $this->add(array('name' => 'partner_paid_expense_id', 'options' => array('label' => ''), 'attributes' => array('type' => 'text', 'class' => 'form-control width-100 margin-left-5', 'id' => 'partner_paid_expense_id', 'placeholder' => 'Expense ID')));
     $no_collection = array('id' => 'finance_no_collection', 'use_hidden_element' => false, 'checked_value' => 1, 'unchecked_value' => 0, 'class' => 'margin-top-10');
     if ($data->getNo_collection() == 1) {
         $no_collection['checked'] = 'checked';
     }
     $this->add(array('name' => 'finance_no_collection', 'options' => array('label' => ''), 'type' => 'Zend\\Form\\Element\\Checkbox', 'attributes' => $no_collection));
     $this->add(array('name' => 'finance_booked_state', 'options' => array('label' => '', 'value_options' => ReservationTicketService::$arrivalStatuses), 'type' => 'Zend\\Form\\Element\\Select', 'attributes' => array('id' => 'finance_booked_state', 'class' => 'form-control')));
     $this->add(array('name' => 'finance_booked_state_changed', 'attributes' => array('id' => 'finance_booked_state_changed', 'data-current' => $current_finance_booked_state, 'value' => 0, 'type' => 'hidden')));
     $this->add(array('name' => 'acc_currency_rate', 'attributes' => array('type' => 'hidden', 'id' => 'acc_currency_rate')));
     $this->add(array('name' => 'acc_currency_sign', 'attributes' => array('type' => 'hidden', 'id' => 'acc_currency_sign')));
     $this->add(array('name' => 'customer_currency_rate', 'attributes' => array('type' => 'hidden', 'id' => 'customer_currency_rate')));
     $this->add(array('name' => 'booking_ginosi_comment', 'options' => array('label' => ''), 'attributes' => array('type' => 'textarea', 'class' => 'form-control', 'rows' => '3', 'id' => 'booking_ginosi_comment', 'placeholder' => 'Write comments here')));
     $teams = [0 => '-- Select Team --'];
     foreach ($options['teams'] as $row) {
         $teams[$row->getId()] = $row->getName();
     }
     $this->add(['name' => 'booking_ginosi_comment_team', 'options' => ['label' => '', 'value_options' => $teams], 'type' => 'Zend\\Form\\Element\\Select', 'attributes' => ['id' => 'booking_ginosi_comment_team', 'class' => 'form-control']]);
     $this->add(['name' => 'booking_ginosi_comment_frontier', 'type' => 'Zend\\Form\\Element\\Checkbox', 'attributes' => ['id' => 'booking_ginosi_comment_frontier']]);
     $this->add(array('name' => 'housekeeping_comment', 'options' => array('label' => ''), 'attributes' => array('type' => 'textarea', 'class' => 'form-control', 'placeholder' => 'Write housekeeping comments here', 'rows' => '3', 'id' => 'housekeeping_comment')));
     $this->add(array('name' => 'booking_ginosi_comment_view', 'options' => array('label' => ''), 'attributes' => array('type' => 'textarea', 'class' => 'span10', 'rows' => '7', 'readonly' => 'readonly', 'id' => 'booking_ginosi_comment_view')));
     $this->add(array('name' => 'housekeeping_comment_view', 'options' => array('label' => ''), 'attributes' => array('type' => 'textarea', 'style' => 'width: 535px;', 'rows' => '7', 'readonly' => 'readonly')));
     $this->add(array('name' => 'model', 'options' => array('label' => '', 'value_options' => $this->getModel($options['partner_data'])), 'type' => 'Zend\\Form\\Element\\Select', 'attributes' => array('id' => 'model', 'class' => 'form-control')));
     $this->add(array('name' => 'res-dates', 'attributes' => array('type' => 'text', 'class' => 'form-control', 'id' => 'res-dates')));
     if (is_object($data)) {
         $objectData = new \ArrayObject();
         $objectData['guest_name'] = $data->getGuestFirstName();
         $objectData['guest_last_name'] = $data->getGuestLastName();
         $objectData['guest_email'] = $data->getGuestEmail();
         $objectData['second_guest_email'] = $data->getSecondaryEmail();
         $objectData['guest_country'] = $data->getGuestCountryId();
         $objectData['guest_city'] = $data->getGuestCityName();
         $objectData['guest_address'] = $data->getGuestAddress();
         $objectData['guest_zipcode'] = $data->getGuestZipCode();
         $objectData['guest_phone'] = $data->getGuestPhone();
         $objectData['booking_partners'] = $data->getPartnerId();
         $objectData['booking_affiliate_reference'] = $data->getPartnerRef();
         $objectData['booking_id'] = $data->getId();
         $objectData['booking_res_number'] = $data->getResNumber();
         $objectData['finance_booked_state'] = $data->getArrivalStatus() == 3 ? 2 : $data->getArrivalStatus();
         $objectData['acc_currency_rate'] = $data->getAcc_currency_rate();
         $objectData['acc_currency_sign'] = $data->getAcc_currency_sign();
         $objectData['customer_currency_rate'] = $data->getCurrency_rate();
         $objectData['model'] = $data->getModel();
         $objectData['guest_travel_phone'] = $data->getGuestTravelPhone();
         $objectData['booking_statuses'] = $data->getStatus();
         $objectData['overbooking_status'] = (int) $data->getOverbookingStatus();
         $objectData['apartel_id'] = $data->getApartelId();
         $objectData['occupancy'] = $data->getOccupancy();
         if (is_null($data->getGuestArrivalTime())) {
             $objectData['booking_arrival_time'] = date('H:i', strtotime($options['apartment']['check_in']));
         } else {
             $objectData['booking_arrival_time'] = date('H:i', strtotime($data->getGuestArrivalTime()));
         }
         $this->bind($objectData);
     }
 }