<?php error_reporting(0);
session_name('CAKEPHP'); @session_start();
$PageSecurity = 3;
include ('includes/session.inc');
include ('includes/function_lib.php');
global $db;
include('includes/Class_Branch.php');
include('includes/AccountGroupMaster_Class.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;
            }
          }
        }
?>	 


<!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>Cash Payment</title>

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

@media print{
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;}

h1{
  font-size: 17px;
  font-weight:normal;
  font-family:Arial, Helvetica, sans-serif !important;
  color:#006699;  
}
h2{
  font-size: 15px;
  font-weight:normal;
  font-family:Arial, Helvetica, sans-serif !important;
}
#header
{
  display: table-header-group; position: fixed; top: 0; margin: 0 auto; overflow: hidden;
}
#main
{
  display: table-row; position: fixed; top:107px; margin: 0 auto; height:90%; overflow: hidden;
}
#footer
{
  display: table-footer-group; position: fixed; bottom: 0; margin: 0 auto;
}
.wrapper{width:760px; height: auto; float:left;}
.div_first{
  width: 758px; 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_first .left{
  width: 120px;
  float:left;
  text-align:center;
  padding-top:10px;
  padding-bottom:10px;
}
.div_first .right{
  width:634px;
  float:left; 
  padding-top:10px;
  padding-bottom:10px;
  text-align:center;
  /*order-left:#000 1px solid;*/
}
.div_second, .div_third, .div_forth, .div_fifth{
  width:758px;
  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_third{height:100%;}

.div_second table tr th, .div_second table tr td{border-right:0; 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_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;}

.div_fifth table tr th, .div_fifth table tr td{ border-bottom:#000 1px solid; border-right:0;}
.div_fifth table tr th{background-color: #ccc; text-align: left;}
.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; line-height:18px;}
.f14{color:#000; font-size:18px;}
.mt26{margin-top:2px; width:50%;}
.border_top{border-top:#000 1px solid;}
.border_bottom{border-bottom:#000 1px solid;}
}

@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:800px; height: auto; margin:0px auto;}
.wrapper{width:800px; height: auto; margin:0 auto; border-top:#000000 1px solid;}

h1{
  font-size: 20px;
  font-weight:normal;
  font-family:Arial, Helvetica, sans-serif !important;
  color:#006699;  
}
h2{
  font-size: 18px;
  font-weight:normal;
  font-family:Arial, Helvetica, sans-serif !important;  
}
.div_first{
  width: 800px; 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_first .left{
  width: 120px;
  float:left;
  text-align:center;
  padding-top:10px;
  padding-bottom:10px;
}
.div_first .right{
  width:678px;
  float:left; 
  padding-top:10px;
  padding-bottom:10px;
  text-align:center;
  /*border-left:#000 1px solid;*/
}
.div_second, .div_third, .div_forth, .div_fifth{
  width: 800px; 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:0; 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_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 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:0;}
.div_fifth table tr th{background-color: #ccc; text-align: left;}
.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; line-height:18px;}
.f14{ color:#000; font-size:18px;}
.mt26{margin-top:4px; width:56%;}
.border_top{border-top:#000 1px solid;}
.border_bottom{border-bottom:#000 1px solid;}
}
</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">
<!--<p align="right"><a href="javascript:history.go(-1);"><input type="button" value="Go Back" /></a></p>-->
<?php $conv_check=$s->getField('account_multi_currency','CompanyId',$_SESSION['ACGCompanyId'],'multicurrency');   
      $BillBookType=  $s->getField('voucher_master','VoucherType',$_REQUEST['VPrefix'],'VPrefix');
      $query="select *  from account_book  where id='".$_REQUEST['id']."' ";
       	$result=DB_query($query,$db);
    		$i=1;
    		if(DB_num_rows($result)>0)
    		{
    			while($myrow=DB_fetch_array($result))
    			{
      			$voucher_no=$myrow['Voucher_NO'];
      			$Dates=$myrow['Dates'];
      			$Ref_no=$myrow['Ref_no'];
      			$voucher_no=$myrow['Voucher_NO'];			
      			$narration=trim($myrow['narration']);
      			$document_type=trim($myrow['document_type']);				
      			$transation_type=$myrow['transation_type'];
      			$Branch=$myrow['Branch'];
       		 	$banks_checkno=$myrow['banks_checkno'];
      			// $myrow['banks_checkdate'];
      			$banks_checkdate=ConvertSQLDate($myrow['banks_checkdate']);
      			$banks_receivedfrom=$myrow['banks_receivedfrom'];
      			$favouring_name=$myrow['favouring_name'];
      			$cross_inst=$myrow['cross_inst'];			
       			$deposit_vouchertype=$myrow['deposit_vouchertype'];
      			$dcrno=$myrow['dcrno'];
      			$deposit_voucherdate=ConvertSQLDate($myrow['deposit_voucherdate']);
      			$depositedby=$myrow['depositedby'];
                        
            $currency1=$s->getField('account_book_details','account_bookid',$myrow['id'],'currency');
            $currency2=$s->getField('account_book_details','account_bookid',$myrow['id'],'conv_currency');
                        

	 ?>
   <div id="header">
<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="right">
<h1><?php $sql1 = DB_fetch_array(DB_query("SELECT CompanyName FROM companies where CompanyId='".$_SESSION['ACGCompanyId']."'",$db)); echo $sql1['CompanyName']."<br>"?></h1>
(<?php echo $_SESSION['YearStart']."-".$_SESSION['YearEnd1']; ?>)
<h2><?php echo $fromtitle=  $s->getField('voucher_master','VoucherType',$_REQUEST['VPrefix'],'GroupName');?></h2>
</div>
</div>
<div class="div_second">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr>
    <td width="50%"><span class="f12">No. :</span> <span class="f11"><?php echo $voucher_no; ?></span></td>
    <td style="text-align:right;"><span class="f12">Dated :</span> <span class="f11"><?php echo date("d/m/Y", strtotime($Dates));?></span></td>
  </tr>
</table>
</div>
</div>
<div id="main">
<div class="div_third">
<table width="100%" border="0" cellspacing="0" cellpadding="3">
  <tr>
    <th class="f12">Particulars</th>
    <th width="16%" align="right" class="f12">Amount</th>
  </tr>
  <tr>
    <td colspan="2" class="f12">Account:</td>
  </tr>
  <?php 
		 
		$total_cr=array();$total_dr=array();
	    $query1="select *  from account_book_details where account_bookid ='".$myrow['id']."' and amount_type='DR'  ";
   		$result1=DB_query($query1,$db);
			while($myrow1=DB_fetch_array($result1))
			{ 
		?>
  <tr>
    <td class="f11"><?php  echo $s->getField('accountledger','AccountsID',$myrow1['ledgerid'],'AccountName'); ?>&nbsp;</td>
    <td class="f11" style="text-align:right;"><?php  echo  ($myrow1['amount_type']=='DR'? $myrow1['amount']:"0");
		 $total_dr[]=($myrow1['amount_type']=='DR'? $myrow1['amount']:"0");
		 ?></td>
  </tr>
	<?php } ?>

</table>
</div>
</div>
<div id="footer">  
<div class="div_forth">
<table width="100%" border="0" cellpadding="3" cellspacing="0">
 <tr>
    <td colspan="2" class="f12">Through:</td>
  </tr>
<?php 
      $query2="select *  from account_book_details where account_bookid ='".$myrow['id']."' and amount_type='CR'  ";
      $result2=DB_query($query2,$db);
     while($rs2=DB_fetch_array($result2))
     {

?>

  <tr>
    <td><span class="f11"><?php echo $s->getField('accountledger','AccountsID',$rs2['ledgerid'],'AccountName'); ?></span></td>
    <td width="16%" align="right" class="f12"></td>
  </tr>
  <?php } ?>
  <tr>
    <td><span class="f12">On Account of :</span> <span class="f11"><?php echo $myrow['narration']; ?></span></td>
    <td align="right" class="f12"></td>
  </tr>
  <tr>
    <td><span class="f12">Amount(in Word) :</span> <span class="f12"><?php  echo "Rupees ".ucfirst(number_to_words(array_sum($total_dr)))." only"; ?></span></td>
    <td width="16%" align="right" class="f12"><?php echo array_sum($total_dr); ?></td>
  </tr>
</table>  
</div>
<div class="div_fifth">
<table width="100%" border="0" cellpadding="3" cellspacing="0" style="margin-top:35px;">
  <tr>
    <td width="33%" class="f12">Receiver's Signature</td>
    <td width="33%" align="center" class="f12">Account Assistant</td>
	<td align="right" class="f12">Manager / Accountant</td>
  </tr>
</table>	
</div>	
</div>   
<?php }	} ?>
</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>