<? 
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");
$mdate = date("Y-m-d",strtotime("-3 month"));

$re1=mysqli_query($db,"select distinct(invno),shilglnm,shipgstn,entrydate,doctype,total_invoice_value from sap_einvoice where brcode='$brcode' and entrydate >='$mdate' order by entrydate desc,invno  desc limit 10000");
//print "select distinct(invno),shilglnm,shipgstn,entrydate from sap_einvoice where brcode='$brcode' order by entrydate desc,invno desc limit 1100";
$sss="select distinct(invno),shilglnm,shipgstn,entrydate from sap_einvoice where brcode='$brcode' order by entrydate desc,invno desc limit 1500";
//echo $sss;
?>
<link rel="stylesheet" href="../css/form.css" type="text/css" />
<style>
    table.report 
    {
        width:60%;
    }
</style>
<center>
<form action='sap_spareinvoicejsonnew.php' method='POST' onSubmit="return valid()" id="sapupfrm" name="sapupfrm">
<table cellspacing=1 cellpadding=2 class='report' >
    <tr height=21><td colspan=3 align=center bgcolor='steelblue'><FONT COLOR=white><B>Spare Invoice</td><td colspan=2 align=right bgcolor='steelblue'><input type='button' name='suprsbtn' id='suprsbtn' value='Suppress Eicher INVOICE' onclick="redirurl()"></td></tr>
    <th>Sl No.</th>
              <th>Invno</th><th>Date</th>
              <th>Customer</th><th>Doc.Type</th><th>Value</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)) 
{
    $frqry=mysqli_query($db,"select invno,createtime from tbl_einvoice where brcode='$brcode' and invno = '$row[invno]' limit 1");
	$ss1="select invno,createtime from tbl_einvoice where brcode='$brcode' and invno = '$row[invno]'";
	//echo $ss1;
	
    $frar=mysqli_fetch_array($frqry);    
	$count_no++;
	$mdate = $row['entrydate'];
	$mdate=implode('-', array_reverse(explode('-', $mdate)));
	?> 
    
    <?if(strlen($frar[0])>0){
        
    /*?>
    <td align="right" width="20%">Generated - <?echo substr($frar[1],8,2).'-'.substr($frar[1],5,2).'-'.substr($frar[1],0,4)?></td>
    <?*/
    }else{?>
        <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><?echo $mdate?></td><td width="30%"><? echo $row['1']?>
        </td><td width="30%"><? echo $row['4']?>
        </td><td width="30%"><? echo $row['5']?>
        </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='Save' name='sv' onclick="return deleteRecords(document.sapupfrm);"> <input type=button value='Cancel'>
</td></tr>
</table>
</form>


</td></tr></table>
<script>
function redirurl()
{
    document.location='sap_spareinvoicejsondup.php';
}
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)
 	{
        	formname.deleterec.value="delete";
    		formname.submit();
 	}
	else
		return false;
}
</script>
