<? 
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../index.php'; </script>";
 return;
}
include("test.php");
include("../opendb.php");
include ("../test.php");
//include("calstock.php");
$jcno=$_REQUEST['jcno'];
$invno=$_REQUEST['invno'];
$re=mysqli_query($db,"select * from jobcard where jcno='$jcno' and brcode='$brcode'");
if(mysqli_num_rows($re)<=0)
 {
    print "Jobcard does not exist";
    return;
 }
$jcrow=mysqli_fetch_array($re);
date_default_timezone_set('Asia/Kolkata');
$crtm=date('H:i:s');



?>
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=ISO-8859-1">
<title>Jobcard Invoice</title>

<style>

body{
  -webkit-print-color-adjust:exact;
}
.printable{ 
      page-break-before: always;

      margin-top:30px;
    }
.tbl
{
border: 1px solid black;
border-bottom:0px solid white;
font-size:10px;
text-transform:uppercase;
}
.tbl td
{
border: 0px solid black;
}
#tbl
{
border: 1px solid black;

}
.tble 
{
border: 1px solid black;
border-bottom:0px solid white;
font-size:10px;
border-collapse:collapse;
text-transform:uppercase;

}
.tble  td{

margin-left:10px;
margin-right:10px;
padding-left:10px;
padding-right:10px;
padding-top: 5px;

}

.tble th
{
border:1px solid black;
}
.tbl1{
border: 1px solid black;
border-bottom:0px solid white;
font-size:10px;
border-collapse:collapse;
text-align:right;
text-transform:uppercase;
}
.tbl1 td{
border-bottom:1px solid black;
height:10px;
}

#add_td{
font-size:12px;
height:15px;
}
#add_td br{
margin:0px;
padding:0px;
}
.tot_td{
border-bottom:0px solid black;
}
.tot_td1{
border-top:0px solid black;
}
#tot_tbl td{
border:1px solid black;
border-collapse:collapse;
}
body
 {font-family:Arial;
   }

p{
 margin:0px;
 padding:0px;
 }


  @media print
        {
            #head
            {
                background-color:white;
            }
        }

