Files
weiguang-jewelry-ledger/新账系统/inventory-movements-export.js
T

19 lines
2.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
'use strict';
const {workbook}=require('./xlsx');
const MIME='application/vnd.openxmlformats-officedocument.spreadsheetml.sheet';
const types={increase:'增加',decrease:'减少',transfer:'平移',opening:'开账',count_opening:'对数盘点基准',purchase:'入库',adjustment:'调整',manual:'手动变动',sale:'销售出库',return:'退货入库',manual_reversal:'更正冲回',lock_purchase:'锁价黄金入库',lock_finished:'锁价成品入库',order_edit_reverse:'改单出库冲回',order_edit_sale:'改单出库',order_cancel_reverse:'订单作废冲回',recovery:'回收旧料入库'};
const filters={all:'全部流水',increase:'手动增加',decrease:'手动减少',transfer:'手动平移',manual:'全部手动变动'};
function status(row){
if(row.reversal||row.kind==='manual_reversal')return '更正记录 · 撤回旧记录的库存影响';
if(row.current===false)return row.status==='deleted'?'原记录 · 已删除':row.status==='modified'?'原记录 · 已修改':'冲正/历史记录';
const value=row.status==='modified'?'修改后有效':row.manual?'当前有效':'随原业务记录保留';
return value+(row.manual&&row.pendingApproval?';待麦麦审批':'');
}
function recordedAt(value){const date=new Date(value);return Number.isNaN(date.getTime())?'时间未提供':new Intl.DateTimeFormat('sv-SE',{timeZone:'Asia/Shanghai',year:'numeric',month:'2-digit',day:'2-digit',hour:'2-digit',minute:'2-digit',second:'2-digit',hourCycle:'h23'}).format(date);}
function inventoryMovementsFile(result,date,pocketLabel=key=>key){
const rows=[['序号','日期','货盘','增减克重(g)','类型','备注/原单','经办人','记录时间','状态','增减对数(对)'],...result.movements.map((row,index)=>[index+1,row.date,pocketLabel(row.pocket),row.mg/1000,types[row.kind]||'其他库存变动('+row.kind+')',row.reversal||row.kind==='manual_reversal'?'撤回旧记录的库存影响':row.note||'',row.actor,recordedAt(row.created),status(row),row.stockCount??(row.countUnit==='pair'?'未登记':'')])];
const name=(result.pocket?pocketLabel(result.pocket):'全部货盘').replace(/[\\/:*?"<>|\u0000-\u001f]/g,'_');
return {buffer:workbook(rows,{widths:[8,14,16,18,20,48,18,24,30,18],optionalNumericColumns:[9]}),filename:`库存流水-${name}-${filters[result.kind]}-${date}.xlsx`,contentType:MIME};
}
module.exports={inventoryMovementsFile,MIME};