|
@@ -4,35 +4,74 @@
|
|
|
{
|
|
|
private $db;
|
|
|
|
|
|
- private $userId;
|
|
|
+ private $currentYear;
|
|
|
+ private $currentMonth;
|
|
|
+ private $currentMonthText;
|
|
|
private $startDate;
|
|
|
- private $month;
|
|
|
+ private $startDateTimeString;
|
|
|
+ private $endDate;
|
|
|
+ private $endDateTimeString;
|
|
|
+
|
|
|
private $nextMonth;
|
|
|
- private $previousMonth;
|
|
|
+ private $nextMonthText;
|
|
|
private $nextYear;
|
|
|
+
|
|
|
+ private $previousMonth;
|
|
|
+ private $previousMonthText;
|
|
|
private $previousYear;
|
|
|
- private $year;
|
|
|
- private $endDate;
|
|
|
+
|
|
|
private $entries;
|
|
|
|
|
|
/**
|
|
|
- * @return mixed
|
|
|
+ * @return string
|
|
|
*/
|
|
|
- public function getUserId()
|
|
|
+ public function getCurrentYear()
|
|
|
{
|
|
|
- return $this->userId;
|
|
|
+ return $this->currentYear;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param mixed $userId
|
|
|
+ * @param string $currentYear
|
|
|
*/
|
|
|
- public function setUserId($userId)
|
|
|
+ public function setCurrentYear($currentYear)
|
|
|
{
|
|
|
- $this->userId = $userId;
|
|
|
+ $this->currentYear = $currentYear;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @return mixed
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function getCurrentMonth()
|
|
|
+ {
|
|
|
+ return $this->currentMonth;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param string $currentMonth
|
|
|
+ */
|
|
|
+ public function setCurrentMonth($currentMonth)
|
|
|
+ {
|
|
|
+ $this->currentMonth = $currentMonth;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return string
|
|
|
+ */
|
|
|
+ public function getCurrentMonthText()
|
|
|
+ {
|
|
|
+ return $this->currentMonthText;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param string $currentMonthText
|
|
|
+ */
|
|
|
+ public function setCurrentMonthText($currentMonthText)
|
|
|
+ {
|
|
|
+ $this->currentMonthText = $currentMonthText;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return string
|
|
|
*/
|
|
|
public function getStartDate()
|
|
|
{
|
|
@@ -40,7 +79,7 @@
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param mixed $startDate
|
|
|
+ * @param string $startDate
|
|
|
*/
|
|
|
public function setStartDate($startDate)
|
|
|
{
|
|
@@ -48,23 +87,23 @@
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @return mixed
|
|
|
+ * @return DateTime
|
|
|
*/
|
|
|
- public function getMonth()
|
|
|
+ public function getEndDate()
|
|
|
{
|
|
|
- return $this->month;
|
|
|
+ return $this->endDate;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param mixed $month
|
|
|
+ * @param DateTime $endDate
|
|
|
*/
|
|
|
- public function setMonth($month)
|
|
|
+ public function setEndDate($endDate)
|
|
|
{
|
|
|
- $this->month = $month;
|
|
|
+ $this->endDate = $endDate;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @return mixed
|
|
|
+ * @return string
|
|
|
*/
|
|
|
public function getNextMonth()
|
|
|
{
|
|
@@ -72,7 +111,7 @@
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param mixed $nextMonth
|
|
|
+ * @param string $nextMonth
|
|
|
*/
|
|
|
public function setNextMonth($nextMonth)
|
|
|
{
|
|
@@ -80,23 +119,23 @@
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @return mixed
|
|
|
+ * @return string
|
|
|
*/
|
|
|
- public function getPreviousMonth()
|
|
|
+ public function getNextMonthText()
|
|
|
{
|
|
|
- return $this->previousMonth;
|
|
|
+ return $this->nextMonthText;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param mixed $previousMonth
|
|
|
+ * @param string $nextMonthText
|
|
|
*/
|
|
|
- public function setPreviousMonth($previousMonth)
|
|
|
+ public function setNextMonthText($nextMonthText)
|
|
|
{
|
|
|
- $this->previousMonth = $previousMonth;
|
|
|
+ $this->nextMonthText = $nextMonthText;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @return mixed
|
|
|
+ * @return string
|
|
|
*/
|
|
|
public function getNextYear()
|
|
|
{
|
|
@@ -104,7 +143,7 @@
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param mixed $nextYear
|
|
|
+ * @param string $nextYear
|
|
|
*/
|
|
|
public function setNextYear($nextYear)
|
|
|
{
|
|
@@ -112,51 +151,51 @@
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @return mixed
|
|
|
+ * @return string
|
|
|
*/
|
|
|
- public function getPreviousYear()
|
|
|
+ public function getPreviousMonth()
|
|
|
{
|
|
|
- return $this->previousYear;
|
|
|
+ return $this->previousMonth;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param mixed $previousYear
|
|
|
+ * @param string $previousMonth
|
|
|
*/
|
|
|
- public function setPreviousYear($previousYear)
|
|
|
+ public function setPreviousMonth($previousMonth)
|
|
|
{
|
|
|
- $this->previousYear = $previousYear;
|
|
|
+ $this->previousMonth = $previousMonth;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @return mixed
|
|
|
+ * @return string
|
|
|
*/
|
|
|
- public function getYear()
|
|
|
+ public function getPreviousMonthText()
|
|
|
{
|
|
|
- return $this->year;
|
|
|
+ return $this->previousMonthText;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param mixed $year
|
|
|
+ * @param string $previousMonthText
|
|
|
*/
|
|
|
- public function setYear($year)
|
|
|
+ public function setPreviousMonthText($previousMonthText)
|
|
|
{
|
|
|
- $this->year = $year;
|
|
|
+ $this->previousMonthText = $previousMonthText;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @return mixed
|
|
|
+ * @return string
|
|
|
*/
|
|
|
- public function getEndDate()
|
|
|
+ public function getPreviousYear()
|
|
|
{
|
|
|
- return $this->endDate;
|
|
|
+ return $this->previousYear;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
- * @param mixed $endDate
|
|
|
+ * @param string $previousYear
|
|
|
*/
|
|
|
- public function setEndDate($endDate)
|
|
|
+ public function setPreviousYear($previousYear)
|
|
|
{
|
|
|
- $this->endDate = $endDate;
|
|
|
+ $this->previousYear = $previousYear;
|
|
|
}
|
|
|
|
|
|
/**
|
|
@@ -175,42 +214,189 @@
|
|
|
$this->entries = $entries;
|
|
|
}
|
|
|
|
|
|
- function __construct($month = null,$year = null)
|
|
|
+ /**
|
|
|
+ * @return int
|
|
|
+ */
|
|
|
+ public function getEndDateTimeString()
|
|
|
+ {
|
|
|
+ return $this->endDateTimeString;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param int $endDateTimeString
|
|
|
+ */
|
|
|
+ public function setEndDateTimeString($endDateTimeString)
|
|
|
+ {
|
|
|
+ $this->endDateTimeString = $endDateTimeString;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @return int
|
|
|
+ */
|
|
|
+ public function getStartDateTimeString()
|
|
|
+ {
|
|
|
+ return $this->startDateTimeString;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * @param int $startDateTimeString
|
|
|
+ */
|
|
|
+ public function setStartDateTimeString($startDateTimeString)
|
|
|
+ {
|
|
|
+ $this->startDateTimeString = $startDateTimeString;
|
|
|
+ }
|
|
|
+
|
|
|
+ function __construct($year, $month)
|
|
|
{
|
|
|
$this->db = Staple_DB::get();
|
|
|
|
|
|
+ //Current Dates
|
|
|
+ $currentDate = new DateTime();
|
|
|
+ $currentDate->setDate($year, $month, 1);
|
|
|
+
|
|
|
+ $this->currentYear = $currentDate->format('Y');
|
|
|
+ $this->currentMonth = $currentDate->format('m');
|
|
|
+ $this->currentMonthText = $currentDate->format('F');
|
|
|
+ $this->startDate = $currentDate->modify('-1 month +25 day')->format('Y-m-d');
|
|
|
+ $this->startDateTimeString = strtotime($this->startDate);
|
|
|
+ $currentDate->setDate($year, $month, 1);
|
|
|
+ $this->endDate = $currentDate->modify('+24 day')->format('Y-m-d');
|
|
|
+ $this->endDateTimeString = strtotime($this->endDate);
|
|
|
+
|
|
|
+ //Previous Dates
|
|
|
+ $previousDate = new DateTime();
|
|
|
+ $previousDate->setDate($year, $month, 1);
|
|
|
+ $previousDate->modify('-1 month');
|
|
|
+ $this->previousMonth = $previousDate->format('m');
|
|
|
+ $this->previousMonthText = $previousDate->format('F');
|
|
|
+ $previousDate->setDate($year, $month, 1);
|
|
|
+ $previousDate->modify('-1 year');
|
|
|
+ $this->previousYear = $previousDate->format('Y');
|
|
|
+
|
|
|
+ //Future Dates
|
|
|
+ $furtureDate = new DateTime();
|
|
|
+ $furtureDate->setDate($year, $month, 1);
|
|
|
+ $furtureDate->modify('+1 month');
|
|
|
+ $this->nextMonth = $furtureDate->format('m');
|
|
|
+ $this->nextMonthText = $furtureDate->format('F');
|
|
|
+ $furtureDate->setDate($year, $month, 1);
|
|
|
+ $furtureDate->modify('+1 year');
|
|
|
+ $this->nextYear = $furtureDate->format('Y');
|
|
|
+
|
|
|
+ //Time Entries
|
|
|
+ $this->entries = $this->entries($this->startDate, $this->endDate);
|
|
|
+
|
|
|
+ //Totals
|
|
|
+ $vacationTotal = $this->vacationEntries($this->startDate, $this->endDate);
|
|
|
+ }
|
|
|
+
|
|
|
+ function entries($startDate,$endDate)
|
|
|
+ {
|
|
|
//Get user ID from Auth
|
|
|
$user = new userModel();
|
|
|
- $this->userId = $user->getId();
|
|
|
+ $userId = $user->getId();
|
|
|
|
|
|
- if ($month == NULL) {
|
|
|
- $month = new DateTime();
|
|
|
- $month = $month->format('n');
|
|
|
- }
|
|
|
+ $sql = "SELECT id FROM timeEntries WHERE inTime BETWEEN $this->startDateTimeString AND $this->endDateTimeString AND userId = $userId ORDER BY inTime ASC";
|
|
|
+ if($this->db->query($sql)->num_rows > 0)
|
|
|
+ {
|
|
|
+ $query = $this->db->query($sql);
|
|
|
|
|
|
- if ($year == NULL) {
|
|
|
- $year = new DateTime();
|
|
|
- $year = $year->format('Y');
|
|
|
+ while($result = $query->fetch_assoc())
|
|
|
+ {
|
|
|
+ $entry = new timeEntryModel($result['id']);
|
|
|
+ $data[] = $entry;
|
|
|
+ }
|
|
|
+ return $data;
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ return array();
|
|
|
}
|
|
|
+ }
|
|
|
+
|
|
|
+ function vacationEntries($startDate,$endDate)
|
|
|
+ {
|
|
|
+ //Get user ID from Auth
|
|
|
+ $user = new userModel();
|
|
|
+ $userId = $user->getId();
|
|
|
+
|
|
|
+ //Get vacation timecode ID.
|
|
|
+ $code = new codeModel();
|
|
|
+ $codes = $code->getIdFor('vacation');
|
|
|
+ $timeCode = $codes['id'];
|
|
|
+
|
|
|
+ $sql = "SELECT * FROM timeEntries WHERE inTime BETWEEN $this->startDateTimeString AND $this->endDateTimeString AND userId = $userId AND codeId = $timeCode";
|
|
|
+
|
|
|
+ echo $sql;
|
|
|
|
|
|
- $dateObj = new DateTime();
|
|
|
- $dateObj->setDate($year, $month, 1);
|
|
|
- $end = $dateObj->modify('+24 day');
|
|
|
- $endTime = strtotime($end->format('Y-m-d'));
|
|
|
- $endDate = $end->format('Y-m-d');
|
|
|
- $this->setEndDate($endDate);
|
|
|
- $this->setMonth($end->format('F'));
|
|
|
- $this->setNextMonth($end->modify('+1 month')->format('m'));
|
|
|
- $this->setPreviousMonth($end->modify('-1 month')->format('m'));
|
|
|
-
|
|
|
- $this->setYear($end->format('Y'));
|
|
|
- $this->setNextYear($end->modify('+1 year')->format('Y'));
|
|
|
- $this->setPreviousYear($end->modify('-1 year')->format('Y'));
|
|
|
-
|
|
|
- $start = $dateObj->modify('-1 month +1 day');
|
|
|
- $startTime = strtotime($start->format('Y-m-d'));
|
|
|
- $startDate = $start->format('Y-m-d');
|
|
|
- $this->setStartDate($startDate);
|
|
|
+ if($this->db->query($sql)->fetch_row() > 0)
|
|
|
+ {
|
|
|
+ $query = $this->db->query($sql);
|
|
|
+ $result = $query->fetch_assoc();
|
|
|
+
|
|
|
+ //Set inTime
|
|
|
+ $inTime = new DateTime();
|
|
|
+ $inTime->setTimestamp($result['inTime']);
|
|
|
+
|
|
|
+ //$this->setInTime($inTime->format('h:i A'));
|
|
|
+ $vacationInTime = $inTime->format('h:i A');
|
|
|
+
|
|
|
+ //$this->setInTimeRaw($result['inTime']);
|
|
|
+ $vacationInTimeRaw = $result['inTime'];
|
|
|
+
|
|
|
+ //$this->setRoundedInTime($this->nearestQuarterHour($result['inTime']));
|
|
|
+
|
|
|
+ /*
|
|
|
+ //Out Time
|
|
|
+ $outTime = new DateTime();
|
|
|
+ $outTime->setTimestamp($result['outTime']);
|
|
|
+ $this->setOutTime($outTime->format('h:i A'));
|
|
|
+ $this->setOutTimeRaw($result['outTime']);
|
|
|
+ $this->setRoundedOutTime($this->nearestQuarterHour($result['outTime']));
|
|
|
+
|
|
|
+ $this->setLessTime($result['lessTime']);
|
|
|
+
|
|
|
+ //Calculate Time Worked
|
|
|
+ switch($result['lessTime'])
|
|
|
+ {
|
|
|
+ case 60:
|
|
|
+ $lessTime = 1;
|
|
|
+ break;
|
|
|
+ case 30:
|
|
|
+ $lessTime = 0.5;
|
|
|
+ break;
|
|
|
+ case 15:
|
|
|
+ $lessTime = 0.25;
|
|
|
+ break;
|
|
|
+ default:
|
|
|
+ $lessTime = 0;
|
|
|
+ }
|
|
|
+
|
|
|
+ //Total Worked Time
|
|
|
+ $dateTime1 = new DateTime($this->roundedInTime);
|
|
|
+ $dateTime2 = new DateTime($this->roundedOutTime);
|
|
|
+ $interval = $dateTime1->diff($dateTime2);
|
|
|
+
|
|
|
+ $timeWorked = $this->timeToDecimal($interval->h.":".$interval->i)-$lessTime;
|
|
|
+
|
|
|
+ if($timeWorked !== 0)
|
|
|
+ {
|
|
|
+ $this->setTimeWorked($timeWorked);
|
|
|
+ }
|
|
|
+ else
|
|
|
+ {
|
|
|
+ $this->setTimeWorked(0);
|
|
|
+ }
|
|
|
+
|
|
|
+ //Get Code Information
|
|
|
+ $code = new codeModel();
|
|
|
+ $this->setCodeId($result['codeId']);
|
|
|
+ $code->load($result['codeId']);
|
|
|
+ $this->setCodeName($code->getName());
|
|
|
+
|
|
|
+ return true;
|
|
|
+ */
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
|