<?
ob_start();
session_start();
if(isset($_SESSION['ses_name']))
{
$user=$_SESSION['ses_name'];
}else{
header("location:index.php");
}
$parent_name='';
$ledger_name='';
$transactionbank='';
$veh_num='';
$sdate_12 ='';
$page='1';
include("include/config.php");
require_once "include/Database_functions.php";
$sqlObj=new sqlclass();
$msg = '';

			$from='';
			$to='';
			$amount='';
			$pay_date='';
			$cashed='';
			$cheque_no='';
			$cheque_date=date('d-m-Y');
			$bankname='';
			$branchname='';
			$neft_reference_no='';
			$purpose='';
			$sum_in_letters='';
			$editid = '';
			$empid ='';
			$payMth ='';
if(isset($_REQUEST['savereciept']))
{

if(isset($_REQUEST['bankcheck']) && $_REQUEST['bankcheck']!='')
{
		$bankcheck=2;
		$to=$_REQUEST['received_from'];
		$transactionbank=$_POST['transactionbank'];
		if($_REQUEST['transactiontype']=='cheque')
		{
		$cheque_no=$_REQUEST['cheque_no'];
		$cheque_date=date('Y-m-d',strtotime($_REQUEST['cheque_date']));
		$bankname=$_REQUEST['bankname'];
		$branchname=$_REQUEST['branchname'];
		$referenceno='';
		}
		else
		{
		$cheque_no='';
		$cheque_date='';
		$bankname='';
		$branchname='';
		$referenceno=$_REQUEST['referenceno'];
		}
}
else
{
		$to=1;
		$transactionbank=0;
		$bankcheck=1;
		$cheque_no='';
		$cheque_date='';
		$bankname='';
		$branchname='';
		$referenceno='';
}
$drvid=$_POST['drvid'];
$sq_emp=mysql_query("select * from cf_driver where driver_id ='$drvid'");
$resemp =  mysql_fetch_array($sq_emp);
$efname = $resemp['drivername'];
$payamount=$_POST['received_cash'];
//$monthName = date("F", mktime(0, 0, 0, $payMth, 10));
$pay_date=date('Y-m-d',strtotime($_POST['pay_date']));
$add_date=date("Y-m-d H:i:s");

$received_to=$_POST['received_to'];
$amount=$_POST['received_cash'];
$sum_in_letters=$_POST['sum_in_letters'];

$purpose='Advance paid to '.$efname;



$sql=mysql_query("insert into cf_driver_adv (`drv_id`,`amount`,`purpose`,`pay_date`,`add_date`,`cashed`,`cheque_no`,`cheque_date`,`bankname`,`branchname`,`neft_reference_no`,`sum_in_words`,`transaction_bank`) values ('$drvid','$payamount','$purpose','$pay_date','$add_date','$bankcheck','$cheque_no','$cheque_date','$bankname','$branchname','$referenceno','$sum_in_letters','$transactionbank')");


$ledger = mysql_query("select ledgerid from cf_ledger where empid = '$drvid' and groupid ='8'");
$ledgeres = mysql_fetch_array($ledger);
$to = $ledgeres['ledgerid'];


$sql=mysql_query("insert into cf_voucher (`from`,`to`,`amount`,`purpose`,`pay_date`,`add_date`,`cashed`,`cheque_no`,`cheque_date`,`bankname`,`branchname`,`neft_reference_no`,`sum_in_words`,`transaction_bank`) values ('$drvid','$to','$amount','$purpose','$pay_date','$add_date','$bankcheck','$cheque_no','$cheque_date','$bankname','$branchname','$referenceno','$sum_in_letters','$transactionbank')");

header("location:driver_advance_list.php");
}



?>

<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>OIL FILL</title>
<link href="css/styles.css" rel="stylesheet"  />

<link href="css/menu.css" rel="stylesheet" type="text/css" />
<style>
.newcategoryProfile{ background:#FFFFFF; position:absolute; width:400px; height:250px; z-index:5;
					-webkit-box-shadow: 0px 0px 35px 1px rgba(0,0,0,0.75);
					-moz-box-shadow: 0px 0px 35px 1px rgba(0,0,0,0.75);
					box-shadow: 0px 0px 35px 1px rgba(0,0,0,0.75);}


