<?
include_once('includes/top.php');
include_once('opendb.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');
$verdt=$_REQUEST['verdt'];
$dto1=implode("-",array_reverse(explode("-",$verdt)));
$brres=mysqli_query($db,"select * from branch where brcode='$brcode'");
$brrow=mysqli_fetch_array($brres);
?>
<script type="text/javascript" src="number_to_word.js"></script>
<body bgcolor="#0033FF">
<?php //include('includes/top.php'); ?>
<center>
<table>
<TR><TD COLSPAN=2 ALIGN=CENTER><font color='white'><b>   </b></font><BR>
<font color='white'  > <br><u> </u>
</font>
</td></tr>
</TABLE>
<font> <? print "<B>STOCK VERIFICATION STATEMENT AS ON ".$dto1."</B>";?></font>
<link rel="stylesheet" href="style.css" type="text/css" />
<link type="text/css" href="includes/style1.css" rel="stylesheet" />
<link type="text/css" href="css/form.css" rel="stylesheet" />
<style type="text/css">
tr.top td { border-top: thin solid black; }
tr.bottom td { border-bottom: thin solid black; }
tr.row td:first-child { border-left: thin solid black; }
tr.row td:last-child { border-right: thin solid black; }
</style>
<center>
<?

$re=mysqli_query($db,"select gname,sum(ledqty*sellprice),sum(curstk*sellprice),sum(stock_short*sellprice),sum(stock_excess*sellprice),count(itemcode) from stockverification where stockverifydt='$verdt' and brcode='$brcode' group by gname");
$brres=mysqli_query($db,"select * from branch where brcode='$brcode'");
$brrow=mysqli_fetch_array($brres);
$brnchnm= $brrow[1];

$file =  'stock_ver_abs.prn';
$handle = fopen($file, 'w');
$dss=chr(27).chr(71).chr(N);
$dse=chr(27).chr(72);
$initialized = chr(27).chr(64);
$load = chr(27).chr(25).chr(66);
$bold = chr(27).chr(14);
$unbold = chr(20);
$pagelenth=chr(27).chr(67).chr(36);
$Data = $initialized;
$Data = "\n\n\n";
$Data .= "                           KERALA KHADI & VILLAGE INDUSTRIES BOARD  \n";
$Data .= "                           CENTER NAME : ".$brnchnm." \n";
$Data .= "                           STOCK VERIFICATION AS ON $dto1 \n";
$Data .= "                                 ABSTRACT  \n";
$Data .= chr(15);
$Data.= "  |------------------------|------------------------|---------------------------|----------------------|----------------------|---------------|\n";
$Data.= "  |         Item           |  Stock as per Ledger   |  Stock Actually Verified  |        Excess        |         Short        |    Remarks    |\n";
$Data.= "  |------------------------|------------------------|---------------------------|----------------------|----------------------|---------------|\n";
$i=1;
$tot_led = 0;
$tot_act = 0;
$tot_exc = 0;
$tot_sho = 0;
$ctr_khadi = 1;
$ctr_vip = 1;
$mstr_vip[]="";
$mstr_khadi[]="";
$mkhadi_tot_1 = 0;
$mkhadi_tot_2 = 0;
$mkhadi_tot_3 = 0;
$mkhadi_tot_4 = 0;
$mvip_tot_1 = 0;
$mvip_tot_2 = 0;
$mvip_tot_3 = 0;
$mvip_tot_4 = 0;
$mctr=1;

