/**
 * Copyright (c) 2003-2004 System Integrator Corporation.
 *                 All Rights Reserved.
 */
package jp.co.sint.basic;

import java.sql.Connection;
import java.util.Collection;
import java.util.HashMap;
import java.util.Iterator;
import java.util.LinkedHashMap;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;

import jp.co.sint.config.SIConfig;
import jp.co.sint.config.SIFlagConf;
import jp.co.sint.tools.SIFatalException;
import jp.co.sint.tools.SIUtil;
import jp.co.sint.tools.SIURLParameter;// 7.1.1 ST0236 追加

import org.apache.log4j.Category;

/**
 * @version $Id: SICasherBasic.java,v 1.0 2004/01/09 Exp $
 * @author Jinwang Chen <br>
 * Description:
 * <p>
 * History
 * </p>
 * <p>
 * Author&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Date&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Reason
 * </p>
 * ============&nbsp;&nbsp;&nbsp;==========&nbsp;&nbsp;===========================<br>
 * Jinwang Chen 2004/01/09 18:03:30 Original
 */
public class SICasherBasic extends SIFrontBasic {
  // ログ用のインスタンスの生成
  private static Category log = Category.getInstance(SIConfig.SILOG4J_WEBSHOP_CATEGORY_NAME);
  // 注文番号
  private String orderCode = "";
  // 決済ショップコード
  private String shopCode = "";
  // 支払方法
  private String payMethodName = "";
  
  // 支払方法
  private String payMethodNameBack = "";
  
  //
  private String paymentFlg = "0";
  
  // 7.2.0 ST0300 追加
  private String cvsTypeCode = "";
  
  private String fee = "0";
  
  private String feeTaxFlg = "1";
  
  private String taxRate = "0";
  
  private String sumByPoint = "0";
  
  private String sumOfCB = "0";// ラッピング代を含まない
  
  private String sumOfA = "0";
  
  private String sumOfB = "0";
  
  private String sumOfC = "0";
  
  private String sumOfD = "0";
  
  private String sumOfE = "0";
  
  private String sumOfF = "0";
  
  // 7.2.0 ST1030 追加
  private String sumOfG = "0";
  
  private String sumOfH = "0"; // EDBTG003-00 elecs-tani add セット値引き額
  
  private String sumOfPrice = "0";// 購入価格
  
  private String calcFee = "0";// 手数料計算用お支払額
  
  private String taxFlgOfCB = "0";// ラッピング代を含まないの価格合計の税フラグ
  
  private String taxFlgOfA = "0";// 商品本体(税込み)+ラッピング価格の税フラグ
  
  private String taxFlgOfB = "0";// 配送手数料の税フラグ
  
  private String taxFlgOfC = "0";// 手数料の税フラグ
  
  private String taxFlgOfD = "0";// 支払料金の税フラグ
  
  private String taxFlgOfE = "0";// ポイントの税フラグ
  
  private String taxFlgOfF = "0";// 支払い料金の税フラグ
  
  // 7.2.0 ST1030 追加
  private String taxFlgOfG = "0";// 値引金額の税フラグ
  
  private String totalOfAmount = "0";// 数量
  
  private String maxPoint = "0";
  
  // 7.3.0 PI-NES0501 追加 個別送料分
  private String sumOfCB1 = "0";
  
  private String sumOfA1 = "0";
  
  private String sumOfB1 = "0";
  
  private String sumOfC1 = "0";
  
  private String sumOfD1 = "0";
  
  private String sumOfE1 = "0";
  
  private String sumOfF1 = "0";
  
  private String sumOfG1 = "0";
  
  // 7.3.0 PI-NES0501 追加 通常送料分
  private String sumOfCB2 = "0";
  
  private String sumOfA2 = "0";
  
  private String sumOfB2 = "0";
  
  private String sumOfC2 = "0";
  
  private String sumOfD2 = "0";
  
  private String sumOfE2 = "0";
  
  private String sumOfF2 = "0";
  
  private String sumOfG2 = "0";
  
  // 7.3.0 PI-NES0501 追加 送料調整額
  private String discountFee = "0";
  
  // 7.3.0 PI-NES0501 追加 手数料調整額
  private String discountDeliveryFee = "0";

  private String[] deliveryCheck = null;
  
  private boolean deliveryKomonoCheck = false;
  
  private String komonoDeliveryFee = "0";
  
  public SICasherBasic() {}
  
  public void setOrderCode(String lOrderCode) {
    if (SIUtil.isNull(lOrderCode)) lOrderCode = "";
    this.orderCode = SIUtil.changeTo(lOrderCode.trim(), this.encode);
  }
  
  public void setShopCode(String lShopCode) {
    if (SIUtil.isNull(lShopCode)) lShopCode = "";
    this.shopCode = SIUtil.changeTo(lShopCode.trim(), this.encode);
  }
  
  public void setPayMethodName(String lPayMethodName) {
    if (SIUtil.isNull(lPayMethodName)) lPayMethodName = "";
    this.payMethodName = SIUtil.changeTo(lPayMethodName.trim(), this.encode);
  }
  
  // 7.2.0 ST1030 追加
  public void setPayMethodNameNoEncode(String lPayMethodName) {
    if (SIUtil.isNull(lPayMethodName)) lPayMethodName = "";
    this.payMethodName = lPayMethodName.trim();
  }
  
