/* $Id$ */
/*============================================================================*
 |                 Copyright (c) 2018 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/edit-weekly-timecard.xml');

  EXCEPTION
    WHEN e_does_not_exists THEN
      NULL;
  END;

  
  result := DBMS_XDB.createresource('/public/xxas/emp/view/edit-weekly-timecard.xml',
'<View title="{message.XXAS_TCM_WEEKLY_EDIT_TITLE}" showSubmit="false" submitLabel="{message.XXAS_TCM_WEEKLY_SAVE_AS_DRAFT}" defaultFormHandler="xxas_timecard_entry_pkg.edit_weekly_timecard_handler">
  <EditFields>

    <Container type="submit-group">
      <Submit id="SUBMIT_DRAFT" label="{message.XXAS_TCM_WEEKLY_SUBMIT_DRAFT}" weight="light" color="positive"/>
      <Submit id="SAVE_AS_DRAFT" label="{message.XXAS_TCM_WEEKLY_SAVE_AS_DRAFT}" weight="medium" color="positive"/>
    </Container>

    <Container id="BASIC_GRP">

     <Hidden id="PERSON_ID"/>
     <Hidden id="START_TIME"/>
     <Hidden id="END_TIME"/>
     <Hidden id="EXCLUDE_TERM_BY"/>
     <Hidden id="SOURCE_BLOCK"/>
     <Hidden id="SAVED_SEARCH_ID"/>
     <Hidden id="CALLED_VIEW"/>
     <Hidden id="ASSIGNMENT_ID"/>
     <Hidden id="DATE_START"/>
     <Hidden id="PREV_PERIOD_ID"/>
     <Hidden id="PREV_PAYMENT_TYPE_ID"/>
     <Hidden id="PROD"/>
     <Combolist id="PERIOD_ID" label="{message.XXAS_TCM_WEEKLY_PERIOD_ID}" longlist="false" visible="true" enabled="true" required="true" 
      listProvider="REST:timecard-entry/form/periods?effDate=${field.DATE_START}&amp;personId=${field.PERSON_ID}" triggerName="TCM_DYNAMIC_WEEKLY_FIELDS_DATA" 
      triggerMethod="POST" hideIf="!model.BASIC_GRP.PROD.value || model.BASIC_GRP.PROD.value == &apos;OTL&apos;"/>
     <Date id="PERIOD_DATE" label="{message.XXAS_OTL_WEEKLY_PERIOD_DATE}" visible="true" enabled="true" required="true" 
      triggerName="TCM_DYNAMIC_WEEKLY_FIELDS_DATA" triggerMethod="POST" hideIf="!model.BASIC_GRP.PROD.value || model.BASIC_GRP.PROD.value == &apos;TCM&apos;"/>
     <Hidden id="PAYMENT_TYPE_ID"/>
     <Hidden id="INPUT_FIELD"/>
     <MultiRow id="DR_TIME_ENTRIES" label="DR time entries" toBeInSingleRow="false" createAllowed="false" includeEmptyRow="false" xdbUri="/public/xxas/emp/view/dr_time_entries.xml" 
      hideIf="(!model.BASIC_GRP.PERIOD_ID.value &amp;&amp; model.BASIC_GRP.PROD.value == &apos;TCM&apos;) ||
              (!model.BASIC_GRP.PERIOD_DATE.value &amp;&amp; model.BASIC_GRP.PROD.value == &apos;OTL&apos;) || !model.BASIC_GRP.PAYMENT_TYPE_ID.value" visible="true"/>

    </Container>

  </EditFields>

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