<?php
//共通
require_once '../../base/common.php';
$logger = new logger(basename(__FILE__));
$logger->info("=== af222x_update_start ===");

$response["status"] = "OK";

//返り値
$request_body = file_get_contents('php://input');
$data = json_decode($request_body, true);

$logger->info("data", $data);

try {
  global $dbutil;
  global $stringUtil;
  $valutil = new getValueUtil();
  $ktktcd = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["LGKTKTCD"];

  $ret = "0";
  $header = $data["header"];
  $footer = $data["footer"];

  if ($header["tcls"] == "01") {  //売上
    if ($header["issue_mode"] == "1") { //出庫も行う
      if (!$stringUtil->isEmpty($header["cuiseq"])  //受注下敷き
          || !$stringUtil->isEmpty($header["spktcd"]) ) {  //倉庫あり
        $w_niugoki = "ON";
      } else {
        $w_niugoki = "OFF";
      }
    } else {
      $w_niugoki = "OFF";
    }
  } else {
    $w_niugoki = "OFF";
  }
  if ($w_niugoki == "ON") {
    $kbat = $dbutil->nextVal("innerKBAT");  //afr3123用kbat
    if ($stringUtil->isEmpty($header["cuiseq"])) { //下敷きなし
      if ($stringUtil->isEmpty($header["vseq"])) {
        $cvseq = $valutil->getVSeq("0", $ktktcd, $header["cucd"]);  //afr3123.vseq
      } else {
        $cvseq = $header["vseq"];
      }
      $cuiseq = $dbutil->nextVal("innerviseq");  //afr3123.cuiseq
    } else {
      $cvseq = $header["cvseq"];
      $cuiseq = $header["cuiseq"];
    }
  }

  //StartiDat取得
  $sql = file_get_contents("./sql/getStartIdat.sql");
  $result = $dbutil->selectnocount($sql);
  $start_idat = $result[0]["idat"];

  // ロック生成
	$handle = null;
  $result = lockRequestAP();
  if ($result['ret'] != 0) {
    //afs73Insert
    insertAfs73($dbutil, $start_idat, "ロックエラー");
    throw new UserException("E0002", "登録に失敗しました。",null);
  } else {
    $handle = $result['handle'];
  }

  //登録直前にaus75を再チェック
  $ret_sbat = $valutil->getSbat("1","0",$ktktcd,$header["cucd"],$header["cuscd"]);
  if ($ret_sbat["ret"] != "0") {
    if (!$stringUtil->isEmpty($handle)) {
      lockReleaseAP($handle); //lock解除
    }
    insertAfs73($dbutil, $start_idat, "SBATエラー");
    throw new UserException("E0002", "登録に失敗しました。",null);
  }
  $header["sbat"] = $ret_sbat["sbat"];

  /* 請求訂正対象のデータなのかをチェック */
  if ($header["sts"] == "3") {
    if ($header["old_adat"] <= $header["cdat"]) {
			$w_teiflg = 1;
    } else {
			$w_teiflg = 0;
    }
  }

  if ($w_niugoki == "ON") { //荷動き作るとき
    $retvseq = $cvseq;  //受注の伝票番号
  } else {  //荷動き作らない
    //伝票番号の入力がない場合は自動採番
    if($stringUtil->isEmpty($header["vseq"])) {
      $result = $valutil->getVSeq("0", $ktktcd, $header["cucd"]);
      $header["vseq"] = $result;
  $logger->info("getVseq",$result);
    }

    //新規の場合は、内部伝票番号を採番
    if($stringUtil->isEmpty($header["viseq"])) {
      $viseq = $dbutil->nextVal("innerviseq");
      $header["viseq"] = $viseq;
  $logger->info("getViseq",$result);
    }
    $retvseq = $header["vseq"];
  }

  //atm05.dnflg取得
  $ret05 = $valutil->allMastData("0",'afm05',$header["spktcd"]);
  $w_dnflg = $ret05["dnflg"];
  $w_syflg = $ret05["syflg"];
$logger->info("dnflg",$w_dnflg);

  //担当コード取得
  $sql = file_get_contents("./sql/getSpslcd.sql");
  $whereParams = array();
  $whereParams["cucd"] = $header["cucd"];
  $whereParams["cuscd"] = $header["cuscd"];
  $result = $dbutil->selectnocount($sql, $whereParams);
  if ($result == null) {
    $w_spslcd = "";
  } else {
    $w_spslcd = $result[0]["spslcd"];
  }
$logger->info("spslcd",$w_spslcd);

  //cugdde取得
  $sql = file_get_contents("./sql/getCugdde.sql");
  $whereParams = array();
  $whereParams["cucd"] = $header["cucd"];
  $result = $dbutil->selectnocount($sql, $whereParams);
  if ($result == null) {
    $w_cugdde = "";
  } else {
    $w_cugdde = $result[0]["cugdde"];
  }
$logger->info("cugdde",$w_cugdde);

  if ($header["sts"] == "3") {
    if ($header["adat"] <= $header["cdat"]) {
      $w_sbat = $header["sbat"];
    } else {
      $w_sbat = "-999";
    }
  } else {
    $w_sbat = "-999";
  }
$logger->info("w_sbat",$w_sbat);

  $vlin = 1;

  //新規荷動きあり受注用伝票行数
  $lcnt = 0;
  if ($header["newmode"] == "NEW") {
    foreach($data["data"] as $key => $detail) {
      if (!$stringUtil->isEmpty($detail["ijan"])
        ||!$stringUtil->isEmpty($detail["jan"])
        ||!$stringUtil->isEmpty($detail["gdjnm"])
        ||!$stringUtil->isEmpty($detail["gdjstnd"]) ) { //商品入力あり
        $lcnt = $lcnt + 1;
      }
    }
  }

  foreach($data["data"] as $key => $detail) {
$logger->info("detail>>",$detail);
    if (!$stringUtil->isEmpty($detail["chkLineDel"])) {   /* 行削除された分を削除 */
      if (!$stringUtil->isEmpty($detail["iseq30"])) {
        //請求訂正時の削除はdeleteではなく、teif・sbatをupdate
				//w_teiflg = 1の条件を追加,chgcdをupdate項目に追加
        if ($header["sts"] == "3" && $w_teiflg == "1") {
          delete_upd_Aur32($header["sbat"], $detail["iseq30"], $dbutil, $logger, $vlin);
        } else {
          deleteAur32($detail["iseq30"], $dbutil, $logger, $vlin);
        }
      }
    } else {
      /* ISEQが埋まっているレコード or JANの入力があるレコードを対象とする */
      if (!$stringUtil->isEmpty($detail["iseq30"])
            || !$stringUtil->isEmpty($detail["ijan"])
            || !$stringUtil->isEmpty($detail["jan"])
            || !$stringUtil->isEmpty($detail["gdjnm"])
            || !$stringUtil->isEmpty($detail["gdjstnd"]) ) {

        if ($header["cutaxcls"] == "1" && $header["cutax"] == "1") {  //総額得意先なら
$logger->info("sogaku_cucd");
          $w_ntcst = Number($stringUtil->toNumber($detail["ncst"]));
          if ($header["tcls"] == "03") {  //値引
            //計上日を渡す
						$w_ncst  = -1 * $valutil->calc_gdbcst("1","1",$ktktcd,$header["cucd"],$detail["ijan"],$w_ntcst*-1,$header["adat"]);
					} else {
            //計上日を渡す
            $w_ncst  = $valutil->calc_gdbcst("1","1",$ktktcd,$header["cucd"],$detail["ijan"],$w_ntcst,$header["adat"]);
          }
				} else {
$logger->info("not_sogaku_cucd,cutax=".$header["cutax"]);
          $w_ncst = $stringUtil->toNumber($detail["ncst"]);
					/* 税込単価(ntcst)の取得 */
          if ($header["cutax"] == "1") {
            if ($header["tcls"] == "03") {  //値引き
              //計上日を渡す
							$w_ntcst = -1 * $valutil->get_ntcst($ktktcd, $detail["ijan"], $header["cucd"],$header["adat"],-1 * $w_ncst);
						} else {
              //計上日を渡す
							$w_ntcst = $valutil->get_ntcst($ktktcd, $detail["ijan"], $header["cucd"], $header["adat"], $w_ncst);
            }
					} else {
						$w_ntcst = "";
					}
				}
$logger->info("w_ncst>>".$w_ncst.",w_ntcst>>".$w_ntcst);

        if (!$stringUtil->isEmpty($detail["iseq30"])) { /* ISEQが埋まっているレコードを更新、以外は新規 */
					if ($data["updMode"] != "1") { //削除以外
            if ($header["newmode"] == "NEW"
                  || $header["old_dat2"] != $header["dat2"]
                  || $header["old_adat"] != $header["adat"]
                  || $header["old_dcubcd"] != $header["dcubcd"]
                  || $header["old_cuslip"] != $header["cuslip"]
                  || $header["old_spktcd"] != $header["spktcd"]
                  || $header["old_bbno"] != $header["bbno"]
                  || $header["old_dtxt1"] != $header["dtxt1"]
                  || $header["old_dtxt2"] != $header["dtxt2"]
                  || $header["old_ltxt1"] != $header["ltxt1"]
                  || $header["old_ltxt2"] != $header["ltxt2"]
                  || $footer["old_txt1"] != $footer["txt1"]
                  || $detail["old_jan"] != $detail["jan"]
                  || ($header["tcls"] == "03" && $detail["old_gdjnm"] != $detail["gdjnm"])
                  || ($header["tcls"] == "03" && $detail["old_gdjstnd"] != $detail["gdjstnd"])
                  || $detail["old_vlin"] != $vlin
                  || floatval($stringUtil->toNumber($detail["old_tpno"])) != floatval($stringUtil->toNumber($detail["tpno"]))
                  || floatval($stringUtil->toNumber($detail["old_ncst"])) != floatval($stringUtil->toNumber($detail["ncst"])) ) { //変更があれば

              $oparam = array();
              $oparam["ncst"] = $w_ncst;
              $oparam["ntcst"] = $w_ntcst;
              $oparam["sbat"] = $w_sbat;
              updateAur32($header, $detail, $footer, $oparam, $dbutil, $logger, $vlin);
            }
					} else { //削除
						//SE-322 請求訂正時の削除はdeleteではなく、teif・sbatをupdateするように変更
						//w_teiflg = 1の条件を追加,chgcdをupdate項目に追加
            if ($header["sts"] == "3" && $w_teiflg == "1") {
              delete_upd_Aur32($header["sbat"], $detail["iseq30"], $dbutil, $logger, $vlin);
            } else {
              deleteAur32($detail["iseq30"], $dbutil, $logger, $vlin);
            }
          }
          $vlin = $vlin + 1;  //行カウント
				} else {  //新規行
          if ($data["updMode"] != "1") { //削除以外
            if (!$stringUtil->isEmpty($detail["ijan"])
              ||!$stringUtil->isEmpty($detail["jan"])
              ||!$stringUtil->isEmpty($detail["gdjnm"])
              ||!$stringUtil->isEmpty($detail["gdjstnd"]) ) { //商品入力あり

              if ($header["tcls"] == "03") { //値引
                $w_iseq30 = $dbutil->nextVal("innerseq");
                $oparam = array();
                $oparam["iseq30"] = $w_iseq30;
                $oparam["ncst"] = $w_ncst;
                $oparam["ntcst"] = $w_ntcst;
                $oparam["sbat"] = $w_sbat;
                $oparam["spslcd"] = $w_spslcd;
                insertAur32($header, $detail, $footer, $oparam, $dbutil, $logger, $vlin);
              } else if ($header["tcls"] == "01") { //売上

                $w_iseq30 = $dbutil->nextVal("innerseq"); //aur32.iseq30
                if ($w_niugoki == "ON") { //荷動きデータ
                    //在庫チェック
                    $whereParams = array();
                    $whereParams["spktcd"] = $header["spktcd"];
                    $whereParams["ijan"] = $detail["ijan"];
                    $whereParams["tpno"] = $stringUtil->toNumber($detail["tpno"]);
                    $sql = file_get_contents("./sql/chkZaiko.sql");
                    $result = $dbutil->selectNoCount($sql, $whereParams);
                    if ($result[0]["chkzaiko"] == "-1") { //在庫不足エラー
                      $errmsg = "引当結果がﾏｲﾅｽ在庫となります。引当数を確認して下さい。(JAN:".$detail["jan"].")";
                      $ret = "-1";
                      break;
                    }

                    if ($stringUtil->isEmpty($detail["iseq3123"])) { //受注下敷きなしの場合：受注データ作成
                      $w_iseq3123 = $dbutil->nextVal("Innerseq23"); //aur3123.iseq
                      //afr3123更新
                      $oparam = array();
                      $oparam["iseq"] = $w_iseq3123;
                      $oparam["cvseq"] = $cvseq;
                      $oparam["cuiseq"] = $cuiseq;
                      $oparam["ncst"] = $w_ncst;
                      $oparam["ntcst"] = $w_ntcst;
                      $oparam["lcnt"] = $lcnt;
                      insertAfr3123Niugoki($header, $detail, $footer, $oparam, $dbutil, $logger, $vlin);
                    } else {
                      $w_iseq3123 = $detail["iseq3123"];
                    }

                    //afr3123更新
                    $oparam = array();
                    $oparam["kbat"] = $kbat;
                    $oparam["piseq"] = $w_iseq3123;   //受注データのiseq
                    $oparam["syflg"] = $w_syflg;
                    updateAfr3123Niugoki($header, $detail, $footer, $oparam, $dbutil, $logger, $vlin);

                    //aur32作成
                    $oparam = array();
                    $oparam["start_idat"] = $start_idat;
                    $oparam["iseq30"] = $w_iseq30;
                    $oparam["piseq"] = $w_iseq3123;   //受注データのiseq
                    $oparam["ncst"] = $w_ncst;
                    $oparam["ntcst"] = $w_ntcst;
                    $oparam["sbat"] = $w_sbat;
                    $oparam["spslcd"] = $w_spslcd;
                    $oparam["dnflg"] = $w_dnflg;
                    $oparam["tpno"] = $stringUtil->toNumber($detail["tpno"]);
                    insertAur32Niugoki($header, $detail, $footer, $oparam, $dbutil, $logger, $vlin);
                  } else {  //荷動き不要
                    $oparam = array();
                    $oparam["iseq30"] = $w_iseq30;
                    $oparam["ncst"] = $w_ncst;
                    $oparam["ntcst"] = $w_ntcst;
                    $oparam["sbat"] = $w_sbat;
                    $oparam["spslcd"] = $w_spslcd;
                    insertAur32($header, $detail, $footer, $oparam, $dbutil, $logger, $vlin);
                    if ($w_cugdde == '1') {
                      insertAfr31o($header, $oparam, $dbutil, $logger, $vlin);
      							}
                  }
                }
                $vlin = $vlin + 1;  //新規行カウント
  						}

            }
					}
        }
      }
    }

  //ロック解除
  if (!$stringUtil->isEmpty($handle)) {
    lockReleaseAP($handle); //lock解除
  }

  if ($ret == "0") {  //エラーなし
    $dbutil->commit();
  } else {
    $dbutil->rollback();
  }

  $retData["ret"] = $ret;
  $retData["errmsg"] = $errmsg;
  $retData["vseq"] = $retvseq;
  $response["data"]   = $retData;

} catch(userException $ue) {
  $retData["code"]  = $ue->getErrorCode();
  $retData["msg"]   = $ue->getErrorMessage();

  $response["status"] = "NG";
  $response["data"]   = $retData;

  $dbutil->rollback();

} catch(Exception $e) {
  $response["status"] = "NG";
  $response["data"]   = $e->getMessage();

  $dbutil->rollback();

} finally {
  $logger->info("response", $response );
  print( json_encode($response) );
}

