<? 
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;
}
include("test.php");
include("../opendb.php");
include ("../test.php");
//$re1=mysqli_query($db,"select distinct(invno),shilglnm,shipgstn,entrydate from sap_einvoice where brcode='$brcode' and doctype = 'Tax Invoice' and entrydate >'2021-06-01' and proddesc = 'INCENTIVE CLAIMS WITH GST' order by entrydate desc,invno desc limit 300");
$re1=mysqli_query($db,"select distinct(invno),shilglnm,shipgstn,entrydate from sap_einvoice where brcode='$brcode' and doctype = 'Tax Invoice' and entrydate >'2021-06-01' order by entrydate desc,invno desc limit 300");
//$re1=mysqli_query($db,"select distinct(invno),shilglnm,shipgstn,entrydate from sap_einvoice where brcode='$brcode' and entrydate >'2021-06-01' order by entrydate desc,invno desc");
$sss="select distinct(invno),shilglnm,shipgstn,entrydate from sap_einvoice where brcode='$brcode' and doctype = 'Tax Invoice' and entrydate >'2021-06-01' and proddesc = 'INCENTIVE CLAIMS WITH GST' order by entrydate desc,invno desc limit 300";
//echo $sss;
?>
<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>
<link type="text/css" href="../jquery/jquery-ui.min.css" rel="stylesheet" />	
<link rel="stylesheet" href="../css/form.css" type="text/css" />
<style>
    table.report 
    {
        width:60%;
    }
</style>
<script type="text/javascript">

$(function(){
  $(".supnm").live("keydown.autocomplete",function(){
  $supnm = $(this);
  $row = $supnm.parent().parent();
  $(this).autocomplete({
    source: function( request, response ) {
    $.ajax({
      url: "../search1_cus.php",
      dataType: "json",
      data: "key="+$supnm.val(),
      success: function( data ) {
        response( $.map( data, function( item ) {
          return {
            label: '<span class="la-name">'+item.supnm+' </span><span class="la-name">'+  item.partname + '</span>'    ,
            value: item.supnm,
            name:item.partname,
            tax:item.tax,
            stock:item.stock,
            rate:item.rate,
            reduct:item.reduct,
            }
        }));
      }
    });
  }
  ,
  minLength: 2,
  select: function( event, ui ) {
  $row.find('.partname').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('.qty').focus();
  /*log( ui.item ?
  "Selected: " + ui.item.label :
  "Nothing selected, input was " + this.value);
  */
   }

  }).data("ui-autocomplete")._renderItem = function (ul, item) {
         return $("<li></li>")
             .data("item.autocomplete", item)
             .append( item.label )
             .appendTo(ul);
     };
  });
});
</script>
<script type="text/javascript">
$(function(){
  $(".exphd").live("keydown.autocomplete",function(){
  $led = $(this);
  $row = $led.parent().parent();
  $(this).autocomplete({
    source: function( request, response ) {
    $.ajax({
      url: "../searchled.php",
      dataType: "json",
      data: "key="+$led.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>',
            value: item.cr,
            name:item.cbal,
            }
        }));
      }
    });
  }
  ,
  minLength: 2,
  select: function( event, ui ) {
  $row.find('.led').val(ui.item.value);



  /*log( ui.item ?
  "Selected: " + ui.item.label :
  "Nothing selected, input was " + this.value);
  */
   }

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





</script>
<center>
<form action='' method='POST' onSubmit="return valid()" id="sapupfrm" name="sapupfrm">
<table cellspacing=1 cellpadding=2 class='report' >
    <tr height=21><td colspan=9 align=center bgcolor='steelblue'><FONT COLOR=white><B>GST Multiple</td></tr>
    <th>Sl No.</th>
              <th>Invno</th><th>Date</th>
              <th>Customer</th>
               <th>Status</th><th>INCOME Head</th><th>Customer</th><th>Narration</th><th>Action</th>
    

</td></tr>
<?php
$i=1;
while($row = mysqli_fetch_array($re1)) 
{
    
        $frqry=mysqli_query($db,"select date,narr from gst_income where brcode='$brcode' and refno = '$row[invno]'");
        
    $frar=mysqli_fetch_array($frqry);
    
    $count_no++; ?> 
    <tr><tr >
    <td align="center" width="20%"><? echo $count_no ?></td><td width="20%"><input type=text name='invnovl[]' id=invnovl<? echo $i ?> value='<? echo $row['invno']?>' size=15 readonly style="border: none;
    background: transparent;"> </td><td><?echo implode('-', array_reverse(explode('-', $row[3])))?></td><td width="30%"><? echo $row['1']?>
    </td>
    <?if (strlen($frar[0])>0){?>
        <td colspan=5 width="20%">Posting Done-<?echo implode('-', array_reverse(explode('-', $frar[0])))." ".$frar[1]?>
    <?}else{?>
    <td></td>
    <td><input type=text size=30 name='exphd[]' id='exphd<? echo $i ?>' class=exphd>   
        </td><td><input type=text id='supnm<? echo $i ?>' name=supnm[] size=30 class='supnm' ></td>
        <td><input type=text size=30 name='narrat[]' id='narrat<? echo $i ?>' > </td>
        <td><input type=button value='Update' name='sv' id='svbtn<? echo $i ?>' onclick="return deleteRecords(this.value,this,this.id);"></td>
    <?}?>
        
    
    </tr>
    <?
    $i++;
}
?>




<input type="hidden" name="deleterec" value="" />
<input type="hidden" name="doaction" value="" />


</table>
</form>


</td></tr></table>
<script>
function deleteRecords(str,str1,str2)
{
    var thenum = str2.match(/\d+$/)[0];
    var y=thenum;
    var invvl='invnovl'+(y);
    var exphdvl='exphd'+(y);
    var supnmvl='supnm'+(y);
    var naratvl='narrat'+(y);
    var invno=document.getElementById(invvl).value;
    var exphead=document.getElementById(exphdvl).value;
    var suppliername=document.getElementById(supnmvl).value;
    var narration=document.getElementById(naratvl).value;
    exphead=exphead.replace(/&/g, ' ');
    suppliername=suppliername.replace(/&/g, ' ');
    narration=narration.replace(/&/g, ' ');
    document.location="sapsvgstmulti2out.php?invid="+invno+"&&expensehd="+exphead+"&&suppliernm="+suppliername+"&&narration="+narration;
}
</script>