  public void setPayMethodNameBack(String lPayMethodNameBack) {
    if (SIUtil.isNull(lPayMethodNameBack)) lPayMethodNameBack = "";
    this.payMethodNameBack = SIUtil.changeTo(lPayMethodNameBack.trim(), this.encode);
  }
  
  // 7.2.0 ST1030 追加
  public void setPayMethodNameBackNoEncode(String lPayMethodNameBack) {
    if (SIUtil.isNull(lPayMethodNameBack)) lPayMethodNameBack = "";
    this.payMethodNameBack = lPayMethodNameBack.trim();
  }
  
  public void setPaymentFlg(String lPaymentFlg) {
    if (SIUtil.isNull(lPaymentFlg)) lPaymentFlg = "0";
    this.paymentFlg = lPaymentFlg.trim();
  }
  
  // 7.2.0 ST0300 追加
  public void setCvsTypeCode(String lCvsTypeCode) {
    if (SIUtil.isNull(lCvsTypeCode)) lCvsTypeCode = "";
    this.cvsTypeCode = lCvsTypeCode.trim();
  }
  
  public void setFee(String lFee) {
    if (SIUtil.isNull(lFee)) lFee = "0";
    this.fee = lFee.trim();
  }
  
  public void setFeeTaxFlg(String lFeeTaxFlg) {
    if (SIUtil.isNull(lFeeTaxFlg)) lFeeTaxFlg = "1";
    this.feeTaxFlg = lFeeTaxFlg.trim();
  }
  
  public void setTaxRate(String lTaxRate) {
    if (SIUtil.isNull(lTaxRate)) lTaxRate = "0";
    this.taxRate = lTaxRate.trim();
  }
  
  public void setSumByPoint(String lSumByPoint) {
    // if (SIUtil.isNull(lSumByPoint))lSumByPoint="0";
    this.sumByPoint = lSumByPoint.trim();
  }
  
  // 7.2.0 ST1030 追加
  public void setSumByPointWithEncode(String lSumByPoint) {
    if (SIUtil.isNull(lSumByPoint)) lSumByPoint = "";
    this.sumByPoint = SIUtil.changeTo(lSumByPoint.trim(), this.encode);
  }
  
  public void setTaxFlgOfCB(String lTaxFlgOfCB) {
    if (!taxFlgOfCB.equals("0")) return;
    this.taxFlgOfCB = lTaxFlgOfCB;
  }
  
  public void setTaxFlgOfA(String lTaxFlgOfA) {
    if (!taxFlgOfA.equals("0")) return;
    this.taxFlgOfA = lTaxFlgOfA;
  }
  
  public void setTaxFlgOfB(String lTaxFlgOfB) {
    if (!taxFlgOfB.equals("0")) return;
    if (SIUtil.isNull(lTaxFlgOfB)) lTaxFlgOfB = "1";
    this.taxFlgOfB = lTaxFlgOfB;
  }
  
  public void setTaxFlgOfC(String lTaxFlgOfC) {
    if (!taxFlgOfC.equals("0")) return;
    if (SIUtil.isNull(lTaxFlgOfC)) lTaxFlgOfC = "1";
    this.taxFlgOfC = lTaxFlgOfC;
  }
  
  public void setTaxFlgOfD(String lTaxFlgOfD) {
    if (!taxFlgOfD.equals("0")) return;
    this.taxFlgOfD = lTaxFlgOfD;
  }

  public void setTaxFlgOfE(String lTaxFlgOfE) {
    if (!taxFlgOfE.equals("0")) return;
    this.taxFlgOfE = lTaxFlgOfE;
  }
  
  public void setTaxFlgOfF(String lTaxFlgOfF) {
    if (!taxFlgOfF.equals("0")) return;
    this.taxFlgOfF = lTaxFlgOfF;
  }
  
  // 7.2.0 ST1030 追加
  public void setTaxFlgOfG(String lTaxFlgOfG) {
    if (!lTaxFlgOfG.equals("0")) return;
    this.taxFlgOfG = lTaxFlgOfG;
  }
  
  public void setSumOfCB(String lSumOfCB) {
    if (SIUtil.isNull(lSumOfCB)) lSumOfCB = "0";
    this.sumOfCB = lSumOfCB;
  }
  
  public void setSumOfA(String lSumOfA) {
    if (SIUtil.isNull(lSumOfA)) lSumOfA = "0";
    this.sumOfA = lSumOfA;
  }
  
  public void setSumOfB(String lSumOfB) {
    if (SIUtil.isNull(lSumOfB)) lSumOfB = "0";
    this.sumOfB = lSumOfB;
  }
  
  public void setSumOfC(String lSumOfC) {
    if (SIUtil.isNull(lSumOfC)) lSumOfC = "0";
    this.sumOfC = lSumOfC;
  }
  
  public void setSumOfD(String lSumOfD) {
    if (SIUtil.isNull(lSumOfD)) lSumOfD = "0";
    this.sumOfD = lSumOfD;
  }
  
  public void setSumOfE(String lSumOfE) {
    if (SIUtil.isNull(lSumOfE)) lSumOfE = "0";
    this.sumOfE = lSumOfE;
  }
  
  public void setSumOfF(String lSumOfF) {
    if (SIUtil.isNull(lSumOfF)) lSumOfF = "0";
    this.sumOfF = lSumOfF;
  }
  
