<?
session_start();
include_once('includes/top.php');
include_once("test.php");
include_once('opendb.php');
$brcode=$_SESSION['brcode'];
$user=$_SESSION['user'];
//$br=$_SESSION['branch'];
if(strlen($user)<=0)
{
  print "<script> alert('Invalid User'); document.location='inde.php' </script>";
  return;
}
$level=$_REQUEST['level'];
if(($user=='kishore'||$user=='shahul'||$user=='joy')&&($brcode=='3776'||$brcode=='3810'))
{
   $crstring=1; 
}
$res=mysqli_query($db,"select max(dbno) from crnote where brcode='$brcode'");
 $row=mysqli_fetch_row($res);
 if($row[0]<=0)
  $dbno='25'.$brcode.'050001';
 else
  $dbno=($row[0]+1);
?>
<link type="text/css" href="jquery/jquery-ui.min.css" rel="stylesheet" />
<script type="text/javascript" src="js/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" src="js/jquery.form.js"></script>
<script>

$(function(){
$(".cr").live("keydown.autocomplete",function(){
$cr = $(this);
$row = $cr.parent().parent();
$(this).autocomplete({
		source: function(request, response ) {

		$.ajax({
			url: "searchledpay.php",
			dataType: "json",
			data: "key="+$cr.val(),
			success: function( data ) {
				response( $.map( data, function( item ) {


					return {
						label: '<span class="la-code">'+item.cr+' </span><span class="la-name">'+  item.cbal + '</span><span class="la-stok"> '+ item.stock +'</span><span class="la-rate"> '+item.rate +'</span>'    ,
						value: item.cr,
						name:item.cbal,
						tax:item.tax,

						stock:item.stock,
						rate:item.rate,
						reduct:item.reduct,


					}
				}));
			}
		});
	}

,
	minLength: 2,
	select: function( event, ui ) {
	$row.find('.cr').val(ui.item.cr);
	
        $row.find('.cbal').val(ui.item.name);
	$row.find('.stok').val(ui.item.stock);
	$row.find('.unitprice').val(ui.item.rate);

	$row.find('.tax').val(ui.item.tax);
	$row.find('.itmvl').val(ui.item.reduct);
	$row.find('.cr_amt').focus();
	
	 }

	}).data("ui-autocomplete")._renderItem = function (ul, item) {
         return $("<li></li>")
             .data("item.autocomplete", item)
             .append( item.label )
             .appendTo(ul);
     };


});





}); 




















    function edit(a)
{
   document.location='editdbnote22.php?dbno='+a;
}


</script>

