财务分类体系+统一账本+Excel导入+报表改造
This commit is contained in:
@@ -331,7 +331,97 @@ router.post('/execute', async (req, res) => {
|
||||
VALUES ($1, $2, $3, $4, $5, $6, $7, $8, $9, CURRENT_TIMESTAMP)
|
||||
RETURNING id`,
|
||||
[recordCode, payment_type, source_id, amount, 'CNY', paymentDate, voucher_url, payee_account, remark]);
|
||||
|
||||
|
||||
let finProjectId = null;
|
||||
let finUserId = null;
|
||||
let finUserName = null;
|
||||
let finCategory1 = 'company';
|
||||
let finCategory2 = 'other_company';
|
||||
let finSourceCode = recordCode;
|
||||
let finCounterpartyName = null;
|
||||
let finDescription = remark || '';
|
||||
|
||||
switch (payment_type) {
|
||||
case 'material': {
|
||||
const planRow = await db.query('SELECT purchase_order_id FROM payment_plans WHERE id = $1', [source_id]);
|
||||
if (planRow.rows.length > 0) {
|
||||
const poRow = await db.query('SELECT project_id, code FROM purchase_orders WHERE id = $1', [planRow.rows[0].purchase_order_id]);
|
||||
if (poRow.rows.length > 0) {
|
||||
finProjectId = poRow.rows[0].project_id;
|
||||
finSourceCode = poRow.rows[0].code;
|
||||
}
|
||||
}
|
||||
finCategory1 = 'project';
|
||||
finCategory2 = 'material';
|
||||
finDescription = finDescription || '材料采购付款';
|
||||
break;
|
||||
}
|
||||
case 'primary_freight':
|
||||
case 'secondary_freight': {
|
||||
const lrRow = await db.query('SELECT purchase_order_id FROM logistics_records WHERE id = $1', [source_id]);
|
||||
if (lrRow.rows.length > 0) {
|
||||
const poRow = await db.query('SELECT project_id, code FROM purchase_orders WHERE id = $1', [lrRow.rows[0].purchase_order_id]);
|
||||
if (poRow.rows.length > 0) {
|
||||
finProjectId = poRow.rows[0].project_id;
|
||||
finSourceCode = poRow.rows[0].code;
|
||||
}
|
||||
}
|
||||
finCategory1 = 'project';
|
||||
finCategory2 = 'freight';
|
||||
finDescription = finDescription || (payment_type === 'primary_freight' ? '一次运费付款' : '二次运费付款');
|
||||
break;
|
||||
}
|
||||
case 'advance': {
|
||||
const advRow = await db.query('SELECT project_id, applicant_id, applicant, advance_code, purpose FROM advances WHERE id = $1', [source_id]);
|
||||
if (advRow.rows.length > 0) {
|
||||
finProjectId = advRow.rows[0].project_id;
|
||||
finUserId = advRow.rows[0].applicant_id;
|
||||
finUserName = advRow.rows[0].applicant;
|
||||
finSourceCode = advRow.rows[0].advance_code;
|
||||
finDescription = finDescription || advRow.rows[0].purpose || '预支款';
|
||||
}
|
||||
finCategory1 = finProjectId ? 'project' : 'company';
|
||||
finCategory2 = finProjectId ? 'other_project' : 'other_company';
|
||||
break;
|
||||
}
|
||||
case 'reimbursement': {
|
||||
const reimbRow = await db.query('SELECT project_id, applicant_id, applicant, reimbursement_code, expense_type, description as reimb_desc FROM reimbursements WHERE id = $1', [source_id]);
|
||||
if (reimbRow.rows.length > 0) {
|
||||
finProjectId = reimbRow.rows[0].project_id;
|
||||
finUserId = reimbRow.rows[0].applicant_id;
|
||||
finUserName = reimbRow.rows[0].applicant;
|
||||
finSourceCode = reimbRow.rows[0].reimbursement_code;
|
||||
finDescription = finDescription || reimbRow.rows[0].reimb_desc || '报销';
|
||||
if (reimbRow.rows[0].expense_type === 'project') {
|
||||
finCategory1 = 'project';
|
||||
finCategory2 = 'other_project';
|
||||
} else {
|
||||
finCategory1 = 'company';
|
||||
finCategory2 = 'other_company';
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
const finCode = 'FIN-' + Date.now();
|
||||
const finAmountCny = parseFloat(amount) || 0;
|
||||
await db.query(`
|
||||
INSERT INTO financial_records
|
||||
(record_code, txn_type, category_level1, category_level2,
|
||||
project_id, user_id, user_name,
|
||||
amount_original, currency, exchange_rate, amount_cny,
|
||||
record_date, counterparty_name,
|
||||
source, source_id, source_code,
|
||||
description, voucher_no)
|
||||
VALUES ($1,$2,$3,$4,$5,$6,$7,$8,$9,$10,$11,$12,$13,$14,$15,$16,$17,$18)`,
|
||||
[finCode, 'expense', finCategory1, finCategory2,
|
||||
finProjectId, finUserId, finUserName,
|
||||
amount, 'CNY', 1, finAmountCny,
|
||||
paymentDate, finCounterpartyName,
|
||||
payment_type, source_id, finSourceCode,
|
||||
finDescription, voucher_url]);
|
||||
|
||||
await db.query('COMMIT');
|
||||
|
||||
res.json({
|
||||
|
||||
Reference in New Issue
Block a user