SAP CAP篇十四:写个ERP的会计系统吧,Part I

本系列文章

SAP CAP篇一: 快速创建一个Service,基于Java的实现
SAP CAP篇二:为Service加上数据库支持
SAP CAP篇三:定义Model
SAP CAP篇四:为CAP添加Fiori Elements程序(1)
SAP CAP篇五:为CAP添加Fiori Elements程序(2)
SAP CAP篇六:为CAP添加Fiori Elements程序(3)
SAP CAP篇七:为CAP添加Fiori Launchpad入口 (Sandbox环境)
SAP CAP篇八:为CAP添加App Router并支持Fiori Launchpad (Sandbox环境)
SAP CAP篇九:升级为SAP CDS 7.0, CAP Java 2以及Spring Boot 3
SAP CAP篇十:理解Fiori UI的Annoation定义
SAP CAP篇十一:支持Media Object:图片、附件等
SAP CAP篇十二:AppRouter 深入研究
SAP CAP篇十三:拥抱TypeScript

目标

都说学习一门技术,最好的办法就是用这个技术实现一个目标。在整个的实现过程中,逢山开道,遇水架桥,才能更好地完成技术的“二八原理”。

所以,那就SAP CAP技术写一个ERP的会计系统。

功能列表如下(初步计划,随着开发的进行,会逐步细化):

  • 公司主数据
  • 会计科目表
  • 会计科目主数据
  • 会计凭证
  • 客户主数据
  • 供应商主数据
  • 固定资产主数据
  • 无形资产主数据
  • 会计报表:资产负债表
  • 会计报表:利润表
  • 会计报表:现金流量表

本文会注重在公司主数据。

程序框架

当然,SAP CAP的目标是Cloud Native的,但是Martin Flower在“Microservice Guideline”中也说“Monolith First”,详情参阅链接

那就赶紧开始吧。

使用CDS CLI创建程序

创建CDS CLI来创建程序并安装各种dependence,命令如下:

cds init

然后,安装各种依赖。最终,package.json中关于dependencies如下:

  "dependencies": {
    "@sap/cds": "^7.5.2",
    "@sap/xsenv": "^4.2.0",
    "express": "^4.18.2"
  },
  "devDependencies": {
    "@cap-js/cds-typer": "^0.15.0",
    "@cap-js/sqlite": "^1.4.0",
    "@sap/ux-specification": "^1.120.2",
    "@sapui5/ts-types": "^1.120.4",
    "@types/jest": "^29.5.11",
    "@types/node": "^20.11.5",
    "@typescript-eslint/eslint-plugin": "^6.20.0",
    "@typescript-eslint/parser": "^6.20.0",
    "axios": "^1.6.5",
    "eslint": "^8.56.0",
    "jest": "^29.7.0",
    "ts-jest": "^29.1.2",
    "ts-node": "^10.9.2",
    "typescript": "^5.3.3"
  },

具体的项目创建参阅SAP CAP篇十三:拥抱TypeScript

创建公司主数据

数据库表设计

从数据库层面来定义公司主数据。

namespace finsys.db;

using {
  sap,
  cuid,
  Currency,
  Country
} from '@sap/cds/common';

extend sap.common.Currencies with {
  // Currencies.code = ISO 4217 alphabetic three-letter code
  // with the first two letters being equal to ISO 3166 alphabetic country codes
  // See also:
  // [1] https://www.iso.org/iso-4217-currency-codes.html
  // [2] https://www.currency-iso.org/en/home/tables/table-a1.html
  // [3] https://www.ibm.com/support/knowledgecenter/en/SSZLC2_7.0.0/com.ibm.commerce.payments.developer.doc/refs/rpylerl2mst97.htm
  numcode  : Integer;
  exponent : Integer; //> e.g. 2 --> 1 Dollar = 10^2 Cent
  minor    : String; //> e.g. 'Cent'
}

@cds.odata.valuelist
entity Companies: managed, cuid, sap.common.CodeList {    
    ParentCompany: Association to one Companies;
    Currency: Currency;
    Country: Country;
    Address: String(100);
}

其中:

  • ParentCompany:母公司
  • Currency:本位币
  • Country: 公司所属Country或地区
  • Address:公司具体地址信息

初始数据

运行下述命令来插入初始数据:

cds add data

该命令会自动在db文件夹下添加data文件夹,并为已有的数据库表生成csv文件。

初始数据:Country

文件sap.common-Countries.csv

code;name;descr
AU;Australia;Commonwealth of Australia
CA;Canada;Canada
CN;China;People's Republic of China (PRC)
FR;France;French Republic
DE;Germany;Federal Republic of Germany
IN;India;Republic of India
IL;Israel;State of Israel
MM;Myanmar;Republic of the Union of Myanmar
GB;United Kingdom;United Kingdom of Great Britain and Northern Ireland
US;United States;United States of America (USA)
EU;European Union;European Union

初始数据:Currency

文件sap.common-Currencies.csv

code;symbol;name;descr;numcode;minor;exponent
EUR;€;Euro;European Euro;978;Cent;2
USD;$;US Dollar;United States Dollar;840;Cent;2
CAD;$;Canadian Dollar;Canadian Dollar;124;Cent;2
AUD;$;Australian Dollar;Australian Dollar;036;Cent;2
GBP;£;British Pound;Great Britain Pound;826;Penny;2
ILS;₪;Shekel;Israeli New Shekel;376;Agorat;2
INR;₹;Rupee;Indian Rupee;356;Paise;2
QAR;﷼;Riyal;Katar Riyal;356;Dirham;2
SAR;﷼;Riyal;Saudi Riyal;682;Halala;2
JPY;¥;Yen;Japanese Yen;392;Sen;2
CNY;¥;Yuan;Chinese Yuan Renminbi;156;Jiao;1

初始数据:Language

文件sap.common-Languages.csv

code;name
de;German
fr;French
en;English
en_GB;British English

Service 定义

定义FinanceService

using { finsys.db as dbcommon } from '../db/schema';

service FinanceService {
    entity Companies as projection on dbcompany.Companies;
}

annotate FinanceService.Companies with @odata.draft.enabled;

生成Fiori App

通过Fiori: Open Application Geneator来创建Fiori App。

指定Service
项目描述

App运行

App运行如下:
App 运行
很粗略的一个程序,但是可用了。

后续的文章里面,会继续对这个App进行进一步增强。

相关推荐

  1. 系统安全架构论点论文

    2024-03-19 13:24:02       18 阅读
  2. 【QEMU系统分析之实例)】

    2024-03-19 13:24:02       15 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-19 13:24:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-19 13:24:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-19 13:24:02       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-19 13:24:02       20 阅读

热门阅读

  1. 【DevOps基础篇】Agile中重要的10个衡量指标

    2024-03-19 13:24:02       20 阅读
  2. [日报] Ribbon、Eureka、Nginx、负载均衡

    2024-03-19 13:24:02       19 阅读
  3. OpenCV-图像通道处理

    2024-03-19 13:24:02       20 阅读
  4. 【NLP7-使用RNN模型构建人名分类器】

    2024-03-19 13:24:02       18 阅读
  5. CentOS 同时安装多个版本Python3

    2024-03-19 13:24:02       19 阅读
  6. Python 的 typing 模块:类型提示的利器

    2024-03-19 13:24:02       17 阅读
  7. Stream流

    Stream流

    2024-03-19 13:24:02      16 阅读
  8. docker菜鸟教程

    2024-03-19 13:24:02       17 阅读
  9. 【LAMMPS学习】二、LAMMPS安装(2)MacOS和Win安装

    2024-03-19 13:24:02       16 阅读
  10. R语言基础 - 饼图piechart

    2024-03-19 13:24:02       16 阅读
  11. linux 日志排查

    2024-03-19 13:24:02       19 阅读