<?
session_start();
include('includes/config.php');
include('defs.php');

if(strlen($_SESSION['aid'])==0)
  { header('location:index.php');
}

$usr=$_SESSION['uname'];



 ?>

 <!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">

  <title>GLAKB  | Update Voucher Date</title>

  <!-- Google Font: Source Sans Pro -->
  <link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Source+Sans+Pro:300,400,400i,700&display=fallback">
  <!-- Font Awesome -->
  <link rel="stylesheet" href="../plugins/fontawesome-free/css/all.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="../dist/css/adminlte.min.css">
  <!--Function Email Availabilty---->

</head>
<body class="hold-transition sidebar-mini">
<div class="wrapper">
  <!-- Navbar -->
<?php include_once("includes/navbar.php");?>
  <!-- /.navbar -->

  <!-- Main Sidebar Container -->
 <?php include_once("includes/sidebar.php");?>

 
  <div class="content-wrapper">


<?
$result12 = mysqli_query($link, "select Role from user_details where Name='$usr' ");
$row12=  mysqli_fetch_object($result12);
$role = $row12->Role;
if($role=='Operator')
{
$result = mysqli_query($link, "select Role from user_priv where Name='$usr' and Form='JV-Date' ");
$row=  mysqli_fetch_object($result);
$role = $row->Role;
if($role=='0')
{
{
echo"<center>";
echo"<br><br><br><br><br>";
echo"<img src='users.png' width='160' height='160'><br>";
echo "<font size=6 color=red><b>ACCESS DENIED!</b><br>";
echo "<font size=4 color=darkblue><b>You Do Not Have Permission to View This Page.</b><br>";
goto a;
}
}
}



echo "                <form name='jvsearch' action='' method=POST onSubmit='return formconfirm()'>";

              
              
              function getRealIpAddr()
{
    if (!empty($_SERVER['HTTP_CLIENT_IP']))   //check ip from share internet
    {
      $ip=$_SERVER['HTTP_CLIENT_IP'];
    }
    elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR']))   //to check ip is pass from proxy
    {
      $ip=$_SERVER['HTTP_X_FORWARDED_FOR'];
    }
    else
    {
      $ip=$_SERVER['REMOTE_ADDR'];
    }
    return $ip;
}

              
         /*
              
             if(!$bIsManager)
        {

ECHO "<BR><BR><BR><BR>";

                    echo "<center><img src='/images/stop.jpg'><br>";
echo "-<BR><BR><font size=4><b>YOU ARE NOT AUTHORIZED TO VIEW THIS PAGE!</b></font>";
echo "-<BR><BR><font SIZE=4><b>CONTACT WITH YOUR ADMINISTRATOR FOR MORE DETAILS</b></font>";
echo "-<BR><BR><font SIZE=4><b>THANKS!</b></font>";


                exit;
        }
        */
?>


 <html>
<head>
<style>
#customers {
  font-family: Times-Roman;
  border-collapse: collapse;
  width: 98%;
}

#customers td, #customers th {
  border: 1px solid #4444;
  padding: 4px;
}

#customers tr:nth-child(even){background-color:gainsboro ;}


#customers th {
  padding-top: 5px;
  padding-bottom: 5px;
  text-align: center;
background-color:dodgerblue;
    color: white;
}
</style>   
<link rel="stylesheet" href="css/style.css">


<script language="javascript">



   window.onload= function show()
                        {
                                if(document.jvsearch.strv.value=="")
                                        {

                                                document.jvsearch.strv.focus()
                                        }
                                        }




 function formconfirm() {
return confirm("You Clicked the Button. Continue?<? echo "$coursename";?>");
}

</script>
<table align="center" id="customers">
       
<tr>
    <th colspan="4"><font size="4">UPDATE VOUCHER'S DATE</th>

  </tr>

        <td><b><font size=4 color="black">Voucher No:</b></td>
     <td>

<?php
                                if(isset($_POST['strv']) && !isset($_POST['reset']) )
                                        {

                                                 $strv=$_POST['strv'];
                                                 echo "<input type='text' id='arv3' name='strv' size='25' value='$strv'/>";

                                        }
                                else
                                        {
                                                         echo "<input type='text' id='arv3' name='strv' size='25' value='$strv'/>";
                                        }
                                ?>
<input type="submit" name="submit" value="    View    " /></td>
                             

<?
$strvoucher= Date("Y-m-d");

 AddDate("<font size=3 color=black><b>New Date : </b>", "strFrom", "$strvoucher", 25, 10, 0);
