Skip to content

Commit

Permalink
Merge pull request #108 from lahirulakruwan/main
Browse files Browse the repository at this point in the history
Resolved the conflicts
  • Loading branch information
YujithIsura authored Jan 19, 2024
2 parents 5e88677 + d016c2d commit 05a33ec
Show file tree
Hide file tree
Showing 3 changed files with 160 additions and 17 deletions.
110 changes: 110 additions & 0 deletions api/main.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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<TotalActivityParticipantAttendanceCountByDate, error?> 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'.");
}
}

}

Expand Down
27 changes: 27 additions & 0 deletions api/total_activity_participant_attendance_count_by_date_data.bal
Original file line number Diff line number Diff line change
@@ -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;
}
}

}
40 changes: 23 additions & 17 deletions api/types.bal
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
|};

0 comments on commit 05a33ec

Please sign in to comment.