<? 
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),createtime from tbl_einvoice where brcode='$brcode' order by createtime desc,invno desc limit 800");
?>
<link rel="stylesheet" href="../css/form.css" type="text/css" />
<style>
    table.report 
    {
        width:60%;
    }
    
    
</style>
<center>
<form action='sap_del_einvoicenew.php' method='POST' id="sapupfrm" name="sapupfrm">
<table cellspacing=1 cellpadding=2 class='report' >
    <tr height=21><td colspan=4 align=center bgcolor='steelblue'><FONT COLOR=white><B>Spare Invoice</td></tr>
    <th>Sl No.</th>
              <th>Invno</th>
              <th>Uploaded Date & Time</th>
              <th>Invoice Date</th>
               
               <th>Select All<input name="selectall" value="0" onclick="un_check_category();" type="checkbox" /></th>
    

</td></tr>
<?php
$i=1;
while($row = mysqli_fetch_array($re1)) 
{
    $count_no++;
    $res=mysqli_query($db,"select entrydate from sap_einvoice where invno ='$row[invno]' limit 1");
    $row1=mysqli_fetch_row($res);
    ?> 
    <tr><tr >
    <td align="center" width="20%"><? echo $count_no ?></td><td width="20%"><input type=text name='invnovl[<? echo $i ?>]' value='<? echo $row['invno']?>' size=15 readonly style="border: none;
    background: transparent;"> </td><td width="30%"><? echo $row['1']?>
    </td><td width="30%"><? echo $row1['0']?>
    </td>
    <td align="right" width="20%"><input type="checkbox" name="del[]" id="del[]" value="<? echo $row['invno']?>"  /></td>
    </tr>
    <?
    $i++;
}
?>

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

<tr><td colspan=4 align=center bgcolor='lightsteelblue'>
<input type=button value='Delete' name='sv' onclick="return deleteRecords(document.sapupfrm);"> <input type=button value='Cancel'>
</td></tr>
</table>
</form>


</td></tr></table>
<script>
function un_check_category()
{
  for (var i = 0; i < document.sapupfrm.elements.length; i++) {
    var e = document.sapupfrm.elements[i];
            if ((e.name != 'allbox') && (e.type == 'checkbox')) {
e.checked = document.sapupfrm.selectall.checked;
    }
  }
}
function deleteRecords(formname)
{
        var chks = document.getElementsByName('del[]');

        var hasChecked = false;
        // Get the checkbox array length and iterate it to see if any of them is
//selected
        for (var i = 0; i < chks.length; i++)
        {
                if (chks[i].checked)
                {
                        hasChecked = true;
                        break;
                }
        }
        // if ishasChecked is false then throw the error message
        if (!hasChecked)
        {
                alert("Woops! You forgot to select record(s)");
                return false;
        }
        var agree=confirm("Are you sure you want to upload to the selected recored(s)?");
 	if(agree==true)
 	{
        	document.getElementById("sapupfrm").deleterec.value="delete";
    		document.getElementById("sapupfrm").submit();
 	}
	else
	{
		return false;
	}
}
</script>
