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/TK24902-export-3.03-c-ETR Cash Receipt.sql
/* export all c-ETR Receips [IDP,PDO,TPO,ICP] (unallocated, allocated, on account, returned) from Exchange 2.0 */
/*--------- VALID ------------*/
SELECT 
organisation_details.organisation_reference_id as "Originator ID",
IF(organisation_details.organisation_trade_name,organisation_details.organisation_trade_name,organisation_details.organisation_name) as "Originator Name",
debtors_detail.debtor_reference_id as "Credebtor ID",
IF(debtors_detail.trade_name,debtors_detail.trade_name,debtors_detail.debtor_name) as "Credebtor Name",
DATE(manual_transactions.transaction_date) as "Received",
manual_transactions.manual_transaction_id as "Transaction ID",
DATE(DATE(manual_transactions.created_at)) as "Posted",
IF(manual_transactions.false_payment=0 AND manual_transactions.reconcile_ref!=0,DATE(manual_transactions.transaction_date),"") as "Closed",
IF(manual_transactions.false_payment<>0,DATE(returned_transaction.transaction_date),"") as "Returned",
IF(manual_transactions.false_payment<>0,manual_transactions.false_payment,"") as "Returned Transaction ID", 
IF(manual_transactions.transaction_type = 7 OR manual_transactions.transaction_type = 110, currencies_orig.currency_code, currencies_deb.currency_code) as "Ccy",
manual_transactions.amount as "Face Value",
IF(manual_transactions.transaction_type = 7 OR manual_transactions.transaction_type = 110, IF(currencies_orig.currency_code="EUR",1.000,currency_rates_orig.currency_rate),
	IF(currencies_deb.currency_code="EUR",1.000,currency_rates_deb.currency_rate)) as "Traded Fx",
IF(manual_transactions.transaction_type=110,1,0) as "Deposit",
/*IF(manual_transactions.is_aetr = 1, "a",IF(manual_transactions.transaction_type=7,organisation_details.etr_type,IF(manual_transactions.orpa_id,"b",organisation_details.etr_type))),*/
manual_transactions.transaction_type as "Ex20 Transaction Type",
"c" as "ETR Type" 
FROM manual_transactions 
LEFT JOIN organisation_details ON  organisation_details.user_id = manual_transactions.originator_id 
LEFT JOIN debtors_detail ON debtors_detail.debtor_id = manual_transactions.debtor_id 
LEFT JOIN currencies as currencies_deb ON currencies_deb.currency_id = debtors_detail.currency_id 
LEFT JOIN currencies as currencies_orig ON currencies_orig.currency_id = manual_transactions.currency_id 
LEFT JOIN currency_rates as currency_rates_deb ON currency_rates_deb.currency_id = debtors_detail.currency_id AND currency_rates_deb.currency_date = manual_transactions.transaction_date 
LEFT JOIN currency_rates as currency_rates_orig ON currency_rates_orig.currency_id = manual_transactions.currency_id AND currency_rates_orig.currency_date = manual_transactions.transaction_date 
LEFT JOIN manual_transactions as returned_transaction ON returned_transaction.manual_transaction_id = manual_transactions.false_payment 
LEFT JOIN organisation_currencies ON organisation_currencies.user_id = manual_transactions.originator_id AND currencies_orig.currency_id = organisation_currencies.currency_id 
LEFT JOIN organisation_currencies as oc_eur ON oc_eur.user_id = manual_transactions.originator_id AND oc_eur.currency_id=1 
WHERE manual_transactions.transaction_type IN (1,2,9,19,7,110) AND manual_transactions.is_aetr = 0 AND organisation_details.etr_type="c" AND (manual_transactions.orpa_id=0 OR manual_transactions.orpa_id IS NULL) 
/* AND manual_transactions.false_payment=0 AND manual_transactions.reconcile_ref=0 */
ORDER BY "Originator Name", "Credebtor Name";

/*---------------------*/