const express = require("express");
const router = express.Router();
const authorize = require("../../../middlewares/authorize-sapps");
const reportServices = require("./report.service");
const reportERPNextStockBalanceServices = require("./reportERPNextStockBalance.service");

router.get("/report-master-list", authorize(), reportMasterList);
router.get("/report-sales-contribution", authorize(), reportSalesContribution);
router.get("/report-gimmick-transfer-realization", authorize(), reportGimmickTransferRealization);
router.get("/report-saldo-balance-break-tahunan", authorize(), reportSaldoBalanceBreakTahunan);
router.get("/report-saldo-balance-user", authorize(), reportSaldoBalanceUser);
router.get("/report-uc-cost-realization", authorize(), reportUcCostRealization);
router.get("/report-uc-attendance", authorize(), reportUcAttendance);
router.get("/report-attendance", authorize(), reportAttendance);
router.get("/report-attendance-by-employee", authorize(), reportAttendanceByEmployee);
router.get("/report-cpr", authorize(), reportCPR);
router.get("/report-sales-target", authorize(), reportSalesTarget);
router.get("/report-sales-vs-target", authorize(), reportSalesVsTarget);
router.get("/report-visit-verify", authorize(), reportVisitVerify);
router.get("/report-goods-receipt", authorize(), reportGoodsReceipt);
router.get("/report-up-country", authorize(), reportUpCountry);
router.get("/report-employee-attendance-rate", authorize(), reportEmployeeAttendanceRate);
router.post("/report-erpnext-stock-balance", authorize(), reportERPNextStockBalance);

module.exports = router;

function reportMasterList(req, res, next) {
  reportServices
    .reportMasterList(req.query)
    .then((result) => res.json(result))
    .catch(next);
}

function reportUpCountry(req, res, next) {
  reportServices
    .reportUpCountry(req.query)
    .then((result) => res.json(result))
    .catch(next);
}

function reportAttendance(req, res, next) {
  reportServices
    .reportAttendance(req.query)
    .then((result) => res.json(result))
    .catch(next);
}

function reportAttendanceByEmployee(req, res, next) {
  reportServices
    .reportAttendanceByEmployee(req.query)
    .then((result) => res.json(result))
    .catch(next);
}

function reportCPR(req, res, next) {
  reportServices
    .reportCPR(req.query)
    .then((result) => res.json(result))
    .catch(next);
}

function reportSalesContribution(req, res, next) {
  reportServices
    .reportSalesContribution(req.query)
    .then((result) => res.json(result))
    .catch(next);
}

function reportGimmickTransferRealization(req, res, next) {
  reportServices
    .reportGimmickTransferRealization(req.query)
    .then((result) => res.json(result))
    .catch(next);
}

function reportSaldoBalanceBreakTahunan(req, res, next) {
  reportServices
    .reportSaldoBalanceBreakTahunan(req.query)
    .then((result) => res.json(result))
    .catch(next);
}
function reportSaldoBalanceUser(req, res, next) {
  reportServices
    .reportSaldoBalanceUser(req.query)
    .then((result) => res.json(result))
    .catch(next);
}

function reportUcCostRealization(req, res, next) {
  reportServices
    .reportUcCostRealization(req.query)
    .then((result) => res.json(result))
    .catch(next);
}

function reportUcAttendance(req, res, next) {
  reportServices
    .reportUcAttendance(req.query)
    .then((result) => res.json(result))
    .catch(next);
}

function reportSalesTarget(req, res, next) {
  reportServices
    .reportSalesTarget(req.query)
    .then((result) => res.json(result))
    .catch(next);
}

function reportSalesVsTarget(req, res, next) {
  reportServices
    .reportSalesVsTarget(req.query)
    .then((result) => res.json(result))
    .catch(next);
}

function reportVisitVerify(req, res, next) {
  reportServices
    .reportVisitVerify(req.query)
    .then((result) => res.json(result))
    .catch(next);
}

function reportGoodsReceipt(req, res, next) {
  reportServices
    .reportGoodsReceipt(req.query)
    .then((result) => res.json(result))
    .catch(next);
}

function reportEmployeeAttendanceRate(req, res, next) {
  reportServices
    .reportEmployeeAttendanceRate(req.query)
    .then((result) => res.json(result))
    .catch(next);
}

function reportERPNextStockBalance(req, res, next) {
  reportERPNextStockBalanceServices
    .reportERPNextStockBalance(req.body)
    .then((result) => res.json(result))
    .catch(next);
}
