<?php 
session_name('CAKEPHP'); session_start();
error_reporting(0);
//echo "<pre>";
$_REQUEST=$_SESSION['stock_print'];
//print_r($_REQUEST);
$PageSecurity = 3;
 include ('includes/session.inc');
 include ('includes/function_lib.php');
 include('includes/fun-php.php');
 include('includes/fun-HRClass.php');

$Compamies=DB_query("select * from companies",$db);
$CompamiesRow=DB_fetch_array($Compamies);
$sql1 = "SELECT * FROM companies where CompanyId='".$_SESSION['ACGCompanyId']."'";
  $sqlres = DB_query($sql1,$db);
  $companyRow = DB_fetch_array($sqlres);
  $s=new db_query(); 
 ?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">

<head>
  <meta http-equiv='Content-Type' content='text/html; charset=UTF-8' />
<title>Batch Wise Stock Summary Report</title>

<style type="text/css" media="print">
  @page port {size: portrait;}
@page land {size: landscape;}
 .portrait {page: port;}
.wrapper {page: land;}

</style>

<style type="text/css"> 
@page {size: portrait; margin:10px;}

@media print{
  *{box-sizing:border-box;}
body{ margin:0px; padding:0px;  font-size:12px; line-height: 18px; font-family: Arial, Helvetica, sans-serif; color:#000; font-weight:normal;}

h1,h2,h3,h4,h5,p{ margin:0px; padding:0px;}
p{ text-align:left;}

h1{
  font-size: 20px; line-height: 30px;
  font-weight:bold;
  text-transform: uppercase;
}
h2{
  font-size: 18px; line-height: 28px;
  font-weight:normal;
}
thead{display: table-header-group;}
.wrapper{width:99%; height: auto; float:left; border:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_first, .div_first .full{
  width: 100%; height: auto;
  /*border-bottom: #000000 1px solid;
  border-top: #000000 1px solid;*/
  /*border-left: #000000 1px solid;
  border-right: #000000 1px solid;*/
  float: left; position: relative;
}
 .div_first .left
  {
    width:16%; text-align:left; height:auto; vertical-align:middle; height:auto; padding: 1% 0; float:left;
  }
  .div_first .middle
  {
    width:68%; text-align:center; padding: 1% 0; margin:0 auto; float: left;
  }
  .div_first .right
  {
    width:16%; text-align:right; padding: 1% 0; float: left;
  }

.div_first .full{text-align: center; border: 0;}
.div_second, .div_third{
  width: 100%;
  height:auto;
  float: left;
}
.div_second table tr th, .div_second table tr td{border-right:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_second table tr th{text-align: left; border-top:#000000 1px solid;}
.div_second table tr th:last-child, .div_second table tr td:last-child{border-right:0;}
.div_second table tr:last-child td{border-bottom:0;}
.div_second table tr td > table tr td{border-right:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_second table tr td > table tr td:last-child{border-right:0;}
.div_second table tr td > table tr:last-child td{border-bottom:0;}

.div_third table tr th, .div_third table tr td{ border-bottom:#000 1px solid; border-right:#000 1px solid;}
.div_third table tr th{background-color:transparent; text-align: left;}
.div_third table tr th:last-child, .div_third table tr td:last-child{border-right:none;}
.div_third table tr:last-child td{border-bottom:none;}

.f12{ font-weight: bold; color:#000; font-size:12px;}
.f11{color:#000; font-size:12px; line-height:18px;}
.f14{color:#000; font-size:18px;}
.mt26{margin-top:4px; width:96%;}
.mt27{margin-top:0px; width:66%;}
.mt28{margin-top:0px; width:100%;}
.border_top{border-top:#000 1px solid;}
.border_bottom{border-bottom:#000 1px solid;}
.wdt1{width:8%;}
.wdt2{width:100px;}
.wdt3{width: 66px;}
.wdt4{width: 80px;}
.wdt5{width: 52px;}
.wdt6{width: 60px;}
}

@media screen{
/* CSS Document */
*{box-sizing:border-box;}
body{ margin:0px; padding:0px; background-color:#fff; font-size:12px; font-family: Arial, Helvetica, sans-serif; color:#000; font-weight:normal;}
h1,h2,h3,h4,h5,p{ margin:0px; padding:0px;}
p{ text-align:left;}

#foo{width:1070px; height: auto; margin:0px auto;}
.wrapper{width:1070px; height: auto; margin:10px auto; border-top:#000000 1px solid;}

h1{
  font-size: 24px; line-height: 30px;
  font-weight:bold;
  text-transform: uppercase;
}
h2{
  font-size: 18px; line-height: 28px;
  font-weight:normal;
}
.div_first, .div_first .full{
  width: 100%; height: auto;
  border-left: #000000 1px solid;
  border-right: #000000 1px solid;
  float: left; position: relative; display: table;
}
.div_first .full{text-align: center; border: 0; margin:10px 0 0;}
.div_first .left, .div_first .middle, .div_first .right{float: left; display: table-cell; vertical-align: middle;}
.div_first .left
{
  width:16%; text-align:center; height:auto; vertical-align:middle; padding: 1% 0; 
}
.div_first .middle
{
  width:68%; text-align:center; padding: 1% 0; position: relative; margin:0 auto;
}
.div_first .right
{
  width:16%; text-align:center; padding:1% 0; 
}
.div_second, .div_third, .div_forth{
  width: 100%; height: auto;
  border-top: #000000 1px solid;
  border-left: #000000 1px solid;
  border-right: #000000 1px solid;
  float: left;
}
.div_second table tr th, .div_second table tr td{border-right:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_second table tr th{background-color: #ccc; text-align: left;}
.div_second table tr th:last-child, .div_second table tr td:last-child{border-right:0;}
/*.div_second table tr:last-child td{border-bottom:0;}*/
.div_second table tr td > table tr td{border-right:#000000 1px solid; border-bottom:#000000 1px solid;}
.div_second table tr td > table tr td:last-child{border-right:0;}
.div_second table tr td > table tr:last-child td{border-bottom:0;}

.div_third table tr th, .div_third table tr td{ border-bottom:#000 1px solid; border-right:#000 1px solid;}
.div_third table tr th{background-color: #ccc; text-align: left;}
.div_third table tr th:last-child, .div_third table tr td:last-child{border-right:none;}
/*.div_third table tr:last-child td{border-bottom:none;}*/

.f12{font-weight: bold; color:#000; font-size:12px;}
.f11{ color:#000; font-size:12px; line-height:18px;}
.f14{ color:#000; font-size:18px;}
.mt26{margin-top:4px; width:96%;}
.mt27{margin-top:4px; width:56%;}
.mt28{margin-top:0px; width:90%;}
.border_top{border-top:#000 1px solid;}
.border_bottom{border-bottom:#000 1px solid;}
.wdt1{width:10%;}
.wdt2{width:180px;}
.wdt3{width: 66px;}
.wdt4{width: 120px;}
.wdt5{width: 52px;}
.wdt6{width: 70px;}
}
</style>

</head>
<body>
<div id="foo">
  <p style="text-align:right;"><input type="button" onclick="javascript:toggle_visibility('foo');" value="Print" /></p>
</div>

<div class="wrapper">

<?php 
$sql1 = "SELECT * FROM companies where CompanyId='".$_SESSION['ACGCompanyId']."'";
$sqlres = DB_query($sql1,$db);
$companyRow = DB_fetch_array($sqlres);

$branch=$s->getField('locations','loccode',$_REQUEST['site'],'locationname');
$store=$s->getField('storetype','id',$_SESSION['store'],'StoreName');

error_reporting(0);
?> 

<?php 
   $sql1 = "SELECT * FROM companies where CompanyId='".$_SESSION['ACGCompanyId']."'";
  $sqlres = DB_query($sql1,$db);
  $companyRow = DB_fetch_array($sqlres);

  $arr=array(1=>"Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec");
  
// order Details

  $companylogo=$companyRow['CompanyLogo'];
  
   $sql_branch = "SELECT * FROM locations where loccode='".$_REQUEST['site']."'";
   $sqlres_branch = DB_query($sql_branch,$db);
   $branchRow = DB_fetch_array($sqlres_branch);

   $city_name=$s->GetFieldValue('city_master',"id='".$branchRow['city']."'",'city');
?>
  <!-- <div class="div_first">
    <?php $logoImage=($CompamiesRow['CompanyLogo']=='')?'Final_Logo_RM.png':$CompamiesRow['CompanyLogo']; ?>
        <div class="left"><img src="Setup/CompanyLogo/<?php echo $logoImage;  ?>" class="mt26" /></div>
        <div class="middle"><?php 
      if($CompamiesRow['CompanyName']!="") {echo "<h1>".$CompamiesRow['CompanyName']."</h1>"; } else { echo "";}
      
      if($InoRow['deladd1']!="") { echo $InoRow['deladd1']; } else { echo "";}
      if($InoRow['deladd2']!="") { echo ", ". $InoRow['deladd2']; } else { echo "";}
      if($InoRow['deladd3']!="") { echo ", ". $InoRow['deladd3']; } else { echo "";}
      if($InoRow['city']!="") { echo ", ". $s->getFieldValue("city_master", "id='".$InoRow['city']."'", "city"); } else { echo "";}
      if($InoRow['pincode']!="") { echo " - ".$InoRow['pincode']; } else { echo "";}
      if($InoRow['state']!="") { echo ", ". $s->getFieldValue("state_master", "id='".$InoRow['state']."'", "state"); } else { echo "";}
      if($InoRow['country']!="") { echo ", ". $s->getFieldValue("country_master", "id='".$InoRow['country']."'", "country");
      
       } else { echo "";}
      ?>
       <div class="full"><span class="f11"><?php echo "Phone No.:".$CompamiesRow['Phone'].",   Fax No.: ".$CompamiesRow['fax'].", Email ID.: ".$CompamiesRow['email'].",   Website: ".$CompamiesRow['website']; ?><br>
    <?php  echo $_SESSION['mess']; ?>
    </span></div>
         <h2>Batch Wise Stock Summary Report</h2>
        </div>
        <div class="right"></div>
  </div> -->
  <div class="div_first">
      <div class="left"><img src="images/ssmh-logo.jpeg" class="mt26" /></div>
      <div class="middle"><h1>Shekhar Sharraf Memorial Hospital</h1>
        <div class="f14">RUSA Medical Centre (Aligarh)</div>
        <div class="f12">6Km. Milestone, Agra Road, Aligarh - 202001, U.P. (India)</div>
        <div class="f12">Email : info@rusamedicalcentre.com</div>
        <div class="full"><h2>Batch Wise Stock Summary Report</h2></div>
      </div>
      <div class="right"><img src="images/rusa-logo.jpeg" vspace="10" class="mt27" /></div>
  </div>

<div class="div_second">
  <table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr>
    <th class="f12">S. No.</th>
    <th class="f12">Batch</th>
    <th class="f12">Date of Mfg</th>
    <th class="f12">Date of Expiry</th>
    <th class="f12">Unit</th>   
    <th class="f12">Opening Quantity</th>
    <th class="f12">Received Quantity</th>
    <th class="f12">Issue Quantity</th>  
    <th class="f12">Closing Balance</th>
  </tr>
 <!-- <tr bgcolor="#CCCCCC">
    <td align="center" style="text-align:center;">Primary QTY.</td>
    <td align="center" style="text-align:center;">Secondary QTY.</td>
    <td align="center" style="text-align:center;">Primary QTY.</td>
    <td align="center" style="text-align:center;">Secondary QTY.</td>
    <td align="center" style="text-align:center;">Primary QTY.</td>
    <td align="center" style="text-align:center;">Secondary QTY.</td>
    <td colspan="2" align="center" style="text-align:center;">Plus</td>
    <td colspan="2" align="center" style="text-align:center;">Minus</td>
    <td align="center" style="text-align:center;">Primary QTY. </td>
    <td align="center" style="text-align:center;">Secondary QTY.</td>
  </tr>-->
  <?php 

$subQuery=$_SESSION['subQuery'];
 $filter6=$_SESSION['filter6'];
 $sql1=$_SESSION['sql1'];
   //$sql1="select * from item_master where 1=1 ".$subQuery." order by CategoryID,SubCategoryID,item_name ASC ";
 
 //echo  $sql1="select * from item_master where  ".$filter4."   ";

//echo  $sql1="select * from item_master where  ".$filter4." ";
   $result1=DB_query($sql1,$db);
    
  while($row1=DB_fetch_array($result1))
  {    
      
        // array($row1['id']=>'item_id');
         $sql2="select * from stock_valuation_tbl  where mst_itemid= ".$row1['id']." and ".$filter6."";
          // $_SESSION['sql2']= $sql2;

             $result2=DB_query($sql2,$db);
             if(DB_num_rows($result2)>0)
             {
               $itemarray[]=$row1['id'];

              while($row2=DB_fetch_array($result2))
             {
                              $optype='';$Receivedqty='';$issueqty='';$closing='';
                        
                        $optype=$s->GetFieldValue("stock_valuation_tbl","mst_itemid= ".$row1['id']." and batch_no='".$row2['batch_no']."' 
                          and ".$filter6." and type='OP'","sum(inwardqty_primary)");
                         $Receivedqty=$s->GetFieldValue("stock_valuation_tbl","mst_itemid= ".$row1['id']." and batch_no='".$row2['batch_no']."' 
                          and ".$filter6." and type!='OP'","sum(inwardqty_primary)");
                         $issueqty=$s->GetFieldValue("stock_valuation_tbl","mst_itemid= ".$row1['id']." and batch_no='".$row2['batch_no']."' 
                          and ".$filter6." ","sum(outwardqty_primary)");
                    //$type=$row2['type'];
                      //if($row2['type']=='OP') { $optype=$row2['inwardqty_primary']; }
                      //else {    $optype= "0";   }
                    
                      $batch=$row2['batch_no'];
                      $mid=$row2['primary_unit'];

                                        $closing=($optype+$Receivedqty)-$issueqty;                 
                                if($batch!='')
                  $batch_item_array[$row1['id']][$batch]=array("OP"=>$optype,"recieve"=>$Receivedqty,"issue"=>$issueqty,"unit"=>$mid,"closing"=>$closing,"mdate"=>$row2['date_of_mfg'],"edate"=>$row2['date_of_expiry']);
                  //array('op'=>$optype,'recieve'=>$Receivedqty,$issueqty=>'issue',$closing=>'closing');
                
             }
              }  
             }
            // echo "<pre>";
          //print_r($batch_item_array);

              ?>
                
              <?php foreach ($itemarray as $key => $value)   {   ?>                
   
      <?php    
//echo "<pre>"; 
  //print_r($itemarray); 
    $t='1'; 
    $total='';
          foreach($batch_item_array[$value] as $key1=>$value1)
           {   
               if($_REQUEST['type']=='W' || $_REQUEST['type']=='0')     
               {    
               $total=$total+$value1['closing'];      
            ?>
              <?php if($item1!=$value) { ?>
                  <tr>
                  <td></td>                   
                  <td colspan="8" class="f11"> <?php echo $s->getField('item_master','id',$value,'item_name');  ?></td>
                     </tr>   
              <?php $item1=$value; } ?>      
              <tr>        
              <td class="f11"><?php echo $t;  ?></td>
              <td width="30%" class="f11"><?php echo $key1;  ?></td>
              <td class="f11"><?php  echo date('d/m/Y',strtotime($value1['mdate']));?></td>
              <td class="f11"><?php  echo date('d/m/Y',strtotime($value1['edate']));?></td>
              <td class="f11"><?php echo $s->getField('unitsofmeasure','unitid',$value1['unit'],'unitname');?></td>
              <td style="text-align:right;" class="f11"><?php echo $value1['OP'];  ?></td>                  
              <td style="text-align:right;" class="f11"><?php echo $value1['recieve'];  ?></td>
              <td style="text-align:right;" class="f11"><?php echo $value1['issue'];  ?></td>  
              <td style="text-align:right;" class="f11"><?php  $c=$value1['closing']; echo number_format((float)$c, 2, '.', '');    ?></td>
              </tr>
    
      <?php  }
       else  if($_REQUEST['type']=='Z' && $value1['closing']<='0' )  { ?>
        <?php if($item1!=$value) { ?>
                <tr>
                <td></td>                 
                <td colspan="7"> <?php echo $s->getField('item_master','id',$value,'item_name');  ?></td>
                   </tr>   
            <?php $item1=$value; } ?> 
                      <tr>        
              <td class="f11"><?php echo $t;  ?></td>
              <td width="30%" class="f11"><?php echo $key1;  ?></td>
              <td class="f11" ><?php  echo date('d/m/Y',strtotime($value1['mdate']));?></td>
              <td class="f11"><?php  echo date('d/m/Y',strtotime($value1['edate']));?></td>
              <td class="f11"><?php echo $s->getField('unitsofmeasure','unitid',$value1['unit'],'unitname');?></td>
              <td style="text-align:right;" class="f11"><?php echo $value1['OP'];  ?></td>                  
              <td style="text-align:right;"class="f11"><?php echo $value1['recieve'];  ?></td>
              <td style="text-align:right;"class="f11"><?php echo $value1['issue'];  ?></td>  
              <td style="text-align:right;"class="f11"><?php echo $value1['closing'];   ?></td>
              </tr>
      <?php  } $t++;    }            ?> 
      <?php if($total>'0') { ?>

      <tr><td colspan="9" style="text-align:right;"class="f12">Total=<?php echo  number_format((float)$total, 2, '.', '');  ?></td></tr>
        <?php  } } ?>
    </table>
</div>
</div>

<script type="text/javascript">
  function checkdate(date)
{
  var from =document.getElementById('from').value;
  var to =document.getElementById('to').value;
  
    var cdate=date.split("/");
    var sdate=from.split("/");
    var edate=to.split("/");

    cdate[1]=cdate[1]-1;
    sdate[1]=sdate[1]-1;
    edate[1]=edate[1]-1;
       
    var dateC = new Date(cdate[2], cdate[1], cdate[0]); //Year, Month, Date 
    var dateS = new Date(sdate[2], sdate[1], sdate[0]); //Year, Month, Date
      var dateE = new Date(edate[2], edate[1], edate[0]); //Year, Month, Date

      if (dateS > dateE) {
          alert("Start Date is not greather then Date End.");
          document.getElementById('fromdate').value=from;
          document.getElementById('todate').value=to;
          
      }

      if (dateC > dateE) {
          alert("Date Not greather than "+to);
         document.getElementById('fromdate').value=from;
          document.getElementById('todate').value=to;
         
      }

      if (dateC < dateS) {
          alert(" Date Not less than "+from);
          document.getElementById('fromdate').value=from;
          document.getElementById('todate').value=to;
         
      } 
  
  
}

</script>

<script type="text/javascript">
function showItems(str)
{
   $.post("Get_itemcode.php",{"partName":str},function(data){
  document.getElementById("itemid").innerHTML=data;
});
}
function showsitename160(str)
{

var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
  var data=xmlhttp.responseText.split("__");  
  document.getElementById("storedata7").innerHTML=data[0];
    }
  }
  xmlhttp.open("GET","get_sitenamedata3.php?site="+str,true);
  xmlhttp.send();

//xmlhttp.open("GET","getSort.php?s="+str+"&cat="+cat,true);

  
}


function showsubcat(str)
{
var xmlhttp;
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
  var data=xmlhttp.responseText.split("__");  
  document.getElementById("subcatdata").innerHTML=data[0];
  document.getElementById("itemid").innerHTML=data[1];
    }
  }
  xmlhttp.open("GET","get_sitenamedatasubcat.php?site="+str,true);
  xmlhttp.send();




}

function showdata(str)
{
 if(str=="")
  {
  document.getElementById("itemid").innerHTML="";
  return;
  }
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
    document.getElementById("itemid").innerHTML=xmlhttp.responseText;
    }
  }
  var cat=document.getElementById("maincat").value;
xmlhttp.open("GET","Get_itemcode1.php?partName="+str+"&main="+cat,true);
xmlhttp.send();

}


</script>

<script type="text/javascript" language="javascript">
  function toggle_visibility(id) 
  {
    var e = document.getElementById(id);
  e.style.display = 'none';
  window.print();
  }
</script> 
</body>
</html>


 