全部版块 我的主页
论坛 数据科学与人工智能 IT基础
40 0
2025-12-04

Bigcapital - 开源智能会计软件

Bigcapital 是一款面向中小企业的开源解决方案,集成了智能会计与库存管理功能。基于现代技术架构开发,具备自动化财务处理能力,支持多维度财务分析与决策辅助,适用于需要高效财务管理的企业环境。

docker-compose up -d

主要功能特点

  • 全链路财务管理:涵盖账单、发票、收据、付款、费用报销及信用票据等核心财务流程,实现全流程数字化管理。
  • 库存控制体系:支持多个仓库的独立运营与统一调度,提供库存调拨、成本追踪和库存调整功能,确保资产数据准确。
  • 多分支机构支持:允许不同分支独立记账或集中核算,灵活适配集团化或连锁型企业的组织结构。
  • 多币种交易处理:内置实时汇率机制,可处理跨币种收支业务,自动完成外币折算与汇兑损益计算。
  • 会计自动化引擎:根据业务单据自动生成会计凭证与总账记录,并同步更新各类财务报表。
  • 银行对账集成能力:通过 Plaid 接口对接银行账户,结合规则引擎实现交易自动分类与匹配。
  • 项目成本跟踪:支持按项目归集支出与工时,便于进行盈利性分析和预算控制。
  • 税务配置管理:支持多种税率设置,自动执行税务计算并生成合规申报数据。
  • 权限精细化管理:采用基于角色的访问控制(RBAC),实现模块级、操作级的权限分配。
node packages/server/build/commands.js system:migrate:latest

部署准备

系统依赖要求

  • Node.js v18.x 版本
  • pnpm 包管理工具
  • Docker 及 Docker Compose 环境

快速部署步骤

  1. 克隆项目代码并进入工作目录:
    git clone https://github.com/bigcapital/bigcapital.git && cd bigcapital
  2. 复制示例环境变量文件:
    cp .env.example .env
  3. 安装项目所需依赖包:
    pnpm install
  4. 启动容器化服务组件:
    docker-compose up -d
  5. 构建后端服务程序:
    pnpm run build:server
  6. 执行数据库迁移脚本以初始化结构:
    pnpm run db:migrate
  7. 启动开发模式服务器:
    pnpm run dev:server
/api

使用说明

API 设计规范

系统后端遵循 RESTful 架构风格,所有接口均以 /api 作为统一前缀。同时集成了 Swagger 文档系统,可通过访问指定路径查看完整的接口文档与测试界面。

/swagger

关键功能调用示例

1. 创建财务账户

用于新增如银行账户等会计科目实体。

const accountData = {
  name: "中国银行 - 基本账户",
  account_type: "bank",
  code: "1001",
  currency_code: "CNY",
  active: true
};
// 请求方式:POST
// 接口地址:/api/accounts
    
2. 录入销售发票

提交一笔包含商品明细的客户销售单据。

const invoiceData = {
  customer_id: 1001,
  invoice_date: "2024-01-15",
  due_date: "2024-02-15",
  currency_code: "CNY",
  exchange_rate: 1.0,
  items: [
    {
      item_id: 5001,
      quantity: 2,
      rate: 1500.00,
      description: "企业级软件授权"
    }
  ]
};
// 请求方式:POST
// 接口地址:/api/sales/invoices
    
3. 配置银行交易分类规则

设定自动化规则,将符合条件的银行流水自动归类到指定费用账户。

const bankRule = {
  name: "办公用品自动分类",
  conditions_type: "AND",
  apply_if_account_id: 1001,
  assign_account_id: 6001, // 办公费用账户
  conditions: [
    {
      field: "description",
      comparator: "contains",
      value: "办公用品"
    }
  ]
};
// 请求方式:POST
// 接口地址:/api/banking/rules
    

核心代码片段

服务启动主程序

文件路径:src/main.ts —— 应用入口点

import { NestFactory } from '@nestjs/core';
import { DocumentBuilder, SwaggerModule } from '@nestjs/swagger';
import { AppModule } from './modules/App/App.module';
import { ValidationPipe } from './common/pipes/ClassValidation.pipe';

