Advertisement
Guest User

Untitled

a guest
Dec 12th, 2018
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. select c.partner_status_id,c.rooms_c,c.match_type, c.users_registry_id as id, c.vat, c.address, c.base_country, c.city, c.company_type_id,
  2. c.creator_id,c.description,c.iata,c.languages,c.most_covered_countries,c.longitude,c.latitude,c.name,
  3. c.phone,c.secondary_email,c.website
  4.  from ( select c.*,
  5.     CASE WHEN (tmp2.days is false) THEN 'all'
  6.         WHEN (tmp2.rooms = 1 and tmp2.price = 1) THEN 'full'
  7.         WHEN (tmp2.rooms = 2 and tmp2.price = 1) THEN 'price'
  8.         WHEN (tmp2.rooms = 1 and tmp2.price = 2) THEN 'rooms'
  9.         WHEN (tmp2.rooms = 2 and tmp2.price = 2) THEN 'all'
  10.         ELSE null
  11.     END as match_type,
  12.     (select
  13.         CASE WHEN com.users_registry_id = p1.second_company_id and p1.status_id = ps2.partners_statuses_id THEN ps3.partners_statuses_id
  14.            ELSE p1.status_id END
  15.         from company com
  16.         left join company c2 on com.users_registry_id != c2.users_registry_id  and c2.users_registry_id = c.users_registry_id
  17.         left join partners p1 on (c2.users_registry_id = p1.first_company_id and p1.second_company_id = com.users_registry_id)
  18.             or (c2.users_registry_id = p1.second_company_id and p1.first_company_id = com.users_registry_id)
  19.         left join partners_statuses ps2 on ps2.name = 'PENDING'
  20.         left join partners_statuses ps3 on ps3.name = 'NEW'
  21.         left join partners_statuses ps4 on ps4.name = 'REMOVED'
  22.         where com.users_registry_id = :currentCompanyId) as partner_status_id,
  23.     CASE WHEN (null is not null and tmp2.rooms = 1) THEN tmp2.rooms_c
  24.         ELSE null
  25.     END as rooms_c
  26. from company c
  27. join
  28.     (select
  29.         tmp.users_registry_id as company_id, min(tmp.room_count) as rooms_c,
  30.         CASE
  31.             WHEN (select (cast(:dateTo AS date) - cast(:dateFrom AS date)) = count (*)) THEN true
  32.             ELSE false
  33.         END as days,
  34.         CASE
  35.             WHEN (null is null or sum(case when tmp.room_count >= null then 1 else 0 end) = count (*)) THEN 1
  36.             WHEN (sum(case when tmp.room_count < null  then 1 else 0 end) > 0) THEN 0
  37.             ELSE 2
  38.         END as rooms,
  39.         CASE
  40.             WHEN (11.0 is null or sum(case when tmp.min_price <= 11.0 then 1 else 0 end) = count (*)) THEN 1
  41.             WHEN (sum(case when tmp.min_price > 11.0 then 1 else 0 end) > 0)  THEN 0
  42.             ELSE 2
  43.         END as price
  44.     from (
  45.         select t.* from (select distinct
  46.             c.users_registry_id,
  47.             cast( concat_ws( '-',
  48.             pc.year,
  49.             pcd.month + 1,
  50.             pcd.day ) as date ) as c_date,
  51.             pcd.room_count,
  52.             hs.min_price,
  53.             hs.max_price
  54.         from
  55.             company c
  56.             left join company_type ct on ct.company_type_id = c.company_type_id and ct.name = 'HOTEL'
  57.             left join countries cntr on cntr.country_id = c.base_country
  58.             left join hotel_detail det on det.company_id = c.users_registry_id
  59.             left join price_calendar pc on pc.company_id = c.users_registry_id and pc.year is not null
  60.             left join price_calendar_detales pcd on pcd.price_calendar_id = pc.price_calendar_id
  61.                 and pcd.day is not null and pcd.month is not null
  62.             join hotel_seasons hs on hs.id = pcd.season_id
  63.         where 1=1
  64.         ) t
  65.             where t.c_date between :dateFrom and :dateTo
  66.         ) tmp group by tmp.users_registry_id
  67.     ) tmp2 on tmp2.company_id = c.users_registry_id) c where c.match_type is not null
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement