<?
session_start();
$brcode = $_SESSION['brcode'];
$user = $_SESSION['user'];
$level= $_SESSION['level'];
if(strlen($brcode)<=0)
{
 print "<script> alert('Invalid Login'); parent.document.location='ind.php' </script>";
 return;
}
include("opendb.php");
include("test.php");
$df=$_REQUEST['df'];
$dto=$_REQUEST['dto'];
?>
<link rel="stylesheet" href="../style.css" type="text/css" />
<style>
body,td{font-family:arial narrow;font-size:14}
</style>
<center>
<?
$df = $_REQUEST['df'];
if(!$df)
{
    $d = $_REQUEST['d'];
    $m = $_REQUEST['m'];
    $y = $_REQUEST['y'];
    $d1 = $_REQUEST['d1'];
    $m1 = $_REQUEST['m1'];
    $y1 = $_REQUEST['y1'];
    $df=$y.'-'.$m.'-'.$d;
    $dto=$y1.'-'.$m1.'-'.$d1;
}
print "<font size=4>Day book from ".implode('-', array_reverse(explode('-', $df)))." to ".implode('-', array_reverse(explode('-', $dto)));
print "<hr style={background-color:green;color:green}>";
$re=mysqli_query($db,"select distinct jvno,date,type from journal2 where brcode='$brcode' and  date>='$df' and date<='$dto' group by jvno order by date")or die(mysqli_error());
print "<table bgcolor='ivory' border=0 cellspacing=3 cellpadding=1 width=100%> \n<th>Tr. No <th>Date <th>Particulars <th>Debit <th>Credit <th>Narration <th width=50>Type<th>Ref <th>No";
$ed=0;
while($row=mysqli_fetch_array($re))
{
    $ed=0;
    $re2=mysqli_query($db,"select dramt,cramt,narr,j_type,against,no,partic,tr_no from journal2 where jvno='$row[jvno]' and brcode='$brcode'") or die(mysqli_error());
    print "\n<tr bgcolor='silver'><td>$row[jvno]</td><td>".implode('-', array_reverse(explode('-', $row['date'])))."</td><td></td>";
    print "\n<td></td><td></td><td></td><td></td>";
    print "<td> </td><td></td>";
    while($jvrow=mysqli_fetch_array($re2))
    {
        //echo $jvrow['j_type']."test".$row['jvno'];
        print "\n<tr><td>&nbsp;</td><td>&nbsp;</td><td>$jvrow[partic]</td>";
        print "<td align=right>".nozero($jvrow['dramt'])."</td>";
        print "<td align=right>".nozero($jvrow['cramt'])."</td><td>$jvrow[narr]</td><td>$jvrow[j_type]</td><td>$jvrow[against]</td><td>$jvrow[no]</td></tr>";
        $jvtype=$jvrow['j_type'];
        $jvtranno=$jvrow['tr_no'];
        if($jvrow['j_type']=='CR' || $jvrow['j_type']=='CP' ||$jvrow['j_type']=='BP' || $jvrow['j_type']=='BR' || $jvrow['j_type']=='JV'|| $jvrow['j_type']=='TDSJV' || $jvrow['j_type']=='GST Credit Note' || $jvrow['j_type']=='CR Note')
            $ed='1';
        /* else
        $ed='0';*/
    }
    if($level>=4) 
    {
        if($ed==1)
        {
            if(($user=='mathew')||($user=='sreejith')||($user=='shameem')||($user=='thomas')||($user=='minosh')||($user=='vibin')||($user=='antony' && $brcode == 'PSN638') ||($brcode == 'PSN841'))
            {
                //echo $jvtype;
                //echo "<br>";
                if($jvtype=='BR')
                {
                    
                    if($jvtranno<='')
                    {
                        print "<td colspan=7 align=right></td>";
                    }
                    else
                    {
                        print "<td colspan=7 align=right><input type=button value='Edit' onClick=ed1('$row[jvno]','$row[date]','$df','$dto');></td>";
                    }
                }
                else
                {
                    print "<td colspan=7 align=right><input type=button value='Edit' onClick=ed1('$row[jvno]','$row[date]','$df','$dto');></td>";
                }
                print "<td><input type=button value='Del' onClick=ed2('$row[jvno]','$row[date]');></td><td><input type=button value='Preview' onClick=ed3('$row[jvno]','$row[date]');></td></tr>";
            }
        }
    }
    print "<tr><td colspan=9 bgcolor=silver></td></tr>";
}
?>
<script>
function ed1(jv,d,df,dto)
{
 if (confirm('Do you want to edit this entry?'))
  document.location='multientry/editjour.php?jvno='+jv+'&dt='+d+'&df='+df+'&dto='+dto;
}
 
function ed2(jv,d)
{
 if (confirm('Do you want to Delete this entry ?'))
  document.location='multientry/deljour.php?jvno='+jv+'&dt='+d;
}

function ed3(jv,d)
{
 if (confirm('Do you want to Print entry ?'))
  document.location='view.php?code='+jv;
}


</script>

