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

$smarty = new Smarty;
$smarty->compile_check = true;
$smarty->debugging = false;
$title	  ="::: Add Asset For Book :::";
$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'];
$smarty->assign('name',$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);

 //category selected
 $rr=$database->Execute("select category_id from asset_category where category_name like'book%';");
 $a= mysql_fetch_array($rr);
 $cat_id_book= $a[0];
 $rrr=$database->Execute("select category_name from asset_category where category_id = '$cat_id_book';");
 $aa= mysql_fetch_array($rrr);
 $cat_name_book= $aa[0];
 
$smarty->assign('cat_id_book',$cat_id_book);
$smarty->assign('cat_name_book',$cat_name_book);
// po_no selected


	$res3          = $database->Execute("select * from asset_users");
  while($row3    = mysql_fetch_array($res3))
  {
   $userid[]                          = $row3['user_id'];
   $full_name[]                       = $row3['full_name'];
  }
  $smarty->assign("userid",$userid);
  $smarty->assign("full_name",$full_name);

if(isset($_GET['fill']))
  {
   if($_GET['fill']==1)
   {
       $po_no            = trim($_GET['idu392__d9j__932uf']);
       $book_name        = trim($_GET['dh32__jd3ud']);
       $pcs              = trim($_GET['pcs']);
	   
	   $eq_list			= $database->get_from_database("Select * from asset_purchase_order where po_no='$po_no'
	   and category_id='$cat_id_book'");
	   $book_id_list	= explode(',',$eq_list['equipment_id']);
	   //print_r($book_id_list);
	   ////////////////////for book name and pcs/////////////////////////////////////
	   
	    $count_bname=count($book_id_list);
	   for($p=0;$p<$count_bname;$p++)
	    {
	    $data_bname			= $database->get_from_database("SELECT * from asset_books WHERE book_id='$book_id_list[$p]'");   
	    $data_bookname[]    = $data_bname['book_name'];
	    }
	  // print_r($data_bookname);
	   
	   $p = array_count_values($data_bookname);
				    //print_r($p);echo "--";
				       //$p=array();
					$book_nm="";
					$piec="";
					foreach($p as $n=>$v)
					{
						$book_nm[] = $n;
						$piec[] = $v;
					}
					//print_r($book_nm);echo "<br>";
					//print_r($piec);
					$count_nm=count($book_nm);
   					 //for()
	                $a="";
					for($re=0;$re<$count_nm;$re++)
					 {
					 $a.=$re+1;
					 $a.=". ";
					 $a.=$book_nm[$re];
					 $a.="(";
					 $a.=$piec[$re];
					 $a.="Pc/s) "; 
					 //$a.=",";
					 $all_book_names[]=$a;
					 $a="";
					 
					 }
	   //echo $a;
	   
	$smarty->assign('a',$all_book_names);   
	   /////////////////////for book name and pcs/////////////////////////////////////
	   $price=0;
	   for($i=0;$i<count($book_id_list);$i++)
	      {
		  	$book_price	= $database->get_from_database("Select price from asset_books where book_id='$book_id_list[$i]'");
			$price+=$book_price['price'];	
		  }
		  
       $smarty->assign('po_no',$po_no);
       $smarty->assign('book_name',$book_name);
	   $smarty->assign('pcs',$pcs); 
	   $smarty->assign('total_price',$price); 
	}
	
  }

  
  
  if(isset($_GET['act']))
  {
   if($_GET['act']=="add")
   {
    $category_name              = trim($_POST['cat_name']);
    $category_id                = trim($_POST['cat_id']);
    $po_no                      = trim ($_POST['po_no']);   
    $asset_price                = trim($_POST['asset_price']);
	$asset_description          = trim($_POST['asset_description']);
	$receive_date               = trim($_POST['receive_date']);
	$issued_userid              = trim($_POST['issued_userid']);
	
	$res_bid                    = $database->Execute("select * from asset_purchase_order where po_no='$po_no' and          category_id='$category_id'");
	
	$rs  = mysql_fetch_array($res_bid);
	$book_id=$rs['equipment_id'];
	
   

  ////////////////////////////////////////////////insert query///////////////////////////////////////////////////
	$ins_id = $database->insert("insert into asset_assets (category_id,  asset_nickname, po_no, vendor_id, asset_price, equipment_id, asset_description, receive_date, create_date) values ('$category_id', '','$po_no', '', '$asset_price', '$book_id', '$asset_description', '$receive_date', '$date')");

	if($ins_id)
	{
		$book_id_list 	= explode(",",$book_id);
		for($j=0;$j<count($book_id_list);$j++)
		{
			$database->update("UPDATE asset_books SET status = 2 WHERE book_id='$book_id_list[$j]'");
			$database->insert("insert into asset_book_history  (asset_tag, po_no, book_id, assigned_userid, issued_on, return_date, change_date) values ('$ins_id', '$po_no', '$book_id_list[$j]', '0', '0000-00-00', '0000-00-00', '0000-00-00')");
		}
		redirect ("manage_asset.php","Add");
	}

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