<?php
   switch($_REQUEST[mode]) {
    case "hapus":
        
    break;    
   }

  function SaveData() {
    global $objAxpDB;
    $objAxpDB->Allow_Save(false);
    $strSQL=array();
    switch($_REQUEST[mode]) {
      case "simpan":
        $_REQUEST["fdyear"]=getDateYmd($_REQUEST["fdyear"]);
        $strSQL["Insert tlcurrency_hdr"][]="INSERT INTO tlcurrency_hdr (
                ftbranch_code, ftsimbol,
                ftdescription, fcrate, fdyear,
                ftcreated_user, fdcreated_date
                ) SELECT
                '{$_SESSION['strbranch']}' AS ftbranch_code,'{$_REQUEST['ftsimbol']}' AS ftsimbol,
                '{$_REQUEST['ftdescription']}' AS ftdescription,'".CCur($_REQUEST['fcrate'])."' AS fcrate, '{$_REQUEST['fdyear']}' AS fdyear,
                '{$_SESSION['username']}' AS ftcreated_user,now() AS fdcreated_date
                ";

        for($j=1; $j<count($_REQUEST['fnindexD0']); $j++) {
          $strSQL["Insert tlcurrency_det"][]="INSERT INTO tlcurrency_det (
                ftbranch_code, fnindex, ftsimbol,
                ftmonth, fnyear, fcrate,
                ftcreated_user, fdcreated_date,
                ftmodified_user, fdmodified_date
                ) SELECT
                '{$_SESSION['strbranch']}' AS ftbranch_code,'{$j}' AS fnindex,'{$_REQUEST['ftsimbol']}' AS ftsimbol,
                '{$_REQUEST['ftmonthD0'][$j]}' AS ftmonth,'".CCur($_REQUEST['fnyearD0'][$j])."' AS fnyear,'".CCur($_REQUEST['fcrateD0'][$j])."' AS fcrate,
                '{$_SESSION['username']}' AS ftcreated_user,now() AS fdcreated_date,
                '{$_SESSION['username']}' AS ftmodified_user,now() AS ftmodified_date";
        }
      break;
    }

    return $strSQL;
  }

  function UpdateData() {
    global $objAxpDB;
    $objAxpDB->Allow_Update(false);    
    $strSQL=array();
    switch($_REQUEST[mode]) {
    case "update":
        list($d, $m, $y)=split("/", $_REQUEST["fdyear"]);
        $_REQUEST["fdyear"]=getDateYmd($_REQUEST["fdyear"]);
        
        $strSQL["Update tlcurrency_hdr"][]="UPDATE tlcurrency_hdr SET ftdescription = '{$_REQUEST['ftdescription']}',
                fcrate = '" .CCur($_REQUEST['fcrate']). "', fdyear = '{$_REQUEST['fdyear']}', ftmodified_user = '{$_SESSION['username']}', fdmodified_date = now()
                WHERE ftsimbol = '{$_REQUEST['ftsimbol']}'";
                
        $strSQL["Delete tlcurrency_det"][]="DELETE FROM tlcurrency_det WHERE ftsimbol='{$_REQUEST['ftsimbol']}' AND fnyear='{$y}'";
        for($j=1; $j<count($_REQUEST['fnindexD0']); $j++) {
            $strSQL["Insert tlcurrency_det"][]="INSERT INTO tlcurrency_det (
                ftbranch_code, fnindex, ftsimbol,
                ftmonth, fnyear, fcrate,
                ftcreated_user, fdcreated_date,
                ftmodified_user, fdmodified_date
                ) SELECT
                '{$_SESSION['strbranch']}' AS ftbranch_code,'{$j}' AS fnindex,'{$_REQUEST['ftsimbol']}' AS ftsimbol,  
                '{$_REQUEST['ftmonthD0'][$j]}' AS ftmonth,'".CCur($_REQUEST['fnyearD0'][$j])."' AS fnyear,'".CCur($_REQUEST['fcrateD0'][$j])."' AS fcrate,
                '{$_SESSION['username']}' AS ftcreated_user,now() AS fdcreated_date,
                '{$_SESSION['username']}' AS ftmodified_user,now() AS ftmodified_date";
               
        } 
      
      break;
    }

   return $strSQL;
 }

  function DeleteData() {
    global $objAxpDB;
    $strSQL=array();
    switch($_REQUEST[mode]) {
    case "hapus":
        list($d, $m, $y)=split("/", $_REQUEST["fdyear"]);

        $strSQL["Delete tlcurrency_det"][]="DELETE FROM tlcurrency_det WHERE ftsimbol='{$_REQUEST['ftsimbol']}' AND fnyear='{$y}'";
        
      break;
    }
        
   return $strSQL;
 }