<link href="https://fonts.googleapis.com/css?family=Content|Moul|Titillium+Web" rel="stylesheet">
<style>

    @media print {

        .container {
            width: 821px !important;
            font-size: 16px !important;
            box-shadow: none !important;
        }

        .table-responsive-ss table tr, .table-responsive-ss td {
            font-size: 16px !important;
        }

        p, span, b {
            font-size: 16px !important;
        }

        .table-responsive-ss * {
            -webkit-print-color-adjust: exact;
        }

        .table-responsive-ss table {
            width: 100%;
            margin-top: 1px !important;
            padding-top: -21px !important;
            font-family: "Times New Roman" !important;
        }

        .table-responsive-ss th {
            white-space: nowrap;
        }

        .table-responsive-ss tr th {

            vertical-align: middle !important;
            color: white !important;
            /* background-color: #112EB0 !important; */
        }

    }

    .table-responsive-ss table {
        width: 100%;
        margin-top: 1px !important;
        padding-top: -21px !important;
    }

    .table-responsive-ss th {
        white-space: nowrap;
    }

    .table-responsive-ss tr th {

        vertical-align: middle !important;
        color: white !important;
        font-size: 12px !important;
        /* background-color: #112EB0 !important; */
        font-family: "Times New Roman" !important;
    }

</style>

