+
+
Total Hours in Office
+
${convertToHoursAndMinutes(userHours)}
+
+
+
Average Hours per Day
+
${convertToHoursAndMinutes(userAverage)}
+
+
+
+
Average Arrival Time
+
${arrival}
+
+
+
Average Departure Time
+
${departure}
+
+
+
In-Office Rate
+
${Math.floor(inOfficeRate)}%
+
+
+
+
+
+ `;
+ // On iOS/android prints the given html. On web prints the HTML from the current page.
+ const { uri } = await Print.printToFileAsync({ html });
+ console.log('File has been saved to:', uri);
+ await shareAsync(uri, { UTI: '.pdf', mimeType: 'application/pdf' });
+ };
+
+ const fetchUserAnalytics = async (timefrom: string, timeto: string) => {
+
+ // console.log(timeTo);
+ setIsLoading(true);
+ try {
+ const hours = await fetchUserTotalHours(timefrom, timeto);
+ console.log('hours', hours);
+ const average = await fetchUserAverageHours(timefrom, timeto);
+ // const ratio = await fetchWorkRatio(timefrom, timeto);
+ const peak = await fetchUserPeakHours(timefrom, timeto);
+ const arrivalDeparture = await fetchUserArrivalAndDeparture(timefrom, timeto);
+ const inOffice = await fetchUserInOfficeRate(timefrom, timeto);
+ // console.log('hours', hours);
+ // console.log('average', average);
+ // console.log('ratio', ratio);
+ // console.log('peak', peak);
+ // console.log('arrivalDeparture', arrivalDeparture[0]);
+ // console.log('inOffice', inOffice);
+ setUserHours(hours);
+ setUserAverage(average);
+ // setWorkRatio(ratio);
+ setPeakHours(peak);
+ setArrival(arrivalDeparture[0]);
+ setDeparture(arrivalDeparture[1]);
+ setInOfficeRate(inOffice);
+ setIsLoading(false);
+ } catch (error) {
+ setUserHours(-1);
+ setUserAverage(-1);
+ // setWorkRatio(ratio);
+ setPeakHours(-1);
+ setArrival(-1);
+ setDeparture(-1);
+ setInOfficeRate(-1);
+ setIsLoading(false);
+ console.log('Error fetching user analytics:', error);
+ }
+ };
+
+ useEffect(() => {
+ // resetTimeFrames();
+ fetchUserAnalytics("", "");
+ }, []);
+
+ const hideDatePicker1 = () => {
+ setDatePicker1Visibility(false);
+ };
+
+ const showDatePicker1 = () => {
+ setDatePicker1Visibility(true);
+ };
+
+ const hideDatePicker2 = () => {
+ setDatePicker2Visibility(false);
+ };
+
+ const showDatePicker2 = () => {
+ setDatePicker2Visibility(true);
+ };
+
+ const handleConfirm1 = async (date: Date) => {
+ const selectedDate: string = date.toISOString();
+ // console.log('selected', selectedDate);
+ setTimeFrom(selectedDate);
+ hideDatePicker1();
+ setGraphData(null);
+ setTotalGraph(false);
+ await fetchUserAnalytics(selectedDate, timeTo);
+ };
+
+ const handleConfirm2 = async (date: Date) => {
+ const selectedDate: string = date.toISOString();
+ // console.log('selected', selectedDate);
+ setTimeTo(selectedDate);
+ hideDatePicker2();
+ setGraphData(null);
+ setTotalGraph(false);
+ await fetchUserAnalytics(timeFrom, selectedDate);
+ };
+
+ const resetTimeFrames = () => {
+ setTimeFrom("");
+ setTimeTo("");
+ }
+
+ function extractDateFromDate(dateString: string): string {
+ const date = new Date(dateString);
+ return date.toDateString();
+ }
+
+ useEffect(() => {
+ const getAccentColour = async () => {
+ let accentcolour = await SecureStore.getItemAsync('accentColour');
+ setAccentColour(accentcolour);
+ };
+ setIsDarkMode(currentTheme === 'dark');
+ getAccentColour();
+ }, []);
+
+ return (
+