<?php 

$config = array('role' =>'form', 'class'=>'form-horizontal','id'=>'create_category_form', 'name'=>'create_category_form');

echo form_open_multipart(base_url("#"),$config);

?>

<?php //print_r($discount_details) ?>

            <div class="modal-header">

            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>

            <h4 class="modal-title">Discount Manage (Brokers)</h4>

            <font style="color:#333;">Please fill in the information below. The field labels marked with * are required input fields.</font>

            </div>

            <div class="modal-body">

                <div id="error"></div>

            <div class="row form-group">

             <div class="col-md-12">

                    <h5>Discount start range *</h5>
                    <p>
                    <input type="hidden" value="<?php $retVal = (isset($discount_details)) ? $discount_details['pd_discount_id'] : NULL ; echo $retVal; ?>" name="dicount_tble_id" id="dicount_tble_id">
                    <input type="number" class="form-control" value="<?php $retVal = (isset($discount_details)) ? $discount_details['start_range_value'] : NULL ; echo $retVal; ?>" name="start_ds" id="start_ds">
                    </p>
                    <h5>Discount end range*</h5>
                    <p>
                    <input type="number" class="form-control" name="end_ds" id="end_ds" value="<?php $retVal = (isset($discount_details)) ? $discount_details['end_range_value'] : NULL ; echo $retVal; ?>">
                    </p>
                    <h5>Discount *</h5>
                    <p>
                     <input type="number" class="form-control" name="discount" id="discount" value="<?php $retVal = (isset($discount_details)) ? $discount_details['discount_value'] : NULL ; echo $retVal; ?>">
                    </p>
                     <p>
                    <select class="form-control" id="is_precentage" name="is_precentage"> <option <?php if(isset($discount_details['is_precentage'])){if($discount_details['is_precentage']==0){echo "selected";}} ?> value="0"> AS VALUE</option><option <?php if(isset($discount_details['is_precentage'])){if($discount_details['is_precentage']==1){echo "selected";}} ?> value="1"> AS PRECENTAGE</option></select>
                    </p>

            <div class="modal-footer">
            <input type="submit" name="add_category" value="<?php $retVal = (isset($discount_details)) ? "Update Discount" : "Add Discount" ; echo $retVal; ?>" class="btn btn-primary">
            </div>
            </div>
            </div>
            </div>
  </form>
		<!-- start: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY VALIDATION-->
		<script src="<?php echo asset_url(); ?>js/form-validation-create_category.js"></script>
		<!-- end: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY  VALIDATION-->

			<script>

			jQuery(document).ready(function() {

				FormValidator.init();

			});

        function add_category(form) {
            var category_id = $("input#dicount_tble_id").val();
            if (category_id!="") {
                $('body').modalmanager('loading');
                setTimeout(function () {
                    $.ajax({
                    url: "<?php echo base_url('broker/update_discount'); ?>", // Url to which the request is send
                    type: "POST",             // Type of request to be send, called as method
                    data: new FormData(form), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
                    contentType: false,       // The content type used when sending data to the server.
                    cache: false,             // To unable request pages to be cached
                    processData:false,        // To send DOMDocument or non processed data file it is set to false
                        success: function(data)   // A function to be called if request succeeds
                        {
                            var obj = jQuery.parseJSON(data);
                            if (obj.status==0) 
                               {
                                    $('div#error').html('<div class="alert alert-block alert-danger fade in"><button type="button" class="close" data-dismiss="alert">×</button><h4 class="alert-heading"><i class="fa fa-times-circle"></i> Error!</h4>'+obj.validation+'</div>');
                                    $('body').modalmanager('removeLoading');
                                } 
                               else
                                {
                                   $('body').modalmanager('removeLoading');
                                    $('div#ajax-modal').modal('hide');
                                    set_message('categories notice!','Category successfully updated');
									location.reload(true);
                               };
                        }
                    });
                }, 1000);
            } else{
                    $('body').modalmanager('loading');
                    setTimeout(function () {
                        $.ajax({
                        url: "<?php echo base_url('broker/update_discount'); ?>", // Url to which the request is send
                        type: "POST",             // Type of request to be send, called as method
                        data: new FormData(form), // Data sent to server, a set of key/value pairs (i.e. form fields and values)
                        contentType: false,       // The content type used when sending data to the server.
                        cache: false,             // To unable request pages to be cached
                        processData:false,        // To send DOMDocument or non processed data file it is set to false
                        success: function(data)   // A function to be called if request succeeds
                        {
                            var obj = jQuery.parseJSON(data);
                            if (obj.status==0) 
                                {
                                    $('#error').html('<div class="alert alert-block alert-danger fade in"><button type="button" class="close" data-dismiss="alert">×</button><h4 class="alert-heading"><i class="fa fa-times-circle"></i> Error!</h4>'+obj.validation+'</div>');
                                    $('body').modalmanager('removeLoading');
                                } 
                                else
                                {
                                    $('body').modalmanager('removeLoading');
                                    $('div#ajax-modal').modal('hide');
                                    set_message('categories notice!','Category successfully added');
                                    category_load();
                                };
                       }
                        });
                    }, 1000);
                };
        }



		</script>          

