<?php
     if($_REQUEST['ajax']) {
        switch($_REQUEST['code']) {
            case "transno":
              if(RetRstField("SELECT fnid FROM txovertime_money_hdr WHERE ftovertime_money_no='{$_REQUEST['fttrans_no']}'")) {
                  ?>

                  alert('No. transaksi sudah dipakai...\n System akan mengenerate No. transaksi kembali ...\n Silahkan ulangi proses penyimpanan...  ');
                  OnChangeDate_fdtrans_date();
            <?php
              }
              else {
                    ?>


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

            <?php
              }
			   die("");
            break;
        }
       
    }
    if(!$_REQUEST['id']) {
            $strAutoNumber1="ajax_do('query2.php?code=2&ftmodule_code=hrd008&thbln=' + document.getElementById(\"fdtrans_date\").value + '&field_name=ftovertime_money_no&no_trans=ftovertime_money_no&table_name=txovertime_money_hdr');";

            $strAutoNumber0=" function OnChangeDate_fdtrans_date() {
                                           {$strAutoNumber1}

                                          
                                     }
                                     OnChangeDate_fdtrans_date();
										  var i=document.getElementsByName('fnindexD0[]').length;
											document.getElementById(\"TransactionDetail0\").deleteRow(2);
                                ";

            $objAxpDB->FormJS($strAutoNumber0);
     }
  // Deklarasi UctVw
    $objAxpDB->ViewName("Daftar Pembayaran Uang Lembur");
    $objAxpDB->ViewTable("vHRPembayaranUangLembur");
    $objAxpDB->ViewSQL("select a.fnid, a.ftovertime_money_no, a.fdtrans_date, a.fdovertime_money_start_date, a.fdovertime_money_end_date, a.ftnotes, b.fttrans_status_name from txovertime_money_hdr  a left join tstransaction_status b on a.fnstatus=b.fntrans_status_code and b.fntrans_group_code=2 order by  a.ftovertime_money_no desc, a.fdtrans_date desc");
    $objAxpDB->ViewCaption("ID, No. Pembayaran Lembur, Tgl. Transaksi, Periode 1, Periode 2, Catatan, Status");
	$objAxpDB->ViewPeriod(TRUE);

    // Deklarasi Header & Footer
    $objAxpDB->FormName("Pembayaran Uang Lembur");
    $objAxpDB->FormSQL("select  ftovertime_money_no, fdtrans_date, fdovertime_money_start_date, fdovertime_money_end_date, ftnotes, fnstatus from txovertime_money_hdr");
    $objAxpDB->FormCaption("No. Pembayaran Lembur, Tgl. Transaksi, Periode 1, Periode 2, Catatan, Status");
    $objAxpDB->FormPosition("TL, TL, TL, TL,  BL, BR");
	if(!$_REQUEST['id']) {
		$ajax1=" OnClick=\"ajax_do('hrd.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&id=0&ajax=1&code=grid&fdovertime_money_start_date='+ document.getElementById('fdovertime_money_start_date').value +'&fdovertime_money_end_date='+ document.getElementById('fdovertime_money_end_date').value);\"";

		$objAxpDB->FormLayout(3,"<input type='button' id='cmd_process' name='cmd_process' value='Prosess' {$ajax1}>");
	}
    // Deklarasi Detail
    $objAxpDB->GridSQL(0, "select  fnindex, ftemployee_code, fneffective_days, fnovertime_money_days, fcbasic_overtime_money, fcovertime_money,  fcamount, ftdescription from txovertime_money_det");
    $objAxpDB->GridCaption(0, "No., Pegawai, Hari(Efektif), Hari(Lembur), Uang Lembur/ Periode, Uang Lembur, Penyesuaian, Catatan");


     $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("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, 1, 1, 0, 1, 1, 1");
            $objAxpDB->GridLocked(0, "1, 1, 1, 1,1,1,0,0");
    } 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,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,1,1,1,1");
    }

	if($_REQUEST['ajax']) {
           switch($_REQUEST['code']) {
           case "grid":
               ob_start();

                       $ssql="select d.fnindex as fnindex,b.ftemployee_code,
									ff10_get_fnovertime_money_days(b.ftemployee_code,'".CDate($_REQUEST['fdovertime_money_start_date'])."','".CDate($_REQUEST['fdovertime_money_end_date'])."') as fneffective_days,
									count(b.fnindex) as fnovertime_money_days,
									c.fcamount as fcbasic_overtime_money,
									sum(ff09_get_overtime(b.ftovertime_hours,c.fcamount))  as fcovertime_money,        
										sum(ff09_get_overtime(b.ftovertime_hours,c.fcamount))  as fcamount,
									d.ftdescription
								from txovertime_hdr a
									inner join txovertime_det b on a.ftovertime_no=b.ftovertime_no
									left join tlemployee_salary_inc c on c.ftsalary_category_code='A05' and b.ftemployee_code=c.ftemployee_code
									left join txovertime_money_det d on 1=0
								where a.fnstatus=1 and b.fnemployee_status=0 and 
									a.fdovertime_date>='".CDate($_REQUEST['fdovertime_money_start_date'])."' and a.fdovertime_date<='".CDate($_REQUEST['fdovertime_money_end_date'])."' 
								group by b.ftemployee_code
                                   #                               ";
                        $objAxpDB->GridSQL(0,$ssql);

					

               $objAxpDB->Process();
               $objAxpDB->setGrid2(0);
               $html = ob_get_contents();
               ob_end_clean();
               ?>

                    div = document.getElementById('txtHint0');
                    var m='<?php echo js_esc($html); ?>';
                    m= m.replace(/^\s*|\s*$/g,"");

                    div.innerHTML =m;
                    RowIndex0();
                    reSize();
                   
               <?

               break;

           }
           die("");
           exit;
    }
	
    $objAxpDB->Process();
    $objAxpDB->WriteHtmlTable();


?>
