-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
78 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { PurchaseReportView, Expense } from '../type/common'; | ||
import { createCsv, createCsvData } from './createCsv'; | ||
|
||
export const createPurchaseReportCsv = async ( | ||
purchaseReportsViews: PurchaseReportView[], | ||
expenses: Expense[], | ||
) => | ||
createCsv( | ||
createCsvData(purchaseReportsViews, [ | ||
{ | ||
getCustomValue: (row) => row.purchaseReport.id || '', | ||
label: 'ID', | ||
}, | ||
{ | ||
getCustomValue: (row) => | ||
expenses.find((expense) => expense.id === row.purchaseOrder.expenseID)?.name || '', | ||
label: '報告した局', | ||
}, | ||
{ | ||
getCustomValue: (row) => String(row.purchaseReport.createdAt).split('T')[0] || '', | ||
label: '報告日', | ||
}, | ||
{ | ||
getCustomValue: (row) => row.purchaseOrder.deadline || '', | ||
label: '購入日', | ||
}, | ||
{ | ||
getCustomValue: (row) => | ||
(row.purchaseItems.reduce((sum, item) => item.financeCheck ? (sum + item.price * item.quantity) : sum, 0) + row.purchaseReport.addition - row.purchaseReport.discount)|| '0', | ||
label: '合計金額', | ||
}, | ||
{ | ||
getCustomValue: (row) => (row.purchaseReport.financeCheck ? '○' : '' || ''), | ||
label: '財務局長チェック', | ||
}, | ||
{ | ||
getCustomValue: (row) => | ||
row.purchaseItems | ||
.map( | ||
(item) => | ||
`${item.item}/${item.price}円/${item.quantity}個/` + | ||
(item.financeCheck ? '○' : '×'), | ||
) | ||
.join(' , ') || '', | ||
label: '購入物品 (品名/値段/数量/財務局長チェック)', | ||
}, | ||
{ | ||
getCustomValue: (row) => row.purchaseReport.remark || '', | ||
label: '備考', | ||
}, | ||
]), | ||
); |