  // 7.2.0 ST1030 追加
  public void setSumOfG(String lSumOfG) {
    if (SIUtil.isNull(lSumOfG)) lSumOfG = "0";
    this.sumOfG = lSumOfG;
  }
  
  public void setSumOfPrice(String lSumOfPrice) {
    if (SIUtil.isNull(lSumOfPrice)) lSumOfPrice = "0";
    this.sumOfPrice = lSumOfPrice;
  }
  
  public void setTotalOfAmount(String lTotalOfAmount) {
    if (SIUtil.isNull(lTotalOfAmount)) lTotalOfAmount = "0";
    this.totalOfAmount = lTotalOfAmount;
  }
  
  public void setCalcFee(String lCalcFee) {
    if (SIUtil.isNull(lCalcFee)) lCalcFee = "0";
    this.calcFee = lCalcFee.trim();
  }
  
  public void setMaxPoint(String lMaxPoint) {
    if (SIUtil.isNull(lMaxPoint)) lMaxPoint = "0";
    this.maxPoint = SIUtil.changeTo(lMaxPoint.trim(), this.encode);
  }
  
  public String getOrderCode() {
    return this.orderCode;
  }
  
  public String getSumOfCB() {
    return this.sumOfCB;
  }
  
  public String getFee() {
    return this.fee;
  }
  
  public String getFeeIncTax() {
    log.debug("getFeeIncTax:getFeeTaxFlg()=" + getFeeTaxFlg() + ",");
    if (getFeeTaxFlg().equals("0") || getFeeTaxFlg().equals("2")) return getFee();
    
    String lTax = "0";
    try {
      lTax = SIUtil.multi_LD(getFee(), SIUtil.div_DL(getTaxRate(), "100"));
    } catch (SIFatalException e) {
      e.printStackTrace();
    }
    return SIUtil.add_LL(getFee(), lTax);
  }
  
  public String getFeeTaxFlg() {
    return this.feeTaxFlg;
  }
  
  public String getFeeTaxName() {
    if (this.getSumOfC().equals("0")) return "";// 7.2.0 ST1085 追加
    if (getFeeTaxFlg().equals("0")) return "(" + SIFlagConf.SIFLAG_TAX_0 + ")";
    else if (getFeeTaxFlg().equals("1")) return "(" + SIFlagConf.SIFLAG_TAX_1 + ")";
    else if (getFeeTaxFlg().equals("2")) return "(" + SIFlagConf.SIFLAG_TAX_2 + ")";
    else return "";
  }
  
  public String getTaxRate() {
    return this.taxRate;
  }
  
  public String getShopCode() {
    return this.shopCode;
  }
  
  public String getCasherShopCode() {
    // 7.2.0 ST0224 修正 ここから
    if (SIConfig.SIRUNNING_MODE_CURRENT == SIConfig.SIRUNNING_MODE_TOGETHER) return SIConfig.SIMALL.getMallShopCode();
    if (SIUtil.isNull(getShopCode())) {
      log.warn("not set casher shopcode.");
      return "";
    }
    // 7.2.0 ST0224 修正 ここまで
    else return getShopCode();
  }
  
  public String getPayMethodName() {
    return this.payMethodName;
  }
  
  public String getPayMethodNameBack() {
    return this.payMethodNameBack;
  }
  
  public String getPaymentFlg() {
    return this.paymentFlg;
  }
  
  // 7.2.0 ST0300 追加
  public String getCvsTypeCode() {
    return this.cvsTypeCode;
  }
  
  public String getSumByPoint() {
    return this.sumByPoint;
  }
  
  public String getSumOfA() {
    return this.sumOfA;
  }
  
  public String getSumOfB() {
    return this.sumOfB;
  }
  
  public String getSumOfC() {
    return this.sumOfC;
  }
  
  public String getSumOfD() {
    return this.sumOfD;
  }
  
  public String getSumOfE() {
    return this.sumOfE;
  }
  
  public String getSumOfF() {
    return this.sumOfF;
  }
  
  // 7.2.0 ST1030 追加
  public String getSumOfG() {
    return this.sumOfG;
  }
  
  public String getTotalOfAmount() {
    return this.totalOfAmount;
  }
  
  public String getSumOfPrice() {
    return this.sumOfPrice;
  }
  
  public String getTaxFlgNameOfA() {
    if (getSumOfA().equals("0")) return "";
    return getTaxFlgName(taxFlgOfA);
  }
  
  public String getTaxFlgNameOfB() {
    if (getSumOfB().equals("0")) return "";
    return getTaxFlgName(taxFlgOfB);
  }
  
  public String getTaxFlgNameOfC() {
    if (getSumOfC().equals("0")) return "";
    return getTaxFlgName(taxFlgOfC);
  }
  
  public String getTaxFlgNameOfD() {
    if (getSumOfD().equals("0")) return "";
    return getTaxFlgName(taxFlgOfD);
  }
  
  public String getTaxFlgNameOfE() {
    if (getSumOfE().equals("0")) return "";
    return getTaxFlgName(taxFlgOfE);
  }
  
  public String getTaxFlgNameOfF() {
    if (getSumOfF().equals("0")) return "";
    return getTaxFlgName(taxFlgOfF);
  }
  
  // 7.2.0 ST1030 追加
  public String getTaxFlgNameOfG() {
    if (getSumOfG().equals("0")) return "";
    return getTaxFlgName(taxFlgOfG);
  }
  
