فهرست منبع

Merge pull request #28 from advation/printing

Printing
Adam 9 سال پیش
والد
کامیت
9299c487ce

+ 0 - 3
application/controllers/indexController.php

@@ -28,9 +28,6 @@ class indexController extends Staple_Controller
 		$report = new weeklyReportModel();
 
 		$this->view->week = $report->getWeekWorked($this->userId, $week, $year);
-
-		$unlock = new unlockModel();
-		$this->view->unlockedTimes = count($unlock->load($this->userId));
 	}
 }
 ?>

+ 193 - 0
application/controllers/reportsController.php

@@ -7,6 +7,7 @@ class reportsController extends Staple_Controller
 
     public function _start()
     {
+        $this->_setLayout('main');
         $auth = Staple_Auth::get();
         $this->authLevel = $auth->getAuthLevel();
         $user = new userModel();
@@ -42,6 +43,29 @@ class reportsController extends Staple_Controller
         $date = new DateTime();
         $date->setDate($year, $month, 1);
         $this->view->month = $date->format('F');
+
+        $printTimeSheetForm = new printTimeSheetForm();
+        if($printTimeSheetForm->wasSubmitted())
+        {
+            $printTimeSheetForm->addData($_POST);
+            if($printTimeSheetForm->validate())
+            {
+                $data = $printTimeSheetForm->exportFormData();
+
+                $this->layout->addScriptBlock("
+                    window.open('".$this->_link(array("reports","printpreview",$year,$month,$data['account']))."');
+                    ");
+                $this->view->printTimeSheetForm = $printTimeSheetForm;
+            }
+            else
+            {
+                $this->view->printTimeSheetForm = $printTimeSheetForm;
+            }
+        }
+        else
+        {
+            $this->view->printTimeSheetForm = $printTimeSheetForm;
+        }
     }
 
     public function changeyear()
@@ -133,4 +157,173 @@ class reportsController extends Staple_Controller
             }
         }
     }
+
+    public function printpreview($year,$month,$uid)
+    {
+        $this->_setLayout('print');
+
+        $user = new userModel();
+        $account = $user->userInfo($uid);
+
+        $this->view->firstName = $account['firstName'];
+        $this->view->lastName = $account['lastName'];
+        $this->view->batchId = $account['batchId'];
+        $this->view->year = $year;
+        $this->view->month = date('F',$month);
+
+
+        $timesheet = new timesheetModel($year, $month,$uid);
+        $this->view->timesheet = $timesheet;
+
+    }
+
+    public function payperiod($year = null, $month = null)
+    {
+        if ($year == null) {
+            $year = date('Y');
+        }
+
+        if ($month == null) {
+            $month = date('m');
+        }
+        $this->view->year = $year;
+
+        $date = new DateTime();
+        $date->setDate($year,$month,26);
+        $date->setTime(0,0,0);
+        $this->view->month = $date->format('m');
+        $date->modify('-1 month');
+        $this->view->previousMonth = $date->format('m');
+
+        $date2 = new DateTime();
+        $date2->setDate($year,$month,25);
+        $date2->setTime(24,0,0);
+
+        $interval = date_diff($date,$date2);
+
+        $this->view->span = $interval->days;
+
+        $reports = new reportModel($year, $month);
+        $this->view->report = $reports->payPeriodTotals($year, $month);
+    }
+
+    public function payperiodprint($year, $month)
+    {
+        if($year != null || $month != null)
+        {
+            $this->_setLayout('print');
+            $this->view->year = $year;
+
+            $date = new DateTime();
+            $date->setDate($year,$month,26);
+            $date->setTime(0,0,0);
+            $this->view->month = $date->format('m');
+            $date->modify('-1 month');
+            $this->view->previousMonth = $date->format('m');
+
+            $date2 = new DateTime();
+            $date2->setDate($year,$month,25);
+            $date2->setTime(24,0,0);
+
+            $interval = date_diff($date,$date2);
+
+            $this->view->span = $interval->days;
+
+            $reports = new reportModel($year, $month);
+            $this->view->report = $reports->payPeriodTotals($year, $month);
+            $this->view->startDate = $date->format("F jS Y");
+            $days = $interval->days - 1;
+            $date->modify("+$days days");
+            $this->view->endDate = $date->format("F jS Y");
+        }
+        else
+        {
+            header("location:".$this->_link(array('reports','payperiod'))."");
+        }
+    }
+
+    public function payroll($year = null, $month =  null)
+    {
+        if($year == null)
+        {
+            $year = date('Y');
+        }
+
+        if($month == null)
+        {
+            $month = date('m');
+        }
+
+        $this->view->year = $year;
+
+        $date = new DateTime();
+        $date->setDate($year,$month,26);
+        $date->setTime(0,0,0);
+        $this->view->month = $date->format('m');
+        $date->modify('-1 month');
+        $this->view->previousMonth = $date->format('m');
+
+        $date2 = new DateTime();
+        $date2->setDate($year,$month,25);
+        $date2->setTime(24,0,0);
+
+        $interval = date_diff($date,$date2);
+
+        $this->view->span = $interval->days;
+
+        $reports = new reportModel($year, $month);
+        $this->view->report = $reports->payroll($year, $month);
+        $this->view->startDate = $date->format("F jS Y");
+        $days = $interval->days - 1;
+        $date->modify("+$days days");
+        $this->view->endDate = $date->format("F jS Y");
+
+        $codes = new codeModel();
+        $this->view->codes = $codes->allCodes();
+    }
+
+    public function payrollprint($year = null, $month =  null)
+    {
+        if($year != null || $month != null) {
+            $this->_setLayout('print');
+            if ($year == null) {
+                $year = date('Y');
+            }
+
+            if ($month == null) {
+                $month = date('m');
+            }
+
+            $this->view->year = $year;
+
+            $date = new DateTime();
+            $date->setDate($year, $month, 26);
+            $date->setTime(0, 0, 0);
+            $this->view->month = $date->format('m');
+            $date->modify('-1 month');
+            $this->view->previousMonth = $date->format('m');
+
+            $date2 = new DateTime();
+            $date2->setDate($year, $month, 25);
+            $date2->setTime(24, 0, 0);
+
+            $interval = date_diff($date, $date2);
+
+            $this->view->span = $interval->days;
+
+            $reports = new reportModel($year, $month);
+            $this->view->report = $reports->payroll($year, $month);
+            $this->view->startDate = $date->format("F jS Y");
+            $days = $interval->days - 1;
+            $date->modify("+$days days");
+            $this->view->endDate = $date->format("F jS Y");
+
+            $codes = new codeModel();
+            $this->view->codes = $codes->allCodes();
+        }
+        else
+        {
+            header("location:".$this->_link(array('reports','payroll'))."");
+        }
+    }
 }