<style>
 td{font-family:verdana;font-size:14;color:black;}
 th{font-family:verdana;font-size:14;color:white;background-color:#5b5858}
 body{background-color:silver;}
 select
  {border-style:ridge;
   border-color:black;
   height:25px;
   border-size=1;
   font-family:verdana;
   color:black;
  }
 input
  {border-style:ridge;
   border-color:#22437f;
   background-color:white;
   height:25px;
   font-weight:bold;
   border-size=1;
   font-family:sans-serif;
   color:BLACK;
  }
</style>
<head>
<title>AMPL EICHER</title>
 <script src="rightclick_deactive.js"></script>
    <script type="text/javascript" src="scripts/jquery-latest.js"></script>
	<link type="text/css" href="includes/style1.css" rel="stylesheet" />
  <link type="text/css" href="css/form.css" rel="stylesheet" />
    <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>
 var dr_cr=[];
function showNature()
{
 var nature=dr_cr[document.f1.grp.selectedIndex];
 if(nature=='Assets'||nature=='Expenses')
    document.f1.drcr.value='Dr';
 else if(nature=='Liabilities'||nature=='Income')
    document.f1.drcr.value='Cr';
 else
   document.f1.drcr.value='';
}

function chkey(abc)
{
 yy=abc.value
 if(yy.indexOf('  ')>-1) 
  {
    alert('Multiple space is not allowed');
    abc.value='';
  }
 if(yy.indexOf("'")>-1) 
  {
    alert("\' is not allowed");
    abc.value='';
  }
 if(yy.indexOf('"')>-1) 
  {
    alert("\" is not allowed");
    abc.value='';
  }
 if(yy.indexOf('&')>-1) 
  {
    alert("\& is not allowed");
    abc.value='';
  }
}

function valid()
{ 
 subOK="false";
 x=confirm("Do you want to save?");
 if(x)
  subOK="true";
   if(subOK=="true")
     return true;
   else
     return false;
} 

</script>

<body background="back_ground.jpg">
<?
if($level>=0)
{?>
<body>
<center>
<form name=f1 action="svcrnote1.php" method=post onSubmit="return valid()">
<table width=90%>
<tr><td colspan=2 bgcolor=#5b5858 align=center><font color=white size=3>Credit Note <input type=hidden name=dbno value=<? print $dbno ?>><? print $dbno ?></font></tr></td>
<tr><td>Debit</td><td><select  name=led >
    <option value= 'DISCOUNT ALLOWED'>DISCOUNT ALLOWED</option>
    <option value='Coupon Scheme'>coupon scheme</option>
    <option value='GOODWILL CLAIM A/C'>GOODWILL CLAIM A/C</option><option value='Outward Supply - Labour'>Outward Supply - Labour</option><option value='TCS PAYABLE'>TCS PAYABLE</option>
    <option value= 'Outward Supply - Sales'>Outward Supply - Sales</option>
    <option value= 'Transportation Charges'>Transportation Charges</option>
    </select>
    
Date:dd <input type=text name='d' size='2' value='<?print date("d",time());?>'>
mm <input type=text name='m' size='2' value='<?print date("m",time());?>'>
yy <input type=text name='y' size='4' value='<?print date("Y",time());?>'>
</td>
</tr>
<tr><td>Head</td><td>
    <input type='text' name='cr' id='cr' class='cr' size=75 autocomplete='off' list='htmlListTags'>
 Tax Type<select name='taxtype' ><option>INTRA STATE</option><option>INTER STATE</option></select></td></tr>
<tr><td>Amount </td><td><input type=text onChange=calc() name=op> 

<!--
<select name=drcr>
<option>Dr</option>
<option>Cr</option>
<select>
-->
Tax %<select name='taxp' onChange=calc()><option>0.00</option><option>18.00</option><option>28.00</option></select>
 <input type=text name='tax' size=10 value='0'>Amount Before Tax <input type=text readonly name='amt2'></td>

</tr>
<tr><td>Desc.</td><td><input type=textarea name=desc  size=60 ></td></tr>


<tr><td colspan=2 bgcolor=#5b5858 align=center>
<input type=submit value="Save"> <input type=button value="Cancel" onClick=document.location='blank.html'> 
</tr></td>
</table>
</form>

<?
}
?>

<script>
function calc()
{
 net=parseFloat(document.f1.op.value);
 amt=(net* 100)/(100+parseFloat(document.f1.taxp.value))
 document.f1.amt2.value=parseFloat(amt.toFixed(2));

 tax=parseFloat(document.f1.amt2.value)*parseFloat(document.f1.taxp.value)/100;
 document.f1.tax.value=(net-amt).toFixed(2);
}
</script>
<table border=1>
<th>slno<th>No<th>Date</th><th>Head<th>Details<th>Amount<th>Action</th>
<?
$res1=mysqli_query($db,"select * from crnote where brcode='$brcode'");
$k=1;

while( $row1=mysqli_fetch_array($res1))
{
print"<tr><td>$k</td><td>$row1[dbno]</td><td>".datetohtml($row1['date'])."</td><td>$row1[partic]</td><td>$row1[narr]</td><td>$row1[cramt]</td>";
if($crstring=='1')
{
print "<td align=center><input type=button value='edit' onClick=javascript:edit1('$row1[1]','$row1[8]')></td>";
}
print "<td align=center><input type=button value='del' onClick=javascript:del1('$row1[1]','$row1[8]')></td></tr>";
$k++;
}

?>

<script>
function del1(a,b)
{
 if(confirm('Do you want to delete Cr No.'+a))
   document.location='delcrnote.php?crno='+a+'&jvno='+b;
}
function edit1(a,b)
{
   document.location='editcrnote.php?crno='+a+'&jvno='+b;
}

</script>

</table>
