/* $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/timecard-event.xml');

  EXCEPTION
    WHEN e_does_not_exists THEN
      NULL;
  END;

  
  result := DBMS_XDB.createresource('/public/xxas/emp/view/timecard-event.xml',
'<View title="Log Time" showSubmit="true" submitLabel="{message.XXAS_RB_COM_SAVE}" defaultFormHandler="xxas_timecard_entry_pkg.update_timecard_entry">
  <EditFields>

    <Container id="BASIC_GRP">

     <Hidden id="PERSON_ID"/>
     <Hidden id="ASSIGNMENT_ID"/>
     <Hidden id="LOG_ENTRY_ID"/>
     <Hidden id="SOURCE_BLOCK"/>
     <Hidden id="SAVED_SEARCH_ID"/>
     <Hidden id="CURRENT_STATE_CODE"/>
	 <Hidden id="CURRENT_INS_UPD_DEL"/>
     <Hidden id="COSTABLE_TYPE"/>
     <Hidden id="CALLED_VIEW"/>
     <Hidden id="DATE_START"/>
     <Hidden id="DATE_START_TYPE"/>
	 <Html id="STATUS"  visible="true"   enabled="false" 
      hideIf="model.BASIC_GRP.CURRENT_STATE_CODE.value != &apos;A&apos; || model.BASIC_GRP.CURRENT_INS_UPD_DEL.value != &apos;D&apos;"/>
     <ListItem id="APPROVERS" style="row" listFunction="xxas_timecard_entry_pkg.get_approvers" visible="false"/>
     <Combolist id="EMPLOYEES" label="{message.XXAS_TCM_EVENT_EMPLOYEES}" emptyValue="{message.XXAS_TCM_EVENT_EMPLOYEES_SRCH}" 
      listProvider="REST:calendar-event/search/asg-dr-only-and-savedsearch?q={searchText}&amp;dateStart=${fieldNR.DATE_START}&amp;savedSearchId=${fieldNR.SAVED_SEARCH_ID}"
      required="true" longlist="true" visible="true" enabled="true" multipleSelection="true" style="tags"
      triggerName="TCM_PAYMENT_TYPES_OL_TCM" triggerMethod="POST" hideIf="!model.BASIC_GRP.CALLED_VIEW.value || model.BASIC_GRP.CALLED_VIEW.value == &apos;EMP&apos;"/>
     <Combolist id="JOB_ID" label="{message.XXAS_TCM_EVENT_JOB}" required="true" visible="true" enabled="true"
      listProvider="REST:calendar-event/search/emp-worker-asgs?q={searchText}&amp;dateStart=${fieldNR.DATE_START}&amp;personId=${fieldNR.PERSON_ID}"
      triggerName="TCM_PAYMENT_TYPES_OL_TCM" triggerMethod="POST" hideIf="!model.BASIC_GRP.CALLED_VIEW.value || model.BASIC_GRP.CALLED_VIEW.value == &apos;TEAM&apos;"/>
     <Date id="DR_DATE_START" label="{message.XXAS_EMP_START_DATE}" visible="true" enabled="true" required="true"
      triggerName="TCM_DURATION_CALC_OL_TIMECARDS" triggerMethod="POST" hideIf="!model.BASIC_GRP.DATE_START_TYPE.value || model.BASIC_GRP.DATE_START_TYPE.value == &apos;DATE_RANGE&apos;"/>
     <DateRange id="DATE_RANGE" label="{message.XXAS_TCM_EVENT_DR}" startDateLabel="{message.XXAS_EMP_START_DATE}" endDateLabel="{message.XXAS_EMP_END_DATE}"
      visible="true" enabled="true" startDateRequired="true" endDateRequired="false" triggerName="TCM_DURATION_CALC_OL_TIMECARDS" triggerMethod="POST"
      hideIf="!model.BASIC_GRP.DATE_START_TYPE.value || model.BASIC_GRP.DATE_START_TYPE.value == &apos;DATE_START&apos;"/>
     <Html id="TODAY_LOGGED_SUMMARY" label="{message.XXAS_TCM_EVENT_TODAY_LOG_SUM}" visible="true" enabled="false" 
      hideIf="((model.BASIC_GRP.CALLED_VIEW.value == &apos;TEAM&apos; &amp;&amp;
      (!model.BASIC_GRP.EMPLOYEES.value || !model.BASIC_GRP.EMPLOYEES.value[0].id || !model.BASIC_GRP.DATE_START_TYPE.value 
      || (model.BASIC_GRP.DATE_START_TYPE.value == &apos;DATE_RANGE&apos; &amp;&amp; !model.BASIC_GRP.DATE_RANGE.value.startDate) 
      || (model.BASIC_GRP.DATE_START_TYPE.value == &apos;DATE_START&apos; &amp;&amp; !model.BASIC_GRP.DR_DATE_START.value)
      )) || (model.BASIC_GRP.CALLED_VIEW.value == &apos;EMP&apos; &amp;&amp; 
      (!model.BASIC_GRP.JOB_ID.value || !model.BASIC_GRP.DATE_START_TYPE.value 
      || (model.BASIC_GRP.DATE_START_TYPE.value == &apos;DATE_RANGE&apos; &amp;&amp; !model.BASIC_GRP.DATE_RANGE.value.startDate)
      || (model.BASIC_GRP.DATE_START_TYPE.value == &apos;DATE_START&apos; &amp;&amp; !model.BASIC_GRP.DR_DATE_START.value)
      )))"/>
     <Html id="TOTAL_LOGGED_SUMMARY" label="{message.XXAS_TCM_EVENT_TOTAL_LOG_SUM}" visible="true" enabled="false" 
      hideIf="((model.BASIC_GRP.CALLED_VIEW.value == &apos;TEAM&apos; &amp;&amp;
      (!model.BASIC_GRP.EMPLOYEES.value || !model.BASIC_GRP.EMPLOYEES.value[0].id || !model.BASIC_GRP.DATE_START_TYPE.value 
      || (model.BASIC_GRP.DATE_START_TYPE.value == &apos;DATE_RANGE&apos; &amp;&amp; !model.BASIC_GRP.DATE_RANGE.value.startDate) 
      || (model.BASIC_GRP.DATE_START_TYPE.value == &apos;DATE_START&apos; &amp;&amp; !model.BASIC_GRP.DR_DATE_START.value)
      )) || (model.BASIC_GRP.CALLED_VIEW.value == &apos;EMP&apos; &amp;&amp; 
      (!model.BASIC_GRP.JOB_ID.value || !model.BASIC_GRP.DATE_START_TYPE.value 
      || (model.BASIC_GRP.DATE_START_TYPE.value == &apos;DATE_RANGE&apos; &amp;&amp; !model.BASIC_GRP.DATE_RANGE.value.startDate)
      || (model.BASIC_GRP.DATE_START_TYPE.value == &apos;DATE_START&apos; &amp;&amp; !model.BASIC_GRP.DR_DATE_START.value)
      )))"/>
     <Combolist id="PAYMENT_TYPE_ID" label="{message.XXAS_TCM_EVENT_PAYMENT_TYPE}" longlist="false" visible="true" enabled="true" required="true" 
      listProvider="REST:timecard-entry/form/payment-types?asgId=${field.ASSIGNMENT_ID}&amp;effDate=${field.DATE_START}"
      triggerName="TCM_DYNAMIC_FIELDS_GEN" triggerMethod="POST"/>

     <Hidden id="TIME_START"/>
     <Hidden id="TIME_STOP"/>
     <Hidden id="TIME_RANGE"/>
     <Hidden id="DURATION"/>

     <Hidden id="FIELD1"/>
     <Hidden id="FIELD2"/>
     <Hidden id="FIELD3"/>
     <Hidden id="FIELD4"/>
     <Hidden id="FIELD5"/>

     <Poplist id="REPEAT_ENTRY" label="{message.XXAS_TCM_EVENT_REPEAT}" listProvider="LOOKUP_TYPE:YES_NO" enabled="true"
      value="N" showAsBoolean="true" positiveBooleanValue="Y" visible="true"
      triggerName="TCM_SUMMARY_MSG_OL_TIMECARDS" triggerMethod="POST" hideIf="!model.BASIC_GRP.PAYMENT_TYPE_ID.value"/>
     <Poplist id="REPEATS" label="{message.XXAS_TCM_EVENT_REPEATS}" listProvider="VALUE_SET_NAME:XXAS_TCM_Repeat_Options" enabled="true" 
      hideIf="!model.BASIC_GRP.PAYMENT_TYPE_ID.value || model.BASIC_GRP.REPEAT_ENTRY.value == &apos;N&apos;" visible="true" 
      required="true" triggerName="TCM_SUMMARY_MSG_OL_TIMECARDS" triggerMethod="POST"/>
     <Number id="REPEAT_DAILY" label="{message.XXAS_TCM_EVENT_REPEAT_EVERY}" visible="true" enabled="true" required="true" 
      description="{message.XXAS_TCM_EVENT_REPEAT_DAYS}" hideIf="!model.BASIC_GRP.PAYMENT_TYPE_ID.value || model.BASIC_GRP.REPEAT_ENTRY.value == &apos;N&apos; || 
      !model.BASIC_GRP.REPEATS.value || model.BASIC_GRP.REPEATS.value.id != &apos;D&apos;"
      triggerName="TCM_SUMMARY_MSG_OL_TIMECARDS" triggerMethod="POST"/>
     <Number id="REPEAT_WEEKLY" label="{message.XXAS_TCM_EVENT_REPEAT_EVERY}" visible="true" enabled="true" required="true" 
      description="{message.XXAS_TCM_EVENT_REPEAT_WEEKS}" hideIf="!model.BASIC_GRP.PAYMENT_TYPE_ID.value || model.BASIC_GRP.REPEAT_ENTRY.value == &apos;N&apos; || 
      !model.BASIC_GRP.REPEATS.value || model.BASIC_GRP.REPEATS.value.id != &apos;W&apos;"
      triggerName="TCM_SUMMARY_MSG_OL_TIMECARDS" triggerMethod="POST"/>
     <Number id="REPEAT_MONTHLY" label="{message.XXAS_TCM_EVENT_REPEAT_EVERY}" visible="true" enabled="true" required="true" 
      description="{message.XXAS_TCM_EVENT_REPEAT_MONTHS}" hideIf="!model.BASIC_GRP.PAYMENT_TYPE_ID.value || model.BASIC_GRP.REPEAT_ENTRY.value == &apos;N&apos; 
      || !model.BASIC_GRP.REPEATS.value || model.BASIC_GRP.REPEATS.value.id != &apos;M&apos;"
      triggerName="TCM_SUMMARY_MSG_OL_TIMECARDS" triggerMethod="POST"/>

     <Poplist id="ENDS" label="{message.XXAS_TCM_EVENT_ENDS}" listProvider="VALUE_SET_NAME:XXAS_TCM_Repeat_Ends" enabled="true" required="true"
      hideIf="!model.BASIC_GRP.PAYMENT_TYPE_ID.value || model.BASIC_GRP.REPEAT_ENTRY.value == &apos;N&apos; || !model.BASIC_GRP.REPEATS.value" visible="true"
      triggerName="TCM_SUMMARY_MSG_OL_TIMECARDS" triggerMethod="POST"/>

     <Number id="OCCURENCES" label="{message.XXAS_TCM_EVENT_OCCURENCES}" visible="true" enabled="true" required="true" 
      hideIf="!model.BASIC_GRP.PAYMENT_TYPE_ID.value || model.BASIC_GRP.REPEAT_ENTRY.value == &apos;N&apos; || !model.BASIC_GRP.REPEATS.value || !model.BASIC_GRP.ENDS.value || 
      model.BASIC_GRP.ENDS.value.id != &apos;A&apos;" description="{message.XXAS_TCM_EVENT_ENTRY_REP_OCCUR}"
      triggerName="TCM_SUMMARY_MSG_OL_TIMECARDS" triggerMethod="POST"/>

     <Date id="TILL_END_DATE" label="{message.XXAS_TCM_EVENT_END_DATE}" visible="true" enabled="true" required="true" 
      hideIf="!model.BASIC_GRP.PAYMENT_TYPE_ID.value || model.BASIC_GRP.REPEAT_ENTRY.value == &apos;N&apos; || !model.BASIC_GRP.REPEATS.value || !model.BASIC_GRP.ENDS.value || 
      model.BASIC_GRP.ENDS.value.id != &apos;O&apos;" description="{message.XXAS_TCM_EVENT_ENTRY_REP_DATE}"
      triggerName="TCM_SUMMARY_MSG_OL_TIMECARDS" triggerMethod="POST"/>

     <TextInput id="SUMMARY_MSG" label="{message.XXAS_TCM_EVENT_SUMMARY}" visible="true" enabled="false" 
      hideIf="!model.BASIC_GRP.PAYMENT_TYPE_ID.value || model.BASIC_GRP.REPEAT_ENTRY.value == &apos;N&apos; || !model.BASIC_GRP.REPEATS.value || !model.BASIC_GRP.ENDS.value"/>

      <Hidden id="COST_ALL_FF_CODE"/>
      <Hidden id="COST_ALL_FF_ST_CODE"/>
      <Flexfield applicationShortCode="PAY" flexCode="COST" flexStructureCode="${field.COST_ALL_FF_ST_CODE}"/>
      <Hidden id="OVERRIDE_APPROVER"/>
      <TextArea id="COMMENTS_TO_APPROVER" label="{message.XXAS_RB_TCM_APPR_CMNTS}" enabled="true" required="false" 
       visible="true" maxChars="4000" hideIf="!model.BASIC_GRP.PAYMENT_TYPE_ID.value"/>

    </Container>

    <Container id="OVERLAP_ENTRIES" label="{message.XXAS_TCM_EVENT_OL_ENTRIES}" hideIf="!model.BASIC_GRP.PAYMENT_TYPE_ID.value">
     <ListItem id="OL_ENTRIES_LI"  visible="true"
      listFunction="xxas_timecard_entry_pkg.ol_timecard_entries"/>
    </Container>

  </EditFields>

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