<?
session_start();
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Session timed out'); parent.document.location='../index.php'; </script>";
 return;
}
//clude("top.php");
include("opendb.php");
include("test.php");
//include ("calcsparestock.php");
$ker=mysqli_query($db,"select brstate from branch where brcode='$brcode'");
$kar=mysqli_fetch_array($ker);
$invno=$_REQUEST['invno']; 
$mnfr=$_REQUEST['mnfr'];

?>
<title>AC POSTING</title>
<link href="css/form.css" type="text/css" rel="stylesheet" media="screen"  />
<link type="text/css" href="jquery/jquery-ui.min.css" rel="stylesheet" />	
<script type="text/javascript" src="jquery/jquery.js"></script>
<script type="text/javascript" src="jquery/jquery-1.7.min.js"></script>
<script type="text/javascript" src="jquery/jquery-ui.min.js"></script>
<script type="text/javascript" src="jquery/jquery.jqEasyCharCounter.min.js"></script>
    <script type="text/javascript">
        $(function() {
          if ($.browser.msie && $.browser.version.substr(0,1)<7)
          {
			$('li').has('ul').mouseover(function(){
				$(this).children('ul').show();
				}).mouseout(function(){
				$(this).children('ul').hide();
				})
          }
        });        
    </script>
  
<script type="text/javascript">
function dispField(htmlID,htmlID1,htmlID2) {
if (document.f1.RadioGroup1[0].checked == true) {
document.getElementById(htmlID).style.display = "";
document.getElementById(htmlID1).style.display = "none";
document.getElementById(htmlID2).style.display = "none";
  }
else if (document.f1.RadioGroup1[1].checked == true) {
document.getElementById(htmlID).style.display = "";
document.getElementById(htmlID1).style.display = "none";
document.getElementById(htmlID2).style.display = "none";
  }
else if (document.f1.RadioGroup1[2].checked == true) {
document.getElementById(htmlID).style.display = "";
document.getElementById(htmlID1).style.display = "none";
document.getElementById(htmlID2).style.display = "none";
  }

      }
</script>
<script type="text/javascript">
function shortkey_tblopen(){
               
               var rowCounts = document.getElementById('myTable').rows.length;
		 if(rowCounts<=1){
		          
			document.getElementById('insrowbttn').click(); 
               }		   					
 		 
 }
</script>
<script type="text/javascript">
 var count1=0;
 var empname=[];

 var cur=1;
 //var partcode=[];
 var partname=[];
 var unitprice=[];
 var qty=[];
 var tot=[];
 var typ=[];
 var cnt=1;





 $(document).ready(function(){
  $("#svbttn").click(function(){

$("#msgbox").html('<small>Loading...</small>');



 if(document.f1.paytype.selectedIndex<='')
 {
  alert('Invalid Payment Type');
  document.f1.paytype.focus();
  return false;
 }
 if(confirm('Do you want to save?'))
	  {
 

      // var name= $(this).attr('name');

       //$('#type_name').val(name);

     var values1 = $("#jforms").serialize();

   // $(".typeselecter").attr("disabled", true);
    // $("#td1").html('');

      $.ajax({
        url: "svinvoice_edit.php",
        type: "POST",
       data:   values1,
         success: function(msg){
              if(parseInt(msg)!=0)

              {

                $('#msgbox').html(msg);
               // $("#load").html('');
                //$(".typeselecter").attr("disabled", false);
    }


        },
      error:function(){
          alert("failure");
          $("#msgbox").html('there is error while submit');
      }
      });
	 }
	 else
	  {
   return false;
	  }
   });
   });

</script>
<style>


#mask {
	display: none;
	background:url(images/bgimg1.gif) repeat;
	//background: #000; 
	position: fixed; left: 0; top: 0; 
	z-index: 10;
	width: 100%; height: 100%;
	opacity: 0.8;
	z-index: 999;
}

.login-popup{
		display:none;
	background:white;
	padding: 10px; 	
	border: 2px solid #ddd;
	float: left;
	font-size: 1.2em;
	position: fixed;
	top: 4%; left: 45%;
	z-index: 99999;
	box-shadow: 0px 0px 20px #999;
	-moz-box-shadow: 0px 0px 20px #999; /* Firefox */
    -webkit-box-shadow: 0px 0px 20px #999; /* Safari, Chrome */
	border-radius:3px 3px 3px 3px;
    -moz-border-radius: 3px; /* Firefox */
    -webkit-border-radius: 3px; /* Safari, Chrome */
}
}