$logger->info("=== af222x_updata_end ===");

function delete_upd_Aur32($sbat, $iseq30, $dbutil, $logger, $vlin) {
  $valueData = array();
  $valueData["sbat"] = $sbat;
  $valueData["chgcd"] = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["CHGCD"];
  $valueData["iseq30"] = $iseq30;

  $sql = file_get_contents("./sql/delete_upd.sql");
  $result = $dbutil->update($sql, $valueData);
}

function deleteAur32($iseq30, $dbutil, $logger, $vlin) {
  $valueData = array();
  $valueData["iseq30"] = $iseq30;

  $sql = file_get_contents("./sql/delete.sql");
  $result = $dbutil->delete($sql, $valueData);
}

function updateAur32($header, $data, $footer, $oparam, $dbutil, $logger, $vlin) {
  global $stringUtil;
  $valutil = new getValueUtil();

  $updParams = array();

  $updParams["dat2"] = $header["dat2"];
  $updParams["adat"] = $header["adat"];
  $updParams["dcubcd"] = $header["dcubcd"];
  $updParams["cuslip"] = $header["cuslip"];
  $updParams["bbno"] = $header["bbno"];
  $updParams["dtxt1"] = $header["dtxt1"];
  $updParams["dtxt2"] = $header["dtxt2"];
  $updParams["ltxt1"] = $header["ltxt1"];
  $updParams["ltxt2"] = $header["ltxt2"];
  $updParams["vlin"] = $vlin;
  $updParams["ijan"] = $data["ijan"];
  $updParams["tpno"] = $stringUtil->toNumber($data["tpno"]);
  $updParams["icst"] = $stringUtil->toNumber($oparam["ncst"]);
  $updParams["sal"] =  $stringUtil->toNumber($data["sal"]);
  $updParams["fcst"] = $stringUtil->toNumber($data["gdcst"]);
  $updParams["txt1"] = $footer["txt1"];
  $updParams["upchg"] = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["CHGCD"];
  $updParams["sbat"] = $oparam["sbat"];
  if ($header["tcls"] == "03" && $stringUtil->isEmpty($data["jan"])) {	//値引
    $updParams["gdjnm"] = $data["gdjnm"];
    $updParams["gdjstnd"] = $data["gdjstnd"];
  } else {
    $updParams["gdjnm"] = "";
    $updParams["gdjstnd"] = "";
  }
  $updParams["cutaxcls"] = $header["cutaxcls"];
  $updParams["ntcst"] = $stringUtil->toNumber($oparam["ntcst"]);
  $updParams["ncst"] = $stringUtil->toNumber($oparam["ncst"]);

  $updParams["iseq30"] = $data["iseq30"];

  $sql = file_get_contents("./sql/update.sql");
  $logger->info($sql, $updParams);
  $result = $dbutil->update($sql, $updParams);

  return $reuslt;
}

