public function getPendingTransactionsAction()
    {
        $auth = $this->getServiceLocator()->get('library_backoffice_auth');
        if (!$auth->checkUniversalDashboardPermission(UserService::DASHBOARD_TRANSACTION_PENDING)) {
            return $this->redirect()->toRoute('home');
        }
        /* @var $pendingTransactionWidgetService \DDD\Service\UniversalDashboard\Widget\PendingTransaction */
        $pendingTransactionWidgetService = $this->getServiceLocator()->get('service_universal_dashboard_widget_pending_transaction');
        $dataSet = $pendingTransactionWidgetService->getPendingTransactions();
        $preparedData = [];
        $statusList = Booking\BankTransaction::$transactionStatus;
        $chargebackList = [Booking\BankTransaction::BANK_TRANSACTION_TYPE_CHARGEBACK_DISPUTE => Objects::getChargeType()[Booking\BankTransaction::BANK_TRANSACTION_TYPE_CHARGEBACK_DISPUTE], Booking\BankTransaction::BANK_TRANSACTION_TYPE_CHARGEBACK_FRAUD => Objects::getChargeType()[Booking\BankTransaction::BANK_TRANSACTION_TYPE_CHARGEBACK_FRAUD], Booking\BankTransaction::BANK_TRANSACTION_TYPE_CHARGEBACK_OTHER => Objects::getChargeType()[Booking\BankTransaction::BANK_TRANSACTION_TYPE_CHARGEBACK_OTHER]];
        if ($dataSet && count($dataSet)) {
            foreach ($dataSet as $row) {
                $strStatuses = $strType = $actionsColumn = $disabled = '';
                $transactionId = $row['id'];
                $reservationId = $row['reservation_id'];
                $actionsColumn = '<a href="//' . DomainConstants::BO_DOMAIN_NAME . '/booking/edit/' . $row['res_number'] . '#financial_details" class="btn btn-xs btn-primary" target="_blank" data-html-content="View"></a>';
                if ($row['status'] == Booking\BankTransaction::BANK_TRANSACTION_STATUS_PENDING && $row['type'] == Booking\BankTransaction::BANK_TRANSACTION_TYPE_CHARGEBACK_OTHER) {
                    $disabled = 'disabled';
                    foreach ($chargebackList as $key => $item) {
                        $strType .= '<li><a href="javascript:void(0)"  onClick="changePendingTransactionType(this, ' . $key . ')">' . $item . '</a></li>';
                    }
                    $actionsColumn .= '
                        <div class="btn-group margin-right-10 chb-transaction-type">
                            <button type="button" class="btn btn-xs btn-success dropdown-toggle" data-toggle="dropdown" aria-expanded="false">
                                <span class="exist-transaction-type-button">Change Type</span> <span class="caret"></span>
                            </button>
                            <ul class="dropdown-menu" role="menu">' . $strType . '</ul>
                        </div>';
                }
                foreach ($statusList as $key => $item) {
                    if ($key == Booking\BankTransaction::BANK_TRANSACTION_STATUS_PENDING) {
                        continue;
                    }
                    $strStatuses .= "<li><a href='javascript:void(0)' onClick='changePendingTransaction(this, {$key}, {$transactionId}, {$reservationId})'>{$item}</a></li>";
                }
                $actionsColumn .= '
                    <div class="btn-group">
                        <button type="button" class="btn btn-xs btn-success dropdown-toggle exist-transaction-status-button" data-toggle="dropdown" ' . $disabled . '>
                            Select Status <span class="caret"></span>
                        </button>
                        <ul class="dropdown-menu" role="menu"> ' . $strStatuses . '</ul>
					</div>';
                $preparedData[] = ["0" => $row['res_number'], "1" => $row['acc_name'], "2" => $row['guest'], "3" => Objects::getChargeTypeById($row['type']), "4" => $row['acc_amount'] . ' ' . $row['symbol'], "5" => date(Constants::GLOBAL_DATE_TIME_FORMAT, strtotime($row['date'])), "6" => $actionsColumn];
            }
        }
        return new JsonModel(["aaData" => $preparedData]);
    }
