<?
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  | Delete Purchases </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='Del-Purchase' ");
$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='voucher' method=POST>";
                ?>

<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: 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">


<table align="center" id="customers">
       
<tr>
    <th colspan="4"><font size="4">DELETE COMPANY PURCHASES</th>

  </tr>
                 <td colspan="2"><b><font size=4 color="black">Enter Invoice 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    " /></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 Invoice Date: </b> &nbsp;", "strdate", $strvoucher, 10, 10, 0);         
     
                                        }
                                else
                                        {
  AddDate1("<b><font size=4 color=black>(or) Select Invoice Date: </b> &nbsp;", "strdate", $strvoucher, 10, 10, 0);         
                                           }


?>





<input type="submit" name="dsubmit" value="    Show    " /></td>
 </tr>
         <?
         
if($_GET['action']=='delete'){
$lid=intval($_GET['tid']);
//$profilepic=$_GET['profilepic'];
//$ppicpath="teacherspic"."/".$profilepic;
$query=mysqli_query($link,"delete from ledgers where Inv_No='$lid' and L_Type='Finished Purchases' ");
$query=mysqli_query($link,"delete from purchases where Inv_No='$lid' ");
$query=mysqli_query($link,"delete from p_details where Inv_No='$lid' ");
$query=mysqli_query($link,"delete from raw_sales where Inv2='$lid' ");


if($query){
//unlink($ppicpath);
echo "<script>alert('Invoice Details Deleted Successfully.');</script>";
echo "<script type='text/javascript'> document.location = 'del_purchase.php'; </script>";


}
}         
                  
         
         
         
if(isset($_POST['submit']))
{
$strvoucher=$_POST['strvoucher'];

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




$strQuery = "Select * from p_details where Inv_No='$strvoucher' ";
       
?>

<table align="center" id="customers">
       <br>
<tr>
    <th colspan="12"><font size="3">Invoice Details</th>

  </tr>
<?


           echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Invoice Date</b>";
        echo "        </td>";
        
        echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Company Name</b>";
        echo "        </td>";

        
        echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Total Amount</b>";
        echo "        </td>";
echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Federal Tax</b>";
        echo "        </td>";
         echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Sales Tax</b>";

      echo"  </td>";
       echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Net Total</b>";

      echo"  </td>";
       echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>DC#</b>";

      echo"  </td>";
     
       echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Warehouse</b>";

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

      echo"  </td>";
     echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Delete Invoice</b>";

      echo"  </td>";
     

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

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

echo "<td align=center> <font size=2 color=black> $date</td>";
echo "<td align=center> <font size=2 color=black> $row->Company</td>";
echo "<td align=center> <font size=2 color=black> $row->Total</td>";
echo "<td align=center> <font size=2 color=black> $row->F_Amt</td>";
echo "<td align=center> <font size=2 color=black> $row->S_Amt</td>";

echo "<td align=center> <font size=2 color=black> $row->N_Total</td>";
echo "<td align=center> <font size=2 color=black> $row->DC_No</td>";

echo "<td align=center> <font size=2 color=black> $row->Warehouse</td>";
echo "<td align=center> <font size=2 color=black> $row->addby</td>";
 ?>
<td align=center>
 <a href="del_purchase.php?action=delete&&tid=<?php echo $row->Inv_No; ?>" style="color:red;" title="Delete Voucher" onclick="return confirm('Do you really want to delete this Voucher?');"><i class="fa fa-trash" aria-hidden="true"></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 * from p_details where Inv_Date='$date' order by Inv_No";

  ?>

<table align="center" id="customers">
       <br>
<tr>
    <th colspan="12"><font size="3">Invoice Details</th>

  </tr>
<?


           echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Invoice#</b>";
        echo "        </td>";
        
           echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Invoice Date</b>";
        echo "        </td>";
        
        echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Company Name</b>";
        echo "        </td>";

        
        echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Total Amount</b>";
        echo "        </td>";
echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Federal Tax</b>";
        echo "        </td>";
         echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Sales Tax</b>";

      echo"  </td>";
       echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Net Total</b>";

      echo"  </td>";
       echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>DC#</b>";

      echo"  </td>";
     
       echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Warehouse</b>";

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

      echo"  </td>";
     echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Delete Invoice</b>";

      echo"  </td>";
     

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

                                        while($row = mysqli_fetch_object($nResult))
                                        {
$date = strtotime($row->Inv_Date);
$date = date("d-m-Y",$date);      
echo "<td align=center> <font size=2 color=black> $row->Inv_No</td>";

echo "<td align=center> <font size=2 color=black> $date</td>";
echo "<td align=center> <font size=2 color=black> $row->Company</td>";
echo "<td align=center> <font size=2 color=black> $row->Total</td>";
echo "<td align=center> <font size=2 color=black> $row->F_Amt</td>";
echo "<td align=center> <font size=2 color=black> $row->S_Amt</td>";

echo "<td align=center> <font size=2 color=black> $row->N_Total</td>";
echo "<td align=center> <font size=2 color=black> $row->DC_No</td>";

echo "<td align=center> <font size=2 color=black> $row->Warehouse</td>";
echo "<td align=center> <font size=2 color=black> $row->addby</td>";
 ?>
<td align=center>
 <a href="del_purchase.php?action=delete&&tid=<?php echo $row->Inv_No; ?>" style="color:red;" title="Delete Voucher" onclick="return confirm('Do you really want to delete this Voucher?');"><i class="fa fa-trash" aria-hidden="true"></i> </a>
</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  ?>