<?php  include "header.php"; ?>

<?php
$id = $_GET['id'];
$statement = $pdo->prepare("SELECT * FROM tbl_customers  WHERE tbl_customers.id=?");
$statement->execute(array($id));
$emp_data = $statement->fetchAll(PDO::FETCH_ASSOC);
$totalData = $statement->rowCount();


if($totalData==1){
    foreach($emp_data as $data){
     
        $customer_name = $data['customer_name'];
        $mobile_no = $data['mobile_no'];
        $alter_mobile_no = $data['alter_mobile_no'];
        $gender = $data['gender'];
        $religion = $data['religion'];
        $address = $data['address'];
        $city = $data['city'];
        $dob = $data['dob'];
        $wedding_date = $data['wedding_date'];
        
        
        $wedding_date = $data['wedding_date'];
        $pan_no = $data['pan_no'];
        $aadhaar_no = $data['aadhaar_no'];
        $gst_no = $data['gst_no'];
        
        $driving_no = $data['driving_no'];
        $voter_no = $data['voter_no'];
        $others_no = $data['others_no'];
        $nominee_name = $data['nominee_name'];
        $nominee_mobile_no = $data['nominee_mobile_no'];
        $nominee_address = $data['nominee_address'];
        $nominee_type = $data['nominee_type'];
        $remarks = $data['remarks'];
        $pincode = $data['pincode'];
        $state = $data['state'];
      

    
?>
<div class="content-wrapper">
        <section class="content-header">
            <h1>Update Customers</h1>
            <ol class="breadcrumb">
                <li><a href="index.php"><i class="fa fa-dashboard"></i> Home</a></li>
                <li class="active">Update Customers</li>            
            </ol>
        </section>


        <div class="col-lg-12 alerts">
            <div id="custom-alerts" style="display:none;">
                <div class="alert alert-dismissable">
                    <div class="custom-msg"></div>
                </div>
            </div>
            
            <?php if ($error)  { ?>
            <div class="alert alert-danger alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4><i class="icon fa fa-ban"></i> Error</h4>
                <?= $error; ?>
            </div>
            <?php $error=0;} if ($warning) { ?>
            <div class="alert alert-warning alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4><i class="icon fa fa-warning"></i> Warning</h4>
                <?= $warning; ?>
            </div>
            <?php  $warning=0;} if ($message) { ?>
            <div class="alert alert-success alert-dismissable">
                <button aria-hidden="true" data-dismiss="alert" class="close" type="button">×</button>
                <h4>    <i class="icon fa fa-check"></i> Success</h4>
                <?= $message; ?>
            </div>
            <?php $message=0; } ?>
        </div>
        <div class="clearfix"></div>







<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box box-primary" style="box-shadow: rgba(0, 0, 0, 0.16) 0px 3px 6px, rgba(0, 0, 0, 0.23) 0px 3px 6px;">
                <!--<div class="box-header">
                    <h3 class="box-title">Please fill in the information below</h3>
                </div>-->
                <div class="box-body">
                    
                    
                <div id="content-div"> 
                    <div class="col-lg-12">

                        <form id="form_details" autocomplete="off">
                                                
                            <input name="ids" value="<?=$id?>" hidden>                 
                        <div class="row">
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label class="required" for="customer_name">Customer Name</label>                                    
                                    <input type="text" name="customer_name" value="<?=$customer_name?>" placeholder="Enter the Customer Name" class="form-control" id="customer_name"  required="required" />
                                </div>
                            </div>
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label class="required" for="mobile_no">Mobile Number</label>  <span id="error_message" style="color: red; font-weight: 600;"></span>                                  
                                    <input type="text" name="mobile_no" value="<?=$mobile_no?>" placeholder="Enter the Mobile Number" class="form-control" id="mobile_no"  required="required" onkeypress="if(this.value.length==10) return false;return isNumber(event);" />
                                </div>
                            </div>
                            
                            <div class="col-lg-3">
                                <div class="form-group mb-4">
                                    <label class="required" for="city_town">City/Town</label>
                                    <input type="text" name="city_town" value="<?=$city?>" class="form-control" id="city_town" placeholder="City/Town">
                                </div>
                            </div>
                            
                            
                            
                            
                            
                          
                            
                            <div class="col-md-2">
                                <div class="form-group">
                                    <label class="required" for="gender">Gender</label>
                                    <select name="gender" id="gender" class="form-control select2">
                                        <option value="Male" <?php if($gender=="Male"){echo "selected";}?>>Male</option>
                                        <option value="Female" <?php if($gender=="Female"){echo "selected";}?>>Female</option>
                                    </select>
                                </div>
                            </div>
                                        
                            
                            
                            <div class="col-md-3">
                                <div class="form-group">
                                    <label class="optional" for="alter_mobile_no">Alter Mobile Number</label>                                    
                                    <input type="text" name="alter_mobile_no" value="<?=$alter_mobile_no?>" placeholder="Alter Mobile Number" class="form-control" id="alter_mobile_no"   />
                                </div>
                            </div>
                            
                                        <div class="col-lg-2">
                                            <div class="form-group mb-4">
                                                <label class="optional" for="dob">Date of Birth</label>
                                                <input type="date" name="dob" class="form-control" id="dob" value="<?=$dob?>">
                                            </div>
                                        </div>
                                        
                                        <div class="col-lg-2">
                                            <div class="form-group mb-4">
                                                <label class="optional" for="wedding_date">Wedding Date</label>
                                                <input type="date" name="wedding_date" class="form-control" id="wedding_date" value="<?=$wedding_date?>">
                                            </div>
                                        </div>
                                        
                                        
                                        <div class="col-lg-2">
                                            <div class="form-group mb-4">
                                                <label class="optional" for="religion">Religion</label>
                                                <select name="religion" id="religion" class="form-control select2">
                                                    <option value="">Select Religion</option>
                                                    <option value="Hindu" <?= ($religion=="Hindu" ? "selected" : "") ?>>Hindu</option>
                                                    <option value="Muslim" <?= ($religion=="Muslim" ? "selected" : "") ?>>Muslim</option>
                                                    <option value="Christian" <?= ($religion=="Christian" ? "selected" : "") ?>>Christian</option>
                                                </select>
                                            </div>
                                        </div>
                                        
                                        
                                        
                                        
                                        <div class="col-md-3">
                                            <div class="form-group">
                                                <label class="required" for="proof">Proof</label>
                                                <select name="proof" id="proof" class="form-control select2" onchange="prooF()">
                                                    <option value="1">Aadhaar No</option>
                                                    <option value="2">Pan No</option>
                                                    <option value="3">Driving Licence</option>
                                                    <option value="4">Voter ID</option>
                                                    <option value="5">Others</option>
                                                </select>
                                            </div>
                                        </div>
                                
                                
                                            
                                            
                                            
                                            
                                            <div class="col-lg-3" style="display: none;" id="proof_1">
                                                <div class="form-group mb-4">
                                                    <label class="optional" for="aadhaar_no">Aadhaar Number</label>
                                                    <input type="text" name="aadhaar_no" class="form-control" id="aadhaar_no" placeholder="Aadhaar Number" value="<?=$aadhaar_no?>" onkeypress="if(this.value.length==12) return false;return isNumber(event);">
                                                </div>
                                            </div>
                                            
                                            <div class="col-lg-3" style="display: none;" id="proof_2">
                                                <div class="form-group mb-4">
                                                    <label class="optional" for="pan_no">Pan Number</label>
                                                    <input type="text" name="pan_no" class="form-control" id="pan_no" placeholder="Pan Number" value="<?=$pan_no?>" >
                                                </div>
                                            </div>
                                            
                                            
                                            <div class="col-lg-3" style="display: none;" id="proof_3">
                                                <div class="form-group mb-4">
                                                    <label class="optional" for="driving_no">Driving Licence No</label>
                                                    <input type="text" name="driving_no" class="form-control" id="driving_no" placeholder="Driving Licence No" value="<?=$driving_no?>" >
                                                </div>
                                            </div>
                                            
                                            
                                            <div class="col-lg-3" style="display: none;" id="proof_4">
                                                <div class="form-group mb-4">
                                                    <label class="optional" for="voter_id_no">Voter ID</label>
                                                    <input type="text" name="voter_id_no" class="form-control" id="voter_id_no" placeholder="Voter ID" value="<?=$voter_no?>" >
                                                </div>
                                            </div>
                                            
                                            <div class="col-lg-3" style="display: none;" id="proof_5">
                                                <div class="form-group mb-4">
                                                    <label class="optional" for="other_proof_no">Other Proof</label>
                                                    <input type="text" name="other_proof_no" class="form-control" id="other_proof_no" placeholder="Other Proof Number" value="<?=$others_no?>" >
                                                </div>
                                            </div>
                                        
                                        
                                        <div class="col-lg-3">
                                            <div class="form-group mb-4">
                                                <label class="optional" for="gst_no">GST Number</label>
                                                <input type="text" name="gst_no" class="form-control" id="gst_no" value="<?=$gst_no?>" placeholder="GST Number">
                                            </div>
                                        </div>
                                        
                                        
                                        <div class="col-lg-3">
                                            <div class="form-group mb-4">
                                                <label class="optional" for="address">Address</label>
                                                <textarea type="text" name="address" rows="5" class="form-control" id="address" placeholder="Address"><?=$address?></textarea>
                                            </div>
                                        </div>
                                        
                                        
                                        <div class="col-lg-3">
                                            <div class="form-group mb-4">
                                                <label class="optional" for="remarks">Remarks</label>
                                                <textarea type="text" name="remarks" rows="3" class="form-control" id="remarks" placeholder="Remarks"><?=$remarks?></textarea>
                                            </div>
                                        </div>
                                        
                                        
                        <div class="clearfix"></div>
                    
                    
                                            <div class="col-lg-3">
                                                <div class="form-group mb-4">
                                                    <label class="required" for="customer_state">State</label>
                                                    <select name="customer_state" class="form-control select2" style="width:100%" id="customer_state">
                                                        <?php $statement = $pdo->prepare("SELECT * FROM `tbl_state` WHERE status=1");
                                                            $statement->execute();
                                                            $resultsss = $statement->fetchAll(PDO::FETCH_ASSOC); 
                                                            foreach ($resultsss as $ress) { ?>
                                                                <option value="<?=$ress['state']?>" <?php if($ress['state']=="$state"){ echo "selected"; }?>><?=$ress['state']?></option>
                                                        <?php  }  ?>
                                                    </select>
                                                </div>
                                            </div>
                      
                                            <div class="col-md-3">
                                                <div class="form-group">
                                                    <label class="required" for="pincode">Pincode</label>                                   
                                                    <input type="text" name="pincode" value="<?=$pincode?>" placeholder="Enter the Pincode" class="form-control" id="pincode"  onkeypress="if(this.value.length==6) return false; return isNumber(event);"/>
                                                </div>
                                            </div>
                                            
                                            <div class="col-md-2">
                                                <div class="form-group">
                                                    <label class="required" for="location_id">Locations</label>                                   
                                                    <select name="location_id" class="form-control select2" style="width:100%" id="location_id" required="required">
                                                        <?php 
                                                            $statement = $pdo->prepare("SELECT bb.* FROM `tbl_business_branch` bb WHERE bb.status=1 $branch_conditions");
                                                            $statement->execute();
                                                            $location_result = $statement->fetchAll(PDO::FETCH_ASSOC); 
                                                            foreach ($location_result as $result) { ?>
                                                                <option value="<?=$result['id']?>" <?php if(isset($datas) && $datas[0]['cus_location_id']==$result['id']){ echo "selected";}?> ><?=$result['location_name']?></option>
                                                        <?php  }  ?>
                                                    </select>
                                                </div>
                                            </div>
                            
                            
                            
                        </div>
                        
                        
                        
                        <div class="row filter" style="background: darkcyan; color: white; padding: 10px; border-radius: 5px; margin: 5px; cursor: pointer; margin-bottom: 29px;">
                                <b>Nominee Details (Show/Hide) </b> <span style="float: right; padding-right: 10px;"><i class="fa fa-caret-down" style="font-size: 18px;"></i></span>
                        </div>
                            
                            
                            
                            <div class="row" id="filter">
                                <div class="col-lg-3">
                                    <div class="form-group mb-4">
                                        <label class="optional" for="nominee_name">Nominee Name</label>
                                        <input type="text" name="nominee_name" class="form-control" id="nominee_name" value="<?=$nominee_name?>" placeholder="Nominee Name">
                                    </div>
                                </div>
                                
                                <div class="col-lg-3">
                                    <div class="form-group mb-4">
                                        <label class="optional" for="nominee_mobile_no">Nominee Mobile No</label>
                                        <input type="text" name="nominee_mobile_no" class="form-control" id="nominee_mobile_no" value="<?=$nominee_mobile_no?>" placeholder="Nominee Mobile No"  onkeypress="if(this.value.length==10) return false;return isNumber(event);">
                                    </div>
                                </div>
                                
                                <div class="col-lg-3">
                                    <div class="form-group mb-4">
                                        <label class="optional" for="nominee_address">Nominee Address</label>
                                        <textarea type="text" name="nominee_address" rows="5" class="form-control" id="nominee_address" placeholder="Nominee Address"><?=$nominee_address?></textarea>
                                    </div>
                                </div>
                                
                                
                                
                                <div class="col-lg-3">
                                    <div class="form-group mb-4">
                                        <label class="optional" for="nominee_type">Nominee Type</label>
                                        <select name="nominee_type" class="form-control select2" style="width:100%" id="nominee_type">
                                            <option value="">Nominee Type</option>
                                            <?php $statement = $pdo->prepare("SELECT * FROM `tbl_nominee_types` WHERE status=1");
                                                $statement->execute();
                                                $resultsss = $statement->fetchAll(PDO::FETCH_ASSOC); 
                                                foreach ($resultsss as $ress) { ?>
                                                    <option value="<?=$ress['name']?>" <?= ($nominee_type==$ress['name']) ? "selected":"" ?>><?=$ress['name']?></option>
                                            <?php  }  ?>
                                        </select>
                                    </div>
                                </div>
                                
                            </div>
                        
                        
                        

                        <div class="form-group" style="text-align:center;">
                            <input type="submit"  id="submit" value="Update Customers" class="btn btn-success" />
                        </div>
                        
                    </form>

                    </div>
                      
                    
                        <div class="form-group" style="text-align:center;">
                            <a href="customers-edit.php?id=<?=$id?>"><button class="btn btn-primary" ><i class="fa fa-refresh"></i> Reset Form</button></a>
                            <a href="customers.php"><button class="btn btn-warning" ><i class="fa fa-chevron-left"></i> Back to List</button></a>
                         </div>
                </div> 
                
                
<div class="container" id="loading-div" style="display: none; margin-top: 40px; margin-bottom: 40px;">
        <center> <img src="img/loading.gif" style="width: 250px;"><br><b class="blinking">Processing Please Wait...</b></center>
</div>
                    
                    
                    
                    
                    <div class="container" id="success-div" style="display: none; margin-top: 40px; margin-bottom: 40px;">
                        <center><b class="blinking" style="font-size:22px;">Customer Details Updated Successfully...</b><br>
                            <img src="img/success.gif" style="width: 250px;">
                            <br><br>
                            <a href="customers-edit.php?id=<?=$id?>"><button class="btn btn-info"><i class="fa fa-refresh"></i> Reset Form</button></a>
                            &nbsp;&nbsp;
                            <a href="customers.php"><button class="btn btn-warning"><i class="fa fa-chevron-left"></i> Back to List</button></a>
                        </center>
                    </div>
                    <div class="clearfix"></div>
                </div>
            </div>
        </div>
    </div>
</section>

<?php } } ?>
<?php include "footer.php"; ?>

