Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- PROCEDURE handleBadge(p_person_id IN NUMBER, p_vehicle_data_id IN NUMBER,
- p_vehicle_id IN NUMBER, p_fixed_unit_id IN NUMBER,
- p_gps_full_date IN DATE, p_total_distance IN NUMBER) IS
- last_person_activity_id NUMBER(10);
- last_start_vehicle_data_id NUMBER(10);
- last_start_date DATE;
- last_stop_vehicle_data_id NUMBER(10);
- last_stop_date DATE;
- last_vehicle_id NUMBER(10);
- last_fixed_unit_id NUMBER(10);
- BEGIN
- --select last_activity
- BEGIN
- p_db_trc.trc(2, 'log','handlebadge '||p_person_id||' '||TO_CHAR(p_gps_full_date, 'DD/MM/YYYY HH24:MI'));
- SELECT person_activity_id, start_vehicle_data_id, start_date, stop_vehicle_data_id, stop_date, vehicle_id, fixed_unit_id
- 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
- FROM person_activity, person
- WHERE person.last_person_activity_id = person_activity.person_activity_id
- AND person.person_id=p_person_id;
- 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'));
- IF (TO_CHAR(p_gps_full_date, 'DD/MM/YYYY') = TO_CHAR(last_start_date, 'DD/MM/YYYY')) THEN
- p_db_trc.trc(2, 'log',' same day');
- --same day then ...
- -- check is last activity is not closed
- IF last_stop_vehicle_data_id IS NULL THEN
- p_db_trc.trc(2, 'log',' stop current activity');
- -- stop last_activity
- closeActivity(last_person_activity_id, p_vehicle_data_id, p_gps_full_date, p_total_distance);
- 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
- p_db_trc.trc(2, 'log',' not same unit then create new activity');
- 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);
- END IF;
- ELSE
- p_db_trc.trc(2, 'log',' last activity is closed then create new one');
- -- lastactivitty is already closed than restart a new one
- IF last_vehicle_id IS NOT NULL THEN
- --create work activity between last_stop_vehicle_data_id and p_person_data_id
- 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);
- END IF;
- 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);
- END IF;
- ELSE
- p_db_trc.trc(2, 'log',' not same day as last then create new');
- --not same day then new activity start
- 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);
- END IF;
- EXCEPTION WHEN NO_DATA_FOUND THEN
- p_db_trc.trc(2, 'log',' last activity not found');
- 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);
- END;
- NULL;
- END;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement