Esempio n. 1
0
 public function formAction()
 {
     $this->_withoutView();
     $bookingref = RM_Reservation_Manager::getInstance()->getReservationID();
     $billingModel = new RM_Billing();
     $billingRow = $billingModel->createRow();
     $billingRow->reservation_id = $bookingref;
     $billingRow->total_paid = '0.00';
     $billingRow->save();
     RM_Reservation_Manager::getInstance()->setPaymentTotal('0.00')->setPaymentStatus(RM_Payments_Status::TRANSACTION_END_SUCCESSFULLY);
     $this->_forward('success', 'Payments');
 }
 protected function _assign(Dwoo_Data $data)
 {
     $details = $this->_eventData->getAllDetails();
     $reservationID = $this->_eventData->getReservationID();
     $reservationModel = new RM_Reservations();
     $reservation = $reservationModel->find($reservationID)->current();
     $arrayDetails = array();
     foreach ($details as $detail) {
         $arrayDetails[] = array('unit' => $detail->getUnit()->toArray(), 'period' => (array) $detail->getPeriod(), 'periodtime' => (array) $detail->getPeriod(true), 'persons' => $detail->getPersons(), 'total' => $detail->getTotal());
     }
     // total paid and total due
     $billing = new RM_Billing();
     $priceCharges = $billing->getPrice($reservationID);
     $billingArray['tax'] = $priceCharges->tax;
     $billingArray['paid'] = $billing->getPaymentsTotal($reservation);
     $billingArray['due'] = $priceCharges->total;
     $billingArray['confirmed'] = $reservation->confirmed ? $translate->_('MessageYes') : $translate->_('MessageNo');
     $data->assign('details', $arrayDetails);
     $data->assign('reservation_id', $this->_eventData->getReservationID());
     return $data;
 }
 protected function _assign(Dwoo_Data $data)
 {
     $translate = RM_Environment::getInstance()->getTranslation(RM_Environment::TRANSLATE_MAIN);
     $locationsDAO = new RM_Locations();
     $reservationID = $this->_eventData->getReservationID();
     $reservationModel = new RM_Reservations();
     $reservation = $reservationModel->find($reservationID)->current();
     // reservation details
     $details = $this->_eventData->getAllDetails();
     $arrayDetails = array();
     foreach ($details as $detail) {
         $unit = $detail->getUnit()->toArray();
         $period = $detail->getPeriod()->toArray();
         $periodWithTime = $detail->getPeriod()->toArray(true);
         $location = $locationsDAO->fetchByUnit($unit['id'])->toArray();
         $extrasForTemplate = array();
         $extras = $detail->getExtras();
         foreach ($extras as $extra) {
             $extrasForTemplate[] = $extra->toArray();
         }
         $arrayDetails[] = array('unit' => $unit, 'locationInfo' => isset($location[0]) ? $location[0] : '', 'period' => $period, 'periodtime' => $periodWithTime, 'persons' => $detail->getPersons()->getAll(), 'total' => $detail->getTotal(), 'extras' => $extrasForTemplate);
     }
     // total paid and total due
     $billing = new RM_Billing();
     $priceCharges = $billing->getPrice($reservationID);
     $billingArray['tax'] = $priceCharges->tax;
     $billingArray['paid'] = $billing->getPaymentsTotal($reservation);
     $billingArray['due'] = $priceCharges->total;
     $billingArray['confirmed'] = $reservation->confirmed ? $translate->_('MessageYes') : $translate->_('MessageNo');
     // return the data to the template
     $data->assign('extras', $extrasForTemplate);
     $data->assign('details', $arrayDetails);
     $data->assign('user', $this->_eventData->getUser()->toArray());
     $data->assign('reservation_id', $reservationID);
     $data->assign('billing', $billingArray);
     return $data;
 }
Esempio n. 4
0
 /**
  * Returns total paid for this reservation
  *
  * @return float
  */
 public function getTotalPaid()
 {
     $billingModel = new RM_Billing();
     $billingTotal = $billingModel->getPaymentsTotal($this);
     return $billingTotal;
 }