  public String getTaxFlgName(String lTaxFlg) {
    if (lTaxFlg.equals("0")) return "(" + SIFlagConf.SIFLAG_TAX_0 + ")";
    else if (lTaxFlg.equals("1")) return "(" + SIFlagConf.SIFLAG_TAX_1 + ")";
    else if (lTaxFlg.equals("2")) return "(" + SIFlagConf.SIFLAG_TAX_2 + ")";
    else return "";
  }
  
  public String getCalcFee() {
    return this.calcFee;
  }
  
  public String getMaxPoint() {
    return this.maxPoint;
  }
  
  public String getSumOfA2() {
    return sumOfA2;
  }
  
  public void setSumOfA2(String sumOfA2) {
    this.sumOfA2 = sumOfA2;
  }
  
  public String getSumOfB2() {
    return sumOfB2;
  }
  
  public void setSumOfB2(String sumOfB2) {
    this.sumOfB2 = sumOfB2;
  }
  
  public String getSumOfC2() {
    return sumOfC2;
  }
  
  public void setSumOfC2(String sumOfC2) {
    this.sumOfC2 = sumOfC2;
  }
  
  public String getSumOfCB2() {
    return sumOfCB2;
  }
  
  public void setSumOfCB2(String sumOfCB2) {
    this.sumOfCB2 = sumOfCB2;
  }
  
  public String getSumOfD2() {
    return sumOfD2;
  }
  
  public void setSumOfD2(String sumOfD2) {
    this.sumOfD2 = sumOfD2;
  }
  
  public String getSumOfE2() {
    return sumOfE2;
  }
  
  public void setSumOfE2(String sumOfE2) {
    this.sumOfE2 = sumOfE2;
  }
  
  public String getSumOfF2() {
    return sumOfF2;
  }
  
  public void setSumOfF2(String sumOfF2) {
    this.sumOfF2 = sumOfF2;
  }
  
  public String getSumOfA1() {
    return sumOfA1;
  }
  
  public void setSumOfA1(String sumOfA1) {
    this.sumOfA1 = sumOfA1;
  }
  
  public String getSumOfB1() {
    return sumOfB1;
  }
  
  public void setSumOfB1(String sumOfB1) {
    this.sumOfB1 = sumOfB1;
  }
  
  public String getSumOfC1() {
    return sumOfC1;
  }
  
  public void setSumOfC1(String sumOfC1) {
    this.sumOfC1 = sumOfC1;
  }
  
  public String getSumOfCB1() {
    return sumOfCB1;
  }
  
  public void setSumOfCB1(String sumOfCB1) {
    this.sumOfCB1 = sumOfCB1;
  }
  
  public String getSumOfD1() {
    return sumOfD1;
  }
  
  public void setSumOfD1(String sumOfD1) {
    this.sumOfD1 = sumOfD1;
  }
  
  public String getSumOfE1() {
    return sumOfE1;
  }
  
  public void setSumOfE1(String sumOfE1) {
    this.sumOfE1 = sumOfE1;
  }
  
  public String getSumOfF1() {
    return sumOfF1;
  }
  
  public void setSumOfF1(String sumOfF1) {
    this.sumOfF1 = sumOfF1;
  }
  
  public String getSumOfG1() {
    return sumOfG1;
  }
  
  public void setSumOfG1(String sumOfG1) {
    this.sumOfG1 = sumOfG1;
  }
  
  public String getSumOfG2() {
    return sumOfG2;
  }
  
  public void setSumOfG2(String sumOfG2) {
    this.sumOfG2 = sumOfG2;
  }
  
  /**
   * @return discountDeliveryFee を戻します。
   */
  public String getDiscountDeliveryFee() {
    if (SIUtil.isNull(this.discountDeliveryFee)) this.discountDeliveryFee = "0";
    return discountDeliveryFee;
  }
  
  /**
   * @param discountDeliveryFee discountDeliveryFee を設定。
   */
  public void setDiscountDeliveryFee(String discountDeliveryFee) {
    this.discountDeliveryFee = discountDeliveryFee;
  }
  
  /**
   * @return discountFee を戻します。
   */
  public String getDiscountFee() {
    if (SIUtil.isNull(this.discountFee)) this.discountFee = "0";
    return discountFee;
  }
  
  /**
   * @param discountFee discountFee を設定。
   */
  public void setDiscountFee(String discountFee) {
    this.discountFee = discountFee;
  }

  //getter of deliveryCheck
  public String[] getDeliveryCheck() {
    return this.deliveryCheck;
  }
  
  //setter of deliveryCheck
  public void setDeliveryCheck(String[] deliveryCheck) {
    this.deliveryCheck = deliveryCheck;
  }
  
  
  //setter of deliveryKomonoCheck
  public void setDeliveryKomonoCheck(boolean deliveryKomonoCheck) {
    this.deliveryKomonoCheck = deliveryKomonoCheck;
  }
  
  //getter of deliveryKomonoCheck
  public boolean isDeliveryKomonoCheck() {
    return this.deliveryKomonoCheck;
  }
  
  //getter of komonoDeliveryFee
  public String getKomonoDeliveryFee() {
    return this.komonoDeliveryFee;
  }
  
  //setter of komonoDeliveryFee
  public void setKomonoDeliveryFee(String komonoDeliveryFee) {
    if (SIUtil.isNull(komonoDeliveryFee)) komonoDeliveryFee = "0";
    this.komonoDeliveryFee = SIUtil.changeTo(komonoDeliveryFee.trim(), this.encode);
  }
  
