<?php
session_start();

if($HTTP_SESSION_VARS['dbName']==""){
header("location:../index.php");
}

include("config.inc.php");
include("Functions_Sales.php");

if($mainaction=='')
	$mainaction='insert';
	
$connection = mysql_connect($config['dbServer'],$config['dbUser'],$config['dbPass']) or die("Could not connect to DB");
mysql_select_db($HTTP_SESSION_VARS['dbName'],$connection) or die("Could not find DB");

/// Color Grids    Base1 Base2     Decimal for Amounts

$querysetup="select DecimalBase, DecimalBase1, DecimalBase2, base1, base2, grid_color1, grid_color2 from setup";
$resultsetup=mysql_query($querysetup,$connection) or die(mysql_error());
while($rowsetup=mysql_fetch_array($resultsetup)){
	extract($rowsetup);
}

print<<<HERE
<html>
<head>

<link rel="stylesheet" href="default.css" type="text/css" />
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<SCRIPT type="text/javascript" src="shortcut.js"></script>
<script type="text/javascript" language="javascript">

function showlistwarehouse(str){
	window.open('List_Warehouses.php?str='+str,'warehouselist','width=850,height=400,toolbar=no,location=no,directories=no,status=yes,menubar=no,scrollbars=yes,copyhistory=no,resizable=yes');
}

function AddDetail(){
	x=document.warehouseqty;
	
	var minqty=x.min_qty.value;
	var minqty1=parseInt(minqty)*1/1;
	
	var maxqty=x.max_qty.value;
	var maxqty1=parseInt(maxqty)*1/1;
	
	var percent=x.item_percentage.value;
	var percent1=parseInt(percent)*1/1;
	
	if(x.warehouse_code.value==""){
		alert('Warehouse is Mandatory !');
		x.warehouse_code.focus();
	}
	
	else if(x.min_qty.value==""){
		alert('Min Quantity is Mandatory !');
		x.min_qty.focus();
	}
	
	else if(minqty!=minqty1 && minqty!=""){
		alert('Min Quantity Must be A Number !');
		x.min_qty.focus();
	}
	
	else if(x.max_qty.value==""){
		alert('Max Quantity is Mandatory !');
		x.max_qty.focus();
	}
	
	else if(maxqty!=maxqty1 && maxqty!=""){
		alert('Max Quantity Must be A Number !');
		x.max_qty.focus();
	}
	
	else if(x.item_percentage.value==""){
		alert('Percentage is Mandatory !');
		x.item_percentage.focus();
	}
	
	else if(percent!=percent1 && percent!=""){
		alert('Percentage Must be A Number !');
		x.item_percentage.focus();
	}
	
	else{
		x.action="Form_Items_Warehouses_Actions.php";
		x.submit();
	}
}	
	
	

</script>
<style type="text/css">

body,td,th {
	font-family: Verdana, Arial, Helvetica, sans-serif;
	font-size: 11px;
}

.style11 {color: #999999; font-weight: bold; }
.style27 {color: #999999 ;font-size: 10px; font-weight:bold;}
.style15 {color: #5151FF; font-size: 11px;}
.selectstyle {font-size: 11px; font-family:arial,verdana,geneva; color:#000000; width=52px}
.selectstyle1 {font-size: 11px; font-family:arial,verdana,geneva; color:#000000; width=35px}
</style>
<link type="text/css" rel="stylesheet" href="dhtmlgoodies_calendar.css?random=20051112" media="screen"></LINK>
<SCRIPT type="text/javascript" src="dhtmlgoodies_calendar.js?random=20060118"></script>



<title> Item Quantity per Warehouse</title>
</head>
<body>
<form name='warehouseqty' method='post'>
<input type='hidden' name='item_code' value='$item_code'>
<input type='hidden' name='mainaction' value='$mainaction'>
<input type='hidden' name='item_id' value='$item_id'>
<input type='hidden' name='warehouseqty_id' value='$warehouseqty_id'>

HERE;

$style= "style=' background-color:#4069A7; color:#FFFFFF;font-family:Verdana, Arial, Helvetica, sans-serif; font-size:12px;'";

echo "<table  border=0><tr><td valign='top'>";
echo "<table style='table-layout:fixed' border=0 >
		<col width=20>
		<col width=20>
		<col width=180>
		<col width=220>
		<col width=90>
		<col width=90>
		<col width=90>";
echo "<tr bgcolor='#F7F7F7' height=25px><td height='20' colspan='8' align='center'><font size='1' color='#FF0000' face='Verdana'><b>$message</b></font></td></tr>";
echo"<tr bgcolor='#F7F7F7' height='25'>";
echo"<td>&nbsp;</td><td>&nbsp;</td><td><span class='style11'>Warehouse</span></td><td><span class='style11'>Name</span></td><td><span class='style11'>Min qty</span></td><td><span class='style11'>Max Qty</span> </td><td ><span class='style11'> Qty %</span></td><td ><span class='style11'>&nbsp;</span></td></tr>";

echo"<tr bgcolor='#F7F7F7' height='25'>";
echo"<td>&nbsp;</td><td>&nbsp;</td><td><input type='text' name='warehouse_code' value='$warehouse_code' readonly size='20'>";
echo"<label>&nbsp;<span class='style11'><img src='img/btnopen.jpg' title=' Select Warehouse ' width='15' height='20' border='0' onMouseOver=\"style.cursor='hand'\" onClick='showlistwarehouse(1); ' /></span></label></td>";
echo"<td><input type='text' name='warehouse_name' value='$warehouse_name' readonly size='30'></td>";
echo"<td><input type='text' name='min_qty' value='$min_qty'  size='5'></td><td><input type='text' name='max_qty' value='$max_qty' size='5'></td><td><input type='text' name='item_percentage' value='$item_percentage' size='5'></td>";
echo"	<td align='center'><input type='button'  name='adddetail' value='Submit'";  	
echo"	onclick='AddDetail();'  title='Add Detail'  $style></td></tr>";


$query_items="select warehouseqty.warehouse_code,warehouse_name,minqty,maxqty,warehouse_percentage from warehouseqty 
			left join warehouse on warehouse.warehouse_code=warehouseqty.warehouse_code
			where item_id='".$item_id."'";


$result_items=mysql_query($query_items,$connection);
while($row_item=mysql_fetch_row($result_items)){

	if($i%2==0)
			$Color="style='background-color:".$grid_color1."'";
		else			
			$Color="style='background-color:".$grid_color2."'";	
		
		echo'<tr '.$Color.'>';

print<<<HERE
	<td align=center width='3%'><img border='0' src='images/button_edit.png' width='12' height='13' title='Edit Detail' onmouseover="this.style.cursor='pointer'" onclick="Edit_Record('$rows[0]')" $ModMode ></td>
	<td align=center width='3%'><img border='0' src='images/c_delete.png' width='9' height='10' title='Delete Detail' onmouseover="this.style.cursor='pointer'" OnClick="confirm_delete('$code','$rows[0]')" $DelMode></td>

HERE;

	echo"</td><td>$row_item[0]</td><td>$row_item[1]</td><td>$row_item[2]</td><td>$row_item[3]</td><td>$row_item[4]</td><td></td></tr>";
	$i=$i+1;
}

echo"</table><td></tr>";


echo"</form></body></html>";
?>


