<?php require_once('header.php'); ?>
<?php
if(isset($_POST['form1'])) {
   // var_dump($_POST);
	    $valid = 1;

        $cscs_awb='';
        $pl3_awb='';
    
		                    
            // 	**********************************  Generate CSCS AWB No Start ********************************************
            $statement = $pdo->prepare("SELECT MAX(id) as big_id FROM pickup_entry");
			$statement->execute();
			$result = $statement->fetchAll(PDO::FETCH_ASSOC);
			//$rows = mysqli_num_rows($result);
				foreach ($result as $row)
				{
				    $bid=$row['big_id'];
                    
                    if($bid!='')
                    {
                        $awb_nos=$row['big_id']+1;
                        $cscs_awb=100000+$awb_nos;
                    }
                    else
                    {
                        $cscs_awb=100001;
                    }
				}
        
    if(empty($_POST['3pl_awb'])) { 	$pl3_awb='';}
	else{ $pl3_awb=$_POST['3pl_awb']; }
        
	if(empty($_POST['hsn_code'])) {
		$valid = 0;
		$error_message .= 'HSN Code can not be empty<br>';
	}
		if(empty($_POST['ref_no'])) {
		$valid = 0;
		$error_message .= 'Ref No can not be empty<br>';
	}
	if(empty($_POST['taxable_value'])) {
		$valid = 0;
		$error_message .= 'Taxable Value can not be empty<br>';
	}
	
// 	if(empty($_POST['gst_rate'])) {
// 		$valid = 0;
// 		$error_message .= 'GSTax Rate can not be empty<br>';
// 	}
	
// 	if(empty($_POST['gst_amount'])) {
// 		$valid = 0;
// 		$error_message .= 'GSTax Amount can not be empty<br>';
// 	}
	
// 	if(empty($_POST['buyer_gst'])) {
// 		$valid = 0;
// 		$error_message .= 'Buyer & Seller Gst No can not be empty<br>';
// 	}

	if($_POST['client_id']=='none') {
		$valid = 0;
		$error_message .= 'Select the Client <br>';
	}
                            
    if($valid==1)
    {
        $statement = $pdo->prepare("SHOW TABLE STATUS LIKE 'pickup_entry'");
		$statement->execute();
		$result = $statement->fetchAll();
		foreach($result as $row) {
			$ai_id=$row[10];
		}
        
            date_default_timezone_set('Asia/Kolkata');
            //$date = date('Y/m/d h:i:s a', time());
		$statement = $pdo->prepare("INSERT INTO pickup_entry (courier_id,client_id,cscs_awb,status_code,3pl_awb,ref_no,order_type,boxes,collectable_amount,shipper_name,shipper_address,shipper_city,shipper_state,shipper_pincode,shipper_phone,consignee_name,consignee_address,consignee_city,consignee_state,consignee_pincode,consignee_phone,product_description,quantity,invoice_value,taxable_value,hsn_code,discount,gst_amount,mrp,ewaybill,rto_name,rto_address,rto_city,rto_state,rto_pincode,rto_phone,a_weight,vw_length,vw_breadth,vw_height,v_weight,c_weight,gst_rate,buyer_gst,seller_gst,date_added,business_mode,business_type) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)");
		$statement->execute(array($_POST['courier_id'],$_POST['client_id'],$cscs_awb,1,$pl3_awb,$_POST['ref_no'],$_POST['order_type'],$_POST['boxes'],$_POST['collectable_amount'],$_POST['shipper_name'],$_POST['shipper_address'],$_POST['shipper_city'],$_POST['shipper_state'],$_POST['shipper_pincode'],$_POST['shipper_phone'],$_POST['consignee_name'],$_POST['consignee_address'],$_POST['consignee_city'],$_POST['consignee_state'],$_POST['consignee_pincode'],$_POST['consignee_phone'],$_POST['product_description'],$_POST['quantity'],$_POST['invoice_value'],$_POST['taxable_value'],$_POST['hsn_code'],$_POST['discount'],$_POST['gst_amount'],$_POST['mrp'],$_POST['ewaybill'],$_POST['rto_name'],$_POST['rto_address'],$_POST['rto_city'],$_POST['rto_state'],$_POST['rto_pincode'],$_POST['rto_phone'],$_POST['a_weight'],$_POST['vw_length'],$_POST['vw_breadth'],$_POST['vw_height'],$_POST['v_weight'],$_POST['c_weight'],$_POST['gst_rate'],$_POST['buyer_gst'],$_POST['seller_gst'],$_POST['date_added'],$_POST['pincode_mode'],$_POST['pincode_type']));
	
		
		
			/*Tracking Module Start*/
		$statement = $pdo->prepare("INSERT INTO tbl_tracking (pickup_entry_id,user_id,location,status,status_code,description,remark,created_at) VALUES (?,?,?,?,?,?,?,?)");
		$statement->execute(array($ai_id,$clientId,$clientLocation,'pending','1','Shipment Softdata Created Successfully','Material Safe...',$_POST['date_added']));
		
		$success_message = 'Pickup Entry is added successfully!';

		unset($_POST['client_id']);
		unset($_POST['cscs_awb']);
		unset($_POST['3pl_awb']);
		unset($_POST['ref_no']);
		unset($_POST['order_type']);
		unset($_POST['collectable_amount']);
		unset($_POST['shipper_name']);
		unset($_POST['shipper_address']);
		unset($_POST['shipper_city']);
		unset($_POST['shipper_state']);
		unset($_POST['shipper_pincode']);
		unset($_POST['shipper_phone']);
		unset($_POST['consignee_name']);
		unset($_POST['consignee_address']);
		unset($_POST['consignee_city']);
		unset($_POST['consignee_state']);
		unset($_POST['consignee_pincode']);
		unset($_POST['consignee_phone']);
		unset($_POST['product_description']);
		unset($_POST['quantity']);
		unset($_POST['boxes']);
		unset($_POST['invoice_value']);
		unset($_POST['taxable_value']);
		unset($_POST['hsn_code']);
		unset($_POST['discount']);
		unset($_POST['gst_amount']);
		unset($_POST['mrp']);
		unset($_POST['ewaybill']);
		unset($_POST['rto_name']);
		unset($_POST['rto_address']);
		unset($_POST['rto_city']);
		unset($_POST['rto_state']);
		unset($_POST['rto_pincode']);
		unset($_POST['rto_phone']);
		unset($_POST['a_weight']);
		unset($_POST['vw_length']);
		unset($_POST['vw_breadth']);
		unset($_POST['vw_height']);
		unset($_POST['v_weight']);
		unset($_POST['c_weight']);
		unset($_POST['gst_rate']);
		unset($_POST['buyer_gst']);		;
		unset($_POST['seller_gst']);
	
    }
	
}
?>

