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
	 ('PDUTKNB','duty_kanban_page','MDUTY','initKanbanBoard','','duty/kanban','duty','Duty kanban management page','PAG','fa-solid fa-person-chalkboard',1,false,false,NULL);

INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('XDKNGS','duty_kanban_get_states','PDUTKNB','getDutyStates','','duty/kanban','duty','Permission to get duty states','EXE','',1,false,false,NULL);

ALTER TABLE public.duty_duties ADD client_id int8 NULL;
ALTER TABLE public.duty_duties ADD date_request date NULL;
ALTER TABLE public.duty_duties ADD date_expiry date NULL;


CREATE TABLE public.code_list_duties_services (
    code varchar(3) NOT NULL,
    description varchar(50) NULL,
    ord int8 NULL,
    icon varchar(255) NULL,
    misc varchar(255) NULL,
    properties jsonb NULL,
    CONSTRAINT code_list_duties_services_pk PRIMARY KEY (code)
);
CREATE UNIQUE INDEX code_list_duties_services_code_idx ON public.code_list_duties_services USING btree (code);

CREATE TABLE public.code_list_duties_task_types (
    code varchar(3) NOT NULL,
    description varchar(50) NULL,
    ord int8 NULL,
    icon varchar(255) NULL,
    misc varchar(255) NULL,
    properties jsonb NULL,
    CONSTRAINT code_list_duties_task_types_pk PRIMARY KEY (code)
);
CREATE UNIQUE INDEX code_list_duties_task_types_code_idx ON public.code_list_duties_task_types USING btree (code);


-- public.duty_duties_tasks definition

-- Drop table

-- DROP TABLE public.duty_duties_tasks;

CREATE TABLE public.duty_duties_tasks (
	id bigserial NOT NULL,
	task_name varchar(255) NULL,
	duty_id int8 NULL,
	user_id int8 NULL,
	date_created date NULL,
	date_expiry date NULL,
	task_type varchar(3) NULL,
	remarks varchar(255) NULL,
	meta jsonb NOT NULL DEFAULT '{}'::json,
	status varchar(3) NULL,
    ord int4 NULL,
	CONSTRAINT duty_duties_tasks_fk FOREIGN KEY (duty_id) REFERENCES public.duty_duties(id)  ON DELETE CASCADE
);
CREATE UNIQUE INDEX duty_duties_tasks_id_idx ON public.duty_duties_tasks USING btree (id);

INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('XDTSKAD','duty_tasks_list_add','SDUTEDT','addDutyTasks','','duty/duties','duty','Permission to add duty tasks','EXE','',1,false,false,NULL);

INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('XDTKGET','duty_tasks_list_get','SDUTIES','getDutyTasks','','duty/duties','duty','Permission to get Tasks list','EXE','',1,false,false,NULL);

INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('XDTKDEL','duty_tasks_list_delete','SDUTEDT','delDutyTasks','','duty/duties','duty','permission to delete task list','EXE','',1,false,false,NULL);

INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('XDTKUPD','duty_tasks_list_update','SDUTEDT','updDutyTasks','','duty/duties','duty','permission to update tasks','EXE','',1,false,false,NULL);

INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('XDTYCRT','duty_duties_create','SDUTIES','crtDuty','','duty/duties','duty','Permission to duty create status','EXE','',1,false,false,NULL);