Esempio n. 2
0
 public function getBookingOptions($data)
 {
     /**
      * @var \DDD\Service\Booking\BookingAddon $bookingAddonService
      * @var \DDD\Dao\Partners\Partners $partnerDao
      * @var \DDD\Dao\Booking\Charge $chargeDao
      * @var \DDD\Dao\Booking\ChargeTransaction $bankTransactionDao
      * @var \DDD\Dao\ApartmentGroup\ApartmentGroup $apartmentGroupDao
      * @var ChargeAuthorizationService $chargeAuthorizationService
      * @var Psp $pspDao
      */
     $bookingAddonService = $this->getServiceLocator()->get('service_booking_booking_addon');
     $partnerDao = $this->getServiceLocator()->get('dao_partners_partners');
     $apartmentGroupDao = $this->getServiceLocator()->get('dao_apartment_group_apartment_group');
     $chargeDao = $this->getServiceLocator()->get('dao_booking_charge');
     $bankTransactionDao = $this->getServiceLocator()->get('dao_booking_change_transaction');
     $apartmentDao = $this->getServiceLocator()->get('dao_accommodation_accommodations');
     $curencyRateDao = new \DDD\Dao\Currency\Currency($this->getServiceLocator(), 'DDD\\Domain\\Booking\\Currency');
     $countryDao = new \DDD\Dao\Geolocation\Countries($this->getServiceLocator());
     $teamsDao = new \DDD\Dao\Team\Team($this->getServiceLocator());
     $statusDao = new \DDD\Dao\Booking\Statuses($this->getServiceLocator());
     $accDeailsDao = new \DDD\Dao\Apartment\Details($this->getServiceLocator(), 'ArrayObject');
     $apartmentDescriptionDao = new \DDD\Dao\Apartment\Description($this->getServiceLocator(), 'ArrayObject');
     $chargeAuthorizationService = $this->getServiceLocator()->get('service_reservation_charge_authorization');
     $detailsRow = $accDeailsDao->fetchOne(['apartment_id' => $data['apartmentIdAssigned']]);
     $accInfo = $apartmentDao->fetchOne(['id' => $data['apartmentIdAssigned']]);
     $apartmentDescription = $apartmentDescriptionDao->fetchOne(['apartment_id' => $data['apartmentIdAssigned']]);
     $result = [];
     $result['apartment']['check_in'] = $apartmentDescription['check_in'];
     $status = $data['status'];
     $countries = $countryDao->getAllActiveCountries();
     $result['countries'] = $countries;
     /**
      * @todo do not fetchAll
      * Fetch using usage service
      */
     $result['teams'] = $teamsDao->fetchAll(['usage_notifiable' => 1]);
     $affiliateID = $data['aff_id'];
     $partner = $partnerDao->getPartners($affiliateID);
     $result['partners'] = iterator_to_array($partner);
     $result['partner_data'] = $partnerDao->getPartnerModel($affiliateID);
     $statuses = $statusDao->getAllList($status);
     $result['statuses'] = iterator_to_array($statuses);
     $pspDao = $this->getServiceLocator()->get('dao_psp_psp');
     $pspList = $pspDao->getPspListForTransaction();
     $result['psp'] = iterator_to_array($pspList);
     $addonsList = $bookingAddonService->getAddons();
     $addonsArray = $bookingAddonService->getAddonsArray();
     $creditCardsForAuthorization = $chargeAuthorizationService->getCreditCardsForAuthorization($data['id']);
     $result['credit_cards_for_authorization'] = $creditCardsForAuthorization;
     if ($status == BookingService::BOOKING_STATUS_BOOKED) {
         unset($addonsArray[BookingAddon::ADDON_TYPE_PENALTY]);
     } else {
         unset($addonsArray[BookingAddon::ADDON_TYPE_ACC]);
         unset($addonsArray[BookingAddon::ADDON_TYPE_NIGHT]);
     }
     $result['addons'] = $addonsList;
     $result['addons_array'] = $addonsArray;
     $result['apartels'] = $apartmentGroupDao->getApartelsByApartmentId($data['apartmentIdAssigned']);
     $curencyRate = $curencyRateDao->fetchAll();
     $curencyRateArray = [];
     foreach ($curencyRate as $row) {
         if ($detailsRow) {
             if ((int) $detailsRow['cleaning_fee']) {
                 if ($row->getId() == $accInfo->getCurrencyId()) {
                     $cleaningFeeData = ['currency_id' => $row->getId(), 'cname' => $row->getCode(), 'currency_rate' => $row->getValue()];
                 }
             }
         }
         $curencyRateArray[] = ['code' => $row->getCode(), 'value' => $row->getValue()];
     }
     if ($detailsRow) {
         if ((int) $detailsRow['cleaning_fee']) {
             $result['addons_array'][BookingAddon::ADDON_TYPE_CLEANING_FEE]['value'] = $detailsRow['cleaning_fee'];
             $result['addons_array'][BookingAddon::ADDON_TYPE_CLEANING_FEE]['currency_id'] = $cleaningFeeData['currency_id'];
             $result['addons_array'][BookingAddon::ADDON_TYPE_CLEANING_FEE]['cname'] = $cleaningFeeData['cname'];
             $result['addons_array'][BookingAddon::ADDON_TYPE_CLEANING_FEE]['currency_rate'] = $cleaningFeeData['currency_rate'];
         }
     }
     $result['curencyRate'] = json_encode($curencyRateArray);
     $chargeType = Objects::getChargeType();
     $result['chargeType'] = $chargeType;
     $charges = $chargeDao->getChargesByReservationId($data['id'], 1);
     $result['charges'] = iterator_to_array($charges);
     $charged = $chargeDao->getChargesByReservationId($data['id'], 0);
     $result['charged'] = iterator_to_array($charged);
     $getSumAndBalance = $this->getSumAndBalanc($data['id']);
     $result['balances_and_summaries'] = $getSumAndBalance;
     $transactions = $bankTransactionDao->getReservationTransactions($data['id']);
     $result['transactions'] = $transactions->count() ? iterator_to_array($transactions) : false;
     $auth = $this->getServiceLocator()->get('library_backoffice_auth');
     $hasFinanceRole = $auth->hasRole(Roles::ROLE_RESERVATION_FINANCE);
     $hasPayableRole = $auth->hasRole(Roles::ROLE_BILLPAY);
     $hasTransactionVerifierRole = $auth->hasRole(Roles::ROLE_BOOKING_TRANSACTION_VERIFIER);
     $result['hasFinanceRole'] = $hasFinanceRole;
     $result['hasFinanceRole'] = $hasFinanceRole;
     $result['hasPayableRole'] = $hasPayableRole;
     $result['hasTransactionVerifierRole'] = $hasTransactionVerifierRole;
     if ($auth->hasRole(Roles::ROLE_CREDIT_CARD)) {
         $result['hasCreditCardViewer'] = true;
     }
     return $result;
 }
