V3.2.0 结转不依赖考核记录 + 补发查对应月盈亏
1. 结转不依赖考核记录: - 1月有结转但2月/3月无考核记录 → 创建虚拟group(目标=满月,实际=0) - 虚拟记录正常发放结转奖金 - 无客户关联 → 不查盈亏,正常发放 2. 补发查对应月盈亏: - 补发1月 → 查1月亏损表 - 补发2月 → 查2月亏损表 - 当月/结转/累计补发 → 查当月亏损表 - 奖金发放记录新增"盈亏查询月"列 Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -199,14 +199,31 @@ def write_summary_jan(wb, records, loss_data=None, plate_client=None):
|
||||
write_total(ws,rn,1,{'达标':jan_dl})
|
||||
AW(ws)
|
||||
|
||||
def build_payment_records(month, month_data, loss_data, plate_client):
|
||||
"""构建奖金发放记录列表,每条考核应发一行,叠加亏损筛选"""
|
||||
def build_payment_records(month, month_data, all_loss_data, plate_client):
|
||||
"""构建奖金发放记录列表,每条考核应发一行,叠加亏损筛选。
|
||||
all_loss_data: {1: loss_dict, 2: loss_dict, 3: loss_dict_or_None}
|
||||
补发X月 → 查X月盈亏;其他 → 查当月盈亏;无客户 → 正常发放
|
||||
"""
|
||||
# 发放类型→查哪个月盈亏
|
||||
def get_loss_month(cat, settle_month):
|
||||
if '补发1月' in cat: return 1
|
||||
if '补发2月' in cat: return 2
|
||||
if '补发3月' in cat: return 3
|
||||
return settle_month
|
||||
|
||||
records = []
|
||||
for cat, dl in month_data.items():
|
||||
loss_month = get_loss_month(cat, month)
|
||||
loss_data = all_loss_data.get(loss_month)
|
||||
|
||||
for d in dl:
|
||||
client = (plate_client or {}).get(d['车牌'], '')
|
||||
if loss_data:
|
||||
loss_status = loss_data.get(client, '未匹配') if client else '未匹配'
|
||||
|
||||
# 无客户关联(如虚拟结转记录)→ 正常发放
|
||||
if not client:
|
||||
loss_status = '否'
|
||||
elif loss_data:
|
||||
loss_status = loss_data.get(client, '未匹配')
|
||||
else:
|
||||
loss_status = '未匹配' # 无亏损表视为未匹配,不发放
|
||||
|
||||
@@ -222,8 +239,9 @@ def build_payment_records(month, month_data, loss_data, plate_client):
|
||||
'车牌号': d['车牌'],
|
||||
'业务员': d['销售'],
|
||||
'部门': d['部门'],
|
||||
'客户名称': client,
|
||||
'客户名称': client or '(无客户关联)',
|
||||
'发放类型': cat,
|
||||
'盈亏查询月': f'{loss_month}月',
|
||||
'考核应发': 考核应发,
|
||||
'客户盈亏': loss_status,
|
||||
'亏损拦截': 拦截,
|
||||
@@ -235,7 +253,7 @@ def write_payment_record_sheet(wb, month, payment_records):
|
||||
"""写入奖金发放记录sheet"""
|
||||
ws = wb.create_sheet(f'{month}月奖金发放记录')
|
||||
|
||||
headers = ['车牌号','业务员','部门','客户名称','发放类型',
|
||||
headers = ['车牌号','业务员','部门','客户名称','发放类型','盈亏查询月',
|
||||
'考核应发','客户盈亏','亏损拦截','实发金额']
|
||||
WH(ws, headers)
|
||||
|
||||
@@ -246,25 +264,24 @@ def write_payment_record_sheet(wb, month, payment_records):
|
||||
rn = 2
|
||||
for r in sorted(payment_records, key=lambda x: (x['业务员'], x['车牌号'])):
|
||||
WR(ws, rn, [r['车牌号'], r['业务员'], r['部门'], r['客户名称'], r['发放类型'],
|
||||
r.get('盈亏查询月',''),
|
||||
R(r['考核应发']), r['客户盈亏'], R(r['亏损拦截']), R(r['实发金额'])])
|
||||
# 颜色
|
||||
if r['客户盈亏'] == '是':
|
||||
for ci in [7, 8, 9]: ws.cell(row=rn, column=ci).fill = red_fill
|
||||
for ci in [8, 9, 10]: ws.cell(row=rn, column=ci).fill = red_fill
|
||||
elif r['客户盈亏'] == '未匹配':
|
||||
for ci in [7, 8, 9]: ws.cell(row=rn, column=ci).fill = yellow_fill
|
||||
for ci in [8, 9, 10]: ws.cell(row=rn, column=ci).fill = yellow_fill
|
||||
elif r['实发金额'] > 0:
|
||||
ws.cell(row=rn, column=9).fill = green_fill
|
||||
ws.cell(row=rn, column=10).fill = green_fill
|
||||
rn += 1
|
||||
|
||||
# 合计行
|
||||
total_应发 = sum(r['考核应发'] for r in payment_records)
|
||||
total_拦截 = sum(r['亏损拦截'] for r in payment_records)
|
||||
total_实发 = sum(r['实发金额'] for r in payment_records)
|
||||
rn += 1
|
||||
WR(ws, rn, ['', '', '', '', '合计', R(total_应发), '', R(total_拦截), R(total_实发)])
|
||||
for ci in range(5, 10): ws.cell(row=rn, column=ci).font = Font(bold=True)
|
||||
WR(ws, rn, ['', '', '', '', '合计', '', R(total_应发), '', R(total_拦截), R(total_实发)])
|
||||
for ci in range(5, 11): ws.cell(row=rn, column=ci).font = Font(bold=True)
|
||||
|
||||
ws.auto_filter.ref = f"A1:I1"
|
||||
ws.auto_filter.ref = f"A1:J1"
|
||||
AW(ws)
|
||||
return payment_records
|
||||
|
||||
@@ -428,7 +445,10 @@ def write_salesperson_sheet(wb, person, dept, settle_month, D, G, month_data, ve
|
||||
if g_cur: break
|
||||
if not g_cur: continue
|
||||
|
||||
first = g_cur['recs'][0]
|
||||
if g_cur['recs']:
|
||||
first = g_cur['recs'][0]
|
||||
else:
|
||||
first = {'合同编号':'','客户名称':'(无考核记录)','考核目标':g_cur.get('考核目标','')}
|
||||
mkm = g_cur['目标km']
|
||||
|
||||
# 第1行:车辆信息 + 各月里程/目标
|
||||
|
||||
Reference in New Issue
Block a user