<?php require_once('header.php'); 
$uuid=$fn->gen_uuid();
if(isset($_POST['form1'])) {
    
    $statement = $pdo->prepare("UPDATE tbl_ftl_details_new SET ftl_number=?,ftl_date=?,transport_name=?,driver_mobile_no=?,vechicle_no=?,
    vechicle_type=?,mode_of_dispatch=?,pick_up_form=?,delivery_location=?,delivery_date=?,
    total_fright=?,loading_unloading=?,detention=?,advance=?,balance=?,
    delivery_commitment_date=?,deliverd_date=?,pod_received_date=?,vehicle_owner_name=?,driver_name=?,
    contact_no=?,alter_no=?,vender_advance_slip_no=?,vender_advance_date=?,consignee_id=?,
    docket_no=?,cus_fright_charge=?,cus_vendor_cost=?,cus_loading_unloading=?,cus_other_charges=?,
    cus_pl=?,bank_name=?,account_no=?,ifsc_code=?,prepared_by=?,
    marketing_executive=?,approved_by=?,status=?,loading_chrg_init=?,loading_chrg_final=? WHERE id=?");
	$resultss = $statement->execute(array($_POST['ftl_number'],$_POST['ftl_date'],$_POST['transport_name'],$_POST['driver_mobile_no'],$_POST['vechicle_no'],
	$_POST['vechicle_type'],$_POST['mode_of_dispatch'],$_POST['pick_up_form'],$_POST['delivery_location'],$_POST['delivery_date'],
	$_POST['total_fright'],$_POST['loading_unloading'],$_POST['detention'],$_POST['advance'],$_POST['balance'],
	$_POST['delivery_commitment_date'],$_POST['deliverd_date'],$_POST['pod_received_date'],$_POST['vehicle_owner_name'],$_POST['driver_name'],
	$_POST['contact_no'],$_POST['alter_no'],$_POST['vender_advance_slip_no'],$_POST['vender_advance_date'],$_POST['consignee_id'],
	$_POST['docket_no'],$_POST['cus_fright_charge'],$_POST['cus_vendor_cost'],$_POST['cus_loading_unloading'],$_POST['cus_other_charges'],
	$_POST['cus_pl'],$_POST['bank_name'],$_POST['account_no'],$_POST['loading_chrg_init'],$_POST['loading_chrg_final'],
	$_POST['marketing_executive'],$_POST['approved_by'],'1',$_POST['ifsc_code'],$_POST['prepared_by'],$_REQUEST['id']));
    
    
	if($resultss){
	    $success_message = 'FTL Booking Details Is Updated Successfully';

	}else{
	    
	    $error_message = 'Something Went Wrong Pls Check The FTL Booking Add Details';
	}
	
}	
			
	
?>

<section class="content-header" style="background-color: white;">
	    
	<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>
				<p>Print The FTL DETAILS</p>
				<a href="ftl-booking-print.php?id=<?=$_GET['id']?>" target="_blank" class="btn btn-warning" style="text-decoration: none;">Print FTL</a>
			</div>
			<?php endif; ?>
		</div>
		<div class="col-md-4" style="text-align: left;">
			<h4><i class="fa fa-map-marker"></i> Update FTL Bookings Details</h4>
		</div>
		<div class="col-md-8" style="text-align: right;"> 
	         <a href="ftl-booking-list.php" class="btn btn-warning btn-sm"><i class="fa fa-arrow-left"></i> Back to Booking List</a>
		</div>
	</div> 
	
	<?php
if(!isset($_REQUEST['id'])) {
	header('location: logout.php');
	exit;
} else {
	// Check the id is valid or not
	$statement = $pdo->prepare("SELECT * FROM tbl_ftl_details_new WHERE id=?");
	$statement->execute(array($_REQUEST['id']));
	$total = $statement->rowCount();
	$result = $statement->fetchAll(PDO::FETCH_ASSOC);
	if( $total == 0 ) {
		header('location: logout.php');
		exit;
	}
}
?>
	
	
	<div class="row">
		<div class="col-md-12">
		    <form class="form-horizontal" action="" method="post" id="add_form" enctype="multipart/form-data">
		        <div class="box box-warning" style="box-shadow: rgba(0, 0, 0, 0.19) 0px 10px 20px, rgba(0, 0, 0, 0.23) 0px 6px 6px;">
					<div class="box-body">
					    <div class="row" style="margin: 20px 0px;">
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>FTL ORDER/ADVANCE SLIP NO<span style='color:red;'>*</span></label>
						            <input type="text" name="ftl_number" id="ftl_number" value="<?=$result[0]['ftl_number']?>" class="form-control">
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>DATE<span style='color:red;'>*</span></label>
						            <input type="date" name="ftl_date" id="ftl_date" value="<?=$result[0]['ftl_date']?>" class="form-control">
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>Transporter name<span style='color:red;'>*</span></label>
						            <input type="text" name="transport_name" id="transport_name" value="<?=$result[0]['transport_name']?>" class="form-control">
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>DRIVER MOB. NO.<span style='color:red;'>*</span></label>
						            <input type="text" name="driver_mobile_no" id="driver_mobile_no" value="<?=$result[0]['transport_name']?>" class="form-control">
						        </div>
						        
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>VEHICLE NO<span style='color:red;'>*</span></label>
						            <input type="text" name="vechicle_no" id="vechicle_no" value="<?=$result[0]['vechicle_no']?>" class="form-control">
						        </div>
						        
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>VEHICLE TYPE<span style='color:red;'>*</span></label>
						            <input type="text" name="vechicle_type" id="vechicle_type" value="<?=$result[0]['vechicle_type']?>" class="form-control">
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>MODE OF DISPATCH<span style='color:red;'>*</span></label>
						            <input type="text" name="mode_of_dispatch" id="mode_of_dispatch" value="<?=$result[0]['mode_of_dispatch']?>" class="form-control">
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>PICK UP FROM<span style='color:red;'>*</span></label>
						            <input type="text" name="pick_up_form" id="pick_up_from"  value="<?=$result[0]['ftl_number']?>" class="form-control">
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>Delivery Location<span style='color:red;'>*</span></label>
						            <input type="text" name="delivery_location" id="delivery_location" value="<?=$result[0]['delivery_location']?>" class="form-control">
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>Delivery State<span style='color:red;'>*</span></label>
						            <input type="text" name="delivery_date" id="delivery_date" value="<?=$result[0]['delivery_date']?>" class="form-control">
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>Total Frieght<span style='color:red;'>*</span></label>
						            <input type="text" name="total_fright" id="total_fright" value="<?=$result[0]['total_fright']?>" class="form-control">
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>LOADING/UNLOADING<span style='color:red;'>*</span></label>
						            <select name="loading_unloading" id="loading_unloading" class="form-control select2" required>
								       <option value=''>Select LOADING/UNLOADING</option>
									   <option value="LOADING" <?php if($result[0]['loading_unloading']=='LOADING'){ ?>selected<?php } ?>>LOADING</option>
									   <option value="UNLOADING" <?php if($result[0]['loading_unloading']=='UNLOADING'){ ?>selected<?php } ?>>UNLOADING</option>
								</select>
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>LOADING/UNLOADING CHARGES - INITIAL<span style='color:red;'>*</span></label>
						            <input type="number" name="loading_chrg_init" id="loading_chrg_init" value="<?=$result[0]['loading_chrg_init']?>" class="form-control">
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>DETENTION<span style='color:red;'>*</span></label>
						            <input type="text" name="detention" id="detention" value="<?=$result[0]['detention']?>" class="form-control">
						        </div>
						        
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>ADVANCE<span style='color:red;'>*</span></label>
						            <input type="text" name="advance" id="advance" value="<?=$result[0]['advance']?>" class="form-control">
						        </div>
						        
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>BALANCE<span style='color:red;'>*</span></label>
						            <input type="text" name="balance" id="balance" value="<?=$result[0]['balance']?>" class="form-control">
						        </div>
						        
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>Delivery Commitment date<span style='color:red;'>*</span></label>
						            <input type="date" name="delivery_commitment_date" id="delivery_commitment_date" value="<?=$result[0]['delivery_commitment_date']?>" class="form-control">
						        </div>
						        
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>Delivered date<span style='color:red;'>*</span></label>
						            <input type="date" name="deliverd_date" id="deliverd_date" value="<?=$result[0]['deliverd_date']?>" class="form-control">
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>POD Received date<span style='color:red;'>*</span></label>
						            <input type="date" name="pod_received_date" id="pod_received_date" value="<?=$result[0]['pod_received_date']?>" class="form-control">
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>Vehicle Owner name<span style='color:red;'>*</span></label>
						            <input type="text" name="vehicle_owner_name" id="vehicle_owner_name" value="<?=$result[0]['vehicle_owner_name']?>" class="form-control">
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>Driver's Name<span style='color:red;'>*</span></label>
						            <input type="text" name="driver_name" id="driver_name" value="<?=$result[0]['driver_name']?>" class="form-control">
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>Contact No<span style='color:red;'>*</span></label>
						            <input type="number" name="contact_no" id="contact_no" value="<?=$result[0]['contact_no']?>" class="form-control">
						        </div>
						        
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>Alter No<span style='color:red;'>*</span></label>
						            <input type="number" name="alter_no" id="alter_no" value="<?=$result[0]['alter_no']?>" class="form-control">
						        </div>
						        
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>Vender Advance slip no<span style='color:red;'>*</span></label>
						            <input type="number" name="vender_advance_slip_no" value="<?=$result[0]['vender_advance_slip_no']?>" id="vender_advance_slip_no" class="form-control">
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>Vender Advance Date<span style='color:red;'>*</span></label>
						            <input type="date" name="vender_advance_date" id="vender_advance_date" value="<?=$result[0]['vender_advance_date']?>" class="form-control">
						        </div>
						        
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>Select Consignee<span style='color:red;'>*</span></label>
						            <select name="consignee_id" id="consignee_id" class="form-control select2">
    							        <option value="">Select Consignee</option>
    							       <?php
							        	$statement = $pdo->prepare("SELECT * FROM tbl_customer");
            							$statement->execute();
            							$cus_result = $statement->fetchAll(PDO::FETCH_ASSOC);
                						 foreach($cus_result as $rows)
                						 {?>
                						 <option value="<?=$rows['id']?>" <?php if($result[0]['consignee_id']==$rows['id']){ ?>selected<?php } ?>><?=$rows['cust_name']?></option>
                						 <?php } ?>
    							    </select>
						        </div>
								<div class="col-md-3" style="margin-top: 10px;">
						            <label>Venus Docket No<span style='color:red;'>*</span></label>
						            <input type="text" name="docket_no" id="docket_no" value="<?=$result[0]['docket_no']?>" class="form-control">
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>Our Frieght Charges<span style='color:red;'>*</span></label>
						            <input type="text" name="cus_fright_charge" id="cus_fright_charge" value="<?=$result[0]['cus_fright_charge']?>" class="form-control">
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>Vender cost<span style='color:red;'>*</span></label>
						            <input type="text" name="cus_vendor_cost" id="cus_vendor_cost" value="<?=$result[0]['cus_vendor_cost']?>" class="form-control">
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>LOADING/UNLOADING<span style='color:red;'>*</span></label>
						            <select name="cus_loading_unloading" id="cus_loading_unloading" class="form-control select2" required>
        							       <option value=''>Select LOADING/UNLOADING</option>
        								   <option value="LOADING" <?php if($result[0]['cus_loading_unloading']=='LOADING'){ ?>selected<?php } ?>>LOADING</option>
									   <option value="UNLOADING" <?php if($result[0]['cus_loading_unloading']=='UNLOADING'){ ?>selected<?php } ?>>UNLOADING</option>
        							</select>
						        </div>
                                <div class="col-md-3" style="margin-top: 10px;">
						            <label>LOADING/UNLOADING CHARGES - FINAL<span style='color:red;'>*</span></label>
						            <input type="number" name="loading_chrg_final" id="loading_chrg_final" class="form-control" value="<?=$result[0]['loading_chrg_final']?>" >
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>Other Charges<span style='color:red;'>*</span></label>
						            <input type="text" name="cus_other_charges" id="cus_other_charges" value="<?=$result[0]['cus_other_charges']?>" class="form-control">
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>OUR P/L<span style='color:red;'>*</span></label>
						            <input type="text" name="cus_pl" id="cus_pl" value="<?=$result[0]['cus_pl']?>" class="form-control">
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>Bank Name<span style='color:red;'>*</span></label>
						            <input type="text" name="bank_name" id="bank_name"  value="<?=$result[0]['bank_name']?>" class="form-control">
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>Account no<span style='color:red;'>*</span></label>
						            <input type="text" name="account_no" id="account_no" value="<?=$result[0]['account_no']?>" class="form-control">
						        </div>
						        
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>IFSC<span style='color:red;'>*</span></label>
						            <input type="text" name="ifsc_code" id="ifsc_code" value="<?=$result[0]['ifsc_code']?>" class="form-control">
						        </div>
						        
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>Prepared by<span style='color:red;'>*</span></label>
						            <input type="text" name="prepared_by" id="prepared_by" value="<?=$result[0]['prepared_by']?>" class="form-control">
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>Marketing Executive<span style='color:red;'>*</span></label>
						            <input type="text" name="marketing_executive" id="marketing_executive"  value="<?=$result[0]['marketing_executive']?>" class="form-control">
						        </div>
						        <div class="col-md-3" style="margin-top: 10px;">
						            <label>Approved by<span style='color:red;'>*</span></label>
						            <input type="text" name="approved_by" id="approved_by" value="<?=$result[0]['approved_by']?>" class="form-control">
						        </div>
						        <br>
						        <div class="form-group">
        							<div class="col-sm-12">
        								<center><input type="submit" id="submit" class="btn btn-success btn-sm" name="form1" value="Save FTL Details"></center>
        							</div>
        						</div>
						        			        
						 </div>
					</div>
				</div>
		    </form>
		</div>
	</div>
</section>



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