  // EDBTG003-00 elecs-tani add start
  /**
   * @return sumOfH
   */
  public String getSumOfH() {
    return sumOfH;
  }
  
  /**
   * @param sumOfH セットする sumOfH
   */
  public void setSumOfH(String sumOfH) {
    this.sumOfH = sumOfH;
  }
  // EDBTG003-00 elecs-tani add end
  
  /**
   * <b>getFullPointFlg</b> 全額ポイントで支払うかどうかをチェックします
   * 
   * @param なし
   * @return なし
   * @throws なし
   */
  public boolean getFullPointFlg() {
    if (getCalcFee().equals("0") && Long.parseLong(getSumOfE()) <= Long.parseLong(getMaxPoint())) {
      return true;
    } else {
      return false;
    }
  }
  
  /**
   * <b>setPayMethodFee</b> 支払フラグ、支払料金の設定を行います
   * 
   * @param Connection
   * @return なし
   * @throws なし
   */
  private void setPayMethodFee(Connection lConnection) {
    
    // 手数料計算金額が０の時は支払方法をリセット
    if (this.getPayMethodName().equals(SIConfig.SIPointPayName) || this.getPayMethodName().equals(SIConfig.SIZeroPayName)) {
      if (SIUtil.isNotNull(this.getPayMethodNameBack())) {
        this.setEncode(SIConfig.SIENCODE_NONE);
        this.setPayMethodName(this.getPayMethodNameBack());// 支払フラグの設定
        this.setEncode(SIConfig.SIENCODE_SHIFT_JIS);
      } else {
        this.setPayMethodName("");// 支払フラグの設定
        this.setPaymentFlg("");// 支払フラグの設定
        this.setFee("");// 支払い料金の設定
        this.setFeeTaxFlg("");// 支払い料金税区分の設定
      }
    }
    
    // ポイント全額支払
    if ((SIUtil.isNotNull(this.getSumByPoint()) && !this.getSumByPoint().equals("0"))
        && (SIUtil.isNull(this.getCalcFee()) || (SIUtil.isNotNull(this.getCalcFee()) && Integer.parseInt(this.getCalcFee()) <= 0))) {
      this.setEncode(SIConfig.SIENCODE_NONE);
      this.setPayMethodName(SIConfig.SIPointPayName);// 支払フラグの設定
      this.setPaymentFlg(SIFlagConf.SIFLAG_PAYMENTFLG_POINT);// 支払フラグの設定
      this.setFee(SIConfig.SIPointPayFee);// 支払い料金の設定
      this.setDiscountFee(SIConfig.SIPointPayFee);// 手数料調整額の設定
      this.setFeeTaxFlg("0");// 支払い料金税区分の設定
      this.setEncode(SIConfig.SIENCODE_SHIFT_JIS);
      // 送料＋商品合計が0円
    } else if ((SIUtil.isNull(this.getSumByPoint()) || this.getSumByPoint().equals("0")) && (SIUtil.isNull(this.getCalcFee()) || this.getCalcFee().equals("0"))) {
      this.setEncode(SIConfig.SIENCODE_NONE);
      this.setPayMethodName(SIConfig.SIZeroPayName);// 支払フラグの設定
      this.setPaymentFlg(SIFlagConf.SIFLAG_PAYMENTFLG_POINT);// 支払フラグの設定
      this.setFee(SIConfig.SIPointPayFee);// 支払い料金の設定
      this.setDiscountFee(SIConfig.SIPointPayFee);// 手数料調整額の設定
      this.setFeeTaxFlg("0");// 支払い料金税区分の設定
      this.setEncode(SIConfig.SIENCODE_SHIFT_JIS);
      // ポイント全額支払以外
    } else {
      // 支払フラグと支払料金の設定
      SIPayMethod lPayMethod = new SIPayMethod();
      lPayMethod.setEncode(SIConfig.SIENCODE_NONE);
      
      if (SIUtil.isNull(getShopCode())) {// モール一括決済
        lPayMethod.setMallShopCode(SIConfig.SIMALL.getMallShopCode());
      } else {// ショップ決済
        lPayMethod.setMallShopCode(getShopCode());
      }
      
      lPayMethod.setPayMethodName(getPayMethodName());
      lPayMethod.setPrice(this.getCalcFee());
      lPayMethod.resetPayMethodName(lConnection);//
      
      this.setPaymentFlg(lPayMethod.getPaymentFlg());// 支払フラグの設定
      this.setFee(lPayMethod.getFee());// 支払い料金の設定
    }
  }
  
  public void calcSum(HttpServletRequest lRequest, Connection lConnection, SIURLParameter lUrlParam) {
    calcSum(lRequest, lConnection, lUrlParam, "", "");
  }
  
