@extends('layouts.master')

@section('content')
<div class="content">
    <div class="row">
        <form action="{{ url('admin/employee/update/'.$employee->id) }}" enctype="multipart/form-data" method="POST" role="form">
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <header class="panel-heading" style="height:50px;">
                <div class="pull-left">
                    {{$title}}
                </div>
                <div>
                     @if(\Auth::user()->utype==1)
                        <a style="margin-right:3px" href="{{ url('admin/employee') }}" class="btn btn-sm btn-info pull-right"><i class="fa fa-list"></i> Employee List</a>
                         <a style="margin-right:3px"  href="{{ url('admin/employee/add') }}" class="btn btn-sm btn-info pull-right"><i class="fa fa-plus"></i> Employee Add</a> <br><br>
                    @endif
                </div>
            </header>
        </div>
        <div class="col-xs-5 col-sm-5 col-md-5 col-lg-5">
            <div class="panel panel-default">
                <div class="panel-heading" style="height:50px;">
                    <h3 class="panel-title">Employee Information</h3>
                </div>
                <div class="panel-body">
                    {{ csrf_field() }}
                    <div class="form-group {{ $errors->has('name') ? 'has-error' : '' }}">
                        <label for="name">Full Name <i class="text-danger">*</i></label>
                        <input type='text' name="name" id="name" class="form-control" placeholder="Full Name" value="{{$employee->name }}" required="">
                        <lebel class="text-danger"> {{ $errors->first('name') }}</lebel>
                    </div>
                    <div class="form-group {{ $errors->has('personal_email') ? 'has-error' : '' }}">
                        <label for="personal_email">personal Email <i class="text-danger">*</i></label>
                        <input type='email' name="personal_email" id="personal_email" class="form-control" value="{{ $employee->personal_email }}" required="" placeholder="Personal Email">
                        <lebel class="text-danger"> {{ $errors->first('personal_email') }}</lebel>
                    </div>
                    <div class="form-group {{ $errors->has('phone') ? 'has-error' : '' }}">
                        <label for="phone">Phone <i class="text-danger">*</i></label>
                        <input type='text' name="phone" id="phone" class="form-control" required="" placeholder="Phone Number" value="{{ $employee->phone }}">
                        <lebel class="text-danger"> {{ $errors->first('phone') }}</lebel>
                    </div>
                    <div class="form-group">
                        <label for="phonetwo">Phone2</label>
                        <input type='text' name="phonetwo" value="{{ $employee->phonetwo }}" id="phonetwo" class="form-control"   placeholder="Phone Number">
                    </div>
                    <div class="form-group {{ $errors->has('birth_day') ? 'has-error' : '' }}">
                        <label for="birth_day">Date of birth <i class="text-danger">*</i></label>
                        <input type='text' name="birth_day" id="birth_day" class="form-control date" placeholder="Date of birth" value="{{ $employee->birth_day }}" required="" >
                        <lebel class="text-danger"> {{ $errors->first('birth_day') }}</lebel>
                    </div>
                    <div class="form-group {{ $errors->has('present_address') ? 'has-error' : '' }}">
                        <label for="present_address">Present Address <i class="text-danger">*</i></label>
                        <input type='text' name="present_address" id="present_address" class="form-control" placeholder="Present Address" value="{{ $employee->present_address }}" required="">
                        <lebel class="text-danger"> {{ $errors->first('present_address') }}</lebel>
                    </div>
                    <div class="form-group">
                        <label for="per_address">Permanent Address</label>
                        <input type='text' name="per_address" id="per_address" class="form-control" placeholder="Permanent Address" value="{{ $employee->per_address }}">
                    </div>
                    <div class="form-group">
                        <label for="note">Note</label>
                        <textarea name="note" id="note" class="form-control" placeholder="Note">{{ $employee->note }}</textarea>
                    </div>
                    <div class="form-group">
                        <label for="facebook">Facebook</label>
                        <input type='text' name="facebook" id="facebook" class="form-control" placeholder="Facebook" value="{{ $employee->facebook }}">
                    </div>
                    <div class="form-group">
                        <label for="skype">Skype</label>
                        <input type='text' name="skype" id="skype" class="form-control" placeholder="Skype" value="{{ $employee->skype }}">
                    </div>
                    <div class="form-group">
                        <label for="linkedin">Linkedin</label>
                        <input type='text' name="linkedin" id="linkedin" class="form-control" placeholder="Linkedin" value="{{ $employee->linkedin }}">
                    </div>
                    <div class="form-group">
                        <label for="linkedin">Picture</label>
                        <input type='file' name="image" class='form-control'>
                    </div>
                    <div>
                        <img src="{{ asset('/assets/document/employee/'.$employee->image) }}" alt="Pic" height="95" width="120">
                    </div>

                    <div class="clearfix"></div>
                    

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

        <div class="col-xs-7 col-sm-7 col-md-7 col-lg-7">
            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading" style="height:50px;">
                        <div class="pull-left">
                        <h3 class="panel-title">Employment History: <small>Please Add Recent First</small></h3>
                        </div>
                        
                        
                    </div>
                    <div class="panel-body">
                        <table class="table table-bordered tbl-items">
                            <thead>
                                <tr>
                                    <th>#</th>
                                    <th>date</th>
                                    <th>Designation</th>
                                    <th>Salary Grade</th>
                                    <th>Action</th>
                                </tr>
                            </thead>
                            <tbody class="ehbody">
                                <?php $i=1;?>
                                @foreach($emp_details as $emp_history)
                                <tr>
                                    <input type='text' name="emp_we_id[]" class="hidden" value="{{ $emp_history->id }}">

                                    <td>{{ $i++ }}</td>
                                    <td><input type='text' name="joining_date[]" class="form-control date" placeholder="Date" value="{{ $emp_history->joining_date }}" required="" ></td>
                                    <td width="30%">
                                        <select name="current_designation[]" class='form-control' id="current_designation" required="" >
                                            <option disabled selected value>Choose One..</option>
                                            @foreach($all_designation as $info)
                                            <option value="{{ $info->id }}" @if($emp_history->designation_id==$info->id) {{'selected'}} @endif>{{ $info->name }}</option>
                                            @endforeach
                                        </select>
                                    </td> 
                                    <td width="30%">
                                        <select name="salary_grade[]" class='form-control' id="salary_grade" required="" >
                                            <option disabled selected value>Choose One..</option>
                                            @foreach($all_grade as $row)
                                            <option value="{{ $row->id }}" @if($emp_history->grade_id==$row->id) {{'selected'}} @endif >{{ $row->name }}</option>
                                            @endforeach
                                        </select>
                                    </td>
                                    <td></td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                        <button type='button' id='add_exp_history' class='btn btn-sm' title='Add New Item'><i class="fa fa-plus"></i> Add Promotion</button>

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

            <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
                <div class="panel panel-default">
                    <div class="panel-heading">
                        <h3 class="panel-title">File Upload</h3>
                    </div>
                    <div class="panel-body">
                    
                        <table class="table table-bordered tbl-items">
                            <thead>
                                <tr>
                                    <th>#</th>
                                    <th width="35%">Document Type</th>
                                    <th>File</th>
                                    <th>Action</th>
                                </tr>
                            </thead>
                            <tbody class="filebody">
                                <?php $i=1;?>
                                @foreach($employee_document as $emp_doc)
                                <tr>

                                    <input type='text' name="emp_doc_id[]" class="hidden" value="{{ $emp_doc->id }}">

                                    <td>{{ $i++ }}</td>
                                    <td>
                                        <select name="document_id[]" class='form-control'>
                                            <option disabled selected value>Choose One..</option>
                                            @foreach($all_document as $info)
                                            <option value="{{$info->id}}" @if($info->id == $emp_doc->document_id){{ 'selected' }}@endif>{{$info->document_name}}</option>
                                            @endforeach
                                        </select>
                                    </td>
                                    <td>
                                        <input type='file' name="file[]" class='form-control'>
                                        <small style="margin-top:3px;font-size: 10px;"> {{ @$emp_doc->file}}</small>
                                    </td>
                                    <td></td>
                                </tr>
                                @endforeach
                            </tbody>
                        </table>
                        <button type='button' id='add_file' class='btn btn-sm' title='Add New Item'><i class="fa fa-plus"></i> Add more item</button>
                    </div>
                </div>
            </div>
        </div>
        
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">Academic Information</h3>
                </div>
                <div class="panel-body">
                    <table class="table table-bordered tbl-items">
                        <thead>
                            <tr>
                                <th>#</th>
                                <th width="17%">Education Level</th>
                                <th width="23%">Institute</th>
                                <th>Major/Group</th>
                                <th>Marks/CGPA</th>
                                <th>Passing Year</th>
                                <th>Duration</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody class="resultbody">
                            <?php $i=1;?>
                            @foreach($employee_education as $emp_edu)
                            <tr>
                                <input type='text' name="emp_edu_id[]" class="hidden" value="{{ $emp_edu->id }}">
                                 <td>{{ $i++ }}</td>
                                <td>
                                    <select name="edu_level[]" id="edu_level" class='form-control' >
                                        <option disabled selected value>Choose One..</option>
                                        @foreach($all_level as $info)
                                        <option value="{{$info->id}}" @if($info->id == $emp_edu->edu_level_id){{ 'selected' }}@endif>{{$info->level_name}}</option>
                                        @endforeach
                                    </select>
                                </td>
                                <td>
                                    <input type='text' name="institute[]" class='form-control' placeholder="Institute" value="{{ $emp_edu->institute_name }}">
                                </td>
                                <td>
                                    <input type='text' name="major[]" class='form-control' placeholder="Major" value="{{ $emp_edu->major }}">
                                </td>
                                <td>
                                    <input type='text' name="marks[]" class='form-control' placeholder="Marks" value="{{ $emp_edu->marks }}">
                                </td>
                                <td>
                                    <input type='text' name="passing_year[]" class='form-control' placeholder="Passing Year" value="{{ $emp_edu->passing_year }}">
                                </td>
                                <td>
                                    <input type='text' name="duration[]" class='form-control' placeholder="Duration" value="{{ $emp_edu->duration }}">
                                </td>
                                <td> </td>
                            </tr>
                            @endforeach
                        </tbody>
                    </table>
                    <button type='button' id='add_item' class='btn btn-sm' title='Add New Item'><i class="fa fa-plus"></i> Add more item</button>
                </div>
            </div>
        </div>
        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">Work Experience</h3>
                </div>
                <div class="panel-body">
                    <table class="table table-bordered tbl-items">
                        <thead>
                            <tr>
                                <th>#</th>
                                <th>Org Name</th>
                                <th>Org Contact</th>
                                <th>Designation</th>
                                <th>Start Date</th>
                                <th>End Date</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody class="expbody">
                            <?php $i=1;?>
                            @foreach($employee_ewe as $all_des)
                            <tr>
                                 <input type='text' name="emp_exp_id[]" class="hidden" value="{{ $all_des->id }}">
                                 <td>{{ $i++ }}</td>
                                <td>
                                    <input type='text' name="org_name[]" class='form-control' value="{{ $all_des->org_name }}" placeholder="Name">
                                </td>
                                <td>
                                    <input type='text' name="org_contact[]" class='form-control' value="{{ $all_des->org_contact }}" placeholder="Contact">
                                </td>
                                <td>
                                    <select name="designation[]" class='form-control' >
                                        <option disabled selected value>Choose One..</option>
                                        @foreach($all_designation as $data)
                                        <option value="{{ $data->id }}" @if($all_des->designation_id == $data->id) {{"selected"}} @endif>{{ $data->name }}</option>
                                        @endforeach
                                    </select>
                                </td>
                                <td>
                                    <input type='text' name="start_date[]" class='form-control date' value="{{ $all_des->start_date }}" placeholder=" Date">
                                </td>
                                <td>
                                    <input type='text' name="end_date[]" class='form-control date' value="{{ $all_des->end_date }}" placeholder=" date">
                                </td>
                                <td> </td>
                            </tr>
                            @endforeach
                        </tbody>
                    </table>
                    <button type='button' id='add_exp' class='btn btn-sm' title='Add New Item'><i class="fa fa-plus"></i> Add more item</button>
                </div>
            </div>
        </div>

        <div class="col-xs-12 col-sm-12 col-md-12 col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h3 class="panel-title">Reference / Emergence Contact</h3>
                </div>
                <div class="panel-body">
                    <table class="table table-bordered tbl-items">
                        <thead>
                            <tr>
                                <th>#</th>
                                <th>Person Name</th>
                                <th>Relation</th>
                                <th>Phone 1</th>
                                <th>Phone 2</th>
                                <th>Email</th>
                                <th width="17%">Address</th>
                                <th>Action</th>
                            </tr>
                        </thead>
                        <tbody class="refbody">
                            <?php $i=1;?>
                            @if(!empty($employee_ref))
                            @foreach($employee_ref as $emp_ref)
                            <tr>
                                <input type='text' name="emp_ref_id[]" class="hidden" value="{{ $emp_ref->id }}">
                                 <td>{{ $i++ }}</td>
                                <td>
                                    <input type='text' name="person_name[]" class='form-control' placeholder="Name" value="{{ $emp_ref->person_name }}">
                                </td>
                                <td>
                                    <input type='text' name="relation[]" class='form-control' placeholder="Relation" value="{{ $emp_ref->relation }}">
                                </td>
                                <td>
                                    <input type='text' name="phone1[]" class='form-control' placeholder="Phone 1" value="{{ $emp_ref->phone1 }}">
                                </td>
                                <td>
                                    <input type='text' name="phone2[]" class='form-control' placeholder="Phone 2" value="{{ $emp_ref->phone2 }}">
                                </td>
                                <td>
                                    <input type='text' name="email[]" class='form-control' placeholder="Email" value="{{ $emp_ref->email }}">
                                </td>
                                <td>
                                    <input type='text' name="address[]" class='form-control' placeholder="Address" value="{{ $emp_ref->address }}">
                                </td>
                                <td> </td>
                            </tr>
                            @endforeach
                            @endif
                        </tbody>
                    </table>
                    <button type='button' id='add_ref_item' class='btn btn-sm' title='Add New Item'><i class="fa fa-plus"></i> Add more item</button>
                </div>
                <div class="panel-footer pull-right">
                    <button type="submit" class="btn btn-primary"><i class="fa fa-save"></i> Update data</button>
                    <a href="{{ url('admin/employee') }}" class="btn btn-default">
                    <i class="fa fa-times"></i> Cancel</a>
                </div>
            </div>
        </div>

        </form>
    </div>
