
<?php $this->load->view('site/layout'); ?>

<?php $this->load->view('site/navbar'); ?> 

<div class="kt-content  kt-grid__item kt-grid__item--fluid kt-grid kt-grid--hor" id="kt_content">

    <!-- begin:: Content Head -->
    <div class="kt-subheader  kt-grid__item" id="kt_subheader">
        <div class="kt-container  kt-container--fluid ">
            <div class="kt-subheader__main">
                <h3 class="kt-subheader__title"><a href="<?php echo base_url() ?>Dashboard/"><?php echo $this->lang->line('dashboard'); ?></a></h3>
                <span class="kt-subheader__separator kt-subheader__separator--v"></span>
                <span class="kt-subheader__desc"><?php echo $this->lang->line('absent'); ?></span>
            </div>

        </div>
    </div>
</div>  
<div class="kt-container  kt-container--fluid  kt-grid__item kt-grid__item--fluid">
    <button class="btn btn-primary mb-3" onclick="toggle_filter()"><?= $this->lang->line('show_hide_filter') ?></button>
    <div class="alert alert-light alert-elevate" role="alert" id="filter_container">
        <div class="alert-text">
            <?php if ($this->session->flashdata('success')): ?>
                <div class="alert alert-success alert-dismissible">
                    <button type="button" class="close" data-dismiss="alert" aria-hidden="true">×</button>
                    <h4><i class="icon fa-warning"></i> Success!</h4>&nbsp;
                    <?= $this->lang->line('op_success'); ?>
                </div>
            <?php endif; ?>  
            <form class="kt-form kt-form--label-right" method="post" action=""> 
                <div class="kt-portlet__body">
                    <div class="form-group row">
                        <label for="example-text-input" class="col-2 col-form-label"><?php echo $this->lang->line('date') ?></label>
                        <div class="col-9">
                            <input type="text" name="start_expiry" id="start_expiry" class="form-control" value="<?= set_value('start_expiry') ?>"> 
                        </div>
                        <div class="col-1" style="padding-left: 0px">
                            <a onclick="clear_date()" class="btn btn-light btn-text-primary btn-hover-text-primary font-weight-bold"><?= $this->lang->line('clear') ?></a>
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="example-text-input" class="col-2 col-form-label"><?php echo $this->lang->line('products') ?></label>
                        <div class="col-9">
                            <select multiple name="products[]" class="topnav form-control select2_plug" >
                                <?php
                                foreach ($products as $value) {
                                    $selected = '';
                                    if (!empty($this->input->post('products'))) {
                                        if (in_array($value->name, $this->input->post('products'))) {
                                            $selected = 'selected';
                                        }
                                    }
                                    ?>
                                    <option <?= $selected ?> value="<?php echo $value->name ?>"><?php echo $value->name ?></option>
                                <?php } ?>
                            </select> 
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="example-text-input" class="col-2 col-form-label"><?php echo $this->lang->line('student') ?></label>
                        <div class="col-9">
                            <select multiple name="username[]" class="topnav form-control select2_plug" >
                                <?php
                                foreach ($username as $value) {
                                    $selected = '';
                                    if (!empty($this->input->post('username'))) {
                                        if (in_array($value->username, $this->input->post('username'))) {
                                            $selected = 'selected';
                                        }
                                    }
                                    ?>
                                    <option <?= $selected ?> value="<?php echo $value->username ?>"><?php echo $value->username ?></option>
                                <?php } ?>
                            </select> 
                        </div>
                    </div>
                    <div class="form-group row">
                        <label for="example-text-input" class="col-2 col-form-label"><?php echo $this->lang->line('attend_status') ?></label>
                        <div class="col-9">
                            <select multiple name="attend_status[]" class="topnav form-control select2_plug" >
                                <?php
                                $selected1 = $selected2 = $selected3 = '';
                                if (!empty($this->input->post('attend_status'))) {
                                    if (in_array($this->lang->line('present'), $this->input->post('attend_status'))) {
                                        $selected1 = 'selected';
                                    }
                                    if (in_array($this->lang->line('absent'), $this->input->post('attend_status'))) {
                                        $selected2 = 'selected';
                                    }
                                    if (in_array($this->lang->line('late'), $this->input->post('attend_status'))) {
                                        $selected3 = 'selected';
                                    }
                                }
                                ?>
                                <option <?= $selected1 ?> value="<?php echo $this->lang->line('present') ?>"></option>
                                <option <?= $selected2 ?> value="<?php echo $this->lang->line('absent') ?>"></option>
                                <option <?= $selected3 ?> value="<?php echo $this->lang->line('late') ?>"></option>
                            </select> 
                        </div>
                    </div>
                    <div class="form-group row">
                        <div class="col-1">
                        </div>
                        <button  class="btn btn-brand btn-elevate btn-icon-sm mr-5">
                            <?php echo $this->lang->line('submit') ?>
                        </button>

                    </div>
                </div>
            </form>          
        </div>
    </div>
