<?php

$PageSecurity = 3;
error_reporting(0); 
  
setlocale(LC_MONETARY, 'en_IN');    //For Indian Currency Format

include('includes/SQL_CommonFunctions.inc');
include('includes/session.inc');
include('includes/function_lib.php');

$id=$_REQUEST['id'];
 
$editres=DB_fetch_array(DB_query("select * from addissue where id='".$_REQUEST['id']."' ",$db));

$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();
//echo $id;
//echo '<link href="'.$rootpath. '/css/'. $_SESSION['Theme'] .'/default.css" rel="stylesheet" type="text/css" />';
?>

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

<!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>Issue Sheet 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; 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;}

h1{
  font-size: 20px; line-height: 30px;
  font-weight:bold;
  text-transform: uppercase;
}
h2{
  font-size: 18px; line-height: 28px;
  font-weight:normal;
}
.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;
  float: left;
}
.div_first .full{text-align: center; border:0;}
 .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_second, .div_third, .div_forth{
  width: 100%;
  height:auto;
  border-top: #000000 1px solid;
  float: left;
}
.div_second table tr th, .div_second table tr td{border-right:#000000 0px solid; border-bottom:#000000 1px solid;}
.div_second table tr th{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: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;}

.div_forth table tr th, .div_forth table tr td{ border-bottom:#000 1px solid; border-right:#000 0px solid;}
.div_forth table tr th{background-color: #ccc; text-align: left;}
.div_forth table tr th:last-child, .div_forth table tr td:last-child{border-right:none;}
/*.div_forth 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: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 0px 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;}

.div_forth table tr th, .div_forth table tr td{ border-bottom:#000 1px solid; border-right:#000 0px solid;}
.div_forth table tr th{background-color: #ccc; text-align: left;}
.div_forth table tr th:last-child, .div_forth table tr td:last-child{border-right:none;}
/*.div_forth 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>

<?php 
 
function number_to_words($no)
{
    $string   = null;
    $fraction   = null;
    $decimal    = ' point ';
    $words = array('0'=> '' ,
      '1'=> 'one' ,
      '2'=> 'two' ,
      '3' => 'three',
      '4' => 'four',
      '5' => 'five',
      '6' => 'six',
      '7' => 'seven',
      '8' => 'eight',
      '9' => 'nine',
      '10' => 'ten',
      '11' => 'eleven',
      '12' => 'twelve',
      '13' => 'thirteen',
      '14' => 'fouteen',
      '15' => 'fifteen',
      '16' => 'sixteen',
      '17' => 'seventeen',
      '18' => 'eighteen',
      '19' => 'nineteen',
      '20' => 'twenty',
      '30' => 'thirty',
      '40' => 'fourty',
      '50' => 'fifty',
      '60' => 'sixty',
      '70' => 'seventy',
      '80' => 'eighty',
      '90' => 'ninty',
      '100' => 'hundred AND ',
      '1000' => 'thousand',
      '100000' => 'lakh',
      '10000000' => 'crore');
    if($no == 0)
      return ' ';
    else {
      if (strpos($no, '.') !== false) {
          list($no, $fraction) = explode('.', $no);
      }

      $novalue='';
      $highno=$no;
      $remainno=0;
      $value=100;
      $value1=1000;
      
      while($no>=100) {
        if(($value <= $no) && ($no < $value1)) {
          $novalue=$words["$value"];
          $highno = (int)($no/$value);
          $remainno = $no % $value;
          break;
        }
        $value= $value1;
        $value1 = $value * 100;
      }

      if (null !== $fraction && is_numeric($fraction) && $fraction!=0) {
          $string = $decimal;
          $words1 = array();
          foreach (str_split((string) $fraction) as $number) {
              $words1[] = $words[$number];
          }
          $string .= implode(' ', $words1);
      }
      
      if(array_key_exists("$highno",$words))
      {
        return $words["$highno"]." ".$novalue." ".number_to_words($remainno).$string;
      }else {
        $unit=$highno%10;
        $ten =(int)($highno/10)*10;
        return $words["$ten"]." ".$words["$unit"]." ".$novalue." ".number_to_words($remainno).$string;
      }
    }
  }
  
 
  function getRate($qty,$total,$basicamt,$totalexcise,$rate)
  {
   // echo $qty." <br/> ".$total." <br/> ".$basicamt." <br/>".$totalexcise."<br/> ".$rate;
    //echo "<br/>";
    $x= round(($totalexcise * $total/$basicamt),2);
    $y=round(($x/$qty),2);
    return $z=round(($y+$rate),2);
    //return $rate;

  }


?>



<div class="wrapper">
  <!-- <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>TEST 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>TEST 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>
    <td width="9%" class="f12">Branch</td>
    <td width="28%" class="f11">: <?php echo $s->getField('locations','loccode',$editres['site'],'locationname');?></td>
    <td width="13%" class="f12">Store</td>
    <td width="20%" class="f11">: <?php echo $godown=$s->getField('storetype','id',$editres['mst_storeid'],'StoreName'); ?></td>
    <td width="9%" class="f12">Issue No. </td>
    <td class="f11 brdr_btm">: <?php  echo $editres['issue_slipno'];  ?></td>
  </tr>
  <tr>
    <td class="f12">Issue Date</td>
    <td class="f11">: <?php echo date('d/m/Y',strtotime($editres['issuedate']))?></td>
    <td class="f12">To Store</td>
    <td class="f11">: <?php echo $s->getField('storetype','id',$editres['to_store'],'StoreName');?></td>
    <td class="f12" colspan="2">&nbsp;</td>    
  </tr>  
</table>
    </div>
<?php 
    $sql=DB_query("Select * from issueqty where issue_id=".$editres['id']."",$db);?>
<div class="div_third">
      <table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr>
    <th width="5%" align="center" class="f12">S.No.</th>
    <th width="10%" align="center" class="f12">Item Code</th>
    <th align="center" class="f12">Item Name</th>
    <th width="10%" align="center" class="f12">Batch</th>
    <!-- <th width="10%" align="center" class="f12">Stock</th> -->
    <th style="text-align:center;" colspan="4" class="f12">Qty to be issued</th>
    </tr>
  <?php $i=1;
while($row=DB_fetch_array($sql)){
    extract($row);
   
   
    $unit=$s->getField('item_master','id',$row['mst_itemid'],'mst_unitid');
	//$conunit=$s->getField('item_master','id',$row['conv_unitid'],'mst_unitid');

	//echo $row['conv_unitid']."<br>";
	//echo $conunit;

	$priUOM=$s->getField('unitsofmeasure','unitid',$unit,'unitname'); //Primary Unit
	 
   $sec_unit_id=$s->getField('item_master','id',$row['mst_itemid'],'conv_unit');
  $secondUOM=$s->getField('unitsofmeasure','unitid',$sec_unit_id,'unitname');



	 $query = "SELECT sum(inwardqty_primary) as inwardqty_primary,sum(outwardqty_primary) as outwardqty_primary,date_of_mfg,date_of_expiry,batch_no
   FROM `stock_valuation_tbl` where mst_itemid = '".$row['mst_itemid']."' and site='".$editres['site']."' and store='".$editres['mst_storeid']."' and batch_no='".$row['batch_no']."' group by batch_no";
 // echo $query;
  $sql1 = DB_query($query,$db); 
  //$i=1;
  if(DB_num_rows($sql1)>0)
  {
    while($myrow=DB_fetch_array($sql1))
    {
     
      $qty=$myrow['inwardqty_primary'] - $myrow['outwardqty_primary'];
    }
  }
    
?>
  <tr>
    <td class="f11"><?php echo $i; ?>&nbsp;</td>
    <td class="f11"><?php echo $s->getField('item_master','id',$row['mst_itemid'],'StockID'); ?>&nbsp;</td>
    <td class="f11"><?php echo $s->getField('item_master','id',$row['mst_itemid'],'item_name');?></td>
    <td class="f11"><?php echo $row['batch_no'];?>&nbsp;</td>
    <!-- <td align="right" class="f11"><?php //echo $qty;?>&nbsp;</td> -->
    <td width="10%" align="right" class="f11"><?php echo $row['issueqty']; ?></td>
    <td width="5%" class="f11"><?php echo $priUOM;?></td>
    <td width="10%" align="right" class="f11"><?php echo $row['stock_qty2'];?></td>
    <td width="5%" class="f11"><?php echo $secondUOM; ?></td>
    </tr>
  <?php $i++; } ?>   
    </table>
  </div>
<div class="div_forth">
  <table width="100%" border="0" cellspacing="0" cellpadding="3">

  <tr>
    <td width="50%" height="80" valign="bottom"><span class="f11"><?php echo $editres['material_received_by']; ?></span><br><span class="f12">Material Recieved By</span></td>
    <td align="right" valign="bottom"><span class="f11"><?php echo $s->getField('www_users','id',$editres['material_issue_by'],'realname');?></span><br><span class="f12">Material Issued By</span></td>
    </tr>        
  <tr>
    <td colspan="2" class="f12" align="center">
    Head Office : <?php echo $data['Address1']." , ".$data['Address2']." , ".$data['City']." , ".$data['State']." , ".$data['Country']." - ".$data['Zipcode']." , Phone - ".$data['Phone']." , Fax-".$data['fax'].", Email-".$data['email']; ?></td>
    </tr>
  </table>
</div>

</div>

</body>
</html>