当前位置: 首页>>代码示例>>PHP>>正文


PHP Employee::has方法代码示例

本文整理汇总了PHP中app\Employee::has方法的典型用法代码示例。如果您正苦于以下问题:PHP Employee::has方法的具体用法?PHP Employee::has怎么用?PHP Employee::has使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在app\Employee的用法示例。


在下文中一共展示了Employee::has方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: exportToExcel

 public function exportToExcel()
 {
     // $path = storage_path('app/DTRTemplates/DTRSummary.xlsx'); //Path of the excel template to be loaded
     $path = storage_path('app/DTRTemplates/DTRSummary.xlsx');
     Excel::load($path, function ($reader) {
         //load the excel file
         $raw_sheet = $reader->sheet('raw');
         //select the raw sheet of the excel file
         $summary_sheet = $reader->sheet('summary');
         //select the summary sheet of the excel file
         $rawSheetIndex = 1;
         $summarySheetIndex = 3;
         $employees = Employee::has('employee_dtrs')->with('employee_dtrs', 'shifts')->orderBy('last_name')->get();
         foreach ($employees as $employee) {
             //get the employee logs within the provided days
             $rawSheetIndex = $rawSheetIndex + 2;
             $staffcode = $employee->employee_id;
             $staffname = strtoupper($employee->last_name) . ', ' . $employee->first_name;
             $computations = value(function () use($employee) {
                 $late = new DateTime('00:00:00');
                 $undertime = new DateTime('00:00:00');
                 $overbreak = new DateTime('00:00:00');
                 $hrs_worked = new DateTime('00:00:00');
                 foreach ($employee->employee_dtrs as $dtr) {
                     $late->add(computeTimeInterval($dtr->late, '00:00:00'));
                     $undertime->add(computeTimeInterval($dtr->undertime, '00:00:00'));
                     $overbreak->add(computeTimeInterval($dtr->overbreak, '00:00:00'));
                     $hrs_worked->add(computeTimeInterval($dtr->end_of_duty, $dtr->start_of_duty));
                 }
                 //return an array with employee late, undertime, overbreak and hrs_worked value
                 return ['late' => toMinutes(date_diff($late, new DateTime('00:00:00'))), 'undertime' => toMinutes(date_diff($undertime, new DateTime('00:00:00'))), 'overbreak' => toMinutes(date_diff($overbreak, new DateTime('00:00:00'))), 'hrs_worked' => toHours(date_diff($hrs_worked, new DateTime('00:00:00')))];
             });
             //add a new row and put all the gathered datas
             $row = $summary_sheet->appendRow($summarySheetIndex, [$staffcode, $staffname, $computations['late'], $computations['undertime'], $computations['overbreak'], '', $computations['hrs_worked']]);
             ++$summarySheetIndex;
             foreach ($employee->employee_dtrs as $employee_dtr) {
                 // dd($employee_dtr);
                 //assign the data to the variables
                 $date = date('Y-m-d', strtotime($employee_dtr->start_of_duty));
                 $login = date('H:i:s', strtotime($employee_dtr->start_of_duty));
                 $logout = date('H:i:s', strtotime($employee_dtr->end_of_duty));
                 $late = $employee_dtr->late;
                 $undertime = $employee_dtr->undertime;
                 $lateToMinutes = stringToMinutes($late);
                 $undertimeToMinutes = stringToMinutes($undertime);
                 $shift_from = $employee_dtr->shift->shift_from;
                 $shift_to = $employee_dtr->shift->shift_to;
                 if ($lateToMinutes > 200 && $lateToMinutes < 240) {
                     $lateToMinutes = 240;
                 }
                 if ($undertimeToMinutes > 200 && $undertimeToMinutes < 240) {
                     $undertimeToMinutes = 240;
                 }
                 //add a new row and put all the gathered datas
                 if ($employee_dtr->remarks == 'ABSENT') {
                     $login = 'ABSENT';
                     $logout = 'ABSENT';
                     $lateToMinutes = 480;
                 }
                 $row = $raw_sheet->appendRow($rawSheetIndex, [$staffname, $date, $login, $logout, $shift_from, $shift_to, $late, $lateToMinutes, $undertime, $undertimeToMinutes, null, $employee_dtr->remarks]);
                 $staffname = null;
                 ++$rawSheetIndex;
                 //increment the index to know what row are we
             }
         }
     })->download('xlsx');
     //download the excel file
 }
开发者ID:rosemalejohn,项目名称:hpo-hris,代码行数:68,代码来源:DtrController.php

示例2: getEmployees

 public function getEmployees()
 {
     return response()->json(Employee::has('company')->get());
 }
开发者ID:ValentinNikolaev,项目名称:Laravel5-dhtmlxScheduler-demo,代码行数:4,代码来源:SchedulerApiController.php


注:本文中的app\Employee::has方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。