<?
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  | View Purchase Orders</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;
$mrole = $row12->Role;
if($role=='Operator')
{
$result = mysqli_query($link, "select Role from user_priv where Name='$usr' and Form='View-Orders' ");
$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='m_head' action=''  method=POST >";


              ?>
<script language="javascript" type="text/javascript">

   window.onload= function show()
                        {
                                if(document.m_head.strdept.value =="")
                                        {

                                                document.m_head.strdept.focus()
                                        }
                                        }
                                        



  function show_cbo1()
                {
                        var val = document.getElementById('item3').value;
                        
                        location.href = "search.php?Name="+val;
                }

function formconfirm() {


if((document.m_head.item3.value) == '')
{
alert("Please Seelct Category to Search!");
document.m_head.item3.focus();
return false;
}


    if((document.m_head.strdept.value) == '')
        
    {
            alert("Please Enter Search Value!");
document.m_head.strdept.focus();

            return false;
        }

    



return true;
}
  </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="6"><font size="5">PURCHASE ORDER STATUS DETAILS</th>

  </tr> 
                           
  <tr>                         
<td>     
<?



$strvoucher1= Date("Y-m-d");

if(isset($_POST['strDate1']) && !isset($_POST['reset']) )
{
$strvoucher1=$_POST['strDate1'];
AddDate1("<b><font size=3 color=black>From Date: </b> &nbsp;", "strDate1", $strvoucher1, 10, 10, 0);         
}
else
{
AddDate1("<b><font size=3 color=black>From Date: </b> &nbsp;", "strDate1", $strvoucher1, 10, 10, 0);         
}
?>

<?


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

if(isset($_POST['strDate']) && !isset($_POST['reset']) )
{
$strvoucher=$_POST['strDate'];
AddDate1("<b><font size=3 color=black>To Date: </b> &nbsp;", "strDate", $strvoucher, 10, 10, 0);         
}
else
{
AddDate1("<b><font size=3 color=black>To Date: </b> &nbsp;", "strDate", $strvoucher, 10, 10, 0);         
}

?> 


 <input type="submit" name="save1" value="Show Orders" style="background: none; color:#007BFF; border:2px solid #007BFF; padding:2px 20px; border-radius:5px;">

</tr>
</table>
         
  
<?
if($_GET['action']=='delete'){
$lid=intval($_GET['tid']);
//$profilepic=$_GET['profilepic'];
//$ppicpath="teacherspic"."/".$profilepic;
$query=mysqli_query($link,"delete from porder where Inv_No='$lid' ");

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


}
}         
               


