<style>
    table.dataTable tr.group td{font-weight:bold;background-color:#e0e0e0}
    
     table.dataTable tr.group,
        tr.group:hover {
            background-color: #ddd !important;
        }
    
</style>

<div class="wrapper">
    <div class="container">
        <!-- Page-Title -->
        <div class="row">
            <div class="col-sm-12">
                <div class="btn-group pull-right m-t-15">
                    <form method="post" action="<?php echo base_url(); ?>accounting_controller/controlaccountadd">
                        <input type="hidden" name="csrf_test_name" id="accounts_add_csrf" value=""/>
                        <input type="hidden" name="id_account_main" id="id_account_main" value="<?php echo $account_main[0]['id_account_main']; ?>"/>
                        <input type="hidden" name="account_main" id="account_main" value="<?php echo $account_main[0]['account_main']; ?>"/>
                        <button type="submit" onclick="$('#accounts_add_csrf').val($('#cook').val());" class="btn btn-custom waves-effect waves-light" >Add Control Account<span class="m-l-5"><i class="fa fa-plus"></i></span></button>
                    </form>
                </div>
                <h4 class="page-title">CONTROL ACCOUNTS - <?php echo $account_main[0]['account_main'];?> - <small>(<?php echo $business[0]['business_name'];?>)</small>:</h4>
                <a class="btn btn-warning waves-effect waves-light" href="<?php echo base_url(); ?>coa"  ><i class="fa fa-arrow-left"></i> Back To Main Accounts</a>
            </div>
        </div>
        <?php if ($this->session->flashdata('Success') && $this->session->flashdata('Success') != ""){  ?>
        <div class="row">
            <div class="col-sm-12">
                <div class="alert alert-success">
                    <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                    <strong>Success!</strong> <?php echo $this->session->flashdata('Success'); ?>
                </div>
            </div>
        </div>
        <?php } ?>
        <?php if ($this->session->flashdata('Error') && $this->session->flashdata('Error') != ""){  ?>
        <div class="row">
            <div class="col-sm-12">
                <div class="alert alert-danger">
                    <a href="#" class="close" data-dismiss="alert" aria-label="close">&times;</a>
                    <strong>Error!</strong> <?php echo $this->session->flashdata('Error'); ?>
                </div>
            </div>
        </div>
        <?php } ?>
        <div class="row" id="divselection">
            <div class="col-sm-12">
                <div class="card-box ">
                    <h4 class="header-title m-t-0 m-b-30"></h4>
                    <div class="row">
                        <div class="col-lg-12">
                            <table id="datatable-buttons" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
                                <thead>
                                    <tr>
                                        <th>ID</th>
                                        <th>Account Number</th>
                                        <th>Account Title</th>
                                        <th>Belongs to</th>
                                        <th>Created On</th>
                                        <th>Delete</th>
                                        <th>Edit</th>
                                        <th>Sub Control Accounts</th>
                                    </tr>
                                </thead>
                                <tbody>
                                    <?php foreach($account_control as $account_head){ ?>
                                    <tr>
                                        <td><?php echo $account_head['id_account_control']; ?></td>
                                        
                                        <td style="font-weight: bold;"><?php echo $account_head['account_control_number']; ?></td>
                                        <td style="font-weight: bold;"><?php echo $account_head['account_control']; ?></td>
                                        <td ><?php echo $account_main[0]['account_main']; ?></td>
                                        <td><?php echo $account_head['created_on']; ?></td>
                                        <td class='noprint'>       
                                            
                                            <form class='deleteform' method="POST" action="<?php echo base_url(); ?>accounting_controller/control_account_delete">
                                                <input type="hidden" name="id_account_main"  value="<?php echo $account_main[0]['id_account_main']; ?>"/>
                                                <input type="hidden" name="id_account_control" id="delete_main_<?php echo $account_head['id_account_control']; ?>" value="<?php echo $account_head['id_account_control']; ?>">
                                                <input type="hidden" name="csrf_test_name" id="accounts_delete_csrf_<?php echo $account_head['id_account_control'];?>" value=""/>
                                                <button type="submit" onclick="$('#accounts_delete_csrf_<?php echo $account_head['id_account_control'];?>').val($('#cook').val()); " class="btn btn-icon waves-effect waves-light btn-danger m-l-5"> <i class="fa fa-trash"></i> </button>  
                                            </form>
                                        </td>
                                        <td>
                                            <form   method="post" action="<?php echo base_url(); ?>accounting_controller/controlaccountedit">
                                                <input type="hidden" name="id_account_control" id="account_control_<?php echo $account_head['id_account_control']; ?>" value="<?php echo $account_head['id_account_control']; ?>">
                                                <input type="hidden" name="csrf_test_name" id="accounts_edit_csrf_<?php echo $account_head['id_account_control'];?>" value=""/>
                                                <button type="submit" onclick="$('#accounts_edit_csrf_<?php echo $account_head['id_account_control'];?>').val($('#cook').val());" class="btn btn-icon waves-effect waves-light btn-info m-l-5"> <i class="fa fa-keyboard-o"></i> </button>  
                                            </form>
                                        </td>
                                        <td>
                                            
                                                <a href='<?php echo base_url(); ?>sub_control_accounts/<?php echo $account_main[0]['id_account_main']."/".$account_head['id_account_control'];?>' class='btn waves-effect waves-light btn-warning m-l-5'><i class="fa fa-plus"></i> Sub Control Accounts</a>
                                            
                                        </td>
                                    </tr>
                                    <?php }?>
                                </tbody>
                            </table>
                            
                        </div>
                    </div>
                </div>
            </div>
        </div>    
    </div>
</div>

<script>
    
    $(window).load(function() {
         
        $(".deleteform").submit(function(event){
            var form = this;
            event.preventDefault();
            swal({
                title: 'Confirm Deletion',
                text: "Are you sure?",
                type: 'warning',
                showCancelButton: true,
                confirmButtonColor: '#ff5b5b !important',
                cancelButtonColor: '#d33',
                cancelButtonText: 'No',
                confirmButtonText: 'Yes'
                
            }, function(isConfirm) {          
                if(isConfirm){
                    form.submit();
                }
            });
        });
        
         
     });
    
    $(document).ready(function() {
        var table =$('#datatable-buttons').DataTable({
                "lengthMenu": [[10, 25, 50, -1], [10, 25, 50, "All"]],                
                "stateSave": false,
                <?php if(DOWNLOAD == true || $this->session->userdata('role') == 'Admin' || $this->session->userdata('role')=='Super User'){ ?>
                    "dom": "Bfrtlip",
                    "buttons": [{extend: "copy", className: "btn-sm btn-custom btn-trans"}, {extend: "csv", className: "btn-sm btn-pink btn-trans"}, {
                        extend: "excel",
                        className: "btn-sm btn-warning btn-trans"
                    }, {extend: "pdf", className: "btn-sm btn-purple btn-trans"}],
                <?php } else { ?>
                    dom: "frtlip",
                <?php } ?>    
                "responsive": !0,
               
		"order": [[ 0, 'asc' ]],
		"displayLength": 25
            });

            // Order by the grouping
	
        
        toastr.options = {
            "closeButton": true,
            "debug": true,
            "newestOnTop": true,
            "progressBar": true,
            "positionClass": "toast-bottom-center",
            "preventDuplicates": true,
            "onclick": null,
            "showDuration": "300",
            "hideDuration": "1000",
            "timeOut": "5000",
            "extendedTimeOut": "1000",
            "showEasing": "swing",
            "hideEasing": "linear",
            "showMethod": "fadeIn",
            "hideMethod": "fadeOut"
        };

        $(".numeric").keypress(function(e) {
            //if the letter is not digit then display error and don't type anything
            if (e.which != 13 && e.which != 8 && e.which != 0 && (e.which < 48 || e.which > 57)) {
                return false;
            }
        });
        
    });

    
</script>