<?
session_start();
include("../opendb.php");
include('mysqli_table.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='inde.php'; </script>";
 return;
}
include_once('testtot.php');

      $type=$_REQUEST['gname'];
	$verdt=$_REQUEST['dfrom'];
 //$dfrom=$y1.'-'.$m1.'-'.$d1;
 //$dto=$y2.'-'.$m2.'-'.$d2;
  //$dto1=implode("-",array_reverse(explode("-",$verdt)));
$dto1=implode("-",array_reverse(explode("-",$verdt)));
$brqry="select brname from branch where brcode='$brcode'";
$brrs=mysqli_query($db,$brqry);
$brrw=mysqli_fetch_array($brrs);
$brnchnm=$brrw[0];


       
			
				
			//$pdf = new FPDF();
                     $pdf = new FPDF('L','mm','A4');
			$pdf->AddPage();						
			$pdf->SetFont('Arial','B',10);
			$pdf->SetFont('','B');
			$dedres1=mysqli_query($db,"select brname from branch where brcode='$brcode'") or die("er5:".mysqli_error($db));
			$br_1=mysqli_fetch_array($dedres1);
			$pdf->SetFont('','BU');
			$pdf->Cell(250,5,'KERALA KHADI & VILLAGE INDUSTRIES BOARD',0,1,'C');
			$pdf->SetFont('Arial','',11);
			$brnchnm=strtoupper($brnchnm);						
                     $pdf->Cell(250,5,'CENTER NAME :'.$brnchnm,0,1,'C');
                     //$pdf->Ln(4);
		 	//$pdf->Ln(4);
			$pagno=1;
                     $pdf->Cell(250,5,'STOCK VERIFICATION STATEMENT AS ON '.$dto1,0,1,'C');$pdf->Cell(20,5,'Page '.$pagno,0,1,'C');
                     $pdf->SetFont('Arial','',10);
                     $pdf->Cell(13,10,'No.','LTR');$pdf->Cell(20,10,'Stock No.','LTR');$pdf->Cell(30,10,'Item Name','LTR');$pdf->Cell(20,10,'Rate','LTR');
                     $pdf->Cell(40,10,'Stock as per Ledger','LTR');$pdf->Cell(40,10,'Stock actually verified','LTR'); 
			$pdf->Cell(40,10,'Excess','LTR');$pdf->Cell(40,10,'Short','LTR');  $pdf->Cell(20,10,'Remarks','LTR');               
                     //$pdf->Ln(4);
                     $pdf->Ln(4);
                     $pdf->Ln(4);
  
if($type=='All')
    {
        $re=mysqli_query($db,"select * from stockverification where stockverifydt='$verdt' and brcode='$brcode' group by itemcode ");
    }
else
{
    $re=mysqli_query($db,"select * from stockverification where stockverifydt='$verdt' and gname='$type' and brcode='$brcode' group by itemcode ");
}
//$sql="select * from stockverification where stockverifydt='$verdt' and gname='$type' and brcode='$brcode' group by itemcode ";
//echo $sql;
//print "<tr style='border:1px solid black;'><td>Item Group : </td><td>$type</td><td colspan='9'></td></tr>";