</style>
<body onload='window.print()'>
<?
    $cess_tot=0;
    $qry=mysqli_query($db,"select * from jobcard where jcno='$jcno' and brcode='$brcode'");
    $sql="select * from jobcard where jcno='$jcno'  and brcode='$brcode'";
    //echo $sql;
    $row=mysqli_fetch_array($qry);       

    $balres1=mysqli_query($db,"select * from ledger where brcode = '$brcode' and led ='$row[cname]'");

    $balrow1=mysqli_fetch_row($balres1);
    $cusqry=mysqli_query($db,"select * from customer where acname='$row[cname]'");
    $cusrow=mysqli_fetch_array($cusqry);
    
    /*
    $balres2=mysqli_query($db,"select sum(amt) from down_payment where jcno='$jcno' and brcode = '$brcode' and jvno>0 ");
    $balrow2=mysqli_fetch_row($balres2);
    $adv=$balrow2[0];
    */
    $balres=mysqli_query($db,"select sum(dramt),sum(cramt) from journal2 where brcode='$brcode' and partic='$row[cname]'");
    $balrow=mysqli_fetch_row($balres);
    if($balrow1[3]=='Dr')
    {
        $bal=($balrow[0]+$balrow1[2])-$balrow[1]; //print '<br>bal'.$row[2];
    }
    else
    {
        $bal=$balrow[1]+$balrow1[2]-$balrow[0];
    }

    $date = $row['estdate'];
    $invdate1 = $row['inv_date'];
    $invdate = date("d-m-Y", strtotime($invdate1));
    $newDate = date("d-m-Y", strtotime($date));


   

    $q_count2=mysqli_query($db,"select count(*) from jcardserv where jcno='$jcno' and brcode='$brcode'");
    $sq="select count(*) from jcardserv where jcno='$jcno' and brcode='$brcode'";
    //echo $sq;
    $cnt2=mysqli_fetch_array($q_count2);
   

    $count=$cnt2[0];
    if(strlen($count)<=0)
    {
        $count=0;
    }

    //$limit=23;
    $limit=10;
    $pg_no=floor($count/$limit);
 
 



    $j=1;
    $i=1;
	$jtot=0;
	$pdisctot=0;
	$ltot=0;
	$subtot=0;
	$ldis=0;
 
	$res2=mysqli_query($db,"select * from jcardparts where jcno='$jcno' and brcode='$brcode'");
	while($res3=mysqli_fetch_array($res2))
	{
        $slno_pt[$j]=$j;
        $code_pt[$j]=$res3['partcode'];
        $item_pt[$j]=$res3['partname'];
        $qty_pt[$j] =$res3['qty'];
        $rate_pt[$j]=$res3['rate'];
        $disc_per[$j]=$res3['disc'];
        $bef_tax[$j]=$res3['amt'];
		//$ltot_pt+=$res3['tot'];
		//$ldis+=$res3['dis'];
		$tr = "select * from partmaster where partcode = '$res3[partcode]'";
        $trd=mysqli_query($db,$tr);
        $trdrow=mysqli_fetch_array($trd);
        $hscd_pt[$j]="(".$trdrow['hsncode'].")";

		$cgstprc_pt[$j]=$res3['cgstp'];
		$sgstprc_pt[$j]=$res3['sgstp'];
		$cgstamt_pt[$j]=$res3['cgstamt'];
		$sgstamt_pt[$j]=$res3['sgstamt'];
	    $igstprc_pt[$j]=$res3['igstp'];
	    $igstamt_pt[$j]=$res3['igstamt'];
	    $cessprc_pt[$j]=$res3['cessp'];
	    $cessamt_pt[$j]=$res3['cessamt'];
	    $ptot_pt[$j]=$res3['gtot'];
		
		$cgstot_pt+=$res3['cgstamt'];
		$sgstot_pt+=$res3['sgstamt'];
		$igstot_pt+=$res3['igstamt'];
		
		$prttot_pt+=$res3['amt'];
		$ltot_pt+=$res3['gtot'];
		$item_tot+=($res3['gtot']-$res3['cessamt']);
		$cess_tot += $res3['cessamt'];
		$j++;
             
	}
	
$ntot_pt=$ltot_pt;

	$res21=mysqli_query($db,"select * from jcardserv where jcno='$jcno' and brcode='$brcode'");
	while($res31=mysqli_fetch_array($res21))
	{
        $slno[$i]=$i;
        $code[$i]=$res31['service'];
        $item[$i]=$res31['descr'];
        $qty[$i] ='1.00';
        $rate[$i]=$res31['servamt'];
		$ltot+=$res31['tot'];
		$subtot+=$res31['subamt'];
		$ldis+=$res31['dis'];

		    $cgstprc[$i]=$res31['cgstp'];
		    $sgstprc[$i]=$res31['sgstp'];
		    $cgstamt[$i]=$res31['cgstamt'];
		    $sgstamt[$i]=$res31['sgstamt'];

		    $igstprc[$i]=$res31['igstp'];
		    $igstamt[$i]=$res31['igstamt'];
		    $cessamtl[$i]=$res31['hredutx'];
		    $hsncode[$i]=998714;
		    $hscd[$i]="(998714)";
		
		$prttot+=$res31['servamt'];
	
		$cgstot+=$res31['cgstamt'];
		$sgstot+=$res31['sgstamt'];
		$igstot+=$res31['igstamt'];
		
		$ptot[$i]=$res31['tot'];
		$lab_tot+=round(($res31['tot']-$res31['hredutx']),2);
		$cess_tot += $res31['hredutx'];
		$i++;
             
	}
	
$gtot=$jtot+$ltot;


print $invdate1;

if($invdate1>'2016-01-31')

{ 
$gtot=$ptot+$ltot+$subtot;


}

