Beispiel #1
0
 /**
  * @param array $expenseData
  * @param float $newTransactionAmount
  * @return array
  */
 private function getExpenseTicketData($expenseData, $newTransactionAmount)
 {
     $currencyUtility = new Currency($this->getServiceLocator()->get('dao_currency_currency'));
     $newTransactionCurrencyId = $this->getAccountFrom()->getCurrency();
     if ($newTransactionCurrencyId != $expenseData['currency_id']) {
         $newTransactionAmount = $currencyUtility->convert($newTransactionAmount, (int) $newTransactionCurrencyId, (int) $expenseData['currency_id']);
     }
     return ['isChanged' => false, 'currencyId' => $expenseData['currency_id'], 'managerId' => $expenseData['manager_id'], 'purpose' => $expenseData['purpose'], 'expectedCompletionDate' => date('Y-m-d', strtotime($expenseData['expected_completion_date_start'])) . ' - ' . date('Y-m-d', strtotime($expenseData['expected_completion_date_end'])), 'limit' => $expenseData['limit'], 'title' => $expenseData['title'], 'balance' => ['ticket' => $expenseData['ticket_balance'] - $newTransactionAmount, 'deposit' => $expenseData['deposit_balance'], 'transaction' => $expenseData['transaction_balance'] - $newTransactionAmount, 'item' => $expenseData['item_balance']]];
 }
Beispiel #2
0
 /**
  * @param $apartmentId
  * @param $apartmentCurrencyIsoCode
  * @param $guestCurrencyIsoCode
  * @param $checkCurrency
  * @return float|int
  */
 public function getApartmentCleaningFeeInGuestCurrency($apartmentId, $apartmentCurrencyIsoCode, $guestCurrencyIsoCode, $checkCurrency = false)
 {
     /**
      * @var ApartmentDetailsDAO $apartmentDetailsDao
      */
     $apartmentDetailsDao = $this->getServiceLocator()->get('dao_apartment_details');
     $cleaningFee = $apartmentDetailsDao->getCleaningFee($apartmentId);
     if ($cleaningFee) {
         if (!$checkCurrency || $apartmentCurrencyIsoCode == $guestCurrencyIsoCode) {
             return $cleaningFee;
         }
         /**
          * @var \DDD\Dao\Currency\Currency $currencyDao
          */
         $currencyDao = $this->getServiceLocator()->get('dao_currency_currency');
         $currencyConverter = new Currency($currencyDao);
         $cleaningFee = $currencyConverter->convert($cleaningFee, $apartmentCurrencyIsoCode, $guestCurrencyIsoCode);
     } else {
         $cleaningFee = 0;
     }
     return $cleaningFee;
 }
Beispiel #3
0
 /**
  * @param array $data
  * @return array
  */
 public function bookingReservationData($data)
 {
     $apartmentService = $this->getServiceLocator()->get('service_website_apartment');
     $currencyDao = $this->getServiceLocator()->get('dao_currency_currency');
     $filter = $this->filterReservationData($data);
     if (!$filter) {
         return ['status' => 'error'];
     }
     $inventoryDao = $this->getInventoryDao();
     $arrival = date('Y-m-d', strtotime($data['arrival']));
     $departure = date('Y-m-d', strtotime($data['departure']));
     $occupancy = $data['guest'];
     $bookNightCount = Helper::getDaysFromTwoDate($arrival, $departure);
     $checkNightCount = Helper::getDaysFromTwoDate($arrival, date('Y-m-d'));
     $result = $inventoryDao->bookingReservationData($data['rate-for-booking'], $arrival, $departure, $data['guest'], $bookNightCount, $checkNightCount);
     if (!$result) {
         return ['status' => 'not_av'];
     }
     $session_booking = Helper::getSessionContainer('booking');
     // Clear Booking Data
     $session_booking->getManager()->getStorage()->clear('booking');
     // Media
     $img = Helper::getImgByWith($result['img1'], WebSite::IMG_WIDTH_SEARCH, true, true);
     if ($img) {
         $result['image'] = $img;
     }
     // Date view user
     $result['from'] = $data['arrival'];
     $result['to'] = $data['departure'];
     // Date
     $result['date_from'] = $arrival;
     $result['date_to'] = $departure;
     $result['guest'] = $data['guest'];
     $result['night_count'] = $bookNightCount;
     // Change currency
     $userCurrency = $this->getCurrencySite();
     $currencySymbol = WebSite::DEFAULT_CURRENCY;
     $currencyResult = $currencyDao->fetchOne(['code' => $userCurrency]);
     $result['acc_price'] = $result['amount_price'];
     if ($currencyResult) {
         $currencySymbol = $currencyResult->getSymbol();
     }
     if ($userCurrency != $result['code']) {
         $currencyUtility = new Currency($currencyDao);
         $price = $currencyUtility->convert($result['amount_price'], $result['code'], $userCurrency);
         $result['amount_price'] = $price;
         $result['symbol'] = $currencySymbol;
     }
     $result['user_currency'] = $userCurrency;
     // Price calculate
     $result['acc_currency'] = $result['code'];
     $result['apartment_id'] = $result['prod_id'];
     $payments = $this->getPaymentsData($result, $occupancy);
     $result['payments'] = $payments;
     //cancellation policy
     $cancellationPolicy = $apartmentService->cancelationPolicy($result);
     $result['cancelation_type'] = $cancellationPolicy['type'];
     $result['cancelation_policy'] = $cancellationPolicy['description'];
     //set reservation data in to session
     $session_booking->reservation = $result;
     return ['status' => 'success', 'result' => $session_booking->reservation];
 }
