tag:jbilling.tenderapp.com,2012-10-15:/discussions/questions/257-how-to-delete-a-company-from-jbillingjBilling: Discussion 2016-08-12T04:02:13Ztag:jbilling.tenderapp.com,2012-10-15:Comment/267981172013-08-06T14:10:31Z2013-08-06T14:12:34ZHow to delete a company from jbilling<div><p>Hello Eric,</p>
<p>You can try with the following SQL queries. They should be
enough for deleting a whole entity and its data:</p>
<pre>
# Removing a whole entity
# Warning! this is not deleting all the international_description columns!
# see a complement query down this file
delete from contact_map where table_id = 10 and foreign_id in (select id from base_user where entity_id = XXX);
delete from contact_map where table_id = 5 and foreign_id = XXX;
delete from contact_field where contact_id not in ( select contact_id from contact_map); -- needs optmize with exists
delete from contact where id not in ( select contact_id from contact_map); -- needs optmize with exists
delete from preference where table_id = 10 and foreign_id in (select id from base_user where entity_id = XXX);
delete from customer where user_id in ( select id from base_user where entity_id = XXX);
delete from partner_payout where partner_id in ( select p.id from partner p, base_user b where p.user_id = b.id and b.entity_id = XXX);
delete from partner where user_id in ( select id from base_user where entity_id = XXX);
delete from order_line where order_id in ( select p.id from purchase_order p, base_user b where p.user_id = b.id and b.entity_id = XXX);
delete from order_process where order_id in ( select p.id from purchase_order p, base_user b where p.user_id = b.id and b.entity_id = XXX);
delete from purchase_order where user_id in ( select id from base_user where entity_id = XXX);
delete from payment_invoice where invoice_id in ( select i.id from invoice i, base_user b where i.user_id = b.id and entity_id = XXX);
delete from invoice_line where invoice_id in ( select p.id from invoice p, base_user b where p.user_id = b.id and b.entity_id = XXX);
delete from invoice where user_id in ( select id from base_user where entity_id = XXX);
delete from partner_payout where payment_id in ( select p.id from payment p, base_user b where p.user_id = b.id and b.entity_id = XXX);
delete from payment_info_cheque where payment_id in ( select p.id from payment p, base_user b where p.user_id = b.id and b.entity_id = XXX);
delete from payment_authorization where payment_id in ( select p.id from payment p, base_user b where p.user_id = b.id and b.entity_id = XXX);
delete from payment where user_id in ( select id from base_user where entity_id = XXX);
create table id_temp ( id integer);
insert into id_temp (id)
select credit_card_id from user_credit_card_map m, base_user b where m.user_id = b.id and b.entity_id = XXX;
delete from user_credit_card_map where user_id in ( select id from base_user where entity_id = XXX);
delete from credit_card where id in ( select id from id_temp );
drop table id_temp;
delete from notification_message_arch_line where message_archive_id in ( select p.id from notification_message_arch p, base_user b where p.user_id = b.id and b.entity_id = XXX);
delete from notification_message_arch where user_id in ( select id from base_user where entity_id = XXX);
delete from user_role_map where user_id in (select id from base_user where entity_id = XXX);
delete from event_log where user_id in (select id from base_user where entity_id = XXX);
delete from report_user where user_id in (select id from base_user where entity_id = XXX);
delete from permission_user where user_id in (select id from base_user where entity_id = XXX);
delete from item_user_price where user_id in (select id from base_user where entity_id = XXX);
delete from ach where user_id in (select id from base_user where entity_id = XXX);
delete from promotion_user_map where user_id in (select id from base_user where entity_id = XXX);
delete from base_user where entity_id = XXX;
delete from item_price where item_id in ( select id from item where entity_id = XXX);
delete from item_type_map where item_id in ( select id from item where entity_id = XXX);
delete from promotion where item_id in ( select id from item where entity_id = XXX);
delete from item_type_map where type_id in ( select id from item_type where entity_id = XXX);
delete from item where entity_id = XXX;
delete from item_type where entity_id = XXX;
delete from pluggable_task_parameter where task_id in ( select id from pluggable_task where entity_id = XXX);
delete from pluggable_task where entity_id = XXX;
delete from entity_delivery_method_map where entity_id = XXX;
delete from billing_process_configuration where entity_id = XXX;
delete from notification_message_line where message_section_id in ( select s.id from notification_message_section s, notification_message n where n.entity_id = XXX and s.message_id = n.id);
delete from notification_message_section where message_id in ( select id from notification_message where entity_id = XXX);
delete from notification_message where entity_id = XXX;
delete from process_run_total where process_run_id in ( select pr.id from process_run pr, billing_process p where pr.process_id = p.id and p.entity_id = XXX);
delete from process_run where process_id in ( select id from billing_process where entity_id = XXX);
delete from billing_process where entity_id = XXX;
delete from order_period where entity_id = XXX;
delete from entity_payment_method_map where entity_id = XXX;
delete from event_log where entity_id = XXX;
delete from report_entity_map where entity_id = XXX;
delete from currency_entity_map where entity_id = XXX;
delete from ageing_entity_step where entity_id = XXX;
delete from contact_field where type_id in ( select id from contact_field_type where entity_id = XXX);
delete from contact_field_type where entity_id = XXX;
delete from preference where table_id = 5 and foreign_id = XXX;
delete from contact_map where type_id in (select id from contact_type where entity_id = XXX);
delete from contact_type where entity_id = XXX;
delete from list_field_entity where list_entity_id in ( select id from list_entity where entity_id = XXX);
delete from list_entity where entity_id = XXX;
delete from entity where id = XXX;
</pre>
<p>Hope this answers your question!</p>
<p>Let us know if we can help you with anything else.</p>
<p>Regards,</p>
<p>jBilling Technical Support Team</p></div>Technical Support