<?php
/**
* @package RestConvertSimakbmn
* @copyright Copyright (c) PT Gamatechno Indonesia
* @Analyzed By Dyan Galih
* @author Didi Zuliansyah
* @version 01
* @startDate 2013-01-01
* @lastUpdate 2013-01-01
* @description Class untuk mengkonversi (import/update) SIMAKBMN ke gtaset21
*/

require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/'.Dispatcher::Instance()->mModule.'/business/importBmn'.GTFWConfiguration::GetValue('application','university_code').'.class.php';

class RestConvertSimakbmn extends RestResponse {

	public function get() {
		$univCode = GTFWConfiguration::GetValue('application','university_code');
		$dynClass = 'importBmn'.$univCode;
		$Obj = new $dynClass();

		$isFirstConvertion = $Obj->countInventarisasiDetail();
		
		$startTime = microtime(true);
		if((int)$isFirstConvertion == 0){
			$result = $Obj->firstConvert();
			$label = 'Konversi SIMAKBMN';
		}else{
			$result = $Obj->updateConvert();
			$label = 'Update SIMAKBMN ke gtAset21';
		}
		$endTime = microtime(true);
		
		if($result['status']){
			$msg = $label.' Berhasil (exec. time '.($endTime-$startTime).' detik)';
			$status = 200;
		}else{ 
			$msg = $label.' Gagal (exec. time '.($endTime-$startTime).' detik). Error : '.$result['msg'];
			$status = 404;
		}
		
		return array("status"=>$status,"message"=>$msg,"data"=>'');
	}
	
	public function post() {
	}
	public function put() {
	}
	public function delete() {
	}
}
?>