Beispiel #4
0
 /**
  * @todo: Put all into callback
  *
  * @return bool
  * @throws \Exception
  */
 public function process()
 {
     /**
      * @var \DDD\Dao\Booking\Booking $bookingDao
      * @var \DDD\Dao\Booking\ChargeTransaction $bankTransactionDao
      * @var \Library\Authentication\BackofficeAuthenticationService $authenticationService
      * @var \DDD\Service\Booking\BookingTicket $bookingTicketService
      * @var \DDD\Dao\Currency\Currency $currencyDao
      * @var BookingTicket $bookingTicket
      * @var \DDD\Domain\Currency\Currency $currencyDomain
      * @var Logger $logger
      */
     $authenticationService = $this->getServiceLocator()->get('library_backoffice_auth');
     $bookingTicketService = $this->getServiceLocator()->get('service_booking_booking_ticket');
     $currencyDao = $this->getServiceLocator()->get('dao_currency_currency');
     $bookingDao = $this->getServiceLocator()->get('dao_booking_booking');
     $logger = $this->getServiceLocator()->get('ActionLogger');
     $currencyUtility = new Currency($currencyDao);
     $dao = $this->getDao();
     $transactionIdList = parent::processGeneralTransaction();
     if (count($transactionIdList) > 1) {
         throw new \RuntimeException('It is impossible to store more than one transaction id for expense transaction.');
     } else {
         $moneyTransactionId = array_shift($transactionIdList);
     }
     $totalAmount = abs($this->getAccountTo()->getAmount());
     $bankCurrency = $this->getAccountTo()->getCurrency();
     $currencyDomain = $currencyDao->fetchOne(['id' => $bankCurrency]);
     $bankCurrencyCode = $currencyDomain->getCode();
     if (count($this->getReservations())) {
         foreach ($this->getReservations() as $reservationId) {
             $bookingDao->setEntity(new BookingTicket());
             $bookingTicket = $bookingDao->fetchOne(['id' => $reservationId]);
             if (!$bookingTicket) {
                 throw new \Exception('Undefined reservation number.');
             }
             $resNumber = $bookingTicket->getReservationNumber();
             $bankAccountDetails = ['currency_rate' => null];
             if (!$bankAccountDetails) {
                 throw new \Exception("Problem during requested operation for R# {$resNumber}  Partner bank account does not set for this apartment");
             }
             $balances = $bookingTicketService->getSumAndBalanc($bookingTicket->getId());
             $partnerBalanceInApartmentCurrency = $balances['partnerBalanceInApartmentCurrency'];
             $partnerBalanceInCustomerCurrency = $balances['partnerBalanceInCustomerCurrency'];
             // definitions
             $accAmount = abs($partnerBalanceInApartmentCurrency);
             $reservationData = ['partner_settled' => 1, 'partner_balance' => 0];
             if ($totalAmount > 0) {
                 if ($bookingTicket->getApartmentCurrencyCode() == $bankCurrencyCode) {
                     if ($accAmount <= $totalAmount) {
                         $bankAmount = $accAmount;
                         $totalAmount -= $accAmount;
                     } else {
                         $reservationData['partner_balance'] = $accAmount - $totalAmount;
                         $bankAmount = $totalAmount;
                         $accAmount = $totalAmount;
                         $totalAmount = 0;
                     }
                 } else {
                     $bankAmount = $currencyUtility->convert($accAmount, $bookingTicket->getApartmentCurrencyCode(), $bankCurrencyCode);
                     if ($bankAmount <= $totalAmount) {
                         $totalAmount -= $bankAmount;
                     } else {
                         $bankAmount = $totalAmount;
                         $accConvertedAmount = $currencyUtility->convert($totalAmount, $bankCurrencyCode, $bookingTicket->getApartmentCurrencyCode());
                         // In case of partly payment, partner balance cannot be equal to zero
                         $reservationData['partner_balance'] = $accAmount - $accConvertedAmount;
                         $accAmount = $accConvertedAmount;
                         $totalAmount = 0;
                     }
                 }
             } else {
                 $bankAmount = 0;
             }
             $dao->save(['money_transaction_id' => $moneyTransactionId, 'reservation_id' => $bookingTicket->getId(), 'user_id' => $authenticationService->getIdentity()->id, 'date' => date('Y-m-d H:i:s'), 'cache_user' => 0, 'type' => BankTransaction::BANK_TRANSACTION_TYPE_COLLECT, 'status' => BankTransaction::BANK_TRANSACTION_STATUS_APPROVED, 'money_direction' => BankTransaction::TRANSACTION_MONEY_DIRECTION_PARTNER_COLLECT, 'money_account_currency' => $bankCurrencyCode, 'money_account_id' => $this->getAccountTo()->getAccountId(), 'bank_rate' => null, 'bank_amount' => $bankAmount, 'acc_amount' => $accAmount, 'apartment_id' => $bookingTicket->getApartmentIdAssigned(), 'customer_amount' => -1 * $partnerBalanceInCustomerCurrency, 'comment' => "Automatic partner transaction was created after marking ticket as \"Partner Settled\".\n                                  Based on bank transaction of {$this->getAccountTo()->getAmount()} amount."]);
             // It is inessention here, but let it be
             $this->setMinorTransferId($dao->lastInsertValue);
             $bookingDao->update($reservationData, ['id' => $reservationId]);
             $logger->save(Logger::MODULE_BOOKING, $bookingTicket->getId(), Logger::ACTION_PARTNER_SETTLED);
         }
     }
     return $moneyTransactionId;
 }
