<?
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 Product Details</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">
<?
$usr=$_SESSION['uname'];
$idd=$_GET['tid'];


echo "                <form name='sub_head' action='' method=POST onSubmit='return  validateForm();'>";




?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
 
  

  <!-- 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">
  <!-- DataTables -->
  <link rel="stylesheet" href="../plugins/datatables-bs4/css/dataTables.bootstrap4.min.css">
  <link rel="stylesheet" href="../plugins/datatables-responsive/css/responsive.bootstrap4.min.css">
  <link rel="stylesheet" href="../plugins/datatables-buttons/css/buttons.bootstrap4.min.css">
  <!-- Theme style -->
  <link rel="stylesheet" href="../dist/css/adminlte.css">
</head>


              <div class="card-body">
 
 
    
<style>

 

       
        .input-box {
            width: 100%;
            padding: 4px;
            margin-top: 2px;
            margin-bottom: 2px;
            border: 2px solid gainsboro;
            border-radius: 4px;
            font-size: 16px;

        }



#customers {
  font-family: Times-Roman;
  border-collapse: collapse;
  width: 80%;
}

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

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


#customers th {
  padding-top: 8px;
  padding-bottom: 8px;
  text-align: center;
  background-color:royalblue;
  color: white;
}
</style>   


<script language="javascript">

 function formconfirm() {
return confirm("Do you want to Save the Record?<? echo "$coursename";?>"); 
}

function processkey(e)
                {
                        var kc = (window.Event?e.which:e.keyCode)
                        if (kc >=48 && kc<= 57 || kc ==8 || kc == 46)
                                return true
                        else
                                return false

     
           }
function validateForm()
{
if((document.sub_head.item33.value) == '')
{
alert("Please Select Accounts Cost Center!");
document.sub_head.item33.focus();
return false;
}


if((document.sub_head.strcode.value) == '')
{
alert("Please Enter Accounts Code!");
document.sub_head.strcode.focus();
return false;
}

if((document.sub_head.strname.value) == '')
{
alert("Please Enter Accounts Head Name!");
document.sub_head.strname.focus();
return false;
}

return true;
}






                
</script>
<form name="voucher" method="POST" action="" >



<body>
<div id="content">
<div id="left">



   <link rel="stylesheet" href="css/style.css">


<?
$result = mysqli_query($link, "select * from products where Id='$idd'");
while($row  = mysqli_fetch_object($result))
{
        $full=$row->Full_Name;
$name=$row->Name;
$api=$row->API;
$grade=$row->Grade;
$pack=$row->Size;
$code=$row->Item_Code;
$pper=$row->DP;
$rper=$row->R_Price;
$wper=$row->W_Price;
$dper=$row->D_Price;
$lit=$row->Unit_Liter;
$cqty=$row->Carton_Qty;
$cqty=$row->Carton_Qty;
$rdate=$row->R_Date;
$ptype=$row->Item_Type;
$art=$row->Article;
$cate=$row->Category;
$pdtype=$row->Category2;

}                                
?>


<table align="center" id="customers">
       
<tr>
    <th colspan="6"><font size="5">EDIT PRODUCT DETAILS</th>

  </tr>


<td><b><font size=3 color="black">Product Code (PD000):</b></td>
<td>
<input type="text" name="strcode" id="strcode" value="<?php echo $code ?>" class="input-box" style='color: black; font-family: Times-Roman; background-color: lightblue; font-size:20px;' readonly  /></td>

  

<td><b><font size=3 color="black">Product Full Name:</b></td>
<td >
<input type="text" name="name" id="name" value="<?php echo $full ?>" class="input-box" readonly /></td>


  
<tr align="left">
<td><b><font size=3 color="black">Product Title:</b></td>
<td >
<input type="text" name="name" id="name" value="<?php echo $name ?>" class="input-box" /></td>

    

  