INSERT INTO public.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','duty_duties_search_by_user','Form to add and edit duties',false,'<form id="duty_duties_form"  autocomplete="off">
	
	<div class="row">
	
		<div class="form-group col-md-4">
			<label for="task">{form_duty_duties_task}</label>
			<input id="task" type="text" class="form-control" name="main[task]" required>
			<input id="id" type="hidden" class="form-control" name="id" required>
		</div>
		
	
		<div class="form-group col-md-4">
			<label for="user_id">{form_duty_duties_user_id}</label>
			<select id="user_id" class="form-control" name="main[user_id]" data-list="/api/v1/users/" required></select>
		</div>
		
		<div class="form-group col-md-4">
			<label for="nota">{form_duty_duties_nota}</label>
			<input id="nota" class="form-control" name="meta[additionalFields][nota]" >
		</div>
		
		
		 <div class="form-group col-md-3">
			<label for="stanza">{form_action_visits_stanza}</label>
			<input class="form-control" id="stanza" name="meta[additionalFields][stanza]">
		</div>
		
		<div class="form-group col-md-4">
			<label for="targa">{form_duty_duties_targa}</label>
			<input id="targa" class="form-control" name="meta[additionalFields][targa]" >
		</div>
		<div class="form-group col-md-4">
			<label for="type">{form_duty_duties_type}</label>
			<input id="type" class="form-control" name="type" >
		</div>
	</div><br> 
</form>','{"form": [[{"id": "user_id_search", "key": "id", "cols": 3, "list": "api/v1/users/", "name": "user_id", "type": "dropdown", "label": "Duties by User", "values": "username", "onchange": "jivaCoreFunc.setFilter(event)", "autofocus": true}]]}',NULL,NULL,NULL,NULL,NULL,NULL,NULL);

-- Auto-generated SQL script #202312151329
UPDATE public.core_assets
	SET asset_parameters='{
  "form": [
    [
      {
        "id": "client_id",
        "key": "id",
        "cols": 6,
        "name": "client_id",
        "type": "typeahead",
        "label": "Cliente",
        "values": "entity_name,person_name",
        "mandatory": false,
        "createForm": "registry_list_form",
        "valueSearch": "api/v1/registry/search/id:",
        "typeaheadList": "api/v1/registry/search/entity_name!person_name:",
        "createEndpoint": "/api/v1/registry",
        "createdEntryFields": "entity_name,entity_brand,person_name,person_surname",
        "createEndpointMethod": "post"
      },
      {
        "id": "type",
        "cols": 3,
        "list": "/api/v1/misc/codelists/code_list_duties_services",
        "name": "type",
        "type": "dropdown",
        "label": "Service",
        "values": "description",
        "onchange": "jivaCoreOptions.unsavedData=true;setDutyTaskName()",
        "mandatory": false,
        "createForm": "duty_services_codelist_form",
        "defaultValue": "ZZZ",
        "createEndpoint": "/api/v2/admin/codelists/code_list_duties_services",
        "createdEntryFields": "description",
        "createEndpointMethod": "post"
      },
      {
        "id": "price",
        "cols": 2,
        "name": "meta[price]",
        "type": "text",
        "label": "Price",
        "autofocus": true
      },
      {
        "id": "currency",
        "cols": 1,
        "name": "meta[currency]",
        "type": "text",
        "label": "Currency",
        "autofocus": true
      }
    ],
    [
      {
        "id": "task",
        "cols": 6,
        "name": "task",
        "type": "text",
        "label": "Duty name",
        "autofocus": true,
        "mandatory": true,
        "relatedHidden": "id"
      },
      {
        "id": "date_request",
        "cols": 2,
        "name": "date_request",
        "type": "date",
        "label": "Date Request",
        "default": "today",
        "onchange": "jivaCoreOptions.unsavedData=true;checkAllDates();",
        "validate": "mandatory,date",
        "mandatory": true
      },
      {
        "id": "date_expiry",
        "cols": 2,
        "name": "date_expiry",
        "type": "date",
        "label": "Date Expiry",
        "onchange": "jivaCoreOptions.unsavedData=true;checkAllDates();",
        "mandatory": false
      },
      {
        "id": "user_id",
        "key": "id",
        "cols": 2,
        "list": "api/v1/users/",
        "name": "user_id",
        "type": "dropdown",
        "label": "Users",
        "values": "username",
        "onchange": "jivaCoreOptions.unsavedData=true;",
        "autofocus": true,
        "createForm": "core_users_form",
        "defaultValue": "ZZZ",
        "createEndpoint": "/api/v1/users/new",
        "createdEntryFields": "description",
        "createEndpointMethod": "post"
      }
    ],
    [
      {
        "id": "note",
        "cols": 12,
        "name": "meta[note]",
        "type": "richtext",
        "label": "Description",
        "onchange": "jivaCoreOptions.unsavedData=true;",
        "mandatory": false
      }
    ]
  ]
}'::jsonb
	WHERE asset_name='duty_duties_form';

