
package com.jasamedika.medifirst2000.controller;

import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.orm.jpa.JpaSystemException;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

import com.jasamedika.medifirst2000.constants.Constants;
import com.jasamedika.medifirst2000.constants.MessageResource;
import com.jasamedika.medifirst2000.controller.base.LocaleController;
import com.jasamedika.medifirst2000.core.web.WebConstants;
import com.jasamedika.medifirst2000.entities.KartuPengendaliDetail;
import com.jasamedika.medifirst2000.exception.ServiceVOException;
import com.jasamedika.medifirst2000.service.BaseAnggaranService;
import com.jasamedika.medifirst2000.service.DetailAnggaranService;
import com.jasamedika.medifirst2000.service.KartuPengendaliService;
import com.jasamedika.medifirst2000.util.rest.RestUtil;
import com.jasamedika.medifirst2000.vo.DetailAnggaranVO;
import com.jasamedika.medifirst2000.vo.KartuPengendaliCustomVO;
import com.jasamedika.medifirst2000.vo.KartuPengendaliDetailVO;
import com.jasamedika.medifirst2000.vo.PenawaranHargaVO;
import com.jasamedika.medifirst2000.vo.RegistrasiPelayananVO;
import com.jasamedika.medifirst2000.vo.RekapPemenangUlpVO;
import com.jasamedika.medifirst2000.vo.UpdateJadwalVO;
import com.jasamedika.medifirst2000.vo.UploadVO;
import com.jasamedika.medifirst2000.vo.UploadExcelVO;
import com.jasamedika.medifirst2000.vo.VerifikasiKartuPengendaliDetailVO;
import com.jasamedika.medifirst2000.vo.VerifikasiKartuPengendaliHeaderVO;

@RestController
@RequestMapping("/kartu-pengendali")
public class KartuPengendaliController extends LocaleController<RegistrasiPelayananVO> {

	@Autowired
	private KartuPengendaliService service;
	
	@Autowired
	private DetailAnggaranService  detailAnggaranService;
	
	private static final Logger LOGGER = LoggerFactory.getLogger(KartuPengendaliController.class);

	// save kartu Pengendali
	@RequestMapping(value = "/save-kartu-pengendali", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> saveKartuPengendali(@Valid @RequestBody KartuPengendaliCustomVO vo,
			HttpServletRequest request) {
		try {
			Map<String, Object> result = service.saveKartuPengendali(vo);
			if (null != result)
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
						getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);

		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when saveKartuPengendali", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when saveKartuPengendali", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}

	}