</style>
<link type="text/css" href="css_date/ui-lightness/jquery-ui-1.7.2.custom.css" rel="stylesheet" />
<script type='text/javascript' src="https://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="js/trippopup.js" type="text/javascript"></script>
<!----------------------------css for auto complete-------------------------------->
<link rel="stylesheet" href="css/chosen.css">

<!--end-->

<script type='text/javascript' src="js/jquery.autocomplete.js"></script>
<link rel="stylesheet" type="text/css" href="js/jquery.autocomplete.css" />

<script type="text/javascript" src="scripts_date/jquery-calendar-1.7.2.js"></script>
<script language="javascript">

$(document).ready(function(){
$('#pay_date').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});

$(document).ready(function(){
$('#add_date').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});

$(document).ready(function(){
$('#cheque_date').datepicker({
showOn: 'both',
buttonImage: 'icons_date/calendar.gif',
buttonImageOnly: true,
changeMonth: true,
changeYear: true,
dateFormat: 'dd-mm-yy'
});
});

function test_skill(junkVal) {

   // var junkVal=document.getElementById('rupees').value;
    //junkVal=Math.floor(junkVal);
    var obStr=new String(junkVal);
    numReversed=obStr.split("");
    actnumber=numReversed.reverse();

    if(Number(junkVal) >=0){
        //do nothing
    }
    else{
        alert('wrong Number cannot be converted');
        return false;
    }
    if(Number(junkVal)==0){
        document.getElementById('sum_in_letters').value=obStr+''+'Rupees Zero Only';
        return false;
    }
    if(actnumber.length>9){
        alert('Oops!!!! the Number is too big to covertes');
        return false;
    }

    var iWords=["Zero", " One", " Two", " Three", " Four", " Five", " Six", " Seven", " Eight", " Nine"];
    var ePlace=['Ten', ' Eleven', ' Twelve', ' Thirteen', ' Fourteen', ' Fifteen', ' Sixteen', ' Seventeen', ' Eighteen', ' Nineteen'];
    var tensPlace=['dummy', ' Ten', ' Twenty', ' Thirty', ' Forty', ' Fifty', ' Sixty', ' Seventy', ' Eighty', ' Ninety' ];

    var iWordsLength=numReversed.length;
    var totalWords="";
    var inWords=new Array();
    var finalWord="";
    j=0;
    for(i=0; i<iWordsLength; i++){
        switch(i)
        {
        case 0:
            if(actnumber[i]==0 || actnumber[i+1]==1 ) {
                inWords[j]='';
            }
            else {
                inWords[j]=iWords[actnumber[i]];
            }
            inWords[j]=inWords[j];
            break;
        case 1:
            tens_complication();
            break;
        case 2:
            if(actnumber[i]==0) {
                inWords[j]='';
            }
            else if(actnumber[i-1]!=0 && actnumber[i-2]!=0) {
                inWords[j]=iWords[actnumber[i]]+' Hundred and';
            }
            else {
                inWords[j]=iWords[actnumber[i]]+' Hundred';
            }
            break;
        case 3:
            if(actnumber[i]==0 || actnumber[i+1]==1) {
                inWords[j]='';
            }
            else {
                inWords[j]=iWords[actnumber[i]];
            }
            if(actnumber[i+1] != 0 || actnumber[i] > 0){
                inWords[j]=inWords[j]+" Thousand";
            }
            break;
        case 4:
            tens_complication();
            break;
        case 5:
            if(actnumber[i]==0 || actnumber[i+1]==1 ) {
                inWords[j]='';
            }
            else {
                inWords[j]=iWords[actnumber[i]];
            }
            inWords[j]=inWords[j]+" Lakh";
            break;
        case 6:
            tens_complication();
            break;
        case 7:
            if(actnumber[i]==0 || actnumber[i+1]==1 ){
                inWords[j]='';
            }
            else {
                inWords[j]=iWords[actnumber[i]];
            }
            inWords[j]=inWords[j]+" Crore";
            break;
        case 8:
            tens_complication();
            break;
        default:
            break;
        }
        j++;
    }

    function tens_complication() {
        if(actnumber[i]==0) {
            inWords[j]='';
        }
        else if(actnumber[i]==1) {
            inWords[j]=ePlace[actnumber[i-1]];
        }
        else {
            inWords[j]=tensPlace[actnumber[i]];
        }
    }
    inWords.reverse();
    for(i=0; i<inWords.length; i++) {
        finalWord+=inWords[i];
    }
        return finalWord;
    //document.getElementById('container').innerHTML=obStr+'  '+;
       
}
 
    //document.getElementById('container').innerHTML=finalWord;
 function paisa_conver(junkVal){

   junkVal = junkVal.split('.')[0];
 
        var finalWord1 = test_skill(junkVal);
		
    console.log(finalWord1);
    
            var finalWord2;
    var val = document.getElementById('received_cash').value;
 var enteredvalue = document.getElementById('received_cash').value;

        if(val.indexOf('.')!=-1)
    {
          val = val.substring(val.indexOf('.')+1,val.length);
            if(val.length==0){
              finalWord2 = "Rupees Only.";
           }else{
            //   document.getElementById('rupees').value = val;
   paisa = enteredvalue.split('.')[1];
   //console.log(paisa);
   if(paisa){
   
             finalWord2 = "Rupees and"+test_skill(paisa) + " paisa only";
      }else{
    finalWord2 = "Rupees Only.";
   }
    // 
           }
     
    } else{
          finalWord2 = "Rupees Only.";
    }
	
    document.getElementById('sum_in_letters').value=finalWord1 +" "+finalWord2;
 
 
 
 
}

function changeview()
{
if($('#bankcheck').is(':checked')){
$(".fromacc").css("display", "block");
}
else
{
$(".fromacc").css("display", "none");
}
}
function checktranstype(type)
{
if(type=='cheque')
{
$(".chequedetails").css("display", "block");
$(".neftdetails").css("display", "none");
}
if(type=='neft')
{
$(".neftdetails").css("display", "block");
$(".chequedetails").css("display", "none");
}

}


$(document).ready(function(){

var received_cash=document.getElementById('received_cash').value;

if(received_cash!='' && received_cash!='undefined' && received_cash!=0)
{
paisa_conver(received_cash);

}

});
</script>
</head>

<body>
<!------------------popup area (view, edit)--------------->



<!---------------popup area ends------------------>
<div class="viewEmployeePopup login-popup"  id="login-box" style="height: 220px;width:500px;
overflow-x: scroll;">
    <a href="#" class="close">
    <img src="" class="btn_close" title="Close Window" alt="Close" />
    </a>
    <div id="view_emp"></div>
</div>
<div class="wrapper">
  <div>
<?php 
	include("header.php");
?>
 
</div>
 
 <div class="tabbedArea">
   

   
   <div id="popup" align="center"  style="margin-left: 400px;"></div>
   
   <div class="tabBody">
    <h1 align="" style="margin-left:80px">Add Driver Advance </h1>
    <form action="" name="voucherfrm" id="voucherfrm" method="post" accept-charset="utf-8">
<div style="display:none;"></div>		
			
			<table  border="0" cellspacing="0" cellpadding="0" style="width:90%;" >
			
			<?php
			if(isset($_GET['edit']) && $_GET['edit']=='update')
			{
			
			$editid = $_GET['id'];
			$array=mysql_query("select * from cf_reciept where reciept_id='$editid'");
			if($array && mysql_num_rows($array)>0){
			
			while($res=mysql_fetch_array($array))
			{
			$from=$res['from'];
			$to=$res['to'];
			$amount=$res['amount'];
			$pay_date=date('d-m-Y',strtotime($res['pay_date']));
			$cashed=$res['cashed'];
			$cheque_no=$res['cheque_no'];
			$cheque_date=$res['cheque_date'];
			$bankname=$res['bankname'];
			$branchname=$res['branchname'];
			$neft_reference_no=$res['neft_reference_no'];
			$purpose=$res['purpose'];
			$sum_in_letters=$res['sum_in_words'];
			$transactionbank=$res['transaction_bank'];

			}
			}
			}
			?>
				<tr>
    <td width="200" align="center" valign="middle"></td>
    <td width="600" align="center" valign="middle" style="border:#333333 0px solid;">
		<table width="97%" border="0" cellspacing="0" cellpadding="0" class="tableListrec" style="margin-top:0px;">
               <tr>
        <td colspan="2" style="padding-left:0px;">
		<table width="100%" border="0" cellspacing="0" cellpadding="0" style="border:0px;">
		
		<?php
		
					$tin_sql=mysql_query("select max(reciept_id) as max_id from cf_reciept");
				  if($tin_sql && mysql_num_rows($tin_sql)>0)
				  {
				  while($tin_row=mysql_fetch_array($tin_sql))
				  {
				  $max_id=$tin_row['max_id']+1;
				  }
				  }
				  else
				  {
				  $max_id=1;
				  }
		
		?>
  <tr><td style="border:0px;"><b>No : </b>CSH VCHR <?=$max_id?>(CASH VOUCHER) <input type="hidden" name="editreciept" id="editreciept" value="<?=$editid?>" /></td>
    <td style="border:0px;"><b>Pay Date : </b>
		<input type="text" name="pay_date" id="pay_date"  class="slabinput input1" style="width:70px;" value="<?=$pay_date?>" required="required"/></td>
    
  </tr>
