DROP TABLE IF EXISTS `plugin_invoice_items`;
DROP TABLE IF EXISTS `plugin_invoice`;
DROP TABLE IF EXISTS `plugin_invoice_config`;

CREATE TABLE IF NOT EXISTS `plugin_invoice` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `uuid` varchar(255) DEFAULT NULL,
  `order_id` varchar(12) DEFAULT NULL,
  `foreign_id` int(10) unsigned DEFAULT NULL,
  `locale_id` int(10) unsigned DEFAULT NULL,
  `issue_date` date DEFAULT NULL,
  `due_date` date DEFAULT NULL,
  `created` datetime DEFAULT NULL,
  `modified` datetime DEFAULT NULL,
  `status` enum('not_paid','paid','cancelled') DEFAULT NULL,
  `payment_method` varchar(255) DEFAULT NULL,
  `txn_id` varchar(255) DEFAULT NULL,
  `processed_on` datetime DEFAULT NULL,
  `price` decimal(9,2) unsigned DEFAULT NULL,
  `discount` decimal(9,2) unsigned DEFAULT NULL,
  `insurance` decimal(9,2) unsigned DEFAULT NULL,
  `shipping` decimal(9,2) unsigned DEFAULT NULL,
  `tax` decimal(9,2) unsigned DEFAULT NULL,
  `total` decimal(9,2) unsigned DEFAULT NULL,
  `currency` varchar(255) DEFAULT NULL,
  `notes` text DEFAULT NULL,
  `b_name` varchar(255) DEFAULT NULL,
  `b_country_id` int(10) unsigned DEFAULT NULL,
  `b_city` varchar(255) DEFAULT NULL,
  `b_state` varchar(255) DEFAULT NULL,
  `b_zip` varchar(255) DEFAULT NULL,
  `b_address_1` varchar(255) DEFAULT NULL,
  `b_address_2` varchar(255) DEFAULT NULL,
  `s_name` varchar(255) DEFAULT NULL,
  `s_country_id` int(10) unsigned DEFAULT NULL,
  `s_city` varchar(255) DEFAULT NULL,
  `s_state` varchar(255) DEFAULT NULL,
  `s_zip` varchar(255) DEFAULT NULL,
  `s_address_1` varchar(255) DEFAULT NULL,
  `s_address_2` varchar(255) DEFAULT NULL,
  PRIMARY KEY (`id`),
  UNIQUE KEY `uuid` (`uuid`),
  KEY `order_id` (`order_id`),
  KEY `foreign_id` (`foreign_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `plugin_invoice_config` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `invoice_number` varchar(255) DEFAULT NULL,
  `invoice_number_digits` tinyint(2) unsigned NOT NULL DEFAULT 5,
  `invoice_number_reset_yearly` tinyint(1) unsigned NOT NULL DEFAULT 0,
  `y_logo` varchar(255) DEFAULT NULL,
  `y_email_logo` varchar(255) DEFAULT NULL,
  `y_country` int(10) DEFAULT NULL,
  `y_zip` varchar(255) DEFAULT NULL,
  `y_phone` varchar(255) DEFAULT NULL,
  `y_email` varchar(255) DEFAULT NULL,
  `y_url` varchar(255) DEFAULT NULL,
  `y_vat_number` varchar(255) DEFAULT NULL,
  `y_coc_number` varchar(255) DEFAULT NULL,
  `y_bank_iban` varchar(255) DEFAULT NULL,
  `y_bank_name` varchar(255) DEFAULT NULL,
  `si_include` tinyint(1) unsigned DEFAULT 0,
  `o_use_qty_unit_price` tinyint(1) unsigned DEFAULT 1,
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

CREATE TABLE IF NOT EXISTS `plugin_invoice_items` (
  `id` int(10) unsigned NOT NULL AUTO_INCREMENT,
  `invoice_id` int(10) unsigned DEFAULT NULL,
  `tmp` varchar(255) DEFAULT NULL,
  `name` varchar(255) DEFAULT NULL,
  `description` tinytext DEFAULT NULL,
  `qty` decimal(9,2) DEFAULT NULL,
  `unit_price` decimal(9,2) unsigned DEFAULT NULL,
  `amount` decimal(9,2) DEFAULT NULL,
  PRIMARY KEY (`id`),
  KEY `invoice_id` (`invoice_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8;

INSERT INTO `plugin_invoice_config`
  (`id`, `invoice_number`, `invoice_number_digits`, `invoice_number_reset_yearly`, `si_include`, `o_use_qty_unit_price`)
VALUES
  (1, '1', 5, 0, 0, 1);

INSERT INTO `options` (`foreign_id`, `key`, `tab_id`, `value`, `label`, `type`, `order`, `is_visible`, `style`) VALUES
  (1, 'o_invoice_template', 0, '', 'Invoice template (HTML)', 'text', 0, 0, NULL),
  (1, 'o_invoice_template_settings', 0, '{"header_logo_position":"left","show_metadata":{"number":1,"issue_date":1,"due_date":1,"status":1,"order_number":1},"show_customer":{"billing":1,"shipping":1,"coc_number":0},"show_items_columns":{"image":0,"description":1,"qty":1,"unit_price":1,"line_total":1},"show_totals":{"subtotal":1,"discount":1,"shipping":1,"tax":1,"total":1},"show_payment_instructions":1,"show_footer_notes":1,"raw_html_mode":0}', 'Invoice template settings (JSON)', 'text', 0, 0, NULL);

INSERT INTO `plugin_auth_permissions` (`id`, `parent_id`, `key`) VALUES (NULL, NULL, 'pjInvoice');
SET @pjInvoicePermissionId := (SELECT LAST_INSERT_ID());
INSERT INTO `plugin_auth_permissions` (`id`, `parent_id`, `key`) VALUES
  (NULL, @pjInvoicePermissionId, 'pjInvoice_pjActionIndex'),
  (NULL, @pjInvoicePermissionId, 'pjInvoice_pjActionInvoices'),
  (NULL, @pjInvoicePermissionId, 'pjInvoice_pjActionGetInvoices'),
  (NULL, @pjInvoicePermissionId, 'pjInvoice_pjActionView'),
  (NULL, @pjInvoicePermissionId, 'pjInvoice_pjActionSend'),
  (NULL, @pjInvoicePermissionId, 'pjInvoice_pjActionPrint'),
  (NULL, @pjInvoicePermissionId, 'pjInvoice_pjActionCreate'),
  (NULL, @pjInvoicePermissionId, 'pjInvoice_pjActionDelete'),
  (NULL, @pjInvoicePermissionId, 'pjInvoice_pjActionSaveInvoice'),
  (NULL, @pjInvoicePermissionId, 'pjInvoice_pjActionGeneratePdf'),
  (NULL, @pjInvoicePermissionId, 'pjInvoice_generatePdf'),
  (NULL, @pjInvoicePermissionId, 'pjInvoice_pjActionDownloadBulk'),
  (NULL, @pjInvoicePermissionId, 'pjInvoice_pjActionDeleteBulk');

INSERT INTO `plugin_auth_permissions` (`id`, `parent_id`, `key`) VALUES (NULL, NULL, 'pjAdminProfile');
SET @pjAdminProfilePermissionId := (SELECT LAST_INSERT_ID());
INSERT INTO `plugin_auth_permissions` (`id`, `parent_id`, `key`) VALUES
  (NULL, @pjAdminProfilePermissionId, 'pjAdminProfile_pjActionIndex'),
  (NULL, @pjAdminProfilePermissionId, 'pjAdminProfile_pjActionDeleteLogo'),
  (NULL, @pjAdminProfilePermissionId, 'pjAdminProfile_pjActionDeleteEmailLogo');

INSERT INTO `plugin_base_multi_lang` (`foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT p.id, 'pjAuthPermission', l.id, 'title', labels.title, 'data'
FROM `plugin_auth_permissions` p
JOIN `plugin_base_locale` l
JOIN (
  SELECT 'pjInvoice' AS `key`, 'Invoices Menu' AS title
  UNION ALL SELECT 'pjInvoice_pjActionIndex', 'Invoice settings'
  UNION ALL SELECT 'pjInvoice_pjActionInvoices', 'Invoices List'
  UNION ALL SELECT 'pjInvoice_pjActionGetInvoices', 'Load invoices'
  UNION ALL SELECT 'pjInvoice_pjActionView', 'View invoice'
  UNION ALL SELECT 'pjInvoice_pjActionSend', 'Send invoice'
  UNION ALL SELECT 'pjInvoice_pjActionPrint', 'Print invoice'
  UNION ALL SELECT 'pjInvoice_pjActionCreate', 'Create invoice'
  UNION ALL SELECT 'pjInvoice_pjActionDelete', 'Delete invoice'
  UNION ALL SELECT 'pjInvoice_pjActionSaveInvoice', 'Edit invoice status'
  UNION ALL SELECT 'pjInvoice_pjActionGeneratePdf', 'Download PDF'
  UNION ALL SELECT 'pjInvoice_generatePdf', 'Generate PDF'
  UNION ALL SELECT 'pjInvoice_pjActionDownloadBulk', 'Download invoice PDFs'
  UNION ALL SELECT 'pjInvoice_pjActionDeleteBulk', 'Delete multiple invoices'
  UNION ALL SELECT 'pjAdminProfile', 'Company profile'
  UNION ALL SELECT 'pjAdminProfile_pjActionIndex', 'Edit company profile'
  UNION ALL SELECT 'pjAdminProfile_pjActionDeleteLogo', 'Delete company logo'
  UNION ALL SELECT 'pjAdminProfile_pjActionDeleteEmailLogo', 'Delete email logo'
) AS labels ON labels.`key` = p.`key`;

INSERT INTO `fields` VALUES (NULL, 'pjInvoice', 'backend', 'Invoices Menu', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Invoices Menu', 'script');

INSERT INTO `fields` VALUES (NULL, 'pjInvoice_pjActionIndex', 'backend', 'Invoice settings', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Invoice settings', 'script');

INSERT INTO `fields` VALUES (NULL, 'pjInvoice_pjActionInvoices', 'backend', 'Invoices List', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Invoices List', 'script');

INSERT INTO `fields` VALUES (NULL, 'pjInvoice_pjActionGetInvoices', 'backend', 'Load invoices', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Load invoices', 'script');

INSERT INTO `fields` VALUES (NULL, 'pjInvoice_pjActionView', 'backend', 'View invoice', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'View invoice', 'script');

INSERT INTO `fields` VALUES (NULL, 'pjInvoice_pjActionSend', 'backend', 'Send invoice', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Send invoice', 'script');

INSERT INTO `fields` VALUES (NULL, 'pjInvoice_pjActionPrint', 'backend', 'Print invoice', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Print invoice', 'script');

INSERT INTO `fields` VALUES (NULL, 'pjInvoice_pjActionCreate', 'backend', 'Create invoice', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Create invoice', 'script');

INSERT INTO `fields` VALUES (NULL, 'pjInvoice_pjActionDelete', 'backend', 'Delete invoice', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Delete invoice', 'script');

INSERT INTO `fields` VALUES (NULL, 'pjInvoice_pjActionSaveInvoice', 'backend', 'Edit invoice status', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Edit invoice status', 'script');

INSERT INTO `fields` VALUES (NULL, 'pjInvoice_pjActionGeneratePdf', 'backend', 'Download PDF', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Download PDF', 'script');

INSERT INTO `fields` VALUES (NULL, 'pjInvoice_generatePdf', 'backend', 'Generate PDF', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Generate PDF', 'script');

INSERT INTO `fields` VALUES (NULL, 'pjInvoice_pjActionDownloadBulk', 'backend', 'Download invoice PDFs', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Download invoice PDFs', 'script');

INSERT INTO `fields` VALUES (NULL, 'pjInvoice_pjActionDeleteBulk', 'backend', 'Delete multiple invoices', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Delete multiple invoices', 'script');

INSERT INTO `fields` VALUES (NULL, 'pjAdminProfile', 'backend', 'Company profile', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Company profile', 'script');

INSERT INTO `fields` VALUES (NULL, 'pjAdminProfile_pjActionIndex', 'backend', 'Edit company profile', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Edit company profile', 'script');

INSERT INTO `fields` VALUES (NULL, 'pjAdminProfile_pjActionDeleteLogo', 'backend', 'Delete company logo', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Delete company logo', 'script');

INSERT INTO `fields` VALUES (NULL, 'pjAdminProfile_pjActionDeleteEmailLogo', 'backend', 'Delete email logo', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Delete email logo', 'script');

INSERT INTO `multi_lang` VALUES (NULL, 1, 'pjInvoiceConfig', '::LOCALE::', 'y_template', '<table style="width:100%;" border="0"><tbody><tr><td style="width:50%;">{y_logo}</td><td>&nbsp;</td></tr><tr><td><p><strong>{y_company}</strong></p><p>{y_street_address}<br />{y_zip} {y_city}<br />{y_country}<br /><br />Invoice number: {uuid}<br />Invoice date: {issue_date}<br />Order number: {order_id}<br />Payment status: {status}</p></td><td>&nbsp;</td></tr></tbody></table><p>&nbsp;</p><table style="width:100%;"><tbody><tr><td style="width:50%;"><strong>Billing address</strong></td><td style="width:50%;"><strong>Shipping address</strong></td></tr><tr><td><strong>{b_name}</strong><br />{b_address_1}<br />{b_zip} {b_city}<br />{b_country}</td><td><strong>{s_name}</strong><br />{s_address_1}<br />{s_zip} {s_city}<br />{s_country}</td></tr></tbody></table><p>&nbsp;</p>{items}<p>&nbsp;</p><table style="width:100%;"><tbody><tr><td style="text-align:right;">Discount:</td><td style="text-align:right;">{discount}</td></tr><tr><td style="text-align:right;">Shipping:</td><td style="text-align:right;">{shipping}</td></tr><tr><td style="text-align:right;">Tax:</td><td style="text-align:right;">{tax}</td></tr><tr><td style="text-align:right;">Insurance:</td><td style="text-align:right;">{insurance}</td></tr><tr><td style="text-align:right;"><strong>Total:</strong></td><td style="text-align:right;"><strong>{total}</strong></td></tr></tbody></table><p>{notes}</p>', 'script');

INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_menu_invoices', 'backend', 'Invoice plugin / Menu Invoices', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Invoices', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_template', 'backend', 'Invoice plugin / Invoice Template', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Invoice template', 'script');
INSERT INTO `fields` VALUES (NULL, 'PIN09', 'backend', 'Invoice plugin / Email', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Email invoice', 'script');
INSERT INTO `fields` VALUES (NULL, 'PIN12', 'backend', 'Invoice plugin / Invoices title', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Invoices', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_config', 'backend', 'Invoice plugin / Settings button', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Invoice Config', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_status', 'backend', 'Invoice plugin / Status filter', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Invoice status', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_foreign', 'backend', 'Invoice plugin / Type filter', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Type', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_send_invoice_title', 'backend', 'Invoice plugin / Send invoice title', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Send invoice', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_num', 'backend', 'Invoice plugin / Invoice number column', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Invoice #', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_order_id', 'backend', 'Invoice plugin / Order number column', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Order #', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_issue_date', 'backend', 'Invoice plugin / Issue date', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Issue date', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_due_date', 'backend', 'Invoice plugin / Due date', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Due date', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_created', 'backend', 'Invoice plugin / Created', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Created', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_status', 'backend', 'Invoice plugin / Status column', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Status', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_view_invoice', 'backend', 'Invoice plugin / View invoice', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'View invoice', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_download_pdf_invoice', 'backend', 'Invoice plugin / Download PDF', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Download PDF', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_print_invoice', 'backend', 'Invoice plugin / Print invoice', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Print invoice', 'script');
INSERT IGNORE INTO `fields` VALUES (NULL, 'plugin_invoice_email_invoice', 'backend', 'Invoice plugin / Email invoice', 'script', NULL);
SET @id := (SELECT `id` FROM `fields` WHERE `key` = 'plugin_invoice_email_invoice' LIMIT 1);
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Email invoice', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_total', 'backend', 'Invoice plugin / Total', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Total', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_delete_title', 'backend', 'Invoice plugin / Delete title', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Delete invoice?', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_delete_body', 'backend', 'Invoice plugin / Delete body', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Are you sure you want to delete this invoice?', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_download_pdfs_bulk', 'backend', 'Invoice plugin / Bulk download', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Download PDFs', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_invoice_number', 'backend', 'Invoice plugin / Invoice number prefix', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Invoice number prefix', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_number_hint', 'backend', 'Invoice plugin / Number hint', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Set the starting invoice number.', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_number_digits', 'backend', 'Invoice plugin / Number digits', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Number of digits', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_number_reset_yearly', 'backend', 'Invoice plugin / Reset yearly', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Reset yearly', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_number_preview', 'backend', 'Invoice plugin / Number preview', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Preview', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_use_shipping_details', 'backend', 'Invoice plugin / Show shipping details', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Show shipping details', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_use_qty_unit_price', 'backend', 'Invoice plugin / Show quantity and unit price', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Show Qty & Unit price', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_pay_now', 'backend', 'Invoice plugin / Pay now', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Pay now', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_email', 'backend', 'Invoice plugin / Email', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Email', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_billing_info', 'backend', 'Invoice plugin / Billing information', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Billing information', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_shipping_info', 'backend', 'Invoice plugin / Shipping information', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Shipping information', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_company', 'backend', 'Invoice plugin / Company', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Company', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_name', 'backend', 'Invoice plugin / Contact name', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Contact name', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_phone', 'backend', 'Invoice plugin / Phone', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Phone', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_url', 'backend', 'Invoice plugin / Website', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Website', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_street_address', 'backend', 'Invoice plugin / Street address', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Street address', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_zip', 'backend', 'Invoice plugin / ZIP', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'ZIP / postal code', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_city', 'backend', 'Invoice plugin / City', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'City', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_state', 'backend', 'Invoice plugin / State', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'State', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_country', 'backend', 'Invoice plugin / Country', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Country', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_logo', 'backend', 'Invoice plugin / Logo', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Logo', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_available_company_tokens', 'backend', 'Invoice plugin / Available company tokens', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Available company tokens', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_item', 'backend', 'Invoice plugin / Item column', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Item', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_qty', 'backend', 'Invoice plugin / Quantity column', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Qty', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_unit_price', 'backend', 'Invoice plugin / Unit price column', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Unit price', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_i_amount', 'backend', 'Invoice plugin / Amount column', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Amount', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_statuses_ARRAY_paid', 'arrays', 'Invoice statuses / Paid', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Paid', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_statuses_ARRAY_not_paid', 'arrays', 'Invoice statuses / Not paid', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Not paid', 'script');
INSERT INTO `fields` VALUES (NULL, 'plugin_invoice_statuses_ARRAY_cancelled', 'arrays', 'Invoice statuses / Cancelled', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Cancelled', 'script');
INSERT INTO `fields` VALUES (NULL, 'error_titles_ARRAY_PIN12', 'arrays', 'Invoice page / Title', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Invoices', 'script');
INSERT INTO `fields` VALUES (NULL, 'error_bodies_ARRAY_PIN12', 'arrays', 'Invoice page / Description', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Manage your invoices and payments.', 'script');
INSERT INTO `fields` VALUES (NULL, 'error_titles_ARRAY_PIN14', 'arrays', 'Invoice settings / Title', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Invoice settings', 'script');
INSERT INTO `fields` VALUES (NULL, 'error_bodies_ARRAY_PIN14', 'arrays', 'Invoice settings / Description', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Configure the invoice number format and invoice options.', 'script');
INSERT INTO `fields` VALUES (NULL, 'error_titles_ARRAY_PIN02', 'arrays', 'Invoice settings / Success title', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Success!', 'script');
INSERT INTO `fields` VALUES (NULL, 'error_bodies_ARRAY_PIN02', 'arrays', 'Invoice settings / Success body', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'The invoice settings have been updated successfully.', 'script');
INSERT INTO `fields` VALUES (NULL, 'error_titles_ARRAY_PIN04', 'arrays', 'Invoice / Deleted title', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Invoice deleted', 'script');
INSERT INTO `fields` VALUES (NULL, 'error_bodies_ARRAY_PIN04', 'arrays', 'Invoice / Deleted body', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'The invoice has been successfully deleted.', 'script');
INSERT INTO `fields` VALUES (NULL, 'error_titles_ARRAY_PIN09', 'arrays', 'Invoice email / Title', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Email invoice', 'script');
INSERT INTO `fields` VALUES (NULL, 'error_bodies_ARRAY_PIN09', 'arrays', 'Invoice email / Body', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Please check the email address below before sending the invoice to the customer.', 'script');
INSERT INTO `fields` VALUES (NULL, 'front_print_invoice', 'frontend', 'Frontend / Print invoice', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Print invoice', 'script');
INSERT INTO `fields` VALUES (NULL, 'front_view_order_details', 'frontend', 'Frontend / View order details', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'View details', 'script');
INSERT INTO `fields` VALUES (NULL, 'front_orders_history', 'frontend', 'Frontend / Order history', 'script', NULL);
SET @id := (SELECT LAST_INSERT_ID());
INSERT INTO `multi_lang` VALUES (NULL, @id, 'pjBaseField', '::LOCALE::', 'title', 'Order history', 'script');