<script>
    $(document).ready(function(){
       $('#filter').hide();
        $('.filter').click(function(){
            $("#filter").slideToggle();
            return false;
        });
    });
</script>

<script>

function prooF(){
    var proof = $("#proof").val();
    if(proof==1){
        $("#proof_1").show();
        $("#proof_2").hide();
        $("#proof_3").hide();
        $("#proof_4").hide();
        $("#proof_5").hide();
    }else if(proof==2){
        $("#proof_1").hide();
        $("#proof_2").show();
        $("#proof_3").hide();
        $("#proof_4").hide();
        $("#proof_5").hide();
    }else if(proof==3){
        $("#proof_1").hide();
        $("#proof_2").hide();
        $("#proof_3").show();
        $("#proof_4").hide();
        $("#proof_5").hide();
    }else if(proof==4){
        $("#proof_1").hide();
        $("#proof_2").hide();
        $("#proof_3").hide();
        $("#proof_4").show();
        $("#proof_5").hide();
    }else if(proof==5){
        $("#proof_1").hide();
        $("#proof_2").hide();
        $("#proof_3").hide();
        $("#proof_4").hide();
        $("#proof_5").show();
    }
}


$(document).on('keyup', '#mobile_no', function() {
        MobileNoValidation();
});

function MobileNoValidation(){
    var mobile_no = $("#mobile_no").val();
    if(mobile_no.length !== 10){
        $("#error_message").text("(Mobile number must be 10 digits long.)");
        $("#submit").prop('disabled', true);
    } else {
        $("#error_message").text("");
        $("#submit").prop('disabled', false);
    }
    
}
$(document).ready(function() {
    prooF();
   $('#form_details').on('submit', function(e){
                e.preventDefault();
                $('#loading-div').show();
                $('#content-div').hide();
                $("#submit").prop('disabled', true);
                var formData = new FormData(this);
                formData.append('type', 'update_customers');
                    $.ajax({
                            url: 'apis/customers.php',
                            type: 'post',
                            dataType: 'json',
                            data: formData,
                            cache: false,
                            contentType: false,
                            processData: false,
                            enctype: 'multipart/form-data',
                            success: function (response) {
                                console.log(response);
                                if(response['status']==200){
                                     /*alert(response['message']);*/
                                     /*location.reload();*/
                                     $("#submit").prop('disabled', false);
                                     $('#success-div').show();
                                     $('#loading-div').hide();
                                }else{
                                    alert(response['message']);
                                    $("#submit").prop('disabled', false);
                                    $('#loading-div').hide();
                                    $('#content-div').show();
                                }
                            }
                        });
   });
});
</script>