ESH/manage_warehouse.php
2024-10-23 18:28:06 +05:30

189 lines
6.2 KiB
PHP

<?php
include('pop_up_top.php');
$TABLENAME='warehouse_master';
$this_script='manage_warehouse.php';
$acn=$_REQUEST['acn'];
?>
<?php
if(isset($acn) && $acn=='delete')
{
mysqli_query($conn,"DELETE FROM $TABLENAME WHERE ware_id='".$ware_id."'");
}
if(isset($hid) && $hid=='1')
{
$query_main=" SET firm_id='".$firm_id."',warehouse_name='".addslashes($warehouse_name)."',warehouse_code='".addslashes($warehouse_code)."',warehouse_address='".addslashes($warehouse_address)."'";
$query_prefix='';
$query_suffix="";
$query_additional="";
if($frmacn=="Update")
{
$query_prefix='UPDATE ';
$query_suffix=" WHERE ware_id='".$ware_id."' ";
$query_additional="";
$msg="Warehouse Updated Successfully";
}
elseif($frmacn=="Add")
{
$query_prefix='INSERT INTO ';
$query_suffix="";
$query_additional="";
$msg="Warehouse Added Successfully";
}
$sql=$query_prefix.$TABLENAME.$query_main.$query_additional.$query_suffix;
$res=@mysqli_query($conn,$sql);
if(!$res){
$msg='Error adding/updating warehouse. Please make sure the warehouse does not already exist.';
}
//echo "<script>location.replace('$this_script?msg=$msg')</script>";
}
?>
<link href="includes/css-js/admin.css" rel="stylesheet" type="text/css" />
<tr>
<td height="350" valign="top" style="padding:10px;"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td>
<center>
<?php if($acn=='add' || $acn=='update' || $acn=='view') { ?>
<?php
if($acn=='update' || $acn=='view')
{
$sql=@mysqli_query($conn,"SELECT * FROM $TABLENAME WHERE ware_id='".$ware_id."'");
$row=@mysqli_fetch_array($sql);
extract($row);
}
?>
<form name="f1" method="post" action="#" onsubmit="return validateForm();">
<table width="100%" border="0" cellspacing="0" cellpadding="4" class="bdr_table">
<tr><td colspan="4" align="center" style="color:#293D3D; font-size:16px;"><b>Add Warehouse<hr></b></td></tr>
<tr>
<td colspan="4" align="center" >&nbsp;
<span class="txt">
<?php
if($msg)
echo $msg;
?>
</span></td>
</tr>
<tr>
<td align="left" class="bdr_td" width="25%"><span style="color:#293D3D; font-size:10px;" ><b>Firm</b></span></td>
<td align="left" class="bdr_td" width="25%"><span style="color:#293D3D; font-size:10px;" ><select class="selectbox" name="firm_id" id="firm_id" style="width:100%;">
<option value="">--Select Firm--</option>
<?php
$sql_firm ="select a.firm_id,firm_name from tbl_firms a, user_firms b where a.firm_id=b.firm_id and b.user_id= '".$_SESSION['user_id']."'";
generate_options_for_po($sql_firm,$row['firm_id'],'firm_id','firm_name','');
?>
</select></span></td>
<td align="left" class="bdr_td" width="25%"><span style="color:#293D3D; font-size:10px;" ><b>Warehouse Name</b></span></td>
<td align="left" class="bdr_td" width="25%"><input type="text" class="textbox1" name="warehouse_name" id="warehouse_name" value="<?php echo stripslashes($warehouse_name)?>" style="width:100%"/></td>
</tr>
<tr>
<td align="left" class="bdr_td" width="25%"><span style="color:#293D3D; font-size:10px;" ><b>Warehouse Code</b></span></td>
<td align="left" class="bdr_td" width="25%"><input type="text" class="textbox1" name="warehouse_code" id="warehouse_code" value="<?php echo stripslashes($warehouse_code)?>" style="width:100%"/></td>
<td align="left" class="bdr_td" width="25%"><span style="color:#293D3D; font-size:10px;" ><b>Warehouse Address</b></span></td>
<td align="left" class="bdr_td" width="25%"><textarea class="textbox1" name="warehouse_address" style="width:100%;"><?php echo stripslashes($warehouse_address)?></textarea></td>
</tr>
<tr>
<td align="right" class="bg3" colspan="4">
<input type="hidden" name="hid" value="1"> </td>
</tr><tr>
<td align="center" class="bdr_td" colspan="4">
<?php if($acn=='update') { ?>
<input type="submit" name="frmacn" value="Update" class="submitbutton" style="background-color:#CCFF33;">
<?php } else if($acn=='add') { ?>
<input type="submit" name="frmacn" value="Add" class="submitbutton" style="background-color:#CCFF33;" onclick="return CheckBothItem();">
<?php } ?>
<input type="button" value="Close" onclick="window.close();" class="submitbutton" style="background-color:#FF5C33;"> </td>
</tr>
</table>
<?php
$sql_existing_firm = "select warehouse_code,warehouse_name from warehouse_master";
$res_existing_firm = @mysqli_query($conn,$sql_existing_firm);
$count_firm=0;
while($row_existing_firm = @mysqli_fetch_array($res_existing_firm)){
?>
<input type="hidden" name="w_name<?php echo $count_firm?>" id="w_name<?php echo $count_firm?>" value="<?php echo $row_existing_firm['warehouse_name']?>">
<input type="hidden" name="pre_firm<?php echo $count_firm?>" id="pre_firm<?php echo $count_firm?>" value="<?php echo $row_existing_firm['warehouse_code']?>">
<?php $count_firm++; }?>
<input type="hidden" name="count_firm" id="count_firm" value="<?php echo $count_firm?>">
</form>
<?php } else { echo "<script>location.href='techsyn_warehouse_list.php'</script>"; ?>
<?php } ?>
</center>
</fieldset>
</td>
</tr>
</table></td>
</tr>
<script>
var fieldArray = new Array(
new Array('warehouse_name','warehouse_code'), new Array('Please enter warehouse name.','Please enter warehouse code.'));
function validateForm(){
return checkform('f1',fieldArray);
}
function checkFirm(){
alert('hello');
var firm_id = document.getElementById('warehouse_code').value;
CheckBothItem(firm_id);
}
function CheckBothItem(){
var firm_id = document.getElementById('warehouse_code').value;
var warehouse_name = document.getElementById('warehouse_name').value;
var fruits=[];
var fruit=[];
var count = document.getElementById('count_firm').value;
//alert(count);
for(var i=0;i<count;i++){
var pre_firm = document.getElementById('pre_firm'+i).value;
fruits.push(pre_firm);
}
if(fruits.indexOf(firm_id)!=-1){
alert('This Firm Code is already used, Choose another');
return false;
}
for(var j=0;j<count;j++){
var pre_name = document.getElementById('w_name'+j).value;
fruit.push(pre_name);
}
if(fruit.indexOf(warehouse_name)!=-1){
alert('This Firm Name is already used, Choose another');
return false;
}
}
</script>