<?
session_start();
include("opendb.php");
include("test.php");
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Xpress</title>
 <script src=" rightclick_deactive.js"></script> 
</head>
<style type="text/css">
table,tr,td{border-collapse:collapse;padding:1px;border: 1px solid red;}
body{text-transform:uppercase;font-family:Verdana;font-size:10px;color:black;}

tr:nth-child(odd)    { background-color:white; }
tr:nth-child(even)    { background-color:#fff; }
p{
	padding:0px;
	margin:0px;
	text-align: left;text-transform:capitalize;font-size:10px;
}
select,input[type=text], textarea{  
background: #eeeeee; /* Old browsers */
/* IE9 SVG, needs conditional override of 'filter' to 'none' */
background: url(data:image/svg+xml;base64,PD94bWwgdmVyc2lvbj0iMS4wIiA/Pgo8c3ZnIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyIgd2lkdGg9IjEwMCUiIGhlaWdodD0iMTAwJSIgdmlld0JveD0iMCAwIDEgMSIgcHJlc2VydmVBc3BlY3RSYXRpbz0ibm9uZSI+CiAgPGxpbmVhckdyYWRpZW50IGlkPSJncmFkLXVjZ2ctZ2VuZXJhdGVkIiBncmFkaWVudFVuaXRzPSJ1c2VyU3BhY2VPblVzZSIgeDE9IjAlIiB5MT0iMCUiIHgyPSIwJSIgeTI9IjEwMCUiPgogICAgPHN0b3Agb2Zmc2V0PSIwJSIgc3RvcC1jb2xvcj0iI2VlZWVlZSIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgICA8c3RvcCBvZmZzZXQ9IjIzJSIgc3RvcC1jb2xvcj0iI2ZmZmZmZiIgc3RvcC1vcGFjaXR5PSIxIi8+CiAgPC9saW5lYXJHcmFkaWVudD4KICA8cmVjdCB4PSIwIiB5PSIwIiB3aWR0aD0iMSIgaGVpZ2h0PSIxIiBmaWxsPSJ1cmwoI2dyYWQtdWNnZy1nZW5lcmF0ZWQpIiAvPgo8L3N2Zz4=);
background: -moz-linear-gradient(top, #eeeeee 0%, #ffffff 23%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,#eeeeee), color-stop(23%,#ffffff)); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, #eeeeee 0%,#ffffff 23%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, #eeeeee 0%,#ffffff 23%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, #eeeeee 0%,#ffffff 23%); /* IE10+ */
background: linear-gradient(top, #eeeeee 0%,#ffffff 23%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#eeeeee', endColorstr='#ffffff',GradientType=0 ); /* IE6-8 */
border:1px solid #999; padding:3px;
-webkit-border-radius: 3px;
-moz-border-radius: 3px;
border-radius: 3px;


}p{padding:0px;}
em{font-size:14px;}
h3{color:#000;font-size:12px;margin:0px;padding:5px 20px;}
</style>
 <script type="text/javascript" src="scripts/jquery-latest.js"></script>
	<link type="text/css" href="includes/style1.css" rel="stylesheet" />
      <link type="text/css" href="css/form.css" rel="stylesheet" />
<script type="text/javascript" src="js/jquery-1.6.1.min.js"></script>

    <script type="text/javascript">
        $(function() {
          if ($.browser.msie && $.browser.version.substr(0,1)<7)
          {
			$('li').has('ul').mouseover(function(){
				$(this).children('ul').show();
				}).mouseout(function(){
				$(this).children('ul').hide();
				})
          }
        });        
    </script>


<link rel="stylesheet" type="text/css" media="all" href="jsDatePick_ltr.min.css" />
<script type="text/javascript" src="jsDatePick.min.1.3.js"></script>

<script type="text/javascript">
	window.onload = function(){
		new JsDatePick({
			useMode:2,
			target:"inputField",
			dateFormat:"%Y-%m-%d 00:00:00"
			
		});
		new JsDatePick({
			useMode:2,
			target:"inputField1",
			dateFormat:"%Y-%m-%d 23:59:59"
			
		});
              
	};
</script>


<SCRIPT LANGUAGE="JavaScript" SRC="util/PopupWindow.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="util/AnchorPosition.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="util/CalendarPopup.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript" SRC="util/date.js"></SCRIPT>

<script>

 
var cal1 = new CalendarPopup();
cal1.showYearNavigation();

var cal2 = new CalendarPopup();
cal2.showYearNavigation();

  </script>
<style>
.cont
	{


       background-color:#3b5998;

	//background:url(images/bg-inner.jpg) #e9e0c3 repeat-x;
  	width: 100%;position: absolute ;
	height:99%;
    	/* Optional - just for DIV)*/
    	//border: solid 1px #000000;
	-moz-box-shadow: 0px 5px 5px #888;
	-webkit-box-shadow: 0px 5px 5px #888;
	box-shadow: 0px 5px 10px #888;
    
	}
</style>

<script type="text/javascript">
    $(document).ready(function() {
        var cont_left = $("#container").position().left;
        $("a img").hover(function() {
            // hover in
            //$(this).parent().parent().css("z-index", 1);
            $(this).animate({
               height: "110",
               width: "110",
              
            }, "fast");
        }, function() {
            // hover out
         //   $(this).parent().parent().css("z-index", 0);
            $(this).animate({
                height: "80",
                width: "80",
                
            }, "fast");
        });
        
        $(".img").each(function(index) {
            var left = (index * 160) + cont_left;
            $(this).css("left", left + "px");
        });
    });









/////

(function($){
    $.fn.enterNext = function(){
       var _i =0;
       $('input[type=text], select',this)
            .each(function(index){
            _i = index;
            $(this)
                .addClass('tab'+index)
                .keydown(function(event){
                    if(event.keyCode==13){
                        $('.tab'+(index+1)).focus();
                        event.preventDefault();
                    }
                });

        })
     $( "input[type=submit]",this ).addClass('tab'+(_i+1));
}})(jQuery);
    </script>



<body >
<div class='cont'>



<?php
	 include('includes/top.php');
 ?>

<div align='left'><font style="font-family: 'Trebuchet MS',Verdana,Helvetica,sans-serif; font-size:15px;">  &nbsp;&nbsp;Service >>  invoice till report</font></div>

  <form name='f1' action='<?print $PHP_SELF?>'>
	<table class="container" width="93%" align='center' >

		<table class="form" style="width:auto" align='center' >
			<tr>
				<th style="background:grey;">Jobcard Register</th>
			</tr>

			<tr>
				<td>Date.  From <input type="text" id="inputField" name="fromdt" value="<? echo date('Y-m-d 00:00:00');?>" readonly  >  

 				To <input type="text" id="inputField1" name="todt"  value="<? echo date('Y-m-d 23:59:59');?>" readonly ></td>
			</tr>

                       <tr>
				<td align=center>

                                <input type='submit' name='show' value='Show' >
                              

                          </td>
			</tr>

			

            </table>
      </form>

<?
 if(($show)||($show1))
  {

 
?>
   <div align='right'><a href='jc_register_xls.php?fromdt=<?print $fromdt;?>&todt=<?print $todt;?>' title='excel sheet' target='blank'><img src="images/excel.png"></a>

</div>


   <table align='center' class='report' width='100%'> 

	<tr>
		<td colspan='23' > 
	
			<b>
				  REPORT FROM 
			</b>
	
			<?
		
		 		echo dateandtimetoHtml($fromdt); 

			?>
		
			 <b> 
	
				TO 

			</b> 

			 <? 

				echo dateandtimetoHtml($todt); 

			?> 

       </tr> 
 <?

//$sql=mysqli_query($db,"select * from gateentry where entrydate between '$fromdt' and '$todt' and brcode='$brcode'  order by jcno");
 include("jc_register_list.php"); 
?>
     
	<tr>
		<td><h3>SNo </h3></td>

		<td><h3>JobNo</h3></td>

		<td><h3>Date</h3></td>

              <td><h3>Veh. Name</h3>
                </td>

              <td><h3>Model</h3></td>

		<td><h3>RegNo</h3></td>

              <td><h3>Type</h3></td>

		<td><h3>Ins.Co</h3></td>
           
              <td><h3>Job Type</h3></td>

              <td><h3>Customer</h3></td>

              <td><h3>Esti.</br>Delivery Date</h3></td>

 		<td><h3>Labour Amount</h3></td>

 		<td><h3>Advisor</h3></td>

		<td><h3>Status</h3></td>

		<td><h3>StatusDate</h3></td>
             
              <td><h3>Technician</h3></td>

              <td><h3>Remarks</h3></td>

              <td><h3>Pending Order:</h3></td>

              <td><h3>EstNo.</h3></td><td><h3>EstDate.</h3></td><td><h3>EstAmt.</h3></td><td><h3>Cus.Inv</h3></td><td><h3>Ins.Inv</h3></td>


	</tr>

             <form name='f2' action='<?print $PHP_SELF?>'>
              

              

       <tr>
              <td></td>
              <td>
        
                 <select name='jcno1'  style='width:80px;'  >

                  <?
                   $i=1;

                   if(($$fld[$i])&&($$fld[$i]!='All')){
               
                     if(($indic[$i])&&($indic[$i]=='*'))

                         echo   "<option value='*".$not_val[$i]."'  style='background-color:#E0E0E0 ; color:#303030  ;'>Not ".$not_val[$i]."</option>";

                     else

                         echo   "<option>".$jcno1."</option>";
                     

                 } 

        
                ?>

                 <option> All </option>

                  

              <?

                 while($row1=mysqli_fetch_array($fld_list[1])){
                 
                    print "<option>$row1[0]</option>";
               
                    print "<option value='*$row1[0]'  style='background-color:#E0E0E0 ; color:#303030  ;'>Not $row1[0]</option>";
                  }

                 ?>
                 </select>
                 
              </td>
              <td></td>

              <td>

               <select name='vehiclename1' style='width:80px'>
              <?
                   $i=3;

                if(($$fld[$i])&&($$fld[$i]!='All')){
               
                    if(($indic[$i])&&($indic[$i]=='*'))

                      echo   "<option value='*".$not_val[$i]."'  style='background-color:#E0E0E0 ; color:#303030  ;'>Not ".$not_val[$i]."</option>";

                   else

                     echo  "<option>".$vehiclename1."</option>"; 
                     

              } 
             ?>


                  <option> All </option>

              <?

                  while($row1=mysqli_fetch_array($fld_list[3])){
                
                     print "<option>$row1[0]</option>";

                     print "<option value='*$row1[0]'  style='background-color:#E0E0E0 ; color:#303030  ;'>Not $row1[0]</option>";
                  }

                 ?>
                 </select>

              </td>


               <td>

               <select name='model1' style='width:80px'>

		<?
                   $i=4;

                if(($$fld[$i])&&($$fld[$i]!='All')){
               
                    if(($indic[$i])&&($indic[$i]=='*'))

                     echo   "<option value='*".$not_val[$i]."'  style='background-color:#E0E0E0 ; color:#303030  ;'>Not ".$not_val[$i]."</option>";

                   else

                     echo  "<option>".$model1."</option>";
                     

              }
             ?>

		 <option> All </option>

              <?

                  while($row1=mysqli_fetch_array($fld_list[4])){
                
                    print "<option>$row1[0]</option>";

                     print "<option value='*$row1[0]'  style='background-color:#E0E0E0 ; color:#303030  ;'>Not $row1[0]</option>";
                  }

                 ?>
                 </select>

              </td>
             <td>

               <select name='regno1' style='width:80px'>
		<?
                   $i=2;

                if(($$fld[$i])&&($$fld[$i]!='All')){
               
                    if(($indic[$i])&&($indic[$i]=='*'))

                      echo   "<option value='*".$not_val[$i]."'  style='background-color:#E0E0E0 ; color:#303030  ;'>Not ".$not_val[$i]."</option>";

                   else

                     echo  "<option>".$regno1."</option>";
                     

              }
             ?>
		<option> All </option>

              <?

                  while($row1=mysqli_fetch_array($fld_list[2])){
                
                    print "<option>$row1[0]</option>";

                     print "<option value='*$row1[0]'  style='background-color:#E0E0E0 ; color:#303030  ;'>Not $row1[0]</option>";
                  }

                 ?>
                 </select>

              </td>
               <td>

               <select name='instype1' style='width:80px'>

		<?
                  $i=6;

                if(($$fld[$i])&&($$fld[$i]!='All')){
               
                    if(($indic[$i])&&($indic[$i]=='*'))

                     echo   "<option value='*".$not_val[$i]."'  style='background-color:#E0E0E0 ; color:#303030  ;'>Not ".$not_val[$i]."</option>";

                   else

                     echo "<option>".$instype1."</option>";
                     

              }
             ?>

		<option> All </option>

              <?

                  while($row1=mysqli_fetch_array($fld_list[6])){
                
                    print "<option>$row1[0]</option>";

                     print "<option value='*$row1[0]'  style='background-color:#E0E0E0 ; color:#303030  ;'>Not $row1[0]</option>";
                  }

                 ?>
                 </select>

              </td>
               <td>

               <select name='insurance1' style='width:80px'>

             <?
                  $i=7;

                if(($$fld[$i])&&($$fld[$i]!='All')){
               
                    if(($indic[$i])&&($indic[$i]=='*'))

                      echo   "<option value='*".$not_val[$i]."'  style='background-color:#E0E0E0 ; color:#303030  ;'>Not ".$not_val[$i]."</option>";

                   else

                     echo "<option>".$insurance1."</option>";
                     

                }
             ?>

               <option> All </option>

              <?

                  while($row1=mysqli_fetch_array($fld_list[7])){
                
                    print "<option>$row1[0]</option>";

                     print "<option value='*$row1[0]'  style='background-color:#E0E0E0 ; color:#303030  ;'>Not $row1[0]</option>";
                  }

                 ?>
                 </select>

              </td>
               <td>

               <select name='jobtype1' style='width:80px'>

		<?
                   $i=8;

                if(($$fld[$i])&&($$fld[$i]!='All')){
               
                    if(($indic[$i])&&($indic[$i]=='*'))

                      echo   "<option value='*".$not_val[$i]."'  style='background-color:#E0E0E0 ; color:#303030  ;'>Not ".$not_val[$i]."</option>";

                   else

                     echo  "<option>".$jobtype1."</option>";
                     

              }
             ?>

		<option> All </option>

              <?

                  while($row1=mysqli_fetch_array($fld_list[8])){
                
                    print "<option>$row1[0]</option>";

                     print "<option value='*$row1[0]'  style='background-color:#E0E0E0 ; color:#303030  ;'>Not $row1[0]</option>";
                  }

                 ?>
                 </select>

              </td>
              <td>

               <select name='customer1' style='width:80px'>

		<?
                    $i=5;

                if(($$fld[$i])&&($$fld[$i]!='All')){
               
                    if(($indic[$i])&&($indic[$i]=='*'))

                     echo   "<option value='*".$not_val[$i]."'  style='background-color:#E0E0E0 ; color:#303030  ;'>Not ".$not_val[$i]."</option>";

                   else

                     echo  "<option>".$customer1."</option>";
                     

              }
             ?>

		 <option> All </option>

              <?

                  while($row1=mysqli_fetch_array($fld_list[5])){
                
                    print "<option>$row1[0]</option>";

                     print "<option value='*$row1[0]'  style='background-color:#E0E0E0 ; color:#303030  ;'>Not $row1[0]</option>";
                  }

                 ?>
                 </select>

              </td>
               <td></td>
               <td></td>
              <td>

               <select name='receivedby1' style='width:80px'>
		<?
                   $i=9;

                if(($$fld[$i])&&($$fld[$i]!='All')){
               
                    if(($indic[$i])&&($indic[$i]=='*'))

                      echo   "<option value='*".$not_val[$i]."'  style='background-color:#E0E0E0 ; color:#303030  ;'>Not ".$not_val[$i]."</option>";

                   else

                     echo  "<option>".$receivedby1."</option>";
                     

              }
             ?>
		<option> All </option>

              <?

                  while($row1=mysqli_fetch_array($fld_list[9])){
                
                    print "<option>$row1[0]</option>";

                     print "<option value='*$row1[0]'  style='background-color:#E0E0E0 ; color:#303030  ;'>Not $row1[0]</option>";
                  }

                 ?>
                 </select>

              </td>
                 <td>

               <select name='work_status1' style='width:80px'>

		<?
                  $i=10;

                if(($$fld[$i])&&($$fld[$i]!='All')){
               
                    if(($indic[$i])&&($indic[$i]=='*'))

                     echo   "<option value='*".$not_val[$i]."'  style='background-color:#E0E0E0 ; color:#303030  ;'>Not ".$not_val[$i]."</option>";

                   else

                     echo "<option>".$work_status1."</option>";
                     

                }
             ?>

		<option> All </option>

              <?

                  while($row1=mysqli_fetch_array($fld_list[10])){
                
                    print "<option>$row1[0]</option>";

                     print "<option value='*$row1[0]'  style='background-color:#E0E0E0 ; color:#303030  ;'>Not $row1[0]</option>";
                  }

                 ?>
                 </select>

              </td>

              <td></td>

              <td>

                <select name='tech1' style='width:80px'>

		<?

               $fld_list_tech=mysqli_query($db,"select distinct(team) from jcworking_status where  update_date between '$fromdt' and '$todt'  and  brcode='$brcode' ");

                if(($tech1)&&($tech1!='All')){
               
                     $val1  =substr($tech1,1);  

	     	       $indic1=substr($tech1,0,1);

                     if(($indic1)&&($indic1=='*'))

                       echo   "<option value='*".$val1."'  style='background-color:#E0E0E0 ; color:#303030  ;'>Not ".$val1."</option>";

                    else

                      echo "<option>".$tech1."</option>";
                     

                } 
             ?>

		<option> All </option>

              <?

                  while($row1=mysqli_fetch_array($fld_list_tech)){
                
                    print "<option>$row1[0]</option>";

                     print "<option value='*$row1[0]'  style='background-color:#E0E0E0 ; color:#303030  ;'>Not $row1[0]</option>";
                  }

                 ?>
                 </select>

              </td>



                  
              <td colspan=7><input type='hidden' name='fromdt' value='<? echo $fromdt;?>'/>
                       Fin: <select name='fin_date1' style='width:80px'>

		<?
                  $i=11;

                if(($$fld[$i])&&($$fld[$i]!='All')){
               
                    if(($indic[$i])&&($indic[$i]=='*'))

                     echo   "<option value='*".$not_val[$i]."'  style='background-color:#E0E0E0 ; color:#303030  ;'>Yes</option>";

                     else

			echo "<option value='".$not_val[$i]."'>No</option>";

                  }

             ?>

		<option> All </option>
              <option value='*0000-00-00'> Yes </option>
            
              <option value='0000-00-00'> No</option>
              </select>
                
               Inv: <select name='inv_date1' style='width:80px'>

		<?
                  $i=12;

                if(($$fld[$i])&&($$fld[$i]!='All')){
               
                    if(($indic[$i])&&($indic[$i]=='*'))

                     echo   "<option value='*".$not_val[$i]."'  style='background-color:#E0E0E0 ; color:#303030  ;'>Yes</option>";

                   else

			echo "<option value='".$not_val[$i]."'>No</option>";
                     

                }
             ?>

		<option> All </option>
              <option value='*0000-00-00'> Yes </option>
              <option value='0000-00-00'> No</option>
              </select>

             Marked: <select name='marked' style='width:80px'>

		<?

                if(($marked)&&($marked!='All')){
               
                   
                     echo   "<option   style='background-color:#E0E0E0 ; color:#303030  ;'>".$marked."</option>";

                   
                  }

             ?>

		<option> All </option>
              <option > Yes </option>
            
              <option > No</option>
              </select>

    
				<input type='submit' name='show1' value='Show' >
                            <input type='hidden' name='todt' value='<? echo $todt;?>'/></td>
                   </tr>

       
  <?

	$i=1;

	$lab_tot=0;

	$spare_tot=0;


      

	while($row=mysqli_fetch_array($sql))
    	 {
        $flag1=1;

        $re=mysqli_query($db,"select * from prime_jcardparts where brcode='$brcode'  and jcno='$row[1]' and partname not in (select porder from pjcardparts where brcode='$brcode' and jcno='$row[1]')");
         if(mysqli_num_rows($re)>0)
               $pending='Yes';
         else
               $pending='No'; 

           
        

              $r1=mysqli_query($db,"select * from jcworking_status where jcno='$row[1]' and brcode='$brcode' order by id desc limit 1");

             $res=mysqli_fetch_row($r1);

    	 
	      $sql1=mysqli_query($db,"select sum(total),sum(labramt) from jcard_estparts where estno='$row[40]' and  brcode='$brcode'");
     
              $total=mysqli_fetch_row($sql1);
		$sq=mysqli_query($db,"select sum(ac_gas),sum(other_exp),sum(misc),sum(collexces) from jcard_est where estno='$row[40]' and  brcode='$brcode'");
     
              $rs=mysqli_fetch_row($sq);


          if(($tech1)&&($tech1!='All')){
               
                     $val1  =substr($tech1,1);  

	     	       $indic1=substr($tech1,0,1);

                     if(($indic1)&&($indic1=='*')){

                           if($res[8]==$val1)
                           
                                $flag1=0;
                     }
                     else
                     {
                           if($res[8]==$tech1)
                               $flag1=1;
                           else
                               $flag1=0;
                     }
           }
          if($flag1==1){

            
            if(($marked)&&($marked!='All')){

               $mark=mysqli_query($db,"select * from jcardinvoice where jcno='$row[1]' and brcode='$brcode' and marked_amt>0 ");
              if($marked=='Yes') {
                      if(mysqli_num_rows($mark)<=0)
                          $flag1=0;
               
              } 
              if($marked=='No') {

                      if(mysqli_num_rows($mark)<=0)
                          $flag1=1;
              }          
           }

        }

           if($flag1==0)
                 continue;
                   
            	print "<tr>";

              print "<td>".$i++."</td>";
	
		print "<td>$row[1]</td>";

		print "<td>".datetimetoHtml($row[11])."</td>";
        
              print "<td>$row[2]</td>";

		print "<td>$row[3]</td>";

              print "<td>$row[4]</td>";

		print "<td >$row[7]</td>";

		if($row[7]=='Insurance')
			{
			$r++;
			}
		else

			{
			$p++;
			}


		print "<td >$row[8]</td>";

              print "<td >$row[24]</td>";

              print "<td >$row[15]</td>";

              print "<td>".datetimetoHtml($row[28])."</td>";

		print "<td >$row[9]</td>";

		print "<td >$row[10]</td>";

		print "<td >$row[work_status]</td>";

		print "<td >".datetimetoHtml($row[work_status_date])."</td>";

              print "<td >$res[8]</td>";

		print "<td >$res[6]</td>";

              print "<td >".$pending."</td>";

		print "<td >$row[est_no]</td>";

		if($row[est_no]>0)
			{
   			$k++;
			print "<td >".datetimetoHtml($row[est_date])."</td>";

			$sql1=mysqli_query($db,"select sum(total),sum(labramt) from jcard_estparts where estno='$row[40]' and  brcode='$brcode'");
				$total=mysqli_fetch_row($sql1);

			$sq=mysqli_query($db,"select sum(ac_gas),sum(other_exp),sum(misc),sum(collexces) from jcard_est where estno='$row[40]' and  brcode='$brcode'");
              		$rs=mysqli_fetch_row($sq);

		 	$sumamt=$rs[0]+$rs[1]+$rs[2]+$rs[3]+$total[0]+$total[1];

			$est_tot+=$sumamt;

			print "<td >$sumamt</td>";


		       }
		else
			{

			print "<td ></td>";

			print "<td >0</td>";

			}

		$sql12=mysqli_query($db,"select sum(amt) from jcardinvoice where jcno='$row[1]' and  brcode='$brcode' and typ='cus'");
			$total112=mysqli_fetch_row($sql12);

		$sql122=mysqli_query($db,"select distinct(depamt) from jcardinvoice where jcno='$row[1]' and  brcode='$brcode' and typ='cus'");
  			$total1112=mysqli_fetch_row($sql122);
		

		$cusamt=$total112[0]-$total1112[0];


		if($cusamt>0)
			{

			print "<td>$cusamt</td>";	

			$cus_tot+=$cusamt;	

			$c++;

			}
		else
			{

			print "<td ></td>";

			}


		$sql12=mysqli_query($db,"select sum(amt),sum(depamt/2) from jcardinvoice where jcno='$row[1]' and  brcode='$brcode' and typ='ins'");
        		$total12=mysqli_fetch_row($sql12);

		$insamt=$total12[0]-$total12[1];

		if($insamt>0)
			{
			print "<td>$insamt</td>";	

			$ins_tot+=$insamt;	

			$ins++;

			}
		else
			{
	
			print "<td ></td>";

			}


		print "</tr>";
     
     		$lab_tot+=$row[9];

     		$spare_tot+=$row[9];

		$othtot+=$sumamt;

       }  //loop of gateentry query

     	print "<tr>";
  
       print "<td colspan='16' ><b>Total</td>";

       print "<td align='right'><b>".putcoma($spare_tot)."</td>";

       print "<td align='right'><b>Estimate(Nos)</td>";

	print "<td colspan='3' align='right'><b>".putcoma($l)."</td>";

  	print "<td align='right'><b>Estimate(Amount)</td>";

	print "<td align='right'><b>".putcoma($est_tot)."</td>";

	print "</tr>";

	print "<tr><td rowspan='12' colspan='13' align='left'><b>Summary</b></td>";

	print "<tr><td  colspan='11'><hr width='100%'></hr></td></tr>";

	print "<tr><td  align='right' colspan='8'><b>Total Labour QR:</b></td><td align='right' colspan='2'><b>".putcoma($lab_tot)."</b></td></tr>";

	print "<tr><td  align='right' colspan='8'><b>Total Insurance(Cases):</b></td><td align='right' colspan='2'><b>".putcoma($r)."</b></td></tr>";

	print "<tr><td  align='right' colspan='8'><b>Total Private(Cases):</b></td><td align='right' colspan='2'><b>".putcoma($p)."</b></td></tr>";

	print "<tr><td  align='right' colspan='8'><b>Total Estimate (Nos)</b></td><td align='right' colspan='2'><b>".putcoma($k)."</b></td></tr>";

	print "<tr><td  align='right' colspan='8'><b>Total Estimate Amount:</b></td><td align='right' colspan='2'><b>".putcoma($est_tot)."</b></td></tr>";

	print "<tr><td  align='right' colspan='8'><b>Total Cus.Inv (Nos)</b></td><td align='right' colspan='2'><b>".putcoma($c)."</b></td></tr>";

	print "<tr><td  align='right' colspan='8'><b>Total Cus.Inv QR:</b></td><td align='right' colspan='2'><b>".putcoma($cus_tot)."</b></td></tr>";

	print "<tr><td  align='right' colspan='8'><b>Total Ins.Inv (Nos)</b></td><td align='right' colspan='2'><b>".putcoma($ins)."</b></td></tr>";

	print "<tr><td  align='right' colspan='8'><b>Total Insurance.Inv QR:</b></td><td align='right' colspan='2'><b>".putcoma($ins_tot)."</b></td></tr>";

	print "<tr><td  align='right' colspan='8'><b>Grand Total QR:</b></td><td align='right' colspan='2'><b>".putcoma($ngtot)."</b></td></tr>";

	print"</table>";

  }

include("jc_register_list1.php");
                    
              
 ?>
</form>