while($row=mysqli_fetch_array($re))
{
       $mtot_pages = ceil($row[5]/25);
       if(strpos($row[0], "VIP")>0)
       {
          $mstr_vip[$ctr_vip] .= "  |".substr($row[0]."(".$mtot_pages."PAGES)".str_repeat(" ",24),0,24);
          $mstr_vip[$ctr_vip] .= "|".substr(str_repeat(" ",24).number_format($row[1],2),-24);
          $mstr_vip[$ctr_vip] .= "|".substr(str_repeat(" ",27).number_format($row[2],2),-27);
          $mstr_vip[$ctr_vip] .= "|".substr(str_repeat(" ",22).number_format($row[4],2),-22);
          $mstr_vip[$ctr_vip] .= "|".substr(str_repeat(" ",22).number_format($row[3],2),-22);
          $mstr_vip[$ctr_vip] .= "|".substr(str_repeat(" ",8)."" ,-8)."|               |\n";
          $ctr_vip++;
          $mvip_tot_1 += $row[1];
          $mvip_tot_2 += $row[2];
          $mvip_tot_3 += $row[4];
          $mvip_tot_4 += $row[3];
        }
        else
        {
            $mstr_khadi[$ctr_khadi] .= "  |".substr($row[0]."(".$mtot_pages."PAGES)".str_repeat(" ",24),0,24);
            $mstr_khadi[$ctr_khadi] .= "|".substr(str_repeat(" ",24).number_format($row[1],2),-24);
            $mstr_khadi[$ctr_khadi] .= "|".substr(str_repeat(" ",27).number_format($row[2],2),-27);
            $mstr_khadi[$ctr_khadi] .= "|".substr(str_repeat(" ",22).number_format($row[4],2),-22);
            $mstr_khadi[$ctr_khadi] .= "|".substr(str_repeat(" ",22).number_format($row[3],2),-22);
            $mstr_khadi[$ctr_khadi] .= "|               |\n";
            $ctr_khadi++;
            $mkhadi_tot_1 += $row[1];
            $mkhadi_tot_2 += $row[2];
            $mkhadi_tot_3 += $row[4];
            $mkhadi_tot_4 += $row[3];
        }
        $tot_led += $row[1];
        $tot_act += $row[2];
        $tot_exc += $row[4];
        $tot_sho += $row[3];
}
for ($ctr=1;$ctr<$ctr_khadi;$ctr++)
{
      $Data .= $mstr_khadi[$ctr];
}
$Data.= "  |------------------------|------------------------|---------------------------|----------------------|----------------------|---------------|\n";
$pr = $row[4]*$row[3];
$Data .= "  |   KHADI TOTAL     ";
$Data .= "|".substr(str_repeat(" ",24).number_format($mkhadi_tot_1,2),-24);
$Data .= "|".substr(str_repeat(" ",27).number_format($mkhadi_tot_2,2),-27);
$Data .= "|".substr(str_repeat(" ",22).number_format($mkhadi_tot_3,2),-22);
$Data .= "|".substr(str_repeat(" ",22).number_format($mkhadi_tot_4,2),-22);
$Data .= "|               |\n";
$Data.= "  |------------------------|------------------------|---------------------------|----------------------|----------------------|---------------|\n";
for ($ctr=1;$ctr<$ctr_vip;$ctr++)
{
      $Data .= $mstr_vip[$ctr];
}
$new_page = 0;
++$mctr;
$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];
$Data.= "  |------------------------|------------------------|---------------------------|----------------------|----------------------|---------------|\n";
$Data.= "  |   VIP T O T A L   ";
$Data .= "|".substr(str_repeat(" ",24).number_format($mkhadi_tot_1,2),-24);
$Data .= "|".substr(str_repeat(" ",27).number_format($mkhadi_tot_2,2),-27);
$Data .= "|".substr(str_repeat(" ",22).number_format($mkhadi_tot_3,2),-22);
$Data .= "|".substr(str_repeat(" ",22).number_format($mkhadi_tot_4,2),-22);

$Data .= "|               |\n";
$Data.= "  |------------------------|------------------------|---------------------------|----------------------|----------------------|---------------|\n";
$Data.= "  |  GRAND T O T A L  ";
$Data .= "|".substr(str_repeat(" ",24).number_format($mkhadi_tot_1+$mvip_tot_1,2),-24);
$Data .= "|".substr(str_repeat(" ",27).number_format($mkhadi_tot_2+$mvip_tot_2,2),-27);
$Data .= "|".substr(str_repeat(" ",22).number_format($mkhadi_tot_3+$mvip_tot_3,2),-22);
$Data .= "|".substr(str_repeat(" ",22).number_format($mkhadi_tot_4+$mvip_tot_4,2),-22);
$Data .= "|               |\n";
$Data.= "  |--------------------------------------------------------------------------------------------------------------------------------------|\n";
$Data.= "  | Certified that the stock as per the stock list of                      Certified that the stock as per the stock list of             |\n";
$Data.= "  | $brrow[1]                                                              $brrow[1]                                     |\n";
$Data.= "  | has been physically verified in my presence and the                    has been physically verified in my presence and the           |\n";
$Data.= "  | rate, quantity and value noted against each item is correct.           rate, quantity and value noted against each item is correct.  |\n";
$Data.= "  |--------------------------------------------------------------------------------------------------------------------------------------|\n";
$Data.= "  |                                                                                                                                      |\n";
$Data.= "  |                                                                                                                                      |\n";
$Data.= "  | Stock Verification Officer                                             Manager in charge                                             |\n";
$Data.= "  | Dist Khadi and Village Industries                                      $brrow[1]                                             |\n";
$Data.= "  |--------------------------------------------------------------------------------------------------------------------------------------|\n";
$Data .= "\n";
$Data .= chr(18);
$Data .= chr(12);
fwrite($handle, $Data);
fclose($handle);
$output = shell_exec("lp -o media=Custom.10x6in '$file'");
$output=shell_exec("C:\\WINDOWS\\system32\\cmd.exe /c stock_ver_abs.bat");
?>
