Advertisement
lukhor

brutal selekt

Jun 23rd, 2021
1,197
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. select distinct substring(ahp.business_key_, 7, 12)                      as number
  2.               , CASE WHEN AR.text_ IS NULL THEN 'Nový' ELSE AR.text_ END as taskStatus
  3.               , CASE
  4.                     WHEN EXISTS(select *
  5.                                 from ac_order_item a
  6.                                          left join ac_product_item p on a.product_item_id = p.product_item_id
  7.                                 where a.process_instance_id = API.id
  8.                                   and p.product_code = 'KLIMA-PREDNOSTNE-INSTALACIE') then true
  9.                     else false end                                       as priorityInstallation
  10.               , CASE
  11.                     WHEN EXISTS(select *
  12.                                 from ac_order_item a
  13.                                          left join ac_product_item p on a.product_item_id = p.product_item_id
  14.                                 where a.process_instance_id = API.id
  15.                                   and p.product_code = 'KLIMA-PREDNOSTNE-INSTALACIE') then 'áno'
  16.                     else 'nie' end                                       as priorityInstallationString
  17.               , (select first_value(item.device_name) over ()
  18.                  from ac_inventory_item item
  19.                  where item.process_instance_id = API.id)                as acType
  20.               , task.NAME_                                               as taskName
  21.               , task.start_time_                                         as taskCreated       --??
  22.               , to_char(task.start_time_, 'DD.MM.YYYY')                  as taskCreatedString --??
  23.               , task.ID_                                                 as taskId
  24.               , task.ASSIGNEE_                                           as assignee2
  25.               , task.TASK_DEF_KEY_                                       as taskDefKey
  26.               , AC.business_partner_number                               as customerOp
  27.               , concat(BPA.firstname, ' ', BPA.lastname)                 as customer
  28.               , API.created                                              as processStart
  29.               , to_char(API.created, 'DD.MM.YYYY')                       as processStartString
  30.               , ARV.text_                                                as mechanicName
  31.               , ATD.text_                                                as assignTaskDate
  32.               , AR.text_                                                 as acceptationResult
  33.               , API.id                                                   as process_id
  34.               , API.agreement_id
  35.               , REQ.text_                                                as requestId
  36.               , BPA.business_partner_number                              as businessPartnerNumber
  37.               , MADR.city                                                as city
  38.               , MADR.street                                              as street
  39.               , ADE.phone_number                                         as phoneNumber
  40.               , concat(USR.FIRST_, ' ', USR.last_)                       as assignee
  41.               , array_to_string(
  42.         (select array_agg(II.group_id_) from ACT_RU_IDENTITYLINK II where II.task_id_ = task.ID_), ' ,') as identGroup
  43. from act_hi_taskinst task
  44.          left join ACT_ID_USER USR on USR.ID_ = task.assignee_
  45.          left join act_hi_procinst ahp on task.proc_inst_id_ = ahp.id_
  46.          left join act_ru_variable ARV on ARV.proc_inst_id_ = task.proc_inst_id_ AND ARV.name_ = 'mechanicName'
  47.          left join act_ru_variable REQ on REQ.proc_inst_id_ = task.proc_inst_id_ AND REQ.name_ = 'requestId'
  48.          left join act_ru_variable ATD on ATD.proc_inst_id_ = task.proc_inst_id_ AND ATD.name_ = 'assignTaskDate'
  49.          left join act_ru_variable AR on AR.proc_inst_id_ = task.proc_inst_id_ AND AR.is_concurrent_local_ = true AND
  50.                                          AR.name_ = 'acceptationResult'
  51.          left join ac_agreement AA on AA.num = substring(ahp.business_key_, 7, 12)::bigint
  52.          left join ac_business_partner_agr BPA ON BPA.business_partner_agr_id = AA.business_partner_id
  53.          left join ac_address MADR ON MADR.address_id = BPA.main_addr_id
  54.          left join ac_process_instance API on AA.agreement_id = API.agreement_id
  55.          left join ac_delivery ADE on ADE.delivery_id = API.delivery_id
  56.          left join ac_customer AC on AC.customer_id = API.customer_id
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement