INSERT INTO core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('SCNTMSC','count_main_function','MCOUNT','','','count','count','Section for main functions','SEC','',1,false,false,NULL),
	 ('XCNTCRE','count_event_create','SCNTMSC','createCountEvent','','count','count','Permission to create billable event record','EXE','',1,false,false,NULL),
	 ('SCNTEVW','count_events_list','PCNTEVN','','','count/events','count','Section to edit events','SEC','',1,false,false,NULL),
	 ('BCNTSTG','count_events_settings_button','SCNTEVW','','','count/events','count','Button to edit billable event settings','BUT','fa-solid fa-square-sliders',1,false,false,NULL),
	 ('XCNTGET','count_events_get','SCNTEVW','getCountEvents','','count/events','count','Permission to get count events','EXE','',1,false,false,NULL),
	 ('PCNTCNF','count_config','MCOUNT','','','count/config','count','Permission to count config','PAG','fa-solid fa-wrench',1,false,false,NULL),
	 ('PCNTBIL','count_config_billable','PCNTCNF','getObjects','','count/config/billable','count','Permission to count config billable page','PAG','fa-solid fa-file-invoice-dollar',1,false,false,NULL),
	 ('SCNTBIL','count_config_billable_list','PCNTBIL','','','count/config/billable','count','Permission to count config billable section','SEC','',1,false,false,NULL),
	 ('XCNTBGT','count_billable_get','SCNTBIL','getBillableEvents','','count/config/billable','count','Permiassion to get billable events','EXE','',1,false,false,NULL),
	 ('BCNTENB','count_enable_billing_button','SCNTBIL','','','count/config/billable','count','Permission to enable billing button','BUT','fa-solid fa-toggle-on',1,false,false,NULL);
INSERT INTO core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('BCNTDIS','count_disable_billing_button','SCNTBIL','','','count/config/billable','count','Permission to disable billing','BUT','fa-solid fa-toggle-off',1,false,false,NULL),
	 ('BCNTCNF','count_configuration_button','SCNTBIL','','','count/config/billable','count','Permisison to configure button','BUT','fa-solid fa-screwdriver-wrench',1,false,false,NULL),
	 ('XTGGBIL','count_billable_toggle','SCNTBIL','toggleBilling','','count/config/billable','count','Permission to toggle billable state','EXE','',1,false,false,NULL),
	 ('XCCFGBE','count_billable_get_config','SCNTBIL','getBillableEventConfig','','count/config','count','Permission to get billable event configuration.','EXE','',1,false,false,NULL),
	 ('PCNTEVN','count_events_page','MCOUNT','getObjects','','count/events','count','Billable events management page','PAG','fa-solid fa-calendar-check',1,false,false,NULL),
	 ('XCIRADD','count_invoices_rows_add','SCNIVED','addCountInvoicesRows','','count/invoices','count','Permission to create count invoices rows','EXE','',1,false,false,NULL),
	 ('SCNIVED','count_invoices_edit','PCNTINV','','','count/invoices','count','Section to edit count invoices','SEC','',1,false,false,NULL),
	 ('PCNTTPL','count_config_templates','PCNTCNF','getObjects','','count/config/templates','count','Permission to count config tamplates page','PAG','fa-solid fa-file-invoice',1,false,false,NULL),
	 ('SCNTTPL','count_config_templates_list','PCNTTPL','','','ccount/config/templates','count','Permission to count config templates section','SEC','',1,false,false,NULL),
	 ('BCNTTSV','count_config_templates_save_button','SCNTTPL','','','count/config/templates','count','Permission to save template button','BUT','fa-solid fa-floppy-disk',1,false,false,NULL);
INSERT INTO core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('XCIRSUP','count_invoices_rows_totals','SCNTIVW','updInvoiceTotals','','count/invoices','count','Permission to count invoices rows totals','EXE','',1,false,false,NULL),
	 ('BCIRDEL','count_invoices_rows_edit_del','SCNIVED','','','count/invoices','count','Permission to invoices rows delete button','BUT','fas fa-trash',1,false,false,NULL),
	 ('SCCCOVW','count_contracts_view','PCCCONT','','','count/config/contracts','count','Permission to view count contracts ','SEC','',1,false,false,NULL),
	 ('SCCCOED','count_contracts_edit','PCCCONT','','','count/config/contracts','count','Permission to edit count contracts','SEC','',1,false,false,NULL),
	 ('SCNTIVW','count_invoices_view','PCNTINV','','','count/invoices','count','Section to view count invoices','SEC','',1,false,false,NULL),
	 ('XCINGET','count_invoices_get','SCNTIVW','getCountInvoices','','count/invoices','count','Permission to get count invoices','EXE','',1,false,false,NULL),
	 ('BCINADD','count_invoices_view_add','SCNTIVW','','','count/invoices','count','Add invoices button','BUT','fas fa-plus',1,false,false,NULL),
	 ('BCINEDT','count_invoices_view_edit','SCNTIVW','','','count/invoices','count','Edit invoices button','BUT','fas fa-edit',1,false,false,NULL),
	 ('PCNTINV','count_invoices_page','MCOUNT','getObjects','','count/invoices','count','Invoices management page','PAG','fa-solid fa-file-invoice-dollar',1,false,false,NULL),
	 ('BCINBCK','count_invoices_edit_back','SCNIVED','','','count/invoices','count','Count invoices back button','BUT','fas fa-arrow-left',1,false,false,NULL);
INSERT INTO core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('BCINSAV','count_invoices_edit_save','SCNIVED','','','count/invoices','count','Count invoices save button','BUT','fas fa-save',1,false,false,NULL),
	 ('BCCCADD','count_contracts_view_add','SCCCOVW','','','count/config/contracts','count','Permission to add contracts button','BUT','fas fa-plus',1,false,false,NULL),
	 ('BCCCEDT','count_contracts_view_edit','SCCCOVW','','','count/config/contracts','count','Permission to count contracts edit button','BUT','fas fa-edit',1,false,false,NULL),
	 ('XCINADD','count_invoices_add','SCNIVED','addCountInvoices','','count/invoices','count','Permission to create count invoices','EXE','',1,false,false,NULL),
	 ('BCINDEL','count_invoices_view_del','SCNTIVW','','','count/invoices','count','Delete invoices button','BUT','fas fa-trash',1,false,false,NULL),
	 ('XCINDEL','count_invoices_del','SCNIVED','delCountInvoices','','count/invoices','count','Permission to delete count invoices','EXE','',1,false,false,NULL),
	 ('XCINUPD','count_invoices_update','SCNIVED','updCountInvoices','','count/invoices','count','Permision to update count invoices','EXE','',1,false,false,NULL),
	 ('XCIRUPD','count_invoices_rows_upd','SCNIVED','updCountInvoicesRows','','count/invoices','count','Permission to update count invoices rows','EXE','',1,false,false,NULL),
	 ('XCIRDEL','count_invoices_rows_delete','SCNIVED','delCountInvoicesRows','','count/invoices','count','Permission to delete count invoices rows','EXE','',1,false,false,NULL),
	 ('XCIRGET','count_invoices_rows_get','SCNIVED','getCountInvoicesRows','','count/invoices','count','Permission to get count invoices rows','EXE','',1,false,false,NULL);
INSERT INTO core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('BCCCDEL','count_contracts_view_del','SCCCOVW','','','count/config/contracts','count','Permission to count contracts edit button','BUT','fas fa-trash',1,false,false,NULL),
	 ('PCCCONT','count_config_contracts','PCNTCNF','getObjects','','count/config/contracts','count','Permission to count config contracts page','PAG','fa-solid fa-file-signature',1,false,false,NULL),
	 ('BCCNSAV','count_contracts_edit_save','SCCCOED','','','count/config/contracts','count','Count contracts save button','BUT','fas fa-save',1,false,false,NULL),
	 ('BCCNDEL','count_contracts_rows_edit_del','SCCCOED','','','count/config/contracts','count','Permission to contracts rows delete button','BUT','fas fa-trash',1,false,false,NULL),
	 ('BCCNBCK','count_contracts_edit_back','SCCCOED','','','count/config/contracts','count','Count contracts back button','BUT','fas fa-arrow-left',1,false,false,NULL),
	 ('XCCNADD','count_contracts_add','SCCCOED','addCountContracts','','count/config/contracts','count','Permission to create count contracts','EXE','',1,false,false,NULL),
	 ('XCCCADD','count_contracts_rows_add','SCCCOED','addCountContractsRows','','count/config/contracts','count','Permission to create count contracts rows','EXE','',1,false,false,NULL),
	 ('XCCNDEL','count_contracts_del','SCCCOED','delCountContracts','','count/config/contracts','count','Permission to delete count contracts','EXE','',1,false,false,NULL),
	 ('XCCRDEL','count_contracts_rows_delete','SCCCOED','delCountContractsRows','','count/config/contracts','count','Permission to delete count contracts rows','EXE','',1,false,false,NULL),
	 ('XCCCGET','count_contracts_get','SCCCOVW','getCountContracts','','count/config/contracts','count','Permission to get count contracts','EXE','',1,false,false,NULL);
INSERT INTO core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('XCCRGET','count_contracts_rows_get','SCCCOED','getCountContractsRows','','count/config/contracts','count','Permission to get count contracts rows','EXE','',1,false,false,NULL),
	 ('XCCNUPD','count_contracts_update','SCCCOED','updCountContracts','','count/config/contracts','count','Permission to update count contracts','EXE','',1,false,false,NULL),
	 ('XCCRUPD','count_contracts_rows_upd','SCCCOED','updCountContractsRows','','count/config/contracts','count','Permission to update count contracts rows','EXE','',1,false,false,NULL),
	 ('XCISGET','count_invoices_services_get','SCNIVED','getContractsServices','','count/invoices','count','Permissiont to get count services ','EXE','',1,false,false,NULL);


INSERT INTO core_assets (asset_type,asset_name,description,custom,asset_innerhtml,asset_parameters,asset_code,before_trigger,after_trigger,failure_rollback,exec_order,meta,role_id) VALUES
	 ('form','count_invoices_form','Form for count invoices',false,NULL,'{"form": [[{"id": "client_id", "cols": 3, "list": "api/v1/registry/registrylist/CLI ", "name": "client_id", "type": "dropdown", "label": "table_count_invoices_client_id", "mandatory": false}, {"id": "supplier_id", "cols": 3, "list": "api/v1/registry/registrylist/SUP", "name": "supplier_id", "type": "dropdown", "label": "table_count_invoices_supplier_id", "mandatory": false}, {"id": "invoice_date", "cols": 3, "name": "invoice_date", "type": "date", "label": "table_count_invoices_invoice_date", "mandatory": true}, {"id": "invoice_total", "cols": 3, "name": "invoice_total", "type": "int", "label": "table_count_invoices_invoice_total", "disabled": true}], [{"id": "invoice_vat", "cols": 3, "name": "invoice_vat", "type": "int", "label": "table_count_invoices_invoice_vat", "disabled": true}, {"id": "currency", "cols": 3, "list": "api/v1/misc/codelists/currencies", "name": "currency", "type": "dropdown", "label": "table_count_invoices_currency", "mandatory": true}, {"id": "", "cols": 3, "name": "", "type": "toggle-list", "label": "Select options", "elements": [{"id": "paid", "name": "paid", "label": "table_count_invoices_paid"}, {"id": "credit_note", "name": "credit_note", "label": "table_count_invoices_credit_note"}, {"id": "proforma", "name": "proforma", "label": "table_count_invoices_proforma"}], "mandatory": false}]]}',NULL,NULL,NULL,NULL,NULL,NULL,NULL),
	 ('form','self_profile_view_form','form to create self profile',false,NULL,'{"form": [[{"id": "email", "cols": 6, "name": "email", "type": "text", "label": "self_profile_email", "mandatory": true, "relatedHidden": "id"}, {"id": "password", "cols": 6, "name": "password", "type": "text", "label": "self_profile_password", "mandatory": true}], [{"id": "language", "cols": 6, "list": "/api/v1/misc/codelists/jc_languages", "name": "language", "type": "dropdown", "label": "self_profile_language", "mandatory": true}, {"id": "confirm_password", "cols": 6, "name": "confirm_password", "type": "text", "label": "self_profile_confirm_password", "mandatory": true}], [{"id": "meta.profile.logo", "cols": 4, "name": "meta[profile][logo]", "type": "file", "label": "Logo", "folder": "settings", "filename": "company-logo.png", "onchange": "jivaCoreFunc.onChange.fileUpload(this);", "mandatory": false}, {"id": "meta.profile.pic", "cols": 4, "name": "meta[profile][pic]", "type": "file", "label": "Picture", "onchange": "jivaCoreFunc.onChange.fileUpload(this);", "mandatory": false}, {"id": "", "cols": 4, "name": "", "type": "toggle-list", "label": "Select", "elements": [{"id": "userStatusSwitch", "name": "userStatusSwitch", "label": "Status"}], "mandatory": false}]]}',NULL,NULL,NULL,NULL,NULL,NULL,NULL),
	 ('form','count_contracts_form','Form to add contracts',false,NULL,'{"form": [[{"id": "description", "cols": 3, "name": "description", "type": "text", "label": "table_count_contracts_description", "mandatory": true}, {"id": "client_id", "cols": 3, "list": "api/v1/registry/registrylist/CLI ", "name": "client_id", "type": "dropdown", "label": "table_count_contracts_client_id", "mandatory": true}]]}',NULL,NULL,NULL,NULL,NULL,NULL,NULL);

ALTER TABLE public.code_list_count_invoices_currency RENAME TO code_list_currencies;
ALTER TABLE public.code_list_currencies ADD CONSTRAINT code_list_currencies_pk PRIMARY KEY (code);