<section class="content-header">
	<div class="content-header-left">
		<h1>Add Pickup Entry</h1>
	</div>
	<div class="content-header-right">
		<a href="view-pickup-entry.php?status=1" class="btn btn-danger btn-sm">View All</a>&emsp;&emsp;
			<a href="pickup-entry-bulk-upload.php" class="btn btn-danger btn-sm">CSCS Bulk Upload</a>
	</div>
</section>


<section class="content">

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

			<?php if($error_message): ?>
			<div class="callout callout-danger">
				<p>
					<?php echo $error_message; ?>
				</p>
			</div>
			<?php endif; ?>

			<?php if($success_message): ?>
			<div class="callout callout-success">
				<p><?php echo $success_message; ?></p>
			</div>
			<?php endif; ?>
			
			<form class="form-horizontal" action="" method="post" enctype="multipart/form-data">
				<div class="box box-info">
					<div class="box-body">
					    <div class="form-group">
							<label for="" class="col-sm-2 control-label">Select Client <span style='color:red;'>*</span></label>
							<div class="col-sm-6">
							    <select name="client_id" id="client_id" class="form-control">
							       <?php if($clientType=="Admin"){ ?>
							        <option ='none'>--Select Client--</option>
							        <?php
							        	$statement = $pdo->prepare("SELECT * FROM tbl_user where (role='client' or role='Modicare') and delete_status!=1");
							         }
							         else{
							        	$statement = $pdo->prepare("SELECT * FROM tbl_user where id=$clientId");
							         }
            							$statement->execute();
            							$result = $statement->fetchAll(PDO::FETCH_ASSOC);
            						 foreach($result as $rows)
            						 {?>
            						     <option value="<?php echo $rows['id']; ?>"><?php echo $rows['full_name']; ?></option>
            						<?php }
							        ?>
							        
							    </select>
							</div>
						</div>
						<?php if($clientType=="Admin"){ ?>
						 <div class="form-group">
							<label for="" class="col-sm-2 control-label">Select Courier <span style='color:red;'>*</span></label>
							<div class="col-sm-6">
							    <select name="courier_id" id="courier_id" class="form-control">
							       <?php 
							       $statement = $pdo->prepare("SELECT * FROM `courier_company`");
        							$statement->execute();
        							$result = $statement->fetchAll(PDO::FETCH_ASSOC);
            						 foreach($result as $rows) { ?>
            						     <option value="<?php echo $rows['id']; ?>"><?php echo $rows['company_name']; ?></option>
            						<?php } ?>
							        
							    </select>
							</div>
						</div>
						<?php } ?>
						<?php if($clientType=="Admin"){ ?>
						<!--<div class="form-group">-->
						<!--	<label for="" class="col-sm-2 control-label">CSCS AWB <span style='color:red;'>*</span></label>-->
						<!--	<div class="col-sm-6">-->
						<!--		<input type="text" autocomplete="off" class="form-control" id="cscs_awb" name="cscs_awb" value="<?php // if(isset($_POST['cscs_awb'])){echo $_POST['cscs_awb'];} ?>">-->
						<!--	</div>-->
						<!--		<div class="col-sm-4">-->
						<!--	    <span id="ncheck"> </span>-->
						<!--	</div>-->
						<!--</div>-->
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">3PL AWB </label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" id="3pl_awb" name="3pl_awb" value="<?php if(isset($_POST['3pl_awb'])){echo $_POST['3pl_awb'];} ?>">
							</div>
							<div class="col-sm-4">
							    <span id="ncheck1"> </span>
							</div>
						</div>
						<?php } ?>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Ref No <span style='color:red;'>*</span></label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" id="ref_no" name="ref_no" value="<?php if(isset($_POST['ref_no'])){echo $_POST['ref_no'];} ?>">
							</div>
								<div class="col-sm-4">
							    <span id="ncheck2"> </span>
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Order Type </label>
							<div class="col-sm-2">
								<select name="order_type" class="form-control" id="order_type">
        						     <option value="cod">COD</option>
        						     <option value="prepaid">Prepaid</option>
    						    </select>
							</div>
						</div>
						<div class="form-group" id="collectable">
							<label for="" class="col-sm-2 control-label">Collectable Amount </label>
							<div class="col-sm-3">
								<input type="number" step='any' autocomplete="off" class="form-control" id="collectable_amount" name="collectable_amount" value="<?php if(isset($_POST['collectable_amount'])){echo $_POST['collectable_amount'];} ?>">
							</div>
						</div>
						<?php if($clientType!="Admin"){  
						
						$full_name=$_SESSION['user']['full_name'];
						$address=$_SESSION['user']['address'];
						$city=$_SESSION['user']['city'];
						$state=$_SESSION['user']['state'];
						$pincode=$_SESSION['user']['pincode'];
						$phone=$_SESSION['user']['phone'];
						
						}
						?>
						
						
							<div class="form-group">
						    <label for="" class="col-sm-2 control-label">Business Mode <span style='color:red;'>*</span></label>
							<div class="col-sm-2">
							    <select class="form-control" name="pincode_mode" id="pincode_mode">
							        <option value='0'>---Select Mode---</option>
							        <option value='air' selected>AIR</option>
							        <option value='surface'>SURFACE</option>
							    </select>
							</div>
							<div class="col-sm-2">
							   <input type="radio" name='pincode_type' value="b2b" checked>&ensp;B2B<br>
							   <input type="radio" name='pincode_type' value="b2c">&ensp;B2C
							</div>
						</div>
						
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Shipper Name <span style='color:red;'>*</span></label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" id="shipper_name" name="shipper_name" value="<?php if(isset($full_name)){ echo $full_name; } ?>">
							</div>
						</div>
							<div class="form-group">
							<label for="" class="col-sm-2 control-label">Shipper Address <span style='color:red;'>*</span></label>
							<div class="col-sm-6">
								<textarea class="form-control" name="shipper_address" id="shipper_address"  required style="height:100px;"><?php if(isset($address)){ echo $address;} ?></textarea>
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Shipper City <span style='color:red;'>*</span></label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" required class="form-control" name="shipper_city" id="shipper_city" value="<?php if(isset($city)){ echo $city; } ?>">
							</div>
						</div>
					
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Shipper State <span style='color:red;'>*</span></label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" required class="form-control" name="shipper_state" id="shipper_state" value="<?php if(isset($state)){echo $state;} ?>">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Shipper Pincode <span style='color:red;'>*</span></label>
							<div class="col-sm-6">
								<input type="number" autocomplete="off" required class="form-control" name="shipper_pincode" id="shipper_pincode" value="<?php if(isset($pincode)){echo $pincode;} ?>">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Shipper Phone <span style='color:red;'>*</span></label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="shipper_phone" id="shipper_phone" value="<?php if(isset($phone)){echo $phone;} ?>">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Consignee Name <span style='color:red;'>*</span></label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="consignee_name" value="<?php if(isset($_POST['consignee_name'])){echo $_POST['consignee_name'];} ?>">
							</div>
						</div>
							<div class="form-group">
							<label for="" class="col-sm-2 control-label">Consignee Address <span style='color:red;'>*</span></label>
							<div class="col-sm-6">
								<textarea class="form-control" name="consignee_address"  style="height:100px;"><?php if(isset($_POST['consignee_address'])){echo $_POST['consignee_address'];} ?></textarea>
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Consignee City <span style='color:red;'>*</span></label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="consignee_city" value="<?php if(isset($_POST['consignee_city'])){echo $_POST['consignee_city'];} ?>">
							</div>
						</div>
					
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Consignee State <span style='color:red;'>*</span></label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="consignee_state" value="<?php if(isset($_POST['consignee_state'])){echo $_POST['consignee_state'];} ?>">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Consignee Pincode <span style='color:red;'>*</span></label>
							<div class="col-sm-3">
								<input type="number" autocomplete="off" class="form-control" onkeyup='get_availability()' id="consignee_pincode" name="consignee_pincode" value="<?php if(isset($_POST['consignee_pincode'])){echo $_POST['consignee_pincode'];} ?>">
							</div>
								<div class="col-sm-5">
								<span id="availability"></span>
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Consignee Phone <span style='color:red;'>*</span></label>
							<div class="col-sm-6">
								<input type="number" autocomplete="off" class="form-control" name="consignee_phone" value="<?php if(isset($_POST['consignee_phone'])){echo $_POST['consignee_phone'];} ?>">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Product Description<span></span></label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="product_description" value="<?php if(isset($_POST['product_description'])){echo $_POST['product_description'];} ?>">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Pickup Entry Date<span></span></label>
							<div class="col-sm-6">
								<input type="date" autocomplete="off" class="form-control" name="date_added" value="<?php echo date("Y-m-d") ?>">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Quantity </label>
							<div class="col-sm-6">
								<input type="number" step='any' autocomplete="off" class="form-control" name="quantity" id="quantity" value="<?php if(isset($_POST['quantity'])){echo $_POST['quantity'];} ?>">
							</div>
						</div>
							<div class="form-group">
							<label for="" class="col-sm-2 control-label">No.Of Boxes <span style='color:red;'>*</span></label>
							<div class="col-sm-6">
								<input type="number" step='any' autocomplete="off" class="form-control" name="boxes" id="boxes" value="<?php if(isset($_POST['boxes'])){echo $_POST['boxes'];} ?>">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Actual Weight </label>
							<div class="col-sm-2">
								<input type="number" step=any  autocomplete="off" class="form-control" name="a_weight" id="a_weight" value="<?php if(isset($_POST['a_weight'])){echo $_POST['a_weight'];} ?>">
							</div>
						</div>
						<div class="row">
						    <div class="col-md-12">
						        	<div class="form-group">
							<label for="" class="col-sm-2 control-label">Volumetric Weight </label>
							<div class="col-sm-2">
								<input type="text" readonly autocomplete="off" class="form-control" name="v_weight" id="v_weight" value="<?php if(isset($_POST['v_weight'])){echo $_POST['v_weight'];} ?> " >
							</div>
							<label for="" class="col-sm-1 control-label">Vol.Length</label>
							<div class="col-sm-1">
								<input type="number" step=any  autocomplete="off" class="form-control" name="vw_length" id="vw_length" value="<?php if(isset($_POST['vw_length'])){echo $_POST['vw_length'];} ?>">
							</div>
							<label for="" class="col-sm-1 control-label">Vol.Breadth</label>
							<div class="col-sm-1">
								<input type="number" step=any  autocomplete="off" class="form-control" name="vw_breadth" id="vw_breadth" value="<?php if(isset($_POST['vw_breadth'])){echo $_POST['vw_breadth'];} ?>">
							</div>
							<label for="" class="col-sm-1 control-label">Vol.Height</label>
							<div class="col-sm-1">
								<input type="number" step=any  autocomplete="off" class="form-control" name="vw_height" id="vw_height" value="<?php if(isset($_POST['vw_height'])){echo $_POST['vw_height'];} ?>">
							</div>
						</div>
						    </div>
						</div>
					
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Charged Weight </label>
							<div class="col-sm-2">
								<input type="number" step=any  autocomplete="off" class="form-control" name="c_weight" id="c_weight" value="<?php if(isset($_POST['c_weight'])){echo $_POST['c_weight'];} ?>">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Taxable Value <span style='color:red;'>*</span></label>
							<div class="col-sm-6">
								<input type="number" step='any' autocomplete="off" class="form-control" onkeyup="cal_gst()" name="taxable_value" id="taxable_value" value="<?php if(isset($_POST['taxable_value'])){echo $_POST['taxable_value'];} ?>">
							</div>
						</div>
							<div class="form-group">
							<label for="" class="col-sm-2 control-label">MRP </label>
							<div class="col-sm-6">
								<input type="number" step=any  autocomplete="off" class="form-control" name="mrp" value="<?php if(isset($_POST['mrp'])){echo $_POST['mrp'];} ?>">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">HSN Code <span style='color:red;'>*</span></label>
							<div class="col-sm-6">
								<input type="hidden" class="form-control" style="padding: 6px;height: 35px;" id="hsn_code" name="hsn_code" value="<?php if(isset($_POST['hsn_code'])){echo $_POST['hsn_code'];} ?>" required>
                                <input type="text" class="form-control" style="padding: 6px;height: 35px;"  id="txt_hsncode" placeholder="Search HSN Code" required>
                                
                                <input type="hidden"  id="igst"  name="igst" >
                                <input type="hidden"  id="cgst"  name="cgst" >
                                <input type="hidden"  id="sgst"  name="sgst" >
                                
							</div>
						</div>
						
                        <ul id="searchResult"></ul> 
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Discount (if any)<span></span></label>
							<div class="col-sm-6">
								<input type="number" step='any' autocomplete="off" class="form-control" name="discount" value="<?php if(isset($_POST['discount'])){echo $_POST['discount'];} ?>">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Gst Type <span style='color:red;'>*</span></label>
							<div class="col-sm-2">
							    <select name="gst_rate" onchange="cal_gst()" class="form-control" id="gst_rate">
    						     <option value="">Select Type</option>
    						     <option value="gr_igst">IGST</option>
    						     <option value="gr_cgst">CGST/SGST</option>
    						    </select>
    						</div>
						</div>
						
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Gst Amount </label>
							<div class="col-sm-6">
								<input type="number" step=any  autocomplete="off" class="form-control" name="gst_amount" id="gst_amount" value="<?php if(isset($_POST['gst_amount'])){echo $_POST['gst_amount'];} ?>">
							</div>
						</div>
					    <div class="form-group">
							<label for="" class="col-sm-2 control-label">Invoice Value </label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="invoice_value" id="invoice_value" value="<?php if(isset($_POST['invoice_value'])){echo $_POST['invoice_value'];} ?>">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Ewaybill </label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="ewaybill" value="<?php if(isset($_POST['ewaybill'])){echo $_POST['ewaybill'];} ?>">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Buyer Gst </label>
							<div class="col-sm-6">
							    <input type="text" autocomplete="off" class="form-control col-sm-4" name="buyer_gst" value="<?php if(isset($_POST['buyer_gst'])){echo $_POST['buyer_gst'];} ?>" >
    						     
    						</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">Seller Gst </label>
							<div class="col-sm-6">
							    <input type="text" autocomplete="off" class="form-control " name="seller_gst" value="<?php if(isset($_POST['seller_gst'])){echo $_POST['seller_gst'];} ?>" >
    						
    						</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">RTO Name </label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="rto_name" id="rto_name" value="<?php if(isset($full_name)){ echo $full_name; } ?>">
							</div>
						</div>
							<div class="form-group">
							<label for="" class="col-sm-2 control-label">RTO Address </label>
							<div class="col-sm-6">
								<textarea class="form-control" name="rto_address" id="rto_address"  style="height:100px;"><?php if(isset($address)){ echo $address;} ?></textarea>
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">RTO City </label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="rto_city" id="rto_city" value="<?php if(isset($city)){echo $city;} ?>">
							</div>
						</div>
					
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">RTO State </label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="rto_state" id="rto_state" value="<?php if(isset($state)){echo $state;} ?>">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">RTO Pincode </label>
							<div class="col-sm-6">
								<input type="number" autocomplete="off" class="form-control" name="rto_pincode" id="rto_pincode" value="<?php if(isset($pincode)){echo $pincode;} ?>">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label">RTO Phone </label>
							<div class="col-sm-6">
								<input type="text" autocomplete="off" class="form-control" name="rto_phone" id="rto_phone" value="<?php if(isset($phone)){echo $phone;} ?>">
							</div>
						</div>
						<div class="form-group">
							<label for="" class="col-sm-2 control-label"></label>
							<div class="col-sm-6">
								<button type="submit" id='form_submit' class="btn btn-success pull-left" disabled name="form1">Submit</button>
							</div>
						</div>
					</div>
				</div>
			</form>
		</div>
	</div>