  /**
   * <b>calcSum</b> 合計料金と各手数料を計算する
   * 
   * @param lRequest リクエスト
   * @param lConnection DBへのコネクション
   * @param lUrlParam
   * @return なし
   * @throws なし
   */
  public void calcSum(HttpServletRequest lRequest, Connection lConnection, SIURLParameter lUrlParam, String exSumOfB1, String exSumOfB2) {// 7.1.1 ST0236 修正
    String lDeliveryFee = "0";
    String lSumOfCB = "0";
    String lSumOfA = "0";
    String lSumOfB = "0";// 送料
    String lSumOfC = "0";// 手数料
    String lSumOfD = "0";
    String lSumOfE = "0";
    String lSumOfF = "0";
    String lSumOfPrice = "0";
    String lTotalOfAmount = "0";
    
    String lSumOfCB1 = "0";
    String lSumOfA1 = "0";
    String lSumOfB1 = "0";// 送料
    String lSumOfC1 = "0";// 手数料
    String lSumOfD1 = "0";
    String lSumOfE1 = "0";
    String lSumOfF1 = "0";
    String lSumOfPrice1 = "0";
    String lDeliveryFee1 = "0";
    String lSumOfCB2 = "0";
    String lSumOfA2 = "0";
    String lSumOfB2 = "0";// 送料
    String lSumOfC2 = "0";// 手数料
    String lSumOfD2 = "0";
    String lSumOfE2 = "0";
    String lSumOfF2 = "0";
    
    String lSumOfPrice2 = "0";
    String lDeliveryFee2 = "0";
    
    String discountDeliveryFee = "0";// 送料調整額
    String discountFee = "0";// 手数料調整額
    
    // EDBTG003-00 nagayoshi add start
    // セット値引金額
    String lSumOfH = "0";
    // EDBTG003-00 nagayoshi add end
    
    // セッションの取得
    HttpSession session = lRequest.getSession(true);
    
    SIMallShop lMallShop = new SIMallShop();
    if (SIUtil.isNotNull(getShopCode())) {
      lMallShop = new SIMallShop(getShopCode());
      lMallShop.reset(lConnection);
    } else lMallShop = SIConfig.SIMALL;
    setFeeTaxFlg(lMallShop.getFeeTaxFlg());
    setTaxRate(SITax.getTaxRate(lConnection));
    
    LinkedHashMap deliveryMap = (LinkedHashMap) session.getAttribute(SIConfig.SISESSION_CART_DELIVERY_NAME);
    Collection deliveryColl = SICartDetail.getDeliveryCollection(lRequest, this.getShopCode());
    Iterator deliveryIte = deliveryColl.iterator();
    
    while (deliveryIte.hasNext()) {
      SIOrderDelivery deliveryID = (SIOrderDelivery) deliveryIte.next();
      
      if ("0".equals(deliveryID.getDeliveryTypeCode())) {
        // 各配送先の送料を計算
        Collection detailColl = SICartDetail.getDetailCollection(lRequest, deliveryID.getDeliveryCode(), deliveryID.getShopCode());
        lDeliveryFee = SIDeliveryFee.calcDeliveryFee(lConnection, deliveryID.getShopCode(), deliveryID, detailColl);
        deliveryID.setDeliveryFee(lDeliveryFee);
        
        // ショップ送料消費税
        lSumOfB1 = SIUtil.add_LL(lSumOfB1, deliveryID.getDeliveryFeeIncTax());
        setTaxFlgOfB(deliveryID.getDeliveryTaxFlg());
        
        deliveryMap.put(deliveryID.getDeliveryCode(), deliveryID);
        
        Iterator detailIte = detailColl.iterator();
        while (detailIte.hasNext()) {
          SIOrderDetail detailID = (SIOrderDetail) detailIte.next();
          if (SIUtil.isNull(getShopCode()) || getShopCode().equals(detailID.getShopCode())) {// 当分の決済のショップコード
            lSumOfCB1 = SIUtil.add_LL(lSumOfCB1, detailID.getPriceOfCmdty());
            lSumOfA1 = SIUtil.add_LL(lSumOfA1, detailID.getPriceIncGift());
            setTaxFlgOfCB(detailID.getTaxFlg());
            
            if (!detailID.getWrappingTaxFlg().equals("0") || !detailID.getTaxFlg().equals("0")) {
              setTaxFlgOfA("2");
            }
            
            lSumOfPrice1 = SIUtil.add_LL(lSumOfPrice1, SIUtil.multi_LL(detailID.getAmount(), detailID.getPriceIncTax()));
            lTotalOfAmount = SIUtil.add_LL(lTotalOfAmount, detailID.getAmount());// トータルの数量
          }
        }
      } else if ("1".equals(deliveryID.getDeliveryTypeCode())) {
        // 各配送先の送料を計算
        Collection detailColl2 = SICartDetail.getDetailCollection(lRequest, deliveryID.getDeliveryCode(), deliveryID.getShopCode());
        lDeliveryFee2 = SIDeliveryFee.calcDeliveryFee(lConnection, deliveryID.getShopCode(), deliveryID, detailColl2);
        deliveryID.setDeliveryFee(lDeliveryFee2);
        this.setKomonoDeliveryFee(lDeliveryFee2);
        
        // ショップ送料消費税
        lSumOfB2 = SIUtil.add_LL(lSumOfB2, deliveryID.getDeliveryFeeIncTax());
        setTaxFlgOfB(deliveryID.getDeliveryTaxFlg());
        
        deliveryMap.put(deliveryID.getDeliveryCode(), deliveryID);
        
        Iterator detailIte2 = detailColl2.iterator();
        while (detailIte2.hasNext()) {
          SIOrderDetail detailID2 = (SIOrderDetail) detailIte2.next();
          if (SIUtil.isNull(getShopCode()) || getShopCode().equals(detailID2.getShopCode())) {// 当分の決済のショップコード
            lSumOfCB2 = SIUtil.add_LL(lSumOfCB2, detailID2.getPriceOfCmdty());
            lSumOfA2 = SIUtil.add_LL(lSumOfA2, detailID2.getPriceIncGift());
            setTaxFlgOfCB(detailID2.getTaxFlg());
            
            if (!detailID2.getWrappingTaxFlg().equals("0") || !detailID2.getTaxFlg().equals("0")) {
              setTaxFlgOfA("2");
            }
            
            lSumOfPrice2 = SIUtil.add_LL(lSumOfPrice2, SIUtil.multi_LL(detailID2.getAmount(), detailID2.getPriceIncTax()));
            lTotalOfAmount = SIUtil.add_LL(lTotalOfAmount, detailID2.getAmount());// トータルの数量
          }
        }
      }
    }
    
    // 調整額計算
    if (SIUtil.isNotNull(this.getDiscountDeliveryFee())) {
      discountDeliveryFee = this.getDiscountDeliveryFee();
    }
    if (SIUtil.isNotNull(this.getDiscountFee())) {
      discountFee = this.getDiscountFee();
    }
    
    lDeliveryFee = lDeliveryFee1 + lDeliveryFee2;
    lSumOfCB = SIUtil.add_LL(lSumOfCB1, lSumOfCB2);
    lSumOfA = SIUtil.add_LL(lSumOfA1, lSumOfA2);
    if (SIUtil.isNotNull(exSumOfB1)) lSumOfB1 = exSumOfB1;
    if (SIUtil.isNotNull(exSumOfB2)) lSumOfB2 = exSumOfB2;
    lSumOfB = SIUtil.add_LL(lSumOfB1, lSumOfB2);
    lSumOfD = SIUtil.add_LL(lSumOfD1, lSumOfD2);
    lSumOfE = SIUtil.add_LL(lSumOfE1, lSumOfE2);
    lSumOfPrice = SIUtil.add_LL(lSumOfPrice1, lSumOfPrice2);
    lSumOfE = SIUtil.add_LL(lSumOfE, getSumByPoint());
    lSumOfD = SIUtil.add_LLL(lSumOfA, lSumOfB, lSumOfC);// 7.3.0 PI-NES0501 修正
    lSumOfD = SIUtil.add_LLL(lSumOfD, discountFee, discountDeliveryFee);// 7.3.0 PI-NES0501 修正
    
    // EDBTG003-00 nagayoshi add start
    // セット値引金額の取得
    SIOrderSetCmdty lOrderSetCmdty = new SIOrderSetCmdty();
    lSumOfH = lOrderSetCmdty.getSetDisCountPrice(lRequest);
    // EDBTG003-00 nagayoshi add end
    
    if (SIUtil.isNull(this.getSumByPoint())) {
      this.setSumByPoint(this.getMaxPoint());
      // ポイント使用額を丸める。
      // EDBTG003-00 elecs-matsushima mod start
//      if (Long.parseLong(SIUtil.add_LLL(lSumOfA, lSumOfB, discountDeliveryFee)) <= Long.parseLong(this.getMaxPoint())) {// 7.3.0 PI-NES05011 修正
//        this.setSumByPoint(SIUtil.sub(SIUtil.add_LLL(lSumOfA, lSumOfB, discountDeliveryFee), this.getSumOfG()));
//      }
      if (Long.parseLong(SIUtil.sub_LL(SIUtil.add_LLL(lSumOfA, lSumOfB, discountDeliveryFee),lSumOfH)) <= Long.parseLong(this.getMaxPoint())) {
        this.setSumByPoint(SIUtil.sub(SIUtil.add_LLL(lSumOfA, lSumOfB, discountDeliveryFee), SIUtil.add_LL(this.getSumOfG(), lSumOfH)));
      }
      // EDBTG003-00 elecs-matsushima mod end
      lSumOfE = this.getSumByPoint();
    } else if (!lSumOfE.equals("0")) {
      // EDBTG003-00 elecs-matsushima mod start
//      if (Long.parseLong(lSumOfD) < Long.parseLong(lSumOfE) && Long.parseLong(this.getMaxPoint()) < Long.parseLong(lSumOfE)) {
//        // this.setSumByPoint(this.getMaxPoint());
//      } else if (Long.parseLong(lSumOfD) < Long.parseLong(lSumOfE) && Long.parseLong(this.getMaxPoint()) > Long.parseLong(lSumOfE)) {
//        this.setSumByPoint(SIUtil.sub(SIUtil.add_LLL(lSumOfA, lSumOfB, discountDeliveryFee), this.getSumOfG()));
//      }
      if (Long.parseLong(SIUtil.sub_LL(lSumOfD, lSumOfH)) < Long.parseLong(lSumOfE) && Long.parseLong(this.getMaxPoint()) < Long.parseLong(lSumOfE)) {
        // this.setSumByPoint(this.getMaxPoint());
      } else if (Long.parseLong(SIUtil.sub_LL(lSumOfD, lSumOfH)) < Long.parseLong(lSumOfE) && Long.parseLong(this.getMaxPoint()) > Long.parseLong(lSumOfE)) {
        this.setSumByPoint(SIUtil.sub(SIUtil.add_LLL(lSumOfA, lSumOfB, discountDeliveryFee), SIUtil.add_LL(this.getSumOfG(), lSumOfH)));
      }
      // EDBTG003-00 elecs-matsushima mod end
      lSumOfE = this.getSumByPoint();
    }
    // EDBTG003-00 nagayoshi add start
//    setCalcFee(SIUtil.sub_LL(SIUtil.sub_LL(SIUtil.add_LLL(lSumOfA, lSumOfB, discountDeliveryFee), lSumOfE), this.getSumOfG()));// 手数料計算用
    setCalcFee(SIUtil.sub_LL(SIUtil.sub_LL(SIUtil.add_LLL(lSumOfA, lSumOfB, discountDeliveryFee), lSumOfE), SIUtil.add_LL(this.getSumOfG(), lSumOfH)));// 手数料計算用
    // EDBTG003-00 nagayoshi add end
    // 支払い料金の設定
    setPayMethodFee(lConnection);
    
    // 全額ポイント決済の場合：手数料がゼロになるため
    discountFee = "0";
    if (SIUtil.isNotNull(this.getDiscountFee())) {
      discountFee = this.getDiscountFee();
    }
    if (!lSumOfE.equals("0") && this.getCalcFee().equals("0") && this.getPayMethodName().equals(SIConfig.SIPointPayName)) {
      this.setSumByPoint(SIUtil.sub(SIUtil.sub(SIUtil.add_LLL(lSumOfA, lSumOfB, discountDeliveryFee),lSumOfH), this.getSumOfG()));
    }
    
    lSumOfC1 = SIUtil.add_LL(lSumOfC1, getFeeIncTax());
    lSumOfD1 = SIUtil.add_LLL(lSumOfA1, lSumOfB1, lSumOfC1);
    lSumOfD2 = SIUtil.add_LLL(lSumOfA2, lSumOfB2, lSumOfC2);
    lSumOfD1 = SIUtil.add_LLL(lSumOfD1, discountFee, discountDeliveryFee);
    
    // 7.2.0 ST1030 修正 ここから
    lSumOfC = SIUtil.add_LL(lSumOfC1, lSumOfC2);
    lSumOfF1 = SIUtil.sub_LL(lSumOfD1, lSumOfE1);
    lSumOfF2 = SIUtil.sub_LL(lSumOfD2, lSumOfE2);
    lSumOfF = SIUtil.sub_LL(SIUtil.add_LL(lSumOfF1, lSumOfF2), this.getSumOfG());
    // 7.2.0 ST1030 修正 ここまで
    
    // バックで支払区分がクレジットの時はリセットする。
    // 7.2.0 ST0300 修正 ここから
    // 支払区分がコンビニ決済の時もリセットする
    // if(SIUtil.isNotNull((String)lUrlParam.getParam("siteFlg")) &&
    // ((String)lUrlParam.getParam("siteFlg")).equals("back") &&
    // (this.getPaymentFlg().equals(SIFlagConf.SIFLAG_PAYMENTFLG_CARD) ||
    // this.getPaymentFlg().equals(SIFlagConf.SIFLAG_PAYMENTFLG_CVS))) { //7.1.2 ST0236 修正
    // //7.2.0 ST0300 修正 ここまで
    // this.setPayMethodName("");//支払フラグの設定
    // this.setPaymentFlg("");//支払フラグの設定
    // this.setFee("");//支払い料金の設定
    // this.setFeeTaxFlg("");//支払い料金税区分の設定
    // }
    
    lSumOfD = SIUtil.add_LL(lSumOfD1, lSumOfD2);// 7.3.0 PI-NES0501 修正
    // EDBTG003-00 nagayoshi add start
    // 合計金額より、セット値引を減算
    lSumOfF = SIUtil.sub_LL(lSumOfF, lSumOfH);
    // EDBTG003-00 nagayoshi add end
    lSumOfF = SIUtil.sub(lSumOfF, lSumOfE);// 7.3.0 PI-NES0501 修正
    
    session.setAttribute(SIConfig.SISESSION_CART_DELIVERY_NAME, deliveryMap);
    
    setSumOfCB(lSumOfCB);
    setSumOfA(lSumOfA);
    setSumOfB(lSumOfB);
    setSumOfC(lSumOfC);
    setSumOfD(lSumOfD);
    setSumOfE(lSumOfE);
    // EDBTG003-00 nagayoshi add start
    setSumOfH(lSumOfH);
    // EDBTG003-00 nagayoshi add end
    setSumOfF(lSumOfF);
    setSumOfPrice(lSumOfPrice);
    setTotalOfAmount(lTotalOfAmount);
    
    setSumOfCB1(lSumOfCB1);
    setSumOfA1(lSumOfA1);
    setSumOfB1(lSumOfB1);
    setSumOfC1(lSumOfC1);
    setSumOfD1(lSumOfD1);
    setSumOfE1(lSumOfE1);
    setSumOfF1(lSumOfF1);
    
    setSumOfCB2(lSumOfCB2);
    setSumOfA2(lSumOfA2);
    setSumOfB2(lSumOfB2);
    setSumOfC2(lSumOfC2);
    setSumOfD2(lSumOfD2);
    setSumOfE2(lSumOfE2);
    setSumOfF2(lSumOfF2);
    
    // 税の設定
    setTaxFlgOfC(getFeeTaxFlg());
    if ((!lSumOfB.equals("0") && !taxFlgOfB.equals("0")) || (!lSumOfC.equals("0") && taxFlgOfC.equals("0"))) setTaxFlgOfD("1");
    else setTaxFlgOfD(taxFlgOfA);
    setTaxFlgOfF(taxFlgOfD);
  }
}