<?PHP
ob_start();
session_start();
include 'connect.php';
if(isset($_SESSION['adminemail']))
{
$user=$_SESSION['adminemail'];

$gtp=mysql_query("select * from admin where username='$user'");
$gtp1=mysql_fetch_array($gtp);

include 'top.php';
?>



			<div class="main-content">
				<div class="main-content-inner">
					<div class="breadcrumbs ace-save-state" id="breadcrumbs">
						<ul class="breadcrumb">
							<li>
								<i class="ace-icon fa fa-home home-icon"></i>
								<a href="#">Home</a>
							</li>
							<li class="active">Delivery</li>
						</ul><!-- /.breadcrumb -->
					</div>

					<div class="page-content">
			

						<div class="page-header">
                        
<?php

$aca=mysql_query("select * from financial where user='$user' order by ID desc");
$aca1=mysql_fetch_array($aca);

$financial=$aca1['financial'];

?>
                        
                        <table style="width:100%;">
                        
                        <tr><td style="width:50%;">
                        
							<h1>
								Delivery
							</h1>
                            
                            </td>
                            
                            <td style="width:50%; text-align:right; padding-right:15px; font-size:15px;">
                            
                            <i class="fa fa-calendar"></i>&nbsp; <?php echo $financial; ?>
                            
                            </td></tr></table>
                            
						</div><!-- /.page-header -->

						<div class="row">
							<div class="col-xs-12">
                            
								<!-- PAGE CONTENT BEGINS -->


<script src="assets/js/jquery.js"></script>

<script>
	
jQuery(function($){
		   
	// simple jQuery validation script
	$('#course').submit(function(){
		
		var valid = true;
		var errormsg = 'This field is required!';
		var errorcn = 'error';
		
		$('.' + errorcn, this).remove();			
		
		$('#required', this).each(function(){
			var parent = $(this).parent();
			if( $(this).val() == '' ){
				var msg = $(this).attr('title');
				msg = (msg != '') ? msg : errormsg;
				$('<span style="font-size:13px;color:#FF0000; padding-left:3px;" class="'+ errorcn +'">'+ msg +'</span>')
					.appendTo(parent)
					.fadeIn('fast')
					.click(function(){ $(this).remove(); });
				valid = false;
			};
		});
		
		return valid;
		
		$('button:submit').prop('disabled', true);
		
	});
	
});	

</script>   
								
										
                                        
<?php

if(isset($_GET['id']))
{

$id=$_GET['id'];

if(isset($_POST['submit']))
{

$id=$_POST['id'];

$date=$_POST['date'];

$invoiceno = $_POST['invoiceno'];

$vehicleno = $_POST['vehicleno'];

$departuredate=$_POST['departuredate'];

$arrivaldate=$_POST['arrivaldate'];

$startingkm=$_POST['startingkm'];

$closingkm=$_POST['closingkm'];

$driver=$_POST['driver'];

$phone=$_POST['phone'];

// now we insert it into the database

$date=date('Y-m-d',strtotime($date));

if($invoiceno)
{
	
$departuredate=date('Y-m-d',strtotime($departuredate));
$arrivaldate=date('Y-m-d',strtotime($arrivaldate));

$in= "update delivery set date='$date',invoiceno='$invoiceno',vehicleno='$vehicleno',departuredate='$departuredate',arrivaldate='$arrivaldate',startkm='$startingkm',endkm='$closingkm',driver='$driver',phone='$phone' where ID='$id'";

$in1 = mysql_query($in) or die(mysql_error());

if($in1)
{

 header("location:viewdelivery.php?s=1");

}

}

else
{

 header("location:viewdelivery.php?s=2");

}


}

else
{

$ex=mysql_query("select * from delivery where ID='".$id."'");
$ex1=mysql_fetch_array($ex);

echo'<form id="course" action="viewdelivery.php?id='.$id.'" method="post">

<input type="hidden" name="id" value="'.$id.'" />

<table width="70%" style="margin:auto; line-height:35px;">

<tr><td>Date</td><td>:</td><td><input type="text" name="date" class="datepicker" id="required" title="*" value="'.date('d-m-Y',strtotime($ex1['date'])).'" autocomplete="off" /></td></tr>

<tr><td width="32%">Invoice No. <span class="red">*</span></td><td width="11">:</td><td><select name="invoiceno" id="required" title="*" style="width:220px;">
<option value="">Select Invoiceno</option>';

?>

<option value="<?php echo $ex1['invoiceno'] ?>" <?php if($ex1['invoiceno']==$ex1['invoiceno']){ echo'selected="selected"'; } ?>><?php echo $ex1['invoiceno']; ?></option>

<?php

$invc=mysql_query("select * from invoice group by invoiceno order by invoiceno asc");
while($invc1=mysql_fetch_array($invc))
{

$chk=mysql_query("select * from delivery where invoiceno='$invc1[invoiceno]'");
$chk1=mysql_num_rows($chk);

if($chk1==0)
{
echo"<option value='".$invc1['invoiceno']."'>".$invc1['invoiceno']."</option>";
}
	
}

echo'</select></td></tr>

<tr><td>Vehicle No. <span class="red">*</span></td><td>:</td><td><select name="vehicleno" id="required" title="*" style="width:220px;">

<option value="">Select Vehicle No</option>';

$sel=mysql_query("select * from transport order by ID asc");
while($sel1=mysql_fetch_array($sel))
{

$svno="<option value='".$sel1['vehicleno']."'>".$sel1['vehicleno']."</option>";
$svno=str_replace("<option value='".$sel1['vehicleno']."'","<option value='".$sel1['vehicleno']."' selected",$svno);
echo $svno;
	
}

echo'</select></td></tr>

<tr><td>Departure Date <span class="red">*</span></td><td>:</td><td><input autocomplete="off" type="text" name="departuredate" class="datepicker" id="required" title="*" value="'.date('d-m-Y',strtotime($ex1['departuredate'])).'" /></td></tr>

<tr><td>Arrival Date <span class="red">*</span></td><td>:</td><td><input autocomplete="off" type="text" name="arrivaldate" class="popupdatepicker" id="required" title="*" value="'.date('d-m-Y',strtotime($ex1['arrivaldate'])).'" /></td></tr>

<tr><td>Starting Km <span class="red">*</span></td><td>:</td><td><input autocomplete="off" type="text" name="startingkm" id="required" title="*" value="'.$ex1['startkm'].'" /></td></tr>

<tr><td>Closing Km <span class="red">*</span></td><td>:</td><td><input autocomplete="off" type="text" name="closingkm" id="required" title="*" value="'.$ex1['endkm'].'" /></td></tr>

<tr><td>Driver <span class="red">*</span></td><td>:</td><td><input autocomplete="off" type="text" name="driver" id="required" title="*" value="'.$ex1['driver'].'" /></td></tr>

<tr><td>Phone <span class="red">*</span></td><td>:</td><td><input autocomplete="off" type="text" name="phone" id="required" title="*" value="'.$ex1['phone'].'" /></td></tr>

<tr><td colspan="3" style="text-align:center; padding-top:7px;"><button type="submit" name="submit" class="btn btn-sm btn-primary">Submit</button></td></tr>

</table>

</form>';

}

}

else
	{
		
	
		
		
	if (isset($_GET['s'])) 	
	{
	 $status=$_GET['s'];
		
		 if($status=='1')
		 {
			 echo'<div class="alert alert-block alert-success">
									<button type="button" class="close" data-dismiss="alert">
										<i class="ace-icon fa fa-times"></i>
									</button>
						Values Edited Successfully.
				  </div>';				  
		 }
		 if($status=='7')
		 {
			 echo'<div class="alert alert-block alert-success">
									<button type="button" class="close" data-dismiss="alert">
										<i class="ace-icon fa fa-times"></i>
									</button>
						Values Deleted Successfully.
				  </div>';				  
		 }
	}		


echo'<table style="width:99%; margin:11px auto 10px auto;">
                                        
                                        <tr><td style="width:20%;">
                                        <a href="delivery.php"><button class="btn btn-minier btn-info">+ Add Delivery</button></a>
                                        </td>
                                        
                                        <td style="width:50%;"></td>
                                        
                                        <td style="width:30%;">
                                        
                                        </td>
                                        
                                        </tr>
                                        
                                        </table>';

	echo"<table id='dynamic-table' class='table table-striped table-bordered table-hover'>

	<thead><th style='width:7%;'>S.No</th><th style='width:12%;'>Vehicle No.</th><th style='width:10%;'>Invoiceno</th>
	<th style='width:10%;'>Starting Km</th><th style='width:10%;'>Closing Km</th><th style='width:13%;'>Driver</th>
	<th style='width:12%;'>Phone</th><th style='width:10%;'>Edit</th></thead>";

	$getsite3="select * from delivery order by ID asc";
	$getsite4=mysql_query($getsite3) or die("Could not get");
	$sno=0;
	while($getsite5=mysql_fetch_array($getsite4))
	{
		$sno=$sno+1;

		echo"<tr><td>".$sno."</td><td>".$getsite5['vehicleno']."</td><td>".$getsite5['invoiceno']."</td>
		<td>".$getsite5['startkm']."</td><td>".$getsite5['endkm']."</td><td>".$getsite5['driver']."</td>
		<td>".$getsite5['phone']."</td><td>
		
														<div class='hidden-sm hidden-xs btn-group'>
														
														<a href='viewdelivery1.php?id=".$getsite5['ID']."' title='View'>
																<i class='ace-icon fa fa-search-plus bigger-100 blue'></i></a> &nbsp;";
														
															if($gtp1['type']!='staff')
															{
															echo"<a href='viewdelivery.php?id=".$getsite5['ID']."' title='Edit'>
																<i class='ace-icon fa fa-pencil bigger-100 green'></i></a>";
															}
															
														 echo"</div>
		</td></tr>";

		}

		echo "</table>";

	}

?>




										<!-- PAGE CONTENT ENDS -->
									</div><!-- /.col -->
								</div><!-- /.row -->
							</div><!-- /.page-content -->
						</div>
					</div><!-- /.main-content -->


<?php
include 'bottom.php';
}
else
{

 header("location:login.php");
}
ob_flush();

?>