<?php
require_once GTFWConfiguration::GetValue('application', 'docroot') . 'module/sewa_aset/business/SewaAset.class.php';
require_once GTFWConfiguration::GetValue('application', 'docroot') .
'main/function/date.php';

class PrintRtfSewaAset extends HtmlResponse
{

   function ProcessRequest()
   {
      $_GET = $_GET->AsArray();
      $Obj	 	= new SewaAset;
		$code 	= $_GET['code'];
		$start 	= (int)$_GET['start'];
		$limit 	= (int)$_GET['limit'];

		$return	= $Obj->GetDataSewaAset($start, $limit, $code);

      return $return;
   }

   function ParseTemplate($data = NULL)
   {
		$contents = file_get_contents(GTFWConfiguration::GetValue( 'application', 'docroot')."doc/template_sewa_aset.rtf");

		$i=0;
		$n=0;
		for($i;$i<sizeof($data);$i++){
		$n++;
			//-- convert dulu
			$startDate		= IndonesianDate($data[$i][sewa_tanggal_awal], 'YYYY-MM-DD');
			$lastDate		= IndonesianDate($data[$i][sewa_tanggal_akhir], 'YYYY-MM-DD');
			$startDate		= $startDate." ".$data[$i][sewa_waktu_awal];
			$lastDate		= $lastDate." ".$data[$i][sewa_waktu_akhir];

			if(isset($data[$i][mitra])){
				$mu	= $data[$i][mitra];
			} else {
				$mu	= $data[$i][unitkerja];
			}
			//-- end of convert

			$nomor 			.='\f1\fs20'.' '.$n.'\par';
			$nsewa			.='\f1\fs20'.' '.$data[$i][sewa_nomor].'\par';
			$unitmitra		.='\f1\fs20'.' '.$mu.'\par';
			$keterangan		.='\f1\fs20'.' '.$data[$i][keterangan].'\par';
			$tglawal			.='\f1\fs20'.' '.$startDate.'\par';
			$tglakhir		.='\f1\fs20'.' '.$lastDate.'\par';
		}
		//-- buat asesorisnya
		$namacompany 	= GTFWConfiguration::GetValue('organization', 'company_name');
		$kota 	= GTFWConfiguration::GetValue('organization', 'city');
		$header 	= "Sewa Aset";
		$namacetak	 	= $_SESSION['username'];
		$tglcetak		= IndonesianDate(date('Y-m-d'), 'YYYY-MM-DD');
		
		//-- disini kontennya
		$contents = str_replace('[NAMACOMPANY]', $namacompany, $contents);
		$contents = str_replace('[HEADER]', $header, $contents);
		$contents = str_replace('[NAMACETAK]', $namacetak, $contents);
		$contents = str_replace('[TGLCETAK]', $tglcetak, $contents);
		$contents = str_replace('[NOMOR]', $nomor, $contents);
		$contents = str_replace('[KOTA]', $kota, $contents);
		$contents = str_replace('[NOMORSEWA]', $nsewa, $contents);
		$contents = str_replace('[UNITMITRA]', $unitmitra, $contents);
		$contents = str_replace('[TGLMULAI]', $tglawal, $contents);
		$contents = str_replace('[TGLSELESAI]', $tglakhir, $contents);
		$contents = str_replace('[KETERANGAN]', $keterangan, $contents);

		header("Content-type: application/msword");
		header("Content-disposition: inline; filename=sewa_aset".date('d-m-Y').".rtf");
		header("Content-length: " . strlen($contents));
		print $contents;
	}
}
?>