<form class="form-horizontal" id="user_basic_data">
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="col-lg-6">
                <div class="form-group">
                    <label class="col-lg-3 control-label" style="text-align: left;">Amount</label>
                    <div class="col-lg-8">
                        <input placeholder="Name" class="form-control pull-left name" type="text" name="name" value="<?php echo !empty($user_details->name) ? $user_details->name : '';?>"> 
                        <!-- <span class="help-block m-b-none">Example block-level help text here.</span> -->
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-3 control-label" style="text-align: left;">Payment Date</label>
                    <div class="col-lg-8">
                        <input placeholder="Email" class="form-control pull-left contact_email" type="email" name="contact_email" value="<?php echo !empty($user_details->contact_email) ? $user_details->contact_email : '';?>">
                    </div>
                </div>
                <div class="form-group">
                    <label class="col-lg-3 control-label" style="text-align: left;">Payment Mode</label>
                    <div class="col-lg-8">
                        <input placeholder="Phone" class="form-control pull-left contact_phone" type="text" name="contact_phone" value="<?php echo !empty($user_details->contact_phone) ? $user_details->contact_phone : '';?>">
                    </div>
                </div>
				<div class="form-group">
                    <label class="col-lg-3 control-label" style="text-align: left;">Reference#</label>
                    <div class="col-lg-8">
                        <input placeholder="Display Name" class="form-control pull-left contact_display_name" type="text" name="contact_display_name" value="<?php echo !empty($user_details->contact_display_name) ? $user_details->contact_display_name : '';?>">
                    </div>
                </div>
                               
            </div>
            <div class="col-lg-6">
                
            </div>
        </div>
    </div>

    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <!-- ================================== BiLLING INFO ====================================================-->
            <div class="col-lg-12">
			
			
				<div class="ibox-content">

                        <table class="table">
                            <thead>
                            <tr>
                                <th>Date</th>
                                <th>Bill#</th>
                                <th>Bill Amount</th>
                                <th>Amount Due</th>
								<th>Payment</th>
                            </tr>
                            </thead>
                            <tbody>
                            <tr>
                                <td>07/07/17 <br/>Due Date: 07/07/17</td>
                                <td>INV-000003</td>
                                <td>25000</td>
                                <td>25000</td>
								<td><input type="checkbox" name="" value="" /></td>
                            </tr>
							<tr>
                                <td>07/07/17 <br/>Due Date: 07/07/17</td>
                                <td>INV-000003</td>
                                <td>25000</td>
                                <td>25000</td>
								<td><input type="checkbox" name="" value="" /></td>
                            </tr>
                           
                            </tbody>
                        </table>

                </div>
			
                
            </div>

            <!-- ================================== SHIPPING INFO ====================================================-->
           
        </div>
    </div>
    <div class="ibox float-e-margins">
        <div class="ibox-content">
            <div class="form-group">
                <div class="col-lg-3">
                    <button class="btn btn-sm btn-primary pull-right m-t-n-xs save_userData" type="submit"><strong>Save</strong></button>
					<button class="btn btn-sm btn-primary pull-right m-t-n-xs save_userData" type="submit"><strong>Cancel</strong></button>
                </div>
            </div>
        </div>
    </div>
