<script>

  function chkBefore() { {*PDF出力前チェック*}
    var errflg = false;
    var frmh = $("#headerTop");
    var frm = $(this).closest(".contents").find(".header");
    common.clearFormError(frm);
    var  wprompt;

    {*入力チェック*}
    {*
    if(stringUtil.isEmpty(frmh.find(".ktktcd").val()) ) {
      errflg = true;
      common.addError(frmh.find(".ktktcd"),"入力して下さい。" , null, true);
    }
    *}
    if(stringUtil.isEmpty(frmh.find(".tmon").val()) ) {
      errflg = true;
    }
      
    return errflg;
    
  }

  function do_PDF() {
    let errflg = false;
    var frmh = $("#headerTop");
    common.clearFormError(frmh);
    
    var tmon = common.getValue(frmh.find(".tmon"));
    var ktktcd = common.getValue(frmh.find(".ktktcd"));
    
    if(frmh.find(".chkZero").prop("checked")){
      var cls = "1";
    }else{
      var cls = "0";  
    }

    if (tmon == "") {
      alert("決算棚卸実績がありません。");
      return false;
    
    }
    
    if (chkBefore()) {
      alert('エラーがあります');
      return false;
    } else {
      if(window.confirm("【棚卸集計表】を出力します。よろしいですか？")) {
        
        
        let param2 = { "method": "GetWseqMjan" };
        let irep = "AF4A4X";
    
        $.ajax({
          type: "GET",
          url: "../../api/getWseq.php",
          data: param2,
          dataType: "json",
          scriptCharset: 'utf-8',
          success: function(data, status, xhr) {
            var wurl = "{$_REPORT_URL}" + "AF999I?WSEQ="+ JSON.parse(data.data)
                    + "&IREP=" + irep
                    + "&CHGCD=" + "{$_SYSTEM_NAME_EN_CHGCD}"
                    + "&KTKTCD=" + "{$_SYSTEM_NAME_EN_LGKTKTCD}"
                    + "&VEND=" + "{$_SYSTEM_NAME_EN_VEND}"
                    + "&ACCD=" + "{$_SYSTEM_NAME_EN_ACCD}"
                    + "&DBNO=" + "{$_SYSTEM_NO}"
                    + "&JOKEN1=" + ktktcd
                    + "&JOKEN2=" + tmon
                    + "&JOKEN3=" + cls
                    + '&PDF=1';
            window.open(wurl, irep+JSON.parse(data.data));
          }
        });

      }
    }
  }

  function do_CSV() {
    let errflg = false;
    var frmh = $("#headerTop");
    common.clearFormError(frmh);
    
    var tmon = common.getValue(frmh.find(".tmon"));
    var ktktcd = common.getValue(frmh.find(".ktktcd"));
    
    if(frmh.find(".chkZero").prop("checked")){
      var cls = "1";
    }else{
      var cls = "0";  
    }
    
    if (tmon == "") {
      alert("決算棚卸実績がありません。");
      return false;
    
    }
    
    if (chkBefore()) {
      alert('エラーがあります');
      return false;
    } else {
      if(window.confirm("【棚卸集計表】を出力します。よろしいですか？")) {
        
        
        let param2 = { "method": "GetWseqMjan" };
        let irep = "AF4A4C";
    
        $.ajax({
          type: "GET",
          url: "../../api/getWseq.php",
          data: param2,
          dataType: "json",
          scriptCharset: 'utf-8',
          success: function(data, status, xhr) {
            var wurl = "{$_REPORT_URL}" + "AF999C?WSEQ="+ JSON.parse(data.data)
                    + "&CSVID=" + irep
                    + "&CHGCD=" + "{$_SYSTEM_NAME_EN_CHGCD}"
                    + "&KTKTCD=" + "{$_SYSTEM_NAME_EN_LGKTKTCD}"
                    + "&VEND=" + "{$_SYSTEM_NAME_EN_VEND}"
                    + "&ACCD=" + "{$_SYSTEM_NAME_EN_ACCD}"
                    + "&DBNO=" + "{$_SYSTEM_NO}"
                    + "&JOKEN1=" + ktktcd
                    + "&JOKEN2=" + tmon
                    + "&JOKEN3=" + cls
                    + '&PDF=0';
            window.open(wurl, irep+JSON.parse(data.data));
          }
        });

      }
    }
  }

  $(document).ready(function(){
    /* 明細 高さ 自動設定
    //===================================================================*/

    /* イベント
    //===================================================================*/
    //　F1
    $(document).on("click", ".Func1:not('.noevent')", function(e) {
    });
    //　F2
    $(document).on("click", ".Func2:not('.noevent')", function(e) {
    });
    //　F3
    $(document).on("click", ".Func3:not('.noevent')", function(e) {
    });
    //　F4
    $(document).on("click", ".Func4:not('.noevent')", function(e) {
    });
    //　F5
    $(document).on("click", ".Func5:not('.noevent')", function(e) {
    });
    //　F6
    $(document).on("click", ".Func6:not('.noevent')", function(e) {
    });
    //　F7
    $(document).on("click", ".Func7:not('.noevent')", function(e) {
    });
    //　F8
    $(document).on("click", ".Func8:not('.noevent')", function(e) {
    });
    //　F9 PDF
    $(document).on("click", ".Func9:not('.noevent')", function(e) {
      do_PDF();
    });
    //　F10
    $(document).on("click", ".Func10:not('.noevent')", function(e) {
      do_CSV();
    });
    //　F11
    $(document).on("click", ".Func11:not('.noevent')", function(e) {
    });
    //　F12 メニュー/戻る
    $(document).on("click", ".Func12:not('.noevent')", function(e) {
      $('.btn-close').trigger('click');
    });

    //画面初期表示時動作
    $("#headerTop").find(".hdat").focus();

    //MENUボタン===============================
    $(document).on("focus", ".header .dummy", function(e) {
      $("#topmenu").find(".Func10").focus();
    });

    $("#headerTop").find(".keycd").focus();
    

    //====明細行動作======

  });

</script>
