支持按账号自定义单据默认经办人
This commit is contained in:
1 parent
476f81a8d1
commit
81584dc45a
9 files changed
+152
-15
No files matched your search
+13
-1
@@ -80,6 +80,18 @@ class Ledger {
|
||||
run(sql,...args){return this.db.prepare(sql).run(...args);}
|
||||
meta(key,fallback=null){const v=this.one('SELECT value FROM meta WHERE key=?',key);return v?JSON.parse(v.value):fallback;}
|
||||
setMeta(key,value){this.run('INSERT INTO meta VALUES (?,?) ON CONFLICT(key) DO UPDATE SET value=excluded.value',key,JSON.stringify(value));}
|
||||
salespersonSettings(){return {...{owner:'麦麦',assistant:'张'},...this.meta('salesperson-settings',{})};}
|
||||
defaultSalesperson(actor){return this.salespersonSettings()[actor.role]||actor.name;}
|
||||
saveSalespersonSettings(input,actor){
|
||||
owner(actor);const result={};
|
||||
for(const role of ['owner','assistant']){
|
||||
const label=(role==='owner'?'麦麦':'助理')+'账号默认经办人';
|
||||
if(typeof input?.[role]!=='string')fail(label+'请填写1~30字');
|
||||
result[role]=text(input[role],label,30);
|
||||
}
|
||||
this.setMeta('salesperson-settings',result);this.audit('salesperson-settings','更新默认经办人',actor,result);
|
||||
return {ok:true,salespersonSettings:result};
|
||||
}
|
||||
audit(entity,action,actor,detail){this.run('INSERT INTO audit(entity,action,actor,detail,created) VALUES (?,?,?,?,?)',entity,action,actor.name,JSON.stringify(detail),now());}
|
||||
transact(key,actor,payload,fn){
|
||||
if(!/^[a-zA-Z0-9_-]{16,100}$/.test(String(key)))fail('缺少有效操作号,请刷新后重试');
|
||||
@@ -212,7 +224,7 @@ class Ledger {
|
||||
const autoNumber=prior?.paper_date&&prior.paper_number.match(/^\d{8}-?(\d+)$/);
|
||||
const paper=newNumber?this.paperNumber(date,true):autoNumber?date.replaceAll('-','')+autoNumber[1]:prior.paper_number;
|
||||
if(this.one("SELECT id FROM orders WHERE REPLACE(paper_number,'-','')=? AND id<>?",paper.replaceAll('-',''),id||''))fail('该日期已有相同纸单号,请保留原日期或取消后重开',409);
|
||||
const common=[date,text(input.customer,'客户称呼',60,true),text(input.salesperson||actor.name,'开单人',30),text(input.note,'客户单备注',240,true),paper,JSON.stringify(lines),discount,total];
|
||||
const common=[date,text(input.customer,'客户称呼',60,true),text(input.salesperson||prior?.salesperson||this.defaultSalesperson(actor),'开单人',30),text(input.note,'客户单备注',240,true),paper,JSON.stringify(lines),discount,total];
|
||||
if(id){
|
||||
this.run('UPDATE orders SET date=?,customer=?,salesperson=?,note=?,paper_number=?,lines=?,discount=?,total=? WHERE id=?',...common,id);this.touch(id);
|
||||
} else {
|
||||
|
||||
Reference in new issue
Block a user