<?php session_start();
if($_SESSION[invcox] == ""){
header("location:login.php?action=need");
}else{

include("config.php");?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>A2Z Accounting Software</title>
<link href="style.css" rel="stylesheet" type="text/css" />
<SCRIPT language="JavaScript" type="text/javascript">

function validate()

{
	if(document.enquiryform.pname.value=="")

		{//alert ("Please type Product Code.")
			document.enquiryform.pname.focus()
			return false

		}
}

function validate2()

{
	if(document.form1.product.value=="")

		{
			alert ("Please Select Product .")
			document.form1.product.focus()
			return false

		}
		
	if(document.form1.product_type.value=="")

		{
			alert ("Please Type product type .")
			document.form1.product_type.focus()
			return false

		}
	if(document.form1.product_model.value=="")

		{
			alert ("Please Type product model .")
			document.form1.product_model.focus()
			return false

		}
	if(document.form1.product_code.value=="")

		{
			alert ("Please Type product code.")
			document.form1.product_code.focus()
			return false

		}
}
function validate3()

{
	if(document.form2.pname2.value=="")

		{
			alert ("Please Type Product .")
			document.form2.pname2.focus()
			return false

		}
		
	if(document.form2.product_type2.value=="")

		{
			alert ("Please Type product type .")
			document.form2.product_type2.focus()
			return false

		}
	if(document.form2.product_model2.value=="")

		{
			alert ("Please Type product model .")
			document.form2.product_model2.focus()
			return false

		}
	if(document.form2.product_code2.value=="")

		{
			alert ("Please Type product code.")
			document.form2.product_code2.focus()
			return false

		}
}
function formfile(){
var pmodo=document.form1.pmodo.value;
document.form1.product_model.value=pmodo;
}

function formfile1(){
var ptyp=document.form1.ptyp.value;
document.form1.product_type.value=ptyp;
}
function formfile3(){
var pmodo=document.form2.pmodo2.value;
document.form2.product_model2.value=pmodo;
}

function formfile2(){
var ptyp=document.form2.ptyp2.value;
document.form2.product_type2.value=ptyp;
}
</SCRIPT>
</head>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<body>

<table width="95%" border="0" align="center" cellpadding="0" cellspacing="1" class="box-wrap">
  <tr>
    <td><?php include("top.php");?></td>
  </tr>
  <tr>
    <td bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="1" cellpadding="0">
        <tr>
          <td height="30" align="left" background="images/place_bg.jpg" class="link2"><strong>&nbsp;<a href="index.php">Home</a> &gt; <a href="inventory.php">Inventory</a></strong> &gt; <a href="add_product.php"><strong> Product Entry </strong></a></td>
        </tr>
        <tr>
          <td align="center">&nbsp;</td>
        </tr>
        <tr>
          <td>&nbsp;</td>
        </tr>
		<?php 
		if($_GET[action] == 'edit'){
		?>
        <tr>
          <td><form action="restaurant_update_pname.php" method="post" enctype="multipart/form-data" name="form2" id="form2" onsubmit="return validate3()">
            <table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">
              <tr>
                <td height="25" colspan="2" bgcolor="#CCCCCC"><strong>Edit   Product details (Model, Type, Code, etc) </strong></td>
              </tr>
			  <?php 
			 
			$result=mysql_query("select * from restaurant_product_details  WHERE id='$_GET[id]' limit 1");
			$row=mysql_fetch_array($result);
			  ?>
              <tr>
                <td width="17%" height="37" bgcolor="#FFFFFF">Product Name : </td>
                <td bgcolor="#FFFFFF" class="input200"><input name="pname2" type="text" id="pname2" value="<?php echo $row[pname];?>" />
                  <input name="id" type="hidden" id="id" value="<?php echo $row[id];?>" /></td>
                </tr>
              <tr>
                <td height="30" bgcolor="#FFFFFF">Product item : </td>
                <td bgcolor="#FFFFFF" class="input200"><input name="product_item2" type="text" id="product_item2" value="<?php echo $row[product_item];?>" size="20" />
                  <input name="pdid" type="hidden" id="pdid" value="<?php echo $row[id];?>" /></td>
                </tr>
              <tr>
                <td height="30" bgcolor="#FFFFFF">Sale Rate :</td>
                <td bgcolor="#FFFFFF"><input name="sale_rate2" type="text" id="sale_rate2" value="<?php echo $row[sale_rate];?>" size="25" /></td>
              </tr>
                <tr>
                  <td height="30" bgcolor="#FFFFFF">Sr:</td>
                  <td bgcolor="#FFFFFF"><input name="sr2" type="text" id="sr2" value="<?php echo $row[sr];?>" size="25" /></td>
                </tr>
                <tr>
                  <td height="30" bgcolor="#FFFFFF">Material</td>
                  <td bgcolor="#FFFFFF"><table width="300" border="0" cellpadding="3" cellspacing="1" class="list_table">
                    <tbody>
                      <tr>
                        <td width="391">Material</td>
                        <td width="94">Qty</td>
                      </tr>
                      <tr>
                        <td><select name="meterial_11" id="meterial_11" data-placeholder="Select Product Category" class="category" >
                          <option value="0">Select Product Category</option>
                          <?php 

				  $cresult=mysql_query("select * from meterial_category  order by name ASC");

			$crow=mysql_fetch_array($cresult);

			do{

				  ?>
                          <option value="<?php echo $crow[id]; ?>" <?php if($row[meterial_1] == $crow[id]){echo 'selected="selected"';}?>><?php echo $crow[name]; ?></option>
                          <?php }while($crow=mysql_fetch_array($cresult));?>
                        </select></td>
                        <td><input name="meterial_qty11" type="number" value="<?php echo $row[meterial_qty1];?>" min="0" onfocus="if(this.value==0) this.value='';" onblur="if(this.value=='') this.value=0;" id="meterial_qty11" size="3" /></td>
                      </tr>
                      <tr>
                        <td><select name="meterial_21" id="meterial_7" data-placeholder="Select Product Category" class="category" >
                          <option value="0">Select Product Category</option>
                          <?php 

				  $cresult=mysql_query("select * from meterial_category  order by name ASC");

			$crow=mysql_fetch_array($cresult);

			do{

				  ?>
                          <option value="<?php echo $crow[id]; ?>" <?php if($row[meterial_2] == $crow[id]){echo 'selected="selected"';}?>><?php echo $crow[name]; ?></option>
                          <?php }while($crow=mysql_fetch_array($cresult));?>
                        </select></td>
                        <td><input name="meterial_qty21" type="number" value="<?php echo $row[meterial_qty2];?>" min="0" onfocus="if(this.value==0) this.value='';" onblur="if(this.value=='') this.value=0;" id="meterial_qty7" size="3" /></td>
                      </tr>
                      <tr>
                        <td><select name="meterial_31" id="meterial_8" data-placeholder="Select Product Category" class="category" >
                          <option value="0">Select Product Category</option>
                          <?php 

				  $cresult=mysql_query("select * from meterial_category  order by name ASC");

			$crow=mysql_fetch_array($cresult);

			do{

				  ?>
                          <option value="<?php echo $crow[id]; ?>" <?php if($row[meterial_3] == $crow[id]){echo 'selected="selected"';}?>><?php echo $crow[name]; ?></option>
                          <?php }while($crow=mysql_fetch_array($cresult));?>
                        </select></td>
                        <td><input name="meterial_qty31" type="number" value="<?php echo $row[meterial_qty3];?>" min="0" onfocus="if(this.value==0) this.value='';" onblur="if(this.value=='') this.value=0;" id="meterial_qty8" size="3" /></td>
                      </tr>
                      <tr>
                        <td><select name="meterial_41" id="meterial_9" data-placeholder="Select Product Category" class="category" >
                          <option value="0">Select Product Category</option>
                          <?php 

				  $cresult=mysql_query("select * from meterial_category  order by name ASC");

			$crow=mysql_fetch_array($cresult);

			do{

				  ?>
                          <option value="<?php echo $crow[id]; ?>" <?php if($row[meterial_4] == $crow[id]){echo 'selected="selected"';}?>><?php echo $crow[name]; ?></option>
                          <?php }while($crow=mysql_fetch_array($cresult));?>
                        </select></td>
                        <td><input name="meterial_qty41" type="number" value="<?php echo $row[meterial_qty4];?>" min="0" onfocus="if(this.value==0) this.value='';" onblur="if(this.value=='') this.value=0;" id="meterial_qty9" size="3" /></td>
                      </tr>
                      <tr>
                        <td><select name="meterial_51" id="meterial_10" data-placeholder="Select Product Category" class="category" >
                          <option value="0">Select Product Category</option>
                          <?php 

				  $cresult=mysql_query("select * from meterial_category  order by name ASC");

			$crow=mysql_fetch_array($cresult);

			do{

				  ?>
                          <option value="<?php echo $crow[id]; ?>" <?php if($row[meterial_5] == $crow[id]){echo 'selected="selected"';}?>><?php echo $crow[name]; ?></option>
                          <?php }while($crow=mysql_fetch_array($cresult));?>
                        </select></td>
                        <td><input name="meterial_qty51" type="number" value="<?php echo $row[meterial_qty5];?>" min="0" onfocus="if(this.value==0) this.value='';" onblur="if(this.value=='') this.value=0;" id="meterial_qty10" size="3" /></td>
                      </tr>
                    </tbody>
                  </table></td>
                </tr>
                <tr>
                  <td height="30" bgcolor="#FFFFFF">Shorting : </td>
                  <td bgcolor="#FFFFFF"><select name="shorting2" id="shorting2">
                      <option value="1" <?php if($row[shorting] == '1'){echo 'selected="selected"';}?>>1</option>
                      <option value="2" <?php if($row[shorting] == '2'){echo 'selected="selected"';}?>>2</option>
                      <option value="3" <?php if($row[shorting] == '3'){echo 'selected="selected"';}?>>3</option>
                      <option value="4" <?php if($row[shorting] == '4'){echo 'selected="selected"';}?>>4</option>
                      <option value="5" <?php if($row[shorting] == '5'){echo 'selected="selected"';}?>>5</option>
                      
                        <option value="6" <?php if($row[shorting] == '6'){echo 'selected="selected"';}?>>6</option>
                        
                          <option value="7" <?php if($row[shorting] == '7'){echo 'selected="selected"';}?>>7</option>
                          
                            <option value="8" <?php if($row[shorting] == '8'){echo 'selected="selected"';}?>>8</option>
                            
                              <option value="9" <?php if($row[shorting] == '9'){echo 'selected="selected"';}?>>9</option>
                              
                                <option value="10" <?php if($row[shorting] == '10'){echo 'selected="selected"';}?>>10</option>
                                
                                
                                      </select>
                  </td>
                </tr>
                <tr>
                <td height="30" bgcolor="#FFFFFF">Active </td>
                <td bgcolor="#FFFFFF"><input name="active2" type="checkbox" id="active2" value="1" checked="checked" <?php if($row[active] == ''){echo 'checked="checked" ';}?>/></td>
              </tr>
              <tr>
                <td height="30" bgcolor="#FFFFFF">&nbsp;</td>
                <td bgcolor="#FFFFFF"><input type="submit" name="Submit2" value="Update" /></td>
                </tr>
            </table>
          </form></td>
        </tr>
		<?php }else{?>
        <tr>
          <td>
		  
		  <form action="restaurant_insert_product_details.php" method="post" enctype="multipart/form-data" name="form1" id="form1" onsubmit="return validate2()">
          <br />
          <table width="100%" border="0" cellpadding="2" cellspacing="1" bgcolor="#CCCCCC">
              <tr>
                <td height="25" colspan="2" bgcolor="#CCCCCC"><strong>Add  Product details (Model, Type, Code, etc)  </strong></td>
              </tr>
              <tr>
                <td width="17%" bgcolor="#FFFFFF">Product Name : </td>
                <td bgcolor="#FFFFFF" class="input200"><input name="pname" type="text" id="pname" value="<?php echo $_GET[product_type];?>" size="20" /></td>
                </tr>
              <tr>
                <td bgcolor="#FFFFFF">Product item : </td>
                <td bgcolor="#FFFFFF" class="input200"><input name="product_item" type="text" id="product_item" value="<?php echo $_GET[product_model];?>" size="20" /></td>
                </tr>
              <tr>
                <td bgcolor="#FFFFFF">Sale Rate :</td>
                <td bgcolor="#FFFFFF"><input name="sale_rate" type="text" id="sale_rate" size="25" /></td>
                </tr>
              <tr>
                <td height="30" bgcolor="#FFFFFF">Sr:</td>
                <td bgcolor="#FFFFFF"><input name="sr" type="text" id="sr" size="25" /></td>
                </tr>
              <tr>
                <td height="30" bgcolor="#FFFFFF">Material</td>
                <td bgcolor="#FFFFFF"><table width="300" border="0" cellpadding="3" cellspacing="1" class="list_table">
                  <tbody>
                    <tr>
                      <td width="391">Material</td>
                      <td width="94">Qty</td>
                      </tr>
                    <tr>
                      <td><select name="meterial_1" id="meterial_1" data-placeholder="Select Product Category" class="category" >
                        
                        <option value="0">Select Product Category</option>
                        
                        <?php 

				  $cresult=mysql_query("select * from meterial_category  order by name ASC");

			$crow=mysql_fetch_array($cresult);

			do{

				  ?>
                        
                        <option value="<?php echo $crow[id]; ?>" <?php if($_GET[name] == $crow[id]){echo 'selected="selected"';}?>><?php echo $crow[name]; ?></option>
                        
                        <?php }while($crow=mysql_fetch_array($cresult));?>
                        
                        </select></td>
                      <td><input name="meterial_qty1" type="number" value="0" min="0" onfocus="if(this.value==0) this.value='';" onblur="if(this.value=='') this.value=0;" id="meterial_qty1" size="3" /></td>
                    </tr>
                    <tr>
                      <td><select name="meterial_2" id="meterial_2" data-placeholder="Select Product Category" class="category" >
                        <option value="0">Select Product Category</option>
                        <?php 

				  $cresult=mysql_query("select * from meterial_category  order by name ASC");

			$crow=mysql_fetch_array($cresult);

			do{

				  ?>
                        <option value="<?php echo $crow[id]; ?>" <?php if($_GET[name] == $crow[id]){echo 'selected="selected"';}?>><?php echo $crow[name]; ?></option>
                        <?php }while($crow=mysql_fetch_array($cresult));?>
                        </select></td>
                      <td><input name="meterial_qty2" type="number" value="0" min="0" onfocus="if(this.value==0) this.value='';" onblur="if(this.value=='') this.value=0;" id="meterial_qty2" size="3" /></td>
                    </tr>
                    <tr>
                      <td><select name="meterial_3" id="meterial_3" data-placeholder="Select Product Category" class="category" >
                        <option value="0">Select Product Category</option>
                        <?php 

				  $cresult=mysql_query("select * from meterial_category  order by name ASC");

			$crow=mysql_fetch_array($cresult);

			do{

				  ?>
                        <option value="<?php echo $crow[id]; ?>" <?php if($_GET[name] == $crow[id]){echo 'selected="selected"';}?>><?php echo $crow[name]; ?></option>
                        <?php }while($crow=mysql_fetch_array($cresult));?>
                        </select></td>
                      <td><input name="meterial_qty3" type="number" value="0" min="0" onfocus="if(this.value==0) this.value='';" onblur="if(this.value=='') this.value=0;" id="meterial_qty3" size="3" /></td>
                    </tr>
                    <tr>
                      <td><select name="meterial_4" id="meterial_4" data-placeholder="Select Product Category" class="category" >
                        <option value="0">Select Product Category</option>
                        <?php 

				  $cresult=mysql_query("select * from meterial_category  order by name ASC");

			$crow=mysql_fetch_array($cresult);

			do{

				  ?>
                        <option value="<?php echo $crow[id]; ?>" <?php if($_GET[name] == $crow[id]){echo 'selected="selected"';}?>><?php echo $crow[name]; ?></option>
                        <?php }while($crow=mysql_fetch_array($cresult));?>
                        </select></td>
                      <td><input name="meterial_qty4" type="number" value="0" min="0" onfocus="if(this.value==0) this.value='';" onblur="if(this.value=='') this.value=0;" id="meterial_qty4" size="3" /></td>
                    </tr>
                    <tr>
                      <td><select name="meterial_5" id="meterial_5" data-placeholder="Select Product Category" class="category" >
                        <option value="0">Select Product Category</option>
                        <?php 

				  $cresult=mysql_query("select * from meterial_category  order by name ASC");

			$crow=mysql_fetch_array($cresult);

			do{

				  ?>
                        <option value="<?php echo $crow[id]; ?>" <?php if($_GET[name] == $crow[id]){echo 'selected="selected"';}?>><?php echo $crow[name]; ?></option>
                        <?php }while($crow=mysql_fetch_array($cresult));?>
                      </select></td>
                      <td><input name="meterial_qty5" type="number" value="0" min="0" onfocus="if(this.value==0) this.value='';" onblur="if(this.value=='') this.value=0;" id="meterial_qty5" size="3" /></td>
                    </tr>
                  </tbody>
                </table></td>
              </tr>
              <tr>
                <td height="30" bgcolor="#FFFFFF">Shorting : </td>
                <td bgcolor="#FFFFFF"><select name="shorting" id="shorting">
                  <option value="1">1</option>
                  <option value="2">2</option>
                  <option value="3">3</option>
                  <option value="4">4</option>
                  <option value="5">5</option>
                  
                  <option value="6">6</option>
                  <option value="7">7</option>
                  <option value="8">8</option>
                  <option value="9">9</option>
                  <option value="10">10</option>
                  </select>
                  </td>
              </tr>
              <tr>
                <td height="30" bgcolor="#FFFFFF">Active</td>
                <td bgcolor="#FFFFFF"><input name="active" type="checkbox" id="active" value="1" checked="checked"   /></td>
                </tr>
              <tr>
                <td height="30" bgcolor="#FFFFFF">&nbsp;</td>
                <td width="83%" bgcolor="#FFFFFF"><input type="submit" name="Submit3" value="Submit" /></td>
                </tr>
            </table>
          </form></td>
        </tr>
		<?php }?>
        <tr>
          <td><br />
            <table width="100%" border="0" cellpadding="3" cellspacing="1" bgcolor="#CCCCCC">
              <tr>
                <td colspan="10" bgcolor="#969696"><strong>Product List </strong></td>
              </tr>
              <tr>
                <td bgcolor="#CCCCCC"><strong>Sr.</strong></td>
                <td bgcolor="#CCCCCC"><strong>Product Name </strong></td>
                <td bgcolor="#CCCCCC"><strong>Product item </strong></td>
                <td bgcolor="#CCCCCC">&nbsp;</td>
                <td width="7%" bgcolor="#CCCCCC"><strong>Sale Rate</strong></td>
                <td width="3%" bgcolor="#CCCCCC">Sr</td>
                <td width="2%" bgcolor="#CCCCCC">Shorting</td>
                <td width="6%" bgcolor="#CCCCCC">Available </td>
                <td width="9%" align="center" bgcolor="#CCCCCC"><strong>Edit</strong></td>
                <td width="9%" align="center" bgcolor="#CCCCCC"><strong>Delete</strong></td>
              </tr>
              <?php 
 
			
			
			$sr=0;
			 
			$result=mysql_query("SELECT rpd . * , mc1.name AS material1_name, mc2.name AS material2_name, mc3.name AS material3_name, mc4.name AS material4_name, mc5.name AS material5_name
FROM restaurant_product_details rpd
LEFT JOIN meterial_category mc1 ON rpd.meterial_1 = mc1.id
LEFT JOIN meterial_category mc2 ON rpd.meterial_2 = mc2.id
LEFT JOIN meterial_category mc3 ON rpd.meterial_3 = mc3.id
LEFT JOIN meterial_category mc4 ON rpd.meterial_4 = mc4.id
LEFT JOIN meterial_category mc5 ON rpd.meterial_5 = mc5.id
  order by rpd.shorting,rpd.sr asc");
			$row=mysql_fetch_array($result);

			
			  do{
			 
             $sr=$sr+1;    

?>

              <tr>
                <td width="4%" bgcolor="#FFFFFF"><?php echo $sr;?></td>
                <td width="25%" bgcolor="#FFFFFF"><?php  
				 
				echo $row[pname];
				?></td>
                <td width="17%" bgcolor="#FFFFFF"><?php echo $row[product_item];?></td>
                <td width="18%" bgcolor="#FFFFFF"><?php 

if($row[meterial_qty1]!="0"){ echo "($row[material1_name]  - $row[meterial_qty1]) , ";}
if($row[meterial_qty2]!="0"){ echo "($row[material2_name]  - $row[meterial_qty2]) , ";}
if($row[meterial_qty3]!="0"){ echo "($row[material3_name]  - $row[meterial_qty3]) , ";}
if($row[meterial_qty4]!="0"){ echo "($row[material4_name]  - $row[meterial_qty4]) , ";}
if($row[meterial_qty5]!="0"){ echo "($row[material5_name]  - $row[meterial_qty5]) ";}

				
  	
				?></td>
                <td valign="top" bgcolor="#FFFFFF"><?php echo $row[sale_rate];?></td>
                <td valign="top" bgcolor="#FFFFFF"><?php echo $row[sr];?></td>
                <td valign="top" bgcolor="#FFFFFF"><?php echo $row[shorting];?></td>
                <td valign="top" bgcolor="#FFFFFF">
                
                <?php if($row[active] == '1' ){?>
                <img src="images/yes.jpg" width="20" height="20" alt=""/>
                <?php }else{?>
                <img src="images/no.jpg" width="20" height="20" alt=""/>
                <?php }?>                </td>
                <td align="center" bgcolor="#FFFFFF" class="link"><a href="restaurant_add_product.php?id=<?php echo $row[id];?>&amp;action=edit&model=<?php echo $row[product_code];?>">Edit</a></td>
                <td align="center" bgcolor="#FFFFFF" class="link">Delete  </td>
              </tr>

			  <?php 
        
     
			  }while($row=mysql_fetch_array($result));
			  ?>
            </table>
          <br /></td>
        </tr>
    </table></td>
  </tr>
  <tr>
    <td><?php include("bot.php");?></td>
  </tr>
</table>
</body>
</html>
<?php }?>