//print "<TR><td></td><td></td><td></td><td></td><td align='right'>Qty</td><td  align='right'>Value</td><td align='right'>Qty</td><td  align='right'>Value</td><td align='right'>Qty</td><td  align='right'>Value</td><td align='right'>Qty</td><td  align='right'>Value</td></tr>";
$i=1;
$tprice=0;
$q1=0;$q2=0;$q3=0;$q4=0;
$t1=0;$t2=0;$t3=0;$t4=0;
$mctr=1;
$p_q1 =0;
$p_v1 =0;
$p_q2 =0;
$p_v2 =0;
$p_q3 =0;
$p_v3 =0;
$p_q4 =0;
$p_v4 =0;
while($row=mysqli_fetch_array($re))
{
       $op_qty = $row[2]-$row[3];
       $ledgvl=$row[3]*$row[4];
       $actualvl=$row[3]*$row[5];
       $excsvl=$row[3]*$row[10];
       $shrtvl=$row[3]*$row[9];
	  if($mctr>25)
       {
         $mctr = 1;
         $new_page = 1;
       }

	 if($new_page==1)
       {
	$pagno++;
	


						$pdf->Cell(83,5,'Page  Total','LTRB',0, 'L');$pdf->Cell(20,5,$p_q1,'LTRB',0, 'R');$pdf->Cell(20,5,number_format($p_v1,2),'LTRB',0, 'R');
                                         $pdf->Cell(20,5,number_format($p_q2,2),'LTRB',0, 'R');$pdf->Cell(20,5,number_format($p_v2,2),'LTRB',0, 'R');$pdf->Cell(20,5,number_format($p_q3,2),'LTRB',0, 'R');
                                         $pdf->Cell(20,5,number_format($p_v3,2),'LTRB',0, 'R');$pdf->Cell(20,5,number_format($p_q4,2),'LTRB',0, 'R');$pdf->Cell(20,5,number_format($p_v4,2),'LTRB',0, 'R');$pdf->Cell(20,5,'','LTRB',0, 'R');
	

		
					$pdf->Ln(5);	
	
		$pdf->Cell(123,18,'Stock Verification Officer','LTR',0, 'L');$pdf->Cell(140,18,'Manager in charge','LTR',0, 'R');
	$pdf->Ln(9);	
	$pdf->Cell(123,9,'Dist Khadi and Village Industries','LRB',0, 'L');$pdf->Cell(140,9,$brnchnm,'LRB',0, 'R');
			$pdf->AddPage();						
			$pdf->SetFont('Arial','B',10);
			$pdf->SetFont('','B');
			$dedres1=mysqli_query($db,"select brname from branch where brcode='$brcode'") or die("er5:".mysqli_error($db));
			$br_1=mysqli_fetch_array($dedres1);
			$pdf->SetFont('','BU');
			$pdf->Cell(250,5,'KERALA KHADI & VILLAGE INDUSTRIES BOARD',0,1,'C');
			$pdf->SetFont('Arial','',11);
			$brnchnm=strtoupper($brnchnm);						
                     $pdf->Cell(250,5,'CENTER NAME :'.$brnchnm,0,1,'C');
                     //$pdf->Ln(4);
		 	//$pdf->Ln(4);
                     $pdf->Cell(250,5,'STOCK VERIFICATION STATEMENT AS ON '.$dto1,0,1,'C');$pdf->Cell(20,5,'Page '.$pagno,0,1,'C');
                     $pdf->SetFont('Arial','',10);
                     $pdf->Cell(13,10,'No.','LTR');$pdf->Cell(20,10,'Stock No.','LTR');$pdf->Cell(30,10,'Item Name','LTR');$pdf->Cell(20,10,'Rate','LTR');
                     $pdf->Cell(40,10,'Stock as per Ledger','LTR');$pdf->Cell(40,10,'Stock actually verified','LTR'); 
			$pdf->Cell(40,10,'Excess','LTR');$pdf->Cell(40,10,'Short','LTR');  $pdf->Cell(20,10,'Remarks','LTR');  
		$pdf->Ln(4);
                     $pdf->Ln(4);
			 $new_page = 0;
           $p_q1 =0;
           $p_v1 =0;
           $p_q2 =0;
           $p_v2 =0;
           $p_q3 =0;
           $p_v3 =0;
           $p_q4 =0;
           $p_v4 =0;

		}





       if(($row[4]==0)&&($row[5]==0))
       {    $a=0;
       }
       else
       {
		
       
			$pdf->Cell(13,5,$i++,'LTRB',0, 'R');$pdf->Cell(20,5,$row[1],'LTRB',0, 'L');$pdf->Cell(30,5,substr($row[2],0,12),'LTRB',0, 'L');$pdf->Cell(20,5,$row[3],'LTRB',0, 'R');$pdf->Cell(20,5,$row[4],'LTRB',0, 'R');
			$pr = $row[4]*$row[3];
$pdf->Cell(20,5,number_format($pr,2),'LTRB',0, 'R');$pdf->Cell(20,5,$row[5],'LTRB',0, 'R');
$pr = $row[5]*$row[3];
$pdf->Cell(20,5,number_format($pr,2),'LTRB',0, 'R');$pdf->Cell(20,5,$row[10],'LTRB',0, 'R');$pdf->Cell(20,5,$row[10]*$row[3],'LTRB',0, 'R');$pdf->Cell(20,5,$row[9],'LTRB',0, 'R');$pdf->Cell(20,5,$row[9]*$row[3],'LTRB',0, 'R');$pdf->Cell(20,5,$row[13],'LTRB',0, 'R');
		$pdf->Ln(5);				
	 $p_q1 +=$row[4];
       $p_v1 +=$row[4]*$row[3];
       $p_q2 +=$row[5];
       $p_v2 +=$row[5]*$row[3];
       $p_q3 +=$row[10];
       $p_v3 +=$row[10]*$row[3];
       $p_q4 +=$row[9];
       $p_v4 +=$row[9]*$row[3];

       $q1+=$row[4];
       $q2+=$row[5];
       $q3+=$row[10];
       $q4+=$row[9];
       $t1+=$row[4]*$row[3];
       $t2+=$row[5]*$row[3];
       $t3+=$row[10]*$row[3];
       $t4+=$row[9]*$row[3];



}









			
++$mctr;						
                                         //$pdf->Ln(4);
 }

				$pdf->Cell(83,5,'Page  Total','LTRB',0, 'L');$pdf->Cell(20,5,$p_q1,'LTRB',0, 'R');$pdf->Cell(20,5,number_format($p_v1,2),'LTRB',0, 'R');
                                         $pdf->Cell(20,5,number_format($p_q2,2),'LTRB',0, 'R');$pdf->Cell(20,5,number_format($p_v2,2),'LTRB',0, 'R');$pdf->Cell(20,5,number_format($p_q3,2),'LTRB',0, 'R');
                                         $pdf->Cell(20,5,number_format($p_v3,2),'LTRB',0, 'R');$pdf->Cell(20,5,number_format($p_q4,2),'LTRB',0, 'R');$pdf->Cell(20,5,number_format($p_v4,2),'LTRB',0, 'R');$pdf->Cell(20,5,'','LTRB',0, 'R');
	
