Ejemplo n.º 1
0
 /**
  * @param bool $reservationId
  * @return array|\DDD\Domain\Booking\FirstCharge|null|ResultSet
  */
 public function getForCharge($reservationId = false)
 {
     $this->resultSetPrototype->setArrayObjectPrototype(new \DDD\Domain\Booking\FirstCharge());
     $result = $this->fetchAll(function (Select $select) use($reservationId) {
         $select->columns(['id', 'res_number', 'guest_currency_code', 'apartment_currency_code', 'price', 'currency_rate', 'is_refundable', 'refundable_before_hours', 'date_from', 'date_to', 'penalty_fixed_amount', 'model', 'apartment_id_assigned', 'partner_commission', 'rate_capacity' => 'man_count', 'occupancy', 'guest_email', 'partner_id', 'partner_ref', 'channel_name', 'nights' => new Expression('datediff(date_to, date_from)')]);
         $select->join(['city' => DbTables::TBL_CITIES], $this->getTable() . '.acc_city_id = city.id', [], Select::JOIN_LEFT)->join(['location_detail' => DbTables::TBL_LOCATION_DETAILS], 'city.detail_id = location_detail.id', ['tot', 'tot_type', 'tot_included', 'tot_additional', 'tot_max_duration', 'vat', 'vat_type', 'vat_included', 'vat_additional', 'vat_max_duration', 'sales_tax', 'sales_tax_type', 'sales_tax_included', 'sales_tax_additional', 'sales_tax_max_duration', 'city_tax', 'city_tax_type', 'city_tax_included', 'city_tax_additional', 'city_tax_max_duration'], Select::JOIN_LEFT)->join(['charge' => DbTables::TBL_CHARGE], $this->getTable() . '.id = charge.reservation_id', ['addons_type'], Select::JOIN_LEFT)->join(['logs' => DbTables::TBL_ACTION_LOGS], new Expression($this->getTable() . '.id = logs.identity_id AND logs.user_id = ' . UserService::USER_GUEST), ['remarks' => 'value'], Select::JOIN_LEFT);
         $select->join(['country' => DbTables::TBL_COUNTRIES], $this->getTable() . '.acc_country_id = country.id', [], Select::JOIN_LEFT);
         $select->join(['country_currency_tbl' => DbTables::TBL_CURRENCY], 'country.currency_id = country_currency_tbl.id', ['country_currecny' => 'code'], Select::JOIN_LEFT);
         if ($reservationId) {
             $select->where->equalTo($this->getTable() . '.id', $reservationId);
         } else {
             $where = new Where();
             $where->notEqualTo($this->getTable() . '.check_charged', 1)->equalTo($this->getTable() . '.status', BookingService::BOOKING_STATUS_BOOKED)->isNull('charge.addons_type')->expression('(' . $this->getTable() . '.is_refundable = 2 or ' . $this->getTable() . '.refundable_before_hours >= TIMESTAMPDIFF(HOUR, NOW(), ' . $this->table . '.date_from))', array());
             $apartelChannelResPredicate = new Predicate();
             $apartelChannelResPredicate->greaterThan($this->getTable() . '.apartel_id', 0)->greaterThan($this->getTable() . '.channel_res_id', 0);
             $apartelChargePredicate = new Predicate();
             $apartelChargePredicate->addPredicate($apartelChannelResPredicate);
             $apartelChargePredicate->or->equalTo($this->getTable() . '.apartel_id', 0);
             $where->addPredicate($apartelChargePredicate);
             $select->where($where);
         }
     });
     if ($reservationId && $result->count()) {
         return $result->current();
     }
     return $result;
 }
Ejemplo n.º 2
0
 /**
  * @param array $fieldMap
  *
  * @return Predicate
  */
 public function filter($fieldMap = array())
 {
     if (empty($this->filter['filters'])) {
         return array();
     }
     $where = new Predicate();
     $where->addPredicate($this->parseFilters($this->filter, $fieldMap));
     return $where;
 }
