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

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

/*
  重複チェック
*/
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) {
    if($detail["cshcd"] != $detail["orgcshcd"]
    ) { //ユニークキーに変更があるものだけ
      $whereParams = array();
      $whereParams["cucd"]=$detail["cucd"];
      $whereParams["cshcd"]=$detail["cshcd"];

      $sql = file_get_contents("./sql/chkAfm036.sql");
      
      $ret_cnt = $dbutil->select($sql, $whereParams);
  
      if($ret_cnt[0]["cnt"] != '0') {
        $ret = '-1';
        $duplicshpcd=$detail["cshcd"];
        $pgno = $detail["pgno"];
        break;
      }
    }
  }

  $ret_array["ret"] = $ret;
  $ret_array["duplicshcd"] = $duplicshcd;
  $ret_array["pgno"] = $pgno;

  return $ret_array;
}


?>
