<?php
ob_start();
session_name('CAKEPHP'); session_start();
//error_reporting(FALSE);
$PageSecurity = 1;
include ('includes/session.inc');
include ('includes/function_lib.php');
include('includes/fun-php.php');
include('includes/fun-HRClass.php');
 $vendorid=$_SESSION['vender'];

global $db; 

$Compamies=DB_query("select * from companies",$db);
$CompamiesRow=DB_fetch_array($Compamies);
?>
<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>

<!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>Ledger Report</title>

<style type="text/css"> 
@print {size:A4; margin:20px 20px;}

@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;
  color:#006699;  
}
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:10%; text-align:left; height:auto; vertical-align:middle; height:auto; padding: 10px; position: absolute; left: 0; top: 0;
        }
        .div_first .middle
        {
          width:60%; text-align:center; padding: 10px; margin:0 auto; position: relative;
        }
        .div_first .right
        {
          width:20%;text-align:right; padding: 10px; position: absolute; right: 0; top: 0;
        }

.div_first .full{text-align: center; border: 0;}
.div_second, .div_third{
  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 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:90%;}
.mt27{margin-top:0px; width:90%;}
.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; 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;
  color:#006699;  
}
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:8%; text-align:center; height:auto; vertical-align:middle; padding: 1%; 
        }
        .div_first .middle
        {
          width:78%; text-align:center; padding: 1%; position: relative; margin:0 auto;
        }
        .div_first .right
        {
          width:8%; 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;}*/

.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: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']=='')?'Final_Logo_RM.png':$CompamiesRow['CompanyLogo']; ?>
      <div class="left"><img src="Setup/CompanyLogo/<?php echo $logoImage;  ?>" class="mt26" /></div>
    	<div class="middle"><?php 
    	$sql1 = "SELECT * FROM companies where CompanyId='".$_SESSION['ACGCompanyId']."'";
	$sqlres = DB_query($sql1,$db);
	$companyRow = DB_fetch_array($sqlres);

//$logo="";

		if($companyRow['CompanyName']!="") {echo "<h1>".$companyRow['CompanyName']."</h1>"; } else { echo "";}
		echo "  <span class='f12'>A Unit of Mani Mandir Sewa Nyas Samiti</span> <br>
       <span class='f12'>Tulsibari, Praikrma Marg, Ayodhya - 224123, Dist. - Faizabad</span>";
		// if($companyRow['Address1']!="") { echo $companyRow['Address1']; } else { echo "";}
		// if($companyRow['Address2']!="") {echo ", ". $companyRow['Address2']; } else { echo "";}
		// if($companyRow1['deladd3']!="") {echo ", ". $companyRow1['deladd3']; } else { echo "";}
		// if($companyRow['City']!="") {echo ", ". $companyRow['City']; } else { echo "";}
		// if($companyRow['State']!="") {echo ", ". $companyRow['State']; } else { echo "";}
		// if($companyRow['Country']!="") {echo ", ". $companyRow['Country'];
		// if($companyRow['Zipcode']!="") {echo " - ".$companyRow['Zipcode']; } else { echo "";}

		// } else { echo "";} ?>
		<div class="full"><h2>Stock Ledger Register Report</h2>
	<span class="f11"><?php	echo ""."<span class='f12'>Phone No.:</span> ".$companyRow['Phone'].", <span class='f12'>Fax No.:</span> ".$companyRow['fax'].", <span class='f12'>CIN No.:</span> ".$companyRow['cin'].", <span class='f12'>Email ID:</span> ".$companyRow['email'].", <span class='f12'>Website:</span> ".$companyRow['website'];	
	
// $logo.="</td>";
// $logo.="</tr>";
// $logo.="</table>";
// $logo.="</div>";
// echo $logo;
?></span></div>
      </div>
      <div class="right"><img src="images/eye-logo-blue.png" vspace="10" class="mt27" /></div>
    </div>
<div class="div_second">
<table align="center" width="100%" border="0" cellpadding="3" cellspacing="0">
<tr>
	<td class="f12" width="5%"> Date</td>
	<td class="f12" style="width:290px;">Particulars</td>
	<td class="f12" width="12%">V. No </td>
	<td class="f12" width="12%">V. Type </td>
	<td class="f12" width="10%">Debit Amount</td>
	<td class="f12" width="10%">Credit Amount</td>
	<?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) {      ?> 
	<td class="f12" width="16%">Remarks</td>
	<?php } ?>