Beispiel #5
0
 /**
  * @param array $data
  * @return array
  */
 public function searchApartmentList($data, $getAll = false)
 {
     /**
      * @var \DDD\Dao\Currency\Currency $currencyDao
      */
     $currencyDao = $this->getServiceLocator()->get('dao_currency_currency');
     $filterData = $this->filterSearchData($data);
     $apartelList = $apartels = $options = [];
     $error = false;
     $totalPages = 1;
     $queryString = '';
     if ($filterData) {
         return ['status' => 'error', 'msg' => $filterData];
     }
     $correcrData = $this->correctData($data);
     $bedrooms = $this->defineBedrooms($data);
     $guest = $correcrData['guest'];
     $page = $correcrData['page'];
     $arrival = $correcrData['arrival'];
     $departure = $correcrData['departure'];
     $apartelGeneralDao = $this->getApartelGeneralDao();
     $pageItemCount = WebSite::PAGINTAION_ITEM_COUNT;
     $offset = (int) ($page - 1) * $pageItemCount;
     if (isset($data['city'])) {
         $city = $data['city'];
         // Has date
         if ($arrival && $departure) {
             $apartelsResult = $apartelGeneralDao->getApartmentsByCityDate($city, $arrival, $departure, $guest, $pageItemCount, $offset, $bedrooms);
             $options['price_text'] = $this->getTextLineSite(1210);
         } else {
             $apartelsResult = $apartelGeneralDao->getApartmentsCity($city, $guest, $pageItemCount, $offset, $getAll, $bedrooms);
             $options['price_text'] = $this->getTextLineSite(1333);
         }
     } elseif (isset($data['apartel'])) {
         $apartel = $data['apartel'];
         // Has date
         if ($arrival && $departure) {
             $apartelsResult = $apartelGeneralDao->getApartmentsByApartelDate($apartel, $arrival, $departure, $guest, $pageItemCount, $offset, $bedrooms);
             $options['price_text'] = $this->getTextLineSite(1210);
         } else {
             $apartelsResult = $apartelGeneralDao->getApartmentsApartel($apartel, $guest, $pageItemCount, $offset, $getAll, $bedrooms);
             $options['price_text'] = $this->getTextLineSite(1333);
         }
     } else {
         return ['status' => 'error'];
     }
     $apartmentList = $apartelsResult['result'];
     $total = $apartelsResult['total'];
     $totalPages = $total > 0 ? ceil($total / $pageItemCount) : 1;
     if (!$apartmentList->count()) {
         return ['status' => 'no_av', 'msg' => $this->getTextLineSite(1218)];
     }
     $visitorLoc = $this->getVisitorCountry();
     // Change currency
     $userCurrency = $this->getCurrencySite();
     $currencySymbol = WebSite::DEFAULT_CURRENCY;
     $currencyResult = $currencyDao->fetchOne(['code' => $userCurrency]);
     if ($currencyResult) {
         $currencySymbol = $currencyResult->getSymbol();
     }
     $currencyUtility = new Currency($currencyDao);
     $query_array = [];
     if ($arrival && $departure) {
         array_push($query_array, 'arrival=' . Helper::dateForUrl($arrival));
         array_push($query_array, 'departure=' . Helper::dateForUrl($departure));
         array_push($query_array, 'guest=' . $guest);
         $queryString = '?' . implode('&', $query_array);
     } elseif ($guest >= 1) {
         $queryString = '?guest=' . $guest;
     } elseif ($getAll) {
         $queryString = '?show=reviews';
     }
     $apartmentList = iterator_to_array($apartmentList);
     // add apartel id if apartel reservation
     if (isset($data['apartel'])) {
         $queryString .= ($queryString ? '&' : '?') . 'apartel_id=' . current($apartmentList)['apartment_group_id'];
     }
     foreach ($apartmentList as $al) {
         // Generate image
         $noImg = false;
         if ($al['img1']) {
             if ($img = Helper::getImgByWith($al['img1'], WebSite::IMG_WIDTH_SEARCH)) {
                 $noImg = true;
                 $al['image'] = $img;
             }
         }
         if (!$noImg) {
             $al['image'] = Constants::VERSION . 'img/no_image.png';
         }
         // Calculate percent
         if ($arrival && $departure) {
             $al['percent'] = round(($al['price_max'] - $al['price_min']) / $al['price_max'] * 100);
         } else {
             $al['percent'] = rand(10, 13);
             $al['rate_name'] = 'Non refundable';
         }
         // User currency price
         if ($userCurrency != $al['code']) {
             $price = $currencyUtility->convert($al['price_min'], $al['code'], $userCurrency);
             $al['price_min'] = $price;
             $al['symbol'] = $currencySymbol;
         }
         $al['url_to_search'] = 'apartment/' . $al['url'] . '--' . $al['slug'] . $queryString;
         // Sale percent
         array_push($apartels, $al);
     }
     // Pagination view
     $paginatinView = $this->paginationViewItem($total, $page, $pageItemCount);
     return ['apartelList' => $apartels, 'totalPages' => $totalPages, 'status' => 'success', 'paginatinView' => $paginatinView, 'options' => $options, 'visitorLoc' => $visitorLoc];
 }
