 
   SET NEW.personID = personID();
   SELECT projectID INTO pID FROM timeSheet WHERE timeSheet.timeSheetID = NEW.timeSheetID;
-  SELECT rate,rateUnitID INTO rate,rateUnitID FROM projectPerson WHERE projectID = pID AND personID = personID();
+  SELECT rate,rateUnitID INTO r,rUnitID FROM projectPerson WHERE projectID = pID AND personID = personID();
 
   -- if rate is neq project-person rate AND they're don't have perm halt with error about rate
-  IF (neq(NEW.rate,rate) AND NOT can_edit_rate(personID(),pID)) THEN
+  IF (neq(NEW.rate,r) AND NOT can_edit_rate(personID(),pID)) THEN
     call alloc_error("Time sheet's rate is not editable.");
   END IF;
 
-  IF (NEW.rate IS NULL AND rate) THEN
-    SET NEW.rate = rate;
-    SET NEW.timeSheetItemDurationUnitID = rateUnitID;
+  IF (NEW.rate IS NULL AND r) THEN
+    SET NEW.rate = r;
+    SET NEW.timeSheetItemDurationUnitID = rUnitID;
   END IF;
 
   IF (NEW.taskID) THEN

BEGIN
  DECLARE validDate DATE;
  DECLARE pID INTEGER;
  DECLARE rate BIGINT(20);
  DECLARE rateUnitID INTEGER;
  call check_edit_timeSheet(OLD.timeSheetID);

  SET NEW.timeSheetItemModifiedUser = personID();

DROP FUNCTION IF EXISTS has_perm $$
CREATE FUNCTION has_perm(pID INTEGER, action INTEGER, tableN VARCHAR(255)) RETURNS BOOLEAN READS SQL DATA
BEGIN
  DECLARE p varchar(255);
  DECLARE rtn BOOLEAN;
  SELECT perms INTO p FROM person WHERE personID = pID;

  SELECT count(*) INTO rtn
    FROM permission
   WHERE tableName = tableN
     AND (actions & action = action)
     AND (roleName IS NULL OR roleName = '' OR find_in_set(roleName,p)>0);
  return rtn;
END
$$
