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, openRetailRelationshipAccounts from .getaccount import getAccountBalance, getCustomerBalance, getAccountByName, get_account_total_amount from .bizaccount import BizAccounting from .recharge import RechargeBiz, recharge_accounting from .consume import consume_accounting 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, case when c.balance is null then 0.00 else c.balance end as balance from subject a, account b left join ( 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 on c.accountid = b.id where 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.consume_accounting = consume_accounting 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 g.openRetailRelationshipAccounts = openRetailRelationshipAccounts