<?php
//ob_start();
session_name('CAKEPHP'); session_start();
$PageSecurity = 1;
include('config.php');
include('includes/ConnectDB.inc');
include('includes/function_lib.php');
include('includes/LanguageSetup.php');
include('includes/DateFunctions.inc');
include('includes/stockcalculation.php');
$com_name=DB_fetch_assoc(DB_query("SELECT * FROM companies where CompanyId='".$_SESSION['ACGCompanyId']."'",$db));
$resultreceived=DB_query("select * from transfer_receipt where id='".$_REQUEST['id']."'",$db);
      $row=DB_fetch_array($resultreceived);

      $function_filter[0]=$row['site'];
    $function_filter[1]=$row['store_to'];
    $function_filter[2]=date('Y-m-d');

$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>Site to Site Transfer Receive</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"> 
@print {size: portrait; margin:10px;}

@media print{
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: 24px;
  font-weight:normal;
  font-family:Arial, Helvetica, sans-serif !important;
}
h2{
  font-size: 18px; line-height: 22px;
  font-weight:normal;
  font-family:Arial, Helvetica, sans-serif !important;
}
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:18%; text-align:left; height:auto; vertical-align:middle; height:auto; padding: 1%; float:left;
  }
  .div_first .middle
  {
    width:58%; text-align:center; padding: 1%; margin:0 auto; float: left;
  }
  .div_first .right
  {
    width:18%; text-align:right; padding: 1%; float: left;
  }

.div_first .full{text-align: center; border: 0;}
.div_second, .div_third, .div_forth, .div_fifth{
  width: 100%;
  height:auto;
  border-top: #000000 1px solid;
  /*border-bottom: #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{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 0px 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 1px solid;}
.div_forth table tr th{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;}

.div_fifth table tr th, .div_fifth table tr td{ border-bottom:#000 1px solid; border-right:#000 1px solid;}
.div_fifth table tr th:last-child, .div_fifth table tr td:last-child{border-right:none;}


.f12{ font-weight: bold; color:#000; font-size:12px;}
.f11{color:#000; font-size:12px; font-weight: normal; line-height:18px;}
.f14{color:#000; font-size:18px;}
.mt26{margin-top:4px; width:90%;}
.mt27{margin-top:0px; width:62%;}
.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 */
body{ margin:0px; padding:0px; background-color:#fff; 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;}

#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: 28px;
  font-weight:bold;
  font-family:Arial, Helvetica, sans-serif !important;
}
h2{
  font-size: 18px; line-height: 22px;
  font-weight:normal;
  font-family:Arial, Helvetica, sans-serif !important;  
}
.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; 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:18%; text-align:center; height:auto; vertical-align:middle; padding: 1%; 
}
.div_first .middle
{
  width:58%; text-align:center; padding: 1%; position: relative; margin:0 auto;
}
.div_first .right
{
  width:18%; text-align:center; padding:1%; 
}
.div_second, .div_third, .div_forth, .div_fifth{
  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;
}

.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 0px 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 1px 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;}

