"ROUTINE_DEFINITION":"begin\n\n declare _contracts_done, _events_done, _mappings_done, _is_end boolean default false;\n declare _contract_id, _bm_id, _default_bm_id, _profile_id, _network_id int(11) unsigned;\n declare _t, _start_date, _end_date datetime;\n declare _effective_start_time decimal(13,3);\n declare _bm_ids, _old_bm_ids varchar(65535);\n\n declare contracts_cur cursor for select bm.contract_id\n from billing_mappings bm left join contracts_billing_profile_network cbpn on bm.contract_id = cbpn.contract_id\n where cbpn.id is null group by bm.contract_id;\n declare continue handler for not found set _contracts_done = true;\n\n set _old_bm_ids = \"\";\n\n open contracts_cur;\n contracts_loop: loop\n fetch contracts_cur into _contract_id;\n if _contracts_done then\n leave contracts_loop;\n end if;\n nested1: begin\n\n declare events_cur cursor for select t,is_end from (\n (select coalesce(bm.start_date,from_unixtime(0)) as t, 0 as is_end\n from billing_mappings bm join contracts c on bm.contract_id = c.id where contract_id = _contract_id)\n union all\n (select coalesce(end_date,from_unixtime(2147483647) - 0.001) as t, 1 as is_end from billing_mappings where contract_id = _contract_id)\n ) as events group by t, is_end order by t, is_end;\n declare continue handler for not found set _events_done = true;\n\n set _events_done = false;\n open events_cur;\n events_loop: loop\n fetch events_cur into _t, _is_end;\n if _events_done then\n leave events_loop;\n end if;\n\n nested2: begin\n\n declare mappings_cur cursor for select bm1.id, bm1.start_date, bm1.end_date, bm1.billing_profile_id, bm1.network_id from\n billing_mappings bm1 where bm1.contract_id = _contract_id and bm1.start_date <=> (select bm2.start_date\n from billing_mappings bm2 where\n bm2.contract_id = _contract_id\n and (bm2.start_date <= _t or bm2.start_date is null)\n and (if(_is_end,bm2.end_date > _t,bm2.end_date >= _t) or bm2.end_date is null)\n order by bm2.start_date desc limit 1) order by bm1.id asc;\n declare continue handler for not found set _mappings_done = true;\n\n set _effective_start_time = (select unix_timestamp(if(_is_end,_t + 0.001,_t)));\n set _bm_ids = \"\";\n set _mappings_done = false;\n open mappings_cur;\n mappings_loop1: loop\n fetch mappings_cur into _bm_id, _start_date, _end_date, _profile_id, _network_id;\n if _mappings_done then\n leave mappings_loop1;\n end if;\n set _bm_ids = (select concat(_bm_ids,\"-\",_bm_id));\n set _default_bm_id = _bm_id;\n end loop mappings_loop1;\n close mappings_cur;\n\n if _old_bm_ids != _bm_ids then\n set _mappings_done = false;\n open mappings_cur;\n mappings_loop2: loop\n fetch mappings_cur into _bm_id, _start_date, _end_date, _profile_id, _network_id;\n if _mappings_done then\n leave mappings_loop2;\n end if;\n\n call add_contract_billing_profile_network_schedule(_contract_id,if(_bm_id = _default_bm_id,1,0),_start_date,_end_date,\n _effective_start_time,_profile_id,_network_id);\n\n end loop mappings_loop2;\n close mappings_cur;\n end if;\n set _old_bm_ids = _bm_ids;\n end nested2;\n end loop events_loop;\n close events_cur;\n end nested1;\n end loop contracts_loop;\n close contracts_cur;\nend",
"ROUTINE_DEFINITION":"begin\n\n declare _contracts_done, _events_done, _mappings_done, _is_end boolean default false;\n declare _contract_id, _bm_id, _default_bm_id, _profile_id, _network_id int(11) unsigned;\n declare _t, _start_date, _end_date datetime;\n declare _effective_start_time decimal(13,3);\n declare _bm_ids, _old_bm_ids varchar(65535);\n\n declare contracts_cur cursor for select bm.contract_id\n from billing_mappings bm left join contracts_billing_profile_network cbpn on bm.contract_id = cbpn.contract_id\n where cbpn.id is null group by bm.contract_id;\n declare continue handler for not found set _contracts_done = true;\n\n set _old_bm_ids = \"\";\n\n open contracts_cur;\n contracts_loop: loop\n fetch contracts_cur into _contract_id;\n if _contracts_done then\n leave contracts_loop;\n end if;\n nested1: begin\n\n declare events_cur cursor for select t,is_end from (\n (select coalesce(bm.start_date,from_unixtime(0)) as t, 0 as is_end\n from billing_mappings bm join contracts c on bm.contract_id = c.id where contract_id = _contract_id)\n union all\n (select coalesce(end_date,from_unixtime(2147483647) - 0.001) as t, 1 as is_end from billing_mappings where contract_id = _contract_id)\n ) as events group by t, is_end order by t, is_end;\n declare continue handler for not found set _events_done = true;\n\n set _events_done = false;\n open events_cur;\n events_loop: loop\n fetch events_cur into _t, _is_end;\n if _events_done then\n leave events_loop;\n end if;\n\n nested2: begin\n\n declare mappings_cur cursor for select bm1.id, bm1.start_date, bm1.end_date, bm1.billing_profile_id, bm1.network_id from\n billing_mappings bm1 where bm1.contract_id = _contract_id and bm1.start_date <=> (select bm2.start_date\n from billing_mappings bm2 where\n bm2.contract_id = _contract_id\n and (bm2.start_date <= _t or bm2.start_date is null)\n and (if(_is_end,bm2.end_date > _t,bm2.end_date >= _t) or bm2.end_date is null)\n order by bm2.start_date desc limit 1) order by bm1.id asc;\n declare continue handler for not found set _mappings_done = true;\n\n set _effective_start_time = coalesce((select unix_timestamp(if(_is_end,_t + 0.001,_t))),0);\n set _bm_ids = \"\";\n set _mappings_done = false;\n open mappings_cur;\n mappings_loop1: loop\n fetch mappings_cur into _bm_id, _start_date, _end_date, _profile_id, _network_id;\n if _mappings_done then\n leave mappings_loop1;\n end if;\n set _bm_ids = (select concat(_bm_ids,\"-\",_bm_id));\n set _default_bm_id = _bm_id;\n end loop mappings_loop1;\n close mappings_cur;\n\n if _old_bm_ids != _bm_ids then\n set _mappings_done = false;\n open mappings_cur;\n mappings_loop2: loop\n fetch mappings_cur into _bm_id, _start_date, _end_date, _profile_id, _network_id;\n if _mappings_done then\n leave mappings_loop2;\n end if;\n\n call add_contract_billing_profile_network_schedule(_contract_id,if(_bm_id = _default_bm_id,1,0),_start_date,_end_date,\n _effective_start_time,_profile_id,_network_id);\n\n end loop mappings_loop2;\n close mappings_cur;\n end if;\n set _old_bm_ids = _bm_ids;\n end nested2;\n end loop events_loop;\n close events_cur;\n end nested1;\n end loop contracts_loop;\n close contracts_cur;\nend",
INSERTINTO`email_templates`VALUES(1,NULL,'subscriber_default_email','default@sipwise.com','Subscriber created','Dear Customer,\n\nA new subscriber [% subscriber %] has been created for you.\n\nYour faithful Sipwise system\n\n-- \nThis is an automatically generated message. Do not reply.','');
INSERTINTO`email_templates`VALUES(2,NULL,'passreset_default_email','default@sipwise.com','Password reset email','Dear Customer,\n\nPlease go to [% url %] to set your password and log into your self-care interface.\n\nYour faithful Sipwise system\n\n-- \nThis is an automatically generated message. Do not reply.','');
INSERTINTO`email_templates`VALUES(3,NULL,'invoice_default_email','default@sipwise.com','Invoice #[%invoice.serial%] from [%invoice.period_start_obj.ymd%] to [%invoice.period_end_obj.ymd%]','Dear Customer,\n\nPlease find your invoice #[%invoice.serial%] for [%invoice.period_start_obj.month_name%], [%invoice.period_start_obj.year%] in attachment of this letter.\n\nYour faithful Sipwise system\n\n--\nThis is an automatically generated message. Do not reply.','');
@ -2511,12 +2572,73 @@ INSERT INTO `email_templates` VALUES (9,NULL,'fax_notify_ok_default_email','[% m
INSERTINTO`email_templates`VALUES(10,NULL,'fax_notify_error_default_email','[% mail_from %]','Fax transmission to [% callee %] has failed',' Fax from [% caller %] to [% callee %] has failed.\n\n Status: [% status %]\n Attempts: [% attempts %]\n Sent pages: [% sent_pages %] of [% pages %]\n Reason: [% reason %]\n\n--\nPlease do not reply to this auto-generated E-Mail.','');
INSERTINTO`email_templates`VALUES(11,NULL,'fax_notify_secret_update_default_email','[% mail_from %]','Preferences update notification',' Secret key for subscriber [% subscriber %] has been updated.\n\n New secret key: [% secret_key %]\n\n--\nPlease do not reply to this auto-generated E-Mail.','');
INSERTINTO`email_templates`VALUES(12,NULL,'admin_passreset_default_email','default@sipwise.com','Password reset email','Dear Customer,\n\nPlease go to [% url %] to set your password and log into your admin interface.\n\nYour faithful Sipwise system\n\n-- \nThis is an automatically generated message. Do not reply.','');