<td><b><font size=3 color="black">API:</b></td>
<td colspan="2">
<input type="text" name="api" id="api" value="<?php echo $api ?>" class="input-box" /></td>




<tr>
    <td><b><font size=3 color="black">Grade:</b></td>
                        <td>
    <select class="form-control" name="grade" id="grade" style=font-size="16" >
                                <option value="<?php echo $grade ?>"><?php echo $grade ?></option>
                                <?php 
                                if(isset($_GET['City']))
                                        {
                                                $City = $_GET['City'];
                                                
                                                
                
                                        }
                                else                        
                                        $City = "";
                                        
                                        //include('config.php');
$result = mysqli_query($link, "select Distinct Name from grades 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>
 

<td><b><font size=3 color="black">Product Packing:</font></b></td>
<td>
<select class="form-control" name=ptype>
<option value="<?php echo $ptype ?>"><?php echo $ptype ?></option>
<option value='Pack'>Pack</option>
<option value='Bucket'>Bucket</option>

<option value='Drum'>Drum</option>
<tr>


<td>
<b><font size=3 color="black">Liter per Unit:</b>

<?
echo "<td align=left><b><input type='text' name='lit' size='15' style='color: black; font-family: Times-Roman; background-color: lightblue; font-size:2' id='lit' value='$lit' onkeypress='return processkey(event)'>";

?>


<td>
<b><font size=3 color="black">Unit per Carton:</b>

<?
echo "<td align=left><b><input type='text' name='ucart' size='15' style='color: black; font-family: Times-Roman; background-color: lightblue; font-size:2' id='ucart' value='$cqty' onkeypress='return processkey(event)'>";

?>
<tr>


<td><b><font size=3 color="black">Size:</font></b></td>
<td>
<select class="form-control" name=pack>
<option value="<?php echo $pack ?>"><?php echo $pack ?></option>
<option value='3L X 4'>3L X 4</option>
<option value='4L X 4'>4L X 4</option>
<option value='6L X 3'>6L X 3</option>
<option value='1L X 12'>1L X 12</option>
<option value='1.5L X 12'>1.5L X 12</option>
<option value='700ml X 12'>700ml X 12</option>
<option value='500ml X 24'>500ml X 24</option>
<option value='6L X 1'>6L X 1</option>
<option value='8L X 1'>8L X 1</option>
<option value='8L X 2'>8L X 2</option>

<option value='10L X 1'>10L X 1</option>
<option value='20L X 1'>20L X 1</option>
<option value='208L X 1'>208L X 1</option>
<option value='210L X 1'>210L X 1</option>


</select>

  


<td>
<b><font size=3 color="black">Purchase Cost (Per Litre):</b>

<?
echo "<td align=left><b><input type='text' name='prate' size='15' style='color: black; font-family: Times-Roman; background-color: lightblue; font-size:2' id='prate' value='$pper' onkeypress='return processkey(event)'>";

?>

<tr>
<td>
<b><font size=3 color="black">Retail Price (Per Litre):</b>

<?
echo "<td align=left><b><input type='text' name='rrate' size='15' style='color: black; font-family: Times-Roman; background-color: lightblue; font-size:2' id='rrate' value='$rper' onkeypress='return processkey(event)'>";

?>



<td>
<b><font size=3 color="black">Dealer Price (Per Litre):</b>

<?
echo "<td align=left><b><input type='text' name='drate' size='15' style='color: black; font-family: Times-Roman; background-color: lightblue; font-size:2' id='drate' value='$dper' onkeypress='return processkey(event)'>";
?>
<tr>
<td>
<b><font size=3 color="black">Whole Sale Price (Per Litre):</b>

<?
echo "<td align=left><b><input type='text' name='wrate' size='15' style='color: black; font-family: Times-Roman; background-color: lightblue; font-size:2' id='wrate' value='$wper' onkeypress='return processkey(event)'>";





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



?>
<tr>



    <td><b><font size=3 color="black">Category:</b></td>
                        <td>
    <select class="form-control" name="cat" id="cat" style=font-size="16" >
                                <option value="<?php echo $cate ?>"><?php echo $cate ?></option>
                                <?php 
                                if(isset($_GET['Cat1']))
                                        {
                                                $Cat1 = $_GET['Cat1'];
                                                
                                                
                
                                        }
                                else                        
                                        $Cat1 = "";
                                        
                                        //include('config.php');
$result = mysqli_query($link, "select Distinct Name from category order by Name");
                                        while($row  = mysqli_fetch_object($result))
                                        {
                                                        if($Cat1 == $row->Name)
                                                        {
                                                                echo "<option value=\"$row->Name\" selected=\"selected\">$row->Name</option>";
                                                        }        
                                                        else
                                                        {
                                                                echo "<option value=\"$row->Name\">$row->Name</option>";
                                                        }
                                        }
                                ?>
                                </select>
 
<td>
<b><font size=3 color="black">Article #:</b>




<?
echo "<td align=left><b><input type='text' name='arti' size='15' style='color: black; font-family: Times-Roman; background-color: lightblue; font-size:2' id='arti' value='$art' onkeypress='return processkey(event)'>";
?>

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

<td colspan="2">



<tr>
<td colspan="5" align="center">
<input type="submit" name="save" value="Update Details" style="background: none; color:#007BFF; border:2px solid #007BFF; padding:2px 20px; border-radius:5px;">


<input type="submit" name="hme" value="Main Search Page" style="background: none; color:#007BFF; border:2px solid #007BFF; padding:2px 20px; border-radius:5px;">

  </td>

</table>



         
<?php


if(isset($_POST['hme']))
{
$link1 = "<script>window.open('prodview.php','_self')</script>";
echo $link1;
}


if(isset($_POST['save']))
{
date_default_timezone_set ("Asia/Karachi");
$date = date('d-m-Y (h:i:s a)', time());
$expdate = strtotime($_POST['strDate']);
$expdate = date("Y-m-d",$expdate);
$codee = $_POST['strcode'];
$name = $_POST['name'];
$api = $_POST['api'];
$grade = $_POST['grade'];
$ptype = $_POST['ptype'];
$lit = $_POST['lit'];
$ucart = $_POST['ucart'];
$pack = $_POST['pack'];
$prate = $_POST['prate'];
$rrate = $_POST['rrate'];
$wrate = $_POST['wrate'];
$drate = $_POST['drate'];
$cat = $_POST['cat'];
$arti = $_POST['arti'];
$pcm = $_POST['pcmo'];

$fname=$name." ".$grade." ".$lit."L";


$sql1 = "SELECT * FROM products where Full_Name='$fname' ";
$q = $link->query($sql1);
if ($q->num_rows == 1) 
{

$result = mysqli_query($link, "update products set API='$api', Item_Type='$ptype', Unit_Liter='$lit', Carton_Qty='$ucart', Size='$pack', R_Price='$rrate', W_Price='$wrate', D_Price='$drate', DP='$prate', R_Date='$expdate', Article='$arti', Category='$cat', Category2='$pcm' where Item_Code = '$codee' ");



goto donot1;
}




$result = mysqli_query($link, "update products set Name='$name', Grade='$grade', Full_Name='$fname', API='$api', Item_Type='$ptype', Unit_Liter='$lit', Carton_Qty='$ucart', Size='$pack', R_Price='$rrate', W_Price='$wrate', D_Price='$drate', DP='$prate', R_Date='$expdate', Article='$arti', Category='$cat', Category2='$pcm' where Item_Code = '$codee' ");



donot1:
echo "<script language='javascript'>";
echo "alert('Successfully Updated!')";
echo "</script>";

$link1 = "<script>window.open('edit_prod.php?tid=$idd','_self')</script>";
echo $link1;

donot:

}



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