<?php 
error_reporting(0);
session_start();

$lastinvoice_id = $_SESSION['lastinvoice_id'];

 
if(!isset($_SESSION['admin']) || ($_SESSION['admin'] == "") )
{
	?>
<script language="javascript">window.location.href="index.php";</script>
<?php 
}
include "config.php";
?>
<!DOCTYPE html>
<!--[if lt IE 7]>      <html class="no-js lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
<!--[if IE 7]>         <html class="no-js lt-ie9 lt-ie8"> <![endif]-->
<!--[if IE 8]>         <html class="no-js lt-ie9"> <![endif]-->
<!--[if gt IE 8]><!-->
<html class="no-js">
<!--<![endif]-->
<head>
<meta charset="utf-8">
<title>Generate Invoice Detail</title>
<meta name="author" content="pixelcave">
<meta name="robots" content="noindex, nofollow">
<meta name="viewport" content="width=device-width,initial-scale=1">
<link rel="shortcut icon" href="img/favicon.ico">
<link rel="apple-touch-icon" href="img/apple-touch-icon.png">
<link rel="apple-touch-icon" sizes="57x57" href="img/apple-touch-icon-57x57-precomposed.png">
<link rel="apple-touch-icon" sizes="72x72" href="img/apple-touch-icon-72x72-precomposed.png">
<link rel="apple-touch-icon" sizes="114x114" href="img/apple-touch-icon-114x114-precomposed.png">
<link rel="apple-touch-icon-precomposed" href="img/apple-touch-icon-precomposed.png">
<link rel="stylesheet" href="http://fonts.googleapis.com/css?family=Roboto:400,400italic,700,700italic">
<link rel="stylesheet" href="css/bootstrap.css">
<link rel="stylesheet" href="css/plugins.css">
<link rel="stylesheet" href="css/main.css">
<link rel="stylesheet" href="css/themes.css">

  <link href="datepicker/css/datepicker.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="datepicker/js/datepicker.js"></script>
  
    
<script src="js/vendor/modernizr-2.6.2-respond-1.1.0.min.js"></script>

<script type="application/javascript">
  function isNumberKey(evt)
      {
         var charCode = (evt.which) ? evt.which : event.keyCode
         if (charCode > 31 && (charCode < 48 || charCode > 57))
            return false;

         return true;
      }
</script>

<link rel="stylesheet" type="text/css" href="popupform/js/fancybox/main.css" />
<script type="text/javascript" src="popupform/js/jquery-1.5.min.js"></script>
<link rel="stylesheet" type="text/css" href="popupform/js/fancybox/jquery.fancybox-1.3.4.css" media="screen" />

  

</head>
<body>

<div style='display:none;'>
    <div id="send_testimonial_afb_area">
      
      <div id="send_testimonial_afb_note" class="afb_note" ></div>
      <div id="send_testimonial_afb_fields">
        <center>
              <form id="send_testimonial" name="send_testimonial" class="form-horizontal form-box" method="post" >
		  <!--<form id="send_testimonial" name="send_testimonial" method="post" action="#">-->
		  
		  <h1 class="form-box-header">Select Invoice Format</h1>
		  
            <table align="center" cellpadding="0" cellspacing="0" width="100%">
              <!--<tr>
                <td width="40%"><div class="wrap">
                    <label class="in_field">Your Name</label>
                  </div></td>
                <td width="60%"><input  type="text" name="sender_name" value="" />
                </td>
              </tr>-->
             <!-- <tr>
                <td width="40%"><div class="wrap">
                    <label class="in_field">Collage Name</label>
                  </div></td>
                <td width="60%"><input  type="text" name="sender_name" value="" />
                </td>
              </tr>-->
             <!-- <tr>
                <td width="40%"><div class="wrap">
                    <label class="in_field">Email</label>
                  </div></td>
                <td width="60%"><input  type="text" name="sender_name" value="" />
                </td>
              </tr>-->
             <!-- <tr>
                <td width="40%"><div class="wrap">
                    <label class="in_field">Mobile</label>
                  </div></td>
                <td width="60%"><input  type="text" name="sender_name" value="" />
                </td>
              </tr>-->
              <tr>
                <td width="40%"><div class="wrap">
                    <label class="in_field">Invoice Format</label>
                  </div></td>
                <td width="60%"><select name="invoice_format">
                    <option value="">--Select Format--</option>
					 <option value="with_header">With Header</option>
					  <option value="without_header">Without Header</option>
                  </select>
                </td>
              </tr>
			  <tr>
			  <td><br></td>
			  </tr>
              <!--<tr>
                <td width="40%"><div class="wrap">
                    <label class="in_field" >Stream</label>
                  </div></td>
                <td width="60%"><select id="send_testimonial_sender_name">
                    <option value="">--select--</option>
                  </select>
                </td>
              </tr>-->
              <!--<tr>
                <td width="40%"><div class="wrap">
                    <label class="in_field" >Message</label>
                  </div></td>
                <td width="60%"><textarea rows="5" cols="25"  name="testimonial" ></textarea>
                </td>
              </tr>-->
              <tr>
                <td width="40%">&nbsp;</td>
                <td width="60%">
				<button class="btn btn-success" name="generate_print"><i class="icon-print"></i> Print Invoice</button>
				
				<!--<input type="submit" name="generate_print" value="Print Invoice" class="btn btn-success" />-->
                </td>
              </tr>
			  
			  <tr>
			  <td><br></td>
			  </tr>
			  
            </table>
          </form>
        </center>
      </div>
    </div>
