<?php
/*
Author : Nikolius
Email : n1colius.lau@gmail.com
Date : 13-Jul-2015 09:21 AM
*/
require_once $cfg->mValue['docroot'] . "module/sia_setting/business/sia_setting.class.php";
class Wilayah extends SiaSetting {
   function Wilayah(&$configObject, $dataProceed) {
      SiaSetting::SiaSetting($configObject, $dataProceed);
      $this->AppendSqlQueries("module/wilayah/business/wilayah.sql.php");
   }

   function GetDataForSync(){
      $dataList = $this->GetProperty("DataProceed");

      $this->StartTransaction();
      $prosesInsertUpdate = TRUE;

      //update data feeder..
      for ($i=0; $i < count($dataList); $i++) {
         $p = array(
            $dataList[$i]['id_wil'],
            $dataList[$i]['nm_wil'],
            $dataList[$i]['asal_wil'],
            $dataList[$i]['kode_bps'],
            $dataList[$i]['kode_dagri'],
            $dataList[$i]['kode_keu'],
            $dataList[$i]['id_induk_wilayah'],
            $dataList[$i]['id_level_wil'],
            $dataList[$i]['id_negara'],
            $dataList[$i]['nm_wil'],
            $dataList[$i]['asal_wil'],
            $dataList[$i]['kode_bps'],
            $dataList[$i]['kode_dagri'],
            $dataList[$i]['kode_keu'],
            $dataList[$i]['id_induk_wilayah'],
            $dataList[$i]['id_level_wil'],
            $dataList[$i]['id_negara']
         );
         $proses = $this->ExecuteUpdateQuery($this->mSqlQueries['syncData'], $p);
         if($proses == FALSE) $prosesInsertUpdate = FALSE;
      }

      //get data negara
      $dataNegara = $this->GetAllDataAsArray($this->mSqlQueries['getDataNegara'], array());
      $negKode = $dataNegara[0]['negKode'];
      $p = array(
         $negKode
      );
      $proses = $this->ExecuteUpdateQuery($this->mSqlQueries['updateIdNegara'], $p);
      if($proses == FALSE) $prosesInsertUpdate = FALSE;

      //get data propinsi
      $dataPropinsi = $this->GetAllDataAsArray($this->mSqlQueries['getDataPropinsi'], array());
      for ($i=0; $i < count($dataPropinsi); $i++) {
         $p = array(
            $dataPropinsi[$i]['propKode'],
            '%'.$dataPropinsi[$i]['propNama'].'%',
         );
         $proses = $this->ExecuteUpdateQuery($this->mSqlQueries['updateIdPropinsi'], $p);
         if($proses == FALSE) $prosesInsertUpdate = FALSE;
      }

      //get data kota
      $dataKota = $this->GetAllDataAsArray($this->mSqlQueries['getDataKota'], array());
      for ($i=0; $i < count($dataKota); $i++) {
         $arrTemp = explode(' ',$dataKota[$i]['kotaNama']);
         if(strtoupper($arrTemp[0]) == "KOTA" || strtoupper($arrTemp[0]) == "KAB."){
            unset($arrTemp[0]);
         }
         $impKota = implode(' ', $arrTemp);

         $p = array(
            $dataKota[$i]['kotaKode'],
            '%'.$impKota.'%'
         );
         $proses = $this->ExecuteUpdateQuery($this->mSqlQueries['updateIdKota'], $p);
         if($proses == FALSE) $prosesInsertUpdate = FALSE;
      }

      $this->CompleteTransaction($prosesInsertUpdate);
      return $prosesInsertUpdate;
   }
}
?>