2025-07-16 14:32:14 +08:00

29 lines
893 B
Python

from datetime import datetime
from appPublic.uniqueID import getID
from appPublic.timeUtils import strdate_add
from accounting.businessdate import get_business_date
async def accounting_ledger(sor):
rd = await get_business_date(sor)
d = strdate_add(rd, days=-1)
print(f'{rd=}, {d=}')
ts = datetime.now()
sql = """
select a.accounting_orgid,
a.subjectid,
sum(case a.balance_at when '1' then b.balance else 0 end) as c_balance,
sum(case a.balance_at when '0' then b.balance else 0 end) as d_balance
from account a, acc_balance b
where a.id = b.accountid
and b.acc_date = ${acc_date}$
group by a.accounting_orgid, a.subjectid
"""
recs = await sor.sqlExe(sql, {'acc_date':d})
await sor.sqlExe('delete from ledger where acc_date=${acc_date}$',
{'acc_date':d})
for r in recs:
r['id'] = getID()
r['acc_date'] = d
await sor.C('ledger', r.copy())