<?php
ob_start();
error_reporting(0);
include("connect.php");
session_start(); 
$ver = $_SESSION["admin_id"];
$admin_id = $_SESSION["admin_id"];
$dis_id = $_SESSION["manager_id"];
$user_type = $_SESSION["user_type"];
$user_session = $_SESSION["user_session"];
 
$policy_no= base64_decode($_GET['id']);
$u_id= base64_decode($_GET['id3']);
$user=$_GET['id2'];
 $npolicy=$_GET['npolicy'];
$user1=$_GET['user'];
if(!isset($_SESSION["admin_id"])){
   header('location:http://www.btcover.appexperts.net');
}
date_default_timezone_set('Asia/Calcutta');
	$cdate  = date("Y-m-d");
	
	
	
?>
<!DOCTYPE html>
<html dir="ltr" lang="en">

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <!-- Tell the browser to be responsive to screen width -->
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- Favicon icon -->
    <link rel="icon" type="image/png" sizes="16x16" href="assets/images/favicon.png">
    <title>BTCOVER : Admin Dashboard</title>
    <!-- Custom CSS -->
    <link rel="stylesheet" type="text/css" href="assets/libs/select2/dist/css/select2.min.css">
    <link rel="stylesheet" type="text/css" href="assets/libs/jquery-minicolors/jquery.minicolors.css">
    <link rel="stylesheet" type="text/css" href="assets/libs/bootstrap-datepicker/dist/css/bootstrap-datepicker.min.css">
    <link rel="stylesheet" type="text/css" href="assets/libs/quill/dist/quill.snow.css">
    <link href="dist/css/style.min.css" rel="stylesheet">
	<script>
		function setpolicy(policy_no)
		{
			
			document.getElementById('old_policy_number').value=policy_no;
			
		}
		</script>	
		<script type="text/javascript">
window.onload=function WindowLoad(event)
{	
			 
var patt = "^[TMP]{3}[_][0-9]{10}[_][0-9]{2}$";
var str='<?php echo $policy_no ?>';

var str1='<?php echo $npolicy ?>';

var result = str.match(patt);

		if(result)
		{
					
		document.getElementById('update_button').style.display="block";	
		}
		else
		{
			document.getElementById('update_button').style.display="none";	
		}

	console.log(admin_id);
}
</script>
</head>