function insertAur32($header, $data, $footer, $oparam, $dbutil, $logger, $vlin) {
$logger->info("insertAur32");
  global $stringUtil;
  $valutil = new getValueUtil();

  $updParams = array();

  $updParams["iseq30"] = $oparam["iseq30"];
  $updParams["tcls"] = $header["tcls"];
  $updParams["ktktcd"] = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["LGKTKTCD"];
  $updParams["sdday"] = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["SDDAY"];
  $updParams["ijan"] = $data["ijan"];
  $updParams["cucd"] = $header["cucd"];
  $updParams["cuscd"] = $header["cuscd"];
  $updParams["adat"] = $header["adat"];
  $updParams["dat2"] = $header["dat2"];
  $updParams["viseq"] = $header["viseq"];
  $updParams["vseq"] = $header["vseq"];
  $updParams["vlin"] = $vlin;
  $updParams["cuslip"] = $header["cuslip"];
  $updParams["tpno"] = $stringUtil->toNumber($data["tpno"]);
  $updParams["icst"] = $stringUtil->toNumber($oparam["ncst"]);
  $updParams["sal"] =  $stringUtil->toNumber($data["sal"]);
  $updParams["fcst"] = $stringUtil->toNumber($data["gdcst"]);
  $updParams["amt"] = $stringUtil->toNumber($data["s_cst"]);
  $updParams["spslcd"] = $oparam["spslcd"];
  $updParams["chgcd"] = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["CHGCD"];
  $updParams["txt1"] = $footer["txt1"];
  $updParams["dcubcd"] = $header["dcubcd"];
  $updParams["bbno"] = $header["bbno"];
  $updParams["dtxt1"] = $header["dtxt1"];
  $updParams["dtxt2"] = $header["dtxt2"];
  $updParams["ltxt1"] = $header["ltxt1"];
  $updParams["ltxt2"] = $header["ltxt2"];
  $updParams["sbat"] = $oparam["sbat"];
    if ($header["tcls"] == "03" && $stringUtil->isEmpty($data["jan"])) {	//値引
      $updParams["gdjnm"] = $data["gdjnm"];
      $updParams["gdjstnd"] = $data["gdjstnd"];
    } else {
      $updParams["gdjnm"] = "";
      $updParams["gdjstnd"] = "";
    }
  $updParams["ntcst"] = $stringUtil->toNumber($oparam["ntcst"]);
  $updParams["dat3"] = $header["dat3"];
  $updParams["dat4"] = $header["dat4"];
  $updParams["hvseq"] = $header["hvseq"];
  $updParams["iseq3123"] = $data["iseq3123"]; //受注下敷き用
  $updParams["spktcd"] = $header["spktcd"];

  $sql = file_get_contents("./sql/insert.sql");
  $logger->info($sql, $updParams);
  $result = $dbutil->insert($sql, $updParams);

  return $reuslt;
}

