CREATE OR REPLACE PACKAGE BODY locations_pkg AS
/******************************************************************************
 *
 * PROCEDURE get_location_groups
 *
 ******************************************************************************/
PROCEDURE get_location_groups
(
   p_site_id               IN location_group.site_id%TYPE,
   p_location_group        OUT location_group_type,
   p_location_description  OUT loc_group_description_type
)
IS
   CURSOR c_location_group IS
      SELECT
         name,
         description
      FROM
         location_group
      WHERE
         site_id = p_site_id
      ORDER BY name;

   -- loop counter
   l_row_counter     BINARY_INTEGER;

BEGIN

   -- Initialise the row counter
   l_row_counter := 0;

   -- loop through the location_groups
   FOR this_row IN c_location_group LOOP

      -- increment the row count
      l_row_counter := l_row_counter + 1;

      -- add the data to the return arrays
      p_location_group(l_row_counter) := TRIM(this_row.name);
      p_location_description(l_row_counter) := TRIM(this_row.description);

      -- ensure we do not return too much data to the MWS
      EXIT WHEN l_row_counter = MAX_ROWS;

   END LOOP; -- end of looping through cursor c_location_group

END get_location_groups;


/******************************************************************************
 *
 * PROCEDURE create_location_group
 *
 ******************************************************************************/

PROCEDURE create_location_group
(
   p_site_id               IN location_group.site_id%TYPE,
   p_name                  IN location_group.name%TYPE,
   p_description           IN location_group.description%TYPE,
   p_last_user             IN location_group.last_user%TYPE,
   p_out_row_id            OUT location_group.appn_row_id%TYPE
) IS
BEGIN
   INSERT INTO location_group(site_id, name, description, last_user)
      VALUES (p_site_id, p_name, p_description, p_last_user)
   RETURNING appn_row_id INTO p_out_row_id;
END create_location_group;


/******************************************************************************
 *
 * PROCEDURE edit_location_group
 *
 ******************************************************************************/

PROCEDURE edit_location_group
(
   p_appn_row_id           IN location_group.appn_row_id%TYPE,
   p_description           IN location_group.description%TYPE,
   p_last_user             IN location_group.last_user%TYPE
) IS
BEGIN
   UPDATE location_group
      SET description = p_description
         ,last_user = p_last_user
   WHERE appn_row_id = p_appn_row_id;
END edit_location_group;

END locations_pkg;
/