drop function ec_gift_cert_unshipped_amount (integer);
drop function ec_cert_unshipped_one_order (integer, integer);
drop function ec_earlier_certs_on_one_order (integer, integer);
drop function ec_one_gift_cert_on_one_order (integer, integer);
drop function ec_cash_amount_to_refund (numeric, integer);
drop function ec_reinst_gift_cert_on_order (integer);
drop function gift_certificate_amount_left (integer);
drop function ec_order_amount_owed (integer);
drop function ec_gift_certificate_balance (integer);
drop trigger ec_cert_amount_remains on ec_gift_certificate_usage;
drop function trig_ec_cert_amount_remains();
drop function ec_total_refund (integer);
drop function ec_shipment_cost (integer);
drop function ec_order_cost (integer);
drop function ec_tax (numeric, numeric, integer);
drop function ec_shipment_gift_certificate (integer);
drop function ec_order_gift_cert_amount (integer);
drop function ec_shipment_tax (integer);
drop function ec_shipment_shipping (integer);
drop function ec_shipment_price (integer);
drop function ec_total_tax (integer);
drop function ec_total_shipping (integer);
drop function ec_total_price (integer);

drop table ec_automatic_email_log;
drop table ec_problems_log;
drop view ec_problem_id_sequence;
drop sequence ec_problem_id_seq;
drop trigger fin_trans_ccard_update_tr on ec_financial_transactions;
drop function fin_trans_ccard_update_tr();
drop view ec_fin_transactions_reportable;
drop table ec_financial_transactions;
drop view ec_transaction_id_sequence;
drop sequence ec_transaction_id_seq;
drop table ec_spam_log;
drop view ec_spam_id_sequence;
drop sequence ec_spam_id_seq;
drop table ec_cat_mailing_lists;
drop trigger ec_email_templates_audit_tr on ec_email_templates;
drop function ec_email_templates_audit_tr();
drop table ec_email_templates_audit;
drop table ec_email_templates;
drop view ec_email_template_id_sequence;
drop sequence ec_email_template_id_seq;
drop table ec_canned_responses;
drop view ec_canned_response_id_sequence;
drop sequence ec_canned_response_id_seq;
drop trigger ec_picklist_items_audit_tr on ec_picklist_items;
drop function ec_picklist_items_audit_tr();
drop table ec_picklist_items_audit;
drop table ec_picklist_items;
drop view ec_picklist_item_id_sequence;
drop sequence ec_picklist_item_id_seq;
drop table ec_cs_action_info_used_map;
drop table ec_customer_service_actions;
drop trigger ec_cs_issue_inserts on ec_customer_service_issues;
drop function ec_cs_issue_inserts();
drop table ec_cs_issue_type_map;
drop table ec_customer_service_issues;
drop view ec_customer_service_reps;
drop trigger ec_cs_interaction_inserts on ec_customer_serv_interactions;
drop function ec_cs_interaction_inserts();
drop table ec_customer_serv_interactions;
drop trigger ec_user_identificate_date_tr on ec_user_identification;
drop function ec_user_identificate_date_tr();
drop table ec_user_identification;
drop view ec_user_ident_id_sequence;
drop sequence ec_user_ident_id_seq;
drop view ec_interaction_id_sequence;
drop sequence ec_interaction_id_seq;
drop view ec_action_id_sequence;
drop sequence ec_action_id_seq;
drop view ec_issue_id_sequence;
drop sequence ec_issue_id_seq;
drop table ec_gift_certificate_usage;
drop function ec_gift_certificates_audit_tr();
drop table ec_gift_certificates_audit;
drop view ec_gift_certificates_issued;
drop view ec_gift_certificates_purchased;
drop view ec_gift_certificates_approved;
drop table ec_gift_certificates;
drop view ec_gift_cert_id_sequence;
drop sequence ec_gift_cert_id_seq;
drop trigger ec_offers_audit_tr on ec_offers;
drop function ec_offers_audit_tr();
drop table ec_offers_audit;
drop view ec_offers_current;
drop table ec_offers;
drop view ec_offer_sequence;
drop sequence ec_offer_seq;
drop trigger ec_retailer_locations_audit_tr on ec_retailer_locations;
drop function ec_retailer_locations_audit_tr();
drop table ec_retailer_locations_audit;
drop table ec_retailer_locations;
drop view ec_retailer_location_sequence;
drop sequence ec_retailer_location_seq;
drop trigger ec_retailers_audit_tr on ec_retailers;
drop function ec_retailers_audit_tr();
drop table ec_retailers_audit;
drop table ec_retailers;
drop view ec_retailer_sequence;
drop sequence ec_retailer_seq;
drop trigger ec_sales_tax_by_state_audit_tr on ec_sales_tax_by_state;
drop function ec_sales_tax_by_state_audit_tr();
drop table ec_sales_tax_by_state_audit;
drop table ec_sales_tax_by_state;
drop trigger ec_admin_settings_audit_tr on ec_admin_settings;
drop function ec_admin_settings_audit_tr();
drop table ec_admin_settings_audit;
drop table ec_admin_settings;
drop trigger ec_order_state_after_tr on ec_items;
drop function ec_order_state_after_tr();
drop view ec_items_money_view;
drop view ec_items_shippable;
drop view ec_items_refundable;
drop view ec_items_reportable;
drop table ec_items;
drop view ec_item_id_sequence;
drop sequence ec_item_id_seq;
drop table ec_refunds;
drop view refund_id_sequence;
drop sequence refund_id_seq;
drop trigger ec_shipments_audit_tr on ec_shipments;
drop function ec_shipments_audit_tr();
drop table ec_shipments_audit;
drop trigger ec_shipment_address_update_tr on ec_shipments;
drop function ec_shipment_address_update_tr();
drop table ec_shipments;
drop view ec_shipment_id_sequence;
drop sequence ec_shipment_id_seq;
drop view ec_orders_shippable;
drop view ec_orders_reportable;
drop table ec_orders;
drop view ec_order_id_sequence;
drop sequence ec_order_id_seq;
drop table ec_user_session_offer_codes;
drop table ec_user_session_info;
drop table ec_user_sessions;
drop view ec_user_session_sequence;
drop sequence ec_user_session_seq;
drop trigger ec_custom_p_f_values_audit_tr on ec_custom_product_field_values;
drop function ec_custom_p_f_values_audit_tr();
drop table ec_custom_p_field_values_audit;
drop table ec_custom_product_field_values;
drop trigger ec_custom_prod_fields_audit_tr on ec_custom_product_fields;
drop function ec_custom_prod_fields_audit_tr();
drop table ec_custom_product_fields_audit;
drop table ec_custom_product_fields;
drop table ec_category_template_map;
drop trigger ec_subsubcat_prod_map_audit_tr on ec_subsubcategory_product_map;
drop function ec_subsubcat_prod_map_audit_tr();
drop table ec_subsubcat_prod_map_audit;
drop table ec_subsubcategory_product_map;
drop trigger ec_subcat_prod_map_audit_tr on ec_subcategory_product_map;
drop function ec_subcat_prod_map_audit_tr();
drop table ec_subcat_prod_map_audit;
drop table ec_subcategory_product_map;
drop trigger ec_cat_prod_map_audit_tr on ec_category_product_map;
drop function ec_cat_prod_map_audit_tr();
drop table ec_category_product_map_audit;
drop table ec_category_product_map;
drop trigger ec_product_reviews_audit_tr on ec_product_reviews;
drop function ec_product_reviews_audit_tr();
drop table ec_product_reviews_audit;
drop table ec_product_reviews;
drop view ec_product_review_id_sequence;
drop sequence ec_product_review_id_seq;
drop trigger ec_product_comments_audit_tr on ec_product_comments;
drop function ec_product_comments_audit_tr();
drop table ec_product_comments_audit;
drop table ec_product_comments;
drop view ec_product_comment_id_sequence;
drop sequence ec_product_comment_id_seq;
drop trigger ec_product_links_audit_tr on ec_product_links;
drop function ec_product_links_audit_tr();
drop table ec_product_links_audit;
drop table ec_product_links;
drop trigger ec_user_class_user_audit_tr on ec_user_class_user_map;
drop function ec_user_class_user_audit_tr();
drop table ec_user_class_user_map_audit;
drop table ec_user_class_user_map;
drop view ec_recommendations_cats_view;
drop trigger ec_product_recommend_audit_tr on ec_product_recommendations;
drop function ec_product_recommend_audit_tr();
drop table ec_product_recommend_audit;
drop table ec_product_recommendations;
drop view ec_recommendation_id_sequence;
drop sequence ec_recommendation_id_seq;
drop trigger ec_product_u_c_prices_audit_tr on ec_product_user_class_prices;
drop function ec_product_u_c_prices_audit_tr();
drop table ec_product_u_c_prices_audit;
drop table ec_product_user_class_prices;
drop trigger ec_user_classes_audit_tr on ec_user_classes;
drop function ec_user_classes_audit_tr();
drop table ec_user_classes_audit;
drop table ec_user_classes;
drop view ec_user_class_id_sequence;
drop sequence ec_user_class_id_seq;
drop table ec_creditcards;
drop view ec_creditcard_id_sequence;
drop sequence ec_creditcard_id_seq;
drop table ec_addresses;
drop view ec_address_id_sequence;
drop sequence ec_address_id_seq;
drop trigger ec_product_series_map_audit_tr on ec_product_series_map;
drop function ec_product_series_map_audit_tr();
drop table ec_product_series_map_audit;
drop table ec_product_series_map;
drop trigger ec_sale_prices_audit_tr on ec_sale_prices;
drop function ec_sale_prices_audit_tr();
drop table ec_sale_prices_audit;
drop view ec_sale_prices_current;
drop table ec_sale_prices;
drop view ec_sale_price_id_sequence;
drop sequence ec_sale_price_id_seq;
drop table ec_product_purchase_comb;
drop trigger ec_products_audit_tr on ec_products;
drop function ec_products_audit_tr();
drop table ec_products_audit;
drop view ec_products_searchable;
drop view ec_products_displayable;
\i ec-product-sc-drop.sql
\i ec-product-package-drop.sql
drop table ec_products;