-- Auto-generated SQL script #202312181422
UPDATE public.core_assets
	SET asset_parameters='{
  "form": [
    [
      {
        "id": "client_id",
        "key": "id",
        "cols": 6,
        "name": "client_id",
        "type": "typeahead",
        "label": "Cliente",
        "values": "entity_name,person_name",
        "autofocus": true,
        "mandatory": false,
        "createForm": "registry_list_form",
        "valueSearch": "api/v1/registry/search/id:",
        "typeaheadList": "api/v1/registry/search/entity_name!person_name:",
        "createEndpoint": "/api/v1/registry",
        "additionalClass": "form-control-sm",
        "createdEntryFields": "entity_name,entity_brand,person_name,person_surname",
        "createEndpointMethod": "post"
      },
      {
        "id": "type",
        "cols": 3,
        "list": "/api/v1/misc/codelists/code_list_duties_services",
        "name": "type",
        "type": "dropdown",
        "label": "Service",
        "values": "description",
        "onchange": "jivaCoreOptions.unsavedData=true;setDutyTaskName()",
        "mandatory": false,
        "createForm": "duty_services_codelist_form",
        "defaultValue": "ZZZ",
        "createEndpoint": "/api/v2/admin/codelists/code_list_duties_services",
        "additionalClass": "form-select-sm",
        "createdEntryFields": "description",
        "createEndpointMethod": "post"
      },
      {
        "id": "price",
        "cols": 2,
        "name": "meta[price]",
        "type": "text",
        "label": "Price",
        "autofocus": false,
        "additionalClass": "form-control-sm"
      },
      {
        "id": "currency",
        "cols": 1,
        "name": "meta[currency]",
        "type": "text",
        "label": "Currency",
        "autofocus": false,
        "additionalClass": "form-control-sm"
      }
    ],
    [
      {
        "id": "task",
        "cols": 6,
        "name": "task",
        "type": "text",
        "label": "Duty name",
        "mandatory": true,
        "relatedHidden": "id",
        "additionalClass": "form-control-sm"
      },
      {
        "id": "date_request",
        "cols": 2,
        "name": "date_request",
        "type": "date",
        "label": "Date Request",
        "default": "today",
        "onchange": "jivaCoreOptions.unsavedData=true;checkAllDates();",
        "validate": "mandatory,date",
        "mandatory": true,
        "additionalClass": "form-control-sm"
      },
      {
        "id": "date_start",
        "cols": 2,
        "name": "date_start",
        "type": "date",
        "label": "Date Start",
        "onchange": "jivaCoreOptions.unsavedData=true;checkAllDates();",
        "mandatory": false,
        "additionalClass": "form-control-sm"
      },
      {
        "id": "date_expiry",
        "cols": 2,
        "name": "date_expiry",
        "type": "date",
        "label": "Date Expiry",
        "onchange": "jivaCoreOptions.unsavedData=true;checkAllDates();",
        "mandatory": false,
        "additionalClass": "form-control-sm"
      }
    ],
    [
      {
        "id": "user_id",
        "key": "id",
        "cols": 2,
        "list": "api/v1/users/",
        "name": "user_id",
        "type": "dropdown",
        "label": "Users",
        "values": "username",
        "onchange": "jivaCoreOptions.unsavedData=true;",
        "autofocus": true,
        "createForm": "core_users_form",
        "defaultValue": "ZZZ",
        "createEndpoint": "/api/v1/users/new",
        "additionalClass": "form-select-sm",
        "createdEntryFields": "description",
        "createEndpointMethod": "post"
      }
      ],
    [
      {
        "id": "note",
        "cols": 12,
        "name": "meta[note]",
        "type": "richtext",
        "label": "Description",
        "onchange": "jivaCoreOptions.unsavedData=true;",
        "mandatory": false
      }
    ]
  ]
}'::jsonb
	WHERE asset_name='duty_duties_form';


