库存流水支持隐藏已删除记录并同步筛选导出

This commit is contained in:
summer committed 2026-11-19 00:55:38 +08:00
1 parent 90bdc75150
commit 8cac61deb3
6 files changed
+150 -27

No files matched your search

+10 -6
View File
@@ -555,6 +555,9 @@ class Ledger {
if(!query||typeof query!=='object'||Array.isArray(query))fail('库存流水筛选无效');
const kind=query.kind===undefined?'all':query.kind;
if(typeof kind!=='string'||!['all','increase','decrease','transfer','manual'].includes(kind))fail('筛选流水类型无效');
const hideDeletedValue=query.hideDeleted===undefined?false:query.hideDeleted;
if(![true,false,'true','false'].includes(hideDeletedValue))fail('隐藏已删除记录筛选无效');
const hideDeleted=hideDeletedValue===true||hideDeletedValue==='true';
const allRows=InventoryCounts.decorate(this,this.rows('SELECT * FROM movements ORDER BY created DESC,rowid DESC'));
// 库存及盘点流水三人共用;业务详情、修改和审批仍由原权限控制。
const visible=allRows;
@@ -564,21 +567,22 @@ class Ledger {
const pocket=query.pocket===undefined?'':query.pocket;
if(typeof pocket!=='string'||pocket&&!pockets.some(p=>p.pocket===pocket))fail('筛选货盘无效');
const manualKinds=kind==='all'?null:InventoryChanges.manualMovementKinds(this,allRows,visible);
const filtered=visible.filter(row=>(!pocket||row.pocket===pocket)&&(kind==='all'||(kind==='manual'?manualKinds.has(row.id):manualKinds.get(row.id)===kind)));
return {pocket,pockets,kind,filtered};
const deletedIds=hideDeleted?InventoryChanges.deletedMovementIds(this):null;
const filtered=visible.filter(row=>!deletedIds?.has(row.id)&&(!pocket||row.pocket===pocket)&&(kind==='all'||(kind==='manual'?manualKinds.has(row.id):manualKinds.get(row.id)===kind)));
return {pocket,pockets,kind,hideDeleted,filtered};
}
inventoryMovements(query={},actor=this.actor){
const {pocket,pockets,kind,filtered}=this.inventoryMovementSelection(query),pageValue=query.page===undefined?'1':query.page;
const {pocket,pockets,kind,hideDeleted,filtered}=this.inventoryMovementSelection(query),pageValue=query.page===undefined?'1':query.page;
if(!['string','number'].includes(typeof pageValue)||!Number.isSafeInteger(Number(pageValue))||Number(pageValue)<1||String(Number(pageValue))!==String(pageValue))fail('流水页码须为正整数');
const total=filtered.length,limit=100,totalPages=Math.max(1,Math.ceil(total/limit)),page=Math.min(Number(pageValue),totalPages);
// 共享范围内筛选后分页;返回专门的盘点投影,不扩展原业务访问权限。
const movements=InventoryChanges.decorate(this,filtered.slice((page-1)*limit,page*limit),actor,this.businessEnv(),{shared:true});
return {pocket,pockets,kind,total,shown:movements.length,limit,pageSize:limit,page,totalPages,hasPrev:page>1,hasNext:page<totalPages,movements};
return {pocket,pockets,kind,hideDeleted,total,shown:movements.length,limit,pageSize:limit,page,totalPages,hasPrev:page>1,hasNext:page<totalPages,movements};
}
inventoryMovementsExport(query={},actor=this.actor){
const {pocket,kind,filtered}=this.inventoryMovementSelection(query);
const {pocket,kind,hideDeleted,filtered}=this.inventoryMovementSelection(query);
if(filtered.length>1048575)fail('超过Excel单表行数上限,请缩小筛选范围');
return {pocket,kind,movements:InventoryChanges.decorate(this,filtered,actor,this.businessEnv(),{shared:true})};
return {pocket,kind,hideDeleted,movements:InventoryChanges.decorate(this,filtered,actor,this.businessEnv(),{shared:true})};
}
inventorySnapshots(query={}){
const date=day(query.date||today()),from=day(query.from||'2000-01-01');