salescrm/b/promoting/settle_accounts.dspy
2025-10-27 15:50:44 +08:00

53 lines
2.8 KiB
Plaintext
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

async def settle_accounts(ns):
"""供应商结算统计 年、月、日、周、季
0实时结算1:日结2:周结3:月结4:季结5年结
参数id 用户id
"""
db = DBPools()
async with db.sqlorContext('kboss') as sor:
try:
account = await sor.R('account', {'orgid':ns['orgid'],'subjectid':ns['subjectid']})
# 购买/购买冲正
BUY = 0
BUY_REVERSE = 0
if len(account) >= 1:
newdate = await get_business_date(sor=None)
provider = await sor.R('provider',{'orgid':ns['orgid']})
if provider[0]['settle_mode'] == '1' or provider[0]['settle_mode'] == '0':
date = strdate_add(newdate,-1,0,0)
nsa = {'accountid':account[0]['id'],'acc_date':date}
sql = """select * from acc_detail where acc_date = ${acc_date}$ and accountid = ${accountid}$ and (summary = 'BUY' or summary = 'BUY_REVERSE');"""
bill = await sor.sqlExe(sql,nsa)
if len(bill) >= 1:
for i in bill:
if i['summary'] == 'BUY':
BUY += float(i['amount'])
elif i['summary'] == 'BUY_REVERSE':
BUY_REVERSE += float(i['amount'])
elif provider[0]['settle_mode'] == '2':
date = strdate_add(newdate, -7, 0, 0)
elif provider[0]['settle_mode'] == '3':
date = strdate_add(newdate, 0, -1, 0)
elif provider[0]['settle_mode'] == '4':
date = strdate_add(newdate, 0, -3, 0)
elif provider[0]['settle_mode'] == '5':
date = strdate_add(newdate, 0, 0, -1)
nss = {'accountid':account[0]['id'], 'sdate': date,'edate': newdate}
sql = """select * from acc_detail where acc_date > ${sdate}$ and acc_date <= ${edate}$ and accountid = ${accountid}$ and (summary = 'BUY' or summary = 'BUY_REVERSE');"""
if provider[0]['settle_mode'] != '0' and provider[0]['settle_mode'] != '1':
bill = await sor.sqlExe(sql, nss)
if len(bill) >= 1:
for i in bill:
if i['summary'] == 'BUY':
BUY += float(i['amount'])
elif i['summary'] == 'BUY_REVERSE':
BUY_REVERSE += float(i['amount'])
else:
bill = ''
return {'status': True, 'data': bill,'BUY':BUY,'BUY_REVERSE':BUY_REVERSE}
except Exception as e:
raise e
return {'status': False, 'msg': '获取失败'}
ret = await settle_accounts(params_kw)
return ret