<?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>

$(".bank").live('change',function() {

		  var bank=$(this).val();

		  var dataString = 'bank='+ bank;

		  //alert(dataString);

		  $.ajax

		  ({

		  type: "GET",

		  url: "getacc.php",

		  data: dataString,

		  cache: false,

		  success: function(resp)

		  {
		  
		  $('.account').html($('#account',resp).html());

		  }

		  });

});


$(".category").live('change',function() {

		  var category=$(this).val();

		  var dataString = 'category='+ category;

		  //alert(dataString);

		  $.ajax

		  ({

		  type: "GET",

		  url: "getsubcategory.php",

		  data: dataString,

		  cache: false,

		  success: function(resp)

		  {
		  
		  $('.subcategory').html($('#subcategory',resp).html());
		  
		  }

		  });

});
		  
</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;
			};
		});
		
		var r=0
		$('.check').each(function(i){
		
		if($(this).attr('checked'))
		{
			
		var row = $(this).parents('.item-row');
		
		r++;
		}
		
		});
		//alert(r);
		
		if(r==0)
		{
		alert("Select atleast one invoice");
		valid = false;
		}
		
		return valid;
		
		$('button:submit').prop('disabled', true);
		
	});
	
});	

</script>
								
                                
                                
<?php        

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

$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'];

$check=$_POST['check'];

$deliveryofficer=$_POST['deliveryofficer'];

// now we insert it into the database

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

foreach($check as $chk)
{

$inv=$invoiceno[$chk];

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

$slmx=mysql_query("select MAX(ID) as id from delivery");
$slmx1=mysql_fetch_array($slmx);

$nmx=$slmx1['id']+1;

$up=mysql_query("update invoice set delivery_status='Delivered' where invoiceno='$inv'");

$in= "INSERT INTO delivery(ID,date,invoiceno,vehicleno,startkm,endkm,driver,phone,departuredate,arrivaldate,deliveryofficer)

			VALUES('$nmx','$date','$inv','$vehicleno','$startingkm','$closingkm','$driver','$phone','$departuredate','$arrivaldate','$deliveryofficer')";

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

}

if($in1)
{

 header("location:viewdelivery1.php?id=".$nmx."&s=1");

}

else
{

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

}

}

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 Added Successfully.
				  </div>';				  
		 }
		 if($status=='2')
		 {
			 echo'<div class="alert alert-block alert-danger">
									<button type="button" class="close" data-dismiss="alert">
										<i class="ace-icon fa fa-times"></i>
									</button>
						Values Not Inserted. Please try again.
				  </div>';				  
		 }
	}

?>

<form id="course" action="delivery.php" method="post">

<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="*" autocomplete="off" /></td></tr>

<tr><td width="32%">Invoice No. <span class="red">*</span></td><td width="11">:</td><td>

<table>

<?php

$n=0;
$inv=mysql_query("select * from invoice where delivery_status=''");
while($inv1=mysql_fetch_array($inv))
{
	
$n=$n+1;

if($n%3==0)
{
echo"<tr><td style='padding:0 7px;'><input type='checkbox' class='check' name='check[".$n."]' value='".$n."' style='margin-top:11px;' /> <input type='hidden' name='invoiceno[".$n."]' value='".$inv1['invoiceno']."' />".$inv1['invoiceno']."</td></tr>";
}
else
{
echo"<td style='padding:0 7px;'><input type='checkbox' class='check' name='check[".$n."]' value='".$n."' style='margin-top:11px;' /> <input type='hidden' name='invoiceno[".$n."]' value='".$inv1['invoiceno']."' />".$inv1['invoiceno']."</td>";
}

}

?>

</table>

</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>

<?php

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

echo"<option value='".$sel1['vehicleno']."'>".$sel1['vehicleno']."</option>";
	
}

?>

</select></td></tr>

<tr><td>Delivery Officer <span class="red">*</span></td><td>:</td><td><input autocomplete="off" type="text" name="deliveryofficer" id="required" title="*" /></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="*" /></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="*" /></td></tr>

<tr><td>Starting Km <span class="red">*</span></td><td>:</td><td><input autocomplete="off" type="text" name="startingkm" id="required" title="*" /></td></tr>

<tr><td>Closing Km <span class="red">*</span></td><td>:</td><td><input autocomplete="off" type="text" name="closingkm" id="required" title="*" /></td></tr>

<tr><td>Driver <span class="red">*</span></td><td>:</td><td><input autocomplete="off" type="text" name="driver" id="required" title="*" /></td></tr>

<tr><td>Phone <span class="red">*</span></td><td>:</td><td><input autocomplete="off" type="text" name="phone" id="required" title="*" /></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>

<?php

}
	
?>
                                                                
        
								

										<!-- 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();
?>