<?php
require_once GTFWConfiguration::GetValue( 'application', 'docroot').'module/'.Dispatcher::Instance()->mModule.'/business/lapNeracaAset.class.php';
require_once GTFWConfiguration::GetValue('application', 'docroot') . 'main/function/date.php';

class ViewPopupInventarisasi extends HtmlResponse {

   function TemplateModule() {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').'module/'.Dispatcher::Instance()->mModule.'/template');
      $this->SetTemplateFile('popup_inventarisasi.html');
   }

   function ProcessRequest() {
      $Obj = new lapNeracaAset();
      $User = $Obj->GetDataUserByUsername($_SESSION['username']);

	  @$msg = Messenger::Instance()->Receive(__FILE__);
	  @$this->Pesan = $msg[0][1];
	  @$this->css = $msg[0][2];
	  
      if (isset($_GET['page'])) $post = @$msg[0][0];
      else $post = $_POST->AsArray();
      
      $get = (is_object($_GET)) ? $_GET->AsArray() : $_GET;

      if (empty($post)) $post = array
      (
         "jenis_kib" => $get['id'],
         "tanggal" => $get['date'],
         "sbr_dana" => "all",
         "kepemilikan" => "all",
         "lokasi" => "all",
         "kondisi" => "all",
         "status" => "1",
         "unit_pj_id" => $get['unit'],
         "key" => ""
      );
      
      Messenger::Instance()->Send(Dispatcher::Instance()->mModule, 'PopupInventarisasi', 'view', 'html', array($post), Messenger::UntilFetched);
      
      if ($User['role_id'] != 1)
      {
         $unit = $Obj->GetDataUnitByUnitname($post['unit_pj']);
         if ($User['unit_kerja_id'] != $unit['unitkerjaId'] AND $User['unit_kerja_id'] != $unit['unitkerjaParentId'])
            $post['unit_pj'] = $User['unit_kerja_nama'];
      }

      $return['filter_cetak'] = $post;
      $key = $post['key'];

      //combo
      $cbxkib = $Obj->GetCbxJenisKibAll();
      #Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'jenis_kib', array('jenis_kib', $cbxkib, $post['jenis_kib'], true, ''), Messenger::CurrentRequest);

      $cbxsumberdana = $Obj->GetCbxSumberDana();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'sbr_dana', array('sbr_dana', $cbxsumberdana, $post['sbr_dana'], true, ''), Messenger::CurrentRequest);

