@extends('client.layouts.app')
@section('title','تعديل موظف')
@section('content')
  <!-- BEGIN: Content-->
  <div class="app-content content ">
    <div class="content-overlay"></div>
    <div class="header-navbar-shadow"></div>
    <div class="content-wrapper container-xxl p-0">
      <div class="content-header row">
        <div class="content-header-left col-md-9 col-12 mb-2">
          <div class="row breadcrumbs-top">
            <div class="col-12">
              <h2 class="content-header-title float-start mb-0">تعديل موظف</h2>
              <div class="breadcrumb-wrapper">
                <ol class="breadcrumb">
                  <li class="breadcrumb-item"><a href="{{route('client.home')}}">لوحة التحكم</a>
                  </li>
                  <li class="breadcrumb-item"><a href="{{route('client.employees.index')}}">الموظفين</a>
                  </li>
                  <li class="breadcrumb-item active">{{$employee->name}}
                  </li>
                  <li class="breadcrumb-item active">تعديل
                  </li>
                </ol>
              </div>
            </div>
          </div>
        </div>
        <div class="content-header-right text-md-end col-md-3 col-12 col-12 d-md-block d-none">
          <div class="mb-1 breadcrumb-right">
            <div class="dropdown">
                <a  href="{{ route('client.employees.index') }}">
                    <button class="btn-icon btn btn-primary" type="button"><i data-feather='eye'> </i></button>
                </a>
            </div>
          </div>
        </div>
      </div>
      <div class="content-body">
        <!-- Basic Horizontal form layout section start -->
        <!-- Basic multiple Column Form section start -->
<section id="multiple-column-form">
<div class="row">
  <div class="col-12">
    <div class="card">
      <div class="card-header">
        <h4 class="card-title">البيانات الاساسية</h4>
      </div>
      <div class="card-body">
        <form class="parsley-style-1" id="addForm" method="post">
      @csrf
      <input type="hidden" name="company_id" value="{{$company_id}}">
      <input type="hidden" name="id" value="{{$employee->id}}">

      <div class="row">
          <div class="col-md-3 col-12">
            <div class="mb-1">
              <b class="form-label"> اسم الموظف </b>
              <input   class="form-control"  name="name" type="text" placeholder="اسم الموظف" value="{{$employee->name}}">
            </div>
          </div>
          <div class="col-md-3 col-12">
            <div class="mb-1">
              <b class="form-label" for="balance">رصيد البداية :  </b>
              <input  type="radio" value="for" name="balance_type" @if($employee->balance > 0) checked @endif  /> له
              <input   type="radio" value="on" name="balance_type"@if($employee->balance <= 0) checked @endif /> عليه
              <input  type="text"  name="balance_start" class="form-control" placeholder="رصيد البداية للموظف"  value="{{abs($employee->balance)}}">
               </div>
          </div>

          <div class="col-md-3 col-12">
            <div class="mb-1">
              <b class="form-label"> تاريخ الميلاد </b>
              <input class="form-control"  name="birth_date" type="date" value="{{$employee->birth_date}}">
            </div>
          </div>
          <div class="col-md-3 col-12">
            <div class="mb-1">
              <b class="form-label">  الوظيفة </b>
              <input  class="form-control" name="job" type="text" placeholder="أدخل الوظيفة" value="{{$employee->job}}">
            </div>
          </div>
          <div class="col-md-3 col-12">
            <div class="mb-1">
              <b class="form-label">  رقم الضمان الإجتماعي</b>
              <input  class="form-control" name="civil_registry" type="text"placeholder="رقم الضمان الإجتماعي" value="{{$employee->civil_registry}}">
            </div>
          </div>
          <div class="col-md-3 col-12">
            <div class="mb-1">
              <b class="form-label"> العنوان </b>
              <input  class="form-control" name="address" type="text" placeholder="عنوان الموظف" value="{{$employee->address}}">
            </div>
          </div>
          <div class="col-md-3 col-12">
            <div class="mb-1">
              <b class="form-label"> الهاتف </b>
              <input class="form-control"  name="phone_number" type="text" placeholder="رقم هاتف الموظف"value="{{$employee->phone_number}}">
            </div>
          </div>
          <div class="col-md-3 col-12">
            <div class="mb-1">
              <b class="form-label"> الراتب </b>
              <input   class="form-control" name="salary" type="number" step="any" placeholder="راتب الموظف" value="{{$employee->salary}}">
            </div>
          </div>

          <div class="col-md-3 col-12">
            <div class="mb-1">
              <b  class="d-block"> حالة العمل </b>
              <input type="radio" @if($employee->work_status == "working") checked @endif name="work_status" value="working" /> يعمل
              <br>
              <input type="radio" @if($employee->work_status == "quit") checked @endif name="work_status" value="quit" /> قدم استقالته
            </div>
          </div>
      </div>
      <div class="col-12" align="center">
        <br>
          <button type="submit" class="btn btn-success me-1">تعديل</button>
          <button type="button" class="btn btn-outline-danger" onclick="window.history.back()">رجوع</button>
        </div>
      </div>
  </form>
      </div>
    </div>
  </div>
</div>
</section>
<!-- Basic Floating Label Form section end -->

      </div>
    </div>
  </div>
  <!-- END: Content-->
@endsection

@section('script')

    <script>
   
   
        var selectForm = $('#addForm');

if (selectForm) {
    selectForm.validate({

        rules: {
            
    'name': {
        required: true,
      },
      'salary': {
        required: true,
      }
    
    }
  });
}

$("#addForm").on('submit',(function(e) {

e.preventDefault();

$.ajax({

  url: "{{route('client.employees.update')}}",

  type: "POST",

  data:  new FormData(this),

  dataType:  'json',

  contentType: false,

  cache: false,

  processData:false,
  
  beforeSend : function (){var ifConnected = window.navigator.onLine;if (!ifConnected) {toastr.info("يتم الآن إعادة الإتصال","لا يوجد إتصال بالإنترنت",{positionClass: "toast-top-right",tapToDismiss: !1,timeOut: 2e3,rtl: $("html").attr("data-textdirection")});}},

  success: function(response) {

    if(response.status){

            toastr.success("",response.message,{
			positionClass: "toast-top-right",
			tapToDismiss: !1,
			timeOut: 2e3,
			rtl: $("html").attr("data-textdirection")
		    });      

    } 

  },
  error: function(response){
          $.each(response.responseJSON.errors, function (key, item) 
          {
            toastr.error("",item,{
			positionClass: "toast-top-right",
			tapToDismiss: !1,
			timeOut: 2e3,
			rtl: $("html").attr("data-textdirection")
		    });

          });
  },

 });

}));

        </script>
@endsection
