<?php 
error_reporting(0);
session_start();
include "config.php";

 $invoiceid = $_GET['invoiceid']; 
 
if(!isset($_SESSION['admin']) || ($_SESSION['admin'] == "") )
{
	?>
<script language="javascript">window.location.href="index.php";</script>
<?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 Quotation 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>


  

</head>
<body>
<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 List</a></li>
      </ul>
   
      <?php 						
		$ure=mysql_query("select * from tbl_generate_invoice_mst where 	invoice_id='$invoiceid'");
		$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">Client Name : &nbsp;&nbsp;</label> 
               <div class="controls">     
              <div class="input-prepend">
              
                 <input type="text" required id="val_username" readonly name="domain_name" value="<?php echo $urow['customername']; ?>">
              </div>
                  
              <div class="input-prepend">
              <label class="control-label" for="val_username">Status : &nbsp;&nbsp;</label>
                 <input type="text" required id="val_username" readonly name="domain_name" value="<?php echo $urow['status']; ?>">
              </div>
              </div>
              </div>
              
              
              
               <div class="control-group">
            <label class="control-label" for="val_username">Invoice No.: &nbsp;&nbsp;</label>
            <div class="controls">
              <div class="input-prepend">
                <input type="text" required id="val_username" readonly name="amount" style="width:233px;" value="<?php echo $urow['invoice_no']; ?>">
              </div>
              
              
               
          
             
              <div class="input-prepend">
              <label class="control-label" for="val_username">Invoice Date : &nbsp;&nbsp;</label>
                 <input type="text" required id="val_username" readonly name="qty" value="<?php echo $urow['invoice_date']; ?>">
              </div>
              </div>
              </div>
              
             
          
           <div class="control-group">
            <label class="control-label" for="val_username">Quotation No. : &nbsp;&nbsp;</label>
            <div class="controls">
              <div class="input-prepend">
                <input type="text" required id="val_username" readonly name="duration" style="width:233px;" value="<?php echo $urow['quotation_no']; ?>">
              </div>
             
              <div class="input-prepend" >
             <label class="control-label" for="val_username">Quatation Date : &nbsp;&nbsp;</label>
             <input type="text" required id="val_username" readonly name="duration" style="width:233px;" value="<?php echo $urow['quotation_date']; ?>">
              </div>
             </div>
          </div>
           
        
        </div>
      </form>
      <br>
 <button id="addRow" class="btn btn-success" onClick="location.href = 'generate_extra_invoice_detail_add.php?invoiceid=<?php echo $invoiceid ?>';"><i class="icon-plus"></i> Add Generate Invoice Detail </button>     
      <h4 align="center">Invoice Detail</h4>
      
      
      <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</th> 
  <th>Time Duration</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
	$ure= mysql_query("SELECT * FROM  tbl_generate_invoice_detail where invoice_id = '$invoiceid'") ;	
		while($urow=mysql_fetch_array($ure)) {
		?>  
        <tr>
<td class="span1">
<div class="btn-group">
<a href="generate_extra_invoice_detail_add.php?invoice_dtid=<?php echo $urow['quotation_in_id']; ?>&&invoiceid=<?php echo $urow['invoice_id']; ?>" data-toggle="tooltip" title="Edit" class="btn btn-mini btn-success" style="margin-right:10px;"><i class="icon-pencil"></i></a>
<?php echo "<a href='#' data-toggle='tooltip' title='Delete' class='btn btn-mini btn-danger' onclick='del(this,$urow[quotation_in_id])'>" ?><i class="icon-remove"></i></a></div></td>

           <td><?php echo $urow['productname']; ?></td>
            <td><?php echo $urow['title']; ?></td>
             <td><div align="right"><?php echo $amount1 = $urow['price']; ?>.00</div></td>
              <td><?php echo $qty1 = $urow['qty']; ?></td>
               <td><?php echo $urow['duration']; ?></td>
                
                 
  <td>                           
                             
                             

				 <div align="right"><?php 	echo $amount = $amount1 * $qty1; ?>.00</div></td>
            
           <td><?php echo $urow['remark']; ?></td>
						

 

                            </tr>
                            
                           
<?php } ?>

					 <tr><td colspan="8"><br /> </td></tr>
                        
                         <tr><td colspan="6" align="right"><div align="right"><strong>Total Amount:</strong></div></td>
                         
                         <td colspan="2"><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  SUM(total_amount) from  tbl_generate_invoice_detail where invoice_id = '$invoiceid'"); 
 						 $sord111=mysql_fetch_array($ure111);
 							echo  $total_amount =  $sord111['SUM(total_amount)']; 
						?>.00 </strong>					 </td></tr>


</tbody>
</table>

 <script language="javascript">
function del(obj,id)
{
        if(confirm("Are You Sure To Delete ?"))
        {
            obj.href="invoice_detail.php?id="+id;
        }
    
}
</script>

		<?php
        if(isset($_GET['id']))
		{
		$delquery="select * from tbl_generate_invoice_detail where quotation_in_id=".$_GET['id'];
		$delquery111=mysql_query($delquery);
		$delquery11=mysql_fetch_array($delquery111);
		$del_amount = $delquery11['total_amount'];
		//$del_adv_amount = $delquery11['cheque_cash_amount'];
		$invoice_id = $delquery11['invoice_id'];
		
	    $delqueryold="select * from tbl_generate_invoice_mst where invoice_id= '$invoice_id'"; 
		$delqueryold111=mysql_query($delqueryold);
		$delqueryold11=mysql_fetch_array($delqueryold111);
		$old_amount = $delqueryold11['total_amount'];
		$old_adv_amount = $delqueryold11['adv_amount'];
		
		$new_fnal_amount = $old_amount - $del_amount;
		//$new_adv_amount = $del_adv_amount - $old_adv_amount;
		$new_pending_amount = $new_fnal_amount - $old_adv_amount;
		
		$qry111 = "update tbl_generate_invoice_mst set total_amount='$new_fnal_amount',adv_amount ='$old_adv_amount',pending_amount='$new_pending_amount' where invoice_id= '$invoice_id'"; 
		mysql_query($qry111) or die(mysql_error());
		
		$delquery="select * from tbl_generate_invoice_detail where quotation_in_id=".$_GET['id'];
		$dusr="delete from  tbl_generate_invoice_detail where quotation_in_id=$_GET[id]";
		$dre=mysql_query($dusr);
		?>
	    <script language="javascript">window.location.href="invoice_detail.php?invoiceid=<?php echo $invoice_id; ?>"</script>
        <?php		
			}
			?>	

<h4 align="center">Payment Detail</h4>
 
<table id="example-datatables" class="table table-striped table-bordered table-hover">
<thead>
<tr>
<th class="span1">Action</th>

 <th>Receipt No</th>
 <th>Payment Date</th>
 <th>Payment By </th>  
 <th>Amount</th> 
 <th>Payment Type</th> 
 <th>Bank Name</th> 
 <th>Acc. No.</th>           
 <th>Cheque No.</th>
  <th>Cheque Date</th>
   <th>Print</th>

 </tr>
</thead>
<tbody>




	<?php
	$ure= mysql_query("SELECT * FROM  tbl_customer_payment where invoice_id = '$invoiceid'") ;	
		while($urow=mysql_fetch_array($ure)) {
		 $paymentid	= $urow['payment_id']; 
		  $chequedate	= $urow['cheque_date']; 
		?>  
        <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[payment_id])'>" ?><i class="icon-remove"></i></a></div></td>
			 <td><?php echo $urow['receipt_no']; ?></td>
           <td><?php $date1=$urow['payment_date'];
			echo $payment_date=date("d-m-Y", strtotime($date1));  ?></td>
            
            <td><?php echo $urow['payment_by']; ?></td>
            
             <td><div align="right"><?php echo $amount1 = $urow['cheque_cash_amount']; ?>.00</div></td>
             <td><?php echo $qty1 = $urow['payment_through']; ?></td>
             <td><?php echo $urow['bank_name']; ?></td>
             <td><?php echo $urow['acc_no']; ?></td>
             <td><?php echo $urow['cheque_no']; ?></td>
             <?php if($chequedate != '1970-01-01' && $chequedate != '0000-00-00'){?>
            <td><?php $date11=$urow['cheque_date'];
			echo $cheque_date=date("d-m-Y", strtotime($date11));  ?></td>
            <?php } else {?>
            <td>-</td>
            <?php }?>
             <td><a href="print_invoice_payment_detail.php?paymentid=<?php echo $paymentid; ?>">Print</a></td>
            </tr>
                            
                           
<?php } ?>

					 <tr><td colspan="11"><br /> </td></tr>
                        
                         <tr><td colspan="4" align="right"><div align="right"><strong>Total Deposit Amount:</strong></div></td>
                         
                         <td colspan="1" ><div align="right"><strong>
                        
                     <?php
                      	 $ure1112=mysql_query("select  SUM(cheque_cash_amount) from  tbl_customer_payment where invoice_id = '$invoiceid'"); 
 						 $sord1112=mysql_fetch_array($ure1112);
 							echo  $total_deposit_amount =  $sord1112['SUM(cheque_cash_amount)']; 
						?>.00 </strong>		</div>	 </td>
                        
                        <td colspan="6">
                        Total Pending Amount: <?php
                      	 $ure111=mysql_query("select  SUM(total_amount) from  tbl_generate_invoice_detail where invoice_id = '$invoiceid'"); 
 						 $sord111=mysql_fetch_array($ure111);
 							echo  $price =  $sord111['SUM(total_amount)']; 
						?>.00 - 
                        <?php
                      	 $ure1111=mysql_query("select  SUM(cheque_cash_amount) from  tbl_customer_payment where invoice_id = '$invoiceid'"); 
 						 $sord1111=mysql_fetch_array($ure1111);
 							echo  $total_deposit_amount =  $sord1111['SUM(cheque_cash_amount)']; 
						?>.00 = <?php echo $total_pending = $price - $total_deposit_amount; ?>
                        
                        </td>
                        
                        </tr>

 <tr>
                        <td colspan="11" align="center">
                       <form id="form-validation"  method="post" name="form" action="generate_invoice_list.php" class="form-horizontal form-box remove-margin">
                       <input type="submit" name="generate_neworder" value="Back To Invoice List" class="btn btn-success">
                        </form>                        </td>
                        
                        
                        
                        </tr>
