<?php
class PengembalianAset extends Database
{
   protected $mSqlFile;
   function __construct($connectionNumber = 0)
   {
      $this->mSqlFile = 'module/pengembalian_aset/business/pengembalian_aset.sql.php';
      parent::__construct($connectionNumber);
      #$this->setDebugOn();
	}

   public function GetHour()
   {
      for ($i = 1;$i < 24;$i++)
      {
         $hour[$i - 1]['id'] = $i;
         $hour[$i - 1]['name'] = $i;
			if($hour[$i - 1]['id'] < 10){
				$hour[$i - 1]['id'] = '0'.$hour[$i - 1]['id'];
			}
      }
      return $hour;
   }

   public function GetMinute()
   {
      for ($i = 0;$i < 60;$i++)
      {
         $minute[$i]['id'] = $i;
         $minute[$i]['name'] = $i;
      }
      return $minute;
   }

   function GetCount(){
   	$result = $this->Open($this->mSqlQueries['get_count'],array());
   	return $result[0]['total'];
   }
   
   function GetDataUserByUsername ($name)
   {
   	if (isset($this->mUserByUserName[$name])) return $this->mUserByUserName[$name];
   	$result = $this->Open($this->mSqlQueries['get_data_user_by_username'], array($name));
   	$this->mUserByUserName[$name] = $result[0];
   	return $result[0];
   }
   
	public function GetDataPengembalianCount($nomor='', $label='')
   {
      $result = $this->Open($this->mSqlQueries['get_data_pengembalian_count'], array('%'.$nomor.'%'));
      if (is_array($result))
         return $result[0]['total'];
      else return 0;
   }
	
	public function GetDataPengembalian($start, $limit, $nomor='')
	{
		$result = $this->Open($this->mSqlQueries['get_data_pengembalian'], array('%'.$nomor.'%', $start, $limit));
		return $result;
	}
	
	public function GetDataPengembalianAsetById($sewaId)
	{
		if(is_array($sewaId)){
			$sewaId = implode("', '", $sewaId);
		}
		$result = $this->Open($this->mSqlQueries['get_data_pengembalian_aset_by_id'], array($sewaId));
		return $result;
	}
	
	public function GetDataPengembalianAsetDetilById($sewaId)
	{
		$result = $this->Open($this->mSqlQueries['get_data_pengembalian_aset_detil_by_id'], array($sewaId));
		return $result;
	}

	//-- do ada disini
	function DoUpdateInvDet($invId)
	{
		$userId = Security::Instance()->mAuthentication->getcurrentuser()->GetUserId();
		$result = $this->Execute($this->mSqlQueries['do_update_investaris_detil'], array($userId, $invId));
		return $result;
	}

	public function DoAddPengembalianAset($sewa, $number, $keterangan, $tgl, $user)
	{
		$result = $this->Execute($this->mSqlQueries['do_add_pengembalian_aset'], array($sewa, $number, $keterangan, $tgl, $user));
		
		return $result;
	}

	public function DoAddPengembalianAsetDet($biayaId, $terlambat, $rusak, $ganti, $keterangan, $invId) {
		$result = $this->Execute($this->mSqlQueries['do_add_pengembalian_aset_det'], array($biayaId, $terlambat, $rusak, $ganti, $keterangan));
		if($result){
			$result = $this->DoUpdateInvDet($invId);
		}
		return $result;
	}

	public function GetCountDataSewaAset($kodeSewa/*, $status_isi = 'all'*/) {
		$result = $this->Open($this->mSqlQueries['get_count_data_sewa_aset'], array('%'.$kodeSewa.'%'/*, $status_isi, $status_isi*/));
		if (!$result)
		{
			return 0;
		}
			else
		{
			return $result[0]['total'];
		}
	}

	# multiunit
	public function GetDataSewaAset($startRec, $itemViewed, $kodeSewa/*, $status_isi = 'all'*/) {
		$user = $this->GetDataUserByUsername($_SESSION['username']);
		$result = $this->Open($this->mSqlQueries['get_data_sewa_aset'], array('%'.$kodeSewa.'%',$user['unitkerjaKodeSistem'],$user['unitkerjaKodeSistem'].'.%',/*, $status_isi, $status_isi,*/ $startRec, $itemViewed));
		return $result;
	}
}
?>