2025-12-25 16:56:45 +08:00

71 lines
2.4 KiB
Python

from appPublic.registerfunction import RegisterFunction
from appPublic.dictObject import DictObject
from appPublic.log import debug, exception, error
from ahserver.serverenv import ServerEnv
from sqlor.dbpools import get_sor_context
from .accounting_config import Accounting
from .bill import write_bill
from .openaccount import openOwnerAccounts, openProviderAccounts, openResellerAccounts, openCustomerAccounts
from .getaccount import getAccountBalance, getCustomerBalance, getAccountByName, get_account_total_amount
from .bizaccount import BizAccounting
from .recharge import RechargeBiz, recharge_accounting
from .consume import ConsumeBiz
async def all_my_accounts(request):
env = request._run_ns
userid = await env.get_user()
userorgid = await env.get_userorgid()
async with get_sor_context(request._run_ns, 'accounting') as sor:
sql = """select b.id, a.name, b.balance_at, c.balance from
subject a, account b,
(select a.* from acc_balance a, (select accountid, max(acc_date) max_date from acc_balance group by accountid) b where a.accountid=b.accountid and a.acc_date=b.max_date) c
where c.accountid = b.id
and b.subjectid = a.id
and b.orgid = ${orgid}$
"""
ns = {'orgid': userorgid}
recs = await sor.sqlExe(sql, ns)
return recs
async def get_accdetail(request, accountid, page=1):
env = request._run_ns
userorgid = await env.get_userorgid()
async with get_sor_context(env, 'accounting') as sor:
sql = """select a.*,
c.name
from acc_detail a, account b, subject c
where b.subjectid = c.id
and a.accountid = b.id
and b.id = ${accountid}$
"""
ns = {
'accountid': accountid,
'page': page,
'sort': 'acc_date desc'
}
ret = await sor.sqlExe(sql, ns)
return ret
return {
'total': 0,
'rows': []
}
def load_accounting():
g = ServerEnv()
g.Accounting = Accounting
g.RechargeBiz = RechargeBiz
g.ConsumeBiz = ConsumeBiz
g.write_bill = write_bill
g.openOwnerAccounts = openOwnerAccounts
g.openProviderAccounts = openProviderAccounts
g.openResellerAccounts = openResellerAccounts
g.openCustomerAccounts = openCustomerAccounts
g.getAccountBalance = getAccountBalance
g.getCustomerBalance = getCustomerBalance
g.getAccountByName = getAccountByName
g.get_account_total_amount = get_account_total_amount
g.BizAccounting = BizAccounting
g.recharge_accounting = recharge_accounting
g.get_accdetail = get_accdetail
g.all_my_accounts = all_my_accounts