+ 46 - 0
application/controllers/timesheetController.php

@@ -6,6 +6,7 @@ class timesheetController extends Staple_Controller
 
     public function _start()
     {
+        $this->_setLayout('main');
         $auth = Staple_Auth::get();
         $user = new userModel();
         $user->userInfo($auth->getAuthId());
@@ -140,6 +141,51 @@ class timesheetController extends Staple_Controller
         $this->view->changeYearForm = $changeYearForm;
     }
 
+    public function printpreview($id = null, $year = null, $month = null)
+    {
+        $this->_setLayout('print');
+
+        //Set year and month variables if undefined.
+        if($year == null)
+        {
+            $date = new DateTime();
+            $year = $date->format('Y');
+        }
+
+        if($month == null)
+        {
+            $date = new DateTime();
+            if($date->format("j") >= 26)
+            {
+                $month = $date->modify('+1 month')->format('m');
+            }
+            else
+            {
+                $month = $date->format('m');
+            }
+        }
+
+        //Load timesheet for user.
+        $timesheet = new timesheetModel($year,$month);
+
+        $user = new userModel();
+        $user->userInfo($this->userId);
+
+        $this->view->firstName = $user->getFirstName();
+        $this->view->lastName = $user->getLastName();
+        $this->view->batchId = $user->getBatchId();
+
+        //Pass timesheet object to view
+        if($id == $this->userId)
+        {
+            $this->view->timesheet = $timesheet;
+        }
+        else
+        {
+            header("location: ".$this->_link(array('timesheet'))."");
+        }
+    }
+
     public function remove($id = null)
     {
         if($id != null)

+ 70 - 0
application/forms/printTimeSheetForm.php

@@ -0,0 +1,70 @@
+<?php
+
+class printTimeSheetForm extends Staple_Form
+{
+    public function _start()
+    {
+        //$this->setLayout('');
+
+        $this->setName('printTimeSheet')
+            ->setAction($this->link(array('reports')));
+
+        $account = new Staple_Form_FoundationSelectElement('account','Select an account');
+        $account->setRequired()
+            ->addOption('','Select an account')
+            ->addOptionsArray($this->accounts())
+            ->addValidator(new Staple_Form_Validate_InArray($this->accounts(1)));
+
+        $submit = new Staple_Form_FoundationSubmitElement('submit','Submit');
+        $submit->addClass('button expand radius');
+
+        $this->addField($account,$submit);
+    }
+
+    function accounts($ids = null)
+    {
+        $user = new userModel();
+        $id = $user->getId();
+        $authLevel = $user->getAuthLevel();
+
+        $accounts = new userModel();
+        $users = $accounts->listAll();
+        $data = array();
+        if($ids == null)
+        {
+            foreach($users as $user)
+            {
+
+                if($user['type'] == 'part')
+                {
+                    $type = 'Part Time';
+                }
+
+                if($user['type'] == 'full')
+                {
+                    $type = 'Full Time';
+                }
+
+                if($user['supervisorId'] == $id)
+                {
+                    $data[$user['id']] = $user['lastName'].", ".$user['firstName']." ($type)";
+                }
+                elseif($authLevel >= 900)
+                {
+                    $data[$user['id']] = $user['lastName'].", ".$user['firstName']." ($type)";
+                }
+            }
+        }
+        else
+        {
+            foreach($users as $user)
+            {
+                $data[] = $user['id'];
+            }
+        }
+
+        return $data;
+    }
+}
+
+?>

+ 9 - 2
application/layouts/main.phtml

@@ -28,8 +28,8 @@
                 </h4>
             </div>
         </div>
-        <div class="contain-to-grid hide-for-print">
-        <nav class="top-bar" data-topbar role="navigation">
+        <div class="contain-to-grid">
+        <nav class="top-bar hide-for-print" data-topbar role="navigation">
             <ul class="title-area">
                 <li class="name">
 
@@ -73,6 +73,13 @@
                                     <li><a href=\"".$this->link(array('reports','unlock'))."\"><i class=\"fa fa-unlock\"></i> Time Unlock</a></li>
                                 </ul>
                             </li>
+                            <li class=\"has-dropdown\">
+                                <a href=\"#\"><i class='fa fa-file'></i> Reports</a>
+                                <ul class=\"dropdown\">
+                                    <li><a href=\"".$this->link(array('reports','payroll'))."\"><i class=\"fa fa-usd\"></i> Payroll Report</a></li>
+                                    <li><a href=\"".$this->link(array('reports','payperiod'))."\"><i class=\"fa fa-clock-o\"></i> Pay Period Report</a></li>
+                                </ul>
+                            </li>
                             ";
                         }
                     ?>

+ 75 - 0
application/layouts/print.phtml

