/* $Id$ */
/*============================================================================*
 |                 Copyright (c) 2017 Applaud Solutions UK Ltd                |
 |                             All rights reserved                            |
 *===========================================================================*/

SET VERIFY OFF
SET FEEDBACK OFF
SET SCAN OFF
WHENEVER OSERROR  EXIT FAILURE ROLLBACK
WHENEVER SQLERROR EXIT FAILURE ROLLBACK



DECLARE 

  e_dir_exists EXCEPTION;
  PRAGMA EXCEPTION_INIT(e_dir_exists, -31003);

  e_does_not_exists EXCEPTION;
  PRAGMA EXCEPTION_INIT(e_does_not_exists , -31001);

  result boolean;
  
BEGIN

  BEGIN

    result := DBMS_XDB.createfolder('/public/xxas/');
    result := DBMS_XDB.createfolder('/public/xxas/emp/');
    result := DBMS_XDB.createfolder('/public/xxas/emp/view/');

  EXCEPTION
    WHEN e_dir_exists THEN
      NULL;
  END;

  
  BEGIN

    DBMS_XDB.DeleteResource('/public/xxas/emp/view/absence-event.xml');

  EXCEPTION
    WHEN e_does_not_exists THEN
      NULL;
  END;

  
  result := DBMS_XDB.createresource('/public/xxas/emp/view/absence-event.xml',
'<View title="Absence" showSubmit="true" submitLabel="{message.XXAS_RB_COM_SAVE}" defaultFormHandler="xxas_absence_event_pkg.update_absence_event">
  <EditFields>

    <Container id="BASIC_GRP">

      <Hidden id="PERSON_ID"/>
      <Hidden id="ASSIGNMENT_ID"/>
      <Hidden id="ABSENCE_ATTENDANCE_ID"/>
      <Hidden id="TRANSACTION_ID"/>
      <Hidden id="TRANSACTION_STEP_ID"/>
      <Hidden id="SOURCE_BLOCK"/>
      <Hidden id="SAVED_SEARCH_ID"/>
      <Hidden id="CALLED_VIEW"/>
      <Hidden id="BUSINESS_GROUP_ID"/>
      <Hidden id="OBJECT_VERSION_NUMBER"/>
      <Hidden id="STARTDATE"/>
      <Hidden id="ENDDATE"/>
      <Hidden id="STARTTIME"/>
      <Hidden id="ENDTIME"/>
	    <Hidden id="VACATION_RULES_PERM"/>
	    <Hidden id="REDIRECT_NOTIF_OLD"/>
      <Hidden id="MANAGER_ID"/>
      <ListItem id="APPROVERS" style="row" listFunction="xxas_selfservice_workflow_pkg.get_workflow_details2" visible="false"/>
      <Combolist id="EMPLOYEES" label="{message.XXAS_EMP_ABS_EVENT_EMPLOYEE}" listProvider="REST:calendar-event/search/loggedinemp-or-dir-reportee-only?q={searchText}&amp;dateStart=${fieldNR.STARTDATE}&amp;dateEnd=${fieldNR.ENDDATE}&amp;savedSearchId=${fieldNR.SAVED_SEARCH_ID}&amp;managerId=${fieldNR.MANAGER_ID}" 
       required="true" longlist="true" enabled="true" visible="true" triggerName="ABS_DUR_CALC_OL_ABS_ACR_BAL" triggerMethod="POST" hideIf="!model.BASIC_GRP.CALLED_VIEW.value || model.BASIC_GRP.CALLED_VIEW.value == &apos;EMP&apos;"/>
      <Combolist id="OVERRIDE_ASSIGNMENT_ID" label="{message.XXAS_EMP_ABS_EVENT_OR_ASG_ID}" required="false" visible="false" enabled="true"
       listProvider="REST:calendar-event/search/emp-worker-asgs?q={searchText}&amp;dateStart=${fieldNR.STARTDATE}&amp;personId=${fieldNR.PERSON_ID}"/>
      <Poplist id="LEAVE_STATUS" label="{message.XXAS_EMP_ABS_STATUS}" visible="true" enabled="true" required="true" 
       listProvider="VALUE_SET_NAME:Applaud Absence Statuses"/>
      <Poplist id="ABSENCE_TYPE_ID" label="{message.XXAS_EMP_ABS_TYPE}" enabled="true" required="true" 
       listProvider="VALUE_SET_NAME:Applaud Absence Types" triggerName="ABS_DATE_TIME_SHOW_REASONS_ACR_BAL" triggerMethod="POST"/>
      <Combolist id="ABS_ATTENDANCE_REASON_ID" label="{message.XXAS_EMP_REASON}" enabled="true" required="false" visible="true" 
       longlist="false" listProvider="REST:absence-event/reasons?personId=${field.PERSON_ID}&amp;absAttTypeId=${field.ABSENCE_TYPE_ID}"/>
      <Date id="DATE_NOTIFICATION" label="{message.XXAS_EMP_NOTIFIED}" enabled="true" required="false" visible="false"/>
      <DateTimeRange id="DATE_TIME_RANGE" label="{message.XXAS_EMP_ABS_EVENT_DTR}" startDateLabel="{message.XXAS_EMP_START_DATE}" endDateLabel="{message.XXAS_EMP_END_DATE}" 
       startTimeLabel="{message.XXAS_EMP_START_TIME}" endTimeLabel="{message.XXAS_EMP_END_TIME}" visible="false" enabled="true" 
       startDateRequired="true" triggerName="ABS_DUR_CALC_OL_ABS_ACR_BAL" triggerMethod="POST"/>
      <DateRange id="DATE_RANGE" label="{message.XXAS_EMP_ABS_EVENT_DR}" startDateLabel="{message.XXAS_EMP_START_DATE}" endDateLabel="{message.XXAS_EMP_END_DATE}" 
       visible="false" enabled="true" startDateRequired="true" triggerName="ABS_DUR_CALC_OL_ABS_ACR_BAL" triggerMethod="POST"/>
      <Hidden id="DURATION_TYPE"/>
      <Number id="DURATION_DAYS" label="{message.XXAS_EMP_ABS_EVENT_DUR_DAYS}" enabled="true" required="false" visible="false" decimalPrecision="4"/>
      <Number id="DURATION_HOURS" label="{message.XXAS_EMP_ABS_EVENT_DUR_HOURS}" enabled="true" required="false" visible="false" decimalPrecision="4"/>

	  <Poplist id="REDIRECT_NOTIF" label="{message.XXAS_EMP_ABS_REDIRECT}" description="{message.XXAS_EMP_ABS_REDIRECT_DESC}" listProvider="LOOKUP_TYPE:YES_NO" showAsBoolean="true" positiveBooleanValue="Y" hideIf="!model.BASIC_GRP.VACATION_RULES_PERM.value || model.BASIC_GRP.VACATION_RULES_PERM.value == &apos;N&apos;" />
	  <Poplist id="RULE" label="{message.XXAS_NOTIF_RULE}" required="true" listProvider="LOOKUP_TYPE:XXAS_COM_NOTIF_RULES" visible="true" hideIf="!model.BASIC_GRP.REDIRECT_NOTIF.value ||model.BASIC_GRP.REDIRECT_NOTIF.value==&apos;N&apos;"/>
	  <Combolist id="GRANTEE" label="{message.XXAS_NOTIF_ASSIGNEE}" longlist="true"  listProvider="REST:wfroles/vac-rule-roles?q={searchText}" required="true" hideIf="!model.BASIC_GRP.REDIRECT_NOTIF.value ||model.BASIC_GRP.REDIRECT_NOTIF.value==&apos;N&apos;"/>
      <Combolist id="REPLACEMENT_PERSON_ID" label="{message.XXAS_REPLACED_BY}" visible="false" enabled="true" required="false" longlist="true" 
       emptyValue="{message.XXAS_EMP_ABS_EVENT_REP_BY_SRCH}" listProvider="VALUE_SET_NAME:Applaud Per People List"/>      
      <Flexfield applicationId="800" descriptiveFlexfieldName="PER_ABSENCE_ATTENDANCES" descriptiveFlexContextCode="${param.pInformationType}"/>
      <Flexfield applicationId="800" descriptiveFlexfieldName="PER_ABS_DEVELOPER_DF" descriptiveFlexContextCode="${param.pDeveloperContextCode}"/>

      <TextArea id="COMMENTS_TO_APPROVER" label="{message.XXAS_RB_TCM_APPR_CMNTS}" enabled="true" required="false" visible="true" 
       maxChars="4000"/>

      <MultiRow id="ATTACHMENTS" createAllowed="true" toBeInSingleRow="true" createLabel="{message.XXAS_EMP_ABS_EVENT_ADD_ATTACH}" xdbUri="/public/xxas/emp/view/attach.xml"/>

    </Container>

     <Container id="PROJECTED_BALANCE" label="{message.XXAS_EMP_ABS_EVENT_PROJ_BAL}" visible="false">
        <Date id="EFFECTIVE_AT" label="{message.XXAS_ACC_BALANCES_AT}" enabled="true" required="true" visible="true" triggerName="ABS_PROJ_BAL_ACCR_PLAN" triggerMethod="POST"/>
        <Poplist id="ACCRUAL_PLAN_ID" label="{message.XXAS_ACCRUAL_PLAN}" required="true" listProvider="REST:jobs/${field.ASSIGNMENT_ID}/accrual-plans/absence-type/${field.ABSENCE_TYPE_ID}" hideIf="!field.values || field.values.length &lt; 2" triggerName="ABS_PROJ_BAL_ACCR_PLAN" triggerMethod="POST"/>
        <Html id="HTML_TEXT" visible="false"/>
        <Item id="ACCRUAL_CHART" style="detail" itemFunction="xxas_absence_management_pkg.leave_balance_chart"/>
     </Container>

    <Container id="OVERLAP_ABSENCES" label="{message.XXAS_EMP_ABS_EVENT_OL_ABSENCES}" hideIf="!model.BASIC_GRP.ABSENCE_TYPE_ID.value || ((model.BASIC_GRP.DURATION_TYPE.value==&apos;H&apos; || model.BASIC_GRP.DURATION_TYPE.value==&apos;XXASNODATA&apos;)  &amp;&amp; ((!model.BASIC_GRP.DATE_TIME_RANGE.value.startDate &amp;&amp; !model.BASIC_GRP.DATE_TIME_RANGE.value.endDate) || 
     (!model.BASIC_GRP.DATE_TIME_RANGE.value.startDate &amp;&amp; model.BASIC_GRP.DATE_TIME_RANGE.value.endDate) || (model.BASIC_GRP.DATE_TIME_RANGE.value.startDate &amp;&amp; !model.BASIC_GRP.DATE_TIME_RANGE.value.endDate))) || 
	 (model.BASIC_GRP.DURATION_TYPE.value==&apos;D&apos; &amp;&amp; ((!model.BASIC_GRP.DATE_RANGE.value.startDate &amp;&amp; !model.BASIC_GRP.DATE_RANGE.value.endDate) || 
     (!model.BASIC_GRP.DATE_RANGE.value.startDate &amp;&amp; model.BASIC_GRP.DATE_RANGE.value.endDate) || (model.BASIC_GRP.DATE_RANGE.value.startDate &amp;&amp; !model.BASIC_GRP.DATE_RANGE.value.endDate)))">
     <ListItem id="OL_ABSENCES_LI" visible="true" style="row"
      listFunction="xxas_absence_event_pkg.ol_absence_entries" noDataMessage="{message.XXAS_OL_ABSENCES_NM}"/>
    </Container>

  </EditFields>

</View>' ); 
xxas_forms_pkg.update_forms_resource('/public/xxas/emp/view/absence-event.xml');
END;
/
COMMIT;
EXIT;