</table>
         </td>
      </tr>
      <tr>
        <td style="border:0px;" valign="top" colspan="2">
	
			          
                    
		</td>					
      </tr>
	  <!-- <tr>
        <td colspan="2" align="left">&nbsp;</td>
      </tr> -->
      <tr>
        <td height="30" align="left" colspan="2">
		
		<?php /*?><div class="ui-widget"><label for="received_to">Ledgername : </label>
		<select class="chzn-select restselect input45" name="received_to" required="required">
     	<?php
		 $sq_ledger=mysql_query("select * from cf_ledger where ledgerid = 71");
		 while($resledger=mysql_fetch_array($sq_ledger))
   			{
  		?>
   			<option value="<?=$resledger['ledgerid']?>" ><?=$resledger['ledgername']?></option>
        <?php
    		}
  			?>
     </select></div><?php */?>	
		
		
		<div class="ui-widget"><label for="received_to">Driver Name : </label>
	<select class="chzn-select restselect input45" name="drvid" required="required">
     <option value="">Select Driver</option>
		<?php
		 $sq_drv=mysql_query("select * from cf_driver");
		 while($resdrv=mysql_fetch_array($sq_drv))
   		{
  		?>
   			<option value="<?=$resdrv['driver_id']?>" ><?=$resdrv['drivername']?></option>
        <?php
    	}
  		?>
     </select></div>	
	 <br/>
	
				
		 
		<span class="" style="float:right;">Bank  <input type="checkbox" name="bankcheck" id="bankcheck" <?php if($cashed==2) {?> checked="checked" <?php } ?> value="1" onClick="changeview()" ></span></td>
		
      </tr>
     
	 <tr>
        <td height="30" colspan="2" align="left">
		<?php if($cashed==1 || $cashed=='') {?>
		<span class="fromacc" style="display:none;">
		<?php } 
		elseif($cashed==2 )
		{
		?> <span class="fromacc" style="display:block;">
		<?php } ?>
		<div class="ui-widget"><label for="ledgerreceived">Bank A/c : </label>
		  <table width="500" border="1">
  <tr><td><select  name="received_from" class="input1" >
     <option value="">Select Ledger</option>
       <?php 
         $sq_tripno="select * from cf_ledger where groupid=12";
   $arrtripno1=mysql_query($sq_tripno);
   while($restripno=mysql_fetch_array($arrtripno1))
   {
  ?>
   <option  <?php if($restripno['ledgerid']==$to) { ?> selected="selected" <?php } ?>  value="<?=$restripno['ledgerid']?>" ><?=$restripno['ledgername']?></option>
        <?php
    }
  ?>
     </select></td>
	 
	 <td><select  name="transactionbank" class="input1" >
     <option value="">Select Bank</option>
       <?php 
         $sq_bankno="select * from cf_bank ";
   $arrbankno1=mysql_query($sq_bankno);
   while($resbankno=mysql_fetch_array($arrbankno1))
   {
  ?>
   <option  <?php if($resbankno['bank_id']==$transactionbank) { ?> selected="selected" <?php } ?>  value="<?=$resbankno['bank_id']?>" ><?=$resbankno['bankname']?></option>
        <?php
    }
  ?>
     </select></td>
	 
	 <td>
	 
	 <input type="radio" name="transactiontype" <?php if($cheque_no!=0) { ?> checked="checked" <?php } ?> value="cheque" class="transactiontype" onClick="checktranstype('cheque')">Cheque