</div>
<div class="kt-portlet kt-portlet--mobile" style="margin-right: 22px;">
    <div class="kt-portlet__head kt-portlet__head--lg">
        <div class="kt-portlet__head-label">
            <span class="kt-portlet__head-icon">
                <i class="kt-font-brand flaticon2-line-chart"></i>
            </span>
            <h3 class="kt-portlet__head-title">
                <?php echo $this->lang->line('absent'); ?>
            </h3>
        </div>
        <div class="kt-portlet__head-toolbar">
            <div class="kt-portlet__head-wrapper">
                <div class="kt-portlet__head-actions">
                    &nbsp;
                    <!-- <form method="post" action=""> 
                      <button type="submit" name="report" value="<?php echo $start_expiry; ?>"  class="btn btn-brand btn-elevate btn-icon-sm">
                        <i class="la la-download"></i>
                    <?php echo $this->lang->line('report') ?>
                      </button>
                    </form> -->
                </div>
            </div>
        </div>
    </div>
    <div class="kt-portlet__body">
        <form action="<?= base_url() ?>User/delete_absent_bulk" method="post" >
        	<?php if(get_ap('attendance_del',$this->operator_id)){ ?>
                <div class="row" style="display: block">
                    <button type="submit" class="btn btn-danger pull-right">
                        <i class="fa fa-trash"></i> <?= $this->lang->line('delete_all_selected') ?>
                    </button>
                </div>
            <?php } ?>
            <div class="clearfix"></div>
            <br/>
            <!--begin: Datatable -->
            <table class="table table-bordered table-hover " id="list_table" >
                <thead>
                    <tr> 
                    	<?php if(get_ap('attendance_del',$this->operator_id)){ ?>
                        	<th></th>
                        <?php  } ?>
                        <th><?php echo $this->lang->line('sno') ?></th>
                        <th><?php echo $this->lang->line('the-name') ?></th>
                        <th><?php echo $this->lang->line('products') ?></th>
                        <th><?php echo $this->lang->line('date') ?></th>
                        <th><?php echo $this->lang->line('attendance') ?></th>
                        <?php if(get_ap('attendance_del',$this->operator_id)){ ?>
                        	<th class='text-center'><?php echo $this->lang->line('delete') ?></th>
                        <?php } ?>

                    </tr>
                </thead>
                <tbody>

                    <?php
                    $count = 1;
                    foreach ($all_groups as $row) {
                        ?>
                        <tr>
                        	<?php if(get_ap('attendance_del',$this->operator_id)){ ?>
                            	<td><input type="checkbox" name="delete[<?= $row->sno ?>]" /></td>
                            <?php } ?>
                            <td><?php echo $count++; ?></td>
                            <?php
                            $this->db->where('id', $row->user_id);
                            $user = $this->db->get('bills_user')->row();
                            ?>
                            <td><?php echo @$user->username; ?></td>
                            <?php
                            $this->db->where('id', $row->product_id);
                            $product = $this->db->get('bills_producer')->row();
                            ?>
                            <td><?php echo @$product->name; ?></td>
                            <td><?php echo @$row->date; ?></td>
                            <td><?php
                                if ($row->present == '2')
                                    echo '<span class="btn btn-sm btn-warning" style="border-radius: 2rem;padding: 0.15rem 5px; color: #fff;!important">' . $this->lang->line('late') . ' ' . $this->lang->line('present') . '</span>';
                                if ($row->present == '1')
                                    echo '<span class="btn btn-sm btn-success" style="border-radius: 2rem;padding: 0.15rem 5px; color: #fff;!important">' . $this->lang->line('present') . '</span>';
                                if ($row->present == '0')
                                    echo '<span class="btn btn-sm btn-danger" style="border-radius: 2rem;padding: 0.15rem 5px; color: #fff;!important">' . $this->lang->line('absent') . '</span>';
                                ?></td>
							<?php if(get_ap('attendance_del',$this->operator_id)){ ?>
                                <td class='text-center'>
                                    <a href=""  onclick="alert_box(<?php echo $row->sno; ?>)" title="delete" > <button class="btn btn-icon btn-danger btn-sm"><i class="la la-trash"></i></button>
                                    </a>
                                </td> 
                            <?php } ?>
                        </tr>
                    <?php } ?>
                </tbody>
            </table>
        </form>
        <!--end: Datatable -->
    </div>

</div><!-- /.row -->
<?php $this->load->view('site/footer_2'); ?> 
<script >
    $("#filter_container").hide();
    $(".select2_plug").select2();
    function absent_reports() {
        // var search[] = <?php //echo $all_groups ?>;
        // alert('dad');
        $.ajax({
            type: "POST",
            url: "<?php echo base_url() ?>producer/absent_report",
            data: JSON.stringify({'data': 'search'}),
            // success: function() {
            // var dd =  obj = JSON.parse(e)
            // $(".new-select").html(dd);
            // }
        });
    }
</script>
<script>function alert_box(id) {
        var result = confirm("Are You Confirm!")
        if (result) {
            window.location.href = "<?= base_url('producer/delete_absent/') ?>" + id;

        }

    }
    function toggle_filter() {
        $("#filter_container").toggle();
        $(".select2_plug").select2();
    }
    function clear_date() {
        $("#start_expiry").val('');
    }
    
    $(function () {
    
        $("#list_table").DataTable({dom: 'Bfrtip',
            destroy: true,
            buttons: [
                {
                    extend: 'excelHtml5',
                    charset: 'UTF-16LE',
                    fieldSeparator: '\t',
                    bom: true
                },
                {
                    extend: 'csvHtml5',
                    charset: 'UTF-16LE',
                    fieldSeparator: '\t',
                    bom: true
                },
                {
                    extend: 'pdfHtml5',
                    charset: 'UTF-16LE',
                    fieldSeparator: '\t',
                    bom: true
                },
                {
                    extend: 'print',
                    autoPrint: false,
                    footer: true
                }

            ]
        });
//            buttons: [
//                'copyHtml5',
//                'excelHtml5',
//                'csvHtml5',
//                'pdfHtml5'
//            ]
    });
</script>