Пример #1
0
 /**
  * @param int $reservationId
  *
  * @return \Traversable|array
  */
 public function getFirstAccTaxCharge($reservationId)
 {
     $this->resultSetPrototype->setArrayObjectPrototype(new \DDD\Domain\Booking\ForCancelCharge());
     $result = $this->fetchAll(function (Select $select) use($reservationId) {
         $select->join(['addons' => DbTables::TBL_BOOKING_ADDONS], $this->getTable() . '.addons_type = addons.id', ['addon' => 'name', 'location_tax' => 'location_join', 'cxl_apply' => 'cxl_apply'], Select::JOIN_LEFT);
         $select->where->equalTo($this->getTable() . '.reservation_id', $reservationId);
         $select->where->equalTo($this->table . '.status', ChargeService::CHARGE_STATUS_NORMAL);
         $accOrTaxWhere = new Predicate();
         $accOrTaxWhere->in($this->table . '.addons_type', [BookingAddon::ADDON_TYPE_ACC, BookingAddon::ADDON_TYPE_PARKING, BookingAddon::ADDON_TYPE_CLEANING_FEE, BookingAddon::ADDON_TYPE_DISCOUNT, BookingAddon::ADDON_TYPE_COMPENSATION, BookingAddon::ADDON_TYPE_EXTRA_PERSON]);
         // acc or parking
         $accOrTaxWhere->OR;
         $accOrTaxWhere->notEqualTo('addons.location_join', '');
         // taxes
         $select->where->addPredicate($accOrTaxWhere);
         $select->order('id ASC');
     });
     return $result;
 }
Пример #2
0
 public function testInCreatesInPredicate()
 {
     $predicate = new Predicate();
     $predicate->in('foo.bar', array('foo', 'bar'));
     $parts = $predicate->getExpressionData();
     $this->assertEquals(1, count($parts));
     $this->assertContains('%s IN (%s, %s)', $parts[0]);
     $this->assertContains(array('foo.bar', 'foo', 'bar'), $parts[0]);
 }
Пример #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;
 }