</section>
<script>
 $(document).ready(function(){
    $("#txt_hsncode").keyup(function(){
        var search = $(this).val();
        if(search != ""){
            $.ajax({
                url: 'getsearch_hsncode.php',
                type: 'post',
                data: {search:search},
                dataType: 'json',
                success:function(response){
                    var len = response.length;
                    $("#searchResult").empty();
                    for( var i = 0; i<len; i++){
                        var id = response[i]['id'];
                        var hsncode = response[i]['hsncode'];
                        $("#searchResult").append("<li value='"+hsncode+"'>"+hsncode+"</li>");
                         }                    
                    // binding click event to li
                    $("#searchResult li").bind("click",function(){
                        setText(this);
                    });
                }
            });
        }
    });
});
function setText(element){
    var value = $(element).text();
    var userid = $(element).val();
    $("#txt_hsncode").val(value);
    $("#hsn_code").val(userid);
    $("#searchResult").empty(); 
     
      if(userid != ""){
            $.ajax({
                url: 'getsearch_hsncode.php',
                type: 'post',
                data: {search:userid},
                dataType: 'json',
                success:function(response){
                    var len = response.length;
                    for( var i = 0; i<len; i++){
                        var id = response[i]['id'];
                        var hsncode = response[i]['hsncode'];
                        var igst = response[i]['igst'];
                        var cgst = response[i]['cgst'];
                        var sgst = response[i]['sgst'];
                        
                         $("#igst").val(igst);
                         $("#cgst").val(cgst);
                         $("#sgst").val(sgst);
                    }                    
                }
            });
         }
      }