</div>
@stop


@section('script')
<script type="text/javascript">
    $(function () {
        $('#add_item').click(function () {
            var n = ($('.resultbody tr').length - 0) + 1;
            var tr = '<tr><td class="no">' + n + '</td>' +
                    '<td class=hidden><input type="text" name="new_edu_id" value="use_for_new_item"></td>'+
                    '<td><select name="edu_level_new[]" class="form-control" required=""><option disabled selected value>Choose One..</option>@foreach($all_level as $info)<option value="{{ $info->id}}">{{ $info->level_name }}</option>@endforeach</select></td>'+
                    '<td><input type="text" class="institute form-control" required="" name="institute_new[]" placeholder="Institute" ></td>'+
                    '<td><input type="text" class="major form-control" required="" name="major_new[]" placeholder="Major" ></td>'+
                    '<td><input type="text" class="marks form-control" required="" name="marks_new[]" placeholder="Marks"></td>'+
                    '<td><input type="text" class="passing_year form-control" required="" name="passing_year_new[]" placeholder="Passing Year"></td>'+
                    '<td><input type="text" class="duration form-control" name="duration_new[]" placeholder="Duration"></td>'+
                    '<td><input id="delete_item" type="button" class="btn btn-danger" value="x"></td>';

            $('.resultbody').append(tr);
        });
        $('.resultbody').delegate('#delete_item', 'click', function () {
            $(this).parent().parent().remove();
        });
    });
