- 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
106 lines
2.8 KiB
Plaintext
106 lines
2.8 KiB
Plaintext
|
|
ns = params_kw.copy()
|
|
for k, v in ns.items():
|
|
if v == 'NaN' or v == 'null' or v == '':
|
|
ns[k] = None
|
|
|
|
accountid = ns.get('accountid')
|
|
if not accountid:
|
|
return {
|
|
"widgettype": "Error",
|
|
"options": {
|
|
"title": "参数错误",
|
|
"cwidth": 16,
|
|
"cheight": 9,
|
|
"timeout": 3,
|
|
"message": "账户ID不能为空"
|
|
}
|
|
}
|
|
|
|
credit_limit_amount = float(ns.get('credit_limit', 0) or 0)
|
|
if credit_limit_amount <= 0:
|
|
return {
|
|
"widgettype": "Error",
|
|
"options": {
|
|
"title": "参数错误",
|
|
"cwidth": 16,
|
|
"cheight": 9,
|
|
"timeout": 3,
|
|
"message": "授信额度必须大于0"
|
|
}
|
|
}
|
|
|
|
valid_from = ns.get('valid_from')
|
|
valid_to = ns.get('valid_to')
|
|
remark = ns.get('remark')
|
|
record_id = ns.get('id')
|
|
|
|
user_id = await get_user()
|
|
orgid = await get_userorgid()
|
|
|
|
db = DBPools()
|
|
dbname = get_module_dbname('accounting')
|
|
async with db.sqlorContext(dbname) as sor:
|
|
if record_id:
|
|
sql = """
|
|
UPDATE credit_limit
|
|
SET credit_limit = ${credit_limit}$,
|
|
available_credit = ${credit_limit}$ - used_credit,
|
|
valid_from = ${valid_from}$,
|
|
valid_to = ${valid_to}$,
|
|
remark = ${remark}$,
|
|
updated_at = CURRENT_TIMESTAMP
|
|
WHERE id = ${id}$ AND orgid = ${orgid}$
|
|
"""
|
|
await sor.sqlExe(sql, {
|
|
'credit_limit': credit_limit_amount,
|
|
'valid_from': valid_from,
|
|
'valid_to': valid_to,
|
|
'remark': remark,
|
|
'id': record_id,
|
|
'orgid': orgid
|
|
})
|
|
debug(f'Updated credit limit {record_id} to {credit_limit_amount}')
|
|
else:
|
|
new_id = uuid()
|
|
now = datetime.now()
|
|
data = {
|
|
'id': new_id,
|
|
'accountid': accountid,
|
|
'orgid': orgid,
|
|
'credit_limit': credit_limit_amount,
|
|
'used_credit': 0,
|
|
'available_credit': credit_limit_amount,
|
|
'valid_from': valid_from,
|
|
'valid_to': valid_to,
|
|
'status': 'active',
|
|
'created_at': now,
|
|
'updated_at': now,
|
|
'created_by': user_id,
|
|
'remark': remark
|
|
}
|
|
await sor.C('credit_limit', data)
|
|
debug(f'Created credit limit for {accountid}: {credit_limit_amount}')
|
|
|
|
return {
|
|
"widgettype": "Message",
|
|
"options": {
|
|
"cwidth": 16,
|
|
"cheight": 9,
|
|
"title": "授信额度设置成功",
|
|
"timeout": 3,
|
|
"message": "ok"
|
|
}
|
|
}
|
|
|
|
return {
|
|
"widgettype": "Error",
|
|
"options": {
|
|
"title": "设置失败",
|
|
"cwidth": 16,
|
|
"cheight": 9,
|
|
"timeout": 3,
|
|
"message": "failed"
|
|
}
|
|
}
|