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

  EXCEPTION
    WHEN e_does_not_exists THEN
      NULL;
  END;

  
  result := DBMS_XDB.createresource('/public/xxas/emp/view/accrual-balance.xml',
'<View showSubmit="false" title="Accrual balance" defaultFormHandler="" clientAutosave="true">

  <EditFields>
  
    <Container id="CONTAINER">
      <Hidden id="ASSIGNMENT_ID"/>
      <Date id="EFFECTIVE_AT" label="{message.XXAS_ACC_BALANCES_AT}" enabled="true" required="true" visible="true" refreshOnChange="true"/>
      <Poplist id="ACCRUAL_PLAN_ID" label="{message.XXAS_ACCRUAL_PLAN}" required="true" listProvider="REST:jobs/${field.ASSIGNMENT_ID}/accrual-plans" hideIf="!field.values || field.values.length &lt; 2" refreshOnChange="true"/>
      <Html id="HTML_TEXT" visible="false"/>
      <Item id="ACCRUAL_CHART" style="detail" itemFunction="xxas_absence_management_pkg.leave_balance_chart"/>
    </Container>

  </EditFields>

</View>' ); 

  xxas_forms_pkg.update_forms_resource('/public/xxas/emp/view/accrual-balance.xml');

END;
/
COMMIT;
EXIT;
