<?php

/*------------------------------------------------
$valutil = new getValueUtil();
を記述して使用
値を取得する関数
-------------------------------------------------*/
class getValueUtil {
  private $logger;

  function __construct() {
    $this->logger = new logger(basename(__FILE__));
  }

  function __destruct() {
  }

  /*
  name  : allMastData
  func  : マスタ情報全項目取得
  io    : $stpflg : i : 0=廃止可(デフォルト), 1=廃止不可, 2=マスタ無し可
          $tblnm : i : テーブル名
          $key1 : i : key1
          $key2 : i : key2
          $key3 : i : key3
          $key4 : i : key4
          $key5 : i : key5
  return : 取得した値(配列) データなしの場合は空の配列1
  */
  public function allMastData($stpflg="0", $tblnm,$key1=null,$key2=null,$key3=null,$key4=null,$key5=null,$key6=null,$key7=null,$key8=null,$key9=null,$key10=null) {
    try {
      global $serverUtil;
      global $stringUtil;
      global $dbutil;
//$this->logger->info("allMastData_start", $tblnm);

      $w_tblnm = mb_strtoupper($tblnm);
      $file = $serverUtil->getProjectDir() . "/util/sql/alldata/".$w_tblnm.".sql";
      $sql = file_get_contents($file);

      $this->logger->info("FILE", $file);

      $whereParams = array();

      //テーブルごとに条件を変更
      if ($w_tblnm == "AFM02") {
        $cdnm = "JAN";
        $whereParams["inpcd"] = $key1;
        $whereParams["kbn"] = $key2;  //1:jan, 2:vjan, 3:jan後方一致, 9:ijan
      } else if ($w_tblnm == "AFM02E") {
        $cdnm = "IJAN";
        $whereParams["ijan"] = $key1;
        $whereParams["mcd"] = $key2;
      } else if ($w_tblnm == "AFM03") {
        $cdnm = "得意先";
        $whereParams["inpcd"] = $key1;
      } else if ($w_tblnm == "AFM03C") {
        $cdnm = "オンライン識別子";
        $whereParams["rcvdst"] = $key1;
        $whereParams["ktktcd"] = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["LGKTKTCD"];
      } else if ($w_tblnm == "AFM032") {
        $cdnm = "店舗";
        $whereParams["inpcd"] = $key1;
        $whereParams["cucd"] = $key2;
      } else if ($w_tblnm == "AFM036") {
        $cdnm = "得意先センター";
        $whereParams["cshcd"] = $key1;
        $whereParams["cucd"] = $key2;
      } else if ($w_tblnm == "AFM04") {
        $cdnm = "仕入先";
        $whereParams["inpcd"] = $key1;
      } else if ($w_tblnm == "AFM05") {
        if ($key2 <> "2") {
          $cdnm = "倉庫";
        } else {
          $cdnm = "拠点";
        }
        $whereParams["inpcd"] = $key1;
      } else if ($w_tblnm == "AFM08") {
        $cdnm = "担当者";
        $whereParams["chgcd"] = $key1;
      } else if ($w_tblnm == "AFM90") {
        $cdnm = "コード";
        $whereParams["cls"] = $key1;
        $whereParams["scls1"] = $key2;
      } else if ($w_tblnm == "AXM99") {
        $cdnm = "制御";
        $whereParams["ktktcd"] = $key1;
      } else if ($w_tblnm == "AXM993A") {
        $cdnm = "権限";
        $whereParams["apid"] = $key1;
      }
$this->logger->info($w_tblnm.">>",$sql);
$this->logger->info($w_tblnm.">>",$whereParams);
      $result = $dbutil->select($sql, $whereParams);
$this->logger->info($w_tblnm."ret>>",$result);
      if ($result == null) {
        $result = array();
        $obj = [
          "cd"=>"",
          "ret"=>"-1",
          "msg"=>"入力された".$cdnm."は未登録です。"
        ];
        array_push($result, $obj);

        if ($w_tblnm == "AFM03") {
          $result[0]["cucd"] = $key1;
          $result[0]["retcucd"] = "";
        } else if ($w_tblnm == "AFM032") {
          $result[0]["cuscd"] = $key1;
          $result[0]["retcucd"] = "";
        } else if($w_tblnm == "AFM02") {
          $result[0]["jan"] = $key1;
        }

        if($stpflg == "2") {
          $result[0]["ret"] = '0';
        } else {
          $result[0]["ret"] = "-1";
//          $result[0]["msg"] = "該当データがありません";
        }
      } else {
        $result[0]["retcucd"] = $result[0]["cucd"];
        if ($stpflg == "1" && $result[0]["stpflg"] == "1") { //廃止エラー
          $result[0]["ret"] = "-1";
          $result[0]["msg"] = "該当データは廃止されています。";
        } else {
          $result[0]["cdnm"] = $cdnm;
          $result[0]["ret"] = "0";
        }
      }

//$this->logger->info($result);


    } catch(Exception $e) {
      throw new userException("E0003", "エラーが発生しました。", "", __FILE__, __LINE__);
    }

    return $result[0];
  }


