diff --git a/excel_writer.py b/excel_writer.py index bccc0f6..233e1be 100644 --- a/excel_writer.py +++ b/excel_writer.py @@ -340,12 +340,15 @@ def write_salesperson_sheet(wb, person, dept, settle_month, D, G, month_data, ve def write_vehicle_tracking_sheet(wb, settle_month, G, master_vehicles, vehicle_payments, vehicle_info): ws = wb.create_sheet('车辆考核追踪') + wrap_align = Alignment(wrap_text=True, vertical='top') + + # 表头:每月用一列"业务员/里程/目标/达标"(多人换行) headers = ['车牌号','车架号','归属公司','车型','考核目标','月度奖励金额'] for m in range(1, settle_month+1): - headers += [f'{m}月业务员',f'{m}月应考核',f'{m}月实际',f'{m}月达标'] + headers.append(f'{m}月考核明细') if settle_month >= 2: - headers += ['累计应完成','累计实际','累计达标'] - headers += ['本月发放金额','发放给谁','发放类型','累计已发期数','累计已发金额','剩余可发期数'] + headers += ['累计里程/目标','累计达标'] + headers += ['本月发放明细','累计已发期数','累计已发金额','剩余可发期数'] WH(ws, headers) rn=2 @@ -355,31 +358,46 @@ def write_vehicle_tracking_sheet(wb, settle_month, G, master_vehicles, vehicle_p pays=vehicle_payments.get(plate, []) row=[plate,mv.get('车架号',''),mv.get('归属公司',''),mv.get('车型确定',''), info.get('考核目标',''),info.get('月度奖励',0) or ''] + cum_t=0; cum_a=0 for m in range(1, settle_month+1): mgs=[(k,g) for k,g in G.get(m,{}).items() if k[0]==plate] if mgs: - persons=', '.join(sorted(set(g['销售'] for _,g in mgs))) - ts=sum(g['应考核'] for _,g in mgs); As=sum(g['实际'] for _,g in mgs) - q='达标' if any(g['有达标'] for _,g in mgs) else '未达标' - cum_t+=ts; cum_a+=As - row+=[persons,R(ts),R(As),q] + # 每个(车牌,销售)组一行,换行显示 + lines = [] + for _,g in sorted(mgs, key=lambda x: x[0][1]): + t=g['应考核']; a=g['实际'] + cum_t+=t; cum_a+=a + q='达标' if g['有达标'] else '未达标' + lines.append(f"{g['销售']}: {R(a,0)}/{R(t,0)} {q}") + row.append('\n'.join(lines)) else: - row+=['','','',''] - if settle_month>=2: - row+=[R(cum_t),R(cum_a),'达标' if (cum_a>=cum_t and cum_t>0) else '未达标'] + row.append('') - # 本月发放(截至settle_month) + if settle_month>=2: + cum_q='达标' if (cum_a>=cum_t and cum_t>0) else '未达标' + row+=[f'{R(cum_a,0)}/{R(cum_t,0)}', cum_q] + + # 本月发放明细(多人多类型换行) tp=[p for p in pays if p['结算月']==settle_month] if tp: - row+=[R(sum(p['金额'] for p in tp)),', '.join(sorted(set(p['业务员'] for p in tp))), - ', '.join(sorted(set(p['类型'] for p in tp)))] + pay_lines = [] + for p in sorted(tp, key=lambda x: x['业务员']): + pay_lines.append(f"{p['业务员']}: {R(p['金额'])}({p['类型']})") + row.append('\n'.join(pay_lines)) else: - row+=[0,'',''] + row.append('') # 奖金池(截至settle_month) pays_to_date=[p for p in pays if p['结算月']<=settle_month] tp_count=len(pays_to_date); tp_amt=sum(p['金额'] for p in pays_to_date) row+=[tp_count,R(tp_amt) if tp_amt>0 else 0,12-tp_count] - WR(ws,rn,row); rn+=1 + + WR(ws,rn,row) + # 对含换行的单元格设置自动换行 + for ci in range(len(row)): + cell = ws.cell(row=rn, column=ci+1) + if isinstance(cell.value, str) and '\n' in cell.value: + cell.alignment = wrap_align + rn+=1 AW(ws)