function insertAfr31o($header, $oparam, $dbutil, $msg, $tcls) {
  global $stringUtil;

  $updParams = array();
  $updParams["iseq30"] = $oparam["iseq30"];
  $updParams["cucd"] = $header["cucd"];
  $updParams["cuscd"] = $header["cuscd"];
  $updParams["adat"] = $header["adat"];

  $sql = file_get_contents("./sql/insert_afr31o.sql");
  $result = $dbutil->insert($sql, $updParams);
}

/*売上入力：荷動きデータ作成*/
function insertAur32Niugoki($header, $data, $footer, $oparam, $dbutil, $logger, $vlin) {
$logger->info("insertAur32Niugoki");
  global $stringUtil;
  $valutil = new getValueUtil();

  $updParams = array();

  $updParams["start_idat"] = $oparam["start_idat"];
  $updParams["iseq30"] = $oparam["iseq30"];
  $updParams["piseq"] = $oparam["piseq"];   //受注データのiseq
  $updParams["sdday"] = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["SDDAY"];
  $updParams["ijan"] = $data["ijan"];
  $updParams["cucd"] = $header["cucd"];
  $updParams["cuscd"] = $header["cuscd"];
  $updParams["ktktcd"] = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["LGKTKTCD"];
  $updParams["spktcd"] = $header["spktcd"];
  $updParams["adat"] = $header["adat"];
  $updParams["tpno"] = $oparam["tpno"];
  $updParams["gdcst"] = $stringUtil->toNumber($data["gdcst"]);
  $updParams["slcd"] = $oparam["spslcd"];
  $updParams["chgcd"] = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["CHGCD"];
  $updParams["dcubcd"] = $header["dcubcd"];
  $updParams["bbno"] = $header["bbno"];
  $updParams["dnflg"] = $oparam["dnflg"];
  $updParams["ntcst"] = $stringUtil->toNumber($oparam["ntcst"]);

  $updParams["cuslip"] = $header["cuslip"];
  $updParams["dtxt1"] = $header["dtxt1"];
  $updParams["dtxt2"] = $header["dtxt2"];
  $updParams["ltxt1"] = $header["ltxt1"];
  $updParams["ltxt2"] = $header["ltxt2"];
  $updParams["txt1"] = $footer["txt1"];

  $sql = file_get_contents("./sql/insertNiugoki.sql");
  $logger->info($sql, $updParams);
  $result = $dbutil->insert($sql, $updParams);

  return $reuslt;
}

