Location: PHPKode > projects > CoreAsset > coreasset/manage_purchase.php
<?php
require_once("lib/inc.php");
require_once("lib/security.php");
error_reporting(0);
$smarty = new Smarty;
$smarty->compile_check = true;
$smarty->debugging = false;
$title	  ="::: Manage 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
$mes      = "";
$num      = "";
$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);

if($status < 5)
{
    $rr=$database->Execute("select category_id from asset_category where category_name like 'book%';");
	$a= mysql_fetch_array($rr);
	$cat_id_book= $a[0];
	$smarty->assign('cat_id_book',$cat_id_book);
	$num_book = $database->no_of_rows("select * from asset_purchase_order where category_id = '$cat_id_book'");
	$smarty->assign('num_book_rows',$num_book);

	
  // echo $cat_id_book;
    $num = $database->no_of_rows("select * from asset_purchase_order");

    if(isset($_GET['hd83___2y8dh328f____8hhdiw___jd9']))
    {
     if($status < 4)
     {
        $po_no 			= $_GET['hd83___2y8dh328f____8hhdiw___jd9'];
		$eq_list		= $database->get_from_database("SELECT * FROM asset_purchase_order where po_no ='$po_no'");
		$book_id_list	= explode(',',$eq_list['equipment_id']);
		$cat_id			=$eq_list['category_id'];
		if($database->delet("delete from asset_purchase_order where po_no ='$po_no'"))
        {
		 if($cat_id == $cat_id_book)
		 {
		  for($i=0;$i<count($book_id_list);$i++)
		  {
		  		if($book_id_list[$i]!="")
				  { 
				  	$database->update("UPDATE asset_books SET status=0 where book_id='$book_id_list[$i]'");
				  }
		  }
		 } 
		 // Asset deleted
		 $database->delet("delete from asset_assets where po_no ='$po_no'");
         
        // equipment is decremented
		for($r=0;$r<count($book_id_list)-1;$r++)
			 {
		       $database->decrement("asset_equipment","status","1","$book_id_list[$r]","equipment_id");
	          }
		redirect ("manage_purchase.php","Delete");
		}
        else
        {
         echo mysql_error();
        }
      }
      else
      {
       $num = "invalid";
       $smarty->assign('num',$num);
      }
    }

    if(isset($_GET['act']))
    {
     if($_GET['act']=="Add")
     {
      $mes = "Purchase Order is Successfully Created !";
     }
     if($_GET['act']=="Edit")
     {
      $mes = "Purchase Order is Successfully Updated !";
     }
     if($_GET['act']=="Delete")
     {
      $mes = "Purchase Order is Successfully Deleted !";
     }
     if($_GET['act']=="Exist")
     {
      $mes = "Purchase Order is already Added ...";
     }
    }


    if($num-$num_book > 0)
    {
      $res          = $database->Execute("select * from asset_purchase_order");
      while($row1   = mysql_fetch_array($res))
      {
       $num123		= $database->no_of_rows("select * from asset_assets where po_no ='$row1[po_no]'");
       if($num123 > 0)
       {
        $f = 1;
       }
       else
       {
        $f = 0;
       }
       $flag[]                = $f;
       $po_no[]               = $row1['po_no'];
       $po_date[]             = $row1['po_date'];
       $cat_id[]			  = $row1['category_id']; 
	 // print_r($po_no);
       // *******************  GETTING VENDOR INFORMATION ***********************************************************
       $vendor_id[]           = $row1['vendor_id'];
       $vend_id               = $row1['vendor_id'];
       $row3                  = $database->get_from_database("select * from asset_vendor where vendor_id='$vend_id'");
       $vendor_name[]         = $row3['vendor_name'];

       // *******************  GETTING EQUIPMENT INFORMATION *********************************************************
       $equipment_id[]        = $row1['equipment_id'];
       $eq_id                 = $row1['equipment_id'];
	   $nof_pcs[]             = $row1['no_pcs'];
	   $n_pcs                 = $row1['no_pcs'];
       $no_pcs                = explode(",",$n_pcs);
       $eq                    = explode(",",$eq_id);
       foreach($eq as $n=>$v)
       {
       //echo $v;
         if($v!="")
         {
           $row4                  = $database->get_from_database("select * from asset_equipment where equipment_id='$v'");
           $eq_mod	   =	$row4['equipment_model'];
		   $equip_name.=    $row4['equipment_name']." [".$eq_mod."]"." ".$no_pcs[$n]." Pcs"."<br>";
         }
       }
       
       $equipment_name[]        = $equip_name;
       //echo "<br>";
       $equip_name = "";
      }
      $smarty->assign('cat_id',$cat_id); 
      $smarty->assign('po_no',$po_no);
      $smarty->assign('po_date',$po_date);
      $smarty->assign('vendor_id',$vendor_id);
      $smarty->assign('vendor_name',$vendor_name);
      $smarty->assign('equipment_id',$equipment_id);
	  $smarty->assign('nof_pcs',$nof_pcs);
      $smarty->assign('equipment_name',$equipment_name);
      $smarty->assign('flag',$flag);
    }
  $smarty->assign('num',$num);
  $smarty->assign('mes',$mes);
 // print_r($po_no);
  
  ///////end of general purchase order////////////////////////////////////////////////////////
  
    ///////start of book purchase order////////////////////////////////////////////////////////
  
      $res              = $database->Execute("select * from asset_purchase_order where category_id = $cat_id_book");
      while($row_book   = mysql_fetch_array($res))
      {
	   $book_id[]		= $row_book['equipment_id'];
	   $po_no1[]        = $row_book['po_no'];
	   $num123			= $database->no_of_rows("select * from asset_assets where po_no ='$row_book[po_no]'");
       if($num123 > 0)
       {
        $f = 1;
       }
       else
       {
        $f = 0;
       }
       $flag_book[]                = $f;
	   $po_date1[]      = $row_book['po_date'];
	  }
	  //echo count($po_no1);
	  // print_r($po_no1);
    $smarty->assign('book_id',$book_id);
    $smarty->assign("po_no1",$po_no1);
	$smarty->assign("po_date1",$po_date1);
	$smarty->assign('flag_book',$flag_book);
    $count_book = count($book_id);
   ////////////////////////////////////////////////////////////////////////////////////////////////////
   
   
    for($i=0;$i<$count_book;$i++)
   {
     $a=explode(",",$book_id[$i]);
	 $count_no = count($a);
	 $bb="";
	  
	 for($j=0;$j<$count_no;$j++)
	 {  
	    $b_id = $a[$j];
	    $res_bookname          = $database->Execute("select * from asset_books where book_id = $b_id");
	  
	   
      while($row_bookname   = mysql_fetch_array($res_bookname))
      {
	   $bb.= $row_bookname['book_name'] ;
	   $bb.=",";
	   }
	 }
	$book_final[$i] = $bb;
	 
   }

   //print_r($book_final);
   
   for($u=0; $u<$num_book; $u++)
    {
                    $book_f=$book_final[$u];// echo "--";
					
					$bb_final=explode(",",$book_f);
					//print_r($bb_final);echo "--";
				    $p = array_count_values($bb_final);
				    //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);
					$a="";
					for($k=0;$k<count($book_nm)-1;$k++)
					{
					 //echo $book_nm[$k];
					  $a.=$k+1;
					  $a.=". ";
					 $a.=$book_nm[$k];
					 $a.=" (";
					 $a.=$piec[$k];
					 $a.=" Pc/s ) "; 
					 $a.="<br>";
					}
					//echo $a;
					//echo  $a; echo "<br>";
   					$arr[]   = $a;
					//echo $u;
   }
   //print_r($arr);
   //echo count($arr);
    
   //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
  
   $smarty->assign("arr1",$arr);
 
}
else
{
 $num = "invalid";
 $smarty->assign('num',$num);
}

$smarty->assign('name',$name);
$smarty->assign('book_length','0');
$smarty->assign('status',$status);
$smarty->display('manage_purchase.tpl');

?>
Return current item: CoreAsset