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

 th{
  

   // background-color: grey;  
    font-weight: bold;  
    color: white; 
    border:1px solid #D7D7D1;

    border-collapse:collapse;
   

background: rgb(181,189,200); /* Old browsers */
background: -moz-linear-gradient(top, rgba(181,189,200,1) 0%, rgba(130,140,149,1) 36%, rgba(40,52,59,1) 100%); /* FF3.6+ */
background: -webkit-gradient(linear, left top, left bottom, color-stop(0%,rgba(181,189,200,1)), color-stop(36%,rgba(130,140,149,1)), color-stop(100%,rgba(40,52,59,1))); /* Chrome,Safari4+ */
background: -webkit-linear-gradient(top, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* Chrome10+,Safari5.1+ */
background: -o-linear-gradient(top, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* Opera 11.10+ */
background: -ms-linear-gradient(top, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* IE10+ */
background: linear-gradient(to bottom, rgba(181,189,200,1) 0%,rgba(130,140,149,1) 36%,rgba(40,52,59,1) 100%); /* W3C */
filter: progid:DXImageTransform.Microsoft.gradient( startColorstr='#b5bdc8', endColorstr='#28343b',GradientType=0 ); /* IE6-9 */

 }

.myButton {
	-moz-box-shadow:inset 0px -3px 7px 0px #ffffff;
	-webkit-box-shadow:inset 0px -3px 7px 0px #ffffff;
	box-shadow:inset 0px -3px 7px 0px #ffffff;
	background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #ededed), color-stop(1, #dfdfdf));
	background:-moz-linear-gradient(top, #ededed 5%, #dfdfdf 100%);
	background:-webkit-linear-gradient(top, #ededed 5%, #dfdfdf 100%);
	background:-o-linear-gradient(top, #ededed 5%, #dfdfdf 100%);
	background:-ms-linear-gradient(top, #ededed 5%, #dfdfdf 100%);
	background:linear-gradient(to bottom, #ededed 5%, #dfdfdf 100%);
	filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#ededed', endColorstr='#dfdfdf',GradientType=0);
	background-color:#ededed;
	-moz-border-radius:3px;
	-webkit-border-radius:3px;
	border-radius:3px;
	border:1px solid #dcdcdc;
	display:inline-block;
	cursor:pointer;
	color:#777777;
	font-family:arial;
	font-size:13px;
	padding:9px 23px;
	text-decoration:none;
	text-shadow:0px 1px 0px #ffffff;
}
.myButton:hover {
	background:-webkit-gradient(linear, left top, left bottom, color-stop(0.05, #dfdfdf), color-stop(1, #ededed));
	background:-moz-linear-gradient(top, #dfdfdf 5%, #ededed 100%);
	background:-webkit-linear-gradient(top, #dfdfdf 5%, #ededed 100%);
	background:-o-linear-gradient(top, #dfdfdf 5%, #ededed 100%);
	background:-ms-linear-gradient(top, #dfdfdf 5%, #ededed 100%);
	background:linear-gradient(to bottom, #dfdfdf 5%, #ededed 100%);
	filter:progid:DXImageTransform.Microsoft.gradient(startColorstr='#dfdfdf', endColorstr='#ededed',GradientType=0);
	background-color:#dfdfdf;
}
.myButton:active {
	position:relative;
	top:1px;
}



</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 >
<?php include('includes/top.php'); ?>
<div class='cont'>

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

		<table class="form" style="width:auto" align='center' >
			<tr>
				<th  colspan=2>Jobcard  Analysis:</th></tr>
			
				<tr><td> 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>
			
				<td>

                                <input type='submit' class='myButton' name='show1' value=' Released  But Not Finalised' >
                                <input type='submit' class='myButton' name='show2' value='Finalised But Not Invoiced' >
                                <input type='submit' class='myButton' name='show3' value='Invoiced But Not Marked' >
                                <input type='submit' class='myButton' name='show4' value=' Finalised Is Done' >
                                <input type='submit' class='myButton' name='show5' value='Invoice Is Done.' >

                          
                          </td></tr>

				<tr><th colspan=2 height='10'></th></tr>

			

            </table>
      </form>

<?
 if(($show1)||($show2)||($show3)||($show4)||($show5))
  {

  $title='';
	if($show1){
	$sql=mysqli_query($db,"select * from gateentry where entrydate between '$fromdt' and '$todt' and brcode='$brcode' and work_status='RELASED' and fin_date <='0000-00-00' and instype='Insurance' order by jcno");
        $title=$show1;
       }

      if($show2){
	$sql=mysqli_query($db,"select * from gateentry where entrydate between '$fromdt' and '$todt' and brcode='$brcode' and invno<='0' and fin_date >'0000-00-00' and instype='Insurance' order by jcno");
   
        $title=$show2;
       }
	
     if($show3){

       $sql=mysqli_query($db,"SELECT DISTINCT gateentry.*,  jcardinvoice .invno FROM gateentry INNER JOIN jcardinvoice ON gateentry.invno=jcardinvoice .invno where jcardinvoice .marked_amt=0 and jcardinvoice .brcode='$brcode' AND gateentry .brcode='$brcode' AND gateentry.entrydate between '$fromdt' and '$todt' and gateentry.instype='Insurance' order by gateentry.jcno");
       $title=$show3;
       }

      if($show4){
	$sql=mysqli_query($db,"select * from gateentry where entrydate between '$fromdt' and '$todt' and brcode='$brcode'  and fin_date >'0000-00-00' and instype='Insurance' order by jcno");
   
        $title=$show4;
       }

      if($show5){
	$sql=mysqli_query($db,"select * from gateentry where entrydate between '$fromdt' and '$todt' and brcode='$brcode' and invno>'0' and instype='Insurance' order by jcno");
   
        $title=$show5;
       }


?>

 <table align='center' class='report'> 

	<tr>
		<td colspan='25' > 
	
			<b>
				  <? echo $title;?> Report FROM 
			</b>
	
			<?
		
		 		echo dateandtimetoHtml($fromdt); 

			?>
		
			 <b> 
	
				TO 

			</b> 

			 <? 

				echo dateandtimetoHtml($todt); 

			?> 

       </tr>  

<tr><th> JobNo <th>  Date <th>  RegNo <th>Veh.Name <th>  Model <th>  Customer <th>  Type <th>  Ins.Co <th>Job Type<th>Pending Order<th>  Labour Amount <th>  Pur. Amount <th>  Finalisation Spare  Amount <th>  Finalisation Labour Amount <th>  Deprc. Amount <th>  Marked. Amount <th> Profit <th>  Advisor <th>  Status <th>  Technician <th>  Remarks <th>  StatusDate <th>Est.Delivery Dt<th>  EstNo<th>  EstDate <th>  EstAmt <th>  Cus.Inv <th>  Ins.Inv </tr>";

<?
	$i=1;

	$lab_tot=0;

	$spare_tot=0;

   


	while($row=mysqli_fetch_array($sql))
    	 {
  
    	     $jno=$row[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='$jno' and  brcode='$brcode' order by id desc limit 1");

             $res=mysqli_fetch_row($r1);

             $r2=mysqli_query($db,"select sum(gtot) from pjcardparts where jcno='$jno' and  brcode='$brcode'");

             $res2=mysqli_fetch_row($r2);

             $r3=mysqli_query($db,"select fin_labour, fin_spare from finalisation where jcno='$jno' and  brcode='$brcode'");

             $res3=mysqli_fetch_row($r3);

        

             $r4=mysqli_query($db,"select depamt,marked_amt from jcardinvoice where jcno='$jno' and  brcode='$brcode' order by jcno limit 1");

             $res4=mysqli_fetch_row($r4);

	      $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($res3[1]>0)
                    $profit=$res3[1]-$res2[0];

              else
                     $profit='';

		print "<tr><td>$row[1]</td>";

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

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

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

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

              print "<td>$row[16]</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>".$pending."</td>";

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

		print "<td>$res2[0]</td>";
		print "<td>$res3[1]</td>";
		print "<td>$res3[0]</td>";
		print "<td>$res4[0]</td>";
              print "<td>$res4[1]</td>";
              print "<td>".$profit."</td>";
		print "<td>$row[10]</td>";
	       print "<td>$row[work_status]</td>";
              print "<td>$res[8]</td>";
		print "<td>$res[6]</td>";
              print "<td>".datetimetoHtml($row[work_status_date])."</td>";
              print "<td>".datetimetoHtml($row[estdate])."</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;
             	       $contents .=$sumamt."\t";


            }
           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'");
	$sql122=mysqli_query($db,"select distinct(depamt) from jcardinvoice where jcno='$row[1]' and  brcode='$brcode' and typ='cus'");

	$total112=mysqli_fetch_row($sql12);
	$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>";
	}


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

     		$spare_tot+=$row[9];
		$othtot+=$sumamt;

      }

     	

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

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

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

	print "<td colspan='14' 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='13' colspan='22' align='left'><b>Summary</b></td>";
print "<tr><td  colspan='6'><hr width='100%'></hr></td></tr>";
print "<tr><td  align='right' colspan='4'><b>Total Labour QR:</b></td><td align='right' colspan='2'><b>".putcoma($lab_tot)."</b></td></tr>";
print "<tr><td  align='right' colspan='4'><b>Total Insurance(Cases):</b></td><td align='right' colspan='2'><b>".putcoma($r)."</b></td></tr>";
print "<tr><td  align='right' colspan='4'><b>Total Private(Cases):</b></td><td align='right' colspan='2'><b>".putcoma($p)."</b></td></tr>";


print "<tr><td  align='right' colspan='4'><b>Total Estimate (Nos)</b></td><td align='right' colspan='2'><b>".putcoma($k)."</b></td></tr>";
print "<tr><td  align='right' colspan='4'><b>Total Estimate Amount:</b></td><td align='right' colspan='2'><b>".putcoma($est_tot)."</b></td></tr>";
print "<tr><td  align='right' colspan='4'><b>Total Cus.Inv (Nos)</b></td><td align='right' colspan='2'><b>".putcoma($c)."</b></td></tr>";
print "<tr><td  align='right' colspan='4'><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='4'><b>Total Ins.Inv (Nos)</b></td><td align='right' colspan='2'><b>".putcoma($ins)."</b></td></tr>";
print "<tr><td  align='right' colspan='4'><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='4'><b>Grand Total QR:</b></td><td align='right' colspan='2'><b>".putcoma($ngtot)."</b></td></tr>";




print"</table>";


}

?>
