<?php

if($_REQUEST['ajax']) {

  switch($_REQUEST['code']) {

    case "ftbranch_code":

      if(RetRstField("SELECT ftbranch_code FROM tlbranch WHERE ftbranch_code='{$_REQUEST['ftbranch_code']}'"))
      {
        ?>
          alert('Kode Cabang sudah dipakai... ');
        <?php
      }
      else
      {
        ?>
          submitbutton('Simpan','','','','');
        <?php
      }
    break;

  }
  die("");
  exit;
}
  Getsecurity('setting_cabang');
$objAxpDB->ViewName("Daftar Setting Cabang");

$objAxpDB->ViewSQL("SELECT a.fnid,
                   a.ftbranch_code,
                   a.ftbranch_name,
                   CONCAT(a.ftbranch_type_code,' - ',b.ftbranch_type_name) AS ftbranch_type_code,
                   a.ftregion_code,
                   a.ftbranch_main,
                   case when fnstatus=0 then 'Tidak Aktif' else 'Aktif' end as Status
                   FROM tlbranch A
                   INNER JOIN tlbranch_type B ON a.ftbranch_type_code=b.ftbranch_type_code");

$objAxpDB->ViewCaption("id,Kode Cabang,Nama Cabang, Tipe Cabang, Wilayah, Cabang Utama, Status");

$objAxpDB->FormName("Setting Cabang");

$objAxpDB->FormSQL("SELECT fnid,ftbranch_code,ftbranch_name,ftbranch_type_code,
                   ftregion_code,ftbranch_main,ftaddress,ftcity,ftstate,
                   ftcountry,fttelephone,ftfax,ftemail,ftnpwp,fdnpwp_date,ftzip_code,fnStatus FROM tlbranch");

$objAxpDB->FormCaption("id,Kode Cabang,Nama Cabang, Tipe Cabang, Wilayah, Cabang Utama,
                        Alamat, Kota,Negara,Provinsi,No.Telp,Fax,Email, NPWP, Tanggal NPWP, Zip Code,Status");

$objAxpDB->FormPosition("HD,TL, TL, TL, TL, TL,TL, TL, TR, TR, TR,TR,TR,TR,TR,TR,TR,TR,TR,TR,TR");

$objAxpDB->SetStatus("id");

$objAxpDB->Lookup('fnStatus', 'SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status where fntrans_status_code<>2 and fntrans_group_code=9', 'fntrans_status_code', 'fttrans_status_name', 1,true);

$objAxpDB->Lookup('ftbranch_type_code', 'SELECT ftbranch_type_code, ftbranch_type_name FROM tlbranch_type', 'ftbranch_type_code', 'ftbranch_type_name', 1,true);


if ($objAxpDB->GetStatus("id") == "") {

    $objAxpDB->ButtonShow("baru");


  }elseif($objAxpDB->GetStatus("id") == 0){

    $objAxpDB->ButtonShow("reset, simpan, tutup");

  }elseif($objAxpDB->GetStatus("id") != 0) {

    $objAxpDB->FormLocked("1,1");
    $objAxpDB->ButtonShow("update, hapus, tutup");

  }


$objAxpDB->Process();
$objAxpDB->WriteHtmlTable();
