<div class="wrapper">
    <div class="container">
        <!-- Page-Title -->
        <div class="row">
            <div class="col-sm-12">
                <h4 class="page-title">Edit Coupon Category:</h4>
            </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">Coupon Category:</h4>
                    <form method="post" action="<?php echo base_url();?>coupon_controller/update_coupon_category">
                        <input type="hidden" name="csrf_test_name" id="coupon_csrf" value=""/>
                        <div class="form-group">
                            <div class="row m-t-20">
                                <div class="col-md-6">
                                    <label class="form-label">Coupon Category Title</label>
                                    <input class="form-control" name="coupon_category" value = "<?php echo $coupon_category->coupon_category ;?>">
                                </div>
                                
                                <div class="col-md-6">
                                    <label class="form-label">Category Type</label>
                                    <select class="form-control" name="coupon_type">
                                        <option <?php if($coupon_category->coupon_type =='service'){echo 'selected="selected"';}?> value="service">Discount on Services</option>
                                        <option <?php if($coupon_category->coupon_type =='invoice'){echo 'selected="selected"';}?> value="service">Discount on Invoice</option>
                                    </select>
                                </div>
                                
                            </div>
                            <div class="row m-t-20">
                               <div class="col-md-6">
                                    <label class="form-label">Category Prefix</label>
                                    <input class="form-control" name="coupon_category_prefix" value = "<?php echo $coupon_category->coupon_category_prefix ;?>">
                                </div>
                            
                               <div class="col-md-6">
                                    <label class="form-label">Category Discount %</label>
                                    <input class="form-control" type="number" step="0.1" min="1" max="100" name="discount_perc" value = "<?php echo $coupon_category->discount_perc ;?>">
                                </div>
                            
                            </div>  
                            <div class="row m-t-20">
                               <div class="col-md-6">
                                    <label class="form-label">Category Description</label>
                                    <textarea class="form-control" name="coupon_category_desc"><?php echo $coupon_category->coupon_category ;?></textarea>
                                </div>
                                
                                 <div class="col-md-6">
                                    <div class="btn-group pull-right m-t-15">
                                        
                                        <a href="<?php echo base_url();?>coupon_category" class="btn waves-effect waves-light btn-default m-t-20">Back</a>
                                        <button onclick="$('#coupon_csrf').val($('#cook').val());" class="btn waves-effect waves-light btn-pink m-t-20">Save</button>
                                    </div>
                                </div>
                            </div>  
                            
                        </div>
                    </form>
                </div>
            </div>
        </div>  
        <?php if($coupon_category->coupon_type =='service'){ ?>
         <div class="row" id="divservices">
            <div class="col-sm-12">
                <div class="card-box ">
                    <h4 class="header-title m-t-0 m-b-30">Services that these coupons can be used on:</h4>
                    
                    <div class="row">
                        <form method="POST" action="<?php echo base_url().'coupon_controller/update_services';?>"
                        <div class="col-md-12">
                            <div class="col-lg-4">
                                <div class="form-group">
                                    <label for="unselected" class="control-label">Services</label>
                                    <select class="form-control" name="unselected" id="unselected" multiple="multiple">
                                        <?php 
                                        if(isset($services)){
                                        foreach ($services as $service){
                                        ?>
                                        <option value="<?php echo $service['id_business_services']; ?>">
                                            <?php echo $service['service_name']; ?>
                                        </option>
                                        <?php }} ?>
                                    </select>
                                </div> 
                            </div>
                            <div class="col-lg-4" style="vertical-align: center; text-align: center;">
                                <label for="drag" class="control-label m-t-40">&nbsp;</label>
                                <i class="fa fa-arrow-right" style="font-size: 24px;"></i>
                            </div>
                            <div class="col-lg-4">
                                <div class="form-group">
                                    <label for="selected" class="control-label">Selected Services</label>
                                    <select class="form-control" name="services[]" id="selected" multiple="multiple">
                                        <?php if(isset($category_services)){?>
                                            <?php foreach($category_services as $service){?>
                                            <option value="<?php echo $service['service_id']; ?>">
                                                <?php echo $service['service_name']; ?>
                                            </option>
                                            <?php } ?>
                                        <?php } ?>
                                    </select>
                                </div> 
                            </div>
                        
                        <div class="col-md-12">
                            <div class="btn-group pull-right m-t-15">
                                <input type="hidden" name="category_id" value = "<?php echo $coupon_category->id_coupon_category ;?>">
                                <button style="float: right;"  class="btn waves-effect waves-light btn-pink m-t-20">Update Services List</button>
                            </div>
                        </div>
                    </form>
                    </div>
                </div>    
                    
                </div>
                
            </div>

        <?php } ?>
             <div class="row" id="divcoupons">
                <div class="col-sm-12">
                    <div class="card-box ">
                        <form method="POST" action="<?php echo base_url();?>coupon_controller/generate_sequence">
                        <h4 class="header-title m-t-0 m-b-30">Generate Coupon Sequence in <?php echo $coupon_category->coupon_category ;?>:</h4>

                        <div class="row">
                            
                            <div class="col-md-4">
                                <div class="form-group">
                                    <lable for="min" class="form-label">Starting</lable>
                                    <input class="form-control" name="min" id="min" value="<?php echo $coupon_listing->min; ?>" readonly="readonly">
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <lable for="max" class="form-label">Ending</lable>
                                    <input class="form-control" name="max" id="min" value="<?php echo $coupon_listing->max; ?>" readonly="readonly">
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <lable for="total" class="form-label">Total coupons in already Existing Seq</lable>
                                    <input class="form-control" name="total" id="total" value="<?php echo $coupon_listing->total; ?>" readonly="readonly">
                                </div>
                            </div>
                            
                        </div>
                        <div class="row">
                            
                            <div class="col-md-4">
                                <div class="form-group">
                                    <lable for="total" class="form-label">Generate Seq for how many coupons:</lable>
                                    <input class="form-control" type="number" step="1" min="10" max="5000" name="seq" id="seq" value="10">
                                </div>
                            </div>
                            <div class="col-md-2">
                                <div class="form-group">
                                    <lable for="total" class="form-label">Seq will start from:</lable>
                                    <input class="form-control" name="starting" id="starting" value="<?php echo $coupon_listing->starting;?>">
                                </div>
                            </div>
                            <div class="col-md-4">
                                <div class="form-group">
                                    <lable for="total" class="form-label">Coupons will Expire on:</lable>
                                    <input class="form-control" name="validity" id="validity" value="">
                                </div>
                            </div>
                            <div class="col-md-2">
                                    <input type="hidden" name="category_prefix" value = "<?php echo $coupon_category->coupon_category_prefix ;?>">
                                    <input type="hidden" name="cateogry_id" value="<?php echo $coupon_category->id_coupon_category ;?>">
                                    <input type="hidden" name="cateogry" value="<?php echo $coupon_category->coupon_category ;?>">
                                    <button type=submit" class="btn btn-primary m-t-20" id="generate" >Go</button>
                                
                            </div>
                        </div>
                        </form>
                    </div>
                </div>
            </div>
         </div>        
        
        
    </div>
</div>


<script type="text/javascript">
    $(document).ready(function() {
        <?php 
        $givendate = date('Y-m-d');
        $next_month = date('Y-m-d', strtotime($givendate. ' + 1 month'));?>
        
        $('#validity').datepicker({
            default: '<?php echo $next_month; ?>',
            autoclose: true,
            todayHighlight: true,
            format: 'yyyy-mm-dd'
        }).datepicker('setDate', new Date());
        
        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;
            }
        });
        
        
        //Two Select box for products insert moving....Start
                $('#unselected').on('change', function() {
                    var val1 = $("#unselected option:selected").val();
                    var txt1 = $("#unselected option:selected").text();
                    
                    
                    $('#selected option').each(function() {
                        if($(this).attr('value') == val1){
                            alert("already exist!");die;
                        }
                    });
                    
                    $('#selected').append('<option selected value="'+val1+'">'+txt1+'</opiton>');
     
                });
                $('#selected').on('click', function() {
                    $("#selected option:selected").remove();
                    $('#selected').find('option').prop('selected',true);
                });
                //Two Select box for products insert moving....End
    });

</script>