BEGIN;
CREATE OR REPLACE FUNCTION _tmp_wo(p_name text, p_seq int, p_match text, p_acct int, p_tax int, p_label text) RETURNS void AS $$
DECLARE v_mid int; v_lid int;
BEGIN
  INSERT INTO account_reconcile_model (name, sequence, company_id, trigger, match_label, match_label_param, active, can_be_proposed, create_uid, write_uid, create_date, write_date)
  VALUES (jsonb_build_object('en_US', p_name), p_seq, 1, 'auto_reconcile', 'contains', p_match, true, true, 2, 2, NOW(), NOW()) RETURNING id INTO v_mid;
  INSERT INTO account_reconcile_model_line (model_id, company_id, sequence, account_id, amount_type, amount, amount_string, label, partner_id, create_uid, write_uid, create_date, write_date)
  VALUES (v_mid, 1, 10, p_acct, 'percentage', 100, '100', jsonb_build_object('en_US', p_label), 1, 2, 2, NOW(), NOW()) RETURNING id INTO v_lid;
  INSERT INTO account_reconcile_model_line_account_tax_rel (account_reconcile_model_line_id, account_tax_id) VALUES (v_lid, p_tax);
END; $$ LANGUAGE plpgsql;

SELECT _tmp_wo('RBC Visa - CC Payment Received', 900, 'PAYMENT - THANK YOU', 77, 32, 'RBC CC Payment from Chequing');
SELECT _tmp_wo('RBC Visa - Credit Card Payment', 901, 'credit card payment', 77, 32, 'RBC CC Payment from Chequing');
SELECT _tmp_wo('RBC Visa - RBC CC Payment', 902, 'RBC credit card', 77, 32, 'RBC CC Payment from Chequing');
SELECT _tmp_wo('RBC Visa - Payment to CC', 903, 'payment to credit card', 77, 32, 'RBC CC Payment from Chequing');

DROP FUNCTION _tmp_wo(text, int, text, int, int, text);
COMMIT;