@@ -0,0 +1,75 @@
+<?php echo $this->doctype; ?>
+<!--[if IE 9]><html class="lt-ie10" lang="en" > <![endif]-->
+<html class="no-js" lang="en">
+<head>
+    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
+    <meta charset="utf-8">
+
+    <title><?php echo $this->title; ?></title>
+    <?php
+    $this->scripts();
+    $this->styles();
+    ?>
+    <style>
+        @page
+        {
+            size: auto;   /* auto is the initial value */
+
+            /* this affects the margin in the printer settings */
+            margin: 10mm 10mm 10mm 10mm;
+        }
+
+        body
+        {
+            /* this affects the margin on the content before sending to printer */
+            margin: 0px;
+        }
+
+        td
+        {
+            padding:2px !important;
+            font-size:8pt !important;
+        }
+
+        th
+        {
+            padding:2px !important;
+            font-size:8pt !important;
+        }
+
+        p
+        {
+            font-size:8pt !important;
+        }
+
+    </style>
+</head>
+<body onload="window.print()">
+<nav class="top-bar hide-for-print" data-topbar role="navigation">
+    <ul class="title-area">
+        <li class="name">
+            <h1><a href="#">Print Preview</a></h1>
+        </li>
+    </ul>
+
+    <section class="top-bar-section">
+        <!-- Right Nav Section -->
+        <ul class="right">
+            <li><a href="#" id="print"><i class="fa fa-print"></i> Print</a></li>
+            <li><a href="#" id="close"><i class="fa fa-close"></i> Close</a></li>
+        </ul>
+    </section>
+</nav>
+<?php $this->content();?>
+
+<script>
+    $("#print").click(function() {
+        window.print();
+    });
+
+    $("#close").click(function() {
+        window.close();
+    });
+</script>
+</body>
+</html>

+ 0 - 1
application/models/codeModel.php

@@ -96,7 +96,6 @@
 
 		function allCodes()
 		{
-
 			$auth = Staple_Auth::get();
 			$uid = $auth->getAuthId();
 			$user = new userModel();

+ 105 - 0
application/models/reportModel.php

@@ -216,4 +216,109 @@ class reportModel extends Staple_Model
     {
 
     }
+
+    function payPeriodTotals($year, $month)
+    {
+        //Get all users
+        $users = new userModel();
+        $accounts = $users->listAll();
+
+        $data = array();
+
+        $date = new DateTime();
+        $date->setTime(0,0,0);
+        $date->setDate($year,$month,26);
+        $date->modify('-1 month');
+        $startDate = $date->format('U');
+        $date->modify('+1 month -1 day');
+        $date->setTime(23,59,59);
+        $endDate = $date->format('U');
+
+        foreach($accounts as $account)
+        {
+            $userId = $account['id'];
+            $userName = $account['lastName'].", ".$account['firstName'];
+            $sql = "
+                SELECT * FROM timeEntries WHERE inTime >= '".$this->db->real_escape_string($startDate)."' AND inTime <= '".$this->db->real_escape_string($endDate)."' AND userId = '".$this->db->real_escape_string($userId)."' ORDER BY inTime ASC;
+            ";
+
+            $query = $this->db->query($sql);
+            $data2 = array();
+
+            $setDate = 0;
+            $timeWorked = 0;
+            while($result = $query->fetch_assoc())
+            {
+                $day = new DateTime();
+                $day->setTimestamp($result['inTime']);
+                $date = $day->format('Y-m-d');
+                $entry = $this->calculateEntry($result['id']);
+
+                if($date == $setDate)
+                {
+                    $timeWorked = $timeWorked + $entry['timeWorked'];
+                }
+                else
+                {
+                    $timeWorked = $entry['timeWorked'];
+                }
+
+                $data2[$date] = $timeWorked;
+                $setDate = $date;
+            }
+            $data[$userName] = $data2;
+        }
+        return $data;
+    }
+
+    function payroll($year, $month)
+    {
+        $users = new userModel();
+        $accounts = $users->listAll();
+
+        $data = array();
+
+        $date = new DateTime();
+        $date->setTime(0,0,0);
+        $date->setDate($year,$month,26);
+        $date->modify('-1 month');
+        $startDate = $date->format('U');
+        $date->modify('+1 month -1 day');
+        $date->setTime(23,59,59);
+        $endDate = $date->format('U');
+
+        foreach($accounts as $account)
+        {
+            $userId = $account['id'];
+            $userName = $account['lastName'] . ", " . $account['firstName'];
+            $sql = "
+                SELECT * FROM timeEntries WHERE inTime >= '" . $this->db->real_escape_string($startDate) . "' AND inTime <= '" . $this->db->real_escape_string($endDate) . "' AND userId = '" . $this->db->real_escape_string($userId) . "' ORDER BY inTime ASC;
+            ";
+
+            $query = $this->db->query($sql);
+            $data2 = array();
+
+            $setCode = 0;
+            $timeWorked = 0;
+            while($result = $query->fetch_assoc())
+            {
+                $entry = $this->calculateEntry($result['id']);
+                $code = $entry['code'];
+
+                if($code == $setCode)
+                {
+                    $timeWorked = $timeWorked + $entry['timeWorked'];
+                }
+                else
+                {
+                    $timeWorked = $entry['timeWorked'];
+                }
+
+                $data2[$code] = $timeWorked;
+                $setCode = $code;
+            }
+            $data[$userName] = $data2;
+        }
+        return $data;
+    }
 }

+ 10 - 2
application/models/timeEntryModel.php

@@ -533,18 +533,26 @@
             }
 		}
 
