<link rel="stylesheet" href="<?php echo base_url();?>assets/js/validationEngine.jquery.css" type="text/css" />
<link rel="stylesheet" href="<?php echo base_url();?>assets/css/cust_paginition.css" type="text/css" />
<div class="layout-app">
    <div class="container"><div class="row row-app">
            <div class="col-md-12">
                <div class="col-separator col-separator-first col-unscrollable bg-none">
                    <div class="col-table">
                        <div class="row">
                            <div class="col-md-12">
                                <div class="widget">
                                    <?php $this->load->view('admin/flashdata_admin'); ?>

                                    <div class="widget-head">
                                        <a href="#addPromo" data-toggle="modal" class="btn btn-inverse pull-right mar" target="_blank" onclick="return add_promotion()"><i class="fa fa-fw fa-plus"></i>Add New</a>
                                        <h4 class="heading">Vouchers</h4>

                                    </div>
                                    <div class="clearfix"></div>

                                    <div class="widget-body">
                                        <div>
                                            <div class="clearfix"></div>
                                        </div>
                                    </div>
                                    <table class="table table-white table-vertical-center margin-none table-striped footable">
                                        <thead>
                                        <tr>
                                            <th data-class="highlight" class="text-center">Sr. No.</th>
                                            <th>Voucher Name</th>
                                            <th>Voucher Amount</th>
                                            <th>Created</th>
                                            <th>Valid Until</th>
                                            <th>Status</th>
                                            <th class="text-center">Edit</th>
                                            <!--<th class="text-center">Delete</th> -->
                                        </tr>
                                        </thead>
                                        <tbody>
                                        <?php  if(count($vouchers) > 0) {
                                            $intCounter = 1;
                                            $statusOptions = ['1' => 'Active', '2' => 'Inactive'];
                                            foreach ($vouchers as $voucher){
                                                ?>

                                                <tr>
                                                    <td class="text-center" ><?php echo $intCounter; ?></td>
                                                    <td><?php echo ucwords($voucher['voucher_name']); ?></td>
                                                    <td><?php echo number_format($voucher['voucher_amount'],2); ?> SGD</td>
                                                    <td><?php echo ucwords(date('d-m-Y', strtotime($voucher['created_date']))); ?></td>
                                                    <td><?php echo ucwords(date('d-m-Y', strtotime($voucher['valid_until']))); ?></td>
                                                    <td><?php echo ucwords($statusOptions[$voucher['status']]); ?></td>
                                                    <?php $strDecodedId = base64_encode($voucher['id']); ?>
                                                    <td class="text-center"><a href="#editPromo" data-toggle="modal" onclick="return edit_promotion('<?php echo $strDecodedId; ?>')"><i class="fa fa-pencil"></i></a></td>
                                                </tr>
                                            <?php  $intCounter++; }
                                        } else {?>
                                            <tr>
                                                <td class="text-center" colspan = "3">Sorry, No agent found !!</td>
                                            </tr>
                                        <?php } ?>
                                        </tbody>
                                    </table>
                                    <div class="text-center innerAll border-top pagination">
                                        <?php //echo $cust_Pagination; ?>
                                    </div>
                                </div>
                                <!-- // END TRENDS -->
                            </div>


                        </div>

                    </div>
                    <div class="col-separator-h"></div>
                </div>
            </div>
        </div>
    </div>
</div>
</div>
<div class="modal fade" id="addPromo" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content" id="tran_preview">

        </div>
    </div>
</div>
<div class="modal fade" id="editPromo" data-backdrop="static">
    <div class="modal-dialog">
        <div class="modal-content" id="edit_promo">

        </div>
    </div>
</div>
<script src="<?php echo base_url(); ?>assets/library/jquery/jquery.min.js"></script>
<script src="<?php echo base_url();?>assets/js/custom.js" type="text/javascript"></script>
<script src="<?php echo base_url();?>assets/plugins/forms_elements_multiselect/js/jquery.multi-select.js?v=v2.0.0-rc1&sv=v0.0.1.2"></script>
<script src="<?php echo base_url();?>assets/plugins/forms_elements_bootstrap-datepicker/js/bootstrap-datepicker.js"></script>
<script src="<?php echo base_url();?>assets/components/forms_elements_bootstrap-select/bootstrap-select.js"></script>
<script src="<?php echo base_url();?>assets/components/forms_elements_bootstrap-select/bootstrap-select.init.js"></script>
<script src="<?php echo base_url();?>assets/components/forms_elements_fuelux-radio/fuelux-radio.init.js"></script>
<script src="<?php echo base_url();?>assets/components/forms_elements_multiselect/multiselect.init.js?v=v2.0.0-rc1&sv=v0.0.1.2"></script>
<script src="<?php echo base_url();?>assets/js/jquery.validationEngine-en.js" type="text/javascript"></script>
<script src="<?php echo base_url();?>assets/js/jquery.validationEngine.js" type="text/javascript"></script>
<script src="<?php echo base_url(); ?>assets/js/subscriber.js"></script>
<script type="application/javascript">
    function add_promotion()
    {
        $.ajax({
            url:"<?php echo base_url(); ?>index.php/vouchers/add_vouchers",
            'type' : 'GET',
            success:function(result){
                $("#tran_preview").html(result);
                //alert(result);
            }
        });
    }

    function edit_promotion(intPromotionId)
    {
        $.ajax({
            url:"<?php echo base_url(); ?>index.php/vouchers/add_vouchers",
            'data' : {
                'voucher_id' :intPromotionId
            },
            'type' : 'GET',
            success:function(result){
                $("#edit_promo").html(result);
            }
        });
    }


</script>