
<?php $__env->startSection('content'); ?>
    <div class="az-content-breadcrumb">
        <span>Control Account</span>
    </div>
    <div class="d-flex justify-content-between align-items-center">
        <h2 class="az-content-title" style="display: inline">Control Account List</h2>
        <span>
            <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Control Account add')): ?>
                <button type="button" class="btn btn-az-primary" data-toggle="modal" data-target="#exampleModal">
                    <i class="fas fa-plus"></i>Add Account
                </button>
            <?php endif; ?>
        </span>
    </div>

    <div class="row">
        <div class="col-md-12 col-lg-12 col-xl-12">
            <div>
                <table id="example2" class="table table-striped">
                    <thead>
                        <tr>
                            <th class="wd-10p">S.No</th>
                            <th class="wd-10p">Account #</th>
                            <th class="wd-10p">Account Name</th>
                            <th class="wd-10p">Date</th>
                            <th class="wd-20p">Action</th>
                        </tr>
                    </thead>
                    <tbody>
                        
                        <?php $__currentLoopData = $control_account; $__env->addLoop($__currentLoopData); foreach($__currentLoopData as $key => $m_acc): $__env->incrementLoopIndices(); $loop = $__env->getLastLoop(); ?>
                            <tr>
                                <td><?php echo e($key + 1); ?></td>
                                <td><?php echo e($m_acc->control_account_number); ?></td>
                                <td><?php echo e($m_acc->control_account_name); ?></td>
                                <td><?php echo e($m_acc->created_at); ?></td>
                                <td>
                                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Sub Control Account list')): ?>
                                        <a class="btn btn-az-primary"
                                            href="<?php echo e(url('sub_control_account/' . $main_account->id_main_account . '/' . $m_acc->id_control_account)); ?>">

                                            Sub Control Account
                                        </a>
                                    <?php endif; ?>
                                    <?php if (app(\Illuminate\Contracts\Auth\Access\Gate::class)->check('Control Account edit')): ?>
                                        <a type="button" class="btn " style="background-color: #ffb136; color: white"
                                            data-toggle="modal" data-target="#exampleModal2"
                                            data-id="<?php echo e($m_acc->id_control_account); ?>"
                                            data-name="<?php echo e($m_acc->control_account_name); ?>">
                                            <i class="fas fa-edit"></i>
                                        </a>
                                    <?php endif; ?>
                                </td>
                            </tr>
                        <?php endforeach; $__env->popLoop(); $loop = $__env->getLastLoop(); ?>
                    </tbody>
                    <tfoot>
                        <tr>
                            <th class="wd-10p">S.No</th>
                            <th class="wd-10p">Account #</th>
                            <th class="wd-10p">Account Name</th>
                            <th class="wd-10p">Date</th>
                            <th class="wd-20p">Action</th>
                        </tr>
                    </tfoot>
                </table>
            </div>
        </div>
    </div>

    <div class="modal fade" id="exampleModal" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
        aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Add Control Account</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form id="addMainAccountForm" action="<?php echo e(url('control_account/store')); ?>" method="POST">
                        <?php echo csrf_field(); ?>
                        <div class="form-group" hidden>
                            <label for="accountName">Main Account ID</label>
                            <input type="text" class="form-control" id="id_main_account" name="id_main_account"
                                value="<?php echo e($main_account->id_main_account); ?>" required>
                        </div>
                        <div class="form-group">
                            <label for="accountName">Account Name</label>
                            <input type="text" class="form-control" id="name" name="name" required>
                        </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-primary">Save</button>
                    </form>
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>

    <div class="modal fade" id="exampleModal2" tabindex="-1" role="dialog" aria-labelledby="exampleModalLabel"
        aria-hidden="true">
        <div class="modal-dialog" role="document">
            <div class="modal-content">
                <div class="modal-header">
                    <h5 class="modal-title" id="exampleModalLabel">Edit Sub Control Account</h5>
                    <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                        <span aria-hidden="true">&times;</span>
                    </button>
                </div>
                <div class="modal-body">
                    <form id="editForm" method="POST">
                        <?php echo csrf_field(); ?>
                        <div class="form-group" hidden>
                            <label for="accountName">Main Account ID</label>
                            <input type="text" class="form-control" id="id_control_account" name="id_control_account"
                                value="<?php echo e($main_account->id_main_account); ?>" required>
                        </div>
                        <div class="form-group">
                            <label for="accountName">Account Name</label>
                            <input type="text" class="form-control" id="name" name="name" required>
                        </div>
                </div>
                <div class="modal-footer">
                    <button type="submit" class="btn btn-primary">Save</button>
                    </form>
                    <button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
                </div>
            </div>
        </div>
    </div>
<?php $__env->stopSection(); ?>

<?php $__env->startPush('scripts'); ?>
    <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js"></script>

    <script type="text/javascript">
        $('#exampleModal2').on('show.bs.modal', function(event) {
            var button = $(event.relatedTarget); // Button that triggered the modal
            var id = button.data('id'); // Extract info from data-* attributes
            var name = button.data('name');

            var modal = $(this);
            modal.find('#editForm').attr('action', '<?php echo e(url('control_account/update')); ?>/' + id);
            modal.find('#name').val(name);
        });

        $(function() {



            oTable = $('#example2').DataTable({

                responsive: !0
            });



        });
    </script>
<?php $__env->stopPush(); ?>

<?php echo $__env->make('layouts.master', \Illuminate\Support\Arr::except(get_defined_vars(), ['__data', '__path']))->render(); ?><?php /**PATH C:\wamp64\www\mds-scm\resources\views/Chart_of_account/control_account.blade.php ENDPATH**/ ?>