<?php $__env->startSection('section-title', 'Account'); ?>
<?php $__env->startSection('page-title', 'Transfer'); ?>
<?php if(check_permission('bank-transfer-create')): ?>
    <?php $__env->startSection('action-button'); ?>
        <a href="#" id="modal_btn" class="btn btn-primary-rgba">
            <i class="mr-2 feather icon-plus"></i>
            Add Transfer
        </a>
    <?php $__env->stopSection(); ?>
<?php endif; ?>
<?php $__env->startSection('content'); ?>
    <div class="row">
        <div class="col-lg-12">
            <div class="card m-b-30">
                <div class="card-body">
                    <div class="table-responsive">
                        <table id="datatable-buttons" class="table table-striped table-bordered">
                            <thead class="table-primary">
                                <tr class="text-center">
                                    <th> Date </th>
                                    <th> From Account </th>
                                    <th> To Account </th>
                                    <th> Note </th>
                                    <th> Amount </th>
                                    <th> Created By </th>
                                </tr>
                            </thead>
                            <tbody>
                                <?php
                                    $total = 0;
                                ?>
                                <?php $__currentLoopData = $bank_transfers; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $transfer): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                                    <tr class="text-center">
                                        <td> <?php echo e(date('d-m-Y',strtotime($transfer->date))); ?> </td>
                                        <td> <?php echo e($transfer->from_bank_account->bank_name); ?> </td>
                                        <td> <?php echo e($transfer->to_bank_account->bank_name); ?> </td>
                                        <td> <?php echo e(($transfer->note != NULL)?$transfer->note:'NULL'); ?> </td>
                                        <td> <?php echo e(number_format($transfer->amount,2)); ?> TK</td>
                                        <td> <?php echo e($transfer->user->name); ?> </td>
                                    </tr>
                                    <?php
                                        $total += $transfer->amount;
                                    ?>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                            <tfoot>
                                <tr>
                                    <th colspan="4" class="text-end"> Total Amount </th>
                                    <th class="text-center"> <?php echo e(number_format($total,2)); ?> TK</th>
                                    <th class="text-center"></th>
                                </tr>
                            </tfoot>
                        </table>
                    </div>
                    <div class="pagination justify-content-center">
                        <?php echo e($bank_transfers->links()); ?>

                    </div>
                </div>
            </div>
        </div>
    </div>
    <?php echo $__env->make('backend.pages.account.transfer.model', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('js'); ?>
    <script type="text/javascript">
        $("#modal_btn").on("click", function () {
            //show payment_modal
            $("#modal").modal("show");
        });

        $(function(){
            $(document).on('change', '.from_bank_id', function(){
                var bank_id = $(this).val();
                if (bank_id != '') {
                    $.ajax({
                        url: "<?php echo e(route('get-account-balance')); ?>",
                        type: "GET",
                        data: { bank_id: bank_id },
                        success: function(data){
                            // Format the balance
                            var formattedBalance = parseFloat(data.balance).toLocaleString('en-US');
                            
                            // Display formatted balance
                            var balance = 'Current Balance: ' + formattedBalance + ' TK';
                            $('#from_amount').text(balance);
                            
                            // Store the original numeric balance in the hidden input
                            $('.from_amount').val(data.balance);
                        }
                    });
                }
            });
        });


        $(function(){
            $(document).on('change', '.to_bank_id', function(){
                var bank_id = $(this).val();
                if (bank_id != '') {
                    $.ajax({
                        url: "<?php echo e(route('get-account-balance')); ?>",
                        type: "GET",
                        data: { bank_id: bank_id },
                        success: function(data){
                            // Format the balance
                            var formattedBalance = parseFloat(data.balance).toLocaleString('en-US');
                            
                            // Display formatted balance
                            var balance = 'Current Balance: ' + formattedBalance + ' TK';
                            $('#to_amount').text(balance);
                        }
                    });
                }
            });
        });


        $(function(){
            $(document).on('change', '#from_bank_id', function(){
            var from_bank_id = $(this).val();
            if (from_bank_id != '') {
                $.ajax({
                    url:"<?php echo e(route('get-to-account')); ?>",
                    type:"GET",
                    data:{from_bank_id:from_bank_id},
                    success:function(data){
                    var html = '<option value="">Select Account</option>';
                    $.each(data,function(key,v){
                        html +='<option value="'+v.id+'">'+v.bank_name+'</option>';
                    });
                    $('#to_bank_id').html(html);
                    $('.to_bank_id').trigger('change');
                    }
                });
            }
            });
        });
    </script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('backend.layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH D:\laragon\www\fast-pos\resources\views/backend/pages/account/transfer/index.blade.php ENDPATH**/ ?>