Ejemplo n.º 3
0
 /**
  * @param array $data
  * @return array
  */
 public function getPayToPartnerReservations(array $data)
 {
     /**
      * @var \DDD\Dao\Booking\Booking $bookingDao
      */
     $bookingDao = $this->getServiceLocator()->get('dao_booking_booking');
     $bookingDao->setEntity(new \DDD\Domain\Booking\BookingTableRow());
     $where = new Where();
     if (isset($data['res_number'])) {
         $where->equalTo(DbTables::TBL_BOOKINGS . '.res_number', $data['res_number']);
     } else {
         $partnerId = $data['partner'];
         $dateFrom = $data['date_from'];
         $dateTo = $data['date_to'];
         $dist = $data['dist'];
         $where->equalTo(DbTables::TBL_BOOKINGS . '.partner_id', $partnerId);
         $where->greaterThanOrEqualTo(DbTables::TBL_BOOKINGS . '.date_to', date('Y-m-d', strtotime($dateFrom)));
         $where->lessThanOrEqualTo(DbTables::TBL_BOOKINGS . '.date_to', date('Y-m-d', strtotime($dateTo)));
         $where->greaterThan(DbTables::TBL_BOOKINGS . '.partner_balance', 0);
         $where->equalTo(DbTables::TBL_BOOKINGS . '.partner_settled', 0);
         $where->equalTo(DbTables::TBL_BOOKINGS . '.payment_settled', 1);
         $where->expression(DbTables::TBL_BOOKINGS . '.apartment_id_assigned not in (?, ?)', [Constants::TEST_APARTMENT_1, Constants::TEST_APARTMENT_2]);
         if (is_array($dist) && count($dist)) {
             $apartmentIdList = [];
             $apartelIdList = [];
             $fiscalList = [];
             foreach ($dist as $distItem) {
                 list($entityType, $entityId) = explode('_', $distItem);
                 // 1 for apartment, 2 for apartel (as a convention)
                 if ($entityType == Distribution::TYPE_APARTMENT) {
                     array_push($apartmentIdList, $entityId);
                 } elseif ($entityType == Distribution::TYPE_APARTEL) {
                     array_push($apartelIdList, $entityId);
                 } else {
                     array_push($fiscalList, $entityId);
                 }
             }
             if (!count($apartmentIdList) && !count($apartelIdList) && !count($fiscalList)) {
                 throw new \RuntimeException('Entity not selected.');
             }
             $wrapperPredicate = new Predicate();
             $checkAddOr = false;
             // apartment
             if (count($apartmentIdList)) {
                 $predicate = new Predicate();
                 $predicate->in(DbTables::TBL_BOOKINGS . '.apartment_id_origin', $apartmentIdList)->lessThan(DbTables::TBL_BOOKINGS . '.apartel_id', 1);
                 $wrapperPredicate->addPredicate($predicate);
                 $checkAddOr = true;
             }
             // apartel
             if (count($apartelIdList)) {
                 if ($checkAddOr) {
                     $wrapperPredicate->or;
                 }
                 $checkAddOr = true;
                 $wrapperPredicate->in(DbTables::TBL_BOOKINGS . '.apartel_id', $apartelIdList);
             }
             // fiscal
             if (count($fiscalList)) {
                 if ($checkAddOr) {
                     $wrapperPredicate->or;
                 }
                 $wrapperPredicate->in('fiscal.id', $fiscalList);
             }
             $where->addPredicate($wrapperPredicate);
         }
     }
     $reservations = $bookingDao->getPayToPartnerReservationsByFilter($where);
     $reservationList = [];
     if ($reservations->count()) {
         foreach ($reservations as $reservation) {
             array_push($reservationList, ['id' => $reservation->getReservationId(), 'res_number' => $reservation->getReservationNumber(), 'status' => $reservation->getStatus(), 'apartel_id' => $reservation->getApartelId(), 'booking_date' => $reservation->getBookingDate(), 'departure_date' => $reservation->getDepartureDate(), 'apartment_id' => $reservation->getApartmentId(), 'apartment_name' => $reservation->getApartmentName(), 'partner_id' => $reservation->getPartnerId(), 'partner_name' => $reservation->getPartnerName(), 'guest_balance' => $reservation->getGuestBalance(), 'partner_balance' => $reservation->getPartnerBalance(), 'symbol' => $reservation->getSymbol(), 'currency_id' => $reservation->getCurrencyId()]);
         }
     }
     return $reservationList;
 }