
@extends('layouts.nav')
@section('title')
Process Cash Book
@endsection
@section('content')
<div class="d-sm-flex align-items-center justify-content-between mb-4">
                        <h1 class="h3 mb-0 text-gray-800">Process Cash Book</h1>

                      </div>

                    <div class="card shadow mb-4">

                        <div class="card-header py-3 d-flex justify-content-between align-items-center">
                            <h6 class="m-0 font-weight-bold text-primary" id="formHeader">Process Cash Book</h6>

                        </div>
                        @if (session('success'))
                            <div class="alert alert-success" id="successMessage"  style="margin: 20px;">
                                {{ session('success') }}
                            </div>
                        @endif

                        @if ($errors->any())

                                    <div class="form-group"  id="successMessage"  style="margin: 20px;">
                                        <div class="card bg-warning text-white shadow">
                                            <div class="card-body">

                                                @foreach ($errors->all() as $error)
                                                <div style="color: red; ">{{ $error }}</div>
                                                @endforeach

                                            </div>
                                        </div>
                                    </div>
                                    @endif
                            <form class="card-body" action="{{route('saveProcessCashBook')}}" method="post"  id="accountTypeForm">
                            @csrf
                            <input type="hidden" id="accountId" name="id" value="">

                                <div class="form-group row">
                                    <div class="col-sm-6 mb-3 mb-sm-0">
                                    <select class="form-control form-control-user" id="account" name="account"  value="{{ old('account') }}"  required>
                                        <option value="" disabled selected>Select Cash Book</option>

                                        @foreach ($gls as $gl)

                                        <option value="{{ $gl->AccCode }}">{{$gl->Name }}</option>

                                        @endforeach
                                    </select>
                                    </div>
                                    <div class="col-sm-6">

                                    <input type="date" class="form-control form-control-user" id="date" placeholder="Entry Date" name="date"  value="{{ old('date', \Carbon\Carbon::now()->format('Y-m-d')) }}" required>
                                   </div>
                                </div>

                               <div class="form-group row">
                                <div class="col-sm-6 mb-3 mb-sm-0">
                                    <select class="form-control form-control-user" id="contra" name="contra" value="{{ old('contra') }}" required>
                                        <option value="" disabled selected>Select Module</option>
                                        <option value="Reff">Use Reference</option>
                                        @foreach ($Accounts as $glsac)
                                            @if($type === 'Suppliers')
                                                <option value="{{ $glsac->AccCode }}">{{ $glsac->AccCode }} / {{ $glsac->Name ?? 'N/A' }}</option>
                                            @elseif($type === 'GL')
                                                <option value="{{ $glsac->AccCode }}">{{ $glsac->AccCode }} / {{ $glsac->AccName ?? 'N/A' }}</option>
                                            @else
                                                {{-- Handle unexpected $type --}}
                                                <option value="{{ $glsac->AccCode }}">{{ $glsac->AccCode }} / {{ $glsac->AccName ?? $glsac->Name ?? 'N/A' }}</option>
                                            @endif
                                        @endforeach
                                    </select>
                                </div>

                                    <div class="col-sm-6">
                                        <input type="text" class="form-control form-control-user" id="narr" placeholder="Description" name="narr"  value="{{ old('narr') }}" required >
                                   </div>

                                </div>

                                <div class="form-group row">
                                    <div class="col-sm-6 mb-3 mb-sm-0">

                                    <input type="text" class="form-control form-control-user" id="reff" placeholder="Refference" name="reff"  value="{{ old('reff') }}" required >

                                    </div>
                                    <div class="col-sm-6">

                                        <input type="text" class="form-control form-control-user" id="amount" placeholder="0.00" name="amount"  value="{{ old('amount') }}" required >

                                        </div>


                                </div>
                                <div class="form-group row">
                                    <div class="col-sm-6 mb-3 mb-sm-0">

                                    <select class="form-control form-control-user" id="curr" name="curr"  value="{{ old('curr') }}"  required>
                                        <option value="" disabled selected>Select Currency</option>

                                        @foreach ($currencys as $currency)

                                        <option value="{{ $currency->ID}}">{{ $currency->Name }}</option>

                                        @endforeach
                                    </select>
                                    </div>
                                    <div class="col-sm-6">
                                    <select class="form-control form-control-user" id="tr" name="tr"  value="{{ old('tr') }}"  required>
                                        <option value="" disabled selected>Select TR Code</option>
                                        <option value="DR">Receipt</option>
                                        <option value="CR">Payment</option>
                                    </select>
                                        </div>
                                </div>

                               <div style="display: flex;">
                               <input type="submit" style="width: 100px;height: 40px; margin-right: 10px; margin-top: 6px" value="Proccess" class="btn btn-primary btn-user btn-block" id="submitButton"/>
                                <input style="width: 100px;"    type="reset" value="Refresh" class="btn btn-secondary btn-user btn-block"  onclick="hideMessages()"/>
                               </div>
                                <hr>
                             </form>
                    </div>
                    @endsection