</tr>
<?php 
$data_array=$_SESSION['leddata'];
//echo "<pre>";
//print_r($data_array);



		  	     $flag='';	
				 
 			   //while($RowData1 = DB_fetch_array($ResultData5))
			   $AMTDR1='';
			   foreach($data_array as $k=>$val)
			   { 
			    if($val['flag']=='voucher')
				{
				if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==4)
				{
				 
					 
					   if($_REQUEST['ledgerid']=='DayBook')
					   {
					   	  $ResultData2=DB_query("select * from account_book_details where account_bookid ='".$val['Pid']."'",$db);

					   }
					   else
					   { 
					  
					   	   if($_REQUEST['ledgerdata']!='')
					   	   {
					   	     $ResultData2=DB_query("select A.id,A.account_bookid,A.amount as AMT,  A.ledgerid as ledgerid,B.amount,B.currency,B.amount_type FROM account_book_details A, account_book_details  B   where A.account_bookid ='". $val['Pid']."' and B.ledgerid='".$_REQUEST['ledgerdata']."' AND A.ledgerid!='".$_REQUEST['ledgerdata']."'   and  A.account_bookid=B.account_bookid  and A.amount!='0.00' and A.amount!='' GROUP BY A.account_bookid ",$db);
					   	    }
					   	    else
					   	    {
					   	      $ResultData2=DB_query("select A.id,A.account_bookid,A.amount as AMT,  A.ledgerid as ledgerid,B.amount,B.currency,B.amount_type FROM account_book_details A, account_book_details  B   where A.account_bookid ='". $val['Pid']."' and  A.account_bookid=B.account_bookid  and A.amount!='0.00' and A.amount!='' GROUP BY A.account_bookid ",$db);	
					   	    } 
					   }
			   }
			else
			   {		   
			   	       if($_REQUEST['ledgerid']=='DayBook')
					   {					   
					   	$ResultData2=DB_query("select * from account_book_details where account_bookid ='". $val['Pid']."'  ",$db);

					   }
					   else
					   {
                             if($ledgerdata!='')
                             {
					   	     $ResultData2=DB_query("select A.id,A.account_bookid,A.amount as AMT,  A.ledgerid as ledgerid,B.amount,B.currency,B.amount_type FROM account_book_details A, account_book_details  B   where A.account_bookid ='".$val['Pid']."'  and B.ledgerid='".$_REQUEST['ledgerdata']."' AND A.ledgerid!='".$_REQUEST['ledgerdata']."' and  A.account_bookid=B.account_bookid 	and A.amount!='0.00' and A.amount!=''",$db);
					   	      }
					   	      else
					   	      {
					   	      $ResultData2=DB_query("select A.id,A.account_bookid,A.amount as AMT,  A.ledgerid as ledgerid,B.amount,B.currency,B.amount_type FROM account_book_details A, account_book_details  B   where A.account_bookid ='".$val['Pid']."' and  A.account_bookid=B.account_bookid 	and A.amount!='0.00' and A.amount!=''",$db);
					   	      } 
                        }
						
 					}
				
					}	

					
						
			if(DB_num_rows($ResultData2)>0)
			  {		
			   ?>
			   <tr class="f11">
			   <td >&nbsp;<?php echo ConvertSQLDate($val['date'])?></td>
			   <td >&nbsp;</td>
			   <td >&nbsp;<?php echo $val['Voucher_NO'];?></td>
			   <td >&nbsp;<?php 
			       if($val['flag']=='voucher'){
					echo  $Vprefixval= $s->getField('voucher_master','VoucherType',$val['Vprefix'],'GroupName');}
					else{echo $val['Vprefix'];}
 				  ?> 			   </td>
			   <td >&nbsp;</td>
			   <td >&nbsp;</td>
			   <?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) {      ?> 
			   <td ><?php	echo $s->getField('account_book','id',$val['Pid'],'narration');  ?></td>
			   <?php } ?>
			 
			   </tr>
 				<?php $AMTDR=0; $AMTCR=0; 
				 while($RowData2 = DB_fetch_array($ResultData2))
			  	 { 
				?>
 				<tr class="f11">
				<td >&nbsp;</td>
				<td >&nbsp;<?php 
				if($val['flag']=='voucher')
				{
				echo $s->GetFieldValue('accountledger',"AccountsID='".$RowData2['ledgerid']."'",'AccountName');				
				}
				
				?></td> 
				<td >&nbsp;</td>   
				<?php ?>
	    	     <td ><?php
				 echo $RowData2['VPrefix'];
				  	echo  $s->GetFieldValue('voucher_master',"VoucherType='".$RowData2['VPrefix']."'",'GroupName');?> </td>
				<td style="text-align:right;"><?php  $AMTDR=0; 
				
				if($RowData2['amount_type']=='DR')
				echo $AMTDR=$RowData2['amount'];
                 else
				 echo $AMTDR=0;				
				$TDR[]= $AMTDR;
				 ?></td>
				<td style="text-align:right;"><?php $AMTCR=0;
			    if($val['flag']=='voucher'){				   	    
				if($RowData2['amount_type']=='CR')
				{
				echo $AMTCR=$RowData2['amount'];}
			    }
				else
				{echo $AMTCR=0;}
				$TCR[]= $AMTCR;
				?></td>
				<?php 
				if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) {      ?> 
				<td >&nbsp;</td>    	    
				<?php } ?>
				<td >&nbsp;</td>  
			</tr>
            <?php  
			 
			 
			   }
			?><tr><td colspan="8" ></td>
			   </tr>
	   <?php } }
	 
      
			?><?php if($_REQUEST['AcType']=='Ledger'){?>
		<tr class="f11">
 		  <td >&nbsp;</td> 		   
 		  <td >&nbsp;</td>		  
		  <td >&nbsp;</td>
 		  <td class="f12" style="text-align:right;">Opening Balance:</td>
 		  <td class="f12" style="text-align:right;"><?php echo $openingDRBalance;?></td>
 		<td class="f12" style="text-align:right;"><?php echo $openingCRBalance;?></td>
		<td>&nbsp;</td>
 		<?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) { ?> <?php } ?>
	   </tr><?php }?>
	    <tr>
 		  <td colspan="4" style="text-align:right;" class="f12" > Current Total:</td>
 		  <?php if($_REQUEST['AcType']=='Day' || $_REQUEST['AcType']=='Ledger'){?>
		   <?php }?>
		   
 		  <td class="f12" style="text-align:right;">
		  <?php 
		  if(!empty($AMTDR1)){$TDR1=array_sum($AMTDR1);}else{$TDR1=0;}
		 // echo "<pre>";print_r($TDR);
		  if(!empty($TDR))  $tdr1=array_sum($TDR); else $tdr1=0;
		  echo round(($tdr1+$TDR1),2); 
		  //echo "<br /><br />---"; print_r($AMTDR1);
		   ?>&nbsp;</td>
		 <?php 
		   if($_REQUEST['ledgerentry']==1)
		   $colvalue=2;
		   else
		   $colvalue=1;
		   ?>
 		<td class="f12" style="text-align:right;" colspan="<?php echo $colvalue; ?>"><?php 
 		  if(!empty($TCR)) $tcr=array_sum($TCR); else $tcr=0;
 		 echo round($tcr,2); ?></td>
 		
 		<?php if($_REQUEST['ledgerentry']==1 || $_REQUEST['ledgerentry']==2) {      ?> <?php } ?>
	    </tr>
			 <?php if($_REQUEST['ledgerid']=='Ledger'){?>
	    <tr>
 		  <td colspan="4" style="text-align:right;" class="f12">Closing Balance: </td>
 		   
 		  <?php 
 		  if(!empty($TDR))
		  $DR_total=$openingDRBalance+array_sum($TDR);
		  else
		  $DR_total=0;
		  if(!empty($TCR)) 
		  $CR_total=$openingCRBalance+array_sum($TCR);
		  else
		  $CR_total=0;	
		 
		   if($DR_total>$CR_total)
		   {$DR_balance=$DR_total-$CR_total;}
		   if($CR_total>$DR_total)
		   {$CR_balance=$CR_total-$DR_total;}
		   
		   
		   
		   if($DR_total==$CR_total)
		   {
		   		if(isset($openingDRBalance)){
				$DR_balance=$DR_total-$CR_total;}
				else if(isset($openingCRBalance))
				{$CR_balance=$CR_total-$DR_total;}
		   }
		   
		   ?>
		     
 		  <td style="text-align:right;" class="f12"><?php echo $DR_balance;?></td>
 		<td colspan="<?php echo $colvalue; ?>" class="f12" style="text-align:right;"><?php echo $CR_balance;?></td>
 		
 	
	    </tr>
	    <?php } ?>
</table>
	  
</div>
</div>

</body>
</html>