/*下敷きなしの受注データ作成*/
function insertAfr3123Niugoki($header, $data, $footer, $oparam, $dbutil, $logger, $vlin) {
$logger->info("insertAfr3123Niugoki");
  global $stringUtil;
  $valutil = new getValueUtil();

  $updParams = array();

  $updParams["iseq"] = $oparam["iseq"];
  $updParams["cvseq"] = $oparam["cvseq"];
  $updParams["cuiseq"] = $oparam["cuiseq"];
  $updParams["vlin"] = $vlin;
  $updParams["lcnt"] = $oparam["lcnt"];
  $updParams["cuslip1"] = "02";
  $updParams["cuslip2"] = "";  //手入力任意
  $updParams["cucd"] = $header["cucd"];
  $updParams["cuscd"] = $header["cuscd"];
  $updParams["ncst"] = $stringUtil->toNumber($oparam["ncst"]);
  $updParams["ntcst"] = $stringUtil->toNumber($oparam["ntcst"]);
  $updParams["sal"] =  $stringUtil->toNumber($data["sal"]);
  $updParams["gdcst"] = $stringUtil->toNumber($data["gdcst"]);
  $updParams["gdflg"] = "1";  //1固定
  $updParams["ydat"] = $header["dat2"];
  $updParams["climit"] = $header["dat2"];
  $updParams["mvpno"] = $stringUtil->toNumber($data["tpno"]);
  $updParams["sts"] = "1";
  $updParams["cshpcd"] = "";  //センターコードがないから未指定
  $updParams["jan"] = $data["jan"];
  $updParams["ijan"] = $data["ijan"];
  $updParams["spktcd"] = $header["spktcd"];
  $updParams["ktktcd"] = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["LGKTKTCD"];
  $updParams["chgcd"] = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["CHGCD"];
  $updParams["com"] = ""; //受注備考
  $updParams["jmcat"] = "1";
  $updParams["pkbn1"] = "0";
  $updParams["pkbn2"] = "0";
  $sql = file_get_contents("./sql/insert3123.sql");
  $logger->info($sql, $updParams);
  $result = $dbutil->insert($sql, $updParams);

  return $reuslt;
}
/*受注更新：荷動きデータ作成*/
function updateAfr3123Niugoki($header, $data, $footer, $oparam, $dbutil, $logger, $vlin) {
$logger->info("updateAfr3123Niugoki");
  global $stringUtil;
  $valutil = new getValueUtil();

  $updParams = array();

  $updParams["kbat"] = $oparam["kbat"];
  $updParams["ddat"] = "";
  $updParams["iseq3123"] = $oparam["piseq"];   //受注データのiseq
  $updParams["syflg"] = $oparam["syflg"];
  $updParams["sdday"] = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["SDDAY"];
  $sql = file_get_contents("./sql/update3123.sql");
  $logger->info($sql, $updParams);
  $result = $dbutil->insert($sql, $updParams);

  return $reuslt;
}
function insertAfs73($dbutil, $start_idat, $msg, $tcls) {
  global $stringUtil;

  $valueData = array();
  $valueData["wsid"] = 'AP'.$_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["LGKTKTCD"];
  $valueData["prgid"] = 'AF222X';
  $valueData["start_idat"] = $start_idat;
  if ($tcls == "01") {
    $valueData["title"] = '売上入力';
  } else if ($tcls == "03") {
    $valueData["title"] = '値引入力';
  } else {
    $valueData["title"] = '';
  }
  $valueData["inf2"] = $msg;

  $sql = file_get_contents("./sql/insertAfs73.sql");
  $result = $dbutil->insert($sql, $valueData);
  $dbutil->commit();
}

?>