    /*
  name  : chkAfm02CntB4GetNm
  func  : 名称取得前のafm02のチェック
          ret=0 で、返り値のinpcdを使用し、その後の処理(get allMMastData)に進む
  io    : $cucd   : i :
          $stpflg : i :
  return:   ret:  0: その後の処理(get allMMastData)に進む
                     (前方検索件数<=1)
            ret: -2: 前方検索で複数ヒット → 複数検索画面を開く
  */
  public function chkAfm02CntB4GetNm($inpcd,$stpflg) {
    $retData = array (
      "ret" => "0",      //0: 次の処理(get allMstData へ進む), -2: 複数ヒット。複数選択画面を開く
      "inpcd" => ""      //ret=0の場合に、マスタに当てるcucd
    );

    try {
      global $stringUtil;
      global $serverUtil;
      global $dbutil;

      if(strlen($inpcd) >= 4 && strlen($inpcd) <= 6) {
        //条件
        $file = $serverUtil->getProjectDir() . "/util/sql/chkAfm02CntB4GetNm.sql";
        $this->logger->info("FILE", $file);

        $whereParams = array();
        $whereParams["inpcd"] = $inpcd;
        $whereParams["stpflg"] = $stpflg;
        $sql = file_get_contents($file);
        $result = $dbutil->selectNoCount($sql, $whereParams);
$this->logger->info("ret_chkAfm02CngB4GetNm",$result);

        if((int)$result[0]["w_hitcnt"] == 1) {
          //後方一致で結果1件なら、そのcucdで名称取得する
          $retData["inpcd"] = $result[0]["w_max"];
        } else if((int)$result[0]["w_hitcnt"] > 1) {
          //後方一致で結果複数なら、複数検索画面を上げる
          $retData["ret"] = "-2";
          $retData["msg"] = "複数件ヒット";
        } else {
          //前方一致で結果0件なら、そのまま返す
          $retData["inpcd"] = $inpcd;
        }
      } else if (strlen($inpcd) == 12) {
        //条件
        $file = $serverUtil->getProjectDir() . "/util/sql/getComnpackMakeCD.sql";
        $this->logger->info("FILE", $file);
        $whereParams = array();
        $whereParams["pmode"] = '4';
        $whereParams["inpcd"] = $inpcd;
        $sql = file_get_contents($file);
        $result = $dbutil->selectNoCount($sql, $whereParams);
        $retData["inpcd"] = $result[0]["inpcd"];
      } else {
        $retData["inpcd"] = $inpcd;
      }

    } catch(userException $ue) {
      $dbutil->rollback();
    } catch(Exception $e) {
      $dbutil->rollback();
    }
    return $retData;
  }

