@extends('template.app')

@section('meta')
@endsection

@section('title')
    Expense Create
@endsection

@section('styles')
<style>
     .col-sm-3{
        font-size: 15px;
    }
    .form-control{
        height: 32px;
        font-size: 14px;
    }
    .custom-form-spacing {
      margin-bottom: -5px !important;
    }
</style>
@endsection

@section('content')
<div class="page-breadcrumb">
    <div class="row">
        <div class="col-7 align-self-center">
            <h4 class="page-title text-truncate text-dark font-weight-medium mb-1"></h4>
            <div class="d-flex align-items-center">
                <nav aria-label="breadcrumb">
                    <ol class="breadcrumb m-0 p-0">
                        <li class="breadcrumb-item"><a href="{{ route('dashboard') }}" class="text-muted">Dashboard</a></li>
                        <li class="breadcrumb-item"><a href="{{ route('fasttag') }}" class="text-muted">Expense Master</a></li>
                        <li class="breadcrumb-item text-muted active" aria-current="page">Create</li>
                    </ol>
                </nav>
            </div>
        </div>
    </div>
</div>
<div class="container-fluid">
    <div class="row">
        <div class="col-12">
            <div class="card">
                <div class="card-body">
                    <form action="{{ route('pettycash.insert') }}" name="form" id="form" method="post" enctype="multipart/form-data">
                        @csrf
                        @method('POST')

                        <div class="row">
                            <div class="form-group col-sm-3 custom-form-spacing">
                                <label for="to_branch">Expense Type</label>
                                <select class="form-control" name="expense_type_id" id="expense_type_id">
                                <option value="">Select Expense Type</option>
                                @if($expensetypes->count() > 0)
                                    @foreach($expensetypes as $expense)
                                <option value="{{$expense->id}}">{{ $expense->title }}</option>
                                @endforeach
                                @endif
                                </select>
                                <span class="kt-form__help error to_branch"></span>
                            </div>    
                             <div class="form-group col-sm-3 custom-form-spacing">
                                <label for="to_branch">Expense Department</label>
                                <select class="form-control" name="department_id" id="department_id">
                                <option value="">Select Department</option>
                                    @foreach($departments as $department)
                                <option value="{{$department->id}}">{{ $department->name }}</option>
                                @endforeach
                                </select>
                                <span class="kt-form__help error to_branch"></span>
                            </div>   
                            <div class="form-group col-sm-3 custom-form-spacing">
                                <label for="tag_id">Pay To</label>
                                <input type="text" name="pay_to" id="pay_to" class="form-control" placeholder="Enter Pay To">
                                <span class="kt-form__help error tag_id"></span>
                            </div>
                            <div class="form-group col-sm-3 custom-form-spacing">
                                <label for="amount">Amount</label>
                                <input type="number" name="amount" id="amount" class="form-control" placeholder="Enter Amount">
                                <span class="kt-form__help error amount"></span>
                            </div>
                             <div class="form-group col-sm-3">
                                <label for="amount">Description</label>
                                <textarea class="form-control" id="description" name ="description"></textarea>
                                <span class="kt-form__help error amount"></span>
                            </div>
                        </div>
                        <div class="form-group">
                            <button type="submit" class="btn waves-effect waves-light btn-sm btn-rounded btn-outline-primary">Submit</button>
                            <a href="{{ route('pettycash') }}" class="btn waves-effect btn-sm waves-light btn-rounded btn-outline-secondary">Back</a>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
@endsection

@section('scripts')
<script>
    $(document).ready(function() {
        var form = $('#form');
        $('.kt-form__help').html('');
        form.submit(function(e) {
            $('.help-block').html('');
            $('.m-form__help').html('');
            $.ajax({
                url: form.attr('action'),
                type: form.attr('method'),
                data: new FormData($(this)[0]),
                dataType: 'json',
                async: false,
                processData: false,
                contentType: false,
                success: function(json) {
                    return true;
                },
                error: function(json) {
                    if (json.status === 422) {
                        e.preventDefault();
                        var errors_ = json.responseJSON;
                        $('.kt-form__help').html('');
                        $.each(errors_.errors, function(key, value) {
                            $('.' + key).html(value);
                        });
                    }
                }
            });
        });
    });
</script>
@endsection