@extends('layouts.master')

@section('content')
<section class="content">
     <div class="row">
     <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">New Journal</h3>
            </div>
            <div class="panel-body">
                @include('layouts.message')
                <form action="{{ url('account/journal/save') }}" method="POST" class="form-horizontal" role="form" enctype="multipart/form-data">
                        {{ csrf_field() }}
                    <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                            <div class="form-group">
                                <label for="account_head" class="col-sm-12 col-xs-12 col-md-4 col-lg-4 control-label">Debit Head</label>
                                
                                <div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
                                    <select name="account_head" id="account_head" class="form-control">
                                        <option value="">-Select Account Head-</option>
                                        @if($account_types)
                                        @foreach($account_types as $type)
                                            <optgroup label="{{ $type->name }}">
                                            @if($type->acc_head)
                                            @foreach($type->acc_head as $head)
                                            <option value="{{ $head->id }}">{{ $head->name }}</option>
                                                @if($head->children)
                                                @foreach($head->children as $child)
                                                    <option value="{{ $child->id }}">&nbsp;&nbsp;&nbsp;{{ $child->name }}</option>
                                                @endforeach
                                                @endif
                                            @endforeach
                                            @endif
                                            </optgroup>
                                        @endforeach
                                        @endif
                                    </select>
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="amount" class="col-sm-12 col-xs-12 col-md-4 col-lg-4 control-label">Amount</label>
                                
                                <div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
                                    <input type="text" name="amount" id="amount" class="form-control" onkeypress="return checkNumber(event)" required placeholder="Amount"> 
                                </div>
                            </div>
                            <div class="form-group">
                                <label for="description" class="col-sm-12 col-xs-12 col-md-4 col-lg-4 control-label">Description</label>
                                
                                <div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
                                    <textarea name="description" id="description" class="form-control" placeholder="Description"></textarea>
                                </div>
                            </div>
                            <!--    <div class="form-group">
                                <label for="due_date" class="col-sm-12 col-xs-12 col-md-2 col-lg-2 control-label">Due Date</label>
                                                        
                                                        <div class="col-xs-12 col-sm-12 col-md-5 col-lg-5">
                                                            <input type="text" name="due_date" id="due_date" class="form-control date" required placeholder="Due Date"> 
                                                        </div>
                            </div> -->
                            <div class="form-group">
                                <div class="col-sm-8 col-sm-offset-4">
                                    <button type="submit" class="btn btn-primary"><i class="fa fa-save"></i> Save</button>

                                    <a href="{{ url('account/journal') }}" class="btn btn-default"><i class="fa fa-times"></i> Cancel</a>
                                </div>
                            </div>
                    </div>

                    <div class="col-xs-6 col-sm-6 col-md-6 col-lg-6">
                            <div class="form-group">
                                <label for="credit_head" class="col-sm-12 col-xs-12 col-md-4 col-lg-4 control-label">Credit Head</label>
                                
                                <div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
                                    <select name="credit_head" id="credit_head" class="form-control">
                                        <option value="">-Select Credit Head-</option>
                                        @if($account_types)
                                        @foreach($account_types as $type)
                                            <optgroup label="{{ $type->name }}">
                                            @if($type->acc_head)
                                            @foreach($type->acc_head as $head)
                                            <option value="{{ $head->id }}">{{ $head->name }}</option>
                                                @if($head->children)
                                                @foreach($head->children as $child)
                                                    <option value="{{ $child->id }}">&nbsp;&nbsp;&nbsp;{{ $child->name }}</option>
                                                @endforeach
                                                @endif
                                            @endforeach
                                            @endif
                                            </optgroup>
                                        @endforeach
                                        @endif
                                    </select>
                                </div>
                            </div>

                            <div class="form-group">
                                <label for="date" class="col-sm-12 col-xs-12 col-md-4 col-lg-4 control-label">Date</label>
                            
                                <div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
                                    <input type="text" name="date" id="date" class='form-control date' value="{{ date('Y-m-d') }}">
                                </div>
                            </div>

                            <div class="form-group">
                                <label for="date" class="col-sm-12 col-xs-12 col-md-4 col-lg-4 control-label">Upload document</label>
                            
                                <div class="col-xs-12 col-sm-12 col-md-8 col-lg-8">
                                    <input type="file" name="filedocument" id="">
                                </div>
                            </div>
                    </div>
                    
                </form>
            </div>
        </div>
     </div>
     </div>
</section>
@stop

@section('script')
<script type="text/javascript">
$(document).ready(function() {
     $( ".date" ).datepicker({
          changeMonth: true,
          changeYear: true,
          dateFormat:"yy-mm-dd"
     });

     /**
      * get account head by account type
      */
     // $('#account_type').change(function(){
     //     var id=$(this).val();

     //     $.ajax({
     //         url: "{{ url('account/journal/get_head') }}/"+id,
     //         type: 'GET'
     //     })
     //     .done(function(res) {
     //         $('#account_head').html(res);
     //     });
     // }); //end get account head by account type
});

function checkNumber(evt)
{
    var charCode = (evt.which) ? evt.which : evt.keyCode;
    if (charCode != 46 && charCode > 31 
      && (charCode < 48 || charCode > 57))
    {
        alert('Invalid amount  !!');
       return false;
    }

    return true;
}
</script>
@stop