$ntot1=$gtot-$pdisctot;
$ntot=$ntot1-$row['adv_amt']-$ldis;


 $tot_fill=0;

 for($p=0;$p<=$pg_no;$p++)
 {
   if($p==$pg_no)
      {
       $tot_fill=1;
      }
               /* to fill total amt in last table if it is last print page */
   $lower_lmt=($p*$limit)+1;
    $upper_lmt=($p+1)*$limit;
    

?>

	<table border='0' width='100%' 
     
          <? if($p>0){
           ?>
            class='printable'
           <?
           }
           ?>
             >
	     <tr>
	<td align='center' width='100%' id='add_td'> 
<?
	$qry1=mysqli_query($db,"select * from branch where brcode='$brcode'");
	$row1=mysqli_fetch_array($qry1);
	if($brcode=='MEN888')
        print "<font size='5'><b>PSN MENTOR AND CAREER PRIVATE LIMITED</b></font></p>";
    else
        print "<font size='5'><img src='../images/logo.png' width=50px height=25px><b>PSN AUTOMOBILES PVT LTD</b></font><img src='../img/img-81.jpg' width=50px height=25px></p>";
	print "<p><b>ZF Authorised Dealer</b></p>";
		print "<p><b>GSTIN:$row1[tin]</b></p>";
	print "<font size='2'><b>".$row1['braddr']."</b></font><p >".$row1['brcity'].", ".$row1['brstate']."<br>Phone : $row1[brphone]";

	print " Email: psnzf.tvm@gmail.com";


		$fromdt1=implode('-', array_reverse(explode('-', $row['entrydate'])));
?>
	</td>

	<td align='right'  width='40%'> 
	</td></tr>
	</table>
	
     
	<table border='1' width='100%' style='border-collapse:collapse;'><tr>
	    <td  align='left' width='20%'  >JOB CARD NO:
	    
	    
	    <?
/*if($brcode == 'MAN140')
{
?>
<b>ZFMDJC
<?
}
else if($brcode == 'ERA153')
{
?>
<b>ZFEMJC
<?
}
else if($brcode == 'CAL556')
{
?>
 <b>ZFCTJC
<?
}
else
{
	print '['.substr($brcode,0,3).']';
}*/
?>
<?echo $jcrow['jcno']?></td>
	    
	<th  align='center'  width='50%' style='border:0px solid white;height:20px;font-size:18px;' id='head'>JOB CARD</th>
	<td  align='left' width='30%' >JOB CARD DATE:<? echo $fromdt1 ?></td>
	</tr></table>
	
	
	
	<table width=100% class='tble' border='0'>
    <tr><td>
	
	
	
	<table width=100%  border='1' >
	
	<tr>
	   <td >
		 <b>DEALERS CODE : P085</b>
               
                
			</td> <td >ACCIDENT	</td> 
			<td >REPEAT	</td> 
			<td >
		 
               PAID
                
			</td> 
				<td >
		 
               WRTY.
                
			</td> 
	</tr>
	
	</table>
	
	</td>    
           </tr>
	</table> 
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
	
 
	<table width=100% class='tble' border='0'>
    <tr><td>
       
       
       
       
       <table width=100%  border='1'>
           
           <tr>
            <td>Vehicle Details</td><td>:</td> <td></td>    
           </tr>
           <tr>
            <td>Model</td><td>:</td> <td></td>    
           </tr>
           <tr>
            <td>Chassis No.</td><td>:</td> <td></td>    
           </tr>
           <tr>
            <td>Reg No</td><td>:</td> <td><? echo $row['model'] ?></td>    
           </tr>
           <tr>
            <td>Date of Sale</td><td>:</td> <td></td>    
           </tr>
           <tr>
            <td>KM Covered</td><td>:</td> <td></td>    
           </tr>
           <tr>
            <td></td><td></td> <td></td>    
           </tr>
           </table> 
       
       
       
       
       
       
       
       
       
       
       
       
       
       
    </td>
    
    <td>
       
       
       
       
       <table width=100%  border='1' >
           
           <tr>
            <td colspan=3 align=center>Power Steering Particulars</td> 
           </tr>
           <tr>
            <td width="40%">AGG</td>  <td width="30%">Box</td><td width="30%">Pump</td>
           </tr>
          
           <tr>
            <td width="40%">Part No.</td><td width="30%"></td> <td width="30%"></td>    
           </tr>
           <tr>
            <td width="40%">Sl No</td><td width="30%"></td> <td width="30%"></td>    
           </tr>
           <tr>
            <td width="40%">Month & Year</td><td width="30%"></td> <td width="30%"></td>    
           </tr>
           <tr>
            <td width="40%"></td><td width="30%"></td> <td width="30%"></td>    
           </tr>
           <tr>
            <td width="40%">D.Comm</td><td width="30%"><? echo $row['dcomm'] ?></td> <td width="30%"></td>    
           </tr>
           </table> 
       
       
       
       
       
       
       
       
       
       
       
       
        
    </td>
        
        
        
        
	</tr>
	</table>
	
	
	
	<table width=100% class='tble' border='0'>
    <tr><td>
	
	<table width=100%  border='1' >
           <tr>
            <td colspan=3><b>Customer Name & Address</b</td>   
           </tr>
           <tr>
            <td>Name</td><td>:</td> <td><? echo $row['cname']; ?></td>    
           </tr>
           <tr>
            <td>Address</td><td>:</td> <td><? echo $cusrow['addr1']; ?></td>    
           </tr>
           <tr>
            <td>State</td><td>:</td> <td><? echo $cusrow['state1']; ?></td>    
           </tr>
           <tr>
            <td>GSTIN/Unique ID</td><td>:</td> <td><? echo $cusrow['gst']; ?></td>    
           </tr>
           <tr>
           
            <td>Phone No</td><td>:</td> <td><? echo $cusrow['phone1'] ?></td>    
           
           </tr>
           <tr>
            <td colspan=3></td>   
           </tr>
           </table> 
	
</td>    
           </tr>
	</table> 
	
	
	<style>
	    .tdcls
	    {
	        height:50px;
	    }
	</style>
	
	<table width=100% class='tble' border='0'>
    <tr><td>
	
	
	
	<table width=100%  border='1' >
	<tr><th>Complaint<th>Observation<th>Action Taken</tr>
	<tr>
	   <td align='center' width="35%" class='tdcls'>
		 
               <? echo $row['complaints'] ?>
                
			</td> <td align='center' width="35%" class='tdcls'>
		 
               <? echo $row['observation'] ?>
                
			</td> 
			<td align='center' width="30%" class='tdcls'>
		 
               <? echo $row['action_taken'] ?>
                
			</td> 
	</tr>
	
	</table>
	
	</td>    
           </tr>
	</table> 
	
	
	
	
	
	
	
	
	
	
	
	
	
	
       <table border='1' width='100%' style='border-collapse:collapse;margin-top:0px;font-size:10px;'><tr>
	<th>PARTS REPLACED</th></tr>
	<tr>
	   <td>	</td> 
	</tr>	<tr>
	   <td>	</td> 
	</tr>
	</table>
	
	<table width=100% class='tble'  border='1' FRAME=BOX BORDER=1 CELLPADDING=0 CELLSPACING=0 RULES=COLS >
	<tr><th>SlNo<th>Part Code<th>Part Name<th>Qty<th>Unit Price<th>Disc %<th>Before Tax<th>CGST %<th>CGSt Amt<th>SGST %<th>SGST Amt<th>IGST %<th>IGSt Amt<th>Total Amt</tr>
<?
        for($k=$lower_lmt;$k<=$upper_lmt;$k++)
	    {

        print "<tr><td width='15' style='padding-top: 10px;'>".$slno_pt[$k]."</td><td width='125' style='padding-top: 10px;'>".$code_pt[$k].$hscd_pt[$k]."</td><td width='125' style='padding-top: 10px;'>".$item_pt[$k]."</td><td width='15' style='padding-top: 10px;'>".$qty_pt[$k]."</td><td align='right' width='25' style='padding-top: 10px;'>".$rate_pt[$k]."</td><td align='right' width='25' style='padding-top: 10px;'>".
        $disc_per[$k]."</td><td align='right' width='25' style='padding-top: 10px;'>".$bef_tax[$k]."</td><td align='right' width='25' style='padding-top: 10px;'>".$cgstprc_pt[$k]."</td><td align='right' width='25' style='padding-top: 10px;'>".$cgstamt_pt[$k]."</td><td align='right' width='25' style='padding-top: 10px;'>".$sgstprc_pt[$k]."</td><td align='right' width='25' style='padding-top: 10px;'>".$sgstamt_pt[$k]."</td><td align='right' width='25' style='padding-top: 10px;'>".$igstprc_pt[$k]."</td><td align='right' width='25' style='padding-top: 10px;'>".$igstamt_pt[$k]."</td><td align='right' width='50' style='padding-top: 10px;'>".$ptot_pt[$k]."</td></tr>";
	    }
?>
	</table>	
       <table border='1' width='100%' style='border-collapse:collapse;margin-top:0px;font-size:10px;'>
	<td align='center'  width='100%' style='border:0px solid white;height:12px;'><b>LABOUR CHARGES</td></tr></table>
	<table width=100% class='tble'  border='1' FRAME=BOX BORDER=1 CELLPADDING=0 CELLSPACING=0 RULES=COLS>
	<tr><th>SlNo<th>Service<th >Service Amt<th>CGST %<th>CGSt Amt<th>SGST %<th>SGST Amt<th>IGST %<th>IGSt Amt<th>Total Amt</tr>
<?
        for($k=$lower_lmt;$k<=5;$k++)
	    {
            if($cessamtl[$k]>0)
                $cessp = "1.00";
            else
                $cessp = "";
        print "<tr><td width='15' style='padding-top: 10px;'>".$slno[$k]."</td><td width='250' style='padding-top: 10px;'>".$code[$k].$hscd[$k]."</td><td align='right' width='15' style='padding-top: 10px;'>".$rate[$k]."</td><td align='right' width='15' style='padding-top: 10px;'>".$cgstprc[$k]."</td><td align='right' width='15' style='padding-top: 10px;'>".$cgstamt[$k]."</td><td align='right' width='15' style='padding-top: 10px;'>".$sgstprc[$k]."</td><td align='right' width='15' style='padding-top: 10px;'>".$sgstamt[$k]."</td><td align='right' width='15' style='padding-top: 10px;'>".$igstprc[$k]."</td><td align='right' width='15' style='padding-top: 10px;'>".$igstamt[$k]."</td>";
        print "<td align='right' width='50' style='padding-top: 10px;'>".$ptot[$k]."</td></tr>";
	    }
	    $tot_all=$ntot+$ntot_pt;
	    $rnd=round($tot_all);
?>
	</table>
<table width=100% class='tble'  border='1' FRAME=BOX BORDER=1 CELLPADDING=0 CELLSPACING=0 RULES=COLS>
	<tr><th>Parts Replaced<th>Consumables/Misc. Charges<th >Labour Charges<th>Grand Total</tr>
<?
        
        print "<tr><td align='center' ><b><font size='4px'>$item_tot</font></b></td><td align='center'><b><font size='4px'>0</font></b></td><td align='center'><b><font size='4px'>$lab_tot</font></b></td><td align='center'><b><font size='4px'>$tot_all</font></b></td></tr>";
	   
?>
	</table>
	<table  width=100% class='tbl1' id='tbl' border='0' style='height:50px;text-align: left;'>
	
<tr><td colspan=2 style='border-bottom: 0px;'>	I have taken the delivery of the aggregates after repairs, in good order and to my satisfaction. I here by agree to the jobs listed in the job card and further accept to pay the above amount being charges for repairs and parts replaced.</td></tr>
	<tr><td align=left>

<br><br><br><br><br><br>
Signature of Customer
	</td><td>
	
<br><br><br><br><br><br>
Authorised Sign.
	</td>
	
	
	
	
	
	
	
	
	
	
	

	</tr>
	
	
	
	
	
	

	
	
	
	
	
	
	
	</table>
      
       <table border='1' width='100%' style='border-collapse:collapse;margin-top:10px;font-size:10px;'>
	<td align='right'  width='100%' style='border:0px solid white;height:12px;'><? echo 'Page:'.($p+1).'/'.($pg_no+1);?></td></tr></table>

<?
 }//close for loop
$curtm=date('Y-m-d');
$curtm=implode('-', array_reverse(explode('-', $curtm)));
?>
	 
    
	</table>

