Advertisement
wiby15

report_form_id

Oct 31st, 2019
244
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MySQL 11.17 KB | None | 0 0
  1. CREATE VIEW report_form_id as
  2. select
  3. ifnull(ufd.uid, '') as 'UID',
  4. ifnull(ufd.name, '') as 'Customer',
  5. ifnull(csfd.name, '') as 'Store',
  6. ifnull(csfd.code, '') as 'Kode Toko Apps',
  7. ifnull(pcontact.handphone_value, '') as 'HP',
  8. ifnull(pcontact.phone_value, '') as 'Telepon',
  9. ifnull(creator.creator_name, '') as 'BDS Creator',
  10. ifnull(sapi.sales_name, '') as 'BDS Update',
  11. ifnull(ifnull(sapi.sales_name, creator.creator_name), '') as 'BDS',
  12. ifnull(ifnull(sapi.region_name, creator.region_name), '') as 'Wilayah',
  13. ifnull(ifnull(sapi.area_locality, creator.area_locality), '') as 'Area',
  14. ifnull(ur.roles_target_id, 'buyer') as 'Roles',
  15. ifnull(paddress.address_administrative_area, '') as 'Provinsi Profile',
  16. ifnull(paddress.address_locality, '') as 'Kab/Kota Profile',
  17. ifnull(csfd.address__administrative_area, '') as 'Provinsi Store',
  18. ifnull(csfd.address__locality, '') as 'Kab/Kota Store',
  19. ifnull(cil.address__administrative_area, '') as 'Provinsi Gudang',
  20. ifnull(cil.address__locality, '') as 'Kab/Kota Gudang',
  21. ifnull(csfd.minimum_order_amount__number, '') as 'Minimal Kirim',
  22. ifnull(csmwd.max_wheel_distance_number, '') as 'Maksimal Jarak Kirim',
  23. ifnull(csmwd.max_wheel_distance_unit, '') as 'Unit Jarak',
  24. ifnull(ufd.mail, '') as 'Email User', ifnull(csfd.mail, '') as 'Email Toko',
  25. ifnull(pbank.bank_name, '') as 'Bank Name',
  26. ifnull(pbank.account_number, '') as 'Account No',
  27. ifnull(pbank.account_name, '') as 'Registered Name',
  28. ifnull(pplace_new.place_of_birth_value, '') as 'Tempat Lahir',
  29. ifnull(DATE_FORMAT(STR_TO_DATE(pdob_new.date_of_birth_value, '%Y-%m-%d'), '%Y/%m/%d'), '') as 'Tanggal Lahir',
  30. ifnull(preligion_new.religion_value, '') as 'Agama',
  31. ifnull(paddress.address_address_line1, '') as 'Alamat Customer',
  32. ifnull(csfd.address__address_line1, '') as 'Alamat Store',
  33. ifnull(pcompany.full_name_value, '') as 'Company Name',
  34. ifnull(pcompany.company_type_value, '') as 'Company Type',
  35. ifnull(pcompany.tax_status_value, '') as 'Tax Status',
  36. MONTH(from_unixtime(LEAST(
  37.     COALESCE(seller_table.seller_completed_min,buyer_table.buyer_completed_min,ufd.created),
  38.     COALESCE(buyer_table.buyer_completed_min,ufd.created,seller_table.seller_completed_min),
  39.     COALESCE(ufd.created,seller_table.seller_completed_min,buyer_table.buyer_completed_min))) + interval 7 hour) as 'Joint Month',
  40. ifnull(paddress.location_lon, '') as 'Longitude Profile',
  41. ifnull(paddress.location_lat, '') as 'Latitude Profile',
  42. ifnull(cil.location__lon, '') as 'Longitude Gudang',
  43. ifnull(cil.location__lat, '') as 'Latitude Gudang',
  44. ifnull(pktp.id_number_value, '') as 'ID KTP',
  45. ifnull(pnpwp.id_number_value, '') as 'NPWP',
  46. ifnull(ptransport.name, '') as 'Transportation Type',
  47. ifnull(ud.value, '') as 'Wallet Balance',
  48. if (seller_table.seller_id is not null, 'Pernah Jual', 'Belum Pernah Jual') as 'Status Jual',
  49. if (buyer_table.buyer_id is not null, 'Pernah Beli', 'Belum Pernah Beli') as 'Status Beli',
  50. if (buyer_table.buyer_id is not null || seller_table.seller_id is not null, 'Pernah Transaksi', 'Belum Pernah Transaksi') as 'Status Transaksi',
  51. ifnull(DATE_FORMAT(from_unixtime(seller_table.seller_completed) + interval 7 hour, '%Y/%m/%d'), '') as 'Seller Last Date Order',
  52. ifnull(DATE_FORMAT(from_unixtime(buyer_table.buyer_completed) + interval 7 hour, '%Y/%m/%d'), '') as 'Buyer Last Date Order',
  53. ifnull(if ((seller_table.seller_completed >= buyer_table.buyer_completed || buyer_table.buyer_completed is null), DATE_FORMAT(from_unixtime(seller_table.seller_completed) + interval 7 hour, '%Y/%m/%d'), DATE_FORMAT(from_unixtime(buyer_table.buyer_completed) + interval 7 hour, '%Y/%m/%d')), '') as 'Last Date Transaksi',
  54. if (ufd.login > 0, DATE_FORMAT(FROM_UNIXTIME(ufd.login) + interval 7 hour, '%Y/%m/%d'), '') as 'Last Login',
  55. ifnull(DATE_FORMAT(from_unixtime(LEAST(ifnull(seller_table.seller_completed_min,buyer_table.buyer_completed_min),ifnull(buyer_table.buyer_completed_min,seller_table.seller_completed_min))) + interval 7 hour, '%Y/%m/%d'), '') as 'Tanggal Transaksi Pertama',
  56. DATE_FORMAT(from_unixtime(LEAST(
  57.     COALESCE(seller_table.seller_completed_min,buyer_table.buyer_completed_min,ufd.created),
  58.     COALESCE(buyer_table.buyer_completed_min,ufd.created,seller_table.seller_completed_min),
  59.     COALESCE(ufd.created,seller_table.seller_completed_min,buyer_table.buyer_completed_min))) + interval 7 hour, '%Y/%m/%d') as 'Member From',
  60. ifnull(new_pn.seller_private_network, '') as 'Seller Private Network'
  61. from
  62. users_field_data ufd
  63. left join (select uc.entity_id, ufd_creator.name as 'creator_name', sr.name as 'region_name', sa.name as 'area_locality'
  64.     from user__creator uc
  65.     left join users_field_data ufd_creator
  66.     on uc.creator_target_id = ufd_creator.uid
  67.     left join sales_region__supervisor_id srsi
  68.     on ufd_creator.uid = srsi.supervisor_id_target_id
  69.     left join sales_region sr
  70.     on srsi.entity_id = sr.id
  71.     left join sales_area__sales_region sasr
  72.     on sr.id = sasr.sales_region_target_id
  73.     left join sales_area sa
  74.     on sasr.entity_id = sa.id) creator
  75. on ufd.uid = creator.entity_id
  76. left join (select us.entity_id, ufd_sales.name as 'sales_name', sr.name as 'region_name', sa.name as 'area_locality'
  77.     from user__sales us
  78.     left join users_field_data ufd_sales
  79.     on us.sales_target_id = ufd_sales.uid
  80.     left join sales_region__supervisor_id srsi
  81.     on ufd_sales.uid = srsi.supervisor_id_target_id
  82.     left join sales_region sr
  83.     on srsi.entity_id = sr.id
  84.     left join sales_area__sales_region sasr
  85.     on sr.id = sasr.sales_region_target_id
  86.     left join sales_area sa
  87.     on sasr.entity_id = sa.id) sapi
  88. on ufd.uid = sapi.entity_id
  89. left join commerce_store_field_data csfd
  90. on ufd.uid = csfd.uid
  91. left join commerce_store__commerce_inventory_locations cscil
  92. on csfd.store_id = cscil.entity_id
  93. left join commerce_inventory_location cil
  94. on cscil.commerce_inventory_locations_target_id = cil.id
  95. left join (select csfd_seller.uid as 'seller_id', csfd_seller.store_id as 'seller_store_id', co_seller.state as 'status', max(co_seller.completed) as 'seller_completed', min(co_seller.completed) as 'seller_completed_min'
  96.     from
  97.     commerce_store_field_data csfd_seller
  98.     left join commerce_order co_seller
  99.     on csfd_seller.store_id = co_seller.store_id
  100.     where co_seller.state = 'completed'
  101.     group by csfd_seller.uid) seller_table
  102. on ufd.uid = seller_table.seller_id
  103. left join (select co_buyer.uid as 'buyer_id', csfd_buyer.store_id as 'buyer_store_id', co_buyer.state as 'status', max(co_buyer.completed) as 'buyer_completed', min(co_buyer.completed) as 'buyer_completed_min'
  104.     from
  105.     commerce_store_field_data csfd_buyer
  106.     left join commerce_order co_buyer
  107.     on csfd_buyer.store_id = co_buyer.store_id
  108.     where co_buyer.state = 'completed'
  109.     group by co_buyer.uid) buyer_table
  110. on ufd.uid = buyer_table.buyer_id
  111. left join user__roles ur
  112. on ufd.uid = ur.entity_id
  113. left join commerce_store__max_wheel_distance csmwd
  114. on csfd.store_id = csmwd.entity_id
  115. left join (select p.uid, pa.address_administrative_area, pa.address_locality, pa.address_address_line1,
  116.     pl.location_value, pl.location_lat, pl.location_lon
  117.     from
  118.     profile p
  119.     left join profile__address pa
  120.     on p.profile_id = pa.entity_id
  121.     left join profile__location pl
  122.     on p.profile_id = pl.entity_id where p.status = 1 AND p.is_default = 1 and p.type = 'customer') paddress
  123. on ufd.uid = paddress.uid
  124. left join (select
  125.         p.uid,
  126.         group_concat(b.name SEPARATOR '|') as bank_name,
  127.         group_concat(pba.bank_account_account_number SEPARATOR '|') as account_number,
  128.         group_concat(pba.bank_account_account_name SEPARATOR '|') as account_name
  129.     from profile p
  130.     left join profile__bank_account pba
  131.     on p.profile_id = pba.entity_id
  132.     left join bank b
  133.     on pba.bank_account_bank_id = b.id
  134.     where p.status = 1 and p.type = 'finance'
  135.     group by p.uid) pbank
  136. on ufd.uid = pbank.uid
  137. left join (select p.uid, pfn.full_name_value, pct.company_type_value, pts.tax_status_value
  138.     from profile p
  139.     left join profile__full_name pfn
  140.     on p.profile_id = pfn.entity_id
  141.     left join profile__company_type pct
  142.     on p.profile_id = pct.entity_id
  143.     left join profile__tax_status pts
  144.     on p.profile_id = pts.entity_id
  145.     where p.status = 1 AND p.is_default = 1 and p.type = 'company') pcompany
  146. on ufd.uid = pcompany.uid
  147. left join (select p.uid, pin.id_number_value
  148.     from profile p
  149.     left join profile__id_type pit
  150.     on p.profile_id = pit.entity_id
  151.     left join profile__id_number pin
  152.     on p.profile_id = pin.entity_id
  153.     where p.status = 1 and pit.id_type_value = 'ktp' and pin.id_number_value is not null
  154.     limit 1) pktp
  155. on ufd.uid = pktp.uid
  156. left join (select p.uid, pin.id_number_value
  157.     from profile p
  158.     left join profile__id_type pit
  159.     on p.profile_id = pit.entity_id
  160.     left join profile__id_number pin
  161.     on p.profile_id = pin.entity_id
  162.     where p.status = 1 and pit.id_type_value = 'npwp' and pin.id_number_value is not null
  163.     limit 1) pnpwp
  164. on ufd.uid = pnpwp.uid
  165. left join (select p.uid, ph.handphone_value, pp.phone_value
  166.     from profile p
  167.     left join profile__handphone ph
  168.     on p.profile_id = ph.entity_id
  169.     left join profile__phone pp
  170.     on p.profile_id = pp.entity_id
  171.     where p.status = 1 AND p.is_default = 1 and p.type = 'customer'
  172.     order by p.uid) pcontact
  173. on ufd.uid = pcontact.uid
  174. left join (select p.uid, pplace.place_of_birth_value
  175.     from profile p
  176.     left join profile__place_of_birth pplace
  177.     on p.profile_id = pplace.entity_id
  178.     where p.status = 1 AND p.is_default = 1 and p.type = 'customer') pplace_new
  179. on ufd.uid = pplace_new.uid
  180. left join (select p.uid, preligion.religion_value
  181.     from profile p
  182.     left join profile__religion preligion
  183.     on p.profile_id = preligion.entity_id
  184.     where p.type = 'customer' AND p.status = 1 AND p.is_default = 1) preligion_new
  185. on ufd.uid = preligion_new.uid
  186. left join (select p.uid, pdob.date_of_birth_value
  187.     from profile p
  188.     left join profile__date_of_birth pdob
  189.     on p.profile_id = pdob.entity_id
  190.     where p.type = 'customer' AND p.status = 1 AND p.is_default = 1) pdob_new
  191. on ufd.uid = pdob_new.uid
  192. left join (select group_concat(distinct csfd.name) as 'seller_private_network', upns.entity_id as 'private_network_seller_id'
  193.     from commerce_store_field_data csfd
  194.     left join user__private_network_stores upns
  195.     on csfd.store_id = upns.private_network_stores_target_id
  196.     group by upns.entity_id) new_pn
  197. on ufd.uid = new_pn.private_network_seller_id
  198. left join (select p.uid, group_concat(distinct ttfd.name) as name
  199.     from profile p
  200.     left join profile__transportation_type ptt
  201.     on p.profile_id = ptt.entity_id
  202.     left join taxonomy_term_field_data ttfd
  203.     on ptt.transportation_type_target_id = ttfd.tid
  204.     where p.status = 1 and ptt.bundle = 'customer'
  205.     group by p.uid) ptransport
  206. on ufd.uid = ptransport.uid
  207. left join users_data ud
  208. on ufd.uid = ud.uid and ud.name = 'wallet_balance'
  209. left join (select u_roles.entity_id from user__roles u_roles
  210.     where u_roles.roles_target_id in('administrator', 'ops', 'bd', 'customer_service', 'tester')
  211. ) x_roles
  212. on ufd.uid = x_roles.entity_id
  213. where x_roles.entity_id is null
  214. and ufd.uid != 0
  215. and (creator.creator_name is not null
  216.     or sapi.sales_name is not null);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement