<?php
trait SQLLIB {
/*----------------------------------------------------------------------------*/
/* Construct                                                                  */
/*----------------------------------------------------------------------------*/
    private function __construct($CL) {
        $CL['LG']->cLog('T0001');
        
        // 共通クラスを保持
        $this->CL = $CL;
    }
    
/*----------------------------------------------------------------------------*/
/* Clone                                                                      */
/*----------------------------------------------------------------------------*/
    public final function __clone() {
        $CL['LG']->cLog('S0002');
    }
    
/*----------------------------------------------------------------------------*/
/* Variable                                                                   */
/*----------------------------------------------------------------------------*/
/*------------------------------------*/
/* Public                             */
/*------------------------------------*/


/*------------------------------------*/
/* Private                            */
/*------------------------------------*/
    private static $instance = [];

/*------------------------------------*/
/* Protected                          */
/*------------------------------------*/
    protected $CL;


/*----------------------------------------------------------------------------*/
/* Public Function                                                            */
/*----------------------------------------------------------------------------*/
    // インスタンス作成
    public static function getInstance($CL) {
        $CL['LG']->cLog('T0002');
        $class = get_called_class();
        if (!isset(self::$instance[$class])) self::$instance[$class] = new $class($CL);
        return self::$instance[$class];
    }


/*--------------------------------------------------------*/
/* common                                                 */
/*--------------------------------------------------------*/
    /*--------------------------------------------------------------------------*/
    /* DB接続                                                                   */
    /* Arg1:mysqli                                                              */
    /*      mysqli クラス                                                       */
    /* Arg2:trnflg                                                              */
    /*      true:新規DB接続、false:Arg1のmysqliを使ってDB接続                   */
    /* Arg3:dbflg                                                               */
    /*      true:個別DB接続(会社毎)、false:共通DB接続(会社ログイン)             */
    /* Ret :mysqli クラス                                                       */
    /*--------------------------------------------------------------------------*/
    public function DBConnect($mysqli = NULL, $trnflg = true, $dbflg = true) {
        $this->CL['LG']->cLog('T0002');
        if ($trnflg == true) {
//            if (!isset($_SESSION[$this->CL['DF']->SysID]['DBHost'])) {  // セッションがないとき、強制的に共通DBに接続させる。
            if (!isset($_SESSION[$this->CL['DF']->SysID]['DBName'])) {  // セッションがないとき、強制的に共通DBに接続させる。
                $dbflg = false;
            }
            // trnflgがtrueの場合、新規DB接続する。
            if ($dbflg == true) {
                // 接続先DB:個別
//                $mysqli = new mysqli($_SESSION[$this->CL['DF']->SysID]['DBHost'], $_SESSION[$this->CL['DF']->SysID]['DBUser'], $_SESSION[$this->CL['DF']->SysID]['DBPassWord'], $_SESSION[$this->CL['DF']->SysID]['DBName']);
                $mysqli = new mysqli($this->CL['CF']->db_host, $this->CL['CF']->db_user, $this->CL['CF']->db_pass, $_SESSION[$this->CL['DF']->SysID]['DBName']);
            } else {
                // 接続先DB:共通
                $mysqli = new mysqli($this->CL['CF']->db_host, $this->CL['CF']->db_user, $this->CL['CF']->db_pass, $this->CL['CF']->db_name);
            }
            $mysqli->set_charset("utf8");
        } else if ($trnflg == false) {
            // trnflgがfalseの場合、引数で受けたmysqliをそのまま返す。
            return $mysqli;
        }

        mysqli_report(MYSQLI_REPORT_ERROR);         // SQLエラーの場合、Warningを出力させる。
        
        return $mysqli;
    }
    
    // DB切断
    public function DBClose($mysqli = NULL, $trnflg = true) {
        $this->CL['LG']->cLog('T0002');
        if ($trnflg == true) {
            // trnflgがtrueの場合、DBCloseする。
            return $mysqli->close();
			unset($mysqli);
        } else if ($trnflg == false) {
            // trnflgがfalseの場合、何もしない、
            return true;
        }
        return false;
    }
    
    // DB接続＆トランザクション開始
    public function DBConnectTrn() {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect();    // DBコネクト
        $mysqli->autocommit(false);     // 自動コミットを無効化
        return $mysqli;
    }
    
    // DBロールバック
    public function DBRollback($mysqli) {
        $this->CL['LG']->cLog('T0002');
        return $mysqli->rollback();
    }
    
    // DBコミット
    public function DBCommit($mysqli) {
        $this->CL['LG']->cLog('T0002');
        return $mysqli->commit();
    }
    
/*--------------------------------------------------------*/
/* m_login                                                */
/*--------------------------------------------------------*/
    // ログイン情報を取得する
    public function gLoginRow($id, $iid) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect(NULL, true, false);
        
        $sql  = 'SELECT LoginNo    AS LoginNo ';
        $sql .= '     , CompanyID  AS CompanyID ';
        $sql .= '     , LoginID    AS LoginID ';
        $sql .= '     , PassWord   AS PassWord ';
        $sql .= '     , Remark     AS Remark ';
        $sql .= '     , DBHost     AS DBHost ';
        $sql .= '     , DBUser     AS DBUser ';
        $sql .= '     , DBPassWord AS DBPassWord ';
        $sql .= '     , DBName     AS DBName ';
        $sql .= 'FROM   m_login ';
        $sql .= 'WHERE  CompanyID = ? ';    // $id
        $sql .= 'AND    LoginID = ? ';      // $iid
        $sql .= 'AND    Status = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $CompanyID, $LoginID);
            $CompanyID = $id;
            $LoginID   = $iid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
			$stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 同会社IDの件数を取得する
    public function gCompanyIDSameCntVal($id) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect(NULL, true, false);
        
        $sql  = 'SELECT COUNT(*) AS cnt ';
        $sql .= 'FROM   m_login ';
        $sql .= 'WHERE  CompanyID = ? ';    // $id
        $sql .= 'AND    Status = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $CompanyID);
            $CompanyID = $id;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
			$stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* m_message                                              */
/*--------------------------------------------------------*/
    // エラーメッセージを取得する(ShowCode, Msg1, Msg2)
    public function gMessage($type, $id, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ShowCode,Msg1,Msg2 ';
        $sql .= 'FROM   m_message ';
        $sql .= 'WHERE  Type   = ? ';       // $this->CL['DF']->AUTH
        $sql .= 'AND    Code   = ? ';       // $id
        $sql .= 'AND    LanguageID = ? ';   // $lang
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $Type, $Code, $LanguageID);
            $Type   = $type;
            $Code   = $id;
            $LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
			$stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* m_const                                                */
/*--------------------------------------------------------*/
    // 汎用的に取得する(全件)
    public function gConstList($constid, $byid, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ConstVal1 ';
        $sql .= '     , ConstID2 ';
        $sql .= 'FROM   m_const ';
        $sql .= 'WHERE  ConstID1   = ? ';    // $constid
        $sql .= 'AND    LanguageID = ? ';    // $lang
        $sql .= 'AND    Status     = true ';
        if ($byid) {
            $sql .= 'ORDER BY ConstID2 ';
        } else {
            $sql .= 'ORDER BY ConstVal1 ';
        }
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $ConstID1, $LanguageID);
            $ConstID1   = $constid;
            $LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
			$stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // ユーザ権限名称を取得する(一件)
    public function gConstAuthNameVal($id, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ConstVal1 AS AuthorityName ';
        $sql .= 'FROM   m_const ';
        $sql .= 'WHERE  ConstID1   = ? ';    // $this->CL['DF']->AUTH
        $sql .= 'AND    ConstID2   = ? ';    // $id
        $sql .= 'AND    LanguageID = ? ';    // $lang
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $ConstID1, $ConstID2, $LanguageID);
            $ConstID1   = $this->CL['DF']->AUTH;
            $ConstID2   = $id;
            $LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
			$stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 取引種別名称を取得する(一件)
    public function gConstTrnKindNameVal($id, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ConstVal1 AS TranKindName ';
        $sql .= 'FROM   m_const ';
        $sql .= 'WHERE  ConstID1   = ? ';    // $this->CL['DF']->TRNKIND
        $sql .= 'AND    ConstID2   = ? ';    // $id
        $sql .= 'AND    LanguageID = ? ';    // $lang
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $ConstID1, $ConstID2, $LanguageID);
            $ConstID1   = $this->CL['DF']->TRNKIND;
            $ConstID2   = $id;
            $LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
			$stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 言語名称を取得する(一件)
    public function gConstLangVal($id, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ConstVal1 AS LanguageName ';
        $sql .= 'FROM   m_const ';
        $sql .= 'WHERE  ConstID1   = ? ';    // $this->CL['DF']->LANG
        $sql .= 'AND    ConstID2   = ? ';    // $id
        $sql .= 'AND    LanguageID = ? ';    // $lang
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $ConstID1, $ConstID2, $LanguageID);
            $ConstID1   = $this->CL['DF']->LANG;
            $ConstID2   = $id;
            $LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
			$stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 単位を取得する(一件)
    public function gConstUnitVal($id, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ConstNo   AS UnitNo ';
        $sql .= '     , ConstID2  AS UnitID ';
        $sql .= '     , ConstVal1 AS UnitName ';
        $sql .= '     , ConstVal2 AS UnitRnd ';
        $sql .= '     , ConstVal3 AS UnitVal ';
        $sql .= 'FROM   m_const ';
        $sql .= 'WHERE  ConstID1   = ? ';    // $this->CL['DF']->UNIT
        $sql .= 'AND    ConstID2   = ? ';    // $id
        $sql .= 'AND    LanguageID = ? ';    // $lang
        $sql .= 'AND    Status     = true ';
        $sql .= 'ORDER BY UnitID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $ConstID1, $ConstID2, $LanguageID);
            $ConstID1   = $this->CL['DF']->UNIT;
            $ConstID2   = $id;
            $LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
			$stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 残高ゼロ表示を取得する(一件)
    public function gConstDispStsVal($id, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ConstNo   AS DispNo ';
        $sql .= '     , ConstID2  AS DispID ';
        $sql .= '     , ConstVal1 AS DispName ';
        $sql .= 'FROM   m_const ';
        $sql .= 'WHERE  ConstID1   = ? ';    // $this->CL['DF']->DISP
        $sql .= 'AND    ConstID2   = ? ';    // $id
        $sql .= 'AND    LanguageID = ? ';    // $lang
        $sql .= 'AND    Status     = true ';
        $sql .= 'ORDER BY DispID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $ConstID1, $ConstID2, $LanguageID);
            $ConstID1   = $this->CL['DF']->DISP;
            $ConstID2   = $id;
            $LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
			$stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // BS項目を取得する(一件)
    public function gConstBSVal($id, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ConstNo   AS BSNo ';
        $sql .= '     , ConstID2  AS BSID ';
        $sql .= '     , ConstVal1 AS BSName ';
        $sql .= '     , ConstVal2 AS DBKindID ';
        $sql .= 'FROM   m_const ';
        $sql .= 'WHERE  ConstID1   = ? ';    // $this->CL['DF']->BS
        $sql .= 'AND    ConstID2   = ? ';    // $id
        $sql .= 'AND    LanguageID = ? ';    // $lang
        $sql .= 'AND    Status     = true ';
        $sql .= 'ORDER BY BSID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $ConstID1, $ConstID2, $LanguageID);
            $ConstID1   = $this->CL['DF']->BS;
            $ConstID2   = $id;
            $LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
			$stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // ユーザ権限名称を取得する(全件)
    public function gConstAuthList($lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ConstVal1 AS AuthorityName ';
        $sql .= '     , ConstID2  AS AuthorityID ';
        $sql .= 'FROM   m_const ';
        $sql .= 'WHERE  ConstID1   = ? ';    // $this->CL['DF']->AUTH
        $sql .= 'AND    ConstID3   = ? ';    // $id
        $sql .= 'AND    LanguageID = ? ';    // $lang
        $sql .= 'AND    Status     = true ';
        $sql .= 'ORDER BY ConstID2 ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $ConstID1, $ConstID2, $LanguageID);
            $ConstID1   = $this->CL['DF']->AUTH;
            $ConstID2   = $this->CL['DF']->UserAuthShow;
            $LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
			$stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 言語名称を取得する(全件)
    public function gConstLangList($lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ConstVal1 AS LanguageName ';
        $sql .= '     , ConstID2  AS LanguageID ';
        $sql .= 'FROM   m_const ';
        $sql .= 'WHERE  ConstID1   = ? ';    // $this->CL['DF']->LANG
        $sql .= 'AND    LanguageID = ? ';    // $lang
        $sql .= 'AND    Status     = true ';
        $sql .= 'ORDER BY ConstID2 ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $ConstID1, $LanguageID);
            $ConstID1   = $this->CL['DF']->LANG;
            $LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
			$stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 取引種別を取得する(全件)
    public function gConstTrnKindList($lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ConstID2  AS TransactionKindID ';
        $sql .= '     , ConstVal1 AS TransactionKindName ';
        $sql .= '     , ConstVal2 AS TableName ';
        $sql .= 'FROM   m_const ';
        $sql .= 'WHERE  ConstID1   = ? ';    // $this->CL['DF']->TRNKIND
        $sql .= 'AND    LanguageID = ? ';    // $lang
        $sql .= 'AND    Status     = true ';
        $sql .= 'ORDER BY TransactionKindID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $ConstID1, $LanguageID);
            $ConstID1   = $this->CL['DF']->TRNKIND;
            $LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
			$stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 仕訳帳を取得する(全件)
    public function gConstJnlKindList($lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ConstID2  AS JournalKindID ';
        $sql .= '     , ConstVal1 AS JournalKindName ';
        $sql .= '     , ConstVal2 AS TableName ';
        $sql .= '     , ConstVal3 AS Url ';
        $sql .= 'FROM   m_const ';
        $sql .= 'WHERE  ConstID1   = ? ';    // $this->CL['DF']->JNLKIND
        $sql .= 'AND    LanguageID = ? ';    // $lang
        $sql .= 'AND    Status     = true ';
        $sql .= 'ORDER BY JournalKindID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $ConstID1, $LanguageID);
            $ConstID1   = $this->CL['DF']->JNLKIND;
            $LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
			$stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 特殊仕訳帳を取得する(全件)
    public function gConstSpeJnlKindList($lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ConstID2  AS JournalKindID ';
        $sql .= '     , ConstVal1 AS JournalKindName ';
        $sql .= '     , ConstVal2 AS TableName ';
        $sql .= 'FROM   m_const ';
        $sql .= 'WHERE  ConstID1   = ? ';    // $this->CL['DF']->JNLKIND
        $sql .= 'AND    LanguageID = ? ';    // $lang
        $sql .= 'AND    ConstID2   <> \'0\' ';  // 普通仕訳帳を除外
        $sql .= 'AND    Status     = true ';
        $sql .= 'ORDER BY JournalKindID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $ConstID1, $LanguageID);
            $ConstID1   = $this->CL['DF']->JNLKIND;
            $LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
			$stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 取引ステータスを取得する(全件)
    public function gConstTrnStsList($lang, $TrnStsID) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
//        $sql_TrnSts       = self::sArrID('m_const', $TrnStsID, 'ConstID2');               // 検索条件(固定資産種別)
        $sql_TrnSts       = self::sDataFlg('m_const', $TrnStsID, 'ConstID2');               // 検索条件(固定資産種別)
        
        $sql  = 'SELECT ConstNo   AS TransactionStatusNo ';
        $sql .= '     , ConstID2  AS TransactionStatusID ';
        $sql .= '     , ConstVal1 AS TransactionStatusName ';
        $sql .= 'FROM   m_const ';
        $sql .= 'WHERE  ConstID1   = ? ';    // $this->CL['DF']->TRNSTS
        $sql .= 'AND    LanguageID = ? ';    // $lang
        $sql .= 'AND    Status     = true ';
        $sql .= $sql_TrnSts.' ';
        $sql .= 'ORDER BY ConstID2 ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $ConstID1, $LanguageID);
            $ConstID1   = $this->CL['DF']->TRNSTS;
            $LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 取引ステータスを取得する(一件)
    public function gConstTrnStsVal($id, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ConstNo   AS TrnStsNo ';
        $sql .= '     , ConstID2  AS TrnStsID ';
        $sql .= '     , ConstVal1 AS TrnStsName ';
        $sql .= 'FROM   m_const ';
        $sql .= 'WHERE  ConstID1   = ? ';    // $this->CL['DF']->TRNSTS
        $sql .= 'AND    ConstID2   = ? ';    // $id
        $sql .= 'AND    LanguageID = ? ';    // $lang
        $sql .= 'AND    Status     = true ';
        $sql .= 'ORDER BY TrnStsID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $ConstID1, $ConstID2, $LanguageID);
            $ConstID1   = $this->CL['DF']->TRNSTS;
            $ConstID2   = $id;
            $LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 単位を取得する(全件)
    public function gConstUnitList($lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ConstNo   AS UnitNo ';
        $sql .= '     , ConstID2  AS UnitID ';
        $sql .= '     , ConstVal1 AS UnitName ';
        $sql .= '     , ConstVal2 AS UnitRnd ';
        $sql .= '     , ConstVal3 AS UnitVal ';
        $sql .= 'FROM   m_const ';
        $sql .= 'WHERE  ConstID1   = ? ';    // $this->CL['DF']->UNIT
        $sql .= 'AND    LanguageID = ? ';    // $lang
        $sql .= 'AND    Status     = true ';
        $sql .= 'ORDER BY UnitID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $ConstID1, $LanguageID);
            $ConstID1   = $this->CL['DF']->UNIT;
            $LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 残高ゼロ表示を取得する(全件)
    public function gConstDispStsList($lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ConstNo   AS DispNo ';
        $sql .= '     , ConstID2  AS DispID ';
        $sql .= '     , ConstVal1 AS DispName ';
        $sql .= 'FROM   m_const ';
        $sql .= 'WHERE  ConstID1   = ? ';    // $this->CL['DF']->DISP
        $sql .= 'AND    LanguageID = ? ';    // $lang
        $sql .= 'AND    Status     = true ';
        $sql .= 'ORDER BY DispID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $ConstID1, $LanguageID);
            $ConstID1   = $this->CL['DF']->DISP;
            $LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // BS項目を取得する(全件)
    public function gConstBSList($lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ConstNo   AS BSNo ';
        $sql .= '     , ConstID2  AS BSID ';
        $sql .= '     , ConstVal1 AS BSName ';
        $sql .= '     , ConstVal2 AS DBKindID ';
        $sql .= 'FROM   m_const ';
        $sql .= 'WHERE  ConstID1   = ? ';    // $this->CL['DF']->BS
        $sql .= 'AND    LanguageID = ? ';    // $lang
        $sql .= 'AND    Status     = true ';
        $sql .= 'ORDER BY BSID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $ConstID1, $LanguageID);
            $ConstID1   = $this->CL['DF']->BS;
            $LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // PL項目を取得する(全件)
    public function gConstPLList($lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ConstNo   AS PLNo ';
        $sql .= '     , ConstID2  AS PLID ';
        $sql .= '     , ConstVal1 AS PLName ';
        $sql .= '     , ConstVal2 AS DBKindID ';
        $sql .= 'FROM   m_const ';
        $sql .= 'WHERE  ConstID1   = ? ';    // $this->CL['DF']->PL
        $sql .= 'AND    LanguageID = ? ';    // $lang
        $sql .= 'AND    Status     = true ';
        $sql .= 'ORDER BY PLID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $ConstID1, $LanguageID);
            $ConstID1   = $this->CL['DF']->PL;
            $LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 補助元帳レベルを取得する(全件)
    public function gConstSubLedList($lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ConstNo   AS LvlNo ';
        $sql .= '     , ConstID2  AS LvlID ';
        $sql .= '     , ConstVal1 AS LvlName ';
        $sql .= 'FROM   m_const ';
        $sql .= 'WHERE  ConstID1   = ? ';    // $this->CL['DF']->SUBLEDLVL
        $sql .= 'AND    LanguageID = ? ';    // $lang
        $sql .= 'AND    Status     = true ';
        $sql .= 'ORDER BY LvlID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $ConstID1, $LanguageID);
            $ConstID1   = $this->CL['DF']->SUBLEDLVL;
            $LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* u_company                                              */
/*--------------------------------------------------------*/
    // 会社情報を更新する
    public function uCompanyInfo($id, $lang, $name, $cmonth, $curr, $country, $telno, $faxno, $building, $roomno, $floorno, $village, $addrno, $moo, $soi, $road, $subdist, $district, $province, $postcode, $taxid, $branchno, $smeflg, $whtid1, $whtid2, $whtid3, $whtid4, $insumid, $retearnid, $excvalgainid, $excvallossid, $s_userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_company ';
        $sql .= 'SET    CompanyName = ? ';  // $name
        $sql .= '     , CloseMonth  = ? ';  // $cmonth
        $sql .= '     , CurrencyID  = ? ';  // $curr
        $sql .= '     , CountryID   = ? ';  // $country
        $sql .= '     , TelNo   = ? ';      // $telno
        $sql .= '     , FaxNo   = ? ';      // $faxno
        $sql .= '     , Building   = ? ';   // $building
        $sql .= '     , RoomNo   = ? ';     // $roomno
        $sql .= '     , FloorNo   = ? ';    // $floorno
        $sql .= '     , Village   = ? ';    // $village
        $sql .= '     , AddrNo   = ? ';     // $addrno
        $sql .= '     , Moo   = ? ';        // $moo
        $sql .= '     , Soi   = ? ';        // $soi
        $sql .= '     , Road   = ? ';       // $road
        $sql .= '     , Subdist   = ? ';    // $subdist
        $sql .= '     , District   = ? ';   // $district
        $sql .= '     , Province   = ? ';   // $province
        $sql .= '     , Postcode   = ? ';   // $postcode
        $sql .= '     , TaxID   = ? ';      // $taxid
        $sql .= '     , BranchNo   = ? ';   // $branchno
        $sql .= '     , SMEFlg   = ? ';     // $smeflg
        $sql .= '     , WithHoldingTaxID1   = ? ';  // $whtid1
        $sql .= '     , WithHoldingTaxID2   = ? ';  // $whtid2
        $sql .= '     , WithHoldingTaxID3   = ? ';  // $whtid3
        $sql .= '     , WithHoldingTaxID4   = ? ';  // $whtid4
        $sql .= '     , IncomeSummaryID   = ? ';  			// $insumid
        $sql .= '     , RetainedEarningsID   = ? ';  		// $retearnid
        $sql .= '     , ExchangeValuationGainID   = ? '; 	// $excvalgainid
        $sql .= '     , ExchangeValuationLossID   = ? ';  	// $excvallossid
		
        $sql .= '     , UpdDate     = ? ';  // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser     = ? ';  // $s_userid
        $sql .= 'WHERE  CompanyID   = ? ';  // $id
        $sql .= 'AND    LanguageID  = ? ';  // $langLanguageID
        $sql .= 'AND    Status      = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssssssssssssssssssssssssssssss', $CompanyName, $CloseMonth, $CurrencyID, $CountryID, $TelNo, $FaxNo, $Building, $RoomNo, $FloorNo, $Village, $AddrNo, $Moo, $Soi, $Road, $Subdist, $District, $Province, $Postcode, $TaxID, $BranchNo, $SMEFlg, $WithHoldingTaxID1, $WithHoldingTaxID2, $WithHoldingTaxID3, $WithHoldingTaxID4, $IncomeSummaryID, $RetainedEarningsID, $ExchangeValuationGainID, $ExchangeValuationLossID, $UpdDate, $UpdUser, $CompanyID, $LanguageID);
            $CompanyName    = $name;
            $CloseMonth     = $cmonth;
            $CurrencyID     = $curr;
            $CountryID      = $country;
            $TelNo          = $telno;
            $FaxNo          = $faxno;
            $Building       = $building;
            $RoomNo         = $roomno;
            $FloorNo        = $floorno;
            $Village        = $village;
            $AddrNo         = $addrno;
            $Moo            = $moo;
            $Soi            = $soi;
            $Road           = $road;
            $Subdist        = $subdist;
            $District       = $district;
            $Province       = $province;
            $Postcode       = $postcode;
            $TaxID          = $taxid;
            $BranchNo       = $branchno;
            $SMEFlg         = $smeflg;
            $WithHoldingTaxID1  = $whtid1;
            $WithHoldingTaxID2  = $whtid2;
            $WithHoldingTaxID3  = $whtid3;
            $WithHoldingTaxID4  = $whtid4;
            $IncomeSummaryID  = $insumid;
            $RetainedEarningsID  = $retearnid;
            $ExchangeValuationGainID  = $excvalgainid;
            $ExchangeValuationLossID  = $excvallossid;

            $UpdDate     = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser     = $s_userid;
            $CompanyID   = $id;
            $LanguageID  = $lang;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 会社情報を取得する（1行）
    public function gCompanyRow($id, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT CompanyName ';
        $sql .= '      ,CloseMonth ';
        $sql .= '      ,CurrencyID ';
        $sql .= '      ,CountryID ';
        $sql .= '      ,TelNo ';
        $sql .= '      ,FaxNo ';
        $sql .= '      ,Building ';
        $sql .= '      ,RoomNo ';
        $sql .= '      ,FloorNo ';
        $sql .= '      ,Village ';
        $sql .= '      ,AddrNo ';
        $sql .= '      ,Moo ';
        $sql .= '      ,Soi ';
        $sql .= '      ,Road ';
        $sql .= '      ,Subdist ';
        $sql .= '      ,District ';
        $sql .= '      ,Province ';
        $sql .= '      ,Postcode ';
        $sql .= '      ,TaxID ';
        $sql .= '      ,BranchNo ';
        $sql .= '      ,SMEFlg ';
        $sql .= '      ,WithHoldingTaxID1 ';
        $sql .= '      ,WithHoldingTaxID2 ';
        $sql .= '      ,WithHoldingTaxID3 ';
        $sql .= '      ,WithHoldingTaxID4 ';
        $sql .= '      ,IncomeSummaryID ';
        $sql .= '      ,RetainedEarningsID ';
        $sql .= '      ,ExchangeValuationGainID ';
        $sql .= '      ,ExchangeValuationLossID ';
        $sql .= 'FROM   u_company ';
        $sql .= 'WHERE  CompanyID  = ? ';    // $id
        $sql .= 'AND    LanguageID = ? ';    // $lang
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $CompanyID, $LanguageID);
            $CompanyID  = $id;
            $LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 会社名称・決算月を取得する
    public function gCompanyNameVal($id, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT CompanyName ';
        $sql .= '      ,CloseMonth ';
        $sql .= '      ,CurrencyID ';
        $sql .= 'FROM   u_company ';
        $sql .= 'WHERE  CompanyID  = ? ';    // $id
        $sql .= 'AND    LanguageID = ? ';    // $lang
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $CompanyID, $LanguageID);
            $CompanyID  = $id;
            $LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* u_user                                                 */
/*--------------------------------------------------------*/
    // ユーザ情報を更新する
    public function uUserInfo($userno, $username, $password, $mailaddress, $authority, $deflang, $s_userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_user ';
        $sql .= 'SET    UserName          = ? ';    // $username
        $sql .= '     , PassWord          = ? ';    // $password
        $sql .= '     , AuthorityID       = ? ';    // $authority
        $sql .= '     , MailAddress       = ? ';    // $mailaddress
        $sql .= '     , DefaultLanguageID = ? ';    // $deflang
        $sql .= '     , UpdDate           = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser           = ? ';    // $s_userid
        $sql .= 'WHERE  UserNo            = ? ';    // $userno
        $sql .= 'AND    Status            = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssss', $UserName, $PassWord, $AuthorityID, $MailAddress, $DefaultLanguageID, $UpdDate, $UpdUser, $UserNo);
            $UserName          = $username;
            $PassWord          = $password;
            $AuthorityID       = $authority;
            $MailAddress       = $mailaddress;
            $DefaultLanguageID = $deflang;
            $UpdDate           = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser           = $s_userid;
            $UserNo            = $userno;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // ユーザ情報を更新する(パスワード以外)
    public function uUserInfo2($userno, $username, $mailaddress, $authority, $deflang, $s_userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_user ';
        $sql .= 'SET    UserName          = ? ';    // $username
        $sql .= '     , AuthorityID       = ? ';    // $authority
        $sql .= '     , MailAddress       = ? ';    // $mailaddress
        $sql .= '     , DefaultLanguageID = ? ';    // $deflang
        $sql .= '     , UpdDate           = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser           = ? ';    // $s_userid
        $sql .= 'WHERE  UserNo            = ? ';    // $userno
        $sql .= 'AND    Status            = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssss', $UserName, $AuthorityID, $MailAddress, $DefaultLanguageID, $UpdDate, $UpdUser, $UserNo);
            $UserName          = $username;
            $AuthorityID       = $authority;
            $MailAddress       = $mailaddress;
            $DefaultLanguageID = $deflang;
            $UpdDate           = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser           = $s_userid;
            $UserNo            = $userno;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // ユーザ情報を追加する
    public function iUserInfo($userid, $username, $password, $mailaddress, $authority, $deflang, $s_userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO u_user(UserID, PassWord, AuthorityID, DefaultLanguageID, UserName, MailAddress, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $userid
        $sql .= ',? ';    // $password
        $sql .= ',? ';    // $authority
        $sql .= ',? ';    // $deflang
        $sql .= ',? ';    // $username
        $sql .= ',? ';    // $mailaddress
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $s_userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $s_userid
        $sql .= ',true) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssss', $UserID, $PassWord, $AuthorityID, $DefaultLanguageID, $UserName, $MailAddress, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $UserID            = $userid;
            $PassWord          = $password;
            $AuthorityID       = $authority;
            $DefaultLanguageID = $deflang;
            $UserName          = $username;
            $MailAddress       = $mailaddress;
            $EntDate           = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser           = $s_userid;
            $UpdDate           = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser           = $s_userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // ユーザ情報を削除する
    public function dUserInfo($userno, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_user ';
        $sql .= 'SET    Status  = false ';
        $sql .= '     , UpdDate = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser = ? ';    // $userid
        $sql .= '     , DelDate = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , DelUser = ? ';    // $userid
        $sql .= 'WHERE  UserNo  = ? ';    // $userno
        $sql .= 'AND    Status  = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $UserNo);
            $UpdDate = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser = $userid;
            $DelDate = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser = $userid;
            $UserNo  = $userno;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // ユーザIDをキーにユーザ権限を取得する
    public function gUserAuthIDVal($userid) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT AuthorityID ';
        $sql .= 'FROM   u_user ';
        $sql .= 'WHERE  UserID = ? ';    // $userid
        $sql .= 'AND    Status = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $UserID);
            $UserID = $userid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 同ユーザIDの件数を取得する
    public function gUserIDSameCntVal($userid) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT COUNT(*) AS cnt ';
        $sql .= 'FROM   u_user ';
        $sql .= 'WHERE  UserID = ? ';    // $userid
        $sql .= 'AND    Status = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $UserID);
            $UserID = $userid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // ユーザ情報を取得する(全件)
    public function gUserList($lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT UserNo ';
        $sql .= '     , UserName ';
        $sql .= 'FROM   u_user ';
        $sql .= 'WHERE  Status = true ';
        $sql .= 'ORDER BY UserID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // ユーザ情報を取得する(ログイン用)
    public function gUserRow($user) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT AuthorityID ';
        $sql .= '     , DefaultLanguageID ';
        $sql .= '     , UserName ';
        $sql .= '     , PassWord ';
        $sql .= 'FROM   u_user ';
        $sql .= 'WHERE  UserID   = ? ';    // $user
        $sql .= 'AND    Status   = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $UserID);
            $UserID   = $user;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
	
/*--------------------------------------------------------*/
/* u_usergroup                                            */
/*--------------------------------------------------------*/
    public function iUserGroupInfo($usergroupid, $usergroupname, $s_userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO u_usergroup(UserGroupID, UserGroupName, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $usergroupid
        $sql .= ',? ';    // $usergroupname
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $s_userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $s_userid
        $sql .= ',true) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssss', $UserGroupID, $UserGroupName, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $UserGroupID       = $usergroupid;
            $UserGroupName     = $usergroupname;
            $EntDate           = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser           = $s_userid;
            $UpdDate           = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser           = $s_userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
	
    public function gUserGroupIDSameCntVal($usergroupid) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT COUNT(*) AS cnt ';
        $sql .= 'FROM   u_usergroup ';
        $sql .= 'WHERE  UserGroupID = ? ';    // $usergroupid
        $sql .= 'AND    Status = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $UserGroupID);
            $UserGroupID = $usergroupid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
	
    public function gUserGroupList($searchdate, $syear, $smonth, $sday, $eyear, $emonth, $eday, $searchText, $pageRowText, $pages, $blankflg) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sdate           = self::sSDate($searchdate, $syear, $smonth, $sday);    // 検索条件(開始日)
        $edate           = self::sEDate($searchdate, $eyear, $emonth, $eday);    // 検索条件(終了日)
        $array           = self::sLimit($pageRowText, $pages);                   // 検索条件(ページング)
        $offset          = $array[0];
        $limit           = $array[1];
        
        $sql  = 'SELECT UserGroupNo ';
        $sql .= '     , UserGroupID ';
        $sql .= '     , UserGroupName ';
        $sql .= '     , EntDate ';
        $sql .= 'FROM   u_usergroup ';
        $sql .= 'WHERE  EntDate          >= ? ';    // $sdate
        $sql .= 'AND    EntDate          <= ? ';    // $edate
        $sql .= 'AND    ( ';
        $sql .= '           UserGroupID     LIKE ? ';    // '%'+$searchText+'%'
        $sql .= 'OR         UserGroupName   LIKE ? ';    // '%'+$searchText+'%'
        $sql .= '       ) ';
        $sql .= 'AND    Status= true ';
        $sql .= 'ORDER BY UserGroupID ';
        $sql .= 'LIMIT ?, ? ';    // $offset, $limit
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssii', $SEntDate, $EEntDate, $UserGroupID, $UserGroupName, $Offset, $Limit);
            $SEntDate     = $sdate;
            $EEntDate     = $edate;
            $UserGroupID       = '%'.$searchText.'%';
			$UserGroupName     = '%'.$searchText.'%';
            $Offset       = $offset;
            $Limit        = $limit;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
	
	//ดึงข้อมูลกลุ่มผู้ใช้
    public function gUserGroupRow($usergroupid) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT UserGroupID ';
        $sql .= '     , UserGroupName ';
        $sql .= 'FROM   u_usergroup ';
        $sql .= 'WHERE  UserGroupID   = ? ';    // $usergroupid
        $sql .= 'AND    Status   = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $UserGroupID);
            $UserGroupID   = $usergroupid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
	
    public function uUserGroupInfo($usergroupid, $usergroupname, $s_userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_usergroup ';
        $sql .= 'SET    UserGroupName     = ? ';    // $usergroupname
        $sql .= '     , UpdDate           = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser           = ? ';    // $s_userid
        $sql .= 'WHERE  UserGroupID       = ? ';    // $usergroupid
        $sql .= 'AND    Status            = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssss', $UserGroupName, $UpdDate, $UpdUser, $UserGroupID);
            $UserGroupName          = $usergroupname;
            $UpdDate           = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser           = $s_userid;
            $UserGroupID       = $usergroupid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
	
    public function dUserGroupInfo($usergroupid, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_usergroup ';
        $sql .= 'SET    Status  = false ';
        $sql .= '     , UpdDate = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser = ? ';    // $userid
        $sql .= '     , DelDate = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , DelUser = ? ';    // $userid
        $sql .= 'WHERE  UserGroupID  = ? ';    // $usergroupid
        $sql .= 'AND    Status  = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $UserGroupID);
            $UpdDate = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser = $userid;
            $DelDate = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser = $userid;
            $UserGroupID  = $usergroupid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
	
    
/*--------------------------------------------------------*/
/* m_accountstitles                                       */
/*--------------------------------------------------------*/
    // 勘定科目情報を更新する
    public function uAccSInfo($accid, $lang, $accSName, $pControlAccountflg, $pControlAccountID, $SubLedFlg, $pBOIflg, $pnonBOIflg, $puncertainBOIflg, $pCashBankflg, $pARDmtflg, 
                $pARIntflg, $pStockSalesflg, $pnonStockSalesflg, $pPurchaseStockflg, $pPurchasenonStockflg, $pPurchaseServiceflg, $pAPDmtflg, $pAPIntflg,
                $pAccruedExpenseflg, $pAROthersflg, $pInputVATflg, $pServiceSalesflg, $pInputVATNotSubjectCorporateTaxDeductionflg, $pOutputVATflg, $pSuspenseInputVATflg, $pSuspenseOutputVATflg, $pWithholdingTaxflg, 
                $pWithheldTaxflg, $pImportDutyflg, $pPayableCustomsflg, $pPayableRevDepflg, $pExchangeGainflg, $pExchangeLossflg, $pWHTType, $pWHTType2, $pVATType, $pClientID, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE m_accountstitles ';
        $sql .= 'SET    AccountsTitleSName = ? ';    // $accSName
        $sql .= '    ,  ControlAccountflg  = ? ';    // $pControlAccountflg
        $sql .= '    ,  ControlAccountID   = ? ';    // $pControlAccountID
        $sql .= '    ,  SubLedgerFlg       = ? ';    // $SubLedFlg
        $sql .= '    ,  BOIflg	= ? ';	// $pBOIflg
        $sql .= '    ,  nonBOIflg	= ? ';	// $pnonBOIflg
        $sql .= '    ,  uncertainBOIflg	= ? ';	// $puncertainBOIflg
        $sql .= '    ,  CashBankflg	= ? ';	// $pCashBankflg
        $sql .= '    ,  ARDmtflg	= ? ';	// $pARDmtflg
        $sql .= '    ,  ARIntflg	= ? ';	// $pARIntflg
        $sql .= '    ,  StockSalesflg	= ? ';	// $pStockSalesflg
        $sql .= '    ,  nonStockSalesflg	= ? ';	// $pnonStockSalesflg
        $sql .= '    ,  PurchaseStockflg	= ? ';	// $pPurchaseStockflg
        $sql .= '    ,  PurchasenonStockflg	= ? ';	// $pPurchasenonStockflg
        $sql .= '    ,  PurchaseServiceflg	= ? ';	// $pPurchaseServiceflg
        $sql .= '    ,  APDmtflg	= ? ';	// $pAPDmtflg
        $sql .= '    ,  APIntflg	= ? ';	// $pAPIntflg
        $sql .= '    ,  AccruedExpenseflg	= ? ';	// $pAccruedExpenseflg
        $sql .= '    ,  AROthersflg	= ? ';	// $pAROthersflg
        $sql .= '    ,  InputVATflg	= ? ';	// $pInputVATflg
        $sql .= '    ,  ServiceSalesflg	= ? ';	// $pServiceSalesflg
        $sql .= '    ,  InputVATNotSubjectCorporateTaxDeductionflg	= ? ';	// $pInputVATNotSubjectCorporateTaxDeductionflg
        $sql .= '    ,  OutputVATflg	= ? ';	// $pOutputVATflg
        $sql .= '    ,  SuspenseInputVATflg	= ? ';	// $pSuspenseInputVATflg
        $sql .= '    ,  SuspenseOutputVATflg	= ? ';	// $pSuspenseOutputVATflg
        $sql .= '    ,  WithholdingTaxflg	= ? ';	// $pWithholdingTaxflg
        $sql .= '    ,  WithheldTaxflg	= ? ';	// $pWithheldTaxflg
        $sql .= '    ,  ImportDutyflg	= ? ';	// $pImportDutyflg
        $sql .= '    ,  PayableCustomsflg	= ? ';	// $pPayableCustomsflg
        $sql .= '    ,  PayableRevDepflg	= ? ';	// $pPayableRevDepflg
        $sql .= '    ,  ExchangeGainflg	= ? ';	// $pExchangeGainflg
        $sql .= '    ,  ExchangeLossflg	= ? ';	// $pExchangeLossflg
        $sql .= '    ,  WHTType	= ? ';	// $pWHTType
        $sql .= '    ,  WHTType2	= ? ';	// $pWHTType2
        $sql .= '    ,  VATType	= ? ';	// $pVATType
        $sql .= '    ,  ClientID	= ? ';	// $pClientID
        $sql .= '    ,  UpdDate            = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  UpdUser            = ? ';    // $userid
        $sql .= 'WHERE  AccountsTitleID    = ? ';    // $accid
        $sql .= 'AND    LanguageID         = ? ';    // $lang
        $sql .= 'AND    Status             = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssssssssssssssssssssssssssssssss', $AccountsTitleSName, $ControlAccountflg, $ControlAccountID, $SubLedgerFlg, 
                    $BOIflg, $nonBOIflg, $uncertainBOIflg, $CashBankflg, $ARDmtflg, $ARIntflg, $StockSalesflg, $nonStockSalesflg, 
                    $PurchaseStockflg, $PurchasenonStockflg, $PurchaseServiceflg, $APDmtflg, $APIntflg, $AccruedExpenseflg, $AROthersflg, 
                    $InputVATflg, $ServiceSalesflg, $InputVATNotSubjectCorporateTaxDeductionflg, $OutputVATflg, 
                    $SuspenseInputVATflg, $SuspenseOutputVATflg, $WithholdingTaxflg, $WithheldTaxflg, 
                    $ImportDutyflg, $PayableCustomsflg, $PayableRevDepflg, $ExchangeGainflg, $ExchangeLossflg, $WHTType, $WHTType2, $VATType, $ClientID, $UpdDate, $UpdUser, $AccountsTitleID, $LanguageID);
            $AccountsTitleSName = $accSName;
            $ControlAccountflg  = $pControlAccountflg;
            $ControlAccountID   = $pControlAccountID;
            $SubLedgerFlg       = $SubLedFlg;
            $BOIflg             = $pBOIflg;
            $nonBOIflg          = $pnonBOIflg;
            $uncertainBOIflg    = $puncertainBOIflg;
            $CashBankflg        = $pCashBankflg;
            $ARDmtflg           = $pARDmtflg;
            $ARIntflg           = $pARIntflg;
            $StockSalesflg        = $pStockSalesflg;
            $nonStockSalesflg        = $pnonStockSalesflg;
            $PurchaseStockflg   = $pPurchaseStockflg;
            $PurchasenonStockflg    = $pPurchasenonStockflg;
            $PurchaseServiceflg = $pPurchaseServiceflg;
            $APDmtflg           = $pAPDmtflg;
            $APIntflg           = $pAPIntflg;
            $AccruedExpenseflg  = $pAccruedExpenseflg;
            $AROthersflg    = $pAROthersflg;
            $InputVATflg        = $pInputVATflg;
            $ServiceSalesflg   = $pServiceSalesflg;
            $InputVATNotSubjectCorporateTaxDeductionflg = $pInputVATNotSubjectCorporateTaxDeductionflg;
            $OutputVATflg       = $pOutputVATflg;
            $SuspenseInputVATflg    = $pSuspenseInputVATflg;
            $SuspenseOutputVATflg   = $pSuspenseOutputVATflg;
            $WithholdingTaxflg  = $pWithholdingTaxflg;
            $WithheldTaxflg     = $pWithheldTaxflg;
            $ImportDutyflg      = $pImportDutyflg;
            $PayableCustomsflg  = $pPayableCustomsflg;
            $PayableRevDepflg   = $pPayableRevDepflg;
            $ExchangeGainflg    = $pExchangeGainflg;
            $ExchangeLossflg    = $pExchangeLossflg;
            $WHTType            = $pWHTType;
            $WHTType2           = $pWHTType2;
            $VATType            = $pVATType;
            $ClientID           = $pClientID;
            $UpdDate            = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser            = $userid;
            $AccountsTitleID    = $accid;
            $LanguageID         = $lang;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 勘定科目情報を追加する
    public function iAccSInfo($pAccountsTitleID, $AccKind1Id, $AccKind2Id, $AccKind3Id, $AccKind4Id, $AccKind5Id, $AccSName, $pControlAccountflg, $pControlAccountID, $SubLedFlg, $pBOIflg, $pnonBOIflg, $puncertainBOIflg, 
                        $pCashBankflg, $pARDmtflg, $pARIntflg, $pStockSalesflg, $pnonStockSalesflg, $pPurchaseStockflg, $pPurchasenonStockflg, $pPurchaseServiceflg, $pAPDmtflg, $pAPIntflg, $pAccruedExpenseflg, 
                        $pAROthersflg, $pInputVATflg, $pServiceSalesflg, $pInputVATNotSubjectCorporateTaxDeductionflg, $pOutputVATflg, $pSuspenseInputVATflg, $pSuspenseOutputVATflg, $pWithholdingTaxflg, $pWithheldTaxflg, $pImportDutyflg, $pPayableCustomsflg, $pPayableRevDepflg, $pExchangeGainflg, $pExchangeLossflg, $pWHTType, $pWHTType2, $pVATType, $pClientID, 
                        $lang, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO m_accountstitles(AccountsTitleID, AccountsKind1ID, AccountsKind2ID, AccountsKind3ID, AccountsKind4ID, AccountsKind5ID, LanguageID, AccountsTitleSName, ControlAccountflg, ControlAccountID, SubLedgerFlg, BOIflg, nonBOIflg, uncertainBOIflg, CashBankflg, ARDmtflg, ARIntflg, StockSalesflg, nonStockSalesflg, PurchaseStockflg, PurchasenonStockflg, PurchaseServiceflg, APDmtflg, APIntflg, AccruedExpenseflg, AROthersflg, InputVATflg, ServiceSalesflg, InputVATNotSubjectCorporateTaxDeductionflg, OutputVATflg, SuspenseInputVATflg, SuspenseOutputVATflg, WithholdingTaxflg, WithheldTaxflg, ImportDutyflg, PayableCustomsflg, PayableRevDepflg, ExchangeGainflg, ExchangeLossflg, WHTType, WHTType2, VATType, ClientID, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $pAccountsTitleID
        $sql .= ',? ';    // $AccKind1Id
        $sql .= ',? ';    // $AccKind2Id
        $sql .= ',? ';    // $AccKind3Id
        $sql .= ',? ';    // $AccKind4Id
        $sql .= ',? ';    // $AccKind5Id
        $sql .= ',? ';    // $lang
        $sql .= ',? ';    // $AccSName
        $sql .= ',? ';    // $pControlAccountflg
        $sql .= ',? ';    // $pControlAccountID
        $sql .= ',? ';    // $SubLedFlg
        $sql .= ',? ';    // $pBOIflg
        $sql .= ',? ';    // $pnonBOIflg
        $sql .= ',? ';    // $puncertainBOIflg
        $sql .= ',? ';    // $pCashBankflg
        $sql .= ',? ';    // $pARDmtflg
        $sql .= ',? ';    // $pARIntflg
        $sql .= ',? ';    // $pStockSalesflg
        $sql .= ',? ';    // $pnonStockSalesflg
        $sql .= ',? ';    // $pPurchaseStockflg
        $sql .= ',? ';    // $pPurchasenonStockflg
        $sql .= ',? ';    // $pPurchaseServiceflg
        $sql .= ',? ';    // $pAPDmtflg
        $sql .= ',? ';    // $pAPIntflg
        $sql .= ',? ';    // $pAccruedExpenseflg
        $sql .= ',? ';    // $pAROthersflg
        $sql .= ',? ';    // $pInputVATflg
        $sql .= ',? ';    // $pServiceSalesflg
        $sql .= ',? ';    // $pInputVATNotSubjectCorporateTaxDeductionflg
        $sql .= ',? ';    // $pOutputVATflg
        $sql .= ',? ';    // $pSuspenseInputVATflg
        $sql .= ',? ';    // $pSuspenseOutputVATflg
        $sql .= ',? ';    // $pWithholdingTaxflg
        $sql .= ',? ';    // $pWithheldTaxflg
        $sql .= ',? ';    // $pImportDutyflg
        $sql .= ',? ';    // $pPayableCustomsflg
        $sql .= ',? ';    // $pPayableRevDepflg
        $sql .= ',? ';    // $pExchangeGainflg
        $sql .= ',? ';    // $pExchangeLossflg
        $sql .= ',? ';    // $pWHTType
        $sql .= ',? ';    // $pWHTType2
        $sql .= ',? ';    // $pVATType
        $sql .= ',? ';    // $pClientID
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssssssssssssssssssssssssssssssssssssssssssss', $AccountsTitleID, $AccountsKind1ID, $AccountsKind2ID, $AccountsKind3ID, $AccountsKind4ID, $AccountsKind5ID, 
                        $LanguageID, $AccountsTitleSName, $ControlAccountflg, $ControlAccountID, $SubLedgerFlg, $BOIflg, $nonBOIflg, $uncertainBOIflg, $CashBankflg, 
                        $ARDmtflg, $ARIntflg, $StockSalesflg, $nonStockSalesflg, $PurchaseStockflg, $PurchasenonStockflg, $PurchaseServiceflg, $APDmtflg, $APIntflg, $AccruedExpenseflg, $AROthersflg, 
                        $InputVATflg, $ServiceSalesflg, $InputVATNotSubjectCorporateTaxDeductionflg, $OutputVATflg, $SuspenseInputVATflg, $SuspenseOutputVATflg, 
                        $WithholdingTaxflg, $WithheldTaxflg, $ImportDutyflg, $PayableCustomsflg, $PayableRevDepflg, $ExchangeGainflg, $ExchangeLossflg, $WHTType, $WHTType2, $VATType, $ClientID, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $AccountsTitleID    = $pAccountsTitleID;
            $AccountsKind1ID    = $AccKind1Id;
            $AccountsKind2ID    = $AccKind2Id;
            $AccountsKind3ID    = $AccKind3Id;
            $AccountsKind4ID    = $AccKind4Id;
            $AccountsKind5ID    = $AccKind5Id;
            $LanguageID         = $lang;
            $AccountsTitleSName = $AccSName;
            $ControlAccountflg  = $pControlAccountflg;
            $ControlAccountID   = $pControlAccountID;
            $SubLedgerFlg       = $SubLedFlg;
            $BOIflg             = $pBOIflg;
            $nonBOIflg          = $pnonBOIflg;
            $uncertainBOIflg    = $puncertainBOIflg;
            $CashBankflg        = $pCashBankflg;
            $ARDmtflg           = $pARDmtflg;
            $ARIntflg           = $pARIntflg;
            $StockSalesflg        = $pStockSalesflg;
            $nonStockSalesflg        = $pnonStockSalesflg;
            $PurchaseStockflg   = $pPurchaseStockflg;
            $PurchasenonStockflg    = $pPurchasenonStockflg;
            $PurchaseServiceflg = $pPurchaseServiceflg;
            $APDmtflg           = $pAPDmtflg;
            $APIntflg           = $pAPIntflg;
            $AccruedExpenseflg  = $pAccruedExpenseflg;
            $AROthersflg    = $pAROthersflg;
            $InputVATflg        = $pInputVATflg;
            $ServiceSalesflg   = $pServiceSalesflg;
            $InputVATNotSubjectCorporateTaxDeductionflg = $pInputVATNotSubjectCorporateTaxDeductionflg;
            $OutputVATflg       = $pOutputVATflg;
            $SuspenseInputVATflg    = $pSuspenseInputVATflg;
            $SuspenseOutputVATflg   = $pSuspenseOutputVATflg;
            $WithholdingTaxflg  = $pWithholdingTaxflg;
            $WithheldTaxflg     = $pWithheldTaxflg;
            $ImportDutyflg      = $pImportDutyflg;
            $PayableCustomsflg  = $pPayableCustomsflg;
            $PayableRevDepflg   = $pPayableRevDepflg;
            $ExchangeGainflg    = $pExchangeGainflg;
            $ExchangeLossflg    = $pExchangeLossflg;
            $WHTType            = $pWHTType;
            $WHTType2           = $pWHTType2;
            $VATType            = $pVATType;
            $ClientID           = $pClientID;
            $EntDate            = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser            = $userid;
            $UpdDate            = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser            = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 勘定科目情報を削除する(対象は3言語)
    public function dAccSInfo($accid, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE m_accountstitles ';
        $sql .= 'SET    Status           = false ';
        $sql .= '    ,  UpdDate          = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  UpdUser          = ? ';    // $userid
        $sql .= '    ,  DelDate          = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  DelUser          = ? ';    // $userid
        $sql .= 'WHERE  AccountsTitleID  = ? ';    // $accid
        $sql .= 'AND    Status           = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $AccountsTitleID);
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            $DelDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser          = $userid;
            $AccountsTitleID  = $accid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 勘定科目情報を取得する(全件)
    public function gAccSList($FlgDmt, $FlgInt, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_DmtFlg = self::sDmtFlg('m_accountstitles', $FlgDmt);    // 検索条件(国内仕入副費項目フラグ)
        $sql_IntFlg = self::sIntFlg('m_accountstitles', $FlgInt);    // 検索条件(国外仕入副費項目フラグ)
             
        $sql  = 'SELECT AccountsTitleSName ';
        $sql .= '     , AccountsTitleID  ';
        $sql .= '     , SubLedgerFlg     ';
        $sql .= 'FROM   m_accountstitles ';
        $sql .= 'WHERE  LanguageID         = ? ';    // $lang
        $sql .= 'AND    Status             = true ';
        $sql .= $sql_DmtFlg.' ';
        $sql .= $sql_IntFlg.' ';
        $sql .= 'ORDER BY AccountsTitleID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $LanguageID);
            $LanguageID         = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 勘定科目(小)名称を取得する
    public function gAccSNameVal($AccId, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT AccountsTitleSName ';
        $sql .= '      ,AccountsTitleID ';
        $sql .= '      ,SubLedgerFlg ';
        $sql .= 'FROM   m_accountstitles ';
        $sql .= 'WHERE  AccountsTitleID = ? ';    // $AccId
        $sql .= 'AND    LanguageID       = ? ';    // $lang
        $sql .= 'AND    Status           = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $AccountsTitleID, $LanguageID);
            $AccountsTitleID = $AccId;
            $LanguageID      = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 同勘定科目(小)名称の件数を取得する
    public function gAccSNameIDSameCntVal($AccSName, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT COUNT(*) AS cnt ';
        $sql .= 'FROM   m_accountstitles ';
        $sql .= 'WHERE  AccountsTitleSName = ? ';    // $AccSName
        $sql .= 'AND    LanguageID         = ? ';    // $lang
        $sql .= 'AND    Status             = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $AccountsTitleSName, $LanguageID);
            $AccountsTitleSName = $AccSName;
            $LanguageID         = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 同勘定科目(小)名称かつ同勘定科目(小)NOの件数を取得する
    public function gAccSNameIDNOSameCntVal($AccSName, $lang, $accno) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT COUNT(*) AS cnt ';
        $sql .= 'FROM   m_accountstitles ';
        $sql .= 'WHERE  AccountsTitleSName =  ? ';    // $AccSName
        $sql .= 'AND    LanguageID         =  ? ';    // $lang
        $sql .= 'AND    AccountsTitleID    <> ? ';    // $accno
        $sql .= 'AND    Status             =  true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $AccountsTitleSName, $LanguageID, $AccountsTitleID);
            $AccountsTitleSName = $AccSName;
            $LanguageID         = $lang;
            $AccountsTitleID    = $accno;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 勘定科目を絞り込む
//    public function gAccSSearch($filter, $BOIflg = NULL, $nonBOIflg = NULL, $uncertainBOIflg = NULL, $CashBankflg = NULL, 
//            $ARDmtflg = NULL, $ARIntflg = NULL, $StockSalesflg = NULL, $nonStockSalesflg = NULL, $PurchaseStockflg = NULL, 
//            $PurchasenonStockflg = NULL, $PurchaseServiceflg = NULL, $APDmtflg = NULL, $APIntflg = NULL, $AccruedExpenseflg = NULL, 
//            $AROthersflg = NULL, $InputVATflg = NULL, $ServiceSalesflg = NULL, $InputVATNotSubjectCorporateTaxDeductionflg = NULL, $OutputVATflg = NULL, 
//            $SuspenseInputVATflg = NULL, $SuspenseOutputVATflg = NULL, $WithholdingTaxflg = NULL, $WithheldTaxflg = NULL, $ImportDutyflg = NULL, 
//            $PayableCustomsflg = NULL, $PayableRevDepflg = NULL, $ExchangeGainflg = NULL, $ExchangeLossflg = NULL, $ClientID = NULL, 
//            $ControlAccountflg = '1', $lang = NULL) {
//        $this->CL['LG']->cLog('T0002');
//        $result = '';
//        $mysqli = self::DBConnect();
//        
//        $sql_BOIflg                 = self::sDataFlg('m', $BOIflg, 'BOIflg');					// BOIプロジェクト
//        $sql_nonBOIflg              = self::sDataFlg('m', $nonBOIflg, 'nonBOIflg');				// BOIプロジェクト外
//        $sql_uncertainBOIflg        = self::sDataFlg('m', $uncertainBOIflg, 'uncertainBOIflg');	// 不明（BOI)
//        $sql_CashBankflg            = self::sDataFlg('m', $CashBankflg, 'CashBankflg');			// 現金・預金
//        $sql_ARDmtflg               = self::sDataFlg('m', $ARDmtflg, 'ARDmtflg');				// 売掛金（国内）
//        $sql_ARIntflg               = self::sDataFlg('m', $ARIntflg, 'ARIntflg');				// 売掛金（国外）
//        $sql_StockSalesflg            = self::sDataFlg('m', $StockSalesflg, 'StockSalesflg');			// 売上（国内）
//        $sql_nonStockSalesflg            = self::sDataFlg('m', $nonStockSalesflg, 'nonStockSalesflg');			// 売上（国外）
//        $sql_PurchaseStockflg       = self::sDataFlg('m', $PurchaseStockflg, 'PurchaseStockflg');	// 在庫品目購入
//        $sql_PurchasenonStockflg    = self::sDataFlg('m', $PurchasenonStockflg, 'PurchasenonStockflg');	// 非在庫品目購入
//        $sql_PurchaseServiceflg     = self::sDataFlg('m', $PurchaseServiceflg, 'PurchaseServiceflg');	// 役務購入
//        $sql_APDmtflg               = self::sDataFlg('m', $APDmtflg, 'APDmtflg');				// 買掛金（国内）
//        $sql_APIntflg               = self::sDataFlg('m', $APIntflg, 'APIntflg');				// 買掛金（国外）
//        $sql_AccruedExpenseflg      = self::sDataFlg('m', $AccruedExpenseflg, 'AccruedExpenseflg');				// 未払費用
//        $sql_AROthersflg    = self::sDataFlg('m', $AROthersflg, 'AROthersflg');		// 小口現金払い費用等
//        $sql_InputVATflg            = self::sDataFlg('m', $InputVATflg, 'InputVATflg');			// 仕入VAT
//        $sql_ServiceSalesflg   = self::sDataFlg('m', $ServiceSalesflg, 'ServiceSalesflg');			// 控除対象外仕入VAT
//        $sql_InputVATNotSubjectCorporateTaxDeductionflg = self::sDataFlg('m', $InputVATNotSubjectCorporateTaxDeductionflg, 'InputVATNotSubjectCorporateTaxDeductionflg');			// 損金不算入仕入VAT
//        $sql_OutputVATflg           = self::sDataFlg('m', $OutputVATflg, 'OutputVATflg');		// 売上VAT
//        $sql_SuspenseInputVATflg    = self::sDataFlg('m', $SuspenseInputVATflg, 'SuspenseInputVATflg');		// 仕入VAT用中間勘定
//        $sql_SuspenseOutputVATflg   = self::sDataFlg('m', $SuspenseOutputVATflg, 'SuspenseOutputVATflg');	// 売上VAT用中間勘定
//        $sql_WithholdingTaxflg      = self::sDataFlg('m', $WithholdingTaxflg, 'WithholdingTaxflg');		// 源泉徴収
//        $sql_WithheldTaxflg         = self::sDataFlg('m', $WithheldTaxflg, 'WithheldTaxflg');			// 源泉徴収されたもの
//        $sql_ImportDutyflg          = self::sDataFlg('m', $ImportDutyflg, 'ImportDutyflg');		// 輸入関税
//        $sql_PayableCustomsflg      = self::sDataFlg('m', $PayableCustomsflg, 'PayableCustomsflg');			// 税関への支払 or 未払
//        $sql_PayableRevDepflg       = self::sDataFlg('m', $PayableRevDepflg, 'PayableRevDepflg');			// 歳入局への未払
//        $sql_ExchangeGainflg        = self::sDataFlg('m', $ExchangeGainflg, 'ExchangeGainflg');			// 為替差益
//        $sql_ExchangeLossflg        = self::sDataFlg('m', $ExchangeLossflg, 'ExchangeLossflg');			// 為替差損
//        $sql_ClientID               = self::sDataFlg('m', $ClientID, 'ClientID', true);			// 相手先コード
//        $sql_ControlAccountflg      = self::sDataFlg('m', $ControlAccountflg, 'ControlAccountflg');			// 統制勘定か否か

    public function gAccSSearch($filter, $BOICate = array(), $ACCate = array(),
            $ClientID = NULL, $ControlAccountflg = '1', $lang = NULL) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_BOIflg = '';
        if (isset($BOICate[$this->CL['DF']->ACCate_BOIflg])) {
            $sql_BOIflg = self::sDataFlg('m', $BOICate[$this->CL['DF']->ACCate_BOIflg], 'BOIflg'); // BOIプロジェクト 
        }
        $sql_nonBOIflg = '';
        if (isset($BOICate[$this->CL['DF']->ACCate_nonBOIflg])) {
            $sql_nonBOIflg = self::sDataFlg('m', $BOICate[$this->CL['DF']->ACCate_nonBOIflg], 'nonBOIflg'); // BOIプロジェクト外 
        }
        $sql_uncertainBOIflg = '';
        if (isset($BOICate[$this->CL['DF']->ACCate_uncertainBOIflg])) {
            $sql_uncertainBOIflg = self::sDataFlg('m', $BOICate[$this->CL['DF']->ACCate_uncertainBOIflg], 'uncertainBOIflg'); // 不明（BOI) 
        }
        $sql_CashBankflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_CashBankflg])) {
            $sql_CashBankflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_CashBankflg], 'CashBankflg'); // 現金・預金 
        }
        $sql_ARDmtflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_ARDmtflg])) {
            $sql_ARDmtflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_ARDmtflg], 'ARDmtflg'); // 売掛金（国内） 
        }
        $sql_ARIntflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_ARIntflg])) {
            $sql_ARIntflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_ARIntflg], 'ARIntflg'); // 売掛金（国外） 
        }
        $sql_AROthersflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_AROthersflg])) {
            $sql_AROthersflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_AROthersflg], 'AROthersflg'); // 未収金（国内） 
        }
        $sql_AROthersIntflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_AROthersIntflg])) {
            $sql_AROthersIntflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_AROthersIntflg], 'AROthersIntflg'); // 未収金（国外） 
        }
        $sql_StockSalesflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_StockSalesflg])) {
            $sql_StockSalesflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_StockSalesflg], 'StockSalesflg'); // 売上（在庫品）（国内） 
        }
        $sql_nonStockSalesflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_nonStockSalesflg])) {
            $sql_nonStockSalesflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_nonStockSalesflg], 'nonStockSalesflg'); // 売上（物品）（国内） 
        }
        $sql_ServiceSalesflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_ServiceSalesflg])) {
            $sql_ServiceSalesflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_ServiceSalesflg], 'ServiceSalesflg'); // 売上（役務）（国内） 
        }
        $sql_StockSalesIntflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_StockSalesIntflg])) {
            $sql_StockSalesIntflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_StockSalesIntflg], 'StockSalesIntflg'); // 売上（在庫品）（国外） 
        }
        $sql_nonStockSalesIntflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_nonStockSalesIntflg])) {
            $sql_nonStockSalesIntflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_nonStockSalesIntflg], 'nonStockSalesIntflg'); // 売上（物品）（国外） 
        }
        $sql_ServiceSalesIntflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_ServiceSalesIntflg])) {
            $sql_ServiceSalesIntflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_ServiceSalesIntflg], 'ServiceSalesIntflg'); // 売上（役務）（国外） 
        }
        $sql_DividendSalesIntflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_DividendSalesIntflg])) {
            $sql_DividendSalesIntflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_DividendSalesIntflg], 'DividendSalesIntflg'); // 売上（配当）（国外） 
        }
        $sql_InterestSalesIntflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_InterestSalesIntflg])) {
            $sql_InterestSalesIntflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_InterestSalesIntflg], 'InterestSalesIntflg'); // 売上（利息）（国外） 
        }
        $sql_RoyaltySalesIntflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_RoyaltySalesIntflg])) {
            $sql_RoyaltySalesIntflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_RoyaltySalesIntflg], 'RoyaltySalesIntflg'); // 売上（使用料）（国外） 
        }
        $sql_PurchaseStockflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_PurchaseStockflg])) {
            $sql_PurchaseStockflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_PurchaseStockflg], 'PurchaseStockflg'); // 在庫品目購入（国内） 
        }
        $sql_PurchasenonStockflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_PurchasenonStockflg])) {
            $sql_PurchasenonStockflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_PurchasenonStockflg], 'PurchasenonStockflg'); // 非在庫品目購入（国内） 
        }
        $sql_PurchaseServiceflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_PurchaseServiceflg])) {
            $sql_PurchaseServiceflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_PurchaseServiceflg], 'PurchaseServiceflg'); // 役務購入（国内） 
        }
        $sql_PurchaseStockIntflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_PurchaseStockIntflg])) {
            $sql_PurchaseStockIntflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_PurchaseStockIntflg], 'PurchaseStockIntflg'); // 在庫品目購入 
        }
        $sql_PurchasenonStockIntflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_PurchasenonStockIntflg])) {
            $sql_PurchasenonStockIntflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_PurchasenonStockIntflg], 'PurchasenonStockIntflg'); // 非在庫品目購入 
        }
        $sql_PurchaseServiceIntflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_PurchaseServiceIntflg])) {
            $sql_PurchaseServiceIntflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_PurchaseServiceIntflg], 'PurchaseServiceIntflg'); // 役務購入 
        }
        $sql_PurchaseDividendIntflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_PurchaseDividendIntflg])) {
            $sql_PurchaseDividendIntflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_PurchaseDividendIntflg], 'PurchaseDividendIntflg'); // 配当購入 
        }
        $sql_PurchaseInterestIntflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_PurchaseInterestIntflg])) {
            $sql_PurchaseInterestIntflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_PurchaseInterestIntflg], 'PurchaseInterestIntflg'); // 利息購入 
        }
        $sql_PurchaseRoyaltyIntflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_PurchaseRoyaltyIntflg])) {
            $sql_PurchaseRoyaltyIntflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_PurchaseRoyaltyIntflg], 'PurchaseRoyaltyIntflg'); // 使用料購入 
        }
        $sql_APDmtflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_APDmtflg])) {
            $sql_APDmtflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_APDmtflg], 'APDmtflg'); // 買掛金（国内） 
        }
        $sql_APIntflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_APIntflg])) {
            $sql_APIntflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_APIntflg], 'APIntflg'); // 買掛金（国外） 
        }
        $sql_AccruedExpenseflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_AccruedExpenseflg])) {
            $sql_AccruedExpenseflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_AccruedExpenseflg], 'AccruedExpenseflg'); // 未払金（国内） 
        }
        $sql_AccruedExpenseIntflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_AccruedExpenseIntflg])) {
            $sql_AccruedExpenseIntflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_AccruedExpenseIntflg], 'AccruedExpenseIntflg'); // 未払金（国外） 
        }
        $sql_InputVATflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_InputVATflg])) {
            $sql_InputVATflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_InputVATflg], 'InputVATflg'); // 仕入VAT 
        }
        $sql_InputVATNotSubjectCorporateTaxDeductionflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_InputVATNotSubjectCorporateTaxDeductionflg])) {
            $sql_InputVATNotSubjectCorporateTaxDeductionflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_InputVATNotSubjectCorporateTaxDeductionflg], 'InputVATNotSubjectCorporateTaxDeductionflg'); // 法人税控除対象外仕入VAT 
        }
        $sql_OutputVATflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_OutputVATflg])) {
            $sql_OutputVATflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_OutputVATflg], 'OutputVATflg'); // 売上VAT 
        }
        $sql_SuspenseInputVATflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_SuspenseInputVATflg])) {
            $sql_SuspenseInputVATflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_SuspenseInputVATflg], 'SuspenseInputVATflg'); // 仕入VAT用中間勘定 
        }
        $sql_SuspenseOutputVATflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_SuspenseOutputVATflg])) {
            $sql_SuspenseOutputVATflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_SuspenseOutputVATflg], 'SuspenseOutputVATflg'); // 売上VAT用中間勘定 
        }
        $sql_WithholdingTaxflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_WithholdingTaxflg])) {
            $sql_WithholdingTaxflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_WithholdingTaxflg], 'WithholdingTaxflg'); // 源泉徴収 
        }
        $sql_WithheldTaxflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_WithheldTaxflg])) {
            $sql_WithheldTaxflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_WithheldTaxflg], 'WithheldTaxflg'); // 源泉徴収されたもの 
        }
        $sql_ImportDutyflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_ImportDutyflg])) {
            $sql_ImportDutyflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_ImportDutyflg], 'ImportDutyflg'); // 輸入関税 
        }
        $sql_PayableCustomsflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_PayableCustomsflg])) {
            $sql_PayableCustomsflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_PayableCustomsflg], 'PayableCustomsflg'); // 税関への支払 or 未払 
        }
        $sql_PayableRevDepflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_PayableRevDepflg])) {
            $sql_PayableRevDepflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_PayableRevDepflg], 'PayableRevDepflg'); // 歳入局への未払 
        }
        $sql_ExchangeGainflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_ExchangeGainflg])) {
            $sql_ExchangeGainflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_ExchangeGainflg], 'ExchangeGainflg'); // 為替差益 
        }
        $sql_ExchangeLossflg = '';
        if (isset($ACCate[$this->CL['DF']->ACCate_ExchangeLossflg])) {
            $sql_ExchangeLossflg = self::sDataFlg('m', $ACCate[$this->CL['DF']->ACCate_ExchangeLossflg], 'ExchangeLossflg'); // 為替差損 
        }
        
        $sql_ClientID               = self::sDataFlg('m', $ClientID, 'ClientID', true);			// 相手先コード
        $sql_ControlAccountflg      = self::sDataFlg('m', $ControlAccountflg, 'ControlAccountflg');			// 統制勘定か否か



// $this->CL['LG']->cLog('S0001', ['gAccSSearch', '$sql_PayableCustomsflg:'.$sql_PayableCustomsflg, 'func_get_args:'.json_encode(func_get_args())]);        // log_out for trace
             
        $sql  = 'SELECT m.AccountsTitleID accode ';
        $sql .= ', m.AccountsTitleSName ';
        $sql .= ', m.WHTType ';
        $sql .= ', m.WHTType2 ';
        $sql .= ', m.VATType ';
        $sql .= ', m.AccountsKind1ID ';
        $sql .= ', m.AccountsKind2ID ';
        $sql .= ', m.AccountsKind3ID ';
        $sql .= ', m.AccountsKind4ID ';
        $sql .= ', m.AccountsKind5ID ';
        $sql .= 'FROM m_accountstitles m ';
        $sql .= 'WHERE m.LanguageID = ? ';      // $lang
        $sql .= 'AND m.Status=\'1\' ';
        $sql .= 'AND ( m.AccountsTitleID LIKE ? ';  // $filter
        $sql .= 'OR m.AccountsTitleID IN ';
        $sql .= '( ';
        $sql .= 'SELECT AccountsTitleID FROM m_accountstitles ';
        $sql .= 'WHERE STATUS=\'1\' ';
        $sql .= 'AND AccountsTitleSName LIKE ? ';   // $filter
        $sql .= ') ';
        $sql .= ') ';
        $sql .= $sql_BOIflg.' ';
        $sql .= $sql_nonBOIflg.' ';
        $sql .= $sql_uncertainBOIflg.' ';
        
        $sql .= $sql_CashBankflg;
        $sql .= $sql_ARDmtflg;
        $sql .= $sql_ARIntflg;
        $sql .= $sql_AROthersflg;
        $sql .= $sql_AROthersIntflg;
        $sql .= $sql_StockSalesflg;
        $sql .= $sql_nonStockSalesflg;
        $sql .= $sql_ServiceSalesflg;
        $sql .= $sql_StockSalesIntflg;
        $sql .= $sql_nonStockSalesIntflg;
        $sql .= $sql_ServiceSalesIntflg;
        $sql .= $sql_DividendSalesIntflg;
        $sql .= $sql_InterestSalesIntflg;
        $sql .= $sql_RoyaltySalesIntflg;
        $sql .= $sql_PurchaseStockflg;
        $sql .= $sql_PurchasenonStockflg;
        $sql .= $sql_PurchaseServiceflg;
        $sql .= $sql_PurchaseStockIntflg;
        $sql .= $sql_PurchasenonStockIntflg;
        $sql .= $sql_PurchaseServiceIntflg;
        $sql .= $sql_PurchaseDividendIntflg;
        $sql .= $sql_PurchaseInterestIntflg;
        $sql .= $sql_PurchaseRoyaltyIntflg;
        $sql .= $sql_APDmtflg;
        $sql .= $sql_APIntflg;
        $sql .= $sql_AccruedExpenseflg;
        $sql .= $sql_AccruedExpenseIntflg;
        $sql .= $sql_InputVATflg;
        $sql .= $sql_InputVATNotSubjectCorporateTaxDeductionflg;
        $sql .= $sql_OutputVATflg;
        $sql .= $sql_SuspenseInputVATflg;
        $sql .= $sql_SuspenseOutputVATflg;
        $sql .= $sql_WithholdingTaxflg;
        $sql .= $sql_WithheldTaxflg;
        $sql .= $sql_ImportDutyflg;
        $sql .= $sql_PayableCustomsflg;
        $sql .= $sql_PayableRevDepflg;
        $sql .= $sql_ExchangeGainflg;
        $sql .= $sql_ExchangeLossflg;
        
        $sql .= $sql_ClientID.' ';
        $sql .= $sql_ControlAccountflg.' ';
        $sql .= 'ORDER BY accode; ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $LanguageID, $filter1, $filter2);
            $LanguageID         = $lang;
            $filter1           = '%'.$filter.'%';
            $filter2           = '%'.$filter.'%';
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 同一勘定科目IDの件数を取得する
    public function gAccIDSameCntVal($Accid) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT COUNT(*) AS cnt ';
        $sql .= 'FROM   m_accountstitles ';
        $sql .= 'WHERE  AccountsTitleID = ? ';    // $Accid
        $sql .= 'AND    Status   = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $AccountsTitleID);
            $AccountsTitleID = $Accid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* u_client                                               */
/*--------------------------------------------------------*/
    // 取引先情報を更新する
    public function uCltInfo($cltidBef, $cltidAft, $cltname, $country, $addr1, $addr2, $postcode, $telno, $faxno, $affiliatedflg, $smeflg, $clttype, $taxid, $branchno, $supplierflg, $clientflg, $forwarderflg, $customsflg, $revdepflg, $bankflg, $crelimitid, $crelimitamount, $recpaytypeid, $recpaytype, $recclose1, $recpay1, $recpayon1, $recclose2, $recpay2, $recpayon2, $paypaytypeid, $paypaytype, $payclose1, $paypay1, $paypayon1, $payclose2, $paypay2, $paypayon2, $lang, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_client ';
        $sql .= 'SET    ClientID    = ? ';      // $cltidAft
        $sql .= '    ,  ClientName  = ? ';      // $cltname
        $sql .= '    ,  CountryID  = ? ';       // $country
        $sql .= '    ,  Addr1  = ? ';           // $addr1
        $sql .= '    ,  Addr2  = ? ';           // $addr2
        $sql .= '    ,  Postcode  = ? ';        // $postcode
        $sql .= '    ,  TelNo  = ? ';           // $telno
        $sql .= '    ,  FaxNo  = ? ';           // $faxno
        $sql .= '    ,  AffiliatedFlg  = ? ';   // $affiliatedflg
        $sql .= '    ,  SMEFlg  = ? ';          // $smeflg
        $sql .= '    ,  ClientType  = ? ';      // $clttype
        $sql .= '    ,  TaxID  = ? ';           // $taxid
        $sql .= '    ,  BranchNo  = ? ';        // $branchno
        $sql .= '    ,  SupplierFlg = ? ';      // $supplierflg
        $sql .= '    ,  ClientFlg   = ? ';      // $clientflg
        $sql .= '    ,  ForwarderFlg= ? ';      // $forwarderflg
        $sql .= '    ,  CustomsFlg  = ? ';      // $customsflg
        $sql .= '    ,  RevDepFlg   = ? ';      // $revdepflg
        $sql .= '    ,  BankFlg     = ? ';      // $bankflg
        $sql .= '    ,  CreLimitID  = ? ';      // $crelimitid
        $sql .= '    ,  CreLimitAmount  = ? ';  // $crelimitamount
        $sql .= '    ,  RecPayTypeID  = ? ';    // $recpaytypeid
        $sql .= '    ,  RecPayType  = ? ';      // $recpaytype
        $sql .= '    ,  RecClose1  = ? ';       // $recclose1
        $sql .= '    ,  RecPay1  = ? ';         // $recpay1
        $sql .= '    ,  RecPayOn1  = ? ';       // $recpayon1
        $sql .= '    ,  RecClose2  = ? ';       // $recclose2
        $sql .= '    ,  RecPay2  = ? ';         // $recpay2
        $sql .= '    ,  RecPayOn2  = ? ';       // $recpayon2
        $sql .= '    ,  PayPayTypeID  = ? ';    // $paypaytypeid
        $sql .= '    ,  PayPayType  = ? ';      // $paypaytype
        $sql .= '    ,  PayClose1  = ? ';       // $payclose1
        $sql .= '    ,  PayPay1  = ? ';         // $paypay1
        $sql .= '    ,  PayPayOn1  = ? ';       // $paypayon1
        $sql .= '    ,  PayClose2  = ? ';       // $payclose2
        $sql .= '    ,  PayPay2  = ? ';         // $paypay2
        $sql .= '    ,  PayPayOn2  = ? ';       // $paypayon2
        $sql .= '    ,  UpdDate     = ? ';      // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  UpdUser     = ? ';      // $userid
        $sql .= 'WHERE  ClientID    = ? ';      // $cltidBef
        $sql .= 'AND    LanguageID  = ? ';      // $lang
        $sql .= 'AND    Status      = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssssssssssssssssssssssssssssssssssssss', $ClientID, $ClientName, $CountryID, $Addr1, $Addr2, $Postcode, $TelNo, $FaxNo, $AffiliatedFlg, $SMEFlg, $ClientType, $TaxID, $BranchNo, $SupplierFlg, $ClientFlg, $ForwarderFlg, $CustomsFlg, $RevDepFlg, $BankFlg, $CreLimitID, $CreLimitAmount, $RecPayTypeID, $RecPayType, $RecClose1, $RecPay1, $RecPayOn1, $RecClose2, $RecPay2, $RecPayOn2, $PayPayTypeID, $PayPayType, $PayClose1, $PayPay1, $PayPayOn1, $PayClose2, $PayPay2, $PayPayOn2, $UpdDate, $UpdUser, $ClientID, $LanguageID);
            $ClientID    = $cltidAft;
            $ClientName  = $cltname;
            $CountryID   = $country;
            $Addr1       = $addr1;
            $Addr2       = $addr2;
            $Postcode    = $postcode;
            $TelNo       = $telno;
            $FaxNo       = $faxno;
            $AffiliatedFlg   = $affiliatedflg;
            $SMEFlg      = $smeflg;
            $ClientType  = $clttype;
            $TaxID       = $taxid;
            $BranchNo    = $branchno;
            $SupplierFlg = $supplierflg;
            $ClientFlg   = $clientflg;
            $ForwarderFlg= $forwarderflg;
            $CustomsFlg  = $customsflg;
            $RevDepFlg   = $revdepflg;
            $BankFlg     = $bankflg;
            $CreLimitID  = $crelimitid;
            $CreLimitAmount  = $crelimitamount;
            $RecPayTypeID    = $recpaytypeid;
            $RecPayType  = $recpaytype;
            $RecClose1   = $recclose1;
            $RecPay1     = $recpay1;
            $RecPayOn1   = $recpayon1;
            $RecClose2   = $recclose2;
            $RecPay2     = $recpay2;
            $RecPayOn2   = $recpayon2;
            $PayPayTypeID= $paypaytypeid;
            $PayPayType  = $paypaytype;
            $PayClose1   = $payclose1;
            $PayPay1     = $paypay1;
            $PayPayOn1   = $paypayon1;
            $PayClose2   = $payclose2;
            $PayPay2     = $paypay2;
            $PayPayOn2   = $paypayon2;
            $UpdDate     = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser     = $userid;
            $ClientID    = $cltidBef;
            $LanguageID  = $lang;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 取引先情報を追加する
    public function iCltInfo($cltid, $languageid, $cltname, $country, $addr1, $addr2, $postcode, $telno, $faxno, $affiliatedflg, $smeflg, $clttype, $taxid, $branchno, $supplierflg, $clientflg, $forwarderflg, $customsflg, $revdepflg, $bankflg, $crelimitid, $crelimitamount, $recpaytypeid, $recpaytype, $recclose1, $recpay1, $recpayon1, $recclose2, $recpay2, $recpayon2, $paypaytypeid, $paypaytype, $payclose1, $paypay1, $paypayon1, $payclose2, $paypay2, $paypayon2, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO u_client(ClientID, LanguageID, ClientName, CountryID, Addr1, Addr2, Postcode, TelNo, FaxNo, AffiliatedFlg, SMEFlg, ClientType, TaxID, BranchNo, SupplierFlg, ClientFlg, ForwarderFlg, CustomsFlg, RevDepFlg, BankFlg, CreLimitID, CreLimitAmount, RecPayTypeID, RecPayType, RecClose1, RecPay1, RecPayOn1, RecClose2, RecPay2, RecPayOn2, PayPayTypeID, PayPayType, PayClose1, PayPay1, PayPayOn1, PayClose2, PayPay2, PayPayOn2, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $cltid
        $sql .= ',? ';    // $languageid
        $sql .= ',? ';    // $cltname
        $sql .= ',? ';    // $country
        $sql .= ',? ';    // $addr1
        $sql .= ',? ';    // $addr2
        $sql .= ',? ';    // $postcode
        $sql .= ',? ';    // $telno
        $sql .= ',? ';    // $faxno
        $sql .= ',? ';    // $affiliatedflg
        $sql .= ',? ';    // $smeflg
        $sql .= ',? ';    // $clttype
        $sql .= ',? ';    // $taxid
        $sql .= ',? ';    // $branchno
        $sql .= ',? ';    // $supplierflg
        $sql .= ',? ';    // $clientflg
        $sql .= ',? ';    // $forwarderflg
        $sql .= ',? ';    // $customsflg
        $sql .= ',? ';    // $revdepflg
        $sql .= ',? ';    // $bankflg
        $sql .= ',? ';    // $crelimitid
        $sql .= ',? ';    // $crelimitamount
        $sql .= ',? ';    // $recpaytypeid
        $sql .= ',? ';    // $recpaytype
        $sql .= ',? ';    // $recclose1
        $sql .= ',? ';    // $recpay1
        $sql .= ',? ';    // $recpayon1
        $sql .= ',? ';    // $recclose2
        $sql .= ',? ';    // $recpay2
        $sql .= ',? ';    // $recpayon2
        $sql .= ',? ';    // $paypaytypeid
        $sql .= ',? ';    // $paypaytype
        $sql .= ',? ';    // $payclose1
        $sql .= ',? ';    // $paypay1
        $sql .= ',? ';    // $paypayon1
        $sql .= ',? ';    // $payclose2
        $sql .= ',? ';    // $paypay2
        $sql .= ',? ';    // $paypayon2
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssssssssssssssssssssssssssssssssss', $ClientID, $LanguageID, $ClientName, $CountryID, $Addr1, $Addr2, $Postcode, $TelNo, $FaxNo, $AffiliatedFlg, $SMEFlg, $ClientType, $TaxID, $BranchNo, $SupplierFlg, $ClientFlg, $ForwarderFlg, $CustomsFlg, $RevDepFlg, $BankFlg, $CreLimitID, $CreLimitAmount, $RecPayTypeID, $RecPayType, $RecClose1, $RecPay1, $RecPayOn1, $RecClose2, $RecPay2, $RecPayOn2, $PayPayTypeID, $PayPayType, $PayClose1, $PayPay1, $PayPayOn1, $PayClose2, $PayPay2, $PayPayOn2, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $ClientID    = $cltid;
            $LanguageID  = $languageid;
            $ClientName  = $cltname;
            $CountryID   = $country;
            $Addr1       = $addr1;
            $Addr2       = $addr2;
            $Postcode    = $postcode;
            $TelNo       = $telno;
            $FaxNo       = $faxno;
            $AffiliatedFlg   = $affiliatedflg;
            $SMEFlg      = $smeflg;
            $ClientType  = $clttype;
            $TaxID       = $taxid;
            $BranchNo    = $branchno;
            $SupplierFlg = $supplierflg;
            $ClientFlg   = $clientflg;
            $ForwarderFlg= $forwarderflg;
            $CustomsFlg  = $customsflg;
            $RevDepFlg   = $revdepflg;
            $BankFlg     = $bankflg;
            $CreLimitID  = $crelimitid;
            $CreLimitAmount  = $crelimitamount;
            $RecPayTypeID    = $recpaytypeid;
            $RecPayType  = $recpaytype;
            $RecClose1   = $recclose1;
            $RecPay1     = $recpay1;
            $RecPayOn1   = $recpayon1;
            $RecClose2   = $recclose2;
            $RecPay2     = $recpay2;
            $RecPayOn2   = $recpayon2;
            $PayPayTypeID= $paypaytypeid;
            $PayPayType  = $paypaytype;
            $PayClose1   = $payclose1;
            $PayPay1     = $paypay1;
            $PayPayOn1   = $paypayon1;
            $PayClose2   = $payclose2;
            $PayPay2     = $paypay2;
            $PayPayOn2   = $paypayon2;
            $EntDate     = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser     = $userid;
            $UpdDate     = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser     = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 取引先情報を削除する(対象は3言語)
    public function dCltInfo($cltid, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_client ';
        $sql .= 'SET    Status   = false ';
        $sql .= '    ,  UpdDate  = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  UpdUser  = ? ';    // $userid
        $sql .= '    ,  DelDate  = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  DelUser  = ? ';    // $userid
        $sql .= 'WHERE  ClientID = ? ';    // $cltid
        $sql .= 'AND    Status   = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $ClientID);
            $UpdDate  = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser  = $userid;
            $DelDate  = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser  = $userid;
            $ClientID = $cltid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 同取引先IDの件数を取得する
    public function gCltIDSameCntVal($cltid) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT COUNT(*) AS cnt ';
        $sql .= 'FROM   u_client ';
        $sql .= 'WHERE  ClientID = ? ';    // $cltid
        $sql .= 'AND    Status   = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $ClientID);
            $ClientID = $cltid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 取引先情報を取得する(全件)
    public function gCltList($SupplierFlg, $ClientFlg, $ForwarderFlg, $CustomsFlg, $RevDepFlg, $BankFlg, $searchdate, $syear, $smonth, $sday, $eyear, $emonth, $eday, $searchText, $pageRowText, $pages, $lang, $blankflg) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_SupplierFlg = self::sSupplierFlg('cl', $SupplierFlg);                // 検索条件(仕入先フラグ)
        $sql_ClientFlg   = self::sClientFlg('cl', $ClientFlg);                    // 検索条件(取引先フラグ)
        $sql_ForwarderFlg= self::sDataFlg('cl', $ForwarderFlg, 'ForwarderFlg');   // 検索条件(フォワーダーフラグ)
        $sql_CustomsFlg  = self::sDataFlg('cl', $CustomsFlg, 'CustomsFlg');       // 検索条件(税関フラグ)
        $sql_RevDepFlg   = self::sDataFlg('cl', $RevDepFlg, 'RevDepFlg');         // 検索条件(歳入局フラグ)
        $sql_BankFlg     = self::sDataFlg('cl', $BankFlg, 'BankFlg');             // 検索条件(銀行フラグ)
        $sdate           = self::sSDate($searchdate, $syear, $smonth, $sday);           // 検索条件(開始日)
        $edate           = self::sEDate($searchdate, $eyear, $emonth, $eday);           // 検索条件(終了日)
        $cltno           = self::sCltNo($blankflg);                                     // 検索条件(空白行フラグ)
        $array           = self::sLimit($pageRowText, $pages);                          // 検索条件(ページング)
        $offset          = $array[0];
        $limit           = $array[1];
        
        $sql  = 'SELECT cl.ClientNo ';
        $sql .= '     , cl.ClientID ';
        $sql .= '     , cl.ClientName ';
        $sql .= '     , cl.CountryID ';
        $sql .= '     , cl.Addr1 ';
        $sql .= '     , cl.Addr2 ';
        $sql .= '     , cl.Postcode ';
        $sql .= '     , cl.TelNo ';
        $sql .= '     , cl.FaxNo ';
        $sql .= '     , cl.AffiliatedFlg ';
        $sql .= '     , cl.SMEFlg ';
        $sql .= '     , cl.ClientType ';
        $sql .= '     , cl.TaxID ';
        $sql .= '     , cl.BranchNo ';
        $sql .= '     , cl.SupplierFlg ';
        $sql .= '     , cl.ClientFlg ';
        $sql .= '     , cl.ForwarderFlg ';
        $sql .= '     , cl.CustomsFlg ';
        $sql .= '     , cl.RevDepFlg ';
        $sql .= '     , cl.BankFlg ';
        $sql .= '     , cl.CreLimitID ';
        $sql .= '     , case when cl.CreLimitID = \'\' then cl.CreLimitAmount ELSE ifnull(li.CreLimitAmount, 0) END CreLimitAmount ';
        $sql .= '     , cl.RecPayTypeID ';
        $sql .= '     , case when cl.RecPayTypeID = \'\' then cl.RecPayType ELSE ifnull(tr.PayType, 0) END RecPayType ';
        $sql .= '     , case when cl.RecPayTypeID = \'\' then cl.RecClose1 ELSE ifnull(tr.Close1, 0) END RecClose1 ';
        $sql .= '     , case when cl.RecPayTypeID = \'\' then cl.RecPay1 ELSE ifnull(tr.Pay1, 0) END RecPay1 ';
        $sql .= '     , case when cl.RecPayTypeID = \'\' then cl.RecPayOn1 ELSE ifnull(tr.PayOn1, 0) END RecPayOn1 ';
        $sql .= '     , case when cl.RecPayTypeID = \'\' then cl.RecClose2 ELSE ifnull(tr.Close2, 0) END RecClose2 ';
        $sql .= '     , case when cl.RecPayTypeID = \'\' then cl.RecPay2 ELSE ifnull(tr.Pay2, 0) END RecPay2 ';
        $sql .= '     , case when cl.RecPayTypeID = \'\' then cl.RecPayOn2 ELSE ifnull(tr.PayOn2, 0) END RecPayOn2 ';
        $sql .= '     , cl.PayPayTypeID ';
        $sql .= '     , case when cl.PayPayTypeID = \'\' then cl.PayPayType ELSE ifnull(tp.PayType, 0) END PayPayType ';
        $sql .= '     , case when cl.PayPayTypeID = \'\' then cl.PayClose1 ELSE ifnull(tp.Close1, 0) END PayClose1 ';
        $sql .= '     , case when cl.PayPayTypeID = \'\' then cl.PayPay1 ELSE ifnull(tp.Pay1, 0) END PayPay1 ';
        $sql .= '     , case when cl.PayPayTypeID = \'\' then cl.PayPayOn1 ELSE ifnull(tp.PayOn1, 0) END PayPayOn1 ';
        $sql .= '     , case when cl.PayPayTypeID = \'\' then cl.PayClose2 ELSE ifnull(tp.Close2, 0) END PayClose2 ';
        $sql .= '     , case when cl.PayPayTypeID = \'\' then cl.PayPay2 ELSE ifnull(tp.Pay2, 0) END PayPay2 ';
        $sql .= '     , case when cl.PayPayTypeID = \'\' then cl.PayPayOn2 ELSE ifnull(tp.PayOn2, 0) END PayPayOn2 ';
        $sql .= '     , cl.EntDate ';
        $sql .= 'FROM   u_client cl ';
        $sql .= 'LEFT Join u_creditlimit li ';
        $sql .= 'ON  cl.CreLimitID = li.CreLimitID ';
        $sql .= 'AND cl.LanguageID = li.LanguageID ';
        $sql .= 'LEFT Join u_paytype tr ';
        $sql .= 'ON  cl.RecPayTypeID = tr.PayTypeID ';
        $sql .= 'AND cl.LanguageID = tr.LanguageID ';
        $sql .= 'LEFT Join u_paytype tp ';
        $sql .= 'ON  cl.PayPayTypeID = tp.PayTypeID ';
        $sql .= 'AND cl.LanguageID = tp.LanguageID ';
        $sql .= 'WHERE  cl.LanguageID        = ? ';    // $lang
        $sql .= 'AND    cl.EntDate          >= ? ';    // $sdate
        $sql .= 'AND    cl.EntDate          <= ? ';    // $edate
        $sql .= 'AND    cl.ClientNo         >= ? ';    // $cltno
        $sql .= 'AND    ( ';
        $sql .= '           cl.ClientName LIKE ? ';    // '%'+$searchText+'%'
        $sql .= '       ) ';
        $sql .= $sql_SupplierFlg.' ';
        $sql .= $sql_ClientFlg.' ';
        $sql .= $sql_ForwarderFlg.' ';
        $sql .= $sql_CustomsFlg.' ';
        $sql .= $sql_RevDepFlg.' ';
        $sql .= $sql_BankFlg.' ';
        $sql .= 'AND    cl.Status= true ';
        $sql .= 'ORDER BY cl.ClientID ';
        $sql .= 'LIMIT ?, ? ';    // $offset, $limit
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssii', $LanguageID, $SEntDate, $EEntDate, $ClientNo, $ClientName, $Offset, $Limit);
            $LanguageID = $lang;
            $SEntDate   = $sdate;
            $EEntDate   = $edate;
            $ClientNo   = $cltno;
            $ClientName = '%'.$searchText.'%';
            $Offset     = $offset;
            $Limit      = $limit;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 取引先情報を取得する(一件用)
    public function gCltRow($cltid, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ClientNo ';
        $sql .= '     , ClientID ';
        $sql .= '     , ClientName ';
        $sql .= '     , CountryID ';
        $sql .= '     , Addr1 ';
        $sql .= '     , Addr2 ';
        $sql .= '     , Postcode ';
        $sql .= '     , TelNo ';
        $sql .= '     , FaxNo ';
        $sql .= '     , AffiliatedFlg ';
        $sql .= '     , SMEFlg ';
        $sql .= '     , ClientType ';
        $sql .= '     , TaxID ';
        $sql .= '     , BranchNo ';
        $sql .= '     , SupplierFlg ';
        $sql .= '     , ClientFlg ';
        $sql .= '     , ForwarderFlg ';
        $sql .= '     , CustomsFlg ';
        $sql .= '     , RevDepFlg ';
        $sql .= '     , BankFlg ';
        $sql .= '     , CreLimitID ';
        $sql .= '     , CreLimitAmount ';
        $sql .= '     , RecPayTypeID ';
        $sql .= '     , RecPayType ';
        $sql .= '     , RecClose1 ';
        $sql .= '     , RecPay1 ';
        $sql .= '     , RecPayOn1 ';
        $sql .= '     , RecClose2 ';
        $sql .= '     , RecPay2 ';
        $sql .= '     , RecPayOn2 ';
        $sql .= '     , PayPayTypeID ';
        $sql .= '     , PayPayType ';
        $sql .= '     , PayClose1 ';
        $sql .= '     , PayPay1 ';
        $sql .= '     , PayPayOn1 ';
        $sql .= '     , PayClose2 ';
        $sql .= '     , PayPay2 ';
        $sql .= '     , PayPayOn2 ';
        $sql .= 'FROM   u_client ';
        $sql .= 'WHERE  LanguageID = ? ';    // $lang
        $sql .= 'AND    ClientID   = ? ';    // $cltid
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $LanguageID, $ClientID);
            $LanguageID = $lang;
            $ClientID   = $cltid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 取引先名を取得する(一件用)
    public function gCltNameVal($cltid, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ClientName ';
        $sql .= 'FROM   u_client ';
        $sql .= 'WHERE  LanguageID = ? ';    // $lang
        $sql .= 'AND    ClientID   = ? ';    // $cltid
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $LanguageID, $ClientID);
            $LanguageID = $lang;
            $ClientID   = $cltid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 取引先IDを取得する(一件用)
    public function gCltIDVal($cltno, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ClientID ';
        $sql .= 'FROM   u_client ';
        $sql .= 'WHERE  LanguageID = ? ';    // $lang
        $sql .= 'AND    ClientNo   = ? ';    // $cltno
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $LanguageID, $ClientNo);
            $LanguageID = $lang;
            $ClientNo   = $cltno;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 取引先名を絞り込む
    public function gCltSearch($filter, $SupplierFlg, $ClientFlg, $ForwarderFlg, $CustomsFlg, $RevDepFlg, $BankFlg, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_SupplierFlg = self::sSupplierFlg('m', $SupplierFlg);         // 検索条件(仕入先フラグ)
        $sql_ClientFlg   = self::sClientFlg('m', $ClientFlg);             // 検索条件(取引先フラグ)
        $sql_ForwarderFlg= self::sDataFlg('m', $ForwarderFlg, 'ForwarderFlg');   // 検索条件(フォワーダーフラグ)
        $sql_CustomsFlg  = self::sDataFlg('m', $CustomsFlg, 'CustomsFlg');       // 検索条件(税関フラグ)
        $sql_RevDepFlg   = self::sDataFlg('m', $RevDepFlg, 'RevDepFlg');         // 検索条件(歳入局フラグ)
        $sql_BankFlg     = self::sDataFlg('m', $BankFlg, 'BankFlgFlg');          // 検索条件(銀行フラグ)
        
        $sql  = 'SELECT m.ClientID, m.ClientName ';
        $sql .= ', m.CountryID, m.ClientType, m.TaxID ';
        $sql .= ', m.Addr1 ';
        $sql .= ', m.Addr2 ';
        $sql .= ', m.Postcode ';
        $sql .= ', m.TelNo ';
        $sql .= ', m.FaxNo ';
        $sql .= ', m.AffiliatedFlg ';
        $sql .= ', m.SMEFlg ';
        $sql .= ', m.BranchNo ';
        $sql .= ', m.CreLimitID ';
        $sql .= ', case when m.CreLimitID = \'\' then m.CreLimitAmount ELSE ifnull(li.CreLimitAmount, 0) END CreLimitAmount ';
        $sql .= ', m.RecPayTypeID ';
        $sql .= ', case when m.RecPayTypeID = \'\' then m.RecPayType ELSE ifnull(tr.PayType, 0) END RecPayType ';
        $sql .= ', case when m.RecPayTypeID = \'\' then m.RecClose1 ELSE ifnull(tr.Close1, 0) END RecClose1 ';
        $sql .= ', case when m.RecPayTypeID = \'\' then m.RecPay1 ELSE ifnull(tr.Pay1, 0) END RecPay1 ';
        $sql .= ', case when m.RecPayTypeID = \'\' then m.RecPayOn1 ELSE ifnull(tr.PayOn1, 0) END RecPayOn1 ';
        $sql .= ', case when m.RecPayTypeID = \'\' then m.RecClose2 ELSE ifnull(tr.Close2, 0) END RecClose2 ';
        $sql .= ', case when m.RecPayTypeID = \'\' then m.RecPay2 ELSE ifnull(tr.Pay2, 0) END RecPay2 ';
        $sql .= ', case when m.RecPayTypeID = \'\' then m.RecPayOn2 ELSE ifnull(tr.PayOn2, 0) END RecPayOn2 ';
        $sql .= ', m.PayPayTypeID ';
        $sql .= ', case when m.PayPayTypeID = \'\' then m.PayPayType ELSE ifnull(tp.PayType, 0) END PayPayType ';
        $sql .= ', case when m.PayPayTypeID = \'\' then m.PayClose1 ELSE ifnull(tp.Close1, 0) END PayClose1 ';
        $sql .= ', case when m.PayPayTypeID = \'\' then m.PayPay1 ELSE ifnull(tp.Pay1, 0) END PayPay1 ';
        $sql .= ', case when m.PayPayTypeID = \'\' then m.PayPayOn1 ELSE ifnull(tp.PayOn1, 0) END PayPayOn1 ';
        $sql .= ', case when m.PayPayTypeID = \'\' then m.PayClose2 ELSE ifnull(tp.Close2, 0) END PayClose2 ';
        $sql .= ', case when m.PayPayTypeID = \'\' then m.PayPay2 ELSE ifnull(tp.Pay2, 0) END PayPay2 ';
        $sql .= ', case when m.PayPayTypeID = \'\' then m.PayPayOn2 ELSE ifnull(tp.PayOn2, 0) END PayPayOn2 ';
        $sql .= 'FROM u_client m ';
        $sql .= 'LEFT Join u_creditlimit li ';
        $sql .= 'ON  m.CreLimitID = li.CreLimitID ';
        $sql .= 'AND m.LanguageID = li.LanguageID ';
        $sql .= 'LEFT Join u_paytype tr ';
        $sql .= 'ON  m.RecPayTypeID = tr.PayTypeID ';
        $sql .= 'AND m.LanguageID = tr.LanguageID ';
        $sql .= 'LEFT Join u_paytype tp ';
        $sql .= 'ON  m.PayPayTypeID = tp.PayTypeID ';
        $sql .= 'AND m.LanguageID = tp.LanguageID ';
        $sql .= 'WHERE m.LanguageID = ? ';  // $lang
        $sql .= 'AND m.`Status`=\'1\' ';
        $sql .= 'AND (m.ClientID LIKE ? ';  // $filter
        $sql .= 'OR m.ClientID IN ';
        $sql .= '( ';
        $sql .= 'SELECT ClientID FROM u_client ';
        $sql .= 'WHERE STATUS=\'1\' ';
        $sql .= 'AND ClientName LIKE ? '; // $filter
        $sql .= ') ';
        $sql .= ') ';
        $sql .= $sql_SupplierFlg.' ';
        $sql .= $sql_ClientFlg.' ';
        $sql .= $sql_ForwarderFlg.' ';
        $sql .= $sql_CustomsFlg.' ';
        $sql .= $sql_RevDepFlg.' ';
        $sql .= $sql_BankFlg.' ';
        $sql .= 'ORDER BY m.ClientName; ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $LanguageID, $filter1, $filter2);
            $LanguageID         = $lang;
            $filter1           = '%'.$filter.'%';
            $filter2           = '%'.$filter.'%';
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* u_division                                             */
/*--------------------------------------------------------*/
    // 同事業部IDの件数を取得する
    public function gDivIDSameCntVal($divid) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT COUNT(*) AS cnt ';
        $sql .= 'FROM   u_division ';
        $sql .= 'WHERE  DivisionID = ? ';    // $divid
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $DivisionID);
            $DivisionID = $divid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 事業部情報を追加する
    public function iDivInfo($divid, $languageid, $divname, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO u_division(DivisionID, LanguageID, DivisionName, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $divid
        $sql .= ',? ';    // $languageid
        $sql .= ',? ';    // $divname
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssss', $DivisionID, $LanguageID, $DivisionName, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $DivisionID   = $divid;
            $LanguageID   = $languageid;
            $DivisionName = $divname;
            $EntDate      = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser      = $userid;
            $UpdDate      = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser      = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 事業部情報を取得する(全件)
    public function gDivList($searchdate, $syear, $smonth, $sday, $eyear, $emonth, $eday, $searchText, $pageRowText, $pages, $lang, $blankflg) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sdate           = self::sSDate($searchdate, $syear, $smonth, $sday);    // 検索条件(開始日)
        $edate           = self::sEDate($searchdate, $eyear, $emonth, $eday);    // 検索条件(終了日)
        $array           = self::sLimit($pageRowText, $pages);                   // 検索条件(ページング)
        $offset          = $array[0];
        $limit           = $array[1];
        
        $sql  = 'SELECT DivisionNo ';
        $sql .= '     , DivisionID ';
        $sql .= '     , DivisionName ';
        $sql .= '     , EntDate ';
        $sql .= 'FROM   u_division ';
        $sql .= 'WHERE  LanguageID        = ? ';    // $lang
        $sql .= 'AND    EntDate          >= ? ';    // $sdate
        $sql .= 'AND    EntDate          <= ? ';    // $edate
        $sql .= 'AND    ( ';
        $sql .= '           DivisionName LIKE ? ';    // '%'+$searchText+'%'
        $sql .= '       ) ';
        $sql .= 'AND    Status= true ';
        $sql .= 'ORDER BY DivisionID ';
        $sql .= 'LIMIT ?, ? ';    // $offset, $limit
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssii', $LanguageID, $SEntDate, $EEntDate, $DivisionName, $Offset, $Limit);
            $LanguageID   = $lang;
            $SEntDate     = $sdate;
            $EEntDate     = $edate;
            $DivisionName = '%'.$searchText.'%';
            $Offset       = $offset;
            $Limit        = $limit;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 事業部情報を取得する(一件用)
    public function gDivRow($divid, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT DivisionNo ';
        $sql .= '     , DivisionID ';
        $sql .= '     , DivisionName ';
        $sql .= 'FROM   u_division ';
        $sql .= 'WHERE  LanguageID = ? ';    // $lang
        $sql .= 'AND    DivisionID = ? ';    // $divid
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $LanguageID, $DivisionID);
            $LanguageID = $lang;
            $DivisionID = $divid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 事業部IDを取得する
    public function gDivIDVal($divno, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT DivisionID ';
        $sql .= 'FROM   u_division ';
        $sql .= 'WHERE  LanguageID = ? ';    // $lang
        $sql .= 'AND    DivisionNo = ? ';    // $divno
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $LanguageID, $DivisionNo);
            $LanguageID = $lang;
            $DivisionNo = $divno;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 事業部情報を更新する
    public function uDivInfo($dividBef, $dividAft, $divname, $lang, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_division ';
        $sql .= 'SET    DivisionID   = ? ';    // $dividAft
        $sql .= '    ,  DivisionName = ? ';    // $divname
        $sql .= '    ,  UpdDate      = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  UpdUser      = ? ';    // $userid
        $sql .= 'WHERE  DivisionID   = ? ';    // $dividBef
        $sql .= 'AND    LanguageID   = ? ';    // $lang
        $sql .= 'AND    Status       = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssss', $DivisionID, $DivisionName, $UpdDate, $UpdUser, $DivisionID, $LanguageID);
            $DivisionID   = $dividAft;
            $DivisionName = $divname;
            $UpdDate      = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser      = $userid;
            $DivisionID   = $dividBef;
            $LanguageID   = $lang;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 事業部情報を削除する(対象は3言語)
    public function dDivInfo($divid, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_division ';
        $sql .= 'SET    Status     = false ';
        $sql .= '    ,  UpdDate    = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  UpdUser    = ? ';    // $userid
        $sql .= '    ,  DelDate    = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  DelUser    = ? ';    // $userid
        $sql .= 'WHERE  DivisionID = ? ';    // $divid
        $sql .= 'AND    Status   = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $DivisionID);
            $UpdDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser    = $userid;
            $DelDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser    = $userid;
            $DivisionID = $divid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    
/*--------------------------------------------------------*/
/* u_currency                                             */
/*--------------------------------------------------------*/
    // 同通貨IDの件数を取得する
    public function gCurIDSameCntVal($curid) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT COUNT(*) AS cnt ';
        $sql .= 'FROM   u_currency ';
        $sql .= 'WHERE  CurrencyID = ? ';    // $curid
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $CurrencyID);
            $CurrencyID = $curid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 通貨情報を追加する
    public function iCurInfo($curid, $languageid, $curname, $declen, $unitper, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO u_currency(CurrencyID, LanguageID, CurrencyName, DecimalLength, UnitPer, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $curid
        $sql .= ',? ';    // $languageid
        $sql .= ',? ';    // $curname
        $sql .= ',? ';    // $declen
        $sql .= ',? ';    // $unitper
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssiissss', $CurrencyID, $LanguageID, $CurrencyName, $DecimalLength, $UnitPer, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $CurrencyID   = $curid;
            $LanguageID   = $languageid;
            $CurrencyName = $curname;
            $DecimalLength= $declen;
            $UnitPer	  = $unitper;
            $EntDate      = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser      = $userid;
            $UpdDate      = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser      = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            
			$stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 通貨情報を取得する(全件)
    public function gCurList($searchdate, $syear, $smonth, $sday, $eyear, $emonth, $eday, $searchText, $pageRowText, $pages, $lang, $blankflg) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sdate           = self::sSDate($searchdate, $syear, $smonth, $sday);    // 検索条件(開始日)
        $edate           = self::sEDate($searchdate, $eyear, $emonth, $eday);    // 検索条件(終了日)
        $array           = self::sLimit($pageRowText, $pages);                   // 検索条件(ページング)
        $offset          = $array[0];
        $limit           = $array[1];
        
        $sql  = 'SELECT CurrencyNo ';
        $sql .= '     , CurrencyID ';
        $sql .= '     , CurrencyName ';
        $sql .= '     , DecimalLength ';
        $sql .= '     , EntDate ';
        $sql .= 'FROM   u_currency ';
        $sql .= 'WHERE  LanguageID        = ? ';    // $lang
        $sql .= 'AND    EntDate          >= ? ';    // $sdate
        $sql .= 'AND    EntDate          <= ? ';    // $edate
        $sql .= 'AND    ( ';
        $sql .= '           CurrencyName LIKE ? ';    // '%'+$searchText+'%'
        $sql .= 'OR         CurrencyID   LIKE ? ';    // '%'+$searchText+'%'
        $sql .= '       ) ';
        $sql .= 'AND    Status= true ';
        $sql .= 'ORDER BY CurrencyID ';
        $sql .= 'LIMIT ?, ? ';    // $offset, $limit
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssii', $LanguageID, $SEntDate, $EEntDate, $CurrencyName, $CurrencyID, $Offset, $Limit);
            $LanguageID   = $lang;
            $SEntDate     = $sdate;
            $EEntDate     = $edate;
            $CurrencyName = '%'.$searchText.'%';
            $CurrencyID   = '%'.$searchText.'%';
            $Offset       = $offset;
            $Limit        = $limit;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 通貨情報を取得する(一件用)
    public function gCurRow($curid, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT CurrencyNo ';
        $sql .= '     , CurrencyID ';
        $sql .= '     , CurrencyName ';
        $sql .= '     , DecimalLength ';
        $sql .= '     , UnitPer ';
        $sql .= 'FROM   u_currency ';
        $sql .= 'WHERE  LanguageID = ? ';    // $lang
        $sql .= 'AND    CurrencyID = ? ';    // $curid
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $LanguageID, $CurrencyID);
            $LanguageID = $lang;
            $CurrencyID = $curid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 通貨IDを取得する
    public function gCurIDVal($curno, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT CurrencyID ';
        $sql .= 'FROM   u_currency ';
        $sql .= 'WHERE  LanguageID = ? ';    // $lang
        $sql .= 'AND    CurrencyNo = ? ';    // $curno
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $LanguageID, $CurrencyNo);
            $LanguageID = $lang;
            $CurrencyNo = $curno;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 通貨情報を更新する
    public function uCurInfo($curidBef, $curidAft, $curname, $declen, $unitper, $lang, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_currency ';
        $sql .= 'SET    CurrencyID   = ? ';    // $curidAft
        $sql .= '    ,  CurrencyName = ? ';    // $curname
        $sql .= '    ,  DecimalLength= ? ';    // $declen
        $sql .= '    ,  UnitPer      = ? ';    // $unitper
        $sql .= '    ,  UpdDate      = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  UpdUser      = ? ';    // $userid
        $sql .= 'WHERE  CurrencyID   = ? ';    // $curidBef
        $sql .= 'AND    LanguageID   = ? ';    // $lang
        $sql .= 'AND    Status       = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssiissss', $CurrencyID, $CurrencyName, $DecimalLength, $UnitPer, $UpdDate, $UpdUser, $CurrencyID, $LanguageID);
            $CurrencyID   = $curidAft;
            $CurrencyName = $curname;
            $DecimalLength= $declen;
            $UnitPer	  = $unitper;
            $UpdDate      = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser      = $userid;
            $CurrencyID   = $curidBef;
            $LanguageID   = $lang;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 通貨情報を削除する(対象は3言語)
    public function dCurInfo($curid, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_currency ';
        $sql .= 'SET    Status     = false ';
        $sql .= '    ,  UpdDate    = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  UpdUser    = ? ';    // $userid
        $sql .= '    ,  DelDate    = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  DelUser    = ? ';    // $userid
        $sql .= 'WHERE  CurrencyID = ? ';    // $curid
        $sql .= 'AND    Status   = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $CurrencyID);
            $UpdDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser    = $userid;
            $DelDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser    = $userid;
            $CurrencyID = $curid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
/*--------------------------------------------------------*/
/* u_bank                                                 */
/*--------------------------------------------------------*/
    // 同銀行IDの件数を取得する
    public function gBankIDSameCntVal($bankid) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT COUNT(*) AS cnt ';
        $sql .= 'FROM   u_bank ';
        $sql .= 'WHERE  BankID  = ? ';    // $bankid
        $sql .= 'AND    Status  = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $BankID);
            $BankID = $bankid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 銀行情報を追加する
    public function iBankInfo($bankid, $languageid, $bankname, $dockind, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO u_bank(BankID, LanguageID, BankName, DocKind, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $bankid
        $sql .= ',? ';    // $languageid
        $sql .= ',? ';    // $bankname
        $sql .= ',? ';    // $dockind
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssss', $BankID, $LanguageID, $BankName, $DocKind, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $BankID     = $bankid;
            $LanguageID = $languageid;
            $BankName   = $bankname;
            $DocKind    = $dockind;
            $EntDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser    = $userid;
            $UpdDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser    = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 銀行情報を取得する(全件)
    public function gBankList($searchdate, $syear, $smonth, $sday, $eyear, $emonth, $eday, $searchText, $pageRowText, $pages, $lang, $blankflg) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sdate           = self::sSDate($searchdate, $syear, $smonth, $sday);    // 検索条件(開始日)
        $edate           = self::sEDate($searchdate, $eyear, $emonth, $eday);    // 検索条件(終了日)
        $array           = self::sLimit($pageRowText, $pages);                   // 検索条件(ページング)
        $offset          = $array[0];
        $limit           = $array[1];
        
        $sql  = 'SELECT BankNo ';
        $sql .= '     , BankID ';
        $sql .= '     , BankName ';
        $sql .= '     , DocKind ';
        $sql .= '     , EntDate ';
        $sql .= 'FROM   u_bank ';
        $sql .= 'WHERE  LanguageID        = ? ';    // $lang
        $sql .= 'AND    EntDate          >= ? ';    // $sdate
        $sql .= 'AND    EntDate          <= ? ';    // $edate
        $sql .= 'AND    ( ';
        $sql .= '           BankName LIKE ? ';    // '%'+$searchText+'%'
        $sql .= 'OR         BankID   LIKE ? ';    // '%'+$searchText+'%'
        $sql .= '       ) ';
        $sql .= 'AND    Status= true ';
        $sql .= 'ORDER BY BankID ';
        $sql .= 'LIMIT ?, ? ';    // $offset, $limit
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssii', $LanguageID, $SEntDate, $EEntDate, $BankName, $BankID, $Offset, $Limit);
            $LanguageID   = $lang;
            $SEntDate     = $sdate;
            $EEntDate     = $edate;
            $BankName     = '%'.$searchText.'%';
            $BankID       = '%'.$searchText.'%';
            $Offset       = $offset;
            $Limit        = $limit;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 銀行情報を取得する(一件用)
    public function gBankRow($bankid, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT BankNo ';
        $sql .= '     , BankID ';
        $sql .= '     , BankName ';
        $sql .= '     , DocKind ';
        $sql .= 'FROM   u_bank ';
        $sql .= 'WHERE  LanguageID = ? ';    // $lang
        $sql .= 'AND    BankID = ? ';    // $bankid
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $LanguageID, $BankID);
            $LanguageID = $lang;
            $BankID = $bankid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 銀行IDを取得する
    public function gBankIDVal($bankno, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT BankID ';
        $sql .= 'FROM   u_bank ';
        $sql .= 'WHERE  LanguageID = ? ';    // $lang
        $sql .= 'AND    BankNo = ? ';    // $bankno
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $LanguageID, $BankNo);
            $LanguageID = $lang;
            $BankNo = $bankno;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 銀行情報を更新する
    public function uBankInfo($bankidBef, $bankidAft, $bankname, $dockind, $lang, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_bank ';
        $sql .= 'SET    BankID      = ? ';    // $bankidAft
        $sql .= '    ,  BankName    = ? ';    // $bankname
        $sql .= '    ,  DocKind     = ? ';    // $dockind
        $sql .= '    ,  UpdDate     = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  UpdUser     = ? ';    // $userid
        $sql .= 'WHERE  BankID      = ? ';    // $bankidBef
        $sql .= 'AND    LanguageID  = ? ';    // $lang
        $sql .= 'AND    Status      = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssss', $BankID, $BankName, $DocKind, $UpdDate, $UpdUser, $BankID, $LanguageID);
            $BankID     = $bankidAft;
            $BankName   = $bankname;
            $DocKind    = $dockind;
            $UpdDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser    = $userid;
            $BankID     = $bankidBef;
            $LanguageID = $lang;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 銀行情報を削除する(対象は3言語)
    public function dBankInfo($bankid, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_bank ';
        $sql .= 'SET    Status     = false ';
        $sql .= '    ,  UpdDate    = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  UpdUser    = ? ';    // $userid
        $sql .= '    ,  DelDate    = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  DelUser    = ? ';    // $userid
        $sql .= 'WHERE  BankID = ? ';    // $bankid
        $sql .= 'AND    Status   = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $BankID);
            $UpdDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser    = $userid;
            $DelDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser    = $userid;
            $BankID     = $bankid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
/*--------------------------------------------------------*/
/* u_bankaccount                                          */
/*--------------------------------------------------------*/
    // 同銀行口座IDの件数を取得する
    public function gBankAccIDSameCntVal($bankid, $bankaccountid) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT COUNT(*) AS cnt ';
        $sql .= 'FROM   u_bankaccount ';
        $sql .= 'WHERE  BankID          = ? ';    // $bankid
        $sql .= 'AND    BankAccountID   = ? ';    // $bankaccountid
        $sql .= 'AND    Status          = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $BankID, $BankAccountID);
            $BankID         = $bankid;
            $BankAccountID  = $bankaccountid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 銀行口座情報を追加する
    public function iBankAccInfo($bankid, $bankaccountid, $languageid, $bankaccountname, $bankaccountno, $accountstitleid, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO u_bankaccount(BankID, BankAccountID, LanguageID, BankAccountName, BankAccountNo, AccountsTitleID, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $bankid
        $sql .= ',? ';    // $bankaccountid
        $sql .= ',? ';    // $languageid
        $sql .= ',? ';    // $bankaccountname
        $sql .= ',? ';    // $bankaccountno
        $sql .= ',? ';    // $accountstitleid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssss', $BankID, $BankAccountID, $LanguageID, $BankAccountName, $BankAccountNo, $AccountsTitleID, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $BankID             = $bankid;
            $BankAccountID      = $bankaccountid;
            $LanguageID         = $languageid;
            $BankAccountName    = $bankaccountname;
            $BankAccountNo      = $bankaccountno;
            $AccountsTitleID    = $accountstitleid;
            $EntDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser    = $userid;
            $UpdDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser    = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 銀行口座情報を取得する(全件)
    public function gBankAccList($searchdate, $syear, $smonth, $sday, $eyear, $emonth, $eday, $bankid, $searchText, $pageRowText, $pages, $lang, $blankflg) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sdate           = self::sSDate($searchdate, $syear, $smonth, $sday);    // 検索条件(開始日)
        $edate           = self::sEDate($searchdate, $eyear, $emonth, $eday);    // 検索条件(終了日)
        $sql_Bank        = self::sDataFlg('u_bankaccount', $bankid, 'BankID');   // 検索条件(銀行ID)
        $array           = self::sLimit($pageRowText, $pages);                   // 検索条件(ページング)
        $offset          = $array[0];
        $limit           = $array[1];
        
        $sql  = 'SELECT u_bankaccount.BankAccountCode ';
        $sql .= '     , u_bankaccount.BankID ';
        $sql .= '     , u_bank.BankName ';
        $sql .= '     , u_bankaccount.BankAccountID ';
        $sql .= '     , u_bankaccount.BankAccountName ';
        $sql .= '     , u_bankaccount.BankAccountNo ';
        $sql .= '     , u_bankaccount.AccountsTitleID ';
        $sql .= '     , m_accountstitles.AccountsTitleSName ';
        $sql .= '     , u_bankaccount.EntDate ';
        $sql .= 'FROM   u_bankaccount ';
        $sql .= 'LEFT JOIN u_bank ';
        $sql .= 'ON  u_bank.BankID = u_bankaccount.BankID ';
        $sql .= 'AND u_bank.LanguageID = u_bankaccount.LanguageID ';
        $sql .=	'AND u_bank.Status=TRUE  ';
        $sql .= 'LEFT JOIN m_accountstitles ';
        $sql .= 'ON  m_accountstitles.AccountsTitleID = u_bankaccount.AccountsTitleID ';
        $sql .= 'AND m_accountstitles.LanguageID = u_bankaccount.LanguageID ';
        $sql .=	'AND m_accountstitles.Status=TRUE  ';
        $sql .= 'WHERE  u_bankaccount.LanguageID        = ? ';    // $lang
        $sql .= 'AND    u_bankaccount.EntDate          >= ? ';    // $sdate
        $sql .= 'AND    u_bankaccount.EntDate          <= ? ';    // $edate
        $sql .= 'AND    ( ';
        $sql .= '           u_bankaccount.BankAccountName LIKE ? ';    // '%'+$searchText+'%'
        $sql .= 'OR         u_bankaccount.BankAccountID   LIKE ? ';    // '%'+$searchText+'%'
        $sql .= '       ) ';
        $sql .= $sql_Bank.' ';
        $sql .= 'AND    u_bankaccount.Status= true ';
        $sql .= 'ORDER BY u_bankaccount.BankID, u_bankaccount.BankAccountID ';
        $sql .= 'LIMIT ?, ? ';    // $offset, $limit
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssii', $LanguageID, $SEntDate, $EEntDate, $BankAccountName, $BankID, $Offset, $Limit);
            $LanguageID   = $lang;
            $SEntDate     = $sdate;
            $EEntDate     = $edate;
            $BankAccountName     = '%'.$searchText.'%';
            $BankID       = '%'.$searchText.'%';
            $Offset       = $offset;
            $Limit        = $limit;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 銀行口座情報を取得する(一件用)
    public function gBankAccRow($bankid, $bankaccountid, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT BankAccountCode ';
        $sql .= '     , BankID ';
        $sql .= '     , BankAccountID ';
        $sql .= '     , BankAccountName ';
        $sql .= '     , BankAccountNo ';
        $sql .= '     , AccountsTitleID ';
        $sql .= 'FROM   u_bankaccount ';
        $sql .= 'WHERE  LanguageID      = ? ';    // $lang
        $sql .= 'AND    BankID          = ? ';    // $bankid
        $sql .= 'AND    BankAccountID   = ? ';    // $bankaccountid
        $sql .= 'AND    Status          = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $LanguageID, $BankID, $BankAccountID);
            $LanguageID     = $lang;
            $BankID         = $bankid;
            $BankAccountID  = $bankaccountid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 銀行口座IDを取得する
    public function gBankAccIDVal($bankaccountcode, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT BankID ';
        $sql .= '     , BankAccountID ';
        $sql .= 'FROM   u_bankaccount ';
        $sql .= 'WHERE  LanguageID = ? ';    // $lang
        $sql .= 'AND    BankAccountCode = ? ';    // $bankaccountcode
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $LanguageID, $BankAccountCode);
            $LanguageID = $lang;
            $BankAccountCode = $bankaccountcode;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 銀行口座情報を更新する
    public function uBankAccInfo($bankidBef, $bankaccountidBef, $bankidAft, $bankaccountidAft, $bankaccountname, $bankaccountno, $accountstitleid, $lang, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_bankaccount ';
        $sql .= 'SET    BankID      = ? ';    // $bankidAft
        $sql .= '    ,  BankAccountID   = ? ';    // $bankaccountidAft
        $sql .= '    ,  BankAccountName = ? ';    // $bankaccountname
        $sql .= '    ,  BankAccountNo   = ? ';    // $bankaccountno
        $sql .= '    ,  AccountsTitleID = ? ';    // $accountstitleid
        $sql .= '    ,  UpdDate     = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  UpdUser     = ? ';    // $userid
        $sql .= 'WHERE  BankID      = ? ';    // $bankidBef
        $sql .= 'AND    BankAccountID   = ? ';    // $bankaccountidBef
        $sql .= 'AND    LanguageID  = ? ';    // $lang
        $sql .= 'AND    Status      = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssss', $BankIDAft, $BankAccountIDAft, $BankAccountName, $BankAccountNo, $AccountsTitleID, $UpdDate, $UpdUser, $BankIDBef, $BankAccountIDBef, $LanguageID);
            $BankIDAft     = $bankidAft;
            $BankAccountIDAft   = $bankaccountidAft;
            $BankAccountName    = $bankaccountname;
            $BankAccountNo      = $bankaccountno;
            $AccountsTitleID    = $accountstitleid;
            $UpdDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser    = $userid;
            $BankIDBef     = $bankidBef;
            $BankAccountIDBef      = $bankaccountidBef;
            $LanguageID = $lang;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 銀行口座情報を削除する(対象は3言語)
    public function dBankAccInfo($bankid, $bankaccountid, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_bankaccount ';
        $sql .= 'SET    Status     = false ';
        $sql .= '    ,  UpdDate    = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  UpdUser    = ? ';    // $userid
        $sql .= '    ,  DelDate    = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  DelUser    = ? ';    // $userid
        $sql .= 'WHERE  BankID = ? ';    // $bankid
        $sql .= 'AND    BankAccountID = ? ';    // $bankaccountid
        $sql .= 'AND    Status   = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $BankID, $BankAccountID);
            $UpdDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser    = $userid;
            $DelDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser    = $userid;
            $BankID     = $bankid;
            $BankAccountID      = $bankaccountid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
/*--------------------------------------------------------*/
/* u_segment                                             */
/*--------------------------------------------------------*/
    // 同セグメントIDの件数を取得する
    public function gSegIDSameCntVal($segid) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT COUNT(*) AS cnt ';
        $sql .= 'FROM   u_segment ';
        $sql .= 'WHERE  SegmentID = ? ';    // $segid
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $SegmentID);
            $SegmentID = $segid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // セグメント情報を追加する
    public function iSegInfo($segid, $languageid, $segname, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO u_segment(SegmentID, LanguageID, SegmentName, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $segid
        $sql .= ',? ';    // $languageid
        $sql .= ',? ';    // $segname
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssss', $SegmentID, $LanguageID, $SegmentName, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $SegmentID   = $segid;
            $LanguageID   = $languageid;
            $SegmentName = $segname;
            $EntDate      = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser      = $userid;
            $UpdDate      = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser      = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // セグメント情報を取得する(全件)
    public function gSegList($searchdate, $syear, $smonth, $sday, $eyear, $emonth, $eday, $searchText, $pageRowText, $pages, $lang, $blankflg) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sdate           = self::sSDate($searchdate, $syear, $smonth, $sday);    // 検索条件(開始日)
        $edate           = self::sEDate($searchdate, $eyear, $emonth, $eday);    // 検索条件(終了日)
        $array           = self::sLimit($pageRowText, $pages);                   // 検索条件(ページング)
        $offset          = $array[0];
        $limit           = $array[1];
        
        $sql  = 'SELECT SegmentNo ';
        $sql .= '     , SegmentID ';
        $sql .= '     , SegmentName ';
        $sql .= '     , EntDate ';
        $sql .= 'FROM   u_segment ';
        $sql .= 'WHERE  LanguageID        = ? ';    // $lang
        $sql .= 'AND    EntDate          >= ? ';    // $sdate
        $sql .= 'AND    EntDate          <= ? ';    // $edate
        $sql .= 'AND    ( ';
        $sql .= '           SegmentName LIKE ? ';    // '%'+$searchText+'%'
        $sql .= '       ) ';
        $sql .= 'AND    Status= true ';
        $sql .= 'ORDER BY SegmentID ';
        $sql .= 'LIMIT ?, ? ';    // $offset, $limit
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssii', $LanguageID, $SEntDate, $EEntDate, $SegmentName, $Offset, $Limit);
            $LanguageID   = $lang;
            $SEntDate     = $sdate;
            $EEntDate     = $edate;
            $SegmentName = '%'.$searchText.'%';
            $Offset       = $offset;
            $Limit        = $limit;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // セグメント情報を取得する(一件用)
    public function gSegRow($segid, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT SegmentNo ';
        $sql .= '     , SegmentID ';
        $sql .= '     , SegmentName ';
        $sql .= 'FROM   u_segment ';
        $sql .= 'WHERE  LanguageID = ? ';    // $lang
        $sql .= 'AND    SegmentID = ? ';    // $segid
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $LanguageID, $SegmentID);
            $LanguageID = $lang;
            $SegmentID = $segid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // セグメントIDを取得する
    public function gSegIDVal($segno, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT SegmentID ';
        $sql .= 'FROM   u_segment ';
        $sql .= 'WHERE  LanguageID = ? ';    // $lang
        $sql .= 'AND    SegmentNo = ? ';    // $segno
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $LanguageID, $SegmentNo);
            $LanguageID = $lang;
            $SegmentNo = $segno;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // セグメント情報を更新する
    public function uSegInfo($segidBef, $segidAft, $segname, $lang, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_segment ';
        $sql .= 'SET    SegmentID    = ? ';    // $segidAft
        $sql .= '    ,  SegmentName = ? ';    // $segname
        $sql .= '    ,  UpdDate      = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  UpdUser      = ? ';    // $userid
        $sql .= 'WHERE  SegmentID    = ? ';    // $segidBef
        $sql .= 'AND    LanguageID   = ? ';    // $lang
        $sql .= 'AND    Status       = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssss', $SegmentIDa, $SegmentName, $UpdDate, $UpdUser, $SegmentIDb, $LanguageID);
            $SegmentIDa   = $segidAft;
            $SegmentName  = $segname;
            $UpdDate      = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser      = $userid;
            $SegmentIDb   = $segidBef;
            $LanguageID   = $lang;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // セグメント情報を削除する(対象は3言語)
    public function dSegInfo($segid, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_segment ';
        $sql .= 'SET    Status     = false ';
        $sql .= '    ,  UpdDate    = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  UpdUser    = ? ';    // $userid
        $sql .= '    ,  DelDate    = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  DelUser    = ? ';    // $userid
        $sql .= 'WHERE  SegmentID = ? ';    // $segid
        $sql .= 'AND    Status   = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $SegmentID);
            $UpdDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser    = $userid;
            $DelDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser    = $userid;
            $SegmentID = $segid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // セグメント名を絞り込む
    public function gSegSearch($filter, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT m.SegmentID, m.SegmentName ';
        $sql .= 'FROM u_segment m ';
        $sql .= 'WHERE m.LanguageID = ? ';  // $lang
        $sql .= 'AND m.`Status`=\'1\' ';
        $sql .= 'AND (m.SegmentID LIKE ? ';  // $filter
        $sql .= 'OR m.SegmentID IN ';
        $sql .= '( ';
        $sql .= 'SELECT SegmentID FROM u_segment ';
        $sql .= 'WHERE STATUS=\'1\' ';
        $sql .= 'AND SegmentName LIKE ? '; // $filter
        $sql .= ') ';
        $sql .= ') ';
        $sql .= 'ORDER BY m.SegmentName; ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $LanguageID, $filter1, $filter2);
            $LanguageID         = $lang;
            $filter1           = '%'.$filter.'%';
            $filter2           = '%'.$filter.'%';
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* u_Asset                                                */
/*--------------------------------------------------------*/
    // 資産種別情報を追加する
    public function iAssInfo($assetid, $languageid, $assname, $assperiod, $assrate, $fixassetaccid, $accdipreciatedid, $dipreciationaccid, $gainondisposalid, $lossondisposalid, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO u_asset(AssetID, LanguageID, AssetName, AssetPeriod, AssetRate, FixAssetAccID, AccDipreciatedID, DipreciationAccID, GainOnDisposalID, LossOnDisposalID, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $assetid
        $sql .= ',? ';    // $languageid
        $sql .= ',? ';    // $assname
        $sql .= ',? ';    // $assperiod
        $sql .= ',? ';    // $assrate
        $sql .= ',? ';    // $fixassetaccid
        $sql .= ',? ';    // $accdipreciatedid
        $sql .= ',? ';    // $dipreciationaccid
        $sql .= ',? ';    // $gainondisposalid
        $sql .= ',? ';    // $lossondisposalid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssssss', $AssetID, $LanguageID, $AssetName, $AssetPeriod, $AssetRate, $FixAssetAccID, $AccDipreciatedID, $DipreciationAccID, $GainOnDisposalID, $LossOnDisposalID, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $AssetID     = $assetid;
            $LanguageID  = $languageid;
            $AssetName   = $assname;
            $AssetPeriod = $assperiod;
            $AssetRate   = $assrate;
            $FixAssetAccID      = $fixassetaccid;
            $AccDipreciatedID   = $accdipreciatedid;
            $DipreciationAccID  = $dipreciationaccid;
            $GainOnDisposalID   = $gainondisposalid;
            $LossOnDisposalID   = $lossondisposalid;
            $EntDate     = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser     = $userid;
            $UpdDate     = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser     = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 資産種別情報を取得する(全件)
    public function gAssList($searchdate, $syear, $smonth, $sday, $eyear, $emonth, $eday, $searchText, $pageRowText, $pages, $lang, $blankflg) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sdate           = self::sSDate($searchdate, $syear, $smonth, $sday);    // 検索条件(開始日)
        $edate           = self::sEDate($searchdate, $eyear, $emonth, $eday);    // 検索条件(終了日)
        $array           = self::sLimit($pageRowText, $pages);                   // 検索条件(ページング)
        $offset          = $array[0];
        $limit           = $array[1];
        
        $sql  = 'SELECT AssetNo ';
        $sql .= '     , AssetID ';
        $sql .= '     , AssetName ';
        $sql .= '     , AssetPeriod ';
        $sql .= '     , AssetRate ';
        $sql .= '     , FixAssetAccID ';
        $sql .= '     , AccDipreciatedID ';
        $sql .= '     , DipreciationAccID ';
        $sql .= '     , GainOnDisposalID ';
        $sql .= '     , LossOnDisposalID ';
        $sql .= '     , EntDate ';
        $sql .= 'FROM   u_asset ';
        $sql .= 'WHERE  LanguageID        = ? ';    // $lang
        $sql .= 'AND    EntDate          >= ? ';    // $sdate
        $sql .= 'AND    EntDate          <= ? ';    // $edate
        $sql .= 'AND    ( ';
        $sql .= '           AssetName LIKE ? ';    // '%'+$searchText+'%'
        $sql .= '       ) ';
        $sql .= 'AND    Status= true ';
        $sql .= 'ORDER BY AssetNo ';
        $sql .= 'LIMIT ?, ? ';    // $offset, $limit
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssii', $LanguageID, $SEntDate, $EEntDate, $AssetName, $Offset, $Limit);
            $LanguageID   = $lang;
            $SEntDate     = $sdate;
            $EEntDate     = $edate;
            $AssetName = '%'.$searchText.'%';
            $Offset       = $offset;
            $Limit        = $limit;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 資産種別情報を取得する(一件用)
    public function gAssRow($assid, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT AssetNo ';
        $sql .= '     , AssetName ';
        $sql .= '     , AssetPeriod ';
        $sql .= '     , AssetRate ';
        $sql .= '     , FixAssetAccID ';
        $sql .= '     , AccDipreciatedID ';
        $sql .= '     , DipreciationAccID ';
        $sql .= '     , GainOnDisposalID ';
        $sql .= '     , LossOnDisposalID ';
        $sql .= 'FROM   u_asset ';
        $sql .= 'WHERE  LanguageID = ? ';    // $lang
        $sql .= 'AND    AssetID    = ? ';    // $assid
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $LanguageID, $AssetID);
            $LanguageID = $lang;
            $AssetID    = $assid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 資産種別情報を更新する
    public function uAssInfo($assetID, $assetName, $assetPeriod, $assetRate, $fixassetaccid, $accdipreciatedid, $dipreciationaccid, $gainondisposalid, $lossondisposalid, $lang, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_asset ';
        $sql .= 'SET    AssetName    = ? ';    // $assetName
        $sql .= '    ,  AssetPeriod  = ? ';    // $assetPeriod
        $sql .= '    ,  AssetRate    = ? ';    // $assetRate
        $sql .= '    ,  FixAssetAccID       = ? ';  // $fixassetaccid
        $sql .= '    ,  AccDipreciatedID    = ? ';  // $accdipreciatedid
        $sql .= '    ,  DipreciationAccID   = ? ';  // $dipreciationaccid
        $sql .= '    ,  GainOnDisposalID    = ? ';  // $gainondisposalid
        $sql .= '    ,  LossOnDisposalID    = ? ';  // $lossondisposalid
        $sql .= '    ,  UpdDate      = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  UpdUser      = ? ';    // $userid
        $sql .= 'WHERE  AssetID      = ? ';    // $assetID
        $sql .= 'AND    LanguageID   = ? ';    // $lang
        $sql .= 'AND    Status       = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssss', $AssetName, $AssetPeriod, $AssetRate, $FixAssetAccID, $AccDipreciatedID, $DipreciationAccID, $GainOnDisposalID, $LossOnDisposalID, $UpdDate, $UpdUser, $AssetID, $LanguageID);
            $AssetName   = $assetName;
            $AssetPeriod = $assetPeriod;
            $AssetRate   = $assetRate;
            $FixAssetAccID      = $fixassetaccid;
            $AccDipreciatedID   = $accdipreciatedid;
            $DipreciationAccID  = $dipreciationaccid;
            $GainOnDisposalID   = $gainondisposalid;
            $LossOnDisposalID   = $lossondisposalid;
            $UpdDate     = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser     = $userid;
            $AssetID     = $assetID;
            $LanguageID  = $lang;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 資産種別情報を削除する
    public function dAssInfo($assid, $lang, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_asset ';
        $sql .= 'SET    Status     = false ';
        $sql .= '    ,  UpdDate    = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  UpdUser    = ? ';    // $userid
        $sql .= '    ,  DelDate    = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  DelUser    = ? ';    // $userid
        $sql .= 'WHERE  AssetID    = ? ';    // $assno
        $sql .= 'AND    LanguageID = ? ';    // $lang
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $AssetID, $LanguageID);
            $UpdDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser    = $userid;
            $DelDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser    = $userid;
            $AssetID    = $assid;
            $LanguageID = $lang;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 資産種別IDの最大値を取得する
    public function gAssMaxID() {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT max(AssetID) AssetID ';
        $sql .= 'FROM   u_asset ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }

/*--------------------------------------------------------*/
/* u_paytype                                             */
/*--------------------------------------------------------*/
    // 同支払条件IDの件数を取得する
    public function gPayIDSameCntVal($payid) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT COUNT(*) AS cnt ';
        $sql .= 'FROM   u_paytype ';
        $sql .= 'WHERE  PayTypeID = ? ';    // $payid
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $PayTypeID);
            $PayTypeID = $payid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 支払条件情報を追加する
    public function iPayInfo($payid, $languageid, $payname, $paytype, $close1, $pay1, $payon1, $close2, $pay2, $payon2, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO u_paytype(PayTypeID, LanguageID, PayTypeName, PayType, Close1, Pay1, PayOn1, Close2, Pay2, PayOn2, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $payid
        $sql .= ',? ';    // $languageid
        $sql .= ',? ';    // $payname
        $sql .= ',? ';    // $paytype
        $sql .= ',? ';    // $close1
        $sql .= ',? ';    // $pay1
        $sql .= ',? ';    // $payon1
        $sql .= ',? ';    // $close2
        $sql .= ',? ';    // $pay2
        $sql .= ',? ';    // $payon2
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssssss', $PayTypeID, $LanguageID, $PayTypeName, $PayType, $Close1, $Pay1, $PayOn1, $Close2, $Pay2, $PayOn2, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $PayTypeID   	= $payid;
            $LanguageID   	= $languageid;
			$PayTypeName 	= $payname;
			$PayType 		= $paytype;
			$Close1 		= $close1;
			$Pay1 			= $pay1;
			$PayOn1 		= $payon1;
			$Close2 		= $close2;
			$Pay2 			= $pay2;
			$PayOn2 		= $payon2;
            $EntDate      	= (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser      	= $userid;
            $UpdDate      	= (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser      	= $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 支払条件情報を取得する(全件)
    public function gPayList($searchdate, $syear, $smonth, $sday, $eyear, $emonth, $eday, $searchText, $pageRowText, $pages, $lang, $blankflg) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sdate           = self::sSDate($searchdate, $syear, $smonth, $sday);    // 検索条件(開始日)
        $edate           = self::sEDate($searchdate, $eyear, $emonth, $eday);    // 検索条件(終了日)
        $array           = self::sLimit($pageRowText, $pages);                   // 検索条件(ページング)
        $offset          = $array[0];
        $limit           = $array[1];
        
        $sql  = 'SELECT PayTypeNo ';
        $sql .= '     , PayTypeID ';
        $sql .= '     , PayTypeName ';
		$sql .= '     , PayType ';
		$sql .= '     , Close1 ';
		$sql .= '     , Pay1 ';
		$sql .= '     , PayOn1 ';
		$sql .= '     , Close2 ';
		$sql .= '     , Pay2 ';
		$sql .= '     , PayOn2 ';
        $sql .= '     , EntDate ';
        $sql .= 'FROM   u_paytype ';
        $sql .= 'WHERE  LanguageID        = ? ';    // $lang
        $sql .= 'AND    EntDate          >= ? ';    // $sdate
        $sql .= 'AND    EntDate          <= ? ';    // $edate
        $sql .= 'AND    ( ';
        $sql .= '           PayTypeName LIKE ? ';    // '%'+$searchText+'%'
        $sql .= '       ) ';
        $sql .= 'AND    Status= true ';
        $sql .= 'ORDER BY PayTypeID ';
        $sql .= 'LIMIT ?, ? ';    // $offset, $limit
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssii', $LanguageID, $SEntDate, $EEntDate, $PayTypeName, $Offset, $Limit);
            $LanguageID   = $lang;
            $SEntDate     = $sdate;
            $EEntDate     = $edate;
            $PayTypeName = '%'.$searchText.'%';
            $Offset       = $offset;
            $Limit        = $limit;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 支払条件情報を取得する(一件用)
    public function gPayRow($payid, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT PayTypeNo ';
        $sql .= '     , PayTypeID ';
        $sql .= '     , PayTypeName ';
		$sql .= '     , PayType ';
		$sql .= '     , Close1 ';
		$sql .= '     , Pay1 ';
		$sql .= '     , PayOn1 ';
		$sql .= '     , Close2 ';
		$sql .= '     , Pay2 ';
		$sql .= '     , PayOn2 ';
        $sql .= 'FROM   u_paytype ';
        $sql .= 'WHERE  LanguageID = ? ';    // $lang
        $sql .= 'AND    PayTypeID = ? ';    // $payid
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $LanguageID, $PayTypeID);
            $LanguageID = $lang;
            $PayTypeID = $payid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 支払条件IDを取得する
    public function gPayIDVal($payno, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT PayTypeID ';
        $sql .= 'FROM   u_paytype ';
        $sql .= 'WHERE  LanguageID = ? ';    // $lang
        $sql .= 'AND    PayTypeNo = ? ';    // $payno
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $LanguageID, $PayTypeNo);
            $LanguageID = $lang;
            $PayTypeNo = $payno;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 支払条件情報を更新する
    public function uPayInfo($payidBef, $payidAft, $payname, $paytype, $close1, $pay1, $payon1, $close2, $pay2, $payon2, $lang, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_paytype ';
        $sql .= 'SET    PayTypeID    = ? ';    // $payidAft
		$sql .= '    ,  PayTypeName  = ? ';    // $payname
		$sql .= '    ,  PayType  	 = ? ';    // $paytype
		$sql .= '    ,  Close1  	 = ? ';    // $close1
		$sql .= '    ,  Pay1  		 = ? ';    // $pay1
		$sql .= '    ,  PayOn1  	 = ? ';    // $payon1
		$sql .= '    ,  Close2  	 = ? ';    // $close2
		$sql .= '    ,  Pay2  		 = ? ';    // $pay2
		$sql .= '    ,  PayOn2  	 = ? ';    // $payon2
        $sql .= '    ,  UpdDate      = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  UpdUser      = ? ';    // $userid
        $sql .= 'WHERE  PayTypeID    = ? ';    // $payidBef
        $sql .= 'AND    LanguageID   = ? ';    // $lang
        $sql .= 'AND    Status       = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssssssssss', $PayTypeIDa, $PayTypeName, $PayType, $Close1, $Pay1, $PayOn1, $Close2, $Pay2, $PayOn2, $UpdDate, $UpdUser, $PayTypeIDb, $LanguageID);
            $PayTypeIDa   	= $payidAft;
            $PayTypeName  	= $payname;
			$PayType 		= $paytype;
			$Close1 		= $close1;
			$Pay1 			= $pay1;
			$PayOn1 		= $payon1;
			$Close2 		= $close2;
			$Pay2 			= $pay2;
			$PayOn2 		= $payon2;
            $UpdDate      	= (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser      	= $userid;
            $PayTypeIDb   	= $payidBef;
            $LanguageID   	= $lang;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 支払条件情報を削除する(対象は3言語)
    public function dPayInfo($payid, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_paytype ';
        $sql .= 'SET    Status     = false ';
        $sql .= '    ,  UpdDate    = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  UpdUser    = ? ';    // $userid
        $sql .= '    ,  DelDate    = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  DelUser    = ? ';    // $userid
        $sql .= 'WHERE  PayTypeID = ? ';    // $payid
        $sql .= 'AND    Status   = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $PayTypeID);
            $UpdDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser    = $userid;
            $DelDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser    = $userid;
            $PayTypeID = $payid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 支払条件名を絞り込む
    public function gPaySearch($filter, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT m.PayTypeID, m.PayTypeName ';
        $sql .= ', m.PayType, m.Close1, m.Pay1, m.PayOn1, m.Close2, m.Pay2, m.PayOn2 ';
        $sql .= 'FROM u_paytype m ';
        $sql .= 'WHERE m.LanguageID = ? ';  // $lang
        $sql .= 'AND m.`Status`=\'1\' ';
        $sql .= 'AND (m.PayTypeID LIKE ? ';  // $filter
        $sql .= 'OR m.PayTypeID IN ';
        $sql .= '( ';
        $sql .= 'SELECT PayTypeID FROM u_paytype ';
        $sql .= 'WHERE STATUS=\'1\' ';
        $sql .= 'AND PayTypeName LIKE ? '; // $filter
        $sql .= ') ';
        $sql .= ') ';
        $sql .= 'ORDER BY m.PayTypeName; ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $LanguageID, $filter1, $filter2);
            $LanguageID         = $lang;
            $filter1           = '%'.$filter.'%';
            $filter2           = '%'.$filter.'%';
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* u_creditlimit                                             */
/*--------------------------------------------------------*/
    // 同与信枠IDの件数を取得する
    public function gCreLimitIDSameCntVal($crelimitid) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT COUNT(*) AS cnt ';
        $sql .= 'FROM   u_creditlimit ';
        $sql .= 'WHERE  CreLimitID = ? ';    // $crelimitid
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $CreLimitID);
            $CreLimitID = $crelimitid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 与信枠情報を追加する
    public function iCreLimitInfo($crelimitid, $languageid, $crelimitname, $affiliatedflg, $crelimitamount, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO u_creditlimit(CreLimitID, LanguageID, CreLimitName, AffiliatedFlg, CreLimitAmount, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $crelimitid
        $sql .= ',? ';    // $languageid
		$sql .= ',? ';    // $crelimitname
		$sql .= ',? ';    // $affiliatedflg
		$sql .= ',? ';    // $crelimitamount
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssssss', $CreLimitID, $LanguageID, $CreLimitName, $AffiliatedFlg, $CreLimitAmount, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $CreLimitID   	= $crelimitid;
            $LanguageID   	= $languageid;
			$CreLimitName   = $crelimitname;
			$AffiliatedFlg  = $affiliatedflg;
			$CreLimitAmount = $crelimitamount;
            $EntDate      	= (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser      	= $userid;
            $UpdDate      	= (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser      	= $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 与信枠情報を取得する(全件)
    public function gCreLimitList($searchdate, $syear, $smonth, $sday, $eyear, $emonth, $eday, $searchText, $pageRowText, $pages, $lang, $blankflg) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sdate           = self::sSDate($searchdate, $syear, $smonth, $sday);    // 検索条件(開始日)
        $edate           = self::sEDate($searchdate, $eyear, $emonth, $eday);    // 検索条件(終了日)
        $array           = self::sLimit($pageRowText, $pages);                   // 検索条件(ページング)
        $offset          = $array[0];
        $limit           = $array[1];
        
        $sql  = 'SELECT CreLimitNo ';
        $sql .= '     , CreLimitID ';
		$sql .= '     , CreLimitName ';
		$sql .= '     , AffiliatedFlg ';
		$sql .= '     , CreLimitAmount ';
        $sql .= '     , EntDate ';
        $sql .= 'FROM   u_creditlimit ';
        $sql .= 'WHERE  LanguageID        = ? ';    // $lang
        $sql .= 'AND    EntDate          >= ? ';    // $sdate
        $sql .= 'AND    EntDate          <= ? ';    // $edate
        $sql .= 'AND    ( ';
        $sql .= '           CreLimitName LIKE ? ';    // '%'+$searchText+'%'
        $sql .= '       ) ';
        $sql .= 'AND    Status= true ';
        $sql .= 'ORDER BY CreLimitID ';
        $sql .= 'LIMIT ?, ? ';    // $offset, $limit
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssii', $LanguageID, $SEntDate, $EEntDate, $CreLimitName, $Offset, $Limit);
            $LanguageID   = $lang;
            $SEntDate     = $sdate;
            $EEntDate     = $edate;
            $CreLimitName = '%'.$searchText.'%';
            $Offset       = $offset;
            $Limit        = $limit;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 与信枠情報を取得する(一件用)
    public function gCreLimitRow($crelimitid, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT CreLimitNo ';
        $sql .= '     , CreLimitID ';
		$sql .= '     , CreLimitName ';
		$sql .= '     , AffiliatedFlg ';
		$sql .= '     , CreLimitAmount ';
        $sql .= 'FROM   u_creditlimit ';
        $sql .= 'WHERE  LanguageID = ? ';    // $lang
        $sql .= 'AND    CreLimitID = ? ';    // $crelimitid
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $LanguageID, $CreLimitID);
            $LanguageID = $lang;
            $CreLimitID = $crelimitid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 与信枠IDを取得する
    public function gCreLimitIDVal($crelimitno, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT CreLimitID ';
        $sql .= 'FROM   u_creditlimit ';
        $sql .= 'WHERE  LanguageID = ? ';    // $lang
        $sql .= 'AND    CreLimitNo = ? ';    // $crelimitno
        $sql .= 'AND    Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $LanguageID, $CreLimitNo);
            $LanguageID = $lang;
            $CreLimitNo = $crelimitno;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 与信枠情報を更新する
    public function uCreLimitInfo($crelimitidBef, $crelimitidAft, $crelimitname, $affiliatedflg, $crelimitamount, $lang, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_creditlimit ';
        $sql .= 'SET    CreLimitID   = ? ';    // $crelimitidAft
		$sql .= '    ,  CreLimitName = ? ';    // $crelimitname
		$sql .= '    ,  AffiliatedFlg    = ? ';    // $affiliatedflg
		$sql .= '    ,  CreLimitAmount   = ? ';    // $crelimitamount
        $sql .= '    ,  UpdDate      = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  UpdUser      = ? ';    // $userid
        $sql .= 'WHERE  CreLimitID   = ? ';    // $crelimitidBef
        $sql .= 'AND    LanguageID   = ? ';    // $lang
        $sql .= 'AND    Status       = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssss', $CreLimitIDa, $CreLimitName, $AffiliatedFlg, $CreLimitAmount, $UpdDate, $UpdUser, $CreLimitIDb, $LanguageID);
            $CreLimitIDa   	= $crelimitidAft;
			$CreLimitName   = $crelimitname;
			$AffiliatedFlg  = $affiliatedflg;
			$CreLimitAmount = $crelimitamount;
            $UpdDate      	= (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser      	= $userid;
            $CreLimitIDb   	= $crelimitidBef;
            $LanguageID   	= $lang;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 与信枠情報を削除する(対象は3言語)
    public function dCreLimitInfo($crelimitid, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE u_creditlimit ';
        $sql .= 'SET    Status     = false ';
        $sql .= '    ,  UpdDate    = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  UpdUser    = ? ';    // $userid
        $sql .= '    ,  DelDate    = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  DelUser    = ? ';    // $userid
        $sql .= 'WHERE  CreLimitID = ? ';    // $crelimitid
        $sql .= 'AND    Status   = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $CreLimitID);
            $UpdDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser    = $userid;
            $DelDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser    = $userid;
            $CreLimitID = $crelimitid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 与信枠名を絞り込む
    public function gCreLimitSearch($filter, $AffiliatedFlg, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_AffiliatedFlg = self::sDataFlg('m', $AffiliatedFlg, 'AffiliatedFlg');      // 検索条件(関係会社フラグ)        
        $sql  = 'SELECT m.CreLimitID, m.CreLimitName ';
        $sql .= ', m.AffiliatedFlg, m.CreLimitAmount ';
        $sql .= 'FROM u_creditlimit m ';
        $sql .= 'WHERE m.LanguageID = ? ';  // $lang
        $sql .= 'AND m.`Status`=\'1\' ';
        $sql .= 'AND (m.CreLimitID LIKE ? ';  // $filter
        $sql .= 'OR m.CreLimitID IN ';
        $sql .= '( ';
        $sql .= 'SELECT CreLimitID FROM u_creditlimit ';
        $sql .= 'WHERE STATUS=\'1\' ';
        $sql .= 'AND CreLimitName LIKE ? '; // $filter
        $sql .= ') ';
        $sql .= ') ';
        $sql .= $sql_AffiliatedFlg.' ';
        $sql .= 'ORDER BY m.CreLimitName; ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $LanguageID, $filter1, $filter2);
            $LanguageID        = $lang;
            $filter1           = '%'.$filter.'%';
            $filter2           = '%'.$filter.'%';
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }

/*--------------------------------------------------------*/
/* m_accountstitlel*m_accountstitlem*m_accountstitles     */
/*--------------------------------------------------------*/
    // 勘定科目情報を取得する(勘定科目一覧用)
    public function gAccLMSList($AccTitleID, $searchdate, $syear, $smonth, $sday, $eyear, $emonth, $eday, $searchText, $pageRowText, $pages, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_AccountsTitleID  = self::sArrAccTitleID('m_accountstitles', $AccTitleID);      // 検索条件(勘定科目)
        $sdate                = self::sSDate($searchdate, $syear, $smonth, $sday);          // 検索条件(開始日)
        $edate                = self::sEDate($searchdate, $eyear, $emonth, $eday);          // 検索条件(終了日)
        $array                = self::sLimit($pageRowText, $pages);                         // 検索条件(ページング)
        $offset               = $array[0];
        $limit                = $array[1];
        
        $sql  = 'SELECT m_accountstitles.AccountsTitleSNo AS AccountsTitleSNo ';
        $sql .= '     , m_accountstitles.AccountsTitleID AS AccountsTitleID ';
        $sql .= '     , m_accountstitles.AccountsTitleSName AS AccountsTitleSName ';
        $sql .= '     , m_accountstitles.SubLedgerFlg AS SubLedgerFlg ';
        $sql .= '     , m_accountstitles.ViceExpensesDmtFlg AS ViceExpensesDmtFlg ';
        $sql .= '     , m_accountstitles.ViceExpensesIntFlg AS ViceExpensesIntFlg ';
        $sql .= '     , m_accountskind_1.AccountsKind1ID ';
        $sql .= '     , m_accountskind_1.AccountsKind1Name ';
        $sql .= '     , m_accountskind_2.AccountsKind2ID ';
        $sql .= '     , m_accountskind_2.AccountsKind2Name ';
        $sql .= '     , m_accountskind_3.AccountsKind3ID ';
        $sql .= '     , m_accountskind_3.AccountsKind3Name ';
        $sql .= '     , m_accountskind_4.AccountsKind4ID ';
        $sql .= '     , m_accountskind_4.AccountsKind4Name ';
        $sql .= '     , m_accountskind_5.AccountsKind5ID ';
        $sql .= '     , m_accountskind_5.AccountsKind5Name ';
        $sql .= '     , m_accountskind_5.DrCrFlg ';
        $sql .= '     , m_accountstitles.EntDate AS EntDate ';
        $sql .= 'FROM   m_accountstitles ';
        $sql .= '     , m_accountskind_1 ';
        $sql .= '     , m_accountskind_2 ';
        $sql .= '     , m_accountskind_3 ';
        $sql .= '     , m_accountskind_4 ';
        $sql .= '     , m_accountskind_5 ';
        $sql .= 'WHERE  m_accountstitles.AccountsKind1ID  = m_accountskind_5.AccountsKind1ID ';
        $sql .= 'AND    m_accountstitles.AccountsKind2ID  = m_accountskind_5.AccountsKind2ID ';
        $sql .= 'AND    m_accountstitles.AccountsKind3ID  = m_accountskind_5.AccountsKind3ID ';
        $sql .= 'AND    m_accountstitles.AccountsKind4ID  = m_accountskind_5.AccountsKind4ID ';
        $sql .= 'AND    m_accountstitles.AccountsKind5ID  = m_accountskind_5.AccountsKind5ID ';
        $sql .= 'AND    m_accountskind_1.AccountsKind1ID  = m_accountskind_2.AccountsKind1ID ';
        $sql .= 'AND    m_accountskind_1.AccountsKind1ID  = m_accountskind_3.AccountsKind1ID ';
        $sql .= 'AND    m_accountskind_2.AccountsKind2ID  = m_accountskind_3.AccountsKind2ID ';
        $sql .= 'AND    m_accountskind_1.AccountsKind1ID  = m_accountskind_4.AccountsKind1ID ';
        $sql .= 'AND    m_accountskind_2.AccountsKind2ID  = m_accountskind_4.AccountsKind2ID ';
        $sql .= 'AND    m_accountskind_3.AccountsKind3ID  = m_accountskind_4.AccountsKind3ID ';
        $sql .= 'AND    m_accountskind_1.AccountsKind1ID  = m_accountskind_5.AccountsKind1ID ';
        $sql .= 'AND    m_accountskind_2.AccountsKind2ID  = m_accountskind_5.AccountsKind2ID ';
        $sql .= 'AND    m_accountskind_3.AccountsKind3ID  = m_accountskind_5.AccountsKind3ID ';
        $sql .= 'AND    m_accountskind_4.AccountsKind4ID  = m_accountskind_5.AccountsKind4ID ';
        $sql .= 'AND    m_accountstitles.LanguageID       = ? ';    // $lang
        $sql .= 'AND    m_accountskind_1.LanguageID       = ? ';    // $lang
        $sql .= 'AND    m_accountskind_2.LanguageID       = ? ';    // $lang
        $sql .= 'AND    m_accountskind_3.LanguageID       = ? ';    // $lang
        $sql .= 'AND    m_accountskind_4.LanguageID       = ? ';    // $lang
        $sql .= 'AND    m_accountskind_5.LanguageID       = ? ';    // $lang
        $sql .= 'AND    m_accountstitles.EntDate         >= ? ';    // $sdate
        $sql .= 'AND    m_accountstitles.EntDate         <= ? ';    // $edate
        $sql .= 'AND    m_accountstitles.Status           = true ';
        $sql .= 'AND    m_accountskind_1.Status           = true ';
        $sql .= 'AND    m_accountskind_2.Status           = true ';
        $sql .= 'AND    m_accountskind_3.Status           = true ';
        $sql .= 'AND    m_accountskind_4.Status           = true ';
        $sql .= 'AND    m_accountskind_5.Status           = true ';
        $sql .= 'AND    ( ';
        $sql .= '           m_accountstitles.AccountsTitleID    LIKE ? ';    // '%'+$searchText+'%'
        $sql .= '        OR m_accountstitles.AccountsTitleSName LIKE ? ';    // '%'+$searchText+'%'
        $sql .= '        OR m_accountskind_1.AccountsKind1Name  LIKE ? ';    // '%'+$searchText+'%'
        $sql .= '        OR m_accountskind_2.AccountsKind2Name  LIKE ? ';    // '%'+$searchText+'%'
        $sql .= '        OR m_accountskind_3.AccountsKind3Name  LIKE ? ';    // '%'+$searchText+'%'
        $sql .= '        OR m_accountskind_4.AccountsKind4Name  LIKE ? ';    // '%'+$searchText+'%'
        $sql .= '        OR m_accountskind_5.AccountsKind5Name  LIKE ? ';    // '%'+$searchText+'%'
        $sql .= '       ) ';
        $sql .= $sql_AccountsTitleID.' ';
        $sql .= 'ORDER BY m_accountstitles.AccountsTitleID ';
        $sql .= 'LIMIT ?, ? ';    // $offset, $limit
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssssssssssssii', $AccSLangID, $Acc1LangID, $Acc2LangID, $Acc3LangID, $Acc4LangID, $Acc5LangID, $SEntDate, $EEntDate, $AccID, $AccSName, $acc1Name, $Acc2Name, $Acc3Name, $Acc4Name, $Acc5Name, $Offset, $Limit);
            $AccSLangID = $lang;
            $Acc1LangID = $lang;
            $Acc2LangID = $lang;
            $Acc3LangID = $lang;
            $Acc4LangID = $lang;
            $Acc5LangID = $lang;
            $SEntDate   = $sdate;
            $EEntDate   = $edate;
            $AccID      = '%'.$searchText.'%';
            $AccSName   = '%'.$searchText.'%';
            $acc1Name   = '%'.$searchText.'%';
            $Acc2Name   = '%'.$searchText.'%';
            $Acc3Name   = '%'.$searchText.'%';
            $Acc4Name   = '%'.$searchText.'%';
            $Acc5Name   = '%'.$searchText.'%';
            $Offset     = $offset;
            $Limit      = $limit;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 勘定科目IDで勘定科目情報を取得する(一件用)
    public function gAccLMSRow($accid, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT m_accountstitles.AccountsTitleSNo AS AccountsTitleSNo ';
        $sql .= '     , m_accountstitles.AccountsTitleID AS AccountsTitleID ';
        $sql .= '     , m_accountstitles.AccountsTitleSName AS AccountsTitleSName ';
        $sql .= '     , m_accountstitles.AccountsKind1ID ';
        $sql .= '     , m_accountstitles.AccountsKind2ID ';
        $sql .= '     , m_accountstitles.AccountsKind3ID ';
        $sql .= '     , m_accountstitles.AccountsKind4ID ';
        $sql .= '     , m_accountstitles.AccountsKind5ID ';
        $sql .= '     , m_accountstitles.ControlAccountflg AS ControlAccountflg ';
        $sql .= '     , m_accountstitles.ControlAccountID AS ControlAccountID ';
        $sql .= '     , m_accountstitles.SubLedgerFlg AS SubLedgerFlg ';
        $sql .= '     , m_accountstitles.BOIflg AS BOIflg ';
        $sql .= '     , m_accountstitles.nonBOIflg AS nonBOIflg ';
        $sql .= '     , m_accountstitles.uncertainBOIflg AS uncertainBOIflg ';
        $sql .= '     , m_accountstitles.CashBankflg AS CashBankflg ';
        $sql .= '     , m_accountstitles.ARDmtflg AS ARDmtflg ';
        $sql .= '     , m_accountstitles.ARIntflg AS ARIntflg ';
        $sql .= '     , m_accountstitles.StockSalesflg AS StockSalesflg ';
        $sql .= '     , m_accountstitles.nonStockSalesflg AS nonStockSalesflg ';
        $sql .= '     , m_accountstitles.PurchaseStockflg AS PurchaseStockflg ';
        $sql .= '     , m_accountstitles.PurchasenonStockflg AS PurchasenonStockflg ';
        $sql .= '     , m_accountstitles.PurchaseServiceflg AS PurchaseServiceflg ';
        $sql .= '     , m_accountstitles.APDmtflg AS APDmtflg ';
        $sql .= '     , m_accountstitles.APIntflg AS APIntflg ';
        $sql .= '     , m_accountstitles.AccruedExpenseflg AS AccruedExpenseflg ';
        $sql .= '     , m_accountstitles.AROthersflg AS AROthersflg ';
        $sql .= '     , m_accountstitles.InputVATflg AS InputVATflg ';
        $sql .= '     , m_accountstitles.ServiceSalesflg AS ServiceSalesflg ';
        $sql .= '     , m_accountstitles.InputVATNotSubjectCorporateTaxDeductionflg AS InputVATNotSubjectCorporateTaxDeductionflg ';
        $sql .= '     , m_accountstitles.OutputVATflg AS OutputVATflg ';
        $sql .= '     , m_accountstitles.SuspenseInputVATflg AS SuspenseInputVATflg ';
        $sql .= '     , m_accountstitles.SuspenseOutputVATflg AS SuspenseOutputVATflg ';
        $sql .= '     , m_accountstitles.WithholdingTaxflg AS WithholdingTaxflg ';
        $sql .= '     , m_accountstitles.WithheldTaxflg AS WithheldTaxflg ';
        $sql .= '     , m_accountstitles.ImportDutyflg  AS ImportDutyflg  ';
        $sql .= '     , m_accountstitles.PayableCustomsflg  AS PayableCustomsflg  ';
        $sql .= '     , m_accountstitles.PayableRevDepflg  AS PayableRevDepflg  ';
        $sql .= '     , m_accountstitles.ExchangeGainflg AS ExchangeGainflg ';
        $sql .= '     , m_accountstitles.ExchangeLossflg  AS ExchangeLossflg  ';
        $sql .= '     , m_accountstitles.WHTType AS WHTType ';
        $sql .= '     , m_accountstitles.WHTType2 AS WHTType2 ';
        $sql .= '     , m_accountstitles.VATType AS VATType ';
        $sql .= '     , m_accountstitles.ClientID AS ClientID ';
        $sql .= '     , m_accountskind_5.DrCrFlg ';
        $sql .= 'FROM   m_accountstitles ';
        $sql .= 'LEFT JOIN m_accountskind_5 ';
        $sql .= 'ON     m_accountstitles.AccountsKind1ID  = m_accountskind_5.AccountsKind1ID ';
        $sql .= 'AND    m_accountstitles.AccountsKind2ID  = m_accountskind_5.AccountsKind2ID ';
        $sql .= 'AND    m_accountstitles.AccountsKind3ID  = m_accountskind_5.AccountsKind3ID ';
        $sql .= 'AND    m_accountstitles.AccountsKind4ID  = m_accountskind_5.AccountsKind4ID ';
        $sql .= 'AND    m_accountstitles.AccountsKind5ID  = m_accountskind_5.AccountsKind5ID ';
        $sql .= 'AND    m_accountstitles.LanguageID       = m_accountskind_5.LanguageID ';
        $sql .= 'WHERE  m_accountstitles.LanguageID       = ? ';    // $lang
        $sql .= 'AND    m_accountstitles.AccountsTitleID  = ? ';    // $accid
        $sql .= 'AND    m_accountstitles.Status           = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $AccLangID, $AccSTitleID);
            $AccLangID    = $lang;
            $AccSTitleID  = $accid;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* u_user*m_const                                         */
/*--------------------------------------------------------*/
    // ユーザ情報を取得する(ユーザ一覧用)
    public function gUserConstList($lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_Sub_auth  = '( ';
        $sql_Sub_auth .= '    SELECT ConstVal1, ConstID2 ';
        $sql_Sub_auth .= '    FROM   m_const ';
        $sql_Sub_auth .= '    WHERE  ConstID1   = ? ';    // $this->CL['DF']->AUTH
        $sql_Sub_auth .= '    AND    LanguageID = ? ';    // $lang
        $sql_Sub_auth .= '    AND    Status     = true ';
        $sql_Sub_auth .= ') AS Sub_auth ';
        
        $sql_Sub_lang  = '( ';
        $sql_Sub_lang .= '    SELECT ConstVal1, ConstID2 ';
        $sql_Sub_lang .= '    FROM   m_const ';
        $sql_Sub_lang .= '    WHERE  ConstID1   = ? ';    // $this->CL['DF']->LANG
        $sql_Sub_lang .= '    AND    LanguageID = ? ';    // $lang
        $sql_Sub_lang .= '    AND    Status     = true ';
        $sql_Sub_lang .= ') AS Sub_lang ';
        
        $sql  = 'SELECT u_user.UserNo AS UserNo ';
        $sql .= '     , u_user.UserID AS UserID ';
        $sql .= '     , Sub_auth.ConstVal1 AS AuthorityName ';
        $sql .= '     , Sub_lang.ConstVal1 AS LanguageName ';
        $sql .= '     , u_user.UserName AS UserName ';
        $sql .= '     , u_user.MailAddress AS MailAddress ';
        $sql .= '     , u_user.EntDate AS EntDate ';
        $sql .= 'FROM   u_user ';
        $sql .= '     , '.$sql_Sub_auth.' ';
        $sql .= '     , '.$sql_Sub_lang.' ';
        $sql .= 'WHERE  u_user.AuthorityID       = Sub_auth.ConstID2 ';
        $sql .= 'AND    u_user.DefaultLanguageID = Sub_lang.ConstID2 ';
        $sql .= 'AND    u_user.Status            = true ';
        $sql .= 'ORDER BY u_user.UserID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssss', $AuthConstID1, $AuthLanguageID, $LangConstID1, $LangLanguageID);
            $AuthConstID1   = $this->CL['DF']->AUTH;
            $AuthLanguageID = $lang;
            $LangConstID1   = $this->CL['DF']->LANG;
            $LangLanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // ユーザ情報を取得する(一件用)
    public function gUserConstRow($userno, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_Sub_auth  = '( ';
        $sql_Sub_auth .= '    SELECT ConstVal1, ConstID2 ';
        $sql_Sub_auth .= '    FROM   m_const ';
        $sql_Sub_auth .= '    WHERE  ConstID1   = ? ';    // $this->CL['DF']->AUTH
        $sql_Sub_auth .= '    AND    LanguageID = ? ';    // $lang
        $sql_Sub_auth .= '    AND    Status     = true ';
        $sql_Sub_auth .= ') AS Sub_auth ';
        
        $sql_Sub_lang  = '( ';
        $sql_Sub_lang .= '    SELECT ConstVal1, ConstID2 ';
        $sql_Sub_lang .= '    FROM   m_const ';
        $sql_Sub_lang .= '    WHERE  ConstID1   = ? ';    // $this->CL['DF']->LANG
        $sql_Sub_lang .= '    AND    LanguageID = ? ';    // $lang
        $sql_Sub_lang .= '    AND    Status     = true ';
        $sql_Sub_lang .= ') AS Sub_lang ';
        
        $sql  = 'SELECT u_user.UserNo AS UserNo ';
        $sql .= '     , u_user.UserID AS UserID ';
        $sql .= '     , Sub_auth.ConstVal1 AS AuthorityName ';
        $sql .= '     , Sub_auth.ConstID2 AS AuthorityID ';
        $sql .= '     , Sub_lang.ConstVal1 AS LanguageName ';
        $sql .= '     , u_user.UserName AS UserName ';
        $sql .= '     , u_user.DefaultLanguageID AS DefaultLanguageID ';
        $sql .= '     , u_user.PassWord AS PassWord ';
        $sql .= '     , u_user.MailAddress AS MailAddress ';
        $sql .= 'FROM   u_user ';
        $sql .= '     , '.$sql_Sub_auth.' ';
        $sql .= '     , '.$sql_Sub_lang.' ';
        $sql .= 'WHERE  u_user.AuthorityID       = Sub_auth.ConstID2 ';
        $sql .= 'AND    u_user.DefaultLanguageID = Sub_lang.ConstID2 ';
        $sql .= 'AND    u_user.UserNo            = ? ';    // $userno
        $sql .= 'AND    u_user.Status            = true ';
        $sql .= 'ORDER BY u_user.UserID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssss', $AuthConstID1, $AuthLanguageID, $LangConstID1, $LangLanguageID, $UserNo);
            $AuthConstID1   = $this->CL['DF']->AUTH;
            $AuthLanguageID = $lang;
            $LangConstID1   = $this->CL['DF']->LANG;
            $LangLanguageID = $lang;
            $UserNo         = $userno;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_transaction                                          */
/*--------------------------------------------------------*/
    // 取引を更新する
    public function uTrnInfo($TrnID, $TrnDate, $CltID, $Summary, $trnsts, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql_PostDate = self::sPostDate('t_transaction', $trnsts, $userid);    // 検索条件(処理日)
        $sql_PostUser = self::sPostUser('t_transaction', $trnsts, $userid);    // 検索条件(処理者)
        
        $sql  = 'UPDATE t_transaction ';
        $sql .= 'SET    TransactionDate     = ? ';    // $TrnDate
        $sql .= '     , ClientID            = ? ';    // $CltID
        $sql .= '     , Summary             = ? ';    // $Summary
        $sql .= '     , TransactionStatusID = ? ';    // $trnsts
        $sql .= $sql_PostDate.' ';
        $sql .= $sql_PostUser.' ';
        $sql .= 'WHERE  TransactionID       = ? ';    // $TrnID
        $sql .= 'AND    Status              = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssss', $TransactionDate, $ClientID, $Summary2, $TransactionStatusID, $TransactionID);
            $TransactionDate     = $TrnDate;
            $ClientID            = $CltID;
            $Summary2            = $Summary;
            $TransactionStatusID = $trnsts;
            $TransactionID       = $TrnID;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 取引ステータスを更新する(確定)
    public function uTrnStsConfirm($TrnKindID, $year, $month, $sts, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql_TrnKindID = self::sTrnKindID('t_transaction', $TrnKindID);    // 検索条件(取引種別)
        
        $sql  = 'UPDATE t_transaction ';
        $sql .= 'SET    TransactionStatusID              = ? ';    // $sts
        $sql .= '     , ConfirmDate                      = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , ConfirmUser                      = ? ';    // $userid
        $sql .= '     , UpdDate                          = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser                          = ? ';    // $userid
        $sql .= 'WHERE  SUBSTRING(TransactionDate, 1, 6) = ? ';    // $year+$month;
        $sql .= 'AND    Status                           = true ';
        $sql .= $sql_TrnKindID.' ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssss', $TransactionStatusID, $ConfirmDate, $ConfirmUser, $UpdDate, $UpdUser, $YM);
            $TransactionStatusID = $sts;
            $ConfirmDate         = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $ConfirmUser         = $userid;
            $UpdDate             = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser             = $userid;
            $YM                  = $year.str_pad($month, $this->CL['DF']->LenMonth, $this->CL['DF']->ZERO, STR_PAD_LEFT);
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 取引ステータスを更新する(承認済)
    public function uTrnStsApproved($TrnID, $sts, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE t_transaction ';
        $sql .= 'SET    TransactionStatusID = ? ';    // $sts
        $sql .= '     , ApproveDate         = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , ApproveUser         = ? ';    // $userid
        $sql .= '     , UpdDate             = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser             = ? ';    // $userid
        $sql .= 'WHERE  TransactionID       = ? ';    // $TrnKindID;
        $sql .= 'AND    Status              = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssss', $TransactionStatusID, $ApproveDate, $ApproveUser, $UpdDate, $UpdUser, $TransactionID);
            $TransactionStatusID = $sts;
            $ApproveDate         = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $ApproveUser         = $userid;
            $UpdDate             = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser             = $userid;
            $TransactionID       = $TrnID;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 取引ステータスを更新する(転記済)
    public function uTrnStsPosted($TrnID, $sts, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE t_transaction ';
        $sql .= 'SET    TransactionStatusID = ? ';    // $sts
        $sql .= '     , PostDate         = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , PostUser         = ? ';    // $userid
        $sql .= '     , UpdDate             = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser             = ? ';    // $userid
        $sql .= 'WHERE  TransactionID       = ? ';    // $TrnKindID;
        $sql .= 'AND    Status              = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssss', $TransactionStatusID, $PostDate, $PostUser, $UpdDate, $UpdUser, $TransactionID);
            $TransactionStatusID = $sts;
            $PostDate            = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $PostUser            = $userid;
            $UpdDate             = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser             = $userid;
            $TransactionID       = $TrnID;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 取引を追加する
    public function iTrnInfo($TrnID, $RevNo, $TrnDate, $CltID, $Summary, $userid, $JnlKindID, $trnstsID, $TrnKindID, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_transaction(TransactionID, RevisionNo, TransactionDate, ClientID, TransactionStatusID, Summary, JournalKindID, TransactionKindID, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $TrnID
        $sql .= ',? ';    // $RevNo
        $sql .= ',? ';    // $TrnDate
        $sql .= ',? ';    // $CltID
        $sql .= ',? ';    // $trnstsID
        $sql .= ',? ';    // $Summary
        $sql .= ',? ';    // $JnlKindID
        $sql .= ',? ';    // $TrnKindID
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true ) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssss', $TransactionID, $RevisionNo, $TransactionDate, $ClientID, $TransactionStatusID, $Summary2, $JournalKindID, $TransactionKindID, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $TransactionID       = $TrnID;
            $RevisionNo          = $RevNo;
            $TransactionDate     = $TrnDate;
            $ClientID            = $CltID;
            $TransactionStatusID = $trnstsID;
            $Summary2            = $Summary;
            $JournalKindID       = $JnlKindID;
            $TransactionKindID   = $TrnKindID;
            $EntDate             = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser             = $userid;
            $UpdDate             = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser             = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 取引を削除する
    public function dTrnInfo($TrnID, $RevNo, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE t_transaction ';
        $sql .= 'SET    Status        = false ';
        $sql .= '     , UpdDate       = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser       = ? ';    // $userid
        $sql .= '     , DelDate       = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , DelUser       = ? ';    // $userid
        $sql .= 'WHERE  TransactionID = ? ';    // $TrnID
        $sql .= 'AND    RevisionNo    = ? ';    // $RevNo
        $sql .= 'AND    Status        = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $TransactionID, $RevisionNo);
            $UpdDate       = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser       = $userid;
            $DelDate       = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser       = $userid;
            $TransactionID = $TrnID;
            $RevisionNo    = $RevNo;
             
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 最新の取引IDを取得する
    public function gTrnLatestIDVal($date) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT TransactionID ';
        $sql .= 'FROM   t_transaction ';
        $sql .= 'WHERE TransactionID LIKE ? ';    // $date+'-%'
        $sql .= 'ORDER BY TransactionID DESC ';
        $sql .= 'LIMIT 1 ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $TransactionID);
            $TransactionID = $date.'-%';
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 指定されたステータスの取引が存在する年月を取得する
    public function gYearMonthByTrnSts($min, $max) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT SUBSTRING(TransactionDate, 1, 4) AS Year ';
        $sql .= '     , SUBSTRING(TransactionDate, 5, 2) AS Month ';
        $sql .= 'FROM   t_transaction ';
        $sql .= 'WHERE  TransactionStatusID >= ? ';    // $MinStatus
        $sql .= 'AND    TransactionStatusID <= ? ';    // $MaxStatus
        $sql .= 'AND    Status              = true ';
        $sql .= 'GROUP BY Year, Month ';
        $sql .= 'ORDER BY Year desc, Month desc ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $MinStatus, $MaxStatus);
            $MinStatus = $min;
            $MaxStatus = $max;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 取引を取得する(1件)
    public function gTrnRow($TrnID) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT TransactionNo ';
        $sql .= '     , TransactionID ';
        $sql .= '     , RevisionNo ';
        $sql .= '     , TransactionDate ';
//        $sql .= '     , ClientID ';
        $sql .= '     , TransactionStatusID ';
        $sql .= '     , Summary ';
        $sql .= '     , JournalKindID ';
        $sql .= 'FROM   t_transaction ';
        $sql .= 'WHERE  t_transaction.TransactionID = ? ';    // $TrnID
        $sql .= 'AND    Status                      = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $TransactionID);
            $TransactionID = $TrnID;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 取引種別毎、取引ステータス毎の件数を取得する
    public function gTrnStsKindCntVal($trnstsID, $TrnKindID) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT COUNT(*) AS Cnt ';
        $sql .= 'FROM   t_transaction ';
        $sql .= 'WHERE  t_transaction.TransactionStatusID = ? ';    // $trnstsID
        $sql .= 'AND    t_transaction.TransactionKindID   = ? ';    // $TrnKindID
        $sql .= 'AND    Status                            = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $TransactionStatusID, $TransactionKindID);
            $TransactionStatusID = $trnstsID;
            $TransactionKindID   = $TrnKindID;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 殊仕訳帳用に取引を取得する(全件)
    public function gSpeJnlTrnList($TrnKindID, $sdate, $edate, $trnsts, $JnlKindID, $status, $lang, $pageRowText, $pages) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_TrnKindID = self::sArrTrnKindID('t_transaction', $TrnKindID);      // 検索条件(取引種別)
        $sql_JnlKindID = self::sArrJnlKindID('t_transaction', $JnlKindID);      // 検索条件(仕訳帳種別)
        $sql_TrnSts    = self::sArrTrnSts('t_transaction', $trnsts);            // 検索条件(取引ステータス)
//        $sql_Status    = self::sArrID('t_transaction', $status, 'Status');      // 検索条件(削除ステータス)
        $sql_Status    = self::sDataFlg('t_transaction', $status, 'Status');      // 検索条件(削除ステータス)
        $array         = self::sLimit($pageRowText, $pages);                    // 検索条件(ページング)
        $offset        = $array[0];
        $limit         = $array[1];
        
        $sql  = 'SELECT t_transaction.TransactionNo ';
        $sql .= '     , t_transaction.TransactionID ';
        $sql .= '     , t_transaction.RevisionNo ';
        $sql .= '     , t_transaction.TransactionDate ';
        $sql .= '     , t_transaction.ClientID ';
        $sql .= '     , t_transaction.TransactionStatusID ';
        $sql .= '     , m_const.ConstVal1 ';
        $sql .= '     , t_transaction.Summary ';
        $sql .= '     , t_transaction.JournalKindID ';
        $sql .= '     , t_transaction.TransactionKindID ';
        $sql .= '     , t_transaction.ConfirmDate ';
        $sql .= '     , t_transaction.ConfirmUser ';
        $sql .= '     , t_transaction.PostDate ';
        $sql .= '     , t_transaction.PostUser ';
        $sql .= '     , t_transaction.ApproveDate ';
        $sql .= '     , t_transaction.ApproveUser ';
        $sql .= '     , t_transaction.EntDate ';
        $sql .= '     , t_transaction.EntUser ';
        $sql .= '     , t_transaction.UpdDate ';
        $sql .= '     , t_transaction.UpdUser ';
        $sql .= '     , t_transaction.DelDate ';
        $sql .= '     , t_transaction.DelUser ';
        $sql .= '     , t_transaction.Status ';
        $sql .= 'FROM   t_transaction ';
        $sql .= 'LEFT JOIN m_const ';
        $sql .= 'ON  m_const.ConstID1 = ? ';        // $this->CL['DF']->TRNSTS
        $sql .= 'AND m_const.ConstID2 = t_transaction.TransactionStatusID ';
        $sql .= 'AND m_const.LanguageID = ? ';      // $lang
        $sql .= 'WHERE  t_transaction.TransactionDate >= ? ';     // $sdate
        $sql .= 'AND    t_transaction.TransactionDate <= ? ';     // $edate
        $sql .= $sql_TrnKindID.' ';
        $sql .= $sql_JnlKindID.' ';
        $sql .= $sql_TrnSts.' ';
        $sql .= $sql_Status.' ';
        $sql .= 'ORDER BY t_transaction.TransactionDate, t_transaction.TransactionKindID, t_transaction.TransactionID, t_transaction.RevisionNo ';
        $sql .= 'LIMIT ?, ? ';    // $offset, $limit
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssii', $ConstID1, $LanguageID, $SEntDate, $EEntDate, $Offset, $Limit);
            $ConstID1      = $this->CL['DF']->TRNSTS;
            $LanguageID    = $lang;
            $SEntDate      = $sdate;
            $EEntDate      = $edate;
            $Offset        = $offset;
            $Limit         = $limit;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }

    // 普通仕訳帳用に取引を取得する(全件)
    public function gGenJnlTrnList($TrnKindID, $sdate, $edate, $trnsts, $JnlKindID, $curid, $status, $lang, $pageRowText, $pages) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_TrnKindID = self::sArrTrnKindID('t_transaction', $TrnKindID);      // 検索条件(取引種別)
        $sql_JnlKindID = self::sArrJnlKindID('t_transaction', $JnlKindID);      // 検索条件(仕訳帳種別)
        $sql_TrnSts    = self::sArrTrnSts('t_transaction', $trnsts);            // 検索条件(取引ステータス)
//        $sql_Status    = self::sArrID('t_transaction', $status, 'Status');      // 検索条件(削除ステータス)
        $sql_Status    = self::sDataFlg('t_transaction', $status, 'Status');      // 検索条件(削除ステータス)
        $sql_CurID     = self::sDataFlg('t_generaljournal', $curid, 'CurrencyID');     // 検索条件(通貨ID)
        $array         = self::sLimit($pageRowText, $pages);                    // 検索条件(ページング)
        $offset        = $array[0];
        $limit         = $array[1];
        
        $sql  = 'SELECT distinct ';
        $sql .= '       t_transaction.TransactionNo ';
        $sql .= '     , t_transaction.TransactionID ';
        $sql .= '     , t_transaction.RevisionNo ';
        $sql .= '     , t_transaction.TransactionDate ';
        $sql .= '     , t_transaction.ClientID ';
        $sql .= '     , t_transaction.TransactionStatusID ';
        $sql .= '     , m_const.ConstVal1 ';
        $sql .= '     , t_transaction.Summary ';
        $sql .= '     , t_transaction.JournalKindID ';
        $sql .= '     , t_transaction.TransactionKindID ';
        $sql .= '     , t_transaction.ConfirmDate ';
        $sql .= '     , t_transaction.ConfirmUser ';
        $sql .= '     , t_transaction.PostDate ';
        $sql .= '     , t_transaction.PostUser ';
        $sql .= '     , t_transaction.ApproveDate ';
        $sql .= '     , t_transaction.ApproveUser ';
        $sql .= '     , t_transaction.EntDate ';
        $sql .= '     , t_transaction.EntUser ';
        $sql .= '     , t_transaction.UpdDate ';
        $sql .= '     , t_transaction.UpdUser ';
        $sql .= '     , t_transaction.DelDate ';
        $sql .= '     , t_transaction.DelUser ';
        $sql .= '     , t_transaction.Status ';
        $sql .= '     , t_generaljournal.CurrencyID ';
        $sql .= 'FROM   t_transaction ';
        $sql .= 'LEFT JOIN m_const ';
        $sql .= 'ON  m_const.ConstID1 = ? ';        // $this->CL['DF']->TRNSTS
        $sql .= 'AND m_const.ConstID2 = t_transaction.TransactionStatusID ';
        $sql .= 'AND m_const.LanguageID = ? ';      // $lang
        $sql .= 'LEFT JOIN t_generaljournal ';
        $sql .= 'ON  t_transaction.TransactionID = t_generaljournal.TransactionID ';
        $sql .= 'AND t_transaction.RevisionNo = t_generaljournal.RevisionNo ';
        $sql .= 'WHERE  t_transaction.TransactionDate >= ? ';     // $sdate
        $sql .= 'AND    t_transaction.TransactionDate <= ? ';     // $edate
        $sql .= $sql_TrnKindID.' ';
        $sql .= $sql_JnlKindID.' ';
        $sql .= $sql_TrnSts.' ';
        $sql .= $sql_CurID.' ';
        $sql .= $sql_Status.' ';
        $sql .= 'ORDER BY t_transaction.TransactionDate, t_transaction.TransactionKindID, t_transaction.TransactionID, t_transaction.RevisionNo ';
        $sql .= 'LIMIT ?, ? ';    // $offset, $limit
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssii', $ConstID1, $LanguageID, $SEntDate, $EEntDate, $Offset, $Limit);
            $ConstID1      = $this->CL['DF']->TRNSTS;
            $LanguageID    = $lang;
            $SEntDate      = $sdate;
            $EEntDate      = $edate;
            $Offset        = $offset;
            $Limit         = $limit;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }

/*--------------------------------------------------------*/
/* t_transaction*m_const*t_generaljournal                 */
/*--------------------------------------------------------*/
    // 取引を取得する(復数件)
    public function gTrnGenList($TrnID, $RevNo, $lang, $popSts = NULL) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_TrnSts = self::sPopSts('t_generaljournal', $popSts);    // 検索条件(仕訳ステータス)
        
        $sql_Sub_LineMax  = '( ';
        $sql_Sub_LineMax .= '    SELECT TransactionID , RevisionNo, MAX(Line) AS LineMax ';
        $sql_Sub_LineMax .= '    FROM t_generaljournal ';
        $sql_Sub_LineMax .= '    GROUP BY TransactionID, RevisionNo ';
        $sql_Sub_LineMax .= ') AS Sub_LineMax ';
        
        $sql_Sub_TrnSts  = '( ';
        $sql_Sub_TrnSts .= '    SELECT ConstVal1, ConstID2 ';
        $sql_Sub_TrnSts .= '    FROM   m_const ';
        $sql_Sub_TrnSts .= '    WHERE  ConstID1   = ? ';    // $this->CL['DF']->TRNSTS
        $sql_Sub_TrnSts .= '    AND    LanguageID = ? ';    // $lang
        $sql_Sub_TrnSts .= '    AND    Status     = true ';
        $sql_Sub_TrnSts .= ') AS Sub_TrnSts ';
        
        $sql  = 'SELECT t_transaction.TransactionNo AS TransactionNo ';
        $sql .= '     , t_transaction.TransactionID AS TransactionID ';
        $sql .= '     , t_transaction.RevisionNo AS RevisionNo ';
        $sql .= '     , t_transaction.TransactionDate AS TransactionDate ';
        $sql .= '     , t_transaction.TransactionStatusID AS TransactionStatusID ';
        $sql .= '     , t_transaction.Summary AS Summary ';
        $sql .= '     , t_transaction.EntDate  AS EntDate  ';
        $sql .= '     , Sub_TrnSts.ConstVal1 AS TransactionStatusName ';
        $sql .= '     , t_generaljournal.GeneralJournalNo AS GeneralJournalNo ';
        $sql .= '     , t_generaljournal.ClientID AS ClientID ';
        $sql .= '     , u_client.ClientName ';
        $sql .= '     , t_generaljournal.AccountsTitleID AS AccountsTitleID ';
        $sql .= '     , t_generaljournal.DrCrFlg AS DrCrFlg ';
        $sql .= '     , t_generaljournal.Amount AS Amount ';
        $sql .= '     , t_generaljournal.CurrencyID AS CurrencyID ';
        $sql .= '     , t_generaljournal.FxRate AS FxRate ';
        $sql .= '     , t_generaljournal.FxAmount AS FxAmount ';
        $sql .= '     , t_generaljournal.TaxableAmount AS TaxableAmount ';
        $sql .= '     , t_generaljournal.SegmentID AS SegmentID ';
        $sql .= '     , t_generaljournal.ControlNo AS ControlNo ';
        $sql .= '     , t_generaljournal.DueDate AS DueDate ';
        $sql .= '     , t_generaljournal.VATType AS VATType ';
        $sql .= '     , t_generaljournal.WHTType AS WHTType ';
        $sql .= '     , t_generaljournal.Status AS Status ';
        $sql .= '     , t_generaljournal.Line AS Line ';
        $sql .= '     , Sub_LineMax.LineMax AS LineMax ';
        $sql .= '     , u_user.UserName AS UpdUser ';
        $sql .= '     , m_accountstitles.CashBankflg AS CashBankflg ';
        $sql .= '     , m_accountstitles.ARDmtflg AS ARDmtflg ';
        $sql .= '     , m_accountstitles.ARIntflg AS ARIntflg ';
        $sql .= '     , m_accountstitles.StockSalesflg AS StockSalesflg ';
        $sql .= '     , m_accountstitles.nonStockSalesflg AS nonStockSalesflg ';
        $sql .= '     , m_accountstitles.PurchaseStockflg AS PurchaseStockflg ';
        $sql .= '     , m_accountstitles.PurchasenonStockflg AS PurchasenonStockflg ';
        $sql .= '     , m_accountstitles.PurchaseServiceflg AS PurchaseServiceflg ';
        $sql .= '     , m_accountstitles.APDmtflg AS APDmtflg ';
        $sql .= '     , m_accountstitles.APIntflg AS APIntflg ';
        $sql .= '     , m_accountstitles.AccruedExpenseflg AS AccruedExpenseflg ';
        $sql .= '     , m_accountstitles.AROthersflg AS AROthersflg ';
        $sql .= '     , m_accountstitles.InputVATflg AS InputVATflg ';
        $sql .= '     , m_accountstitles.ServiceSalesflg AS ServiceSalesflg ';
        $sql .= '     , m_accountstitles.InputVATNotSubjectCorporateTaxDeductionflg AS InputVATNotSubjectCorporateTaxDeductionflg ';
        $sql .= '     , m_accountstitles.OutputVATflg AS OutputVATflg ';
        $sql .= '     , m_accountstitles.SuspenseInputVATflg AS SuspenseInputVATflg ';
        $sql .= '     , m_accountstitles.SuspenseOutputVATflg AS SuspenseOutputVATflg ';
        $sql .= '     , m_accountstitles.WithholdingTaxflg AS WithholdingTaxflg ';
        $sql .= '     , m_accountstitles.WithheldTaxflg AS WithheldTaxflg ';
        $sql .= '     , m_accountstitles.ImportDutyflg AS ImportDutyflg ';
        $sql .= '     , m_accountstitles.PayableCustomsflg AS PayableCustomsflg ';
        $sql .= '     , m_accountstitles.PayableRevDepflg AS PayableRevDepflg ';
        $sql .= '     , m_accountstitles.ExchangeGainflg AS ExchangeGainflg ';
        $sql .= '     , m_accountstitles.ExchangeLossflg AS ExchangeLossflg ';
        $sql .= '     , m_accountstitles.WHTType AS WHTTypeAC ';
        $sql .= '     , m_accountstitles.WHTType2 AS WHTTypeAC2 ';
        $sql .= '     , m_accountstitles.VATType AS VATTypeAC ';
        $sql .= '     , m_accountstitles.AccountsTitleSName AS AccountsTitleSName ';
        $sql .= 'FROM   t_transaction ';
        $sql .= 'INNER JOIN  t_generaljournal ';
        $sql .= 'ON    t_transaction.TransactionID       = t_generaljournal.TransactionID ';
        $sql .= 'AND   t_transaction.RevisionNo          = t_generaljournal.RevisionNo ';
        $sql .= 'LEFT JOIN   m_accountstitles ';
        $sql .= 'ON    t_generaljournal.AccountsTitleID  = m_accountstitles.AccountsTitleID ';
        $sql .= 'AND   m_accountstitles.LanguageID       = ? ';    // $lang
        $sql .= 'LEFT JOIN   u_client ';
        $sql .= 'ON    t_generaljournal.ClientID         = u_client.ClientID ';
        $sql .= 'AND   u_client.LanguageID               = m_accountstitles.LanguageID ';
        $sql .= 'LEFT JOIN   u_user ';
        $sql .= 'ON    t_generaljournal.UpdUser          = u_user.UserID ';
        $sql .= 'LEFT JOIN   '.$sql_Sub_LineMax.' ';
        $sql .= 'ON    t_transaction.TransactionID       = Sub_LineMax.TransactionID ';
        $sql .= 'AND   t_transaction.RevisionNo          = Sub_LineMax.RevisionNo ';
        $sql .= 'LEFT JOIN   '.$sql_Sub_TrnSts.' ';
        $sql .= 'ON    t_transaction.TransactionStatusID = Sub_TrnSts.ConstID2 ';
        $sql .= 'WHERE t_transaction.TransactionID       = ? ';    // $TrnID
        $sql .= 'AND   t_transaction.RevisionNo          = ? ';    // $RevNo
//        $sql .= 'AND   t_transaction.Status              = true ';
        $sql .= $sql_TrnSts.' ';
        $sql .= 'ORDER BY t_generaljournal.Status DESC, t_generaljournal.Line ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssss', $LanguageID2, $ConstID1, $LanguageID, $TransactionID, $RevisionNo);
            $ConstID1      = $this->CL['DF']->TRNSTS;
            $LanguageID    = $lang;
            $TransactionID = $TrnID;
            $RevisionNo    = $RevNo;
            $LanguageID2   = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_transaction*m_const                                  */
/*--------------------------------------------------------*/
    // 仕訳帳名称を取得する
    public function gTrnJnlKindNameVal($TrnID, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_Sub_JnlKind  = '( ';
        $sql_Sub_JnlKind .= '    SELECT ConstVal1, ConstVal2, ConstID2 ';
        $sql_Sub_JnlKind .= '    FROM   m_const ';
        $sql_Sub_JnlKind .= '    WHERE  ConstID1   = ? ';    // $this->CL['DF']->JNLKIND
        $sql_Sub_JnlKind .= '    AND    LanguageID = ? ';    // $lang
        $sql_Sub_JnlKind .= '    AND    Status     = true ';
        $sql_Sub_JnlKind .= ') AS Sub_JnlKind ';
        
        $sql  = 'SELECT Sub_JnlKind.ConstVal1 AS JournalKindName ';
        $sql .= 'FROM   t_transaction ';
        $sql .= '     , '.$sql_Sub_JnlKind.' ';
        $sql .= 'WHERE  Sub_JnlKind.ConstID2        = t_transaction.JournalKindID ';
        $sql .= 'AND    t_transaction.TransactionID = ? ';    // $TrnID
        $sql .= 'AND    t_transaction.Status        = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $ConstID1, $LanguageID, $TransactionID);
            $ConstID1      = $this->CL['DF']->JNLKIND;
            $LanguageID    = $lang;
            $TransactionID = $TrnID;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 取引種別名称を取得する
    public function gTrnKindNameVal($TrnID, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_Sub_TrnKind  = '( ';
        $sql_Sub_TrnKind .= '    SELECT ConstVal1, ConstID2 ';
        $sql_Sub_TrnKind .= '    FROM   m_const ';
        $sql_Sub_TrnKind .= '    WHERE  ConstID1   = ? ';    // $this->CL['DF']->TRNKIND
        $sql_Sub_TrnKind .= '    AND    LanguageID = ? ';    // $lang
        $sql_Sub_TrnKind .= '    AND    Status     = true ';
        $sql_Sub_TrnKind .= ') AS Sub_TransactionKind ';
        
        $sql  = 'SELECT Sub_TransactionKind.ConstVal1 AS TransactionKindName ';
        $sql .= 'FROM   t_transaction ';
        $sql .= '     , '.$sql_Sub_TrnKind.' ';
        $sql .= 'WHERE  Sub_TransactionKind.ConstID2 = t_transaction.TransactionKindID ';
        $sql .= 'AND    t_transaction.TransactionID  = ? ';    // $TrnID
        $sql .= 'AND    t_transaction.Status         = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $ConstID1, $LanguageID, $TransactionID);
            $ConstID1      = $this->CL['DF']->TRNKIND;
            $LanguageID    = $lang;
            $TransactionID = $TrnID;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 取引ステータス毎の件数を取得する
    public function gTrnStsCntList($TrnKindID, $date, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_TrnKindID = self::sTrnKindID('t_transaction', $TrnKindID);    // 検索条件(取引種別)
        
        $sql_Sub_TrnSts  = '( ';
        $sql_Sub_TrnSts .= '    SELECT ConstVal1, ConstID2 ';
        $sql_Sub_TrnSts .= '    FROM   m_const ';
        $sql_Sub_TrnSts .= '    WHERE  ConstID1   = ? ';    // $this->CL['DF']->TRNSTS
        $sql_Sub_TrnSts .= '    AND    LanguageID = ? ';    // $lang
        $sql_Sub_TrnSts .= '    AND    Status     = true ';
        $sql_Sub_TrnSts .= ') AS Sub_TrnSts ';
        
        $sql  = 'SELECT t_transaction.TransactionStatusID AS TransactionStatusID ';
        $sql .= '     , Sub_TrnSts.ConstVal1 AS TransactionStatusName ';
        $sql .= '     , COUNT(*) AS Count ';
        $sql .= 'FROM   t_transaction ';
        $sql .= '     , '.$sql_Sub_TrnSts.' ';
        $sql .= 'WHERE  t_transaction.TransactionStatusID = Sub_TrnSts.ConstID2 ';
        $sql .= 'AND    t_transaction.TransactionDate LIKE  ? ';    // $date+'%';
        $sql .= 'AND    t_transaction.Status              = true ';
        $sql .= $sql_TrnKindID.' ';
// ticket 0001856 start
//        $sql .= 'GROUP BY TransactionStatusID; ';
        $sql .= 'GROUP BY t_transaction.TransactionStatusID,Sub_TrnSts.ConstVal1 ; ';
// ticket 0001856 end

        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $ConstID1, $LanguageID, $TranDate);
            $ConstID1   = $this->CL['DF']->TRNSTS;
            $LanguageID = $lang;
            $TranDate   = $date.'%';

            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* 仕訳DB(引数で指定)                                     */
/*--------------------------------------------------------*/
    // 取引毎の合計金額を取得する
    public function gTrnDrCrAmtRow($TrnID, $TableName) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        $TableName = 't_commonjournal';
        
        $sql_Sub_Dr  = '( ';
        $sql_Sub_Dr .= '    SELECT TransactionID, SUM(Amount) AS DrAmount ';
        $sql_Sub_Dr .= '    FROM '.$TableName.' ';
        $sql_Sub_Dr .= '    WHERE  DrCrFlg = ? ';    // $this->CL['DF']->Dr
        $sql_Sub_Dr .= '    AND    Status  = true ';
        $sql_Sub_Dr .= '    GROUP BY TransactionID ';
        $sql_Sub_Dr .= ') AS Sub_Dr ';
        
        $sql_Sub_Cr  = '( ';
        $sql_Sub_Cr .= '    SELECT TransactionID, SUM(Amount) AS CrAmount ';
        $sql_Sub_Cr .= '    FROM '.$TableName.' ';
        $sql_Sub_Cr .= '    WHERE  DrCrFlg = ? ';    // $this->CL['DF']->Cr
        $sql_Sub_Cr .= '    AND    Status  = true ';
        $sql_Sub_Cr .= '    GROUP BY TransactionID ';
        $sql_Sub_Cr .= ') AS Sub_Cr ';
        
        $sql  = 'SELECT Sub_Dr.DrAmount AS DrAmount ';
        $sql .= '     , Sub_Cr.CrAmount AS CrAmount ';
        $sql .= 'FROM   '.$TableName.' ';
        $sql .= '     , '.$sql_Sub_Dr.' ';
        $sql .= '     , '.$sql_Sub_Cr.' ';
        $sql .= 'WHERE  Sub_Dr.TransactionID = Sub_Cr.TransactionID ';
        $sql .= 'AND    '.$TableName.'.TransactionID = Sub_Dr.TransactionID ';
        $sql .= 'AND    '.$TableName.'.TransactionID = Sub_Cr.TransactionID ';
        $sql .= 'AND    '.$TableName.'.TransactionID = ? ';    // $TrnID
        $sql .= 'AND    '.$TableName.'.Status        = true ';
// ticket 0001856 start
//        $sql .= 'GROUP BY '.$TableName.'.TransactionID ';
        $sql .= 'ORDER BY '.$TableName.'.TransactionID ';
// ticket 0001856 end
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $DrDrCrFlg, $CrDrCrFlg, $TransactionID);
            $DrDrCrFlg     = $this->CL['DF']->Dr;
            $CrDrCrFlg     = $this->CL['DF']->Cr;
            $TransactionID = $TrnID;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_transaction*u_client*m_const                         */
/*--------------------------------------------------------*/
    // 取引を取得する(全件)
    public function gTrnList($TrnKindID, $searchdate, $syear, $smonth, $sday, $eyear, $emonth, $eday, $cltid, $trnsts, $JnlKindID, $pageRowText, $pages, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_TrnKindID = self::sArrTrnKindID('t_transaction', $TrnKindID);      // 検索条件(取引種別)
        $sql_JnlKindID = self::sArrJnlKindID('t_transaction', $JnlKindID);      // 検索条件(仕訳帳種別)
        $sql_CltID     = self::sArrCltID('t_transaction', $cltid);              // 検索条件(取引先)
        $sql_TrnSts    = self::sArrTrnSts('t_transaction', $trnsts);            // 検索条件(取引ステータス)
        $sdate         = self::sSDate2($searchdate, $syear, $smonth, $sday);    // 検索条件(開始日)
        $edate         = self::sEDate2($searchdate, $eyear, $emonth, $eday);    // 検索条件(終了日)
        $array         = self::sLimit($pageRowText, $pages);                    // 検索条件(ページング)
        $offset        = $array[0];
        $limit         = $array[1];
        
        $sql_Sub_TrnSts  = '( ';
        $sql_Sub_TrnSts .= '    SELECT ConstVal1, ConstID2 ';
        $sql_Sub_TrnSts .= '    FROM   m_const ';
        $sql_Sub_TrnSts .= '    WHERE  ConstID1   = ? ';    // $this->CL['DF']->TRNSTS
        $sql_Sub_TrnSts .= '    AND    LanguageID = ? ';    // $lang
        $sql_Sub_TrnSts .= '    AND    Status     = true ';
        $sql_Sub_TrnSts .= ') AS Sub_TrnSts ';
        
        $sql_Sub_JnlKind  = '( ';
        $sql_Sub_JnlKind .= '    SELECT ConstVal1, ConstVal2, ConstID2 ';
        $sql_Sub_JnlKind .= '    FROM   m_const ';
        $sql_Sub_JnlKind .= '    WHERE  ConstID1   = ? ';    // $this->CL['DF']->JNLKIND
        $sql_Sub_JnlKind .= '    AND    LanguageID = ? ';    // $lang
        $sql_Sub_JnlKind .= '    AND    Status     = true ';
        $sql_Sub_JnlKind .= ') AS Sub_JnlKind ';
        
        $sql_Sub_TrnKind  = '( ';
        $sql_Sub_TrnKind .= '    SELECT ConstVal1, ConstID2 ';
        $sql_Sub_TrnKind .= '    FROM   m_const ';
        $sql_Sub_TrnKind .= '    WHERE  ConstID1   = ? ';    // $this->CL['DF']->JNLKIND
        $sql_Sub_TrnKind .= '    AND    LanguageID = ? ';    // $lang
        $sql_Sub_TrnKind .= '    AND    Status     = true ';
        $sql_Sub_TrnKind .= ') AS Sub_TransactionKind ';
        
        $sql  = 'SELECT t_transaction.TransactionNo AS TransactionNo ';
        $sql .= '     , t_transaction.TransactionID AS TransactionID ';
        $sql .= '     , t_transaction.TransactionDate AS TransactionDate ';
//        $sql .= '     , t_transaction.ClientID AS ClientID ';
        $sql .= '     , t_transaction.TransactionStatusID AS TransactionStatusID ';
        $sql .= '     , t_transaction.Summary AS Summary ';
        $sql .= '     , t_transaction.ConfirmDate AS ConfirmDate ';
        $sql .= '     , t_transaction.ConfirmUser AS ConfirmUser ';
        $sql .= '     , t_transaction.PostDate AS PostDate ';
        $sql .= '     , t_transaction.PostUser AS PostUser ';
        $sql .= '     , t_transaction.ApproveDate AS ApproveDate ';
        $sql .= '     , t_transaction.ApproveUser AS ApproveUser ';
        $sql .= '     , t_transaction.EntDate AS EntDate ';
        $sql .= '     , t_transaction.EntUser AS EntUser ';
//        $sql .= '     , u_client.ClientName AS ClientName ';
        $sql .= '     , Sub_TrnSts.ConstVal1 AS TransactionStatusName ';
        $sql .= '     , Sub_JnlKind.ConstVal2 AS TableName ';
        $sql .= '     , t_transaction.JournalKindID AS JournalKindID ';
        $sql .= '     , u_user.UserName AS UserName ';
        $sql .= '     , Sub_JnlKind.ConstVal1 AS JournalKindName ';
        $sql .= '     , Sub_TransactionKind.ConstVal1 AS TransactionKindName ';
        $sql .= 'FROM   t_transaction ';
//        $sql .= '     , u_client ';
        $sql .= '     , u_user ';
        $sql .= '     , '.$sql_Sub_TrnSts.' ';
        $sql .= '     , '.$sql_Sub_JnlKind.' ';
        $sql .= '     , '.$sql_Sub_TrnKind.' ';
//        $sql .= 'WHERE  t_transaction.ClientID            = u_client.ClientID ';
        $sql .= 'WHERE  t_transaction.TransactionStatusID = Sub_TrnSts.ConstID2 ';
        $sql .= 'AND    Sub_JnlKind.ConstID2              = t_transaction.JournalKindID ';
        $sql .= 'AND    Sub_TransactionKind.ConstID2      = t_transaction.TransactionKindID ';
        $sql .= 'AND    t_transaction.EntUser             = u_user.UserID ';
//        $sql .= 'AND    u_client.LanguageID               = ? ';    // $lang
        $sql .= 'AND    t_transaction.TransactionDate    >= ? ';    // $sdate
        $sql .= 'AND    t_transaction.TransactionDate    <= ? ';    // $edate
        $sql .= 'AND    t_transaction.Status              = true ';
        $sql .= $sql_TrnKindID.' ';
        $sql .= $sql_JnlKindID.' ';
        $sql .= $sql_CltID.' ';
        $sql .= $sql_TrnSts.' ';
        $sql .= 'ORDER BY SUBSTRING(t_transaction.TransactionDate, 1, 6), t_transaction.TransactionKindID, t_transaction.TransactionID ';
        $sql .= 'LIMIT ?, ? ';    // $offset, $limit
        
        if ($stmt = $mysqli->prepare($sql)) {
//            $stmt->bind_param('sssssssssii', $TrnStsConstID1, $TrnStsLanguageID, $JnlKindConstID1, $JnlKindLanguageID, $TrnKindConstID1, $TrnKindLanguageID, $CltLanguageID, $SEntDate, $EEntDate, $Offset, $Limit);
            $stmt->bind_param('ssssssssii', $TrnStsConstID1, $TrnStsLanguageID, $JnlKindConstID1, $JnlKindLanguageID, $TrnKindConstID1, $TrnKindLanguageID, $SEntDate, $EEntDate, $Offset, $Limit);
            $TrnStsConstID1    = $this->CL['DF']->TRNSTS;
            $TrnStsLanguageID  = $lang;
            $JnlKindConstID1   = $this->CL['DF']->JNLKIND;
            $JnlKindLanguageID = $lang;
            $TrnKindConstID1   = $this->CL['DF']->TRNKIND;
            $TrnKindLanguageID = $lang;
//            $CltLanguageID     = $lang;
            $SEntDate          = $sdate;
            $EEntDate          = $edate;
            $Offset            = $offset;
            $Limit             = $limit;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_generaljournal*m_accountstitles                      */
/*--------------------------------------------------------*/
    // 普通仕訳帳を取得する
    public function gGenList($TrnKindID, $year, $month) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_TrnKindID = self::sTrnKindID('t_transaction', $TrnKindID);    // 検索条件(取引種別)
        
        $sql_Sub_Dr  = '( ';
        $sql_Sub_Dr .= '    SELECT SUM(t_generaljournal.Amount) AS DrAmount ';
        $sql_Sub_Dr .= '    FROM   t_generaljournal, t_transaction ';
        $sql_Sub_Dr .= '    WHERE  t_transaction.TransactionID                    = t_generaljournal.TransactionID ';
        $sql_Sub_Dr .= '    AND    t_transaction.RevisionNo                       = t_generaljournal.RevisionNo ';
        $sql_Sub_Dr .= '    AND    DrCrFlg                                        = ? ';    // $this->CL['DF']->Dr
        $sql_Sub_Dr .= '    AND    SUBSTRING(t_transaction.TransactionDate, 1, 6) = ? ';    // $year.str_pad($month, $this->CL['DF']->LenMonth, $this->CL['DF']->ZERO, STR_PAD_LEFT)
        $sql_Sub_Dr .= '    AND    t_transaction.Status                           = true ';
        $sql_Sub_Dr .= '    AND    t_generaljournal.Status                        = true ';
        $sql_Sub_Dr .= '    '.$sql_TrnKindID.' ';
        $sql_Sub_Dr .= '    GROUP BY t_generaljournal.AccountsTitleID ';
        $sql_Sub_Dr .= ') AS Sub_Dr ON ((t_generaljournal.AccountsTitleID = Sub_Dr.AccountsTitleID) ';
        
        $sql_Sub_Cr  = '( ';
        $sql_Sub_Cr .= '    SELECT t_generaljournal.AccountsTitleID, SUM(t_generaljournal.Amount) AS CrAmount ';
        $sql_Sub_Cr .= '    FROM   t_generaljournal, t_transaction ';
        $sql_Sub_Cr .= '    WHERE  t_transaction.TransactionID                    = t_generaljournal.TransactionID ';
        $sql_Sub_Cr .= '    AND    t_transaction.RevisionNo                       = t_generaljournal.RevisionNo ';
        $sql_Sub_Cr .= '    AND    DrCrFlg                                        = ? ';    // $this->CL['DF']->Cr
        $sql_Sub_Cr .= '    AND    SUBSTRING(t_transaction.TransactionDate, 1, 6) = ? ';    // $year.str_pad($month, $this->CL['DF']->LenMonth, $this->CL['DF']->ZERO, STR_PAD_LEFT)
        $sql_Sub_Cr .= '    AND    t_transaction.Status                           = true ';
        $sql_Sub_Cr .= '    AND    t_generaljournal.Status                        = true ';
        $sql_Sub_Cr .= '    '.$sql_TrnKindID.' ';
        $sql_Sub_Cr .= '    GROUP BY t_generaljournal.AccountsTitleID ';
        $sql_Sub_Cr .= ') AS Sub_Cr ON ((t_generaljournal.AccountsTitleID = Sub_Cr.AccountsTitleID) ';
        
        $sql  = 'SELECT t_generaljournal.AccountsTitleID ';
        $sql .= '     , m_accountstitles.AccountsKind1ID ';
        $sql .= '     , m_accountstitles.AccountsKind2ID ';
        $sql .= '     , m_accountstitles.AccountsKind3ID ';
        $sql .= '     , m_accountstitles.AccountsKind4ID ';
        $sql .= '     , m_accountstitles.AccountsKind5ID ';
        $sql .= '     , IFNULL(Sub_Dr.DrAmount, 0) AS DrAmount ';
        $sql .= '     , IFNULL(Sub_Cr.CrAmount, 0) AS CrAmount ';
        $sql .= '     , (IFNULL(Sub_Dr.DrAmount, 0)-IFNULL(Sub_Cr.CrAmount, 0)) AS Total ';
        $sql .= 'FROM   m_accountstitles ';
        $sql .= '     , t_transaction ';
        $sql .= '     , t_generaljournal ';
        $sql .= '           LEFT OUTER JOIN '.$sql_Sub_Dr.' ';
        $sql .= '           LEFT OUTER JOIN '.$sql_Sub_Cr.' ';
        $sql .= 'WHERE  t_generaljournal.AccountsTitleID               = m_accountstitles.AccountsTitleID ';
        $sql .= 'AND    t_generaljournal.TransactionID                 = t_transaction.TransactionID ';
        $sql .= 'AND    t_generaljournal.RevisionNo                    = t_transaction.RevisionNo ';
        $sql .= 'AND    SUBSTRING(t_transaction.TransactionDate, 1, 6) = ? ';    // $year.str_pad($month, $this->CL['DF']->LenMonth, $this->CL['DF']->ZERO, STR_PAD_LEFT)
        $sql .= 'AND    t_transaction.Status                           = true ';
        $sql .= 'AND    t_generaljournal.Status                        = true ';
        $sql .= 'AND    m_accountstitles.Status                        = true ';
        $sql .= 'ORDER BY t_generaljournal.AccountsTitleID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssss', $DrDrCrFlg, $DrYM, $CrDrCrFlg, $CrYM, $TrnYM);
            $DrDrCrFlg = $this->CL['DF']->Dr;
            $DrYM      = $year.str_pad($month, $this->CL['DF']->LenMonth, $this->CL['DF']->ZERO, STR_PAD_LEFT);
            $CrDrCrFlg = $this->CL['DF']->Cr;
            $CrYM      = $year.str_pad($month, $this->CL['DF']->LenMonth, $this->CL['DF']->ZERO, STR_PAD_LEFT);
            $TrnYM     = $year.str_pad($month, $this->CL['DF']->LenMonth, $this->CL['DF']->ZERO, STR_PAD_LEFT);
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_generaljournal                                       */
/*--------------------------------------------------------*/
    // 普通仕訳帳を追加する
    public function iGenJnlInfo($TrnID, $Rev, $Line, $Client, $AccTitleID, $DrCrFlg, $Amt, $pCurrencyID, $pFxRate, $pFxAmount, $pTaxableAmount, $pSegmentID, $CtrlNo, $Due, $pVATType, $pWHTType, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_generaljournal(TransactionID, RevisionNo, Line, ClientID, AccountsTitleID, DrCrFlg, Amount, CurrencyID, FxRate, FxAmount, TaxableAmount, SegmentID, ControlNo, DueDate, VATType, WHTType, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $TrnID
        $sql .= ',? ';    // $Rev
        $sql .= ',? ';    // $Line
        $sql .= ',? ';    // $Client
        $sql .= ',? ';    // $AccTitleID
        $sql .= ',? ';    // $DrCrFlg
        $sql .= ',? ';    // $Amt
        $sql .= ',? ';    // $pCurrencyID
        $sql .= ',? ';    // $pFxRate
        $sql .= ',? ';    // $pFxAmount
        $sql .= ',? ';    // $pTaxableAmount
        $sql .= ',? ';    // $pSegmentID
        $sql .= ',? ';    // $CtrlNo
        $sql .= ',? ';    // $Due
        $sql .= ',? ';    // $pVATType
        $sql .= ',? ';    // $pWHTType
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true ) ';  
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssssssssssss', $TransactionID, $RevisionNo, $Line, $ClientID, $AccountsTitleID, $DrCrFlg, $Amount, $CurrencyID, $FxRate, $FxAmount, $TaxableAmount, $SegmentID, $ControlNo, $DueDate, $VATType, $WHTType, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $TransactionID    = $TrnID;
            $RevisionNo       = $Rev;
            $Line             = $Line;
            $ClientID         = $Client;
            $AccountsTitleID  = $AccTitleID;
            $DrCrFlg          = $DrCrFlg;
            $Amount           = $Amt;
            $CurrencyID       = $pCurrencyID;
            $FxRate           = $pFxRate;
            $FxAmount         = $pFxAmount;
            $TaxableAmount    = $pTaxableAmount;
            $SegmentID        = $pSegmentID;
            $ControlNo        = $CtrlNo;
            $DueDate          = $Due;
            $VATType          = $pVATType;
            $WHTType          = $pWHTType;
            $EntDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser          = $userid;
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 普通仕訳帳を削除する
    public function dGenJnlInfo($TrnID, $RevNo, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE t_generaljournal ';
        $sql .= 'SET    Status        = false ';
        $sql .= '     , UpdDate       = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser       = ? ';    // $userid
        $sql .= '     , DelDate       = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , DelUser       = ? ';    // $userid
        $sql .= 'WHERE  TransactionID = ? ';    // $TrnID
        $sql .= 'AND    RevisionNo    = ? ';    // $RevNo
        $sql .= 'AND    Status        = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $TransactionID, $RevisionNo);
            $UpdDate       = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser       = $userid;
            $DelDate       = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser       = $userid;
            $TransactionID = $TrnID;
            $RevisionNo    = $RevNo;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 取引明細数を取得する
    public function gTrnLineMaxVal($TrnID) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT MAX(Line) AS LineMax ';
        $sql .= 'FROM   t_generaljournal ';
        $sql .= 'WHERE  TransactionID = ? ';    // $TrnID
        $sql .= 'AND    Status        = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $TransactionID);
            $TransactionID = $TrnID;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 指定取引IDの総勘定元帳上の明細行数を取得する
    public function gGenNumVal($TrnID) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  =   'SET @ROW_NUM = 0; ';
        $result = $mysqli->query($sql);
        
        $sql_Sub_rownum  = '( ';
        $sql_Sub_rownum .= '    SELECT (@ROW_NUM:= @ROW_NUM+1) AS ROW_NUMBER, TransactionID ';
        $sql_Sub_rownum .= '    FROM   t_generaljournal ';
// ticket 0001856 start
//        $sql_Sub_rownum .= '    GROUP BY TransactionID ';
// ticket 0001856 end
        $sql_Sub_rownum .= '    ORDER BY TransactionID, Line, UpdDate ';
        $sql_Sub_rownum .= ') AS Sub_rownum ';
        
        $sql  = 'SELECT ROW_NUMBER ';
        $sql .= 'FROM  '.$sql_Sub_rownum.' ';
        $sql .= 'WHERE  TransactionID = ? ';    // $TrnID
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $TransactionID);
            $TransactionID = $TrnID;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // プライマリキーから行番号を取得する
    public function gTrnLineVal($No, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'SELECT Line AS Line ';
        $sql .= 'FROM   t_generaljournal ';
        $sql .= 'WHERE  GeneralJournalNo = ? ';    // $No
        $sql .= 'AND    Status           = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $GeneralJournalNo);
            $GeneralJournalNo = $No;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_commonjournal                                        */
/*--------------------------------------------------------*/
    // 共通仕訳帳を追加する
    public function iCmnJnlInfo($TrnID, $Line, $Client, $AccTitleID, $DrCrFlg, $Amt, $pCurrencyID, $pFxRate, $pFxAmount, $pTaxableAmount, $pSegmentID, $CtrlNo, $Due, $pVATType, $pWHTType, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_commonjournal(TransactionID, Line, ClientID, AccountsTitleID, DrCrFlg, Amount, CurrencyID, FxRate, FxAmount, TaxableAmount, SegmentID, ControlNo, DueDate, VATType, WHTType, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $TrnID
        $sql .= ',? ';    // $Line
        $sql .= ',? ';    // $Client
        $sql .= ',? ';    // $AccTitleID
        $sql .= ',? ';    // $DrCrFlg
        $sql .= ',? ';    // $Amt
        $sql .= ',? ';    // $pCurrencyID
        $sql .= ',? ';    // $pFxRate
        $sql .= ',? ';    // $pFxAmount
        $sql .= ',? ';    // $pTaxableAmount
        $sql .= ',? ';    // $pSegmentID
        $sql .= ',? ';    // $CtrlNo
        $sql .= ',? ';    // $Due
        $sql .= ',? ';    // $pVATType
        $sql .= ',? ';    // $pWHTType
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true ) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssssssssssssssss', $TransactionID, $Line, $ClientID, $AccountsTitleID, $DrCrFlg, $Amount, $CurrencyID, $FxRate, $FxAmount, $TaxableAmount, $SegmentID, $ControlNo, $DueDate, $VATType, $WHTType, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $TransactionID    = $TrnID;
            $Line             = $Line;
            $ClientID         = $Client;
            $AccountsTitleID  = $AccTitleID;
            $DrCrFlg          = $DrCrFlg;
            $Amount           = $Amt;
            $CurrencyID       = $pCurrencyID;
            $FxRate           = $pFxRate;
            $FxAmount         = $pFxAmount;
            $TaxableAmount    = $pTaxableAmount;
            $SegmentID        = $pSegmentID;
            $ControlNo        = $CtrlNo;
            $DueDate          = $Due;
            $VATType          = $pVATType;
            $WHTType          = $pWHTType;
            $EntDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser          = $userid;
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 共通仕訳帳を削除する
    public function dCmnJnlInfo($TrnID, $Line, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE t_commonjournal ';
        $sql .= 'SET    Status        = false ';
        $sql .= '     , UpdDate       = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser       = ? ';    // $userid
        $sql .= '     , DelDate       = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , DelUser       = ? ';    // $userid
        $sql .= 'WHERE  TransactionID = ? ';    // $TrnID
        $sql .= 'AND    Line          = ? ';    // $Line
        $sql .= 'AND    Status        = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $TransactionID, $LineNo);
            $UpdDate       = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser       = $userid;
            $DelDate       = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser       = $userid;
            $TransactionID = $TrnID;
            $LineNo        = $Line;
             
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
/*--------------------------------------------------------*/
/* t_transaction*m_const*t_commonjournal                  */
/*--------------------------------------------------------*/
    // 取引を取得する(復数件)
    public function gTrnComList($TrnID, $lang, $popSts = NULL) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_TrnSts = self::sPopSts('t_commonjournal', $popSts);    // 検索条件(仕訳ステータス)
        
        $sql_Sub_LineMax  = '( ';
        $sql_Sub_LineMax .= '    SELECT TransactionID , MAX(Line) AS LineMax ';
        $sql_Sub_LineMax .= '    FROM t_commonjournal ';
        $sql_Sub_LineMax .= '    GROUP BY TransactionID ';
        $sql_Sub_LineMax .= ') AS Sub_LineMax ';
        
        $sql_Sub_TrnSts  = '( ';
        $sql_Sub_TrnSts .= '    SELECT ConstVal1, ConstID2 ';
        $sql_Sub_TrnSts .= '    FROM   m_const ';
        $sql_Sub_TrnSts .= '    WHERE  ConstID1   = ? ';    // $this->CL['DF']->TRNSTS
        $sql_Sub_TrnSts .= '    AND    LanguageID = ? ';    // $lang
        $sql_Sub_TrnSts .= '    AND    Status     = true ';
        $sql_Sub_TrnSts .= ') AS Sub_TrnSts ';
        
        $sql  = 'SELECT t_transaction.TransactionNo AS TransactionNo ';
        $sql .= '     , t_transaction.TransactionID AS TransactionID ';
        $sql .= '     , t_transaction.TransactionDate AS TransactionDate ';
        $sql .= '     , t_transaction.JournalKindID AS JournalKindID ';
        $sql .= '     , t_commonjournal.ClientID AS ClientID ';
        $sql .= '     , u_client.ClientName AS ClientName ';
        $sql .= '     , t_transaction.TransactionStatusID AS TransactionStatusID ';
        $sql .= '     , t_transaction.Summary AS Summary ';
        $sql .= '     , Sub_TrnSts.ConstVal1 AS TransactionStatusName ';
        $sql .= '     , t_commonjournal.CommonJournalNo AS CommonJournalNo ';
        $sql .= '     , t_commonjournal.AccountsTitleID AS AccountsTitleID ';
        $sql .= '     , t_commonjournal.DrCrFlg AS DrCrFlg ';
        $sql .= '     , t_commonjournal.Amount AS Amount ';
        $sql .= '     , t_commonjournal.CurrencyID AS CurrencyID ';
        $sql .= '     , t_commonjournal.FxRate AS FxRate ';
        $sql .= '     , t_commonjournal.FxAmount AS FxAmount ';
        $sql .= '     , t_commonjournal.TaxableAmount AS TaxableAmount ';
        $sql .= '     , t_commonjournal.SegmentID AS SegmentID ';
        $sql .= '     , t_commonjournal.ControlNo AS ControlNo ';
        $sql .= '     , t_commonjournal.DueDate AS DueDate ';
        $sql .= '     , t_commonjournal.VATType AS VATType ';
        $sql .= '     , t_commonjournal.WHTType AS WHTType ';
        $sql .= '     , t_commonjournal.Status AS Status ';
        $sql .= '     , t_commonjournal.Line AS Line ';
        $sql .= '     , Sub_LineMax.LineMax AS LineMax ';
        $sql .= '     , u_user.UserName AS UpdUser ';
        $sql .= 'FROM   t_transaction ';
        $sql .= 'INNER JOIN  t_commonjournal ';
        $sql .= 'ON    t_transaction.TransactionID       = t_commonjournal.TransactionID ';
        $sql .= 'LEFT JOIN   u_client ';
        $sql .= 'ON    t_commonjournal.ClientID          = u_client.ClientID ';
        $sql .= 'AND   u_client.LanguageID               = ? ';    // $lang
        $sql .= 'LEFT JOIN   u_user ';
        $sql .= 'ON    t_commonjournal.UpdUser           = u_user.UserID ';
        $sql .= 'LEFT JOIN   '.$sql_Sub_LineMax.' ';
        $sql .= 'ON    t_transaction.TransactionID       = Sub_LineMax.TransactionID ';
        $sql .= 'LEFT JOIN   '.$sql_Sub_TrnSts.' ';
        $sql .= 'ON    t_transaction.TransactionStatusID = Sub_TrnSts.ConstID2 ';
        $sql .= 'WHERE t_transaction.TransactionID       = ? ';    // $TrnID
        $sql .= 'AND   t_transaction.Status              = true ';
        $sql .= $sql_TrnSts.' ';
        $sql .= 'ORDER BY t_commonjournal.Status DESC, t_commonjournal.EntDate DESC, t_commonjournal.Line ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssss', $ClientLanguageID, $ConstID1, $LanguageID, $TransactionID);
            $ClientLanguageID   = $lang;
            $ConstID1           = $this->CL['DF']->TRNSTS;
            $LanguageID         = $lang;
            $TransactionID      = $TrnID;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_transaction*m_const*u_client*u_user                  */
/*--------------------------------------------------------*/
    // 取引(特殊仕訳帳)を取得する(全件)
    public function gSpeTrnList($searchdate, $syear, $smonth, $sday, $eyear, $emonth, $eday, $spejnlid, $trnsts, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_TrnSts = self::sArrTrnSts('t_transaction', $trnsts);            // 検索条件(取引ステータス)
        $sql_SpeJnl = self::sArrSpeJnlID('t_transaction', $spejnlid);        // 検索条件(特殊仕訳帳)
        $sdate      = self::sSDate2($searchdate, $syear, $smonth, $sday);    // 検索条件(開始日)
        $edate      = self::sEDate2($searchdate, $eyear, $emonth, $eday);    // 検索条件(終了日)
        
        $sql_Sub_JnlKind  = '( ';
        $sql_Sub_JnlKind .= '    SELECT ConstVal1, ConstVal2, ConstID2 ';
        $sql_Sub_JnlKind .= '    FROM   m_const ';
        $sql_Sub_JnlKind .= '    WHERE  ConstID1   = ? ';    // $this->CL['DF']->JNLKIND
        $sql_Sub_JnlKind .= '    AND    LanguageID = ? ';    // $lang
        $sql_Sub_JnlKind .= '    AND    Status     = true ';
        $sql_Sub_JnlKind .= ') AS Sub_JnlKind ';
        
        $sql_Sub_TrnSts  = '( ';
        $sql_Sub_TrnSts .= '    SELECT ConstVal1, ConstID2 ';
        $sql_Sub_TrnSts .= '    FROM   m_const ';
        $sql_Sub_TrnSts .= '    WHERE  ConstID1   = ? ';    // $this->CL['DF']->TRNSTS
        $sql_Sub_TrnSts .= '    AND    LanguageID = ? ';    // $lang
        $sql_Sub_TrnSts .= '    AND    Status     = true ';
        $sql_Sub_TrnSts .= ') AS Sub_TrnSts ';
        
        $sql  = 'SELECT t_transaction.TransactionNo AS TransactionNo ';
        $sql .= '     , t_transaction.TransactionID AS TransactionID ';
        $sql .= '     , t_transaction.TransactionDate AS TransactionDate ';
        $sql .= '     , t_transaction.TransactionStatusID AS TransactionStatusID ';
        $sql .= '     , t_transaction.Summary AS Summary ';
        $sql .= '     , u_user.UserName AS UserName ';
        $sql .= '     , Sub_TrnSts.ConstVal1 AS TransactionStatusName ';
        $sql .= '     , Sub_JnlKind.ConstVal1 AS JournalKindName ';
        $sql .= '     , Sub_JnlKind.ConstVal2 AS JournalTblName ';
        $sql .= 'FROM   t_transaction ';
        $sql .= '     , u_user ';
        $sql .= '     , '.$sql_Sub_JnlKind.' ';
        $sql .= '     , '.$sql_Sub_TrnSts.' ';
        $sql .= 'WHERE   t_transaction.EntUser             = u_user.UserID ';
        $sql .= 'AND   t_transaction.TransactionStatusID = Sub_TrnSts.ConstID2 ';
        $sql .= 'AND   Sub_JnlKind.ConstID2              = t_transaction.JournalKindID ';
        $sql .= 'AND   t_transaction.Status              = true ';
        $sql .= 'AND   t_transaction.JournalKindID       <> \'0\' ';    // 普通仕訳帳を除外
        $sql .= 'AND    t_transaction.TransactionDate    >= ? ';    // $sdate
        $sql .= 'AND    t_transaction.TransactionDate    <= ? ';    // $edate
        $sql .= $sql_TrnSts.' ';
        $sql .= $sql_SpeJnl.' ';
        $sql .= 'ORDER BY t_transaction.TransactionID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssss', $JnlKindConstID1, $JnlKindLanguageID, $TrnKindConstID1, $TrnKindLanguageID, $SEntDate, $EEntDate);
            $JnlKindConstID1    = $this->CL['DF']->JNLKIND;
            $JnlKindLanguageID  = $lang;
            $TrnKindConstID1    = $this->CL['DF']->TRNSTS;
            $TrnKindLanguageID  = $lang;
            $SEntDate           = $sdate;
            $EEntDate           = $edate;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_transaction*t_generaljournal*m_const*u_client*       */
/* m_accountstitlel*m_accountstitlem*m_accountstitles*    */
/* u_user                                                 */
/*--------------------------------------------------------*/
    // 取引を取得する(全件)
    public function gGenTrnList($TrnKindID, $searchdate, $syear, $smonth, $sday, $eyear, $emonth, $eday, $curid, $cltid, $segid, $trnsts, $inputuserno, $searchText, $AccTitleID, $pageRowText, $pages, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_AccountsTitleID  = self::sArrAccTitleID('m_accountstitles', $AccTitleID);      // 検索条件(勘定科目)
//        $sql_SegID            = self::sArrID('t_generaljournal', $segid, 'SegmentID');      // 検索条件(通貨ID)
        $sql_SegID            = self::sDataFlg('t_generaljournal', $segid, 'SegmentID');      // 検索条件(通貨ID)
        $sql_CurID            = self::sDataFlg('t_generaljournal', $curid, 'CurrencyID');     // 検索条件(通貨ID)
        $sql_InputUserNo      = self::sArrInputUserNo('u_user', $inputuserno);              // 検索条件(入力者)
        $sql_CltID            = self::sArrCltID('t_generaljournal', $cltid);                // 検索条件(取引先)
        $sql_TrnSts           = self::sArrTrnSts('t_transaction', $trnsts);                 // 検索条件(取引ステータス)
        $sql_TrnKindID        = self::sArrTrnKindID('t_transaction', $TrnKindID);           // 検索条件(取引種別)
        $sdate                = self::sSDate2($searchdate, $syear, $smonth, $sday);         // 検索条件(開始日)
        $edate                = self::sEDate2($searchdate, $eyear, $emonth, $eday);         // 検索条件(終了日)
        $array                = self::sLimit($pageRowText, $pages);                         // 検索条件(ページング)
        $offset               = $array[0];
        $limit                = $array[1];
        
        $sql  = 'SELECT t_transaction.TransactionNo AS TransactionNo ';
        $sql .= '      , t_transaction.TransactionID AS TransactionID ';
        $sql .= '      , t_transaction.RevisionNo AS RevisionNo ';
        $sql .= '      , t_generaljournal.Line AS Line ';
        $sql .= '      , t_transaction.TransactionDate AS TransactionDate ';
        $sql .= '      , t_generaljournal.ClientID AS ClientID ';
        $sql .= '      , t_transaction.TransactionStatusID AS TransactionStatusID ';
        $sql .= '      , t_transaction.Summary AS Summary      , Sub_TrnSts.ConstVal1 AS TransactionStatusName ';
        $sql .= '      , t_generaljournal.GeneralJournalNo AS GeneralJournalNo ';
        $sql .= '      , t_generaljournal.AccountsTitleID AS AccountsTitleID ';
        $sql .= '      , t_generaljournal.DrCrFlg AS DrCrFlg ';
        $sql .= '      , t_generaljournal.Amount AS Amount ';
        $sql .= '      , t_generaljournal.FxAmount  AS FxAmount ';
        $sql .= '      , t_generaljournal.ControlNo AS ControlNo ';
        $sql .= '      , t_generaljournal.DueDate AS DueDate ';
        $sql .= '      , u_segment.SegmentName ';
        $sql .= '      , u_currency.CurrencyName ';
        $sql .= '      , t_transaction.TransactionKindID ';
        $sql .= '      , Sub_TransactionKind.ConstVal1 AS TransactionKindName ';
        $sql .= '      , Sub_JnlKind.ConstVal1 AS JournalKindName ';
        $sql .= '      , u_client.ClientName AS ClientName ';
        $sql .= '      , m_accountstitles.AccountsTitleSName AS AccountsTitleSName ';
        $sql .= '      , u_user.UserName AS UserName ';
        $sql .= '      , t_generaljournal.Status AS Status ';
        $sql .= '      , Sub_LineMax.LineMax AS LineMax ';
        $sql .= 'FROM   t_transaction ';
        $sql .= 'INNER JOIN t_generaljournal ';
        $sql .= 'ON     t_transaction.TransactionID       = t_generaljournal.TransactionID ';
        $sql .= 'AND    t_transaction.RevisionNo          = t_generaljournal.RevisionNo ';
        $sql .= 'INNER JOIN m_accountstitles ';
        $sql .= 'ON     m_accountstitles.AccountsTitleID  = t_generaljournal.AccountsTitleID ';
        $sql .= 'AND    m_accountstitles.LanguageID       = ? ';    // $lang
        $sql .= 'LEFT JOIN u_client ';
        $sql .= 'ON     t_generaljournal.ClientID         = u_client.ClientID ';
        $sql .= 'AND    m_accountstitles.LanguageID       = u_client.LanguageID ';
        $sql .= 'AND    u_client.Status                   = true ';
        $sql .= 'LEFT JOIN u_user ';
        $sql .= 'ON     t_transaction.EntUser             = u_user.UserID ';
        $sql .= 'AND    u_user.Status                     = true ';
        $sql .= 'LEFT JOIN ( ';
        $sql .= '     SELECT TransactionID, RevisionNo, MAX(Line) AS LineMax ';
        $sql .= '     FROM t_generaljournal ';
        $sql .= '     GROUP BY TransactionID, RevisionNo ) AS Sub_LineMax ';
        $sql .= 'ON     t_transaction.TransactionID       = Sub_LineMax.TransactionID ';
        $sql .= 'AND    t_transaction.RevisionNo          = Sub_LineMax.RevisionNo ';
        $sql .= 'LEFT JOIN m_const   Sub_TrnSts ';
        $sql .= 'ON     Sub_TrnSts.ConstID1    = ? ';    // $this->CL['DF']->TRNSTS
        $sql .= 'AND    Sub_TrnSts.LanguageID = m_accountstitles.LanguageID ';
        $sql .= 'AND    t_transaction.TransactionStatusID = Sub_TrnSts.ConstID2 ';
        $sql .= 'LEFT JOIN m_const   Sub_JnlKind ';
        $sql .= 'ON     Sub_JnlKind.ConstID1   = ? ';    // $this->CL['DF']->JNLKIND
        $sql .= 'AND    Sub_JnlKind.LanguageID = m_accountstitles.LanguageID ';
        $sql .= 'AND    Sub_JnlKind.ConstID2   = t_transaction.JournalKindID ';
        $sql .= 'LEFT JOIN m_const   Sub_TransactionKind ';
        $sql .= 'ON     Sub_TransactionKind.ConstID1   = ? ';    // $this->CL['DF']->TRNKIND
        $sql .= 'AND    Sub_TransactionKind.LanguageID = m_accountstitles.LanguageID ';
        $sql .= 'AND    Sub_TransactionKind.ConstID2   = t_transaction.TransactionKindID ';
        $sql .= 'LEFT JOIN u_segment ';
        $sql .= 'ON     t_generaljournal.SegmentID     = u_segment.SegmentID ';
        $sql .= 'AND    u_segment.LanguageID           = m_accountstitles.LanguageID ';
        $sql .= 'AND    u_segment.Status               = true ';
        $sql .= 'LEFT JOIN u_currency ';
        $sql .= 'ON     t_generaljournal.CurrencyID    = u_currency.CurrencyID ';
        $sql .= 'AND    u_currency.Status              = true ';
        $sql .= 'AND    u_currency.LanguageID          = m_accountstitles.LanguageID ';
        $sql .= 'WHERE  t_transaction.TransactionDate    >= ? ';    // $sdate
        $sql .= 'AND    t_transaction.TransactionDate    <= ? ';    // $edate
        $sql .= 'AND    ( ';
        $sql .= '           t_transaction.Summary LIKE      ? ';    // '%'+$searchText+'%'
        $sql .= '       ) ';
        $sql .= 'AND    m_accountstitles.Status           = true ';
        $sql .= $sql_AccountsTitleID.' ';
        $sql .= $sql_InputUserNo.' ';
        $sql .= $sql_CltID.' ';
        $sql .= $sql_SegID.' ';
        $sql .= $sql_CurID.' ';
        $sql .= $sql_TrnSts.' ';
        $sql .= $sql_TrnKindID.' ';
        $sql .= 'ORDER BY t_transaction.TransactionDate, t_generaljournal.TransactionID, t_transaction.RevisionNo, t_generaljournal.Line ';
        $sql .= 'LIMIT ?, ? ';    // $offset, $limit
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssssii', $AccTtlTitleSLangID, $TrnStsConstID1, $JnlKindConstID1, $TrnKindConstID1, $SEntDate, $EEntDate, $Summary2, $Offset, $Limit);
            $AccTtlTitleSLangID = $lang;
            $TrnStsConstID1     = $this->CL['DF']->TRNSTS;
            $JnlKindConstID1    = $this->CL['DF']->JNLKIND;
            $TrnKindConstID1    = $this->CL['DF']->TRNKIND;
            $SEntDate           = $sdate;
            $EEntDate           = $edate;
            $Summary2           = '%'.$searchText.'%';
            $Offset             = $offset;
            $Limit              = $limit;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_ledgerslist                                          */
/*--------------------------------------------------------*/
    // 元丁一覧情報を追加する
    public function iLedList($LedListName, $linemax, $s_userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_ledgerslist(LedgersListID, LedgersListName, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $linemax
        $sql .= ',? ';    // $LedListName
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $s_userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $s_userid
        $sql .= ',true ) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssss', $LedgersListID, $LedgersListName, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $LedgersListID   = $linemax;
            $LedgersListName = $LedListName;
            $EntDate         = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser         = $s_userid;
            $UpdDate         = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser         = $s_userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 元帳一覧を取得する(全件)
    public function gLedNameList() {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT DISTINCT  ';
        $sql .= 'AccountsTitleID  ';
        $sql .= 'FROM ( ';
        $sql .= 'SELECT AccountsTitleID FROM m_openningbalance ';
        $sql .= 'WHERE STATUS=TRUE ';
        $sql .= 'AND amount<>0 ';
        $sql .= 'union ';
        $sql .= 'SELECT AccountsTitleID FROM t_generalledger ';
        $sql .= 'WHERE STATUS=TRUE ';
        $sql .= ') a  ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 元丁IDを取得する(一件)
    public function gLedIDVal($LedListName) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT LedgersListID ';
        $sql .= 'FROM   t_ledgerslist ';
        $sql .= 'WHERE  LedgersListName = ? ';    // $LedListName
        $sql .= 'AND    Status          = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $LedgersListName);
            $LedgersListName = $LedListName;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 元丁IDの最大値を取得する
    public function gLedIDMaxVal() {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT MAX(CAST(LedgersListID AS SIGNED)) AS LedgersListIDMax ';
        $sql .= 'FROM   t_ledgerslist ';
        $sql .= 'WHERE  Status = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_generalledger                                        */
/*--------------------------------------------------------*/
    // 総勘定元帳を追加する
    public function iGenLedInfo($TrnID, $RevNo, $LineNo, $JnlKind, $TrnKindID, $Date, $CltID, $AccTitleID, $DrCrFlg, $Amt, $CtrlNo, $Due, $_Summary, $ContraAcc, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_generalledger (TransactionID, RevisionNo, Line, JournalKindID, TransactionKindID, TransactionDate, ClientID, AccountsTitleID, DrCrFlg, Amount, ControlNo, DueDate, Summary, ContraAccounts, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $TrnID
        $sql .= ',? ';    // $RevNo
        $sql .= ',? ';    // $LineNo
        $sql .= ',? ';    // $JnlKind
        $sql .= ',? ';    // $TrnKindID
        $sql .= ',? ';    // $Date
        $sql .= ',? ';    // $CltID
        $sql .= ',? ';    // $AccTitleID
        $sql .= ',? ';    // $DrCrFlg
        $sql .= ',? ';    // $Amt
        $sql .= ',? ';    // $CtrlNo
        $sql .= ',? ';    // $Due
        $sql .= ',? ';    // $_Summary
        $sql .= ',? ';    // $ContraAcc
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ', true) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssssssssss', $TransactionID, $RevisionNo, $Line, $JournalKindID, $TransactionKindID, $TransactionDate, $ClientID, $AccountsTitleID, $DrCrFlg, $Amount, $ControlNo, $DueDate, $Summary, $ContraAccounts, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $TransactionID	=	$TrnID;
            $RevisionNo          = $RevNo;
            $Line	=	$LineNo;
            $JournalKindID	=	$JnlKind;
            $TransactionKindID	=	$TrnKindID;
            $TransactionDate	=	$Date;
            $ClientID	=	$CltID;
            $AccountsTitleID	=	$AccTitleID;
            $DrCrFlg	=	$DrCrFlg;
            $Amount	=	$Amt;
            $ControlNo	=	$CtrlNo;
            $DueDate	=	$Due;
            $Summary	=	$_Summary;
            $ContraAccounts	=	$ContraAcc;
            $EntDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser          = $userid;
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 総勘定元帳を削除する
    public function dGenLedInfo($TrnID, $JnlKind, $TrnKindID, $Date, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE t_generalledger ';
        $sql .= 'SET    Status        = false ';
        $sql .= '     , UpdDate       = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser       = ? ';    // $userid
        $sql .= '     , DelDate       = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , DelUser       = ? ';    // $userid
        $sql .= 'WHERE  Status        = true ';
        if ($TrnID) {
            $sql .= 'AND    TransactionID = ? ';    // $TrnID
        } else {
            $sql .= 'AND    JournalKindID     = ? ';    // $JnlKind
            $sql .= 'AND    TransactionKindID = ? ';    // $TrnKindID
            $sql .= 'AND    TransactionDate like ? ';    // $Date
        }
        
        if ($stmt = $mysqli->prepare($sql)) {
            if ($TrnID) {
                $stmt->bind_param('sssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $TransactionID);
                $TransactionID = $TrnID;
            } else {
                $stmt->bind_param('sssssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $JournalKindID, $TransactionKindID, $TransactionDate);
                $JournalKindID	=	$JnlKind;
                $TransactionKindID	=	$TrnKindID;
                $TransactionDate	=	$Date.'%';
            }
            $UpdDate       = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser       = $userid;
            $DelDate       = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser       = $userid;
             
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    
    // 総勘定元帳を取得する(一行)
    public function gGenLedRow($TrnID, $RevNo, $LineNo, $status = true) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_Status    = self::sDataFlg('t_generalledger', $status, 'Status');      // 検索条件(削除ステータス)
        
        $sql  = ' SELECT ';
        $sql .= ' LedgerNo ';
        $sql .= ',TransactionID ';
        $sql .= ',RevisionNo ';
        $sql .= ',Line ';
        $sql .= ',JournalKindID ';
        $sql .= ',TransactionKindID ';
        $sql .= ',TransactionDate ';
        $sql .= ',ClientID ';
        $sql .= ',AccountsTitleID ';
        $sql .= ',DrCrFlg ';
        $sql .= ',Amount ';
        $sql .= ',ControlNo ';
        $sql .= ',DueDate ';
        $sql .= ',Summary ';
        $sql .= ',ContraAccounts ';
        $sql .= ',Status ';
        $sql .= 'FROM t_generalledger ';
        $sql .= 'WHERE  TransactionID = ? ';    // $TrnID
        $sql .= 'AND    RevisionNo = ? ';       // $RevNo
        $sql .= 'AND    Line       = ? ';       // $LineNo
        $sql .= $sql_Status;

        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $TransactionID, $RevisionNo, $Line);
            $TransactionID  = $TrnID;
            $RevisionNo     = $RevNo;
            $Line	=	$LineNo;
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_generalledger*m_accountstitles                       */
/*--------------------------------------------------------*/
    // 指定年月での総勘定元帳上の勘定科目別貸借合計を求める （試算表作成用）
    public function gGenLedSum($TrnKindID, $year, $month, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_TrnKindID = self::sTrnKindID('t_generalledger', $TrnKindID);    // 検索条件(取引種別)
        
        $sql  = 'SELECT t_generalledger.AccountsTitleID ';
        $sql .= ',m_accountstitles.AccountsKind1ID ';
        $sql .= ',m_accountstitles.AccountsKind2ID ';
        $sql .= ',m_accountstitles.AccountsKind3ID ';
        $sql .= ',m_accountstitles.AccountsKind4ID ';
        $sql .= ',m_accountstitles.AccountsKind5ID ';
        $sql .= ',sum(case t_generalledger.DrCrFlg when \''.$this->CL['DF']->Dr.'\' then t_generalledger.amount ELSE 0 END) DrAmount ';
        $sql .= ',sum(case t_generalledger.DrCrFlg when \''.$this->CL['DF']->Cr.'\' then t_generalledger.amount ELSE 0 END) CrAmount ';
        $sql .= 'FROM t_generalledger ';
        $sql .= 'LEFT JOIN m_accountstitles  ';
        $sql .= 'ON  m_accountstitles.AccountsTitleID=t_generalledger.AccountsTitleID ';
        $sql .= 'AND m_accountstitles.Status=true ';
        $sql .= 'WHERE SUBSTRING(t_generalledger.TransactionDate, 1, 6)= ?  ';
        $sql .= 'AND t_generalledger.Status=TRUE ';
        $sql .= 'and m_accountstitles.LanguageID=? ';
        $sql .= '    '.$sql_TrnKindID.' ';
        $sql .= 'GROUP BY  t_generalledger.AccountsTitleID ';
        $sql .= ',m_accountstitles.AccountsKind1ID ';
        $sql .= ',m_accountstitles.AccountsKind2ID ';
        $sql .= ',m_accountstitles.AccountsKind3ID ';
        $sql .= ',m_accountstitles.AccountsKind4ID ';
        $sql .= ',m_accountstitles.AccountsKind5ID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $TrnYM, $LangID);
            $TrnYM  = $year.str_pad($month, $this->CL['DF']->LenMonth, $this->CL['DF']->ZERO, STR_PAD_LEFT);
            $LangID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_subledger                                           */
/*--------------------------------------------------------*/
    // 補助元帳を追加する
    public function iSubLedInfo($TrnID, $RevNo, $LineNo, $JnlKind, $TrnKindID, $Date, $CltID, $AccTitleID, $DrCrFlg, $Amt, $pCurrencyID, $pFxRate, $pFxAmount, $pTaxableAmount, $pSegmentID, $CtrlNo, $Due, $pVATType, $pWHTType, $_Summary, $ContraAcc, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_subledger (TransactionID, RevisionNo, Line, JournalKindID, TransactionKindID, TransactionDate, ClientID, AccountsTitleID, DrCrFlg, Amount, CurrencyID, FxRate, FxAmount, TaxableAmount, SegmentID, ControlNo, DueDate, VATType, WHTType, Summary, ContraAccounts, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $TrnID
        $sql .= ',? ';    // $RevNo
        $sql .= ',? ';    // $LineNo
        $sql .= ',? ';    // $JnlKind
        $sql .= ',? ';    // $TrnKindID
        $sql .= ',? ';    // $Date
        $sql .= ',? ';    // $CltID
        $sql .= ',? ';    // $AccTitleID
        $sql .= ',? ';    // $DrCrFlg
        $sql .= ',? ';    // $Amt
        $sql .= ',? ';    // $pCurrencyID
        $sql .= ',? ';    // $pFxRate
        $sql .= ',? ';    // $pFxAmount
        $sql .= ',? ';    // $pTaxableAmount
        $sql .= ',? ';    // $pSegmentID
        $sql .= ',? ';    // $CtrlNo
        $sql .= ',? ';    // $Due
        $sql .= ',? ';    // $pVATType
        $sql .= ',? ';    // $pWHTType
        $sql .= ',? ';    // $_Summary
        $sql .= ',? ';    // $ContraAcc
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ', true) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssssssssssssssssssssss', $TransactionID, $RevisionNo, $Line, $JournalKindID, $TransactionKindID, $TransactionDate, $ClientID, $AccountsTitleID, $DrCrFlg, $Amount, $CurrencyID, $FxRate, $FxAmount, $TaxableAmount, $SegmentID, $ControlNo, $DueDate, $VATType, $WHTType, $Summary, $ContraAccounts, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $TransactionID	=	$TrnID;
            $RevisionNo          = $RevNo;
            $Line	=	$LineNo;
            $JournalKindID	=	$JnlKind;
            $TransactionKindID	=	$TrnKindID;
            $TransactionDate	=	$Date;
            $ClientID	=	$CltID;
            $AccountsTitleID	=	$AccTitleID;
            $DrCrFlg	=	$DrCrFlg;
            $Amount	=	$Amt;
            $CurrencyID       = $pCurrencyID;
            $FxRate           = $pFxRate;
            $FxAmount         = $pFxAmount;
            $TaxableAmount    = $pTaxableAmount;
            $SegmentID        = $pSegmentID;
            $ControlNo        = $CtrlNo;
            $DueDate          = $Due;
            $VATType          = $pVATType;
            $WHTType          = $pWHTType;
            $Summary		=	$_Summary;
            $ContraAccounts	=	$ContraAcc;
            $EntDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser          = $userid;
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 補助元帳を削除する
    public function dSubLedInfo($TrnID, $JnlKind, $TrnKindID, $Date, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE t_subledger ';
        $sql .= 'SET    Status        = false ';
        $sql .= '     , UpdDate       = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser       = ? ';    // $userid
        $sql .= '     , DelDate       = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , DelUser       = ? ';    // $userid
        $sql .= 'WHERE  Status        = true ';
        if ($TrnID) {
            $sql .= 'AND    TransactionID = ? ';    // $TrnID
        } else {
            $sql .= 'AND    JournalKindID     = ? ';    // $JnlKind
            $sql .= 'AND    TransactionKindID = ? ';    // $TrnKindID
            $sql .= 'AND    TransactionDate like ? ';    // $Date
        }
        
        if ($stmt = $mysqli->prepare($sql)) {
            if ($TrnID) {
                $stmt->bind_param('sssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $TransactionID);
                $TransactionID = $TrnID;
            } else {
                $stmt->bind_param('sssssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $JournalKindID, $TransactionKindID, $TransactionDate);
                $JournalKindID	=	$JnlKind;
                $TransactionKindID	=	$TrnKindID;
                $TransactionDate	=	$Date.'%';
            }
            $UpdDate       = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser       = $userid;
            $DelDate       = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser       = $userid;
             
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 補助元帳一覧を取得する(全件)
    public function gSubLedNameList() {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT DISTINCT  ';
        $sql .= 'a.AccountsTitleID  ';
        $sql .= 'FROM ( ';
        $sql .= 'SELECT AccountsTitleID FROM m_openningbalance ';
        $sql .= 'WHERE STATUS=TRUE ';
        $sql .= 'AND amount<>0 ';
        $sql .= 'union ';
        $sql .= 'SELECT AccountsTitleID FROM t_subledger ';
        $sql .= 'WHERE STATUS=TRUE ';
        $sql .= ') a  ';
        $sql .= 'LEFT JOIN m_accountstitles  ';
        $sql .= 'ON m_accountstitles.Status=TRUE  ';
        $sql .= 'AND m_accountstitles.AccountsTitleID=a.AccountsTitleID ';
        $sql .= 'WHERE m_accountstitles.SubLedgerFlg=\'1\' ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 補助元帳を取得する(一行)
    public function gSubLedRow($TrnID, $RevNo, $LineNo, $status = true) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_Status    = self::sDataFlg('t_subledger', $status, 'Status');      // 検索条件(削除ステータス)
        
        $sql  = ' SELECT ';
        $sql .= ' TransactionID ';
        $sql .= ',RevisionNo ';
        $sql .= ',Line ';
        $sql .= ',TransactionDate ';
        $sql .= ',JournalKindID ';
        $sql .= ',TransactionKindID ';
        $sql .= ',AccountsTitleID ';
        $sql .= ',ClientID ';
        $sql .= ',CurrencyID ';
        $sql .= ',FxRate ';
        $sql .= ',FxAmount ';
        $sql .= ',TaxableAmount ';
        $sql .= ',SegmentID ';
        $sql .= ',ControlNo ';
        $sql .= ',DueDate ';
        $sql .= ',VATType ';
        $sql .= ',WHTType ';
        $sql .= ',DrCrFlg ';
        $sql .= ',Amount ';
        $sql .= ',Summary ';
        $sql .= ',ContraAccounts ';
        $sql .= ',Status ';
        $sql .= 'FROM t_subledger ';
        $sql .= 'WHERE  TransactionID = ? ';    // $TrnID
        $sql .= 'AND    RevisionNo = ? ';       // $RevNo
        $sql .= 'AND    Line       = ? ';       // $LineNo
        $sql .= $sql_Status;

        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $TransactionID, $RevisionNo, $Line);
            $TransactionID  = $TrnID;
            $RevisionNo     = $RevNo;
            $Line	=	$LineNo;
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_subledger*m_openningbalance*m_accountstitlel*        */
/* m_accountstitlem*m_accountstitles*u_client             */
/*--------------------------------------------------------*/
    // 補助元帳を取得する
    public function gSubLedList($ID, $sdate, $edate, $level, $cltid, $curflg, $curid, $segflg, $segid, $popSts, $pageRowText, $pages, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_TrnSts    = self::sPopSts('tmp', $popSts);    // 検索条件(ステータス)
        $sql_CltID     = self::sArrCltID('tmp', $cltid); 
        
        $sql_CurID     = '';
        if ($curflg) {
//            $sql_CurID     = self::sArrID('tmp', $curid, 'CurrencyID');
            $sql_CurID     = self::sDataFlg('tmp', $curid, 'CurrencyID');
        }
        $sql_SegID     = '';
        if ($segflg) {
//            $sql_SegID     = self::sArrID('tmp', $segid, 'SegmentID');
            $sql_SegID     = self::sDataFlg('tmp', $segid, 'SegmentID');
        }
        
        $array  = self::sLimit($pageRowText, $pages);                         // 検索条件(ページング)
        $offset = $array[0];
        $limit  = $array[1];
        
        $sql  = 'SELECT ';
        $sql .= ' tmp.datasource ';
        $sql .= ',tmp.TransactionID ';
        $sql .= ',tmp.RevisionNo ';
        $sql .= ',tmp.TransactionDate ';
        $sql .= ',tmp.JournalKindID ';
        $sql .= ',m_const1.ConstVal1 JournalKindName ';
        $sql .= ',m_const1.ConstVal3 JournalProgram ';
        $sql .= ',tmp.TransactionKindID ';
        $sql .= ',tmp.AccountsTitleID ';
        $sql .= ',tmp.ClientID ';
        $sql .= ',u_client.ClientName  ';
        $sql .= ',tmp.CurrencyID ';
        $sql .= ',u_currency.CurrencyName  ';
        $sql .= ',tmp.FxRate ';
        $sql .= ',tmp.FxAmount ';
        $sql .= ',tmp.TaxableAmount ';
        $sql .= ',tmp.SegmentID ';
        $sql .= ',u_segment.SegmentName  ';
        $sql .= ',tmp.ControlNo ';
        $sql .= ',tmp.DueDate ';
        $sql .= ',tmp.VATType ';
        $sql .= ',tmp.WHTType ';
        $sql .= ',tmp.DrCrFlg ';
        $sql .= ',tmp.Amount ';
        $sql .= ',tmp.Summary ';
        $sql .= ',tmp.ContraAccounts ';
        $sql .= ',tmp.Status ';
        $sql .= 'FROM ( ';
        $sql .= 'SELECT ';
        $sql .= ' \'0\' datasource ';
        $sql .= ',\'\' TransactionID ';
        $sql .= ',0 RevisionNo ';
        $sql .= ',\'\' TransactionDate ';
        $sql .= ',\'\' JournalKindID ';
        $sql .= ',\'\' TransactionKindID ';
        $sql .= ',AccountsTitleID ';
        $sql .= ',ClientID ';
        $sql .= ',CurrencyID ';
        $sql .= ',\'\' FxRate ';
        $sql .= ',FxAmount ';
        $sql .= ',\'\' TaxableAmount ';
        $sql .= ',SegmentID ';
        $sql .= ',ControlNo ';
        $sql .= ',\'\' DueDate ';
        $sql .= ',\'\' VATType ';
        $sql .= ',\'\' WHTType ';
        $sql .= ',\'\' DrCrFlg ';
        $sql .= ',Amount ';
        $sql .= ',Summary ';
        $sql .= ',\'\' ContraAccounts ';
        $sql .= ',Status ';
        $sql .= ' FROM m_openbaldetail ';
        $sql .= ' WHERE m_openbaldetail.STATUS=true ';
        $sql .= ' AND   m_openbaldetail.Amount<>0 ';
        $sql .= ' union ';
        $sql .= ' SELECT ';
        $sql .= ' \'1\' datasource ';
        $sql .= ',TransactionID ';
        $sql .= ',RevisionNo ';
        $sql .= ',TransactionDate ';
        $sql .= ',JournalKindID ';
        $sql .= ',TransactionKindID ';
        $sql .= ',AccountsTitleID ';
        $sql .= ',ClientID ';
        $sql .= ',CurrencyID ';
        $sql .= ',FxRate ';
        $sql .= ',FxAmount ';
        $sql .= ',TaxableAmount ';
        $sql .= ',SegmentID ';
        $sql .= ',ControlNo ';
        $sql .= ',DueDate ';
        $sql .= ',VATType ';
        $sql .= ',WHTType ';
        $sql .= ',DrCrFlg ';
        $sql .= ',Amount ';
        $sql .= ',Summary ';
        $sql .= ',ContraAccounts ';
        $sql .= ',Status ';
        $sql .= ' FROM t_subledger  ';
        $sql .= ' ) tmp ';
        $sql .= ' LEFT JOIN m_const AS m_const1  ';
        $sql .= ' ON m_const1.ConstID1=\''.$this->CL['DF']->JNLKIND.'\'  ';
        $sql .= ' AND m_const1.ConstID2=tmp.JournalKindID  ';
        $sql .= ' AND m_const1.LanguageID = ? ';
        $sql .= 'LEFT JOIN u_client  ';
        $sql .= 'ON  u_client.ClientID=tmp.ClientID  ';
        $sql .= 'AND u_client.LanguageID=m_const1.LanguageID  ';
        $sql .= 'AND u_client.Status=TRUE  ';
        $sql .= 'LEFT JOIN u_currency  ';
        $sql .= 'ON  u_currency.CurrencyID=tmp.CurrencyID  ';
        $sql .= 'AND u_currency.LanguageID=m_const1.LanguageID  ';
        $sql .= 'AND u_currency.Status=TRUE  ';
        $sql .= 'LEFT JOIN u_segment  ';
        $sql .= 'ON  u_segment.SegmentID=tmp.SegmentID  ';
        $sql .= 'AND u_segment.LanguageID=m_const1.LanguageID  ';
        $sql .= 'AND u_segment.Status=TRUE  ';
        $sql .= 'WHERE tmp.AccountsTitleID  = ? ';
        $sql .= 'AND   tmp.TransactionDate  >= ? ';    // $sdate
        $sql .= 'AND   tmp.TransactionDate  <= ? ';    // $edate
        $sql .= $sql_CltID.' ';
        $sql .= $sql_CurID.' ';
        $sql .= $sql_SegID.' ';
        $sql .= $sql_TrnSts.' ';
        $sql .= ' ORDER BY  ';
        $sql .= ' tmp.AccountsTitleID ';
        
        $this->SubLedLevel_AgingReport  = 9;    // Aging Report用（相手先、通貨、セグメント、コントロールNoごと）
        if ($level == $this->CL['DF']->SubLedLevel_AgingReport) {
            $sql .= ',tmp.ClientID ';
            $sql .= ',tmp.CurrencyID ';
            $sql .= ',tmp.ControlNo ';
            $sql .= ',tmp.SegmentID ';
        } else {
            if ($curflg) {
                $sql .= ',tmp.CurrencyID ';
            }
            if ($segflg) {
                $sql .= ',tmp.SegmentID ';
            }
            if ($level == $this->CL['DF']->SubLedLevel_Client) {
                $sql .= ',tmp.ClientID ';
            } else if ($level == $this->CL['DF']->SubLedLevel_ControlNo) {
                $sql .= ',tmp.ClientID ';
                $sql .= ',tmp.ControlNo ';
            }
        }
        
        $sql .= ',tmp.TransactionDate ';
        $sql .= ',tmp.datasource ';
        $sql .= ',tmp.TransactionID ';
        $sql .= ',tmp.RevisionNo ';
        $sql .= 'LIMIT ?, ? ';    // $offset, $limit

        
        if ($stmt = $mysqli->prepare($sql)) {
            
            $stmt->bind_param('ssssii', $LangID, $AccountsTitleID, $SEntDate, $EEntDate, $Offset, $Limit);
            $LangID             = $lang;
            $AccountsTitleID    = $ID;
            $SEntDate           = $sdate;
            $EEntDate           = $edate;
            $Offset             = $offset;
            $Limit              = $limit;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        
        self::DBClose($mysqli);
        return $result;
    }
    
    // 残高データ用補助元帳を取得する
    public function gSubLedSearch($sdate, $edate, $cltid, $curid, $ctrlno, $ID, $segment, $CashBankflg = NULL, $ARDmtflg = NULL, $ARIntflg = NULL, 
            $StockSalesflg = NULL, $nonStockSalesflg = NULL, $PurchaseStockflg = NULL, $PurchasenonStockflg = NULL, $PurchaseServiceflg = NULL, $APDmtflg = NULL, $APIntflg = NULL, 
            $AccruedExpenseflg = NULL, $AROthersflg = NULL, $InputVATflg = NULL, $ServiceSalesflg = NULL, $InputVATNotSubjectCorporateTaxDeductionflg = NULL, $OutputVATflg = NULL, 
            $SuspenseInputVATflg = NULL, $SuspenseOutputVATflg = NULL, $WithholdingTaxflg = NULL, $WithheldTaxflg = NULL, $ImportDutyflg = NULL, $PayableCustomsflg = NULL, 
            $PayableRevDepflg = NULL, $ExchangeGainflg = NULL, $ExchangeLossflg = NULL) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_AccID     = self::sDataFlg('tmp', $ID, 'AccountsTitleID');
        $sql_SegmentID = self::sDataFlg('tmp', $segment, 'SegmentID');
        $sql_ControlNo = self::sDataFlg('tmp', $ctrlno, 'ControlNo');
        $sql_CurrencyID = self::sDataFlg('tmp', $curid, 'CurrencyID');
        
        $sql_CashBankflg = '';    // 現金・預金
        $sql_OmitCashBankflg = '';
        if ($CashBankflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitCashBankflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'CashBankflg');
        } else {
            $sql_CashBankflg = self::sDataFlgOr('m_accountstitles', $CashBankflg, 'CashBankflg');
        }
        $sql_ARDmtflg = '';    // 売掛金（国内）
        $sql_OmitARDmtflg = '';
        if ($ARDmtflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitARDmtflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'ARDmtflg');
        } else {
            $sql_ARDmtflg = self::sDataFlgOr('m_accountstitles', $ARDmtflg, 'ARDmtflg');
        }
        $sql_ARIntflg = '';    // 売掛金（国外）
        $sql_OmitARIntflg = '';
        if ($ARIntflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitARIntflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'ARIntflg');
        } else {
            $sql_ARIntflg = self::sDataFlgOr('m_accountstitles', $ARIntflg, 'ARIntflg');
        }
        $sql_StockSalesflg = '';    // 売上（国内）
        $sql_OmitStockSalesflg = '';
        if ($StockSalesflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitStockSalesflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'StockSalesflg');
        } else {
            $sql_StockSalesflg = self::sDataFlgOr('m_accountstitles', $StockSalesflg, 'StockSalesflg');
        }
        $sql_nonStockSalesflg = '';    // 売上（国外）
        $sql_OmitnonStockSalesflg = '';
        if ($nonStockSalesflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitnonStockSalesflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'nonStockSalesflg');
        } else {
            $sql_nonStockSalesflg = self::sDataFlgOr('m_accountstitles', $nonStockSalesflg, 'nonStockSalesflg');
        }
        $sql_PurchaseStockflg = '';    // 在庫品目購入
        $sql_OmitPurchaseStockflg = '';
        if ($PurchaseStockflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitPurchaseStockflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'PurchaseStockflg');
        } else {
            $sql_PurchaseStockflg = self::sDataFlgOr('m_accountstitles', $PurchaseStockflg, 'PurchaseStockflg');
        }
        $sql_PurchasenonStockflg = '';    // 非在庫品目購入
        $sql_OmitPurchasenonStockflg = '';
        if ($PurchasenonStockflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitPurchasenonStockflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'PurchasenonStockflg');
        } else {
            $sql_PurchasenonStockflg = self::sDataFlgOr('m_accountstitles', $PurchasenonStockflg, 'PurchasenonStockflg');
        }
        $sql_PurchaseServiceflg = '';    // 役務購入
        $sql_OmitPurchaseServiceflg = '';
        if ($PurchaseServiceflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitPurchaseServiceflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'PurchaseServiceflg');
        } else {
            $sql_PurchaseServiceflg = self::sDataFlgOr('m_accountstitles', $PurchaseServiceflg, 'PurchaseServiceflg');
        }
        $sql_APDmtflg = '';    // 買掛金（国内）
        $sql_OmitAPDmtflg = '';
        if ($APDmtflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitAPDmtflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'APDmtflg');
        } else {
            $sql_APDmtflg = self::sDataFlgOr('m_accountstitles', $APDmtflg, 'APDmtflg');
        }
        $sql_APIntflg = '';    // 買掛金（国外）
        $sql_OmitAPIntflg = '';
        if ($APIntflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitAPIntflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'APIntflg');
        } else {
            $sql_APIntflg = self::sDataFlgOr('m_accountstitles', $APIntflg, 'APIntflg');
        }
        $sql_AccruedExpenseflg = '';    // 未払費用
        $sql_OmitAccruedExpenseflg = '';
        if ($AccruedExpenseflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitAccruedExpenseflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'AccruedExpenseflg');
        } else {
            $sql_AccruedExpenseflg = self::sDataFlgOr('m_accountstitles', $AccruedExpenseflg, 'AccruedExpenseflg');
        }
        $sql_AROthersflg = '';    // 小口現金払い費用等
        $sql_OmitAROthersflg = '';
        if ($AROthersflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitAROthersflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'AROthersflg');
        } else {
            $sql_AROthersflg = self::sDataFlgOr('m_accountstitles', $AROthersflg, 'AROthersflg');
        }
        $sql_InputVATflg = '';    // 仕入VAT
        $sql_OmitInputVATflg = '';
        if ($InputVATflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitInputVATflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'InputVATflg');
        } else {
            $sql_InputVATflg = self::sDataFlgOr('m_accountstitles', $InputVATflg, 'InputVATflg');
        }
        $sql_ServiceSalesflg = '';    // 控除対象外仕入VAT
        $sql_OmitServiceSalesflg = '';
        if ($ServiceSalesflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitServiceSalesflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'ServiceSalesflg');
        } else {
            $sql_ServiceSalesflg = self::sDataFlgOr('m_accountstitles', $ServiceSalesflg, 'ServiceSalesflg');
        }
        $sql_InputVATNotSubjectCorporateTaxDeductionflg = '';    // 損金不算入仕入VAT
        $sql_OmitInputVATNotSubjectCorporateTaxDeductionflg = '';
        if ($InputVATNotSubjectCorporateTaxDeductionflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitInputVATNotSubjectCorporateTaxDeductionflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'InputVATNotSubjectCorporateTaxDeductionflg');
        } else {
            $sql_InputVATNotSubjectCorporateTaxDeductionflg = self::sDataFlgOr('m_accountstitles', $InputVATNotSubjectCorporateTaxDeductionflg, 'InputVATNotSubjectCorporateTaxDeductionflg');
        }
        $sql_OutputVATflg = '';    // 売上VAT
        $sql_OmitOutputVATflg = '';
        if ($OutputVATflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitOutputVATflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'OutputVATflg');
        } else {
            $sql_OutputVATflg = self::sDataFlgOr('m_accountstitles', $OutputVATflg, 'OutputVATflg');
        }
        $sql_SuspenseInputVATflg = '';    // 仕入VAT用中間勘定
        $sql_OmitSuspenseInputVATflg = '';
        if ($SuspenseInputVATflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitSuspenseInputVATflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'SuspenseInputVATflg');
        } else {
            $sql_SuspenseInputVATflg = self::sDataFlgOr('m_accountstitles', $SuspenseInputVATflg, 'SuspenseInputVATflg');
        }
        $sql_SuspenseOutputVATflg = '';    // 売上VAT用中間勘定
        $sql_OmitSuspenseOutputVATflg = '';
        if ($SuspenseOutputVATflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitSuspenseOutputVATflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'SuspenseOutputVATflg');
        } else {
            $sql_SuspenseOutputVATflg = self::sDataFlgOr('m_accountstitles', $SuspenseOutputVATflg, 'SuspenseOutputVATflg');
        }
        $sql_WithholdingTaxflg = '';    // 源泉徴収
        $sql_OmitWithholdingTaxflg = '';
        if ($WithholdingTaxflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitWithholdingTaxflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'WithholdingTaxflg');
        } else {
            $sql_WithholdingTaxflg = self::sDataFlgOr('m_accountstitles', $WithholdingTaxflg, 'WithholdingTaxflg');
        }
        $sql_WithheldTaxflg = '';    // 源泉徴収されたもの
        $sql_OmitWithheldTaxflg = '';
        if ($WithheldTaxflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitWithheldTaxflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'WithheldTaxflg');
        } else {
            $sql_WithheldTaxflg = self::sDataFlgOr('m_accountstitles', $WithheldTaxflg, 'WithheldTaxflg');
        }
        $sql_ImportDutyflg = '';    // 輸入関税
        $sql_OmitImportDutyflg = '';
        if ($ImportDutyflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitImportDutyflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'ImportDutyflg');
        } else {
            $sql_ImportDutyflg = self::sDataFlgOr('m_accountstitles', $ImportDutyflg, 'ImportDutyflg');
        }
        $sql_PayableCustomsflg = '';    // 税関への支払 or 未払
        $sql_OmitPayableCustomsflg = '';
        if ($PayableCustomsflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitPayableCustomsflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'PayableCustomsflg');
        } else {
            $sql_PayableCustomsflg = self::sDataFlgOr('m_accountstitles', $PayableCustomsflg, 'PayableCustomsflg');
        }
        $sql_PayableRevDepflg = '';    // 歳入局への未払
        $sql_OmitPayableRevDepflg = '';
        if ($PayableRevDepflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitPayableRevDepflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'PayableRevDepflg');
        } else {
            $sql_PayableRevDepflg = self::sDataFlgOr('m_accountstitles', $PayableRevDepflg, 'PayableRevDepflg');
        }
        $sql_ExchangeGainflg = '';    // 為替差益
        $sql_OmitExchangeGainflg = '';
        if ($ExchangeGainflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitExchangeGainflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'ExchangeGainflg');
        } else {
            $sql_ExchangeGainflg = self::sDataFlgOr('m_accountstitles', $ExchangeGainflg, 'ExchangeGainflg');
        }
        $sql_ExchangeLossflg = '';    // 為替差損
        $sql_OmitExchangeLossflg = '';
        if ($ExchangeLossflg == $this->CL['DF']->ClientNonCheck) {
            $sql_OmitExchangeLossflg = self::sDataFlgOr('m_accountstitles', $this->CL['DF']->ClientChecked, 'ExchangeLossflg');
        } else {
            $sql_ExchangeLossflg = self::sDataFlgOr('m_accountstitles', $ExchangeLossflg, 'ExchangeLossflg');
        }
        
        $sql  = 'SELECT ';
        $sql .= ' tmp.datasource ';
        $sql .= ',tmp.TransactionID ';
        $sql .= ',tmp.RevisionNo ';
        $sql .= ',tmp.TransactionDate ';
        $sql .= ',tmp.JournalKindID ';
        $sql .= ',tmp.TransactionKindID ';
        $sql .= ',tmp.AccountsTitleID ';
        $sql .= ',tmp.ClientID ';
        $sql .= ',tmp.CurrencyID ';
        $sql .= ',tmp.FxRate ';
        $sql .= ',tmp.FxAmount ';
        $sql .= ',tmp.TaxableAmount ';
        $sql .= ',tmp.SegmentID ';
        $sql .= ',tmp.ControlNo ';
        $sql .= ',tmp.DueDate ';
        $sql .= ',tmp.VATType ';
        $sql .= ',tmp.WHTType ';
        $sql .= ',tmp.DrCrFlg ';
        $sql .= ',tmp.Amount ';
        $sql .= ',tmp.Summary ';
        $sql .= ',tmp.ContraAccounts ';
        $sql .= ',tmp.Status ';
        $sql .= 'FROM ( ';
        $sql .= 'SELECT ';
        $sql .= ' \'0\' datasource ';
        $sql .= ',\'\' TransactionID ';
        $sql .= ',0 RevisionNo ';
        $sql .= ',\'\' TransactionDate ';
        $sql .= ',\'\' JournalKindID ';
        $sql .= ',\'\' TransactionKindID ';
        $sql .= ',AccountsTitleID ';
        $sql .= ',ClientID ';
        $sql .= ',CurrencyID ';
        $sql .= ',\'\' FxRate ';
        $sql .= ',FxAmount ';
        $sql .= ',\'\' TaxableAmount ';
        $sql .= ',SegmentID ';
        $sql .= ',ControlNo ';
        $sql .= ',\'\' DueDate ';
        $sql .= ',\'\' VATType ';
        $sql .= ',\'\' WHTType ';
        $sql .= ',\'\' DrCrFlg ';
        $sql .= ',Amount ';
        $sql .= ',Summary ';
        $sql .= ',\'\' ContraAccounts ';
        $sql .= ',Status ';
        $sql .= ' FROM m_openbaldetail ';
        $sql .= ' WHERE m_openbaldetail.STATUS=true ';
        $sql .= ' AND   m_openbaldetail.Amount<>0 ';
        $sql .= ' union ';
        $sql .= ' SELECT ';
        $sql .= ' \'1\' datasource ';
        $sql .= ',TransactionID ';
        $sql .= ',RevisionNo ';
        $sql .= ',TransactionDate ';
        $sql .= ',JournalKindID ';
        $sql .= ',TransactionKindID ';
        $sql .= ',AccountsTitleID ';
        $sql .= ',ClientID ';
        $sql .= ',CurrencyID ';
        $sql .= ',FxRate ';
        $sql .= ',FxAmount ';
        $sql .= ',TaxableAmount ';
        $sql .= ',SegmentID ';
        $sql .= ',ControlNo ';
        $sql .= ',DueDate ';
        $sql .= ',VATType ';
        $sql .= ',WHTType ';
        $sql .= ',DrCrFlg ';
        $sql .= ',Amount ';
        $sql .= ',Summary ';
        $sql .= ',ContraAccounts ';
        $sql .= ',Status ';
        $sql .= ' FROM t_subledger  ';
        $sql .= ' WHERE t_subledger.STATUS=true ';
        $sql .= ' ) tmp ';
        $sql .= 'WHERE tmp.ClientID         = ? ';      // $cltid
        $sql .= 'AND   tmp.TransactionDate  >= ? ';     // $sdate
        $sql .= 'AND   tmp.TransactionDate  <= ? ';     // $edate
        $sql .= $sql_AccID.' ';
        $sql .= $sql_SegmentID.' ';
        $sql .= $sql_ControlNo.' ';
        $sql .= $sql_CurrencyID.' ';
        $sql .= 'AND   tmp.AccountsTitleID in ( ';
        $sql .= 'select m_accountstitles.AccountsTitleID ';
        $sql .= 'from m_accountstitles ';
        $sql .= 'WHERE STATUS=true ';
        $sql .= 'AND (false ';
        $sql .= $sql_CashBankflg.' ';
        $sql .= $sql_ARDmtflg.' ';
        $sql .= $sql_ARIntflg.' ';
        $sql .= $sql_StockSalesflg.' ';
        $sql .= $sql_nonStockSalesflg.' ';
        $sql .= $sql_PurchaseStockflg.' ';
        $sql .= $sql_PurchasenonStockflg.' ';
        $sql .= $sql_PurchaseServiceflg.' ';
        $sql .= $sql_APDmtflg.' ';
        $sql .= $sql_APIntflg.' ';
        $sql .= $sql_AccruedExpenseflg.' ';
        $sql .= $sql_AROthersflg.' ';
        $sql .= $sql_InputVATflg.' ';
        $sql .= $sql_ServiceSalesflg.' ';
        $sql .= $sql_InputVATNotSubjectCorporateTaxDeductionflg.' ';
        $sql .= $sql_OutputVATflg.' ';
        $sql .= $sql_SuspenseInputVATflg.' ';
        $sql .= $sql_SuspenseOutputVATflg.' ';
        $sql .= $sql_WithholdingTaxflg.' ';
        $sql .= $sql_WithheldTaxflg.' ';
        $sql .= $sql_ImportDutyflg.' ';
        $sql .= $sql_PayableCustomsflg.' ';
        $sql .= $sql_PayableRevDepflg.' ';
        $sql .= $sql_ExchangeGainflg.' ';
        $sql .= $sql_ExchangeLossflg.' ';
        $sql .= ') ';
        $sql .= 'AND (NOT (false ';
        $sql .= $sql_OmitCashBankflg.' ';
        $sql .= $sql_OmitARDmtflg.' ';
        $sql .= $sql_OmitARIntflg.' ';
        $sql .= $sql_OmitStockSalesflg.' ';
        $sql .= $sql_OmitnonStockSalesflg.' ';
        $sql .= $sql_OmitPurchaseStockflg.' ';
        $sql .= $sql_OmitPurchasenonStockflg.' ';
        $sql .= $sql_OmitPurchaseServiceflg.' ';
        $sql .= $sql_OmitAPDmtflg.' ';
        $sql .= $sql_OmitAPIntflg.' ';
        $sql .= $sql_OmitAccruedExpenseflg.' ';
        $sql .= $sql_OmitAROthersflg.' ';
        $sql .= $sql_OmitInputVATflg.' ';
        $sql .= $sql_OmitServiceSalesflg.' ';
        $sql .= $sql_OmitInputVATNotSubjectCorporateTaxDeductionflg.' ';
        $sql .= $sql_OmitOutputVATflg.' ';
        $sql .= $sql_OmitSuspenseInputVATflg.' ';
        $sql .= $sql_OmitSuspenseOutputVATflg.' ';
        $sql .= $sql_OmitWithholdingTaxflg.' ';
        $sql .= $sql_OmitWithheldTaxflg.' ';
        $sql .= $sql_OmitImportDutyflg.' ';
        $sql .= $sql_OmitPayableCustomsflg.' ';
        $sql .= $sql_OmitPayableRevDepflg.' ';
        $sql .= $sql_OmitExchangeGainflg.' ';
        $sql .= $sql_OmitExchangeLossflg.' ';
        $sql .= ')) ';
        $sql .= ') ';
        $sql .= ' ORDER BY  ';
        $sql .= ' tmp.ControlNo ';
        $sql .= ',tmp.AccountsTitleID ';
        $sql .= ',tmp.SegmentID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            
            $stmt->bind_param('sss', $ClientID, $SEntDate, $EEntDate);
            $ClientID           = $cltid;
            $SEntDate           = $sdate;
            $EEntDate           = $edate;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_generalledger*u_client                               */
/*--------------------------------------------------------*/
    // 元帳を取得する(全件)
    public function gLedList($ID, $sdate, $edate, $drcr, $pageRowText, $pages, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_DrCr = self::sDataFlg('t_generalledger', $drcr, 'DrCrFlg');
        
        $array  = self::sLimit($pageRowText, $pages);                         // 検索条件(ページング)
        $offset = $array[0];
        $limit  = $array[1];
        
        $sql  = 'SELECT t_generalledger.LedgerNo, ';
        $sql .= 't_generalledger.TransactionID, ';
        $sql .= 't_generalledger.RevisionNo, ';
        $sql .= 't_generalledger.Line, ';
        $sql .= 't_generalledger.JournalKindID, ';
        $sql .= 'm_const1.ConstVal1 JournalKindName, ';
        $sql .= 'm_const1.ConstVal3 JournalProgram, ';
        $sql .= 't_generalledger.TransactionKindID, ';
        $sql .= 't_generalledger.TransactionDate, ';
        $sql .= 't_generalledger.AccountsTitleID, ';
        $sql .= 't_generalledger.ContraAccounts, ';
        $sql .= 't_generalledger.DrCrFlg, ';
        $sql .= 't_generalledger.Amount, ';
        $sql .= 't_generalledger.ClientID, ';
        $sql .= 'u_client.ClientName, ';
        $sql .= 't_generalledger.Summary, ';
        $sql .= 't_generalledger.Status ';
        $sql .= 'FROM t_generalledger ';
        $sql .= 'LEFT JOIN m_const AS m_const1 ';
        $sql .= 'ON m_const1.ConstID1=\''.$this->CL['DF']->JNLKIND.'\'  ';
        $sql .= 'AND m_const1.ConstID2=t_generalledger.JournalKindID ';
        $sql .= 'AND m_const1.LanguageID = ? ';
        $sql .= 'LEFT JOIN u_client ';
        $sql .= 'ON  u_client.ClientID=t_generalledger.ClientID ';
        $sql .= 'AND u_client.LanguageID=m_const1.LanguageID ';
        $sql .= 'AND u_client.Status=TRUE  ';
        $sql .= 'WHERE t_generalledger.AccountsTitleID = ? ';
        $sql .= 'AND   t_generalledger.TransactionDate  >= ? ';    // $sdate
        $sql .= 'AND   t_generalledger.TransactionDate  <= ? ';    // $edate
        $sql .= $sql_DrCr.' ';
        $sql .= 'ORDER BY  ';
        $sql .= 't_generalledger.AccountsTitleID, ';
        $sql .= 't_generalledger.TransactionDate, ';
        $sql .= 't_generalledger.LedgerNo ';
        $sql .= 'LIMIT ?, ? ';    // $offset, $limit

        
        if ($stmt = $mysqli->prepare($sql)) {
            
            $stmt->bind_param('ssssii', $LangID, $AccountsTitleID, $SEntDate, $EEntDate, $Offset, $Limit);
            $LangID             = $lang;
            $AccountsTitleID    = $ID;
            $SEntDate           = $sdate;
            $EEntDate           = $edate;
            $Offset             = $offset;
            $Limit              = $limit;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_monthlyconfirm                                       */
/*--------------------------------------------------------*/
    // 月次確定ステータスを追加する
    public function iMoCfmInfo($TrnKindID, $year, $month, $sts, $s_userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_monthlyconfirm(MonthlyConfirmYear, MonthlyConfirmMonth, MonthlyConfirmStatus, TransactionKindID, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $year
        $sql .= ',? ';    // $month
        $sql .= ',? ';    // $sts
        $sql .= ',? ';    // $TrnKindID
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $s_userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $s_userid
        $sql .= ',true ) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssss', $MonthlyConfirmYear, $MonthlyConfirmMonth, $MonthlyConfirmStatus, $TransactionKindID, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $MonthlyConfirmYear   = $year;
            $MonthlyConfirmMonth  = $month;
            $MonthlyConfirmStatus = $sts;
            $TransactionKindID    = $TrnKindID;
            $EntDate              = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser              = $s_userid;
            $UpdDate              = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser              = $s_userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 月次確定ステータスを更新する
    public function uMoCfmSts($TrnKindID, $year, $month, $sts, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql_TrnKindID = self::sTrnKindID('t_monthlyconfirm', $TrnKindID);    // 検索条件(取引種別)
        
        $sql  = 'UPDATE t_monthlyconfirm ';
        $sql .= 'SET    MonthlyConfirmStatus = ? ';    // $sts
        $sql .= '     , UpdDate              = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser              = ? ';    // $userid
        $sql .= 'WHERE  MonthlyConfirmYear   = ? ';    // $year
        $sql .= 'AND    MonthlyConfirmMonth  = ? ';    // $month
        $sql .= 'AND    Status               = true ';
        $sql .= $sql_TrnKindID.' ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssss', $MonthlyConfirmStatus, $UpdDate, $UpdUser, $MonthlyConfirmYear, $MonthlyConfirmMonth);
            $MonthlyConfirmStatus = $sts;
            $UpdDate              = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser              = $userid;
            $MonthlyConfirmYear   = $year;
            $MonthlyConfirmMonth  = $month;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 月次確定ステータスを取得する(一覧)
    public function gMoCfmList($TrnKindID, $MoCfmSts) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_TrnKindID = self::sTrnKindID('t_monthlyconfirm', $TrnKindID);    // 検索条件(取引種別)
        
        $sql  = 'SELECT distinct ';
        $sql .= '       MonthlyConfirmYear ';
        $sql .= '     , MonthlyConfirmMonth ';
        $sql .= 'FROM   t_monthlyconfirm ';
        $sql .= 'WHERE  MonthlyConfirmStatus >= ? ';    // $MoCfmSts
        $sql .= 'AND    Status                = true ';
        $sql .= $sql_TrnKindID.' ';
        $sql .= 'ORDER BY MonthlyConfirmYear, RIGHT(CONCAT(\'00\', MonthlyConfirmMonth), 2) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $MonthlyConfirmStatus);
            $MonthlyConfirmStatus = $MoCfmSts;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 取引仕訳/決算整理仕訳が月次確定している年月を取得する(一覧)
    public function gMoCfmTrdList() {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_Sub_Trd  = '( ';
        $sql_Sub_Trd .= '    SELECT MonthlyConfirmYear ';
        $sql_Sub_Trd .= '         , MonthlyConfirmMonth ';
        $sql_Sub_Trd .= '         , TransactionKindID ';
        $sql_Sub_Trd .= '         , MonthlyConfirmStatus ';
        $sql_Sub_Trd .= '    FROM   t_monthlyconfirm ';
        $sql_Sub_Trd .= '    WHERE  TransactionKindID     = ? ';    // $this->CL['DF']->trd
        $sql_Sub_Trd .= '    AND    MonthlyConfirmStatus >= ? ';    // $this->CL['DF']->cfmSts_Cls
        $sql_Sub_Trd .= '    AND    Status                = true ';
        $sql_Sub_Trd .= ') AS Sub_Trd ';
        
        $sql_Sub_Adj  = '( ';
        $sql_Sub_Adj .= '    SELECT MonthlyConfirmYear ';
        $sql_Sub_Adj .= '         , MonthlyConfirmMonth ';
        $sql_Sub_Adj .= '         , TransactionKindID ';
        $sql_Sub_Adj .= '         , MonthlyConfirmStatus ';
        $sql_Sub_Adj .= '    FROM   t_monthlyconfirm ';
        $sql_Sub_Adj .= '    WHERE  TransactionKindID     = ? ';    // $this->CL['DF']->adj
        $sql_Sub_Adj .= '    AND    MonthlyConfirmStatus >= ? ';    // $this->CL['DF']->cfmSts_Cls
        $sql_Sub_Adj .= '    AND    Status                = true ';
        $sql_Sub_Adj .= ') AS Sub_Adj ';
        
        $sql  = 'SELECT Sub_Trd.MonthlyConfirmYear ';
        $sql .= '     , Sub_Trd.MonthlyConfirmMonth ';
        $sql .= '     , Sub_Trd.TransactionKindID ';
        $sql .= '     , Sub_Adj.TransactionKindID ';
        $sql .= '     , Sub_Trd.MonthlyConfirmStatus ';
        $sql .= '     , Sub_Adj.MonthlyConfirmStatus ';
        $sql .= 'FROM '.$sql_Sub_Trd.' ';
        $sql .= '    ,'.$sql_Sub_Adj.' ';
        $sql .= 'WHERE Sub_Trd.MonthlyConfirmYear  = Sub_Adj.MonthlyConfirmYear ';
        $sql .= 'AND   Sub_Trd.MonthlyConfirmMonth = Sub_Adj.MonthlyConfirmMonth ';
        $sql .= 'ORDER BY Sub_Adj.MonthlyConfirmYear, RIGHT(CONCAT(\'00\', Sub_Adj.MonthlyConfirmMonth), 2) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssss', $TrdTransactionKindID, $TrdMonthlyConfirmStatus, $AdjTransactionKindID, $AdjMonthlyConfirmStatus);
            $TrdTransactionKindID    = $this->CL['DF']->trd;
            $TrdMonthlyConfirmStatus = $this->CL['DF']->cfmSts_Cls;
            $AdjTransactionKindID    = $this->CL['DF']->adj;
            $AdjMonthlyConfirmStatus = $this->CL['DF']->cfmSts_Cls;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 月次確定ステータスの最小年月を取得する(一件)
    public function gMoCfmMinYMRow($TrnKindID, $sts) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_Sub_Cfm  = '( ';
        $sql_Sub_Cfm .= '    SELECT MIN(CAST(MonthlyConfirmYear AS SIGNED)) AS Year ';
        $sql_Sub_Cfm .= '    FROM  t_monthlyconfirm ';
        $sql_Sub_Cfm .= '    WHERE MonthlyConfirmStatus = ? ';    // $sts
        $sql_Sub_Cfm .= '    AND   Status               = true ';
        $sql_Sub_Cfm .= ') As Sub_Cfm ';
        
        $sql  = 'SELECT t_monthlyconfirm.MonthlyConfirmYear AS Year ';
        $sql .= '     , MIN(CAST(t_monthlyconfirm.MonthlyConfirmMonth AS SIGNED)) AS Month ';
        $sql .= 'FROM   t_monthlyconfirm ';
        $sql .= '     , '.$sql_Sub_Cfm.' ';
        $sql .= 'WHERE  t_monthlyconfirm.MonthlyConfirmYear = Sub_Cfm.Year ';
        $sql .= 'AND    MonthlyConfirmStatus                = ? ';    // $sts
        $sql .= 'AND    TransactionKindID                   = ? ';    // $TrnKindID
        $sql .= 'AND    Status                              = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $SubMonthlyConfirmStatus, $CfmMonthlyConfirmStatus, $TransactionKindID);
            $SubMonthlyConfirmStatus = $sts;
            $CfmMonthlyConfirmStatus = $sts;
            $TransactionKindID       = $TrnKindID;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 月次確定ステータスの最大年月を取得する(一件)
    public function gMoCfmMaxYMRow($TrnKindID, $sts) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_Sub_Cfm  = '( ';
        $sql_Sub_Cfm .= '    SELECT MAX(CAST(MonthlyConfirmYear AS SIGNED)) AS Year ';
        $sql_Sub_Cfm .= '    FROM  t_monthlyconfirm ';
        $sql_Sub_Cfm .= '    WHERE MonthlyConfirmStatus >= ? ';    // $sts
        $sql_Sub_Cfm .= '    AND    TransactionKindID                   = ? ';    // $TrnKindID
        $sql_Sub_Cfm .= '    AND   Status               = true ';
//        $sql_Sub_Cfm .= ') As Sub_Cfm ';
        $sql_Sub_Cfm .= ') ';
        
        $sql  = 'SELECT t_monthlyconfirm.MonthlyConfirmYear AS Year ';
        $sql .= '     , MAX(CAST(t_monthlyconfirm.MonthlyConfirmMonth AS SIGNED)) AS Month ';
        $sql .= 'FROM   t_monthlyconfirm ';
//        $sql .= '     , '.$sql_Sub_Cfm.' ';
//        $sql .= 'WHERE  t_monthlyconfirm.MonthlyConfirmYear = Sub_Cfm.Year ';
        $sql .= 'WHERE  t_monthlyconfirm.MonthlyConfirmYear in '.$sql_Sub_Cfm.' ';
        $sql .= 'AND    MonthlyConfirmStatus                >= ? ';    // $sts
        $sql .= 'AND    TransactionKindID                   = ? ';    // $TrnKindID
        $sql .= 'AND    Status                              = true ';
        $sql .= 'GROUP BY t_monthlyconfirm.MonthlyConfirmYear ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssss', $SubMonthlyConfirmStatus, $SubTransactionKindID, $CfmMonthlyConfirmStatus, $TransactionKindID);
            $SubMonthlyConfirmStatus = $sts;
            $SubTransactionKindID    = $TrnKindID;
            $CfmMonthlyConfirmStatus = $sts;
            $TransactionKindID       = $TrnKindID;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_monthlyconfirm*u_user*m_const                        */
/*--------------------------------------------------------*/
    // 月次確定ステータスを取得する(一件)
    public function gMoCfmRow($TrnKindID, $year, $month, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_Sub_cfmsts  = '( ';
        $sql_Sub_cfmsts .= '    SELECT ConstVal1, ConstID2 ';
        $sql_Sub_cfmsts .= '    FROM   m_const ';
        $sql_Sub_cfmsts .= '    WHERE  ConstID1   = ? ';    // $this->CL['DF']->CFMSTS
        $sql_Sub_cfmsts .= '    AND    LanguageID = ? ';    // $lang
        $sql_Sub_cfmsts .= '    AND    Status     = true ';
        $sql_Sub_cfmsts .= ') AS Sub_cfmsts ';
        
        $sql  = 'SELECT t_monthlyconfirm.MonthlyConfirmStatus AS MonthlyConfirmStatus ';
        $sql .= '     , t_monthlyconfirm.MonthlyConfirmYear AS MonthlyConfirmYear ';
        $sql .= '     , t_monthlyconfirm.MonthlyConfirmMonth AS MonthlyConfirmMonth ';
        $sql .= '     , Sub_cfmsts.ConstVal1 AS MonthlyConfirmStatusName ';
        $sql .= '     , u_user.UserName AS UserName ';
        $sql .= '     , t_monthlyconfirm.UpdDate AS UpdDate ';
        $sql .= 'FROM   t_monthlyconfirm ';
        $sql .= '     , u_user ';
        $sql .= '     , '.$sql_Sub_cfmsts.' ';
        $sql .= 'WHERE  t_monthlyconfirm.MonthlyConfirmStatus = Sub_cfmsts.ConstID2 ';
        $sql .= 'AND    t_monthlyconfirm.UpdUser              = u_user.UserID ';
        $sql .= 'AND    t_monthlyconfirm.TransactionKindID    = ? ';    // $TrnKindID
        $sql .= 'AND    t_monthlyconfirm.MonthlyConfirmYear   = ? ';    // $year
        $sql .= 'AND    t_monthlyconfirm.MonthlyConfirmMonth  = ? ';    // (int)$month
        $sql .= 'AND    t_monthlyconfirm.STATUS               = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssss', $ConstID1, $LanguageID, $TransactionKindID, $MonthlyConfirmYear, $MonthlyConfirmMonth);
            $ConstID1             = $this->CL['DF']->CFMSTS;
            $LanguageID           = $lang;
            $TransactionKindID    = $TrnKindID;
            $MonthlyConfirmYear   = $year;
            $MonthlyConfirmMonth  = (int)$month;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_monthlyconfirm*t_transaction                         */
/*--------------------------------------------------------*/
    // 指定された期間の各月の取引仕訳・修正仕訳に関して状態（未承認、承認、転記済、確認済、決算済）の伝票件数を取得する
    public function gCfmStsCntList($from, $to) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT CONCAT(c.monthlyconfirmyear, right(CONCAT(\'0\',c.MonthlyConfirmMonth), 2)) AS yearmonth ';
        $sql .= '    , c.monthlyconfirmyear  ';
        $sql .= '    , c.MonthlyConfirmMonth ';
        $sql .= '    , c.TransactionKindID  ';
        $sql .= '    , c.MonthlyConfirmStatus ';
        $sql .= '    , ifnull(t0.cnt, 0) AS UnapproveCNT ';
        $sql .= '    , ifnull(t1.cnt, 0) AS ApprovedCNT ';
        $sql .= '    , ifnull(t2.cnt, 0) AS PostedCNT ';
        $sql .= '    , ifnull(t3.cnt, 0) AS ConfirmCNT ';
        $sql .= '    , ifnull(t4.cnt, 0) AS CloseCNT ';
        $sql .= 'FROM t_monthlyconfirm c ';
        $sql .= 'LEFT JOIN ( ';
        $sql .= '    SELECT SUBSTRING(TransactionDate, 1, 6) yearmonth0, TransactionKindID, COUNT(*) cnt FROM t_transaction  ';
        $sql .= '    WHERE Status = TRUE ';
        $sql .= '    AND t_transaction.TransactionStatusID = ? ';       // $this->CL['DF']->trnSts_Unapprove
        $sql .= '    GROUP BY yearmonth0, TransactionKindID, TransactionStatusID ';
        $sql .= ') t0 ON CONCAT(c.monthlyconfirmyear, right(CONCAT(\'0\',c.MonthlyConfirmMonth), 2)) = t0.yearmonth0 AND c.TransactionKindID=t0.TransactionKindID ';
        $sql .= 'LEFT JOIN ( ';
        $sql .= '    SELECT SUBSTRING(TransactionDate, 1, 6) yearmonth0, TransactionKindID, COUNT(*) cnt FROM t_transaction  ';
        $sql .= '    WHERE Status = TRUE ';
        $sql .= '    AND t_transaction.TransactionStatusID = ? ';       // $this->CL['DF']->trnSts_Approved;
        $sql .= '    GROUP BY yearmonth0, TransactionKindID, TransactionStatusID ';
        $sql .= ') t1 ON CONCAT(c.monthlyconfirmyear, right(CONCAT(\'0\',c.MonthlyConfirmMonth), 2)) = t1.yearmonth0 AND c.TransactionKindID=t1.TransactionKindID ';
        $sql .= 'LEFT JOIN ( ';
        $sql .= '    SELECT SUBSTRING(TransactionDate, 1, 6) yearmonth0, TransactionKindID, COUNT(*) cnt FROM t_transaction  ';
        $sql .= '    WHERE Status = TRUE ';
        $sql .= '    AND t_transaction.TransactionStatusID = ? ';       // $this->CL['DF']->trnSts_Posted;
        $sql .= '    GROUP BY yearmonth0, TransactionKindID, TransactionStatusID ';
        $sql .= ') t2 ON CONCAT(c.monthlyconfirmyear, right(CONCAT(\'0\',c.MonthlyConfirmMonth), 2)) = t2.yearmonth0 AND c.TransactionKindID=t2.TransactionKindID ';
        $sql .= 'LEFT JOIN ( ';
        $sql .= '    SELECT SUBSTRING(TransactionDate, 1, 6) yearmonth0, TransactionKindID, COUNT(*) cnt FROM t_transaction  ';
        $sql .= '    WHERE Status = TRUE ';
        $sql .= '    AND t_transaction.TransactionStatusID = ? ';       // $this->CL['DF']->trnSts_Confirm;
        $sql .= '    GROUP BY yearmonth0, TransactionKindID, TransactionStatusID ';
        $sql .= ') t3 ON CONCAT(c.monthlyconfirmyear, right(CONCAT(\'0\',c.MonthlyConfirmMonth), 2)) = t3.yearmonth0 AND c.TransactionKindID=t3.TransactionKindID ';
        $sql .= 'LEFT JOIN ( ';
        $sql .= '    SELECT SUBSTRING(TransactionDate, 1, 6) yearmonth0, TransactionKindID, COUNT(*) cnt FROM t_transaction  ';
        $sql .= '    WHERE Status = TRUE ';
        $sql .= '    AND t_transaction.TransactionStatusID = ? ';       // $this->CL['DF']->trnSts_Close;
        $sql .= '    GROUP BY yearmonth0, TransactionKindID, TransactionStatusID ';
        $sql .= ') t4 ON CONCAT(c.monthlyconfirmyear, right(CONCAT(\'0\',c.MonthlyConfirmMonth), 2)) = t4.yearmonth0 AND c.TransactionKindID=t4.TransactionKindID ';
        $sql .= 'WHERE c.Status=true ';
        $sql .= 'AND CONCAT(c.monthlyconfirmyear, right(CONCAT(\'0\',c.MonthlyConfirmMonth), 2)) >= ? ';      // $from
        $sql .= 'AND CONCAT(c.monthlyconfirmyear, right(CONCAT(\'0\',c.MonthlyConfirmMonth), 2)) <= ? ';      // $to
        $sql .= 'ORDER BY yearmonth, TransactionKindID  ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssss', $Unapprove, $Approved, $Posted, $Confirm, $Close, $From, $To);
            $Unapprove  = $this->CL['DF']->trnSts_Unapprove;
            $Approved   = $this->CL['DF']->trnSts_Approved;
            $Posted     = $this->CL['DF']->trnSts_Posted;
            $Confirm    = $this->CL['DF']->trnSts_Confirm;
            $Close      = $this->CL['DF']->trnSts_Close;
            $From       = $from;
            $To         = $to;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }

/*--------------------------------------------------------*/
/* m_accountskind_1                                       */
/*--------------------------------------------------------*/
    // 勘定科目種別情報(1)を取得する(一覧)
    public function gAccKind1NameList($lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT AccountsKind1ID ';
        $sql .= '     , AccountsKind1Name ';
        $sql .= 'FROM   m_accountskind_1 ';
        $sql .= 'WHERE  LanguageID = ? ';    // $lang
        $sql .= 'AND    Status     = true ';
        $sql .= 'ORDER BY AccountsKind1ID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $LanguageID);
            $LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* m_accountskind_1*m_accountskind_2                      */
/*--------------------------------------------------------*/
    // 勘定科目種別情報(2)を取得する(一覧)
    public function gAccKind2NameList($lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT m_accountskind_1.AccountsKind1ID ';
        $sql .= '     , m_accountskind_1.AccountsKind1Name ';
        $sql .= '     , m_accountskind_2.AccountsKind2ID ';
        $sql .= '     , m_accountskind_2.AccountsKind2Name ';
        $sql .= 'FROM   m_accountskind_1 ';
        $sql .= '     , m_accountskind_2 ';
        $sql .= 'WHERE  m_accountskind_1.AccountsKind1ID = m_accountskind_2.AccountsKind1ID ';
        $sql .= 'AND    m_accountskind_1.LanguageID      = ? ';    // $lang
        $sql .= 'AND    m_accountskind_2.LanguageID      = ? ';    // $lang
        $sql .= 'AND    m_accountskind_1.Status          = true ';
        $sql .= 'AND    m_accountskind_2.Status          = true ';
        $sql .= 'ORDER BY m_accountskind_1.AccountsKind1ID, m_accountskind_2.AccountsKind2ID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $K1LanguageID, $K2LanguageID);
            $K1LanguageID = $lang;
            $K2LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* m_accountskind_1*m_accountskind_2*m_accountskind_3     */
/*--------------------------------------------------------*/
    // 勘定科目種別情報(3)を取得する(一覧)
    public function gAccKind3NameList($lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT m_accountskind_1.AccountsKind1ID ';
        $sql .= '     , m_accountskind_1.AccountsKind1Name ';
        $sql .= '     , m_accountskind_2.AccountsKind2ID ';
        $sql .= '     , m_accountskind_2.AccountsKind2Name ';
        $sql .= '     , m_accountskind_3.AccountsKind3ID ';
        $sql .= '     , m_accountskind_3.AccountsKind3Name ';
        $sql .= 'FROM   m_accountskind_1 ';
        $sql .= '     , m_accountskind_2 ';
        $sql .= '     , m_accountskind_3 ';
        $sql .= 'WHERE  m_accountskind_1.AccountsKind1ID = m_accountskind_2.AccountsKind1ID ';
        $sql .= 'AND    m_accountskind_1.AccountsKind1ID = m_accountskind_3.AccountsKind1ID ';
        $sql .= 'AND    m_accountskind_2.AccountsKind2ID = m_accountskind_3.AccountsKind2ID ';
        $sql .= 'AND    m_accountskind_1.LanguageID      = ? ';    // $lang
        $sql .= 'AND    m_accountskind_2.LanguageID      = ? ';    // $lang
        $sql .= 'AND    m_accountskind_3.LanguageID      = ? ';    // $lang
        $sql .= 'AND    m_accountskind_1.Status          = true ';
        $sql .= 'AND    m_accountskind_2.Status          = true ';
        $sql .= 'AND    m_accountskind_3.Status          = true ';
        $sql .= 'ORDER BY m_accountskind_1.AccountsKind1ID, m_accountskind_2.AccountsKind2ID, m_accountskind_3.AccountsKind3ID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $K1LanguageID, $K2LanguageID, $K3LanguageID);
            $K1LanguageID = $lang;
            $K2LanguageID = $lang;
            $K3LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* m_accountskind_1*m_accountskind_2*m_accountskind_3     */
/* m_accountskind_4                                       */
/*--------------------------------------------------------*/
    // 勘定科目種別情報(4)を取得する(一覧)
    public function gAccKind4NameList($lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT m_accountskind_1.AccountsKind1ID ';
        $sql .= '     , m_accountskind_1.AccountsKind1Name ';
        $sql .= '     , m_accountskind_2.AccountsKind2ID ';
        $sql .= '     , m_accountskind_2.AccountsKind2Name ';
        $sql .= '     , m_accountskind_3.AccountsKind3ID ';
        $sql .= '     , m_accountskind_3.AccountsKind3Name ';
        $sql .= '     , m_accountskind_4.AccountsKind4ID ';
        $sql .= '     , m_accountskind_4.AccountsKind4Name ';
        $sql .= 'FROM   m_accountskind_1 ';
        $sql .= '     , m_accountskind_2 ';
        $sql .= '     , m_accountskind_3 ';
        $sql .= '     , m_accountskind_4 ';
        $sql .= 'WHERE  m_accountskind_1.AccountsKind1ID = m_accountskind_2.AccountsKind1ID ';
        $sql .= 'AND    m_accountskind_1.AccountsKind1ID = m_accountskind_3.AccountsKind1ID ';
        $sql .= 'AND    m_accountskind_2.AccountsKind2ID = m_accountskind_3.AccountsKind2ID ';
        $sql .= 'AND    m_accountskind_1.AccountsKind1ID = m_accountskind_4.AccountsKind1ID ';
        $sql .= 'AND    m_accountskind_2.AccountsKind2ID = m_accountskind_4.AccountsKind2ID ';
        $sql .= 'AND    m_accountskind_3.AccountsKind3ID = m_accountskind_4.AccountsKind3ID ';
        $sql .= 'AND    m_accountskind_1.LanguageID      = ? ';    // $lang
        $sql .= 'AND    m_accountskind_2.LanguageID      = ? ';    // $lang
        $sql .= 'AND    m_accountskind_3.LanguageID      = ? ';    // $lang
        $sql .= 'AND    m_accountskind_4.LanguageID      = ? ';    // $lang
        $sql .= 'AND    m_accountskind_1.Status          = true ';
        $sql .= 'AND    m_accountskind_2.Status          = true ';
        $sql .= 'AND    m_accountskind_3.Status          = true ';
        $sql .= 'AND    m_accountskind_4.Status          = true ';
        $sql .= 'ORDER BY m_accountskind_1.AccountsKind1ID, m_accountskind_2.AccountsKind2ID, m_accountskind_3.AccountsKind3ID, m_accountskind_4.AccountsKind4ID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssss', $K1LanguageID, $K2LanguageID, $K3LanguageID, $K4LanguageID);
            $K1LanguageID = $lang;
            $K2LanguageID = $lang;
            $K3LanguageID = $lang;
            $K4LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* m_accountskind_1*m_accountskind_2*m_accountskind_3     */
/* m_accountskind_4*m_accountskind_5                      */
/*--------------------------------------------------------*/
    // 勘定科目種別情報(5)を取得する(一覧)
    public function gAccKind5NameList($lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT m_accountskind_1.AccountsKind1ID ';
        $sql .= '     , m_accountskind_1.AccountsKind1Name ';
        $sql .= '     , m_accountskind_2.AccountsKind2ID ';
        $sql .= '     , m_accountskind_2.AccountsKind2Name ';
        $sql .= '     , m_accountskind_3.AccountsKind3ID ';
        $sql .= '     , m_accountskind_3.AccountsKind3Name ';
        $sql .= '     , m_accountskind_4.AccountsKind4ID ';
        $sql .= '     , m_accountskind_4.AccountsKind4Name ';
        $sql .= '     , m_accountskind_5.AccountsKind5ID ';
        $sql .= '     , m_accountskind_5.AccountsKind5Name ';
        $sql .= '     , m_accountskind_5.DrCrFlg ';
        $sql .= 'FROM   m_accountskind_1 ';
        $sql .= '     , m_accountskind_2 ';
        $sql .= '     , m_accountskind_3 ';
        $sql .= '     , m_accountskind_4 ';
        $sql .= '     , m_accountskind_5 ';
        $sql .= 'WHERE  m_accountskind_1.AccountsKind1ID = m_accountskind_2.AccountsKind1ID ';
        $sql .= 'AND    m_accountskind_1.AccountsKind1ID = m_accountskind_3.AccountsKind1ID ';
        $sql .= 'AND    m_accountskind_2.AccountsKind2ID = m_accountskind_3.AccountsKind2ID ';
        $sql .= 'AND    m_accountskind_1.AccountsKind1ID = m_accountskind_4.AccountsKind1ID ';
        $sql .= 'AND    m_accountskind_2.AccountsKind2ID = m_accountskind_4.AccountsKind2ID ';
        $sql .= 'AND    m_accountskind_3.AccountsKind3ID = m_accountskind_4.AccountsKind3ID ';
        $sql .= 'AND    m_accountskind_1.AccountsKind1ID = m_accountskind_5.AccountsKind1ID ';
        $sql .= 'AND    m_accountskind_2.AccountsKind2ID = m_accountskind_5.AccountsKind2ID ';
        $sql .= 'AND    m_accountskind_3.AccountsKind3ID = m_accountskind_5.AccountsKind3ID ';
        $sql .= 'AND    m_accountskind_4.AccountsKind4ID = m_accountskind_5.AccountsKind4ID ';
        $sql .= 'AND    m_accountskind_1.LanguageID      = ? ';    // $lang
        $sql .= 'AND    m_accountskind_2.LanguageID      = ? ';    // $lang
        $sql .= 'AND    m_accountskind_3.LanguageID      = ? ';    // $lang
        $sql .= 'AND    m_accountskind_4.LanguageID      = ? ';    // $lang
        $sql .= 'AND    m_accountskind_5.LanguageID      = ? ';    // $lang
        $sql .= 'AND    m_accountskind_1.Status          = true ';
        $sql .= 'AND    m_accountskind_2.Status          = true ';
        $sql .= 'AND    m_accountskind_3.Status          = true ';
        $sql .= 'AND    m_accountskind_4.Status          = true ';
        $sql .= 'AND    m_accountskind_5.Status          = true ';
        $sql .= 'ORDER BY m_accountskind_1.AccountsKind1ID, m_accountskind_2.AccountsKind2ID, m_accountskind_3.AccountsKind3ID, m_accountskind_4.AccountsKind4ID, m_accountskind_5.AccountsKind5ID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssss', $K1LanguageID, $K2LanguageID, $K3LanguageID, $K4LanguageID, $K5LanguageID);
            $K1LanguageID = $lang;
            $K2LanguageID = $lang;
            $K3LanguageID = $lang;
            $K4LanguageID = $lang;
            $K5LanguageID = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 勘定科目種別情報(5)を取得する(一件)
    public function gAccKind5NameRow($kind1, $kind2, $kind3, $kind4, $kind5, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT m_accountskind_1.AccountsKind1ID ';
        $sql .= '     , m_accountskind_1.AccountsKind1Name ';
        $sql .= '     , m_accountskind_2.AccountsKind2ID ';
        $sql .= '     , m_accountskind_2.AccountsKind2Name ';
        $sql .= '     , m_accountskind_3.AccountsKind3ID ';
        $sql .= '     , m_accountskind_3.AccountsKind3Name ';
        $sql .= '     , m_accountskind_4.AccountsKind4ID ';
        $sql .= '     , m_accountskind_4.AccountsKind4Name ';
        $sql .= '     , m_accountskind_5.AccountsKind5ID ';
        $sql .= '     , m_accountskind_5.AccountsKind5Name ';
        $sql .= '     , m_accountskind_5.DrCrFlg ';
        $sql .= 'FROM   m_accountskind_1 ';
        $sql .= '     , m_accountskind_2 ';
        $sql .= '     , m_accountskind_3 ';
        $sql .= '     , m_accountskind_4 ';
        $sql .= '     , m_accountskind_5 ';
        $sql .= 'WHERE  m_accountskind_1.AccountsKind1ID = m_accountskind_2.AccountsKind1ID ';
        $sql .= 'AND    m_accountskind_1.AccountsKind1ID = m_accountskind_3.AccountsKind1ID ';
        $sql .= 'AND    m_accountskind_2.AccountsKind2ID = m_accountskind_3.AccountsKind2ID ';
        $sql .= 'AND    m_accountskind_1.AccountsKind1ID = m_accountskind_4.AccountsKind1ID ';
        $sql .= 'AND    m_accountskind_2.AccountsKind2ID = m_accountskind_4.AccountsKind2ID ';
        $sql .= 'AND    m_accountskind_3.AccountsKind3ID = m_accountskind_4.AccountsKind3ID ';
        $sql .= 'AND    m_accountskind_1.AccountsKind1ID = m_accountskind_5.AccountsKind1ID ';
        $sql .= 'AND    m_accountskind_2.AccountsKind2ID = m_accountskind_5.AccountsKind2ID ';
        $sql .= 'AND    m_accountskind_3.AccountsKind3ID = m_accountskind_5.AccountsKind3ID ';
        $sql .= 'AND    m_accountskind_4.AccountsKind4ID = m_accountskind_5.AccountsKind4ID ';
        $sql .= 'AND    m_accountskind_1.LanguageID      = ? ';    // $lang
        $sql .= 'AND    m_accountskind_2.LanguageID      = ? ';    // $lang
        $sql .= 'AND    m_accountskind_3.LanguageID      = ? ';    // $lang
        $sql .= 'AND    m_accountskind_4.LanguageID      = ? ';    // $lang
        $sql .= 'AND    m_accountskind_5.LanguageID      = ? ';    // $lang
        $sql .= 'AND    m_accountskind_1.AccountsKind1ID = ? ';    // $kind1
        $sql .= 'AND    m_accountskind_2.AccountsKind2ID = ? ';    // $kind2
        $sql .= 'AND    m_accountskind_3.AccountsKind3ID = ? ';    // $kind3
        $sql .= 'AND    m_accountskind_4.AccountsKind4ID = ? ';    // $kind4
        $sql .= 'AND    m_accountskind_5.AccountsKind5ID = ? ';    // $kind5
        $sql .= 'AND    m_accountskind_1.Status          = true ';
        $sql .= 'AND    m_accountskind_2.Status          = true ';
        $sql .= 'AND    m_accountskind_3.Status          = true ';
        $sql .= 'AND    m_accountskind_4.Status          = true ';
        $sql .= 'AND    m_accountskind_5.Status          = true ';
        $sql .= 'ORDER BY m_accountskind_1.AccountsKind1ID, m_accountskind_2.AccountsKind2ID, m_accountskind_3.AccountsKind3ID, m_accountskind_4.AccountsKind4ID, m_accountskind_5.AccountsKind5ID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssss', $K1LanguageID, $K2LanguageID, $K3LanguageID, $K4LanguageID, $K5LanguageID, $K1Kind1ID, $K2Kind2ID, $K3Kind3ID, $K4Kind4ID, $K5Kind5ID);
            $K1LanguageID = $lang;
            $K2LanguageID = $lang;
            $K3LanguageID = $lang;
            $K4LanguageID = $lang;
            $K5LanguageID = $lang;
            $K1Kind1ID    = $kind1;
            $K2Kind2ID    = $kind2;
            $K3Kind3ID    = $kind3;
            $K4Kind4ID    = $kind4;
            $K5Kind5ID    = $kind5;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_unadjusttrialbalance                                 */
/*--------------------------------------------------------*/
    // 修正前試算表を追加する
    public function iUnAdjTBInfo($year, $month, $accS, $kind1, $kind2, $kind3, $kind4, $kind5, $drcrFlg, $drAmt, $crAmt, $diff, $drprevamt, $crprevamt, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_unadjusttrialbalance(UnAdjustTrialBalanceYear, UnAdjustTrialBalanceMonth, AccountsTitleID, AccountsKind1ID, AccountsKind2ID, AccountsKind3ID, AccountsKind4ID, AccountsKind5ID, DrPrevAmount, CrPrevAmount, DrAmount, CrAmount, DrCrFlg, Amount, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $year
        $sql .= ',? ';    // $month
        $sql .= ',? ';    // $accS
        $sql .= ',? ';    // $kind1
        $sql .= ',? ';    // $kind2
        $sql .= ',? ';    // $kind3
        $sql .= ',? ';    // $kind4
        $sql .= ',? ';    // $kind5
        $sql .= ',? ';    // $drprevamt
        $sql .= ',? ';    // $crprevamt
        $sql .= ',? ';    // $drAmt
        $sql .= ',? ';    // $crAmt
        $sql .= ',? ';    // $drcrFlg
        $sql .= ',? ';    // $diff
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true ) ';  
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssssssssss', $UnAdjustTrialBalanceYear, $UnAdjustTrialBalanceMonth, $AccountsTitleID, $AccountsKind1ID, $AccountsKind2ID, $AccountsKind3ID, $AccountsKind4ID, $AccountsKind5ID, $DrPrevAmount, $CrPrevAmount, $DrAmount, $CrAmount, $DrCrFlg, $Amount, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $UnAdjustTrialBalanceYear  = $year;
            $UnAdjustTrialBalanceMonth = $month;
            $AccountsTitleID           = $accS;
            $AccountsKind1ID           = $kind1;
            $AccountsKind2ID           = $kind2;
            $AccountsKind3ID           = $kind3;
            $AccountsKind4ID           = $kind4;
            $AccountsKind5ID           = $kind5;
            $DrPrevAmount              = $drprevamt;
            $CrPrevAmount              = $crprevamt;
            $DrAmount                  = $drAmt;
            $CrAmount                  = $crAmt;
            $DrCrFlg                   = $drcrFlg;
            $Amount                    = $diff;
            $EntDate                   = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser                   = $userid;
            $UpdDate                   = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser                   = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 修正前試算表(指定月)を削除する(全件)
    public function dUnAdjTBInfo($year, $month, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE t_unadjusttrialbalance ';
        $sql .= 'SET    Status        = false ';
        $sql .= '     , UpdDate       = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser       = ? ';    // $userid
        $sql .= '     , DelDate       = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , DelUser       = ? ';    // $userid
        $sql .= 'WHERE  CONCAT(UnAdjustTrialBalanceYear, RIGHT(CONCAT(\'00\', UnAdjustTrialBalanceMonth), 2)) = ? ';    // $year+$month
        $sql .= 'AND    Status                                                                                = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $YM);
            $YM = $year.str_pad($month, $this->CL['DF']->LenMonth, $this->CL['DF']->ZERO, STR_PAD_LEFT);
            $UpdDate       = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser       = $userid;
            $DelDate       = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser       = $userid;
             
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
    
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 修正前試算表(指定月)を取得する(全件)
    public function gUnAdjTBList($year, $month) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT AccountsTitleID ';
        $sql .= '     , DrPrevAmount ';
        $sql .= '     , CrPrevAmount ';
        $sql .= '     , DrAmount ';
        $sql .= '     , CrAmount ';
        $sql .= '     , DrCrFlg ';
        $sql .= '     , Amount ';
        $sql .= 'FROM   t_unadjusttrialbalance ';
        $sql .= 'WHERE  CONCAT(UnAdjustTrialBalanceYear, RIGHT(CONCAT(\'00\', UnAdjustTrialBalanceMonth), 2)) = ? ';    // $year+$month
        $sql .= 'AND    Status                                                                                = true ';
        $sql .= 'ORDER BY AccountsTitleID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $YM);
            $YM = $year.str_pad($month, $this->CL['DF']->LenMonth, $this->CL['DF']->ZERO, STR_PAD_LEFT);
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_adjustedtrialbalance                                 */
/*--------------------------------------------------------*/
    // 修正後算表を追加する
    public function iAdjTBInfo($year, $month, $accS, $kind1, $kind2, $kind3, $kind4, $kind5, $drcrFlg, $drAmt, $crAmt, $diff, $drprevamt, $crprevamt, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_adjustedtrialbalance(AdjustedTrialBalanceYear, AdjustedTrialBalanceMonth, AccountsTitleID, AccountsKind1ID, AccountsKind2ID, AccountsKind3ID, AccountsKind4ID, AccountsKind5ID, DrPrevAmount, CrPrevAmount, DrAmount, CrAmount, DrCrFlg, Amount, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $year
        $sql .= ',? ';    // $month
        $sql .= ',? ';    // $accS
        $sql .= ',? ';    // $kind1
        $sql .= ',? ';    // $kind2
        $sql .= ',? ';    // $kind3
        $sql .= ',? ';    // $kind4
        $sql .= ',? ';    // $kind5
        $sql .= ',? ';    // $drprevamt
        $sql .= ',? ';    // $crprevamt
        $sql .= ',? ';    // $drAmt
        $sql .= ',? ';    // $crAmt
        $sql .= ',? ';    // $drcrFlg
        $sql .= ',? ';    // $diff
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true ) ';  
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssssssssss', $AdjustedTrialBalanceYear, $AdjustedTrialBalanceMonth, $AccountsTitleID, $AccountsKind1ID, $AccountsKind2ID, $AccountsKind3ID, $AccountsKind4ID, $AccountsKind5ID, $DrPrevAmount, $CrPrevAmount, $DrAmount, $CrAmount, $DrCrFlg, $Amount, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $AdjustedTrialBalanceYear  = $year;
            $AdjustedTrialBalanceMonth = $month;
            $AccountsTitleID           = $accS;
            $AccountsKind1ID           = $kind1;
            $AccountsKind2ID           = $kind2;
            $AccountsKind3ID           = $kind3;
            $AccountsKind4ID           = $kind4;
            $AccountsKind5ID           = $kind5;
            $DrPrevAmount              = $drprevamt;
            $CrPrevAmount              = $crprevamt;
            $DrAmount                  = $drAmt;
            $CrAmount                  = $crAmt;
            $DrCrFlg                   = $drcrFlg;
            $Amount                    = $diff;
            $EntDate                   = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser                   = $userid;
            $UpdDate                   = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser                   = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 修正前試算表(指定月)を削除する(全件)
    public function dAdjTBInfo($year, $month, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE t_adjustedtrialbalance ';
        $sql .= 'SET    Status        = false ';
        $sql .= '     , UpdDate       = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser       = ? ';    // $userid
        $sql .= '     , DelDate       = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , DelUser       = ? ';    // $userid
        $sql .= 'WHERE  CONCAT(AdjustedTrialBalanceYear, RIGHT(CONCAT(\'00\', AdjustedTrialBalanceMonth), 2)) = ? ';    // $year+$month
        $sql .= 'AND    Status                                                                                = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $YM);
            $YM = $year.str_pad($month, $this->CL['DF']->LenMonth, $this->CL['DF']->ZERO, STR_PAD_LEFT);
            $UpdDate       = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser       = $userid;
            $DelDate       = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser       = $userid;
             
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
    
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 修正後試算表(指定月)を取得する(全件)
    public function gAdjTBList($year, $month) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT AccountsTitleID ';
        $sql .= '     , AccountsKind1ID ';
        $sql .= '     , AccountsKind2ID ';
        $sql .= '     , AccountsKind3ID ';
        $sql .= '     , AccountsKind4ID ';
        $sql .= '     , AccountsKind5ID ';
        $sql .= '     , DrPrevAmount ';
        $sql .= '     , CrPrevAmount ';
        $sql .= '     , DrAmount ';
        $sql .= '     , CrAmount ';
        $sql .= '     , DrCrFlg ';
        $sql .= '     , Amount ';
        $sql .= 'FROM   t_adjustedtrialbalance ';
        $sql .= 'WHERE  CONCAT(AdjustedTrialBalanceYear, RIGHT(CONCAT(\'00\', AdjustedTrialBalanceMonth), 2)) = ? ';    // $year+$month
        $sql .= 'AND    Status                                                                                = true ';
        $sql .= 'ORDER BY AccountsTitleID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $YM);
            $YM = $year.str_pad($month, $this->CL['DF']->LenMonth, $this->CL['DF']->ZERO, STR_PAD_LEFT);
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_profitandloss                                        */
/*--------------------------------------------------------*/
    // 損益計算書を追加する
    public function iPLInfo($year, $month, $accS, $kind1, $kind2, $kind3, $kind4, $kind5, $drcrFlg, $drAmt, $crAmt, $diff, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_profitandloss(ProfitAndLossYear, ProfitAndLossMonth, AccountsTitleID, AccountsKind1ID, AccountsKind2ID, AccountsKind3ID, AccountsKind4ID, AccountsKind5ID, DrCrFlg, DrAmount, CrAmount, Amount, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $year
        $sql .= ',? ';    // $month
        $sql .= ',? ';    // $accS
        $sql .= ',? ';    // $kind1
        $sql .= ',? ';    // $kind2
        $sql .= ',? ';    // $kind3
        $sql .= ',? ';    // $kind4
        $sql .= ',? ';    // $kind5
        $sql .= ',? ';    // $drcrFlg
        $sql .= ',? ';    // $drAmt
        $sql .= ',? ';    // $crAmt
        $sql .= ',? ';    // $diff
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true ) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssssssss', $ProfitAndLossYear, $ProfitAndLossMonth, $AccountsTitleID, $AccountsKind1ID, $AccountsKind2ID, $AccountsKind3ID, $AccountsKind4ID, $AccountsKind5ID, $DrCrFlg, $DrAmount, $CrAmount, $Amount, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $ProfitAndLossYear  = $year;
            $ProfitAndLossMonth = $month;
            $AccountsTitleID    = $accS;
            $AccountsKind1ID    = $kind1;
            $AccountsKind2ID    = $kind2;
            $AccountsKind3ID    = $kind3;
            $AccountsKind4ID    = $kind4;
            $AccountsKind5ID    = $kind5;
            $DrCrFlg            = $drcrFlg;
            $DrAmount           = $drAmt;
            $CrAmount           = $crAmt;
            $Amount             = $diff;
            $EntDate            = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser            = $userid;
            $UpdDate            = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser            = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 損益計算書を削除する
    public function dPLInfo($year, $month, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE t_profitandloss ';
        $sql .= 'SET    Status          = false ';
        $sql .= '     , UpdDate         = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser         = ? ';    // $userid
        $sql .= '     , DelDate         = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , DelUser         = ? ';    // $userid
        $sql .= 'WHERE  ProfitAndLossYear   = ? ';    // $year
        $sql .= 'AND    ProfitAndLossMonth  = ? ';    // $month
        $sql .= 'AND    Status              = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $ProfitAndLossYear, $ProfitAndLossMonth);
            $UpdDate            = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser            = $userid;
            $DelDate            = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser            = $userid;
            $ProfitAndLossYear  = $year;
            $ProfitAndLossMonth = $month;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 損益計算書(指定月)を取得する(全件)
    public function gPLList($year, $month) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT AccountsTitleID ';
        $sql .= '     , AccountsKind1ID ';
        $sql .= '     , AccountsKind2ID ';
        $sql .= '     , AccountsKind3ID ';
        $sql .= '     , AccountsKind4ID ';
        $sql .= '     , AccountsKind5ID ';
        $sql .= '     , DrCrFlg ';
        $sql .= '     , DrAmount ';
        $sql .= '     , CrAmount ';
        $sql .= '     , Amount ';
        $sql .= 'FROM   t_profitandloss ';
        $sql .= 'WHERE  CONCAT(ProfitAndLossYear, RIGHT(CONCAT(\'00\', ProfitAndLossMonth), 2)) = ? ';    // $year+$month
        $sql .= 'AND    Status                                                                  = true ';
        $sql .= 'ORDER BY AccountsTitleID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $YM);
            $YM = $year.str_pad($month, $this->CL['DF']->LenMonth, $this->CL['DF']->ZERO, STR_PAD_LEFT);
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_balancesheet                                         */
/*--------------------------------------------------------*/
    // 貸借対照表を追加する
    public function iBSInfo($year, $month, $accS, $kind1, $kind2, $kind3, $kind4, $kind5, $drcrFlg, $drAmt, $crAmt, $diff, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_balancesheet(BalanceSheetYear, BalanceSheetMonth, AccountsTitleID, AccountsKind1ID, AccountsKind2ID, AccountsKind3ID, AccountsKind4ID, AccountsKind5ID, DrCrFlg, DrAmount, CrAmount, Amount, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $year
        $sql .= ',? ';    // $month
        $sql .= ',? ';    // $accS
        $sql .= ',? ';    // $kind1
        $sql .= ',? ';    // $kind2
        $sql .= ',? ';    // $kind3
        $sql .= ',? ';    // $kind4
        $sql .= ',? ';    // $kind5
        $sql .= ',? ';    // $drcrFlg
        $sql .= ',? ';    // $drAmt
        $sql .= ',? ';    // $crAmt
        $sql .= ',? ';    // $diff
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true ) ';  
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssssssss', $BalanceSheetYear, $BalanceSheetMonth, $AccountsTitleID, $AccountsKind1ID, $AccountsKind2ID, $AccountsKind3ID, $AccountsKind4ID, $AccountsKind5ID, $DrCrFlg, $DrAmount, $CrAmount, $Amount, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $BalanceSheetYear  = $year;
            $BalanceSheetMonth = $month;
            $AccountsTitleID   = $accS;
            $AccountsKind1ID   = $kind1;
            $AccountsKind2ID   = $kind2;
            $AccountsKind3ID   = $kind3;
            $AccountsKind4ID   = $kind4;
            $AccountsKind5ID   = $kind5;
            $DrCrFlg           = $drcrFlg;
            $DrAmount          = $drAmt;
            $CrAmount          = $crAmt;
            $Amount            = $diff;
            $EntDate           = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser           = $userid;
            $UpdDate           = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser           = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 貸借対照表を削除する
    public function dBSInfo($year, $month, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE t_balancesheet ';
        $sql .= 'SET    Status          = false ';
        $sql .= '     , UpdDate         = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser         = ? ';    // $userid
        $sql .= '     , DelDate         = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , DelUser         = ? ';    // $userid
        $sql .= 'WHERE  BalanceSheetYear    = ? ';    // $year
        $sql .= 'AND    BalanceSheetMonth   = ? ';    // $month
        $sql .= 'AND    Status              = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $BalanceSheetYear, $BalanceSheetMonth);
            $UpdDate            = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser            = $userid;
            $DelDate            = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser            = $userid;
            $BalanceSheetYear   = $year;
            $BalanceSheetMonth  = $month;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 貸借対照表(指定月)を取得する(全件)
    public function gBSList($year, $month) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT AccountsTitleID ';
        $sql .= '     , AccountsKind1ID ';
        $sql .= '     , AccountsKind2ID ';
        $sql .= '     , AccountsKind3ID ';
        $sql .= '     , AccountsKind4ID ';
        $sql .= '     , AccountsKind5ID ';
        $sql .= '     , DrCrFlg ';
        $sql .= '     , DrAmount ';
        $sql .= '     , CrAmount ';
        $sql .= '     , Amount ';
        $sql .= 'FROM   t_balancesheet ';
        $sql .= 'WHERE  CONCAT(BalanceSheetYear, RIGHT(CONCAT(\'00\', BalanceSheetMonth), 2)) = ? ';    // $year+$month
        $sql .= 'AND    Status                                                                = true ';
        $sql .= 'ORDER BY AccountsTitleID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $YM);
            $YM = $year.str_pad($month, $this->CL['DF']->LenMonth, $this->CL['DF']->ZERO, STR_PAD_LEFT);
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* m_openningbalance                                      */
/*--------------------------------------------------------*/
    // 開始残高を追加する
    public function iOpenningBalanceInfo($AccS, $Amt, $Summary, $TDate, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO m_openningbalance(AccountsTitleID, Amount, Summary, TransactionDate, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $AccS
        $sql .= ',? ';    // $Amt
        $sql .= ',? ';    // $Summary
        $sql .= ',? ';    // $TDate
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true ) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sdssssss', $AccountsTitleID, $Amount, $_Summary, $TransactionDate, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $AccountsTitleID  = $AccS;
            $Amount           = $Amt;
            $_Summary         = $Summary;
            $TransactionDate  = $TDate;
            $EntDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser          = $userid;
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 開始残高を更新する
    public function uOpenningBalanceInfo($AccS, $Amt, $Summary, $TDate, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE m_openningbalance ';
        $sql .= 'SET    Amount           = ? ';    // $Amt
        $sql .= '     , Summary          = ? ';    // $Summary
        $sql .= '     , TransactionDate  = ? ';    // $TDate
        $sql .= '     , UpdDate          = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser          = ? ';    // $userid
        $sql .= 'WHERE  AccountsTitleID  = ? ';    // $AccS
        $sql .= 'AND    Status           = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('dsssss', $Amount, $_Summary, $TransactionDate, $UpdDate, $UpdUser, $AccountsTitleID);
            $Amount            = $Amt;
            $_Summary          = $Summary;
            $TransactionDate   = $TDate;
            $UpdDate           = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser           = $userid;
            $AccountsTitleID   = $AccS;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 開始残高を取得する(一件/全件)
    public function gOpenningBalanceVal($AccS) {
        $this->CL['LG']->cLog('T0002');
        $sql_AccountsTitleID = self::sArrAccTitleID('m_openningbalance', $AccS);    // 検索条件(勘定科目)
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT TransactionDate ';
        $sql .= '     , AccountsTitleID ';
        $sql .= '     , Amount ';
        $sql .= '     , Summary ';
        $sql .= '     , EntDate ';
        $sql .= '     , EntUser ';
        $sql .= 'FROM   m_openningbalance ';
        $sql .= 'WHERE  m_openningbalance.Status           = true ';
        $sql .= $sql_AccountsTitleID.' ';
        $sql .= 'ORDER BY TransactionDate ';
        $sql .= '       , AccountsTitleID ';

        if ($stmt = $mysqli->prepare($sql)) {
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 開始残高を取得する(全件)
    public function gOpenningBalanceList() {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT TransactionDate ';
        $sql .= '     , AccountsTitleID ';
        $sql .= '     , Amount ';
        $sql .= '     , Summary ';
        $sql .= 'FROM   m_openningbalance ';
        $sql .= 'WHERE  Status   = true ';
        $sql .= 'ORDER BY AccountsTitleID ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* m_openbaldetail                                        */
/*--------------------------------------------------------*/
    // 開始残高明細を追加する
    public function iOpenBalDetailInfo($AccS, $Client, $Amt, $pCurrencyID, $pFxAmount, $pSegmentID, $CtrlNo, $_Summary, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO m_openbaldetail(AccountsTitleID, ClientID, Amount, CurrencyID, FxAmount, SegmentID, ControlNo, Summary, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $AccS
        $sql .= ',? ';    // $Client
        $sql .= ',? ';    // $Amt
        $sql .= ',? ';    // $pCurrencyID
        $sql .= ',? ';    // $pFxAmount
        $sql .= ',? ';    // $pSegmentID
        $sql .= ',? ';    // $CtrlNo
        $sql .= ',? ';    // $_Summary
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true ) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssdsdsssssss', $AccountsTitleID, $ClientID, $Amount, $CurrencyID, $FxAmount, $SegmentID, $ControlNo, $Summary, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $AccountsTitleID  = $AccS;
            $ClientID         = $Client;
            $Amount           = $Amt;
            $CurrencyID       = $pCurrencyID;
            $FxAmount         = $pFxAmount;
            $SegmentID        = $pSegmentID;
            $ControlNo        = $CtrlNo;
            $Summary          = $_Summary;
            $EntDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser          = $userid;
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 開始残高明細を更新する
    public function uOpenBalDetailInfo($AccS, $Client, $Amt, $pCurrencyID, $pFxAmount, $pSegmentID, $CtrlNo, $_Summary, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE m_openbaldetail ';
        $sql .= 'SET    Amount           = ? ';    // $Amt
        $sql .= '     , FxAmount         = ? ';    // $pFxAmount
        $sql .= '     , Summary          = ? ';    // $_Summary
        $sql .= '     , UpdDate          = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser          = ? ';    // $userid
        $sql .= 'WHERE  AccountsTitleID  = ? ';    // $AccS
        $sql .= 'AND    ClientID         = ? ';    // $Client
        $sql .= 'AND    CurrencyID       = ? ';    // $pCurrencyID
        $sql .= 'AND    SegmentID        = ? ';    // $pSegmentID
        $sql .= 'AND    ControlNo        = ? ';    // $CtrlNo
        $sql .= 'AND    Status           = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ddssssssss', $Amount, $FxAmount, $Summary, $UpdDate, $UpdUser, $AccountsTitleID, $ClientID, $CurrencyID, $SegmentID, $ControlNo);
            $Amount            = $Amt;
            $FxAmount          = $pFxAmount;
            $Summary           = $_Summary;
            $UpdDate           = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser           = $userid;
            $AccountsTitleID   = $AccS;
            $ClientID          = $Client;
            $CurrencyID        = $pCurrencyID;
            $SegmentID         = $pSegmentID;
            $ControlNo         = $CtrlNo;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 開始残高明細を取得する(一件/全件)
    public function gOpenBalDetailVal($AccS, $Client, $pCurrencyID, $pSegmentID, $CtrlNo) {
        $this->CL['LG']->cLog('T0002');
        $sql_AccountsTitleID = self::sArrAccTitleID('m_openbaldetail', $AccS);    // 検索条件(勘定科目)
        $sql_ClientID = self::sDataFlg('m_openbaldetail', $Client, 'ClientID');   // 検索条件(相手先ID)
        $sql_CurrencyID = self::sDataFlg('m_openbaldetail', $pCurrencyID, 'CurrencyID');    // 検索条件(通貨ID)
        $sql_SegmentID = self::sDataFlg('m_openbaldetail', $pSegmentID, 'SegmentID');       // 検索条件(セグメントID)
        $sql_ControlNo = self::sDataFlg('m_openbaldetail', $CtrlNo, 'ControlNo');           // 検索条件(コントロールNo)
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT AccountsTitleID ';
        $sql .= '     , ClientID ';
        $sql .= '     , Amount ';
        $sql .= '     , CurrencyID ';
        $sql .= '     , FxAmount ';
        $sql .= '     , SegmentID ';
        $sql .= '     , ControlNo ';
        $sql .= '     , Summary ';
        $sql .= '     , EntDate ';
        $sql .= '     , EntUser ';
        $sql .= 'FROM   m_openbaldetail ';
        $sql .= 'WHERE  m_openbaldetail.Status           = true ';
        $sql .= $sql_AccountsTitleID.' ';
        $sql .= $sql_ClientID.' ';
        $sql .= $sql_CurrencyID.' ';
        $sql .= $sql_SegmentID.' ';
        $sql .= $sql_ControlNo.' ';
        $sql .= 'ORDER BY AccountsTitleID ';
        $sql .= '       , ClientID ';
        $sql .= '       , CurrencyID ';
        $sql .= '       , SegmentID ';
        $sql .= '       , ControlNo ';

        if ($stmt = $mysqli->prepare($sql)) {
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 開始残高明細を削除する
    public function dOpenBalDetailInfo($AccS, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE m_openbaldetail ';
        $sql .= 'SET    Status          = false ';
        $sql .= '     , UpdDate         = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser         = ? ';    // $userid
        $sql .= '     , DelDate         = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , DelUser         = ? ';    // $userid
        $sql .= 'WHERE  AccountsTitleID = ? ';    // $AccS
        $sql .= 'AND    Status          = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $AccountsTitleID);
            $UpdDate            = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser            = $userid;
            $DelDate            = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser            = $userid;
            $AccountsTitleID    = $AccS;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
/*--------------------------------------------------------*/
/* t_purchasedmtjournal                                   */
/*--------------------------------------------------------*/
    // 仕入帳を追加する
    public function iPurchaseDmtJnlInfo($TrnID, $Line, $AccTitleLID, $AccTitleMID, $AccTitleSID, $DrCrFlg, $Amt, $CtrlNo, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_purchasedmtjournal(TransactionID, Line, AccountsTitleLID, AccountsTitleMID, AccountsTitleSID, DrCrFlg, Amount, ControlNo, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $TrnID
        $sql .= ',? ';    // $Line
        $sql .= ',? ';    // $AccTitleLID
        $sql .= ',? ';    // $AccTitleMID
        $sql .= ',? ';    // $AccTitleSID
        $sql .= ',? ';    // $DrCrFlg
        $sql .= ',? ';    // $Amt
        $sql .= ',? ';    // $CtrlNo
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true ) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssss', $TransactionID, $Line, $AccountsTitleLID, $AccountsTitleMID, $AccountsTitleSID, $DrCrFlg, $Amount, $ControlNo, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $TransactionID    = $TrnID;
            $Line             = $Line;
            $AccountsTitleLID = $AccTitleLID;
            $AccountsTitleMID = $AccTitleMID;
            $AccountsTitleSID = $AccTitleSID;
            $DrCrFlg          = $DrCrFlg;
            $Amount           = $Amt;
            $ControlNo        = $CtrlNo;
            $EntDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser          = $userid;
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
/*--------------------------------------------------------*/
/* t_purchasedmttemp                                      */
/*--------------------------------------------------------*/
    // 仕入帳(テンポラリ)を追加する
    public function iPurchaseDmtTempInfo($TrnID, $Line, $Number, $AccTitleLID, $AccTitleMID, $AccTitleSID, $DrCrFlg, $Amt, $CtrlNo, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_purchasedmttemp(TransactionID, Line, Number, AccountsTitleLID, AccountsTitleMID, AccountsTitleSID, DrCrFlg, Amount, ControlNo, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $TrnID
        $sql .= ',? ';    // $Line
        $sql .= ',? ';    // $Number
        $sql .= ',? ';    // $AccTitleLID
        $sql .= ',? ';    // $AccTitleMID
        $sql .= ',? ';    // $AccTitleSID
        $sql .= ',? ';    // $DrCrFlg
        $sql .= ',? ';    // $Amt
        $sql .= ',? ';    // $CtrlNo
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true ) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssssssssss', $TransactionID, $Line, $Number, $AccountsTitleLID, $AccountsTitleMID, $AccountsTitleSID, $DrCrFlg, $Amount, $ControlNo, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $TransactionID    = $TrnID;
            $Line             = $Line;
            $Number           = $Number;
            $AccountsTitleLID = $AccTitleLID;
            $AccountsTitleMID = $AccTitleMID;
            $AccountsTitleSID = $AccTitleSID;
            $DrCrFlg          = $DrCrFlg;
            $Amount           = $Amt;
            $ControlNo        = $CtrlNo;
            $EntDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser          = $userid;
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
/*--------------------------------------------------------*/
/* t_purchaseintjournal                                   */
/*--------------------------------------------------------*/
    // 仕入帳を追加する
    public function iPurchaseIntJnlInfo($TrnID, $Line, $AccTitleLID, $AccTitleMID, $AccTitleSID, $DrCrFlg, $Amt, $CtrlNo, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_purchaseintjournal(TransactionID, Line, AccountsTitleLID, AccountsTitleMID, AccountsTitleSID, DrCrFlg, Amount, ControlNo, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $TrnID
        $sql .= ',? ';    // $Line
        $sql .= ',? ';    // $AccTitleLID
        $sql .= ',? ';    // $AccTitleMID
        $sql .= ',? ';    // $AccTitleSID
        $sql .= ',? ';    // $DrCrFlg
        $sql .= ',? ';    // $Amt
        $sql .= ',? ';    // $CtrlNo
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid;
        $sql .= ',true ) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssss', $TransactionID, $Line, $AccountsTitleLID, $AccountsTitleMID, $AccountsTitleSID, $DrCrFlg, $Amount, $ControlNo, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $TransactionID    = $TrnID;
            $Line             = $Line;
            $AccountsTitleLID = $AccTitleLID;
            $AccountsTitleMID = $AccTitleMID;
            $AccountsTitleSID = $AccTitleSID;
            $DrCrFlg          = $DrCrFlg;
            $Amount           = $Amt;
            $ControlNo        = $CtrlNo;
            $EntDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser          = $userid;
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
/*--------------------------------------------------------*/
/* t_purchaseinttemp                                      */
/*--------------------------------------------------------*/
    // 仕入帳(テンポラリ)を追加する
    public function iPurchaseIntTempInfo($TrnID, $Line, $Number, $AccTitleLID, $AccTitleMID, $AccTitleSID, $DrCrFlg, $Amt, $CtrlNo, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_purchaseinttemp(TransactionID, Line, Number, AccountsTitleLID, AccountsTitleMID, AccountsTitleSID, DrCrFlg, Amount, ControlNo, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $TrnID
        $sql .= ',? ';    // $Line
        $sql .= ',? ';    // $Number
        $sql .= ',? ';    // $AccTitleLID
        $sql .= ',? ';    // $AccTitleMID
        $sql .= ',? ';    // $AccTitleSID
        $sql .= ',? ';    // $DrCrFlg
        $sql .= ',? ';    // $Amt
        $sql .= ',? ';    // $CtrlNo
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true ) ';  
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssssssssss', $TransactionID, $Line, $Number, $AccountsTitleLID, $AccountsTitleMID, $AccountsTitleSID, $DrCrFlg, $Amount, $ControlNo, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $TransactionID    = $TrnID;
            $Line             = $Line;
            $Number           = $Number;
            $AccountsTitleLID = $AccTitleLID;
            $AccountsTitleMID = $AccTitleMID;
            $AccountsTitleSID = $AccTitleSID;
            $DrCrFlg          = $DrCrFlg;
            $Amount           = $Amt;
            $ControlNo        = $CtrlNo;
            $EntDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser          = $userid;
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
/*--------------------------------------------------------*/
/* t_purchasegoodsdmtjournal                              */
/*--------------------------------------------------------*/
    // 仕入帳を追加する
    public function iPurchaseGoodsDmtJnlInfo($TrnID, $Line, $AccTitleLID, $AccTitleMID, $AccTitleSID, $DrCrFlg, $Amt, $CtrlNo, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_purchasegoodsdmtjournal(TransactionID, Line, AccountsTitleLID, AccountsTitleMID, AccountsTitleSID, DrCrFlg, Amount, ControlNo, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $TrnID
        $sql .= ',? ';    // $Line
        $sql .= ',? ';    // $AccTitleLID
        $sql .= ',? ';    // $AccTitleMID
        $sql .= ',? ';    // $AccTitleSID
        $sql .= ',? ';    // $DrCrFlg
        $sql .= ',? ';    // $Amt
        $sql .= ',? ';    // $CtrlNo
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true ) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssss', $TransactionID, $Line, $AccountsTitleLID, $AccountsTitleMID, $AccountsTitleSID, $DrCrFlg, $Amount, $ControlNo, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $TransactionID    = $TrnID;
            $Line             = $Line;
            $AccountsTitleLID = $AccTitleLID;
            $AccountsTitleMID = $AccTitleMID;
            $AccountsTitleSID = $AccTitleSID;
            $DrCrFlg          = $DrCrFlg;
            $Amount           = $Amt;
            $ControlNo        = $CtrlNo;
            $EntDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser          = $userid;
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
/*--------------------------------------------------------*/
/* t_purchasegoodsintjournal                              */
/*--------------------------------------------------------*/
    // 物品購入帳を追加する
    public function iPurchaseGoodsIntJnlInfo($TrnID, $Line, $AccTitleLID, $AccTitleMID, $AccTitleSID, $DrCrFlg, $Amt, $CtrlNo, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_purchasegoodsintjournal(TransactionID, Line, AccountsTitleLID, AccountsTitleMID, AccountsTitleSID, DrCrFlg, Amount, ControlNo, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $TrnID
        $sql .= ',? ';    // $Line
        $sql .= ',? ';    // $AccTitleLID
        $sql .= ',? ';    // $AccTitleMID
        $sql .= ',? ';    // $AccTitleSID
        $sql .= ',? ';    // $DrCrFlg
        $sql .= ',? ';    // $Amt
        $sql .= ',? ';    // $CtrlNo
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid;
        $sql .= ',true ) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssss', $TransactionID, $Line, $AccountsTitleLID, $AccountsTitleMID, $AccountsTitleSID, $DrCrFlg, $Amount, $ControlNo, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $TransactionID    = $TrnID;
            $Line             = $Line;
            $AccountsTitleLID = $AccTitleLID;
            $AccountsTitleMID = $AccTitleMID;
            $AccountsTitleSID = $AccTitleSID;
            $DrCrFlg          = $DrCrFlg;
            $Amount           = $Amt;
            $ControlNo        = $CtrlNo;
            $EntDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser          = $userid;
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
/*--------------------------------------------------------*/
/* t_purchasegoodsinttemp                                 */
/*--------------------------------------------------------*/
    // 物品購入帳(テンポラリ)を追加する
    public function iPurchaseGoodsIntTempInfo($TrnID, $Line, $Number, $AccTitleLID, $AccTitleMID, $AccTitleSID, $DrCrFlg, $Amt, $CtrlNo, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_purchasegoodsinttemp(TransactionID, Line, Number, AccountsTitleLID, AccountsTitleMID, AccountsTitleSID, DrCrFlg, Amount, ControlNo, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $TrnID
        $sql .= ',? ';    // $Line
        $sql .= ',? ';    // $Number
        $sql .= ',? ';    // $AccTitleLID
        $sql .= ',? ';    // $AccTitleMID
        $sql .= ',? ';    // $AccTitleSID
        $sql .= ',? ';    // $DrCrFlg
        $sql .= ',? ';    // $Amt
        $sql .= ',? ';    // $CtrlNo
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true ) ';  
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssssssssss', $TransactionID, $Line, $Number, $AccountsTitleLID, $AccountsTitleMID, $AccountsTitleSID, $DrCrFlg, $Amount, $ControlNo, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $TransactionID    = $TrnID;
            $Line             = $Line;
            $Number           = $Number;
            $AccountsTitleLID = $AccTitleLID;
            $AccountsTitleMID = $AccTitleMID;
            $AccountsTitleSID = $AccTitleSID;
            $DrCrFlg          = $DrCrFlg;
            $Amount           = $Amt;
            $ControlNo        = $CtrlNo;
            $EntDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser          = $userid;
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
/*--------------------------------------------------------*/
/* t_purchaseservicesdmtjournal                           */
/*--------------------------------------------------------*/
    // 物品購入帳を追加する
    public function iPurchaseServicesDmtJnlInfo($TrnID, $Line, $AccTitleLID, $AccTitleMID, $AccTitleSID, $DrCrFlg, $Amt, $CtrlNo, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_purchaseservicesdmtjournal(TransactionID, Line, AccountsTitleLID, AccountsTitleMID, AccountsTitleSID, DrCrFlg, Amount, ControlNo, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $TrnID
        $sql .= ',? ';    // $Line
        $sql .= ',? ';    // $AccTitleLID
        $sql .= ',? ';    // $AccTitleMID
        $sql .= ',? ';    // $AccTitleSID
        $sql .= ',? ';    // $DrCrFlg
        $sql .= ',? ';    // $Amt
        $sql .= ',? ';    // $CtrlNo
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid;
        $sql .= ',true ) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssss', $TransactionID, $Line, $AccountsTitleLID, $AccountsTitleMID, $AccountsTitleSID, $DrCrFlg, $Amount, $ControlNo, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $TransactionID    = $TrnID;
            $Line             = $Line;
            $AccountsTitleLID = $AccTitleLID;
            $AccountsTitleMID = $AccTitleMID;
            $AccountsTitleSID = $AccTitleSID;
            $DrCrFlg          = $DrCrFlg;
            $Amount           = $Amt;
            $ControlNo        = $CtrlNo;
            $EntDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser          = $userid;
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
/*--------------------------------------------------------*/
/* t_purchaseservicesdmttemp                              */
/*--------------------------------------------------------*/
    // 物品購入帳(テンポラリ)を追加する
    public function iPurchaseServicesDmtTempInfo($TrnID, $Line, $Number, $AccTitleLID, $AccTitleMID, $AccTitleSID, $DrCrFlg, $Amt, $CtrlNo, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_purchaseservicesdmttemp(TransactionID, Line, Number, AccountsTitleLID, AccountsTitleMID, AccountsTitleSID, DrCrFlg, Amount, ControlNo, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $TrnID
        $sql .= ',? ';    // $Line
        $sql .= ',? ';    // $Number
        $sql .= ',? ';    // $AccTitleLID
        $sql .= ',? ';    // $AccTitleMID
        $sql .= ',? ';    // $AccTitleSID
        $sql .= ',? ';    // $DrCrFlg
        $sql .= ',? ';    // $Amt
        $sql .= ',? ';    // $CtrlNo
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true ) ';  
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssssssssss', $TransactionID, $Line, $Number, $AccountsTitleLID, $AccountsTitleMID, $AccountsTitleSID, $DrCrFlg, $Amount, $ControlNo, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $TransactionID    = $TrnID;
            $Line             = $Line;
            $Number           = $Number;
            $AccountsTitleLID = $AccTitleLID;
            $AccountsTitleMID = $AccTitleMID;
            $AccountsTitleSID = $AccTitleSID;
            $DrCrFlg          = $DrCrFlg;
            $Amount           = $Amt;
            $ControlNo        = $CtrlNo;
            $EntDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser          = $userid;
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
/*--------------------------------------------------------*/
/* t_purchaseservicesintjournal                           */
/*--------------------------------------------------------*/
    // 物品購入帳を追加する
    public function iPurchaseServicesIntJnlInfo($TrnID, $Line, $AccTitleLID, $AccTitleMID, $AccTitleSID, $DrCrFlg, $Amt, $CtrlNo, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_purchaseservicesintjournal(TransactionID, Line, AccountsTitleLID, AccountsTitleMID, AccountsTitleSID, DrCrFlg, Amount, ControlNo, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $TrnID
        $sql .= ',? ';    // $Line
        $sql .= ',? ';    // $AccTitleLID
        $sql .= ',? ';    // $AccTitleMID
        $sql .= ',? ';    // $AccTitleSID
        $sql .= ',? ';    // $DrCrFlg
        $sql .= ',? ';    // $Amt
        $sql .= ',? ';    // $CtrlNo
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid;
        $sql .= ',true ) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssss', $TransactionID, $Line, $AccountsTitleLID, $AccountsTitleMID, $AccountsTitleSID, $DrCrFlg, $Amount, $ControlNo, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $TransactionID    = $TrnID;
            $Line             = $Line;
            $AccountsTitleLID = $AccTitleLID;
            $AccountsTitleMID = $AccTitleMID;
            $AccountsTitleSID = $AccTitleSID;
            $DrCrFlg          = $DrCrFlg;
            $Amount           = $Amt;
            $ControlNo        = $CtrlNo;
            $EntDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser          = $userid;
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
/*--------------------------------------------------------*/
/* t_purchaseservicesinttemp                              */
/*--------------------------------------------------------*/
    // 物品購入帳(テンポラリ)を追加する
    public function iPurchaseServicesIntTempInfo($TrnID, $Line, $Number, $AccTitleLID, $AccTitleMID, $AccTitleSID, $DrCrFlg, $Amt, $CtrlNo, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_purchaseservicesinttemp(TransactionID, Line, Number, AccountsTitleLID, AccountsTitleMID, AccountsTitleSID, DrCrFlg, Amount, ControlNo, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $TrnID
        $sql .= ',? ';    // $Line
        $sql .= ',? ';    // $Number
        $sql .= ',? ';    // $AccTitleLID
        $sql .= ',? ';    // $AccTitleMID
        $sql .= ',? ';    // $AccTitleSID
        $sql .= ',? ';    // $DrCrFlg
        $sql .= ',? ';    // $Amt
        $sql .= ',? ';    // $CtrlNo
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true ) ';  
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssssssssss', $TransactionID, $Line, $Number, $AccountsTitleLID, $AccountsTitleMID, $AccountsTitleSID, $DrCrFlg, $Amount, $ControlNo, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $TransactionID    = $TrnID;
            $Line             = $Line;
            $Number           = $Number;
            $AccountsTitleLID = $AccTitleLID;
            $AccountsTitleMID = $AccTitleMID;
            $AccountsTitleSID = $AccTitleSID;
            $DrCrFlg          = $DrCrFlg;
            $Amount           = $Amt;
            $ControlNo        = $CtrlNo;
            $EntDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser          = $userid;
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
/*--------------------------------------------------------*/
/* m_taxrate                                              */
/*--------------------------------------------------------*/
    // 当該日付の税率を取得する(種別毎、複数)
    public function gTaxRateVal($TaxKind, $Date, $Country) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT r.TaxType ';
        $sql .= '      ,r.Rate ';
        $sql .= '      ,r.StartDate ';
        $sql .= '      ,r.CountryID ';
        $sql .= 'FROM m_taxrate r ';
        $sql .= 'INNER JOIN ( ';
        $sql .= '    SELECT  KindFlg ';
        $sql .= '          , CountryID ';
        $sql .= '          , TaxType ';
        $sql .= '          , MAX(StartDate) StartDate ';
        $sql .= '    FROM m_taxrate ';
        $sql .= '    WHERE KindFlg=? ';     // $TaxKind
        $sql .= '    AND CountryID=? ';     // $Country
        $sql .= '    AND StartDate<=? ';    // $Date
        $sql .= '    AND EndDate>=? ';      // $Date
        $sql .= '    AND STATUS=true ';
        $sql .= '    GROUP BY KindFlg,CountryID, TaxType ';
        $sql .= '    ) k ';
        $sql .= 'ON k.KindFlg = r.KindFlg ';
        $sql .= 'AND k.TaxType=r.TaxType ';
        $sql .= 'AND k.CountryID=r.CountryID ';
        $sql .= 'AND k.StartDate=r.StartDate ';
        $sql .= 'WHERE r.status=true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssss', $KindFlg, $CountryID, $StartDate, $EndDate);
            $KindFlg   = $TaxKind;
            $CountryID = $Country;
            $StartDate = $Date;
            $EndDate   = $Date;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_transaction*u_client*t_salestaxdmtjournal            */
/*--------------------------------------------------------*/
    // 取引を取得する(復数件)
    public function gSalesTaxDmtJournalList($date, $SalesAccL, $SalesAccM, $SalesAccS, $OutputVatAccL, $OutputVatAccM, $OutputVatAccS, $CashAccL, $CashAccM, $CashAccS, $ARAccL, $ARAccM, $ARAccS, $JnlKindID, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_Sub_Sales  = 't_salestaxdmtjournal AS Sales ';
        $sql_Sub_Sales .= 'ON ( ';
        $sql_Sub_Sales .= '       (t_transaction.TransactionID = Sales.TransactionID) ';
        $sql_Sub_Sales .= '   AND (Sales.AccountsTitleLID      = ?) ';    // $SalesAccL
        $sql_Sub_Sales .= '   AND (Sales.AccountsTitleMID      = ?) ';    // $SalesAccM
        $sql_Sub_Sales .= '   AND (Sales.AccountsTitleSID      = ?) ';    // $SalesAccS
        $sql_Sub_Sales .= '   AND (Sales.Status                = true) ';
        $sql_Sub_Sales .= '   ) ';
        
        $sql_Sub_Vat  = 't_salestaxdmtjournal AS VAT ';
        $sql_Sub_Vat .= 'ON ( ';
        $sql_Sub_Vat .= '       (t_transaction.TransactionID = VAT.TransactionID) ';
        $sql_Sub_Vat .= '   AND (VAT.AccountsTitleLID      = ?) ';    // $OutputVatAccL
        $sql_Sub_Vat .= '   AND (VAT.AccountsTitleMID      = ?) ';    // $OutputVatAccM
        $sql_Sub_Vat .= '   AND (VAT.AccountsTitleSID      = ?) ';    // $OutputVatAccS
        $sql_Sub_Vat .= '   AND (VAT.Status                = true) ';
        $sql_Sub_Vat .= '   ) ';
        
        $sql_Sub_Cash  = 't_salestaxdmtjournal AS Cash ';
        $sql_Sub_Cash .= 'ON ( ';
        $sql_Sub_Cash .= '       (t_transaction.TransactionID = Cash.TransactionID) ';
        $sql_Sub_Cash .= '   AND (Cash.AccountsTitleLID      = ?) ';    // $CashAccL
        $sql_Sub_Cash .= '   AND (Cash.AccountsTitleMID      = ?) ';    // $CashAccM
        $sql_Sub_Cash .= '   AND (Cash.AccountsTitleSID      = ?) ';    // $CashAccS
        $sql_Sub_Cash .= '   AND (Cash.Status                = true) ';
        $sql_Sub_Cash .= '   ) ';
        
        $sql_Sub_AR  = 't_salestaxdmtjournal AS AR ';
        $sql_Sub_AR .= 'ON ( ';
        $sql_Sub_AR .= '       (t_transaction.TransactionID = AR.TransactionID) ';
        $sql_Sub_AR .= '   AND (AR.AccountsTitleLID      = ?) ';    // $ARAccL
        $sql_Sub_AR .= '   AND (AR.AccountsTitleMID      = ?) ';    // $ARAccM
        $sql_Sub_AR .= '   AND (AR.AccountsTitleSID      = ?) ';    // $ARAccS
        $sql_Sub_AR .= '   AND (AR.Status                = true) ';
        $sql_Sub_AR .= '   ) ';
        
        $sql  = 'SELECT t_transaction.TransactionID  ';
        $sql .= '     , t_transaction.TransactionStatusID  ';
        $sql .= '     , t_transaction.Summary  ';
        $sql .= '     , u_client.ClientName  ';
        $sql .= '     , Sales.Amount as SalesAmount ';
        $sql .= '     , Sales.ControlNo as SalesControlNo ';
        $sql .= '     , VAT.Amount as VatAmount ';
        $sql .= '     , VAT.ControlNo as VatControlNo ';
        $sql .= '     , Cash.Amount as CashAmount ';
        $sql .= '     , Cash.ControlNo as CashControlNo ';
        $sql .= '     , AR.Amount as ARAmount ';
        $sql .= '     , AR.ControlNo as ARControlNo ';
        $sql .= 'FROM   u_client  ';
        $sql .= '     , t_transaction ';
        $sql .= '           LEFT OUTER JOIN '.$sql_Sub_Sales.' ';
        $sql .= '           LEFT OUTER JOIN '.$sql_Sub_Vat.' ';
        $sql .= '           LEFT OUTER JOIN '.$sql_Sub_Cash.' ';
        $sql .= '           LEFT OUTER JOIN '.$sql_Sub_AR.' ';
        $sql .= 'WHERE  t_transaction.TransactionDate = ? ';    // $date
        $sql .= 'AND    u_client.LanguageID           = ? ';    // $lang
        $sql .= 'AND    t_transaction.JournalKindID   = ? ';    // $JnlKindID
        $sql .= 'AND    t_transaction.ClientID        = u_client.ClientID  ';
        $sql .= 'AND    t_transaction.Status          = true  ';
        $sql .= 'AND    u_client.Status               = true  ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssssssssssss', $SalesAccL, $SalesAccM, $SalesAccS, $OutputVatAccL, $OutputVatAccM, $OutputVatAccS, $CashAccL, $CashAccM, $CashAccS, $ARAccL, $ARAccM, $ARAccS, $date, $lang, $JnlKindID);
            $SalesAccL     = $SalesAccL;
            $SalesAccM     = $SalesAccM;
            $SalesAccS     = $SalesAccS;
            $OutputVatAccL = $OutputVatAccL;
            $OutputVatAccM = $OutputVatAccM;
            $OutputVatAccS = $OutputVatAccS;
            $CashAccL      = $CashAccL;
            $CashAccM      = $CashAccM;
            $CashAccS      = $CashAccS;
            $ARAccL        = $ARAccL;
            $ARAccM        = $ARAccM;
            $ARAccS        = $ARAccS;
            $JnlKindID     = $JnlKindID;
            $date          = $date;
            $lang          = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_salestaxdmtjournal                                   */
/*--------------------------------------------------------*/
    // 売上帳を追加する
    public function iSalesTaxDmtJnlInfo($TrnID, $Line, $AccTitleLID, $AccTitleMID, $AccTitleSID, $DrCrFlg, $Amt, $CtrlNo, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_salestaxdmtjournal(TransactionID, Line, AccountsTitleLID, AccountsTitleMID, AccountsTitleSID, DrCrFlg, Amount, ControlNo, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $TrnID
        $sql .= ',? ';    // $Line
        $sql .= ',? ';    // $AccTitleLID
        $sql .= ',? ';    // $AccTitleMID
        $sql .= ',? ';    // $AccTitleSID
        $sql .= ',? ';    // $DrCrFlg
        $sql .= ',? ';    // $Amt
        $sql .= ',? ';    // $CtrlNo
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true ) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssss', $TransactionID, $Line, $AccountsTitleLID, $AccountsTitleMID, $AccountsTitleSID, $DrCrFlg, $Amount, $ControlNo, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $TransactionID    = $TrnID;
            $Line             = $Line;
            $AccountsTitleLID = $AccTitleLID;
            $AccountsTitleMID = $AccTitleMID;
            $AccountsTitleSID = $AccTitleSID;
            $DrCrFlg          = $DrCrFlg;
            $Amount           = $Amt;
            $ControlNo        = $CtrlNo;
            $EntDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser          = $userid;
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
/*--------------------------------------------------------*/
/* t_transaction*u_Client*t_salestaxintjournal            */
/*--------------------------------------------------------*/
    // 売上帳(課税取引/国外)を取得する
    public function gSalesTaxIntJournalList($date, $SalesAccL, $SalesAccM, $SalesAccS, $CashAccL, $CashAccM, $CashAccS, $ARAccL, $ARAccM, $ARAccS, $JnlKindID, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_Sub_Sales  = 't_salestaxintjournal AS Sales ';
        $sql_Sub_Sales .= 'ON ( ';
        $sql_Sub_Sales .= '       (t_transaction.TransactionID = Sales.TransactionID) ';
        $sql_Sub_Sales .= '   AND (Sales.AccountsTitleLID      = ?) ';    // $SalesAccL
        $sql_Sub_Sales .= '   AND (Sales.AccountsTitleMID      = ?) ';    // $SalesAccM
        $sql_Sub_Sales .= '   AND (Sales.AccountsTitleSID      = ?) ';    // $SalesAccS
        $sql_Sub_Sales .= '   AND (Sales.Status                = true) ';
        $sql_Sub_Sales .= '   ) ';
        
        $sql_Sub_Cash  = 't_salestaxintjournal AS Cash ';
        $sql_Sub_Cash .= 'ON ( ';
        $sql_Sub_Cash .= '       (t_transaction.TransactionID = Cash.TransactionID) ';
        $sql_Sub_Cash .= '   AND (Cash.AccountsTitleLID      = ?) ';    // $CashAccL
        $sql_Sub_Cash .= '   AND (Cash.AccountsTitleMID      = ?) ';    // $CashAccM
        $sql_Sub_Cash .= '   AND (Cash.AccountsTitleSID      = ?) ';    // $CashAccS
        $sql_Sub_Cash .= '   AND (Cash.Status                = true) ';
        $sql_Sub_Cash .= '   ) ';
        
        $sql_Sub_AR  = 't_salestaxintjournal AS AR ';
        $sql_Sub_AR .= 'ON ( ';
        $sql_Sub_AR .= '       (t_transaction.TransactionID = AR.TransactionID) ';
        $sql_Sub_AR .= '   AND (AR.AccountsTitleLID      = ?) ';    // $ARAccL
        $sql_Sub_AR .= '   AND (AR.AccountsTitleMID      = ?) ';    // $ARAccM
        $sql_Sub_AR .= '   AND (AR.AccountsTitleSID      = ?) ';    // $ARAccS
        $sql_Sub_AR .= '   AND (AR.Status                = true) ';
        $sql_Sub_AR .= '   ) ';
        
        $sql  = 'SELECT t_transaction.TransactionID  ';
        $sql .= '     , t_transaction.TransactionStatusID  ';
        $sql .= '     , t_transaction.Summary  ';
        $sql .= '     , u_client.ClientName  ';
        $sql .= '     , Sales.Amount as SalesAmount ';
        $sql .= '     , Sales.ControlNo as SaleControlNo ';
        $sql .= '     , Cash.Amount as CashAmount ';
        $sql .= '     , Cash.ControlNo as CashControlNo ';
        $sql .= '     , AR.Amount as ARAmount ';
        $sql .= '     , AR.ControlNo as ARControlNo ';
        $sql .= 'FROM   u_client  ';
        $sql .= '     , t_transaction ';
        $sql .= '           LEFT OUTER JOIN '.$sql_Sub_Sales.' ';
        $sql .= '           LEFT OUTER JOIN '.$sql_Sub_Cash.' ';
        $sql .= '           LEFT OUTER JOIN '.$sql_Sub_AR.' ';
        $sql .= 'WHERE  t_transaction.TransactionDate = ? ';    // $date
        $sql .= 'AND    u_client.LanguageID           = ? ';    // $lang
        $sql .= 'AND    t_transaction.JournalKindID   = ? ';    // $JnlKindID
        $sql .= 'AND    t_transaction.ClientID        = u_client.ClientID  ';
        $sql .= 'AND    t_transaction.Status          = true  ';
        $sql .= 'AND    u_client.Status               = true  ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssss', $SalesAccL, $SalesAccM, $SalesAccS, $CashAccL, $CashAccM, $CashAccS, $ARAccL, $ARAccM, $ARAccS, $date, $lang, $JnlKindID);
            $SalesAccL     = $SalesAccL;
            $SalesAccM     = $SalesAccM;
            $SalesAccS     = $SalesAccS;
            $CashAccL      = $CashAccL;
            $CashAccM      = $CashAccM;
            $CashAccS      = $CashAccS;
            $ARAccL        = $ARAccL;
            $ARAccM        = $ARAccM;
            $ARAccS        = $ARAccS;
            $JnlKindID     = $JnlKindID;
            $date          = $date;
            $lang          = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_salestaxintjournal                                   */
/*--------------------------------------------------------*/
    // 売上帳(課税取引/国外)を追加する
    public function iSalesTaxIntJnlInfo($TrnID, $Line, $AccTitleLID, $AccTitleMID, $AccTitleSID, $DrCrFlg, $Amt, $CtrlNo, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_salestaxintjournal(TransactionID, Line, AccountsTitleLID, AccountsTitleMID, AccountsTitleSID, DrCrFlg, Amount, ControlNo, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $TrnID
        $sql .= ',? ';    // $Line
        $sql .= ',? ';    // $AccTitleLID
        $sql .= ',? ';    // $AccTitleMID
        $sql .= ',? ';    // $AccTitleSID
        $sql .= ',? ';    // $DrCrFlg
        $sql .= ',? ';    // $Amt
        $sql .= ',? ';    // $CtrlNo
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true ) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssss', $TransactionID, $Line, $AccountsTitleLID, $AccountsTitleMID, $AccountsTitleSID, $DrCrFlg, $Amount, $ControlNo, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $TransactionID    = $TrnID;
            $Line             = $Line;
            $AccountsTitleLID = $AccTitleLID;
            $AccountsTitleMID = $AccTitleMID;
            $AccountsTitleSID = $AccTitleSID;
            $DrCrFlg          = $DrCrFlg;
            $Amount           = $Amt;
            $ControlNo        = $CtrlNo;
            $EntDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser          = $userid;
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
/*--------------------------------------------------------*/
/* t_transaction*u_Client*t_salesempjournal               */
/*--------------------------------------------------------*/
    // 売上帳(課税取引/国外)を取得する
    public function gSalesEmpJournalList($date, $SalesAccL, $SalesAccM, $SalesAccS, $CashAccL, $CashAccM, $CashAccS, $ARAccL, $ARAccM, $ARAccS, $JnlKindID, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_Sub_Sales  = 't_salesempjournal AS Sales ';
        $sql_Sub_Sales .= 'ON ( ';
        $sql_Sub_Sales .= '       (t_transaction.TransactionID = Sales.TransactionID) ';
        $sql_Sub_Sales .= '   AND (Sales.AccountsTitleLID      = ?) ';    // $SalesAccL
        $sql_Sub_Sales .= '   AND (Sales.AccountsTitleMID      = ?) ';    // $SalesAccM
        $sql_Sub_Sales .= '   AND (Sales.AccountsTitleSID      = ?) ';    // $SalesAccS
        $sql_Sub_Sales .= '   AND (Sales.Status                = true) ';
        $sql_Sub_Sales .= '   ) ';
        
        $sql_Sub_Cash  = 't_salesempjournal AS Cash ';
        $sql_Sub_Cash .= 'ON ( ';
        $sql_Sub_Cash .= '       (t_transaction.TransactionID = Cash.TransactionID) ';
        $sql_Sub_Cash .= '   AND (Cash.AccountsTitleLID      = ?) ';    // $CashAccL
        $sql_Sub_Cash .= '   AND (Cash.AccountsTitleMID      = ?) ';    // $CashAccM
        $sql_Sub_Cash .= '   AND (Cash.AccountsTitleSID      = ?) ';    // $CashAccS
        $sql_Sub_Cash .= '   AND (Cash.Status                = true) ';
        $sql_Sub_Cash .= '   ) ';
        
        $sql_Sub_AR  = 't_salesempjournal AS AR ';
        $sql_Sub_AR .= 'ON ( ';
        $sql_Sub_AR .= '       (t_transaction.TransactionID = AR.TransactionID) ';
        $sql_Sub_AR .= '   AND (AR.AccountsTitleLID      = ?) ';    // $ARAccL
        $sql_Sub_AR .= '   AND (AR.AccountsTitleMID      = ?) ';    // $ARAccM
        $sql_Sub_AR .= '   AND (AR.AccountsTitleSID      = ?) ';    // $ARAccS
        $sql_Sub_AR .= '   AND (AR.Status                = true) ';
        $sql_Sub_AR .= '   ) ';
        
        $sql  = 'SELECT t_transaction.TransactionID  ';
        $sql .= '     , t_transaction.TransactionStatusID  ';
        $sql .= '     , t_transaction.Summary  ';
        $sql .= '     , u_client.ClientName  ';
        $sql .= '     , Sales.Amount as SalesAmount ';
        $sql .= '     , Sales.ControlNo as SalesControlNo ';
        $sql .= '     , Cash.Amount as CashAmount ';
        $sql .= '     , Cash.ControlNo as CashControlNo ';
        $sql .= '     , AR.Amount as ARAmount ';
        $sql .= '     , AR.ControlNo as ARControlNo ';
        $sql .= 'FROM   u_client  ';
        $sql .= '     , t_transaction ';
        $sql .= '           LEFT OUTER JOIN '.$sql_Sub_Sales.' ';
        $sql .= '           LEFT OUTER JOIN '.$sql_Sub_Cash.' ';
        $sql .= '           LEFT OUTER JOIN '.$sql_Sub_AR.' ';
        $sql .= 'WHERE  t_transaction.TransactionDate = ? ';    // $date
        $sql .= 'AND    u_client.LanguageID           = ? ';    // $lang
        $sql .= 'AND    t_transaction.JournalKindID   = ? ';    // $JnlKindID
        $sql .= 'AND    t_transaction.ClientID        = u_client.ClientID  ';
        $sql .= 'AND    t_transaction.Status          = true  ';
        $sql .= 'AND    u_client.Status               = true  ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssss', $SalesAccL, $SalesAccM, $SalesAccS, $CashAccL, $CashAccM, $CashAccS, $ARAccL, $ARAccM, $ARAccS, $date, $lang, $JnlKindID);
            $SalesAccL     = $SalesAccL;
            $SalesAccM     = $SalesAccM;
            $SalesAccS     = $SalesAccS;
            $CashAccL      = $CashAccL;
            $CashAccM      = $CashAccM;
            $CashAccS      = $CashAccS;
            $ARAccL        = $ARAccL;
            $ARAccM        = $ARAccM;
            $ARAccS        = $ARAccS;
            $JnlKindID     = $JnlKindID;
            $date          = $date;
            $lang          = $lang;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_salesempjournal                                      */
/*--------------------------------------------------------*/
    // 売上帳(課税取引/国外)を追加する
    public function iSalesEmpJnlInfo($TrnID, $Line, $AccTitleLID, $AccTitleMID, $AccTitleSID, $DrCrFlg, $Amt, $CtrlNo, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_salesempjournal(TransactionID, Line, AccountsTitleLID, AccountsTitleMID, AccountsTitleSID, DrCrFlg, Amount, ControlNo, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $TrnID
        $sql .= ',? ';    // $Line
        $sql .= ',? ';    // $AccTitleLID
        $sql .= ',? ';    // $AccTitleMID
        $sql .= ',? ';    // $AccTitleSID
        $sql .= ',? ';    // $DrCrFlg
        $sql .= ',? ';    // $Amt
        $sql .= ',? ';    // $CtrlNo
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true ) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssss', $TransactionID, $Line, $AccountsTitleLID, $AccountsTitleMID, $AccountsTitleSID, $DrCrFlg, $Amount, $ControlNo, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $TransactionID    = $TrnID;
            $Line             = $Line;
            $AccountsTitleLID = $AccTitleLID;
            $AccountsTitleMID = $AccTitleMID;
            $AccountsTitleSID = $AccTitleSID;
            $DrCrFlg          = $DrCrFlg;
            $Amount           = $Amt;
            $ControlNo        = $CtrlNo;
            $EntDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser          = $userid;
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
/*--------------------------------------------------------*/
/* t_purchasegoodsdmttemp                                 */
/*--------------------------------------------------------*/
    // 仕入帳(テンポラリ)を追加する
    public function iPurchaseGoodsDmtTempInfo($TrnID, $Line, $Number, $AccTitleLID, $AccTitleMID, $AccTitleSID, $DrCrFlg, $Amt, $CtrlNo, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_purchasegoodsdmttemp(TransactionID, Line, Number, AccountsTitleLID, AccountsTitleMID, AccountsTitleSID, DrCrFlg, Amount, ControlNo, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $TrnID
        $sql .= ',? ';    // $Line
        $sql .= ',? ';    // $Number
        $sql .= ',? ';    // $AccTitleLID
        $sql .= ',? ';    // $AccTitleMID
        $sql .= ',? ';    // $AccTitleSID
        $sql .= ',? ';    // $DrCrFlg
        $sql .= ',? ';    // $Amt
        $sql .= ',? ';    // $CtrlNo
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true ) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssssssssss', $TransactionID, $Line, $Number, $AccountsTitleLID, $AccountsTitleMID, $AccountsTitleSID, $DrCrFlg, $Amount, $ControlNo, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $TransactionID    = $TrnID;
            $Line             = $Line;
            $Number           = $Number;
            $AccountsTitleLID = $AccTitleLID;
            $AccountsTitleMID = $AccTitleMID;
            $AccountsTitleSID = $AccTitleSID;
            $DrCrFlg          = $DrCrFlg;
            $Amount           = $Amt;
            $ControlNo        = $CtrlNo;
            $EntDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser          = $userid;
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }        
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
/*--------------------------------------------------------*/
/* t_specialjournal                                       */
/*--------------------------------------------------------*/
    // 特殊仕訳帳を追加する
    public function iSpecialJournalInfo($pJournalKindID, $pTransactionID, $pRevisionNo, $pLine, $pTransactionDate, $pSectionID, $pSectionLine, $pAccountsTitleID, $pDrCrFlg, $pAmount, 
            $pCurrencyID, $pFxRate, $pFxAmount, $pTaxableAmount, $pFxTaxableAmount, $pSegmentID, $pClientID, $pControlNo, $pDueDate, $pVATType, $pWHTType, $pSummary, $pRemark, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_specialjournal(JournalKindID, TransactionID, RevisionNo, Line, TransactionDate, SectionID, SectionLine, AccountsTitleID, DrCrFlg, Amount, CurrencyID, FxRate, FxAmount, TaxableAmount, FxTaxableAmount, SegmentID, ClientID, ControlNo, DueDate, VATType, WHTType, Summary, Remark, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';	// $pJournalKindID
        $sql .= ',? ';	// $pTransactionID
        $sql .= ',? ';	// $pRevisionNo
        $sql .= ',? ';	// $pLine
        $sql .= ',? ';	// $pTransactionDate
        $sql .= ',? ';	// $pSectionID
        $sql .= ',? ';	// $pSectionLine
        $sql .= ',? ';	// $pAccountsTitleID
        $sql .= ',? ';	// $pDrCrFlg
        $sql .= ',? ';	// $pAmount
        $sql .= ',? ';	// $pCurrencyID
        $sql .= ',? ';	// $pFxRate
        $sql .= ',? ';	// $pFxAmount
        $sql .= ',? ';	// $pTaxableAmount
        $sql .= ',? ';	// $pFxTaxableAmount
        $sql .= ',? ';	// $pSegmentID
        $sql .= ',? ';	// $pClientID
        $sql .= ',? ';	// $pControlNo
        $sql .= ',? ';	// $pDueDate
        $sql .= ',? ';	// $pVATType
        $sql .= ',? ';	// $pWHTType
        $sql .= ',? ';	// $pSummary
        $sql .= ',? ';	// $pRemark
        $sql .= ',? ';	// (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';	// $userid
        $sql .= ',? ';	// (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';	// $userid
        $sql .= ',true ) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssssssssssssssssssssssss', $JournalKindID, $TransactionID, $RevisionNo, $Line, $TransactionDate, $SectionID, $SectionLine, $AccountsTitleID, 
                    $DrCrFlg, $Amount, $CurrencyID, $FxRate, $FxAmount, $TaxableAmount, $FxTaxableAmount, $SegmentID, $ClientID, $ControlNo, $DueDate, $VATType, $WHTType, $Summary, $Remark, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $JournalKindID	= $pJournalKindID;
            $TransactionID	= $pTransactionID;
            $RevisionNo 	= $pRevisionNo;
            $Line		= $pLine;
            $TransactionDate	= $pTransactionDate;
            $SectionID	= $pSectionID;
            $SectionLine		= $pSectionLine;
            $AccountsTitleID	= $pAccountsTitleID;
            $DrCrFlg	= $pDrCrFlg;
            $Amount		= $pAmount;
            $CurrencyID	= $pCurrencyID;
            $FxRate		= $pFxRate;
            $FxAmount	= $pFxAmount;
            $TaxableAmount	= $pTaxableAmount;
            $FxTaxableAmount	= $pFxTaxableAmount;
            $SegmentID	= $pSegmentID;
            $ClientID	= $pClientID;
            $ControlNo	= $pControlNo;
            $DueDate	= $pDueDate;
            $VATType	= $pVATType;
            $WHTType	= $pWHTType;
            $Summary	= $pSummary;
            $Remark 	= $pRemark;
            $EntDate	= (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser	= $userid;
            $UpdDate	= (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser	= $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }        
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 特殊仕訳帳を削除する（仕訳帳ID + 取引ID）
    public function dSpecialJournalInfo($pJournalKindID, $pTransactionID, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE t_specialjournal ';
        $sql .= 'SET    Status        = false ';
        $sql .= '     , UpdDate       = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser       = ? ';    // $userid
        $sql .= '     , DelDate       = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , DelUser       = ? ';    // $userid
        $sql .= 'WHERE  JournalKindID = ? ';    // $$pJournalKindID
        $sql .= 'AND    TransactionID = ? ';    // $pTransactionID
        $sql .= 'AND    Status        = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $JournalKindID, $TransactionID);
            $JournalKindID	= $pJournalKindID;
            $TransactionID	= $pTransactionID;
            $UpdDate       = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser       = $userid;
            $DelDate       = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser       = $userid;
             
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
    
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 特殊仕訳帳データを取得する(1取引分)
    public function gSpeJnlRow($TrnID, $RevNo, $status, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
//        $sql_Status    = self::sArrID('t_specialjournal', $status, 'Status');      // 検索条件(削除ステータス)
        $sql_Status    = self::sDataFlg('t_specialjournal', $status, 'Status');      // 検索条件(削除ステータス)
        
        $sql  = 'SELECT t_specialjournal.SpecialJournalNo ';
        $sql .= '     , t_specialjournal.JournalKindID ';
        $sql .= '     , t_specialjournal.TransactionID ';
        $sql .= '     , t_specialjournal.RevisionNo ';
        $sql .= '     , t_specialjournal.Line ';
        $sql .= '     , t_specialjournal.TransactionDate ';
        $sql .= '     , t_specialjournal.SectionID ';
        $sql .= '     , t_specialjournal.SectionLine ';
        $sql .= '     , t_specialjournal.AccountsTitleID ';
        $sql .= '     , m_accountstitles.AccountsTitleSName ';
        $sql .= '     , t_specialjournal.DrCrFlg ';
        $sql .= '     , t_specialjournal.Amount ';
        $sql .= '     , t_specialjournal.CurrencyID ';
        $sql .= '     , u_currency.CurrencyName ';
        $sql .= '     , u_currency.DecimalLength ';
        $sql .= '     , t_specialjournal.FxRate ';
        $sql .= '     , t_specialjournal.FxAmount ';
        $sql .= '     , t_specialjournal.TaxableAmount ';
        $sql .= '     , t_specialjournal.FxTaxableAmount ';
        $sql .= '     , t_specialjournal.SegmentID ';
        $sql .= '     , u_segment.SegmentName ';
        $sql .= '     , t_specialjournal.ClientID ';
        $sql .= '     , u_client.ClientName ';
        $sql .= '     , t_specialjournal.ControlNo ';
        $sql .= '     , t_specialjournal.DueDate ';
        $sql .= '     , t_specialjournal.VATType ';
        $sql .= '     , t_specialjournal.WHTType ';
        $sql .= '     , m_accountstitles.VATType VATTypeAC ';
        $sql .= '     , m_accountstitles.WHTType WHTTypeAC ';
        $sql .= '     , m_accountstitles.WHTType2 WHTTypeAC2 ';
        $sql .= '     , t_specialjournal.Summary ';
        $sql .= '     , t_specialjournal.Remark ';
        $sql .= '     , t_specialjournal.EntDate ';
        $sql .= '     , t_specialjournal.EntUser ';
        $sql .= '     , t_specialjournal.UpdDate ';
        $sql .= '     , t_specialjournal.UpdUser ';
        $sql .= '     , t_specialjournal.DelDate ';
        $sql .= '     , t_specialjournal.DelUser ';
        $sql .= '     , t_specialjournal.Status ';
        $sql .= 'FROM   t_specialjournal ';
        $sql .= 'LEFT JOIN m_accountstitles ';
        $sql .= 'ON  m_accountstitles.AccountsTitleID = t_specialjournal.AccountsTitleID ';
        $sql .= 'AND m_accountstitles.Status = true ';
        $sql .= 'AND m_accountstitles.LanguageID = ? ';             // $lang
        $sql .= 'LEFT JOIN u_client ';
        $sql .= 'ON  u_client.ClientID = t_specialjournal.ClientID ';
        $sql .= 'AND u_client.LanguageID = m_accountstitles.LanguageID ';
        $sql .= 'AND u_client.Status=TRUE  ';
        $sql .= 'LEFT JOIN u_segment ';
        $sql .= 'ON  u_segment.SegmentID = t_specialjournal.SegmentID ';
        $sql .= 'AND u_segment.LanguageID = m_accountstitles.LanguageID ';
        $sql .= 'AND u_segment.Status=TRUE  ';
        $sql .= 'LEFT JOIN u_currency ';
        $sql .= 'ON  u_currency.CurrencyID = t_specialjournal.CurrencyID ';
        $sql .= 'AND u_currency.LanguageID = m_accountstitles.LanguageID ';
        $sql .= 'AND u_currency.Status=TRUE  ';
        $sql .= 'WHERE  t_specialjournal.TransactionID   = ? ';     // $TrnID
        $sql .= 'AND    t_specialjournal.RevisionNo      = ? ';     // $RevNo
        $sql .= $sql_Status.' ';
        $sql .= 'ORDER BY t_specialjournal.SectionID, t_specialjournal.SectionLine ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $LanguageID, $TransactionID, $RevisionNo);
            $LanguageID     = $lang;
            $TransactionID  = $TrnID;
            $RevisionNo     = $RevNo;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 既に入力された為替レートを取得する
    public function gExchangeRateVal($pJournalKindID, $pTransactionDate, $pCurrencyID, $pDrCrFlg) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_JournalKindID      = self::sDataFlg('t_specialjournal', $pJournalKindID, 'JournalKindID');		// 伝票種別
        $sql_DrCrFlg            = self::sDataFlg('t_specialjournal', $pDrCrFlg, 'DrCrFlg');					// 借方/借方 (0:Dr, 1:Cr)
        
        $sql  = 'SELECT FxRate ';
        $sql .= 'FROM   t_specialjournal ';
        $sql .= 'WHERE  TransactionDate = ? ';    // $pTransactionDate
        $sql .= 'AND    CurrencyID      = ? ';    // $pCurrencyID
        $sql .= $sql_JournalKindID.' ';
        $sql .= $sql_DrCrFlg.' ';
        $sql .= 'AND    Status          = true ';
        $sql .= 'GROUP BY FxRate ';
        $sql .= 'ORDER BY FxRate ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $TransactionDate, $CurrencyID);
            $TransactionDate    = $pTransactionDate;
            $CurrencyID         = $pCurrencyID;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_rate                                                 */
/*--------------------------------------------------------*/
    // 為替レート情報を更新する
    public function uRateInfo($rateno, $currencyid, $transactiondate, $ratetype, $fxrate, $s_userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE t_rate ';
        $sql .= 'SET    CurrencyID          = ? ';    // $currencyid
        $sql .= '     , TransactionDate     = ? ';    // $transactiondate
        $sql .= '     , RateType            = ? ';    // $ratetype
        $sql .= '     , FxRate              = ? ';    // $fxrate
        $sql .= '     , UpdDate             = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser             = ? ';    // $s_userid
        $sql .= 'WHERE  RateNo              = ? ';    // $rateno
        $sql .= 'AND    Status              = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssss', $CurrencyID, $TransactionDate, $RateType, $FxRate, $UpdDate, $UpdUser, $RateNo);
            $CurrencyID         = $currencyid;
            $TransactionDate    = $transactiondate;
            $RateType           = $ratetype;
            $FxRate             = $fxrate;
            $UpdDate            = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser            = $s_userid;
            $RateNo             = $rateno;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 為替レート情報を追加する
    public function iRateInfo($currencyid, $transactiondate, $ratetype, $fxrate, $s_userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_rate(CurrencyID, TransactionDate, RateType, FxRate, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES ( ';
        $sql .= ' ? ';    // $currencyid
        $sql .= ',? ';    // $transactiondate
        $sql .= ',? ';    // $ratetype
        $sql .= ',? ';    // $fxrate
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $s_userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $s_userid
        $sql .= ',true) ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssss', $CurrencyID, $TransactionDate, $RateType, $FxRate, $EntDate, $EntUser, $UpdDate, $UpdUser);
            $CurrencyID         = $currencyid;
            $TransactionDate    = $transactiondate;
            $RateType           = $ratetype;
            $FxRate             = $fxrate;
            $EntDate            = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser            = $s_userid;
            $UpdDate            = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser            = $s_userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 為替レート情報を削除する
    public function dRateInfo($rateno, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE t_rate ';
        $sql .= 'SET    Status  = false ';
        $sql .= '     , UpdDate = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , UpdUser = ? ';    // $userid
        $sql .= '     , DelDate = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '     , DelUser = ? ';    // $userid
        $sql .= 'WHERE  RateNo  = ? ';    // $rateno
        $sql .= 'AND    Status  = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $RateNo);
            $UpdDate = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser = $userid;
            $DelDate = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser = $userid;
            $RateNo  = $rateno;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 為替レート情報を取得する
    public function gRateRow($currencyid, $transactiondate, $ratetype) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT RateNo ';
        $sql .= '     , FxRate ';
        $sql .= 'FROM   t_rate ';
        $sql .= 'WHERE  CurrencyID      = ? ';    // $currencyid
        $sql .= 'AND    TransactionDate = ? ';    // $transactiondate
        $sql .= 'AND    RateType        = ? ';    // $ratetype
        $sql .= 'AND    Status          = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $CurrencyID, $TransactionDate, $RateType);
            $CurrencyID         = $currencyid;
            $TransactionDate    = $transactiondate;
            $RateType           = $ratetype;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* t_fixasset                                 */
/*--------------------------------------------------------*/
    // 同固定資産IDの件数を取得する
    public function gFixAssetIDSameCntVal($AssetID, $AssetNo = -1) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT COUNT(*) AS cnt ';
        $sql .= 'FROM   t_fixasset ';
        $sql .= 'WHERE  FixAssetID =  ? ';    // $FixAssetID
        $sql .= 'AND    FixAssetNo <> ? ';    // $FixAssetNo
        $sql .= 'AND    Status     =  true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $FixAssetID, $FixAssetNo);
            $FixAssetID = $AssetID;
            $FixAssetNo = $AssetNo;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }

    // 固定資産情報を追加する
    public function iFixAsset($pFixAssetID, $pFixAssetName, $pDivisionID, $pAssetID, $pAssetPeriod, $pAssetRate, $pParentAssetNo, $pPurTransactionID, $pAssPurDate, $pDepStaDate, $pDepEndDate, $pEliminateDate, $pEliTransactionID, $pAssPrice, $pRsdPrice, $pSummary, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_fixasset(FixAssetID, FixAssetName, DivisionID, AssetID, AssetPeriod, AssetRate, ParentAssetNo, PurTransactionID, AssPurDate, DepStaDate, DepEndDate, EliminateDate, EliTransactionID, AssPrice, RsdPrice, Summary, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES (';

        $sql .= ' ? ';	// $FixAssetID
        $sql .= ',? ';	// $FixAssetName
        $sql .= ',? ';	// $DivisionNo
        $sql .= ',? ';	// $AssetID
        $sql .= ',? ';	// $AssetPeriod
        $sql .= ',? ';	// $AssetRate
        $sql .= ',? ';	// $ParentAssetNo
        $sql .= ',? ';	// $PurTransactionID
        $sql .= ',? ';	// $AssPurDate
        $sql .= ',? ';	// $DepStaDate
        $sql .= ',? ';	// $DepEndDate
        $sql .= ',? ';	// $EliminateDate
        $sql .= ',? ';	// $EliTransactionID
        $sql .= ',? ';	// $AssPrice
        $sql .= ',? ';	// $RsdPrice
        $sql .= ',? ';	// $Summary
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true ) ';

        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssssssssssss', $FixAssetID, $FixAssetName, $DivisionID, $AssetID, $AssetPeriod, $AssetRate, $ParentAssetNo, $PurTransactionID, $AssPurDate, $DepStaDate, $DepEndDate, $EliminateDate, $EliTransactionID, $AssPrice, $RsdPrice, $Summary, $EntDate, $EntUser, $UpdDate, $UpdUser);

            $FixAssetID	= $pFixAssetID;
            $FixAssetName	= $pFixAssetName;
            $DivisionID	= $pDivisionID;
            $AssetID	= $pAssetID;
            $AssetPeriod	= $pAssetPeriod;
            $AssetRate	= $pAssetRate;
            $ParentAssetNo	= $pParentAssetNo;
            $PurTransactionID	= $pPurTransactionID;
            $AssPurDate	= $pAssPurDate;
            $DepStaDate	= $pDepStaDate;
            $DepEndDate	= $pDepEndDate;
            $EliminateDate	= $pEliminateDate;
            $EliTransactionID	= $pEliTransactionID;
            $AssPrice	= $pAssPrice;
            $RsdPrice	= $pRsdPrice;
            $Summary	= $pSummary;
            $EntDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser          = $userid;
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }

    // 固定資産情報を更新する
    public function uFixAsset($pFixAssetNo, $pFixAssetID, $pFixAssetName, $pDivisionID, $pAssetID, $pAssetPeriod, $pAssetRate, 
			$pParentAssetNo, $pPurTransactionID, $pAssPurDate, $pDepStaDate, $pDepEndDate, $pEliminateDate, 
			$pEliTransactionID, $pAssPrice, $pRsdPrice, $pSummary, $s_userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
		$sql  = ' update t_fixasset ';
		$sql .= ' set ';
		$sql .= ' FixAssetID = ?, ';
		$sql .= ' FixAssetName = ?, ';
		$sql .= ' DivisionID = ?, ';
		$sql .= ' AssetID = ?, ';
		$sql .= ' AssetPeriod = ?, ';
		$sql .= ' AssetRate = ?, ';
		$sql .= ' ParentAssetNo = ?, ';
		$sql .= ' PurTransactionID = ?, ';
		$sql .= ' AssPurDate = ?, ';
		$sql .= ' DepStaDate = ?, ';
		$sql .= ' DepEndDate = ?, ';
		$sql .= ' EliminateDate = ?, ';
		$sql .= ' EliTransactionID = ?, ';
		$sql .= ' AssPrice = ?, ';
		$sql .= ' RsdPrice = ?, ';
		$sql .= ' Summary = ?, ';
		$sql .= ' UpdDate = ?, ';
		$sql .= ' UpdUser = ?, ';
		$sql .= ' Status = true ';
		$sql .= ' where FixAssetNo = ? ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssssssssssssssss', 
				$FixAssetID, $FixAssetName, $DivisionID, $AssetID, $AssetPeriod, $AssetRate, $ParentAssetNo, $PurTransactionID, 
				$AssPurDate, $DepStaDate, $DepEndDate, $EliminateDate, $EliTransactionID, 
				$AssPrice, $RsdPrice, $Summary, $UpdDate, $UpdUser, $FixAssetNo);

			$FixAssetID = $pFixAssetID;
			$FixAssetName = $pFixAssetName;
			$DivisionID = $pDivisionID;
			$AssetID = $pAssetID;
			$AssetPeriod = $pAssetPeriod;
			$AssetRate = $pAssetRate;
			$ParentAssetNo = $pParentAssetNo;
			$PurTransactionID = $pPurTransactionID;
			$AssPurDate = $pAssPurDate;
			$DepStaDate = $pDepStaDate;
			$DepEndDate = $pDepEndDate;
			$EliminateDate = $pEliminateDate;
			$EliTransactionID = $pEliTransactionID;
			$AssPrice = $pAssPrice;
			$RsdPrice = $pRsdPrice;
			$Summary = $pSummary;
			$UpdDate = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
			$UpdUser = $s_userid;
			$FixAssetNo = $pFixAssetNo;

            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 固定資産情報を削除する
    public function dFixAsset($pFixAssetNo, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE t_fixasset ';
        $sql .= 'SET    Status     = false ';
        $sql .= '    ,  UpdDate    = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  UpdUser    = ? ';    // $userid
        $sql .= '    ,  DelDate    = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  DelUser    = ? ';    // $userid
        $sql .= 'WHERE  FixAssetNo = ? ';    // $pFixAssetNo
        $sql .= 'AND    Status   = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $FixAssetNo);
            $UpdDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser    = $userid;
            $DelDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser    = $userid;
            $FixAssetNo = $pFixAssetNo;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }

    // 固定資産情報を取得する(全件)
    public function gFAssList($searchdate1, $syear1, $smonth1, $sday1, $eyear1, $emonth1, $eday1, 
                            $searchdate2, $syear2, $smonth2, $sday2, $eyear2, $emonth2, $eday2, 
                            $assetID, $divisionID, $elitransactionID,
                            $searchText, $pageRowText, $pages, $lang, $blankflg) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $psdate          = self::sSDate2($searchdate1, $syear1, $smonth1, $sday1);    // 検索条件(購入日開始)
        $pedate          = self::sEDate2($searchdate1, $eyear1, $emonth1, $eday1);    // 検索条件(購入日終了)
        $esdate          = self::sSDate2($searchdate2, $syear2, $smonth2, $sday2);    // 検索条件(除却日開始)
        $eedate          = self::sEDate2($searchdate2, $eyear2, $emonth2, $eday2);    // 検索条件(除却日終了)
//        $sql_AssID       = self::sArrID('f', $assetID, 'AssetID');               // 検索条件(固定資産種別)
//        $sql_DivID       = self::sArrID('f', $divisionID, 'DivisionID');         // 検索条件(事業部)
        $sql_AssID       = self::sDataFlg('f', $assetID, 'AssetID');               // 検索条件(固定資産種別)
        $sql_DivID       = self::sDataFlg('f', $divisionID, 'DivisionID');         // 検索条件(事業部)
        $sql_EliID       = self::sDataFlg('f', $elitransactionID, 'EliTransactionID');  // 検索条件(除却取引ID)
        $array           = self::sLimit($pageRowText, $pages);                   // 検索条件(ページング)
        $offset          = $array[0];
        $limit           = $array[1];

        $sql  = 'SELECT f.FixAssetNo ';
        $sql .= '     , f.FixAssetID ';
        $sql .= '     , f.FixAssetName ';
        $sql .= '     , f.DivisionID ';
        $sql .= '     , d.DivisionName ';
        $sql .= '     , f.AssetID ';
        $sql .= '     , a.AssetName ';
        $sql .= '     , f.AssetPeriod ';
        $sql .= '     , f.AssetRate ';
        $sql .= '     , f.ParentAssetNo ';
        $sql .= '     , f.PurTransactionID ';
        $sql .= '     , f.AssPurDate ';
        $sql .= '     , f.DepStaDate ';
        $sql .= '     , f.DepEndDate ';
        $sql .= '     , f.EliminateDate ';
        $sql .= '     , f.EliTransactionID ';
        $sql .= '     , f.AssPrice ';
        $sql .= '     , f.RsdPrice ';
        $sql .= '     , f.Summary ';
        $sql .= '     , f.EntDate ';
        $sql .= '     , CONCAT(f.FixAssetID, \' : \', f.FixAssetName) IDName ';
        $sql .= 'FROM   t_fixasset f ';
        $sql .= 'LEFT JOIN u_asset a on f.AssetID = a.AssetID and a.LanguageID = ? ';    // $lang
        $sql .= 'AND a.Status=TRUE  ';
        $sql .= 'LEFT JOIN u_division d on f.DivisionID = d.DivisionID and d.LanguageID = ? ';    // $lang
        $sql .= 'AND d.Status=TRUE  ';
        $sql .= 'WHERE  f.AssPurDate          >= ? ';    // $psdate
        $sql .= 'AND    f.AssPurDate          <= ? ';    // $pedate
        $sql .= 'AND  ((f.EliminateDate       >= ? ';    // $esdate
        $sql .= 'AND    f.EliminateDate       <= ? ) ';  // $eedate
        $sql .= 'OR     f.EliminateDate       =  \'\' ) '; 
        $sql .= $sql_AssID.' ';
        $sql .= $sql_DivID.' ';
        $sql .= $sql_EliID.' ';
        $sql .= 'AND    ( ';
        $sql .= '           f.FixAssetName LIKE ? ';    // '%'+$searchText+'%'
        $sql .= 'OR         f.FixAssetID LIKE ? ';    // '%'+$searchText+'%'
        $sql .= 'OR         f.Summary LIKE ? ';    // '%'+$searchText+'%'
        $sql .= '       ) ';
        $sql .= 'AND    f.Status= true ';
        $sql .= 'ORDER BY f.FixAssetID ';
        $sql .= 'LIMIT ?, ? ';    // $offset, $limit

        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssssssii', $LanguageID, $LanguageID2, $PSDate, $PEDate, $ESDate, $EEDate, $FixAssetName, $FixAssetID, $Summary, $Offset, $Limit);
            $LanguageID   = $lang;
            $LanguageID2  = $lang;
            $PSDate       = $psdate;
            $PEDate       = $pedate;
            $ESDate       = $esdate;
            $EEDate       = $eedate;
            $FixAssetName = '%'.$searchText.'%';
            $FixAssetID = '%'.$searchText.'%';
            $Summary = '%'.$searchText.'%';
            $Offset       = $offset;
            $Limit        = $limit;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 固定資産情報を取得する(一件用)
    public function gFAssRow($assno, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT f.FixAssetNo ';
        $sql .= '     , f.FixAssetID ';
        $sql .= '     , f.FixAssetName ';
        $sql .= '     , f.DivisionID ';
        $sql .= '     , f.AssetID ';
        $sql .= '     , f.AssetPeriod ';
        $sql .= '     , f.AssetRate ';
        $sql .= '     , f.ParentAssetNo ';
        $sql .= '     , f.PurTransactionID ';
        $sql .= '     , f.AssPurDate ';
        $sql .= '     , f.DepStaDate ';
        $sql .= '     , f.DepEndDate ';
        $sql .= '     , f.EliminateDate ';
        $sql .= '     , f.EliTransactionID ';
        $sql .= '     , f.AssPrice ';
        $sql .= '     , f.RsdPrice ';
        $sql .= '     , f.Summary ';
        $sql .= '     , f.EntDate ';
        $sql .= '     , a.AssetName ';
        $sql .= '     , a.FixAssetAccID ';
        $sql .= '     , a.AccDipreciatedID ';
        $sql .= '     , a.DipreciationAccID ';
        $sql .= '     , a.GainOnDisposalID ';
        $sql .= '     , a.LossOnDisposalID ';
        $sql .= 'FROM   t_fixasset f ';
        $sql .= 'LEFT JOIN u_asset a ';
        $sql .= 'ON  a.Status     = true ';
        $sql .= 'AND a.AssetID    = f.AssetID ';
        $sql .= 'AND a.LanguageID = ? ';        // $lang
        $sql .= 'WHERE  f.FixAssetNo = ? ';     // $assno
        $sql .= 'AND    f.Status     = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $LanguageID, $FixAssetNo);
            $LanguageID = $lang;
            $FixAssetNo = $assno;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 固定資産台帳を取得する(全件)
    public function gFAssLedger($term, $prterm, $searchdate1, $syear1, $smonth1, $sday1, $eyear1, $emonth1, $eday1, 
                            $searchdate2, $syear2, $smonth2, $sday2, $eyear2, $emonth2, $eday2, 
                            $assetID, $divisionID,
                            $searchText, $pageRowText, $pages, $lang, $blankflg) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $psdate          = self::sSDate2($searchdate1, $syear1, $smonth1, $sday1);    // 検索条件(購入日開始)
        $pedate          = self::sEDate2($searchdate1, $eyear1, $emonth1, $eday1);    // 検索条件(購入日終了)
        $esdate          = self::sSDate2($searchdate2, $syear2, $smonth2, $sday2);    // 検索条件(除却日開始)
        $eedate          = self::sEDate2($searchdate2, $eyear2, $emonth2, $eday2);    // 検索条件(除却日終了)
//        $sql_AssID       = self::sArrID('f', $assetID, 'AssetID');               // 検索条件(固定資産種別)
//        $sql_DivID       = self::sArrID('f', $divisionID, 'DivisionID');         // 検索条件(事業部)
        $sql_AssID       = self::sDataFlg('f', $assetID, 'AssetID');               // 検索条件(固定資産種別)
        $sql_DivID       = self::sDataFlg('f', $divisionID, 'DivisionID');         // 検索条件(事業部)
        $array           = self::sLimit($pageRowText, $pages);                   // 検索条件(ページング)
        $offset          = $array[0];
        $limit           = $array[1];


        $sql  = 'SELECT f.FixAssetNo ';
        $sql .= '     , f.FixAssetID ';
        $sql .= '     , f.FixAssetName ';
        $sql .= '     , f.DivisionID ';
        $sql .= '     , d.DivisionName ';
        $sql .= '     , f.AssetID ';
        $sql .= '     , a.AssetName ';
        $sql .= '     , f.AssetPeriod ';
        $sql .= '     , f.AssetRate ';
        $sql .= '     , f.ParentAssetNo ';
        $sql .= '     , f.PurTransactionID ';
        $sql .= '     , f.AssPurDate ';
        $sql .= '     , f.DepStaDate ';
        $sql .= '     , ifnull(d1.DepEndDate, \'\') DepEndDate ';
        $sql .= '     , f.EliminateDate ';
        $sql .= '     , f.EliTransactionID ';
        $sql .= '     , f.Summary ';
        $sql .= '     , ifnull(d2.AssPrice, 0) AssPrice';
        $sql .= '     , ifnull(d2.AssPrice - d2.PrevAccDepAmt - d2.DepreciationAmt, 0) prev ';
        $sql .= '     , ifnull(d1.AssPrice - d1.PrevAccDepAmt, 0) - ifnull(d2.AssPrice - d2.PrevAccDepAmt - d2.DepreciationAmt, 0) fluctuation ';
        $sql .= '     , ifnull(d1.AssPrice - d1.PrevAccDepAmt - d1.DepreciationAmt, 0) balance ';
        $sql .= '     , ifnull(d1.PrevAccDepAmt + d1.DepreciationAmt, 0) accdep ';
        $sql .= '     , ifnull(d1.PrevAccDepAmt, 0) PrevAccDepAmt ';
        $sql .= '     , ifnull(d1.DepreciationAmt, 0) DepreciationAmt ';
        $sql .= '     , ifnull(d1.RsdPrice, 0) RsdPrice ';
        $sql .= '     , f.EntDate  ';
        $sql .= ' FROM t_fixasset f ';
        $sql .= ' LEFT JOIN u_asset a ';
        $sql .= '     ON f.AssetID=a.AssetID ';
        $sql .= '     AND a.LanguageID=? ';             // $LanguageID
        $sql .= '     AND a.Status=TRUE  ';
        $sql .= ' LEFT JOIN u_division d ';
        $sql .= '     ON f.DivisionID=d.DivisionID ';
        $sql .= '     AND d.LanguageID=? ';             // $LanguageID2
        $sql .= '     AND d.Status=TRUE  ';
        $sql .= ' LEFT JOIN t_depreciation d2  ';
        $sql .= '     ON d2.Status=true  ';
        $sql .= '     AND f.FixAssetNo = d2.FixAssetNo  ';
        $sql .= '     AND d2.DepreciationTerm= ? ';     // $PrTerm
        $sql .= '     AND d2.Status=TRUE  ';
        $sql .= ' LEFT JOIN t_depreciation d1 ';
        $sql .= '     ON d1.Status=true  ';
        $sql .= '     AND f.FixAssetNo = d1.FixAssetNo  ';
        $sql .= '     AND d1.DepreciationTerm=? ';          // $Term
        $sql .= '     AND d1.Status=TRUE  ';
        $sql .= 'WHERE  f.Status=true ';
        $sql .= 'AND    f.AssPurDate          >= ? ';    // $psdate
        $sql .= 'AND    f.AssPurDate          <= ? ';    // $pedate
        $sql .= 'AND  ((f.EliminateDate       >= ? ';    // $esdate
        $sql .= 'AND    f.EliminateDate       <= ? ) ';  // $eedate
        $sql .= 'OR     f.EliminateDate       =  \'\' ) '; 
        $sql .= 'AND    ( ';
        $sql .= '           not (d1.FixAssetNo is null) ';
        $sql .= 'OR         not (d2.FixAssetNo is null) ';
        $sql .= '       ) ';
        $sql .= $sql_AssID.' ';
        $sql .= $sql_DivID.' ';
        $sql .= 'AND    ( ';
        $sql .= '           f.FixAssetName LIKE ? ';    // '%'+$searchText+'%'
        $sql .= 'OR         f.FixAssetID LIKE ? ';    // '%'+$searchText+'%'
        $sql .= 'OR         f.Summary LIKE ? ';    // '%'+$searchText+'%'
        $sql .= '       ) ';
        $sql .= 'AND    f.Status= true ';
        $sql .= 'AND    ( ';
        $sql .= '           f.EliminateDate = \'\' ';
        $sql .= 'OR         f.EliminateDate > ? ';    // $PrTerm+'~~'
        $sql .= '       ) ';
        $sql .= 'ORDER BY f.FixAssetID ';
        $sql .= 'LIMIT ?, ? ';    // $offset, $limit

        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssssii', $LanguageID, $LanguageID2, $PrTerm, $Term, $PSDate, $PEDate, $ESDate, $EEDate, $FixAssetName, $FixAssetID, $Summary, $PrTerm2, $Offset, $Limit);
            $LanguageID   = $lang;
            $LanguageID2  = $lang;
            $PrTerm       = $prterm;
            $Term         = $term;
            $PSDate       = $psdate;
            $PEDate       = $pedate;
            $ESDate       = $esdate;
            $EEDate       = $eedate;
            $FixAssetName = '%'.$searchText.'%';
            $FixAssetID   = '%'.$searchText.'%';
            $Summary      = '%'.$searchText.'%';
            $PrTerm2      = $prterm.'~~';
            $Offset       = $offset;
            $Limit        = $limit;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 固定資産台帳(from - to)を取得する(全件)
    public function gFAssLedger2($term, $prterm, 
                            $assetID, $divisionID,
                            $searchText, $pageRowText, $pages, $lang, $blankflg) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
//        $sql_AssID       = self::sArrID('f', $assetID, 'AssetID');               // 検索条件(固定資産種別)
//        $sql_DivID       = self::sArrID('f', $divisionID, 'DivisionID');         // 検索条件(事業部)
        $sql_AssID       = self::sDataFlg('f', $assetID, 'AssetID');               // 検索条件(固定資産種別)
        $sql_DivID       = self::sDataFlg('f', $divisionID, 'DivisionID');         // 検索条件(事業部)
        $array           = self::sLimit($pageRowText, $pages);                   // 検索条件(ページング)
        $offset          = $array[0];
        $limit           = $array[1];

        $sql  = 'SELECT ';
        $sql .= 'f.FixAssetNo,';
        $sql .= 'f.FixAssetID,';
        $sql .= 'f.FixAssetName,';
        $sql .= 'f.DivisionID,';
        $sql .= 'd.DivisionName,';
        $sql .= 'f.AssetID,';
        $sql .= 'a.AssetName,';
        $sql .= 'f.AssetPeriod,';
        $sql .= 'f.AssetRate,';
        $sql .= 'f.AssPurDate,';
        $sql .= 'f.DepStaDate,';
        $sql .= 'f.DepEndDate,';
        $sql .= 'f.EliminateDate,';
        $sql .= 'f.PurTransactionID,';
        $sql .= 'f.EliTransactionID,';
        $sql .= 'f.Summary ';
        $sql .= 'FROM t_fixasset f ';
        $sql .= 'LEFT JOIN u_asset a ';
        $sql .= 'ON a.AssetID=f.AssetID ';
        $sql .= 'AND a.LanguageID=? ';             // $LanguageID
        $sql .= 'AND a.Status=TRUE  ';
        $sql .= 'LEFT JOIN u_division d ';
        $sql .= 'ON d.DivisionID=f.divisionid ';
        $sql .= 'AND d.LanguageID=? ';             // $LanguageID2
        $sql .= 'AND d.Status=TRUE  ';
        $sql .= 'WHERE f.FixAssetNo IN ( ';
        $sql .= 'SELECT fixassetno ';
        $sql .= 'FROM t_depreciation ';
        $sql .= 'WHERE STATUS=true ';
        $sql .= 'AND depreciationterm>= ? ';     // $PrTerm
        $sql .= 'AND depreciationterm<= ? ';     // $Term
        $sql .= ') ';
        $sql .= $sql_AssID.' ';
        $sql .= $sql_DivID.' ';
        $sql .= 'AND    ( ';
        $sql .= '           f.FixAssetName LIKE ? ';    // '%'+$searchText+'%'
        $sql .= 'OR         f.FixAssetID LIKE ? ';    // '%'+$searchText+'%'
        $sql .= 'OR         f.Summary LIKE ? ';    // '%'+$searchText+'%'
        $sql .= '       ) ';
        $sql .= 'AND    f.Status= true ';
        $sql .= 'AND    ( ';
        $sql .= '           f.EliminateDate = \'\' ';
        $sql .= 'OR         f.EliminateDate > ? ';    // $PrTerm+'~~'
        $sql .= '       ) ';
        $sql .= 'ORDER BY f.FixAssetID ';
        $sql .= 'LIMIT ?, ? ';    // $offset, $limit

        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssii', $LanguageID, $LanguageID2, $PrTerm, $Term, $FixAssetName, $FixAssetID, $Summary, $PrTerm2, $Offset, $Limit);
            $LanguageID   = $lang;
            $LanguageID2  = $lang;
            $PrTerm       = $prterm;
            $Term         = $term;
            $FixAssetName = '%'.$searchText.'%';
            $FixAssetID   = '%'.$searchText.'%';
            $Summary      = '%'.$searchText.'%';
            $PrTerm2      = $prterm.'~~';
            $Offset       = $offset;
            $Limit        = $limit;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }

/*--------------------------------------------------------*/
/* t_depreciation                                         */
/*--------------------------------------------------------*/
    // 減価償却情報を追加する
    public function iDepreciation($pFixAssetNo, $pDepreciationTerm, $pDepreciationDate, $pApproveStatus, $pDepreciationAmt, $pDepEndDate, $pAssPrice, $pPrevAccDepAmt, $pRsdPrice, $pRemark, $pApproveDate, $pApproveUser, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'INSERT INTO t_depreciation(FixAssetNo, DepreciationTerm, DepreciationDate, ApproveStatus, DepreciationAmt, DepEndDate, AssPrice, PrevAccDepAmt, RsdPrice, Remark, ApproveDate, ApproveUser, EntDate, EntUser, UpdDate, UpdUser, Status) VALUES (';

        $sql .= ' ? ';	// $FixAssetNo
        $sql .= ',? ';	// $DepreciationTerm
        $sql .= ',? ';	// $DepreciationDate
        $sql .= ',? ';	// $ApproveStatus
        $sql .= ',? ';	// $DepreciationAmt
        $sql .= ',? ';	// $DepEndDate
        $sql .= ',? ';	// $AssPrice
        $sql .= ',? ';	// $PrevAccDepAmt
        $sql .= ',? ';	// $RsdPrice
        $sql .= ',? ';	// $Remark
        $sql .= ',? ';	// $ApproveDate
        $sql .= ',? ';	// $ApproveUser
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= ',? ';    // $userid
        $sql .= ',true ) ';

        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssssssss', $FixAssetNo, $DepreciationTerm, $DepreciationDate, $ApproveStatus, $DepreciationAmt, $DepEndDate, $AssPrice, $PrevAccDepAmt, $RsdPrice, $Remark, $ApproveDate, $ApproveUser, $EntDate, $EntUser, $UpdDate, $UpdUser);

            $FixAssetNo	=	$pFixAssetNo;
            $DepreciationTerm	=	$pDepreciationTerm;
            $DepreciationDate	=	$pDepreciationDate;
            $ApproveStatus	    =	$pApproveStatus;
            $DepreciationAmt	=	$pDepreciationAmt;
            $DepEndDate	        =	$pDepEndDate;
            $AssPrice	        =	$pAssPrice;
            $PrevAccDepAmt	    =	$pPrevAccDepAmt;
            $RsdPrice	        =	$pRsdPrice;
            $Remark	            =	$pRemark;
            $ApproveDate	    =	$pApproveDate;
            $ApproveUser	    =	$pApproveUser;
            $EntDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $EntUser          = $userid;
            $UpdDate          = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser          = $userid;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }

    // 減価償却情報を更新する
    public function uDepreciation($pFixAssetNo, $pDepreciationTerm, $pDepreciationDate, $pApproveStatus, $pDepreciationAmt, 
            $pDepEndDate, $pAssPrice, $pPrevAccDepAmt, $pRsdPrice, $pRemark, $pApproveDate, $pApproveUser, $s_userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
		$sql  = ' update t_depreciation ';
		$sql .= ' set ';
        $sql .= ' DepreciationDate = ?, ';
        $sql .= ' ApproveStatus = ?, ';
        $sql .= ' DepreciationAmt = ?, ';
        $sql .= ' DepEndDate = ?, ';
        $sql .= ' AssPrice = ?, ';
        $sql .= ' PrevAccDepAmt = ?, ';
        $sql .= ' RsdPrice = ?, ';
        $sql .= ' Remark = ?, ';
        $sql .= ' ApproveDate = ?, ';
        $sql .= ' ApproveUser = ?, ';
        $sql .= ' UpdDate = ?, ';
        $sql .= ' UpdUser = ?, ';
		$sql .= ' Status = true ';
		$sql .= ' where FixAssetNo = ? ';
		$sql .= ' and   DepreciationTerm = ? ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssssssssssss', 
				$DepreciationDate, $ApproveStatus, $DepreciationAmt, $DepEndDate, $AssPrice, $PrevAccDepAmt, $RsdPrice, 
                $Remark, $ApproveDate, $ApproveUser, $UpdDate, $UpdUser, $FixAssetNo, $DepreciationTerm);

            $DepreciationDate	=	$pDepreciationDate;
            $ApproveStatus	    =	$pApproveStatus;
            $DepreciationAmt	=	$pDepreciationAmt;
            $DepEndDate	        =	$pDepEndDate;
            $AssPrice	        =	$pAssPrice;
            $PrevAccDepAmt	    =	$pPrevAccDepAmt;
            $RsdPrice	        =	$pRsdPrice;
            $Remark	            =	$pRemark;
            $ApproveDate	    =	$pApproveDate;
            $ApproveUser	    =	$pApproveUser;
			$UpdDate            =   (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
			$UpdUser            =   $s_userid;
            $FixAssetNo	        =	$pFixAssetNo;
            $DepreciationTerm	=	$pDepreciationTerm;

            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }
    
    // 最後の償却計算月？を取得する （パラメータは計算状況フラグ）
    public function gFinalDepreciationCalcMonth($CalcStatus = NULL, $Direction = true) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ';
        if ($Direction) {
            $sql  .= 'MAX(DepreciationTerm) AS DepreciationTerm ';
        } else {
            $sql  .= 'MIN(DepreciationTerm) AS DepreciationTerm ';
        }
        $sql .= 'FROM   t_depreciation ';
        $sql .= 'WHERE  Status     =  true ';
        $sql .= 'AND   (ApproveStatus = ? ';    // $ApproveStatus
        if ($CalcStatus == NULL){
            $sql .= 'OR     true ';
        }
        $sql .= ')';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $ApproveStatus);
            $ApproveStatus = $CalcStatus;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }

    // 指定された月の償却データの件数を取得する
    public function gDepreciationCntVal($pDepreciationTerm, $CalcStatus = NULL) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT COUNT(*) AS cnt ';
        $sql .= 'FROM   t_depreciation ';
        $sql .= 'WHERE  Status     =  true ';
        $sql .= 'AND    DepreciationTerm    = ? ';    // $DepreciationTerm
        $sql .= 'AND   (ApproveStatus       = ? ';    // $ApproveStatus
        if ($CalcStatus == NULL){
            $sql .= 'OR     true ';
        }
        $sql .= ')';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $DepreciationTerm, $ApproveStatus);
            $DepreciationTerm = $pDepreciationTerm;
            $ApproveStatus = $CalcStatus;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }

    // 指定された資産の指定された月以前の償却額の合計を取得する
    public function gAccumulateDepreciation($pFixAssetNo, $pDepreciationTerm) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT ifnull(SUM(DepreciationAmt), 0) AS DepreciationAmt ';
        $sql .= 'FROM   t_depreciation ';
        $sql .= 'WHERE  Status              =  true ';
        $sql .= 'AND    FixAssetNo          = ? ';    // $FixAssetNo
        $sql .= 'AND    DepreciationTerm    < ? ';    // $DepreciationTerm
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ss', $FixAssetNo, $DepreciationTerm);
            $FixAssetNo = $pFixAssetNo;
            $DepreciationTerm = $pDepreciationTerm;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 減価償却情報を取得する(一件用)
    public function gDepreciationRow($pFixAssetNo, $pDepreciationTerm, $pStatus = NULL) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT DepreciationNo ';
        $sql .= '     , FixAssetNo ';
        $sql .= '     , DepreciationTerm ';
        $sql .= '     , DepreciationDate ';
        $sql .= '     , ApproveStatus ';
        $sql .= '     , DepreciationAmt ';
        $sql .= '     , DepEndDate ';
        $sql .= '     , AssPrice ';
        $sql .= '     , PrevAccDepAmt ';
        $sql .= '     , RsdPrice ';
        $sql .= '     , Remark ';
        $sql .= '     , ApproveDate ';
        $sql .= '     , ApproveUser ';
        $sql .= 'FROM   t_depreciation ';
        $sql .= 'WHERE  DepreciationTerm    = ? ';    // $DepreciationTerm
        $sql .= 'AND   (FixAssetNo          = ? ';    // $FixAssetNo
        if ($pFixAssetNo == NULL) {
            $sql .= 'OR     true ';
        }
        $sql .= ') ';
        $sql .= 'AND   (Status              = ? ';    // $Status
        if ($pStatus == NULL) {
            $sql .= 'OR     true ';
        }
        $sql .= ') ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $DepreciationTerm, $FixAssetNo, $Status);
            $FixAssetNo         = $pFixAssetNo;
            $DepreciationTerm   = $pDepreciationTerm;
            $Status             = $pStatus;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }

    // 減価償却情報を削除する
    public function dDepreciation($pDepreciationTerm, $pFixAssetNo, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  = 'UPDATE t_depreciation ';
        $sql .= 'SET    Status     = false ';
        $sql .= '    ,  UpdDate    = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  UpdUser    = ? ';    // $userid
        $sql .= '    ,  DelDate    = ? ';    // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .= '    ,  DelUser    = ? ';    // $userid
        $sql .= 'WHERE  DepreciationTerm = ? ';    // $DepreciationTerm
        $sql .= 'AND   (FixAssetNo = ? ';    // $FixAssetNo
        if ($pFixAssetNo == NULL) {
        $sql .= 'OR     true ';    // $Status
        }
        $sql .= ') ';
        $sql .= 'AND    Status   = true ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('ssssss', $UpdDate, $UpdUser, $DelDate, $DelUser, $DepreciationTerm, $FixAssetNo);
            $UpdDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser    = $userid;
            $DelDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $DelUser    = $userid;
            $DepreciationTerm = $pDepreciationTerm;
            $FixAssetNo = $pFixAssetNo;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }

    // 減価償却情報の承認（承認キャンセル）を行う
    public function aDepreciation($pflg, $pDepreciationTerm, $pFixAssetNo, $userid, $mysqli, $trnflg) {
        $this->CL['LG']->cLog('T0002');
        $mysqli = self::DBConnect($mysqli, $trnflg);
        
        $sql  ='update t_depreciation ';
        $sql .='set ';
        $sql .='    ApproveStatus = ? ';    // $ApproveStatus
        $sql .='   ,ApproveDate = ? ';      // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .='   ,ApproveUser = ? ';      // $userid
        $sql .='   ,UpdDate = ? ';          // (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s')
        $sql .='   ,UpdUser = ? ';          // $userid
        $sql .='where   DepreciationTerm = ? ';    // $DepreciationTerm
        $sql .= 'AND   (FixAssetNo = ? ';   // $FixAssetNo
        if ($pFixAssetNo == NULL) {
        $sql .= 'OR     true ';    // $Status
        }
        $sql .= ') ';
        $sql .='and     Status = true ';

        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sssssss', $ApproveStatus, $ApproveDate, $ApproveUser, $UpdDate, $UpdUser, $DepreciationTerm, $FixAssetNo);
            if ($pflg) {
                $ApproveStatus  = $this->CL['DF']->trnSts_Approved;
                $ApproveDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
                $ApproveUser    = $userid;
            } else {
                $ApproveStatus  = $this->CL['DF']->trnSts_Unapprove;
                $ApproveDate    = NULL;
                $ApproveUser    = '';
            }
            $UpdDate    = (new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s');
            $UpdUser    = $userid;
            $DepreciationTerm = $pDepreciationTerm;
            $FixAssetNo = $pFixAssetNo;
            
            $stmt->execute();
            $ret = self::gResult($mysqli, $sql, json_encode(func_get_args()));
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
            $ret = false;
        }
        self::DBClose($mysqli, $trnflg);
        return $ret;
    }

    // 固定資産種別毎計算結果を取得する
    public function gDepListByType($Mth1, $Mth2, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql	=	'SELECT ';
		$sql	.=	'f.AssetID,';
		$sql	.=	'a.AssetName,';
		$sql	.=	'COUNT(f.FixAssetNo) cnt,';
		$sql	.=	'SUM(IFNULL(d1.AssPrice - d1.PrevAccDepAmt - d1.DepreciationAmt,0)) beginning,';
		$sql	.=	'SUM(IFNULL(d2.AssPrice - d2.PrevAccDepAmt,0) - IFNULL(d1.AssPrice - d1.PrevAccDepAmt - d1.DepreciationAmt,0)) fluctuation,';
		$sql	.=	'SUM(IFNULL(d2.DepreciationAmt,0)) DepreciationAmt,';
		$sql	.=	'SUM(IFNULL(d2.AssPrice - d2.PrevAccDepAmt - d2.DepreciationAmt,0)) ending ';
		$sql	.=	'FROM t_fixasset f ';
		$sql	.=	'LEFT JOIN u_asset a ';
		$sql	.=	'    ON  f.AssetID=a.AssetID ';
		$sql	.=	'    AND a.LanguageID=? ';               // $LanguageID
        $sql	.=	'    AND a.Status=TRUE  ';
		$sql	.=	'LEFT JOIN t_depreciation d1 ';
		$sql	.=	'    ON  d1.STATUS=TRUE ';
		$sql	.=	'    AND f.FixAssetNo=d1.FixAssetNo ';
		$sql	.=	'    AND d1.DepreciationTerm= ? ';          // $Month1 (previous month)
		$sql	.=	'LEFT JOIN t_depreciation d2 ';
		$sql	.=	'    ON  d2.STATUS=TRUE ';
		$sql	.=	'    AND f.FixAssetNo=d2.FixAssetNo ';
		$sql	.=	'    AND d2.DepreciationTerm= ? ';          // $Month2 (this month)
		$sql	.=	'WHERE f.Status=TRUE ';
		$sql	.=	'AND (NOT(d1.DepreciationNo IS NULL AND d2.DepreciationNo IS NULL)) ';
		$sql	.=	'GROUP BY f.AssetID, a.AssetName';

        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $LanguageID, $Month1, $Month2);
            $LanguageID   = $lang;
            $Month1       = $Mth1;
            $Month2       = $Mth2;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*--------------------------------------------------------*/
/* ***                                                    */
/*--------------------------------------------------------*/
    // 特殊仕訳帳(各種)の合計金額を取得する
    public function gSpeJnlAmtList($TrnID, $TableName) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql  = 'SELECT SUM(Amount) AS Amount ';
        $sql .= 'FROM '.$TableName.' ';
        $sql .= 'WHERE  DrCrFlg = 0 ';
        $sql .= 'AND    TransactionID = ? ';    // $TrnID
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('s', $targetTrnID);
            $targetTrnID = $TrnID;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 特殊仕訳帳(各種)の勘定科目毎の合計金額を取得する
    public function gSpeJnlAmtAccList($TrnID) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_TransactionID      = self::sArrTransactionID('t_specialjournal', $TrnID);              // 検索条件(取引ID)
        
        $sql  = 'SELECT t_specialjournal.SectionID ';
        $sql .= '     , m_accountstitles.AccountID ';
        $sql .= '     , m_accountstitles.SubLedgerFlg ';
        $sql .= '     , t_specialjournal.DrCrFlg ';
        $sql .= '     , SUM(t_specialjournal.Amount) AS Amount ';
        $sql .= 'FROM t_specialjournal ';
        $sql .= 'LEFT JOIN (SELECT DISTINCT AccountsTitleID, CASE WHEN ControlAccountID=\'\' THEN AccountsTitleID ELSE ControlAccountID END AccountID, SubLedgerFlg ';
        $sql .= 'FROM m_accountstitles where m_accountstitles.Status = true) m_accountstitles ';
        $sql .= 'ON t_specialjournal.AccountsTitleID = m_accountstitles.AccountsTitleID ';
        $sql .= 'WHERE t_specialjournal.Status = true ';
        $sql .= $sql_TransactionID.' ';
        $sql .= 'GROUP BY t_specialjournal.SectionID, m_accountstitles.AccountID, t_specialjournal.DrCrFlg, m_accountstitles.SubLedgerFlg ';
        $sql .= 'ORDER BY t_specialjournal.SectionID, m_accountstitles.AccountID, t_specialjournal.DrCrFlg, m_accountstitles.SubLedgerFlg ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
    // 特殊仕訳帳用に勘定科目リストを取得する
    public function gSpeJnlAccList($TrnKindID, $sdate, $edate, $trnsts, $JnlKindID, $status, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_TrnKindID = self::sArrTrnKindID('t_transaction', $TrnKindID);      // 検索条件(取引種別)
        $sql_JnlKindID = self::sArrJnlKindID('t_transaction', $JnlKindID);      // 検索条件(仕訳帳種別)
        $sql_TrnSts    = self::sArrTrnSts('t_transaction', $trnsts);            // 検索条件(取引ステータス)
//        $sql_Status    = self::sArrID('t_transaction', $status, 'Status');      // 検索条件(削除ステータス)
        $sql_Status    = self::sDataFlg('t_transaction', $status, 'Status');      // 検索条件(削除ステータス)
        
        $sql  = 'SELECT t_specialjournal.SectionID ';
        $sql .= '     , t_specialjournal.AccountsTitleID ';
        $sql .= '     , m_accountstitles.AccountsTitleSName ';
        $sql .= 'FROM   t_specialjournal ';
        $sql .= 'LEFT JOIN t_transaction ';
        $sql .= 'ON  t_transaction.TransactionID  = t_specialjournal.TransactionID ';
        $sql .= 'AND t_transaction.RevisionNo = t_specialjournal.RevisionNo ';
        $sql .= 'LEFT JOIN m_accountstitles ';
        $sql .= 'ON  m_accountstitles.AccountsTitleID = t_specialjournal.AccountsTitleID ';
        $sql .= 'AND m_accountstitles.LanguageID = ? ';      // $lang
        $sql .=	'AND m_accountstitles.Status=TRUE  ';
        $sql .= 'WHERE  t_transaction.TransactionDate >= ? ';     // $sdate
        $sql .= 'AND    t_transaction.TransactionDate <= ? ';     // $edate
        $sql .= $sql_TrnKindID.' ';
        $sql .= $sql_JnlKindID.' ';
        $sql .= $sql_TrnSts.' ';
        $sql .= $sql_Status.' ';
        $sql .= 'GROUP BY t_specialjournal.SectionID, t_specialjournal.AccountsTitleID, m_accountstitles.AccountsTitleSName ';
        $sql .= 'ORDER BY t_specialjournal.SectionID, t_specialjournal.AccountsTitleID, m_accountstitles.AccountsTitleSName ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $LanguageID, $SEntDate, $EEntDate);
            $LanguageID    = $lang;
            $SEntDate      = $sdate;
            $EEntDate      = $edate;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }

    // 特殊仕訳帳データを取得する(指定された条件で)
    public function gSpeJnlList($TrnKindID, $sdate, $edate, $trnsts, $JnlKindID, $section, $accid, $TrnID, $status, $lang) {
        $this->CL['LG']->cLog('T0002');
        $result = '';
        $mysqli = self::DBConnect();
        
        $sql_JnlKindID = self::sArrJnlKindID('t_specialjournal', $JnlKindID);              // 検索条件(仕訳帳種別)
        $sql_TrnSts    = self::sArrTrnSts('t_transaction', $trnsts);                    // 検索条件(取引ステータス)
//        $sql_Section   = self::sArrID('t_specialjournal', $section, 'SectionID');       // 検索条件(セクションID)
//        $sql_TitleID   = self::sArrID('t_specialjournal', $accid, 'AccountsTitleID');   // 検索条件(勘定科目)
        $sql_Section   = self::sDataFlg('t_specialjournal', $section, 'SectionID');       // 検索条件(セクションID)
        $sql_TitleID   = self::sDataFlg('t_specialjournal', $accid, 'AccountsTitleID');   // 検索条件(勘定科目)
        $sql_TransactionID  = self::sArrTransactionID('t_specialjournal', $TrnID);      // 検索条件(取引ID)
//        $sql_Status    = self::sArrID('t_specialjournal', $status, 'Status');           // 検索条件(削除ステータス)
        $sql_Status    = self::sDataFlg('t_specialjournal', $status, 'Status');           // 検索条件(削除ステータス)
        
        $sql  = 'SELECT t_specialjournal.SpecialJournalNo ';
        $sql .= '     , t_specialjournal.JournalKindID ';
        $sql .= '     , t_specialjournal.TransactionID ';
        $sql .= '     , t_specialjournal.RevisionNo ';
        $sql .= '     , t_specialjournal.Line ';
        $sql .= '     , t_specialjournal.TransactionDate ';
        $sql .= '     , t_specialjournal.SectionID ';
        $sql .= '     , t_specialjournal.SectionLine ';
        $sql .= '     , t_specialjournal.AccountsTitleID ';
        $sql .= '     , m_accountstitles.AccountsTitleSName ';
        $sql .= '     , t_specialjournal.DrCrFlg ';
        $sql .= '     , t_specialjournal.Amount ';
        $sql .= '     , t_specialjournal.CurrencyID ';
        $sql .= '     , u_currency.CurrencyName ';
        $sql .= '     , u_currency.DecimalLength ';
        $sql .= '     , t_specialjournal.FxRate ';
        $sql .= '     , t_specialjournal.FxAmount ';
        $sql .= '     , t_specialjournal.TaxableAmount ';
        $sql .= '     , t_specialjournal.FxTaxableAmount ';
        $sql .= '     , t_specialjournal.SegmentID ';
        $sql .= '     , u_segment.SegmentName ';
        $sql .= '     , t_specialjournal.ClientID ';
        $sql .= '     , u_client.ClientName ';
        $sql .= '     , t_specialjournal.ControlNo ';
        $sql .= '     , t_specialjournal.DueDate ';
        $sql .= '     , t_specialjournal.VATType ';
        $sql .= '     , t_specialjournal.WHTType ';
        $sql .= '     , t_specialjournal.Summary ';
        $sql .= '     , t_specialjournal.Remark ';
        $sql .= '     , t_specialjournal.EntDate ';
        $sql .= '     , t_specialjournal.EntUser ';
        $sql .= '     , t_specialjournal.UpdDate ';
        $sql .= '     , t_specialjournal.UpdUser ';
        $sql .= '     , t_specialjournal.DelDate ';
        $sql .= '     , t_specialjournal.DelUser ';
        $sql .= '     , t_specialjournal.Status ';
        $sql .= 'FROM   t_specialjournal ';
        $sql .= 'LEFT JOIN m_accountstitles ';
        $sql .= 'ON  m_accountstitles.AccountsTitleID = t_specialjournal.AccountsTitleID ';
        $sql .= 'AND m_accountstitles.LanguageID = ? ';             // $lang
        $sql .=	'AND m_accountstitles.Status=TRUE  ';
        $sql .= 'LEFT JOIN u_client ';
        $sql .= 'ON  u_client.ClientID = t_specialjournal.ClientID ';
        $sql .= 'AND u_client.LanguageID = m_accountstitles.LanguageID ';
        $sql .=	'AND u_client.Status=TRUE  ';
        $sql .= 'LEFT JOIN u_segment ';
        $sql .= 'ON  u_segment.SegmentID = t_specialjournal.SegmentID ';
        $sql .= 'AND u_segment.LanguageID = m_accountstitles.LanguageID ';
        $sql .=	'AND u_segment.Status=TRUE  ';
        $sql .= 'LEFT JOIN u_currency ';
        $sql .= 'ON  u_currency.CurrencyID = t_specialjournal.CurrencyID ';
        $sql .= 'AND u_currency.LanguageID = m_accountstitles.LanguageID ';
        $sql .=	'AND u_currency.Status=TRUE  ';
        $sql .= 'WHERE  t_specialjournal.TransactionDate >= ? ';     // $sdate
        $sql .= 'AND    t_specialjournal.TransactionDate <= ? ';     // $edate
        $sql .= $sql_JnlKindID.' ';
        $sql .= $sql_TrnSts.' ';
        $sql .= $sql_Section.' ';
        $sql .= $sql_TitleID.' ';
        $sql .= $sql_Status.' ';
        $sql .= 'ORDER BY t_specialjournal.SectionID, t_specialjournal.SectionLine ';
        
        if ($stmt = $mysqli->prepare($sql)) {
            $stmt->bind_param('sss', $LanguageID, $SEntDate, $EEntDate);
            $LanguageID     = $lang;
            $SEntDate      = $sdate;
            $EEntDate      = $edate;
            
            $stmt->execute();
            if (self::gResult($mysqli, $sql, json_encode(func_get_args()))) {
                $result = self::fetch_all($stmt);
            } else {
                $result = false;
            }
            $stmt->free_result();
            $stmt->close();
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, json_encode(func_get_args())));
                $result = false;
        }
        self::DBClose($mysqli);
        return $result;
    }
    
/*----------------------------------------------------------------------------*/
/* Private Function                                                           */
/*----------------------------------------------------------------------------*/
/*--------------------------------------------------------*/
/* common                                                 */
/*--------------------------------------------------------*/
    // mysqli_errnoを判定する
    private function gResult($mysqli, $sql = '', $params = NULL) {
        $this->CL['LG']->cLog('T0002');
        if (mysqli_errno($mysqli) == $this->CL['DF']->mysqli_errno_success) {
            return true;
        } else {
            $this->CL['LG']->cLog('F0002', array($mysqli->error, $sql, $params));
            return false;
        }
    }
    
    // fetch_all
    private function fetch_all(&$stmt) {
        $this->CL['LG']->cLog('T0002');
        $hits = array();
        $params = array();
        $meta = $stmt->result_metadata();
        while ($field = $meta->fetch_field()) {
            $params[] = &$row[$field->name];
        }
        call_user_func_array(array($stmt, 'bind_result'), $params);
        while ($stmt->fetch()) {
            $c = array();
            foreach($row as $key => $val) {
                $c[$key] = $val;
            }
            $hits[] = $c;
        }
        return $hits;
    }
    
/*--------------------------------------------------------*/
/* Search Condition(Val)                                  */
/*--------------------------------------------------------*/
    // テーブル名設定
    private function gTable($tbl) {
        $this->CL['LG']->cLog('T0002');
        if (isset($tbl)) {
            return $tbl.'.';
        } else {
            return '';
        }
    }
    
    // 検索条件(開始日)
    private function sSDate($searchdate, $syear, $smonth, $sday) {
        $this->CL['LG']->cLog('T0002');
        if (isset($searchdate)) {
            return $syear.'-'.str_pad($smonth, $this->CL['DF']->LenMonth, $this->CL['DF']->ZERO, STR_PAD_LEFT).'-'.str_pad($sday, $this->CL['DF']->LenDay, $this->CL['DF']->ZERO, STR_PAD_LEFT).' '.$this->CL['DF']->NewestHMS;
        } else {
            return $this->CL['DF']->NewestDate;
        }
    }
    
    // 検索条件(終了日)
    private function sEDate($searchdate, $eyear, $emonth, $eday) {
        $this->CL['LG']->cLog('T0002');
        if (isset($searchdate)) {
            return $eyear.'-'.str_pad($emonth, $this->CL['DF']->LenMonth, $this->CL['DF']->ZERO, STR_PAD_LEFT).'-'.str_pad($eday, $this->CL['DF']->LenDay, $this->CL['DF']->ZERO, STR_PAD_LEFT).' '.$this->CL['DF']->OldestHMS;
        } else {
            return $this->CL['DF']->OldestDate;
        }
    }
    
    // 検索条件(開始日)
    private function sSDate2($searchdate, $syear, $smonth, $sday) {
        $this->CL['LG']->cLog('T0002');
        if (isset($searchdate)) {
            return $syear.str_pad($smonth, $this->CL['DF']->LenMonth, $this->CL['DF']->ZERO, STR_PAD_LEFT).str_pad($sday, $this->CL['DF']->LenDay, $this->CL['DF']->ZERO, STR_PAD_LEFT);
        } else {
            return $this->CL['DF']->NewestDate2;
        }
    }
    
    // 検索条件(終了日)
    private function sEDate2($searchdate, $eyear, $emonth, $eday) {
        $this->CL['LG']->cLog('T0002');
        if (isset($searchdate)) {
            return $eyear.str_pad($emonth, $this->CL['DF']->LenMonth, $this->CL['DF']->ZERO, STR_PAD_LEFT).str_pad($eday, $this->CL['DF']->LenDay, $this->CL['DF']->ZERO, STR_PAD_LEFT);
        } else {
            return $this->CL['DF']->OldestDate2;
        }
    }
    
    // 検索条件(空白行フラグ)
    private function sCltNo($blankflg) {
        $this->CL['LG']->cLog('T0002');
        if ($blankflg == $this->CL['DF']->blankHide) {
            return $this->CL['DF']->CltBlkE;
        } else {
            return $this->CL['DF']->CltBlkS;
        }
    }
    
    // 検索条件(ページング)
    private function sLimit($pageRowText, $pages) {
        $this->CL['LG']->cLog('T0002');
        if ((isset($pageRowText)) && (isset($pages)) && ($pageRowText != '')) {
            $limit = $pageRowText;
            $offset = ($pages-1)*$limit;
            return array($offset, $limit);
        } else if ((isset($pageRowText)) && ($pageRowText != '')) {
            $limit = $pageRowText;
            return array(0, $limit);
        } else {
            return array(0, $this->CL['DF']->intmax);
        }
    }
    
/*--------------------------------------------------------*/
/* Search Condition(SQL-Single)                           */
/*--------------------------------------------------------*/
    // 検索条件(各種フラグ)
    private function sDataFlg($tbl, $val, $flgname, $orblank = false) {
        $this->CL['LG']->cLog('T0002');
        $mTbl = self::gTable($tbl);
        if ($val == NULL) {
            // 検索対象：全て
            return '';
        }
        if (is_array($val)) {
            if (count($val) == 0) {
                return '';
            } 
            if (array_values($val)[0] == $this->CL['DF']->ALL) {
                return '';
            }
            $work = 'AND ( ';
            foreach ($val AS $value ) {
                $work .= '('.$mTbl.$flgname.' = \''.$value.'\') OR ';
            }
            if ($orblank) {
                $work .= '('.$mTbl.$flgname.' = \'\') OR ';
            }
            $work .= ') ';
            return str_replace(') OR )', ') )', $work);
            
        } else {
            if ($orblank) {
                return 'AND ('.$mTbl.$flgname.' = \''.$val.'\' OR '.$mTbl.$flgname.' = \'\') ';
            } else {
                return 'AND '.$mTbl.$flgname.' = \''.$val.'\' ';
            }
        }
    }
    
    // 検索条件(各種フラグ、Or条件)
    private function sDataFlgOr($tbl, $val, $flgname, $orblank = false) {
        $this->CL['LG']->cLog('T0002');
        $mTbl = self::gTable($tbl);
        if ($val == NULL) {
            // 検索対象：全て
            return '';
        }
        if (is_array($val)) {
            if (count($val) == 0) {
                return '';
            } 
            if (array_values($val)[0] == $this->CL['DF']->ALL) {
                return '';
            }
            $work = 'OR ( ';
            foreach ($val AS $value ) {
                $work .= '('.$mTbl.$flgname.' = \''.$value.'\') OR ';
            }
            if ($orblank) {
                $work .= '('.$mTbl.$flgname.' = \'\') OR ';
            }
            $work .= ') ';
            return str_replace(') OR )', ') )', $work);
            
        } else {
            if ($orblank) {
                return 'OR ('.$mTbl.$flgname.' = \''.$val.'\' OR '.$mTbl.$flgname.' = \'\') ';
            } else {
                return 'OR '.$mTbl.$flgname.' = \''.$val.'\' ';
            }
        }
    }
    
    // 検索条件(取引種別)
    private function sTrnKindID($tbl, $TrnKindID) {
        $this->CL['LG']->cLog('T0002');
        $mTbl = self::gTable($tbl);
        if ($TrnKindID != NULL) {
            // 検索対象：全て
            return 'AND '.$mTbl.'TransactionKindID = \''.$TrnKindID.'\' ';
        } else {
            return '';
        }
    }
    
    // 検索条件(仕訳ステータス)
    private function sPopSts($tbl, $popSts) {
        $this->CL['LG']->cLog('T0002');
        $mTbl = self::gTable($tbl);
        if (!empty($popSts)) {
            return 'AND '.$mTbl.'Status = true ';
        } else {
            return '';
        }
    }
    
    // 検索条件(処理日)
    private function sPostDate($tbl, $trnsts, $userid) {
        $this->CL['LG']->cLog('T0002');
        $mTbl = self::gTable($tbl);
        if ($trnsts == $this->CL['DF']->trnSts_Posted) {
            // 転記済
            return ', '.$mTbl.'PostDate = \''.(new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s').'\' ';
        } else if ($trnsts == $this->CL['DF']->trnSts_Approved) {
            // 承認済
            return ', '.$mTbl.'ApproveDate = \''.(new DateTime('NOW', new DateTimeZone('UTC')))->format('Y-m-d H:i:s').'\' ';
        } else if ($trnsts == $this->CL['DF']->trnSts_Unapprove) {
            // 未承認
            return ', '.$mTbl.'ApproveDate = NULL ';
        } else {
            return '';
        }
    }
    
    // 検索条件(処理者)
    private function sPostUser($tbl, $trnsts, $userid) {
        $this->CL['LG']->cLog('T0002');
        $mTbl = self::gTable($tbl);
        if ($trnsts == $this->CL['DF']->trnSts_Posted) {
            // 転記済
            return ', '.$mTbl.'PostUser = \''.$userid.'\' ';
        } else if ($trnsts == $this->CL['DF']->trnSts_Approved) {
            // 承認済
            return ', '.$mTbl.'ApproveUser = \''.$userid.'\' ';
        } else if ($trnsts == $this->CL['DF']->trnSts_Unapprove) {
            // 未承認
            return ', '.$mTbl.'ApproveUser = NULL ';
        } else {
            return '';
        }
    }
    
    // 検索条件(仕入先フラグ)
    private function sSupplierFlg($tbl, $SupplierFlg) {
        $this->CL['LG']->cLog('T0002');
        $mTbl = self::gTable($tbl);
        if ($SupplierFlg != NULL) {
            // 検索対象：全て
            return 'AND '.$mTbl.'SupplierFlg = \''.$SupplierFlg.'\' ';
        } else {
            return '';
        }
    }
    
    // 検索条件(取引先フラグ)
    private function sClientFlg($tbl, $ClientFlg) {
        $this->CL['LG']->cLog('T0002');
        $mTbl = self::gTable($tbl);
        if ($ClientFlg != NULL) {
            // 検索対象：全て
            return 'AND '.$mTbl.'ClientFlg = \''.$ClientFlg.'\' ';
        } else {
            return '';
        }
    }
    
    // 検索条件(取引先ID)
    private function sTrnID($tbl, $TrnID) {
        $this->CL['LG']->cLog('T0002');
        $mTbl = self::gTable($tbl);
        if ($TrnID != NULL) {
            // 検索対象：全て
            return 'AND '.$mTbl.'TransactionID = \''.$TrnID.'\' ';
        } else {
            return '';
        }
    }
    
/*--------------------------------------------------------*/
/* Search Condition(SQL-Array)                            */
/*--------------------------------------------------------*/
     // 検索条件(汎用)
    private function sArrID($tbl, $id, $idname) {
        $this->CL['LG']->cLog('T0002');
        if (isset($id)) {
            $mTbl = self::gTable($tbl);
            if (!is_array($id)) {
                $id = array($id);
            }
            if (array_values($id)[0] != $this->CL['DF']->ALL) {
                $work = 'AND ( ';
                foreach ($id AS $value ) {
                    $work .= '('.$mTbl.$idname.' = \''.$value.'\') OR ';
                }
                $work .= ') ';
                return str_replace(') OR )', ') )', $work);
            }
        }
        return '';
    }
    
    // 検索条件(勘定科目)
    private function sArrAccTitleID($tbl, $AccTitleID) {
        $this->CL['LG']->cLog('T0002');
        if (isset($AccTitleID)) {
            $mTbl = self::gTable($tbl);
            if (is_array($AccTitleID)) {
                if (array_values($AccTitleID)[0] != $this->CL['DF']->ALL && array_values($AccTitleID)[0] != '') {
                    $work = 'AND ( ';
                    foreach ($AccTitleID AS $value ) {
                        $work .= '('.$mTbl.'AccountsTitleID = \''.$value.'\') OR ';
                    }
                    $work .= ') ';
                    return str_replace(') OR )', ') )', $work);
                }
            } else {
                if ($AccTitleID != $this->CL['DF']->ALL && $AccTitleID != '') {
                    $work = 'AND ( ';
                    $work .= '('.$mTbl.'AccountsTitleID = \''.$AccTitleID.'\')';
                    $work .= ') ';
                    return $work;
                }
            }
        }
        return '';
    }
    
   // 検索条件(勘定科目(大))
    private function sArrAccTitleLID($tbl, $AccTitleLID) {
        $this->CL['LG']->cLog('T0002');
        if (isset($AccTitleLID)) {
            $mTbl = self::gTable($tbl);
            if (!is_array($AccTitleLID)) {
                $AccTitleLID = array($AccTitleLID);
            }
            if (array_values($AccTitleLID)[0] != $this->CL['DF']->ALL) {
                $work = 'AND ( ';
                foreach ($AccTitleLID AS $value) {
                    $work .= '('.$mTbl.'AccountsTitleLID = \''.$value.'\') OR ';
                }
                $work .= ') ';
                return str_replace(') OR )', ') )', $work);
            }
        }
        return '';
    }
    
    // 検索条件(勘定科目(中))
    private function sArrAccTitleMID($tbl, $AccTitleMID) {
        $this->CL['LG']->cLog('T0002');
        if (isset($AccTitleMID)) {
            $mTbl = self::gTable($tbl);
            if (!is_array($AccTitleMID)) {
                $AccTitleMID = array($AccTitleMID);
            }
            if (array_values($AccTitleMID)[0] != $this->CL['DF']->ALL) {
                $work = 'AND ( ';
                foreach ($AccTitleMID AS $value ) {
                    $buff = explode('-', $value);
                    $work .= '(('.$mTbl.'AccountsTitleLID = \''.$buff[0].'\') AND ('.$mTbl.'AccountsTitleMID = \''.$buff[1].'\')) OR ';
                }
                $work .= ') ';
                return str_replace(') OR )', ') )', $work);
            }
        }
        return '';
    }
    
    // 検索条件(勘定科目(小))
    private function sArrAccTitleSID($tbl, $AccTitleSID) {
        $this->CL['LG']->cLog('T0002');
        if (isset($AccTitleSID)) {
            $mTbl = self::gTable($tbl);
            if (!is_array($AccTitleSID)) {
                $AccTitleSID = array($AccTitleSID);
            }
            if (array_values($AccTitleSID)[0] != $this->CL['DF']->ALL) {
                $work = 'AND ( ';
                foreach ($AccTitleSID AS $value ) {
                    $buff = explode('-', $value);
                    $work .= '(('.$mTbl.'AccountsTitleLID = \''.$buff[0].'\') AND ('.$mTbl.'AccountsTitleMID = \''.$buff[1].'\') AND ('.$mTbl.'AccountsTitleSID = \''.$buff[2].'\')) OR ';
                }
                $work .= ') ';
                return str_replace(') OR )', ') )', $work);
            }
        }
        return '';
    }
    
    // 検索条件(取引種別)
    private function sArrTrnKindID($tbl, $TrnKindID) {
        $this->CL['LG']->cLog('T0002');
        if (isset($TrnKindID)) {
            if (!is_array($TrnKindID)) {
                $TrnKindID = array($TrnKindID);
            }
            $mTbl = self::gTable($tbl);
            if (array_values($TrnKindID)[0] != $this->CL['DF']->ALL) {
                $work = 'AND ( ';
                foreach ($TrnKindID AS $value ) {
                    $work .= '('.$mTbl.'TransactionKindID = \''.$value.'\') OR ';
                }
                $work .= ') ';
                return str_replace(') OR )', ') )', $work);
            }
        }
        return '';
    }
    
    // 検索条件(仕訳帳種別)
    private function sArrJnlKindID($tbl, $JnlKindID) {
        $this->CL['LG']->cLog('T0002');
        if (isset($JnlKindID)) {
            $mTbl = self::gTable($tbl);
            if (!is_array($JnlKindID)) {
                $JnlKindID = array($JnlKindID);
            }
            if (array_values($JnlKindID)[0] != $this->CL['DF']->ALL) {
                $work = 'AND ( ';
                foreach ($JnlKindID AS $value ) {
                    $work .= '('.$mTbl.'JournalKindID = \''.$value.'\') OR ';
                }
                $work .= ') ';
                return str_replace(') OR )', ') )', $work);
            }
        }
        return '';
    }
    
    // 検索条件(取引先)
    private function sArrCltID($tbl, $cltid) {
        $this->CL['LG']->cLog('T0002');
        if (isset($cltid)) {
            $mTbl = self::gTable($tbl);
            if (!is_array($cltid)) {
                $cltid = array($cltid);
            }
            if (array_values($cltid)[0] != $this->CL['DF']->ALL) {
                $work = 'AND ( ';
                foreach ($cltid AS $value ) {
                    $work .= '('.$mTbl.'ClientID = \''.$value.'\') OR ';
                }
                $work .= ') ';
                return str_replace(') OR )', ') )', $work);
            }
        }
        return '';
    }
    
    // 検索条件(取引ステータス)
    private function sArrTrnSts($tbl, $trnsts) {
        $this->CL['LG']->cLog('T0002');
        return self::sDataFlg($tbl, $trnsts, 'TransactionStatusID');
    }
    
    // 検索条件(特殊仕訳帳)
    private function sArrSpeJnlID($tbl, $jnlid) {
        $this->CL['LG']->cLog('T0002');
        if (isset($jnlid)) {
            $mTbl = self::gTable($tbl);
            if (!is_array($jnlid)) {
                $jnlid = array($jnlid);
            }
            if (array_values($jnlid)[0] != $this->CL['DF']->ALL) {
                $work = 'AND ( ';
                foreach ($jnlid AS $value ) {
                    $work .= '('.$mTbl.'JournalKindID = \''.$value.'\') OR ';
                }
                $work .= ') ';
                return str_replace(') OR )', ') )', $work);
            }
        }
        return '';
    }
    
    // 検索条件(国内仕入副費項目フラグ)
    private function sDmtFlg($tbl, $ViceExpensesDmtFlg) {
        $this->CL['LG']->cLog('T0002');
        $mTbl = self::gTable($tbl);
        if ($ViceExpensesDmtFlg != NULL) {
            // 検索対象：全て
            return 'AND '.$mTbl.'ViceExpensesDmtFlg = \''.$ViceExpensesDmtFlg.'\' ';
        }
        return '';
    }
    
    // 検索条件(国外仕入副費項目フラグ)
    private function sIntFlg($tbl, $ViceExpensesIntFlg) {
        $this->CL['LG']->cLog('T0002');
        $mTbl = self::gTable($tbl);
        if ($ViceExpensesIntFlg != NULL) {
            // 検索対象：全て
            return 'AND '.$mTbl.'ViceExpensesIntFlg = \''.$ViceExpensesIntFlg.'\' ';
        }
        return '';
    }
    
    // 検索条件(入力者)
    private function sArrInputUserNo($tbl, $inputuserno) {
        $this->CL['LG']->cLog('T0002');
        if (isset($inputuserno)) {
            $mTbl = self::gTable($tbl);
            if (!is_array($inputuserno)) {
                $inputuserno = array($inputuserno);
            }
            if (array_values($inputuserno)[0] != $this->CL['DF']->ALL) {
                $work = 'AND ( ';
                foreach ($inputuserno AS $value ) {
                    $work .= '('.$mTbl.'UserNo = \''.$value.'\') OR ';
                }
                $work .= ') ';
                return str_replace(') OR )', ') )', $work);
            }
        }
        return '';
    }
    
    // 検索条件(取引ID)
    private function sArrTransactionID($tbl, $transactionid) {
        $this->CL['LG']->cLog('T0002');
        if (isset($transactionid)) {
            $mTbl = self::gTable($tbl);
            if (!is_array($transactionid)) {
                $transactionid = array($transactionid);
            }
            if (array_values($transactionid)[0] != $this->CL['DF']->ALL) {
                $work = 'AND ( ';
                foreach ($transactionid AS $value ) {
                    $work .= '('.$mTbl.'TransactionID = \''.$value.'\') OR ';
                }
                $work .= ') ';
                return str_replace(') OR )', ') )', $work);
            }
        }
        return '';
    }
}
?>