if(isset($_POST['save1']))
        {


$frm = strtotime($_POST['strDate1']);
$frm = date("Y-m-d",$frm);

$to = strtotime($_POST['strDate']);
$to = date("Y-m-d",$to);


$result = mysqli_query($link, "SELECT Inv_Date, addby, Warehouse, Salesman, Inv_No, Customer, City, Sum(Total) as tot, Sum(G_Total) as tot1, Sum(N_Total) as tot2, Sum(R_Dis) as tdis, Status, Reason  FROM porder where Inv_Date between '$frm' and '$to' Group by Inv_No order by Inv_No");



?>


 <table align="center" id="customers">
 <br>

<tr>
<th colspan="17"><font size="4">PURCHASE ORDER DETAILS</th>

  </tr> 
                           
  <tr>                         
     
<?


 echo "        <tr>";
        
                echo "        <td align=center>";
          echo "                <b><font size=3 color=darkblue> S.No </b>";
        echo "        </td>";

echo "        <td align=center>";
        echo "                <b><font size=3 color=darkblue>Order Date</b>";
        echo "        </td>";
   
echo "        <td align=center>";
        echo "                <b><font size=3 color=darkblue>Warehouse</b>";
        echo "        </td>";
echo "        <td align=center>";
        echo "                <b><font size=3 color=darkblue>Order#</b>";
        echo "        </td>";

           echo "        <td align=center>";
        echo "                <b><font size=3 color=darkblue>Customer Name</b>";
        echo "        </td>";
         echo "        <td align=center>";
        echo "                <b><font size=3 color=darkblue>Customer City</b>";
        echo "        </td>";
         echo "        <td align=center>";
        echo "                <b><font size=3 color=darkblue>Total</b>";
        echo "        </td>";
 echo "        <td align=center>";
        echo "                <b><font size=3 color=darkblue>Discount</b>";
        echo "        </td>";
    
             echo "        <td align=center>";
        echo "                <b><font size=3 color=darkblue>Net Total</b>";
        echo "        </td>";

       echo "        <td align=center>";
        echo "                <b><font size=3 color=darkblue>Salesman</b>";
        echo "        </td>";
      
     
        echo "        <td align=center>";
        echo "                <b><font size=3 color=darkblue>Order By</b>";
        echo "        </td>";
          
 echo "        <td align=center>";
        echo "                <b><font size=3 color=darkblue>Re-Print Order</b>";
        echo "        </td>";
     
echo "        <td align=center>";
        echo "                <b><font size=3 color=darkblue>Delete Order</b>";
        echo "        </td>";
echo "        <td align=center>";
        echo "                <b><font size=3 color=darkblue>Order Status</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>Process Invoice</b>";
        echo "        </td>";

        echo "</tr>";
        $count=0;
        $one=1;
        $pmma=0;
$pdis=0;
$tot=0;
$tons=0;


                                        while($row = mysqli_fetch_object($result))
                                        {
                                        $count=$one+$count;
               
$dte = strtotime($row->Inv_Date);
$dte = date("d-m-Y",$dte);

$sts=$row->Status;
if($sts=='N')
{
$asts='Approval Pending';
}

elseif($sts=='Y')
{
$asts='Approved';
}

elseif($sts=='C')
{
$asts='Dis-Approved';
}

elseif($sts=='D')
{
$asts='Invoice Done';
}

$tot=$row->Total+$tot;
$tons=$row->N_Total+$tons;
$tdis=$row->Dis+$tdis;


echo "<td align=center><font size=3 color=black>$count</td>";
echo "<td align=center><font size=3 color=black>$dte</td>";
echo "<td align=center><font size=3 color=black>$row->Warehouse</td>";
echo "<td align=center><font size=3 color=black>$row->Inv_No</td>";
echo "<td align=center><font size=3 color=black>$row->Customer</td>";
echo "<td align=center><font size=3 color=black>$row->City</td>";

echo "<td align=center><font size=3 color=black>$row->tot1</td>";
echo "<td align=center><font size=3 color=black>$row->tdis</td>";
echo "<td align=center><font size=3 color=black>$row->tot2</td>";
echo "<td align=center><font size=3 color=black>$row->Salesman</td>";

echo "<td align=center><font size=3 color=black>$row->addby</td>";

echo "<td align=center><a href =rep_order1.php?inv=$row->Inv_No target='_blank'><img src='viw.png' width='30' height='30'></a></td>";

if($asts=='Approval Pending')
{
?>
<td align=center>
 <a href="view_orders.php?action=delete&&tid=<?php echo $row->Inv_No; ?>" style="color:red;" title="Delete Order" onclick="return confirm('Do you really want to delete this Order?');"><i class="fa fa-trash" aria-hidden="true"></i> </a>
</td>
<?
}
else{
echo "<td align=center>";
    
}
echo "<td align=center><font size=3 color=black>$asts</td>";
echo "<td align=center><font size=3 color=black>$row->Reason</td>";

if($asts=='Approved')
{
echo "<td align=center><a href =process.php?inv=$row->Inv_No><img src='images/c.png' width='30' height='30'></a></td>";
}

elseif($asts=='Approval Pending')
{
echo "<td align=center></td>";
}

elseif($asts=='Dis-Approved')
{
echo "<td align=center>";

}

elseif($asts=='Invoice Done')
{
echo "<td align=center>";

}

echo "</tr>";
}
 
  echo "
                                </form>
                                </table>
                        ";

}

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  ?>