    /*
  name  : chkAfm03CntB4GetNm
  func  : 名称取得前のafm03のチェック
          ret=0 で、返り値のcucdを追加い、その後の処理(get allMMastData)に進む
  io    : $cucd   : i :
          $stpflg : i :
          $cntchk : i : 1=件数チェックしない コードのみ戻す マスタメンテ用
  return:   ret:  0: その後の処理(get allMMastData)に進む
                     (前方検索件数<=1)
            ret: -2: 前方検索で複数ヒット → 複数検索画面を開く
  */
  public function chkAfm03CntB4GetNm($cucd,$stpflg,$cntchk) {
    $retData = array (
      "ret" => "0",      //0: 次の処理(get allMstData へ進む), -2: 複数ヒット。複数選択画面を開く
      "cucd" => ""      //ret=0の場合に、マスタに当てるcucd
    );

    try {
      global $stringUtil;
      global $serverUtil;
      global $dbutil;


      $retAxm994 = $this->getAxm994("CUCD");
      if ($retAxm994 == null){
        $r01 = "4";  //得意先ｺｰﾄﾞ桁数
        $r02 = "0";  //0:後0埋め,1:前0埋め
      } else {
        $r01 = $retAxm994["r01"];  //得意先ｺｰﾄﾞ桁数
        $r02 = $retAxm994["r02"];  //0:後0埋め,1:前0埋め
      }
      $this->logger->info("chkAfm03CntB4GetNm_r01:".$r01.", r02:".$r02);

      if(strlen($cucd) < (int)$r01) {
        //条件
        $file = $serverUtil->getProjectDir() . "/util/sql/chkAfm03CntB4GetNm.sql";
        $this->logger->info("FILE", $file);

        if ($cntchk == "1") { //件数チェックしない
          if($r02 == '0') {
            //後(右)0埋め
            $retData["cucd"] = str_pad($cucd,(int)$r01,'0',STR_PAD_RIGHT);
          } else if ($r02 == '1'){
            //前(左)0埋め
            $retData["cucd"] = str_pad($cucd,(int)$r01,'0',STR_PAD_LEFT);
          } else {
            $retData["cucd"] = $cucd;
          }

        } else {
          $whereParams = array();
          $whereParams["cucd"] = $cucd;
          $whereParams["stpflg"] = $stpflg;
          $sql = file_get_contents($file);
          $result = $dbutil->selectNoCount($sql, $whereParams);
          $this->logger->info("chkAfm03CntB4GetNm", $result);

          if((int)$result[0]["w_hitcnt"] == 1) {
            //前方一致で結果1件なら、そのcucdで名称取得する
            $retData["cucd"] = $result[0]["w_max"];
          } else if((int)$result[0]["w_hitcnt"] > 1) {
            //前方一致で結果複数なら、複数検索画面を上げる
            $retData["ret"] = "-2";
            $retData["msg"] = "複数件ヒット";
          } else {
            //前方一致で結果0件なら、lpad or rpadした値を返して、そのcucdで名称取得する

            if($r02 == '0') {
              //後(右)0埋め
              $retData["cucd"] = str_pad($cucd,(int)$r01,'0',STR_PAD_RIGHT);
            } else if ($r02 == '1'){
              //前(左)0埋め
              $retData["cucd"] = str_pad($cucd,(int)$r01,'0',STR_PAD_LEFT);
            } else {
              $retData["cucd"] = $cucd;
            }
          }
        }

      } else {
        $retData["cucd"] = substr($cucd,0,(int)$r01);
      }

    } catch(userException $ue) {
      $dbutil->rollback();
    } catch(Exception $e) {
      $dbutil->rollback();
    }
    return $retData;
  }

  /*
name  : getAfm032Cuscd
func  : cuscdをlpad or rpad
io    : $cuscd   : i :
        $stpflg : i :
return:   ret:  0: 0固定
*/

public function getAfm032Cuscd($cuscd) {
  $retData = array (
    "ret" => "0",      //0固定
    "cuscd" => ""      //マスタに充てるcuscd
  );

  try {
    global $stringUtil;
    global $serverUtil;
    global $dbutil;

    $retAxm994 = $this->getAxm994("CUSCD");
    if ($retAxm994 == null) {
      $r01 = "6";  //店舗ｺｰﾄﾞ桁数
      $r02 = "2";  //0:後0埋め,1:前0埋め
    } else {
      $r01 = $retAxm994["r01"];  //店舗ｺｰﾄﾞ桁数
      $r02 = $retAxm994["r02"];  //0:後0埋め,1:前0埋め,2:0埋めしない
    }
    $this->logger->info("getAfm032Cuscd_r01:".$r01.", r02:".$r02);

    if(strlen($cuscd) < (int)$r01) { //桁数に満たない
$this->logger->info("cuscd=".$cuscd."len=".strlen($cuscd));
      //pad or rpadした値を返す
      if($r02 == '0') {
        //後(右)0埋め
        $retData["cuscd"] = str_pad($cuscd,(int)$r01,'0',STR_PAD_RIGHT);
      } else if ($r02 == '1'){
        //前(左)0埋め
        $retData["cuscd"] = str_pad($cuscd,(int)$r01,'0',STR_PAD_LEFT);
      } else {
        $retData["cuscd"] = $cuscd;
      }
    } else {
      $retData["cuscd"] = substr($cuscd,0,(int)$r01);
    }
//$this->logger->info("getAfm032Cuscd_ret:",$retData);

  } catch(userException $ue) {
    $dbutil->rollback();
  } catch(Exception $e) {
    $dbutil->rollback();
  }
  return $retData;
}

/*
name  : getAxm99
func  : axm99の取得
io    : $ktktcd : i ktktcd
return: 結果
*/
public function getAxm99($ktktcd = null) {
try {
  global $serverUtil;
  global $stringUtil;

  $file = $serverUtil->getProjectDir() . "/util/sql/get_axm99.sql";
  $this->logger->info("FILE", $file);
  global $dbutil;

  if ($stringUtil->isEmpty($ktktcd)) {
    $ktktcd = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["LGKTKTCD"];
  }
  //条件
  $whereParams["ktktcd"] = $ktktcd;
  $sql = file_get_contents($file);
  $result = $dbutil->selectNoCount($sql, $whereParams);
  if ($result == null) {
    $retData = array();
  } else {
    $retData = $result[0];
  }
} catch(userException $ue) {
  $dbutil->rollback();
} catch(Exception $e) {
  $dbutil->rollback();
}
return $retData;
}

