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

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

/*
  重複チェック
*/
function chkRegBefore($dbutil, $data){
$logger = new logger(basename(__FILE__));
  global $stringUtil;
$logger->info("chkRegBefore>>",$data);
  $ret_array = array(
    "ret" => "0", //0:OK, -1:マスタと重複
  );
  $ret = '0';

  $valutil = new getValueUtil();

  $header = $data["header"][0];
  $dataList = $data["data"];

  foreach($dataList as $detail) {
    $whereParams = array();
      
    $whereParams["cucd"]=$header["cucd"];
    $whereParams["cugdcd"]=$detail["cugdcd"];
    $whereParams["medcd"]=$detail["medcd"];
    $whereParams["cugdde"]=$detail["cugdde"];

    $sql = file_get_contents("./sql/chkAfm031.sql");
    
    $ret_cnt = $dbutil->select($sql, $whereParams);

    if($ret_cnt[0]["cnt"] != '0') {
      $ret = '-1';
      $dupliCugdcd=$detail["cugdcd"];
      $dupliMedcd=$detail["medcd"];
      $dupliCugdde=$detail["cugdde"];
      $orgCugdcd=$detail["orgCugdcd"];
      $orgMedcd=$detail["orgMedcd"];
      $orgCugdde=$detail["orgCugdde"];
      break;
    }
  }

  $ret_array["ret"] = $ret;
  $ret_array["dupliCugdcd"] = $dupliCugdcd;
  $ret_array["dupliMedcd"] = $dupliMedcd;
  $ret_array["dupliCugdde"] = $dupliCugdde;
  $ret_array["orgCugdcd"] = $orgCugdcd;
  $ret_array["orgMedcd"] = $orgMedcd;
  $ret_array["orgCugdde"] = $orgCugdde;

  return $ret_array;
}

?>