.div_fifth table tr th, .div_fifth table tr td{ border-bottom:#000 1px solid; border-right:#000 1px solid;}
.div_fifth table tr th:last-child, .div_fifth table tr td:last-child{border-right:none;}

.f12{font-weight: bold; color:#000; font-size:12px;}
.f11{ color:#000; font-size:12px; font-weight: normal; line-height:18px;}
.f14{ color:#000; font-size:18px;}
.mt26{margin-top:4px; width:90%;}
.mt27{margin-top:0px; width:52%;}
.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">
<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>Site Transfer Note</h2>
      </div>
      <div class="right"></div>
</div>

<div class="div_second">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr>
    <td width="10%" class="f12">Branch</td>
    <td width="40%" class="f11">: <?php echo $s->getField('locations','loccode',$row['site'],'locationname'); ?></td>
    <td width="10%" class="f12">Store</td>
    <td class="f11">: <?php echo $s->getField('storetype','id',$row['store_to'],'StoreName'); ?></td>
  </tr>
  <tr>
    <td class="f12">SRN No.</td>
    <td class="f11">: <?php echo $row['received_slip_no']; ?></td>
    <td class="f12">Date</td>
    <td class="f11">: <?php echo date('d/m/Y',strtotime($row['received_date'])); ?></td>
  </tr>  
  <tr>
    <td class="f12">STN  No.</td>
    <td class="f11">: <?php echo $s->getField('transfer_issue','id',$row['issue_slipno'],'issue_slipno'); ?></td>
    <td class="f12">Date</td>
    <td class="f11">: <?php echo date('d/m/Y',strtotime($s->getField('transfer_issue','id',$row['issue_slipno'],'issuedate'))); ?></td>
  </tr> 
</table>
</div>
<div class="div_third">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr>
    <td class="f12" width="10%">Address</td>
    <td width="40%" class="f11">: 
      <?php $site=$s->getField('transfer_issue','id',$row['issue_slipno'],'sitecode');
         echo $s->getField('locations','loccode', $site,'locationname');
     ?>, <?php echo $s->getField('locations','loccode', $site,'deladd1');
     ?> <?php echo $s->getField('locations','loccode', $site,'deladd2');
     ?> <?php echo $s->getField('locations','loccode', $site,'deladd3');
     ?>, 
      <?php 
  $city=$s->getField('locations','loccode', $site,'city');
  $state=$s->getField('locations','loccode', $site,'state');
  $country=$s->getField('locations','loccode', $site,'country');
   ?>, <?php echo $s->getField('city_master','id',$city,'city'); ?>,<?php echo $s->getField('state_master','id',$state,'state'); ?>,<?php echo $s->getField('country_master','id',$country,'country'); ?>,Pin-<?php echo $s->getField('locations','loccode', $site,'pincode'); ?>
    </td>
    <td width="10%" class="f12">Phone</td>
    <td width="15%" class="f11">: <?php echo $s->getField('locations','loccode', $site,'phone1'); ?></td>
    <td width="5%" class="f12">Email</td>
    <td class="f11">: <?php echo $s->getField('locations','loccode', $site,'email'); ?></td>
  </tr>
  <tr>
    <td class="f12">Remarks</td>
    <td colspan="5" class="f11"><?php echo $row['remarks']; ?></td>
  </tr>
</table>
</div>
<div class="div_forth">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tbody>
  <tr>
    <th width="4%" class="f12">S.No.</th>
    <th width="10%" class="f12">Item Code</th>
    <th width="20%" class="f12">Item Name</th>
    <th class="f12">Pkg Description</th>
    <th width="10%" class="f12">Batch no.</th>
   <!-- <th width="8%" class="f12">Stock Balance</th> -->
    <!-- <th width="8%" class="f12">Issue Qty.</th> -->
   <!-- <th width="8%" class="f12">Pending. Qty.</th> -->
    <th colspan="4" class="f12">Received Qty.</th>
   <!-- <th width="45%">Batch No.</th>
    <th width="7%">Unit</th>
    <th>Issued Qty</th>-->
    </tr>
    <?php
    $issueQty=array();
            $resultIssue=DB_query("select itemid, SUM(issueqty) as issueQty 
              from transfer_issue_details where transfer_issue_id='".$row['issue_slipno']."' group by itemid",$db);
            while($rowrIssue=DB_fetch_array($resultIssue))
            {
               $issueQty[$rowrIssue['itemid']]=$rowrIssue['issueQty'];
            }       
            $receivedQty=array();
            $resultRecevied=DB_query("select itemid, SUM(reciveqty) as reciveQty from transfer_receipt_details 
              where issue_slip_no='".$row['issue_slipno']."'   group by itemid",$db);
            while($rowRecevied=DB_fetch_array($resultRecevied))
            {
            $receivedQty[$rowRecevied['itemid']]=$rowRecevied['reciveQty']; 
            }   
 
    $i=1;
   // echo "select * from addmrnqty where id='".$_GET['site']."'";
    $sql=DB_query("select * from transfer_receipt_details where transfer_receipt_id='".$_REQUEST['id']."'",$db);
    while($rowre=DB_fetch_array($sql))
    {
     $itemcode=$s->getField('item_master','id',$rowre['itemid'],'StockID');
     $itemname=$s->getField('item_master','id',$rowre['itemid'],'item_name');
     //$unitid=$s->getField('item_master','id',$rowre['itemid'],'mst_unitid');
    //$unit=$s->getField('unitsofmeasure','unitid',$unitid,'unitname');
      $unitid=$rowre['uom'];
      $unitid1=$rowre['uom1'];
      // echo item_description
      $unit=$s->getField('unitsofmeasure','unitid',$unitid,'unitname');
      $unit1=$s->getField('unitsofmeasure','unitid',$unitid1,'unitname');
 /*   
$op=openingBalance($function_filter,$rowre['itemid']);
$in_1=receivedMRN($function_filter,$rowre['itemid']);
$out_1=issueSlip($function_filter,$rowre['itemid']);
$out_2=issueSiteToSite($function_filter,$rowre['itemid']);    
$in_2=receivedSiteToSite($function_filter,$rowre['itemid']);
$out_3=issueMatarialReturn($function_filter,$rowre['itemid']);
$in_3=receivedReturn($function_filter,$rowre['itemid']);  
$out_4=Rgpchallan($function_filter,$rowre['itemid']);
$out_5=Nrgp($function_filter,$rowre['itemid']);
$in_4=Rgpreturn($function_filter,$rowre['itemid']);  
$in_5=FinishedMR($function_filter,$rowre['itemid']);
$in_6=MaterialConReceived($function_filter,$rowre['itemid']);
$out_6=MaterialConIssue($function_filter,$rowre['itemid']);
$in_7=PhysicalStockPlus($function_filter,$rowre['itemid']);
$out_7=PhysicalStockMinus($function_filter,$rowre['itemid']);
$out_8=dispatchIssue($function_filter,$rowre['itemid']);
$out_9=jobWorkChallan57Issue($function_filter,$rowre['itemid']);
$in_8=jobWorkChallanReturn($function_filter,$rowre['itemid']);
$in_9=direct_purchase_bill($function_filter,$rowre['itemid']);
$invalue=($op+$in_1+$in_2+$in_3+$in_4+$in_5 + $in_6 + $in_7 + $in_8 + $in_9);
$outvalue=($out_1+$out_2+$out_3+$out_4+$out_5 + $out_6 + $out_7 + $out_8 + $out_9);
$tot=$invalue-$outvalue;
$stockbalance=$tot;

     $total_current=$tot;*/
    
 $op=openingBalance($function_filter,$rowre['itemid']);
$in_1=receivedMRN($function_filter,$rowre['itemid']);
$out_1=issueSlip($function_filter,$rowre['itemid']);
$out_2=issueSiteToSite($function_filter,$rowre['itemid']);    
$in_2=receivedSiteToSite($function_filter,$rowre['itemid']);
$out_3=issueMatarialReturn($function_filter,$rowre['itemid']);
$in_3=receivedReturn($function_filter,$rowre['itemid']);  
$out_4=Rgpchallan($function_filter,$rowre['itemid']);
$out_5=Nrgp($function_filter,$rowre['itemid']);
$in_4=Rgpreturn($function_filter,$rowre['itemid']);  
$in_5=FinishedMR($function_filter,$rowre['itemid']);
$in_6=MaterialConReceived($function_filter,$rowre['itemid']);
$out_6=MaterialConIssue($function_filter,$rowre['itemid']);
$in_7=PhysicalStockPlus($function_filter,$rowre['itemid']);
$out_7=PhysicalStockMinus($function_filter,$rowre['itemid']);
$out_8=dispatchIssue($function_filter,$rowre['itemid']);
$out_9=jobWorkChallan57Issue($function_filter,$rowre['itemid']);
$in_8=jobWorkChallan57Received($function_filter,$rowre['itemid']);
$invalue=($op+$in_1+$in_2+$in_3+$in_4+$in_5 + $in_6 + $in_7 + $in_8);
 $outvalue=($out_1+$out_2+$out_3+$out_4+$out_5 + $out_6 + $out_7 + $out_8 + $out_9);
$tot=$invalue-$outvalue;
$stockbalance=$tot;

     $total_current=$tot;  
    
     ?>
  <tr>
    <td class="f11"><?php echo $i; ?></td>
    <td class="f11"><?php echo $itemcode; ?></td>
    <td class="f11"><?php echo $itemname; ?></td>    
    <td class="f11"><?php echo $rowre['item_description']; ?></td>
    <td class="f11"><?php echo $rowre['batch_no']; ?></td>
    <!-- <td class="f11"><?php //echo $total_current; ?></td> -->
   <!-- <td class="f11"><?php echo $issueQty[$rowre['itemid']]; ?></td> -->
   <!-- <td align="right" class="f11"><?php echo (($issueQty[$rowre['itemid']] - $rowre['reciveqty'])); ?></td> -->
    <td class="f11" width="8%"><?php echo $rowre['reciveqty']; ?></td> 
    <td class="f11" width="5%"><?php echo $unit; ?></td>
    <td class="f11" width="8%"><?php echo $rowre['stock_qty2']; ?></td>
    <td class="f11" width="5%"><?php echo $unit1; ?></td> 
    </tr>
  <?php $i++; } ?>
  </tbody>
</table>
</div>
<div class="div_third">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr>
    <td width="10%" class="f12">Prepared By</td>
    <td class="f11">: <?php 
    $preparedbyID=$s->getField('transfer_receipt','id',$_REQUEST['id'],'createdby');
    echo $s->getField('www_users','id',$preparedbyID,'realname'); ?></td>
  </tr>
  <tr>
    <td class="f12">Date</td>
    <td class="f11">: &nbsp;</td>
  </tr>
</table>
</div>
<div class="div_fifth">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr>
    <td height="80" valign="bottom" align="right" class="f12">Authorized Signatory</td>
    </tr>
</table>
</div>
</div>

<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>
</body>
</html>