accountant-expert by personamanagmentlayer/pcl
npx skills add https://github.com/personamanagmentlayer/pcl --skill accountant-expert为会计系统、财务报告、税务合规和现代会计技术提供专业指导。
from decimal import Decimal
from datetime import datetime
from enum import Enum
from typing import List
class AccountType(Enum):
ASSET = "asset"
LIABILITY = "liability"
EQUITY = "equity"
REVENUE = "revenue"
EXPENSE = "expense"
class Account:
def __init__(self, code: str, name: str, account_type: AccountType):
self.code = code
self.name = name
self.type = account_type
self.balance = Decimal('0')
self.debit_total = Decimal('0')
self.credit_total = Decimal('0')
def is_debit_normal(self) -> bool:
"""检查账户是否通常为借方余额"""
return self.type in [AccountType.ASSET, AccountType.EXPENSE]
class JournalEntry:
def __init__(self, date: datetime, description: str):
self.id = self.generate_entry_id()
self.date = date
self.description = description
self.lines = []
self.posted = False
def add_line(self, account: Account, debit: Decimal = None,
credit: Decimal = None):
"""向日记账分录添加行"""
if debit and credit:
raise ValueError("Cannot have both debit and credit")
self.lines.append({
"account": account,
"debit": debit or Decimal('0'),
"credit": credit or Decimal('0')
})
def validate(self) -> bool:
"""验证日记账分录(借方必须等于贷方)"""
total_debits = sum(line["debit"] for line in self.lines)
total_credits = sum(line["credit"] for line in self.lines)
return total_debits == total_credits
def post(self) -> bool:
"""将日记账分录过账到分类账"""
if not self.validate():
raise ValueError("Entry does not balance")
for line in self.lines:
account = line["account"]
if line["debit"]:
account.debit_total += line["debit"]
if line["credit"]:
account.credit_total += line["credit"]
# 根据账户类型更新余额
if account.is_debit_normal():
account.balance = account.debit_total - account.credit_total
else:
account.balance = account.credit_total - account.debit_total
self.posted = True
return True
广告位招租
在这里展示您的产品或服务
触达数万 AI 开发者,精准高效
class FinancialStatements:
def __init__(self, company_name: str, period_end: datetime):
self.company_name = company_name
self.period_end = period_end
self.accounts = []
def generate_balance_sheet(self) -> dict:
"""生成资产负债表"""
assets = self.sum_accounts_by_type(AccountType.ASSET)
liabilities = self.sum_accounts_by_type(AccountType.LIABILITY)
equity = self.sum_accounts_by_type(AccountType.EQUITY)
# 计算留存收益
revenue = self.sum_accounts_by_type(AccountType.REVENUE)
expenses = self.sum_accounts_by_type(AccountType.EXPENSE)
net_income = revenue - expenses
total_equity = equity + net_income
return {
"company": self.company_name,
"period_end": self.period_end,
"assets": {
"current_assets": self.get_current_assets(),
"non_current_assets": self.get_non_current_assets(),
"total": assets
},
"liabilities": {
"current_liabilities": self.get_current_liabilities(),
"non_current_liabilities": self.get_non_current_liabilities(),
"total": liabilities
},
"equity": {
"share_capital": equity,
"retained_earnings": net_income,
"total": total_equity
},
"balanced": assets == (liabilities + total_equity)
}
def generate_income_statement(self, period_start: datetime,
period_end: datetime) -> dict:
"""生成利润表(损益表)"""
revenue = self.sum_accounts_by_type(AccountType.REVENUE)
expenses = self.sum_accounts_by_type(AccountType.EXPENSE)
gross_profit = revenue - self.get_cogs()
operating_expenses = self.get_operating_expenses()
operating_income = gross_profit - operating_expenses
interest_expense = self.get_interest_expense()
tax_expense = self.calculate_tax(operating_income - interest_expense)
net_income = operating_income - interest_expense - tax_expense
return {
"company": self.company_name,
"period": f"{period_start.date()} to {period_end.date()}",
"revenue": revenue,
"cogs": self.get_cogs(),
"gross_profit": gross_profit,
"operating_expenses": operating_expenses,
"operating_income": operating_income,
"interest_expense": interest_expense,
"tax_expense": tax_expense,
"net_income": net_income,
"eps": self.calculate_eps(net_income)
}
def generate_cash_flow_statement(self) -> dict:
"""生成现金流量表"""
return {
"operating_activities": self.calculate_operating_cash_flow(),
"investing_activities": self.calculate_investing_cash_flow(),
"financing_activities": self.calculate_financing_cash_flow(),
"net_change_in_cash": self.calculate_net_cash_change(),
"beginning_cash": self.get_beginning_cash(),
"ending_cash": self.get_ending_cash()
}
class TaxCalculator:
def calculate_corporate_tax(self, taxable_income: Decimal,
jurisdiction: str = "US") -> dict:
"""计算企业所得税"""
if jurisdiction == "US":
tax_rate = Decimal('0.21') # 联邦税率
elif jurisdiction == "UK":
tax_rate = Decimal('0.19')
else:
tax_rate = Decimal('0.25') # 默认税率
tax_amount = taxable_income * tax_rate
return {
"taxable_income": taxable_income,
"tax_rate": tax_rate,
"tax_amount": tax_amount.quantize(Decimal('0.01')),
"effective_rate": tax_rate,
"jurisdiction": jurisdiction
}
def calculate_vat(self, net_amount: Decimal, vat_rate: Decimal) -> dict:
"""计算增值税/销售税"""
vat_amount = net_amount * vat_rate
gross_amount = net_amount + vat_amount
return {
"net_amount": net_amount,
"vat_rate": vat_rate,
"vat_amount": vat_amount.quantize(Decimal('0.01')),
"gross_amount": gross_amount.quantize(Decimal('0.01'))
}
def calculate_depreciation(self, cost: Decimal, salvage_value: Decimal,
useful_life_years: int,
method: str = "straight_line") -> List[dict]:
"""计算折旧计划表"""
if method == "straight_line":
annual_depreciation = (cost - salvage_value) / useful_life_years
schedule = []
book_value = cost
for year in range(1, useful_life_years + 1):
depreciation = annual_depreciation
book_value -= depreciation
schedule.append({
"year": year,
"depreciation": depreciation.quantize(Decimal('0.01')),
"accumulated_depreciation": (annual_depreciation * year).quantize(Decimal('0.01')),
"book_value": book_value.quantize(Decimal('0.01'))
})
return schedule
class FinancialRatios:
@staticmethod
def current_ratio(current_assets: Decimal, current_liabilities: Decimal) -> Decimal:
"""流动比率:流动资产 / 流动负债"""
return (current_assets / current_liabilities).quantize(Decimal('0.01'))
@staticmethod
def quick_ratio(current_assets: Decimal, inventory: Decimal,
current_liabilities: Decimal) -> Decimal:
"""速动比率:(流动资产 - 存货)/ 流动负债"""
return ((current_assets - inventory) / current_liabilities).quantize(Decimal('0.01'))
@staticmethod
def debt_to_equity(total_debt: Decimal, total_equity: Decimal) -> Decimal:
"""负债权益比率:总负债 / 总权益"""
return (total_debt / total_equity).quantize(Decimal('0.01'))
@staticmethod
def return_on_equity(net_income: Decimal, shareholders_equity: Decimal) -> Decimal:
"""净资产收益率:净利润 / 股东权益"""
return (net_income / shareholders_equity * 100).quantize(Decimal('0.01'))
@staticmethod
def return_on_assets(net_income: Decimal, total_assets: Decimal) -> Decimal:
"""总资产收益率:净利润 / 总资产"""
return (net_income / total_assets * 100).quantize(Decimal('0.01'))
@staticmethod
def profit_margin(net_income: Decimal, revenue: Decimal) -> Decimal:
"""净利润率:净利润 / 收入"""
return (net_income / revenue * 100).quantize(Decimal('0.01'))
❌ 大型企业使用收付实现制 ❌ 不进行账户核对 ❌ 缺少审计跟踪 ❌ 收入确认不一致 ❌ 内部控制不足 ❌ 交易记录文件不完整 ❌ 延迟报税和产生罚款
每周安装数
153
代码仓库
GitHub 星标数
11
首次出现
Jan 24, 2026
安全审计
安装于
opencode135
codex133
gemini-cli131
cursor129
github-copilot125
kimi-cli122
Expert guidance for accounting systems, financial reporting, tax compliance, and modern accounting technology.
from decimal import Decimal
from datetime import datetime
from enum import Enum
from typing import List
class AccountType(Enum):
ASSET = "asset"
LIABILITY = "liability"
EQUITY = "equity"
REVENUE = "revenue"
EXPENSE = "expense"
class Account:
def __init__(self, code: str, name: str, account_type: AccountType):
self.code = code
self.name = name
self.type = account_type
self.balance = Decimal('0')
self.debit_total = Decimal('0')
self.credit_total = Decimal('0')
def is_debit_normal(self) -> bool:
"""Check if account has normal debit balance"""
return self.type in [AccountType.ASSET, AccountType.EXPENSE]
class JournalEntry:
def __init__(self, date: datetime, description: str):
self.id = self.generate_entry_id()
self.date = date
self.description = description
self.lines = []
self.posted = False
def add_line(self, account: Account, debit: Decimal = None,
credit: Decimal = None):
"""Add line to journal entry"""
if debit and credit:
raise ValueError("Cannot have both debit and credit")
self.lines.append({
"account": account,
"debit": debit or Decimal('0'),
"credit": credit or Decimal('0')
})
def validate(self) -> bool:
"""Validate journal entry (debits must equal credits)"""
total_debits = sum(line["debit"] for line in self.lines)
total_credits = sum(line["credit"] for line in self.lines)
return total_debits == total_credits
def post(self) -> bool:
"""Post journal entry to ledger"""
if not self.validate():
raise ValueError("Entry does not balance")
for line in self.lines:
account = line["account"]
if line["debit"]:
account.debit_total += line["debit"]
if line["credit"]:
account.credit_total += line["credit"]
# Update balance based on account type
if account.is_debit_normal():
account.balance = account.debit_total - account.credit_total
else:
account.balance = account.credit_total - account.debit_total
self.posted = True
return True
class FinancialStatements:
def __init__(self, company_name: str, period_end: datetime):
self.company_name = company_name
self.period_end = period_end
self.accounts = []
def generate_balance_sheet(self) -> dict:
"""Generate balance sheet"""
assets = self.sum_accounts_by_type(AccountType.ASSET)
liabilities = self.sum_accounts_by_type(AccountType.LIABILITY)
equity = self.sum_accounts_by_type(AccountType.EQUITY)
# Calculate retained earnings
revenue = self.sum_accounts_by_type(AccountType.REVENUE)
expenses = self.sum_accounts_by_type(AccountType.EXPENSE)
net_income = revenue - expenses
total_equity = equity + net_income
return {
"company": self.company_name,
"period_end": self.period_end,
"assets": {
"current_assets": self.get_current_assets(),
"non_current_assets": self.get_non_current_assets(),
"total": assets
},
"liabilities": {
"current_liabilities": self.get_current_liabilities(),
"non_current_liabilities": self.get_non_current_liabilities(),
"total": liabilities
},
"equity": {
"share_capital": equity,
"retained_earnings": net_income,
"total": total_equity
},
"balanced": assets == (liabilities + total_equity)
}
def generate_income_statement(self, period_start: datetime,
period_end: datetime) -> dict:
"""Generate income statement (P&L)"""
revenue = self.sum_accounts_by_type(AccountType.REVENUE)
expenses = self.sum_accounts_by_type(AccountType.EXPENSE)
gross_profit = revenue - self.get_cogs()
operating_expenses = self.get_operating_expenses()
operating_income = gross_profit - operating_expenses
interest_expense = self.get_interest_expense()
tax_expense = self.calculate_tax(operating_income - interest_expense)
net_income = operating_income - interest_expense - tax_expense
return {
"company": self.company_name,
"period": f"{period_start.date()} to {period_end.date()}",
"revenue": revenue,
"cogs": self.get_cogs(),
"gross_profit": gross_profit,
"operating_expenses": operating_expenses,
"operating_income": operating_income,
"interest_expense": interest_expense,
"tax_expense": tax_expense,
"net_income": net_income,
"eps": self.calculate_eps(net_income)
}
def generate_cash_flow_statement(self) -> dict:
"""Generate cash flow statement"""
return {
"operating_activities": self.calculate_operating_cash_flow(),
"investing_activities": self.calculate_investing_cash_flow(),
"financing_activities": self.calculate_financing_cash_flow(),
"net_change_in_cash": self.calculate_net_cash_change(),
"beginning_cash": self.get_beginning_cash(),
"ending_cash": self.get_ending_cash()
}
class TaxCalculator:
def calculate_corporate_tax(self, taxable_income: Decimal,
jurisdiction: str = "US") -> dict:
"""Calculate corporate income tax"""
if jurisdiction == "US":
tax_rate = Decimal('0.21') # Federal rate
elif jurisdiction == "UK":
tax_rate = Decimal('0.19')
else:
tax_rate = Decimal('0.25') # Default rate
tax_amount = taxable_income * tax_rate
return {
"taxable_income": taxable_income,
"tax_rate": tax_rate,
"tax_amount": tax_amount.quantize(Decimal('0.01')),
"effective_rate": tax_rate,
"jurisdiction": jurisdiction
}
def calculate_vat(self, net_amount: Decimal, vat_rate: Decimal) -> dict:
"""Calculate VAT/Sales tax"""
vat_amount = net_amount * vat_rate
gross_amount = net_amount + vat_amount
return {
"net_amount": net_amount,
"vat_rate": vat_rate,
"vat_amount": vat_amount.quantize(Decimal('0.01')),
"gross_amount": gross_amount.quantize(Decimal('0.01'))
}
def calculate_depreciation(self, cost: Decimal, salvage_value: Decimal,
useful_life_years: int,
method: str = "straight_line") -> List[dict]:
"""Calculate depreciation schedule"""
if method == "straight_line":
annual_depreciation = (cost - salvage_value) / useful_life_years
schedule = []
book_value = cost
for year in range(1, useful_life_years + 1):
depreciation = annual_depreciation
book_value -= depreciation
schedule.append({
"year": year,
"depreciation": depreciation.quantize(Decimal('0.01')),
"accumulated_depreciation": (annual_depreciation * year).quantize(Decimal('0.01')),
"book_value": book_value.quantize(Decimal('0.01'))
})
return schedule
class FinancialRatios:
@staticmethod
def current_ratio(current_assets: Decimal, current_liabilities: Decimal) -> Decimal:
"""Liquidity ratio: Current Assets / Current Liabilities"""
return (current_assets / current_liabilities).quantize(Decimal('0.01'))
@staticmethod
def quick_ratio(current_assets: Decimal, inventory: Decimal,
current_liabilities: Decimal) -> Decimal:
"""Acid test: (Current Assets - Inventory) / Current Liabilities"""
return ((current_assets - inventory) / current_liabilities).quantize(Decimal('0.01'))
@staticmethod
def debt_to_equity(total_debt: Decimal, total_equity: Decimal) -> Decimal:
"""Leverage ratio: Total Debt / Total Equity"""
return (total_debt / total_equity).quantize(Decimal('0.01'))
@staticmethod
def return_on_equity(net_income: Decimal, shareholders_equity: Decimal) -> Decimal:
"""ROE: Net Income / Shareholders' Equity"""
return (net_income / shareholders_equity * 100).quantize(Decimal('0.01'))
@staticmethod
def return_on_assets(net_income: Decimal, total_assets: Decimal) -> Decimal:
"""ROA: Net Income / Total Assets"""
return (net_income / total_assets * 100).quantize(Decimal('0.01'))
@staticmethod
def profit_margin(net_income: Decimal, revenue: Decimal) -> Decimal:
"""Net Profit Margin: Net Income / Revenue"""
return (net_income / revenue * 100).quantize(Decimal('0.01'))
❌ Using cash accounting for large businesses ❌ No account reconciliations ❌ Missing audit trails ❌ Inconsistent revenue recognition ❌ Inadequate internal controls ❌ Poor documentation of transactions ❌ Late tax filing and penalties
Weekly Installs
153
Repository
GitHub Stars
11
First Seen
Jan 24, 2026
Security Audits
Gen Agent Trust HubPassSocketPassSnykPass
Installed on
opencode135
codex133
gemini-cli131
cursor129
github-copilot125
kimi-cli122
通过 LiteLLM 代理让 Claude Code 对接 GitHub Copilot 运行 | 高级变通方案指南
33,600 周安装