const express = require("express");
const router = express.Router();
const authorize = require("../../../../middlewares/authorize-sapps");
const erpService = require("./erp.service");
const erpItemService = require("./erp.item.service");
const erpCompanyService = require("./erp.company.service");
const erpWarehouseService = require("./erp.warehouse.service");
const erpAccountService = require("./erp.account.service");
const erpDepartmentService = require("./erp.department.service");
const erpFiscalYearService = require("./erp.fiscalyear.service");
const erpBudgetService = require("./erp.budget.service");
const erpUOMService = require("./erp.uom.service");
const erpItemPriceService = require("./erp.itemprice.service");

router.get("/get-delivery-orders", authorize(), getDeliveryOrder);
router.get("/get-sales-invoices", authorize(), getSalesInvoice);
router.get("/get-batchs", authorize(), getBatch);
router.get("/get-principals", authorize(), getPrincipal);
router.get("/get-material-requests", authorize(), getMaterialRequests);
router.get("/get-purchase-order-by-material-request", authorize(), getPurchaseOrderByMaterialRequest);
router.get("/get-purchase-orders", authorize(), getPurchaseOrders);
router.get("/get-purchase-receipt-by-purchase-order", authorize(), getPurchaseReceiptByPurchaseOrder);
router.get("/get-purchase-order-items", authorize(), getPurchaseOrderItems);

router.get("/get-users", authorize(), getUsers);
router.get("/get-employees", authorize(), getEmployees);
router.get("/get-customers", authorize(), getCustomers);
router.get("/get-departments", authorize(), getDepartments);
router.get("/get-designations", authorize(), getDesignations);
router.get("/get-items", authorize(), getItems);
router.get("/get-holiday-groups", authorize(), getHolidayGroups);

router.get("/get-status", authorize(), getStatus);

router.post("/get-budgets", authorize(), getBudgetList);
router.post("/get-budget-accounts", authorize(), getBudgetAccount);
router.post("/get-item-prices", authorize(), getItemPriceList);

router.post("/get-accounts", authorize(), getAccounts);

router.post("/get-option-items", authorize(), getOptionItems);
router.post("/get-option-companies", authorize(), getOptionCompanies);
router.post("/get-option-warehouses", authorize(), getOptionWarehouses);
router.post("/get-option-accounts", authorize(), getOptionAccounts);
router.post("/get-option-departments", authorize(), getOptionDepartments);
router.post("/get-option-fiscal-years", authorize(), getOptionFiscalYears);
router.post("/get-option-uom", authorize(), getOptionUOM);
router.post("/get-option-item-prices", authorize(), getOptionItemPrices);

router.post("/import-user", authorize(), importUser);
router.post("/import-users", authorize(), importUsers);
router.post("/import-all-user", authorize(), importAllUser);

router.post("/import-employee", authorize(), importEmployee);
router.post("/import-employees", authorize(), importEmployees);
router.post("/import-all-employee", authorize(), importAllEmployee);

router.post("/import-customer-list", authorize(), importCustomer);
router.post("/import-customer-lists", authorize(), importCustomers);
router.post("/import-all-customer-list", authorize(), importAllCustomer);

router.post("/import-department", authorize(), importDepartment);
router.post("/import-departments", authorize(), importDepartments);
router.post("/import-all-department", authorize(), importAllDepartment);

router.post("/import-designation", authorize(), importDesignation);
router.post("/import-designations", authorize(), importDesignations);
router.post("/import-all-designation", authorize(), importAllDesignation);

router.post("/import-item", authorize(), importItem);
router.post("/import-items", authorize(), importItems);
router.post("/import-all-item", authorize(), importAllItem);

router.post("/sync-item-prices", authorize(), syncItemPrices);

router.post("/import-holiday-group", authorize(), importHolidayGroup);

module.exports = router;

// get data
function getDeliveryOrder(req, res, next) {
	erpService
		.getDeliveryOrder(req.query)
		.then((result) => res.json(result))
		.catch(next);
}

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

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

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

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

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

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

function getPurchaseOrders(req, res, next) {
	erpService
		.getPurchaseOrders(req.query)
		.then((result) => res.json(result))
		.catch(next);
}
function getPurchaseReceiptByPurchaseOrder(req, res, next) {
	erpService
		.getPurchaseReceiptByPurchaseOrder(req.query)
		.then((result) => res.json(result))
		.catch(next);
}

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

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

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

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

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

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

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

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

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

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

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

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

// get options
function getOptionAccounts(req, res, next) {
	erpAccountService
		.getOptionAccounts(req.body)
		.then((result) => res.json(result))
		.catch(next);
}

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

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

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

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

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

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

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

// import data
function importUser(req, res, next) {
	erpService
		.importUser(req.body)
		.then((result) => res.json(result))
		.catch(next);
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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