Browse Source

(*)合同明细导出

master
zmh 2 years ago
parent
commit
cb26cbeb16
  1. 32
      api/app/lib/controllers/report/achievement.js
  2. 3
      api/app/lib/routes/report/index.js
  3. 18
      api/app/lib/utils/xlsxDownload.js
  4. 2
      web/client/src/sections/business/containers/performanceReport/contractDetails.jsx
  5. 2
      web/client/src/sections/business/containers/performanceReport/invoicingDetails.jsx

32
api/app/lib/controllers/report/achievement.js

@ -310,9 +310,39 @@ async function getInvoicingDetail(ctx) {
ctx.body = { name: 'FindError', message: '查询开票明细表数据失败' }
}
}
/**
* 导出合同明细表数据
*/
async function exportContractDetail(ctx) {
try {
const { models } = ctx.fs.dc;
let exportData = await models.ContractDetail.findAll({
order: [['id', 'DESC']]
});
const { utils: { simpleExcelDown, contractDetailsColumnKeys } } = ctx.app.fs;
let header = [];
Object.keys(contractDetailsColumnKeys).map(key => {
header.push({ title: contractDetailsColumnKeys[key], key: key });
})
const fileName = `合同明细表_${moment().format('YYYYMMDDHHmmss')}` + '.xlsx'
const filePath = await simpleExcelDown({ data: exportData, header, fileName: fileName, needIndexCell: false })
const fileData = fs.readFileSync(filePath);
ctx.status = 200;
ctx.set('Content-Type', 'application/x-xls');
ctx.set('Content-disposition', 'attachment; filename=' + encodeURI(fileName));
ctx.body = fileData;
} catch (error) {
ctx.fs.logger.error(`path:${ctx.path},error:${error}`)
ctx.status = 400;
ctx.body = { name: 'ExportAllError', message: '导出合同明细表数据失败' }
}
}
module.exports = {
getReceivedDetail,//回款
getAchievementDetail,//业绩
getContractDetail,
getInvoicingDetail
getInvoicingDetail,
exportContractDetail
}

3
api/app/lib/routes/report/index.js

@ -21,4 +21,7 @@ module.exports = function (app, router, opts) {
app.fs.api.logAttr['GET/invoicing/detail'] = { content: '查询开票明细表', visible: false };
router.get('/invoicing/detail', achieve.getInvoicingDetail);
app.fs.api.logAttr['GET/export/contract/detail'] = { content: '导出合同明细表', visible: false };
router.get('/export/contract/detail', achieve.exportContractDetail);
};

18
api/app/lib/utils/xlsxDownload.js

@ -19,7 +19,7 @@ module.exports = function (app, opts) {
}
}
async function simpleExcelDown({ data = [], header = [], fileName = moment().format('YYYY-MM-DD HH:mm:ss') } = {}) {
async function simpleExcelDown({ data = [], header = [], fileName = moment().format('YYYY-MM-DD HH:mm:ss'), needIndexCell = true } = {}) {
const fileDirPath = path.join(__dirname, `../../downloadFiles`)
makeDir(fileDirPath)
const file = new xlsx.File();
@ -35,9 +35,11 @@ module.exports = function (app, opts) {
headerStyle.border.bottomColor = '#000000';
const headerRow = sheet_1.addRow();
const indexCell = headerRow.addCell();
indexCell.value = '序号'
indexCell.style = headerStyle
if (needIndexCell) {
const indexCell = headerRow.addCell();
indexCell.value = '序号'
indexCell.style = headerStyle
}
for (let h of header) {
const cell = headerRow.addCell();
cell.value = h.title;
@ -54,9 +56,11 @@ module.exports = function (app, opts) {
style.border.bottomColor = '#000000';
for (let i = 0; i < data.length; i++) {
const row = sheet_1.addRow();
const indexCell = row.addCell();
indexCell.value = i + 1
indexCell.style = headerStyle
if (needIndexCell) {
const indexCell = row.addCell();
indexCell.value = i + 1
indexCell.style = headerStyle
}
for (let h of header) {
const cell = row.addCell();
cell.value = data[i][h.key] || h.defaultValue || '-';

2
web/client/src/sections/business/containers/performanceReport/contractDetails.jsx

@ -9,7 +9,7 @@ import '../../style.less';
import moment from 'moment'
const ContractDetails = (props) => {
const { dispatch, actions } = props
const { dispatch, actions, user } = props
const { businessManagement } = actions;
const [keywordTarget, setKeywordTarget] = useState('contractNo');
const [keyword, setKeyword] = useState('');//

2
web/client/src/sections/business/containers/performanceReport/invoicingDetails.jsx

@ -9,7 +9,7 @@ import '../../style.less';
import moment from 'moment'
const InvoicingDetails = (props) => {
const { dispatch, actions } = props
const { dispatch, actions, user } = props
const { businessManagement } = actions;
const [keywordTarget, setKeywordTarget] = useState('contractNo');
const [keyword, setKeyword] = useState('');//

Loading…
Cancel
Save