</tbody>
</table>

<script language="javascript">
function del(obj,id)
{
        if(confirm("Are You Sure To Delete ?"))
        {
            obj.href="invoice_detail.php?id="+id;
        }
    
}
</script>

		<?php
        if(isset($_GET['id']))
		{
		$delquery112="select * from tbl_customer_payment where payment_id=".$_GET['id'];
		$delquery112=mysql_query($delquery112);
		$delquery112=mysql_fetch_array($delquery112);
		$invoice_id = $delquery112['invoice_id']; 
		$cheque_cash_amount = $delquery112['cheque_cash_amount'];
		
		
	    $delqueryold113="select * from tbl_generate_invoice_mst where invoice_id= '$invoice_id'"; 
		$delqueryold113=mysql_query($delqueryold113);
		$delqueryold113=mysql_fetch_array($delqueryold1113);
	
		$total_amount	 = $delqueryold113['total_amount'];  
		$old_adv_amount	 = $delqueryold113['adv_amount']; 
		$old_pending_amount = $delqueryold113['pending_amount']; 
		$cur_payment = $cheque_cash_amount; 
	
		$new_adv_amount = $old_adv_amount - $cur_payment; 
	    $new_pending_amount =  $total_amount - $new_adv_amount;
		
		
		
		$qry114 = "update tbl_generate_invoice_mst set adv_amount='$new_adv_amount',pending_amount ='$new_pending_amount' where invoice_id= '$invoice_id'"; 
		mysql_query($qry114) or die(mysql_error());
		
		$delquery="select * from tbl_customer_payment where payment_id=".$_GET['id'];
		$dusr="delete from  tbl_customer_payment where payment_id=$_GET[id]";
		$dre=mysql_query($dusr);
		?>
	    <script language="javascript">window.location.href="invoice_detail.php?invoiceid=<?php echo $invoice_id; ?>"</script>
        <?php		
			}
			?>	



 
    </div>
    <?php include 'footer.php' ?>
  </div>
</div>
<?php include 'profile_popup.php' ?>
<!--[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>
</body>
</html>


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