</script>
<script type="text/javascript">
    $(function () {
        $('#add_exp').click(function () {
            var n = ($('.expbody tr').length - 0) + 1;
            var tr = '<tr><td class="no">' + n + '</td>' +
                    '<td class=hidden><input type="hidden" name="new_exp_id" value="use_for_new_item"></td>'+
                    '<td><input type="text" class="org_name form-control" required=""  name="org_name_new[]" placeholder="Name" ></td>'+
                    '<td><input type="text" class="org_contact form-control" required=""  name="org_contact_new[]" placeholder="Contact" ></td>'+
                    '<td><select name="designation_new[]" class="form-control" required="" ><option disabled selected value>Choose One..</option>@foreach($all_designation as $info)<option value="{{ $info->id}}">{{ $info->name }}</option>@endforeach</select></td>'+                    
                    '<td><input type="date" class="start_date form-control date" required=""  name="start_date_new[]"  placeholder="Start Date"></td>'+
                    '<td><input type="date" class="end_date form-control date" required=""  name="end_date_new[]" placeholder="End Date"></td>'+
                    '<td><input id="delete_exp" type="button" class="btn btn-danger" value="x"></td>';

            $('.expbody').append(tr);
        });
        $('.expbody').delegate('#delete_exp', 'click', function () {
            $(this).parent().parent().remove();
        });
    });
