/* $Id$ */
/*============================================================================*
 |                 Copyright (c) 2016 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/cwkleaverrequest.xml');

  EXCEPTION
    WHEN e_does_not_exists THEN
      NULL;
  END;

  
  result := DBMS_XDB.createresource('/public/xxas/emp/view/cwkleaverrequest.xml',
'<View showSubmit="true" submitLabel="{message.XXAS_RB_COM_SAVE}" title="Contingent Worker leaver request" defaultFormHandler="xxas_periods_of_placement_pkg.submit_cwk_leaver_request">

  <EditFields>

    <Container id="TERM_GRP" label="{message.XXAS_MSS_TERM_GRP}">
      <Hidden id="PERSON_ID"/>
      <Hidden id="DATE_START"/>
      <Hidden id="PERIOD_OF_PLACEMENT_ID"/>
      <Hidden id="ASSIGNMENT_ID"/>
      <Hidden id="TRANSACTION_ID"/>
      <Hidden id="TRANSACTION_STEP_ID"/>
      <Hidden id="OBJECT_VERSION_NUMBER"/>
      <ListItem id="APPROVERS" style="row" listFunction="xxas_selfservice_workflow_pkg.get_workflow_details2" visible="false"/>
      <Poplist id="EFFECTIVE_DATE_OPTION" label="{message.XXAS_MSS_EFFECTIVE_DATE_OPTION}" visible="true" required="true" listProvider="LOOKUP_TYPE:XXAS_MSS_TERM_EFF_DATE_OPTION" enabled="true"/>
      <Date id="LAST_DAY_OF_WORK" enabled="true" label="{message.XXAS_MSS_ACTUAL_TERM_DATE}" visible="true" required="true" hideIf="!model.TERM_GRP.EFFECTIVE_DATE_OPTION.value || model.TERM_GRP.EFFECTIVE_DATE_OPTION.value.id == &apos;A&apos;"/>
      <Date id="FINAL_APPROVER_DATE" enabled="false" label="{message.XXAS_MSS_ACTUAL_TERM_DATE}" visible="false" hideIf="!model.TERM_GRP.EFFECTIVE_DATE_OPTION.value || model.TERM_GRP.EFFECTIVE_DATE_OPTION.value.id == &apos;E&apos;"/>
      <Poplist id="LEAV_REAS" label="{message.XXAS_MSS_LEAV_REAS}" enabled="true" visible="true" listProvider="LOOKUP_TYPE:HR_CWK_TERMINATION_REASONS"/>
      <Poplist id="PERSON_TYPE" label="{message.XXAS_MSS_PERSON_TYPE}" enabled="true" required="false" listProvider="VALUE_SET_NAME:XXAS_EX_CWK_Person_Types"/>
      <Poplist id="ASG_STATUS" label="{message.XXAS_MSS_ASG_STATUS}" enabled="true" required="false" visible="false" listProvider="VALUE_SET_NAME:XXAS_Terminated_CWK_Statuses"/>
      <Poplist id="REHIRE_FLAG" label="{message.XXAS_MSS_REHIRE_FLAG}" enabled="true" listProvider="LOOKUP_TYPE:YES_NO" visible="false"/>
      <TextInput id="REHIRE_REASON" label="{message.XXAS_MSS_REHIRE_REASON}" enabled="true" visible="false"/>
      <Hidden id="IS_MANAGER"/>
      <Hidden id="DIRECT_REPORTS_COUNT"/>
      <Hidden id="IS_ORG_INFO"/>
      <Hidden id="PEND_REQ"/>
    </Container>

    <Container id="REASSIGN_GRP" label="{message.XXAS_MSS_REASSIGN_GRP}" hideIf="model.TERM_GRP.IS_MANAGER.value == &apos;N&apos;">

      <Poplist id="REASSIGN_INDIVIDUAL_DRS" label="{message.XXAS_MSS_REASSIGN_IND_DRS}" listProvider="LOOKUP_TYPE:YES_NO" enabled="true"
       value="N" showAsBoolean="true" positiveBooleanValue="Y" hideIf="model.TERM_GRP.PEND_REQ.value == &apos;Y&apos;"/>
      <Date id="EFFECTIVE_DATE_DR" label="{message.XXAS_MSS_EFFECTIVE_DATE_DR}" enabled="true" required="true" visible="false" 
       hideIf="model.REASSIGN_GRP.REASSIGN_INDIVIDUAL_DRS.value == &apos;Y&apos; || model.TERM_GRP.PEND_REQ.value == &apos;Y&apos;"/>
      <Combolist id="NEW_MANAGER_DR" label="{message.XXAS_MSS_NEW_MANAGER_DR}" enabled="true" required="true" listProvider="REST:peoplesearch/dir-reportee?q={searchText}" longlist="true" 
       hideIf="model.REASSIGN_GRP.REASSIGN_INDIVIDUAL_DRS.value == &apos;Y&apos; || model.TERM_GRP.PEND_REQ.value == &apos;Y&apos;"/>

      <MultiRow id="DIRECT_REPORTS" xdbUri="/public/xxas/emp/view/directreports.xml" visible="true" 
       hideIf="model.REASSIGN_GRP.REASSIGN_INDIVIDUAL_DRS.value == &apos;N&apos; &amp;&amp; model.TERM_GRP.PEND_REQ.value == &apos;N&apos;"/>

    </Container>

    <Container id="RELATION_GRP" label="{message.XXAS_MSS_RELATION_GRP}" hideIf="model.TERM_GRP.IS_ORG_INFO.value == &apos;N&apos;">

      <Poplist id="ORG_UPDATE_NEW_MANAGER" label="{message.XXAS_MSS_ORG_UPDATE_NEW_MGR}" listProvider="LOOKUP_TYPE:YES_NO" enabled="true"
       value="N" showAsBoolean="true" positiveBooleanValue="Y" hideIf="model.TERM_GRP.PEND_REQ.value == &apos;Y&apos;"/>

      <MultiRow id="ORG_INFORMATION" xdbUri="/public/xxas/emp/view/orgmgr.xml" visible="true" />

    </Container>

    <Container id="ADDL_INFO_GRP" label="{message.XXAS_MSS_ADDL_INFO_GRP}">
      <Flexfield applicationId="800" descriptiveFlexfieldName="PER_PERIODS_OF_PLACEMENT"/>
      <Flexfield applicationId="800" descriptiveFlexfieldName="PER_PDP_DEVELOPER_DF"/>
      <TextInput id="COMMENTS_TO_APPROVER" label="{message.XXAS_RB_TCM_APPR_CMNTS}" enabled="true" required="false"/>
    </Container>

    <Container id="ATTACH_GRP" label="{message.XXAS_RB_EMP_ATTACHMENTS}">
      <Attachment id="ATTACHMENTS" label="{message.XXAS_RB_EMP_ATTACHMENTS}" enabled="true" required="false" entityName="PQH_SS_ATTACHMENT" pk1Field="INSTANCE_PK2_VALUE" categoryCode="MISC"/>
    </Container>

  </EditFields>

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