async function bootstrap() {
  const app = await NestFactory.create(AppModule);
  app.setGlobalPrefix('/api');

  // 启用全局验证管道
  app.useGlobalPipes(new ValidationPipe());

  // 构建 Swagger API 文档
  const config = new DocumentBuilder()
    .setTitle('Bigcapital')
    .setDescription('Financial accounting software')
    .setVersion('1.0')
    .build();

  const document = SwaggerModule.createDocument(app, config);
    
// 主应用启动配置
await app.listen(process.env.PORT ?? 3000);
SwaggerModule.setup('swagger', app, document);

bootstrap();

docker-compose up -d
// 数据库迁移脚本:创建账户表结构 // migrations/20240101000000_create_accounts_table.js exports.up = function (knex) { return knex.schema.createTable('accounts', (table) => { table.increments('id').comment('自增ID'); table.string('name').index(); // 账户名称 table.string('slug'); // 唯一标识符 table.string('account_type').index(); // 账户类型 table.integer('parent_account_id').unsigned().references('id').inTable('accounts'); // 父账户 table.string('code', 10).index(); // 账户代码 table.text('description'); // 描述 table.boolean('active').defaultTo(true).index(); // 是否激活 table.integer('index').unsigned(); // 排序索引 table.boolean('predefined').defaultTo(false).index(); // 是否预定义 table.decimal('amount', 15, 5); // 金额 table.string('currency_code', 3).index(); // 货币代码 table.timestamps(); // 创建和更新时间 }).raw('ALTER TABLE `ACCOUNTS` AUTO_INCREMENT = 1000'); // 设置自增起始值 }; exports.down = (knex) => knex.schema.dropTableIfExists('accounts');
node packages/server/build/commands.js system:migrate:latest
// 数据库迁移脚本:创建会计分录交易记录表 // migrations/20240101000002_create_accounts_transactions_table.js exports.up = function (knex) { return knex.schema.createTable('accounts_transactions', (table) => { table.increments(); table.decimal('credit', 13, 3); // 贷方金额 table.decimal('debit', 13, 3); // 借方金额 table.string('currency_code', 3); // 货币代码 table.decimal('exchange_rate', 13, 9); // 汇率 table.string('transaction_type').index(); // 交易类型 table.string('reference_type').index(); // 关联类型 table.integer('reference_id').index(); // 关联ID table.integer('account_id').unsigned().index().references('id').inTable('accounts'); // 账户ID table.string('contact_type').nullable().index(); // 联系人类型 table.integer('contact_id').unsigned().nullable().index(); // 联系人ID table.string('transaction_number').nullable().index(); // 交易编号 table.string('reference_number').nullable().index(); // 参考编号 table.integer('item_id').unsigned().nullable().index(); // 商品ID table.integer('item_quantity').unsigned().nullable().index(); // 商品数量 table.string('note'); // 备注 }); }; exports.down = function (knex) { return knex.schema.dropTableIfExists('accounts_transactions'); };
exports.up = function (knex) {
    return knex.schema.createTable('ACCOUNTS_TRANSACTIONS', (table) => {
        table.increments('id').primary();
        table.integer('user_id').unsigned().index(); // 用户ID
        table.integer('index_group').unsigned().index(); // 分组索引
        table.integer('index').unsigned().index(); // 交易索引
        table.date('date').index(); // 交易日期
        table.datetime('created_at').index(); // 创建时间
        table.boolean('costable'); // 是否可成本化
        table.integer('tax_rate_id').unsigned().references('id').inTable('tax_rates'); // 税率ID
        table.decimal('tax_rate').unsigned(); // 税率
        table.integer('branch_id').unsigned().references('id').inTable('branches'); // 分支机构ID
        table.integer('projectId').unsigned().references('id').inTable('projects'); // 项目ID
    }).raw('ALTER TABLE `ACCOUNTS_TRANSACTIONS` AUTO_INCREMENT = 1000');
};

// migrations/20240101000012_create_inventory_transactions_table.js
docker-compose up -d
exports.up = function (knex) { return knex.schema.createTable('inventory_transactions', (table) => { table.increments('id'); table.date('date').index(); // 交易日期 table.string('direction').index(); // 方向(入库/出库) table.integer('item_id').unsigned().index().references('id').inTable('items'); // 商品ID table.integer('quantity').unsigned(); // 数量 table.decimal('rate', 13, 3).unsigned(); // 单价 table.string('transaction_type').index(); // 交易类型 table.integer('transaction_id').unsigned().index(); // 交易ID table.integer('entry_id').unsigned().index(); // 分录ID table.integer('cost_account_id').unsigned(); // 成本账户ID table.integer('warehouse_id').unsigned().references('id').inTable('warehouses'); // 仓库ID table.integer('branch_id').unsigned().references('id').inTable('branches'); // 分支机构ID table.timestamps(); // 时间戳 }); }; // migrations/20240101000034_create_bank_rules_table.js
node packages/server/build/commands.js system:migrate:latest
exports.up = function (knex) { return knex.schema.createTable('bank_rules', (table) => { table.increments('id').primary(); table.string('name'); // 规则名称 table.integer('order').unsigned(); // 执行顺序 table.integer('apply_if_account_id').unsigned().references('id').inTable('accounts'); // 适用账户 table.string('apply_if_transaction_type'); // 适用交易类型 table.string('assign_category'); // 分配类别 }); };
// migrations/20240101000006_create_bank_rules_table.js
exports.up = function(knex) {
  return knex.schema
    .createTable('bank_rules', (table) => {
      table.increments('id').primary();
      table.string('name'); // 规则名称
      table.string('description'); // 规则描述
      table.integer('assign_account_id').unsigned().references('id').inTable('accounts'); // 分配账户
      table.string('assign_payee'); // 分配收款方
      table.string('assign_memo'); // 分配备注
      table.string('conditions_type'); // 条件类型(AND/OR)
      table.timestamps();
    })
    .createTable('bank_rule_conditions', (table) => {
      table.increments('id').primary();
      table.integer('rule_id').unsigned().references('id').inTable('bank_rules'); // 规则ID
      table.string('field'); // 条件字段
      table.string('comparator'); // 比较运算符
      table.string('value'); // 条件值
    });
};

// 多币种汇率管理
// migrations/20240101000007_create_exchange_rates_table.js
exports.up = function(knex) {
  return knex.schema.createTable('exchange_rates', (table) => {
    table.increments();
    table.string('currency_code', 4).index(); // 货币代码
    table.decimal('exchange_rate'); // 汇率
    table.date('date').index(); // 汇率日期
    table.timestamps(); // 时间戳
  }).raw('ALTER TABLE `EXCHANGE_RATES` AUTO_INCREMENT = 1000');
};

// 项目成本跟踪
// migrations/20240101000026_create_projects_table.js
exports.up = (knex) => {
  return knex.schema
    .createTable('projects', (table) => {
      table.increments('id').comment('自增ID');
      table.string('name'); // 项目名称
      table.integer('contact_id').unsigned(); // 客户ID
      table.date('deadline'); // 截止日期
      table.decimal('cost_estimate'); // 成本估算
      table.string('status'); // 项目状态
      table.timestamps();
    })
    .createTable('tasks', (table) => {
      table.increments('id').comment('自增ID');
      table.string('name'); // 任务名称
      table.string('charge_type'); // 计费类型
      table.decimal('rate'); // 费率
      table.decimal('estimate_hours').unsigned(); // 预估工时
      table.decimal('actual_hours').unsigned(); // 实际工时
      table.decimal('invoiced_hours').unsigned().default(0); // 已开票工时
      table.integer('project_id').unsigned().references('id').inTable('projects'); // 项目ID
      table.timestamps();
    });
};

// 税务管理系统
// migrations/20240101000029_create_tax_rates_table.js
exports.up = (knex) => {
  return knex.schema.createTable('tax_rates', (table) => {
    table.increments();
    table.string('name'); // 税率名称
    table.string('code'); // 税率代码
    table.decimal('rate'); // 税率值
  });
};
// 描述
// 是否不可抵扣
// 是否复合税
// 是否激活
[table.date('deleted_at');] // 删除时间 [table.timestamps();] }; };
二维码

扫码加我 拉你入群

请注明:姓名-公司-职位

以便审核进群资格,未注明则拒绝

相关推荐
栏目导航
热门文章
推荐文章

说点什么

分享

扫码加好友,拉您进群
各岗位、行业、专业交流群