	// Kartu Pengendai Paging
	// Jika ANggaran maka kelompok User/isPpk null
	// Jika Ppk Maka kelompok User / is Ppk=true
	// Jika Ulp Maka is Ulp = true
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/kartu-pengendali-list")
	@ResponseBody
	public Map<String, Object> multipleCondition(
			@RequestParam(value = "page", required = false, defaultValue = "0") Integer page,
			@RequestParam(value = "take", required = false, defaultValue = "100") Integer limit,
			@RequestParam(value = "sort", required = false, defaultValue = "id") String sort,
			@RequestParam(value = "dir", required = false, defaultValue = "asc") String dir,
			@RequestParam(value = "dateStart", required = false) String dateStart,
			@RequestParam(value = "dateEnd", required = false) String dateEnd,
			@RequestParam(value = "pengendaliId", required = false) Integer pengendaliId,
			@RequestParam(value = "kelompokUser", required = false) Boolean isPpk,
			@RequestParam(value = "isUlp", required = false) Boolean isUlp,
			@RequestParam(value = "isPp", required = false) Boolean isPp) {

		Map<String, Object> resultPageMap = service.kartuPengenDaliPAging(page, limit, sort, dir, dateStart, dateEnd,
				pengendaliId, isPpk, isUlp,isPp);

		return resultPageMap;
	}

	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/kartu-pengendali-header-list")
	@ResponseBody
	public Map<String, Object> kartuPengendaliHeader(
			@RequestParam(value = "page", required = false, defaultValue = "0") Integer page,
			@RequestParam(value = "take", required = false, defaultValue = "100") Integer limit,
			@RequestParam(value = "sort", required = false, defaultValue = "id") String sort,
			@RequestParam(value = "dir", required = false, defaultValue = "asc") String dir,
			@RequestParam(value = "dateStart", required = false) String dateStart,
			@RequestParam(value = "dateEnd", required = false) String dateEnd,
			@RequestParam(value = "pengendaliId", required = false) Integer pengendaliId,
			@RequestParam(value = "isPpk", required = false) Boolean isPpk,
			@RequestParam(value = "isUlp", required = false) Boolean isUlp,
			@RequestParam(value = "isPp", required = false) Boolean isPp,
			@RequestParam(value = "isAnggaran", required = false) Boolean isAnggaran,
			@RequestParam(value = "isPengendali", required = false) Boolean isPengendali,
			@RequestParam(value = "isDirekturTerkait", required = false) Boolean isDirekturTerkait) {

		Map<String, Object> resultPageMap = service.kartuPengenDaliPagingHeader(page, limit, sort, dir, dateStart,
				dateEnd, pengendaliId, isPpk, isUlp,isPp, isAnggaran, isPengendali, isDirekturTerkait);

		return resultPageMap;
	}


	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/pre-add-penerimaan")
	@ResponseBody
	public Map<String, Object> preAddPenerimaan(
			@RequestParam(value = "page", required = false, defaultValue = "0") Integer page,
			@RequestParam(value = "take", required = false, defaultValue = "100") Integer limit,
			@RequestParam(value = "sort", required = false, defaultValue = "id") String sort,
			@RequestParam(value = "dir", required = false, defaultValue = "asc") String dir,
			@RequestParam(value = "dateStart", required = false) String dateStart,
			@RequestParam(value = "dateEnd", required = false) String dateEnd,
			@RequestParam(value = "supplierId", required = false) Integer supplierId) {

		Map<String, Object> resultPageMap = service.preAddPenerimaan(page, limit, sort, dir, dateStart,dateEnd, supplierId);

		return resultPageMap;
	}

	
	// Generate Template Excel
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/generate-template-exel")
	@ResponseBody
	public Map<String, Object> generateTemplateExcel(@RequestParam(value = "noRec", required = false) String noRec,HttpServletResponse response) throws IOException {

		String fileName = service.generateTemplateExcel(noRec);

		String fileType = "application/vnd.ms-excel";
		// Find this file id in database to get file name, and file type

		// You must tell the browser the file type you are going to send
		// for example application/pdf, text/plain, text/html, image/jpg
		response.setContentType(fileType);

		// Make sure to show the download dialog
		response.setHeader("Content-disposition", "attachment; filename="+fileName);

		// Assume file name is retrieved from database
		// For example D:\\file\\test.pdf

		File my_file = new File(fileName);

		// This should send the file to browser
		OutputStream out = response.getOutputStream();
		FileInputStream in = new FileInputStream(my_file);
		byte[] buffer = new byte[4096];
		int length;
		while ((length = in.read(buffer)) > 0) {
			out.write(buffer, 0, length);
		}
		in.close();
		out.flush();

		return null;
	}

	// verifikasi PPK
	@RequestMapping(value = "/save-verifikasi-spek-anggaran", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> saveVerifikasiKartuPengendaliDetail(
			@Valid @RequestBody VerifikasiKartuPengendaliDetailVO vo, HttpServletRequest request) {
		try {
			Map<String, Object> result = service.verifikasiPpk(vo);
			if (null != result)
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
						getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);

		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when Kartu Pengendali Detail", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when Kartu Pengendali Detail", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}
	}
	
	// Rekap Pemenang from Ppk
	@RequestMapping(value = "/rekap-pemenang", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> rekapPemenang(
			@Valid @RequestBody VerifikasiKartuPengendaliDetailVO vo, HttpServletRequest request) {
		try {
			Map<String, Object> result = service.rekapPemenang(vo);
			if (null != result)
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
						getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);

		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when Kartu Pengendali Detail", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when Kartu Pengendali Detail", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}
	}
	
	// Rekap Pemenang from Ulp
	@RequestMapping(value = "/rekap-pemenang-from-ulp", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> rekapPemenangFromUlp(@Valid @RequestBody RekapPemenangUlpVO vo, HttpServletRequest request) {
		try {
			Map<String, Object> result = service.rekapPemenangFromUlp(vo);
			if (null != result)
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);

		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when Kartu Pengendali Detail", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when Kartu Pengendali Detail", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}
	}

	// Verifikasi by Anggaran By etail
	@RequestMapping(value = "/verifikasi-kartu-pengendali-by-anggaran", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> verifikasiKartuPengendaliByAnggaran(
			@Valid @RequestBody VerifikasiKartuPengendaliDetailVO vo, HttpServletRequest request) {
		try {
			Map<String, Object> result = service.verifikasiKartuPengendaliDetailByAnggaran(vo);
			if (null != result)
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
						getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);

		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when saveKartuPengendali", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when saveKartuPengendali", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}

	}

