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

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

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

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

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

    $rowcnt = $result[0]["rowcnt"];
    
  } 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["rowcnt"] = $rowcnt;

  return $ret_array;
}

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

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

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

    $rowcnt = $result[0]["rowcnt"];
    
  } 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["rowcnt"] = $rowcnt;

  return $ret_array;
}

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

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

  try {
    $whereParams=array();
    $whereParams["ktktcd"]["in"] = $_SESSION[$GLOBALS['SYSTEM_NAME_EN']]["LGKTKTCD"];
    $whereParams["cucd"]["in"] = $data["cucd"];
    $whereParams["cuscd"]["in"] = $data["cuscd"];
    $whereParams["cuscd2"]["in"] = $data["cuscd2"];
    $whereParams["wret"]["out"] = "";
    $sql = file_get_contents("./sql/callFmAf9032x.sql");
    $logger->info("callFmAf9032x>>".$sql,$whereParams);
    
    $result = $dbutil->call($sql, $whereParams);
    $logger->info("result",$result);

    $wret = $result["wret"];
    
  } 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["wret"] = $wret;

  return $ret_array;
}


?>
