diff --git a/db_scripts/diff/15703.down b/db_scripts/diff/15703.down new file mode 100644 index 00000000..b8d346a5 --- /dev/null +++ b/db_scripts/diff/15703.down @@ -0,0 +1,4 @@ +use billing; + +drop function if exists get_billing_profile_contract_cnt; +drop function if exists get_billing_network_contract_cnt; \ No newline at end of file diff --git a/db_scripts/diff/15703.up b/db_scripts/diff/15703.up new file mode 100644 index 00000000..b6d7d49f --- /dev/null +++ b/db_scripts/diff/15703.up @@ -0,0 +1,78 @@ +use billing; + +delimiter ;; +drop function if exists get_billing_profile_contract_cnt;; +create function get_billing_profile_contract_cnt( + _profile_id int, + _limit int +) returns int(11) +deterministic reads sql data +begin + + if _limit >= 0 then + return (select + count(1) + from (select + 1 + from billing.contracts_billing_profile_network_schedule cbpns + join billing.contracts_billing_profile_network cbpn on cbpns.profile_network_id = cbpn.id + join billing._v_actual_effective_start_time est on est.contract_id = cbpn.contract_id and cbpns.effective_start_time = est.effective_start_time + join billing.contracts as c on est.contract_id = c.id + where + cbpn.billing_profile_id = _profile_id + and c.status != 'terminated' + limit _limit) as q + ); + end if; + + return (select + count(1) + from billing.contracts_billing_profile_network_schedule cbpns + join billing.contracts_billing_profile_network cbpn on cbpns.profile_network_id = cbpn.id + join billing._v_actual_effective_start_time est on est.contract_id = cbpn.contract_id and cbpns.effective_start_time = est.effective_start_time + join billing.contracts as c on est.contract_id = c.id + where + cbpn.billing_profile_id = _profile_id + and c.status != 'terminated' + ); + +end;; + +drop function if exists get_billing_network_contract_cnt;; +create function get_billing_network_contract_cnt( + _network_id int, + _limit int +) returns int(11) +deterministic reads sql data +begin + + if _limit >= 0 then + return (select + count(1) + from (select + 1 + from billing.contracts_billing_profile_network_schedule cbpns + join billing.contracts_billing_profile_network cbpn on cbpns.profile_network_id = cbpn.id + join billing._v_actual_effective_start_time est on est.contract_id = cbpn.contract_id and cbpns.effective_start_time = est.effective_start_time + join billing.contracts as c on est.contract_id = c.id + where + cbpn.billing_network_id = _network_id + and c.status != 'terminated' + limit _limit) as q + ); + end if; + + return (select + count(1) + from billing.contracts_billing_profile_network_schedule cbpns + join billing.contracts_billing_profile_network cbpn on cbpns.profile_network_id = cbpn.id + join billing._v_actual_effective_start_time est on est.contract_id = cbpn.contract_id and cbpns.effective_start_time = est.effective_start_time + join billing.contracts as c on est.contract_id = c.id + where + cbpn.billing_network_id = _network_id + and c.status != 'terminated' + ); + +end;; + +delimiter ; \ No newline at end of file