Add A 2nd Domain

Add New Domain

WARNING: The following instructions are a work in progress and have not been fully tested under Fearless359 SimpleInvoices. Testing will be performed in the future to verify and possibly automate this set up process.

Note: These instructions center around using phpMyAdmin. If you do not have this tool, you will need to adapt the instructions to that tool.

The default domain for SimpleInvoices is 1. For all intent and purposes, the domain is essentially a company. If you need to maintain invoices for a second company, you can do this by setting up a second domain. The users, customers, products, billers, invoices, invoice numbering, payments, inventory, etc. all exist within a domain. The domain is determined by the domain set for the user performing the activity. Therefore, the authentication.enabled option in custom.config.php must be set to true to use multiple domains.

To add a domain into SimpleInvoices, do the following:

  1. In phpMyAdmin, access the SimpleInvoices database.
  2. Select the SQL tab.
  3. Copy and paste the following SQL code into the phpMyAdmin SQL window.
  4. Edit the 5 “SET” values to reflect what you want them to be. Note:
    1. The domain_username must be unique in si_user irrespective of the new domain_id.
    2. The domain_pwd will be required to log in to the new domain.
    3. The domain_email does NOT need to be unique.
    4. The domain_name must be unique. It cannot duplicate a name in the si_user_domain table.
    5. The domain_num must be unique and should be the next sequential value for the id field of the si_user_domain table.
SET @domain_username:='doamin2username'; -- must be unique in si_user
SET @domain_pwd:='simpleinvoices'; -- new domain admin password
SET @domain_email:='domain2@simpleinvoices.test'; -- does not need to be unique
SET @domain_name:='simpleinvoices.test'; -- must be unique in si_user_domain
SET @domain_num:=2; -- domain number - must be unique in si_user_domain

INSERT INTO `si_custom_flags` (`domain_id`, `associated_table`, `flg_id`, `field_label`, `enabled`, `field_help`)
VALUES (@domain_num, 'products',  1, '', 0, ''),
       (@domain_num, 'products',  2, '', 0, ''),
       (@domain_num, 'products',  3, '', 0, ''),
       (@domain_num, 'products',  4, '', 0, ''),
       (@domain_num, 'products',  5, '', 0, ''),
       (@domain_num, 'products',  6, '', 0, ''),
       (@domain_num, 'products',  7, '', 0, ''),
       (@domain_num, 'products',  8, '', 0, ''),
       (@domain_num, 'products',  9, '', 0, ''),
       (@domain_num, 'products', 10, '', 0, '');

INSERT INTO `si_custom_fields` (`cf_id`, `cf_custom_field`, `cf_custom_label`, `cf_display`, `domain_id`)
VALUES ( 1, 'biller_cf1',   NULL, '0', @domain_num),
       ( 2, 'biller_cf2',   NULL, '0', @domain_num),
       ( 3, 'biller_cf3',   NULL, '0', @domain_num),
       ( 4, 'biller_cf4',   NULL, '0', @domain_num),
       ( 5, 'customer_cf1', NULL, '0', @domain_num),
       ( 6, 'customer_cf2', NULL, '0', @domain_num),
       ( 7, 'customer_cf3', NULL, '0', @domain_num),
       ( 8, 'customer_cf4', NULL, '0', @domain_num),
       ( 9, 'product_cf1',  NULL, '0', @domain_num),
       (10, 'product_cf2',  NULL, '0', @domain_num),
       (11, 'product_cf3',  NULL, '0', @domain_num),
       (12, 'product_cf4',  NULL, '0', @domain_num),
       (13, 'invoice_cf1',  NULL, '0', @domain_num),
       (14, 'invoice_cf2',  NULL, '0', @domain_num),
       (15, 'invoice_cf3',  NULL, '0', @domain_num),
       (16, 'invoice_cf4',  NULL, '0', @domain_num);

INSERT INTO `si_payment_types` (`pt_id`, `domain_id`, `pt_description`, `pt_enabled`)
VALUES (1, @domain_num, 'Cash', '1'),(2, @domain_num, 'Credit Card', '1');

INSERT INTO `si_preferences` (`pref_id`, `domain_id`, `pref_description`, `pref_currency_sign`, `pref_inv_heading`,
                              `pref_inv_wording`, `pref_inv_detail_heading`, `pref_inv_detail_line`,
                              `pref_inv_payment_method`, `pref_inv_payment_line1_name`, `pref_inv_payment_line1_value`,
                              `pref_inv_payment_line2_name`, `pref_inv_payment_line2_value`, `pref_enabled`, `status`,
                              `locale`, `language`, `index_group`, `currency_code`, `include_online_payment`,
                              `currency_position`)
VALUES (1, @domain_num, 'AltInvoice', '$', 'Invoice', 'Invoice', 'Details',
           'Payment is to be made within 14 days of the invoice being sent',
           'Electronic Funds Transfer', 'Account name', 'H. & M. Simpson', 'Account number:',
           '0123-4567-7890', '1', 1, 'en_US', 'en_US', 1, 'USD', NULL, 'left'),
       (2, @domain_num, 'AltReceipt', '$', 'Receipt', 'Receipt', 'Details', 
           '<br />This transaction has been paid in full, please keep this receipt as proof of purchase.<br /> Thank you',
           '', '', '', '', '', '1', 1, 'en_US', 'en_US', 1, 'USD', NULL, 'left'),
       (3, @domain_num, 'AltEstimate', '$', 'Estimate', 'Estimate', 'Details',
           '<br />This is an estimate of the final value of services rendered.<br />Thank you',
           '', '', '', '', '', '1', 1, 'en_US', 'en_US', 1, 'USD', NULL, 'left'),
       (4, @domain_num, 'AltQuote', '$', 'Quote', 'Quote', 'Details', 
           '<br />This is a quote of the final value of services rendered.<br />Thank you',
           '', '', '', '', '', '1', 1, 'en_US', 'en_US', 1, 'USD', NULL, 'left');

INSERT INTO `si_system_defaults` SELECT *
FROM (SELECT NULL AS id, a.name, a.value, @domain_num AS domain_id, extension_id 
      FROM `si_system_defaults` a 
      WHERE a.domain_id = 1 
        AND a.name NOT IN (SELECT b.name FROM `si_system_defaults` b WHERE b.domain_id = @domain_num)) c;

INSERT INTO `si_tax` (`tax_id`, `tax_description`, `tax_percentage`, `type`, `tax_enabled`, `domain_id`)
VALUES (1, 'No Tax',     0.000000, '%', '1', @domain_num),
       (2, 'GST',        7.000000, '%', '1', @domain_num),
       (3, 'VAT',       10.000000, '%', '1', @domain_num),
       (4, 'Sales Tax', 10.000000, '%', '1', @domain_num),
       (5, 'Postage',   20.000000, '$', '1', @domain_num);

INSERT INTO `si_user` (`id`, `email`, `role_id`, `domain_id`, `password`, `enabled`, `user_id`, `username`) VALUES (1, @domain_email, 1, @domain_num, MD5(@domain_pwd), 1, 0, @domain_username); INSERT INTO `si_user_domain` (`id`, `name`) VALUES (@domain_num, @domain_name);