HEX
Server: Apache/2.2.15 (CentOS)
System: Linux ip-10-0-2-146.eu-west-1.compute.internal 2.6.32-754.35.1.el6.centos.plus.x86_64 #1 SMP Sat Nov 7 11:33:42 UTC 2020 x86_64
User: root (0)
PHP: 5.6.40
Disabled: NONE
Upload Files
File: /www/exchange0old/sql/export/TK25383-export-People.sql
/* Investors */
/*--------- VALID ------------*/
SELECT 
		tr2.ref_id              as "Ex. 2.0 Related Org ID",
		IF(od_i.organisation_name = '', "Credebt Exchange Limited", od_i.organisation_name) 
		                        as "Ex. 2.0 Related Org",
		IF(tr.register_type = 1, "Organisation","People") 
		                        as "Ex. 2.0 Type",
		IF(tr2.ref_id = '','Ledger Owner','Intermediary') 
		                        as 'Ex. 2.0 Related Role', 
		"Investor"              as "Ex. 2.0 Role",
		tr.ref_id               as 'Ex. 2.0 LID',
	    tr.temp_reg_id		    as 'Ex. 2.0 SID',
		""                      as "Salutation",
		IF(tr.register_type = 1, '',
			GROUP_CONCAT(cd.first_name SEPARATOR ' & ')) as 'First Name',
		IF(tr.register_type = 1, '',
			cd.last_name)      as 'Last Name',
		CONCAT(IF(tr.register_type = 1, '',
			GROUP_CONCAT(cd.first_name SEPARATOR ' & ')),
			' ',
			IF(tr.register_type = 1, '',
			cd.last_name))	   as "People Name",
		IF(tr.register_type = 1, tr.organization_name, "") 
		                       as "Organisation Name", 
		""                     as "Title",
		cd.birth_date          as "Date of Birth",
		cm.country_name	       as 'Registration Country',
       ''                      as 'Registration Number',
       ''                      as 'VAT Number',
	   CONCAT(ad.address_phone_country,ad.address_phone_code,ad.address_phone) 
	                           as 'Phone',
	   ""                      as "Mobile",
	   ad.address_email        as "Email",
	   ""                      as "Former last name",
	   ""                      as "Notes",
	   ""                      as "PPS Number",
	   ""                      as "PPSN Document",
	   ""                      as "Photo URL",
	   ""                      as "Pronounced",
	   "Billing"               as "Address Type",
	   ad.address_line_one     as 'Address_1',
	   ad.address_line_two     as "Address_2",
	   ""                      as "Address_3",
	   ad.address_city	       as 'City',
	   ad.address_state        as 'State/County',
       ad.address_zipcode      as 'Postal Code',
       cm.country_name	       as 'Country',
	   ""                      as "CRM ID",
	   "New"                   as "Status",
	   "EUR"                   as "People Currency",
       /*IF(tr.register_type = '1', tr.organization_name,
          GROUP_CONCAT(DISTINCT CONCAT(cd.first_name, ' ', cd.last_name) SEPARATOR
	                       ' & '))						   
						       as 'Bank Account Name',*/
	   IF(bank_names.bank_name = "","Other",bank_names.bank_name) as "Bank Name",
	   "Current"			   as "Bank Account Type",
	   account_name			   as 'Bank Account Name',
	   account_no			   as 'Account Number',
	   sort_code			   as 'Sort Code',
       replace(acc.iban_code,' ','') as 'IBAN',
       replace(acc.swift_code,' ','') as 'Swift/BIC Code',
       ''					   as 'Spool Id Dec',
       ''					   as 'Spool Id Hex' 
       /*od_i.organisation_id    as 'Intermediary short ID',*/
FROM temp_registration tr
         LEFT JOIN organisation_details od_r ON od_r.user_id = tr.user_id
         LEFT JOIN investor_relation ir ON ir.investor_id = tr.temp_reg_id
         LEFT JOIN organisation_details od_i ON od_i.user_id = ir.intermediary_id
         LEFT JOIN temp_registration tr2 ON tr2.user_id = od_i.user_id
         LEFT JOIN contact_details cd ON cd.temp_reg_id = tr.temp_reg_id AND
                                         (cd.contact_flag = 3 OR (cd.contact_flag = 0 AND cd.bank_id = 0))
         LEFT JOIN address_details ad ON ad.address_id = cd.work_address_id
         LEFT JOIN country_mas cm ON cm.country_id = ad.address_country 
		 LEFT JOIN contact_details cb ON tr.temp_reg_id = cb.temp_reg_id AND cb.position = 1
		 LEFT JOIN organisation_bank_details bank ON bank.contact_id = cb.contact_id  
		 LEFT JOIN organisation_bank_account_details acc
                   ON acc.status = 0 AND bank.organisation_bank_id = acc.organisation_bank_id
		 LEFT JOIN bank_details bank_names ON bank_names.bank_id = bank.bank_id 
WHERE tr.user_type = 6
  AND tr.status IN (2, 4, 5, 6)
GROUP BY od_r.user_id
ORDER BY od_r.organisation_id;