const express = require('express');
const router = express.Router();
const accountingService = require('./accounting.service');
const authorize = require('../../../../middlewares/authorize-sapps');

router.post('/get-accounts-receivable', getAccountsReceivable);
router.post('/get-accounts-payable', getAccountsPayable);
router.post('/get-profit-and-loss', getProfitAndLoss);
router.post('/get-balance-sheet', getBalanceSheet);
router.post('/get-financial-ratio', getFinancialRatio);

module.exports = router;

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

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

function getProfitAndLoss(req, res, next) {
    console.log('req.body', req.body);
    accountingService.getProfitAndLoss(req.body)
        .then(result => res.json(result))
        .catch(next);
}

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

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