<?php
//共通
require_once '../base/common.php';
require_once '../util/getPopupUtil.php';
$logger = new logger(basename(__FILE__));
$logger->info("===getPopupSearch_Start===");

$response["status"] = "NG";

try {
  global $dbutil;

  $requestBody = file_get_contents('php://input');
  $data = json_decode($requestBody, true);
  $logger->info("data", $data );

  if ($data["popmode"] == 'afm02x') {
    $result = getPopupAfm02x($data);
  } else if ($data["popmode"] == 'afm02x1') {
    $result = getPopupAfm02x1($data);
  } else if ($data["popmode"] == 'afm03x') {
    $result = getPopupAfm03x($data);
  } else if ($data["popmode"] == 'afm03x1') {
    $result = getPopupAfm03x1($data);
  } else if ($data["popmode"] == 'afm032x') {
    $result = getPopupAfm032x($data);
  } else if ($data["popmode"] == 'afm032x1') {
    $result = getPopupAfm032x1($data);
  }  else if ($data["popmode"] == 'afm036x') {
    $result = getPopupAfm036x($data);
  } else if ($data["popmode"] == 'afm04x') {
    $result = getPopupAfm04x($data);
  } else if ($data["popmode"] == 'afm05x') {
    $result = getPopupAfm05x($data);
  } else if ($data["popmode"] == 'afm08x') {
    $result = getPopupAfm08x($data);
  } else if ($data["popmode"] == 'afm03cx') {
    $result = getPopupAfm03cx($data);
  } else if ($data["popmode"] == 'afm90x') {
    $result = getPopupAfm90x($data);

  //固有画面
  } else if ($data["popmode"] == 'af203x1') { //受注入力 複写店舗選択
    $result = getPopupAf203x1($data);
  } else if ($data["popmode"] == 'af203x2') { //受注入力 伝票検索
    $result = getPopupAf203x2($data);
  } else if ($data["popmode"] == 'af212x1') { //発注番号検索
    $result = getPopupAf212x1($data);
  } else if ($data["popmode"] == 'af215x1') { //直送発注入力 複写店舗選択
    $result = getPopupAf215x1($data);
  } else if ($data["popmode"] == 'af222x1') { //売上・値引伝票検索
    $result = getPopupAf222x1($data);
  } else if ($data["popmode"] == 'af233x1') { //仕入・
    $result = getPopupAf233x1($data);
  } else if ($data["popmode"] == 'af241x1') { //得意先返品
    $result = getPopupAf241x1($data);
  } else if ($data["popmode"] == 'af244x1') { //仕入先返品
    $result = getPopupAf244x1($data);
  } else if ($data["popmode"] == 'af251x1') { //転送出庫指示 伝票検索
    $result = getPopupAf251x1($data);
  } else if ($data["popmode"] == 'af254x1') { //転送入庫 伝票検索
    $result = getPopupAf254x1($data);
  } else if ($data["popmode"] == 'af265x1') { //入金入力 伝票検索
    $result = getPopupAf265x1($data);
  } else if ($data["popmode"] == 'af271x1') { //支払入力 伝票検索
    $result = getPopupAf271x1($data);
  }

  //$logger->info("popSearchResult",$result);

  if ($result[0]['ret'] == '0') {
    $response["status"] = "OK";
    $response["data"]   = json_encode($result,true);
  } elseif ($result[0]['ret'] == '-1') {
    $retData["msg"]     = $dbutil->getNoDataMsg();
    $response["data"]   = $retData;
  } elseif ($result[0]['ret'] == '-2') {
    $retData["code"]    = $result[0]['code'];
    $retData["msg"]     = $result[0]['msg'];
    $response["data"]   = $retData;
  }

} catch(userException $ue) {
  $retData["code"]  = $ue->getErrorCode();
  $retData["msg"]   = $ue->getErrorMessage();

  $response["status"] = "NG";
  $response["data"]   = $retData;

  $dbutil->rollback();
} catch(Exception $e) {
  $response["status"] = "NG";
  $response["data"]   = $e->getMessage();

  $dbutil->rollback();

} finally {
  print(json_encode($response));
}


$logger->info("=== end ===", $response);


?>
