Prechádzať zdrojové kódy

Making an administrative report that displays total hours worked, sick, and vacation time for a given day.

Adam Day 9 rokov pred
rodič
commit
260a1c583c

+ 76 - 0
application/controllers/reportsController.php

@@ -42,6 +42,25 @@ 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();
+                header("location: ".$this->_link(array('reports','printpreview',$year,$month,$data['account']))."");
+            }
+            else
+            {
+                $this->view->printTimeSheetForm = $printTimeSheetForm;
+            }
+        }
+        else
+        {
+            $this->view->printTimeSheetForm = $printTimeSheetForm;
+        }
     }
 
     public function changeyear()
@@ -133,4 +152,61 @@ class reportsController extends Staple_Controller
             }
         }
     }
+
+    public function printpreview($year,$month,$uid)
+    {
+        $report = new reportModel($year,$month);
+
+        $user = new userModel();
+        $account = $user->userInfo($uid);
+        $userName = $account['lastName'].", ".$account['firstName'];
+
+        $data = array();
+        foreach($report->timesheets as $account => $entry)
+        {
+            if($userName == $account)
+            {
+                foreach($entry as $key=>$value)
+                {
+
+                    if($value['code'] == 'Normal')
+                    {
+                        if(array_key_exists($value['date'],$data))
+                        {
+                            $data[$value['date']]['normal'] = $data[$value['date']]['normal'] + $value['timeWorked'];
+                        }
+                        else
+                        {
+                            $data[$value['date']]['normal'] = $value['timeWorked'];
+                        }
+                    }
+
+                    if($value['code'] == 'Sick')
+                    {
+                        if(array_key_exists($value['date'],$data))
+                        {
+                            $data[$value['date']]['sick'] = $data[$value['date']]['sick'] + $value['timeWorked'];
+                        }
+                        else
+                        {
+                            $data[$value['date']]['sick'] = $value['timeWorked'];
+                        }
+                    }
+
+                    if($value['code'] == 'Vacation')
+                    {
+                        if(array_key_exists($value['date'],$data))
+                        {
+                            $data[$value['date']]['vacation'] = $data[$value['date']]['vacation'] + $value['timeWorked'];
+                        }
+                        else
+                        {
+                            $data[$value['date']]['vacation'] = $value['timeWorked'];
+                        }
+                    }
+                }
+            }
+        }
+        $this->view->data = $data;
+    }
 }

+ 59 - 0
application/forms/printTimeSheetForm.php

@@ -0,0 +1,59 @@
+<?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','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['supervisorId'] == $id)
+                {
+                    $data[$user['id']] = $user['lastName'].", ".$user['firstName']." (". $user['type'] .")";
+                }
+                elseif($authLevel >= 900)
+                {
+                    $data[$user['id']] = $user['lastName'].", ".$user['firstName']." (". $user['type'] .")";
+                }
+            }
+        }
+        else
+        {
+            foreach($users as $user)
+            {
+                $data[] = $user['id'];
+            }
+        }
+
+        return $data;
+    }
+}
+
+?>

+ 13 - 2
application/layouts/print.phtml

@@ -16,19 +16,30 @@
             size: auto;   /* auto is the initial value */
 
             /* this affects the margin in the printer settings */
-            margin: 15mm 0mm 15mm 0mm;
+            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:10pt !important;
+            font-size:8pt !important;
         }
 
     </style>

+ 0 - 1
application/models/codeModel.php

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

+ 1 - 1
application/models/timesheetModel.php

@@ -327,7 +327,7 @@
 			$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->endDate = $currentDate->modify('+25 day')->format('Y-m-d');
 			$this->endDateTimeString = strtotime($this->endDate);
 
 			//Previous Dates

+ 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 id="modalTitle">Select an account</h2>
+    <?php echo $this->printTimeSheetForm ?>
+    <a class="close-reveal-modal" aria-label="Close">&#215;</a>
+</div>
+
 <script>
     $(function() {
 

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

@@ -0,0 +1,11 @@
+<?php
+
+foreach($this->data as $date=>$hours)
+{
+    echo "$date<br>";
+    echo "<pre>";
+    print_r($hours);
+    echo "</pre>";
+}
+
+?>