<?php $__env->startSection('content'); ?>
<div class="d-flex flex-wrap justify-content-between align-items-center gap-3 mb-4">
    <h1 class="h3 mb-0">Transaction History</h1>
    <form class="row g-2 ajax-filter" method="GET" action="<?php echo e(route('reports.transactions')); ?>" data-ajax-target="#report-results">
        <div class="col-auto">
            <input class="form-control" name="date_from" type="date" value="<?php echo e($filters['date_from'] ?? ''); ?>" placeholder="From Date">
        </div>
        <div class="col-auto">
            <input class="form-control" name="date_to" type="date" value="<?php echo e($filters['date_to'] ?? ''); ?>" placeholder="To Date">
        </div>
        <div class="col-auto">
            <select class="form-select" name="currency_id">
                <option value="">All currencies</option>
                <?php $__currentLoopData = $currencies; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $currency): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($currency->id); ?>" <?php if(($filters['currency_id'] ?? '') == $currency->id): echo 'selected'; endif; ?>>
                        <?php echo e($currency->code); ?>

                    </option>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </select>
        </div>
        <div class="col-auto">
            <select class="form-select" name="agent_id">
                <option value="">All agents</option>
                <?php $__currentLoopData = $agents; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $agent): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                    <option value="<?php echo e($agent->id); ?>" <?php if(($filters['agent_id'] ?? '') == $agent->id): echo 'selected'; endif; ?>>
                        <?php echo e($agent->name); ?>

                    </option>
                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
            </select>
        </div>
        <div class="col-auto">
            <button class="btn btn-primary" type="submit">Filter</button>
        </div>
        <div class="col-auto">
            <a class="btn btn-outline-success export-link" href="<?php echo e(route('reports.transactions', array_merge(request()->except('export'), ['export' => 'xls']))); ?>">Excel</a>
        </div>
    </form>
</div>

<div id="report-results">
<div class="card">
    <div class="card-body">
        <div class="table-responsive">
            <table class="table table-striped align-middle">
                <thead>
                    <tr>
                        <th>Date</th>
                        <th>Type</th>
                        <th>Agent</th>
                        <th>Currency</th>
                        <th class="text-end">Quantity</th>
                        <th class="text-end">Rate</th>
                        <th class="text-end">Payment Amount</th>
                        <th class="text-end">Total Profit</th>
                        <th></th>
                    </tr>
                </thead>
                <tbody>
                    <?php $__empty_1 = true; $__currentLoopData = $transactions; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $transaction): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); $__empty_1 = false; ?>
                        <tr>
                            <td><?php echo e($transaction->created_at->format('Y-m-d H:i')); ?></td>
                            <td class="text-capitalize"><?php echo e($transaction->type); ?></td>
                            <td><?php echo e(optional($transaction->agent)->name ?? '-'); ?></td>
                            <td><?php echo e($transaction->currency->code); ?></td>
                            <td class="text-end"><?php echo e(number_format((float) $transaction->quantity, 4)); ?> <?php echo e($transaction->currency->code); ?></td>
                            <td class="text-end"><?php echo e(number_format((float) $transaction->rate, 4)); ?></td>
                            <td class="text-end"><?php echo e(number_format((float) $transaction->payment_amount, 4)); ?> <?php echo e(optional($transaction->paymentCurrency)->code); ?></td>
                            <td class="text-end"><?php echo e(number_format((float) $transaction->total_profit, 4)); ?></td>
                            <td class="text-end">
                                <div class="btn-group btn-group-sm">
                                    <?php if($transaction->type === 'buy'): ?>
                                        <?php if(is_null($transaction->payment_account_id) && $transaction->agentBalance): ?>
                                            <a class="btn btn-outline-primary" href="<?php echo e(route('agent-balances.edit', $transaction->agentBalance)); ?>" title="Edit">
                                                <i class="feather icon-edit-2"></i> Edit
                                            </a>
                                        <?php else: ?>
                                            <a class="btn btn-outline-primary" href="<?php echo e(route('transactions.buy.edit', $transaction)); ?>" title="Edit">
                                                <i class="feather icon-edit-2"></i> Edit
                                            </a>
                                        <?php endif; ?>
                                    <?php elseif($transaction->type === 'sell'): ?>
                                        <a class="btn btn-outline-primary" href="<?php echo e(route('transactions.sell.edit', $transaction)); ?>" title="Edit">
                                            <i class="feather icon-edit-2"></i> Edit
                                        </a>
                                    <?php elseif($transaction->type === 'borrow'): ?>
                                        <a class="btn btn-outline-primary" href="<?php echo e(route('borrows.edit', $transaction)); ?>" title="Edit">
                                            <i class="feather icon-edit-2"></i> Edit
                                        </a>
                                    <?php endif; ?>
                                    
                                    <form action="<?php echo e(route('transactions.destroy', $transaction)); ?>" method="POST" onsubmit="return confirm('Are you sure you want to delete this transaction? This will reverse all balance effects.')" style="display:inline;">
                                        <?php echo csrf_field(); ?>
                                        <?php echo method_field('DELETE'); ?>
                                        <button type="submit" class="btn btn-outline-danger" title="Delete">
                                            <i class="feather icon-trash-2"></i> Delete
                                        </button>
                                    </form>
                                    
                                    <a class="btn btn-outline-secondary" href="<?php echo e(route('reports.transactions.show', $transaction)); ?>" title="Details">
                                        <i class="feather icon-eye"></i> Details
                                    </a>
                                </div>
                            </td>
                        </tr>
                    <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); if ($__empty_1): ?>
                        <tr>
                            <td class="text-muted text-center" colspan="9">No transactions found.</td>
                        </tr>
                    <?php endif; ?>
                </tbody>
            </table>
        </div>
    </div>
</div>
</div>
<?php $__env->stopSection(); ?>

<?php echo $__env->make('layouts.app', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH F:\christopher\currencychangerui\resources\views/reports/transactions.blade.php ENDPATH**/ ?>