整合公共店铺配置与动态员工管理,保留最新订单功能及历史账兼容
This commit is contained in:
commit
b87f774386
84 files changed
+1622
-715
No files matched your search
@@ -2,7 +2,7 @@
|
||||
let createMode='direct',priceLockRequest=0,priceLockDeliveryId='',currentPriceLock=null,priceLockPoolRead=null,priceLockPoolError='';
|
||||
const priceLockDraftKey=()=>`mm-price-lock-draft-${session.user.id}`;
|
||||
const priceLockDeliveryKey=id=>`mm-price-lock-delivery-${session.user.id}-${id}`;
|
||||
const priceLockPayerName=payer=>({owner:'麦麦',assistant:'娜娜',assistant2:'小昊'})[payer]||'待补';
|
||||
const priceLockPayerName=payer=>payer?teamMemberName(payer):'待补';
|
||||
function priceLockCreateControls(){return `<div class="create-mode-controls" role="group" aria-label="开单方式">${button('直接开单','create-mode',createMode==='direct'?'primary':'',`data-mode="direct"`)}${button('锁价','create-mode',createMode==='lock'?'primary':'',`data-mode="lock"`)}</div>`;}
|
||||
function invalidatePriceLockViews(){++priceLockRequest;}
|
||||
function priceLockReadDraft(key){try{return JSON.parse(localStorage.getItem(key)||'null');}catch{return null;}}
|
||||
@@ -65,7 +65,7 @@ function priceLockPoolPreview(date,quantity,lineIndex=0,form=$('#price-lock-crea
|
||||
const fromAmount=LedgerCalc.poolMaterialAmount(pool.totalAmount,pool.totalMg,prefixMg),allocations=[],parts=(pool.purchases||[]).flatMap(purchase=>purchase.allocations||[{payer:purchase.payer,amount:purchase.amount}]);
|
||||
let skip=fromAmount,left=amount,zeroPayer='';
|
||||
for(const part of parts){
|
||||
if(!['owner','assistant','assistant2'].includes(part.payer)||!Number.isSafeInteger(part.amount)||part.amount<=0)throw new Error('料池付款来源未完整读到,请刷新料池。');
|
||||
if(!teamMemberKeys().includes(part.payer)||!Number.isSafeInteger(part.amount)||part.amount<=0)throw new Error('料池付款来源未完整读到,请刷新料池。');
|
||||
if(skip>=part.amount){skip-=part.amount;continue;}
|
||||
zeroPayer||=part.payer;const value=Math.min(left,part.amount-skip),saved=allocations.find(item=>item.payer===part.payer);
|
||||
if(value){if(saved)saved.amount+=value;else allocations.push({payer:part.payer,amount:value});}left-=value;skip=0;if(!left)break;
|
||||
@@ -323,7 +323,7 @@ async function submitPriceLockForm(form){
|
||||
const locks=priceLockLines(lock),items=data.lines||[{...data.line,inventory:data.inventory,extraMaterial:data.extraMaterial}];if(items.length!==locks.length)throw new Error('请逐件填写全部锁价商品后整单交付。');
|
||||
const costs=items.map((line,index)=>{const item=locks[index];if(data.lines&&line.lineId!==item.id)throw new Error('交付商品与原锁记录不一致,请重新读取。');return priceLockDeliveryRowCost(item,line.quantity,line.extraMaterial,index,form);});
|
||||
validateIssueDraft({lines:items,fee_items:data.fee_items,discount:data.discount,rounding_mode:'yuan'},{requireIdentity:false});
|
||||
items.forEach((line,index)=>{if(pocketCountsEnabled(line.inventory.pocket)&&!['stocked','receive'].includes(line.inventory.countSource))throw new Error('请选择商品 '+(index+1)+' 的成品来源。');if(!state.pockets.includes(line.inventory.pocket)||!['receive','stocked'].includes(line.inventory.original))throw new Error(`请选择商品 ${index+1} 的实际出库货盘,并确认原锁金料是否已入库。`);if(costs[index].extraMg&&line.extraMaterial?.source!=='pool'&&(!['receive','stocked'].includes(line.inventory.extra)||!['owner','assistant','assistant2'].includes(line.extraMaterial?.payer)||!line.extraMaterial?.verified))throw new Error(`请填写商品 ${index+1} 的补重料价、付款人、是否已入库,并确认实际付款。`);});
|
||||
items.forEach((line,index)=>{if(pocketCountsEnabled(line.inventory.pocket)&&!['stocked','receive'].includes(line.inventory.countSource))throw new Error('请选择商品 '+(index+1)+' 的成品来源。');if(!state.pockets.includes(line.inventory.pocket)||!['receive','stocked'].includes(line.inventory.original))throw new Error(`请选择商品 ${index+1} 的实际出库货盘,并确认原锁金料是否已入库。`);if(costs[index].extraMg&&line.extraMaterial?.source!=='pool'&&(!['receive','stocked'].includes(line.inventory.extra)||!teamMemberKeys().includes(line.extraMaterial?.payer)||!line.extraMaterial?.verified))throw new Error(`请填写商品 ${index+1} 的补重料价、付款人、是否已入库,并确认实际付款。`);});
|
||||
const total=LedgerCalc.orderTotal(items.map(line=>LedgerCalc.sale(line).sale),LedgerCalc.cents(data.discount),'yuan'),difference=total.total-lock.netReceived;if(difference>0&&isCreditCardAccount(data.settlement.account)&&!creditCardAvailable())throw new Error('信用卡收款暂未准备好,请刷新后重新核对。');if(difference&&!data.settlement.verified)throw new Error('请先核实客户补款或退款已实际完成。');if(!data.verified)throw new Error('请核对各件实物、实际成本、库存来源与整单客户收付款后确认交付。');
|
||||
const actual=line=>({quantity:line.quantity,...(pocketCountsEnabled(line.inventory?.pocket||line.pocket)?{stockCount:stockCountValue(line.stockCount)}:{}),laborRate:line.laborRate,laborMode:line.laborMode,pieces:line.pieces,charges:line.charges,payer:line.payer,costParts:{labor:line.costParts.labor,accessories:line.costParts.accessories,other:line.costParts.other},costLabor:line.costLabor,costPayers:line.costPayers});
|
||||
if(data.lines)data.lines=items.map((line,index)=>({...actual(line),lineId:line.lineId,inventory:{pocket:line.inventory.pocket,original:line.inventory.original,...(pocketCountsEnabled(line.inventory.pocket)?{countSource:line.inventory.countSource}:{}),...(costs[index].extraMg?{extra:line.inventory.extra}:{})},...(costs[index].extraMg?{extraMaterial:line.extraMaterial}:{})}));
|
||||
@@ -349,13 +349,13 @@ function priceLockActivityRows(activity){
|
||||
function priceLockActivityHTML(activity){
|
||||
if(!activity?.summary?.eventCount)return '';
|
||||
const s=activity.summary,rows=priceLockActivityRows(activity);
|
||||
return `<section class="panel lock-activity"><h2>锁价实际收付</h2><p class="small muted">${e(activity.from===activity.date?activity.date:activity.from+' 至 '+activity.date)}实际发生的锁价收退款与支出。此区不随订单搜索或状态筛选变化;每日对账归集这些收付。待交付不计销售和利润;交付日计入完整订单利润,原锁料款不重复记支出。</p><div class="lock-activity-summary"><span>客户实收<strong>¥${yuan(s.receipt)}</strong></span><span>客户实退<strong>¥${yuan(s.refund)}</strong></span><span>麦麦实际支出<strong>¥${yuan(s.ownerOutlay)}</strong></span><span>娜娜实际支出<strong>¥${yuan(s.assistantOutlay)}</strong></span></div><details><summary>查看 ${rows.length} 项收付记录</summary><div class="table-wrap"><table class="lock-activity-table"><thead><tr><th>日期/锁价单</th><th>项目/客户</th><th>账户/付款人</th><th class="number">金额</th></tr></thead><tbody>${rows.map(item=>`<tr><td>${e(item.date)}<br><button class="link-button" data-action="open-price-lock" data-id="${e(item.price_lock_id)}">${e(item.number||'锁价记录')}</button></td><td>${e(item.activityType)} · ${e(item.activityName)}<div class="small muted">${e(item.customer)}</div></td><td>${e(item.who)}</td><td class="number">${item.amount==null?'待补齐':'¥'+yuan(item.amount)}</td></tr>`).join('')}</tbody></table></div></details></section>`;
|
||||
return `<section class="panel lock-activity"><h2>锁价实际收付</h2><p class="small muted">${e(activity.from===activity.date?activity.date:activity.from+' 至 '+activity.date)}实际发生的锁价收退款与支出。此区不随订单搜索或状态筛选变化;每日对账归集这些收付。待交付不计销售和利润;交付日计入完整订单利润,原锁料款不重复记支出。</p><div class="lock-activity-summary"><span>客户实收<strong>¥${yuan(s.receipt)}</strong></span><span>客户实退<strong>¥${yuan(s.refund)}</strong></span><span>${e(teamMemberName("owner"))}实际支出<strong>¥${yuan(s.ownerOutlay)}</strong></span><span>${e(teamMemberName("assistant"))}实际支出<strong>¥${yuan(s.assistantOutlay)}</strong></span></div><details><summary>查看 ${rows.length} 项收付记录</summary><div class="table-wrap"><table class="lock-activity-table"><thead><tr><th>日期/锁价单</th><th>项目/客户</th><th>账户/付款人</th><th class="number">金额</th></tr></thead><tbody>${rows.map(item=>`<tr><td>${e(item.date)}<br><button class="link-button" data-action="open-price-lock" data-id="${e(item.price_lock_id)}">${e(item.number||'锁价记录')}</button></td><td>${e(item.activityType)} · ${e(item.activityName)}<div class="small muted">${e(item.customer)}</div></td><td>${e(item.who)}</td><td class="number">${item.amount==null?'待补齐':'¥'+yuan(item.amount)}</td></tr>`).join('')}</tbody></table></div></details></section>`;
|
||||
}
|
||||
function priceLockActivityText(activity){
|
||||
if(!activity?.summary?.eventCount)return [];
|
||||
const s=activity.summary;return ['锁价实际收付(按实际发生日期,不重复计原锁付款;待交付不计销售和利润)',`客户实收 ¥${yuan(s.receipt)};客户实退 ¥${yuan(s.refund)};麦麦实际支出 ¥${yuan(s.ownerOutlay)};娜娜实际支出 ¥${yuan(s.assistantOutlay)}`,...priceLockActivityRows(activity).map(item=>`${item.date} / ${item.number||'锁价记录'} / ${item.customer} / ${item.activityType} / ${item.activityName} / ${item.who} / ${item.amount==null?'待补齐':'¥'+yuan(item.amount)}`),''];
|
||||
const s=activity.summary;return ['锁价实际收付(按实际发生日期,不重复计原锁付款;待交付不计销售和利润)',`客户实收 ¥${yuan(s.receipt)};客户实退 ¥${yuan(s.refund)};${teamMemberName("owner")}实际支出 ¥${yuan(s.ownerOutlay)};${teamMemberName("assistant")}实际支出 ¥${yuan(s.assistantOutlay)}`,...priceLockActivityRows(activity).map(item=>`${item.date} / ${item.number||'锁价记录'} / ${item.customer} / ${item.activityType} / ${item.activityName} / ${item.who} / ${item.amount==null?'待补齐':'¥'+yuan(item.amount)}`),''];
|
||||
}
|
||||
function priceLockInventoryCreditHTML(order){
|
||||
if(!order.assistantInventoryCredit)return '';
|
||||
return `<div class="note">留在自有货盘的金料/退回货品由娜娜垫付 <strong>¥${yuan(order.assistantInventoryCredit)}</strong>,已在货款结算中抵扣。${order.assistantInventoryCreditExplanation?`<div class="small">${e(order.assistantInventoryCreditExplanation)}</div>`:''}<div class="small">抵扣后货款待结 ¥${yuan(order.costDue)};利润待结 ¥${yuan(order.profitDue)}。库存垫资只抵扣结算,不重复扣减订单成本或利润。</div></div>`;
|
||||
return `<div class="note">留在自有货盘的金料/退回货品由${e(teamMemberName("assistant"))}垫付 <strong>¥${yuan(order.assistantInventoryCredit)}</strong>,已在货款结算中抵扣。${order.assistantInventoryCreditExplanation?`<div class="small">${e(order.assistantInventoryCreditExplanation)}</div>`:''}<div class="small">抵扣后货款待结 ¥${yuan(order.costDue)};利润待结 ¥${yuan(order.profitDue)}。库存垫资只抵扣结算,不重复扣减订单成本或利润。</div></div>`;
|
||||
}
|
||||
Reference in new issue
Block a user