Beispiel #6
0
 /**
  * Use to generate and download reservations CSV file
  */
 public function downloadCsvAction()
 {
     /**
      * @var \DDD\Service\Booking\BookingManagement $bookingManagementService
      * @var \DDD\Service\Booking\BookingTicket $bookingTicketService
      * @var GeoliteCountry $geoliteCountryService
      * @var BookingExportRow[]|\ArrayObject $reservations
      */
     $bookingManagementService = $this->getServiceLocator()->get('service_booking_management');
     $bookingTicketService = $this->getServiceLocator()->get('service_booking_booking_ticket');
     $geoliteCountryService = $this->getServiceLocator()->get('service_geolite_country');
     // getting query parameters
     $queryParams = $this->params()->fromQuery();
     // get reservations data
     $reservations = $bookingManagementService->getReservationsToExport(null, null, $queryParams);
     $filteredArray = [];
     $currencyDao = $this->getServiceLocator()->get('dao_currency_currency');
     $currencyUtility = new Currency($currencyDao);
     foreach ($reservations as $reservation) {
         $isBlacklist = $reservation->isBlacklist();
         $isBlacklist = is_null($isBlacklist) ? 'No' : 'Yes';
         $sumAndBalanc = $bookingTicketService->getSumAndBalanc($reservation->getId());
         $filteredArray[] = ["Reservation" => $reservation->getReservationNumber(), "Affiliate ID" => $reservation->getAffiliateID(), "Affiliate Name" => $reservation->getPartnerName(), "Affiliate Reference" => $reservation->getPartnerRef(), "Status" => $reservation->getStatus(), "Blacklist" => $isBlacklist, "Apartel" => $reservation->getApartel(), "Booking Date" => date('Y-m-d', strtotime($reservation->getReservationDate())), "Booking Time" => date('H:i:s', strtotime($reservation->getReservationDate())), "Apartment Id" => $reservation->getApartmentIdAssigned(), "Apartment Name" => $reservation->getProductName(), "Apartment Building" => $reservation->getApartmentBuilding(), "Apartment City" => $reservation->getApartmentCity(), "Guest" => $reservation->getGuestFullName(), "Country" => $reservation->getCountry_name(), "City" => $reservation->getGuestCityName(), "IP" => $geoliteCountryService->composeIPAndCountryNameString($reservation->getIP()), "Arrival Date" => $reservation->getArrivalDate(), "Departure Date" => $reservation->getDepartureDate(), "Nights" => Helper::getDaysFromTwoDate($reservation->getArrivalDate(), $reservation->getDepartureDate()), "PAX" => $reservation->getPAX(), "Rate" => $reservation->getRateName(), "Base Price (EUR)" => $currencyUtility->convert(str_replace(',', '', $reservation->getPrice()), $reservation->getApartmentCurrencyCode(), 'EUR'), "Base Currency" => $reservation->getApartmentCurrencyCode(), "Base Price" => $reservation->getPrice(), "Charges(Ginosi)" => $sumAndBalanc['ginosiCollectChargesSummaryInApartmentCurrency'], "Transactions(Ginosi)" => $sumAndBalanc['ginosiCollectTransactionsSummaryInApartmentCurrency'], "Balance" => $reservation->getGuestBalance(), "Charges(Partner)" => $sumAndBalanc['partnerCollectChargesSummaryInApartmentCurrency'], "Transactions(Partner)" => $sumAndBalanc['partnerCollectTransactionsSummaryInApartmentCurrency'], "Partner Balance" => $reservation->getPartnerBalance(), "No Collection" => $reservation->getNo_collection(), "Review Score" => $reservation->getReviewScore(), "Like" => $reservation->getLike(), "Dislike" => $reservation->getDislike(), "Actual Arrival Date" => $reservation->getActualArrivalDate(), "Actual Departure Date" => $reservation->getActualDepartureDate()];
     }
     if (count($filteredArray)) {
         $response = $this->getResponse();
         $headers = $response->getHeaders();
         $utilityCsvGenerator = new CsvGenerator();
         $filename = 'reservations_' . str_replace(' ', '_', date('Y-m-d')) . '.csv';
         $utilityCsvGenerator->setDownloadHeaders($headers, $filename);
         $csv = $utilityCsvGenerator->generateCsv($filteredArray);
         $response->setContent($csv);
         return $response;
     } else {
         Helper::setFlashMessage(['notice' => 'The search results were empty, nothing to download.']);
         $url = $this->getRequest()->getHeader('Referer')->getUri();
         $this->redirect()->toUrl($url);
     }
 }