-- nuke all created objects
-- need to do this before nuking the type
delete from acs_objects where object_type = 'ec_product';
create function inline_0 ()
returns integer as '
begin  
        PERFORM acs_object_type__drop_type (''ec_product'', ''f''); 
	return 0;
end;' language 'plpgsql';

select inline_0 ();
drop function inline_0 ();

drop view ec_subsubcategories_augmented;
drop trigger ec_subsubcategories_audit_tr on ec_subsubcategories;
drop function ec_subsubcategories_audit_tr();
drop table ec_subsubcategories_audit;
drop table ec_subsubcategories;
drop view ec_subsubcategory_id_sequence;
drop sequence ec_subsubcategory_id_seq;
drop view ec_subcategories_augmented;
drop trigger ec_subcategories_audit_tr on ec_subcategories;
drop function ec_subcategories_audit_tr();
drop table ec_subcategories_audit;
drop table ec_subcategories;
drop view ec_subcategory_id_sequence;
drop sequence ec_subcategory_id_seq;
drop trigger ec_categories_audit_tr on ec_categories;
drop function ec_categories_audit_tr();
drop table ec_categories_audit;
drop table ec_categories;
drop view ec_category_id_sequence;
drop sequence ec_category_id_seq;
drop trigger ec_templates_audit_tr on ec_templates;
drop function ec_templates_audit_tr();
drop table ec_templates_audit;
drop table ec_templates;
drop function timespan_days(float);
drop function least(numeric,numeric);
drop view ec_template_id_sequence;
drop sequence ec_template_id_seq;

\i pl-sql-utilities-drop.sql