</script>
<script type="text/javascript">
    $(function () {
        $('#add_ref_item').click(function () {
            var n = ($('.refbody tr').length - 0) + 1;
            var tr = '<tr><td class="no">' + n + '</td>' +
                    '<td class=hidden><input type="text" name="new_ref_id" value="use_for_new_item"></td>'+
                    '<td><input type="text" class="person_name form-control" required=""  name="person_name_new[]" placeholder="Name" ></td>'+
                    '<td><input type="text" class="relation form-control" required=""  name="relation_new[]" placeholder="Relation" ></td>'+
                    '<td><input type="text" class="phone1 form-control" required=""  name="phone1_new[]" placeholder="Phone 1" ></td>'+
                    '<td><input type="text" class="phone2 form-control" required=""  name="phone2_new[]"  placeholder="Phone 2"></td>'+
                    '<td><input type="email" class="email form-control" required=""  name="email_new[]" placeholder="Email Address"></td>'+
                    '<td><input type="text" class="address form-control" name="address_new[]" placeholder="Address"></td>'+
                    '<td><input id="delete_ref" type="button" class="btn btn-danger" value="x"></td>';

            $('.refbody').append(tr);
        });
        $('.refbody').delegate('#delete_ref', 'click', function () {
            $(this).parent().parent().remove();
        });
    });
