/* $Id: xxas_rest_mass_missed_punches_upd.sql 6216 2018-10-23 05:56:55Z ybudamala $ */
/*============================================================================*
 |                 Copyright (c) 2019 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
                       := 'MassMissedPunch';

BEGIN

  xxas_com_sr_pkg.set_rest_service
    (p_service_name       => l_SERVICE
    ,p_description        => 'MassMissedPunch'
    ,p_consumes           => 'application/xml'
    ,p_produces           => 'application/xml'
    ,p_path               => 'mass-missed-punch');

  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'MassMissedPunchesForm'
    ,p_description        => 'Get Mass Missed Punches Form'
    ,p_methods            => 'GET'
    ,p_remove_root_ele    => true
    ,p_path               => 'form'
    ,p_sql                =>
      q'[
          SELECT xxas_tcm_missed_punch_pkg.mass_punches_form
                   ({requestParam.personId}
                   ,{requestParam.sourceBlock}
                   ,{requestParam.savedSearchId}
                   ,{requestParam.excludeTermBy}
                   ,{requestParam.includeSelf}) "data"
          FROM   dual
      ]'
    );

  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'MissedPunchUpdate'
    ,p_description        => 'Missed punch update'
    ,p_methods            => 'PUT'
    ,p_path               => 'assignment/{assignmentId}/person/{personId}/clock/{pendingClockId}/save'
    ,p_remove_root_ele    => true
    ,p_plsql              =>
      q'[
         DECLARE

            l_resp         xxas_http_resp_obj;
		        l_request_xml  xmltype;
            l_response_xml  xmltype;
         BEGIN

           l_request_xml := {requestBody};

           xxas_tcm_missed_punch_pkg.auto_save_punch_details
             (p_person_id        => {pathParam.personId}
			       ,p_assignment_id    => {pathParam.assignmentId}
			       ,p_pending_clock_id => {pathParam.pendingClockId}
             ,p_form_data_xml    => l_request_xml
             ,p_response_xml     => l_response_xml);

           l_resp := xxas_http_response
                       .ok(l_response_xml)
                       .build();

           {response} := l_resp;

         END
		]'
    );

  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'MissedPunchSubmitFix'
    ,p_description        => 'Missed punch submit fix'
    ,p_methods            => 'POST'
    ,p_path               => 'submit-fix'
    ,p_remove_root_ele    => true
    ,p_plsql              =>
      q'[
         DECLARE

           l_resp         xxas_http_resp_obj;
		   l_request_xml  XMLType;
           l_response_xml XMLType;
         BEGIN

           l_request_xml := {requestBody};

           l_response_xml := xxas_tcm_missed_punch_pkg.submit_fixes
                               (p_form_data_xml    => l_request_xml);

           l_resp := xxas_http_response
                       .ok(l_response_xml
                          )
                       .build();

           {response} := l_resp;

         END
		]'
    );

  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'MissedPunchApprove'
    ,p_description        => 'Missed punch approve'
    ,p_methods            => 'POST'
    ,p_path               => 'approve-punch'
    ,p_remove_root_ele    => true
    ,p_plsql              =>
      q'[
         DECLARE

           l_resp         xxas_http_resp_obj;
		   l_request_xml  XMLType;
           l_response_xml XMLType;

         BEGIN

           l_request_xml := {requestBody};

           l_response_xml := xxas_tcm_missed_punch_pkg.approve_punches
                               (p_form_data_xml    => l_request_xml
                               ,p_person_id    => {pathParam.person_id});

           l_resp := xxas_http_response
                       .ok(l_response_xml
                          )
                       .build();

           {response} := l_resp;

         END
		]'
    );
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'MissedPunchReject'
    ,p_description        => 'Missed punch reject'
    ,p_methods            => 'POST'
    ,p_path               => 'return-punch'
    ,p_remove_root_ele    => true
    ,p_plsql              =>
      q'[
         DECLARE

           l_resp         xxas_http_resp_obj;
		   l_request_xml  XMLType;
           l_response_xml XMLType;

         BEGIN

           l_request_xml := {requestBody};

           l_response_xml := xxas_tcm_missed_punch_pkg.return_punches
                               (p_form_data_xml    => l_request_xml
                               ,p_person_id    => {pathParam.person_id});

           l_resp := xxas_http_response
                       .ok(l_response_xml
                          )
                       .build();

           {response} := l_resp;

         END
		]'
    );
  xxas_com_sr_pkg.set_rest_method
    (p_service_name       => l_SERVICE
    ,p_method_name        => 'MissedPunchDelete'
    ,p_description        => 'Missed punch delete punch'
    ,p_methods            => 'DELETE'
    ,p_path               => 'delete-punch'
    ,p_remove_root_ele    => true
    ,p_plsql              =>
      q'[
         DECLARE

           l_resp         xxas_http_resp_obj;
		       l_request_xml  XMLType;
           l_response_xml XMLType;

         BEGIN

           l_request_xml := {requestBody};

           l_response_xml := xxas_tcm_missed_punch_pkg.delete_punches
                               (p_form_data_xml    => l_request_xml
                               ,p_punchtype        => {requestParam.punchType});

           l_resp := xxas_http_response
                       .ok(l_response_xml
                          )
                       .build();

           {response} := l_resp;

         END
		]'
    );

END;
/
COMMIT;
EXIT;