?>
<input type="submit" name="del" value="   Update   " />
</td>
                             <?
                                if(isset($_POST['submit']))
        {
        
         $strv=$_POST['strv'];
$strQuery = "select M_Head, D_Date,code,Details,Debit,Credit, A_Id, Chq from ledgers where vch_number='$strv' order by ID";
?>
<table align="center" id="customers">
       <BR>
<tr>
    <th colspan="8"><font size="4">VOUCHER DETAILS</th>

  </tr>
  <?                                            
           echo "        <td align=center>";
           

        echo "                <b><font size=3 color=darkblue>Date</b>";
        echo "        </td>";
 echo "        <td align=center>";
        
        echo "                <b><font size=3 color=darkblue>Cost Center</b>";
        echo "        </td>";
        echo "        <td align=center>";
        echo "                <b><font size=3 color=darkblue>Accounts Code</b>";
        echo "        </td>";
        echo "        <td align=center>";
        echo "                <b><font size=3 color=darkblue>Accounts Head</b>";
        echo "        </td>";
        
        echo "        <td align=center>";
        echo "                <b><font size=3 color=darkblue>Remarks</b>";
        echo "        </td>";
        
echo "        <td align=center>";
        echo "                <b><font size=3 color=darkblue>Cheque No.</b>";
        echo "        </td>";
        

        echo "        <td align=center>";
        echo "                <b><font size=3 color=darkblue>Debit</b>";
        echo "        </td>";
         echo "        <td align=center>";
        echo "                <b><font size=3 color=darkblue>Credit</b>";


      echo"  </td>";


        echo "</tr>";
                                                             $nResult = mysqli_query($link, $strQuery);

                                        while($row = mysqli_fetch_object($nResult))
                                        {
                                                
$date = strtotime($row->D_Date);
$date = date("d-m-Y",$date);      

echo "<td align=center> <font size=3 color=black> $date</td>";
echo "<td align=center> <font size=3 color=black> $row->M_Head</td>";
echo "<td align=center> <font size=3 color=black> $row->A_Id</td>";
echo "<td align=center> <font size=3 color=black> $row->code</td>";
echo "<td align=center> <font size=3 color=black> $row->Details</td>";
echo "<td align=center> <font size=3 color=black> $row->Chq</td>";
echo "<td align=center> <font size=3 color=black> $row->Debit</td>";
echo "<td align=center> <font size=3 color=black> $row->Credit</td>";
      
                                                echo "</tr>";

     }



                                        }




if(isset($_POST['del']))
{
    $strv=$_POST['strv'];
      $ndate=$_POST['strFrom'];
if($strv=="" or $strv=='0')
{
   echo "<script language='javascript'>";
echo "alert('Invalid Voucher Number!')";
echo "</script>";
exit;

}

/*

 date_default_timezone_set ("Asia/Karachi");
$the_time =date("H:i:s A", time());

  $d_date=date("Y-m-d",time());

  $ip=getRealIpAddr();
  

  $strQuery2 = "select D_Date,sum(Debit) as deb,sum(Credit) as cre, vch_number, Usr from ledgers where vch_number='$strv' group by vch_number";
  $nResult2 = mysqli_query($link, $strQuery2);

                                        while($row2 = mysqli_fetch_object($nResult2))
                                        {
                                        $dat=$row2->D_Date;
                                        $deb=$row2->deb;
                                        $cre=$row2->cre;
                                        $vno=$row2->vch_number;
                                        $e_usr=$row2->Usr;
                                        }
                                        
                                        
 mysqli_query($link, "insert into usr(vch_number, time, d_date, name, vch_date, deb, cre, e_usr, ip) values ('$vno','$the_time','$d_date','$usr1','$dat','$deb','$cre','$e_usr','$ip')");
*/
$result = mysqli_query($link, "update ledgers set D_Date='$ndate' where vch_number = '$strv'");
echo "<script language='javascript'>";
echo "alert('Voucher Date Updated Successfully!')";
echo "</script>";
}


                                        ?>






<?
a:
        include "footer.php";
?>
</div>
<!-- ./wrapper -->

<!-- jQuery -->
<script src="../plugins/jquery/jquery.min.js"></script>
<!-- Bootstrap 4 -->
<script src="../plugins/bootstrap/js/bootstrap.bundle.min.js"></script>
<!-- bs-custom-file-input -->
<script src="../plugins/bs-custom-file-input/bs-custom-file-input.min.js"></script>
<!-- AdminLTE App -->
<script src="../dist/js/adminlte.min.js"></script>
<!-- AdminLTE for demo purposes -->
<script src="../dist/js/demo.js"></script>
<!-- Page specific script -->
<script>
$(function () {
  bsCustomFileInput.init();
});
</script>
</body>
</html>
<?php  ?>