Beispiel #7
0
 public function chargeAction()
 {
     $detailDao = $this->getServiceLocator()->get('dao_apartment_details');
     $request = $this->getRequest();
     $bookingId = (int) $this->params()->fromRoute('booking_id', 0);
     $hash = $this->params()->fromRoute('hash', '');
     $itemId = $this->params()->fromRoute('item_id', 0);
     if (!$bookingId || Helper::hashForFrontierCharge($bookingId) != $hash) {
         Helper::setFlashMessage(['error' => TextConstants::ERROR_NO_ITEM]);
         return $this->redirect()->toRoute('backoffice/default', ['controller' => 'concierge', 'action' => 'view']);
     }
     /**
      * @var \DDD\Service\Frontier $service
      */
     $service = $this->getServiceLocator()->get('service_frontier');
     $data = $service->getDataForFrontierCharge($bookingId, $itemId);
     if (!$data) {
         Helper::setFlashMessage(['error' => TextConstants::ERROR_NO_ITEM]);
         return $this->redirect()->toRoute('backoffice/default', ['controller' => 'concierge', 'action' => 'view']);
     }
     $creditCards = false;
     if (isset($data['booking_data']['customer_id']) && $data['booking_data']['customer_id'] > 0) {
         /**
          * @var Card $cardService
          */
         $cardService = $this->getServiceLocator()->get('service_card');
         $creditCards = $cardService->getCustomerCreditCardsForFrontier($data['booking_data']['customer_id']);
     }
     $creditCardForm = new CreditCard();
     $currencyDao = $this->getServiceLocator()->get('dao_currency_currency');
     $currencyUtility = new Currency($currencyDao);
     $limitAmount = $currencyUtility->convert(200, 'USD', $data['booking_data']['acc_currency_sign']);
     $apartmentSpotsDao = $this->getServiceLocator()->get('dao_apartment_spots');
     $parkingSpotPriority = $apartmentSpotsDao->getApartmentParkingPrioritySpots($data['booking_data']['apartment_id_assigned']);
     $spotsPriority = [];
     foreach ($parkingSpotPriority as $key => $value) {
         if (!is_null($value)) {
             array_push($spotsPriority, $value);
         }
     }
     return array('data' => $data, 'itemId' => $itemId, 'creditCards' => $creditCards, 'creditCardForm' => $creditCardForm, 'limitAmount' => $limitAmount, 'spotsPriority' => $spotsPriority);
 }
