----------------------------------------------------------------------------------------------------------------------------------------------------------------
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_form','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": "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}]]}',NULL,NULL,NULL,NULL,NULL,NULL,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) VALUES
	 ('form','duty_duties_filters_form','Form for duty filters',false,'<form id="objects_filters">
    <div class="row is_not_supplier">
        <div class="form-group col-md-1">
            <label for="filter_id">{duty_duties_id}</label>
            <input type="text" class="form-control" id="filter_id" data-filter-type="eq" name="dd.id"
                onkeydown="jivaCoreFunc.setFilter(event);">
        </div>
        <div class="form-group col-md-3">
            <label for="filter_task">{duty_duties_task}</label>
            <input class="form-control" id="filter_task" data-filter-type="like" data-empty-first="true"
                name="dd.task" onkeydown="jivaCoreFunc.setFilter(event);">
        </div>
        <div class="form-group col-md-3">
            <label for="filter_status">{duty_duties_status}</label>
            <input type="text" class="form-control" id="filter_status" data-filter-type="like" name="dd.status"
                onkeydown="jivaCoreFunc.setFilter(event);">
        </div>
    </div><br>
</form>
','{}',NULL,NULL,NULL,NULL,NULL,NULL);



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

-- 37 permissions for duty module;

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
	 ('XDTYSTR','duty_duties_start','SDUTIES','strDuty','','duty/duties','duty','Permission to duty start status','EXE','',1,false,false,NULL),
	 ('XMOBMET','duty_set_mobile_meta','JDUTY','setMobileMeta','','duty','duty','Permission to set mobile meta','EXE','',1,false,false,NULL),
	 ('XDUTDEL','duty_duties_list_delete','SDUTEDT','delDutyDuties','','duty/duties','duty','permission to delete duty list','EXE','',1,false,false,NULL),
	 ('XDUTGET','duty_duties_list_get','SDUTIES','getDutyDuties','','duty/duties','duty','Permission to get duties list','EXE','',1,false,false,NULL),
	 ('BDTYEND','duty_duties_end','SDUTIES','','','duty/duties','duty','Permission to end duty button','BUT','fas fa-chess-board',1,false,false,NULL),
	 ('XTEMPCM','temporary_complete_status_change','SDUTIES','hafterHookDutyCom','','duty/duties','duty','Permission to verify visit status change through duty','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
	 ('MDUTY','duty',NULL,NULL,NULL,'duty','duty','Access to duty module','MOD','fa-solid fa-truck-ramp-box',500,false,false,NULL),
	 ('BDUTSAV','duty_duties_list_edit_save','SDUTEDT','','','duty/duties','duty','Permission to duties save button','BUT','fas fa-save',1,false,false,NULL),
	 ('JDUTY','mobile_duty_jason','MDUTY','dutyPage.json','','duty/mobile','duty','Permission to view duty page mobile','MOB','',1,false,false,NULL),
	 ('SDUTEDT','duty_duties_list_edit','PDUTIES','','','duty/duties','duty','Permission to duties edit section','SEC','',1,false,false,NULL),
	 ('XDTYUSR','duty_add_user','SDUTIES','addUserDuty','','duty/duties','duty','Permission to add user to duty','EXE','',1,false,false,NULL),
	 ('BDTYASS','duty_duties_assign','SDUTIES','','','duty/duties','duty','Permission to assign user button','BUT','fas fa-id-card-alt',1,false,false,NULL),
	 ('PDUTIES','duty_duties_list','MDUTY','getObjects','','duty/duties','duty','Permission to duties page','PAG','far fa-address-card',1,false,false,NULL),
	 ('SDUTIES','duty_duties_list_view','PDUTIES','','','duty/duties','duty','Permission to duties view section ','SEC','',1,false,false,NULL),
	 ('BDUTBCK','duty_duties_list_edit_back','SDUTEDT','','','duty/duties','duty','Permission to duties back button','BUT','fas fa-arrow-left',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
	 ('XDTYCOM','duty_complete_status','SDUTIES','comDuty','','duty/duties','duty','Permission to duty complete status','EXE','',1,false,false,NULL),
	 ('BDTYSTR','duty_duties_start_button','SDUTIES','','','duty/duties','duty','Permission to duty start button','BUT','fas fa-flag-checkered',1,false,false,NULL),
	 ('BDUTDEL','duty_duties_list_view_delete','SDUTIES','','','duty/duties','duty','Permission to duties delete button','BUT','fas fa-trash',1,false,false,NULL),
	 ('BDUTEDT','duty_duties_list_view_edit','SDUTIES','','','duty/duties','duty','Permission to duties edit button','BUT','fas fa-edit',1,false,false,NULL),
	 ('XDUTUPD','duty_duties_list_update','SDUTEDT','updDutyDuties','','duty/duties','duty','permission to update duties','EXE','',1,false,false,NULL),
	 ('BDUTADD','duty_duties_list_view_add','SDUTIES','','','duty/duties','duty','Permission to duties add button','BUT','fas fa-plus',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
	 ('XUSEDUT','duty_user_get_duties','JDUTY','getUserDuties','','duty/mobile','duty','Permission to get duties for user','EXE','',1,false,false,NULL),
	 ('XDUTADD','duty_duties_list_add','SDUTEDT','addDutyDuties','','duty/duties','duty','Permission to add duties ','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
	 ('BDTYSRC','duty_duties_button_search','SDUTIES','','','duty/duties','duty',' Permission to search button','BUT','fas fa-search',1,false,false,NULL),
	 ('BDTYFLT','duty_duties_button_filters','SDUTIES','','','duty_duties','duty','Permission to filter button','BUT','fas fa-filter',1,false,false,NULL),
	 ('BDTREMV','duty_duties_button_filters_remove','SDUTIES','','','duty_duties','duty','Permissiont to remove filter button','BUT','fas fa-times',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
	 ('BDYTRPR','duty_duties_repaired','SDUTEDT','','','duty/duties','duty','Permission to repaired button','BUT','fa-solid fa-hammer',1,false,false,NULL);

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


INSERT INTO public.core_settings (setting_type,setting_name,value,properties,ord) VALUES
	 ('duty_settings','duty_general_configuration','{"autoUnassign": false, "autoUnassignSeconds": 600, "avoidAutoAssignOnDispatcherAvailable": false, "maximumAutoassignedDuties": 1, "assignWaitingTimeForScheduledDuties": 1800}',
	 '{"section_desc": "Manage duty settings", "section_icon": "fa-solid fa-truck-ramp-box", 
	 "setting_desc": "Duty Conguration", "setting_icon": "fas fa-edit", "section_button": "Manage", 
	 "setting_button": "Configure"}',25);  

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
	 ('BDCRTDV','duty_create_visit_delivery','SDUTEDT','','','duty/duties','duty','Permission to create visit delivery button','BUT','fa-solid fa-truck',1,false,false,NULL);

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



-- ****************************************************************************************************************************************************************
--                                             VARIES WITH EACH INSTALLATION
-- ****************************************************************************************************************************************************************


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


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','CRT','Created','["", "ASG"]',NULL,'/*
require_once($_ENV[''JIVENV''][''funcFiles''][''updDutyDuties''][''filePath'']);

$arg[''id''] = %id%;
$arg[''user_id''] = "";

$updDuty = updDutyDuties($arg);
$out[''dutyUpdate''] = $updDuty;



require_once($_ENV[''JIVENV''][''funcFiles''][''getDutyDuties''][''filePath'']);

$functionOut = json_decode(getDutyDuties(%id%), TRUE);
//print_r ($functionOut);
$dutyObj = $functionOut[''rows''][0];
$services = $dutyObj[''task''];

//$signObj[''meta''][''duty_duties''][$services] = %id%;
// $visitObj[''object''] = $workorderObj[''object''];
// $visitObj[''services''] = $workorderObj[''services''];
// $visitObj[''client_id''] = $workorderObj[''client_id''];

$dutyMeta = $dutyObj[''meta''];
// print_r ($dutyMeta);

$signId = $dutyMeta[''sign_workorders''][$services][''id''];
$woMeta[''duty_duties''][$services][''id''] = %id%;
$woMetaOut = setMeta (''sign_workorders'', $signId , $woMeta, true);

$visitId = $dutyMeta[''action_visits''][''id''];
$avMeta[''duty_duties''][$services][''id''] = %id%;
$avMetaOut = setMeta (''action_visits'', $visitId , $avMeta, true);

$_ENV[''JIVENV''][''woMetaOut''] = $woMeta;
$_ENV[''JIVENV''][''avMetaOut''] = $avMeta;
$changed = $avMetaOut;
*/','[{"type": "DRP", "fields": ["additionalFields"], "object": "sign_workorders"}, {"fields": ["additionalFields"], "object": "action_visits"}]',false,false,false,true,'{"kanban": {"ord": 1, "class": ["kanban-created"]}}',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','ASG','Assigned','["", "CRT", "ASG"]',NULL,'
require_once($_ENV[''JIVENV''][''funcFiles''][''getDutyDuties''][''filePath'']);
require_once($_ENV[''JIVENV''][''funcFiles''][''getDutyTasks''][''filePath'']);
require_once($_ENV[''JIVENV''][''funcFiles''][''updDutyTasks''][''filePath'']);

$dutyArgs[''id''] = %id%;
$getDuty = getDutyDuties($dutyArgs);

$userID = $getDuty[''rows''][0][''user_id''];

$taskArgs[''duty_id''] = %id%;
$getTasks = getDutyTasks($taskArgs);

if(count($getTasks[''rows'']) > 0){
	for ($i=0; $i < count($getTasks[''rows'']); $i++) { 
	    $task = $getTasks[''rows''][$i];
	    $taskID = $task[''id''];
	
	    $arg[''id''] = $taskID;
	    $arg[''user_id''] = $userID;
	
	    if ($task[''user_id''] == null) {
	        $updTask = updDutyTasks($arg);
	        $out[''taskUpdate''] = $updTask;
	    }
	  }
}
/*
require_once($_ENV[''JIVENV''][''funcFiles''][''getDutyDuties''][''filePath'']);
    require_once($_ENV[''JIVENV''][''funcFiles''][''getUserDetails''][''filePath'']);
    require_once($_ENV[''JIVENV''][''funcFiles''][''sendMessage''][''filePath'']);

    $functionOut = json_decode(getDutyDuties(%id%), TRUE);

    $userId	= $functionOut[''rows''][0][''user_id''];

    $userDetailOut = json_decode(getUserDetails($userId), TRUE);
    
    $mail = $userDetailOut[''rows''][0][''email''];

    if ($mail != null || $mail != "") {

        // try {
            sendMessage(
                array(
                    "id"=>%id%,
                    "template" => "new_duty_template",
                    "recipients" => $mail
                )
            );
        // } catch(Exception $e) {
        //     $out[''error''] = true;
        //     $out[''message''] = $e->getMessage();
        //   }
      
    }
    // else{
    //     $out[''error''] = true;
    //     $out[''message''] = "Cannot send mail to this user";
    // }

 */','[]',false,false,false,true,'{"kanban": {"ord": 2, "class": ["kanban-assigned"]}}',NULL);

-- Auto-generated SQL script #202401080819
UPDATE public.core_sm_states
	SET after_hook='<?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;'
	WHERE object_name='duty_duties' AND state_code='STR';

IINSERT 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','COM','Complete','["CRT", "STR", "COM", "ASG"]',NULL,'require_once($_ENV[''JIVENV''][''funcFiles''][''getDutyDuties''][''filePath'']);

//     $functionOut = json_decode(getDutyDuties(%id%), TRUE);
    
//     $dutyObj = $functionOut[''rows''][0];
//     $out[''dutyObj''] = $dutyObj;
//     $visitID = $dutyObj[''meta''][''action_visits''][''id''];
    
    
//     require_once($_ENV[''JIVENV''][''funcFiles''][''getVisits''][''filePath'']);
    
//     $functionOut = json_decode(getVisits($visitID), TRUE);
    
//     $visitObj = $functionOut[''rows''][0];
    
//     $out[''visit''] = $visitObj;
    
//     $visStatus = $visitObj[''status''];
    
    
//     if ($visStatus == ''RTL'') {
    
//         require_once($_ENV[''JIVENV''][''funcFiles''][''outVisits''][''filePath'']);
    
//         $outVisitStatus = json_decode(outVisits($visitID), TRUE);
    
//         $changed = $outVisitStatus;

//         require_once($_ENV[''JIVENV''][''funcFiles''][''freePosition''][''filePath'']);
    
//         $freePos = json_decode(freePosition($visitID), true);

//         $out[''freePos''] = $freePos;
    
//     }else{
    
//         require_once($_ENV[''JIVENV''][''funcFiles''][''confirmVisits''][''filePath'']);
    
//         $inVisitStatus = json_decode(confirmVisits($visitID), TRUE);
    
//         $changed = $inVisitStatus;

//     }','[]',true,false,false,true,'{"kanban": {"ord": 5, "class": ["kanban-completed"]}}',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
	 ('SDUTREM','duty_reminders_view','PDUTREM','','','duty/reminders','duty','Permission to reminders view section','SEC','',1,false,false,NULL),
	 ('BDRMADD','duty_reminders_view_add','SDUTREM','','','duty/reminders','duty','Permission to duty reminders add button','BUT','fas fa-plus',1,false,false,NULL),
	 ('BDRMEDT','duty_reminders_view_edit','SDUTREM','','','duty/reminders','duty','Permission to duty reminders edit button','BUT','fas fa-edit',1,false,false,NULL),
	 ('BDRMDEL','duty_reminders_view_del','SDUTREM','','','duty/reminders','duty','Permission to duty reminders delete button','BUT','fas fa-trash',1,false,false,NULL),
	 ('XDRMGET','duty_reminders_get','SDUTREM','getDutyReminders','','duty/reminders','duty','Permission to get duty reminders','EXE','',1,false,false,NULL),
	 ('SSRMEDT','duty_reminders_edit','PDUTREM','','','duty/reminders','duty','Permission to duty reminders edit section','SEC','',1,false,false,NULL),
	 ('BDRMSAV','duty_reminders_edit_save','SSRMEDT','','','duty/reminders','duty','Permission to duty reminders save button','BUT','fas fa-save',1,false,false,NULL),
	 ('BDRMBCK','duty_reminders_edit_back','SSRMEDT','','','duty/reminders','duty','Permission to duty reminders back button','BUT','fas fa-arrow-left',1,false,false,NULL),
	 ('XDRMDEL','duty_reminders_delete','SSRMEDT','delDutyReminders','','duty_reminders','duty','Permission to delete duty reminders','EXE','',1,false,false,NULL),
	 ('XDRMADD','duty_reminders_add','SSRMEDT','addDutyReminders','','duty/reminders','duty','Permission to add duty reminders','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
	 ('XDRMUPD','duty_reminders_update','SSRMEDT','updDutyReminders','','duty/reminders','duty','Permission to update duty reminders','EXE','',1,false,false,NULL),
	 ('PDUTREM','duty_reminders','MDUTY','getObjects','','duty/reminders','duty','Permission to reminders page','PAG','fa-solid fa-business-time',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
	 ('PDUNEWS','duty_news','MDUTY','getObjects','','duty/news','duty','Permission to news page','PAG','fa-regular fa-newspaper',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
	 ('XDTNWGT','duty_news_get','PDUNEWS','getDutyNews','','count/invoices','count','Permission to retrieve news','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
	 ('XDTNWAD','duty_news_add','PDUNEWS','addDutyNews','','count/invoices','count','Permission to add news','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
	 ('XDTNWUP','duty_news_upd','PDUNEWS','updDutyNews','','count/invoices','count','Permission to update news','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
	 ('XDTNWDL','duty_news_del','PDUNEWS','delDutyNews','','count/invoices','count','Permission to delete news','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
	 ('PDUTNWS','duty_news_page','MDUTY','getObjects','','duty/news','duty','Duty news management page','PAG','fa-solid fa-arrow-right-to-city',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
	 ('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);

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);

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);

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_services_codelist_form','Duties services codelist form',false,NULL,'{"form": [[{"id": "code", "cols": 2, "name": "code", "type": "text", "label": "Code", "mandatory": true, "additionalClass": "form-control-sm"}, {"id": "description", "cols": 6, "name": "description", "type": "text", "label": "Description", "onchange": "generateDutyServiceCode(this)", "autofocus": true, "mandatory": true, "additionalClass": "form-control-sm"}, {"id": "properties.firstPrice", "cols": 2, "name": "properties[firstPrice]", "type": "text", "label": "Price", "mandatory": false, "customFunction": "setServicePrice", "additionalClass": "eur_decimal,form-control-sm", "customFunctionParams": "code=$out[\"code\"],first_price=$args[\"properties\"][\"firstPrice\"]"}, {"id": "type", "cols": 2, "list": "/api/v1/misc/codelists/code_list_count_measure_unit", "name": "type", "type": "dropdown", "label": "Unit", "values": "description", "mandatory": false, "createForm": "duty_services_codelist_form", "defaultValue": "EVR", "createEndpoint": "/api/v2/admin/codelists/code_list_count_measure_unit", "additionalClass": "form-select-sm", "createdEntryFields": "description", "createEndpointMethod": "post"}]]}',NULL,NULL,NULL,NULL,NULL,NULL,NULL);
