<?php
$PageSecurity = 1;
session_name('CAKEPHP'); session_start();
ob_start();
$PageSecurity = 1;
include('config.php');
include('includes/ConnectDB.inc');
include('includes/function_lib.php');
include('includes/LanguageSetup.php');
include('includes/DateFunctions.inc');
include('Account/fun-Trial.php');
setlocale(LC_MONETARY, 'en_IN');
if($_REQUEST['search2'])
{
	$_SESSION['tab']='tab2';
 $month=$_REQUEST['month'];
$years=$_REQUEST['years'];
 $vendor_code=$_REQUEST['vender'];
$cndtn="";
 
}

 ?>

 <?php 
$sql1 = "SELECT CompanyName FROM companies where CompanyId='".$_SESSION['ACGCompanyId']."'";
$sqlres = DB_query($sql1,$db);
$companyRow = DB_fetch_array($sqlres);
$Compamies=DB_query("select * from companies",$db);
$CompamiesRow=DB_fetch_array($Compamies);
?>
<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>Columnar Purchase Register</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: landscape; 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{
  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 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 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;}

.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:70%;}
.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{
  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 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;}

.div_forth{border-bottom:#000000 1px solid;}

.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:100%;}
.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']=='')?'electra.jpg':$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>Columnar Purchase Register</h2>
      </div>
      <div class="right"></div>
</div>