</form>
<script type="text/javascript">
    $(document).ready(function () {
        $('.i-checks').iCheck({
            checkboxClass: 'icheckbox_square-green'
        });

        $('.has_gst').on('ifChecked', function(){
            $(this).val('1');
            $('.gstn_block').removeClass('hide');
        });

        $('.has_gst').on('ifUnchecked', function(){
            $(this).val('0');
           $('.gstn_block').addClass('hide'); 
        });

        $('.same_billing_shipping').on('ifChecked', function(){
            $(this).val('1');
            $("#shipping_block :input").attr("disabled", true);
        });

        $('.same_billing_shipping').on('ifUnchecked', function(){
            $(this).val('0');
           $("#shipping_block :input").attr("disabled", false);
        });

        
        $( "#user_basic_data" ).on( "submit", function( event ) {
            event.preventDefault();
            
            if ($('.name').val() == '') {
                $('.name').parent().parent().addClass('has-error');
                return false;
            } else {
                $('.name').parent().parent().removeClass('has-error');
            }

            if ($('.company_name').val() == '') {
                $('.company_name').parent().parent().addClass('has-error');
                return false;
            } else {
                $('.company_name').parent().parent().removeClass('has-error');
            }

            if ($('.contact_display_name').val() == '') {
                $('.contact_display_name').parent().parent().addClass('has-error');
                return false;
            } else {
                $('.contact_display_name').parent().parent().removeClass('has-error');
            }

            if ($('.contact_email').val() == '') {
                $('.contact_email').parent().parent().addClass('has-error');
                return false;
            } else {
                $('.contact_email').parent().parent().removeClass('has-error');
            }

            if ($('.contact_phone').val() == '') {
                $('.contact_phone').parent().parent().addClass('has-error');
                return false;
            } else {
                $('.contact_phone').parent().parent().removeClass('has-error');
            }

            if ($('.contact_website').val() == '') {
                $('.contact_website').parent().parent().addClass('has-error');
                return false;
            } else {
                $('.contact_website').parent().parent().removeClass('has-error');
            }   
            
            // if ($('.has_gst').val() == '') {
            //     $('.has_gst').parent().parent().addClass('has-error');
            //     return false;
            // } 

            if (($('.has_gst').val() == 1) && ($('.gstn').val() == '')) {
                $('.gstn').parent().parent().addClass('has-error');
                return false;
            } else {
                $('.gstn').parent().parent().removeClass('has-error');
            }  

            if ($('.contact_type').val() == '') {
                $('.contact_type').parent().parent().addClass('has-error');
                return false;
            } else {
                $('.contact_type').parent().parent().removeClass('has-error');
            }   

            var user_id = '<?php echo $user_id;?>';

            var name = $('.name').val();
            var company_name = $('.company_name').val();
            var contact_display_name = $('.contact_display_name').val();
            var contact_email = $('.contact_email').val();
            var contact_phone = $('.contact_phone').val();
            var contact_website = $('.contact_website').val();
            var has_gst = $('.has_gst').val();
            var gstn = $('.gstn').val();
            var contact_type = $('.contact_type').val();

            var billing_address = $('.billing_address').val();
            var billing_city = $('.billing_city').val();
            var billing_state = $('.billing_state').val();
            var billing_zip = $('.billing_zip').val();
            var billing_country = $('.billing_country').val();
            var billing_fax = $('.billing_fax').val();
            
            var same_address = $('.same_billing_shipping').val();
            var shipping_address = ($('.same_billing_shipping').val() == 1) ? billing_address : $('.shipping_address').val();
            var shipping_city = ($('.same_billing_shipping').val() == 1) ? billing_city : $('.shipping_city').val();
            var shipping_state = ($('.same_billing_shipping').val() == 1) ? billing_state : $('.shipping_state').val();
            var shipping_zip = ($('.same_billing_shipping').val() == 1) ? billing_zip : $('.shipping_zip').val();
            var shipping_country = ($('.same_billing_shipping').val() == 1) ? billing_country : $('.shipping_country').val();
            var shipping_fax = ($('.same_billing_shipping').val() == 1) ? billing_fax : $('.shipping_fax').val();
            
            $.ajax({
                url: '<?php echo site_url('user/save_basic_info');?>',
                type: "POST",
                data:{
                    user_id : user_id,
                    name : name,
                    company_name : company_name,
                    contact_display_name : contact_display_name,
                    contact_email : contact_email,
                    contact_phone : contact_phone,
                    contact_website : contact_website,
                    has_gst : has_gst,
                    gstn : gstn,
                    contact_type : contact_type,
                    same_address : same_address,
                    billing_address : billing_address,
                    billing_city : billing_city,
                    billing_state : billing_state,
                    billing_zip : billing_zip,
                    billing_country : billing_country,
                    billing_fax : billing_fax,
                    shipping_address : shipping_address,
                    shipping_city : shipping_city,
                    shipping_state : shipping_state,
                    shipping_zip : shipping_zip,
                    shipping_country : shipping_country,
                    shipping_fax : shipping_fax
                },
                success: function(html){ 
                    console.log('saved');
                }
            });

        });

    });
</script>