<?php
$cate_id = "STS_ORDER_PROD";
include_once "{$_SERVER['DOCUMENT_ROOT']}/common.inc.php";
include_once _SVC_INC_PATH_ ."/auth_check.php";
include_once _HOME_INC_PATH_ ."/ajax_init.php";


if( !_notAuth("R") ){/************ 권한체크*/
  switch( $_REQUEST['mode'] ){
    case "getOperationList":
      $sql = "USP_P_OPER_LIST_S10";

      $params = array(
        "USER_ID"        => $GLOBALS['_Umem']['member_id'],
      );

      $rst = $baseObj->DB->exec($sql,$params);

      $rows = array();
      if( $rst ){
        $retval['code'] = true;
        while( $row = $baseObj->DB->fetch_array($rst) ){

          $rows[] = $row;
        }
        $retval['data'] = $rows;
        $retval['mesg'] = "정상적으로 작동하였습니다.";
      }else{
        $retval['code'] = false;
      }
      break;
    // 생산오더별 진행현황
    case 'getStsList':

      $squl = "USP_P_STS_PROCESS_OPER_S10";
      $params = array(
        "WO_NO"   => $_REQUEST["P_WO_NO"] ?: "",
        "OP_CD"   => $_REQUEST["OP_CD"] ?: "",
      );
      $rst = $baseObj->DB->exec($squl, $params);

      $rows = array();
      if ($rst) {
        $retval['code'] = true;
        while ($row = $baseObj->DB->fetch_array($rst)) {
          $rows[] = $row;
        };
        $retval['data'] = $rows;
        $retval['mesg'] = '정상 동작 되었습니다.';
      } else {
        $retval['code'] = false;
      }

      break;
    case 'getComingOper':
      $squl = "USP_P_STS_PROCESS_OPER_S20";

      $params = array(
        "WO_NO"   => $_REQUEST["WO_NO"] ?: "",
        "OP_CD"   => $_REQUEST["OP_CD"] ?: "",
      );

      $rst = $baseObj->DB->exec($squl, $params);

      $rows = array();
      if ($rst) {
        $retval['code'] = true;
        while ($row = $baseObj->DB->fetch_array($rst)) {
          $rows[] = $row;
        };
        $retval['data'] = $rows;
        $retval['mesg'] = '정상 동작 되었습니다.';
      } else {
        $retval['code'] = false;
      }

      break;
    case 'getPreviewList':
      $squl = "USP_P_STS_PROCESS_OPER_S20";

      $params = array(
        "WO_NO"   => $_REQUEST["WO_NO"] ?: "",
        "OP_CD"   => $_REQUEST["OP_CD"] ?: "",
      );

      $rst = $baseObj->DB->exec($squl, $params);

      $rows = array();
      if ($rst) {
        $retval['code'] = true;
        while ($row = $baseObj->DB->fetch_array($rst)) {
          $rows[] = $row;
        };
        $retval['data'] = $rows;
        $retval['mesg'] = '정상 동작 되었습니다.';
      } else {
        $retval['code'] = false;
      }

      break;
    case 'updateSort':
      $_REQUEST["reqdata"] = json_decode($_REQUEST['reqdata'], true);
      $rst = true;
      foreach ($_REQUEST['reqdata'] as $data) {
        $sql = "USP_P_OPER_LIST_U10";
        $data = (array)$data;

        $params = array(
          "MAKE_USER_ID"    => $GLOBALS['_Umem']['member_id'],
          "OP_CD"   => $data["OP_CD"] ?: "",
          "OP_SEQ"   => $data["DISPLAY_SEQ"] ?: "",
          "NO"   => $data["NO"] ?: 0,
        );


        $rst = $baseObj->DB->exec($sql, $params);

      }


      if ($rst) {
        $retval['code'] = true;

      } else {
        $retval['code'] = false;
      }

      break;
    }
  }

  if( !$_REQUEST['no_echo'] ){
    echo json_encode($retval);
  }