ALTER TABLE public.duty_duties ADD date_start date NULL;


INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('BDYTSTS','duty_duties_edit_status_button','SDUTEDT','','','duty/duties','duty','Permission to status change button','BUT','fa-solid fa-play',1,false,false,NULL);

INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('BDYTCOM','duty_duties_complete','SDUTEDT','','','duty/duties','duty','Permission to status change button','BUT','fa-solid fa-check',1,false,false,NULL);


INSERT INTO public.core_sm_states (object_name,state_code,description,allowed_from,before_hook,after_hook,feedback,afterhook_once,feedback_once,prevent_feedback_on_afterhook,billable,meta,object_type) VALUES
	 ('duty_duties','HLD','Hold','["STR"]',NULL,NULL,'[{"type": "DRP", "fields": ["additionalFields"], "object": "sign_workorders"}, {"fields": ["additionalFields"], "object": "action_visits"}]',true,false,false,true,'{"kanban": {"ord": 3, "class": ["kanban-started"]}}',NULL);

INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('XDTYHLD','duty_hold_status','SDUTIES','hldDuty','','duty/duties','duty','Permission to duty hold status','EXE','',1,false,false,NULL);

INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('BDYTVST','duty_duties_view_status_button','SDUTEDT','','','duty/duties','duty','Permission to status change button','BUT','fa-solid fa-play',1,false,false,NULL);

INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('BDYTVCM','duty_duties_view_complete','SDUTEDT','','','duty/duties','duty','Permission to status change button','BUT','fa-solid fa-check',1,false,false,NULL);

INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('BDTMPSV','duty_duties_template_save','SDUTEDT','','','duty/duties','duty','Permission to save template button','BUT','fa-regular fa-rectangle-list',1,false,false,NULL);

INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('PDTPIPL','duty_pipelines_list','MDUTY','getObjects','','duty/pipelines','duty','Permission to pipelines page','PAG','fa-solid fa-handshake',2,false,false,NULL);

INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('SDTPIPL','duty_pipelines_list_view','PDTPIPL','','','duty/pipelines','duty','Permission to pipelines view section ','SEC','',1,false,false,NULL);
INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('SDPPLED','duty_pipelines_list_edit','PDTPIPL','','','duty/pipelines','duty','Permission to pipelines edit section ','SEC','',1,false,false,NULL);

INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('BDPLADD','duty_pipelines_add_button','SDTPIPL','','','duty/pipelines','duty','Permission to pipelines add button','BUT','fas fa-plus',1,false,false,NULL),
	 ('BDPLBCK','duty_pipelines_back_button','SDPPLED','','','duty/pipelines','duty','Permission to pipelines back button','BUT','fas fa-arrow-left',1,false,false,NULL),
	 ('BDPLDEL','duty_pipelines_delete_button','SDTPIPL','','','duty/pipelines','duty','Permission to pipelines delete button','BUT','fas fa-trash',1,false,false,NULL),
	 ('BDPLEDT','duty_pipelines_edit_button','SDTPIPL','','','duty/pipelines','duty','Permission to pipelines edit button','BUT','fas fa-edit',1,false,false,NULL),
	 ('BDPLSAV','duty_pipelines_save_button','SDPPLED','','','duty/pipelines','duty','Permission to pipelines save button','BUT','fas fa-save',1,false,false,NULL);


----------------------------------------------------------------------------------------------------------------------------------------------------------------


-- public.duty_pipelines definition

-- Drop table

-- DROP TABLE public.duty_pipelines;

CREATE TABLE public.duty_pipelines (
	id bigserial NOT NULL,
	"name" varchar(255) NULL,
	user_id int8 NULL,
	group_id int8 NULL,
	meta jsonb NOT NULL DEFAULT '{}'::json
);

INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('XPPLADD','duty_pipelines_list_add','SDPPLED','addDutyPipelines','','duty/pipelines','duty','Permission to add pipelines ','EXE','',1,false,false,NULL);
INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('XPPLUPD','duty_pipelines_list_update','SDPPLED','updDutyPipelines','','duty/pipelines','duty','permission to update pipelines','EXE','',1,false,false,NULL);
INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('XPPLDEL','duty_pipelines_list_delete','SDPPLED','delDutyPipelines','','duty/pipelines','duty','permission to delete pipeline','EXE','',1,false,false,NULL);
INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('XPPLGET','duty_pipelines_list_get','SDTPIPL','getDutyPipelines','','duty/pipelines','duty','Permission to get pipelines list','EXE','',1,false,false,NULL);
INSERT INTO public.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','duty_pipelines_form','Form to add and edit pipelines',false,NULL,'{"form": [[{"id": "name", "cols": 6, "name": "name", "type": "text", "label": "Name", "autofocus": false, "additionalClass": "form-control-sm"}]]}',NULL,NULL,NULL,NULL,NULL,NULL,NULL);
INSERT INTO public.core_permissions (code,permission_name,parent,permission_function,default_child,permission_namespace,"module",permission_description,permission_type,icon,ord,hidden,guest,meta) VALUES
	 ('XPPLPHS','duty_pipelines_phases_get','SDTPIPL','getPipelinePhases','','duty/pipelines','duty','Permission to get pipeline phases','EXE','',1,false,false,NULL);

ALTER TABLE public.duty_duties ADD pipeline_id int8 NULL;


-- Auto-generated SQL script #202401051037
UPDATE public.core_assets
	SET asset_parameters='{
  "form": [
    [
      {
        "id": "client_id",
        "key": "id",
        "cols": 4,
        "name": "client_id",
        "type": "typeahead",
        "label": "Cliente",
        "values": "entity_name,person_name",
        "autofocus": true,
        "mandatory": false,
        "createForm": "registry_list_form",
        "valueSearch": "api/v1/registry/search/id:",
        "typeaheadList": "api/v1/registry/search/entity_name!person_name:",
        "createEndpoint": "/api/v1/registry",
        "additionalClass": "form-control-sm",
        "createdEntryFields": "entity_name,entity_brand,person_name,person_surname",
        "createEndpointMethod": "post"
      },
      {
        "id": "type",
        "cols": 3,
        "list": "/api/v1/misc/codelists/code_list_duties_services",
        "name": "type",
        "type": "dropdown",
        "label": "Service",
        "values": "description",
        "onchange": "jivaCoreOptions.unsavedData=true;setDutyTaskName();setDutyPrice();",
        "mandatory": false,
        "createForm": "duty_services_codelist_form",
        "defaultValue": "ZZZ",
        "createEndpoint": "/api/v2/admin/codelists/code_list_duties_services",
        "additionalClass": "form-select-sm",
        "createdEntryFields": "description",
        "createEndpointMethod": "post"
      },
      {
        "id": "price",
        "cols": 2,
        "name": "meta[price]",
        "type": "text",
        "label": "Price",
        "autofocus": false,
        "additionalClass": "form-control-sm"
      },
      {
        "id": "currency",
        "cols": 1,
        "name": "meta[currency]",
        "type": "text",
        "label": "Currency",
        "autofocus": false,
        "additionalClass": "form-control-sm"
      },
      {
        "id": "user_id",
        "key": "id",
        "cols": 2,
        "list": "api/v1/users/",
        "name": "user_id",
        "type": "dropdown",
        "label": "Users",
        "values": "username",
        "onchange": "jivaCoreOptions.unsavedData=true;",
        "autofocus": true,
        "createForm": "core_users_form",
        "defaultValue": "ZZZ",
        "createEndpoint": "/api/v1/users/new",
        "additionalClass": "form-select-sm,not-available-free",
        "createdEntryFields": "description",
        "createEndpointMethod": "post"
      }
    ],
    [
      {
        "id": "task",
        "cols": 4,
        "name": "task",
        "type": "text",
        "label": "Duty name",
        "mandatory": true,
        "relatedHidden": "id",
        "additionalClass": "form-control-sm"
      },
      {
        "id": "pipeline_id",
        "key": "id",
        "cols": 2,
        "list": "api/v1/duty/pipelines/",
        "name": "pipeline_id",
        "type": "dropdown",
        "label": "Pipeline",
        "values": "name",
        "onchange": "jivaCoreOptions.unsavedData=true;",
        "createForm": "duty_pipelines_form",
        "createEndpoint": "api/v1/duty/pipelines/",
        "additionalClass": "form-select-sm",
        "createdEntryFields": "name",
        "createEndpointMethod": "post"
      },
      {
        "id": "date_request",
        "cols": 2,
        "name": "date_request",
        "type": "datetime",
        "label": "Request",
        "default": "todayAndNow",
        "onchange": "jivaCoreOptions.unsavedData=true;checkAllDates();",
        "validate": "mandatory,date",
        "mandatory": true,
        "additionalClass": "form-control-sm"
      },
      {
        "id": "date_start",
        "cols": 2,
        "name": "date_start",
        "type": "datetime",
        "label": "Start",
        "onchange": "jivaCoreOptions.unsavedData=true;checkAllDates();",
        "mandatory": false,
        "additionalClass": "form-control-sm"
      },
      {
        "id": "date_expiry",
        "cols": 2,
        "name": "date_expiry",
        "type": "datetime",
        "label": "Expiry",
        "onchange": "jivaCoreOptions.unsavedData=true;checkAllDates();",
        "mandatory": false,
        "additionalClass": "form-control-sm"
      }
    ],
    [
      {
        "id": "note",
        "cols": 12,
        "name": "meta[note]",
        "type": "richtext",
        "label": "Description",
        "onchange": "jivaCoreOptions.unsavedData=true;",
        "mandatory": false,
        "labelToggle": true
      }
    ]
  ]
}'::jsonb
	WHERE asset_name='duty_duties_form';

