

<?php $__env->startSection('title', 'General Ledger'); ?>

<?php $__env->startSection('content'); ?>
<div class="card mb-4">
    <div class="card-header">
        <h4 class="card-title mb-0">General Ledger</h4>
    </div>
    <div class="card-body">
        <form method="GET" action="<?php echo e(route('accounting.reports.general-ledger')); ?>">
            <div class="row g-3 align-items-end">
                <div class="col-md-3">
                    <label class="form-label">Start Date</label>
                    <input type="date" name="start_date" class="form-control" value="<?php echo e($startDate); ?>">
                </div>
                <div class="col-md-3">
                    <label class="form-label">End Date</label>
                    <input type="date" name="end_date" class="form-control" value="<?php echo e($endDate); ?>">
                </div>
                <div class="col-md-4">
                    <label class="form-label">Account</label>
                    <select name="account_id" class="form-select select2">
                        <option value="">Select an account</option>
                        <?php $__currentLoopData = $accounts; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $acc): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <option value="<?php echo e($acc->id); ?>" <?php echo e($accountId == $acc->id ? 'selected' : ''); ?>>
                                <?php echo e($acc->name); ?> (<?php echo e($acc->code); ?>) - <?php echo e(ucfirst($acc->model_type)); ?>

                            </option>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </select>
                </div>
                <div class="col-md-2 d-flex gap-2">
                    <button type="submit" class="btn btn-primary w-100">
                        <i class="fas fa-filter me-2"></i>Filter
                    </button>
                    <a href="<?php echo e(route('accounting.reports.general-ledger')); ?>" class="btn btn-secondary w-100">
                        <i class="fas fa-times me-2"></i>Clear
                    </a>
                </div>
            </div>
        </form>
    </div>
</div>

<?php if($selectedAccount): ?>
<div class="card">
    <div class="card-header bg-light d-flex justify-content-between align-items-center">
        <h5 class="card-title mb-0">
            Account: <?php echo e($selectedAccount->name); ?> (<?php echo e($selectedAccount->code); ?>)
        </h5>
        <div class="d-flex gap-3">
            <div><strong>Opening Balance:</strong> Rs. <?php echo e(number_format($openingBalance, 2)); ?></div>
            <div><strong>Closing Balance:</strong> Rs. <?php echo e(number_format($closingBalance, 2)); ?></div>
        </div>
    </div>
    <div class="card-body p-0">
        <div class="table-responsive">
            <table class="table table-hover table-bordered mb-0">
                <thead class="table-light">
                    <tr>
                        <th>Date</th>
                        <th>Reference</th>
                        <th>Remarks</th>
                        <th class="text-end">Debit</th>
                        <th class="text-end">Credit</th>
                        <th class="text-end">Running Balance</th>
                    </tr>
                </thead>
                <tbody>
                    <tr>
                        <td colspan="5" class="text-end fw-bold">Opening Balance</td>
                        <td class="text-end fw-bold"><?php echo e(number_format($openingBalance, 2)); ?></td>
                    </tr>
                    <?php $runningBalance = $openingBalance; ?>
                    <?php $__empty_1 = true; $__currentLoopData = $transactions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $txn): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <?php
                            $runningBalance += ($txn->transaction_type == 'debit' ? $txn->amount : -$txn->amount);
                        ?>
                        <tr>
                            <td><?php echo e($txn->created_at->format('d/m/Y')); ?></td>
                            <td><?php echo e(ucfirst($txn->reference_type)); ?> #<?php echo e($txn->reference_id); ?></td>
                            <td><?php echo e($txn->remarks); ?></td>
                            <td class="text-end"><?php echo e($txn->transaction_type == 'debit' ? number_format($txn->amount, 2) : '-'); ?></td>
                            <td class="text-end"><?php echo e($txn->transaction_type == 'credit' ? number_format($txn->amount, 2) : '-'); ?></td>
                            <td class="text-end"><?php echo e(number_format($runningBalance, 2)); ?></td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td colspan="6" class="text-center py-4">No transactions found for the selected period.</td>
                        </tr>
                    <?php endif; ?>
                    <tr class="table-light fw-bold">
                        <td colspan="5" class="text-end">Closing Balance</td>
                        <td class="text-end"><?php echo e(number_format($closingBalance, 2)); ?></td>
                    </tr>
                </tbody>
            </table>
        </div>
    </div>
</div>
<?php endif; ?>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('plugin-scripts'); ?>
<script>
    // Initialize select2 if available
    if (typeof jQuery !== 'undefined') {
        $(document).ready(function() {
            if ($.fn.select2) {
                $('.select2').select2({ theme: 'bootstrap-5' });
            }
        });
    }
</script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.app', array_diff_key(get_defined_vars(), ['__data' => 1, '__path' => 1]))->render(); ?><?php /**PATH C:\laragon\www\habibcables-ERP\resources\views\accounting\reports\general_ledger.blade.php ENDPATH**/ ?>