ZulfadlyAshBurn Posted May 5, 2020 Share Posted May 5, 2020 I'm creating a shift system where it stores into database which shift is the user in. However sometimes their shift extends over the other shift. How can I implement it better I'm currently using the time to get which shift they are on. There are two shift. 1) morning: 0800 - 1930hrs 2) night: 1930 - 0800hrs Sometimes the shift will overrun. How do I maintain on which shift they were. $whatshift = (int) date("Hi"); if ($whatshift > "0800" && $whatshift < "1800") { $shift = 1; } else { $shift = 2; } Quote Link to comment https://forums.phpfreaks.com/topic/310708-shift-system/ Share on other sites More sharing options...
requinix Posted May 5, 2020 Share Posted May 5, 2020 1 hour ago, ZulfadlyAshBurn said: How do I maintain on which shift they were. How do you maintain which shift they were on? If you had to decide, how would you do it? Quote Link to comment https://forums.phpfreaks.com/topic/310708-shift-system/#findComment-1577589 Share on other sites More sharing options...
ZulfadlyAshBurn Posted May 6, 2020 Author Share Posted May 6, 2020 Currently the code is run and the shift value is added into the database with other data. However sometimes the night shift overruns the morning shift time and thus the shift value will change to 1 instead. I was think of setting a cookie when the user logged in and store the session for 12hours. However I cannot confirm the time of their login this the 12hours cookie will overrun into the next shift. Quote Link to comment https://forums.phpfreaks.com/topic/310708-shift-system/#findComment-1577592 Share on other sites More sharing options...
kicken Posted May 6, 2020 Share Posted May 6, 2020 Can you not just check which user logged in and what day it is then check the schedule for their shift? If you just try and check a persons shift when the log in and they may login many times than that won't really work by itself. You need to either have a defined schedule or some sort of clock in/clock out feature to that they use at the start and end of their shift. Quote Link to comment https://forums.phpfreaks.com/topic/310708-shift-system/#findComment-1577593 Share on other sites More sharing options...
requinix Posted May 6, 2020 Share Posted May 6, 2020 I wasn't asking what the code does. I meant you. The human being. So how would you decide what shift was correct? Perhaps it's like kicken suggested and you only think about when they clocked in? Quote Link to comment https://forums.phpfreaks.com/topic/310708-shift-system/#findComment-1577595 Share on other sites More sharing options...
ZulfadlyAshBurn Posted May 8, 2020 Author Share Posted May 8, 2020 If I worked morning shift, its shift 1. If I worked night shift, it's shift 2. There is no fixed schedule thus when they key in their entry, it checks if the time is after 1800hrs. But sometimes their shift extends to the next morning which is shift 1 but I want the shift to remain as shift 2. Quote Link to comment https://forums.phpfreaks.com/topic/310708-shift-system/#findComment-1577715 Share on other sites More sharing options...
kicken Posted May 8, 2020 Share Posted May 8, 2020 You won't be able to get determine their shift at any given moment by checking the current time. There's not enough information to do that. If it's a system the login to and stay logged into through out the day then you could determine it at login and store it in a session variable. So long as they stay logged in that'd be fine. Even that however could fail if they end up logging out but then have to login again after their shift technically ended for some last minute stuff before going home. So the only ideal solutions are to either Let your users select the shift when making their entries. Perhaps have a supervisor review the entries for accuracy Have a defined schedule you can use to look up their shift. This is less of a technical problem and more of a business process problem. First, determine how their shift is determined in the business process. Many places just use a clock-in/clock-out process where at the start of their shift the employee completes a clock-in process and at the end they complete a clock-out process. Quote Link to comment https://forums.phpfreaks.com/topic/310708-shift-system/#findComment-1577732 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.