<body>
    <!-- ============================================================== -->
    <!-- Preloader - style you can find in spinners.css -->
    <!-- ============================================================== -->
   
	 <div id="main-wrapper">
   <?php include("header.php"); ?>
    
     <?php include("menu.php"); ?>
	
        <div class="page-wrapper">
            <!-- ============================================================== -->
            <!-- Bread crumb and right sidebar toggle -->
            <!-- ============================================================== -->
            <div class="page-breadcrumb">
                <div class="row">
                    <div class="col-12 d-flex no-block align-items-center">
                        <h4 class="page-title">Policy Detail</h4>
                        <div class="ml-auto text-right">
                            <nav aria-label="breadcrumb">
                                <ol class="breadcrumb">
                                    <li class="breadcrumb-item"><a href="dashboard.php">Dashboard</a></li>
									<?php if($user=='customer') { ?>
								 <li class="breadcrumb-item"><a href="customer.php">View Customer</a></li>
								 <li class="breadcrumb-item"><a href="customer-policy.php?id=<?php echo base64_encode($u_id)?>">View Policies</a></li>
									<?php } ?>
									<?php if($user=='agent') { ?>
								 <li class="breadcrumb-item"><a href="agent.php">View Agent</a></li>
								 <li class="breadcrumb-item"><a href="agent-policy.php?id=<?php echo base64_encode($u_id)?>">View Policies</a></li>
									<?php } ?>
									<?php if($user1=='policy') { ?>
									<li class="breadcrumb-item"><a href="policy.php">All Policy</a></li>
									<?php } ?>
									<li class="breadcrumb-item active" aria-current="page">View Policy</li>
                                </ol>
                            </nav>
                        </div>
                    </div>
                </div>
            </div>
            <!-- ============================================================== -->
            <!-- End Bread crumb and right sidebar toggle -->
            <!-- ============================================================== -->
            <!-- ============================================================== -->
            <!-- Container fluid  -->
            <!-- ============================================================== -->
            <div class="container-fluid">
                <!-- ============================================================== -->
                <!-- Start Page Content -->
                <!-- ============================================================== -->
				
                <div class="row" style="float:left; width:100%; overflow-Y: auto; height: 500px;">
                    <div class="col-md-12">
                        <div class="card">
						 <div class="row" >
                    <div class="col-md-12">
					
                        <div class="card-body">
						
						<?php 
						
						$query=mysqli_query($con,"SELECT * FROM `tbl_policy_master` ,tbl_customer,tbl_vehicle_master where tbl_policy_master.customer_id=tbl_customer.customer_id  and tbl_policy_master.policy_no in ('$policy_no','$npolicy') and tbl_vehicle_master.vehicle_id=tbl_policy_master.vehicle_id and tbl_policy_master.admin_id='$ver' and tbl_policy_master.status in ('Active','Renewal Pending')");
						$fetch=mysqli_fetch_assoc($query);
						extract($fetch);
						
						?>
						  <div class="col-md-12" id="update_button" style="display:none">
						<a href="javascript:void(0)" data-toggle="modal" data-target="#add-new-event" style="float: right; font-size:12px;padding:1px 5px;" onclick="setpolicy('<?php echo $fetch['policy_no']?>')" class="btn btn-success"  >Update Policy</a>
						</div>
						<div class="modal fade none-border" id="add-new-event">
									<div class="modal-dialog">
									<div class="modal-content">
								<div class="modal-header">
                             
                                <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            </div>
                            <div class="modal-body">
                                <form   method="post"  enctype="multipart/form-data">
                                    
										<div class="row">
										<div class="col-md-12">
										<div class="form-group ">
                                            <label class="control-label">New Policy Number</label>
                                             <input class="form-control form-white" placeholder="New Policy Number" id="new_policy_number" type="text" name="new_policy_number" style="text-transform:uppercase;"  />
                                        </div>
                                        </div>
                                        </div>
										
										<br>
										
										 <input class="form-control form-white" placeholder="old_policy_number" id="old_policy_number" type="hidden" name="old_policy_number" />
										 
										
                                <button type="submit" class="btn btn-success" name="sub1" >Save</button>
                                <button type="button" class="btn btn-secondary waves-effect" data-dismiss="modal">Close</button>
                            </div>
                                </form>
								<?php 
								if(isset($_POST['sub1']))
								{
									$ver = $_SESSION['manager_id'];
	$new_policy_number = $_POST['new_policy_number'];
	$old_policy_number = $_POST['old_policy_number'];
	
	date_default_timezone_set('Asia/Calcutta');
	$cdate  = date("Y-m-d")." ".date('h:i:s');
			
	$uq2=mysqli_query($con,"update tbl_policy_master set policy_no='$new_policy_number',update_datetime='$cdate' where policy_no='$old_policy_number'"); 
	$uq3=mysqli_query($con,"update tbl_customer_premium set policy_no='$new_policy_number' where policy_no='$old_policy_number'"); 
	$uq4=mysqli_query($con,"update tbl_agent_commission set policy_no='$new_policy_number' where policy_no='$old_policy_number'"); 
		
	header('location:policy-detail.php?npolicy='.$new_policy_number.'&user'.$_GET['user']);
}
								?>
                            </div>
                           
                        </div>
                    </div>
						<br>
						<br>
                            <table   border="2px;" width="100%">
                                <thead>
							
								<tr><th colspan="4" style="text-align:center"><b><h4 class="card-title m-b-0" >CUSTOMER DETAILS</h4></b></th><tr>
                                   
                                </thead>
                                <tbody>
                                    <tr>
                                        <td>Customer Name</td>
                                        <td colspan="3"><?php echo $fetch['customer_name'];?></td>
                                    </tr>
									<tr>
                                        <td>Customer Phone</td>
                                        <td colspan="3"><?php echo $fetch['phone_no'];?></td>
                                    </tr>
									<tr>
                                        <td>Customer Address</td>
                                        <td colspan="3"><?php echo $fetch['address'];?></td>
                                    </tr>
									<?php 
									$query_company=mysqli_query($con,"SELECT * FROM `tbl_policy_master` ,tbl_insurance_company where tbl_policy_master.company_id=tbl_insurance_company.company_id and tbl_policy_master.policy_no='$policy_no'");
									$fetch11=mysqli_fetch_assoc($query_company);?>
									<tr>
                                        <td>Company Name</td>
                                        <td colspan="3"><?php echo $fetch11['company_name'];?></td>
                                    </tr>
									<?php 
									$query1=mysqli_query($con,"SELECT * FROM `tbl_policy_master` ,tbl_customer_premium,tbl_agent where tbl_policy_master.policy_no=tbl_customer_premium.policy_no and tbl_customer_premium.agent_id=tbl_agent.agent_id and tbl_policy_master.policy_no='$policy_no'");
									$fetch1=mysqli_fetch_assoc($query1);?>
									<tr>
                                        <td>Agent Name</td>
                                        <td ><?php echo $fetch1['agent_name'];?></td>
										<td>Agent Phone No.</td>
                                        <td><?php echo $fetch1['agent_phone'];?></td>
                                    </tr>
									
									<tr>
                                        <td>Policy Number</td>
                                        <td colspan="3"><?php echo $fetch['policy_no'];?></td>
										
                                    </tr>
									
									<tr>
										<td>Policy Date</td>
                                        <td><?php echo date("d-M-Y", strtotime($fetch['policy_date']) );?></td>
                                        <td>Policy Term</td>
                                        <td><?php echo $fetch['policy_term']." ".$fetch['term_value'];?></td>
                                    </tr>
                                   
                              </tbody>
                            </table>
							<br>
						 <div class="table-responsive" style="float:left; width:100%; overflow-Y: auto;">
                                <table id="zero_config" class="table table-striped table-bordered" >
                                <thead>
								
								<tr><th colspan="12" style="text-align:center"><b><h4 class="card-title m-b-0" > VEHICLE DETAILS</h4></b></th><tr>
                                
                                </thead>
                                <tbody>
                                    <tr>
                                        <td>Passenger assist</td>
                                        <td>Vehicle Category</td>
                                        <td>Vehicle Total IDV</td>
                                        <td>Make & Model</td>
                                        <td>Registration Number</td>
                                        <td>Seating Capacity</td>
                                        <td>Engine No.</td>
                                        <td>Chassis No.</td>
                                        <td>Manufacturing Year</td>
                                        <td>Body Type</td>
                                        <td>Fuel Type</td>
                                        <td>HP/CC</td>
                                    
                                     </tr>
									<tr>
									<td><?php echo $passenger_assist; ?></td>
									<td><?php echo $vehicle_type; ?></td>
									<td><?php echo $idv; ?></td>
									<td><?php echo $make_model; ?></td>
									<td><?php echo $registration_no; ?></td>
									<td><?php echo $seating_capacity; ?></td>
									<td><?php echo $engine_no; ?></td>
									<td><?php echo $chassis_no; ?></td>
									<td><?php echo $manufacturing_year; ?></td>
									<td><?php echo $body_type; ?></td>
									<td><?php echo $fuel_type; ?></td>
									<td><?php echo $hp_cc; ?></td>
                                    </tr>
                                    
                                    
                              </tbody>
                            </table>
							 </div>
							 </div>
                        </div>
							<div class="col-md-6">
							 <div class="card-body">
							<table  border="2px;" width="100%">
                                <thead>
								
								<tr><th colspan="2" style="text-align:center"><b><h4 class="card-title m-b-0" >Section I- Own Damage(A)</h4></b></th><tr>
                                    <tr>
                                        <th  colspan="2">Basic Cover</th>
                                        
                                    </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td>Basic OD</td>
                                        <td> &nbsp; <i class="fa fa-inr" aria-hidden="true"></i> <i class="fa fa-rupee-sign" style="font-size:11px;"></i> <?php echo $od;?></td>
                                    </tr>
									
									  <tr>
                                        <td>OD Discount (<?php echo $od_discount_per; ?> %)</td>
                                        <td> &nbsp; <i class="fa fa-inr" aria-hidden="true"></i> <i class="fa fa-rupee-sign" style="font-size:11px;"></i> <?php echo $od_discount;?></td>
                                    </tr>
									
                                    <tr>
                                        <td>Total Own-Damage Premium(A) </td>
                                        <td> &nbsp; <i class="fa fa-inr" aria-hidden="true"></i> <i class="fa fa-rupee-sign" style="font-size:11px;"></i> <b><?php echo $totalA;?></b></td>
                                    </tr>
									<?php if($gst_typeA=="CGST/SGST") { ?>
									
									 <tr>
                                        <td>CGST (<?php echo ($gst_percentageA/2); ?> %) </td>
                                        <td> &nbsp; <i class="fa fa-inr" aria-hidden="true"></i> <i class="fa fa-rupee-sign" style="font-size:11px;"></i> <b><?php echo $cGstA;?></b></td>
                                    </tr>
									 <tr>
                                        <td>SGST (<?php echo ($gst_percentageA/2); ?> %) </td>
                                        <td> &nbsp; <i class="fa fa-inr" aria-hidden="true"></i> <i class="fa fa-rupee-sign" style="font-size:11px;"></i> <b><?php echo $sGstA;?></b></td>
                                    </tr>
									
									<?php } else { ?>
									
									 <tr>
                                        <td>IGST (<?php echo ($gst_percentageA); ?> %) </td>
                                        <td> &nbsp; <i class="fa fa-inr" aria-hidden="true"></i> <i class="fa fa-rupee-sign" style="font-size:11px;"></i> <b><?php echo $iGstA;?></b></td>
                                    </tr>
									<?php } ?>
                                    
                              </tbody>
                            </table>
							<br>
							<table class="table" border="2px;" width="100%">
                                <thead>
								
								<tr><th colspan="2" style="text-align:center"><b><h4 class="card-title m-b-0" >Section III- Add On Covers(C)</h4></b></th><tr>
                                
                                </thead>
                                <tbody>
                                    <tr>
                                        <td>Passenger assist</td>
                                        <td> &nbsp; <i class="fa fa-inr" aria-hidden="true"></i> <i class="fa fa-rupee-sign" style="font-size:11px;"></i> <?php echo $passenger_assist; ?></td>
                                    </tr>
									<tr>
                                        <td>Depreciation Cover</td>
                                        <td> &nbsp; <i class="fa fa-inr" aria-hidden="true"></i> <i class="fa fa-rupee-sign" style="font-size:11px;"></i> <?php echo $depreciation; ?></td>
                                    </tr>
                                    <tr>
                                        <td>Total Add On Cover Premium(C)</td>
                                        <td> &nbsp; <i class="fa fa-inr" aria-hidden="true"></i> <i class="fa fa-rupee-sign" style="font-size:11px;"></i> <b><?php echo $totalC; ?></b></td>
                                    </tr>
									
									<?php if($gst_typeC=="CGST/SGST") { ?>
									
									 <tr>
                                        <td>CGST (<?php echo ($gst_percentageC/2); ?> %) </td>
                                        <td> &nbsp; <i class="fa fa-inr" aria-hidden="true"></i> <i class="fa fa-rupee-sign" style="font-size:11px;"></i> <b><?php echo $cGstC;?></b></td>
                                    </tr>
									 <tr>
                                        <td>SGST (<?php echo ($gst_percentageC/2); ?> %) </td>
                                        <td> &nbsp; <i class="fa fa-inr" aria-hidden="true"></i> <i class="fa fa-rupee-sign" style="font-size:11px;"></i> <b><?php echo $sGstC;?></b></td>
                                    </tr>
									
									<?php } else { ?>
									
									 <tr>
                                        <td>IGST (<?php echo ($gst_percentageC); ?> %) </td>
                                        <td> &nbsp; <i class="fa fa-inr" aria-hidden="true"></i> <i class="fa fa-rupee-sign" style="font-size:11px;"></i> <b><?php echo $iGstC;?></b></td>
                                    </tr>
									<?php } ?>
                                    
                              </tbody>
                            </table>
                       
                    </div>
                    </div>
					
					<div class="col-md-6">
                        <div class="card-body">
                            <table   border="2px;" width="100%">
                                <thead>
								<tr><th colspan="2" style="text-align:center"><b><h4 class="card-title m-b-0" >Section II- Liability(B)</h4></b></th><tr>
                                    <tr>
                                        <th  colspan="2"><b>Third Party Premium</b></th>
                                         </tr>
									  <tr>
                                         <th  colspan="2">Basic TP</th>
                                      </tr>
                                </thead>
                                <tbody>
                                    <tr>
                                        <td>Basic Cover</td>
                                        <td> &nbsp; <i class="fa fa-inr" aria-hidden="true"></i> <i class="fa fa-rupee-sign" style="font-size:11px;"></i> <?php echo $cover?></td>
                                    </tr>
									<tr>
                                        <td colspan="2"><b>PA Benefits</b></td>
                                        
                                    </tr>
									<tr>
                                        <td>PA To Owner Driver</td>
                                        <td> &nbsp; <i class="fa fa-inr" aria-hidden="true"></i> <i class="fa fa-rupee-sign" style="font-size:11px;"></i> <?php echo $pa?></td>
                                    </tr>
									<tr>
                                        <td colspan="2"><b>Legal Liability</b></td>
                                        
                                    </tr>
									<tr>
                                        <td>LL To Paid Driver</td>
                                        <td> &nbsp; <i class="fa fa-inr" aria-hidden="true"></i> <i class="fa fa-rupee-sign" style="font-size:11px;"></i> <?php echo $liabilities?></td>
                                    </tr>
                                    <tr>
                                        <td>Total Liability Premium(B) </td>
                                        <td> &nbsp; <i class="fa fa-inr" aria-hidden="true"></i> <i class="fa fa-rupee-sign" style="font-size:11px;"></i> <b><?php echo $totalB?></b></td>
                                    </tr>
									
									<?php if($gst_typeB=="CGST/SGST") { ?>
									
									 <tr>
                                        <td>CGST (<?php echo ($gst_percentageB/2); ?> %) </td>
                                        <td> &nbsp; <i class="fa fa-inr" aria-hidden="true"></i> <i class="fa fa-rupee-sign" style="font-size:11px;"></i> <b><?php echo $cGstB;?></b></td>
                                    </tr>
									 <tr>
                                        <td>SGST (<?php echo ($gst_percentageB/2); ?> %) </td>
                                        <td> &nbsp; <i class="fa fa-inr" aria-hidden="true"></i> <i class="fa fa-rupee-sign" style="font-size:11px;"></i> <b><?php echo $sGstB;?></b></td>
                                    </tr>
									
									<?php } else { ?>
									
									 <tr>
                                        <td>IGST (<?php echo ($gst_percentageB); ?> %) </td>
                                        <td> &nbsp; <i class="fa fa-inr" aria-hidden="true"></i> <i class="fa fa-rupee-sign" style="font-size:11px;"></i> <b><?php echo $iGstB;?></b></td>
                                    </tr>
									<?php } ?>
									
									
                                    
                              </tbody>
                            </table>
							
							
							
							<br><br>
							
							
							 <table   border="2px;" width="100%">
                                <tbody>
                                    <tr>
                                        <td>Net Premium (<?php echo $calculation_param; ?>)</td>
                                        <td> &nbsp; <i class="fa fa-inr" aria-hidden="true"></i> <i class="fa fa-rupee-sign" style="font-size:11px;"></i> <?php echo $net_premium; ?></td>
                                    </tr>
									
									<tr>
                                        <td>Total GST</td>
                                        <td> &nbsp; <i class="fa fa-inr" aria-hidden="true"></i> <i class="fa fa-rupee-sign" style="font-size:11px;"></i> <?php echo $totalGst; ?></td>
                                    </tr>
									
									<tr>
                                        <td>Total Premium</td>
                                        <td> &nbsp; <i class="fa fa-inr" aria-hidden="true"></i> <i class="fa fa-rupee-sign" style="font-size:11px;"></i> <?php echo $premium_amt; ?></td>
                                    </tr>
                                    
                              </tbody>
                            </table>
							
                        </div>
                    </div>
				
					</div>
                            
							
				<a href="download_policy.php?id=<?php echo base64_encode($policy_no)?>" target='_blank'><input type="button" class="btn btn-success" value="Download" /></a>	
							
							
                        </div>
                    
          

                    </div>
              
                </div>
                <!-- editor -->
               
                <!-- ============================================================== -->
                <!-- End PAge Content -->
                <!-- ============================================================== -->
                <!-- ============================================================== -->
                <!-- Right sidebar -->
                <!-- ============================================================== -->
                <!-- .right-sidebar -->
                <!-- ============================================================== -->
                <!-- End Right sidebar -->
                <!-- ============================================================== -->
            </div>
            </div>
            <!-- ============================================================== -->
            <!-- End Container fluid  -->
            <!-- ============================================================== -->
            <!-- ============================================================== -->
            <!-- footer -->
            <!-- ============================================================== -->
             <footer class="footer text-center">
                  2019 &copy; All Rights Reserved by BTCOVER. Designed and Developed by <a href="http://www.belltechnology.in/">Bell Technology</a>.
            </footer>
          
            <!-- ============================================================== -->
            <!-- End footer -->
            <!-- ============================================================== -->
        </div>
        <!-- ============================================================== -->
        <!-- End Page wrapper  -->
        <!-- ============================================================== -->
    </div>
    <!-- ============================================================== -->
    <!-- End Wrapper -->
    <!-- ============================================================== -->
    <!-- ============================================================== -->
    <!-- All Jquery -->
    <!-- ============================================================== -->
    <script src="assets/libs/jquery/dist/jquery.min.js"></script>
    <!-- Bootstrap tether Core JavaScript -->
    <script src="assets/libs/popper.js/dist/umd/popper.min.js"></script>
    <script src="assets/libs/bootstrap/dist/js/bootstrap.min.js"></script>
    <!-- slimscrollbar scrollbar JavaScript -->
    <script src="assets/libs/perfect-scrollbar/dist/perfect-scrollbar.jquery.min.js"></script>
    <script src="assets/extra-libs/sparkline/sparkline.js"></script>
    <!--Wave Effects -->
    <script src="dist/js/waves.js"></script>
    <!--Menu sidebar -->
    <script src="dist/js/sidebarmenu.js"></script>
    <!--Custom JavaScript -->
    <script src="dist/js/custom.min.js"></script>
    <!-- This Page JS -->
    <script src="assets/libs/inputmask/dist/min/jquery.inputmask.bundle.min.js"></script>
    <script src="dist/js/pages/mask/mask.init.js"></script>
    <script src="assets/libs/select2/dist/js/select2.full.min.js"></script>
    <script src="assets/libs/select2/dist/js/select2.min.js"></script>
    <script src="assets/libs/jquery-asColor/dist/jquery-asColor.min.js"></script>
    <script src="assets/libs/jquery-asGradient/dist/jquery-asGradient.js"></script>
    <script src="assets/libs/jquery-asColorPicker/dist/jquery-asColorPicker.min.js"></script>
    <script src="assets/libs/jquery-minicolors/jquery.minicolors.min.js"></script>
    <script src="assets/libs/bootstrap-datepicker/dist/js/bootstrap-datepicker.min.js"></script>
    <script src="assets/libs/quill/dist/quill.min.js"></script>
    <script>
        //***********************************//
        // For select 2
        //***********************************//
        $(".select2").select2();

        /*colorpicker*/
        $('.demo').each(function() {
        //
        // Dear reader, it's actually very easy to initialize MiniColors. For example:
        //
        //  $(selector).minicolors();
        //
        // The way I've done it below is just for the demo, so don't get confused
        // by it. Also, data- attributes aren't supported at this time...they're
        // only used for this demo.
        //
        $(this).minicolors({
                control: $(this).attr('data-control') || 'hue',
                position: $(this).attr('data-position') || 'bottom left',

                change: function(value, opacity) {
                    if (!value) return;
                    if (opacity) value += ', ' + opacity;
                    if (typeof console === 'object') {
                        console.log(value);
                    }
                },
                theme: 'bootstrap'
            });

        });
        /*datwpicker*/
        jQuery('.mydatepicker').datepicker();
        jQuery('#datepicker-autoclose').datepicker({
            autoclose: true,
            todayHighlight: true
        });
        var quill = new Quill('#editor', {
            theme: 'snow'
        });

    </script>
</body>

</html>