</script>
<script type="text/javascript">
    $(function () {
        $('#add_exp_history').click(function () {
            var n = ($('.ehbody tr').length - 0) + 1;
            var tr = '<tr><td class="no">' + n + '</td>' +
                    '<td class=hidden><input type="hidden" name="new_emp_we_id" value="use_for_new_item"></td>'+
                    '<td><input type="date" name="joining_date_new[]" id="joining_date" class="form-control date" placeholder="Date" required="" ></td>'+
                    '<td><select name="current_designation_new[]" class="form-control" required=""><option disabled selected value> Choose One..</option>@foreach($all_designation as $info)<option value="{{ $info->id}}">{{ $info->name }}</option>@endforeach</select></td>'+
                    '<td><select name="salary_grade_new[]" class="form-control" required=""><option disabled selected value> Choose One..</option>@foreach($all_grade as $info)<option value="{{ $info->id}}">{{ $info->name }}</option>@endforeach</select></td>'+
                    '<td><input id="delete_item" type="button" class="btn btn-danger" value="x"></td>';

            $('.ehbody').append(tr);
            
            $('#add_exp_history').hide();
            
        });
        $('.ehbody').delegate('#delete_item', 'click', function () {
            $(this).parent().parent().remove();
            $('#add_exp_history').show();
        });
    });
</script>
<script type="text/javascript">
    $(function () {
        $('#add_file').click(function () {
            var n = ($('.filebody tr').length - 0) + 1;
            var tr = '<tr><td class="no">' + n + '</td>' +
                    '<td class=hidden><input type="text" name="new_doc_id" value="use_for_new_item"></td>'+
                    '<td><select name="document_id_new[]" class="form-control" required=""><option disabled selected value> Choose One..</option>@foreach($all_document as $info)<option value="{{ $info->id}}">{{ $info->document_name }}</option>@endforeach</select></td>'+
                    '<td><input type="file" name="file_new[]" class="form-control" required=""></td>'+
                    '<td><input id="delete_item" type="button" class="btn btn-danger" value="x"></td>';

            $('.filebody').append(tr);
        });
        $('.filebody').delegate('#delete_item', 'click', function () {
            $(this).parent().parent().remove();
        });
    });
</script>
<script type="text/javascript">
$(document).ready(function() {
     $( ".date" ).datepicker({
          changeMonth: true,
          changeYear: true,
          yearRange: "c-100:c+10", 
          dateFormat:"yy-mm-dd"
     });
});
</script>
@stop