Esempio n. 3
0
 /**
  * @param int $transactionId
  * @param int $transactionStatus
  * @param int $transactionType
  * @return array
  */
 public function changeTransactionState($transactionId, $transactionStatus, $transactionType)
 {
     /**
      * @var \DDD\Dao\Booking\ChargeTransaction $bankTransactionDao
      * @var \Library\Authentication\BackofficeAuthenticationService $authenticationService
      * @var \DDD\Service\Booking\BookingTicket $bookingTicketService
      * @var ChargeTransaction $transactionData
      * @var Transactions $moneyTransactionDao
      */
     $authService = $this->getServiceLocator()->get('library_backoffice_auth');
     $bookingTicketService = $this->getServiceLocator()->get('service_booking_booking_ticket');
     $bankTransactionDao = $this->getServiceLocator()->get('dao_booking_change_transaction');
     $moneyTransactionDao = $this->getServiceLocator()->get('dao_finance_transaction_transactions');
     $bookingDao = $this->getServiceLocator()->get('dao_booking_booking');
     $timestamp = date('Y-m-d H:i:s');
     try {
         $bankTransactionDao->beginTransaction();
         if (!($transactionId > 0 && $transactionStatus > 0)) {
             throw new \RuntimeException(TextConstants::ERROR_BAD_REQUEST);
         }
         $auth = $authService->getIdentity();
         $logger = $auth->firstname . ' ' . $auth->lastname;
         $transactionData = $bankTransactionDao->fetchOne(['id' => $transactionId], ['reservation_id', 'money_transaction_id', 'status', 'comment', 'type']);
         if (!$transactionData) {
             throw new \RuntimeException(TextConstants::ERROR_BAD_REQUEST);
         }
         $comment = sprintf(TextConstants::COMMENT_TRANSACTION_ONLY_STATUS, self::$transactionStatus[$transactionData->getStatus()], self::$transactionStatus[$transactionStatus], $timestamp, $logger);
         $changeData = ['status' => $transactionStatus, 'reviewed' => 0];
         $returnStatus = 'success';
         $returnMsg = TextConstants::SUCCESS_UPDATE;
         if ($transactionType > 0 && in_array($transactionType, [self::BANK_TRANSACTION_TYPE_CHARGEBACK_FRAUD, self::BANK_TRANSACTION_TYPE_CHARGEBACK_OTHER, self::BANK_TRANSACTION_TYPE_CHARGEBACK_DISPUTE])) {
             $changeData['type'] = $transactionType;
             // in case when transaction is chargeback and it's reason of fraud, we must update data in black list table
             if ($transactionType == self::BANK_TRANSACTION_TYPE_CHARGEBACK_FRAUD && $transactionStatus == self::BANK_TRANSACTION_STATUS_APPROVED) {
                 $serviceFraud = $this->getServiceLocator()->get('service_fraud');
                 $fraud = $serviceFraud->saveFraudManual($transactionData->getReservationId());
                 if (isset($fraud['status']) && $fraud['status'] != 'success' && isset($fraud['msg'])) {
                     $returnStatus = 'warning';
                     $returnMsg .= "<br>{$fraud['msg']}";
                 }
             }
             $comment = sprintf(TextConstants::COMMENT_TRANSACTION_STATUS_TYPE, Objects::getChargeType()[$transactionData->getType()], self::$transactionStatus[$transactionData->getStatus()], Objects::getChargeType()[$transactionType], self::$transactionStatus[$transactionStatus], $timestamp, $logger);
         }
         if ($transactionData->getComment()) {
             $comment = "{$transactionData->getComment()}<br>{$comment}";
         }
         // Money Transaction status change
         if ($transactionStatus == self::BANK_TRANSACTION_STATUS_VOIDED) {
             $siblingCount = $moneyTransactionDao->getSiblingTransactionsCount($transactionData->getMoneyTransactionId());
             // If One to One connected reservation transaction
             if ($siblingCount == 1) {
                 // Disconnect from money transaction
                 $changeData['money_transaction_id'] = null;
                 $returnMsg = 'Reservation Transaction voided and all related Money Transactions have also been removed.';
                 // Remove money transaction
                 $moneyTransactionDao->delete(['id' => $transactionData->getMoneyTransactionId()]);
             } else {
                 $returnMsg = 'Reservation Transaction has been voided, however the Money Transaction has NOT been removed.';
             }
         }
         $changeData['comment'] = $comment;
         $bankTransactionDao->save($changeData, ['id' => $transactionId]);
         // after transaction save, we must recalculate balance and update it in reservations table
         $balances = $bookingTicketService->getSumAndBalanc($transactionData->getReservationId());
         $updateReservationData = ['guest_balance' => number_format($balances['ginosiBalanceInApartmentCurrency'], 2, '.', ''), 'partner_balance' => number_format($balances['partnerBalanceInApartmentCurrency'], 2, '.', '')];
         $bookingDao->save($updateReservationData, ['id' => $transactionData->getReservationId()]);
         $bankTransactionDao->commitTransaction();
         $result = ['status' => $returnStatus, 'msg' => $returnMsg];
     } catch (\RuntimeException $ex) {
         $bankTransactionDao->rollbackTransaction();
         $result = ['status' => 'error', 'msg' => $ex->getMessage()];
     } catch (\Exception $ex) {
         $bankTransactionDao->rollbackTransaction();
         $result = ['status' => 'error', 'msg' => TextConstants::SERVER_ERROR];
     }
     return $result;
 }