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

$logger = new logger(basename(__FILE__));
$logger->info("===af222x_index_start===");
$logger->info('post', $_POST);

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

//POPUP
$assign_var["hasPopJan"] = "1"; //afm02
$assign_var["hasPopCucd"] = "1"; //afm03
$assign_var["hasPopCuscd"] = "1"; //afm032
$assign_var["hasPopKtktcd"] = "1"; //afm05
$assign_var["hasPopAf222x1"] = "1";  //伝票検索
$assign_var["hasPopAf203x2"] = "1";  //受注伝票検索

$header = Array(
  "newmode" => "NEW",
  "under_mode" => "0",  //1:下敷き axm994.r01
  "issue_mode" => "0",  //1:出庫する axm994.r02
);
$valutil = new getValueUtil();

//売上、値引をパラメータで区別する
//param1 : tcls : 01=売上入力 or 03=値引入力
if($_GET != null) {
  $header["param1"] = $_GET["param1"];
}

//入力チェック画面から開かれる
if($_POST != null) {
  $header["pmode"] = "1";
  foreach($_POST as $key => $val) {
    $header[$key] = $val;
  }
  //起動引数
  //param1 : tcls : 01=売上入力 or 03=値引入力
  //以下照会画面より
  //p_cucd, p_cuscd, p_vseq, p_viseq, p_tcls
  $header["cucd"] = $_POST["p_cucd"];
  $header["cuscd"] = $_POST["p_cuscd"];
  $header["vseq"] = $_POST["p_vseq"];
  $header["viseq"] = $_POST["p_viseq"];
  $header["tcls"] = $_POST["p_tcls"];
  $ret03 = $valutil->allMastData("0",'afm03',$header["cucd"]);
  $ret032 = $valutil->allMastData("0",'afm032',$header["cuscd"],$header["cucd"]);
  $header["cunm"] = $ret03["cunm"];
  $header["spnm"] = $ret032["spnm"];

} else {
  $header["tcls"] = $header["param1"];  //tclsをセット
  $header["pmode"] = "0";
}

//タイトル変更
if($header["tcls"] == '01') {  //売上
  $header["title"] = "売上入力";
} else if($header["tcls"] == '03') {
  $header["title"] = "値引入力";
}

try {
  //総額得意先の単価入力 CUTAXCLS
  $ret994x = $valutil->getAxm994("CUTAXCLS");
  if ($ret994x == null) {
    $header["cutaxcls"] = "0";
  } else {
    if ($stringUtil->isEmpty($ret994x["r01"])) {
      $header["cutaxcls"] = "0";
    } else {
      $header["cutaxcls"] = $ret994x["r01"];
    }
  }
  //受注下敷き、出庫有無、店舗任意可/不可
  $ret994x1 = $valutil->getAxm994("AF222X");
  if ($ret994x1 == null) {
    $header["under_mode"] = "0";
    $header["issue_mode"] = "0";
  } else {
    if ($stringUtil->isEmpty($ret994x1["r01"])) { //下敷き
      $header["under_mode"] = "0";
    } else {
      $header["under_mode"] = $ret994x1["r01"];
    }
    if ($stringUtil->isEmpty($ret994x1["r02"])) { //出庫
      $header["issue_mode"] = "0";
    } else {
      $header["issue_mode"] = $ret994x1["r02"];
    }
  }

} catch(userException $ue) {
  $assign_var["hasError"] = true;
  $assign_var["errorMsg"] = $ue->getMessage();
} catch(Exception $e) {
  $assign_var["hasError"] = true;
  $assign_var["errorMsg"] = $e->getMessage();
}

$assign_var["header"] = $header;
$logger->info("header", $header);

// 初期表示
$dataList = Array(
);
$obj = [];
array_push($dataList, $obj);

$logger->info("dataList", $dataList);
$assign_var["dataList"] = $dataList;

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

$logger->info("=== af222x_index_end ===");
?>
