gaoluyang
2 天以前 98312d84f785c09574bfd5add730ea448fb0cbd5
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
import type { VbenFormSchema } from '#/adapter/form';
import type { VxeTableGridOptions } from '#/adapter/vxe-table';
import type { FinLedgerApi } from '#/api/erp/finance/ledger';
 
import { DICT_TYPE } from '@vben/constants';
 
import { z } from '#/adapter/form';
import { getAccountSubjectList } from '#/api/erp/finance/subject';
 
import dayjs from 'dayjs';
 
/** 行类型 -> 展示文案 */
export const LEDGER_ROW_TYPE_LABEL: Record<string, string> = {
  opening: '期初余额',
  entry: '明细',
  monthly_total: '本月合计',
  yearly_total: '本年累计',
};
 
/** 行类型 -> Tag 颜色 */
export const LEDGER_ROW_TYPE_COLOR: Record<string, string> = {
  opening: 'blue',
  entry: 'default',
  monthly_total: 'orange',
  yearly_total: 'purple',
};
 
/**
 * 账页查询表单
 *
 * 说明:账页只统计「已过账」的凭证,未过账、已作废的凭证不计入。
 */
export function useLedgerFormSchema(): VbenFormSchema[] {
  return [
    {
      fieldName: 'subjectCode',
      label: '会计科目',
      component: 'ApiTreeSelect',
      componentProps: {
        api: getAccountSubjectList,
        labelField: 'subjectName',
        valueField: 'subjectCode',
        childrenField: 'children',
        placeholder: '请选择会计科目',
        treeDefaultExpandAll: true,
        showSearch: true,
        treeNodeFilterProp: 'subjectName',
      },
      rules: 'selectRequired',
    },
    {
      fieldName: 'startMonth',
      label: '起始月份',
      component: 'DatePicker',
      componentProps: {
        picker: 'month',
        allowClear: true,
        valueFormat: 'YYYY-MM',
        format: 'YYYY-MM',
        style: { width: '100%' },
        placeholder: '选择起始月份',
      },
      defaultValue: dayjs().startOf('year').format('YYYY-MM'),
    },
    {
      fieldName: 'endMonth',
      label: '结束月份',
      component: 'DatePicker',
      componentProps: {
        picker: 'month',
        allowClear: true,
        valueFormat: 'YYYY-MM',
        format: 'YYYY-MM',
        style: { width: '100%' },
        placeholder: '选择结束月份',
      },
      defaultValue: dayjs().format('YYYY-MM'),
    },
    {
      fieldName: 'includeChildren',
      label: '包含下级科目',
      component: 'Switch',
      componentProps: {
        checkedChildren: '是',
        unCheckedChildren: '否',
      },
      defaultValue: false,
      rules: z.boolean().default(false).optional(),
      help: '开启后,所选科目及其全部下级科目的发生额与余额合并统计',
    },
  ];
}
 
/** 总账列:期初 + 逐月合计 + 本年累计 */
export function useGeneralColumns(): VxeTableGridOptions<FinLedgerApi.LedgerRow>['columns'] {
  return [
    {
      field: 'rowType',
      title: '行类型',
      width: 110,
      fixed: 'left',
      slots: { default: 'rowType' },
    },
    {
      field: 'period',
      title: '期间',
      width: 110,
    },
    {
      field: 'subjectCode',
      title: '科目编码',
      minWidth: 120,
    },
    {
      field: 'subjectName',
      title: '科目名称',
      minWidth: 160,
    },
    {
      field: 'debit',
      title: '借方发生额',
      minWidth: 140,
      align: 'right',
      formatter: 'formatAmount2',
    },
    {
      field: 'credit',
      title: '贷方发生额',
      minWidth: 140,
      align: 'right',
      formatter: 'formatAmount2',
    },
    {
      field: 'direction',
      title: '方向',
      width: 80,
      align: 'center',
      slots: { default: 'direction' },
    },
    {
      field: 'balance',
      title: '期末余额',
      minWidth: 140,
      align: 'right',
      formatter: 'formatAmount2',
    },
  ];
}
 
/** 明细账列:期初 + 逐笔分录 + 结转合计 */
export function useDetailColumns(): VxeTableGridOptions<FinLedgerApi.LedgerRow>['columns'] {
  return [
    {
      field: 'rowType',
      title: '行类型',
      width: 110,
      fixed: 'left',
      slots: { default: 'rowType' },
    },
    {
      field: 'date',
      title: '日期',
      width: 120,
      formatter: 'formatDate',
    },
    {
      field: 'voucherNo',
      title: '凭证字号',
      minWidth: 140,
    },
    {
      field: 'subjectCode',
      title: '科目编码',
      minWidth: 120,
    },
    {
      field: 'summary',
      title: '摘要',
      minWidth: 200,
      showOverflow: 'tooltip',
    },
    {
      field: 'debit',
      title: '借方金额',
      minWidth: 140,
      align: 'right',
      formatter: 'formatAmount2',
    },
    {
      field: 'credit',
      title: '贷方金额',
      minWidth: 140,
      align: 'right',
      formatter: 'formatAmount2',
    },
    {
      field: 'direction',
      title: '方向',
      width: 80,
      align: 'center',
      slots: { default: 'direction' },
    },
    {
      field: 'balance',
      title: '余额',
      minWidth: 140,
      align: 'right',
      formatter: 'formatAmount2',
    },
  ];
}
 
/** 余额方向字典类型,供页面渲染方向标签使用 */
export const LEDGER_DIRECTION_DICT = DICT_TYPE.FINANCE_BALANCE_DIRECTION;