Bläddra i källkod

Supervisor and Admin accounts can now print individual user timesheets.

Adam Day 9 år sedan
förälder
incheckning
8605513a53

+ 9 - 1
application/controllers/reportsController.php

@@ -51,7 +51,11 @@ class reportsController extends Staple_Controller
             if($printTimeSheetForm->validate())
             {
                 $data = $printTimeSheetForm->exportFormData();
-                header("location: ".$this->_link(array('reports','printpreview',$year,$month,$data['account']))."");
+
+                $this->layout->addScriptBlock("
+                    window.open('".$this->_link(array("reports","printpreview",$year,$month,$data['account']))."');
+                    ");
+                $this->view->printTimeSheetForm = $printTimeSheetForm;
             }
             else
             {
@@ -167,5 +171,9 @@ class reportsController extends Staple_Controller
         $this->view->year = $year;
         $this->view->month = date('F',$month);
 
+
+        $timesheet = new timesheetModel($year, $month,$uid);
+        $this->view->timesheet = $timesheet;
+
     }
 }

+ 14 - 3
application/forms/printTimeSheetForm.php

@@ -9,7 +9,7 @@ class printTimeSheetForm extends Staple_Form
         $this->setName('printTimeSheet')
             ->setAction($this->link(array('reports')));
 
-        $account = new Staple_Form_FoundationSelectElement('account','Account');
+        $account = new Staple_Form_FoundationSelectElement('account','Select an account');
         $account->setRequired()
             ->addOption('','Select an account')
             ->addOptionsArray($this->accounts())
@@ -34,13 +34,24 @@ class printTimeSheetForm extends Staple_Form
         {
             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']." (". $user['type'] .")";
+                    $data[$user['id']] = $user['lastName'].", ".$user['firstName']." ($type)";
                 }
                 elseif($authLevel >= 900)
                 {
-                    $data[$user['id']] = $user['lastName'].", ".$user['firstName']." (". $user['type'] .")";
+                    $data[$user['id']] = $user['lastName'].", ".$user['firstName']." ($type)";
                 }
             }
         }

+ 2 - 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">
 

+ 1 - 1
application/layouts/print.phtml

@@ -44,7 +44,7 @@
 
     </style>
 </head>
-<body onload="window.prints()">
+<body onload="window.print()">
 <nav class="top-bar hide-for-print" data-topbar role="navigation">
     <ul class="title-area">
         <li class="name">

+ 26 - 10
application/models/timesheetModel.php

@@ -302,11 +302,11 @@
 
 
 
-		function __construct($year, $month, $user = null)
+		function __construct($year, $month, $uid = null)
 		{
 			$this->db = Staple_DB::get();
 
-			if($user == null)
+			if($uid == null)
 			{
 				//Get batchID
 				$user = new userModel();
@@ -314,7 +314,7 @@
 			}
 			else
 			{
-				$user = new userModel($user);
+				$user = new userModel($uid);
 			}
 
 			//Current Dates
@@ -351,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();
 
@@ -360,7 +360,7 @@
 			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);
 
@@ -378,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)
@@ -424,11 +432,19 @@
 		}
 		*/
 
-		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 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;";

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

@@ -178,7 +178,7 @@
 </div>
 
 <div id="print" class="reveal-modal small" data-reveal aria-labelledby="Print Report" aria-hidden="true" role="dialog">
-    <h2 id="modalTitle">Select an account</h2>
+    <h2>Print Individual Time Sheet</h2>
     <?php echo $this->printTimeSheetForm ?>
     <a class="close-reveal-modal" aria-label="Close">&#215;</a>
 </div>

+ 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
                                         {

+ 51 - 48
application/views/timesheet/printpreview.phtml

@@ -3,8 +3,11 @@
         <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) ?></p>
-        <p><b>Report Generated:</b> <?php echo date('l, F jS Y g:i A') ?></p>
+        <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>
 
@@ -43,7 +46,7 @@
 <div class="row">
     <div class="small-12 columns">
         <h3>Time Sheet</h3>
-        <p><i>Adjusted</i> time calculated to the nearest quarter hour. <br> 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>
+        <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>
@@ -62,66 +65,66 @@
     </div>
 </div>
 
-        <?php
+<?php
 
-            $currentBatch = $this->batchId;
+$currentBatch = $this->batchId;
 
-            foreach($this->timesheet->entries as $entry)
-            {
-                echo "
+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->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>";
-                }
+    if($entry->outTime != $entry->roundedOutTime)
+    {
+        echo "<td>".$entry->roundedOutTime."</td>";
+    }
+    else
+    {
+        echo "<td> N/A </td>";
+    }
 
-                echo "
+    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>";
-                }
+    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>";
+    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>
+    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>