<?php
     if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
            case "transno":
              if(RetRstField("SELECT fnid FROM txleave WHERE ftleave_no='{$_REQUEST['fttrans_no']}'")) {
                  ?>
                   alert('No. transaksi sudah dipakai...\n System akan mengenerate No. transaksi kembali ...\n Silahkan ulangi proses penyimpanan...  ');
                  OnChangeDate_fdattendance_date();
            <?php
              }
              else {
                    ?>


                  submitbutton('Simpan','','','','');

            <?php
              }
               die("");
            break;
           case "fnleave_days":
             $ssql=" SELECT DATEDIFF('".CDate($_REQUEST['fdleave_end_date'])."','".CDate($_REQUEST['fdleave_start_date'])."') as fnleave_days ";
             ?>
                
                  document.getElementById('fnleave_days').value='<?php echo (int)RetRstField($ssql)+1; ?>';
             <?php
             die("");
           break;
        }
       
    }
     if(!$_REQUEST['id']) {
            $strAutoNumber1="ajax_do('query2.php?code=2&ftmodule_code=hrd002&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftleave_no&no_trans=ftleave_no&table_name=txleave');";

            $ajax_fnleave_days=" ajax_do('hrd.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=fnleave_days&fdleave_start_date='+ document.getElementById('fdleave_start_date').value +'&fdleave_end_date='+ document.getElementById('fdleave_end_date').value);";

            $strAutoNumber0=" function OnChangeDate_fdtrans_date() {
                                           {$strAutoNumber1}
                                     }                               
                                     OnChangeDate_fdtrans_date();                                      
                                      document.getElementById('fnleave_days').value='0';
                                      function OnChangeDate_fdleave_start_date() {
                                            {$ajax_fnleave_days}
                                      }
                                      function OnChangeDate_fdleave_end_date() {
                                             {$ajax_fnleave_days}
                                      }
                                ";
            $objAxpDB->FormJS($strAutoNumber0);
     }

    Getsecurity("cuti");
     
    // Deklarasi UctVw
    $objAxpDB->ViewName("Daftar Cuti");
    $objAxpDB->ViewTable("vHRCuti");
    $objAxpDB->ViewSQL("SELECT a.fnid, a.ftleave_no, a.ftemployee_code,d.ftemployee_name, a.fdtrans_date,
                                a.ftleave_type_code, a.fdleave_start_date, a.fdleave_end_date,
                                a.fnleave_days, a.ftleave_notes, c.fttrans_status_name 
                        FROM txleave a
                        LEFT JOIN tstransaction_status c ON a.fnstatus = c.fntrans_status_code AND c.fntrans_group_code = 2
                        LEFT JOIN tlemployee d on a.ftemployee_code=d.ftemployee_code
                        order by a.ftleave_no desc,a.fdtrans_date desc ");
    $objAxpDB->ViewCaption("ID, No. Transaksi, Kode Pegawai,Nama Pegawai, Tgl. Transaksi, Type Cuti, Tgl. Mulai Cuti, Tgl. Selesai Cuti, Jumlah Cuti,Catatan, Status");
    $objAxpDB->ViewPeriod(TRUE);

    // Deklarasi Header & Footer
    $objAxpDB->FormName("Cuti");
    $objAxpDB->FormSQL("select ftleave_no, ftemployee_code, fdtrans_date, ftleave_type_code, fdleave_start_date, fdleave_end_date, fnleave_days, ftleave_notes, fnstatus  from txleave");
    $objAxpDB->FormCaption("No. Transaksi, Kode Pegawai, Tgl. Transaksi, Type Cuti, Tgl. Mulai Cuti, Tgl. Selesai Cuti, Jumlah Cuti,Catatan, Status");
    $objAxpDB->FormPosition("TL, TL, TL, TL, TL, TL, TL, TL,TL ");
      // Deklarasi Detail
  
    $objAxpDB->Lookup("fnstatus", "SELECT fntrans_status_code, fttrans_status_name FROM tstransaction_status WHERE fntrans_group_code = 2", "fntrans_status_code", "fttrans_status_name", 1, True);
    $objAxpDB->Lookup("ftleave_type_code", "SELECT ftleave_type_code, ftleave_type_name FROM tlleave_type", "ftleave_type_code", "ftleave_type_name", 0, True);
    $objAxpDB->Lookup("ftemployee_code", "SELECT ftemployee_code, ftemployee_name FROM tlemployee", "ftemployee_code", "ftemployee_name", -1, False);
  
 
    $objAxpDB->SetStatus("id, fnstatus");
    if ($objAxpDB->GetStatus("id") == "") {
        $objAxpDB->ButtonShow("baru , cetak_daftar,  export_excel , tutup");
    } elseif ($objAxpDB->GetStatus("id") == 0) {
        $objAxpDB->ButtonShow("reset, simpan, tutup");
        $objAxpDB->FormLocked("0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1");
        $objAxpDB->GridLocked(0, "1, 0, 0, 1");
        $objAxpDB->GridAllowAddNew(0, TRUE);
        $objAxpDB->GridAllowDelete(0, TRUE);
    } elseif ($objAxpDB->GetStatus("fnstatus") == 1) {      
        $objAxpDB->ButtonShow("cetak,batal, tutup");
        $objAxpDB->FormLocked("1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1");
        $objAxpDB->GridLocked(0, "1, 1, 1, 1");
    } elseif ($objAxpDB->GetStatus("fnStatus") == 9) {
        $objAxpDB->ButtonShow("tutup");
        $objAxpDB->FormLocked("1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1");
        $objAxpDB->GridLocked(0, "1, 1, 1, 1");
    }

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

?>
