<?php
ob_start();
session_name('CAKEPHP'); session_start();
$PageSecurity = 3;
include ('includes/session.inc');
include ('includes/function_lib.php');
include('includes/fun-php.php');
include('includes/fun-HRClass.php');
global $db; 
$ledgerdata = $_REQUEST['ledgerdata'];
$fromdate_1=ConvertSQLDate($_REQUEST['fromdate']);
$todate_1=ConvertSQLDate($_REQUEST['todate']);
//$GetRecord1 = $_SESSION['ACGAccountBookQuery'];
//$GetRecord1= $_SESSION['ledger'];
if($ledgerdata!='0')
{
  $GetRecord1 ="SELECT A.VPrefix  ,A.Voucher_NO ,A.id AS Pid, A.Dates FROM account_book A, account_book_details b WHERE A.id=b.account_bookid and A.Dates between  '".$fromdate_1."' and '".$todate_1."'
   and branch='".$_REQUEST['site']."' and A.VPrefix  ='".$_REQUEST['vprifix']."' and b.ledgerid='".$_REQUEST['ledgerdata']."' and A.cancel_status=0 ".$cond." 
    group by A.Voucher_NO ORDER BY  A.Dates ASC";
 }
 else
 {
 	$GetRecord1="SELECT A.VPrefix  ,A.Voucher_NO ,A.id AS Pid, A.Dates FROM account_book A, account_book_details b WHERE A.id=b.account_bookid and A.Dates between  '".$fromdate_1."' and '".$todate_1."'
   and branch='".$_REQUEST['site']."' and A.VPrefix  ='".$_REQUEST['vprifix']."' and A.cancel_status=0 ".$cond." 
    group by A.Voucher_NO ORDER BY  A.Dates ASC";
 } 
$ResultData1 = DB_query($GetRecord1,$db);
$numrows = DB_num_rows($ResultData1);

$getLedgerName=$s->GetFieldValue('accountledger',"AccountsID='".$ledgerdata."'" ,'AccountName');
$accountType=$s->GetFieldValue('accountledger',"AccountsID='".$ledgerdata."'" ,'openingtype');
if($accountType=='DR')
{
$openingDRBalance=$s->GetFieldValue('accountledger',"AccountsID='".$ledgerdata."'" ,'openingBalance');
}
elseif($accountType=='CR')
{
$openingCRBalance=$s->GetFieldValue('accountledger',"AccountsID='".$ledgerdata."'" ,'openingBalance');
}
$Compamies=DB_query("select * from companies",$db);
$CompamiesRow=DB_fetch_array($Compamies);
$CompamiesRow['CompanyId'];
$branch=$s->GetFieldValue('locations',"CompanyId='".$CompamiesRow['Branch_Permission']."'",'locationname');
?>

<!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' />

