本系列文章
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的会计系统吧,Part I
SAP CAP篇十五:写个ERP的会计系统吧,Part II
SAP CAP篇十六:写个ERP的会计系统吧,Part III
目标
基于前一篇的基础继续开发ERP系统。
本篇侧重于会计凭证,会计凭证是会计事务在系统的承载。
会计凭证的创建——需要符合基本的会计等式,即“有借必有贷,借贷必相等”。从业务意义上来说,会计凭证是企业各种报表的基础。
开发步骤
数据库表设计
从数据库层面来定义会计凭证。
借贷
借贷的定义DebitCreditIndicator
如下:
type DebitCreditIndicatorEnum : String(1) enum {
debit = 'D';
creidt = 'C';
}
@cds.odata.valuelist
entity DebitCreditIndicators: sap.common.CodeList {
key DebitCreditIndicator: DebitCreditIndicatorEnum;
}
初始化数据
在db
文件夹下,创建DebitCreditIndicator.csv
用以在初始化数据。
DebitCreditIndicator;name
D;Debit
C;Credit
会计凭证
会计凭证的如下:
entity Documents: managed {
key ID: Int32;
Company: Association to one dbcompany.Companies not null;
PostingDate: Date @cds.on: {insert: $now, update: $now };
Description: String(100);
Items : Composition of many {
key ID: Int16;
DebitCreditIndicator: Association to one DebitCreditIndicators not null;
Account: Association to one dbaccount.Accounts not null;
Amount: Decimal(15, 2) not null;
Currency: Currency not null;
Description: String(100);
};
}
Service 定义
更新FinanceService
,添加如下Entities。
@readonly
entity DebitCreditIndicators as projection on dbdocument.DebitCreditIndicators;
这里,用@readonly
限制借贷定义为只读。
entity Documents as projection on dbdocument.Documents;
同时,需要指定Documents
为Odata.draft.enabled
,这样,Fiori Elements会自动启用编辑功能:Create, Update。
annotate FinanceService.Documents with @odata.draft.enabled;
生成Fiori App
通过Fiori: Open Application Geneator
来创建Fiori App。
查看生成的App的Information:
更新CDS Annotation
annotate service.Documents with @(
UI.SelectionFields: [
Company_ID,
PostingDate
],
UI.LineItem : [
{
$Type : 'UI.DataField',
Label : 'ID',
Value : ID,
},
{
$Type : 'UI.DataField',
Label : 'Company',
Value : Company_ID,
},
{
$Type : 'UI.DataField',
Label : 'Posting Date',
Value : PostingDate,
},
{
$Type : 'UI.DataField',
Label : 'Description',
Value : Description,
},
]
);
annotate service.Documents with @(
UI.FieldGroup #GeneratedGroup1 : {
$Type : 'UI.FieldGroupType',
Data : [
{
$Type : 'UI.DataField',
Label : 'ID',
Value : ID,
},
{
$Type : 'UI.DataField',
Label : 'Company',
Value : Company_ID,
},
{
$Type : 'UI.DataField',
Label : 'PostingDate',
Value : PostingDate,
},
{
$Type : 'UI.DataField',
Label : 'Description',
Value : Description,
},
],
},
UI.Facets : [
{
$Type : 'UI.ReferenceFacet',
ID : 'GeneratedFacet1',
Label : 'General Information',
Target : '@UI.FieldGroup#GeneratedGroup1',
},
]
);
App运行
后续的文章里面,将开始定义凭证。