<?
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  | Cash Sales Invoice</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='Inv-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='m_head' method=POST onSubmit='return validateForm()'>";


              ?>
              <html>
<head>
<style>
    
#customers1{
  font-family: Times-Roman;
  border-collapse: collapse;
  width: 60%;
}

#customers1 td, #customers1 th {
  border: 1px solid #4444;
  padding: 5px;
}

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


#customers1 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" type="text/javascript">

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

                                                document.m_head.ctype.focus()
                                        }
                                        }
                                        
function formconfirm() {
return confirm("Do You want to Continue?<? echo "$coursename";?>");
}

 
function validateForm()
{

if((document.m_head.city.value) == '')
{
alert("Please Select City First!");
document.m_head.city.focus();
return false;
}
if((document.m_head.cust.value) == '')
{
alert("Please Select Customer Name First!");
document.m_head.cust.focus();
return false;
}


return true;
}






function show_cbo4()
                {
                        var val = document.getElementById('city').value;
                           //var val3 = document.getElementById('strDate').value;
                      
                        location.href = "add_bill.php?City="+val;
                }

function show_cbo11()
                {
                        var val = document.getElementById('cust').value;
                         var val1 = document.getElementById('city').value;
                       
                           //var val3 = document.getElementById('strDate').value;
                      
                        location.href = "add_bill.php?M_Headc="+val+"&City="+val1;
                }


             







  </script>





 <table align="center" id="customers1">
       
<tr>
    <th colspan="6"><font size="5">CASH SALES INVOICES</th>

  </tr>               
       
                       
<!DOCTYPE html>
<html>
<head>
    
    <style>
        #suggestions {
            border: 2px solid #ccc;
            display: none;
            position: absolute;
            background-color: white;
            width: 300px;
            max-height: 250px;
            overflow-y: auto;
            z-index: 1000;
        }
        #suggestions div {
            padding: 3px;
            cursor: pointer;
        }
        #suggestions div:hover,
        #suggestions .selected {
            background-color: #f0f0f0;
        }
    </style>
</head>
<body>
<?
$result12 = mysqli_query($link, "select MAX(Inv_No) as inv from s_details" );
while($row12  = mysqli_fetch_object($result12))
{
$inv=$row12->inv+1;
}

echo "<td colspan=6 align=right>Invoice#  SIB-<input type='text' id='strinv' name='strinv' size='13' style='color: black; font-family: Times-Roman; background-color: lightblue; font-size:20px;' value='$inv' readonly   />";


?>

<tr>


<td align=left width="250" ><b><font size=3 color=black>Select Sales City:</b></td>
                        <td align=left>
                                <select class="form-control" name="city" id="city"  onchange="show_cbo4()">
                                <option value="">select</option>
                                <?php 
                                if(isset($_GET['City']))
                                        {
                                                $City = $_GET['City'];
                                                
                                                
                
                                        }
                                else                        
                                        $City = "";
                                        
                                        //include('config.php');
                                        $result = mysqli_query($link, "select Distinct Name from city order by Name");
                                        while($row  = mysqli_fetch_object($result))
                                        {
                                                        if($City == $row->Name)
                                                        {
                                                                echo "<option value=\"$row->Name\" selected=\"selected\">$row->Name</option>";
                                                        }        
                                                        else
                                                        {
                                                                echo "<option value=\"$row->Name\">$row->Name</option>";
                                                        }
                                        }
                                ?>
                                </select>

<tr>

<td align=left ><b><font size=3 color=black>Select Target Warehouse:</b></td>
                        <td align=left >
                                <select class="form-control" name="cust" id="cust"  onchange="show_cbo11()">
                                <option value="">select</option>
                                <?php 
                                if(isset($_GET['M_Headc']))
                                        {
                                                $M_Headc = $_GET['M_Headc'];
                                                
                                                
                
                                        }
                                else                        
                                        $M_Headc = "";
                                        
                                        //include('config.php');
                                        $result = mysqli_query($link, "select Distinct Name from warehouse order by Name");
                                        while($row  = mysqli_fetch_object($result))
                                        {
                                                        if($M_Headc == $row->Name)
                                                        {
                                                                echo "<option value=\"$row->Name\" selected=\"selected\">$row->Name</option>";
                                                        }        
                                                        else
                                                        {
                                                                echo "<option value=\"$row->Name\">$row->Name</option>";
                                                        }
                                        }
                                ?>
                                </select>

  
<tr>
<td><b><font size=3 color="black">Province:</font></b></td>
<td>
<select class="form-control" name=prov id=prov>
<option value='BALOCHISTAN'>BALOCHISTAN</option>
<option value='PUNJAB'>PUNJAB</option>
<option value='SINDH'>SINDH</option>
<option value='KPK'>KPK</option>

</select>
<tr>