img.btn_close {
	float: right; 
	margin: -28px -28px 0 0;
}

fieldset { 
	border:none; 
}

form.signin .textbox label { 
	display:block; 
	padding-bottom:7px; 
}

form.signin .textbox span { 
	display:block;
}

form.signin p, form.signin span { 
	color:white; 
	font-size:11px; 
	line-height:18px;
} 

form.signin .textbox input { 
	background:#666666; 
	border-bottom:1px solid #333;
	border-left:1px solid #000;
	border-right:1px solid #333;
	border-top:1px solid #000;
	color:white; 
	border-radius: 3px 3px 3px 3px;
	-moz-border-radius: 3px;
    -webkit-border-radius: 3px;
	font:13px Arial, Helvetica, sans-serif;
	padding:6px 6px 4px;
	width:200px;
}

form.signin input:-moz-placeholder { color:white; text-shadow:0 0 2px #000; }
form.signin input::-webkit-input-placeholder { color:hwite; text-shadow:0 0 2px #000;  }

.submit button { 
	background: -moz-linear-gradient(center top, #f3f3f3, #dddddd);
	background: -webkit-gradient(linear, left top, left bottom, from(#f3f3f3), to(#dddddd));
	background:  -o-linear-gradient(top, #f3f3f3, #dddddd);
    filter: progid:DXImageTransform.Microsoft.gradient(startColorStr='#f3f3f3', EndColorStr='#dddddd');
	border-color:#000; 
	border-width:1px;
	border-radius:4px 4px 4px 4px;
	-moz-border-radius: 4px;
    -webkit-border-radius: 4px;
	color:#333;
	cursor:pointer;
	display:inline-block;
	padding:6px 6px 4px;
	margin-top:10px;
	font:12px; 
	width:100px;
}

.button:hover { background:#ddd; }


.del{
      border: none;
     background: url("images/delete.png") no-repeat scroll 0 0 transparent;
}




.pop-up2 {position:absolute; top:2px; left:50px;padding-left:180px;}
.pop-up2:target {position:static; left:0;}

.popBox2 {
  background:#ffffff;

 
  width:75%;
  min-height:100%;



   z-index:1;

  border:1px solid #3a3a3a;


  -moz-border-radius:12px;
  border-radius:12px;
  -webkit-box-shadow:2px 2px 4px #3a3a3a;
  -moz-box-shadow:2px 2px 4px #3a3a3a;
  box-shadow:2px 2px 4px #3a3a3a;
  opacity:0;
 -webkit-transition: opacity 0.5s ease-in-out;
  -moz-transition: opacity 0.5s ease-in-out;
  -o-transition: opacity 0.5s ease-in-out;
  -ms-transition: opacity 0.5s ease-in-out;
  transition: opacity 0.5s ease-in-out;  
}
:target .popBox2 {position:fixed; opacity:1;}

.popBox2:hover {box-shadow:3px 3px 6px #5a5a5a;}



.lightbox {display:none; text-indent:0em; background:#000; opacity:0.0; width:100%; height:60%; position:fixed; top:0; left:0; bottom:0; right:0;}
:target .lightbox {display:block}



  


/* .popScroll {max-height:99%; overflow-y:scroll;} removed 17/07/2012 */
.popScroll2 {position:absolute; top:2%; left:3%; right:3%; bottom:9%; overflow-y:auto; *overflow-y:scroll; padding-right:0.5em}


</style>

<body background="back_ground.jpg">
<br><br>
<center>
<table class="container"><tr><td>

<form name="f1" id="jforms" method='POST' action='updatedownamt.php' onsubmit='return validateform()'>

<div id="view" class="login-popup">

</div>
		<div id="login-box" class="login-popup">
        <a href="#" class="close"><img src="images/close_pop.png" class="btn_close" title="Close Window" alt="Close" /></a>
          <div id='msgbox'></div>
		</div>

<?
$slqry="SELECT acname from customer where brcode='$brcode' order by acname";
$slrs=mysqli_query($db,$slqry);
?>
<?
print "<center><table border=0  cellspacing=1 cellpadding=3 class='form' ><th colspan=6 style='background-color: steelblue;color: white;'><H3>AC POSTING</TH>";
print "<tr><td></td><td></td>";
print "<td></td><td></td>";
print"</tr>";
?>


<tr><td>Customer</td><td>

<select name='sup' id="to_new_customer" style='width:160px;border:1px solid grey; border-style:dotted;' onchange='getinvno(this.value)' onkeypress='return handleEnter(this, event)'><option>-select-</option>	
<? while($slrow=mysqli_fetch_array($slrs))
{
?>
<option value='<? echo $slrow[0] ?>'><? echo $slrow[0] ?></option>
<?
}
?>

</select>
</td>
<?
$cshrec=mysqli_query($db,"select max(crno) from cshrec where brcode='$brcode'");
$cshrow=mysqli_fetch_array($cshrec);
$mrecno=$cshrow[0]+1;
$bnkrec=mysqli_query($db,"select max(brno) from bnkrec where brcode='$brcode'");
$bnkrow=mysqli_fetch_array($bnkrec);
$mbnkno=$bnkrow[0]+1;

print "</tr>";
?>
<tr>  <td>INV NO: </td><td> <select name='invno' id=invno onchange='getadvamt()' ></select> </td></tr>

<tr>  <td>Adv Amt: </td><td> <input type='text' name='advamt' id='advamt'  size=20 readonly/> </td></tr>

         <tr>  <td>Outstanding: </td><td> <input type='text' name='outstanding' id='outstanding'  size=20 readonly/>
                                           <input type='hidden' name='tot' id='tot_val' value='<? echo $tot_payment; ?>' size=8 readonly/> </td></tr>

  	 <tr>  <td>Add New Amt: </td><td> <input type='text' name='down_amt' id='down_amt' value='0' onchange='updadvamt()' size=20/> </td></tr>

 	 <tr>  <td>DPR Date: </td><td><input type="text" id="d1" value="<?echo date('d');?>"  name="d1"  size=1 >
                                     <input type="text" id="d2" value="<?echo date('m');?>"  name="d2"  size=1 >
                                     <input type="text" id="d3" value="<?echo date('Y');?>"  name="d3"  size=2 >
        </td></tr>

        <tr>  <td colspan=2>With A/c :<input type='radio' name='flag' id='with' value='yes' checked /> &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Without A/c: </td></tr>

<tr>  

<td>CASH:(<?echo $mrecno?>)<input name="RadioGroup1" type="radio" value="1" onChange="dispField('t1','t2','t3');" /></td><td> BANK:(<?print $mbnkno?>)<input type="radio" name="RadioGroup1" value="2" onChange="dispField('t2','t1','t3');"/></td>
<td> JOURNAL<input type="radio" name="RadioGroup1" value="3" onChange="dispField('t3','t2','t1');"/></td></tr>
<tr>
                                    <td colspan="6">

<div id="t1"  style="display:none"><table width="98%" border="0" align="center">
                                        <tr>
                                          <td width="10%">&nbsp;</td>
                                          <td width="81%"><table width="100%" border="0">
                                            <tr>
                                              <td width="15%">Narration</td>
                                              <td width="37%">
<textarea rows="4" cols="40" name="cshnart" id="cshnart" >
</textarea>

</td>
                                                                                          </tr>
                                          </table></td>
                                                                                  </tr>
                                      </table></div>
                                        <div id="t2" style="display:none"><table width="98%" border="0" align="center">
                                        <tr>
                                          <td width="10%">&nbsp;</td>
                                          <td width="81%"><table width="100%" border="0">
<?
$acqury="select distinct(led) from ledger where brcode='$brcode' and grp='BALANCE WITH BANKS'";
$acres=mysqli_query($db,$acqury);

?>
                                            
<tr>
                                              <td width="15%">BANK NAME:</td>
   
                                           <td width="37%">
<select name='bnkled' id='bnkled'>
<?
while($acrow=mysqli_fetch_array($acres))
{
?>
<option value='<? echo $acrow[0] ?>'><? echo $acrow[0] ?></option>

<?
}
?>
</select>

</td>
                                              
                                            </tr>

<tr>
                                              <td width="13%">NARRATION:</td>
                                              <td width="35%">

<textarea rows="4" cols="40" name="bnknart" id="bnknart" >
</textarea>

</td>
						
                                            </tr>



				<tr>
                                              
						<td width="13%">CHEQUE NO:</td>
                                              <td width="35%"><input name="bnkchqno" type="text"  id="bnkchqno" size=40 /></td>

                                            </tr>

                                          </table></td>
                                                                                  </tr>
                                      </table></div>


















<div id="t3" style="display:none"><table width="98%" border="0" align="center">
                                        <tr>
                                          <td width="10%">&nbsp;</td>
                                          <td width="81%"><table width="100%" border="0">
<?
$acqury1="select distinct(led) from ledger where brcode='$brcode'";
$acres1=mysqli_query($db,$acqury1);

?>
                                            
<tr>
                                              <td width="15%">LEDGER NAME:</td>
   
                                           <td width="37%">
<select name='jourled' id='jourled'>
<?
while($acrow=mysqli_fetch_array($acres1))
{
?>
<option value='<? echo $acrow[0] ?>'><? echo $acrow[0] ?></option>

<?
}
?>
</select>

</td>
                                              
                                            </tr>

<tr>
                                              <td width="13%">NARRATION:</td>
                                              <td width="35%">

<textarea rows="4" cols="40" name="jrnart" id="jrnart" >
</textarea>

</td>
						
                                            </tr>



				

                                          </table></td>
                                                                                  </tr>
                                      </table></div>




















<div id='div1'></div>



<?

print "<tr><th colspan=10></tr>";
print"</table><br>";

?>

<center>
<table class=report>

<tr>    

<td colspan='6' align=center>  
<table border=0 cellspacing=1 cellpadding=3 id="myTable" class='tble1'>




<tr>
<th colspan=18><input value="Update"  type="submit" id='svbttn'>
<input type=button value='Cancel' onClick=window.close()></th>
</table>
</form>
<div id='div1'></div>



<script type="text/javascript">

$(document).bind('keydown', 'Alt+n',function (e){

if(e.which==83 && e.ctrlKey) {
e.preventDefault()
 $( "#svbttn" ).click();
        return false;
}   
    if(e.which==78 && e.altKey){
	 //alert (e.which);
        shortkey_tblopen();
        return false;
    } 
 
   if(e.which==82 && e.altKey){
	 
         window.location.reload(true);
        return false;
    } 
      
    
});
function myFunction()
	{
		window.location.reload(true);
        	return false;
	}
</script>

<script>


function getinvno(str)
{
//var brnchtp=document.f1.brnchtp.value;
    document.getElementById("invno").innerHTML='Advance';
if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
        
        
		//alert(xmlhttp.responseText);
        document.getElementById("invno").innerHTML=xmlhttp.responseText;
        document.getElementById("div1").innerHTML='';

    }
  }
   // alert(str);
    xmlhttp.open("GET","showinvno.php?cname="+str,true);
    xmlhttp.send();
}
function getadvamt()
{
var cname=document.f1.sup.value;
var invnovl=document.f1.invno.value;
var down_amt=document.f1.down_amt.value;



if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
        //alert(xmlhttp.responseText);
       document.getElementById("div1").innerHTML= xmlhttp.responseText;
	document.getElementById("advamt").value=document.getElementById("advamtnw").value;
	document.getElementById("outstanding").value=document.getElementById("outstamtnw").value;
//document.getElementById("div1").innerHTML=document.getElementById("tbldiv");
document.getElementById("div1").append(document.getElementById("tbldiv"));

        
    }
  }
xmlhttp.open("GET","showadvamt.php?cname="+cname+"&&invno="+invnovl+"&&dwnamt="+down_amt,true);
xmlhttp.send();

}


function updadvamt()
{
var cname=document.f1.sup.value;
var invnovl=document.f1.invno.value;
var down_amt=document.f1.down_amt.value;
//var brnchtp=document.f1.brnchtp.value;


if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }
xmlhttp.onreadystatechange=function()
  {
  if (xmlhttp.readyState==4 && xmlhttp.status==200)
    {
        
       document.getElementById("div1").innerHTML= xmlhttp.responseText;
	document.getElementById("advamt").value=document.getElementById("advamtnw").value;
	document.getElementById("outstanding").value=document.getElementById("outstamtnw").value;
//alert(document.getElementById("outstamtnw").value);

//document.getElementById("div1").innerHTML=document.getElementById("tbldiv");
document.getElementById("div1").append(document.getElementById("tbldiv"));
//document.f1.down_amt.value=0;
        
    }
  }
xmlhttp.open("GET","updadvamt.php?cname="+cname+"&&invno="+invnovl+"&&dwnamt="+down_amt,true);
xmlhttp.send();

}



function validateform()
{
    if(document.querySelector('input[name="RadioGroup1"]:checked') == null) {
    window.alert("You need to choose an option!");
    return false;
}
	if(document.getElementById("down_amt").value<=0)
	{
		alert('Please enter amount');
		document.f1.down_amt.foucus();
		return false;
	
	}
	
}

</script>

