<?php
#echo 'proc'; exit;
require_once GTFWConfiguration::GetValue( 'application', 'docroot') . 'module/penyusutan/business/Penyusutan.class.php';

class ProcessPenyusutan {
     
   function InsertPenyusutan() {
      $_POST = $_POST->AsArray();
      $Obj = new Penyusutan();
      if(!empty($_POST['btnbatal'])) {
         $urlRedirect = Dispatcher::Instance()->GetUrl('penyusutan', 'Penyusutan', 'view', 'html');
      }else{
         $id_klmpk = $_POST['ID_KELOMPOK']; $jenis = $_POST['data']['tambah']['jenis'] ; $besar = $_POST['data']['tambah']['besar'];
         if(empty($id_klmpk) || empty($jenis) || empty($besar)) {
            $urlRedirect = Dispatcher::Instance()->GetUrl('penyusutan', 'Penyusutan', 'view', 'html'). '&err=' . Dispatcher::Instance()->Encrypt('null');
         }else{
            $insert = $Obj->DoAdd($_POST['ID_KELOMPOK'], $_POST['data']['tambah']['jenis'], $_POST['data']['tambah']['besar']);
            if($insert){
               $urlRedirect = Dispatcher::Instance()->GetUrl('penyusutan', 'Penyusutan', 'view', 'html'). '&err=' . Dispatcher::Instance()->Encrypt('add');
            }else{
               $urlRedirect = Dispatcher::Instance()->GetUrl('penyusutan', 'Penyusutan', 'view', 'html'). '&err=' . Dispatcher::Instance()->Encrypt('noadd');
            }
         }
      }
      return $urlRedirect;
   }
   
   function UpdatePenyusutan() {
      $_POST = $_POST->AsArray();
      #print_r($_POST);
      $Obj = new Penyusutan();
      if(!empty($_POST['btnbatal'])) {
         $urlRedirect = Dispatcher::Instance()->GetUrl('penyusutan', 'Penyusutan', 'view', 'html');
      }else{
         $id_klmpk = $_POST['ID_KELOMPOK']; $jenis = $_POST['data']['tambah']['jenis'] ; $besar = $_POST['data']['tambah']['besar'];
         $id_penyusutan = $_POST['data']['tambah']['id_penyusutan'];
         if(empty($id_klmpk) || empty($jenis) || empty($besar)) {
            $urlRedirect = Dispatcher::Instance()->GetUrl('penyusutan', 'Penyusutan', 'view', 'html'). '&err=' . Dispatcher::Instance()->Encrypt('null') . '&id_penyusutan=' . Dispatcher::Instance()->Encrypt($id_penyusutan);
         }else{
            $update = $Obj->DoUpdate($_POST['ID_KELOMPOK'], $_POST['data']['tambah']['jenis'], $_POST['data']['tambah']['besar'], $_POST['data']['tambah']['id_penyusutan']);
            if($update) {
               $urlRedirect = Dispatcher::Instance()->GetUrl('penyusutan', 'Penyusutan', 'view', 'html'). '&err=' . Dispatcher::Instance()->Encrypt('update');
            }else{
               $urlRedirect = Dispatcher::Instance()->GetUrl('penyusutan', 'Penyusutan', 'view', 'html'). '&err=' . Dispatcher::Instance()->Encrypt('noupdate');
            }
         }
      }
      return $urlRedirect;
   }
   
   function Delete () {     
      $Obj = new Penyusutan();
      $_POST = $_POST->AsArray();
      #echo 'delet disini';
      #print_r($_POST); exit;
      $delete = $Obj->DoDelete($_POST['idDelete']);
      if($delete) {
         $urlRedirect = Dispatcher::Instance()->GetUrl('penyusutan', 'Penyusutan', 'view', 'html'). '&err=' . Dispatcher::Instance()->Encrypt('del');
      }else{
         $urlRedirect = Dispatcher::Instance()->GetUrl('penyusutan', 'Penyusutan', 'view', 'html'). '&err=' . Dispatcher::Instance()->Encrypt('nodel');
      }
      return $urlRedirect;
   }
}
?>