Advertisement
psi_mmobile

Untitled

Feb 26th, 2020
655
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PL/SQL 3.25 KB | None | 0 0
  1.   PROCEDURE handleBadge(p_person_id IN NUMBER, p_vehicle_data_id IN NUMBER,
  2.                         p_vehicle_id IN NUMBER, p_fixed_unit_id IN NUMBER,  
  3.                         p_gps_full_date IN DATE, p_total_distance IN NUMBER) IS  
  4.     last_person_activity_id NUMBER(10);
  5.     last_start_vehicle_data_id NUMBER(10);
  6.     last_start_date DATE;
  7.     last_stop_vehicle_data_id NUMBER(10);
  8.     last_stop_date DATE;
  9.     last_vehicle_id NUMBER(10);
  10.     last_fixed_unit_id NUMBER(10);
  11.   BEGIN
  12.     --select last_activity
  13.     BEGIN
  14.       p_db_trc.trc(2, 'log','handlebadge '||p_person_id||' '||TO_CHAR(p_gps_full_date, 'DD/MM/YYYY HH24:MI'));
  15.  
  16.       SELECT person_activity_id, start_vehicle_data_id, start_date, stop_vehicle_data_id, stop_date, vehicle_id, fixed_unit_id
  17.       INTO last_person_activity_id, last_start_vehicle_data_id, last_start_date, last_stop_vehicle_data_id, last_stop_date, last_vehicle_id, last_fixed_unit_id
  18.       FROM person_activity, person
  19.       WHERE person.last_person_activity_id = person_activity.person_activity_id
  20.       AND person.person_id=p_person_id;
  21.      
  22.       p_db_trc.trc(2, 'log',' last = '||TO_CHAR(last_start_date, 'DD/MM/YYYY HH24:MI')||' '||TO_CHAR(last_stop_date, 'DD/MM/YYYY HH24:MI'));
  23.  
  24.       IF (TO_CHAR(p_gps_full_date, 'DD/MM/YYYY') = TO_CHAR(last_start_date, 'DD/MM/YYYY')) THEN
  25.  
  26.         p_db_trc.trc(2, 'log',' same day');
  27.         --same day then ...
  28.         -- check is last activity is not closed
  29.         IF last_stop_vehicle_data_id IS NULL THEN
  30.           p_db_trc.trc(2, 'log',' stop current activity');
  31.           -- stop last_activity
  32.           closeActivity(last_person_activity_id, p_vehicle_data_id, p_gps_full_date, p_total_distance);
  33.           IF ((NVL(p_vehicle_id, 0) != NVL(last_vehicle_id, 0)) OR (NVL(p_fixed_unit_id, 0) != NVL(last_fixed_unit_id, 0))) THEN
  34.           p_db_trc.trc(2, 'log',' not same unit then create new activity');
  35.             createNewActivity(p_person_id, p_vehicle_data_id, p_gps_full_date, NULL, NULL, p_vehicle_id, p_fixed_unit_id, NULL, p_total_distance, NULL);
  36.           END IF;
  37.         ELSE
  38.           p_db_trc.trc(2, 'log',' last activity is closed then create new one');
  39.           -- lastactivitty is already closed than restart a new one
  40.           IF last_vehicle_id IS NOT NULL THEN
  41.             --create work activity between last_stop_vehicle_data_id and p_person_data_id
  42.             createNewActivity(p_person_id, last_stop_vehicle_data_id, last_stop_date, p_vehicle_data_id, p_gps_full_date, NULL, NULL, 1, NULL, NULL);
  43.           END IF;
  44.           createNewActivity(p_person_id, p_vehicle_data_id, p_gps_full_date, NULL, NULL, p_vehicle_id, p_fixed_unit_id, NULL, p_total_distance, NULL);
  45.         END IF;
  46.       ELSE
  47.         p_db_trc.trc(2, 'log',' not same day as last then create new');
  48.         --not same day then new activity start
  49.         createNewActivity(p_person_id, p_vehicle_data_id, p_gps_full_date, NULL, NULL, p_vehicle_id, p_fixed_unit_id, NULL, p_total_distance, NULL);
  50.  
  51.       END IF;
  52.      
  53.     EXCEPTION WHEN NO_DATA_FOUND THEN
  54.       p_db_trc.trc(2, 'log',' last activity not found');
  55.       createNewActivity(p_person_id, p_vehicle_data_id, p_gps_full_date, NULL, NULL, p_vehicle_id, p_fixed_unit_id, NULL, p_total_distance, NULL);
  56.     END;
  57.     NULL;
  58.   END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement