Created
April 19, 2012 12:45
-
-
Save AeroNotix/2420773 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def get_total_balance(self): | |
| """ | |
| Calculates the total balance for the user | |
| This is on the ORM's User model and is just called as | |
| >>>User_Object.get_total_balance() | |
| """ | |
| total, total_mins = 0, 0 | |
| tracking_days = TrackingEntry.objects.filter(user_id=self.id) | |
| for item in tracking_days: | |
| total += ( item.end_time.hour | |
| - item.start_time.hour) | |
| total_mins += ( item.end_time.minute | |
| - item.start_time.minute) | |
| return ( len(tracking_days) * self.shiftlength.hour) | |
| - (total + (total_mins / 60.0)) | |
| vs | |
| function overallBalance($userName) { | |
| $sql_shift = 'SELECT Time_to_sec( | |
| timeDiff(shiftLength, breakLength) | |
| ) | |
| FROM tbluser | |
| WHERE user_id="'. $userName . '"'; | |
| $shift_result = mysql_query($sql_shift, | |
| $GLOBALS['DB']) or die(mysql_error()); | |
| $row = mysql_fetch_row($shift_result); | |
| $shift_value = $row[0]; | |
| $query = 'SELECT | |
| Sec_to_time( | |
| sum(Time_to_sec( | |
| timeDiff( | |
| timeDiff(workEnd, workStart), Breaks | |
| ) | |
| ) | |
| ) - (count(date) * '. $shift_value . ') | |
| ) AS overBalance | |
| FROM tblcalendar | |
| WHERE user_id="' . $userName . '" // taken from session so doesn't need parameterization | |
| AND DayType in("Work Day","Work Part of Day")'; | |
| $result = mysql_query($query, $GLOBALS['DB']) or die(mysql_error()); | |
| $row = mysql_fetch_assoc($result); | |
| return $row['overBalance']; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment