<?
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  | Edit / Delete Recoveries</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-Search' ");
$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;
}
}
}

?>
<form name="voucher" method="post" onsubmit="return confirm('Are you sure you want to Continue');">

<?
                 
                ?>

<script language="javascript">
           window.onload= function show()
                        {
                                if(document.voucher.strvoucher.value =="")
                                        {

                                                document.voucher.strvoucher.focus()
                                        }
                                        }
</script>

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

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

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


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


<table align="center" id="customers">
       
<tr>
    <th colspan="4"><font size="5">EDIT / DELETE CASH RECOVERY VOUCHERS</th>

  </tr>
                 <td colspan="2"><b><font size=4 color="black">Enter Voucher No:</b>
                 <?php
                                if(isset($_POST['strvoucher']) && !isset($_POST['reset']) )
                                        {

$strvoucher=$_POST['strvoucher'];
echo "<input type='text' id='strvoucher' name='strvoucher' onfocus='this.select()' size='15' value='$strvoucher'/>";
}
else
{
echo "<input type='text' id='strvoucher' name='strvoucher' onfocus='this.select()' size='15' value='$strvoucher'/>";
}
?>


<input type="submit" name="submit" value="    Show    " style="background: lightblue; color:black; border:2px solid #007BFF; padding:2px 20px; border-radius:5px;">
<input type="submit" name="dell" value="Delete Complete Voucher" style="background: lightblue; color:black; border:2px solid #007BFF; padding:2px 20px; border-radius:5px;">
</td>
<td>
<?
   $strvoucher = Date("Y-m-d");
if(isset($_POST['strdate']) && !isset($_POST['reset']) )
                                        {

   $strvoucher=$_POST['strdate'];
 AddDate1("<b><font size=4 color=black>(or) Select Date: </b> &nbsp;", "strdate", $strvoucher, 10, 10, 0);         
     
                                        }
                                else
                                        {
  AddDate1("<b><font size=4 color=black>(or) Select Date: </b> &nbsp;", "strdate", $strvoucher, 10, 10, 0);         
                                           }


?>

<input type="submit" name="dsubmit" value="    Show    " style="background: lightblue; color:black; border:2px solid #007BFF; padding:2px 20px; border-radius:5px;"/>

</td>


 </tr>
         <?
        
         
