<?php 
session_start();
include('../includes/dbcon.php');

$str=" ";


$edate=date("Y-m-d");
$userid=$_SESSION['hrm_id'];
$itemname= trim($_POST['itemname']);
$des= trim($_POST['des']);
$sku= trim($_POST['sku']);
$mb= trim($_POST['mb']);
$itemtype= trim($_POST['itemtype']);
$catid= trim($_POST['catid']);
$sp= trim($_POST['sp']);
$cp= trim($_POST['cp']);
$weight= trim($_POST['weight']);
$dimen= trim($_POST['dimen']);
$tr= trim($_POST['tr']);
$dr= trim($_POST['dr']);
$sup= trim($_POST['sup']);
$maxs= trim($_POST['maxs']);
$mins= trim($_POST['mins']);
$rol= trim($_POST['rol']);
$bcode= trim($_POST['bcode']);
$cases= trim($_POST['cases']);
$qoh= trim($_POST['qoh']);
$uni= trim($_POST['uni']);

if (empty($des)){ $des='';  }  
if (empty($sku)){ $sku='';  }  
if (empty($mb)){ $mb='';  } 
if (empty($itemtype)){ $itemtype=0;  } 
if (empty($catid)){ $catid=0;  } 
if (empty($sp)){ $sp=0;  } 
if (empty($cp)){ $cp=0;  } 
if (empty($weight)){ $weight=0;  } 
if (empty($dimen)){ $dimen='';  } 
if (empty($tr)){ $tr=0;  } 
if (empty($dr)){ $dr=0;  } 
if (empty($sup)){ $sup=0;  } 
if (empty($maxs)){ $maxs=0;  } 
if (empty($mins)){ $mins=0;  } 
if (empty($rol)){ $rol=0;  } 
if (empty($bcode)){ $bcode=0;  } 
if (empty($cases)){ $cases=0;  } 
if (empty($qoh)){ $qoh=0;  } 
if (empty($uni)){ $uni=0;  } 

$query=mysqli_query($con," select * from item_master where item_name='$itemname'  ")or die(mysqli_error($con));
$count=mysqli_num_rows($query);
if ($count>0)
{
	echo "<script type='text/javascript'>alert('Exsisting Item!');</script>";
	echo "<script>document.location='admin_item_add.php'</script>"; 
}

else {

		if ( mysqli_query($con,"INSERT INTO item_master(item_name,cat_id,type_id,description,sku,sales_price,cost_price,supplier_id,manufacturer,min_stock_level,max_stock_level,rol,unit_id,Weight,Dimensions,tax_rate,discount_rate,active_status,case_id,barcode,edate,userid,qoh) 
 VALUES('$itemname',$catid,$itemtype,'$des','$sku',$sp,$cp,$sup,'$mb',$mins,$maxs,$rol,$uni,$weight,'$dimen',$tr,$dr,1,$cases,'$bcode','$edate','$userid',0)  ")or die(mysqli_error($con)))
	       {
					
				echo "<script type='text/javascript'>alert('Successfully added New Item!');</script>";
				echo "<script>document.location='admin_item.php'</script>"; 
	     	 
			}
}		

?>