Esempio n. 5
0
 public function ipnAction()
 {
     $this->_withoutView();
     $provider = new RM_Plugin_PayPal();
     $provider->validateIPN();
     RM_Log::toLog("PayPal ipnAction Called");
     if ($provider->ipnData['payment_status'] == "Completed" || $provider->ipnData['payment_status'] == "Pending") {
         RM_Log::toLog("PayPal payment status: " . $provider->ipnData['payment_status']);
         if (str_word_count($provider->ipnData['invoice'], 0, "RM-") > 0) {
             $bookingref = ltrim($provider->ipnData['invoice'], "RM-");
         } else {
             $bookingref = $provider->ipnData['invoice'];
         }
         RM_Log::toLog("Booking ref passed back from PayPal: " . $bookingref);
         $model = new RM_Reservations();
         $reservation = $model->find($bookingref)->current();
         RM_Log::toLog("Reservation Record ID: " . $reservation->id);
         $model->confirm($reservation);
         RM_Log::toLog("Confirmed Updated");
         $model->inProgressComplete($reservation);
         RM_Log::toLog("InProgress Marker Updated");
         // save the total
         // we have a problem here, when this action is called it is called
         // from the paypal.com server. The session is not the same so saving to it
         // is impossible. I think we need to pass to PayPal the 'custom' parameter
         // this could contain something like the session id, however I am not
         // sure if it's possible to update the data in a session with a session
         // id?
         //$manager = RM_Reservation_Manager::getInstance();
         $total_paid = $provider->ipnData['mc_gross'];
         RM_Log::toLog("Total Passed back from PayPal: " . $total_paid);
         //$manager->setPaymentTotal($total_paid); // save the total incase we need it later.
         //if (!$total_paid) $this->_redirect('Reservations', 'notcomplete'); // this handles if the total amount is null'd
         $billingModel = new RM_Billing();
         $billingRow = $billingModel->createRow();
         $billingRow->reservation_id = $bookingref;
         $billingRow->total_paid = $total_paid;
         $billingID = $billingRow->save();
         RM_Log::toLog("Billing Updated");
         // TODO: I can't get thsi working..
         // save the payment information
         $billingPaymentsModel = new RM_BillingPayments();
         $billingPaymentRow = $billingPaymentsModel->createRow();
         $billingPaymentRow->id = $billingID;
         $billingPaymentRow->provider = "PayPal";
         $billingPaymentRow->transaction_id = $provider->ipnData['txn_id'];
         $billingPaymentRow->status = $provider->ipnData['payment_status'];
         $billingPaymentRow->total = $provider->ipnData['mc_gross'];
         $billingPaymentRow->transaction_date = Date("Y-m-d");
         $billingPaymentRow->save();
         RM_Log::toLog("Billing Payments Updated");
         // TODO: if the IPN is successful then we need to set the in_progress flag to 0
         // this is also done in the reservation controller on success we have to do it here also
         // as it is possible the customer may not return to the site via the payment provider
         // return URL in this case the in_progress flag will never be updated that's why we
         // need to do this here also
         // I need to ask Valentin about a standard method for this.
         // TODO: we should also record other information such as the transaction id
         // however this can be added later.
     }
 }
 /**
  * Edit Reservation sets up the enviroment for editing a reservation and loads data.
  *
  * Creates temporary entries for the temp reservation data, loads the form
  * configuration, data for users, calendar information. This method is the PHP
  * code behind the edit.js function. All initial data loaded onto this form
  * is controlled by this method.
  *
  * @param   request id the reservation id.
  * @return 	json    json array information.
  */
 public function editJsonAction()
 {
     $reservationID = $this->_getParam('id', null);
     if ($reservationID == null) {
         return array('data' => array('success' => false));
     }
     $reservationModel = new RM_Reservations();
     $reservation = $reservationModel->find($reservationID)->current();
     if ($reservation == null) {
         return array('data' => array('success' => false));
     }
     $details = $reservation->findReservationDetails();
     $billing = new RM_Billing();
     $reservationDetailsModel = new RM_ReservationDetails();
     $jsonDetails = array();
     $savedpriceData = array();
     $config = new RM_Config();
     $summaryModel = new RM_ReservationSummary();
     foreach ($details as $detail) {
         $unit = $detail->findUnit();
         if ($unit == null) {
             continue;
         }
         $priceSystem = RM_Prices_Manager::getInstance()->getRealPriceSystem($unit);
         $showTimeFields = (int) $priceSystem->getShowTime($unit);
         $unitReservationDetails = $reservationDetailsModel->findByUnit($unit, array($reservation));
         $jsonDisabledPeriods = array();
         // TODO: Need to check if this required
         // not sure why we need this now...
         // each reservation is 1 reservation per unit
         // so why do we need a loop to iterate all reservations.
         //valentin: we need to show every reserved period for this unit by other reservations
         foreach ($unitReservationDetails as $unitReservationDetail) {
             $jsonDisabledPeriods[] = "{\n                    start_date: '" . $unitReservationDetail->getStartDatetime($priceSystem->getDateformat(true)) . "',\n                    end_date: '" . $unitReservationDetail->getEndDatetime($priceSystem->getDateformat(true)) . "',\n                }";
         }
         // other information that is price system specific ie. board_type
         $otherInfo = $priceSystem->getOtherInfo();
         foreach ($otherInfo as $otherName) {
             $othersJson .= $otherName . ": '" . $detail->{$otherName} . "',";
         }
         // get the other systems
         $otherSystems = RM_Environment::getInstance()->getOthersSystems();
         foreach ($otherSystems as $otherSystem) {
             $oSystems[] = "'" . $otherSystem->name . "'";
         }
         $jsonDetails[] = "{\n                unit: {\n                    id: '" . $unit->getId() . "',\n                    name: '" . addslashes($unit->name) . "',\n                },\n                reserved_period: {\n                    start_date: '" . $detail->getStartDatetime($priceSystem->getDateformat(true)) . "',\n                    end_date: '" . $detail->getEndDatetime($priceSystem->getDateformat(true)) . "'\n                },\n                persons: {\n                    adults: '" . $detail->adults . "',\n                    children: '" . $detail->children . "',\n                    infants: '" . $detail->infants . "',\n                },\n                othersystems: [" . implode(",", $oSystems) . "],\n                pricesystem: '" . $priceSystem->name . "',\n                showtime: " . $showTimeFields . ",\n                " . $othersJson . "\n                blocked_periods: [" . implode(',', $jsonDisabledPeriods) . "]\n              }";
         $config = new RM_Config();
         $currencySymbol = $config->getValue('rm_config_currency_symbol');
         $summaryRows = $summaryModel->fetchByReservationDetail($detail)->toArray();
         for ($i = 0; $i < count($summaryRows); $i++) {
             $summaryRows[$i]['total_amount'] = $currencySymbol . RM_Environment::getInstance()->roundPrice($summaryRows[$i]['total_amount']);
         }
         $savedpriceData[] = "{\n                unit: {\n                    id: '" . $unit->getId() . "',\n                    name: '" . addslashes($unit->name) . "',\n                },\n                total_sub: '" . $currencySymbol . RM_Environment::getInstance()->roundPrice($detail->total_price) . "',\n                reserved_period: {\n                    start_date: '" . $detail->getStartDatetime() . "',\n                    end_date: '" . $detail->getEndDatetime() . "'\n                },\n                summary_rows: " . Zend_Json::encode($summaryRows) . ",\n                showtime: " . $showTimeFields . "\n             }\n             ";
     }
     $payments = $billing->getPayments($reservation);
     $paymentsData = array();
     foreach ($payments as $payment) {
         $paymentsData[] = "{\n                date: '" . $payment->transaction_date . "',\n                provider: '" . $payment->provider . "',\n                transactionid: '" . $payment->transaction_id . "',\n                status: '" . $payment->status . "',\n                total_paid: '" . $currencySymbol . RM_Environment::getInstance()->roundPrice($payment->total_paid) . "'\n            }";
     }
     $reservationConfigModel = new RM_ReservationConfig();
     $fields = $reservationConfigModel->getAdminEditFields();
     $jsonFields = array();
     foreach ($fields as $field) {
         $jsonFields[] = $field->admin_view_edit;
     }
     $reservationSummaryRows = $summaryModel->fetchByReservation($reservation)->toArray();
     for ($i = 0; $i < count($reservationSummaryRows); $i++) {
         $reservationSummaryRows[$i]['total_amount'] = $currencySymbol . RM_Environment::getInstance()->roundPrice($reservationSummaryRows[$i]['total_amount']);
     }
     // reservation price information
     $user = $reservation->findParentUsers();
     $json = "{\n            data : " . Zend_Json::encode($reservation->toArray()) . ",\n            fields : [" . implode(',', $jsonFields) . "],\n            user: {\n                id : '" . $user->id . "',\n                last_name : '" . addslashes($user->last_name) . "',\n                first_name : '" . addslashes($user->first_name) . "',\n            },\n            details: [\n                " . implode(',', $jsonDetails) . "\n            ],\n            pricedata: {\n                prices: [" . implode(',', $savedpriceData) . "],\n                reservation_summary_rows: " . Zend_Json::encode($reservationSummaryRows) . ",\n                reservationTotal: '" . $currencySymbol . RM_Environment::getInstance()->roundPrice($reservation->getTotalPrice()) . "'\n            },\n            paymentdata: {\n                payments: [" . implode(',', $paymentsData) . "]\n            }\n        }";
     // set the read marker
     $reservation->is_read = 1;
     $reservation->save();
     return array('data' => $json, 'encoded' => true);
 }
Esempio n. 7
0
 function markPaid(RM_Reservation_Row $reservation)
 {
     $totalPrice = $reservation->getTotalPrice();
     $billingModel = new RM_Billing();
     $totalPaid = $billingModel->getPaymentsTotal($reservation);
     $total = $totalPrice - $totalPaid;
     $billingID = $billingModel->createRow(array('reservation_id' => $reservation->id, 'total_paid' => $total))->save();
     $billingPaymentsModel = new RM_BillingPayments();
     $billingPaymentsModel->createRow(array('id' => $billingID, 'provider' => 'Administrator', 'transaction_id' => '0', 'status' => 'success', 'total' => $total, 'transaction_date' => date('Y-m-d H:i:s')))->save();
     $this->confirm($reservation);
 }