package com.jasamedika.medifirst2000.controller;

import com.jasamedika.medifirst2000.constants.MessageResource;
import com.jasamedika.medifirst2000.controller.base.LocaleController;
import com.jasamedika.medifirst2000.dto.*;
import com.jasamedika.medifirst2000.service.LaundryService;
import com.jasamedika.medifirst2000.vo.KirimProdukVO;
import org.slf4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import java.util.Map;

import static com.jasamedika.medifirst2000.core.web.WebConstants.HttpHeaderInfo.LABEL_SUCCESS;
import static com.jasamedika.medifirst2000.util.DateUtil.toDate;
import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonHttpStatus;
import static com.jasamedika.medifirst2000.util.rest.RestUtil.getJsonResponse;
import static org.slf4j.LoggerFactory.getLogger;
import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR;
import static org.springframework.http.HttpStatus.OK;
import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE;
import static org.springframework.web.bind.annotation.RequestMethod.GET;
import static org.springframework.web.bind.annotation.RequestMethod.POST;

@RestController
@RequestMapping("/laundry")
public class LaundryController extends LocaleController<KirimProdukVO> {

	private static final Logger LOGGER = getLogger(LaundryController.class);

	@Autowired
	private LaundryService laundryService;

	@RequestMapping(value = "/get-all-penerimaan-linen", method = GET, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String, Object>>> getAllPenerimaanLinen(
			@RequestParam(value = "startPeriode", required = false) String startPeriode,
			@RequestParam(value = "endPeriode", required = false) String endPeriode, HttpServletRequest request) {
		List<Map<String, Object>> result = laundryService.getAllPenerimaanLinen(toDate(startPeriode),
				toDate(endPeriode));
		if (result != null) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/save-penerimaan-linen", method = POST, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String, Object>>> savePenerimaanLinen(@RequestBody List<PenerimaanLinenDto> dtos,
			HttpServletRequest request) {
		List<Map<String, Object>> result = laundryService.savePenerimaanLinen(dtos);
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/generate-no-struk", method = GET, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> getNoStruk(HttpServletRequest request) {
		Map<String, Object> result = laundryService.getGenerateNoStruk();
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/get-all-satuan", method = GET, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String, Object>>> getAllSatuan(HttpServletRequest request) {
		List<Map<String, Object>> result = laundryService.getAllSatuan();
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/get-all-penerimaan-linen-filter", method = GET, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String, Object>>> getAllPenerimaanLinenFilter(
			@RequestParam(value = "startPeriode", required = false) String startPeriode,
			@RequestParam(value = "endPeriode", required = false) String endPeriode, HttpServletRequest request) {
		String newEndPeriode = changeTimeEndPeriode(endPeriode);
		List<Map<String, Object>> result = laundryService.getAllPenerimaanLinen(toDate(startPeriode),
				toDate(newEndPeriode));
		if (result != null) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	private String changeTimeEndPeriode(String endPeriode) {
		Date newDate = new Date();
		String newEndPeriode;
		if (endPeriode != null) {
			String tgl = endPeriode.split(" ")[0];
			String timeStamp = new SimpleDateFormat("HH:mm:ss").format(newDate);
			newEndPeriode = tgl + " " + timeStamp;
		} else {
			newEndPeriode = null;
		}

		LOGGER.info("TIME END PERIODE : {}", newEndPeriode);

		return newEndPeriode;
	}

	@RequestMapping(value = "/send-penerimaan-to-pencucian", method = POST, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> sendPenerimaanToPencucian(@RequestBody List<PenerimaanLinenDto> dtos,
			HttpServletRequest request) {
		Map<String, Object> result = laundryService.sendPenerimaanToPencucian(dtos);
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/get-bahan-from-mesin-proses", method = GET, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String, Object>>> getBahanMesinProses(
			@RequestParam(value = "mesinId") Integer mesinId,
			@RequestParam(value = "prosesCuciId") Integer prosesCuciId, HttpServletRequest request) {
		List<Map<String, Object>> result = laundryService.getAllBahanFromMesinAndProses(mesinId, prosesCuciId);
		if (result != null) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/save-proses-cuci", method = POST, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String, Object>>> saveProsesCuci(@RequestBody ProsesCuciLinenDto dtos,
			HttpServletRequest request) {
		List<Map<String, Object>> result = laundryService.prosesCuci2(dtos);
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/get-all-pencucian", method = GET, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<List<ProsesCuciLinenDto>> getAllPencucianFilter(
			@RequestParam(value = "startPeriode", required = false) String startPeriode,
			@RequestParam(value = "endPeriode", required = false) String endPeriode, HttpServletRequest request) {
		String newEndPeriode = changeTimeEndPeriode(endPeriode);
		List<ProsesCuciLinenDto> result = laundryService.getAllPencucianLinen(toDate(startPeriode),
				toDate(newEndPeriode));
		if (result != null) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/get-proses-bilas", method = GET, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String, Object>>> getProsesBilas(
			@RequestParam(value = "prosesCuci") String prosesCuci, HttpServletRequest request) {
		List<Map<String, Object>> result = laundryService.getProsesBilas(prosesCuci);
		if (result != null) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/save-pembilasan", method = POST, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String, Object>>> savePembilasan(@RequestBody ProsesCuciLinenDto dtos,
			HttpServletRequest request) {
		List<Map<String, Object>> result = laundryService.prosesBilas(dtos);
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/get-all-pembilasan", method = GET, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<List<ProsesCuciLinenDto>> getAllPembilasanFilter(
			@RequestParam(value = "startPeriode", required = false) String startPeriode,
			@RequestParam(value = "endPeriode", required = false) String endPeriode, HttpServletRequest request) {
		String newEndPeriode = changeTimeEndPeriode(endPeriode);
		List<ProsesCuciLinenDto> result = laundryService.getAllPembilasan(toDate(startPeriode), toDate(newEndPeriode));
		if (result != null) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/save-pengeringan", method = POST, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String, Object>>> savePengeringan(@RequestBody PengeringanDto dtos,
			HttpServletRequest request) {
		List<Map<String, Object>> result = laundryService.prosesPengeringan(dtos);
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/get-produk-pelipatan", method = GET, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String, Object>>> getProdukPelipatanFilter(HttpServletRequest request) {
		List<Map<String, Object>> result = laundryService.getProdukPelipatan();
		if (result != null) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/save-pelipatan", method = POST, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String, Object>>> savePelipatan(@RequestBody PelipatanDto dtos,
			HttpServletRequest request) {
		List<Map<String, Object>> result = laundryService.prosesPelipatan2(dtos);
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/get-all-pelipatan", method = GET, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<List<PengeringanDto>> getAllPelipatanFilter(
			@RequestParam(value = "startPeriode", required = false) String startPeriode,
			@RequestParam(value = "endPeriode", required = false) String endPeriode, HttpServletRequest request) {
		String newEndPeriode = changeTimeEndPeriode(endPeriode);
		List<PengeringanDto> result = laundryService.getAllPelipatan(toDate(startPeriode), toDate(newEndPeriode));
		if (result != null) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/cek-stok-ruangan", method = GET, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String, Object>>> cekStokRuangan(@RequestBody ProsesCuciLinenDto dtos,
			HttpServletRequest request) {
		List<Map<String, Object>> result = laundryService.cekStokRuangan(dtos);
		if (result != null) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/cek-produk-pelipatan", method = POST, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> cekProdukPelipatan(@RequestBody PelipatanDto dto,
			HttpServletRequest request) {
		Map<String, Object> result = laundryService.cekProdukLipat2(dto);
		if (result != null) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/get-produk-penerimaan-linen-external", method = GET, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String, Object>>> getProdukPenerimaanLinenExternal(HttpServletRequest request) {
		List<Map<String, Object>> result = laundryService.getProdukPenerimaanLinenExternal();
		if (result != null) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/save-penerimaan-linen-external", method = POST, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String, Object>>> savePenerimaanLinenEkternal(
			@RequestBody PenerimaanLinenExternalDto dto, HttpServletRequest request) {
		List<Map<String, Object>> result = laundryService.savePenerimaanLinenExternal(dto);
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/get-satuan-potong", method = GET, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<List<Map<String, Object>>> getAllSatuanPotong(HttpServletRequest request) {
		List<Map<String, Object>> result = laundryService.getAllSatuanPotong();
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/get-pembilasan-to-pengeringan", method = GET, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<ProsesCuciLinenDto> getPembilasanToPengeringan(
			@RequestParam(value = "noRecStrukPelayanan") String noRecStrukPelayanan, HttpServletRequest request) {
		ProsesCuciLinenDto dto = new ProsesCuciLinenDto();
		dto.setNoRecStrukPelayanan(noRecStrukPelayanan);
		ProsesCuciLinenDto result = laundryService.sendPembilasanToPengeringan(dto);
		if (result != null) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/get-pengeringan-to-pelipatan", method = GET, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<ProsesCuciLinenDto> getPengeringanToPelipatan(
			@RequestParam(value = "noRecStrukPelayanan") String noRecStrukPelayanan, HttpServletRequest request) {
		ProsesCuciLinenDto dto = new ProsesCuciLinenDto();
		dto.setNoRecStrukPelayanan(noRecStrukPelayanan);
		ProsesCuciLinenDto result = laundryService.sendPengeringanToPelipatan(dto);
		if (result != null) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/get-all-pengambilan-eksternal", method = GET, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<List<PengeringanDto>> getAllPengambilanLinenEksternal(
			@RequestParam(value = "namaPelanggan", required = false) String namaPelanggan,
			@RequestParam(value = "startPeriode", required = false) String startPeriode,
			@RequestParam(value = "endPeriode", required = false) String endPeriode, HttpServletRequest request) {
		String newEndPeriode = changeTimeEndPeriode(endPeriode);
		List<PengeringanDto> result = laundryService.getAllPengambilanLinenEksternal(namaPelanggan,
				toDate(startPeriode), toDate(newEndPeriode));
		if (result != null) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/save-pengambilan", method = POST, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> savePengambilan(@RequestBody ProsesCuciLinenDto dto,
			HttpServletRequest request) {
		Map<String, Object> result = laundryService.prosesPengambilan(dto);
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/retur-laundry", method = POST, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> saveReturLaundry(@RequestBody ProsesReturDto dto,
			HttpServletRequest request) {
		Map<String, Object> result = laundryService.prosesReturLaundry(dto);
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/get-retur-linen", method = GET, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<PengeringanDto> getAllReturLinen(
			@RequestParam(value = "noRecStrukPelayanan") String noRecStrukPelayanan, HttpServletRequest request) {
		PengeringanDto dto = new PengeringanDto();
		dto.setNoRecStrukPelayanan(noRecStrukPelayanan);
		PengeringanDto result = laundryService.sendPengambilanLinenToReturLinen(dto);
		if (result != null) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/get-all-retur-linen", method = GET, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<List<ProsesReturDto>> getAllReturLinen(
			@RequestParam(value = "startPeriode", required = false) String startPeriode,
			@RequestParam(value = "endPeriode", required = false) String endPeriode, HttpServletRequest request) {
		String newEndPeriode = changeTimeEndPeriode(endPeriode);
		List<ProsesReturDto> result = laundryService.getAllRetur(toDate(startPeriode), toDate(newEndPeriode));
		if (result != null) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/save-pengambilan-linen-internal", method = POST, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> savePengambilanLinenInternal(@RequestBody PenerimaanLinenExternalDto dto,
			HttpServletRequest request) {
		Map<String, Object> result = this.laundryService.savePengambilanLaundryInternal(dto);
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/save-penerimaan-linen-internal", method = POST, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> savePenerimaanLinenInternal(@RequestBody PenerimaanLinenExternalDto dto,
			HttpServletRequest request) {
		Map<String, Object> result = this.laundryService.savePenerimaanLaundryInternal(dto);
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/get-permintaan-linen-bersih-dari-ruangan", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> getOrderLaundrySebelumDiterima(
			@RequestParam(value = "startDate", required = false) String startDate,
			@RequestParam(value = "endDate", required = false) String endDate, HttpServletRequest request) {
		return this.laundryService.getOrderLaundrySebelumDiTerima(startDate, endDate);
	}

	@RequestMapping(value = "/get-pengambilan-linen-kotor", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> getPengambilanLinenKotor(
			@RequestParam(value = "startDate", required = false) String startDate,
			@RequestParam(value = "endDate", required = false) String endDate, HttpServletRequest request) {
		return this.laundryService.getPengambilanLinenKotor(startDate, endDate);
	}

	@RequestMapping(value = "/get-permintaan-linen-bersih-detail", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> getPengambilanLinenKotorDetail(@RequestParam("noRec") String noRec,
			HttpServletRequest request) {
		return this.laundryService.getOrderLaundrySebelumDiTerimaDetail(noRec);
	}

	@RequestMapping(value = "/save-proses-cuci-internal", method = POST, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> saveProsesCuciInternal(@RequestBody ProsesCuciLinenDto dtos,
			HttpServletRequest request) {
		Map<String, Object> result = this.laundryService.saveProsesPencucianInternal(dtos);
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/save-proses-cuci-external", method = POST, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> saveProsesCuciExternal(@RequestBody ProsesCuciLinenDto dtos,
			HttpServletRequest request) {
		Map<String, Object> result = this.laundryService.saveProsesPencucianExternal(dtos);
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/get-proses-cuci", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> gerProsesCuci(@RequestParam("startDate") String startDate,
			@RequestParam("endDate") String endDate, HttpServletRequest request) {
		return this.laundryService.getProsesCucianInternal(startDate, endDate);
	}

	@RequestMapping(value = "/get-proses-cuci-external", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> gerProsesCuciExternal(@RequestParam("startDate") String startDate,
			@RequestParam("endDate") String endDate, HttpServletRequest request) {
		return this.laundryService.getProsesCucianExternal(startDate, endDate);
	}

	@RequestMapping(value = "/get-proses-cuci-by-norec", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> gerProsesCuciByNoRec(@RequestParam("noRec") String noRec, HttpServletRequest request) {
		return this.laundryService.getProsesCuciianInternalByNoRec(noRec);
	}

	@RequestMapping(value = "/get-proses-cuci-external-by-norec", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> gerProsesCuciExternalByNoRec(@RequestParam("noRec") String noRec,
			HttpServletRequest request) {
		return this.laundryService.getProsesCucianExternalByNoRec(noRec);
	}

	@RequestMapping(value = "/save-proses-pengeringan-internal", method = POST, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> saveProsesPengeringan(@RequestBody PengeringanDto dto,
			HttpServletRequest request) {
		Map<String, Object> result = this.laundryService.savePengeringanInternal(dto);
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/save-proses-pengeringan-external", method = POST, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> saveProsesPengeringanExternal(@RequestBody PengeringanDto dto,
			HttpServletRequest request) {
		Map<String, Object> result = this.laundryService.savePengeringanExternal(dto);
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/get-proses-pengeringan", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> getProsesPengeringan(@RequestParam("startDate") String startDate,
			@RequestParam("endDate") String endDate, HttpServletRequest request) {
		return this.laundryService.getProsesPengeringanInternal(startDate, endDate);
	}

	@RequestMapping(value = "/get-proses-pengeringan-external", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> getProsesPengeringanExternal(@RequestParam("startDate") String startDate,
			@RequestParam("endDate") String endDate, HttpServletRequest request) {
		return this.laundryService.getProsesPengeringanExternal(startDate, endDate);
	}

	@RequestMapping(value = "/get-proses-pengeringan-by-norec", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> gerProsesPengeringanByNoRec(@RequestParam("noRec") String noRec,
			HttpServletRequest request) {
		return this.laundryService.getProsesPengeringanInternalByNoRec(noRec);
	}

	@RequestMapping(value = "/get-proses-pengeringan-external-by-norec", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> gerProsesPengeringanExternalByNoRec(@RequestParam("noRec") String noRec,
			HttpServletRequest request) {
		return this.laundryService.getProsesPengeringanExternalByNoRec(noRec);
	}

	@RequestMapping(value = "/save-proses-pelipatan", method = POST, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> saveProsesPelipatan(@RequestBody PelipatanDto dto,
			HttpServletRequest request) {
		Map<String, Object> result = this.laundryService.savePelipatanInternal(dto);
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/save-proses-pelipatan-external", method = POST, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> saveProsesPelipatanExternal(@RequestBody PelipatanDto dto,
			HttpServletRequest request) {
		Map<String, Object> result = this.laundryService.savePelipatanExternal(dto);
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/get-proses-pelipatan", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> getProsesPelipatan(@RequestParam("startDate") String startDate,
			@RequestParam("endDate") String endDate, HttpServletRequest request) {
		return this.laundryService.getProsesPelipatan(startDate, endDate);
	}

	@RequestMapping(value = "/get-proses-pelipatan-external", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> getProsesPelipatanExternal(@RequestParam("startDate") String startDate,
			@RequestParam("endDate") String endDate, HttpServletRequest request) {
		return this.laundryService.getProsesPelipatanExternal(startDate, endDate);
	}

	@RequestMapping(value = "/get-proses-pelipatan-by-norec", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> gerProsesPelipatanByNoRec(@RequestParam("noRec") String noRec,
			HttpServletRequest request) {
		return this.laundryService.getProsesPelipatanByNoRec(noRec);
	}

	@RequestMapping(value = "/get-proses-pelipatan-external-by-norec", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> gerProsesPelipatanExternalByNoRec(@RequestParam("noRec") String noRec,
			HttpServletRequest request) {
		return this.laundryService.getProsesPelipatanExternalByNoRec(noRec);
	}

	@RequestMapping(value = "/save-proses-rollpress", method = POST, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> saveProsesRollPress(@RequestBody PelipatanDto dto,
			HttpServletRequest request) {
		Map<String, Object> result = this.laundryService.saveRollPressInternal(dto);
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/save-proses-rollpress-external", method = POST, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> saveProsesRollPressExternal(@RequestBody PelipatanDto dto,
			HttpServletRequest request) {
		Map<String, Object> result = this.laundryService.saveRollPressExternal(dto);
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/get-proses-rollpress", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> getProsesRollPress(@RequestParam("startDate") String startDate,
			@RequestParam("endDate") String endDate, HttpServletRequest request) {
		return this.laundryService.getProsesRollPress(startDate, endDate);
	}

	@RequestMapping(value = "/get-proses-rollpress-external", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> getProsesRollPressExternal(@RequestParam("startDate") String startDate,
			@RequestParam("endDate") String endDate, HttpServletRequest request) {
		return this.laundryService.getProsesRollPressExternal(startDate, endDate);
	}

	@RequestMapping(value = "/get-proses-rollpress-by-norec", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> getProsesRollPressByNoRec(@RequestParam("noRec") String noRec,
			HttpServletRequest request) {
		return this.laundryService.getProsesRollPressByNoRec(noRec);
	}

	@RequestMapping(value = "/get-proses-rollpress-external-by-norec", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> getProsesRollPressExternalByNoRec(@RequestParam("noRec") String noRec,
			HttpServletRequest request) {
		return this.laundryService.getProsesRollPressExternalByNoRec(noRec);
	}

	@RequestMapping(value = "/get-bahan-laundry", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> getBahanLaundry(HttpServletRequest request) {
		return this.laundryService.getBahanLaundry();
	}

	@RequestMapping(value = "/get-laundry-linen-bersih", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> getStockLaundryLinenBersih(HttpServletRequest request) {
		return this.laundryService.getStockLaundryLinenBersih();
	}

	@RequestMapping(value = "/save-distribusi-linen", method = POST, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> saveDistribusiLinen(@RequestBody PenerimaanLinenExternalDto dto,
			HttpServletRequest request) {
		Map<String, Object> result = this.laundryService.savePenditribusianLinenInternal(dto);
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/get-distribusi-linen-bersih", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> getDistribusiLinenBersih(@RequestParam("startDate") String startDate,
			@RequestParam("endDate") String endDate, HttpServletRequest request) {
		return this.laundryService.getDistribusiLinen(startDate, endDate);
	}

	@RequestMapping(value = "/get-distribusi-linen-bersih-by-ruangan", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> getDistribusiLinenBersihByRuangan(@RequestParam("startDate") String startDate,
			@RequestParam("endDate") String endDate, HttpServletRequest request) {
		return this.laundryService.getDistribusiLinenByRuangan(startDate, endDate);
	}

	@RequestMapping(value = "/save-verifikasi-penerimaan-linenbersih", method = POST, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> saveVerifikasiPenerimaanLinenBersih(@RequestBody PenerimaanLinenDto dto,
			HttpServletRequest request) {
		Map<String, Object> result = this.laundryService.updateTanggalTerimaLinenBersihByRuangan(dto);
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/get-distribusi-linen-bersih-detail", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> getDistribusiLinenBersihDetailByRuangan(@RequestParam("noRec") String noRec,
			HttpServletRequest request) {
		return this.laundryService.getDistribusiLinenBersihDetailByNoRec(noRec);
	}

	@RequestMapping(value = "/get-penerimaan-linen-internal-by-periode", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> getPenerimaanLinenInternalByDate(@RequestParam(value = "startDate") String startDate,
			@RequestParam(value = "endDate") String endDate) {
		return this.laundryService.getPenerimaanLinenInternal(startDate, endDate);
	}

	@RequestMapping(value = "/get-penerimaan-linen-external-by-periode", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> getPenerimaanLinenExternalByDate(@RequestParam(value = "startDate") String startDate,
			@RequestParam(value = "endDate") String endDate) {
		return this.laundryService.getPenerimaanLinenExternal(startDate, endDate);
	}

	@RequestMapping(value = "/get-distribusi-linen-external", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> getDistribusiLinenExternal(@RequestParam(value = "startDate") String startDate,
			@RequestParam(value = "endDate") String endDate) {
		return this.laundryService.getDistribusiLinenExternal(startDate, endDate);
	}

	@RequestMapping(value = "/get-distribusi-linen-external-by-norec", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> getDistribusiLinenBersihDetailByNoRec(@RequestParam("noRec") String noRec,
			HttpServletRequest request) {
		return this.laundryService.getDistribusiLinenExternalByNoRec(noRec);
	}

	@RequestMapping(value = "/save-distribusi-linen-external", method = POST, produces = APPLICATION_JSON_VALUE)
	public ResponseEntity<Map<String, Object>> saveDistribusiLinenExternal(@RequestBody PenerimaanLinenExternalDto dto,
			HttpServletRequest request) {
		Map<String, Object> result = this.laundryService.savePenditribusianLinenExternal(dto);
		if (!result.isEmpty()) {
			mapHeaderMessage.put(LABEL_SUCCESS, getMessage(MessageResource.LABEL_SUCCESS, request));
			return getJsonResponse(result, OK, mapHeaderMessage);
		}
		return getJsonHttpStatus(INTERNAL_SERVER_ERROR, mapHeaderMessage);
	}

	@RequestMapping(value = "/get-jenis-linen", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> getJenisLinen(HttpServletRequest request) {
		return this.laundryService.getJenisLinen();
	}

	@RequestMapping(value = "/get-mesin-by-jenis-linen", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> getMesinByJenisLinen(@RequestParam("idJenis") Integer idJenis,
			HttpServletRequest request) {
		return this.laundryService.getMesinByJenisLinen(idJenis);
	}

	@RequestMapping(value = "/get-produk-by-mesin-jenis-linen", method = GET, produces = APPLICATION_JSON_VALUE)
	public Map<String, Object> getProdukByMesinJenisLinen(@RequestParam("idJenis") Integer idJenis,
			@RequestParam("idMesin") Integer idMesin, HttpServletRequest request) {
		return this.laundryService.getMappingProdukByJenisLinen(idJenis, idMesin);
	}

}
