/*============================================================================*
 |                 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
                       := 'CostAllocation';
                       
BEGIN
      
  xxas_com_sr_pkg.set_rest_service
    (p_service_name       => l_SERVICE
    ,p_description        => 'CostAllocation'
    ,p_consumes           => 'application/xml'
    ,p_produces           => 'application/xml'
    ,p_path               => 'cost-allocation');
    
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'GetPedingCostAllocations'
    ,p_description        => 'Get Pending Cost Allocations'
    ,p_path               => 'pending/{personId}/{processName}'
    ,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 ('flexible' "type",
                                               '&lt;font color="#FF9900"&gt;Pending for approval&lt;/font&gt;' "line2",
                                               xxas_cost_allocation_pkg.get_pending_actions(transaction_id) "line1",
                                               assignment_id "ObjectId",
                                               '#/cost-allocation-view/'  || to_char(assignment_id) || '_' || to_char(transaction_id) "href",
                                               'modal' "target",
                                               'large' "modalWidth"
                                              )	 
                                       )
                              ) 
                       )  "data" 
         FROM ( select hat.transaction_id
                      ,hat.assignment_id
                from hr_api_transactions hat
                where hat.assignment_id = xxas_util_pkg.get_primary_emp_asg({pathParam.personId},sysdate)
                and   hat.status NOT IN ('D', 'N', 'W','ACTIVE', 'AC')
                and   hat.process_name = {pathParam.processName}) ca
      ]'
    );
    
    
    
END;
/
COMMIT;
EXIT;
