ttc-api: added transactionSearch* and projectSearch, more on reportController.
Signed-off-by: supphakitd <67319010028@technictrang.ac.th>
This commit is contained in:
@@ -24,8 +24,6 @@ export class projectSearch {
|
||||
let aryResult = []
|
||||
let condition = {}
|
||||
try {
|
||||
// let username = req.body.request.username;
|
||||
// let password = req.body.request.password;
|
||||
let token = req.headers.authorization?.split(' ')[1];
|
||||
const decoded = verifyToken(token);
|
||||
|
||||
@@ -36,10 +34,10 @@ export class projectSearch {
|
||||
column = `prjnam, prjwntbdg`
|
||||
condition['prjseq'] = req.body.request.prjseq
|
||||
} else if(columnParams == 'result' || columnParams == undefined || columnParams == ''){
|
||||
column = `prjseq, prjnam, prjwntbdg, prjacpbdg, ${database}.translatebdg(prjbdgcod) as prjbdgnam, prjcomstt, prjacpdtm`
|
||||
column = `prjseq, prjnam, prjwntbdg, prjacpbdg, ${database}.translatebdg(prjbdgcod) as prbdgnam, ${database}.translatedtl('COMSTT', prjcomstt) as prjcomstt, prjacpdtm`
|
||||
}
|
||||
|
||||
aryResult = await this.projectSearchService.getProjectSearch(database, column, condition);
|
||||
aryResult = await this.projectSearchService.getProjectSearch(database, column, condition);
|
||||
|
||||
} catch (error) {
|
||||
idx = 1;
|
||||
|
||||
@@ -34,7 +34,7 @@ export class reportController {
|
||||
|
||||
aryResult = await this.reportService.getReportController(database, acpTime, expTime);
|
||||
} catch (error) {
|
||||
idx = 1;
|
||||
idx = 1;b
|
||||
} finally {
|
||||
if (idx === 1) return sendError('เกิดข้อผิดพลาดไม่คาดคิดเกิดขึ้น', 'Unexpected error');
|
||||
if (!aryResult) return sendError('ไม่พบการมีอยู่ของข้อมูล', 'Cannot Find Any Data');
|
||||
@@ -53,20 +53,26 @@ export class reportController {
|
||||
return aryResult;
|
||||
}
|
||||
|
||||
// 2) แยก Budget Type
|
||||
const developStudentList = data.filter(i => i.trnbdgcod === '29');
|
||||
const incomeList = data.filter(i => i.trnbdgcod === '33');
|
||||
const incomeBachelorList = data.filter(i => i.trnbdgcod === '38');
|
||||
const budgetCollegeList = data.filter(i => i.trnbdgcod === '24');
|
||||
const budgetTeachingList = data.filter(i => i.trnbdgcod === '30');
|
||||
const shortBudgetList = data.filter(i => i.trnbdgcod === '25');
|
||||
// 2) แยก Budget Typechar
|
||||
const omitFields = (obj, ...keys) => {
|
||||
const copy = { ...obj };
|
||||
keys.forEach(k => delete copy[k]);
|
||||
return copy;
|
||||
};
|
||||
const developStudentList = data.filter(i => i.trnbdgcod === '29')
|
||||
.map(i => omitFields(i, 'trnbdgcod', 'trncomstt'));
|
||||
const incomeList = data.filter(i => i.trnbdgcod === '33')
|
||||
.map(i => omitFields(i, 'trnbdgcod', 'trncomstt'));
|
||||
const incomeBachelorList = data.filter(i => i.trnbdgcod === '38')
|
||||
.map(i => omitFields(i, 'trnbdgcod', 'trncomstt'));
|
||||
const budgetCollegeList = data.filter(i => i.trnbdgcod === '24')
|
||||
.map(i => omitFields(i, 'trnbdgcod', 'trncomstt'));
|
||||
const budgetTeachingList = data.filter(i => i.trnbdgcod === '30')
|
||||
.map(i => omitFields(i, 'trnbdgcod', 'trncomstt'));
|
||||
const shortBudgetList = data.filter(i => i.trnbdgcod === '25')
|
||||
.map(i => omitFields(i, 'trnbdgcod', 'trncomstt'));
|
||||
|
||||
// const totalIncome = incomeList.reduce((sum, i) => sum + parseFloat(i.actqty || 0), 0);
|
||||
// const totalExpense = expenseList.reduce((sum, e) => sum + parseFloat(e.actqty || 0), 0);
|
||||
|
||||
// const netProfit = totalIncome - totalExpense;
|
||||
// const profitRate = totalIncome > 0 ? (netProfit / totalIncome) * 100 : 0;
|
||||
// const adjustedProfitRate = profitRate + 1.9;
|
||||
|
||||
// ✅ 3) แนบ summary (เหมือนที่เราทำไปก่อนหน้า)
|
||||
var summary = {
|
||||
@@ -79,7 +85,7 @@ export class reportController {
|
||||
shortBudgetList: shortBudgetList,
|
||||
|
||||
// totalIncome: totalIncome.toFixed(2),
|
||||
// totalExpense: totalExpense.toFixed(2),
|
||||
// totalExpense: otalExpense.toFixed(2),
|
||||
// netProfit: netProfit.toFixed(2),
|
||||
};
|
||||
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
import { TransactionSearchService } from '../services/transactionSearchService.js'
|
||||
import { sendError } from '../utils/response.js'
|
||||
// import { OftenError } from '../utils/oftenError.js'
|
||||
import { GeneralService } from '../share/generalservice.js';
|
||||
import { trim_all_array } from '../utils/trim.js'
|
||||
import { verifyToken, generateToken } from '../utils/token.js'
|
||||
|
||||
export class transactionSearch {
|
||||
|
||||
constructor() {
|
||||
this.generalService = new GeneralService();
|
||||
this.transactionSearchService = new TransactionSearchService();
|
||||
}
|
||||
|
||||
async onNavigate(req, res) {
|
||||
this.generalService.devhint(1, 'transactionSearch.js', 'onNavigate() start');
|
||||
let organization = req.body.organization;
|
||||
const prommis = await this.onTransactionSearch(req, res, organization);
|
||||
return prommis;
|
||||
}
|
||||
|
||||
async onTransactionSearch(req, res, database) {
|
||||
let idx = -1
|
||||
let aryResult = []
|
||||
let condition = {}
|
||||
try {
|
||||
// let username = req.body.request.username;
|
||||
// let password = req.body.request.password;
|
||||
let token = req.headers.authorization?.split(' ')[1];
|
||||
const decoded = verifyToken(token);
|
||||
|
||||
database = decoded.organization
|
||||
let columnParams = req.query.column
|
||||
var column = ""
|
||||
if(columnParams == 'edit'){
|
||||
column = `trnseq, trnprjnam, trnprjseq, trnbdgcod, trncomstt`
|
||||
condition['trnseq'] = req.body.request.trnseq
|
||||
} else if(columnParams == 'result' || columnParams == undefined || columnParams == ''){
|
||||
column = `trnprjnam, trnbdgcod, ${database}.translatedtl('COMSTT', trncomstt) AS trncomstt, trnacpdtm`
|
||||
}
|
||||
|
||||
aryResult = await this.transactionSearchService.getTransactionSearch(database, column, condition);
|
||||
|
||||
} catch (error) {
|
||||
idx = 1;
|
||||
} finally {
|
||||
if (idx === 1) return sendError('เกิดข้อผิดพลาดไม่คาดคิดเกิดขึ้น', 'Unexpected error');
|
||||
if (aryResult == 0) return sendError('ไม่พบการมีอยู่ของข้อมูล', 'Cannot Find Any Data');
|
||||
return aryResult
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -6,6 +6,7 @@ import { projectSearch } from '../controllers/projectSearchController.js'
|
||||
import { projectAdd } from '../controllers/projectAddController.js'
|
||||
import { budgetExpense } from '../controllers/budgetExpenseController.js'
|
||||
import { reportController } from '../controllers/ReportController.js'
|
||||
import { transactionSearch } from '../controllers/transactionSearchController.js'
|
||||
|
||||
// import { authMiddleware } from '../middlewares/auth.js'
|
||||
// import { sendResponse } from '../utils/response.js'
|
||||
@@ -17,6 +18,7 @@ const controller_budgetAdd_post = new budgetAdd()
|
||||
const controller_budgetSetup_post = new budgetExpense()
|
||||
const controller_report_post = new reportController()
|
||||
const controller_projectAdd_post = new projectAdd()
|
||||
const controller_transactionSearch_post = new transactionSearch()
|
||||
|
||||
// router.post('/budgetSetup', async (req, res) => {
|
||||
// const result = await controller_budgetSetup_post.onNavigate(req, res)
|
||||
@@ -43,6 +45,11 @@ router.post('/projectadd', async (req, res) => {
|
||||
if (result) return res.json(result)
|
||||
})
|
||||
|
||||
router.post('/transactionsearch', async (req, res) => {
|
||||
const result = await controller_transactionSearch_post.onNavigate(req, res)
|
||||
if (result) return res.json(result)
|
||||
})
|
||||
|
||||
router.post('/budgetexpense', async (req, res) => {
|
||||
const result = await controller_budgetSetup_post.onNavigate(req, res)
|
||||
if (result) return res.json(result)
|
||||
|
||||
26
exthernal-ttc-api/src/services/transactionSearchService.js
Normal file
26
exthernal-ttc-api/src/services/transactionSearchService.js
Normal file
@@ -0,0 +1,26 @@
|
||||
import { GeneralService } from '../share/generalservice.js'
|
||||
|
||||
export class TransactionSearchService {
|
||||
|
||||
constructor() {
|
||||
this.generalService = new GeneralService()
|
||||
}
|
||||
|
||||
async getTransactionSearch(database, column, condition) {
|
||||
const sql = `
|
||||
SELECT
|
||||
${column}
|
||||
FROM ${database}.bdgmst
|
||||
WHERE 1=1
|
||||
`
|
||||
const params = []
|
||||
const result = await this.generalService.executeQueryConditions(database, sql, condition);
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
||||
// bdgseq,
|
||||
// bdgnam,
|
||||
// bdgcod,
|
||||
// bdgttl,
|
||||
// bdgedtdtm
|
||||
Reference in New Issue
Block a user