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

class ViewTableItemDo extends HtmlResponse
{

   function TemplateModule()
   {
      $this->SetTemplateBasedir(GTFWConfiguration::GetValue('application','docroot').
         'module/'.Dispatcher::Instance()->mModule.'/template');
      $this->SetTemplateFile('table_item_do.html');
   }
   
   function ProcessRequest()
   {
   	$Obj = new DeliveryOrder;
   	
   	//get id from get
   	$idUnit = $_GET['idUnit']->Integer()->Raw();
   	$idPeng = $_GET['idPeng']->Integer()->Raw();
		
		if (isset($_GET['id']))
      {
         $result = $Obj->GetDOById($_GET['id']->Integer()->Raw());
         if ($result === false) unset($_GET['id']);
         else
         {
            if (!is_array($this->Data)) $data = $result;
            if ($data['pengadaanId'] == $result['pengadaanId']) $isChangeJmlAset = true;
            $diffJmlAset = $result['jumlahDO'];
         }
      }
      
      $return['data'] = $data;
      unset ($return['data']['jumlahDO']);		
		
   	$return['listItemPengadaan'] = $Obj->GetListItemPengadaanById($idPeng, $idUnit);
   	foreach (array_keys($return['listItemPengadaan']) as $key)
      {
         $return['listItemPengadaan'][$key]['jumlahDO'] = (int) $data['jumlahDO'][$return['listItemPengadaan'][$key]['idMst']];
         if (isset($isChangeJmlAset) AND $isChangeJmlAset)
            $return['listItemPengadaan'][$key]['pengadaanDetJmlAset'] += (int) $diffJmlAset[$return['listItemPengadaan'][$key]['idMst']];
      }
   	Messenger::Instance()->SendToComponent('combobox', 'Combobox', 'view', 'html', 'lokasi_barang', array('pengBrgLokasi', $lokasiBarang, '', 'false', ''), Messenger::CurrentRequest);
   	
      return $return;
   }
   
   
	function ParseTemplate($data = NULL)
   {
      if (empty($data['listItemPengadaan']))
		{
			$this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'YES');
			return;
		}
		else $this->mrTemplate->AddVar('data', 'DATA_EMPTY', 'NO');
      
      $i = 1;
      foreach ($data['listItemPengadaan'] as $value)
      {
         $value['nomor'] = $i;
         $value['class_name'] = ($i%2) ? 'table-common-even' : '';
  
         $this->mrTemplate->AddVars('data_item', $value, '');
         $this->mrTemplate->parseTemplate('data_item', 'a');
         $i++;
      }
   }
}
?>