</script>

<script>
    $(document).ready(function(){
          /***********    For fetching customer address and phone number ***********/
         $('#order_type').on('change',function(){
             var type=$(this).val();
             if(type=='prepaid')
             {
                 $('#collectable_amount').val('0');
                 $('#collectable').hide();
             }
             else
             {
                 $('#collectable_amount').val('');
                 $('#collectable').show();
             }
         });
        
        
         /***********    For fetching gst number ***********/
         $('#client_id').on('change',function(){
           var client_id=$(this).val();
         //  alert(client_id);
           if(client_id!=''){
                $.ajax({
                  type:'POST',
                  url:'get_client_data.php',
                  data:{id:client_id},
                   dataType: 'json',
                  success:function(response){
                      var len = response.length;
                      $('#shipper_name').val(response[0]['full_name']);
                      $('#rto_name').val(response[0]['full_name']);
                      
                      $('#shipper_address').val(response[0]['address']);
                      $('#rto_address').val(response[0]['address']);
                      
                      $('#shipper_city').val(response[0]['city']);
                      $('#rto_city').val(response[0]['city']);
                      
                      $('#shipper_state').val(response[0]['state']);
                      $('#rto_state').val(response[0]['state']);
                      
                      $('#shipper_phone').val(response[0]['phone']);
                      $('#rto_phone').val(response[0]['phone']);
                      
                      $('#shipper_pincode').val(response[0]['pincode']);
                      $('#rto_pincode').val(response[0]['pincode']);
                      
                  }
               });
           }
       });
       /***********    For checking Unique 3PLAWB number ***********/
          $("#3pl_awb").keyup(function(){
              var awb=$(this).val();
              var courier_id=$('#courier_id').val();
              if(awb!=''){
              $.ajax({
                  type:'POST',
                  url:'get_unique_awb.php',
                  data:{awb:awb,type:'pl3_awb',courier_id:courier_id},
                   dataType: 'json',
                  success:function(response){
                      if(response[0]['error']=='0')
                      {
                          $("#ncheck1").css('color','green'); 
                         $("#ncheck1").text(response[0]['txt']); 
                      }
                      else
                      {
                          $("#ncheck1").css('color','red'); 
                         $("#ncheck1").text(response[0]['txt']); 
                      }
                  }
                });
              }
            });
              /***********    For checking Unique 3PLAWB number ***********/
          $("#courier_id").change(function(){
              var awb=$('#3pl_awb').val();
              var courier_id=$('#courier_id').val();
              if(awb!=''){
              $.ajax({
                  type:'POST',
                  url:'get_unique_awb.php',
                  data:{awb:awb,type:'pl3_awb',courier_id:courier_id},
                   dataType: 'json',
                  success:function(response){
                      if(response[0]['error']=='0')
                      {
                          $("#ncheck1").css('color','green'); 
                         $("#ncheck1").text(response[0]['txt']); 
                      }
                      else
                      {
                          $("#ncheck1").css('color','red'); 
                         $("#ncheck1").text(response[0]['txt']); 
                      }
                  }
                });
              }
            });
             /***********    For checking Unique CSCS AWB number ***********/
          $("#cscs_awb").keyup(function(){
              var awb=$(this).val();
              $.ajax({
                  type:'POST',
                  url:'get_unique_awb.php',
                  data:{awb:awb,type:'cscs_awb'},
                   dataType: 'json',
                  success:function(response){
                      if(response[0]['error']=='0')
                      {
                          $("#ncheck").css('color','green'); 
                         $("#ncheck").text(response[0]['txt']); 
                      }
                      else
                      {
                          $("#ncheck").css('color','red'); 
                         $("#ncheck").text(response[0]['txt']); 
                      }
                  }
                });
            });
            /***********    For checking Unique REF Number ***********/
          $("#ref_no").keyup(function(){
              var awb=$(this).val();
              $.ajax({
                  type:'POST',
                  url:'get_unique_awb.php',
                  data:{awb:awb,type:'ref_no'},
                   dataType: 'json',
                  success:function(response){
                      if(response[0]['error']=='0')
                      {
                          $("#ncheck2").css('color','green'); 
                         $("#ncheck2").text(response[0]['txt']); 
                      }
                      else
                      {
                          $("#ncheck2").css('color','red'); 
                         $("#ncheck2").text(response[0]['txt']); 
                      }
                  }
                });
            });
            
    });         
