public List<EntityPaymentClose> GetPaymentList(string random, string strWhereSql, string strOrderBySql)
        {
            List<EntityPaymentClose> entityList = new List<EntityPaymentClose>();

            #region 認証処理

            string companyId = "";
            string groupId = "";
            string userId = "";
            string ipAdress = "";
            string sessionString = "";
            int idFigureCommodity = 0;
            int idFigurePurchase = 0;
            int idFigureCustomer = 0;
            int idFigureSlipNo = 0;

            try
            {
                companyId = ExCast.zCStr(HttpContext.Current.Session[ExSession.COMPANY_ID]);
                groupId = ExCast.zCStr(HttpContext.Current.Session[ExSession.GROUP_ID]);
                userId = ExCast.zCStr(HttpContext.Current.Session[ExSession.USER_ID]);
                ipAdress = ExCast.zCStr(HttpContext.Current.Session[ExSession.IP_ADRESS]);
                sessionString = ExCast.zCStr(HttpContext.Current.Session[ExSession.SESSION_RANDOM_STR]);
                idFigureCommodity = ExCast.zCInt(HttpContext.Current.Session[ExSession.ID_FIGURE_GOODS]);
                idFigurePurchase = ExCast.zCInt(HttpContext.Current.Session[ExSession.ID_FIGURE_PURCHASE]);
                idFigureCustomer = ExCast.zCInt(HttpContext.Current.Session[ExSession.ID_FIGURE_CUSTOMER]);
                idFigureSlipNo = ExCast.zCInt(HttpContext.Current.Session[ExSession.ID_FIGURE_SLIP_NO]);

                string _message = ExSession.SessionUserUniqueCheck(random, ExCast.zCStr(HttpContext.Current.Session[ExSession.SESSION_RANDOM_STR]), ExCast.zCInt(HttpContext.Current.Session[ExSession.USER_ID]));
                if (_message != "")
                {
                    EntityPaymentClose entity = new EntityPaymentClose();
                    entity.MESSAGE = _message;
                    entityList.Add(entity);
                    return entityList;
                }
            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".GetPaymentList(認証処理)", ex);
                EntityPaymentClose entity = new EntityPaymentClose();
                entity.MESSAGE = "認証処理に失敗しました。" + Environment.NewLine + ex.Message.ToString(); ;
                entityList.Add(entity);
                return entityList;
            }
            #endregion

            StringBuilder sb;
            DataTable dt;
            ExMySQLData db;

            try
            {
                db = ExSession.GetSessionDb(ExCast.zCInt(HttpContext.Current.Session[ExSession.USER_ID]),
                                            ExCast.zCStr(HttpContext.Current.Session[ExSession.SESSION_RANDOM_STR]));

                sb = new StringBuilder();

                ExReportManeger rptMgr = new ExReportManeger();
                rptMgr.idFigureCommodity = idFigureCommodity;
                rptMgr.idFigureCustomer = idFigureCustomer;
                rptMgr.idFigurePurchase = idFigurePurchase;
                rptMgr.idFigureSlipNo = idFigureSlipNo;
                sb.Append(rptMgr.GetPaymentListReportSQL(companyId, groupId, strWhereSql, strOrderBySql));

                dt = db.GetDataTable(sb.ToString());

                if (dt.DefaultView.Count > 0)
                {
                    for (int i = 0; i <= dt.DefaultView.Count - 1; i++)
                    {
                        #region Set Entity

                        EntityPaymentClose entity = new EntityPaymentClose();

                        entity.no = ExCast.zCStr(dt.DefaultView[i]["NO"]);
                        entity.purchase_id = ExCast.zCStr(dt.DefaultView[i]["PURCHASE_ID"]);
                        entity.purchase_nm = ExCast.zCStr(dt.DefaultView[i]["PURCHASE_NM"]);
                        entity.payment_close_yyyymmdd = ExCast.zDateNullToDefault(dt.DefaultView[i]["PAYMENT_YYYYMMDD"]);
                        entity.summing_up_group_id = ExCast.zCStr(dt.DefaultView[i]["SUMMING_UP_GROUP_ID"]);
                        entity.summing_up_group_nm = ExCast.zCStr(dt.DefaultView[i]["SUMMING_UP_GROUP_NM"]);
                        entity.person_id = ExCast.zCInt(dt.DefaultView[i]["INPUT_PERSON"]);
                        entity.person_nm = ExCast.zCStr(dt.DefaultView[i]["INPUT_PERSON_NM"]);

                        entity.payment_plan_day = ExCast.zDateNullToDefault(dt.DefaultView[i]["PAYMENT_PLAN_DAY"]);
                        entity.payment_day = ExCast.zCInt(dt.DefaultView[i]["PAYMENT_DAY"]);

                        entity.before_payment_yyyymmdd = ExCast.zDateNullToDefault(dt.DefaultView[i]["BEFORE_PAYMENT_yyyymmdd"]);

                        entity.before_payment_price = ExCast.zCDbl(dt.DefaultView[i]["BEFORE_PAYMENT_PRICE"]);
                        entity.before_payment_price_upd = ExCast.zCDbl(dt.DefaultView[i]["BEFORE_PAYMENT_PRICE"]);
                        entity.payment_cash_price = ExCast.zCDbl(dt.DefaultView[i]["PAYMENT_CASH_PRICE"]);
                        entity.transfer_price = ExCast.zCDbl(dt.DefaultView[i]["TRANSFER_PRICE"]);
                        entity.purchase_price = ExCast.zCDbl(dt.DefaultView[i]["PURCHASE_PRICE"]);
                        entity.no_tax_purchase_price = ExCast.zCDbl(dt.DefaultView[i]["NO_TAX_PURCHASE_PRICE"]);
                        entity.tax = ExCast.zCDbl(dt.DefaultView[i]["TAX"]);

                        entity.payment_price = ExCast.zCDbl(dt.DefaultView[i]["PAYMENT_PRICE"]);

                        // 外税額=税抜金額+消費税額-金額(外税を含めない金額)
                        entity.out_tax = ExCast.zCDbl(dt.DefaultView[i]["OUT_TAX"]);

                        entity.payment_kbn = ExCast.zCInt(dt.DefaultView[i]["PAYMENT_KBN"]);
                        //entity.invoice_kbn_nm = ExCast.zCStr(dt.DefaultView[i]["INVOICE_KBN_NM"]);

                        entity.payment_print_flg = ExCast.zCInt(dt.DefaultView[i]["PAYMENT_PRINT_FLG"]);
                        entity.payment_print_flg_nm = ExCast.zCStr(dt.DefaultView[i]["PAYMENT_PRINT_FLG_NM"]);

                        entity.this_payment_cash_price = ExCast.zCDbl(dt.DefaultView[i]["THIS_PAYMENT_CASH_PRICE"]);

                        entity.payment_cash_receivable_kbn = ExCast.zCInt(dt.DefaultView[i]["PAYMENT_RECEIVABLE_KBN"]);
                        entity.payment_cash_receivable_kbn_nm = ExCast.zCStr(dt.DefaultView[i]["PAYMENT_RECEIVABLE_KBN_NM"]);

                        entity.payment_zan_price = ExCast.zCDbl(dt.DefaultView[i]["PAYMENT_ZAN_PRICE"]);

                        entity.memo = ExCast.zCStr(dt.DefaultView[i]["MEMO"]);

                        entity.payment_exists_flg = 0;
                        entity.exec_flg = false;

                        entity.lock_flg = 0;

                        entityList.Add(entity);

                        #endregion

                    }
                }

            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".GetPaymentList", ex);
                entityList.Clear();
                EntityPaymentClose entity = new EntityPaymentClose();
                entity.MESSAGE = CLASS_NM + ".GetPaymentList : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message.ToString();
                entityList.Add(entity);
            }
            finally
            {
                db = null;
            }

            svcPgEvidence.gAddEvidence(ExCast.zCInt(HttpContext.Current.Session[ExSession.EVIDENCE_SAVE_FLG]),
                                       companyId,
                                       userId,
                                       ipAdress,
                                       sessionString,
                                       DataPgEvidence.PGName.Order.OrderList,
                                       DataPgEvidence.geOperationType.Select,
                                       "Where:" + strWhereSql + ",Orderby:" + strOrderBySql);

            return entityList;

        }
        public List<EntityPaymentClose> GetPaymentTotal(string random, EntityPaymentClosePrm entityPrm)
        {

            EntityPaymentClose entity;
            List<EntityPaymentClose> entityList = new List<EntityPaymentClose>();

            #region 認証処理

            string companyId = "";
            string groupId = "";
            string userId = "";
            string ipAdress = "";
            string sessionString = "";
            string personId = "";

            try
            {
                companyId = ExCast.zCStr(HttpContext.Current.Session[ExSession.COMPANY_ID]);
                groupId = ExCast.zCStr(HttpContext.Current.Session[ExSession.GROUP_ID]);
                userId = ExCast.zCStr(HttpContext.Current.Session[ExSession.USER_ID]);
                ipAdress = ExCast.zCStr(HttpContext.Current.Session[ExSession.IP_ADRESS]);
                sessionString = ExCast.zCStr(HttpContext.Current.Session[ExSession.SESSION_RANDOM_STR]);
                personId = ExCast.zCStr(HttpContext.Current.Session[ExSession.PERSON_ID]);

                string _message = ExSession.SessionUserUniqueCheck(random, ExCast.zCStr(HttpContext.Current.Session[ExSession.SESSION_RANDOM_STR]), ExCast.zCInt(HttpContext.Current.Session[ExSession.USER_ID]));
                if (_message != "")
                {
                    entity = new EntityPaymentClose();
                    entity.MESSAGE = _message;
                    entityList.Add(entity);
                    return entityList;
                }
            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".GetPaymentTotal(認証処理)", ex);
                entity = new EntityPaymentClose();
                entity.MESSAGE = CLASS_NM + ".GetPaymentTotal : 認証処理に失敗しました。" + Environment.NewLine + ex.Message.ToString(); ;
                entityList.Add(entity);
                return entityList;
            }

            #endregion

            StringBuilder sb;
            DataTable dt;
            DataTable dt2;
            ExMySQLData db;

            try
            {
                db = ExSession.GetSessionDb(ExCast.zCInt(HttpContext.Current.Session[ExSession.USER_ID]),
                                            ExCast.zCStr(HttpContext.Current.Session[ExSession.SESSION_RANDOM_STR]));

                sb = new StringBuilder();

                string yyyymmdd = entityPrm.payment_yyyymmdd;

                #region SQL

                sb.Length = 0;
                sb.Append("SELECT CM.ID " + Environment.NewLine);
                sb.Append("      ,CM.TAX_FRACTION_PROC_ID " + Environment.NewLine);
                sb.Append("      ,CM.NAME " + Environment.NewLine);
                sb.Append("      ,CM.SUMMING_UP_GROUP_ID " + Environment.NewLine);
                sb.Append("      ,CM.PAYMENT_DAY " + Environment.NewLine);
                sb.Append("      ,CM.PAYMENT_CYCLE_ID " + Environment.NewLine);
                sb.Append("      ,SL.SUM_PAYMENT_OUT_PRICE " + Environment.NewLine);
                sb.Append("      ,SL.SUM_PAYMENT_IN_PRICE " + Environment.NewLine);
                sb.Append("      ,SL.SUM_PRICE " + Environment.NewLine);
                sb.Append("      ,SL.SUM_TAX " + Environment.NewLine);
                sb.Append("      ,SL.SUM_NO_TAX_PRICE " + Environment.NewLine);
                sb.Append("  FROM M_PURCHASE AS CM" + Environment.NewLine);

                #region Join

                // 今回仕入
                sb.Append("  INNER JOIN (SELECT T.PURCHASE_ID" + Environment.NewLine);
                sb.Append("                    ,SUM(CASE WHEN T.TAX_CHANGE_ID = 3 THEN T.SUM_PRICE" + Environment.NewLine);
                sb.Append("                              ELSE 0 END) AS SUM_PAYMENT_OUT_PRICE" + Environment.NewLine);
                sb.Append("                    ,SUM(CASE WHEN T.TAX_CHANGE_ID = 6 THEN T.SUM_PRICE" + Environment.NewLine);
                sb.Append("                              ELSE 0 END) AS SUM_PAYMENT_IN_PRICE" + Environment.NewLine);
                sb.Append("                    ,SUM(T.SUM_PRICE) AS SUM_PRICE" + Environment.NewLine);
                sb.Append("                    ,SUM(T.SUM_TAX) AS SUM_TAX" + Environment.NewLine);
                sb.Append("                    ,SUM(T.SUM_NO_TAX_PRICE) AS SUM_NO_TAX_PRICE" + Environment.NewLine);
                sb.Append("                FROM T_PURCHASE_H AS T " + Environment.NewLine);
                sb.Append("               WHERE T.DELETE_FLG = 0 " + Environment.NewLine);
                sb.Append("                 AND T.COMPANY_ID = " + companyId + Environment.NewLine);
                sb.Append("                 AND T.GROUP_ID = " + groupId + Environment.NewLine);
                sb.Append("                 AND T.PURCHASE_YMD <= " + ExEscape.zRepStr(yyyymmdd) + Environment.NewLine);
                sb.Append("                 AND T.BUSINESS_DIVISION_ID = 1 " + Environment.NewLine);        // 掛仕入のみ

                // 前回支払分以外の仕入
                sb.Append("                 AND NOT EXISTS (SELECT IV.NO" + Environment.NewLine);
                sb.Append("                                   FROM T_PAYMENT AS IV" + Environment.NewLine);
                sb.Append("                                  WHERE IV.DELETE_FLG = 0 " + Environment.NewLine);
                sb.Append("                                    AND IV.COMPANY_ID = T.COMPANY_ID " + Environment.NewLine);
                sb.Append("                                    AND IV.GROUP_ID = T.GROUP_ID " + Environment.NewLine);
                sb.Append("                                    AND IV.NO = T.PAYMENT_NO " + Environment.NewLine);
                sb.Append("                                    AND IV.PAYMENT_YYYYMMDD < " + ExEscape.zRepStr(yyyymmdd) + Environment.NewLine);
                sb.Append("                                    AND IV.PAYMENT_KBN = 0) " + Environment.NewLine);

                sb.Append("               GROUP BY T.PURCHASE_ID " + Environment.NewLine);
                sb.Append("             ) AS SL" + Environment.NewLine);
                sb.Append("     ON SL.PURCHASE_ID = CM.ID" + Environment.NewLine);

                #endregion

                sb.Append(" WHERE CM.COMPANY_ID = " + companyId + Environment.NewLine);
                sb.Append("   AND CM.DELETE_FLG = 0 " + Environment.NewLine);
                if (!string.IsNullOrEmpty(entityPrm.summing_up_group_id))
                {
                    sb.Append("   AND CM.SUMMING_UP_GROUP_ID = " + ExEscape.zRepStr(entityPrm.summing_up_group_id) + Environment.NewLine);
                }
                if (!string.IsNullOrEmpty(entityPrm.purchase_id))
                {
                    sb.Append("   AND CM.ID = " + ExEscape.zRepStr(ExCast.zNumZeroNothingFormat(entityPrm.purchase_id)) + Environment.NewLine);
                }

                sb.Append(" ORDER BY CM.ID2 " + Environment.NewLine);
                sb.Append("         ,CM.ID " + Environment.NewLine);

                #endregion

                dt = db.GetDataTable(sb.ToString());

                // 排他制御
                DataPgLock.geLovkFlg lockFlg;
                string strErr = DataPgLock.SetLockPg(companyId, userId, PG_NM, groupId, ipAdress, db, out lockFlg);

                if (strErr != "")
                {
                    entity = new EntityPaymentClose();
                    entity.MESSAGE = CLASS_NM + ".GetPaymentTotal : 排他制御(ロック情報取得)に失敗しました。" + Environment.NewLine + strErr;
                    entityList.Add(entity);
                    return entityList;
                }

                if (dt.DefaultView.Count > 0)
                {
                    for (int i = 0; i <= dt.DefaultView.Count - 1; i++)
                    {
                        #region Set Entity

                        entity = new EntityPaymentClose();
                        entity.no = "未";
                        entity.purchase_id = ExCast.zCStr(dt.DefaultView[i]["ID"]);
                        entity.purchase_nm = ExCast.zCStr(dt.DefaultView[i]["NAME"]);
                        entity.payment_close_yyyymmdd = yyyymmdd;
                        entity.summing_up_group_id = ExCast.zCStr(dt.DefaultView[i]["SUMMING_UP_GROUP_ID"]);
                        entity.person_id = ExCast.zCInt(personId);

                        #region 再集計チェック

                        int _invoieReTotalFlg = 0;
                        double _before_payment_price = 0;

                        #region SQL

                        sb.Length = 0;
                        sb.Append("SELECT T.NO " + Environment.NewLine);
                        sb.Append("      ,T.BEFORE_PAYMENT_PRICE " + Environment.NewLine);
                        sb.Append("      ,date_format(T.PAYMENT_PLAN_DAY , " + ExEscape.SQL_YMD + ") AS PAYMENT_PLAN_DAY" + Environment.NewLine);
                        sb.Append("      ,T.PAYMENT_DAY " + Environment.NewLine);
                        sb.Append("  FROM T_PAYMENT AS T" + Environment.NewLine);
                        sb.Append(" WHERE T.COMPANY_ID = " + companyId + Environment.NewLine);
                        sb.Append("   AND T.GROUP_ID = " + groupId + Environment.NewLine);
                        sb.Append("   AND T.DELETE_FLG = 0 " + Environment.NewLine);
                        sb.Append("   AND T.PAYMENT_KBN = 0 " + Environment.NewLine);       // 締請求分のみ
                        sb.Append("   AND T.PURCHASE_ID = " + ExEscape.zRepStr(ExCast.zNumZeroNothingFormat(entity.purchase_id)) + Environment.NewLine);
                        sb.Append("   AND T.PAYMENT_YYYYMMDD = " + ExEscape.zRepStr(yyyymmdd) + Environment.NewLine);
                        sb.Append(" LIMIT 0, 1");

                        #endregion

                        dt2 = db.GetDataTable(sb.ToString());
                        if (dt2.DefaultView.Count > 0)
                        {
                            _invoieReTotalFlg = 1;
                            entity.no = ExCast.zCStr(dt2.DefaultView[0]["NO"]);
                            entity.payment_plan_day = ExCast.zDateNullToDefault(dt2.DefaultView[0]["PAYMENT_PLAN_DAY"]);
                            entity.payment_day = ExCast.zCInt(dt2.DefaultView[0]["PAYMENT_DAY"]);
                            _before_payment_price = ExCast.zCDbl(dt2.DefaultView[0]["BEFORE_PAYMENT_PRICE"]);
                        }

                        #endregion

                        #region 前回支払取得

                        int _paymentExistsFlg = 0;
                        int _before_payment_yyyyymm = 0;
                        string _before_payment_yyyyymmdd = "";

                        #region SQL

                        sb.Length = 0;
                        sb.Append("SELECT T.NO " + Environment.NewLine);
                        sb.Append("      ,date_format(T.PAYMENT_YYYYMMDD , " + ExEscape.SQL_YMD + ") AS PAYMENT_YYYYMMDD" + Environment.NewLine);
                        sb.Append("      ,T.PAYMENT_PRICE " + Environment.NewLine);
                        sb.Append("  FROM T_PAYMENT AS T " + Environment.NewLine);

                        sb.Append(" WHERE T.DELETE_FLG = 0 " + Environment.NewLine);
                        sb.Append("   AND T.COMPANY_ID = " + companyId + Environment.NewLine);
                        sb.Append("   AND T.GROUP_ID = " + groupId + Environment.NewLine);
                        sb.Append("   AND T.PURCHASE_ID = " + ExEscape.zRepStr(ExCast.zNumZeroNothingFormat(dt.DefaultView[i]["ID"])) + Environment.NewLine);
                        sb.Append("   AND T.PAYMENT_KBN = 0 " + Environment.NewLine);               // 締請求分のみ
                        sb.Append("   AND T.PAYMENT_YYYYMMDD < " + ExEscape.zRepStr(yyyymmdd) + Environment.NewLine);
                        sb.Append(" LIMIT 0, 1");

                        #endregion

                        dt2 = db.GetDataTable(sb.ToString());
                        if (dt2.DefaultView.Count > 0)
                        {
                            if (_invoieReTotalFlg == 0)
                            {
                                //entity.no = ExCast.zCStr(dt2.DefaultView[0]["NO"]);
                                _before_payment_price = ExCast.zCDbl(dt2.DefaultView[0]["PAYMENT_PRICE"]);
                            }
                            _paymentExistsFlg = 1;

                            _before_payment_yyyyymmdd = ExCast.zDateNullToDefault(dt2.DefaultView[0]["PAYMENT_YYYYMMDD"]);
                            if (_before_payment_yyyyymmdd != "")
                            {
                                entity.before_payment_yyyymmdd = _before_payment_yyyyymmdd;
                            }
                            else
                            {
                                entity.before_payment_yyyymmdd = "払締無し";
                            }
                        }
                        else
                        {
                            entity.before_payment_yyyymmdd = "払締無し";
                        }


                        #region 支払予定日

                        string _payment_plan_day = "";
                        int _payment_day = 0;
                        DataPlanDay.GetPlanDay(entity.payment_cycle_id,
                                               ExCast.zCInt(dt.DefaultView[i]["PAYMENT_DAY"]),
                                               entityPrm.payment_yyyymmdd,
                                               ref _payment_plan_day,
                                               ref _payment_day);

                        if (_invoieReTotalFlg == 0)
                        {
                            entity.payment_plan_day = _payment_plan_day;
                            entity.payment_day = _payment_day;

                            if (!string.IsNullOrEmpty(entityPrm.payment_plan_yyyymmdd))
                            {
                                entity.payment_plan_day = entityPrm.payment_plan_yyyymmdd;
                            }
                        }

                        #endregion

                        #endregion

                        #region 出金取得

                        double _payment_cash_price = 0;

                        #region SQL

                        sb.Length = 0;
                        sb.Append("SELECT SUM(T.SUM_PRICE) AS SUM_PRICE " + Environment.NewLine);
                        sb.Append("  FROM T_PAYMENT_CASH_H AS T" + Environment.NewLine);
                        sb.Append(" WHERE T.COMPANY_ID = " + companyId + Environment.NewLine);
                        sb.Append("   AND T.GROUP_ID = " + groupId + Environment.NewLine);
                        sb.Append("   AND T.DELETE_FLG = 0 " + Environment.NewLine);
                        sb.Append("   AND T.PURCHASE_ID = " + ExEscape.zRepStr(ExCast.zNumZeroNothingFormat(entity.purchase_id)) + Environment.NewLine);
                        sb.Append("   AND T.PAYMENT_CASH_YMD <= " + ExEscape.zRepStr(yyyymmdd) + Environment.NewLine);
                        sb.Append("   AND IFNULL(T.PAYMENT_NO, 0) > 0 " + Environment.NewLine);
                        // 締支払分のみ
                        sb.Append("   AND EXISTS (SELECT IV.NO" + Environment.NewLine);
                        sb.Append("                 FROM T_PAYMENT AS IV" + Environment.NewLine);
                        sb.Append("                WHERE IV.DELETE_FLG = 0 " + Environment.NewLine);
                        sb.Append("                  AND IV.COMPANY_ID = T.COMPANY_ID " + Environment.NewLine);
                        sb.Append("                  AND IV.GROUP_ID = T.GROUP_ID " + Environment.NewLine);
                        sb.Append("                  AND IV.NO = T.PAYMENT_NO " + Environment.NewLine);
                        sb.Append("                  AND IV.PAYMENT_KBN = 0) " + Environment.NewLine);

                        #endregion

                        dt2 = db.GetDataTable(sb.ToString());
                        if (dt2.DefaultView.Count > 0)
                        {
                            _payment_cash_price = ExCast.zCDbl(dt2.DefaultView[0]["SUM_PRICE"]);
                        }

                        #endregion

                        entity.before_payment_yyyymmdd = _before_payment_yyyyymmdd;
                        entity.before_payment_price = _before_payment_price;
                        entity.payment_cash_price = _payment_cash_price;
                        entity.transfer_price = _before_payment_price - _payment_cash_price;
                        entity.purchase_price = ExCast.zCDbl(dt.DefaultView[i]["SUM_PRICE"]);                   // 外税額含めない金額
                        entity.no_tax_purchase_price = ExCast.zCDbl(dt.DefaultView[i]["SUM_NO_TAX_PRICE"]);
                        entity.tax = ExCast.zCDbl(dt.DefaultView[i]["SUM_TAX"]);                                // 内税・外税計

                        #region 支払時消費税

                        double _payment_out_tax = 0;
                        double _payment_in_tax = 0;
                        int _tax_fraction_proc_id = ExCast.zCInt(dt.DefaultView[i]["TAX_FRACTION_PROC_ID"]);
                        double _sum_payment_out_price = ExCast.zCDbl(dt.DefaultView[i]["SUM_PAYMENT_OUT_PRICE"]);       // 外税/請求時 金額
                        double _sum_payment_in_price = ExCast.zCDbl(dt.DefaultView[i]["SUM_PAYMENT_IN_PRICE"]);         // 内税/請求時 金額

                        if (_sum_payment_out_price != 0 || _sum_payment_in_price != 0)
                        {
                            // 外税/請求時 消費税
                            if (_sum_payment_out_price != 0)
                            {
                                _payment_out_tax = ExMath.zCalcTax(_sum_payment_out_price, 3, 0, _tax_fraction_proc_id);
                            }
                            // 内税/請求時 消費税
                            if (_sum_payment_in_price != 0)
                            {
                                _payment_in_tax = ExMath.zCalcTax(_sum_payment_out_price, 6, 0, _tax_fraction_proc_id);
                            }

                            // 税額の加算
                            entity.tax += _payment_out_tax;
                            entity.tax += _payment_in_tax;

                            // 税抜額の減算
                            entity.no_tax_purchase_price -= _payment_in_tax;
                        }

                        #endregion

                        // 今回請求額=繰越金額+税抜金額+消費税額
                        entity.payment_price = entity.transfer_price + entity.no_tax_purchase_price + entity.tax;

                        // 外税額=税抜金額+消費税額-金額(外税を含めない金額)
                        entity.out_tax = entity.no_tax_purchase_price + entity.tax - entity.purchase_price;

                        //entity.memo = ExCast.zCStr(dt.DefaultView[i]["MEMO"]);

                        entity.payment_exists_flg = _paymentExistsFlg;
                        entity.exec_flg = false;

                        entity.lock_flg = (int)lockFlg;

                        entityList.Add(entity);

                        #endregion
                    }
                }

            }
            catch (Exception ex)
            {
                CommonUtl.ExLogger.Error(CLASS_NM + ".GetPaymentTotal", ex);
                entity = new EntityPaymentClose();
                entity.MESSAGE = CLASS_NM + ".GetPaymentTotal : 予期せぬエラーが発生しました。" + Environment.NewLine + ex.Message.ToString();
                entityList.Clear();
                entityList.Add(entity);
            }
            finally
            {
                db = null;
            }

            svcPgEvidence.gAddEvidence(ExCast.zCInt(HttpContext.Current.Session[ExSession.EVIDENCE_SAVE_FLG]),
                           companyId,
                           userId,
                           ipAdress,
                           sessionString,
                           PG_NM,
                           DataPgEvidence.geOperationType.Select,
                           "");

            return entityList;

        }