@extends($master)
@section('title', 'Manage CashBook')
@section('body')
    <!--app-content open-->


    <!-- PAGE-HEADER -->
    <div class="page-header">
        <div>
            <h1 class="page-title">Manage CashBook</h1>
        </div>
        <div class="ms-auto pageheader-btn">
            <ol class="breadcrumb">
                <li class="breadcrumb-item"><a href="{{route('cashBook')}}">CashBook</a></li>
                <li class="breadcrumb-item active" aria-current="page">Manage CashBook</li>
            </ol>
        </div>
    </div>
    <!-- PAGE-HEADER END -->

    <!-- Row -->
    <div class="row row-sm">
        <div class="col-lg-12">
            <div class="card">
                <div class="card-header border-bottom">
                    <h3 class="card-title">Cash Book Statement</h3>
                    <button id="openModalBtn" class="btn btn-primary ms-auto" data-toggle="modal" data-target="#module">Select Date</button>
                </div>
                <div class="card-body">
                    <div class="">

                    </div>
                    <div class="table-responsive export-table">
                        <table id="file-datatable" class="table table-bordered text-nowrap key-buttons border-bottom  w-100">
                            <thead>
                            <tr>
                                <th class="border-bottom-0">SL No</th>
                                <th class="border-bottom-0">Date</th>
                                <th class="border-bottom-0">Detail</th>
                                <th class="border-bottom-0">Dr.</th>
                                <th class="border-bottom-0">Cr.</th>
                                <th class="border-bottom-0">Balance</th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($cashBooks as $cashBook)
                                <tr>
                                    @if($cashBook->dr+$cashBook->cr != 0)
                                        <td>{{$loop->iteration}}</td>
                                        <td>{{ \Carbon\Carbon::parse($cashBook->updated_at)->format('d-M-Y (H:i:s)') ?? " " }}</td>
                                        @if($cashBook->invoice_id)
                                            <td>#BDC{{ str_pad($cashBook->invoice_id, 6, '0', STR_PAD_LEFT) }}</td>
                                        @else
                                            <td>{{$cashBook->detail}}</td>
                                        @endif
                                        <td>{{ $cashBook->dr != 0 ? number_format($cashBook->dr, 0) : ' ' }}</td>
                                        <td>{{ $cashBook->cr != 0 ? number_format($cashBook->cr, 0) : ' ' }}</td>
                                        <td>{{number_format($cashBook->balance, 0)}}</td>
                                    @endif
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
    <!-- End Row -->
    <!-- CONTAINER CLOSED -->


    <div class="modal fade" id="module" tabindex="-1" aria-labelledby="exampleModalLabel" aria-hidden="true">
        <div class="modal-dialog">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Input Bank Detail</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">

                    <form class="form-horizontal" action="{{route('cashBook.report.baseOnDate')}}" method="POST" enctype="multipart/form-data">
                        @csrf
                        <div class="row">
                            <div class="col-md-12 col-xl-12">
                                <div class="form-group">
                                    <label for="place-top-left" class="form-label">Start Date</label>
                                    <input type="date" class="form-control" name="startDate" maxlength="25" id="place-top-left">
                                </div>
                            </div>
                            <div class="col-md-12 col-xl-12">
                                <div class="form-group">
                                    <label for="place-top-left" class="form-label">End Date</label>
                                    <input type="date" class="form-control" name="endDate" maxlength="25" id="place-top-left">
                                </div>
                            </div>
                            <div class="col-md-12 col-xl-3">
                                <div class="form-group">
                                    <button class="btn btn-primary " type="submit">Find</button>
                                </div>
                            </div>
                        </div>
                    </form>

                </div>
            </div>
        </div>
    </div>

@endsection

