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

                      alert('Kode kurs sudah dipakai ... ');
                <?php
                  }
                  else {
                        ?>


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

                <?php
                  }
                  
                break;
            }       
        }

    GetSecurity('kurs');

    $objAxpDB->LookupMagicQuotes(True);
    $objAxpDB->ViewName("Daftar Kurs");
    //$objAxpDB->ViewTable("vKUKurs");
    $objAxpDB->ViewSQL("SELECT fnid, ftsimbol, ftdescription,fcrate FROM tlcurrency_hdr ORDER BY ftsimbol, ftdescription");
    $objAxpDB->ViewCaption("ID, Kode Mata Uang, Nama Mata, Kurs");

    $objAxpDB->FormName("Kurs");
    $objAxpDB->FormSQL("SELECT  ftsimbol, ftdescription ,fcrate, fdyear FROM tlcurrency_hdr");
    $objAxpDB->FormCaption("Kode Mata Uang, Nama Mata, Kurs, Tahun");
    $objAxpDB->FormPosition("TL, TL, TL, TL");
    
    $strAutoNumber1="ajax_do('keuangan.php?form=".$_REQUEST['form']."&mode=".$_REQUEST['mode']."&ajax=1&code=grid&fnyear=' + document.getElementById('fdyear').value + '&ftsimbol=' + document.getElementById('ftsimbol').value);";
    $strAutoNumber0=" function OnChangeDate_fdyear() {
                         {$strAutoNumber1}
                      }

                      OnChangeDate_fdyear();";
    $objAxpDB->FormJS($strAutoNumber0);

    $objAxpDB->GridSQL(0, "SELECT fnindex, ftsimbol, ftmonth, IFNULL(fnyear, ''), fcrate FROM tlcurrency_det");
    $objAxpDB->GridCaption(0, "No., Kode, Bulan , Tahun, Kurs");

    $objAxpDB->SetStatus("id");                        
    if ($objAxpDB->GetStatus("id") == "") {
            $objAxpDB->ButtonShow("baru");

    }
    elseif ($objAxpDB->GetStatus("id") == 0) {
            $objAxpDB->GridLocked(0, "1, 1, 1, 1, 0");
            $objAxpDB->ButtonShow("reset, simpan, tutup");

    }
    elseif ($objAxpDB->GetStatus("id") != 0) {
            $objAxpDB->ButtonShow("update, hapus, tutup");
            $objAxpDB->GridLocked(0, "1, 1, 1, 1, 0");
            $objAxpDB->FormLocked("1, 0");
    }

    if($_REQUEST['ajax']) {
     switch($_REQUEST['code']) {
       case "grid":
          ob_start();
          list($d, $m, $y)=split("/", $_REQUEST["fnyear"]);
          $fnyear=$y;
          $ssql="SELECT a.fnindex, b.ftsimbol, a.ftmonth, a.fnyear, IFNULL(b.fcrate, CONVERT(0, DECIMAL(19, 4))) AS fcrate FROM (";
          for($i=1; $i<=12; $i++){
            $ssql.=" SELECT $i AS fnindex, MONTHNAME(STR_TO_DATE({$i}, '%m')) AS ftmonth, '{$fnyear}' AS fnyear ";
            if($i!=12) $ssql.=" UNION ALL ";
          }
          $ssql.=" ) AS a LEFT JOIN tlcurrency_det b ON a.ftmonth=b.ftmonth AND a.fnyear=b.fnyear AND b.ftsimbol='{$_REQUEST["ftsimbol"]}' #";

          $objAxpDB->GridSQL(0,$ssql);
          $objAxpDB->GridLocked(0, "1, 1, 1, 1, 0");
          $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();-->
          <?php
          break;
            }
      exit;
    }

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