<?php
include("../include/db.php");

/********************************** CHECK ITEM FOR STORE CREATION***************************************/

function check_vehicle_no($vehicle_no)
  {   
       $sql_select = "select * from vehicle_entry where vehicle_no='$vehicle_no'";
       $rs=mysql_query($sql_select);
       $rs_count=mysql_num_rows($rs);
       return $rs_count; 
}

function get_vehicle_no_edit($vehicle_no)
{
  $sql_select = "select * from vehicle_entry where vehicle_no='$vehicle_no'";
  $rs=mysql_query($sql_select);
  $rscount1=mysql_num_rows($rs);
    if($rscount1!=0)
    {
      while($rsdata=mysql_fetch_object($rs))
     {
      $id=$rsdata->id;
     } 
	return $id;
    }
   }
 /********************************** ADD  QUERY ***************************************/
if(($_POST['action']=="ADD")) 
{
$item_name=$_POST['item_name'];
$particulars=$_POST['particulars'];
$description=$_POST['description'];
$status_type=$_POST['status_type'];
$create_date=date('Y-m-d');
$acadamic_yr=explode("-",$create_date);
$acdmc_yr_res=$acadamic_yr[0];
$Insql=mysql_query("insert into consumable_creation(item,particulars,description,status_type,created_date)values('$item_name','$particulars','$description','$status_type','$create_date')");
echo "Added Successfully!!";

// $insert_id = mysql_insert_id();
//  $Upsq1211="update media_pur_sublist set status_type='$status_type' where particulars='$particulars'";
//  mysql_query($Upsq1211);
}

/********************************** UPDATE QUERY ***************************************/
if(($_POST['action']=="EDIT"))
{
$edit_id = $_POST['edit_id']; 
$item_name=$_POST['item_name'];
$particulars=$_POST['particulars'];
$description=$_POST['description'];
$status_type=$_POST['status_type'];
$create_date=date('Y-m-d');
$acadamic_yr=explode("-",$create_date);
$acdmc_yr_res=$acadamic_yr[0];
$Insql=mysql_query("update consumable_creation set item='$item_name',particulars='$particulars',description='$description',status_type='$status_type',created_date='$create_date' where  id='$_POST[edit_id]'");
echo "Updated Successfully!!";

// $insert_id = mysql_insert_id();
 $Upsq1211="update media_pur_sublist set status_type='$status_type' where particulars='$particulars'";
 mysql_query($Upsq1211);
if($status_type=='Active'){
 $Upsq1211="update media_pur_sublist set status_type='Active' where particulars='$particulars' and status_type = 'In-active'";
 mysql_query($Upsq1211);
}else{
  $Upsq1211="update media_pur_sublist set status_type='In-active' where particulars='$particulars' and status_type = 'Active'";
  mysql_query($Upsq1211);
}
 
}

/********************************************DELETE*****************************************************************/
if($_POST['action']=="delete")
{ 		 
		   $delete2="delete from consumable_creation where id='$_POST[id]'";
			mysql_query($delete2);
			echo "<script>alert('Deleted Succesfully')</script>";
			include("consumable_entry_list.php");
}


?>