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

$logger = new logger(basename(__FILE__));
$logger->info("===af294x_search_start===");

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

$header = Array();
foreach($_POST as $key => $val) {
  $header[$key] = $val;
}
$logger->info("header",$header);

$valutil = new getValueUtil();

//POPUP
$assign_var["hasPopJan"] = "1";
$assign_var["hasPopKtktcd"] = "1";

$assign_var["hasError"] = false;

try {
  global $dbutil;
  global $stringUtil;

  $assign_var["isNoData"] = false;
  $assign_var["noeventClassHeader"] = "";
  $assign_var["noeventClassBody"]   = "";

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

  $ret_array = array(); //return用
  
  $whereParams=array();
  $whereParams["spktcd"] = $header["spktcd"];
  $whereParams["ijan"] = $header["ijan"];
    
  //良品
  $sql = file_get_contents("./sql/getRyohin.sql");
  $logger->info($sql, $whereParams);
  $result1 = $dbutil->select($sql, $whereParams);
  $logger->info("getRyohin_result",$result1);
  if($result1 != null) {
    $ret_array["orgpno3105"] = $result1[0]["psum"];
    $ret_array["newpno3105"] = $result1[0]["psum"];
  } else {
    $ret_array["orgpno3105"] = '0';
    $ret_array["newpno3105"] = '0';
  }

  //不良品
  $sql = file_get_contents("./sql/getFuryohin.sql");
  $logger->info($sql, $whereParams);
  $result2 = $dbutil->select($sql, $whereParams);
  $logger->info("getFuryohin_result",$result2);
  if($result2 != null) {
      $ret_array["orgpno3109"] = $result2[0]["psum"];
      $ret_array["newpno3109"] = $result2[0]["psum"];
  } else {
    $ret_array["orgpno3109"] = '0';
    $ret_array["newpno3109"] = '0';
  }

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

  $assign_var["hasError"] = true;
  $assign_var["errorMsg"] = $ue->getErrorMessage();

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

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

  $assign_var["hasError"] = true;
  $assign_var["errorMsg"] = $e->getErrorMessage();

  //$dbutil->rollback();

} 

$assign_var["header"] = $header;
$assign_var["data"] = $dataList;
//$assign_var["data"] = json_encode($dataList);
$assign_var["footer"] = $footer;

$logger->info('assign_var',$assign_var);

//Smartyへアサイン
$smarty->assign($assign_var);
$smarty->display("index");

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

?>
