<?
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 Sales </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-Sales' ");
$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 CUSTOMER SALES</th>

  </tr>
                 <td colspan="2"><b><font size=4 color="black">Enter Invoice No (Only Digit Number):</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_No2='$lid' ");
$query=mysqli_query($link,"delete from cust_sales where Inv_No='$lid' ");
$query=mysqli_query($link,"delete from s_details where Inv_No='$lid' ");

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


}
}         
                  
if($_GET['action']=='edit'){
$lid=intval($_GET['tid']);
$query=mysqli_query($link,"delete from temp_sinv");

$result420 = mysqli_query($link, "select * from cust_sales where Inv_No='$lid'");
while($row  = mysqli_fetch_array($result420))
{
mysqli_query($link, "insert into temp_sinv (Name, Warehouse, Inv_Type, Unit_Liter, Carton_Qty, Qty, Tunit, Carton, Rate, N_Rate, Stax, S_Amt, Total, G_Total, N_Total, addby, D_Amt, R_Dis) values ('$row[Name]','$row[Warehouse]','$row[Inv_Type]','$row[Unit_Liter]','$row[Carton_Qty]','$row[Qty]','$row[Tunit]','$row[Carton]','$row[Rate]','$row[N_Rate]','$row[Stax]','$row[S_Amt]','$row[Total]','$row[G_Total]','$row[N_Total]','$usr','$row[D_Amt]','$row[R_Dis]')");

}

if($query){
echo "<script type='text/javascript'> document.location = 'edit_sales.php'; </script>";


}
}         

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

$sql1 = "SELECT * FROM s_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 s_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 No.</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>Customer Name</b>";
        echo "        </td>";

        
echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Customer Type</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>Discount</b>";
        echo "        </td>";
         echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Net Amount</b>";

      echo"  </td>";
       echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Salesman</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_Det</td>";

echo "<td align=center> <font size=2 color=black> $date</td>";
echo "<td align=center> <font size=2 color=black> $row->Customer</td>";
echo "<td align=center> <font size=2 color=black> $row->Inv_Type</td>";
echo "<td align=center> <font size=2 color=black> $row->Total</td>";
echo "<td align=center> <font size=2 color=black> $row->Dis</td>";
echo "<td align=center> <font size=2 color=black> $row->N_Total</td>";
echo "<td align=center> <font size=2 color=black> $row->Salesman</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_sales.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 s_details where Inv_Date='$date' order by Inv_No";

  ?>

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

  </tr>
<?

echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Invoice No.</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>Customer Name</b>";
        echo "        </td>";

        
echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Customer Type</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>Discount</b>";
        echo "        </td>";
         echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Net Amount</b>";

      echo"  </td>";
       echo "        <td align=center>";
        echo "                <b><font size=2 color=darkblue>Salesman</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_Det</td>";

echo "<td align=center> <font size=2 color=black> $date</td>";
echo "<td align=center> <font size=2 color=black> $row->Customer</td>";
echo "<td align=center> <font size=2 color=black> $row->Inv_Type</td>";
echo "<td align=center> <font size=2 color=black> $row->Total</td>";
echo "<td align=center> <font size=2 color=black> $row->Dis</td>";
echo "<td align=center> <font size=2 color=black> $row->N_Total</td>";
echo "<td align=center> <font size=2 color=black> $row->Salesman</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_sales.php?action=delete&&tid=<?php echo $row->Inv_No; ?>" style="color:red;" title="Edit Invoice" 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  ?>