
<?php $__env->startSection('content'); ?>
<style>
    .input_upload {
        width:100px;
        height:35px;
        position:absolute;
        bottom:-34px;
        right:350px;
    }
    .account-sidebar {
        position: sticky;
        top: 20px;
        height: calc(100vh - 100px);
    }
    .account-sidebar .nav-link {
        border-radius: 0;
        padding: 12px 15px;
        color: #495057;
    }
    .account-sidebar .nav-link.active {
        background-color: #f8f9fa;
        color: #0d6efd;
        border-left: 3px solid #0d6efd;
        font-weight: 500;
    }
    .account-sidebar .nav-link:hover:not(.active) {
        background-color: #f8f9fa;
    }
    .daybook-table th {
        background-color: #f8f9fa;
    }
    .debit-amount {
        color: #dc3545;
    }
    .credit-amount {
        color: #28a745;
    }
    .total-row {
        font-weight: bold;
        background-color: #f1f1f1;
    }
    .transaction-row:hover {
        background-color: #f8f9fa;
        cursor: pointer;
    }
</style>

<!-- begin::main content -->
<main class="main-content">
    <div class="container-fluid">
        <div class="row">
            
            <!-- Main content area -->
            <div class="col-md-12">
                <div class="page-header">
                    <h3>Transactions</h3>
                    <nav aria-label="breadcrumb">
                        <ol class="breadcrumb">
                            <li class="breadcrumb-item"><a href="<?php echo e(asset('dashboard')); ?>"><?php echo e(__('message.dashboard')); ?></a></li>
                            <li class="breadcrumb-item active" aria-current="page">Day Book</li>
                        </ol>
                    </nav>
                </div>

                <div class="card">
                    <div class="card-header">
                        <form action="<?php echo e(asset('account/all-transactions')); ?>" method="get">
                            <div class="row mt-3">
                                <div class="col-md-8">   
                                    <div class="row">
                                        <div class="form-group col-md-4">
                                            <label>Date</label>
                                            <input type="date" name="date" value="<?php echo e(request('date') ?? date('Y-m-d')); ?>" class="form-control">
                                        </div>
                                        <div class="input-group col-md-4"> 
                                            <div class="pt-4">                                       
                                                <button class="btn border" type="submit">
                                                    <i class="ti ti-search fa-lg"></i>
                                                </button>
                                                <a class="btn btn-white border" href="<?php echo e(asset('account/all-transactions')); ?>">
                                                    <i class="ti ti-reload fa-lg"></i>
                                                </a>
                                            </div>
                                        </div> 
                                    </div>                                     
                                </div>
                                <div class="col-md-4">
                                    <div class=" bg-light p-2 py-3 text-center">
                                        <h5 class="mb-0">Report Date</h5>
                                            <hr>
                                            <span class="font-weight-bold">
                                                <?php echo e(request('date') ? date('d M Y', strtotime(request('date'))) : date('d M Y')); ?>

                                            </span>
                                    </div>
                                </div>
                            </div>
                        </form>
                    </div>

                    <div class="card-body">
                        <div class="table-responsive daybook-box">
                            <div class=" bg-light p-2 py-3 text-center daybook_date d-none">
                                <h5 class="mb-0">Report Date</h5>
                                    <hr>
                                    <span class="font-weight-bold">
                                        <?php echo e(request('date') ? date('d M Y', strtotime(request('date'))) : date('d M Y')); ?>

                                    </span>
                            </div>
                            <table class="table table-bordered daybook-table">
                                <thead>
                                    <tr>
                                        <th>Date</th>
                                        
                                        <th>Transaction Type</th>
                                        <th>Client/Vendor Name</th>
                                        <th class="text-right">Amount</th>
                                        
                                        <th>Note</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php
                                        $total_debit = 0;
                                        $total_credit = 0;
                                    ?>
                                    
                                    
                                    <!-- Sample data - replace with your actual data -->
                                    <?php if(isset($transactions)): ?>
                                        <?php $__currentLoopData = $transactions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $transaction): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                        <tr class="transaction-row">
                                            <td><?php echo e($transaction["date"]); ?></td>
                                            
                                            <td><?php echo e($transaction["transaction_type"]); ?></td>
                                            <td><?php echo e($transaction["customer_name"]); ?></td>
                                            <td><?php echo e($transaction["amount"]); ?></td>
                                            
                                            <td></td>
                                        </tr>
                                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                                    <?php endif; ?>
                                    
                                    <!-- Total Row -->
                                    <tr class="total-row">
                                        <td colspan="3"><strong>Total</strong></td>
                                        <td class="text-right debit-amount"><strong>₹ <?php echo e(number_format($total_debit, 2)); ?></strong></td>
                                        <td class="text-right credit-amount"><strong>₹ <?php echo e(number_format($total_credit, 2)); ?></strong></td>
                                        <td></td>
                                    </tr>
                                    
                                    <!-- Difference Row (should be zero if balanced) -->
                                    <tr>
                                        <td colspan="6" class="text-center <?php echo e($total_debit == $total_credit ? 'text-success' : 'text-danger'); ?>">
                                            <strong>
                                                <?php if($total_debit == $total_credit): ?>
                                                    Day Book Balanced (₹ 0.00)
                                                <?php else: ?>
                                                    Day Book Out of Balance (₹ <?php echo e(number_format(abs($total_debit - $total_credit), 2)); ?>)
                                                <?php endif; ?>
                                            </strong>
                                        </td>
                                    </tr>
                                </tbody>
                            </table>
                        </div>
                        
                        <!-- Export buttons -->
                        <div class="mt-4 text-right">
                            <button class="btn btn-outline-primary print-daybook">
                                <i class="ti ti-download"></i> Export as PDF
                            </button>
                            <button class="btn btn-outline-success ml-2">
                                <i class="ti ti-file-excel"></i> Export as Excel
                            </button>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>
</main>
<!-- end::main content -->
<?php $__env->stopSection(); ?>

<?php $__env->startPush('footer-script'); ?>
<!-- begin::dataTable -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/html2pdf.js/0.9.3/html2pdf.bundle.min.js"></script>

<!-- end::dataTable -->
<script>
    $(document).ready(function() {
        // Print functionality
        $(".print-daybook").click(function(){
            $(".daybook_date").removeClass("d-none");
            var element = document.querySelector(".daybook-box"); 
            var opt = {
                margin: 0.3,
                filename: 'daybook_<?php echo e(request('date') ?? date('Y-m-d')); ?>.pdf',
                image: { type: 'jpeg', quality: 1 },
                html2canvas: { scale: 2 },
                jsPDF: { unit: 'in', format: 'a4', orientation: 'landscape' }
            };

            html2pdf().set(opt).from(element).save();
            setTimeout(()=>{
                $(".daybook_date").addClass("d-none");
            },4000);
        });
        
        // Transaction row click to view details
        $(".transaction-row").click(function() {
            var voucherNo = $(this).find('td:nth-child(2)').text();
            // Add your logic to view transaction details
            window.location.href = "<?php echo e(asset('account/vouchers/')); ?>/" + voucherNo;
        });
    });
</script>
<?php $__env->stopPush(); ?>
<?php echo $__env->make('layout', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH /var/www/peoplebee.in/account/resources/views/accounting/reports/transaction.blade.php ENDPATH**/ ?>