-- Invoice template token labels. Follows the standard plugin_base_fields -> plugin_base_multi_lang pattern.

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_tokens_group_invoice', 'backend', 'Invoice template tokens / group invoice', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_tokens_group_invoice');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_tokens_group_invoice' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'Invoice', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_tokens_group_company', 'backend', 'Invoice template tokens / group company', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_tokens_group_company');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_tokens_group_company' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'Company', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_tokens_group_customer', 'backend', 'Invoice template tokens / group customer', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_tokens_group_customer');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_tokens_group_customer' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'Customer', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_tokens_group_totals', 'backend', 'Invoice template tokens / group totals', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_tokens_group_totals');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_tokens_group_totals' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'Totals', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_invoice_number', 'backend', 'Invoice template token / invoice number', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_invoice_number');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_invoice_number' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'invoice number', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_order_number', 'backend', 'Invoice template token / order number', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_order_number');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_order_number' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'order number', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_issue_date', 'backend', 'Invoice template token / issue date', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_issue_date');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_issue_date' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'issue date', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_due_date', 'backend', 'Invoice template token / due date', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_due_date');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_due_date' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'due date', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_payment_status', 'backend', 'Invoice template token / payment status', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_payment_status');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_payment_status' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'invoice status', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_payment_method', 'backend', 'Invoice template token / payment method', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_payment_method');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_payment_method' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'payment method', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_transaction_id', 'backend', 'Invoice template token / transaction ID', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_transaction_id');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_transaction_id' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'transaction ID', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_company_logo', 'backend', 'Invoice template token / company logo', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_logo');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_logo' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'logo', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_company_name', 'backend', 'Invoice template token / company name', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_name');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_name' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'company name', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_company_address', 'backend', 'Invoice template token / company address', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_address');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_address' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'street address', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_company_zip', 'backend', 'Invoice template token / company ZIP', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_zip');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_zip' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'ZIP / postal code', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_company_city', 'backend', 'Invoice template token / company city', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_city');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_city' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'city', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_company_country', 'backend', 'Invoice template token / company country', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_country');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_country' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'country', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_company_state', 'backend', 'Invoice template token / company state', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_state');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_state' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'state', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_company_phone', 'backend', 'Invoice template token / company phone', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_phone');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_phone' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'phone', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_company_email', 'backend', 'Invoice template token / company email', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_email');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_email' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'email', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_company_url', 'backend', 'Invoice template token / company website', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_url');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_url' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'website', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_company_tax_number', 'backend', 'Invoice template token / company tax number', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_tax_number');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_tax_number' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'tax number', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_company_registration_number', 'backend', 'Invoice template token / company registration number', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_registration_number');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_registration_number' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'registration / COC number', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_company_bank_name', 'backend', 'Invoice template token / company bank name', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_bank_name');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_bank_name' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'bank account name', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_company_bank_account', 'backend', 'Invoice template token / company bank account', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_bank_account');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_company_bank_account' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'bank account / IBAN', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_client_name', 'backend', 'Invoice template token / client name', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_client_name');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_client_name' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'customer name', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_client_email', 'backend', 'Invoice template token / client email', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_client_email');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_client_email' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'customer email', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_billing_name', 'backend', 'Invoice template token / billing name', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_billing_name');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_billing_name' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'billing name', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_billing_address_1', 'backend', 'Invoice template token / billing address line 1', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_billing_address_1');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_billing_address_1' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'billing address line 1', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_billing_address_2', 'backend', 'Invoice template token / billing address line 2', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_billing_address_2');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_billing_address_2' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'billing address line 2', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_billing_zip', 'backend', 'Invoice template token / billing ZIP', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_billing_zip');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_billing_zip' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'billing ZIP / postal code', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_billing_city', 'backend', 'Invoice template token / billing city', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_billing_city');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_billing_city' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'billing city', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_billing_state', 'backend', 'Invoice template token / billing state', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_billing_state');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_billing_state' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'billing state', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_billing_country', 'backend', 'Invoice template token / billing country', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_billing_country');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_billing_country' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'billing country', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_shipping_name', 'backend', 'Invoice template token / shipping name', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_shipping_name');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_shipping_name' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'shipping name', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_shipping_address_1', 'backend', 'Invoice template token / shipping address line 1', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_shipping_address_1');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_shipping_address_1' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'shipping address line 1', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_shipping_address_2', 'backend', 'Invoice template token / shipping address line 2', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_shipping_address_2');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_shipping_address_2' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'shipping address line 2', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_shipping_zip', 'backend', 'Invoice template token / shipping ZIP', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_shipping_zip');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_shipping_zip' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'shipping ZIP / postal code', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_shipping_city', 'backend', 'Invoice template token / shipping city', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_shipping_city');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_shipping_city' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'shipping city', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_shipping_state', 'backend', 'Invoice template token / shipping state', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_shipping_state');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_shipping_state' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'shipping state', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_shipping_country', 'backend', 'Invoice template token / shipping country', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_shipping_country');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_shipping_country' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'shipping country', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_items', 'backend', 'Invoice template token / items', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_items');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_items' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'invoice items table', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_subtotal', 'backend', 'Invoice template token / subtotal', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_subtotal');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_subtotal' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'subtotal', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_discount', 'backend', 'Invoice template token / discount', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_discount');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_discount' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'discount', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_shipping', 'backend', 'Invoice template token / shipping', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_shipping');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_shipping' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'shipping amount', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_tax', 'backend', 'Invoice template token / tax', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_tax');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_tax' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'tax amount', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_insurance', 'backend', 'Invoice template token / insurance', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_insurance');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_insurance' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'insurance amount', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_total', 'backend', 'Invoice template token / total', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_total');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_total' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'total amount', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_currency', 'backend', 'Invoice template token / currency', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_currency');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_currency' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'currency', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_token_notes', 'backend', 'Invoice template token / notes', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_token_notes');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_token_notes' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'invoice notes', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);

INSERT INTO `plugin_base_fields` (`id`, `key`, `type`, `label`, `source`, `modified`)
SELECT NULL, 'invoice_tokens_legacy_note', 'backend', 'Invoice template tokens / legacy note', 'script', NOW() FROM DUAL
WHERE NOT EXISTS (SELECT 1 FROM `plugin_base_fields` WHERE `key` = 'invoice_tokens_legacy_note');

SET @id := (SELECT `id` FROM `plugin_base_fields` WHERE `key` = 'invoice_tokens_legacy_note' LIMIT 1);

INSERT INTO `plugin_base_multi_lang` (`id`, `foreign_id`, `model`, `locale`, `field`, `content`, `source`)
SELECT NULL, @id, 'pjField', l.`id`, 'title', 'Legacy tokens such as {b_name} still work for existing templates.', 'script'
FROM `plugin_base_locale` l
WHERE @id IS NOT NULL AND NOT EXISTS (
  SELECT 1
  FROM `plugin_base_multi_lang` m
  WHERE m.`foreign_id` = @id
    AND m.`model` = 'pjField'
    AND m.`locale` = l.`id`
    AND m.`field` = 'title'
);
