<?php


function SaveData() {
    global $objAxpDB;
    $strSQL=array();
    $objAxpDB->Allow_Save(true);
    switch($_REQUEST[mode]) {
    case "simpan":

    for($j=0; $j < count($_REQUEST['ftasset_codeD0']); $j++) {

          $penyusutan_perbulan = CCur($_REQUEST['fcmonthly_amountD0'][$j]);
          $harga_perolehan     = CCur($_REQUEST['fcacquistion_priceD0'][$j]);
          $tipe = $_REQUEST['fntypeD0'][$j];

          $penyusutan_perbulan_awal = CCur($_REQUEST['fcbalance_amountD0'][$j]);

          $ssql="SELECT IFNULL(SUM(a.fcmonthly_amount), 0) as fcmonthly_amount_tot FROM txdepriciation_det a, txdepriciation_hdr b WHERE
           a.ftasset_code = '{$_REQUEST['ftasset_codeD0'][$j]}' AND a.fttrans_code=b.fttrans_code AND b.fnstatus=1";

          $mysql=mysql_query($ssql);
          $r2=mysql_fetch_assoc($mysql);

          $fcbalance_amount= $harga_perolehan - ($r2["fcmonthly_amount_tot"] + $penyusutan_perbulan);

          $fcbalance_amount=($fcbalance_amount > 0) ? $fcbalance_amount: 0;

        $strSQL['Insert Penyusutan Asset Det'][]="
         INSERT INTO txdepriciation_det
         (fnindex,
          fttrans_code,
          ftasset_code,
          fcmonthly_amount,
          fcbalance_amount,
          fcmonthly_amount_balance,
          ftcreated_user,
          fdcreated_date)
         SELECT
         '{$j}' AS fnindex,
         '{$_REQUEST['fttrans_code']}' AS fttrans_code,
         '{$_REQUEST['ftasset_codeD0'][$j]}' AS ftasset_code,
         '".CCur($_REQUEST['fcmonthly_amountD0'][$j])."' AS fcmonthly_amount,
         '".CCur($fcbalance_amount)."' AS fcbalance_amount,
         '".CCur($_REQUEST['fcbalance_amountD0'][$j])."' AS fcmonthly_amount_balance,
         '{$_SESSION['username']}' AS ftcreated_user,
          now() AS fdcreated_date";
      }


  }
    // echo "<pre>";
    // print_r($strSQL);
    // echo "</pre>";
    // die;
    return $strSQL;
 }