-        function nearestQuarterHour($time)
+        function nearestQuarterHour($time,$string = null)
         {
             //$time = strtotime($time);
             $round = 15*60;
             $rounded = round($time/$round)*$round;
 
-            return date("g:i A", $rounded);
+            if($string == 1)
+            {
+                return $rounded;
+            }
+            else
+            {
+                return date("g:i A", $rounded);
+            }
         }
 
         function timeToDecimal($time)
         {
             $timeArr = explode(':', $time);
+
             $hours = $timeArr[0]*1;
             $minutes = $timeArr[1]/60;
             $dec = $hours + $minutes;

+ 112 - 14
application/models/timesheetModel.php

@@ -20,6 +20,8 @@
 		private $previousMonthText;
 		private $previousYear;
 
+		private $userId;
+
 		private $batch;
 
 		private $entries;
@@ -282,11 +284,29 @@
 			$this->totals = $totals;
 		}
 
-		function __construct($year, $month, $user = null)
+		/**
+		 * @return mixed
+		 */
+		public function getUserId()
+		{
+			return $this->userId;
+		}
+
+		/**
+		 * @param mixed $userId
+		 */
+		public function setUserId($userId)
+		{
+			$this->userId = $userId;
+		}
+
+
+
+		function __construct($year, $month, $uid = null)
 		{
 			$this->db = Staple_DB::get();
 
-			if($user == null)
+			if($uid == null)
 			{
 				//Get batchID
 				$user = new userModel();
@@ -294,7 +314,7 @@
 			}
 			else
 			{
-				$user = new userModel($user);
+				$user = new userModel($uid);
 			}
 
 			//Current Dates
@@ -331,7 +351,7 @@
 			$this->nextYear = $furtureDate->format('Y');
 
 			//Time Entries
-			$this->entries = $this->timeEntries($this->startDate, $this->endDate);
+			$this->entries = $this->timeEntries($uid);
 
 			$timeCode = new codeModel();
 
@@ -340,11 +360,12 @@
 			foreach ($timeCode->allCodes() as $code)
 			{
 				$codeId = $timeCode->getIdFor($code);
-				$totals[$code] = $this->calculatedTotals($codeId['id'],$this->startDate,$this->endDate);
+				$totals[$code] = $this->calculatedTotals($codeId['id'],$this->startDate,$this->endDate,$uid);
 			}
 			$totals['Total Time'] = array_sum($totals);
 
 			$this->setTotals($totals);
+			$this->userId = $user->getId();
 		}
 
 		function validate($batchId)
@@ -357,11 +378,19 @@
 			}
 		}
 
-		function timeEntries($startDate,$endDate)
+		function timeEntries($uid = null)
 		{
-			//Get user ID from Auth
 			$user = new userModel();
-			$userId = $user->getId();
+			if($uid != null)
+			{
+				$account = $user->userInfo($uid);
+				$userId = $account['id'];
+			}
+			else
+			{
+				//Get user ID from Auth
+				$userId = $user->getId();
+			}
 
 			$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)
@@ -403,19 +432,88 @@
 		}
 		*/
 