	// Verifikasi by Anggaran By Header
	@RequestMapping(value = "/verifikasi-kartu-pengendali-by-header", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> verifikasiKartuPengendaliHeadByAnggaran(
			@Valid @RequestBody VerifikasiKartuPengendaliHeaderVO vo, HttpServletRequest request) {
		try {
			Map<String, Object> result = service.verifikasiAnggaran(vo);
			if (null != result)
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
						getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);

		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when Verif Kartu Pengendali", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when Verif Kartu Pengendali", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}

	}

	// Verifikasi by Direktur By Header
	@RequestMapping(value = "/verifikasi-kartu-pengendali-by-direktur", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> verifikasiKartuPengendaliByDirektur(
			@Valid @RequestBody VerifikasiKartuPengendaliHeaderVO vo, HttpServletRequest request) {
		try {
			Map<String, Object> result = service.verfikasiDirekturTerkait(vo);
			if (null != result)
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
						getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);

		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when Verif Kartu Pengendali", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when Verif Kartu Pengendali", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}

	}
	
	// Verifikasi by pp
	@RequestMapping(value = "/verifikasi-kartu-pengendali-by-pp", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> verifikasiKartuPengendaliByPp(
			@Valid @RequestBody VerifikasiKartuPengendaliHeaderVO vo, HttpServletRequest request) {
		try {
			Map<String, Object> result = service.verfikasiPp(vo);
			if (null != result)
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
						getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);

		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when Verif Kartu Pengendali", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when Verif Kartu Pengendali", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}

	}
	
	// Verifikasi by pp
	@RequestMapping(value = "/verifikasi-kartu-pengendali-by-ulp", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> verifikasiKartuPengendaliByUlp(
			@Valid @RequestBody VerifikasiKartuPengendaliHeaderVO vo, HttpServletRequest request) {
		try {
			Map<String, Object> result = service.verfikasiULP(vo);
			if (null != result)
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
						getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);

		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when Verif Kartu Pengendali", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when Verif Kartu Pengendali", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}

	}
	
	// Update Jadwal
	@RequestMapping(value = "/update-jadwal", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> updateJadwal(@Valid @RequestBody UpdateJadwalVO vo, HttpServletRequest request) {
		try {
			Map<String, Object> result = service.updateJadwal(vo);
			if (null != result)
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,
						getMessage(MessageResource.LABEL_SUCCESS, request));
			return RestUtil.getJsonResponse(result, HttpStatus.CREATED, mapHeaderMessage);

		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when update jadwal", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR, mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when update jadwal", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
		}

	}

	// Menampilkan Kartu Pengendali Berdasarkan Norec (array)
	@RequestMapping(value = "/get-detail-kartu-pengendali-list/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public List<Map<String, Object>> kartuPengendliDetailList(
			@RequestParam(value = "noRec", required = true) String noRec) {
		List<Map<String, Object>> kartuPengendliDetailList = service.kartuPengendliDetailList(noRec);

		return kartuPengendliDetailList;
	}

	@RequestMapping(value = "/get-kartu-pengendali-header-by-norec/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public Map<String, Object> getKartuPengendaliHeaderByNoRec(
			@RequestParam(value = "noRec", required = true) String noRec) {
		Map<String, Object> kartuPengendliDetailList = service.getKartuPengendaliHeaderByNoRec(noRec);
		return kartuPengendliDetailList;
	}
	
