
@extends('layouts.app-hr')
@section('content')
    <meta name="csrf-token" content="{{ csrf_token() }}">
    <?php Fun::lang()?>
    @php
        $from_date      = @$_GET['from_date'];
        $to_date        = @$_GET['to_date'];
        $emp_id         = @$_GET['emp_id'];
        $branch_id      = @$_GET['branch_id'];
        $department_id  = @$_GET['department_id'];
        $position_id    = @$_GET['position_id'];
    @endphp
    <div class="page">
        <div class=container-fluid>
            <div class="top-content">
                <div class="row">
                    <div class="col-sm-12 col-xs-12 form-group">
                        <div class="title-add">
                            <div class="pull-left">
                                <h3>{{__('administrator.payslip')}}</h3>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            <div class="top-content">
                <div class="row">
                    <div class="col-sm-12 col-xs-12 form-group paddin-0">
                        <div>
                            <div class="col-sm-4">
                                <div class="form-group">
                                    @php
                                        $branch = App\Model\setup\BranchModel::pluck('name', 'id');
                                    @endphp
                                    <strong for="">{{__('administrator.branch')}}</strong>
                                    {!! Form::select('branch_id', $branch, null, array('class' => 'form-control select2', 'multiple','autocomplete' => 'off')) !!}
                                </div>
                            </div>
                            <div class="col-sm-4">
                                <div class="form-group">
                                    @php
                                        $department = App\Model\Hr\HrDepartmentModel::pluck('english_name', 'id');
                                    @endphp
                                    <strong for="">{{__('administrator.department')}}</strong>
                                    {!! Form::select('department_id', $department, null, array('class' => 'form-control select2', 'multiple','autocomplete' => 'off')) !!}
                                </div>
                            </div>
                            <div class="col-sm-4">
                                <div class="form-group">
                                    @php
                                        $position = App\Model\Hr\HrPositionModel::pluck('english_name', 'id');
                                    @endphp
                                    <strong for="">{{__('administrator.position')}}</strong>
                                    {!! Form::select('position_id', $position, null, array('class' => 'form-control select2', 'multiple', 'autocomplete' => 'off')) !!}
                                </div>
                            </div>
                            <div class="col-sm-4">
                                <div class="form-group">
                                    @php
                                        $user = App\User::pluck('name', 'id');
                                    @endphp
                                    <strong for="">{{__('administrator.employee')}}</strong>
                                    {!! Form::select('emp_id[]',$user, null , ['class' => 'form-control select2', 'multiple','autocomplete' => 'off']) !!}
                                </div>
                            </div>
                            <div class="col-sm-4">
                                <div class="form-group">
                                    <strong for="">{{__('administrator.from_date')}}</strong>
                                    {!! Form::text('from_date', $from_date, array('placeholder' => __('administrator.from_date'),'class' => 'form-control date_picker','id' => 'from_date','autocomplete' => 'off','')) !!}
                                </div>
                            </div>
                            <div class="col-sm-4">
                                <div class="form-group">
                                    <strong for="">{{__('administrator.to_date')}}</strong>
                                    {!! Form::text('to_date', $to_date, array('placeholder' => __('administrator.to_date'),'class' => 'form-control date_picker', 'id' => 'to_date','autocomplete' => 'off','')) !!}
                                </div>
                            </div>
                            <div class=" col-sm-12">
                                <button class=" button_info pull-right print-data" type="button"> {{__('administrator.print')}}</button>
                                <button class=" button_primary pull-right btn_search" type="button"> {{__('administrator.search')}}</button>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="col-md-12 show-report" style="height: 768px; width: 100%; background-color: #ffffff; padding: 20px; -webkit-box-shadow: 0px 6px 26px -6px rgba(0,0,0,0.48);
                        -moz-box-shadow: 0px 6px 26px -6px rgba(0,0,0,0.48);
                        box-shadow: 0px 6px 26px -6px rgba(0,0,0,0.48); border-radius: 5px;overflow: scroll;">

                    </div>
            </div>
        </div>
    </div>

@endsection
@section('script')
    <script>
        $(document).ready(function () {
            $('.print-data').on('click',function () {
                printDiv();
            });
            $('.btn_search').on('click', function(e){
                e.preventDefault();

                var emp_id          = $('[name="emp_id[]"]').val();
                var branch_id       = $('[name="branch_id[]"]').val();
                var department_id   = $('[name="department_id[]"]').val();
                var position_id     = $('[name="position_id[]"]').val();
                var from_date       = $('[name="from_date"]').val();
                var to_date         = $('[name="to_date"]').val();

                $.ajaxSetup({
                    headers: {
                        'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
                    }
                });

                if(from_date != "" && to_date != "")
                {
                    $.ajax({
                        url: "{{route('get.report-payslip-show')}}",
                        type: 'POST',
                        async: false,
                        dataType: 'html',
                        data: {
                            emp_id: emp_id,
                            branch_id: branch_id,
                            department_id: department_id,
                            position_id: position_id,
                            from_date: from_date,
                            to_date: to_date

                        },
                        success: function (d) {
                            $('.show-report').html(d);
                        },
                        error: function (d) {
                            $.alert('Error!');
                        }
                    });

                }else{
                    $.alert('Please Select From Date and To Date!')
                }

            });
        });

        function printDiv()
        {

            var divToPrint=document.getElementById('DivIdToPrint');

            var newWin=window.open('','Print-Window');

            newWin.document.open();

            newWin.document.write('<html>' +
                '<head>' +
                '<style>\n' +
                '    .table-data\n' +
                '    {\n' +
                '        width:100%;\n' +
                '    }\n' +
                '\n' +
                '    .table-data,.table-data  th, .table-data  td\n' +
                '    {\n' +
                '        border-collapse:collapse;\n' +
                '        border: 1px solid #a8a8a8;\n' +
                '    }\n' +
                '\n' +
                '    .table-data  th\n' +
                '    {\n' +
                '        text-align: center;\n' +
                '        padding: 5px;\n' +
                '    }\n' +
                '\n' +
                '    .table-data  td\n' +
                '    {\n' +
                '        padding: 5px;\n' +
                '    }\n' +
                '\n' +
                '    .table-data  tbody > tr:nth-child(odd)\n' +
                '    {\n' +
                '       background-color: #f4f4f4;\n' +
                '        color: #606060;\n' +
                '    }\n' +
                '</style>' +
                '</head>'+
                '<body onload="window.print()">'+divToPrint.innerHTML+'</body>' +
                '</html>');

            newWin.document.close();

            setTimeout(function(){newWin.close();},10);

        }
    </script>
@endsection