if(isset($_POST['dell']))
{
$strvoucher=$_POST['strvoucher'];
$query=mysqli_query($link,"delete from ledgers where vch_number='$strvoucher' ");
if($query){
echo "<script>alert('Voucher Deleted Successfully.');</script>";
echo "<script type='text/javascript'> document.location = 'v_search.php'; </script>";
}
}         
                  
         
         
         
if(isset($_POST['submit']))
{
$strvoucher=$_POST['strvoucher'];

$sql1 = "SELECT * FROM ledgers where vch_number='$strvoucher'";
$q = $link->query($sql1);
if ($q->num_rows==0) 
{
echo "<script language='javascript'>";
echo "alert('Invalid Voucher Number!')";
echo "</script>";
goto donothing;
}



mysqli_query($link, "delete from tmp_vch where usr='$usr' ");
mysqli_query($link, "delete from edit_vch where c_usr='$usr' ");

$result = mysqli_query($link, "select * from ledgers where vch_number='$strvoucher' order by Id");
while($row = mysqli_fetch_object($result))
{
if($row->Debit=='0.00')
{
mysqli_query($link, "insert into tmp_vch (Code, Details, Credit, usr, M_Head, Pmode, Chq, A_Id) values ('$row->Code','$row->Details','$row->Credit','$usr','$row->M_Head','$row->Payment_To','$row->Salesman','$row->A_Id')");

$ddate = $row->D_Date;
$usr1 = $row->usr;
$ltype = $row->L_Type;

}

}

mysqli_query($link, "insert into edit_vch (Vch_Number, V_Date, usr, L_Type, c_usr) values ('$strvoucher','$ddate','$usr1','$ltype','$usr')");




$nResult1 = MySQLi_Query($link, "Select L_Type from ledgers where vch_number='$strvoucher'");
while($rstRow = mysqli_fetch_array($nResult1))
{
$typee= $rstRow['L_Type'];
}



        $strQuery = "select * from ledgers where vch_number='$strvoucher' order by Id ";
  ?>

<table align="center" id="customers">
       <br>
<tr>
    <th colspan="12"><font size="5">VOUCHER DETAILS</th>

  </tr>
<?          echo "        <td align=center>";
        echo "                <b><font size=4 color=darkblue>Date</b>";
        echo "        </td>";
        
        echo "        <td align=center>";
        echo "                <b><font size=4 color=darkblue>Accounts Category</b>";
        echo "        </td>";

        
echo "        <td align=center>";
        echo "                <b><font size=4 color=darkblue>Accounts Head</b>";
        echo "        </td>";
        echo "        <td align=center>";
        echo "                <b><font size=4 color=darkblue>Remarks</b>";
        echo "        </td>";
echo "        <td align=center>";
        echo "                <b><font size=4 color=darkblue>Debit</b>";
        echo "        </td>";
         echo "        <td align=center>";
        echo "                <b><font size=4 color=darkblue>Credit</b>";

      echo"  </td>";
      
      echo "        <td align=center>";
        echo "                <b><font size=4 color=darkblue>Entry By</b>";

      echo"  </td>";
 echo "        <td align=center>";
        echo "                <b><font size=4 color=darkblue>Vch View</b>";

      echo"  </td>";
      echo "        <td align=center>";
        echo "                <b><font size=4 color=darkblue>Edit Vch</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->Code</td>";
echo "<td align=center> <font size=3 color=black> $row->Details</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 "<td align=center> <font size=3 color=black> $row->usr</td>";


echo "<td align=center><a href =rep_cash1.php?vch_number=$strvoucher target='_blank'><img src='viw.png' width='30' height='30'></a></td>";
?>
<td align="center">
 <a href="cash_rec2.php?tid=<?php echo $row->vch_number;?>" title="Edit Voucher Details"> <i class="fa fa-edit" aria-hidden="true" align=center></i> </a>
</td>
<?    

                                                echo "</tr>";

    
}

donothing:
?>
<script language="javascript">

document.voucher.strvoucher.focus()

</script>



<?
     

                                        }
                                        ?>
                     <?

if(isset($_POST['dsubmit']))
        {
        
$date = strtotime($_POST['strdate']);
$date = date("Y-m-d",$date);
$strQuery = "select L_Type, vch_number, vch, D_Date,Code,Details,sum(Debit) as deb,sum(Credit) as cre, usr, V_Time from ledgers where D_Date='$date' and vch_number<>'0' group by vch_number order by vch_number";

  ?>

<table align="center" id="customers">
       <br>
<tr>
    <th colspan="8"><font size="5">VOUCHER DETAILS</th>

  </tr>
<?

echo "        <td align=center>";
        echo "                <b><font size=4 color=darkblue>Date</b>";
        echo "        </td>";
 

           echo "        <td align=center>";
        echo "                <b><font size=4 color=darkblue>Voucher No.</b>";
        echo "        </td>";

           echo "        <td align=center>";
        echo "                <b><font size=4 color=darkblue>Voucher Details</b>";
        echo "        </td>";
         echo "        <td align=center>";
        echo "                <b><font size=4 color=darkblue>Voucher Type</b>";
        echo "        </td>";
  

         echo "        <td align=center>";
        echo "                <b><font size=4 color=darkblue>Total Recoveries</b>";
echo "        </td>";
echo "        <td align=center>";
        echo "                <b><font size=4 color=darkblue>Entry By</b>";
echo "        </td>";
echo "        <td align=center>";
        echo "                <b><font size=4 color=darkblue>Entry Time</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=4 color=black> $date</td>";
echo "<td align=center> <font size=4 color=black> $row->vch_number</td>";
echo "<td align=center> <font size=4 color=black> $row->vch</td>";

echo "<td align=center> <font size=4 color=black> $row->L_Type</td>";
echo "<td align=center> <font size=4 color=black> $row->cre</td>";
echo "<td align=center> <font size=4 color=black> $row->usr</td>";
echo "<td align=center> <font size=4 color=black> $row->V_Time</td>";
echo "</tr>";

     }

     

                                        }
                                        ?>


                                                </td>





                                </tr>

                </center>





         <?

            echo "</form>";
 
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  ?>