</div>

<div id="page-container">

  <?php include 'header.php' ?>
  
  <div id="inner-container">
    <?php include 'left_menu.php' ?>
    <div id="page-content">
      <ul id="nav-info" class="clearfix">
        <li><a href="#"><i class="icon-home"></i></a></li>
        <li class="active"><a href="generate_invoice_list.php">Generate Invoice Detail List</a></li>
      </ul>
      <?php 
	  
	   $ure0=mysql_query("select * from tbl_generate_invoice_mst order by invoice_id desc");
		
		$row0=mysql_fetch_array($ure0); 
		$invoice_no = $row0['invoice_no']; 
	  
if ($_POST['add']) 
{
	
//$v_id=$_REQUEST['v_id'];
//	$ure111=mysql_query("select * from  tbl_vehicle_mst where v_id='$v_id'"); 
//	$row111=mysql_fetch_array($ure111); 
// 	$vehicle_no = $row111['vehicle_no'];
	
	
	//$cat_id=$_REQUEST['cat_id'];
//	$ure222=mysql_query("select * from   tbl_category_mst where cat_id='$cat_id'"); 
//	$row222=mysql_fetch_array($ure222); 
// 	$category_name = $row222['category_name'];
	
	//$mat_id=$_REQUEST['mat_id'];
//	$ure333=mysql_query("select * from   tbl_material_mst where mat_id='$mat_id'"); 
//	$row333=mysql_fetch_array($ure333); 
// 	$material_name = $row333['material_name'];
	
	$prd_id=$_REQUEST['prd_id'];
	$ure444=mysql_query("select * from  tbl_product_master where prd_id='$prd_id'"); 
	$row444=mysql_fetch_array($ure444); 
 	$productname = $row444['productname'];
	
	$domain_name=$_REQUEST['domain_name'];
	$amount=$_REQUEST['amount'];
	$qty=$_REQUEST['qty'];
	$price=$_REQUEST['price'];
	$duration=$_REQUEST['duration'];
	$remark=$_REQUEST['remark'];
	
	$total_amount = $price * $qty;
//	$driver=$_REQUEST['driver']; 
//	$vehicle_exp=$_REQUEST['vehicle_exp'];
//	$liter=$_REQUEST['liter'];
//	$amount=$_REQUEST['amount'];
//	$paymentby=$_REQUEST['paymentby'];
//	$remark=$_REQUEST['remark'];
	$status=$_REQUEST['status'];
	
  $sql=mysql_query("INSERT INTO 
		tbl_generate_invoice_detail
		(invoice_id,productname,title,amount,qty,price,duration,remark,total_amount,status) 
		VALUES ('$lastinvoice_id','$productname','$domain_name','$amount','$qty','$price','$duration','$remark','$total_amount','$status')");
		
		 $lastinvoice_detail_id =  mysql_insert_id();
	  	 $_SESSION['lastinvoice_detail_id'] = $lastinvoice_detail_id;
		 $lastinvoice_detail_id = $_SESSION['lastinvoice_detail_id'];

} 


 $query = "SELECT SUM(qty),SUM(total_amount) FROM tbl_generate_invoice_detail where  invoice_id = '$lastinvoice_id'"; 
 $result = mysql_query($query) or die(mysql_error());

// Print out result
    while($row = mysql_fetch_array($result))
	{
 	$qty =  $row['SUM(qty)'];
 	$rate =  $row['SUM(total_amount)'];		
	}

	$uupQry="UPDATE tbl_generate_invoice_mst SET totalqty='$qty',total_amount='$rate' WHERE invoice_id='$lastinvoice_id'";
	$uuresult=mysql_query($uupQry);

if(isset($_REQUEST['generate_print']))
{
	$invoice_format=$_REQUEST['invoice_format'];
?>
<script>window.location="print_invoice_with_logo.php?lastinvoce_id=<?php echo $lastinvoice_id; ?>&&invoice_format=<?php echo $invoice_format; ?>";</script>
<?php	
}

    $id = $_GET['reg'];						
 	if(isset($_REQUEST['up'])) 
      {   
  	//$v_id=$_REQUEST['v_id'];
	//	$ure111=mysql_query("select * from  tbl_vehicle_mst where v_id='$v_id'"); 
	//	$row111=mysql_fetch_array($ure111); 
	// 	$vehicle_no = $row111['vehicle_no'];
	
	//$cat_id=$_REQUEST['cat_id'];
	//	$ure222=mysql_query("select * from   tbl_category_mst where cat_id='$cat_id'"); 
	//	$row222=mysql_fetch_array($ure222); 
	// 	$category_name = $row222['category_name'];
	
	//$mat_id=$_REQUEST['mat_id'];
	//	$ure333=mysql_query("select * from   tbl_material_mst where mat_id='$mat_id'"); 
	//	$row333=mysql_fetch_array($ure333); 
	// 	$material_name = $row333['material_name'];
	
	$prd_id=$_REQUEST['prd_id'];
	$ure444=mysql_query("select * from  tbl_product_master where prd_id='$prd_id'"); 
	$row444=mysql_fetch_array($ure444); 
 	$productname = $row444['productname'];
	
	$domain_name=$_REQUEST['domain_name'];
	$amount=$_REQUEST['amount'];
	$qty=$_REQUEST['qty'];
	$price=$_REQUEST['price'];
	$duration=$_REQUEST['duration'];
	$remark=$_REQUEST['remark'];
	
	$total_amount = $amount * $qty;
//	$driver=$_REQUEST['driver']; 
//	$vehicle_exp=$_REQUEST['vehicle_exp'];
//	$liter=$_REQUEST['liter'];
//	$amount=$_REQUEST['amount'];
//	$paymentby=$_REQUEST['paymentby'];
//	$remark=$_REQUEST['remark'];
	
	$status=$_REQUEST['status'];
	
	$uupQry="UPDATE tbl_generate_invoice_detail SET quotation_id='$lastquotation_id',productname='$productname',title='$domain_name',amount='$amount',qty='$qty',duration='$duration', remark='$remark',total_amount='$total_amount',status='$status' WHERE quotation_in_id ='$id'";
	$uuresult=mysql_query($uupQry);
	
	
	$quotation_id = $_GET['reg'];
	$query = "SELECT SUM(qty),SUM(total_amount) FROM tbl_generate_invoice_detail where  invoice_id = '$lastinvoice_id'";  
    $result = mysql_query($query) or die(mysql_error());

// Print out result
    while($row = mysql_fetch_array($result))
	{
 	$qty =  $row['SUM(qty)'];
 	$rate =  $row['SUM(total_amount)'];		
	}
	
	$uupQry="UPDATE  tbl_generate_invoice_mst SET totalqty='$qty',total_amount='$rate' WHERE invoice_id	='$lastinvoice_id'";
	$uuresult=mysql_query($uupQry);
	?>
      <script language="javascript">window.location.href="generate_invoice_list.php";</script>
      <?php 
  }
   ?>
      <?php 						
		$ure=mysql_query("select * from tbl_generate_invoice_detail where quotation_in_id='$id'");
		$urow=mysql_fetch_array($ure); ?>
      <form id="form-validation"  method="post" name="form" class="form-horizontal form-box remove-margin">
        <div class="form-box-content">
        
              
               <div class="control-group"> 
               <label class="control-label" for="val_username">Product Name : &nbsp;&nbsp;</label> 
               <div class="controls">     
              <div class="input-prepend">
              
                <select  data-placeholder="Select Supplier Name..." class="chzn-select full" name="prd_id"  tabindex="20" >
                        <option value="">Select Product Name....</option>
                        <?php 
			$ure33=mysql_query("select * from  tbl_product_master");
			while($urow33=mysql_fetch_array($ure33)) {?>
                        <option value="<?php echo $urow33[0]; ?>"> <?php echo $urow33['productname']; ?></option>
                        <?php } ?>
                      </select>
              </div>
                  
              <div class="input-prepend">
              <label class="control-label" for="val_username">Title / Domain Name : &nbsp;&nbsp;</label>
                 <input type="text" required id="val_username" name="domain_name" value="<?php echo $urow['domain_name']; ?>">
              </div>
              </div>
              </div>
              
              
              
               <div class="control-group">
            <label class="control-label" for="val_username">Qty : &nbsp;&nbsp;</label>
            <div class="controls">
              <div class="input-prepend">
                <input type="text" required id="val_username" name="qty" style="width:233px;" value="<?php echo $urow['qty']; ?>">
              </div>
              
              
               
          
             
              <div class="input-prepend">
              <label class="control-label" for="val_username">Price : &nbsp;&nbsp;</label>
                 <input type="text" required id="val_username" name="price" value="<?php echo $urow['price']; ?>">
              </div>
              </div>
              </div>
              
             
          
           <div class="control-group">
            <label class="control-label" for="val_username">Remarks : &nbsp;&nbsp;</label>
            <div class="controls">
              <div class="input-prepend">
                <textarea id="" style="width:253px;" name="remark"><?php echo $row['remark']; ?></textarea>
			
              </div>
             
              <div class="input-prepend" style="width:255px;">
              </div>
             </div>
          </div>
                    
		  
          <div class="form-actions">
            <?php
					 
                        if($id)
						{
						?>
            <input type="submit" name="up" value="Update Generate Invoice Detail" class="btn btn-success">
            <?php 
}
else 
{

?>
            <input type="submit" name="add" value="Add Product" class="btn btn-success">
            <?php } ?>
            
            <!--<button type="reset" class="btn btn-danger"><i class="icon-repeat"></i> Reset</button>-->
          </div>
        </div>
      </form>
      
      
      <table id="example-datatables" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th class="span1">Action</th>
 <th>Product Name </th>
 <th>Title / Domain Name </th> 
 <!--<th>Approx. Amount </th>  -->
 <th>Qty.(Unit) </th> 
 <th>Price</th> 
 <th>Amount</th>
 <th>Remarks </th>
 <!--<th>Weight Date</th>
  <th>Charges</th>-->
 
  <!-- <th> Weight Detail </th>-->
<!--<th class="hidden-phone hidden-tablet">Status</th>-->
 </tr>
</thead>
<tbody>

<?php 						
		$id = $_GET['reg'];				
		 if((isset($_GET['action'])== 'up_sts')) 
		{
  		  $id = $_GET['ids'];
		  $sts = $_GET['sts'];
	
			$qry = "update  tbl_generate_invoice_detail set status='$sts' where quotation_in_id=$id";
			mysql_query($qry) or die(mysql_error());
		}

	$ure= mysql_query("SELECT * FROM  tbl_generate_invoice_detail where invoice_id = '$lastinvoice_id'") ;	
		while($urow=mysql_fetch_array($ure)) {
		?>  
        <tr>
<td class="span1">
<div class="btn-group">
<?php /*?><a href="weight_add.php?reg=<?php echo $urow[0]; ?>" data-toggle="tooltip" title="Edit" class="btn btn-mini btn-success" style="margin-right:10px;"><i class="icon-pencil"></i></a><?php */?>
<?php echo "<a href='#' data-toggle='tooltip' title='Delete' class='btn btn-mini btn-danger' onclick='del(this,$urow[0])'>" ?><i class="icon-remove"></i></a></div></td>

           <td><?php echo $urow['productname']; ?></td>
            <td><?php echo $urow['title']; ?></td>
             
              <td><?php echo $qty = $urow['qty']; ?></td>
			  <td><?php echo $price = $urow['price']; ?></td>
              <td><div align="right"><?php 	echo $amount = $qty * $price; ?>.00</div></td>
			  <td><?php echo $urow['remark']; ?></td>
  
           </tr>
                            
                           
<?php } ?>

					 <tr><td colspan="8"><br /> </td></tr>
                        
                         <tr><td colspan="5" align="right"><div align="right"><strong>Total Amount:</strong></div></td>
                         
                         <td colspan="3"><strong>
                        <?php /*?> <?php
                       		$query1223 = "SELECT SUM(total_amount) FROM tbl_sale_invoice_detail where salein_id='$salein_id'"; 
	  						   	  $result1223 = mysql_query($query1223) or die(mysql_error());
							      $row1223 = mysql_fetch_array($result1223);
								echo  $total_sum =  $row1223['SUM(total_amount)']; 
								 ?>.00/-<?php */?>
                     <?php
                      	 $ure111=mysql_query("select * from  tbl_generate_invoice_mst where invoice_id = '$lastinvoice_id'"); 
 						 $sord111=mysql_fetch_array($ure111);
 						 echo  $totalfinalamount = $sord111['total_amount']; 
						?>.00 </strong>					 </td></tr>

 <tr>
                        <td colspan="8" align="center">
                       
                       <input type="submit" name="generate_print" value="Confirm & Print Invoice" class="btn btn-success" id='contact_form_link'>
					  <!-- <a href="#" id='contact_form_link'>Request for Quote</a> -->
                          </td>
                        </tr>
</tbody>
</table>


 <script language="javascript">
function del(obj,id)
{
        if(confirm("Are You Sure To Delete ?"))
        {
            obj.href="generate_extra_invoice_detail_add.php?id="+id;
        }
    
}
</script>
<?php
if(isset($_GET['id']))
	{
//		 $delquery="select * from tbl_sale_invoice_detail where salein_dt_id=".$_GET['id'];
//		$delquery11=mysql_query($delquery);
//		$del_amount = $delquery11['total_amount'];
		
//		$delqueryold="select * from tbl_sale_invoice_mst where salein_id=$lastsalein_id";
//		$delqueryold11=mysql_query($delqueryold);
//		$old_amount = $delqueryold11['total_amount'];		
//		$new_fnal_amount = $del_amount - $old_amount;
		
		$dusr="delete from   tbl_generate_invoice_detail where quotation_in_id=$_GET[id]";
		$dre=mysql_query($dusr);

//		$qry111 = "update tbl_sale_invoice_mst set total_amount='$new_fnal_amount' where salein_id=$lastsalein_id";
//		mysql_query($qry111) or die(mysql_error());
	//	header('location:purchase_order_product_add.php');
		
		?>
    <script language="javascript">window.location.href="generate_extra_invoice_detail_add.php"</script>
          <?php		
	}
	?>	
    </div>
    <?php include 'footer.php' ?>
  </div>
</div>
<?php include 'profile_popup.php' ?>

<script type="text/javascript" src="popupform/js/fancybox/jquery.easing-1.3.pack.js"></script>
<script type="text/javascript" src="popupform/js/fancybox/jquery.fancybox-1.3.4.js"></script>
<script type="text/javascript">
      <!--
      $(function() { // When DOM is ready
      
        
         $('#contact_form_link').fancybox({
	        'scrolling'		   : 'no',
	        'titleShow'		   : false,
	        'href'             : '#send_testimonial_afb_area',
	        'centerOnScroll'   : true,
	        'transitionIn'	   : 'elastic',
	        'transitionOut'	   : 'elastic',
	        'easingIn'         : 'easeOutBack',
	        'easingOut'        : 'easeInBack'
         });  
             
         $('#contact_form_link_two').fancybox({
	        'scrolling'		   : 'no',
	        'titleShow'		   : false,
	        'href'             : '#basic_afb_area',
	        'centerOnScroll'   : true,
	        'transitionIn'	   : 'elastic',
	        'transitionOut'	   : 'elastic',
	        'easingIn'         : 'easeOutBack',
	        'easingOut'        : 'easeInBack'
         });  
                     });
        -->
      </script>



<!--[if lte IE 8]><script src="js/helpers/excanvas.min.js"></script><![endif]-->
<!--<script src="js/jquery.min.js"></script>-->
<script>!window.jQuery && document.write(unescape('%3Cscript src="js/vendor/jquery-1.9.1.min.js"%3E%3C/script%3E'));</script>
<script src="js/vendor/bootstrap.min.js"></script>
<script src="js/plugins.js"></script>
<script src="js/main.js"></script>
<script>$(function(){$("#form-validation").validate({errorClass:"help-block text-error",errorElement:"span",errorPlacement:function(t,e){e.parents(".controls").append(t)},highlight:function(t){$(t).closest(".control-group").removeClass("success error").addClass("error")},success:function(t){t.addClass("valid").closest(".control-group").removeClass("success error").addClass("success"),t.closest(".help-inline").remove(),t.closest(".help-block").remove()},rules:{val_username:{required:!0,minlength:2},val_password:{required:!0,minlength:5},val_confirm_password:{required:!0,minlength:5,equalTo:"#val_password"},val_email:{required:!0,email:!0},val_website:{required:!0,url:!0},val_date:{required:!0,date:!0},val_range:{required:!0,range:[1,100]},val_number:{required:!0,number:!0},val_digits:{required:!0,digits:!0},val_skill:{required:!0},val_credit_card:{required:!0,creditcard:!0},val_terms:{required:!0}},messages:{val_username:{required:"Please enter a username",minlength:"Your username must consist of at least 2 characters"},val_password:{required:"Please provide a password",minlength:"Your password must be at least 5 characters long"},val_confirm_password:{required:"Please provide a password",minlength:"Your password must be at least 5 characters long",equalTo:"Please enter the same password as above"},val_email:"Please enter a valid email address",val_website:"Please enter your website!",val_date:"Please select a date!",val_range:"Please enter a number between 1 and 100!",val_number:"Please enter a number!",val_digits:"Please enter digits!",val_credit_card:"Please enter a valid credit card!",val_skill:"Please select a skill!",val_terms:"You must agree to the terms!"}})});</script>


<script language="javascript" type="text/javascript">
function getXMLHTTP() { //fuction to return the xml http object
		var xmlhttp=false;	
		try{
			xmlhttp=new XMLHttpRequest();
		}
		catch(e)	{		
			try{			
				xmlhttp= new ActiveXObject("Microsoft.XMLHTTP");
			}
			catch(e){
				try{
				xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
				}
				catch(e1){
					xmlhttp=false;
				}
			}
		}
		 	
		return xmlhttp;
    }
	
		function getBoard(countryId) {		
		var strURL="find_vehicle_name.php?v_id="+countryId;
		var req = getXMLHTTP();
		if (req) {
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('v_id').innerHTML=req.responseText;						
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}
	
	function getState(countryId,stateId) {		
		
		var strURL="findSubject.php?streamid="+countryId+"&subject_id="+stateId;
		var req = getXMLHTTP();
		
		if (req) {
			
			req.onreadystatechange = function() {
				if (req.readyState == 4) {
					// only if "OK"
					if (req.status == 200) {						
						document.getElementById('subject_id').innerHTML=req.responseText;
												
					} else {
						alert("There was a problem while using XMLHTTP:\n" + req.statusText);
					}
				}				
			}			
			req.open("GET", strURL, true);
			req.send(null);
		}		
	}
	
</script>


</body>
</html>


