mirror of https://github.com/sipwise/ngcpcfg.git
You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
273 lines
21 KiB
273 lines
21 KiB
[%
|
|
# vi: ft=tt2
|
|
|
|
# Iterates YAML config lists and translates them into strings suitable for the
|
|
# cdr-exporter config file.
|
|
#
|
|
# @param argv.type One of 'cdr' (default), 'int_cdr', 'events'.
|
|
# @param argv.admin_export_fields
|
|
# @param argv.reseller_export_fields
|
|
# @param argv.export_joins
|
|
# @param argv.export_conditions
|
|
# @return out.admin_fields
|
|
# @return out.reseller_fields
|
|
# @return out.joins
|
|
# @return out.conditions
|
|
USE Utils;
|
|
-%]
|
|
[% MACRO cdr_direction_provider_type_select(dict_table, data_table, base_table, dict_col, val_col, direction, provider, type) BLOCK -%]
|
|
(SELECT data.[%- val_col -%] FROM accounting.[%- data_table -%] AS data INNER JOIN accounting.cdr_direction AS dir ON data.direction_id = dir.id INNER JOIN accounting.cdr_provider AS prov ON data.provider_id = prov.id INNER JOIN accounting.[%- dict_table -%] AS dict ON data.[%- dict_col -%] = dict.id WHERE data.cdr_id = [%- base_table -%].id AND dir.type = "[%- direction -%]" AND prov.type="[%- provider -%]" AND dict.type="[%- type -%]")
|
|
[%- END %]
|
|
[% MACRO cdr_direction_provider_type_select_casesensitive(dict_table, data_table, base_table, dict_col, val_col, direction, provider, type) BLOCK -%]
|
|
(SELECT data.[%- val_col -%] FROM accounting.[%- data_table -%] AS data INNER JOIN accounting.cdr_direction AS dir ON data.direction_id = dir.id INNER JOIN accounting.cdr_provider AS prov ON data.provider_id = prov.id INNER JOIN accounting.[%- dict_table -%] AS dict ON data.[%- dict_col -%] = dict.id WHERE data.cdr_id = [%- base_table -%].id AND dir.type = "[%- direction -%]" AND prov.type="[%- provider -%]" AND BINARY dict.type="[%- type -%]")
|
|
[%- END %]
|
|
[% MACRO edr_type_select(dict_table, data_table, base_table, dict_col, val_col, type) BLOCK -%]
|
|
(SELECT data.[%- val_col -%] FROM accounting.[%- data_table -%] AS data INNER JOIN accounting.[%- dict_table -%] AS dict ON data.[%- dict_col -%] = dict.id WHERE data.event_id = [%- base_table -%].id AND dict.type="[%- type -%]")
|
|
[%- END %]
|
|
[% MACRO cdr_timezone(base_table) BLOCK -%]
|
|
[%
|
|
source_subscriber_timezone = "(SELECT COALESCE((SELECT tz.name FROM billing.v_subscriber_timezone tz WHERE tz.uuid = " _ base_table _ ".source_user_id LIMIT 1),@@global.time_zone))";
|
|
destination_subscriber_timezone = "(SELECT COALESCE((SELECT tz.name FROM billing.v_subscriber_timezone tz WHERE tz.uuid = " _ base_table _ ".destination_user_id LIMIT 1),@@global.time_zone))";
|
|
transit_timezone = "(SELECT COALESCE((SELECT t.name FROM ngcp.timezone t LIMIT 1),@@global.time_zone))";
|
|
-%]
|
|
(IF([%- base_table -%].source_user_id = "0",IF([%- base_table -%].destination_user_id = "0",[%- transit_timezone -%],[%- destination_subscriber_timezone -%]),[%- source_subscriber_timezone -%]))
|
|
[%- END %]
|
|
[% MACRO edr_timezone(base_table) BLOCK -%]
|
|
(SELECT COALESCE((SELECT tz.name FROM billing.v_subscriber_timezone tz WHERE tz.subscriber_id = [%- base_table -%].subscriber_id LIMIT 1),@@global.time_zone))
|
|
[%- END %]
|
|
[% MACRO from_unixtime_tz(column, timezone) BLOCK -%]
|
|
CONVERT_TZ(FROM_UNIXTIME([%- column -%]),@@session.time_zone,[%- timezone -%])
|
|
[%- END %]
|
|
[% MACRO from_tz(column, timezone) BLOCK -%]
|
|
CONVERT_TZ([%- column -%],@@session.time_zone,[%- timezone -%])
|
|
[%- END %]
|
|
[%
|
|
|
|
out = {};
|
|
|
|
#
|
|
# Translate upper-case presets into their proper equivalents.
|
|
#
|
|
|
|
# Presets that map directly into accounting.cdr.X columns.
|
|
|
|
X_cdr_id_list = [ 'call_code', 'call_id', 'call_status', 'call_type', 'destination_account_id', 'destination_carrier_cost', 'destination_carrier_free_time', 'destination_customer_cost', 'destination_customer_free_time', 'destination_domain', 'destination_domain_in', 'destination_external_contract_id', 'destination_external_subscriber_id', 'destination_provider_id', 'destination_reseller_cost', 'destination_reseller_free_time', 'destination_user', 'destination_user_dialed', 'destination_user_id', 'destination_user_in', 'duration', 'peer_auth_realm', 'peer_auth_user', 'rated_at', 'rating_status', 'source_account_id', 'source_carrier_cost', 'source_carrier_free_time', 'source_cli', 'source_clir', 'source_customer_cost', 'source_customer_free_time', 'source_domain', 'source_external_contract_id', 'source_external_subscriber_id', 'source_ip', 'source_provider_id', 'source_reseller_cost', 'source_reseller_free_time', 'source_user', 'source_user_id', 'update_time', 'type', 'reseller_id', 'old_status', 'new_status', 'source_lnp_prefix', 'destination_lnp_prefix' ];
|
|
|
|
FOREACH X_num IN [ 0 .. 9 ];
|
|
X_cdr_id_list.push("source_gpp" _ X_num, "destination_gpp" _ X_num);
|
|
END;
|
|
|
|
X_type = argv.type;
|
|
IF X_type.length == 0;
|
|
X_type = 'cdr';
|
|
END;
|
|
X_base_type = X_type.remove('^int_');
|
|
|
|
X_cdr_id_map = {};
|
|
|
|
FOREACH X_col IN X_cdr_id_list;
|
|
X_upc = X_col.upper;
|
|
X_cdr_id_map.$X_upc = "base_table." _ X_col;
|
|
END;
|
|
|
|
# Other presets
|
|
# cdr fields:
|
|
X_cdr_id_map.CDR_ID = "base_table.id";
|
|
X_cdr_id_map.EVENT_ID = "base_table.id";
|
|
|
|
X_cdr_id_map.SOURCE_SUBSCRIBER_ID = "source_voip_subscribers.id";
|
|
X_cdr_id_map.DESTINATION_SUBSCRIBER_ID = "destination_voip_subscribers.id";
|
|
X_cdr_id_map.INIT_TIME = "CONCAT(FROM_UNIXTIME(FLOOR(base_table.init_time)), \".\", SUBSTRING_INDEX(base_table.init_time, \".\", -1)) as cdr_init_time";
|
|
X_cdr_id_map.START_TIME = "CONCAT(FROM_UNIXTIME(FLOOR(base_table.start_time)), \".\", SUBSTRING_INDEX(base_table.start_time, \".\", -1)) as cdr_start_time";
|
|
X_cdr_id_map.END_TIME = "CONCAT(FROM_UNIXTIME(FLOOR(base_table.start_time + base_table.duration)), \".\", SUBSTRING_INDEX(base_table.start_time + base_table.duration, \".\", -1)) as cdr_end_time";
|
|
X_cdr_id_map.INIT_TIME_TRUNCATED = "FROM_UNIXTIME(FLOOR(base_table.init_time)) as cdr_init_time_truncated";
|
|
X_cdr_id_map.START_TIME_TRUNCATED = "FROM_UNIXTIME(FLOOR(base_table.start_time)) as cdr_start_time_truncated";
|
|
X_cdr_id_map.END_TIME_TRUNCATED = "FROM_UNIXTIME(FLOOR(base_table.start_time + base_table.duration)) as cdr_end_time_truncated";
|
|
X_cdr_id_map.SOURCE_CARRIER_ZONE = "COALESCE(source_carrier_bbz.zone, \"onnet\")";
|
|
X_cdr_id_map.SOURCE_CARRIER_DETAIL = "COALESCE(source_carrier_bbz.detail, \"platform internal\")";
|
|
X_cdr_id_map.SOURCE_CUSTOMER_ZONE = "source_customer_bbz.zone";
|
|
X_cdr_id_map.SOURCE_CUSTOMER_DETAIL = "source_customer_bbz.detail";
|
|
X_cdr_id_map.DESTINATION_CARRIER_ZONE = "destination_carrier_bbz.zone";
|
|
X_cdr_id_map.DESTINATION_CUSTOMER_ZONE = "destination_customer_bbz.zone";
|
|
X_cdr_id_map.DESTINATION_CARRIER_DETAIL = "destination_carrier_bbz.detail";
|
|
X_cdr_id_map.DESTINATION_CUSTOMER_DETAIL = "destination_customer_bbz.detail";
|
|
X_cdr_id_map.SOURCE_RESELLER_ZONE = "source_reseller_bbz.zone";
|
|
X_cdr_id_map.SOURCE_RESELLER_DETAIL = "source_reseller_bbz.detail";
|
|
X_cdr_id_map.DESTINATION_RESELLER_ZONE = "destination_reseller_bbz.zone";
|
|
X_cdr_id_map.DESTINATION_RESELLER_DETAIL = "destination_reseller_bbz.detail";
|
|
X_cdr_id_map.CONTRACT_EXTERNAL_ID = "billing.contracts.external_id";
|
|
X_cdr_id_map.COMPANY = "billing.contacts.company";
|
|
X_cdr_id_map.SUBSCRIBER_EXTERNAL_ID = "billing.voip_subscribers.external_id";
|
|
X_cdr_id_map.SOURCE_LNP_PREFIX = "base_table.source_lnp_prefix";
|
|
X_cdr_id_map.DESTINATION_LNP_PREFIX = "base_table.destination_lnp_prefix";
|
|
X_cdr_id_map.SOURCE_USER_OUT = "base_table.source_user_out";
|
|
X_cdr_id_map.DESTINATION_USER_OUT = "base_table.destination_user_out";
|
|
X_cdr_id_map.SOURCE_LNP_TYPE = "base_table.source_lnp_type";
|
|
X_cdr_id_map.DESTINATION_LNP_TYPE = "base_table.destination_lnp_type";
|
|
|
|
X_cdr_id_map.TIMEZONE = cdr_timezone("base_table") _ " as cdr_timezone";
|
|
|
|
X_cdr_id_map.UPDATE_TIME_LOCALIZED = from_tz("base_table.update_time",cdr_timezone("base_table"));
|
|
|
|
X_cdr_id_map.INIT_TIME_LOCALIZED = "CONCAT(" _ from_unixtime_tz("FLOOR(base_table.init_time)",cdr_timezone("base_table")) _ ", \".\", SUBSTRING_INDEX(base_table.init_time, \".\", -1)) as cdr_init_time_localized";
|
|
X_cdr_id_map.START_TIME_LOCALIZED = "CONCAT(" _ from_unixtime_tz("FLOOR(base_table.start_time)",cdr_timezone("base_table")) _ ", \".\", SUBSTRING_INDEX(base_table.start_time, \".\", -1)) as cdr_start_time_localized";
|
|
X_cdr_id_map.END_TIME_LOCALIZED = "CONCAT(" _ from_unixtime_tz("FLOOR(base_table.start_time + base_table.duration)",cdr_timezone("base_table")) _ ", \".\", SUBSTRING_INDEX(base_table.start_time + base_table.duration, \".\", -1)) as cdr_end_time_localized";
|
|
|
|
X_cdr_id_map.INIT_TIME_LOCALIZED_TRUNCATED = from_unixtime_tz("FLOOR(base_table.init_time)",cdr_timezone("base_table")) _ " as cdr_init_time_localized_truncated";
|
|
X_cdr_id_map.START_TIME_LOCALIZED_TRUNCATED = from_unixtime_tz("FLOOR(base_table.start_time)",cdr_timezone("base_table")) _ " as cdr_start_time_localized_truncated";
|
|
X_cdr_id_map.END_TIME_LOCALIZED_TRUNCATED = from_unixtime_tz("FLOOR(base_table.start_time + base_table.duration)",cdr_timezone("base_table")) _ " as cdr_end_time_localized_truncated";
|
|
|
|
X_cdr_id_map.FURNISHED_CHARGING_INFO = "COALESCE(" _ cdr_direction_provider_type_select("cdr_tag", "cdr_tag_data", "base_table", "tag_id", "val", "destination", "customer", "furnished_charging_info") _ ',"") as furnished_charging_info';
|
|
|
|
X_cdr_id_map.SOURCE_CONCURRENT_CALLS_COUNT = "COALESCE(" _ cdr_direction_provider_type_select("cdr_tag", "cdr_tag_data", "base_table", "tag_id", "val", "source", "customer", "concurrent_calls_count") _ ',"") as source_concurrent_calls_count';
|
|
X_cdr_id_map.SOURCE_CONCURRENT_CALLS_COUNT_CUSTOMER = "COALESCE(" _ cdr_direction_provider_type_select("cdr_tag", "cdr_tag_data", "base_table", "tag_id", "val", "source", "customer", "concurrent_calls_count_customer") _ ',"") as source_concurrent_calls_count_customer';
|
|
X_cdr_id_map.SOURCE_CONCURRENT_CALLS_QUOTA = "COALESCE(" _ cdr_direction_provider_type_select("cdr_tag", "cdr_tag_data", "base_table", "tag_id", "val", "source", "customer", "concurrent_calls_quota") _ ',"") as source_concurrent_calls_quota';
|
|
|
|
X_cdr_id_map.DESTINATION_CONCURRENT_CALLS_COUNT = "COALESCE(" _ cdr_direction_provider_type_select("cdr_tag", "cdr_tag_data", "base_table", "tag_id", "val", "destination", "customer", "concurrent_calls_count") _ ',"") as destination_concurrent_calls_count';
|
|
X_cdr_id_map.DESTINATION_CONCURRENT_CALLS_COUNT_CUSTOMER = "COALESCE(" _ cdr_direction_provider_type_select("cdr_tag", "cdr_tag_data", "base_table", "tag_id", "val", "destination", "customer", "concurrent_calls_count_customer") _ ',"") as destination_concurrent_calls_count_customer';
|
|
X_cdr_id_map.DESTINATION_CONCURRENT_CALLS_QUOTA = "COALESCE(" _ cdr_direction_provider_type_select("cdr_tag", "cdr_tag_data", "base_table", "tag_id", "val", "destination", "customer", "concurrent_calls_quota") _ ',"") as destination_concurrent_calls_quota';
|
|
|
|
X_cdr_id_map.HG_EXT_RESPONSE = "COALESCE(" _ cdr_direction_provider_type_select("cdr_tag", "cdr_tag_data", "base_table", "tag_id", "val", "destination", "customer", "hg_ext_response") _ ',"") as hg_ext_response';
|
|
|
|
# edr fields:
|
|
#X_cdr_id_map.PRIMARY_NUMBER = "(select username from provisioning.voip_dbaliases tmp where tmp.subscriber_id = provisioning.voip_subscribers.id order by is_primary, id limit 1)";
|
|
X_cdr_id_map.PILOT_SUBSCRIBER_ID = edr_type_select(X_base_type _ "_relation","events_relation_data","base_table","relation_id","val","pilot_subscriber_id");
|
|
X_cdr_id_map.PRIMARY_NUMBER = "CONCAT(IFNULL(" _ edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","primary_number_cc") _ ',""),IFNULL(' _ edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","primary_number_ac") _ ',""),IFNULL(' _ edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","primary_number_sn") _ ',""))';
|
|
X_cdr_id_map.PRIMARY_NUMBER_ID = edr_type_select(X_base_type _ "_relation","events_relation_data","base_table","relation_id","val","primary_number_id");
|
|
X_cdr_id_map.PILOT_PRIMARY_NUMBER = "CONCAT(IFNULL(" _ edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","pilot_primary_number_cc") _ ',""),IFNULL(' _ edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","pilot_primary_number_ac") _ ',""),IFNULL(' _ edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","pilot_primary_number_sn") _ ',""))';
|
|
X_cdr_id_map.PILOT_PRIMARY_NUMBER_ID = edr_type_select(X_base_type _ "_relation","events_relation_data","base_table","relation_id","val","pilot_primary_number_id");
|
|
X_cdr_id_map.OLD_PROFILE_NAME = "old_profile.name";
|
|
X_cdr_id_map.NEW_PROFILE_NAME = "new_profile.name";
|
|
X_cdr_id_map.SUBSCRIBER_PROFILE_NAME = edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","subscriber_profile_name");
|
|
X_cdr_id_map.SUBSCRIBER_PROFILE_ID = edr_type_select(X_base_type _ "_relation","events_relation_data","base_table","relation_id","val","subscriber_profile_id");
|
|
X_cdr_id_map.SUBSCRIBER_PROFILE_SET_NAME = edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","subscriber_profile_set_name");
|
|
X_cdr_id_map.SUBSCRIBER_PROFILE_SET_ID = edr_type_select(X_base_type _ "_relation","events_relation_data","base_table","relation_id","val","subscriber_profile_set_id");
|
|
X_cdr_id_map.PILOT_SUBSCRIBER_PROFILE_NAME = edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","pilot_subscriber_profile_name");
|
|
X_cdr_id_map.PILOT_SUBSCRIBER_PROFILE_ID = edr_type_select(X_base_type _ "_relation","events_relation_data","base_table","relation_id","val","pilot_subscriber_profile_id");
|
|
X_cdr_id_map.PILOT_SUBSCRIBER_PROFILE_SET_NAME = edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","pilot_subscriber_profile_set_name");
|
|
X_cdr_id_map.PILOT_SUBSCRIBER_PROFILE_SET_ID = edr_type_select(X_base_type _ "_relation","events_relation_data","base_table","relation_id","val","pilot_subscriber_profile_set_id");
|
|
X_cdr_id_map.FIRST_NON_PRIMARY_ALIAS_USERNAME_BEFORE = edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","first_non_primary_alias_username_before");
|
|
X_cdr_id_map.FIRST_NON_PRIMARY_ALIAS_USERNAME_AFTER = edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","first_non_primary_alias_username_after");
|
|
X_cdr_id_map.PILOT_FIRST_NON_PRIMARY_ALIAS_USERNAME_BEFORE = edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","pilot_first_non_primary_alias_username_before");
|
|
X_cdr_id_map.PILOT_FIRST_NON_PRIMARY_ALIAS_USERNAME_AFTER = edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","pilot_first_non_primary_alias_username_after");
|
|
X_cdr_id_map.NON_PRIMARY_ALIAS_USERNAME = edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","non_primary_alias_username");
|
|
X_cdr_id_map.PRIMARY_ALIAS_USERNAME_BEFORE = edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","primary_alias_username_before");
|
|
X_cdr_id_map.PRIMARY_ALIAS_USERNAME_AFTER = edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","primary_alias_username_after");
|
|
X_cdr_id_map.PILOT_PRIMARY_ALIAS_USERNAME_BEFORE = edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","pilot_primary_alias_username_before");
|
|
X_cdr_id_map.PILOT_PRIMARY_ALIAS_USERNAME_AFTER = edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","pilot_primary_alias_username_after");
|
|
|
|
X_cdr_id_map.FIRST_NON_PRIMARY_ALIAS_USERNAME_BEFORE_AFTER = "IF(" _ edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","first_non_primary_alias_username_before") _ " IS NULL," _ edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","first_non_primary_alias_username_after") _ "," _ edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","first_non_primary_alias_username_before") _ ")";
|
|
X_cdr_id_map.PILOT_FIRST_NON_PRIMARY_ALIAS_USERNAME_BEFORE_AFTER = "IF(" _ edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","pilot_first_non_primary_alias_username_before") _ " IS NULL," _ edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","pilot_first_non_primary_alias_username_after") _ "," _ edr_type_select(X_base_type _ "_tag","events_tag_data","base_table","tag_id","val","pilot_first_non_primary_alias_username_before") _ ")";
|
|
|
|
X_cdr_id_map.TIMESTAMP = "from_unixtime(base_table.timestamp)";
|
|
|
|
X_cdr_id_map.EVENT_TIMESTAMP = "CONCAT(FROM_UNIXTIME(FLOOR(base_table.timestamp)), \".\", SUBSTRING_INDEX(base_table.timestamp, \".\", -1)) as event_timestamp";
|
|
X_cdr_id_map.EVENT_TIMESTAMP_TRUNCATED = "FROM_UNIXTIME(FLOOR(base_table.timestamp)) as event_timestamp_truncated";
|
|
X_cdr_id_map.EVENT_TIMEZONE = edr_timezone("base_table") _ " as event_timezone";
|
|
X_cdr_id_map.EVENT_TIMESTAMP_LOCALIZED = "CONCAT(" _ from_unixtime_tz("FLOOR(base_table.timestamp)",edr_timezone("base_table")) _ ", \".\", SUBSTRING_INDEX(base_table.timestamp, \".\", -1)) as event_timestamp_localized";
|
|
X_cdr_id_map.EVENT_TIMESTAMP_LOCALIZED_TRUNCATED = from_unixtime_tz("FLOOR(base_table.timestamp)",edr_timezone("base_table")) _ " as event_timestamp_localized_truncated";
|
|
|
|
# Translate the fields.
|
|
|
|
out.admin_fields = [];
|
|
FOREACH X_f IN argv.admin_export_fields;
|
|
f = {};
|
|
f.name = X_f;
|
|
f.code = "";
|
|
enabled = 1;
|
|
IF ("HASH" == Utils.get_ref(X_f));
|
|
f.name = X_f.name || X_f.sql;
|
|
f.code = X_f.transformation;
|
|
IF X_f.enable && X_f.enable.lower == "yes";
|
|
enabled = 1;
|
|
ELSE;
|
|
enabled = 0;
|
|
END;
|
|
END;
|
|
# Explicitly declared fields have highest precedence:
|
|
IF X_cdr_id_map.exists(f.name.upper);
|
|
f.sql = "'" _ X_cdr_id_map.${f.name.upper} _ "'";
|
|
# Specify cash balance before/after fields like e.g. source_CuStOmEr_cash_balance_before in config.yml:
|
|
ELSIF (matches = f.name.lower.match('^([a-z]+)_([a-z]+)_([a-z_]*cash_balance)_(before|after)$'));
|
|
f.sql = "'" _ cdr_direction_provider_type_select(X_base_type _ "_cash_balance", X_type _ "_cash_balance_data", "base_table", "cash_balance_id", "val_" _ matches.3, matches.0, matches.1, matches.2) _ "'";
|
|
# Specify time balance before/after fields like e.g. source_CuStOmEr_free_time_balance_after:
|
|
ELSIF (matches = f.name.lower.match('^([a-z]+)_([a-z]+)_([a-z_]*time_balance)_(before|after)$'));
|
|
f.sql = "'" _ cdr_direction_provider_type_select(X_base_type _ "_time_balance", X_type _ "_time_balance_data", "base_table", "time_balance_id", "val_" _ matches.3, matches.0, matches.1, matches.2) _ "'";
|
|
# Specify new cdr relation fields like e.g. source_CuStOmEr_profile_package_id:
|
|
# Note: not to be used in filter conditions.
|
|
ELSIF (matches = f.name.lower.match('^([a-z]+)_([a-z]+)_(profile_package_id|contract_balance_id)$'));
|
|
f.sql = "'" _ cdr_direction_provider_type_select(X_base_type _ "_relation", X_type _ "_relation_data", "base_table", "relation_id", "val", matches.0, matches.1, matches.2) _ "'";
|
|
ELSIF (matches = f.name.match('^(?i:header)_([a-zA-Z0-9_-]+)$'));
|
|
f.sql = "'" _ cdr_direction_provider_type_select_casesensitive(X_base_type _ "_tag", X_type _ "_tag_data", "base_table", "tag_id", "val", "source", "customer", "header=" _ matches.0) _ "'";
|
|
# Lowest precedence: other cdr fields, fields joined on your own or 'calculated' (raw sql) fields...:
|
|
ELSE;
|
|
f.sql = "'" _ f.name _ "'";
|
|
END;
|
|
IF enabled;
|
|
out.admin_fields.push(f);
|
|
END;
|
|
END;
|
|
|
|
out.reseller_fields = [];
|
|
FOREACH X_f IN argv.reseller_export_fields;
|
|
f = {};
|
|
f.name = X_f;
|
|
f.code = "";
|
|
enabled = 1;
|
|
IF ("HASH" == Utils.get_ref(X_f));
|
|
f.name = X_f.name || X_f.sql;
|
|
f.code = X_f.transformation;
|
|
IF X_f.enable && X_f.enable.lower == "yes";
|
|
enabled = 1;
|
|
ELSE;
|
|
enabled = 0;
|
|
END;
|
|
END;
|
|
IF X_cdr_id_map.exists(f.name.upper);
|
|
f.sql = "'" _ X_cdr_id_map.${f.name.upper} _ "'";
|
|
ELSIF (matches = f.name.lower.match('^([a-z]+)_([a-z]+)_([a-z_]*cash_balance)_(before|after)$'));
|
|
f.sql = "'" _ cdr_direction_provider_type_select(X_base_type _ "_cash_balance", X_type _ "_cash_balance_data", "base_table", "cash_balance_id","val_" _ matches.3, matches.0, matches.1, matches.2) _ "'";
|
|
ELSIF (matches = f.name.lower.match('^([a-z]+)_([a-z]+)_([a-z_]*time_balance)_(before|after)$'));
|
|
f.sql = "'" _ cdr_direction_provider_type_select(X_base_type _ "_time_balance", X_type _ "_time_balance_data", "base_table", "time_balance_id","val_" _ matches.3, matches.0, matches.1, matches.2) _ "'";
|
|
ELSIF (matches = f.name.lower.match('^([a-z]+)_([a-z]+)_(profile_package_id|contract_balance_id)$'));
|
|
f.sql = "'" _ cdr_direction_provider_type_select(X_base_type _ "_relation", X_type _ "_relation_data", "base_table", "relation_id", "val", matches.0, matches.1, matches.2) _ "'";
|
|
ELSIF (matches = f.name.match('^(?i:header)_([a-zA-Z0-9_-]+)$'));
|
|
f.sql = "'" _ cdr_direction_provider_type_select_casesensitive(X_base_type _ "_tag", X_type _ "_tag_data", "base_table", "tag_id", "val", "source", "customer", "header=" _ matches.0) _ "'";
|
|
ELSE;
|
|
f.sql = "'" _ f.name _ "'";
|
|
END;
|
|
IF enabled;
|
|
out.reseller_fields.push(f);
|
|
END;
|
|
END;
|
|
|
|
# Build joins and conditions lists.
|
|
|
|
out.joins = [];
|
|
FOREACH X_f IN argv.export_joins;
|
|
IF X_f.alias && X_f.alias.length > 0;
|
|
X_table_spec = X_f.table _ ' ' _ X_f.alias;
|
|
ELSE;
|
|
X_table_spec = X_f.table;
|
|
END;
|
|
IF (matches = X_f.reference_column.lower.match('^(accounting\.)?' _ X_base_type _ '\.(.+)$'));
|
|
X_reference_column = "base_table." _ matches.1;
|
|
ELSE;
|
|
X_reference_column = X_f.reference_column;
|
|
END;
|
|
|
|
out.joins.push("{ '" _ X_table_spec _ "' => { '" _ X_f.key_column _ "' => '" _ X_reference_column _ "' } }");
|
|
END;
|
|
|
|
out.conditions = [];
|
|
FOREACH X_f IN argv.export_conditions;
|
|
IF (matches = X_f.column.lower.match('^(accounting\.)?' _ X_base_type _ '\.(.+)$'));
|
|
X_condition_column = "base_table." _ matches.1;
|
|
ELSE;
|
|
X_condition_column = X_f.column;
|
|
END;
|
|
out.conditions.push("{ '" _ X_condition_column _ "' => { '" _ X_f.operand _ "' => '" _ X_f.compare_value _ "' } }");
|
|
END;
|
|
|
|
-%]
|