/** * @param \DDD\Domain\Booking\ChargeProcess $reservation * @param bool|false $isBookerPrice * @return array * */ public function getToBeChargedItems($reservation, $isBookerPrice = false) { /** * @var $bookingTicketService \DDD\Service\Booking\BookingTicket * @var ApartmentMainService $apartmentMainService * @var \DDD\Service\Textline $textlineService */ $bookingTicketService = $this->getServiceLocator()->get('service_booking_booking_ticket'); $textlineService = $this->getServiceLocator()->get('service_textline'); $discountParams = []; if ($reservation->getPartnerId()) { $discountParams = ['aff_id' => $reservation->getPartnerId(), 'email' => $reservation->getGuestEmail()]; } if ($isBookerPrice) { $totalPrice = $reservation->getBookerPrice(); $price = $reservation->getBookerPrice(); } else { $totalPrice = $reservation->getPrice(); $price = $reservation->getPrice(); } $nightCount = Helper::getDaysFromTwoDate($reservation->getDateTo(), $reservation->getDateFrom()); $currencySymbol = $reservation->getCurrencySymbol(); // Night Charges $chargesList = [['label' => Helper::evaluateTextline($textlineService->getUniversalTextline(1580), ['{{NIGHT_COUNT}}' => $nightCount]), 'price_view' => $currencySymbol . number_format($totalPrice, 2, '.', ' '), 'price' => $totalPrice, 'percent' => 0, 'type' => 'night', 'class' => '', 'description' => '', 'tax_included' => '']]; // Discount Charges $discountValidator = $bookingTicketService->validateAndCheckDiscountData($discountParams, false); $discounted = false; if (isset($discountValidator['discount_value']) && $discountValidator['valid'] && isset($discountValidator['discount_value']) && ceil($discountValidator['discount_value'])) { $discountValue = $totalPrice * $discountValidator['discount_value'] / 100; $price = $totalPrice - $discountValue; $discounted = true; $totalPrice = $totalPrice - $discountValue; array_push($chargesList, ['label' => (isset($discountValidator['partner_name']) ? $discountValidator['partner_name'] : '') . ' ' . $textlineService->getUniversalTextline(1503), 'price_view' => '- ' . $currencySymbol . number_format($discountValue, 2, '.', ' '), 'price' => $discountValue, 'percent' => 0, 'type' => 'discount', 'class' => 'text-danger', 'description' => '', 'tax_included' => '']); } // Taxes Charges /** @var \DDD\Service\Currency\Currency $currencyService */ $currencyService = $this->getServiceLocator()->get('service_currency_currency'); $currencyRate = 1; if ($reservation->getGuestCurrency() != $reservation->getApartmentCurrency()) { $currencyRate = $currencyService->getCurrencyConversionRate($reservation->getGuestCurrency(), $reservation->getApartmentCurrency()); } if ($reservation->getCityTotType() > 0 && $reservation->getCityTot() > 0) { $taxDiscounted = false; $totDuration = $reservation->getTotMaxDuration() ? min($reservation->getTotMaxDuration(), $nightCount) : $nightCount; $totValue = $reservation->getCityTot() + $reservation->getTotAdditional(); if ($reservation->getCityTotType() == Taxes::TAXES_TYPE_PERCENT) { $cityTot = $price / 100 * $totValue * $totDuration / $nightCount; $taxValue = $totValue . ' %'; if ($discounted) { $taxDiscounted = true; } $percent = $totValue; } else { $cityTot = $totDuration * $totValue * $currencyRate; $taxValue = $currencySymbol . ' ' . number_format($totValue * $currencyRate, 2, '.', ' ') . ' ' . $textlineService->getUniversalTextline(1473); $percent = 0; } array_push($chargesList, ['label' => $textlineService->getUniversalTextline(1259) . ' (' . $taxValue . ($reservation->getTotIncluded() == 1 ? ', ' . $textlineService->getUniversalTextline(1472) : '') . ') ' . ($taxDiscounted ? $textlineService->getUniversalTextline(1633) : ''), 'price_view' => $currencySymbol . number_format($cityTot, 2, '.', ' '), 'price' => $cityTot, 'percent' => $percent, 'duration' => $totDuration, 'type' => 'tax', 'class' => 'text-primary', 'description' => $textlineService->getUniversalTextline(1429), 'tax_included' => $reservation->getTotIncluded() == 1 ?: '', 'date' => $reservation->getDateFrom(), 'type_id' => BookingAddon::ADDON_TYPE_TAX_TOT]); if ($reservation->getTotIncluded() != 1) { $totalPrice += $cityTot; } } if ($reservation->getCityVatType() > 0 && $reservation->getCityVat() > 0) { $taxDiscounted = false; $vatDuration = $reservation->getVatMaxDuration() ? min($reservation->getVatMaxDuration(), $nightCount) : $nightCount; $vatValue = $reservation->getCityVat() + $reservation->getVatAdditional(); if ($reservation->getCityVatType() == Taxes::TAXES_TYPE_PERCENT) { $cityVat = $price / 100 * $vatValue * $vatDuration / $nightCount; $taxValue = $vatValue . ' %'; if ($discounted) { $taxDiscounted = true; } $percent = $vatValue; } else { $cityVat = $vatDuration * $vatValue * $currencyRate; $taxValue = $currencySymbol . number_format($vatValue * $currencyRate, 2, '.', ' ') . ' ' . $textlineService->getUniversalTextline(1473); $percent = 0; } array_push($chargesList, ['label' => $textlineService->getUniversalTextline(1260) . ' (' . $taxValue . ($reservation->getVatIncluded() == 1 ? ', ' . $textlineService->getUniversalTextline(1472) : '') . ') ' . ($taxDiscounted ? $textlineService->getUniversalTextline(1633) : ''), 'price_view' => $currencySymbol . number_format($cityVat, 2, '.', ' '), 'price' => $cityVat, 'percent' => $percent, 'duration' => $vatDuration, 'type' => 'tax', 'class' => 'text-primary', 'description' => $textlineService->getUniversalTextline(1430), 'tax_included' => $reservation->getVatIncluded() == 1 ?: '', 'date' => $reservation->getDateFrom(), 'type_id' => BookingAddon::ADDON_TYPE_TAX_VAT]); if ($reservation->getVatIncluded() != 1) { $totalPrice += $cityVat; } } if ($reservation->getCitySalesTaxType() > 0 && $reservation->getCitySalesTax() > 0) { $taxDiscounted = false; $salesTaxDuration = $reservation->getSalesTaxMaxDuration() ? min($reservation->getSalesTaxMaxDuration(), $nightCount) : $nightCount; $salesTaxValue = $reservation->getCitySalesTax() + $reservation->getSalesTaxAdditional(); if ($reservation->getCitySalesTaxType() == Taxes::TAXES_TYPE_PERCENT) { $citySalesTax = $price / 100 * $salesTaxValue * $salesTaxDuration / $nightCount; $taxValue = $salesTaxValue . ' %'; if ($discounted) { $taxDiscounted = true; } $percent = $salesTaxValue; } else { $citySalesTax = $salesTaxDuration * $salesTaxValue * $currencyRate; $taxValue = $currencySymbol . ' ' . number_format($salesTaxValue * $currencyRate, 2, '.', ' ') . ' ' . $textlineService->getUniversalTextline(1473); $percent = 0; } array_push($chargesList, ['label' => $textlineService->getUniversalTextline(1261) . ' (' . $taxValue . ($reservation->getSalesTaxIncluded() == 1 ? ', ' . $textlineService->getUniversalTextline(1472) : '') . ') ' . ($taxDiscounted ? $textlineService->getUniversalTextline(1633) : ''), 'price_view' => $currencySymbol . number_format($citySalesTax, 2, '.', ' '), 'price' => $citySalesTax, 'percent' => $percent, 'duration' => $salesTaxDuration, 'type' => 'tax', 'class' => 'text-primary', 'description' => $textlineService->getUniversalTextline(1431), 'tax_included' => $reservation->getSalesTaxIncluded() == 1 ?: '', 'date' => $reservation->getDateFrom(), 'type_id' => BookingAddon::ADDON_TYPE_SALES_TAX]); if ($reservation->getSalesTaxIncluded() != 1) { $totalPrice += $citySalesTax; } } if ($reservation->getCityTaxType() > 0 && $reservation->getCityTax() > 0) { $cityTaxDuration = $reservation->getCityTaxMaxDuration() ? min($reservation->getCityTaxMaxDuration(), $nightCount) : $nightCount; $cityTaxValue = $reservation->getCityTax() + $reservation->getCityTaxAdditional(); $taxDiscounted = false; if ($reservation->getCityTaxType() == Taxes::TAXES_TYPE_PERCENT) { $cityTax = $price / 100 * $cityTaxValue * $cityTaxDuration / $nightCount; $taxValue = $cityTaxValue . ' %'; if ($discounted) { $taxDiscounted = true; } $percent = $cityTaxValue; } elseif ($reservation->getCityTaxType() == Taxes::TAXES_TYPE_PER_PERSON) { $cityTax = $cityTaxDuration * $cityTaxValue * $currencyRate * $reservation->getOccupancy(); $taxValue = $currencySymbol . ' ' . number_format($cityTaxValue * $currencyRate, 2, '.', ' ') . ' ' . $textlineService->getUniversalTextline(1493); $percent = 0; // Per person per night } else { $cityTax = $cityTaxDuration * $cityTaxValue * $currencyRate; $taxValue = $currencySymbol . ' ' . number_format($cityTaxValue * $currencyRate, 2, '.', ' ') . ' ' . $textlineService->getUniversalTextline(1473); $percent = 0; } array_push($chargesList, ['label' => $textlineService->getUniversalTextline(1262) . ' (' . $taxValue . ($reservation->getCityTaxIncluded() == 1 ? ', ' . $textlineService->getUniversalTextline(1472) : '') . ') ' . ($taxDiscounted ? $textlineService->getUniversalTextline(1633) : ''), 'price_view' => $currencySymbol . number_format($cityTax, 2, '.', ' '), 'price' => $cityTax, 'percent' => $percent, 'duration' => $cityTaxDuration, 'type' => 'tax', 'class' => 'text-primary', 'description' => $textlineService->getUniversalTextline(1432), 'tax_included' => $reservation->getCityTaxIncluded() == 1 ?: '', 'date' => $reservation->getDateFrom(), 'type_id' => BookingAddon::ADDON_TYPE_CITY_TAX]); if ($reservation->getCityTaxIncluded() != 1) { $totalPrice += $cityTax; } } // parking taxes $parkingNights = $this->getParkingNightsFromRemarks($reservation->getRemarks()); if ($parkingNights) { // get apartment dao`s $apartmentDao = $this->getServiceLocator()->get('dao_accommodation_accommodations'); $apartmentSpotsDao = $this->getServiceLocator()->get('dao_apartment_spots'); $reservationNightlyDao = $this->getServiceLocator()->get('dao_booking_reservation_nightly'); $resStartDate = $reservation->getDateFrom(); $resEndDate = $reservation->getDateTo(); $date1 = date_create($resStartDate); $date2 = date_create($resEndDate); $dateDiff = date_diff($date2, $date1)->d + 1; $nightData = $reservationNightlyDao->fetchAll(['reservation_id' => $reservation->getId()], ['id', 'price', 'date', 'rate_name']); $nightlyArr = []; foreach ($nightData as $night) { array_push($nightlyArr, $night); } /** * @var \DDD\Dao\Parking\Spot\Inventory $parkingInventoryDao */ $parkingStart = $reservation->getDateFrom(); $parkingEnd = date('Y-m-j', strtotime($reservation->getDateFrom() . '+' . $parkingNights . ' days')); $newApartmentPreferedSpotId = $availableSpot = $selectedSpot = []; $apartmentPreferSpots = $apartmentSpotsDao->getApartmentSpots($reservation->getApartmentIdAssigned()); if ($apartmentPreferSpots->count()) { foreach ($apartmentPreferSpots as $apartmentPreferSpot) { array_push($newApartmentPreferedSpotId, $apartmentPreferSpot['spot_id']); } $reservationApartmentId = $reservation->getApartmentIdAssigned(); $apartmentService = $this->getServiceLocator()->get('service_apartment_general'); $apartmentTimezone = $apartmentService->getApartmentTimezoneById($reservationApartmentId)['timezone']; $datetime = new \DateTime('now'); $datetime->setTimezone(new \DateTimeZone($apartmentTimezone)); $dateToday = $datetime->format('Y-m-d'); $availableSpot = $apartmentDao->getAvailableSpotsInLotForApartmentForDateRangeByPriority($reservationApartmentId, $parkingStart, $parkingEnd, [], false, [], $dateToday, true, $newApartmentPreferedSpotId); if (count($availableSpot)) { foreach ($availableSpot as $row) { $selectedSpot = $row; } } } $parkingTotal = 0; if ($dateDiff >= $parkingNights && count($availableSpot) && count($selectedSpot)) { for ($iterator = 0; $iterator < $parkingNights; $iterator++) { $parkingTotal += $selectedSpot['price']; } } if ($parkingTotal > 0) { $parkingTotal = $currencyRate * $parkingTotal; $totalPrice += $parkingTotal; array_push($chargesList, ['label' => 'Parking', 'price_view' => $currencySymbol . number_format($parkingTotal, 2, '.', ' '), 'price' => $parkingTotal, 'percent' => 0, 'type' => 'tax', 'class' => 'text-primary', 'description' => $textlineService->getUniversalTextline(1430), 'tax_included' => $reservation->getVatIncluded() == 1 ?: '']); } } // Cleaning Fee $apartmentMainService = $this->getServiceLocator()->get('service_apartment_main'); $cleaningFee = $apartmentMainService->getApartmentCleaningFeeInGuestCurrency($reservation->getApartmentId(), $reservation->getApartmentCurrency(), $reservation->getGuestCurrency(), $reservation->getCheckCurrency()); if ($cleaningFee) { $cleaningFee = $cleaningFee * $currencyRate; $totalPrice += $cleaningFee; array_push($chargesList, ['label' => $textlineService->getUniversalTextline(1497), 'price_view' => $currencySymbol . number_format($cleaningFee, 2, '.', ' '), 'price' => $cleaningFee, 'percent' => 0, 'type' => 'fee', 'class' => 'text-primary', 'description' => $textlineService->getUniversalTextline(1498), 'tax_included' => '']); } // Total array_push($chargesList, ['label' => $textlineService->getUniversalTextline(1305), 'price_view' => $currencySymbol . number_format($totalPrice, 2, '.', ' '), 'price' => $totalPrice, 'percent' => 0, 'type' => 'total', 'class' => '', 'description' => '', 'tax_included' => '']); return $chargesList; }
/** * @param $data * @param $occupancy * @return ChargeProcess */ private function getPaymentsData($data, $occupancy) { $charge = new ChargeProcess(); $charge->setPrice($data['amount_price']); $visitor = new Container('visitor'); if (!is_null($visitor->partnerId) && (int) $visitor->partnerId) { $partnerId = (int) $visitor->partnerId; $charge->setPartnerId($partnerId); } $charge->setDateTo($data['date_to']); $charge->setDateFrom($data['date_from']); $charge->setGuestCurrency($data['user_currency']); $charge->setCountryCurrency($data['country_currency']); if (isset($data['tot_type']) && $data['tot_type'] > 0 && $data['tot'] > 0) { $charge->setCityTot($data['tot'] + $data['tot_additional']); $charge->setCityTotType($data['tot_type']); $charge->setTotIncluded($data['tot_included']); $charge->setTotMaxDuration($data['tot_max_duration']); } if (isset($data['vat_type']) && $data['vat_type'] > 0 && $data['vat'] > 0) { $charge->setCityVat($data['vat'] + $data['vat_additional']); $charge->setCityVatType($data['vat_type']); $charge->setVatIncluded($data['vat_included']); $charge->setVatMaxDuration($data['vat_max_duration']); } if (isset($data['sales_tax_type']) && $data['sales_tax_type'] > 0 && $data['sales_tax'] > 0) { $charge->setCitySalesTax($data['sales_tax'] + $data['sales_tax_additional']); $charge->setCitySalesTaxType($data['sales_tax_type']); $charge->setSalesTaxIncluded($data['sales_tax_included']); $charge->setSalesTaxMaxDuration($data['sales_tax_max_duration']); } if (isset($data['city_tax_type']) && $data['city_tax_type'] > 0 && $data['city_tax'] > 0) { $charge->setCityTax($data['city_tax'] + $data['city_tax_additional']); $charge->setCityTaxType($data['city_tax_type']); $charge->setCityTaxIncluded($data['city_tax_included']); $charge->setCityTaxMaxDuration($data['city_tax_max_duration']); } $charge->setOccupancy($occupancy); $charge->setApartmentId($data['apartment_id']); $charge->setApartmentCurrency($data['acc_currency']); $charge->setCurrencySymbol($data['symbol']); $charge->setCheckCurrency(true); /** @var \DDD\Service\Booking\Charge $chargeService */ $chargeService = $this->getServiceLocator()->get('service_booking_charge'); return $chargeService->getToBeChargedItems($charge); }