<?php
  include '../db_connect.php';
 foreach($_POST as $key => $value){
$_POST[$key] = mysqli_real_escape_string($con,trim($value));
}


if($_GET[mode]=='insert')
{     

        	


		$sql="INSERT INTO `proddet` (`entryid`, `srno`, `rmcode`,`skuid`, `descrip`, `qty`,`unit`, `psrate`, `pamount`, `remarks`) VALUES ('','$_POST[jobid]','$_POST[rmcode]','$_POST[skuid]','$_POST[descrip]', '$_POST[qty]', '$_POST[unit]','$_POST[psrate]','$_POST[pamount]','$_POST[remarks]')";
		
		 if(!mysqli_query($con,$sql))
		   {
			die('Error: ' . mysqli_error($con));
			}
		echo "Record Added Succesfully!!";
		
		 
		

      
}


else if($_GET[mode]=='update')
{
	
		//$sql="UPDATE `jobreg` SET  `total` = '$_POST[total]', `vat` = '$_POST[vat]', `servicetax` = '$_POST[servicetax]', `grtotal` = '$_POST[grtotal]' WHERE `jobid` = $_POST[jobid]";
		
		  //if (mysqli_query($con,$sql)){
		  $sql="UPDATE `proddet` SET  `srno` = '$_POST[jobid]',`rmcode` = '$_POST[rmcode]',`skuid` = '$_POST[skuid]', `descrip` = '$_POST[descrip]', `qty` = '$_POST[qty]', `unit` = '$_POST[unit]', `psrate` = '$_POST[psrate]', `pamount` = '$_POST[pamount]', `remarks` ='$_POST[remarks]'  WHERE entryid= '$_POST[entryid]'";
		  
		  if(!mysqli_query($con,$sql))
		   {
			die('Error: ' . mysqli_error($con));
			}
		  echo "Record Updated Susscessfully!!!";

		//}

}

else if($_GET[mode]=='cpyval')
{
	
			$jobid	=$_POST['jobid'];
			$rmcode	=$_POST['rmcode'];
			$descrip=$_POST['descrip'];
			$qty=$_POST['qty'];
			$unit=$_POST['unit'];
			$psrate=$_POST['psrate'];
			$pamount=$_POST['pamount'];
			$remarks=$_POST['remarks'];
			
			
			for ($i = 0; $i < count($rmcode); $i++) 
			  {
				
					$sql="INSERT INTO `proddet` (`entryid`, `srno`, `rmcode`, `descrip`, `qty`,`unit`, `psrate`, `pamount`, `remarks`) VALUES ('','$jobid','$rmcode','$descrip', '$qty', '$unit','$psrate','$pamount','$remarks')";
		
					
					if(!mysqli_query($con,$sql))
					{
					die('Error: ' . mysqli_error($con));
					}
					echo "Record Copy Succesfully!!";
				
			  }

}


else if($_GET[mode]=='delete')
{
$sql="DELETE from proddet where entryid='$_POST[entryid]'";



if(!mysqli_query($con,$sql))
 {
  die('Error: ' . mysqli_error($con));
  }
echo "Record Deleted Susscessfully!!!";

}
mysqli_close($con);
?>
