<?php
//共通
require_once '../../base/common.php';

/**
 * af271x共通カスタム関数
 */

/*
  伝票番号入力で表示時、同一伝票番号で複数伝票(複数viseq)がないかチェック
*/
function chkSearchBefore($dbutil, $data){
  $logger = new logger(basename(__FILE__));
    global $stringUtil;
  $logger->info("chkSearchBefore>>",$data);
  $ret_array = array(
    "cuiseq" => "",
    "cnt" => "0",
    "ret" => "0",
    "msg" => "",
  );

  $valutil = new getValueUtil();

  try {

    $whereParams = array();
    $whereParams["ktktcd"] = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["LGKTKTCD"];
    $whereParams["mcd"]  = $data["mcd"];
    $whereParams["vseq"]  = $data["vseq"];
    $sql = file_get_contents("./sql/cntAur32.sql");
    $logger->info($sql, $whereParams);
    $result = $dbutil->select($sql, $whereParams);
    $logger->info("cntAur32_result",$result);
    if($result != null) {
      $ret_array["viseq"] = $result[0]["viseq"];
      $ret_array["cnt"] = $result[0]["cnt"];
    } else {
      $ret_array["cnt"] = "0";
    }

    $ret_array["mode"] = $mode;

  } catch(userException $ue) {
    $retData["code"]  = $ue->getErrorCode();
    $retData["msg"]   = $ue->getErrorMessage();
    $response["status"] = "NG";
    $ret_array["ret"] = '-9';
    $ret_array["msg"] = $ue->getErrorMessage();
  } catch(Exception $e) {
    $response["status"] = "NG";
    $response["data"]   = $e->getMessage();
    $ret_array["ret"] = '-9';
    $ret_array["msg"]   = $e->getMessage();
  }

  return $ret_array;
}

/*
  登録前チェック
*/
function chkRegBefore($dbutil, $data){
  $logger = new logger(basename(__FILE__));
    global $stringUtil;
  $logger->info("chkRegBeforeInfo>>",$data);
  $ret_array = array(
    "ret" => "0",
    "ret1" => "0",
    "ret2" => "0",
    "msg" => "",
  );
  $ret = "0";
  $ret1 = "0";  //計上日
  $ret2 = "0";  //明細
  $ret_meisai = array();  //明細エラーあり

  $valutil = new getValueUtil();

  $header = $data["header"];
  $ktktcd = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["LGKTKTCD"];
  $w_tgcnt = 0;
  try {
    $result = $valutil->chk_adat("3", $ktktcd, "", "", $header["adat"]);
    if ($result != "0") {
      $ret1 = "-1";
      $msg = "仕入日が不正です。";
    }
$logger->info("chk_adat:".$result);

    if ($ret1 != "0" || $ret2 != "0") { //エラー有
      $ret = "-1";
    }

    $ret_array["ret"] = $ret;
    $ret_array["ret1"] = $ret1;
    $ret_array["ret2"] = $ret2;
    $ret_array["msg"] = $msg;
    $ret_array["ret_meisai"] = $ret_meisai;
  } catch(userException $ue) {
    $retData["code"]  = $ue->getErrorCode();
    $retData["msg"]   = $ue->getErrorMessage();
    $response["status"] = "NG";
    $ret_array["ret"] = '-9';
  } catch(Exception $e) {
    $response["status"] = "NG";
    $response["data"]   = $e->getMessage();
    $ret_array["ret"] = '-9';
  }

  return $ret_array;
}



?>
