@extends('layouts.masterHome2')

@section('content')

@if (session()->has('message'))
<div class="row">
        <!-- left column -->
        <div class="col-md-2"></div>
        @php
        $type= session('type') ;
        @endphp
        <div class="col-md-4 alert alert-{{$type}} alert-dismissible" style="font-size:18px;font-weight:bold;width:400px;margin-left:15px">
                <button type="button" class="close" data-dismiss="alert" aria-hidden="true">&times;</button>
                {!! session('message') !!}
        </div>
</div> 
@endif

<div class="row" style="padding:10px">
<div class="col-md-1" style="margin-left:18px"></div>
<div class="col-md-6" style="margin-left:18px">
      <div class="card card-info">
          <div class="card-header">
            <h3 class="card-title">أضافة سند صرف عام  </h3>
          </div>
          <!-- /.card-header -->
          <!-- form start -->
          <form  role="form" method="POST" action="{{ url('/payment_voucher/general_create') }}">
                        {{ csrf_field() }}
          <div class="box-body">
            <div class="card-body">

             

                <div class="form-group">
                  <label for="exampleInputPassword1">  يصرف الي   </label>
                  <input type="text"  id="general_name" name="general_name" class="form-control"  placeholder="  يصرف الي    ">
                </div>

                <div class="form-group">
                  <label for="exampleInputPassword1">المبلغ  </label>
                  <input type="number" min="0" id="pay" name="pay" class="form-control"  placeholder=" المبلغ" required>
                </div>


                <div class="form-group">
                <label> طرق الدفع</label>
                <select class="form-control select2 select2-hidden-accessible"   style="width: 100%;text-align:right" name="safe_account_id" id="account_type"  onchange="check_function(this)" required>
                    
                   @foreach( $accounts as $account ) 
                    <option value="{{ $account->id }}"  >{{$account->payment_method->name}} </option>
                    @endforeach
                     
                </select>
                 </div>

               <div id="div_hidden" style="display: none">
                <div class="form-group">
                  <label for="exampleInputPassword1">رقم السريال  </label>
                  <input type="text"  id="serial_" name="serial_" class="form-control"  placeholder=" رقم السريال   " >
                </div>

                <div class="form-group">
                  <label for="exampleInputPassword1">علي بنك   </label>
                  <select class="form-control select2 select2-hidden-accessible"   style="width: 100%;text-align:right" name="bank_id" id="bank_id" >
                    @foreach( $banks as $bank ) 
                    <option value="{{ $bank->id }}"  >{{$bank->name}} </option>
                    @endforeach
                </select>
                </div>

                <div class="form-group">
                  <label for="exampleInputPassword1">   تاريخ الاستحقاق او الايداع  </label>
                  <input type="date"  id="date_" name="date_" class="form-control"  placeholder=" تاريخ الاستحقاق   " >
                </div>

                

              </div>
                <div class="form-group">
                  <label for="exampleInputPassword1">  نظير   </label>
                  <input type="text"  id="note1" name="note1" class="form-control"  placeholder=" نظير   " >
                </div>

                <div class="form-group">
                  <label for="exampleInputPassword1">  ملاحظات   </label>
                  <input type="text"  id="note2" name="note2" class="form-control"  placeholder=" ملاحظات   ">
                </div>


                <input type="hidden"  value="" id="cheque_or_deposite" name="cheque_or_deposite" class="form-control"  placeholder=" cheque or deposite " >



                <div class="card-footer">
                  <button type="submit" class="btn btn-info">Add </button>
                </div>  

              </div>
          </div>


          </form>
      </div>


    </div>
  </div>



<script>

function check_function (sel){


let account_type = sel.options[sel.selectedIndex].text;

let div_hidden = document.getElementById('div_hidden');

if( account_type == "شيك"){
  div_hidden.style.display = "block";
  document.getElementById('cheque_or_deposite').value="cheque"; 
  console.log("cheque");

}else if( account_type == "ايداع بنكي") {
  div_hidden.style.display = "block";
  document.getElementById('cheque_or_deposite').value="deposite"; 
}else {
  div_hidden.style.display = "none";
  document.getElementById('cheque_or_deposite').value="";
}

}

</script>


@endsection