</script>         
<script>
    $(document).ready(function(){
       $(function() {    // Makes sure the code contained doesn't run until
            $('#gst_rate').change(function(){
                $('.gs_rate').hide();
                $('#' + $(this).val()).show();
            });
            
            $('#buyer_gst').change(function(){
                $('.buy_gst').hide();
                $('#' + $(this).val()).show();
            });
            
            $('#seller_gst').change(function(){
                $('.sell_gst').hide();
                $('#' + $(this).val()).show();
            });
        });
    });
    
    $(document).ready(function(){
        $('#vw_length').keyup(calculate);
        $('#vw_breadth').keyup(calculate);
        $('#vw_height').keyup(calculate);
        $('#quantity').keyup(calculate);
        $('#a_weight').keyup(type);
        
        $('#vw_length').change(calculate);
        $('#quantity').change(calculate);
        $('#vw_breadth').change(calculate);
        $('#vw_height').change(calculate);
        $('#a_weight').change(type);
    });
    function calculate()
    {
        var qty=$('#quantity').val();
        var v_weight=parseFloat(($('#vw_length').val() * $('#vw_breadth').val() * $('#vw_height').val())/(5000*qty));
        v_weight=v_weight.toFixed(3);
        $('#v_weight').val(v_weight);
        type()
    }
    
    function type(){
        var act_weight=$('#a_weight').val();
        var vol_weight=$('#v_weight').val();
        if(Number(act_weight)>Number(vol_weight))
        {
            $('#c_weight').val(act_weight);
        }
        else
        {
           $('#c_weight').val(vol_weight); 
        }
    }
    
    function get_availability()
{
            var pincode_mode=$('#pincode_mode').val();
             var pincode_type=$('input[name="pincode_type"]:checked').val();
             var pincode=$('#consignee_pincode').val();
            var tot_length= $("#consignee_pincode").val().replace(/ /g,'').length;
             if(tot_length>5){
              $.ajax({
                  type:'POST',
                  url:'get_oda_pincode.php',
                  data:{pincode_mode:pincode_mode,pincode_type:pincode_type,pincode:pincode},
                  success:function(response){
                      if(response==1)
                      {    
                          $('#form_submit').prop('disabled', false);
                          $('#availability').css('color', 'green');
                          $('#availability').html('Service Available !');
                      }
                      else if(response==0)
                      {
                           $('#form_submit').prop('disabled', true);
                           $('#availability').css('color', 'red');
                           $('#availability').html('Service Not Available For Your Pincode !');
                      }
                      }
                    });
                  }
                }   

                function cal_gst()
                {   
                     var taxable=$('#taxable_value').val();
                     var gst_type=$('#gst_rate').val();
                     var igst=$('#igst').val();
                     var cgst=$('#cgst').val();
                     var sgst=$('#sgst').val();
                     if(gst_type=='gr_igst')
                     {
                        var gst_amount=(taxable*igst)/100;
                     }
                     else if(gst_type=='gr_cgst')
                     {
                         var gst=parseFloat(cgst)+parseFloat(sgst);
                         var gst_amount=(taxable*gst)/100;
                     }
                     $('#gst_amount').val(gst_amount);
                     var invoice=0;
                     invoice=parseFloat(taxable)+parseFloat(gst_amount);
                     $('#invoice_value').val(invoice);
                }
</script>

<?php require_once('footer.php'); ?>