当前位置:   article > 正文

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

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

本系列文章

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;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
初始化数据

db文件夹下,创建DebitCreditIndicator.csv用以在初始化数据。

DebitCreditIndicator;name
D;Debit
C;Credit
  • 1
  • 2
  • 3

会计凭证

会计凭证的如下:

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);
    };
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15

Service 定义

更新FinanceService,添加如下Entities。

@readonly
entity DebitCreditIndicators as projection on dbdocument.DebitCreditIndicators;
  • 1
  • 2

这里,用@readonly限制借贷定义为只读。

entity Documents as projection on dbdocument.Documents;
  • 1

同时,需要指定DocumentsOdata.draft.enabled,这样,Fiori Elements会自动启用编辑功能:Create, Update。

annotate FinanceService.Documents with @odata.draft.enabled;
  • 1

生成Fiori App

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

Entity Selection

查看生成的App的Information:

Application 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',
        },
    ]
);
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63

App运行

App Running

后续的文章里面,将开始定义凭证。

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/小蓝xlanll/article/detail/446426
推荐阅读
相关标签
  

闽ICP备14008679号