$pdf->Ln(5);	
$pdf->Cell(83,5,'T O T A L','LTRB',0, 'L');$pdf->Cell(20,5,$q1,'LTRB',0, 'R');$pdf->Cell(20,5,$t1,'LTRB',0, 'R');
                                         $pdf->Cell(20,5,$q2,'LTRB',0, 'R');$pdf->Cell(20,5,$t2,'LTRB',0, 'R');$pdf->Cell(20,5,$q3,'LTRB',0, 'R');
                                         $pdf->Cell(20,5,$t3,'LTRB',0, 'R');$pdf->Cell(20,5,$q4,'LTRB',0, 'R');$pdf->Cell(20,5,$t4,'LTRB',0, 'R');$pdf->Cell(20,5,'','LTRB',0, 'R');
	$pdf->Ln(5);	
		
	$pdf->Cell(123,14,'Stock Verification Officer','LTR',0, 'L');$pdf->Cell(140,14,'Manager in charge','LTR',0, 'R');
	$pdf->Ln(7);	
	$pdf->Cell(123,9,'Dist Khadi and Village Industries','LRB',0, 'L');$pdf->Cell(140,9,$brnchnm,'LRB',0, 'R');
	$pdf->Ln(9);
	
                               
                        	
                        	//$pdf->Ln(4);
                           $pdf->Ln(4);
                           $pdf->Ln(4);
                      
				$pdf->Output();	
                                             
?>