<?php $__env->startSection('title', 'Manage CashBook'); ?>
<?php $__env->startSection('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="<?php echo e(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">
                    <div class="card-header border-bottom">
                        <?php if($startDate ?? 0): ?>
                            <h3 class="card-title mb-0">Cost For The Date of
                                (<?php echo e(\Carbon\Carbon::parse($startDate)->format('d-M-Y')); ?>

                                --> <?php echo e(\Carbon\Carbon::parse($endDate)->format('d-M-Y')); ?>)</h3>
                        <?php elseif($month ?? 0): ?>
                            <h3 class="card-title mb-0">Cost For The Date of
                                (<?php echo e(\Carbon\Carbon::parse($month)->format('d-M-Y')); ?>)</h3>
                        <?php else: ?>
                            <h3 class="card-title mb-0">Cost For The Date of
                                (<?php echo e(\Carbon\Carbon::parse($today)->format('d-M-Y')); ?>)</h3>
                        <?php endif; ?>
                    </div>
                    <button id="openModalBtn" class="btn btn-primary ms-auto" data-toggle="modal" data-target="#module">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">Cost</th>
                                <th class="border-bottom-0">Balance</th>
                            </tr>
                            </thead>
                            <tbody>
                            <?php
                                // Initialize the starting balance (you can fetch this from the database or set a default value)
                                $balance = 0;
                            ?>

                            <?php $__currentLoopData = $costs; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $cost): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                <?php if($cost->cr > 0): ?>
                                    <?php
                                        // Update the running balance based on the cashBook 'cr'
                                        $balance += $cost->cr;
                                    ?>
                                    <tr>
                                        <td><?php echo e($loop->iteration); ?></td>
                                        <td><?php echo e(\Carbon\Carbon::parse($cost->updated_at)->format('d-M-Y (H:i:s)') ?? " "); ?></td>
                                        <td><?php echo e($cost->detail); ?></td>
                                        <td><?php echo e(number_format($cost->cr, 0)); ?></td>
                                        <td><?php echo e(number_format($balance, 0)); ?></td> <!-- Dynamically updated balance -->
                                    </tr>
                                <?php endif; ?>
                            <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>

                            </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 Date</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="<?php echo e(route('cashBook.report.baseOnDate')); ?>" method="POST" enctype="multipart/form-data">
                        <?php echo csrf_field(); ?>
                        <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>

<?php $__env->stopSection(); ?>



<?php echo $__env->make($master, \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\primary\resources\views/admin/cost/report.blade.php ENDPATH**/ ?>