<style type="text/css"> 
/* ----------------- Print -------------------- */
@page {
    size: A4;
    margin:30px 20px 30px;
}
@media print{
    * { margin: 0; padding-top: 0; padding-bottom: 0; }
body{ margin:0px; padding:0px; font-size:12px; font-family: Arial, Helvetica, sans-serif; color:#000; font-weight:normal;}
h1,h2,h3,h4,h5,p{ margin:0px; padding:0px;}
.wrapper{ width:99%; border:1px solid #000; border-top:0; margin:0 auto; float:left; }

thead{display: table-header-group;}

.div_first, .div_second{
  width:100%; height: auto; float: left;
  border-top: #000000 1px solid !important;
  /*border-left:#000000 1px solid; border-right:#000000 1px solid;*/
  /*border-bottom: #000000 1px solid;*/
}
.div_first .left
        {
          width:20%; float:left; text-align:center; height:auto; vertical-align:middle; padding: 10px;
        }
        .div_first .middle
        {
          width:50%; float:left; text-align:center; padding: 10px;
        }
        .div_first .right
        {
          width:20%; float:left; text-align:center; padding: 10px;
        }
.div_second{ height:100%; border-top:0; }

.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;}

thead{display: table-header-group;}

h2{
  font-size: 18px;
  font-weight:normal;
  margin:0px;
  padding:0px;
  color:#000;  
}
h3{
    font-size: 17px;
    text-align: center;
    text-decoration: none;
  }
.f10{color:#000; font-size:12px; line-height: 18px;}
.f11{color:#000; font-size:12px; line-height:18px;}
.f12{font-weight: bold; color:#000; font-size:12px; line-height: 18px;}
.mt26{margin-top:4%; width: 50%;}
.clr{clear:both;}
.ht{height:36px;}
.h60{height: 40px;}
.pagebreak { page-break-before: always; }
}
@media screen{
/* CSS Document */
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{ margin:0px; padding:0px;}
#foo{width:1000px; height: auto; margin:0px auto;}
.wrapper{
  width: 1000px;
  /* [disabled]height:1220px; */
  background-color: #FFF;
  /*border: 1px solid #000;*/
  margin:0 auto;
}
.clr{clear:both;}
.div_first, .div_second{
  width: 998px;
  border-left: #000000 1px solid; border-right: #000000 1px solid;
  border-top: #000000 1px solid; float:left;
}
.div_first .left
        {
          width:20%; float:left; text-align:center; height:auto; vertical-align:middle; padding: 10px;
        }
        .div_first .middle
        {
          width:50%; float:left; text-align:center; padding: 10px;
        }
        .div_first .right
        {
          width:20%; float:left; text-align:center; padding: 10px;
        }

h2{
  font-size: 20px;
  font-weight:normal;
  margin:0px;
  padding:0px;
  color:#000;
  
}
h3{color: #003399;
    font-size: 18px;
    text-align: center;
    text-decoration: none;
}

.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;}*/

.f12{ font-family:Arial, Helvetica, sans-serif; font-weight: bold; color:#000; font-size:12px; line-height:16px;}
.f11{ font-family:Arial, Helvetica, sans-serif; color:#000; font-size:12px; line-height:16px;}
.f14{ font-family:Arial, Helvetica, sans-serif; color:#000; font-size:13px; line-height:24px;}

.mt26{margin-top:4px; width:50%;}
.fill2{font-family:Arial; font-size:12px; color:#000000;}
.border_top{border-top:#000 1px solid;}
.border_bottom{border-bottom:#000 1px solid;}
}
</style>
<title>Account Book</title>

</head>
<body>
<div id="foo">
  <p align="right"><a href="#" onclick="javascript:toggle_visibility('foo');"><input type="button" value="Print" class="search" /></a></p>
</div>
<div class="wrapper">
<?php 
   $sql1 = "SELECT * FROM companies where CompanyId='".$_SESSION['ACGCompanyId']."'";
  $sqlres = DB_query($sql1,$db);
  $companyRow = DB_fetch_array($sqlres);
  
// order Details
 $arr=array(1=>"Jan","Feb","Mar","Apr","May","June","July","Aug","Sept","Oct","Nov","Dec"); 

?>
  <div class="div_first">
 <?php
      $logoImage=($companyRow['CompanyLogo']=='')?'Final_Logo_RM.png':$companyRow['CompanyLogo'];
   ?>
<div class="left"><img src="Setup/CompanyLogo/<?php echo $logoImage;  ?>" class="mt26" /></div>

 <div class="middle"><img width="42%" src="images/raj-medi.jpg" vspace="10"/>
 <h2><?php echo $s->GetFieldValue('voucher_master',"VoucherType='".$_REQUEST['vprifix']."'",'GroupName'); ?></h2>
 <?php
$logo="<span class='f11'>".'Showing'.' '.$Slogan.' '.$getLedgerName.' '.'From:'.' '.$_REQUEST['fromdate'].' '.'To:'.' '.$_REQUEST['todate']."</span>";
echo $logo;
?></div>
        <div class="right"><img  width="100%" src="images/raj-iso.jpg" vspace="10"/></div>
   
    </div>

	<div class="div_second">
<table width="100%" border="1" cellspacing="0" cellpadding="3">
<?php
if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) 
{
	$header .= "<tr>";
	$header .= "<th width='5%' class='f12'>S.No.</th>";
	$header .= "<th width='7%' class='f12'>Date</th>";
	$header .= "<th class='f12'>Particulars</th>";
	$header .= "<th width='10%' class='f12'>Voucher No.</th>";
	$header .= "<th width='10%' class='f12'>Voucher Type</th>";
	$header .= "<th width='10%' class='f12'>Debit Amount</th>";
	$header .= "<th width='10%' class='f12'>Credit Amount</th>";
	$header .= "<th width='10%' class='f12'>Narrations</th>";
	$header .= "</tr>";
}
else
{
	$header .= "<tr>";
	$header .= "<th width='5%' class='f12'>S.No.</th>";
	$header .= "<th width='7%' class='f12'>Date</th>";
	$header .= "<th class='f12'>Particulars</th>";
	$header .= "<th width='10%' class='f12'>Voucher No.</th>";
	$header .= "<th width='10%' class='f12'>Voucher Type</th>";
	$header .= "<th width='10%' class='f12'>Debit Amount</th>";
	$header .= "<th width='10%' class='f12'>Credit Amount</th>";
	$header .= "</tr>";
}
echo $header;
$counter=0;	
if(DB_num_rows($ResultData1)>0)
{  
	$i=1;
	while($RowData1 = DB_fetch_array($ResultData1))
	{  
		if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==4 || $_REQUEST['ledgerentry']==2 || $_REQUEST['ledgerentry']==3)
		{
			if($ledgerdata!='0')
			{
		       $ResultData2=DB_query("select A.* FROM account_book_details A   where A.account_bookid ='". $RowData1['Pid']."' and A.ledgerid='".$ledgerdata."'    ",$db);
		     }
		     else
		     {
		       $ResultData2=DB_query("select A.* FROM account_book_details A   where A.account_bookid ='". $RowData1['Pid']."' ",$db);	
		     }  
		}
		else					   
		{
		  if($ledgerdata!='0')
		  {
		     $ResultData2=DB_query("select A.id,A.account_bookid,A.amount as AMT,  B.ledgerid as ledgerid,B.amount,B.currency,B.amount_type FROM account_book_details A, account_book_details  B   where A.account_bookid ='". $RowData1['Pid']."' and A.ledgerid='".$ledgerdata."' and  A.account_bookid=B.account_bookid",$db);
		  }
		  else
		  {
		  	$ResultData2=DB_query("select A.id,A.account_bookid,A.amount as AMT,  B.ledgerid as ledgerid,B.amount,B.currency,B.amount_type FROM account_book_details A, account_book_details  B   where A.account_bookid ='". $RowData1['Pid']."' and  A.account_bookid=B.account_bookid",$db);
		  }   
		}
		if(DB_num_rows($ResultData2)>0)
		{
              
		if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) 
		{?>
<tr>
	<td><?php echo $i++.".";?></td>
	<td><?php echo ConvertSQLDate($RowData1['Dates'])?></td>
	<td>&nbsp;</td>
	<td><?php echo $RowData1['Voucher_NO'];?> </td>
	<td><?php echo $vpr= $s->GetFieldValue('voucher_master',"VoucherType='".$RowData1['VPrefix']."'",'VPrefix');?></td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) { ?>
	<td><?php echo $s->getField('account_book','id',$RowData1['Pid'],'narration'); ?></td>
	<?php } ?>
</tr>
<?php 
while($RowData2 = DB_fetch_array($ResultData2))
{ 
$flag=0;
	switch($vpr)
	{
		case 'CP':  
		break;
	}
?>
<tr>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td><?php 
	if($_REQUEST['ledgerid']!='Day'  &&  $_REQUEST['ledgerentry']!=2 && $_REQUEST['ledgerentry']!=3)
	{
	$acid=DB_query("select ledgerid from account_book_details where ledgerid!='".$RowData2['ledgerid']."' and account_bookid='".$RowData2['account_bookid']."' limit 1 ",$db);
	$acid1=DB_fetch_array($acid);
	echo $s->GetFieldValue('accountledger',"AccountsID='".$acid1['ledgerid']."'",'AccountName');
	}
	else 
	{	
	echo $s->GetFieldValue('accountledger',"AccountsID='".$RowData2['ledgerid']."'",'AccountName');
	}
	?>
	</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>
	<?php  
	if($RowData2['amount_type']=='DR')
	echo $AMTDR=$RowData2['amount'];
	else
	echo $AMTDR=0;	
	$TDR[]= $AMTDR;;
	?>
	</td>
	<td>
	<?php  
	if($RowData2['amount_type']=='CR')
	echo $AMTCR=$RowData2['amount'];
	else
	echo $AMTCR=0;
	$TCR[]= $AMTCR;;
	?>
	</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
</tr>
<?php 
$counter++;
//echo $counter;
$numRows1=DB_num_rows($ResultData2);
if($numRows1==1)
{
if($counter%14==0)
{ 
$flag=$numRows1;
?>
<tr>
	<td style="padding:0px;" colspan="8"><hr ></td>
</tr>
</table>
</div>
<div class="div_second">
<?php echo $logo; ?>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<?php echo $header; ?>	
<?php }
}
else
{
if($counter%20==0)
{
$flag=$numRows1;
 ?>
 <tr>
	<td style="padding:0px;" colspan="8"><hr ></td>
</tr>
</table>
</div>
<div class="div_second">
<?php echo $logo; ?>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<?php echo $header; ?>
<?php }
}
}?>
<?php if($flag==0) {?>
<tr>
	<td style="padding:0px;" colspan="8"><hr ></td>
</tr>
<?php } ?>
<?php 
	}
		else
		{ ?>
<tr>
	<td><?php echo $i++.".";?></td>
	<td><?php echo ConvertSQLDate($RowData1['Dates'])?></td>
	<td>&nbsp;</td>
	<td><?php echo $RowData1['Voucher_NO'];?></td>
	<td>
	<?php   
	echo  $vpr= $s->GetFieldValue('voucher_master',"VoucherType='".$RowData1['VPrefix']."'",'VPrefix');?>
	</td>
	<td>&nbsp;</td>
	<?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) {      ?>
	<td>
	<?php	
	echo $s->getField('account_book','id',$RowData1['Pid'],'narration');  
	?>
	</td>
	<?php } ?>
</tr>
<?php 
while($RowData2 = DB_fetch_array($ResultData2))
{ 
$flag1=0;
	switch($vpr)
	{
	case 'CP':  
	break;
	}
?>
<tr >
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td><?php 
	if($_REQUEST['ledgerid']!='Day'  &&  $_REQUEST['ledgerentry']!=2 && $_REQUEST['ledgerentry']!=3)
	{
	$acid=DB_query("select ledgerid from account_book_details where ledgerid!='".$RowData2['ledgerid']."' and account_bookid='".$RowData2['account_bookid']."' limit 1 ",$db);
	$acid1=DB_fetch_array($acid);
	echo $s->GetFieldValue('accountledger',"AccountsID='".$acid1['ledgerid']."'",'AccountName');
	}
	else 
	{	
	
	echo $s->GetFieldValue('accountledger',"AccountsID='".$RowData2['ledgerid']."'",'AccountName');
	}
	?>
	</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	</td>
	<td>
	<?php  
	if($RowData2['amount_type']=='DR')
	echo $AMTDR=$RowData2['amount'];
	else
	echo $AMTDR=0;
	
	$TDR[]= $AMTDR;;
	?>
	</td>
	<td><?php  
	if($RowData2['amount_type']=='CR')
	echo $AMTCR=$RowData2['amount'];
	else
	echo $AMTCR=0;
	$TCR[]= $AMTCR;;
	?></td>
</tr>
<?php 
$counter++;
$numRows1=DB_num_rows($ResultData2);
if($numRows1==1)
{
if($counter%14==0)
{ 
$flag1=$numRows1;
?>
<!-- <tr>
	<td style="padding:0px;" colspan="8"><hr ></td>
</tr> -->
</table>
</div>
<div class="div_second">
<?php echo $logo; ?>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<?php echo $header; ?>	
<?php 
		}
}
else
{
if($counter%20==0)
{ 
$flag1=$numRows1;
?>
<!-- <tr>
	<td style="padding:0px;" colspan=""><hr ></td>
</tr> -->
</table>
</div>
<div class="div_second">
<?php echo $logo; ?>
<table width="100%" border="0" cellspacing="0" cellpadding="3">
<?php echo $header; ?>	
<?php 
		}
}
	
	
	}// END OF WHILE WITHOUT NARRATION
?>
<?php if($flag1==0) {?>
<tr>
	<td style="padding:0px;" colspan="7"><hr ></td>
</tr>
<?php } ?>
					<?php 
					}
				}
			 }
	  	 }
?>
<tr>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td>&nbsp;</td>
	<td nowrap="nowrap">Current Total:</td>
	<td><b><?php echo number_format(array_sum($TDR),2); ?></b>&nbsp;</td>
	<td><b><?php echo number_format(array_sum($TCR),2); ?></b></td>
	<td>&nbsp;</td>
</tr>
</table>
</div>
</div>
<script type="text/javascript" language="javascript">
  function toggle_visibility(id) {
  var msg=confirm("Please Use Mozilla Firefox in Landscap Mode For Better Print");
  if(msg)
  {
       var e = document.getElementById(id);
	       e.style.display = 'none';
		       //alert(e.style.display);
			   window.print();
	}
    }
</script>
</body>
</html>
<?php
$header='';  		
header("Content-type: application/x-msdownload"); 
header("Content-Disposition: attachment; filename=Ledger_Export.xls"); 
header("Pragma: no-cache"); 
header("Expires: 0"); 
print "$header\n$data"; 
	
?>