<td align=left><b><font size=3 color=black>Product Pricing:</b></td>
                        <td align=left>
                                <select class="form-control" name="ctype" id="ctype" style=font-size="16" >
                                <option value="">select</option>
                                <?php 
                                if(isset($_GET['M_Headc']))
                                        {
                                                $M_Headc = $_GET['M_Headc'];
                                                
                                                
                
                                        }
                                else                        
                                        $M_Headc = "";
                                        
                                        //include('config.php');
                                        $result = mysqli_query($link, "select Distinct Title from customer_type order by Title");
                                        while($row  = mysqli_fetch_object($result))
                                        {
                                                        if($M_Headc == $row->Title)
                                                        {
                                                                echo "<option value=\"$row->Title\" selected=\"selected\">$row->Title</option>";
                                                        }        
                                                        else
                                                        {
                                                                echo "<option value=\"$row->Title\">$row->Title</option>";
                                                        }
                                        }
                                ?>
                                </select>


<tr>


           <td colspan="6" align="center">

<input type="submit" name="save" value="Proceed" style="background: none; color:#007BFF; border:2px solid #007BFF; padding:2px 20px; border-radius:5px;">
</td>

</form>
</table>

<form name="print" method="post">

 <table align="center" id="customers1">
       
<tr>
    <th colspan="6"><font size="4">PRINT LAST INVOICE</th>

  </tr>      

<td align="right" width="250">

<b><font size=4 align=center>Print Copies:   </b>
<select class="form-control" name="strrec" size="5">
<option value="Office Copy">Office Copy</option>
<option value="Salesman Copy">Salesman Copy</option>
<option value="Customer Copy">Customer Copy</option>
<option value="Complete Set">Complete Set</option>
<option value="DC Print">DC Print</option>

</select>

<?
$result2 = mysqli_query($link,"select MAX(Inv_No) as inv from s_details where addby = '$usr' ");
while($rstRow = mysqli_fetch_array($result2))
{
$inv_no=$rstRow['inv'];
}


$result3 = mysqli_query($link,"select Customer, Inv_N, Inv_Date from s_details where addby = '$usr' and Inv_No='$inv_no' ");
while($rstRow = mysqli_fetch_array($result3))
{
    $vend=$rstRow['Customer'];
    $invn=$rstRow['Inv_N'];
  $idte=$rstRow['Inv_Date'];
}

echo "<td align=left><b><input type='text' class='input-box' name='dued' size='35' style='color: black; font-family: Times-Roman; background-color: lightblue; font-size:2' id='dued' value='$vend' readonly >";

echo "<b><input type='text' class='input-box' name='dued' size='35' style='color: black; font-family: Times-Roman; background-color: lightblue; font-size:2' id='dued' value='Invoice# $invn-$inv_no Dated: $idte' readonly >";

?>


<input type="submit" name="print" value="View and Print" style="background: none; color:#007BFF; border:2px solid #007BFF; padding:2px 20px; border-radius:5px;">




</form>
</table>

 <?


if(isset($_POST['print']))
{
$tpe=$_POST['strrec'];
$result2 = mysqli_query($link,"select MAX(Inv_No) as inv from s_details where addby = '$usr' ");
while($rstRow = mysqli_fetch_array($result2))
{
$inv=$rstRow['inv'];
}

if($tpe=='Office Copy')
{
$link1 = "<script>window.open('inv_sales1.php?inv=$inv&cust=1','_blank')</script>";
echo $link1;
}

if($tpe=='Salesman Copy')
{
$link1 = "<script>window.open('inv_sales1.php?inv=$inv&cust=2','_blank')</script>";
echo $link1;
}

if($tpe=='Customer Copy')
{
$link1 = "<script>window.open('inv_sales1.php?inv=$inv&cust=3','_blank')</script>";
echo $link1;
}

if($tpe=='Complete Set')
{
$link1 = "<script>window.open('inv_comp.php?inv=$inv','_blank')</script>";
echo $link1;
}


if($tpe=='DC Print')
{
$link1 = "<script>window.open('dc1.php?inv=$inv','_blank')</script>";
echo $link1;
}
}



if(isset($_POST['save']))
{
date_default_timezone_set ("Asia/Karachi");
$date = date('d-m-Y (h:i:s a)', time());


$city=$_POST['city'];
$ware=$_POST['cust'];
$provi=$_POST['prov'];

$itype=$_POST['ctype'];

$result12 = mysqli_query($link, "select  A_Id from acc_heads where Name='CASH CUSTOMER' ");
while($row  = mysqli_fetch_object($result12))
{
$cid=$row->A_Id;
}      




mysqli_query($link, "delete from cust_details where addby='$usr' ");
 


mysqli_query($link, "insert into cust_details (Province, City, Customer, A_Id,  Ctype, Warehouse, addby) values ('$provi','$city','CASH CUSTOMER','$cid','$itype','$ware','$usr')");
  
 $link1 = "<script>window.open('attach_prod.php?tid=$usr','_self')</script>";
echo $link1;


       
         }


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