INSERT INTO public.core_sm_states (object_name,state_code,description,allowed_from,before_hook,after_hook,feedback,afterhook_once,feedback_once,prevent_feedback_on_afterhook,billable,meta,object_type) VALUES
	 ('duty_duties','STR','Started','["CRT", "ASG", "STR", "HLD"]',NULL,'<?php
require_once($_ENV[''JIVENV''][''funcFiles''][''getDutyDuties''][''filePath'']);
require_once($_ENV[''JIVENV''][''funcFiles''][''updDutyDuties''][''filePath'']);
require_once($_ENV[''JIVENV''][''funcFiles''][''getSettingValue''][''filePath'']);

$args[''id''] = %id%;
$functionOut = getDutyDuties($args);
$out[''getDuty''] = $functionOut;

$duty = $functionOut[''rows''][0];

if ($duty[''user_id''] == null) {
    
    $dutySettingValue = getSettingValue(''duty_settings'', ''duty_general_configuration'', TRUE);
    if (isset($dutySettingValue[''objValue''][''autoAssignUserOnEmptyStart'']) && $dutySettingValue[''objValue''][''autoAssignUserOnEmptyStart''] == true) {
        
        $updArgs[''id'']  = %id%;
        $updArgs[''user_id''] = $_ENV[''JIVENV''][''user''][''userData''][''id''];
        $updfunctionOut = updDutyDuties($updArgs);
        $out[''updDuty''] = $updfunctionOut;
    }
}
    
return $out;','[{"type": "DRP", "fields": ["additionalFields"], "object": "sign_workorders"}, {"fields": ["additionalFields"], "object": "action_visits"}]',true,false,false,true,'{"kanban": {"ord": 3, "class": ["kanban-started"]}}',NULL);

-- Auto-generated SQL script #202401091111
UPDATE public.core_sm_states
	SET allowed_from='["CRT", "STR", "HLD", "COM", "ASG"]'::jsonb
	WHERE object_name="duty_duties" and state_code = "COM";