      $cbxkepemilikan = $Obj->GetCbxKepemilikan();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'kepemilikan', array('kepemilikan', $cbxkepemilikan, $post['kepemilikan'], true, ''), Messenger::CurrentRequest);

      $cbxlokasi = $Obj->GetCbxLokasiKampus();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'lokasi', array('lokasi', $cbxlokasi, $post['lokasi'], true, ''), Messenger::CurrentRequest);

      $cbxkondisi = $Obj->GetCbxKondisi();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'kondisi', array('kondisi', $cbxkondisi, $post['kondisi'], true, ''), Messenger::CurrentRequest);
		
	  $cbxstatus = $Obj->GetCbxStatusAset();
      Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'status', array('status', $cbxstatus, $post['status'], true, ''), Messenger::CurrentRequest);

      $cbxkib = $Obj->ConvertCombo($cbxkib);
      $cbxsumberdana = $Obj->ConvertCombo($cbxsumberdana);
      $cbxkepemilikan = $Obj->ConvertCombo($cbxkepemilikan);
      $cbxlokasi = $Obj->ConvertCombo($cbxlokasi);
      $cbxkondisi = $Obj->ConvertCombo($cbxkondisi);
      $cbxstatus = $Obj->ConvertCombo($cbxstatus);

      @$return['filter'] = array
      (
         "JENIS_KIB" => ($cbxkib[$post["jenis_kib"]]) ? $cbxkib[$post["jenis_kib"]] : 'Semua',
         "TANGGAL" => IndonesianDate($post['tanggal'], 'YYYY-MM-DD'),
         "SBR_DANA" => ($cbxsumberdana[$post["sbr_dana"]]) ? $cbxsumberdana[$post["sbr_dana"]] : 'Semua',
         "KEPEMILIKAN" => ($cbxkepemilikan[$post["kepemilikan"]]) ? $cbxkepemilikan[$post["kepemilikan"]] : 'Semua',
         "LOKASI" => ($cbxlokasi[$post["lokasi"]]) ? $cbxlokasi[$post["lokasi"]] : 'Semua',
         "KONDISI" => ($cbxkondisi[$post["kondisi"]]) ? $cbxkondisi[$post["kondisi"]] : 'Semua',
         "STATUS" => ($cbxstatus[$post["status"]]) ? $cbxstatus[$post["status"]] : 'Semua',
         "UNIT" => ($post["unit_pj"]) ? $post["unit_pj"] : 'Semua',
         "KODE" => ($post["key"]) ? $post["key"] : 'Semua'
      );
      
      $itemViewed = 20;
      $currPage = 1;
      $startRec = 0 ;
      if(isset($_GET['page'])) {
         $currPage = (string)$_GET['page']->StripHtmlTags()->SqlString()->Raw();
         $startRec =($currPage-1) * $itemViewed;
      }

      $data_list = $Obj->GetInventarisasi($post, $startRec,$itemViewed);
      $totalData = $Obj->GetCount();

      $url = Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, Dispatcher::Instance()->mSubModule, Dispatcher::Instance()->mAction, Dispatcher::Instance()->mType);
      $dest = "popup-subcontent";
      Messenger::Instance()->SendToComponent('paging', 'Paging', 'view', 'html', 'paging_top', array($itemViewed,$totalData, $url, $currPage,$dest), Messenger::CurrentRequest);

      $return['tanggal'] = $post['tanggal'];
      $return['jenis_kib'] = $post["jenis_kib"];
      @$return['unit_pj'] = $post['unit_pj'];
      $return['unit_pj_id'] = $post['unit_pj_id'];
      $return['key'] = $key;
      $return['inv'] = $data_list;
      $return['start'] = $startRec+1;
      $return['cbx_thn'] = $post['tahun'];
      return $return;
   }

   function ParseTemplate($data = NULL) {

      $this->mrTemplate->AddVar('content', 'URL_SEARCH', Dispatcher::Instance()->GetUrl(Dispatcher::Instance()->mModule, 'PopupInventarisasi', 'view', 'html') );
      $this->mrTemplate->AddVar('content', 'Tanggal', $data['tanggal']);
      $this->mrTemplate->AddVar('content', 'JENIS_KIB', $data['jenis_kib']);
      $this->mrTemplate->AddVar('content', 'UNIT_PJ', $data['unit_pj']);
      $this->mrTemplate->AddVar('content', 'UNIT_PJ_ID', $data['unit_pj_id']);
      $this->mrTemplate->AddVar('content', 'KEY', $data['key']);
      
      // Filter 
      $this->mrTemplate->AddVar('content','FILTER_JENIS_KIB',$data['filter']['JENIS_KIB']);
      $this->mrTemplate->AddVar('content','FILTER_TANGGAL',$data['filter']['TANGGAL']);
      $this->mrTemplate->AddVar('content','FILTER_SBR_DANA',$data['filter']['SBR_DANA']);
      $this->mrTemplate->AddVar('content','FILTER_KEPEMILIKAN',$data['filter']['KEPEMILIKAN']);
      $this->mrTemplate->AddVar('content','FILTER_LOKASI',$data['filter']['LOKASI']);
      $this->mrTemplate->AddVar('content','FILTER_KONDISI',$data['filter']['KONDISI']);
      $this->mrTemplate->AddVar('content','FILTER_STATUS',$data['filter']['STATUS']);
      $this->mrTemplate->AddVar('content','FILTER_UNIT',$data['filter']['UNIT']);
      $this->mrTemplate->AddVar('content','FILTER_KODE',$data['filter']['KODE']);
      //$this->mrTemplate->AddVars('content', $data['filter'], 'FILTER_');
      
      if (empty($data['inv'])) {
         $this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'YES');
      } else {
         $this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'NO');
         $nomor = 1;
         for($i=0; $i<count($data['inv']); $i++) {
            $nomor = $i+$data['start'];
            $data['inv'][$i]['nomor'] = $nomor;
            $data['inv'][$i]['KIB'] = str_replace('|','<br/><span style="border-top: 1px solid black">',$data['inv'][$i]['KIB'])."</span>";
            if($nomor % 2 != 0)
               $data['inv'][$i]['class_name'] = 'table-common-even';
            else
               $data['inv'][$i]['class_name'] = '';

            $data['inv'][$i]['lokasi_aset'] = str_replace(array(' ','@@'),array('&nbsp;', ' &raquo;&nbsp;'),$data['inv'][$i]['lokasi_aset']);

            $data['inv'][$i]['nilai_perolehan'] = number_format($data['inv'][$i]['nilai_perolehan'],2,',','.');
            $data['inv'][$i]['nilai_buku'] = number_format($data['inv'][$i]['nilai_buku'],2,',','.');

//             $data['inv'][$i]['url_detil'] = Dispatcher::Instance()->GetUrl('inventarisasi_detail', 'detailInventarisasi', 'view', 'html').'&id='.$data['inv'][$i]['id'];
//             $data['inv'][$i]['url_edit'] = Dispatcher::Instance()->GetUrl('inventarisasi_detail', 'inventarisasiEdit', 'view', 'html').'&id='.$data['inv'][$i]['id'];
				if($data['inv'][$i]['golBarang']==4||$data['inv'][$i]['golBarang']==5||$data['inv'][$i]['golBarang']==8){
					$data['inv'][$i]['display'] = "none";
				} 
			
            $this->mrTemplate->AddVars('data_item', $data['inv'][$i], 'INV_');
            $this->mrTemplate->parseTemplate('data_item', 'a');
         }
      }

   }

}
?>