Add confirmed Run Wage Cycle controls to P&O

This commit is contained in:
unimatrixgit 2026-11-15 20:23:04 +01:00
commit 3ba10fb9a6

View file

@ -53,14 +53,15 @@ export class PostbankPayroll{
});
const items=await this.bank.query("SELECT actor_id FROM pb_payroll_items WHERE period=? AND state='pending' ORDER BY actor_id",[period]);
let paid=0,failed=0;
for(const item of items){try{await beforePay();if(await this.pay(period,item.actor_id))paid++;}catch{failed++;}}
for(const item of items){try{if(await this.pay(period,item.actor_id,{beforePay}))paid++;}catch{failed++;}}
if(!failed)await this.bank.query("UPDATE pb_payroll_runs SET state='completed' WHERE period=? AND NOT EXISTS (SELECT 1 FROM pb_payroll_items WHERE period=? AND state='pending')",[period,period]);
return {period,paid,failed};
}
async pay(period,actorId){
async pay(period,actorId,{beforePay=async()=>{}}={}){
return this.bank.transaction(async tx=>{
const item=await tx.first('SELECT * FROM pb_payroll_items WHERE period=? AND actor_id=? FOR UPDATE',[period,actorId]);
if(!item||item.state!=='pending')return false;
await beforePay();
const row=await tx.first('SELECT details_json FROM pb_payroll_payslips WHERE period=? AND actor_id=?',[period,actorId]),slip=JSON.parse(row.details_json);
// Revocation stops an unpaid salary; a frozen record alone never grants eligibility.
const eligible=await readPayrollRecipients(this.central,this.clock());