Location: PHPKode > projects > CoreAsset > coreasset/add_purchase.php
<?php
require_once("lib/inc.php");
require_once("lib/security.php");

$smarty = new Smarty;
$smarty->compile_check = true;
$smarty->debugging = false;
$title	  ="::: Add Purchase :::";
$smarty->assign('title',$title);
// Date & Time to be dispalyed on the header 
$date_time	= date("h:i:s A")." ".date("d-m-Y");
$smarty->assign('date_time',$date_time);
// Done
$date     = date("Y-m-d");
$status   = $_SESSION['status'];
$user_id  = $_SESSION['user_id'];
$smarty->assign('user_id',$user_id);
$row      = $database->get_from_database("select * from asset_users where user_id='$user_id'");
$name     = $row['full_name'];
$rw		  = $database->get_from_database("select * from asset_users where user_id='$_SESSION[user_id]'");
$last_login  = $rw['last_login'];
$last_logout = $rw['last_logout'];
$smarty->assign('last_login',$last_login);
$smarty->assign('last_logout',$last_logout);

$rrr=$database->Execute("select category_id from asset_category where category_name like 'book%';");
	   $aa= mysql_fetch_array($rrr);
	   $b= $aa[0];
$result     = $database->Execute("select * from asset_category where category_id != '$b'");
$category_name=array();
$category_id=array();

while($row=mysql_fetch_array($result))
{
array_push($category_name,$row[1]);
array_push($category_id,$row[0]);
}
//print_r($category_name);
if(count($category_id) > 0)
{
$smarty->assign('category_name',$category_name);
$smarty->assign('category_id',$category_id);
$mm="";
$count_cat=1;
$eqpmnt_pc = "";
//echo $count_cat;
}
else
 {
 $mm="Sorry ! No Category is Still Added ";
 $count_cat=0;
 //echo $count_cat;
 }
 $smarty->assign('mm_cat',$mm);
 $smarty->assign('count_cat',$count_cat);
//print_r($category_id);
if(isset($_REQUEST['cat_id']))
{
$cat_id=$_REQUEST['cat_id'];
$rr=$database->Execute("select category_id from asset_category where category_name like'book%';");
	   $a= mysql_fetch_array($rr);
	   $valueofbook= $a[0];
	   $smarty->assign('valueofbook',$valueofbook);
	   if($valueofbook == $cat_id )
	   {
			echo "<script language='Javascript'>location='add_purchase.php';</script>";
	   }
	   
$result_category    = $database->Execute("select * from asset_equipment where category_id=$cat_id;");
$num_eq=mysql_num_rows($result_category);
$smarty->assign("num_eq",$num_eq);
$count_eq=1;

if($num_eq == 0)
{
	$mm="No equipment is Added !!";
	$smarty->assign('mm',$mm);
	$count_eq=0;
}

$smarty->assign('count_eq',$count_eq);
if($cat_id !=""  )
{
$f=5;
}
else
{
  echo "<script language='Javascript'>location='add_purchase.php';</script>";
}
$smarty->assign('cat_id',$cat_id);
//echo "cat id =";echo $cat_id;

//echo $num_eq;
$equip_id=array();
$equip_name=array();
$equip_model=array();
if($f == 5)
{
while($row=mysql_fetch_array($result_category))
{
	array_push($equip_id,$row[0]);
	array_push($equip_model,$row[3]);
	array_push($equip_name,$row[2]);
}

$smarty->assign('equip_name',$equip_name);
$smarty->assign('equip_model',$equip_model);
$smarty->assign('equip_id',$equip_id);
$smarty->assign('eq_siz',sizeof($equip_id));
$smarty->assign('f',$f);
}
}

if($status < 4)
{

if(isset($_GET['act']))
  {
   if($_GET['act']=="add")
   {
    $po_date             = $_POST['date'];
    $vendor_id           = $_POST['vendor_id'];
    $equip_id            = $_POST['equipment_id'];
	$category_id         = $_POST['category'];
	$eq_pc				 = $_POST['eq_pc'];
	
	if(is_array($equip_id))
	{
		$eqpmnt_id = implode(",",$equip_id);
	}
	else
    {
		$eqpmnt_id = $equip_id;
	}
	
	
	foreach($eq_pc as $n=>$v)
     {
		if($v!=0)
		{
			$eqpmnt_pc.=$v.",";
		}
     } 
	   if($category_id == $valueofbook)
	   {
	   $publisher           = $_POST['publisher'];
	   $database->insert("insert into asset_books ( equipment_id,publisher, create_date,vendor_id, category_id) values ('$eqpmnt_id','$publisher', '$date','$vendor_id','$category_id')");
      
	   }
	   else
	   {
      if($database->insert("insert into asset_purchase_order (po_date, vendor_id, category_id,equipment_id, no_pcs,  create_date) values ('$po_date', '$vendor_id','$category_id', '$eqpmnt_id', '$eqpmnt_pc', '$date')"))
      {
	    
		$eqeq=explode(",",$eqpmnt_id);
		//print_r($eqeq);
		     $cc=count($eqeq);
			 for($r=0;$r<$cc-1;$r++)
			 {
		       $database->increment("asset_equipment","status","1","$eqeq[$r]","equipment_id");
	          }
               redirect ("manage_purchase.php","Add");
              
	  }
	  }
    }
 }

 $no1 = $database->no_of_rows("select * from asset_equipment");
 $no2 = $database->no_of_rows("select * from asset_vendor");
 
 if($no1 > 0)
 {
    $res3          = $database->Execute("select * from asset_equipment");
    while($row3   = mysql_fetch_array($res3))
    {
     $equipment_id[]                         = $row3['equipment_id'];
     $equipment_name[]                       = $row3['equipment_name'];
     $equipment_model[]                      = $row3['equipment_model'];
    }
    $smarty->assign("no1",$no1);
    $smarty->assign("equipment_id",$equipment_id);
    $smarty->assign("equipment_model",$equipment_model);
	$smarty->assign("equipment_name",$equipment_name);
 }
 
 if($no2 > 0)
 {
    $res4          = $database->Execute("select * from asset_vendor");
    while($row4   = mysql_fetch_array($res4))
    {
     $vendor_id[]   = $row4['vendor_id'];
     $vendor_name[] = $row4['vendor_name'];
    }
    $smarty->assign("no2",$no2);
    $smarty->assign("vendor_id",$vendor_id);
    $smarty->assign("vendor_name",$vendor_name);
 }

/*
*/
 }

else
{
 $mes = "Sorry ! You have no such Privillage ...";
 $smarty->assign('mes',$mes);
}
$smarty->assign('name',$name);
$smarty->assign('status',$status);

$smarty->assign('i',1);
$smarty->assign('t',"\t");

$smarty->display('add_purchase.tpl');
?>
Return current item: CoreAsset