<div class="div_second">
 <table width="100%" border="0" cellpadding="3" cellspacing="0">
  <tr>
    <th align="left" valign="middle" class="f12">Branch</th>
    <th align="left" valign="middle" class="f12">Voucher Date </th>
    <th align="left" valign="middle" class="f12">Voucher No.</th>
    <th align="left" valign="middle" class="f12">Vendor</th>
    <th align="left" valign="middle" class="f12">Tin No.</th>
    <th align="left" valign="middle" class="f12">Bill Ref.</th>
    <th align="left" valign="middle" class="f12">Bill Ref date</th>
    <th align="left" valign="middle" class="f12">Basic Amount</th>
    <!-- <th align="left" valign="middle" class="f12">Discount</th>
    <th align="left" valign="middle" class="f12">Discounted Amount</th> -->
    <th align="left" valign="middle" class="f12">Pkg.Charges</th>
    <!-- <th align="left" valign="middle" class="f12"><strong>Non Tax Insurance</strong></th> -->
    <th align="left" valign="middle" class="f12">Excise Duty </th>
    <th align="left" valign="middle" class="f12">E Cess</th>
    <th align="left" valign="middle" class="f12">SHE Cess</th>        
    <!-- <th align="left" valign="middle" class="f12">Taxable Amount</th> -->
    <th align="left" valign="middle" class="f12">Freight</th>
    <th align="left" valign="middle" class="f12">Purchase Tax </th>
    <th align="left" valign="middle" class="f12">SGST</th>
    <th align="left" valign="middle" class="f12">CGST</th>
    <th align="left" valign="middle" class="f12">IGST</th>
    <th align="left" valign="middle" class="f12">UTGST</th>
    <th align="left" valign="middle" class="f12">Surcharge Tax</th>
    <!-- <th align="left" valign="middle" class="f12">Entry Tax</th> -->
    <th align="left" valign="middle" class="f12">Insurance</th>
    <th align="left" valign="middle" class="f12">Round Off</th>
    <th align="left" valign="middle" class="f12">Grand Total</th>
  </tr>
  <?php 
   $GT=array();
	 $Basic=array();
	 $pkg=array();
	 $excise=array();
	 $ecess=array();
	 $shecess=array();
	 $discAM=array();
	 $discountedAM=array();
	 $taxable_fright=0;
	 $inputtax=array();
	 $surcharge=array();
	 $freight=array();
	 $other=array();
	 $roundoff=array();
	 $taxable_fright=array();
	 $sgst=array();
	 $cgst=array();
	 $igst=array();
	 $ugst=array();
  $searched2=$_SESSION['colornr'];
  if(!empty($searched2))
  {
  foreach($searched2 as $key=>$row)
  {
   ?>
   <tr>
   <td align="left" valign="top" class="f11"><?php  echo $row['site'];?></td>
   <td align="left" valign="top" class="f11"><?php  echo ConvertSQLDate($row['bill_date'])?></td>
	<td align="left" valign="top" class="f11"><?php  echo $row['bill_book_no']?></td>
	<td align="left" valign="top" class="f11"><?php echo $row['vendor_name'];	?></td>
	<td align="left" valign="top" class="f11"><?php   echo $row['tin_no'];?></td>
	<td align="left" valign="top" class="f11"><?php  echo $row['bill_no']?></td>
	<td align="left" valign="top" class="f11"><?php  echo ConvertSQLDate($row['bill_book_date']);	?></td>
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['basic']); ?></td>
	<!-- <td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['discount_amt']); ?></td>
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['discounted_amt']); ?></td> -->
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['pkg_charges']); ?></td>
	<!-- <td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['non_insurance']); ?></td> -->
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['excise_amt']); ?></td>
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['ecess_amt']); ?></td>
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['shecess_amt']);?></td>
	<!-- <td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['tot_tax_amt']); ?></td> -->
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['freight']); ?></td>
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['taxvalue']);?></td>
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['sgst']);?></td>
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['cgst']);?></td>
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['igst']);?></td>
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['ugst']);?></td>
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['sur_oct_amt']);?></td>
	<!-- <td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['add_charges']);?></td> -->
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['insurance']);?></td>
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['roundoff']); ?></td>
	<td align="right" valign="top" class="f11"><?php  echo money_format('%!i',$row['GrandTotal']);?></td>
	
	 <?php 
	 $Basic[]=$row['basic'];
	// $discAM[]=$row['discount_amt'];
	// $discountedAM[]=$row['discounted_amt'];
	 $pkg[]=$row['pkg_charges'];
	// $non_insurance[]=$row['non_insurance'];
	 $excise[]=$row['excise_amt'];
	 $ecess[]=$row['ecess_amt'];
	 $shecess[]=$row['shecess_amt'];
	// $tot_taxamt[]=$row['tot_tax_amt'];
	 $inputtax[]=$row['taxvalue'];
	 $surcharge[]=$row['sur_oct_amt'];
	 $addCharge[]=$row['add_charges'];
	 $insurance[]=$row['insurance'];
	 $freight[]=$row['freight'];
	 $other[]=$row['roundoff'];
	 $GT[]=$row['GrandTotal'];
	 $sgst[]=$row['sgst'];
	 $cgst[]=$row['cgst'];
	 $igst[]=$row['igst'];
	 $ugst[]=$row['ugst'];
 ?>
  </tr> 
 <?php }
  ?>
 <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
       <td>&nbsp;</td>
      <td class="f12">Total</td>    
     <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($Basic)); ?>&nbsp;</td>
     <!-- <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($discAM)); ?>&nbsp;</td>
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($discountedAM)); ?>&nbsp;</td> -->
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($pkg)); ?>&nbsp;</td>
          <!-- <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($non_insurance)); ?>&nbsp;</td> -->
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($excise)); ?>&nbsp;</td>
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($ecess)); ?>&nbsp;</td>
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($shecess)); ?>&nbsp;</td>
    <!--  <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($tot_taxamt)); ?>&nbsp;</td> -->
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($freight)); ?>&nbsp;</td>
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($inputtax)); ?>&nbsp;</td>
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($sgst)); ?>&nbsp;</td>
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($cgst)); ?>&nbsp;</td>
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($igst)); ?>&nbsp;</td>
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($ugst)); ?>&nbsp;</td>
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($surcharge)); ?>&nbsp;</td>
      <!-- <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($addCharge)); ?>&nbsp;</td> -->
       <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($insurance)); ?>&nbsp;</td>
       <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($other)); ?>&nbsp;</td>
      <td class="f12" style="text-align:right;"><?php echo money_format('%!i',array_sum($GT)); ?>&nbsp;</td>
    
    </tr> 

 <?php } else {?>
 <tr class="f12">
 <td colspan="22">No Result Found.</td>
 </tr>
 <?php } ?>
</table>

</div>
</div>

</body>
</html>