<?php
	
     if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
            case "transno":
              if(RetRstField("SELECT fnid FROM tlbranch WHERE ftbranch_name='{$_REQUEST['ftransno']}'")) {
                  ?>
                  alert('Nama Cabang sudah dipakai... ');
            <?php
              }
              else {
                    ?>
				submitbutton('Simpan','','','','');
                   
            <?php
              }
			die("");
            break;
			case "ajax_kcu":
			?>
				
			<?php
			if($_REQUEST['ftbranch_type_code']=='KCP' &&  $_REQUEST['ftregion_code']!=''){
				$sql="select ftbranch_code,ftbranch_name from tlbranch where ftbranch_type_code='KCU' and ftregion_code='".$_REQUEST['ftregion_code']."'";
				$html='<select class="text" name="ftbranch_main" id="ftbranch_main">';
				$html.='<option selected="" value="">--- Pilih ---</option>';
				$rs=mysql_query($sql);
				while($hsl=mysql_fetch_array($rs)){	
				$html.='<option value="'.$hsl['ftbranch_code'].'">'.$hsl['ftbranch_code'].' -- '.$hsl['ftbranch_name'].'</option>';
				}
				$html.='</select>';
			}else{
				$sql='';
			}	
			
			?>
				document.getElementById('DivCtl_ftbranch_main').innerHTML='<?php echo $html;?>';
			<?php
			
			die("");
			break;
        }       
        die("");
    }
    
        $objAxpDB->ViewName("Daftar Cabang");
        $objAxpDB->ViewSQL("SELECT tlbranch.fnid, tlbranch.ftbranch_code, ftbranch_name, a.ftregion_name AS ftregion_name, 
                            CONCAT(b.ftbranch_type_code,'-',b.ftbranch_type_name),d.fttrans_status_name FROM tlbranch
                            LEFT JOIN tlregion a ON tlbranch.ftregion_code=a.ftregion_code LEFT JOIN tlbranch_type b ON b.ftbranch_type_code=tlbranch.ftbranch_type_code
                            LEFT JOIN tstransaction_status d ON d.fntrans_group_code = 9 and fnstatus = d.fntrans_status_code
                            ORDER BY tlbranch.`ftbranch_code` ASC
                            ");
        
        $objAxpDB->ViewCaption("ID,Kode Cabang,Nama Cabang, Regional, Type Cabang, Status");

        $objAxpDB->FormName("Kantor Cabang");
        $objAxpDB->FormSQL("SELECT   ftbranch_code, ftbranch_name, ftregion_code, ftbranch_type_code, ftbranch_main, ftaddress, ftcity, fttelephone, ftfax, fnstatus from tlbranch");
        $objAxpDB->FormCaption(" Kode Cabang, Nama Cabang, Regional, Type Cabang, Kode Cabang Utama, Alamat, Kota, No Telepon, FAX., Status");
        $objAxpDB->FormPosition("TL,TL,TL,TL,TL,TL,TL,TL,TL,TL,TL");
    
        $objAxpDB->lookup("ftregion_code","select ftregion_code, ftregion_name from tlregion","ftregion_code","ftregion_name",-1,true);
        $objAxpDB->lookup("ftbranch_main","select ftbranch_code, ftbranch_name from tlbranch where ftbranch_type_code='KCU'","ftbranch_code","ftbranch_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);
        $objAxpDB->Lookup("fnstatus", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 9", "fntrans_status_code", "fttrans_status_name", 1,true);
        $ajaxKCU="ajax_do('system.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&ajax=1&code=ajax_kcu&ftbranch_type_code='+ document.getElementById('ftbranch_type_code').value+'&ftregion_code='+document.getElementById('ftregion_code').value);";

        //$objAxpDB->FormScript(3,"onChange=\"{$ajaxKCU}\"");
        $objAxpDB->SetStatus("id");
        if ($objAxpDB->GetStatus("id") == "")
                $objAxpDB->ButtonShow(" baru, tutup");
        elseif ($objAxpDB->GetStatus("id") == 0) {
                $objAxpDB->FormLocked("0, 0, 0,0,1,0");
                $objAxpDB->ButtonShow("reset, simpan, tutup");
        } elseif ($objAxpDB->GetStatus("id") != 0) {
                $objAxpDB->FormLocked("1, 0, 0");
                $objAxpDB->ButtonShow("update, tutup");
        }
        $objAxpDB->Process();
        $objAxpDB->WriteHtmlTable();
	   
       
?>
