Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/css/36.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 我如何计算拉雷维尔的月日?_Php_Laravel_Mongodb - Fatal编程技术网

Php 我如何计算拉雷维尔的月日?

Php 我如何计算拉雷维尔的月日?,php,laravel,mongodb,Php,Laravel,Mongodb,在选择“月”和“年”之后,我有一个月和年的列,它将计算员工当前的总天数,减去该员工当月休假的天数 这是我的控制器文件代码 public function employeeAttendance(Request $request) { $employeeName = User::all(); $employeeLeave = LeaveManagement::all(); $countMonth = $request->get('mo

在选择“月”和“年”之后,我有一个月和年的列,它将计算员工当前的总天数,减去该员工当月休假的天数

这是我的控制器文件代码

 public function employeeAttendance(Request $request)
    {
        $employeeName = User::all();
        $employeeLeave = LeaveManagement::all();

        $countMonth = $request->get('month');
        $countYear = $request->get('year');

        function countDays($year, $month, $ignore) 
        {
            $count = 0;
            $counter = mktime(0, 0, 0, $month, 1, $year);
            while (date("n", $counter) == $month) {
                if (in_array(date("w", $counter), $ignore) == false) 
                {
                    $count++;
                }
                $counter = strtotime("+1 day", $counter);
            }
            return $count;
        }

        $totalWorkingDays = countDays($countYear, $countMonth, array(0, 6));

        return view('pages.attendance', compact('employeeName', 'totalWorkingDays', 'employeeLeave', 'countMonth', 'countYear'));
    }
这是我的查看文件代码

<div class="col-md-5 align-self-center">
                    <h4 class="text-themecolor">{{__('Employee Attendance')}}</h4>
                </div>
            </div>

            <div class="card">
                <div class="card-body">
                <form action="{{ route('employee_attendance') }}" method="GET">
                    <select class="custom-select col-md-2" name="month">
                        <option value="">Select Month</option>
                        <option value="01">January</option>
                        <option value="02">February</option>
                        <option value="03">March</option>
                        <option value="04">April</option>
                        <option value="05">May</option>
                        <option value="06">June</option>
                        <option value="07">July</option>
                        <option value="08">August</option>
                        <option value="09">September</option>
                        <option value="10">October</option>
                        <option value="11">November</option>
                        <option value="12">December</option>
                    </select>
                    <select class="custom-select col-md-2" name="year">
                        <option value="">Select Year</option>
                        <?php
                          for ($year = 2000; $year <= 2050; $year++) 
                          {
                            $selected = (isset($getYear) && $getYear == $year) ? 'selected' : '';
                            echo "<option value=$year $selected>$year</option>";
                          }
                        ?>
                    </select>
                    <button class="btn btn-info" type="submit"><i class="fa fa-search "></i></button>

                    <span style="float:right" class = "btn btn-info" disabled>Total Working Days : {{ $totalWorkingDays }} </span>
                </form>

                    <div class="table-responsive m-t-40">
                        <table class="table table-bordered table-striped ">
                            <thead>
                                <tr>
                                    <th>Employee Name</th>
                                    <th>Present Day</th>
                                    <th>Casual Leave</th>
                                    <th>Medical Leave</th>
                                </tr>
                            </thead>
                            <tbody>

                                @foreach ($employeeName as $empName)
                                @php
                                    $casualCount = $medicalCount = 0;
                                @endphp
                                @foreach($employeeLeave as $empleave)
                                    @if($empName['personal_detail']['first_name'] == $empleave->name)
                                            @if($empleave->type == 'casual')
                                                @php $casualCount++; @endphp
                                            @endif

                                            @if($empleave->type == 'medical')
                                                @php $medicalCount++; @endphp
                                            @endif
                                    @endif
                                @endforeach

                                    @if($empName['username'] != 'admin')
                                        <tr>
                                            <td>
                                                {{$empName['personal_detail']['first_name']}}
                                            </td>
                                            <td>
                                            @if($totalWorkingDays == 0)
                                                {{ $totalWorkingDays }}
                                            @else
                                                @php 
                                                    $totalLeave = $casualCount + $medicalCount;
                                                    $presentDay = $totalWorkingDays - $totalLeave;
                                                @endphp
                                                {{ $presentDay }}
                                            @endif
                                            </td>
                                            <td>
                                                @if( $totalWorkingDays == 0 )
                                                    {{ $totalWorkingDays }}
                                                @elseif( $countMonth ==  date('m', strtotime($empleave->start)) && $countYear ==  date('Y', strtotime($empleave->start))) 
                                                        {{ $casualCount }}
                                                @endif
                                            </td>

                                            <td>
                                                @if( $totalWorkingDays == 0 )
                                                    {{ $totalWorkingDays }}
                                                @elseif( $countMonth ==  date('m', strtotime($empleave->start)) && $countYear ==  date('Y', strtotime($empleave->start))) 
                                                    {{ $medicalCount }}
                                                @endif
                                            </td>
                                        </tr>
                                    @endif
                                @endforeach
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>

{{{(员工出勤)}
选择月份
一月
二月
前进
四月
也许
六月
七月
八月
九月
十月
十一月
十二月
选择年份
总工作日:{{$totalWorkingDays}
员工姓名
今天
事假
病假
@foreach($employeeName作为$empName)
@php
$casualCount=$medicalCount=0;
@endphp
@foreach($employeeLeave作为$Employeave)
@如果($empName['personal\u detail']['first\u name']==$emplave->name)
@如果($emplave->type=='casual')
@php$casualCount++@endphp
@恩迪夫
@如果($emplave->type=='medical')
@php$medicalCount++@endphp
@恩迪夫
@恩迪夫
@endforeach
@如果($empName['username']!='admin')
{{$empName['personal_detail']['first_name']}
@如果($totalWorkingDays==0)
{{$totalWorkingDays}
@否则
@php
$totalLeave=$CausalCount+$medicalCount;
$presentDay=$totalWorkingDays-$totalLeave;
@endphp
{{$presentDay}
@恩迪夫
@如果($totalWorkingDays==0)
{{$totalWorkingDays}
@elseif($countMonth==date('m',strotime($emplave->start))&&$countYear==date('Y',strotime($emplave->start)))
{{$casualCount}
@恩迪夫
@如果($totalWorkingDays==0)
{{$totalWorkingDays}
@elseif($countMonth==date('m',strotime($emplave->start))&&$countYear==date('Y',strotime($emplave->start)))
{{$medicalCount}
@恩迪夫
@恩迪夫
@endforeach

我希望,如果我选择2019年3月,它将给我所有员工该月的当前天数,如果他们在该月休了任何病假或临时假,它将从当前天数列中减去这是您的控制器功能

public function employeeAttendance(Request $request)
{
    $employeeName = User::all();
    $countMonth   = (!empty($request->get('month')) ? intval($request->get('month')) : 0);
    $countYear    = (!empty($request->get('year')) ? intval($request->get('year')) : 0);
    $firstDay     = new DateTime(date('F jS Y h:i:s A', strtotime('first day of ' . date('Y-m', strtotime("$countYear-$countYear")))));
    $lastDay      = new DateTime(date('F jS Y h:i:s A', strtotime('last day of ' . date('Y-m', strtotime("$countYear-$countYear")))));

    $employeeLeave = LeaveManagement::where('yourdatefield', '>=', $firstDay)
        ->where('yourdatefield', '<=', $lastDay)->get();
    $totalWorkingDays = 0;
    if (!empty($countMonth && $countYear)) {
        $totalWorkingDays = $this->countDays($countYear, $countMonth, array(0, 6));
    }
    $result = [];
    foreach ($employeeLeave as $empleave) {
        if ($empleave->type == 'casual') {
            $result[$empleave->name]['casual'][] = $empleave;
        }
        if ($empleave->type == 'medical') {
            $result[$empleave->name]['medical'][] = $empleave;
        }
    }
    return view('pages.attendance', compact('employeeName', 'totalWorkingDays', 'employeeLeave','result'));
}



public function countDays($year, $month, $ignore)
{
    $count   = 0;
    $counter = mktime(0, 0, 0, $month, 1, $year);
    while (date("n", $counter) == $month) {
        if (!in_array(date("w", $counter), $ignore)) {
            $count++;
        }
        $counter = strtotime("+1 day", $counter);
    }
    return $count;
}
向刀片发送
$result

按如下所示更改html表结构

<table class="table table-bordered table-striped ">
    <thead>
        <tr>
            <th>Employee Name</th>
            <th>Present Day</th>
            <th>Casual Leave</th>
            <th>Medical Leave</th>
        </tr>
    </thead>
    <tbody>
        @foreach($result as $empname => $empleave)
            <tr>
                <td>{{ $empname }}</td>
                <td>{{ $totalWorkingDays }}</td>
                <td>{{ count($result[$empname]['casual']) }}</td>
                <td>{{ count($result[$empname]['medical']) }}</td>

            </tr>    
        @endforeach
    </tbody>
</table>

员工姓名
今天
事假
病假
@foreach($empname=>$emplave的结果)
{{$empname}}
{{$totalWorkingDays}
{{count($result[$empname]['casual']])}
{{count($result[$empname]['medical']])}
@endforeach
我得到了这个错误非法的偏移类型(视图:/var/www/html/hrm/resources/views/pages/attention.blade.php)
$result = [];
foreach ($employeeLeave as $empleave) {
    if ($empleave->type == 'casual') {
        $result[$empleave->name]['casual'][] = $empleave;
    }
    if ($empleave->type == 'medical') {
        $result[$empleave->name]['medical'][] = $empleave;
    }
}
<table class="table table-bordered table-striped ">
    <thead>
        <tr>
            <th>Employee Name</th>
            <th>Present Day</th>
            <th>Casual Leave</th>
            <th>Medical Leave</th>
        </tr>
    </thead>
    <tbody>
        @foreach($result as $empname => $empleave)
            <tr>
                <td>{{ $empname }}</td>
                <td>{{ $totalWorkingDays }}</td>
                <td>{{ count($result[$empname]['casual']) }}</td>
                <td>{{ count($result[$empname]['medical']) }}</td>

            </tr>    
        @endforeach
    </tbody>
</table>