<?php
   switch($_REQUEST[mode]) {
    case "hapus":
         //pr("SELECT count(fnid) FROM txgeneral_journal_det WHERE ftcoa_code='{$_REQUEST['ftCOA_Code']}'");
         //die();
         if(RetRstField("SELECT count(a.fnid) FROM txgeneral_journal_hdr a INNER JOIN txgeneral_journal_det b ON a.ftjournal_no = b.ftjournal_no WHERE ftcoa_code = '{$_REQUEST['ftCOA_Code']}' AND a.fnstatus = 1 ")) {
            echo "<script>
                alert('data ini tidak dapat di delete karena sudah digunakan ...');
                window.history.back();
            </script>";   
            die("");            
         }

    break;    
   }

    function SaveData() {
        global $objAxpDB;
        $strSQL=array();
        switch($_REQUEST[mode]) {
        case "simpan":
                if (substr($_REQUEST['ftCOA_Code'], -4) <> '0000') {
                    $ssql="SELECT DISTINCT year(fdperiodesaldo) FROM thsaldoperkiraan ORDER BY fdperiodesaldo DESC LIMIT 1";
                    $fdperiodesaldo = RetRstField($ssql);
                    $fdperiodesaldo = mktime(0,0,0,"01","01",$fdperiodesaldo);
                    $fdperiodesaldo = date("Y-m-d", $fdperiodesaldo);

                    $ssql2="SELECT MAX(fnindex) FROM thsaldoperkiraan GROUP BY YEAR(fdperiodesaldo) ORDER BY fdperiodesaldo DESC LIMIT 1";
                    $fnindex = RetRstField($ssql2) + 1;

                    $strSQL["no perkiraan"][]="insert into thsaldoperkiraan
                            (ftbranch_code,fnindex,ftkode,fdperiodesaldo,fcdebit,fccredit,ftcreated_user,fdcreated_date,ftmodified_user,fdmodified_date)
                            SELECT '{$_SESSION['strbranch']}','{$fnindex}','{$_REQUEST['ftCOA_Code']}','{$fdperiodesaldo}',0,0,'Admin',Now(),'Admin',Now()";
                }
            break;

        }

        return $strSQL;
    }


    function DeleteData() {
        global $objAxpDB;
        $strSQL=array();
        switch($_REQUEST[mode]) {
        case "hapus":
                $strSQL['DELETE no perkiraan'][]="DELETE FROM thsaldoperkiraan WHERE ftkode='{$_REQUEST['ftCOA_Code']}'";
            break;
	}

    return $strSQL;
   }


?>
