diff --git a/api/main.bal b/api/main.bal index 1cbda88..8ab55be 100644 --- a/api/main.bal +++ b/api/main.bal @@ -4382,6 +4382,116 @@ lock { } } + isolated resource function get total_attendance_count_by_date(int? organization_id, int? parent_organization_id, string? from_date = null, string? to_date = null) returns TotalActivityParticipantAttendanceCountByDateData[]|error? { + + stream total_attendance_count_by_date_records; + + if(from_date != null && to_date != null) { + + if(organization_id !=null){ + + lock{ + total_attendance_count_by_date_records = db_client->query( + `SELECT + attendance_date, + COUNT(DISTINCT person_id) AS daily_total + FROM ( + SELECT + DATE(sign_in_time) AS attendance_date, + person_id + FROM + activity_participant_attendance + WHERE + person_id IN ( + SELECT id FROM person WHERE avinya_type_id = 37 AND organization_id = ${organization_id} + ) + AND activity_instance_id IN ( + SELECT DISTINCT id + FROM activity_instance + WHERE activity_id = 4 + ) + AND DATE(sign_in_time) BETWEEN ${from_date} AND ${to_date} + GROUP BY + DATE(sign_in_time), person_id + ) AS daily_counts + WHERE + DAYOFWEEK(attendance_date) BETWEEN 2 AND 6 + GROUP BY + attendance_date + ORDER BY + attendance_date DESC;` + ); + } + }else{ + + lock{ + + total_attendance_count_by_date_records = db_client->query( + `SELECT + attendance_date, + COUNT(DISTINCT person_id) AS daily_total + FROM ( + SELECT + DATE(sign_in_time) AS attendance_date, + person_id + FROM + activity_participant_attendance + WHERE + person_id IN ( + SELECT DISTINCT id + FROM person + WHERE avinya_type_id = 37 + AND organization_id IN ( + SELECT DISTINCT id + FROM organization + WHERE id IN ( + SELECT DISTINCT child_org_id + FROM parent_child_organization + WHERE parent_org_id IN ( + SELECT DISTINCT child_org_id + FROM parent_child_organization + WHERE parent_org_id = ${parent_organization_id} + ) + ) + AND avinya_type = 87 + ) + ) + AND activity_instance_id IN ( + SELECT DISTINCT id + FROM activity_instance + WHERE activity_id = 4 + ) + AND DATE(sign_in_time) BETWEEN ${from_date} AND ${to_date} + GROUP BY + DATE(sign_in_time), person_id + ) AS daily_counts + WHERE + DAYOFWEEK(attendance_date) BETWEEN 2 AND 6 + GROUP BY + attendance_date + ORDER BY + attendance_date DESC;` + ); + } + + } + + TotalActivityParticipantAttendanceCountByDateData[] attendanceCountByDateDatas = []; + + check from TotalActivityParticipantAttendanceCountByDate attendance_count_by_date_record in total_attendance_count_by_date_records + do { + TotalActivityParticipantAttendanceCountByDateData|error attendanceCountByDateData = new TotalActivityParticipantAttendanceCountByDateData(attendance_count_by_date_record); + if !(attendanceCountByDateData is error) { + attendanceCountByDateDatas.push(attendanceCountByDateData); + } + }; + check total_attendance_count_by_date_records.close(); + return attendanceCountByDateDatas; + + }else{ + return error("Provide non-null values for both 'From Date' and 'To Date'."); + } + } } diff --git a/api/total_activity_participant_attendance_count_by_date_data.bal b/api/total_activity_participant_attendance_count_by_date_data.bal new file mode 100644 index 0000000..d52c939 --- /dev/null +++ b/api/total_activity_participant_attendance_count_by_date_data.bal @@ -0,0 +1,27 @@ +public isolated service class TotalActivityParticipantAttendanceCountByDateData { + private TotalActivityParticipantAttendanceCountByDate total_activity_participant_attendance_count_by_date = { + attendance_date: "", + daily_total: -1 + }; + + isolated function init(TotalActivityParticipantAttendanceCountByDate? total_activity_participant_attendance_count_by_date = null) returns error? { + if(total_activity_participant_attendance_count_by_date != null) { // if activity_participant_attendance is provided, then use that and do not load from DB + self.total_activity_participant_attendance_count_by_date = total_activity_participant_attendance_count_by_date.cloneReadOnly(); + return; + } + + } + + isolated resource function get attendance_date() returns string? { + lock { + return self.total_activity_participant_attendance_count_by_date.attendance_date; + } + } + + isolated resource function get daily_total() returns int? { + lock { + return self.total_activity_participant_attendance_count_by_date.daily_total; + } + } + +} diff --git a/api/types.bal b/api/types.bal index 221b58e..26cd4ca 100644 --- a/api/types.bal +++ b/api/types.bal @@ -474,6 +474,29 @@ public type ActivityParticipantAttendanceForLateAttendance record {| string? digital_id; |}; +public type ActivityParticipantAttendanceMissedBySecurity record {| + readonly string? record_type = "activity_participant_attendance_missed_by_security"; + string? sign_in_time; + string? digital_id; + string? description; +|}; + +public type DailyActivityParticipantAttendanceByParentOrg record {| + readonly string? record_type = "daily_activity_participant_attendance_by_parent_org"; + string? description; + int? present_count; + string? svg_src; + string? color; + int? total_student_count; +|}; + +public type TotalActivityParticipantAttendanceCountByDate record {| + readonly string? record_type = "total_activity_participant_attendance_count_by_date"; + string? attendance_date; + int? daily_total; +|}; + + public type ActivityEvaluationCriteria record {| readonly string? record_type = "activity_evaluation_criteria"; int? activity_id; @@ -602,20 +625,3 @@ public type DutyRotationMetaDetails record{| string? end_date; int? organization_id; |}; - -public type ActivityParticipantAttendanceMissedBySecurity record {| - readonly string? record_type = "activity_participant_attendance_missed_by_security"; - string? sign_in_time; - string? digital_id; - string? description; -|}; - -public type DailyActivityParticipantAttendanceByParentOrg record {| - readonly string? record_type = "daily_activity_participant_attendance_by_parent_org"; - string? description; - int? present_count; - string? svg_src; - string? color; - int? total_student_count; -|}; -