<div class="col-lg-10 col-md-10 col-sm-10 col-xs-10 bodyitem">
    <div  style="padding-top:15px;">
        <div class="row">
            <div class='col-lg-12 col-md-12 col-sm-12 col-xs-12 text-uppercase'style="margin-top: 5px;">
                <input type="checkbox" class="checkbox-inline" id="showHideAddPromotion" onclick="checkBlock(this.id, 'AddNewPromotionBox')">
                <span style="color: #FFF"><?php echo $this->lang->line('gkpos_add_new_promotion') ?></span>
            </div>
        </div>
        <input type="hidden" id="currentPage" value="<?php (isset($current_page) && ($current_page != '' || $current_page != null )) ? print $current_page : print'false' ?>">
        <div class="row" id="AddNewPromotionBox">
            <?php echo form_open('gkpos/online/save_promotion/', array('id' => 'promotion_form', 'enctype' => 'multipart/form-data', 'class' => 'form-horizontal')); ?>
            <div id="config_wrapper">
                <fieldset id="config_info">
                    <div class="form-group form-group-sm">	
                        <?php echo form_label('Title', 'gk_name', array('class' => 'control-label col-lg-4 col-md-4 col-sm-4 col-xs-4 text-uppercase required')); ?>
                        <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                            <div class="input-group">
                                <span class="input-group-addon" style="background-color: #FF0000;"><a href="#"><i class="fa fa-table" aria-hidden="true"></i></a></span>
                                <input name="title" class="form-control required"  type="text" id="title" value="<?php isset($title) ? print $title : print'' ?>">
                            </div>
                        </div>
                    </div>

                    <div class="form-group form-group-sm">	
                        <?php echo form_label('Code', 'code', array('class' => 'control-label col-lg-4 col-md-4 col-sm-4 col-xs-4 text-uppercase required')); ?>
                        <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                            <div class="input-group">
                                <span class="input-group-addon" style="background-color: #FF0000;"><a href="#"><i class="fa fa-table" aria-hidden="true"></i></a></span>
                                <input name="code" class="form-control required"  type="text" id="code" value="<?php isset($code) ? print $code : print $promotion_code ?>">
                            </div>
                        </div>
                    </div>
                    <div class="form-group form-group-sm">	
                        <?php echo form_label($this->lang->line('gkpos_amount'), 'amount', array('class' => 'control-label col-lg-4 col-md-4 col-sm-4 col-xs-4 text-uppercase required')); ?>
                        <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                            <div class="input-group">
                                <span class="input-group-addon" style="background-color: #FF0000;"><a href="#"><i class="fa fa-table" aria-hidden="true"></i></a></span>
                                <input name="amount" class="form-control required"  type="text" id="amount" value="<?php isset($amount) ? print $amount : print '' ?>">
                            </div>
                        </div>
                    </div>

                    <div class="form-group form-group-sm">	
                        <label for="radio-inline" class="col-lg-4 col-md-4 col-sm-4 col-xs-4 control-label text-uppercase required"><?php echo $this->lang->line('gkpos_voucher_amount_function') ?></label>
                        <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                            <label class="radio-inline text-uppercase required"><input type="radio" name="function" id="function-percent" value="percent" <?php (isset($function) && $function == "percent") ? print "checked" : '' ?> ><?php echo $this->lang->line('gkpos_percentage') ?></label>
                            <label class="radio-inline text-uppercase required"><input type="radio" name="function" id="function-percent" value="fixed" <?php (isset($function) && $function == "fixed") ? print "checked" : '' ?> ><?php echo $this->lang->line('gkpos_fixed') ?></label>
                        </div>
                    </div>

                    <div class="form-group form-group-sm">	
                        <?php echo form_label($this->lang->line('gkpos_minimum_order'), 'min_order', array('class' => 'control-label col-lg-4 col-md-4 col-sm-4 col-xs-4 text-uppercase required')); ?>
                        <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                            <div class="input-group">
                                <span class="input-group-addon" style="background-color: #FF0000;"><a href="#"><i class="fa" aria-hidden="true"><?php echo $this->config->item('currency_symbol') ?></i></a></span>
                                <input name="min_order" class="form-control required"  type="text" id="amount" value="<?php isset($min_order) ? print $min_order : print '' ?>">
                            </div>
                        </div>
                    </div>
                    <div class="form-group form-group-sm">	
                        <?php echo form_label($this->lang->line('gkpos_start'), 'start', array('class' => 'control-label col-lg-4 col-md-4 col-sm-4 col-xs-4 text-uppercase required')); ?>
                        <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                            <div class="input-group">
                                <span class="input-group-addon" style="background-color: #FF0000;"><a href="#"><i class="fa fa-table" aria-hidden="true"></i></a></span>
                                <input name="start" class="form-control required"  type="text" id="start" value="<?php isset($start) ? print $start : print '' ?>">
                            </div>
                        </div>
                    </div>
                    <div class="form-group form-group-sm">	
                        <?php echo form_label($this->lang->line('gkpos_end'), 'end', array('class' => 'control-label col-lg-4 col-md-4 col-sm-4 col-xs-4 text-uppercase required')); ?>
                        <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                            <div class="input-group">
                                <span class="input-group-addon" style="background-color: #FF0000;"><a href="#"><i class="fa fa-table" aria-hidden="true"></i></a></span>
                                <input name="end" class="form-control required"  type="text" id="end" value="<?php isset($end) ? print $end : print '' ?>">
                            </div>
                        </div>
                    </div>
                    <div class="form-group form-group-sm">	
                        <label for="radio-inline" class="col-lg-4 col-md-4 col-sm-4 col-xs-4 control-label text-uppercase required"><?php echo $this->lang->line('gkpos_status') ?></label>
                        <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                            <label class="radio-inline text-uppercase required"><input type="radio" name="is_opened" id="function-percent" value="1" <?php (isset($is_opened) && $is_opened == "1") ? print "checked" : '' ?> ><?php echo $this->lang->line('gkpos_open') ?></label>
                            <label class="radio-inline text-uppercase required"><input type="radio" name="is_opened" id="function-percent" value="0" <?php (isset($is_opened) && $is_opened == "0") ? print "checked" : '' ?> ><?php echo $this->lang->line('gkpos_close') ?></label>
                        </div>
                    </div>
                    <div class="form-group form-group-sm">	
                        <label for="radio-inline" class="col-lg-4 col-md-4 col-sm-4 col-xs-4 control-label text-uppercase required"><?php echo $this->lang->line('gkpos_where') ?></label>
                        <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                            <label class="radio-inline text-uppercase required"><input type="radio" name="used_as" id="function-percent" value="1" <?php (isset($used_as) && $used_as == "1") ? print "checked" : '' ?> ><?php echo $this->lang->line('gkpos_single_use') ?></label>
                            <label class="radio-inline text-uppercase required"><input type="radio" name="used_as" id="function-percent" value="2" <?php (isset($used_as) && $used_as == "2") ? print "checked" : '' ?> ><?php echo $this->lang->line('gkpos_multiple_use') ?></label>
                        </div>
                    </div>
                    <div class="form-group form-group-sm">	
                        <?php echo form_label($this->lang->line('gkpos_order_type'), '', array('class' => 'text-uppercase control-label col-lg-4 col-md-4 col-sm-4 col-xs-4')); ?>
                        <div class='col-lg-2 col-md-2 col-sm-2 col-xs-2 text-uppercase'style="margin-top: 5px;">
                            <input type="checkbox" name='delivery' class="checkbox-inline"  value='yes' <?php isset($delivery) && $delivery == 'yes' ? print'checked="true"' : '' ?>>
                            <span class="discount-lebel"><?php echo $this->lang->line('gkpos_delivery') ?></span>
                        </div>
                        <div class='col-lg-2 col-md-2 col-sm-2 col-xs-2 text-center text-uppercase' style="margin-top: 5px;">
                            <input type="checkbox" name='collection' class="checkbox-inline"  value='yes' <?php isset($collection) && $collection == 'yes' ? print'checked="true"' : '' ?>>
                            <span class="discount-lebel"><?php echo $this->lang->line('gkpos_collection') ?></span>
                        </div>
                    </div>
                    <div class="form-group form-group-sm">	
                        <?php echo form_label($this->lang->line('gkpos_discount_applied'), '', array('class' => 'text-uppercase control-label col-lg-4 col-md-4 col-sm-4 col-xs-4 required')); ?>
                        <div class='col-lg-2 col-md-2 col-sm-2 col-xs-2 text-uppercase'style="margin-top: 5px;">
                            <input type="checkbox" name='food' class="checkbox-inline"  value='yes' <?php isset($food) && $food == 'yes' ? print'checked="true"' : '' ?>>
                            <span class="discount-lebel"><?php echo $this->lang->line('gkpos_food') ?></span>
                        </div>
                        <div class='col-lg-2 col-md-2 col-sm-2 col-xs-2 text-center text-uppercase' style="margin-top: 5px;">
                            <input type="checkbox" name='nonfood' class="checkbox-inline"  value='yes' <?php isset($nonfood) && $nonfood == 'yes' ? print'checked="true"' : '' ?>>
                            <span class="discount-lebel"><?php echo $this->lang->line('gkpos_non_food') ?></span>
                        </div>
                    </div>

                    <div class="form-group form-group-sm">	
                        <label for="radio-inline" class="col-lg-4 col-md-4 col-sm-4 col-xs-4 control-label text-uppercase required"><?php echo $this->lang->line('gkpos_allow_cross_promotion') ?></label>
                        <div class="col-lg-8 col-md-8 col-sm-8 col-xs-8">
                            <label class="radio-inline text-uppercase required"><input type="radio" name="allow_cross" id="function-percent" value="1" <?php (isset($used_as) && $used_as == "1") ? print "checked" : '' ?> ><?php echo $this->lang->line('gkpos_yes') ?></label>
                            <label class="radio-inline text-uppercase required"><input type="radio" name="allow_cross" id="function-percent" value="0" <?php (isset($used_as) && $used_as == "0") ? print "checked" : '' ?> ><?php echo $this->lang->line('gkpos_no') ?></label>
                        </div>
                    </div>

                    <div class="form-group form-group-md">	
                        <div class="col-md-offset-4 col-md-8">
                            <ul id="promotion_error_message_box" class="error_message_box"></ul>
                            <?php
                            echo form_submit(array(
                                'name' => 'submit_form',
                                'id' => 'submit_form',
                                'value' => $this->lang->line('gkpos_numpad_key_enter'),
                                'class' => 'form-submit-button mainsystembg2 waiting-bg img-responsive delivery-info-submit-btn'));
                            ?>
                        </div>
                    </div>
                </fieldset>
            </div>
            <?php echo form_close(); ?>
            <script type='text/javascript'>
                $(document).ready(function () {
                    $("#start").datepicker({
                        dateFormat: "dd/mm/yy"
                    });
                    $("#end").datepicker({
                        dateFormat: "dd/mm/yy"
                    });
                    $('#promotion_form').validate({
                        submitHandler: function () {
                            var myform = document.getElementById('promotion_form');
                            var formdata = new FormData(myform);
                            $.ajax({
                                url: $('#promotion_form').attr('action'),
                                data: formdata,
                                cache: false,
                                processData: false,
                                contentType: false,
                                type: 'POST',
                                dataType: 'json',
                                success: function (response) {
                                    if (response.success) {
                                        getSettingPage('<?php echo site_url('gkpos/online/promotion') ?>', 'Online - promotion');
                                    } else {
                                        alert(response.message);
                                    }
                                }
                            });
                        },
                        errorClass: "has-error",
                        errorLabelContainer: "#promotion_error_message_box",
                        wrapper: "li",
                        highlight: function (e) {
                            $(e).closest('.form-group').addClass('has-error');
                        },
                        unhighlight: function (e) {
                            $(e).closest('.form-group').removeClass('has-error');
                        },
                        rules: {
                            title: "required",
                            code: "required",
                            amount: {
                                number: true,
                                required: true
                            },
                            function: "required",
                            min_order: {
                                number: true,
                                required: true
                            },
                            is_opened: "required",
                            used_as: "required",
                            start: "required",
                            end: "required",
                            allow_cross: 'required'
                        },
                        messages: {
                            title: "Promotion title is a required field",
                            code: "Please specify promotional code",
                            amount: "Amount is required field",
                            function: 'amount function is required',
                            min_order: 'Minimum order amount to apply this promotional offer',
                            is_opened: 'Please specify promotion status',
                            used_as: 'Please specify terms single or multiple use',
                            start: 'Please specify promotion start date',
                            end: 'Please specify promotion end date',
                            allow_cross: 'Is cross promotion allowed?'
                        }
                    });
                });
            </script>
        </div>
        <div class="row voucher-list" style="margin: 10px">
            <div class="modal-header">
                <div class="page-title col-md-12"><?php echo 'Promotion List' ?></div>
            </div>
            <div class="clearfix"></div>
            <table class="table table-responsive table-bordered fieldset">
                <tr>
                    <th class="text-center text-uppercase"><?php echo "Title" ?></th> 
                    <th class="text-center text-uppercase"><?php echo"Code" ?></th> 
                    <th class="text-center text-uppercase"><?php echo "Amount" ?></th> 
                    <th class="text-center text-uppercase"><?php echo "Col" ?></th> 
                    <th class="text-center text-uppercase"><?php echo "Del" ?></th> 
                    <th class="text-center text-uppercase"><?php echo "Used As" ?></th> 
                    <th class="text-center text-uppercase"><?php echo "Food" ?></th> 
                    <th class="text-center text-uppercase"><?php echo "Non Food" ?></th> 
                    <th class="text-center text-uppercase"><?php echo "Allow Cross" ?></th> 
                    <th class="text-center text-uppercase"><?php echo $this->lang->line('gkpos_action') ?></th> 
                </tr>
                <?php if (!empty($voucher_list)): ?>
                    <?php //debugPrint($voucher_list) ?>
                    <?php foreach ($voucher_list as $voucher): ?> 
                        <tr>
                            <td class="text-center"><?php echo $voucher->title ?></td> 
                            <td class="text-center"><?php echo $voucher->code ?></td> 
                            <td class="text-center"><?php $voucher->function == 'fixed' ? print to_currency($voucher->amount) : print to_tax_decimals($voucher->amount) . '&percnt;' ?></td> 
                            <td class="text-center"><?php echo $voucher->collection == 'yes' ? 'YES' : 'NO' ?></td>
                            <td class="text-center"><?php echo $voucher->delivery == 'yes' ? 'YES' : 'NO' ?></td> 
                            <td class="text-center"><?php echo $voucher->used_as != '2' ? 'Multiple' : 'Single' ?></td>
                            <td class="text-center"><?php echo $voucher->food == 'yes' ? 'YES' : 'NO' ?></td> 
                            <td class="text-center"><?php echo $voucher->nonfood == 'yes' ? 'YES' : 'NO' ?></td> 
                            <td class="text-center"><?php echo $voucher->allow_cross == 1 ? 'YES' : 'NO' ?></td> 
                            <td class="text-center">
                                <a href='javascript:void(0)' onclick="updatePromotion('<?php echo $voucher->id ?>', '<?php echo site_url('gkpos/online/update_promotion') ?>', '<?php $voucher->status == 1 ? print'deactivate' : print 'activate' ?>')"><?php $voucher->status == 1 ? print'Deactivate' : print 'Activate' ?> </a>
                                |
                                <a href='javascript:void(0)' onclick="updatePromotion('<?php echo $voucher->id ?>', '<?php echo site_url('gkpos/online/update_promotion') ?>', 'delete')">Delete</a> 
                            </td> 
                        </tr>
                    <?php endforeach; ?>
                <?php else: ?>
                    <tr>
                        <td colspan="4">No Vouchers found</td> 
                    </tr>
                <?php endif; ?>
            </table>                        
        </div>
    </div>
</div>
<script>
    $(document).ready(function () {
        if ($('#showHideAddPromotion').is(":checked")) {
            $('#AddNewPromotionBox').show();
        } else {
            $('#AddNewPromotionBox').hide();
        }
    });
    function updatePromotion(voucher_id, url, action) {
        $.ajax({
            url: url,
            data: {
                id: voucher_id,
                action: action
            },
            type: "POST",
            success: function (output) {
                getSettingPage('<?php echo site_url("gkpos/online/promotion") ?>', 'Online - Promotion');
            },
        });
    }
</script>