<input type="radio" name="transactiontype" <?php if($neft_reference_no!=0) { ?> checked="checked" <?php } ?> value="neft" class="transactiontype" onClick="checktranstype('neft')">NEFT</td></tr></table> </div>

<?php if($cheque_no!=0) {?>
		 <div class="chequedetails" style="display:block;">
		<?php } 
		else
		{
		?> <div class="chequedetails" style="display:none;">
		<?php } ?>
	
	 <table width="200" border="1">
  <tr>
    <td>Cheque No:</td>
    <td><input type="text" name="cheque_no" id="cheque_no" value="<?=$cheque_no?>" class="input1" ></td>
  </tr>
  <tr>
    <td>Cheque Date</td>
    <td><input type="text" name="cheque_date" id="cheque_date" value="<?=date('d-m-Y',strtotime($cheque_date))?>" class="input1" ></td>
  </tr>
  <tr>
    <td>Bank Name</td>
    <td><input type="text" name="bankname" id="bankname" value="<?=$bankname?>" class="input1" ></td>
  </tr>
    <tr>
    <td>Branch Name</td>
    <td><input type="text" name="branchname" id="branchname" value="<?=$branchname?>" class="input1" ></td>
  </tr>
</table>
		</div>
		<?php if($neft_reference_no!=0) {?>
		 <div class="neftdetails" style="display:block;">
		<?php } 
		else
		{
		?> <div class="neftdetails" style="display:none;">
		<?php } ?>
		
	 <table width="200" border="1">
  <tr>
    <td>Reference No:</td>
    <td><input type="text" name="referenceno" id="referenceno" value="<?=$neft_reference_no?>" class="input1" ></td>
  </tr>
 
</table>
		</div>
	 </span>
	 </td> 
      </tr>
	  
	     
      
      <tr>
        <td height="30" align="left"><h4>Sum of Rs (in words) : <br />
		 #
		 <input name="sum_in_letters" class="slabinput" id="sum_in_letters" style="width:348px; " onKeyUp="PleaseConvert()" readonly="readonly" value="<?=$sum_in_letters?>" type="text"/>		  </h4></td>
        <td rowspan="2" align="" style="border:#cccccc 1px solid; vertical-align:middle"><h4>Amount : </h4>
		<input name="received_cash" class="slabinput input1" id="received_cash" value="<?=$amount?>" style="width:150px;"  onKeyUp="paisa_conver(this.value)" type="text" required="required"/>
		
				</td>
      </tr>
      <?php /*?><tr>
        <td height="30" align="left"><h4>For : </h4>
		<textarea name="purpose" class="slabinput input1" id="purpose" style="height:50px; width: 350px;" cols="30" rows="6"><?=$purpose?></textarea>		</td>
        </tr><?php */?>

	  <tr>
        <td align="left">&nbsp;</td>
        <td align="left">		
		<b>Sign : </b>
		  admin admin </td>
      </tr>
     <!-- <tr>
        <td colspan="2" align="left">&nbsp;</td>
      </tr> -->
    </table>
	
	</td>
    <td width="52" align="center" valign="middle" style="padding-left:80px;"><br />
      <br />
    <div class="submit">
	<input  name="savereciept" alt="Save" class="input1" type="submit" value="Save"/></div>
    <input type="hidden" name="save" />
    
    </td>
    <td width="148" align="left" valign="middle">&nbsp;</td>
  </tr>	
			
  
 </table>	

	</form>			
	</div>
   <div id="list">
   

  </div>

 </div>
 <div class="footer"><p>Powered by <a href="http://www.aadhocc.co.uk/" target="_blank">Aadhocc</a></p></div>
 
</div>
<div class="quicLInksCover">
 <?php 
	include("leftlink.php");
?>

</div>
</body>
<!----------------------- script for autocomplete------------------------------>
		<script src="js/chosen.jquery.min.js" type="text/javascript">
		</script>
		<script type="text/javascript"> 
			$(".chzn-select").chosen({search_contains: true}); 
		</script>

<!----------------end of script -------------------------------->

</html>