-		function calculatedTotals($code,$startDate,$endDate)
+		function calculatedTotals($code,$startDate,$endDate,$uid=null)
 		{
 			//Get user ID from Auth
 			$user = new userModel();
-			$userId = $user->getId();
+			if($uid == null)
+			{
+				$userId = $user->getId();
+			}
+			else
+			{
+				$account = $user->userInfo($uid);
+				$userId = $account['id'];
+			}
 
-			$sql = "SELECT ROUND((TIME_TO_SEC(SEC_TO_TIME(SUM(outTime - inTime)-SUM(lessTime*60)))/3600)*4)/4 AS 'totalTime' FROM timeEntries WHERE inTime > UNIX_TIMESTAMP('$startDate 00:00:00') AND outTime < UNIX_TIMESTAMP('$endDate 00:00:00') AND userId = $userId AND codeId = $code;";
+			//$sql = "SELECT ROUND((TIME_TO_SEC(SEC_TO_TIME(SUM(outTime - inTime)-SUM(lessTime*60)))/3600)*4)/4 AS 'totalTime' FROM timeEntries WHERE inTime > UNIX_TIMESTAMP('$startDate 00:00:00') AND outTime < UNIX_TIMESTAMP('$endDate 23:59:59') AND userId = $userId AND codeId = $code;";
+			$sql = "SELECT inTime, outTime, lessTime FROM timeEntries WHERE inTime > UNIX_TIMESTAMP('$startDate 00:00:00') AND outTime < UNIX_TIMESTAMP('$endDate 23:59:59') AND userId = $userId AND codeId = $code;";
 
-			if($this->db->query($sql)->num_rows > 0)
+			if($this->db->query($sql)->fetch_row() > 0)
 			{
 				$query = $this->db->query($sql);
-				$result = $query->fetch_assoc();
-				return round($result['totalTime'],2);
+
+				$total = 0;
+				while($result = $query->fetch_assoc())
+				{
+
+					$inTime = $result['inTime'];
+					$outTime = $result['outTime'];
+
+					switch($result['lessTime'])
+					{
+						case 60:
+							$lessTime = 1;
+							break;
+						case 30:
+							$lessTime = 0.5;
+							break;
+						case 15:
+							$lessTime = 0.25;
+							break;
+						default:
+							$lessTime = 0;
+					}
+
+					$roundedInTime = $this->nearestQuarterHour($inTime);
+					$roundedOutTime = $this->nearestQuarterHour($outTime);
+
+					$lapse = $roundedOutTime - $roundedInTime;
+					$lapseHours = gmdate ('H:i', $lapse);
+
+					$decimalHours = $this->timeToDecimal($lapseHours);
+					$total = $total + $decimalHours;
+					$total = $total - $lessTime;
+				}
+
+				return $total;
+			}
+			else
+			{
+				return 0;
+			}
+		}
+
+		function nearestQuarterHour($time)
+		{
+			//$time = strtotime($time);
+			$round = 15*60;
+			$rounded = round($time/$round)*$round;
+
+			return $rounded;
+		}
+
+		function timeToDecimal($time)
+		{
+			$timeArr = explode(':', $time);
+
+			$hours = $timeArr[0]*1;
+			$minutes = $timeArr[1]/60;
+			$dec = $hours + $minutes;
+
+			if($dec > 0)
+			{
+				return round($dec,2);
 			}
 			else
 			{

+ 7 - 0
application/views/reports/index.phtml

@@ -11,6 +11,7 @@
         <div class="small-4 columns">
             <ul class="button-group radius left">
                 <li><a class="button small" href="<?php echo $this->link(array('reports','weekly')) ?>"><i class="fa fa-file"></i> Week Report</a></li>
+                <li><a class="button small" data-reveal-id="print"  href="#"><i class="fa fa-print"></i> Print</a></li>
             </ul>
         </div>
         <div class="small-8 columns">
@@ -176,6 +177,12 @@
     <a class="close-reveal-modal" aria-label="Close">&#215;</a>
 </div>
 
+<div id="print" class="reveal-modal small" data-reveal aria-labelledby="Print Report" aria-hidden="true" role="dialog">
+    <h2>Print Individual Time Sheet</h2>
+    <?php echo $this->printTimeSheetForm ?>
+    <a class="close-reveal-modal" aria-label="Close">&#215;</a>
+</div>
+
 <script>
     $(function() {
 

+ 99 - 0
application/views/reports/payperiod.phtml

@@ -0,0 +1,99 @@
+<div class="section">
+    <div class="row">
+        <div class="small-6 columns">
+            <h2><i class="fa fa-file"></i> Pay Period Report</h2>
+        </div>
+        <div class="small-6 columns text-right">
+            <a class="button radius" target="_blank" href="<?php echo $this->link(array('reports','payperiodprint',$this->year,$this->month)) ?>"><i class='fa fa-print'></i> Print</a>
+        </div>
+    </div>
+    <div class="row">
+        <div class="small-12 columns">
+            <style>
+                table {
+                    border:1px solid #ccc;
+                }
+
+                th {
+                    border:1px solid #ccc;
+                    padding:0px;
+                    margin:0px;
+                    background-color: #eaeaea;
+                }
+
+                td {
+                    border:1px solid #ccc;
+                    padding:0px;
+                    margin:0px;
+                }
+
+                .scroll {
+                    overflow-x:scroll;
+                    overflow-y:visible;
+                }
+
+            </style>
+            <div class="scroll">
+                <table>
+                    <thead>
+                    <tr>
+                        <th style="width:150px;"></th>
+                        <?php
+
+                            $date = new DateTime();
+                            $date->setDate($this->year,$this->previousMonth,26);
+
+                            for($i=1;$i<=$this->span;$i++)
+                            {
+                                if($date->format('d') >= 26)
+                                {
+                                    echo "<th style='background-color:#fff;border-bottom:1px solid #ccc; '>".$date->format('D')."<br>".$date->format('n')."/".$date->format('j')."</th>";
+                                }
+                                else
+                                {
+                                    echo "<th style='border-bottom:1px solid #ccc;'>".$date->format('D')."<br>".$date->format('n')."/".$date->format('j')."</th>";
+                                }
+                                $date->modify('+1 day');
+                            }
+                        ?>
+                    </tr>
+                    </thead>
+                    <tbody>
+                    <?php
+
+                        foreach($this->report as $user=>$dates)
+                        {
+                            $totalTime = array_sum($dates);
+                            echo "<tr>";
+                            echo "<td style='border-bottom:1px solid #ccc;'><b>$user</b><br>Total: $totalTime</td>";
+
+                            $date = new DateTime();
+                            $date->setDate($this->year,$this->previousMonth,26);
+                            for($j=1;$j<=$this->span;$j++)
+                            {
+                                echo "<td class='text-center' style='border-bottom:1px solid #ccc;'>";
+                                $value = "-";
+                                foreach ($dates as $entryDate => $total)
+                                {
+                                    $newDate = explode("-", $entryDate);
+                                    $dayOfMonth = $newDate[2];
+
+                                    if($dayOfMonth == $date->format('d'))
+                                    {
+                                        $value = $total;
+                                    }
+                                }
+                                echo $value;
+                                echo "</td>";
+
+                                $date->modify('+1 day');
+                            }
+                            echo "</tr>";
+                        }
+                    ?>
+                    </tbody>
+                </table>
+            </div>
+        </div>
+    </div>
+</div>

+ 84 - 0
application/views/reports/payperiodprint.phtml

@@ -0,0 +1,84 @@
+<style>
+    table {
+        border:1px solid #ccc;
+    }
+
+    th {
+        border:1px solid #ccc;
+        padding:0px;
+        margin:0px;
+        background-color: #eaeaea;
+    }
+
+    td {
+        border:1px solid #ccc;
+        padding:0px;
+        margin:0px;
+    }
+
+</style>
+<table width="100%" style="border:0px; padding:0px; margin:0px;">
+    <tr>
+        <td style="border:0px;"><h3><i class="fa fa-clock-o"></i> Total Hours: <?php echo date("F",$this->month) ?> <?php echo $this->year ?></h3></td>
+        <td style="border:0px;" class="text-right"><?php echo $this->startDate ?> - <?php echo $this->endDate ?></td>
+    </tr>
+</table>
+<table width="100%">
+    <thead>
+    <tr>
+        <th></th>
+        <?php
+
+        $date = new DateTime();
+        $date->setDate($this->year,$this->previousMonth,26);
+
+        for($i=1;$i<=$this->span;$i++)
+        {
+            if($date->format('d') >= 26)
+            {
+                echo "<th style='background-color:#fff;border-bottom:1px solid #ccc; '>".$date->format('D')."<br>".$date->format('n')."/".$date->format('j')."</th>";
+            }
+            else
+            {
+                echo "<th style='border-bottom:1px solid #ccc;'>".$date->format('D')."<br>".$date->format('n')."/".$date->format('j')."</th>";
+            }
+            $date->modify('+1 day');
+        }
+        ?>
+    </tr>
+    </thead>
+    <tbody>
+    <?php
+
+    foreach($this->report as $user=>$dates)
+    {
+        $totalTime = array_sum($dates);
+        echo "<tr>";
+        echo "<td style='border-bottom:1px solid #ccc;'><b>$user</b><br>Total: $totalTime</td>";
+
+        $date = new DateTime();
+        $date->setDate($this->year,$this->previousMonth,26);
+        for($j=1;$j<=$this->span;$j++)
+        {
+            echo "<td class='text-center' style='border-bottom:1px solid #ccc;'>";
+            $value = "-";
+            foreach ($dates as $entryDate => $total)
+            {
+                $newDate = explode("-", $entryDate);
+                $dayOfMonth = $newDate[2];
+
+                if($dayOfMonth == $date->format('d'))
+                {
+                    $value = $total;
+                }
+            }
+            echo $value;
+            echo "</td>";
+
+            $date->modify('+1 day');
+        }
+        echo "</tr>";
+    }
+    ?>
+    </tbody>
+</table>

+ 98 - 0
application/views/reports/payroll.phtml

@@ -0,0 +1,98 @@
+<div class="section">
+    <div class="row">
+        <div class="small-6 columns">
+            <h2><i class="fa fa-file"></i> Payroll Report</h2>
+        </div>
+        <div class="small-6 columns text-right">
+            <a class="button radius" target="_blank" href="<?php echo $this->link(array('reports','payrollprint',$this->year,$this->month)) ?>"><i class='fa fa-print'></i> Print</a>
+        </div>
+    </div>
+    <div class="row">
+        <div class="small-12 columns">
+            <style>
+                table {
+                    border:1px solid #ccc;
+                }
+
+                th {
+                    border:1px solid #ccc;
+                    padding:0px;
+                    margin:0px;
+                    background-color: #eaeaea;
+                }
+
+                td {
+                    border:1px solid #ccc;
+                    padding:0px;
+                    margin:0px;
+                }
+
+                .scroll {
+                    overflow-x:scroll;
+                    overflow-y:visible;
+                }
+
+            </style>
+            <div class="">
+                <table>
+                    <thead>
+                    <tr>
+                       <th style="width:150px;"></th>
+                       <?php
+
+                           foreach($this->codes as $code)
+                           {
+                               if($code == 'Normal')
+                               {
+                                   echo "<th style='background-color:#d8ffd3;'>$code</th>";
+                               }
+                               else
+                               {
+                                   echo "<th>$code</th>";
+                               }
+
+                           }
+
+                       ?>
+                    </tr>
+                    </thead>
+                    <tbody>
+                    <?php
+
+                    foreach($this->report as $user=>$codes)
+                    {
+
+                        echo "<tr>";
+                        echo "<td style='border-bottom:1px solid #ccc;'><b>$user</b></td>";
+
+                        //for($j=1;$j<=count($this->codes);$j++)
+                        foreach($this->codes as $id=>$timeCode)
+                        {
+                            if($timeCode == 'Normal')
+                            {
+                                echo "<td class='text-center' style='background-color:#d8ffd3; border-bottom:1px solid #ccc;'>";
+                            }
+                            else
+                            {
+                                echo "<td class='text-center' style='border-bottom:1px solid #ccc;'>";
+                            }
+                            $value = "-";
+                            foreach ($codes as $code => $total)
+                            {
+                                if($timeCode == $code)
+                                {
+                                    $value = $total;
+                                }
+                            }
+                            echo $value;
+                            echo "</td>";
+                        }
+                        echo "</tr>";
+                    }
+                    ?>
+                    </tbody>
+                </table>
+            </div>
+        </div>
+    </div>
+</div>

+ 89 - 0
application/views/reports/payrollprint.phtml

@@ -0,0 +1,89 @@
+
+<style>
+    table {
+        border:1px solid #ccc;
+    }
+
+    th {
+        border:1px solid #ccc;
+        padding:0px;
+        margin:0px;
+        background-color: #eaeaea;
+    }
+
+    td {
+        border:1px solid #ccc;
+        padding:0px;
+        margin:0px;
+    }
+
+    .scroll {
+        overflow-x:scroll;
+        overflow-y:visible;
+    }
+
+</style>
+<table width="100%" style="border:0px; padding:0px; margin:0px;">
+    <tr>
+        <td style="border:0px;"><h3><i class="fa fa-clock-o"></i> Payroll Report: <?php echo date("F",$this->month) ?> <?php echo $this->year ?></h3></td>
+        <td style="border:0px;" class="text-right"><?php echo $this->startDate ?> - <?php echo $this->endDate ?></td>
+    </tr>
+</table>
+<table width="100%">
+    <thead>
+    <tr>
+       <th style="width:150px;"></th>
+       <?php
+
+           foreach($this->codes as $code)
+           {
+               if($code == 'Normal')
+               {
+                   echo "<th style='background-color:#d8ffd3;'>$code</th>";
+               }
+               else
+               {
+                   echo "<th>$code</th>";
+               }
+
+           }
+
+       ?>
+    </tr>
+    </thead>
+    <tbody>
+    <?php
+
+    foreach($this->report as $user=>$codes)
+    {
+
+        echo "<tr>";
+        echo "<td style='border-bottom:1px solid #ccc;'><b>$user</b></td>";
+
+        //for($j=1;$j<=count($this->codes);$j++)
+        foreach($this->codes as $id=>$timeCode)
+        {
+            if($timeCode == 'Normal')
+            {
+                echo "<td class='text-center' style='background-color:#d8ffd3; border-bottom:1px solid #ccc;'>";
+            }
+            else
+            {
+                echo "<td class='text-center' style='border-bottom:1px solid #ccc;'>";
+            }
+            $value = "-";
+            foreach ($codes as $code => $total)
+            {
+                if($timeCode == $code)
+                {
+                    $value = $total;
+                }
+            }
+            echo $value;
+            echo "</td>";
+        }
+        echo "</tr>";
+    }
+    ?>
+    </tbody>
+</table>

+ 130 - 0
application/views/reports/printpreview.phtml

@@ -0,0 +1,130 @@
+<div class="row">
+    <div class="small-12 columns text-center">
+        <h1><?php echo $this->firstName ?> <?php echo $this->lastName ?> <small><?php echo $this->timesheet->currentMonthText ?> <?php echo $this->timesheet->currentYear ?></small></h1>
+    </div>
+    <div class="small-12 columns text-center">
+        <p>
+            <b>Date Range:</b> <?php echo date("l, F jS Y",$this->timesheet->startDateTimeString) ?> to <?php echo date("l, F jS Y",$this->timesheet->endDateTimeString) ?>
+            <br>
+            <b>Report Generated:</b> <?php echo date('l, F jS Y g:i A') ?>
+        </p>
+    </div>
+</div>
+
+<div class="row">
+    <div class="small-12 columns">
+        <h3>Totals <small>Calculated with <i>Adjusted</i> time</small></h3>
+        <table width="100%">
+            <thead>
+            <tr>
+                <?php
+                foreach($this->timesheet->totals as $title => $value)
+                {
+                    if($value > 0)
+                    {
+                        echo "<th>$title</th>";
+                    }
+                }
+                ?>
+            </tr>
+            </thead>
+            <tbody>
+            <?php
+            foreach($this->timesheet->totals as $title => $value)
+            {
+                if($value > 0)
+                {
+                    echo "<td>$value</td>";
+                }
+            }
+            ?>
+            </tbody>
+        </table>
+    </div>
+</div>
+
+<div class="row">
+    <div class="small-12 columns">
+        <h3>Time Sheet</h3>
+        <p><i>Adjusted</i> time calculated to the nearest quarter hour. Example: <b>9:07 AM</b> will be adjusted to <b>9:00 AM</b> and <b>10:08 AM</b> will be adjusted to <b>10:15 AM</b>.</p>
+        <table width="100%">
+            <thead>
+            <tr>
+                <th>Date</th>
+                <th>In Time <small>(Actual)</small></th>
+                <th>Out Time <small>(Actual)</small></th>
+                <th>In Time <small>(Adjusted)</small></th>
+                <th>Out Time <small>(Adjusted)</small></th>
+                <th>Less Time <small>(Minutes)</small></th>
+                <th>Code</th>
+                <th>Total <small>(Hours)</small></th>
+                <th>Validated</th>
+            </tr>
+            </thead>
+            <tbody>
+    </div>
+</div>
+
+<?php
+
+$currentBatch = $this->batchId;
+
+foreach($this->timesheet->entries as $entry)
+{
+    echo "
+                <tr>
+                    <td>".$entry->date."</td>
+                    <td>".$entry->inTime."</td>
+                    <td>".$entry->outTime."</td>
+                ";
+
+    if($entry->inTime != $entry->roundedInTime)
+    {
+        echo "<td>".$entry->roundedInTime."</td>";
+    }
+    else
+    {
+        echo "<td> N/A </td>";
+    }
+
+    if($entry->outTime != $entry->roundedOutTime)
+    {
+        echo "<td>".$entry->roundedOutTime."</td>";
+    }
+    else
+    {
+        echo "<td> N/A </td>";
+    }
+
+    echo "
+                    <td>".$entry->lessTime."</td>
+                    <td>".$entry->codeName."</td>
+                    <td>".$entry->timeWorked."</td>
+                ";
+
+    if($currentBatch != $entry->batchId)
+    {
+        echo "<td>Yes <i class='fa fa-check'></i></td>";
+    }
+    else
+    {
+        echo "<td>No <i class='fa fa-close'></i></td>";
+    }
+
+    echo "</tr>";
+
+    if(strlen($entry->note) > 0)
+    {
+        echo "
+            <tr>
+                <td class='text-right'><i class='fa fa-edit'></i> Note:</td>
+                <td colspan='7'>".$entry->note."</td>
+            </tr>
+        ";
+    }
+}
+?>
+</tbody>
+</table>
+</div>
+</div>

+ 6 - 9
application/views/reports/weekly.phtml

@@ -14,11 +14,8 @@
                 {
                     echo "
                         <div class='row'>
-                            <div class='small-6 columns'>
-
-                            </div>
-                            <div class='small-6 columns'>
-                                <a class='button secondary radius right' href='".$this->link(array('reports','weekly'))."'>Back</a>
+                            <div class='small-12 columns text-right hide-for-print'>
+                                <a class='button secondary radius' href='".$this->link(array('reports','weekly'))."'>Back</a>
                             </div>
                         </div>
 
@@ -30,7 +27,7 @@
 
                                     if($this->account['type'] == "part")
                                     {
-                                        echo "Part time";
+                                        echo "Part Time";
                                     }
                                     else
                                     {
@@ -65,15 +62,15 @@
                                     {
                                         if($entry['hoursWorked'] >= 18 AND $entry['hoursWorked'] < 20)
                                         {
-                                            echo "<span class='orange'><i class='fa fa-flag'></i> Approaching weekly limit of 20 hours.</span> <b>".$entry['hoursWorked']."</b>";
+                                            echo "<span class='orange'><i class='fa fa-flag'></i> Approaching weekly limit of 20 hours.</span><br>".$entry['hoursWorked'];
                                         }
                                         elseif($entry['hoursWorked'] == 20)
                                         {
-                                            echo "<span class='green'><i class='fa fa-flag'></i> At weekly limit of 20 hours.</span> <b>".$entry['hoursWorked']."</b>";
+                                            echo "<span class='green'><i class='fa fa-flag'></i> At weekly limit of 20 hours.</span><br>".$entry['hoursWorked'];
                                         }
                                         elseif($entry['hoursWorked'] >= 21)
                                         {
-                                            echo "<span class='red'><i class='fa fa-warning'></i> Exceeded weekly limit of 20 hours.</span> <b>".$entry['hoursWorked']."</b>";
+                                            echo "<span class='red'><i class='fa fa-warning'></i> Exceeded weekly limit of 20 hours.</span><br>".$entry['hoursWorked'];
                                         }
                                         else
                                         {

+ 1 - 1
application/views/timesheet/index.phtml

@@ -9,7 +9,7 @@
                 <li><a class="button small secondary" href="<?php echo $this->link(array('timesheet',$this->timesheet->currentYear,$this->timesheet->previousMonth)) ?>"><i class="fa fa-caret-left"></i> Prev.</a></li>
                 <li><a class="button small secondary" href="<?php echo $this->link(array('timesheet',$this->timesheet->currentYear,$this->timesheet->nextMonth)) ?>">Next <i class="fa fa-caret-right"></i></a></li>
                 <li><a class="button small toggleTotals" href="#"><i class="fa fa-calculator"></i> Totals</a></li>
-                <li><a class="button small" href="#"><i class="fa fa-print"></i> Print</a></li>
+                <li><a class="button small" target="_blank" href="<?php echo $this->link(array('timesheet','printpreview',$this->timesheet->userId,$this->timesheet->currentYear,$this->timesheet->currentMonth)) ?>"><i class="fa fa-print"></i> Print</a></li>
                 <?php
                     if($this->needsValidation)
                     {

+ 130 - 0
application/views/timesheet/printpreview.phtml

@@ -0,0 +1,130 @@
+<div class="row">
+    <div class="small-12 columns text-center">
+        <h1><?php echo $this->firstName ?> <?php echo $this->lastName ?> <small><?php echo $this->timesheet->currentMonthText ?> <?php echo $this->timesheet->currentYear ?></small></h1>
+    </div>
+    <div class="small-12 columns text-center">
+        <p>
+            <b>Date Range:</b> <?php echo date("l, F jS Y",$this->timesheet->startDateTimeString) ?> to <?php echo date("l, F jS Y",$this->timesheet->endDateTimeString) ?>
+            <br>
+            <b>Report Generated:</b> <?php echo date('l, F jS Y g:i A') ?>
+        </p>
+    </div>
+</div>
+
+<div class="row">
+    <div class="small-12 columns">
+        <h3>Totals <small>Calculated with <i>Adjusted</i> time</small></h3>
+        <table width="100%">
+            <thead>
+            <tr>
+                <?php
+                foreach($this->timesheet->totals as $title => $value)
+                {
+                    if($value > 0)
+                    {
+                        echo "<th>$title</th>";
+                    }
+                }
+                ?>
+            </tr>
+            </thead>
+            <tbody>
+            <?php
+            foreach($this->timesheet->totals as $title => $value)
+            {
+                if($value > 0)
+                {
+                    echo "<td>$value</td>";
+                }
+            }
+            ?>
+            </tbody>
+        </table>
+    </div>
+</div>
+
+<div class="row">
+    <div class="small-12 columns">
+        <h3>Time Sheet</h3>
+        <p><i>Adjusted</i> time calculated to the nearest quarter hour. Example: <b>9:07 AM</b> will be adjusted to <b>9:00 AM</b> and <b>10:08 AM</b> will be adjusted to <b>10:15 AM</b>.</p>
+        <table width="100%">
+            <thead>
+            <tr>
+                <th>Date</th>
+                <th>In Time <small>(Actual)</small></th>
+                <th>Out Time <small>(Actual)</small></th>
+                <th>In Time <small>(Adjusted)</small></th>
+                <th>Out Time <small>(Adjusted)</small></th>
+                <th>Less Time <small>(Minutes)</small></th>
+                <th>Code</th>
+                <th>Total <small>(Hours)</small></th>
+                <th>Validated</th>
+            </tr>
+            </thead>
+            <tbody>
+    </div>
+</div>
+
+<?php
+
+$currentBatch = $this->batchId;
+
+foreach($this->timesheet->entries as $entry)
+{
+    echo "
+                <tr>
+                    <td>".$entry->date."</td>
+                    <td>".$entry->inTime."</td>
+                    <td>".$entry->outTime."</td>
+                ";
+
+    if($entry->inTime != $entry->roundedInTime)
+    {
+        echo "<td>".$entry->roundedInTime."</td>";
+    }
+    else
+    {
+        echo "<td> N/A </td>";
+    }
+
+    if($entry->outTime != $entry->roundedOutTime)
+    {
+        echo "<td>".$entry->roundedOutTime."</td>";
+    }
+    else
+    {
+        echo "<td> N/A </td>";
+    }
+
+    echo "
+                    <td>".$entry->lessTime."</td>
+                    <td>".$entry->codeName."</td>
+                    <td>".$entry->timeWorked."</td>
+                ";
+
+    if($currentBatch != $entry->batchId)
+    {
+        echo "<td>Yes <i class='fa fa-check'></i></td>";
+    }
+    else
+    {
+        echo "<td>No <i class='fa fa-close'></i></td>";
+    }
+
+    echo "</tr>";
+
+    if(strlen($entry->note) > 0)
+    {
+        echo "
+            <tr>
+                <td class='text-right'><i class='fa fa-edit'></i> Note:</td>
+                <td colspan='7'>".$entry->note."</td>
+            </tr>
+        ";
+    }
+}
+?>
+</tbody>
+</table>
+</div>
+</div>