    /*
  name  : getAxm994
  func  : axm994の取得
  io    : $cls  : i : cls
        : $cls1 : i : cls1 (default null)
  return: 結果
  */
  public function getAxm994($cls,$cls1=null) {
    try {
      global $serverUtil;
      $file = $serverUtil->getProjectDir() . "/util/sql/get_axm994.sql";
      $this->logger->info("FILE", $file);
      global $dbutil;
      //条件
      $whereParams["cls"] = $cls;
      $whereParams["cls1"] = $cls1;
      $sql = file_get_contents($file);
      $result = $dbutil->selectNoCount($sql, $whereParams);
      if ($result == null) {
        $retData = array();
      } else {
        $retData = $result[0];
      }
    } catch(userException $ue) {
      $dbutil->rollback();
    } catch(Exception $e) {
      $dbutil->rollback();
    }
    return $retData;
  }


  /*
name  : getSbat
func  : get_sbat起動
io    : $cls   : i : cls
      : $pmode : i : mode
      : $ktktcd : i : ktktcd
      : $cucd : i : cucd
      : $cuscd : i : cuscd
return: 結果(sbat, cdat(yyyy/mm/dd), sts, ret=0 OK
*/
public function getSbat($cls, $pmode, $ktktcd, $cucd, $cuscd) {
  try {
    global $serverUtil;
    $file = $serverUtil->getProjectDir() . "/util/sql/get_sbat.sql";
    $this->logger->info("FILE", $file);
    global $dbutil;
    //条件
    $whereParams = array();
    $whereParams["cls"]["in"] = $cls;
    $whereParams["pmode"]["in"] = $pmode;
    $whereParams["ktktcd"]["in"] = $ktktcd;
    $whereParams["cucd"]["in"] = $cucd;
    $whereParams["cuscd"]["in"] = $cuscd;
    $whereParams["sbat"]["out"] = "";
    $whereParams["cdat"]["out"] = "";
    $whereParams["sts"]["out"] = "";
    $whereParams["ret"]["out"] = "";
    $sql = file_get_contents($file);
$this->logger->info($sql, $whereParams);
    $result = $dbutil->call($sql, $whereParams);
$this->logger->info($result);
  } catch(userException $ue) {
    $result = array();
    return $result;
  } catch(Exception $e) {
    $result = array();
    return $result;
  }
  return $result;
}

/*
name  : getMaxRecord
func  : afm03より伝票の最大行を取得、nullの時は99行
io    :  PCUCD : in :
return : cnt
*/
public function getMaxRecord($pcucd) {
  try {
    global $serverUtil;
    $file = $serverUtil->getProjectDir() . "/util/sql/getMaxRecord.sql";
    $this->logger->info("FILE", $file);
    global $dbutil;
    //条件
    $whereParams = array();
    $whereParams["cucd"] = $pcucd;
    $sql = file_get_contents($file);
    $this->logger->info('getMaxRecord', $whereParams);
    $result = $dbutil->selectNoCount($sql, $whereParams);
    $ret = $result['ret'];
  } catch(userException $ue) {
//      $dbutil->rollback();
      return 99;
  } catch(Exception $e) {
//      $dbutil->rollback();
      return 99;
  }
  return $result[0]["cnt"];
}

/*
name  : chk_adat
func  : chk_adat(plsql)
io       =	p_cls	  : i : 1:売上入力、得意先返品入力、入金入力
                          2:請求訂正
                          3:支払入力、仕入入力等
            p_ktktcd  : i  : 拠点ｺｰﾄﾞ
            p_cucd	  : i  : 得意先コード
            p_cuscd		  : i  : 店舗コード
            p_adat : i  : 日付(yyyy/mm/dd)
*/
public function chk_adat($cls, $ktktcd=null, $cucd, $cuscd, $adat) {
  try {
    global $serverUtil;
    $file = $serverUtil->getProjectDir() . "/util/sql/chk_adat.sql";
    $this->logger->info("FILE", $file);
    global $dbutil;
    global $stringUtil;

    if($stringUtil->isEmpty($ktktcd)) {
      $ktktcd = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["LGKTKTCD"];
    }

    //条件
    $whereParams = array();
    $whereParams["cls"]    = $cls;
    $whereParams["ktktcd"]  = $ktktcd;
    $whereParams["cucd"]   = $cucd;
    $whereParams["cuscd"]   = $cuscd;
    $whereParams["adat"]  = $adat;

    $sql = file_get_contents($file);
    $this->logger->info('chk_adat_where', $whereParams);
    $result = $dbutil->select($sql, $whereParams);
  } catch(userException $ue) {
//    $dbutil->rollback();
    return 0;
  } catch(Exception $e) {
//    $dbutil->rollback();
    return 0;
  }
  return $result[0]["ret"];
}

/*
name  : calc_amt
func  : calc_amt(plsql)
io       =	p_cucd	  : i : 得意先コード
            p_pno		  : i  : 数量
            p_icst	  : i  : 入力単価
            p_kbn		  : i  : 1:得意先,2:仕入先
            p_ktktcd  : i  : 拠点ｺｰﾄﾞ
            p_cutaxc  : i  : 端数処理区分
*/
public function calc_amt($cucd,$pno,$cst,$kbn='1',$ktktcd=null,$cutaxc=null) {
  try {
    global $serverUtil;
    $file = $serverUtil->getProjectDir() . "/util/sql/calc_amt.sql";
    $this->logger->info("FILE", $file);
    global $dbutil;
    global $stringUtil;

    if($stringUtil->isEmpty($ktktcd)) {
      $ktktcd = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["LGKTKTCD"];
    }

    //条件
    $whereParams = array();
    $whereParams["cucd"]    = $cucd;
    $whereParams["pno"]     = $stringUtil->toNumber($pno);
    $whereParams["cst"]     = $stringUtil->toNumber($cst);
    $whereParams["kbn"]     = $kbn;
    $whereParams["ktktcd"]  = $ktktcd;
    $whereParams["cutaxc"]  = $cutaxc;

    $sql = file_get_contents($file);
    $this->logger->info('calc_amt_where', $whereParams);
    $result = $dbutil->select($sql, $whereParams);
  } catch(userException $ue) {
//    $dbutil->rollback();
    return 0;
  } catch(Exception $e) {
//    $dbutil->rollback();
    return 0;
  }
  return $result[0]["amt"];
}

/*
name  : get_gdbcst
func  : get_gdbcst(plsql)
io       =	p_ijan		  : i  : IJAN
            p_cucd	  : i : 得意先コード
            p_dat	  : i  : 日付
*/
public function get_gdbcst($ijan, $cucd, $dat) {
  try {
    global $serverUtil;
    $file = $serverUtil->getProjectDir() . "/util/sql/get_gdbcst.sql";
    $this->logger->info("FILE", $file);
    global $dbutil;
    global $stringUtil;

    //条件
    $whereParams = array();
    $whereParams["ijan"]    = $ijan;
    $whereParams["cucd"]    = $cucd;
    $whereParams["dat"]  = $dat;

    $sql = file_get_contents($file);
    $this->logger->info('get_gdbcst_where', $whereParams);
//$this->logger->info($sql, $whereParams);
    $result = $dbutil->select($sql, $whereParams);
//$this->logger->info("gdbcst>>",$result);
  } catch(userException $ue) {
//    $dbutil->rollback();
    return 0;
  } catch(Exception $e) {
//    $dbutil->rollback();
    return 0;
  }
  return $result[0]["amt"];
}

/*
name  : calc_gdbcst
func  : calc_gdbcst(plsql)
io       =	p_cls    : i : 1:税抜単価取得，2：税込単価取得，3:税額取得
            p_kbn    : i : 1:得意先,2:仕入先(未使用)
            p_ktktcd : i : 拠点ｺｰﾄﾞ
            p_cucd   : i : 得意先
            p_ijan	 : i : IJAN
            p_icst	 : i : 単価
            p_dat	   : i : 日付
*/
public function calc_gdbcst($cls, $kbn, $ktktcd, $cucd, $ijan, $icst, $dat) {
  try {
    global $serverUtil;
    $file = $serverUtil->getProjectDir() . "/util/sql/calc_gdbcst.sql";
    $this->logger->info("FILE", $file);
    global $dbutil;
    global $stringUtil;

    //条件
    $whereParams = array();
    $whereParams["cls"]     = $cls;
    $whereParams["kbn"]     = $kbn;
    $whereParams["ktktcd"]  = $ktktcd;
    $whereParams["cucd"]    = $cucd;
    $whereParams["ijan"]    = $ijan;
    $whereParams["icst"]    = $icst;
    $whereParams["dat"]     = $dat;

    $sql = file_get_contents($file);
    $this->logger->info('calc_gdbcst_where', $whereParams);
    $result = $dbutil->select($sql, $whereParams);
  } catch(userException $ue) {
//    $dbutil->rollback();
    return 0;
  } catch(Exception $e) {
//    $dbutil->rollback();
    return 0;
  }
  return $result[0]["amt"];
}

/*
name  : get_ntcst
func  : get_ntcst(plsql)
io       =	p_ktktcd : i :
            p_ijan		  : i  : IJAN
            p_cucd : i : 得意先
            p_dat	  : i  : 日付
            p_gdbcst	  : i : 単価
*/
public function get_ntcst($ktktcd, $ijan, $cucd, $dat, $gdbcst) {
  try {
    global $serverUtil;
    $file = $serverUtil->getProjectDir() . "/util/sql/get_ntcst.sql";
    $this->logger->info("FILE", $file);
    global $dbutil;
    global $stringUtil;

    //条件
    $whereParams = array();
    $whereParams["ktktcd"]    = $ktktcd;
    $whereParams["ijan"]    = $ijan;
    $whereParams["cucd"]    = $cucd;
    $whereParams["dat"]  = $dat;
    $whereParams["gdbcst"]    = $gdbcst;

    $sql = file_get_contents($file);
    $this->logger->info('get_ntcst_where', $whereParams);
    $result = $dbutil->select($sql, $whereParams);
  } catch(userException $ue) {
//    $dbutil->rollback();
    return 0;
  } catch(Exception $e) {
//    $dbutil->rollback();
    return 0;
  }
  return $result[0]["amt"];
}

/*
name  : get_gdcst
func  : get_gdcst(plsql)
io       =	p_ijan		  : i  : IJAN
            p_mcd : i : mcd 未指定可
*/
public function get_gdcst($ijan,$mcd="") {
  try {
    global $serverUtil;
    $file = $serverUtil->getProjectDir() . "/util/sql/get_gdcst.sql";
    $this->logger->info("FILE", $file);
    global $dbutil;
    global $stringUtil;

    //条件
    $whereParams = array();
    $whereParams["ijan"]    = $ijan;
    $whereParams["mcd"]    = $mcd;

    $sql = file_get_contents($file);
    $this->logger->info('get_gdcst_where', $whereParams);
    $result = $dbutil->select($sql, $whereParams);
  } catch(userException $ue) {
//    $dbutil->rollback();
    return 0;
  } catch(Exception $e) {
//    $dbutil->rollback();
    return 0;
  }
  return $result[0]["amt"];
}

/*
name  : get_gdhcst
func  : get_gdhcst(plsql)
io       =	p_ijan		  : i  : IJAN
            p_mcd : i : mcd 未指定可
*/
public function get_gdhcst($ijan,$mcd="") {
  try {
    global $serverUtil;
    $file = $serverUtil->getProjectDir() . "/util/sql/get_gdhcst.sql";
    $this->logger->info("FILE", $file);
    global $dbutil;
    global $stringUtil;

    //条件
    $whereParams = array();
    $whereParams["ijan"]    = $ijan;
    $whereParams["mcd"]    = $mcd;

    $sql = file_get_contents($file);
    $this->logger->info('get_gdcst_where', $whereParams);
    $result = $dbutil->select($sql, $whereParams);
  } catch(userException $ue) {
//    $dbutil->rollback();
    return 0;
  } catch(Exception $e) {
//    $dbutil->rollback();
    return 0;
  }
  return $result[0]["amt"];
}

/*
name  : get_gdsal
func  : get_gdsal(plsql)
io       =	p_ijan		  : i  : IJAN
         = p_cucd : : i cucd
*/
public function get_gdsal($ijan, $cucd) {
  try {
    global $serverUtil;
    $file = $serverUtil->getProjectDir() . "/util/sql/get_gdsal.sql";
    $this->logger->info("FILE", $file);
    global $dbutil;
    global $stringUtil;

    //条件
    $whereParams = array();
    $whereParams["ijan"]    = $ijan;
    $whereParams["cucd"]    = $cucd;

    $sql = file_get_contents($file);
    $this->logger->info('get_gdsal_where', $whereParams);
    $result = $dbutil->select($sql, $whereParams);
  } catch(userException $ue) {
//    $dbutil->rollback();
    return 0;
  } catch(Exception $e) {
//    $dbutil->rollback();
    return 0;
  }
  return $result[0]["amt"];
}


/*
name  : gdt_gdbcstEx
func  : get_gdbcstEx( 受注入力と、直送発注入力で使用。元々Forms内で頑張って書かれていたので、そのままもってきた )
io       =	p_ijan     : i : IJAN
         =  p_cucd     : i : cucd
         =  p_dat      : i : dat(期日)
         =  p_cutaxcls : i : 総額得意先の単価入力制御(axm994.cls()) 0:税抜入力/1:税込入力
         =  p_cutax    : i : 消費税伝票表示区分(afm03.cutax) NULL:外税 1:原価総額
*/
public function get_gdbcstEx($ijan, $cucd, $dat, $cutaxcls=null, $cutax=null) {
  try {
    global $serverUtil;
    $file = $serverUtil->getProjectDir() . "/util/sql/get_gdbcstEx.sql";
    $this->logger->info("FILE", $file);
    global $dbutil;
    global $stringUtil;

    //条件
    $whereParams = array();
    $whereParams["ijan"]["in"]     = $ijan;
    $whereParams["cucd"]["in"]     = $cucd;
    $whereParams["dat"]["in"]      = $dat;
    $whereParams["cutaxcls"]["in"] = $cutaxcls;
    $whereParams["cutax"]["in"]    = $cutax;
    $whereParams["gdbcst"]["out"]  = "";

    $sql = file_get_contents($file);
    $this->logger->info('get_gdbcstEx', $whereParams);
    $result = $dbutil->call($sql, $whereParams);
  } catch(userException $ue) {
//    $dbutil->rollback();
    return 0;
  } catch(Exception $e) {
//    $dbutil->rollback();
    return 0;
  }
  return $result["gdbcst"];
}



/*
name  : FmGetTaxrdivTaxrt
func  : 税率関連を取得
io    :  ijan : in:
         climit : in : yyyy/mm/dd(基準日)
         ktktcd : in : ログイン拠点
return : Array["taxdiv","taxrtcls","taxrt"]
*/
public function FmGetTaxrdivTaxrt($ijan, $dat, $ktktcd) {
  try {
    global $serverUtil;
    $file = $serverUtil->getProjectDir() . "/util/sql/FmGetTaxrdivTaxrt.sql";
    $this->logger->info("FILE", $file);
    global $dbutil;
    $ret_array = array();

    //条件
    $whereParams = array();
    $whereParams["ijan"]['in'] = $ijan;
    $whereParams["dat"]['in'] = $dat;
    $whereParams["ktktcd"]['in'] = $ktktcd;

    $whereParams["gdtax"]['out'] = '';
    $whereParams["gdtaxrt"]['out'] = '';
    $whereParams["taxrt"]['out'] = '';

    $sql = file_get_contents($file);
    $this->logger->info('FmGetTaxrdivTaxrt_sql', $sql);
    $this->logger->info('FmGetTaxrdivTaxrt_whereParams', $whereParams);
    $ret_array = $dbutil->call($sql, $whereParams);
    $ret_afm90 = $this->allMastData("","afm90","Z",$ret_array["gdtax"]);
    $ret_array["taxinfo"] = $ret_array["taxrt"]."% ".$ret_afm90["nm"];

  } catch(userException $ue) {
//      $dbutil->rollback();
  } catch(Exception $e) {
//      $dbutil->rollback();
  }
  return $ret_array;
}
/*
name : getVSeq
func : Get_VSeq(plsql)
io   : p_cls : i :
     : p_ktktcd : i :
     : p_cucd : i :
return : vseq
*/
public function getVSeq($pcls, $ktktcd, $cucd) {
  try {
    global $serverUtil;
    $file = $serverUtil->getProjectDir() . "/util/sql/getVseq.sql";
    $this->logger->info("FILE", $file);
    global $dbutil;
    //条件
    $whereParams["pcls"]['in'] = $pcls;
    $whereParams["ktktcd"]['in'] = $ktktcd;
    $whereParams["cucd"]['in']  = $cucd;
    $whereParams["ret"]['out'] = '';

    $sql = file_get_contents($file);
    $result = $dbutil->call($sql, $whereParams);
  } catch(userException $ue) {
    return "";
  } catch(Exception $e) {
    return "";
  }
  return $result["ret"];
}

/*
name : getSeq
func : Get_Seq(plsql)
io     = p_cls      : i : 0:受注(FAX)
                          1:発注
                          2:転送受注(出庫)
                          3:売上
                          4:得意先返品
                          5:得意先直送返品
                          6:入金
                          7:発注なし入荷
                          8:発注なし仕入
                          9:仕入先返品
                         10:支払
                         11:廃棄
return : seq

*/
public function get_seq($cls) {
  try {
    global $serverUtil;
    $file = $serverUtil->getProjectDir() . "/util/sql/get_seq.sql";
    $this->logger->info("FILE", $file);
    global $dbutil;
    global $stringUtil;

    if($stringUtil->isEmpty($accd)) {
      $accd = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["ACCD"];
    }

    //条件
    $whereParams["cls"] = $cls;

    $sql = file_get_contents($file);
//      $this->logger->info('get_seq_sql', $sql);
    $this->logger->info('get_seq_where', $whereParams);
    $result = $dbutil->select($sql, $whereParams);
  } catch(userException $ue) {
//    $dbutil->rollback();
    return 0;
  } catch(Exception $e) {
//    $dbutil->rollback();
    return 0;
  }
  return $result[0]["vseq"];
}



/*
name : insertAfs73
func : afs73にinsertする
io   : bat  : nullの場合、innerbatで取得
       wsid : nullの場合、'AP&||ログインktktcd
       pid  :
       dats : nvl(入力値(yyyy/mm/dd hh24:mi:ss),sysdate)
       datt : nvl(入力値(yyyy/mm/dd hh24:mi:ss),sysdate)
       pnm  :
       inf1 :
       inf2 :

*/
public function insertAfs73($bat,$wsid,$pid,$dats,$datt,$pnm,$inf1,$inf2) {
  try {
    global $serverUtil;
    $file = $serverUtil->getProjectDir() . "/util/sql/insertAfs73.sql";
    $this->logger->info("FILE", $file);
    global $dbutil;
    global $stringUtil;

    if($stringUtil->isEmpty($bat)) {
      $bat = $dbutil->nextVal("innerbat");
    }
    if($stringUtil->isEmpty($accd)) {
      $wsid = 'AP'.$_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["LGKTKTCD"];
    }
    if($stringUtil->isEmpty($pid)) {
      $pid = $serverUtil->getProductId();
    }

    //条件
    $whereParams["bat"] = $bat;
    $whereParams["wsid"] = $wsid;
    $whereParams["pid"] = $pid;
    $whereParams["dats"] = $dats;
    $whereParams["datt"] = $datt;
    $whereParams["pnm"] = $pnm;
    $whereParams["inf1"] = $inf1;
    $whereParams["inf2"] = $inf2;

    $sql = file_get_contents($file);
//      $this->logger->info('insertAfs73_sql', $sql);
    $this->logger->info('insertAfs73_where', $whereParams);
    $result = $dbutil->insert($sql, $whereParams);
  } catch(userException $ue) {
//    $dbutil->rollback();
    return 0;
  } catch(Exception $e) {
//    $dbutil->rollback();
    return 0;
  }
  return $result;
}



  /*
  name  : getCntImpcsv
  func  : impcsvの件数取得
  io    : $wseq
  return: 結果(全件:cnt1, 正常:cnt2, エラー:cnt3, ﾜｰﾆﾝｸﾞ:cnt4)
  */
  public function getCntImpcsv($wseq) {
    try {
      global $serverUtil;
      $file = $serverUtil->getProjectDir() . "/util/sql/get_cnt_impcsv.sql";
      $this->logger->info("FILE", $file);
      global $dbutil;
      //条件
      $whereParams["wseq"] = $wseq;
      $sql = file_get_contents($file);
      $result = $dbutil->selectNoCount($sql, $whereParams);
      $retData = $result[0];
    } catch(userException $ue) {
      $dbutil->rollback();
    } catch(Exception $e) {
      $dbutil->rollback();
    }
    return $retData;
  }


}



?>
