		
<style type="text/css">

    body .modal {
        /* new custom width */
        width: 750px;
        /* must be half of the width, minus scrollbar on the left (30px) */
        margin-left: -375px;
    }

</style>

<form role="form" class="form-horizontal" id="create_salary_pay_form" action="#" method="post">
    <input type="hidden" value="<?php echo $type; ?>" name="type" id="type"/>
    <input type="hidden" value="<?php echo $salary_pay_id; ?>" name="salary_pay_id" id="salary_id"/>
    <form role="form" class="form-horizontal" id="create_salary_pay_form" action="#">

        <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
            <h4 class="modal-title"><?php echo $pageName ?></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">
                <div class="col-md-12">
                    <div class="col-md-5">
                        <div class="form-group">
                            <h5>User *</h5>
                            <input type="hidden"  name="user_id" class="js-data-user-ajax form-control" style="padding:0px 0px; border: none; box-shadow: none" placeholder="-Select User-" />
                        </div>
                        <div class="form-group">
                            <h5>Amount*</h5>
                            <input type="text" class="form-control" name="sp_amount" id="sp_amount" <?php echo (isset($salary_pay_byid['sp_amount'])) ? 'value="' . $salary_pay_byid['sp_amount'] . '"' : null; ?>>
                        </div>


                    </div>
                    <div class="col-md-5 pull-right">
                        <div class="form-group">
                            <h5>Salary Date*</h5>
                            <?php $nowdate = date("Y-m-d H:i:s"); ?>
                            <input id="sp_date" name="sp_date" type='text' class="form-control date" value="" data-bv-field="date"  /> 
                        </div>
                        
                        <div class="form-group">
                            <h5>Is Advance *</h5>
                            
                            <input type="radio"  name="sp_is_sal_advance" value="1"  <?php if(isset($salary_pay_byid['sp_is_sal_advance']) && $salary_pay_byid['sp_is_sal_advance'] == 1){echo 'checked';} else{echo 'checked';} ?>/>Advance
                            <input type="radio"  name="sp_is_sal_advance" value="0"  <?php if(isset($salary_pay_byid['sp_is_sal_advance'])){if($salary_pay_byid['sp_is_sal_advance'] == 0){echo 'checked';}} ?>/>Salary
                        </div>
                        



                        <div class="form-group">
                            <h5>Salary Note*</h5>
                            <textarea class="form-control" rows="3" name="sp_note" id="sl_note" ><?php echo (isset($salary_pay_byid['sp_note'])) ? $salary_pay_byid['sp_note'] : null; ?></textarea>
                        </div>
                    </div>

                </div> <!--col-md-12-->
            </div>
            <div class="modal-footer">
                <input id="add_category" type="submit" name="add_category"  value="<?php echo $btnText; ?>" class="btn btn-primary">
            </div>
    </form>
    <!-- start: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY VALIDATION -->
    <script src="<?php echo base_url(); ?>thems/js/form-validation-salary-payment.js"></script>
    <!-- end: JAVASCRIPTS REQUIRED FOR THIS PAGE ONLY  VALIDATION-->


    <script type="text/javascript">
        jQuery(document).ready(function () {
        FormValidator.init();
        });
        function insertSalaryPayData() {
			  $("#add_category").prop("disabled", true);
		  	  $("#add_category").val('Please wait...');
			  
        var fields = $('#create_salary_pay_form').serialize();
        $.post("<?php echo base_url('salary_payment/save_salary_payment'); ?>", fields)
                .done(function (data) {

                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');
                $('body').attr('class', '');
                } else {
               
              //  loadGrid(); // load customer data
                if (obj.type == 'E') {
                     $('div#ajax-modal').modal('hide');
                displayNotice('page', 'Salary Payment has been updated successfully!');
                location.reload(true);
                }
                if (obj.type == 'A') {
                displayNotice('page', 'Salary Payment has been added successfully!');
                
                 $("#add_category").prop("disabled", false);
		  	  $("#add_category").val('Add Salary Payment');
		  	   $("#sp_amount").val('');
		  	    $('.js-data-user-ajax').select2('data', {id: '', text: '-Select User-'});
		  	    
		  	    
        
		  	 // $('#user_id').select2('focus');
		  	  //  $('#user_id').focus(); 
		  	   
               // location.reload(true);
               loadGrid();
                }
                }


                });
        return false;
        }
        $(':checkbox').on('change', function () {
        $(':checkbox').not(this).prop('checked', false);
        });
    </script>

    <script>
       
        $(".js-data-user-ajax").select2({
        ajax: {
        url: "<?php echo base_url('salary/getUser') ?>",
                dataType: 'json',
                delay: 250,
                data: function (query) {
                if (!query)
                        query = '';
                return {
                search_string: query,
                        format: 'json'
                };
                },
                results: function (data) {
                return {
                results: $.map(data, function (item) {
                var text1 = item.user_first_name + "  (" + item.user_group_name + ")";
                return {
                text: text1,
                        slug: item.user_first_name,
                        id: item.user_id
                };
                })
                };
                },
                cache: true
        }
        });
    </script>

    <script>
        $('#sp_date').datetimepicker({
        format: 'YYYY-MM-DD',
<?php
if (isset($salary_pay_byid['sp_date'])) {
    $d = date("Y, m-1, d", strtotime($salary_pay_byid['sp_date'])); //(1985,01,01)
    ?>
            defaultDate: new Date (<?php echo $d ?>)
<?php } else { ?>
            defaultDate: new Date()
<?php } ?>

        //defaultDate: new Date()

        });
    </script>

    <!--  set value for searchable dropdown if update     -->
    <?php if (isset($salary_pay_id) && $salary_pay_id != 0) { ?>
        <script>
            $('.js-data-user-ajax').select2('data', {id: '<?php echo $salary_pay_byid['user_id'] ?>', text: '<?php echo $salary_pay_byid['user_first_name']." (".$salary_pay_byid['user_group_name'].")" ?>'});
        </script>
    <?php } ?>
    