@if($emp != null)
    <section class="content">
        <div class="table-responsive table-responsive-ss">
            <table class="table table-bordered" border="1" style="width: 100%;border-collapse: collapse;">
                <thead>
                    <tr>
                        <th style="text-align: center;"><input class="ch-em-id-all" type="checkbox"></th>
                        <th style="text-align: center;">Employee</th>
                        <th style="text-align: center;">Month/Year</th>
                        <th style="text-align: center;">Basic Salary</th>
                        <th style="text-align: center;">Overtime</th>
                        <th style="text-align: center;">Working Sunday</th>
                        <th style="text-align: center;">Benefit</th>
                        <th style="text-align: center;">Advance Salary</th>
                        <th style="text-align: center;">Take Leave</th>
                        <th style="text-align: center;">Khmer Rate</th>
                        <th style="text-align: center;">Thai Rate</th>
                        <th style="text-align: center;">Net Payment Kh</th>
                        <th style="text-align: center;">Net Payment Th</th>
                        <th style="text-align: center;">Net Payment </th>

                    </tr>
                </thead>

                <tbody>
                    @php
                        $m_y            = explode('-', $month);
                        $f_month        = isset($m_y[0]) ? $m_y[0] : '';
                        $f_year         = isset($m_y[1]) ? $m_y[1] : '';

                    @endphp
                    @foreach($emp as $row)
                        @php
                            $_emp_id_not    = App\Model\Hr\HrGenSalaryModel::where('emp_id', $row->id)
                                                            ->where('f_year', $f_year)
                                                            ->where('f_month', $f_month)
                                                            ->first();

                            $gen_attends    = App\Model\Hr\TimeAttendanceGenModel::where('emp_id', $row->id)
                                                            ->where('f_year', $f_year)
                                                            ->where('f_month', $f_month)
                                                            ->first();
                            //dd($_emp_id_not, $gen_attends);

                        @endphp
                        @if($_emp_id_not == null && $gen_attends != null)
                            <tr>
                                @php

                                    $f_date = explode('-', $from_date);
                                    $f_date = $f_date[2].'-'.$f_date[1].'-'.$f_date[0];
                                    $t_date = explode('-', $to_date);
                                    $t_date = $t_date[2].'-'.$t_date[1].'-'.$t_date[0];

                                    $gen_sal = App\Helpers\GenSalaryFp::getGenerateSalary($row->id, $f_date, $t_date, $row->basic_salary);
                                    $advance_salary     = $gen_sal != null ? (isset($gen_sal['advance_salary']) ? $gen_sal['advance_salary'] : 0) : 0;
                                    $basic_salary       = $gen_sal != null ? (isset($gen_sal['basic_salary']) ? $gen_sal['basic_salary'] : 0 ) : 0;
                                    $take_leave         = $gen_sal != null ? (isset($gen_sal['take_leave']) ? $gen_sal['take_leave'] : 0 ) : 0;
                                    $total_ot           = $gen_sal != null ? (isset($gen_sal['total_ot']) ? $gen_sal['total_ot'] : 0 ) : 0;
                                    $benefit            = $gen_sal != null ? (isset($gen_sal['benefit']) ? $gen_sal['benefit'] : 0 ) : 0;
                                    $khmer_rate         = $gen_sal != null ? (isset($gen_sal['khmer_rate']) ? $gen_sal['khmer_rate'] : 0 ) : 0;
                                    $thai_rate          = $gen_sal != null ? (isset($gen_sal['thai_rate']) ? $gen_sal['thai_rate'] : 0 ) : 0;
                                    $net_payment        = $gen_sal != null ? (isset($gen_sal['net_payment']) ? $gen_sal['net_payment'] : 0 ) : 0;
                                    $net_payment_kh     = $gen_sal != null ? (isset($gen_sal['net_payment_kh']) ? $gen_sal['net_payment_kh'] : 0 ) : 0;
                                    $net_payment_th     = $gen_sal != null ? (isset($gen_sal['net_payment_th']) ? $gen_sal['net_payment_th'] : 0 ) : 0;
                                    $working_sunday     = $gen_sal != null ? (isset($gen_sal['work_sun']) ? $gen_sal['work_sun'] : 0 ) : 0;

                                @endphp
                                <td>

                                    <input class="ch-em-id" name="emp_id_ch[{{$row->id}}]" type="checkbox"value="{{$row->id}}">
                                    <input type="hidden" name="basic_salary[{{$row->id}}]" value="{{$row->basic_salary}}">

                                    <input type="hidden" name="advance_salary[{{$row->id}}]" value="{{$advance_salary}}">
                                    <input type="hidden" name="take_leave[{{$row->id}}]" value="{{$take_leave}}">

                                    <input type="hidden" name="benefit[{{$row->id}}]" value="{{$benefit}}">
                                    <input type="hidden" name="total_ot[{{$row->id}}]" value="{{(int)$total_ot}}">
                                    <input type="hidden" name="work_sun[{{$row->id}}]" value="{{$working_sunday}}">

                                    <input type="hidden" name="exchange_rate_kh[{{$row->id}}]" value="{{$khmer_rate}}">
                                    <input type="hidden" name="exchange_rate_th[{{$row->id}}]" value="{{$thai_rate}}">

                                    <input type="hidden" name="net_pay_kh[{{$row->id}}]" value="{{$net_payment_kh}}">
                                    <input type="hidden" name="net_pay_th[{{$row->id}}]" value="{{$net_payment_th}}">
                                    <input type="hidden" name="net_pay[{{$row->id}}]" value="{{$net_payment}}">

                                </td>
                                <td style="text-align: center">{{$row->name}}</td>
                                <td style="text-align: center">{{$month}}</td>
                                <td style="text-align: center">$ {{number_format($row->basic_salary, 2)}}</td>
                                <td style="text-align: center">$ {{number_format((int)$total_ot, 2)}}</td>
                                <td style="text-align: center">$ {{number_format($working_sunday, 2)}}</td>
                                <td style="text-align: center">$ {{number_format($benefit, 2)}}</td>
                                <td style="text-align: center">$ {{number_format($advance_salary, 2)}}</td>
                                <td style="text-align: center">$ {{number_format($take_leave, 2)}}</td>
                                <td style="text-align: center">៛ {{number_format($khmer_rate, 2)}}</td>
                                <td style="text-align: center">฿ {{number_format($thai_rate, 2)}}</td>
                                <td style="text-align: center">៛ {{number_format($net_payment_kh, 2)}}</td>
                                <td style="text-align: center">฿ {{number_format($net_payment_th, 2)}}</td>
                                <td style="text-align: center">$ {{number_format($net_payment, 2)}}</td>
                            </tr>
                        @endif
                    @endforeach
                </tbody>
            </table>
        </div>
    </section>
</div>
@else
    <h1>No data to generate!!</h1>
@endif