Beispiel #8
0
 /**
  * @return int Money Transaction Id
  * @throws \Exception
  */
 public function process()
 {
     /**
      * @var \DDD\Dao\Booking\Booking $bookingDao
      * @var \DDD\Dao\Booking\ChargeTransaction $bankTransactionDao
      * @var \Library\Authentication\BackofficeAuthenticationService $authenticationService
      * @var \DDD\Service\Booking\BookingTicket $bookingTicketService
      * @var \DDD\Domain\Booking\BookingTicket $bookingTicket
      * @var \DDD\Dao\Currency\Currency $currencyDao
      * @var Logger $logger
      */
     $authenticationService = $this->getServiceLocator()->get('library_backoffice_auth');
     $bookingTicketService = $this->getServiceLocator()->get('service_booking_booking_ticket');
     $bankTransactionDao = $this->getServiceLocator()->get('dao_booking_change_transaction');
     $currencyDao = $this->getServiceLocator()->get('dao_currency_currency');
     $bookingDao = $this->getServiceLocator()->get('dao_booking_booking');
     $logger = $this->getServiceLocator()->get('ActionLogger');
     $currencyUtility = new Currency($currencyDao);
     $transactionIdList = parent::processGeneralTransaction();
     if (count($transactionIdList) > 1) {
         throw new \RuntimeException('It is impossible to store more than one transaction id for expense and/or reservation transaction.');
     } else {
         $moneyTransactionId = array_shift($transactionIdList);
     }
     $totalAmount = abs($this->getAccountFrom()->getAmount());
     $bankCurrency = $this->getAccountFrom()->getCurrency();
     $currencyDomain = $currencyDao->fetchOne(['id' => $bankCurrency]);
     $bankCurrencyCode = $currencyDomain->getCode();
     // For partner payment operation, expense should be created automatically based on existing data
     $expenseId = $this->createExpense($moneyTransactionId);
     // Set as verified transaction
     $this->changeVerifyStatus($moneyTransactionId, self::IS_VERIFIED);
     if (count($this->getReservations())) {
         foreach ($this->getReservations() as $reservationId) {
             $bookingDao->setEntity(new \DDD\Domain\Booking\BookingTicket());
             $bookingTicket = $bookingDao->fetchOne(['id' => $reservationId]);
             if ($bookingTicket) {
                 $balances = $bookingTicketService->getSumAndBalanc($bookingTicket->getId());
                 $partnerBalanceInApartmentCurrency = $balances['partnerBalanceInApartmentCurrency'];
                 $partnerBalanceInCustomerCurrency = $balances['partnerBalanceInCustomerCurrency'];
                 // definitions
                 $apartmentId = $bookingTicket->getApartmentIdAssigned();
                 $accAmount = $partnerBalanceInApartmentCurrency;
                 $reservationDescriptionSuffix = '';
                 $reservationData = ['partner_settled' => 1];
                 if ($totalAmount > 0) {
                     // In case when everything ok, partner balance must be equal to zero
                     $reservationData['partner_balance'] = 0;
                     if ($bookingTicket->getApartmentCurrencyCode() == $bankCurrencyCode) {
                         if ($accAmount <= $totalAmount) {
                             $bankAmount = $accAmount;
                             $totalAmount -= $accAmount;
                         } else {
                             $reservationData['partner_balance'] = $accAmount - $totalAmount;
                             $bankAmount = $totalAmount;
                             $accAmount = $totalAmount;
                             $totalAmount = 0;
                         }
                     } else {
                         $bankAmount = $currencyUtility->convert($accAmount, $bookingTicket->getApartmentCurrencyCode(), $bankCurrencyCode);
                         if ($bankAmount <= $totalAmount) {
                             $totalAmount -= $bankAmount;
                         } else {
                             $bankAmount = $totalAmount;
                             $accConvertedAmount = $currencyUtility->convert($totalAmount, $bankCurrencyCode, $bookingTicket->getApartmentCurrencyCode());
                             // In case of partly payment, partner balance cannot be equal to zero
                             $reservationData['partner_balance'] = $accAmount - $accConvertedAmount;
                             $accAmount = $accConvertedAmount;
                             $totalAmount = 0;
                         }
                     }
                 } else {
                     $reservationDescriptionSuffix = ' 0 amount of reservation means that general transaction\'s reservations is covering this reservation.';
                     $bankAmount = 0;
                 }
                 // Create transaction
                 $bankTransactionDao->save(['money_transaction_id' => $moneyTransactionId, 'reservation_id' => $bookingTicket->getId(), 'date' => date('Y-m-d H:i:s'), 'user_id' => $authenticationService->getIdentity()->id, 'cache_user' => 0, 'type' => BankTransaction::BANK_TRANSACTION_TYPE_PAY, 'status' => BankTransaction::BANK_TRANSACTION_STATUS_APPROVED, 'money_account_id' => $this->getAccountFrom()->getAccountId(), 'exact_expense_id' => $expenseId, 'bank_rate' => null, 'money_account_currency' => $bankCurrencyCode, 'bank_amount' => $bankAmount, 'acc_amount' => -1 * $accAmount, 'customer_amount' => -1 * $partnerBalanceInCustomerCurrency, 'apartment_id' => $apartmentId, 'money_direction' => BankTransaction::TRANSACTION_MONEY_DIRECTION_PARTNER_COLLECT, 'comment' => "Automatic partner payment transaction was created after marking ticket as \"Partner Settled\"\n                                      Based on bank transaction of {$this->getAccountFrom()->getAmount()}{$bankCurrencyCode} amount.{$reservationDescriptionSuffix}"]);
                 // It is inessention here, but let it be
                 $this->setMinorTransferId($bankTransactionDao->lastInsertValue);
                 $bookingDao->update($reservationData, ['id' => $reservationId]);
                 $logger->save(Logger::MODULE_BOOKING, $bookingTicket->getId(), Logger::ACTION_PARTNER_SETTLED);
             }
             //                else {
             //                    throw new \Exception("Problem during requested operation for R# {$bookingTicket->getReservationNumber()}. Invalid R#");
             //                }
         }
     }
     return $moneyTransactionId;
 }
Beispiel #9
0
 public function currencyConvert($price, $userCurrency, $accCurrency)
 {
     $currencySymbol = WebSite::DEFAULT_CURRENCY;
     $currencyDao = $this->getServiceLocator()->get('dao_currency_currency');
     $currencyResult = $currencyDao->getCurrencyData($userCurrency);
     if ($currencyResult) {
         $currencySymbol = $currencyResult['symbol'];
     }
     $currencyUtility = new Currency($currencyDao);
     $price = $currencyUtility->convert($price, $accCurrency, $userCurrency);
     return [$price, $currencySymbol];
 }