/* $Id$ */
/*============================================================================*
 |                 Copyright (c) 2014 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

  --
  -- Local constants and variables
  --
  l_SERVICE CONSTANT xxas_com_service_repository.service_name%TYPE
                       := 'Payslips';
                       
BEGIN
      
  xxas_com_sr_pkg.set_rest_service
    (p_service_name       => l_SERVICE
    ,p_description        => 'View payslips'
    ,p_path               => 'assignments/{assignmentId}/'
    ,p_consumes           => 'application/xml'
    ,p_produces           => 'application/xml'
    );
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'ViewPayslips'
    ,p_description        => 'Gets all payslips for an assignment'
    ,p_path               => 'payslips'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true
    ,p_sql                =>
      q'[
          SELECT XMLElement
                   ("data"
                   ,XMLAttributes
                     ('true' as "json:force-array"
                     ,'http://json.org/' as "xmlns:json")
                   ,XMLAgg
                     (XMLElement
                       ("item"
                       ,XMLForest
                         ('pdf' "documentType"
                         ,p.summary_text "title"
                         ,xxas_payslip_pkg.payslip_url
                           ({requestParam.viewName}
                           ,{pathParam.assignmentId}
                           ,p.payslip_id
                           ,p.template
                           ,'Y'
                           ,p.rest_api_path) "url"
                         )
                        ,XMLElement
                         ("meta" 
                         ,XMLElement
                           ("options"
                           ,XMLElement
                           ("height"
                           ,'30em')
                           )
                         )
                       )
                     )
                   ) "data"
          FROM  TABLE(xxas_payslip_pkg.get_payslips_tbl
                       ({requestParam.viewName}
                       ,{pathParam.assignmentId})) p
      ]'
    );
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'ViewPayslip'
    ,p_description        => 'Get an applicant for a vacancy'
    ,p_path               => 'payslips/{payslipId}/{templateName}/{viewName}'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true
    ,p_bipub_dd_app       => 'XXAS'
    ,p_bipub_dd_code      => 'XXASEMPPAY'
    ,p_sql                =>
      q'[
          SELECT XMLElement
                   ("Output"
                    ,XMLElement
                     ("ROWSET"
                      ,XMLElement
                        ("ROW"
                         ,XMLElement
                           ("PAYSLIP_DETAILS"
                            ,(xxas_payslip_pkg.get_payslip_details_xml
                                ({pathParam.assignmentId}
                                ,{pathParam.payslipId}
                                ,{pathParam.templateName}
                                ,{pathParam.viewName})
                             )
                           )
                         )
                       )
                     )  "data"                       
           FROM dual
      ]'
    );
  
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'OraclePayslipUS'
    ,p_description        => 'View Oracle seeded payslip for US'
    ,p_path               => 'oracle-payslips/US/{payslipId}'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true
    ,p_bipub_dd_app       => 'PAY'
    ,p_bipub_dd_code      => 'PAYUSPAYSLIP'
    ,p_sql                =>
      q'[
          SELECT xxas_payslip_pkg.get_oracle_details_xml
                  ({pathParam.assignmentId}
                  ,{pathParam.payslipId}
                  ,'US' ) "data"
           FROM dual 
           WHERE xxas_com_sec_pkg.test_instance('XXAS_DT_PAYSLIP', {pathParam.assignmentId}) = 'Y' 
      ]'
    );
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'OraclePayslipAE'
    ,p_description        => 'View Oracle seeded payslip for AE'
    ,p_path               => 'oracle-payslips/AE/{payslipId}'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true
    ,p_bipub_dd_app       => 'PAY'
    ,p_bipub_dd_code      => 'PAYAEPAYSLIP'
    ,p_sql                =>
      q'[
          SELECT xxas_payslip_pkg.get_oracle_details_xml
                  ({pathParam.assignmentId}
                  ,{pathParam.payslipId}
                  ,'AE' ) "data"
           FROM dual 
           WHERE xxas_com_sec_pkg.test_instance('XXAS_DT_PAYSLIP', {pathParam.assignmentId}) = 'Y' 
      ]'
    );   

  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'OraclePayslipMX'
    ,p_description        => 'View Oracle seeded payslip for MX'
    ,p_path               => 'oracle-payslips/MX/{payslipId}'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true
    ,p_bipub_dd_app       => 'PAY'
    ,p_bipub_dd_code      => 'PAYMXPAYSLIP'
    ,p_sql                =>
      q'[
          SELECT xxas_payslip_pkg.get_oracle_details_xml
                  ({pathParam.assignmentId}
                  ,{pathParam.payslipId}
                  ,'MX' ) "data"
           FROM dual 
           WHERE xxas_com_sec_pkg.test_instance('XXAS_DT_PAYSLIP', {pathParam.assignmentId}) = 'Y' 
      ]'
    );      
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'OraclePayslipDK'
    ,p_description        => 'View Oracle seeded payslip for DK'
    ,p_path               => 'oracle-payslips/DK/{payslipId}'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true
    ,p_bipub_dd_app       => 'PAY'
    ,p_bipub_dd_code      => 'PAYDKPAYSLIP'
    ,p_sql                =>
      q'[
          SELECT xxas_payslip_pkg.get_oracle_details_xml
                  ({pathParam.assignmentId}
                  ,{pathParam.payslipId}
                  ,'DK' ) "data"
           FROM dual 
           WHERE xxas_com_sec_pkg.test_instance('XXAS_DT_PAYSLIP', {pathParam.assignmentId}) = 'Y' 
      ]'
    );    

  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'OraclePayslipFI'
    ,p_description        => 'View Oracle seeded payslip for FI'
    ,p_path               => 'oracle-payslips/FI/{payslipId}'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true
    ,p_bipub_dd_app       => 'PAY'
    ,p_bipub_dd_code      => 'PAYFIPAYSLIP'
    ,p_sql                =>
      q'[
          SELECT xxas_payslip_pkg.get_oracle_details_xml
                  ({pathParam.assignmentId}
                  ,{pathParam.payslipId}
                  ,'FI' ) "data"
           FROM dual 
           WHERE xxas_com_sec_pkg.test_instance('XXAS_DT_PAYSLIP', {pathParam.assignmentId}) = 'Y' 
      ]'
    ); 

  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'OraclePayslipNO'
    ,p_description        => 'View Oracle seeded payslip for NO'
    ,p_path               => 'oracle-payslips/NO/{payslipId}'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true
    ,p_bipub_dd_app       => 'PAY'
    ,p_bipub_dd_code      => 'PAYNOPAYSLIP'
    ,p_sql                =>
      q'[
          SELECT xxas_payslip_pkg.get_oracle_details_xml
                  ({pathParam.assignmentId}
                  ,{pathParam.payslipId}
                  ,'NO' ) "data"
           FROM dual 
           WHERE xxas_com_sec_pkg.test_instance('XXAS_DT_PAYSLIP', {pathParam.assignmentId}) = 'Y' 
      ]'
    );      
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'OraclePayslipSE'
    ,p_description        => 'View Oracle seeded payslip for SE'
    ,p_path               => 'oracle-payslips/SE/{payslipId}'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true
    ,p_bipub_dd_app       => 'PAY'
    ,p_bipub_dd_code      => 'PAYSEPAYSLIP'
    ,p_sql                =>
      q'[
          SELECT xxas_payslip_pkg.get_oracle_details_xml
                  ({pathParam.assignmentId}
                  ,{pathParam.payslipId}
                  ,'SE' ) "data"
           FROM dual 
           WHERE xxas_com_sec_pkg.test_instance('XXAS_DT_PAYSLIP', {pathParam.assignmentId}) = 'Y' 
      ]'
    );    

  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'OraclePayslipCA'
    ,p_description        => 'View Oracle seeded payslip for CA'
    ,p_path               => 'oracle-payslips/CA/{payslipId}'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true
    ,p_bipub_dd_app       => 'PAY'
    ,p_bipub_dd_code      => 'PAYCAPAYSLIP'
    ,p_sql                =>
      q'[
          SELECT xxas_payslip_pkg.get_oracle_details_xml
                  ({pathParam.assignmentId}
                  ,{pathParam.payslipId}
                  ,'CA' ) "data"
           FROM dual 
           WHERE xxas_com_sec_pkg.test_instance('XXAS_DT_PAYSLIP', {pathParam.assignmentId}) = 'Y' 
      ]'
    );  

  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'OraclePayslipIP'
    ,p_description        => 'View Oracle seeded payslip for IP'
    ,p_path               => 'oracle-payslips/IP/{payslipId}'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true
    ,p_bipub_dd_app       => 'PAY'
    ,p_bipub_dd_code      => 'PAYIPPAYSLIP'
    ,p_sql                =>
      q'[
          SELECT xxas_payslip_pkg.get_oracle_details_xml
                  ({pathParam.assignmentId}
                  ,{pathParam.payslipId}
                  ,'IP' ) "data"
           FROM dual 
           WHERE xxas_com_sec_pkg.test_instance('XXAS_DT_PAYSLIP', {pathParam.assignmentId}) = 'Y' 
      ]'
    );      
    
END;
/
COMMIT;
EXIT;
