<?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["cucd"] != $detail["orgcucd"]
    || $detail["ijan"] != $detail["orgijan"]
    ) { //ユニークキーに変更があるものだけ
      $whereParams = array();

      $whereParams["cucd"]=$detail["cucd"];
      $whereParams["ijan"]=$detail["ijan"];

      $sql = file_get_contents("./sql/chkAfm0311.sql");
      
      $ret_cnt = $dbutil->select($sql, $whereParams);
  
      if($ret_cnt[0]["cnt"] != '0') {
        $ret = '-1';
        $duplicucd=$detail["cucd"];
        $dupliijan=$detail["ijan"];
        $pgno = $detail["pgno"];
        break;
      }
    }
  }

  $ret_array["ret"] = $ret;
  $ret_array["duplicucd"] = $duplicucd;
  $ret_array["dupliijan"] = $dupliijan;
  $ret_array["pgno"] = $pgno;

  return $ret_array;
}

function Checkcutax($dbutil, $data) {
  $logger = new logger(basename(__FILE__));
  //$logger->info("===Checkcutax===");

  $ret_array = Array(
    'ret' => '0',
    'retcutax' => ""
  );
  $ret = '0';
  $retcutax = "NU";

  try {
    $whereParams=array();
    $whereParams["cucd"] = $data["cucd"];
    $sql = file_get_contents("./sql/Checkcutax.sql");
    //$logger->info("checkcutax2>>".$sql,$whereParams);
    
    $result = $dbutil->select($sql, $whereParams);
    //$logger->info("result",$result);

    $retcutax = $result[0]["retcutax"];
    
  } catch(userException $ue) {
    $ret = "-9";
    //$dbutil->rollback();
    $ret_array['msg'] = $ue->getErrorMessage(); //エラー
  } catch(Exception $e) {
    $ret = "-9";
    //$dbutil->rollback();
    $ret_array['msg'] = $ue->getErrorMessage(); //エラー
  }
  
  $ret_array["ret"] = $ret;
  $ret_array["retcutax"] = $retcutax;

  return $ret_array;
}



?>
