<?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 add_list_btn">
            <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 card_style">
                <div class="card-body">
                    <div class="table-responsive">
                        <table id="datatable-buttons" class="table table-striped">
                            <thead class="header_bg">
                                <tr class="text-center">
                                    <th class="header_style_left"> Date </th>
                                    <th> From Account </th>
                                    <th> To Account </th>
                                    <th> Note </th>
                                    <th> Amount </th>
                                    <th class="header_style_right"> 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 class="table_data_style_left"> <?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 class="table_data_style_right"> <?php echo e($transfer->user->name); ?> </td>
                                    </tr>
                                    <?php
                                        $total += $transfer->amount;
                                    ?>
                                <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                            </tbody>
                            <tfoot>
                                <tr class="header_bg">
                                    <th colspan="4" class="text-right text-white header_style_left"> Total Amount </th>
                                    <th class="text-center text-white"> <?php echo e(number_format($total,2)); ?> TK</th>
                                    <th class="text-center header_style_right"></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\new demo\resources\views/backend/pages/account/transfer/index.blade.php ENDPATH**/ ?>