- Add hub.ui as main entry with stat cards (total/used/available/usage%) - Add credit_overview.ui for user's own credit visualization with progress bars - Add credit_manage.ui for distributor sales to manage customer credits - Add set_credit_form.ui and set_customer_credit.dspy for credit adjustment - Add credit_summary.dspy API for stats data - Enhance creditlimit.py with get_credit_stats, get_my_credit_list, get_all_customer_credits - Register new functions in init.py with ServerEnv
111 lines
3.8 KiB
Python
111 lines
3.8 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, openRetailRelationshipAccounts
|
|
from .getaccount import getAccountBalance, getCustomerBalance, getAccountByName, get_account_total_amount
|
|
from .stats import get_accounting_stats
|
|
from .recharge import RechargeBiz, recharge_accounting
|
|
from .consume import consume_accounting
|
|
from .creditlimit import get_credit_limit_for_account, update_used_credit, set_credit_limit, get_credit_stats, get_my_credit_list, get_all_customer_credits
|
|
|
|
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,
|
|
b.balance
|
|
from
|
|
subject a,
|
|
account b
|
|
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.recharge_accounting = recharge_accounting
|
|
g.get_accdetail = get_accdetail
|
|
g.all_my_accounts = all_my_accounts
|
|
g.openRetailRelationshipAccounts = openRetailRelationshipAccounts
|
|
g.get_accounting_stats = get_accounting_stats
|
|
g.get_credit_limit_for_account = get_credit_limit_for_account
|
|
g.update_used_credit = update_used_credit
|
|
g.set_credit_limit = set_credit_limit
|
|
g.get_credit_stats = get_credit_stats
|
|
g.get_my_credit_list = get_my_credit_list
|
|
g.get_all_customer_credits = get_all_customer_credits
|
|
g.get_credit_stats_web = get_credit_stats_web
|
|
g.get_my_credits_web = get_my_credits_web
|
|
g.get_all_credits_web = get_all_credits_web
|
|
|
|
|
|
async def get_credit_stats_web(request):
|
|
"""Web wrapper for get_credit_stats - used in Jinja2 .ui templates"""
|
|
env = request._run_ns
|
|
userorgid = await env.get_userorgid()
|
|
async with get_sor_context(env, 'accounting') as sor:
|
|
return await get_credit_stats(sor, userorgid)
|
|
|
|
|
|
async def get_my_credits_web(request):
|
|
"""Web wrapper for get_my_credit_list - used in Jinja2 .ui templates"""
|
|
env = request._run_ns
|
|
userorgid = await env.get_userorgid()
|
|
async with get_sor_context(env, 'accounting') as sor:
|
|
return await get_my_credit_list(sor, userorgid)
|
|
|
|
|
|
async def get_all_credits_web(request):
|
|
"""Web wrapper for get_all_customer_credits - used in Jinja2 .ui templates"""
|
|
env = request._run_ns
|
|
userorgid = await env.get_userorgid()
|
|
status_filter = getattr(request, '_params_kw', {}).get('status', None) if hasattr(request, '_params_kw') else None
|
|
async with get_sor_context(env, 'accounting') as sor:
|
|
return await get_all_customer_credits(sor, userorgid, status_filter)
|