	@RequestMapping(value = "/pre-rekap-pemenang/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public Map<String, Object> preRekapPemenang(
			@RequestParam(value = "noRec", required = true) String noRec) {
		Map<String, Object> kartuPengendliDetailList = service.preRekapPemenang(noRec);
		return kartuPengendliDetailList;
	}
	
	
	//getStrukRekap
	@RequestMapping(value = "/get-get-struk-rekap", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public Map<String, Object> getStrukRekap(
			@RequestParam(value = "noRec", required = true) String noRec) {
		Map<String, Object> strukRekap = service.getStrukRekap(noRec);
		return strukRekap;
	}
	
	@RequestMapping(value = "/pre-add-jadwal", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public Map<String, Object> preAddJadwal(
			@RequestParam(value = "noRec", required = true) String noRec) {
		Map<String, Object> data = service.getPreAddJadwal(noRec);
		return data;
	}

	// Menampilkan Kartu Pengendali Berdasarkan Norec (array)
	@RequestMapping(value = "/get-metode-pengadaan-detail", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public Map<String, Object> getMetodePengadaanDetail(
			@RequestParam(value = "id", required = true) Integer id) {
		Map<String, Object> kartuPengendliDetailList = service.metodePengadaanDetail(id);

		return kartuPengendliDetailList;
	}
	
	@RequestMapping(value = "/upload-exel/", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String,Object>> upload(@Valid @RequestBody UploadExcelVO vo,HttpServletRequest request) throws IOException {
		try {
			Map<String,Object> result =  service.uploadExel(vo) ;

			if (null != result)				
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,getMessage(MessageResource.LABEL_SUCCESS,request ));
				return RestUtil.getJsonResponse(result, HttpStatus.CREATED,mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when add Agama", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE,
					e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR,
					mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when add Agama", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE,
					jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT,
					mapHeaderMessage);
		}
		
	}

	
	@RequestMapping(value = "/save-penawaran-harga-supplier/", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes = MediaType.APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String,Object>> savePenawaranHargaSupplier(@Valid @RequestBody PenawaranHargaVO vo,HttpServletRequest request) throws IOException {
		try {
			Map<String,Object> result =  service.savePenawaranHargaSupplier(vo);
			if (null != result)				
				mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,getMessage(MessageResource.LABEL_SUCCESS,request ));
				return RestUtil.getJsonResponse(result, HttpStatus.CREATED,mapHeaderMessage);
		} catch (ServiceVOException e) {
			LOGGER.error("Got exception {} when add Penawaran Harga", e.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE,e.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR,mapHeaderMessage);
		} catch (JpaSystemException jse) {
			LOGGER.error("Got exception {} when add Penawaran Harga", jse.getMessage());
			addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE,jse.getMessage());
			return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT,mapHeaderMessage);
		}
		
	}
	
	@SuppressWarnings("unchecked")
	@RequestMapping(value = "/list-kontrak-grid")
	@ResponseBody
	public Map<String, Object> listKontrakGrid(
			@RequestParam(value = "page", required = false, defaultValue = "0") Integer page,
			@RequestParam(value = "take", required = false, defaultValue = "100") Integer limit,
			@RequestParam(value = "sort", required = false, defaultValue = "id") String sort,
			@RequestParam(value = "dir", required = false, defaultValue = "asc") String dir,
			@RequestParam(value = "dateStart", required = false) String dateStart,
			@RequestParam(value = "dateEnd", required = false) String dateEnd,
			@RequestParam(value = "supplierId", required = false) Integer supplierId,
			@RequestParam(value = "tahun", required = false) Integer tahun) {

		Map<String, Object> resultPageMap = service.listKontrakGrid(page, limit, sort, dir, dateStart, dateEnd, supplierId, tahun);

		return resultPageMap;
	}
	
	@RequestMapping(value = "/get-kelompok-user/", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
	public Map<String, Object> getKelompokUser() {
		Map<String, Object> result = new HashMap<String, Object>();
		result.put("kelompokUser", detailAnggaranService.getKelompokUserLogin());
		return result;
	}
	

	/*
	 * @RequestMapping(value = "/verifikasi-kartu-pengendali", method =
	 * RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE, consumes
	 * = MediaType.APPLICATION_JSON_VALUE) public ResponseEntity<Map<String,
	 * Object>> verifikasiKartuPengendali(@Valid @RequestBody
	 * KartuPengendaliDetailVO vo, HttpServletRequest request) { try {
	 * Map<String,Object> result = service.verifikasiKartuPengendaliDetail(vo);
	 * if (null != result)
	 * mapHeaderMessage.put(WebConstants.HttpHeaderInfo.LABEL_SUCCESS,getMessage
	 * (MessageResource.LABEL_SUCCESS,request)); return
	 * RestUtil.getJsonResponse(result, HttpStatus.CREATED,mapHeaderMessage);
	 * 
	 * } catch (ServiceVOException e) { LOGGER.error(
	 * "Got exception {} when verifikasi kartu Pengendali", e.getMessage());
	 * addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, e.getMessage());
	 * return RestUtil.getJsonHttptatus(HttpStatus.INTERNAL_SERVER_ERROR,
	 * mapHeaderMessage); } catch (JpaSystemException jse) { LOGGER.error(
	 * "Got exception {} when verifikasi kartu Pengendali", jse.getMessage());
	 * addHeaderMessage(Constants.MessageInfo.ERROR_MESSAGE, jse.getMessage());
	 * return RestUtil.getJsonHttptatus(HttpStatus.CONFLICT, mapHeaderMessage);
	 * }
	 * 
	 * }
	 */

}
