@things-factory/accounting 6.0.46

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (227) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/README.md +31 -0
  3. package/assets/images/book-activity.jpg +0 -0
  4. package/assets/images/expense-activity.jpg +0 -0
  5. package/assets/images/hatiolab-logo.png +0 -0
  6. package/client/activities/activity-book-edit.ts +88 -0
  7. package/client/activities/activity-book-view.ts +88 -0
  8. package/client/activities/activity-expense-edit.ts +88 -0
  9. package/client/activities/activity-expense-view.ts +88 -0
  10. package/client/bootstrap.ts +1 -0
  11. package/client/index.ts +0 -0
  12. package/client/pages/account/account-importer.ts +97 -0
  13. package/client/pages/account/account-list-page.ts +348 -0
  14. package/client/pages/accounting-category/accounting-category-importer.ts +97 -0
  15. package/client/pages/accounting-category/accounting-category-list-page.ts +348 -0
  16. package/client/pages/financial-statement/financial-statement-importer.ts +97 -0
  17. package/client/pages/financial-statement/financial-statement-list-page.ts +348 -0
  18. package/client/pages/income-statement/income-statement-importer.ts +97 -0
  19. package/client/pages/income-statement/income-statement-list-page.ts +348 -0
  20. package/client/pages/ledger/ledger-importer.ts +97 -0
  21. package/client/pages/ledger/ledger-list-page.ts +332 -0
  22. package/client/pages/main.ts +24 -0
  23. package/client/pages/transaction/transaction-importer.ts +97 -0
  24. package/client/pages/transaction/transaction-list-page.ts +348 -0
  25. package/client/route.ts +27 -0
  26. package/client/tsconfig.json +11 -0
  27. package/dist-client/activities/activity-book-edit.d.ts +14 -0
  28. package/dist-client/activities/activity-book-edit.js +85 -0
  29. package/dist-client/activities/activity-book-edit.js.map +1 -0
  30. package/dist-client/activities/activity-book-view.d.ts +14 -0
  31. package/dist-client/activities/activity-book-view.js +85 -0
  32. package/dist-client/activities/activity-book-view.js.map +1 -0
  33. package/dist-client/activities/activity-expense-edit.d.ts +14 -0
  34. package/dist-client/activities/activity-expense-edit.js +85 -0
  35. package/dist-client/activities/activity-expense-edit.js.map +1 -0
  36. package/dist-client/activities/activity-expense-view.d.ts +14 -0
  37. package/dist-client/activities/activity-expense-view.js +85 -0
  38. package/dist-client/activities/activity-expense-view.js.map +1 -0
  39. package/dist-client/bootstrap.d.ts +1 -0
  40. package/dist-client/bootstrap.js +2 -0
  41. package/dist-client/bootstrap.js.map +1 -0
  42. package/dist-client/index.d.ts +0 -0
  43. package/dist-client/index.js +2 -0
  44. package/dist-client/index.js.map +1 -0
  45. package/dist-client/pages/account/account-importer.d.ts +22 -0
  46. package/dist-client/pages/account/account-importer.js +100 -0
  47. package/dist-client/pages/account/account-importer.js.map +1 -0
  48. package/dist-client/pages/account/account-list-page.d.ts +62 -0
  49. package/dist-client/pages/account/account-list-page.js +326 -0
  50. package/dist-client/pages/account/account-list-page.js.map +1 -0
  51. package/dist-client/pages/accounting-category/accounting-category-importer.d.ts +22 -0
  52. package/dist-client/pages/accounting-category/accounting-category-importer.js +100 -0
  53. package/dist-client/pages/accounting-category/accounting-category-importer.js.map +1 -0
  54. package/dist-client/pages/accounting-category/accounting-category-list-page.d.ts +62 -0
  55. package/dist-client/pages/accounting-category/accounting-category-list-page.js +326 -0
  56. package/dist-client/pages/accounting-category/accounting-category-list-page.js.map +1 -0
  57. package/dist-client/pages/financial-statement/financial-statement-importer.d.ts +22 -0
  58. package/dist-client/pages/financial-statement/financial-statement-importer.js +100 -0
  59. package/dist-client/pages/financial-statement/financial-statement-importer.js.map +1 -0
  60. package/dist-client/pages/financial-statement/financial-statement-list-page.d.ts +62 -0
  61. package/dist-client/pages/financial-statement/financial-statement-list-page.js +326 -0
  62. package/dist-client/pages/financial-statement/financial-statement-list-page.js.map +1 -0
  63. package/dist-client/pages/income-statement/income-statement-importer.d.ts +22 -0
  64. package/dist-client/pages/income-statement/income-statement-importer.js +100 -0
  65. package/dist-client/pages/income-statement/income-statement-importer.js.map +1 -0
  66. package/dist-client/pages/income-statement/income-statement-list-page.d.ts +62 -0
  67. package/dist-client/pages/income-statement/income-statement-list-page.js +326 -0
  68. package/dist-client/pages/income-statement/income-statement-list-page.js.map +1 -0
  69. package/dist-client/pages/ledger/ledger-importer.d.ts +22 -0
  70. package/dist-client/pages/ledger/ledger-importer.js +100 -0
  71. package/dist-client/pages/ledger/ledger-importer.js.map +1 -0
  72. package/dist-client/pages/ledger/ledger-list-page.d.ts +62 -0
  73. package/dist-client/pages/ledger/ledger-list-page.js +317 -0
  74. package/dist-client/pages/ledger/ledger-list-page.js.map +1 -0
  75. package/dist-client/pages/main.d.ts +1 -0
  76. package/dist-client/pages/main.js +27 -0
  77. package/dist-client/pages/main.js.map +1 -0
  78. package/dist-client/pages/transaction/transaction-importer.d.ts +22 -0
  79. package/dist-client/pages/transaction/transaction-importer.js +100 -0
  80. package/dist-client/pages/transaction/transaction-importer.js.map +1 -0
  81. package/dist-client/pages/transaction/transaction-list-page.d.ts +62 -0
  82. package/dist-client/pages/transaction/transaction-list-page.js +326 -0
  83. package/dist-client/pages/transaction/transaction-list-page.js.map +1 -0
  84. package/dist-client/route.d.ts +1 -0
  85. package/dist-client/route.js +23 -0
  86. package/dist-client/route.js.map +1 -0
  87. package/dist-client/tsconfig.tsbuildinfo +1 -0
  88. package/dist-server/activities/activity-book.js +150 -0
  89. package/dist-server/activities/activity-book.js.map +1 -0
  90. package/dist-server/activities/activity-expense.js +150 -0
  91. package/dist-server/activities/activity-expense.js.map +1 -0
  92. package/dist-server/activities/index.js +19 -0
  93. package/dist-server/activities/index.js.map +1 -0
  94. package/dist-server/controllers/index.js +1 -0
  95. package/dist-server/controllers/index.js.map +1 -0
  96. package/dist-server/index.js +7 -0
  97. package/dist-server/index.js.map +1 -0
  98. package/dist-server/middlewares/index.js +8 -0
  99. package/dist-server/middlewares/index.js.map +1 -0
  100. package/dist-server/migrations/index.js +12 -0
  101. package/dist-server/migrations/index.js.map +1 -0
  102. package/dist-server/routes.js +25 -0
  103. package/dist-server/routes.js.map +1 -0
  104. package/dist-server/service/account/account-history.js +113 -0
  105. package/dist-server/service/account/account-history.js.map +1 -0
  106. package/dist-server/service/account/account-mutation.js +130 -0
  107. package/dist-server/service/account/account-mutation.js.map +1 -0
  108. package/dist-server/service/account/account-query.js +79 -0
  109. package/dist-server/service/account/account-query.js.map +1 -0
  110. package/dist-server/service/account/account-type.js +65 -0
  111. package/dist-server/service/account/account-type.js.map +1 -0
  112. package/dist-server/service/account/account.js +102 -0
  113. package/dist-server/service/account/account.js.map +1 -0
  114. package/dist-server/service/account/event-subscriber.js +21 -0
  115. package/dist-server/service/account/event-subscriber.js.map +1 -0
  116. package/dist-server/service/account/index.js +12 -0
  117. package/dist-server/service/account/index.js.map +1 -0
  118. package/dist-server/service/accounting-category/accounting-category-mutation.js +132 -0
  119. package/dist-server/service/accounting-category/accounting-category-mutation.js.map +1 -0
  120. package/dist-server/service/accounting-category/accounting-category-query.js +79 -0
  121. package/dist-server/service/accounting-category/accounting-category-query.js.map +1 -0
  122. package/dist-server/service/accounting-category/accounting-category-type.js +65 -0
  123. package/dist-server/service/accounting-category/accounting-category-type.js.map +1 -0
  124. package/dist-server/service/accounting-category/accounting-category.js +89 -0
  125. package/dist-server/service/accounting-category/accounting-category.js.map +1 -0
  126. package/dist-server/service/accounting-category/index.js +10 -0
  127. package/dist-server/service/accounting-category/index.js.map +1 -0
  128. package/dist-server/service/financial-statement/event-subscriber.js +21 -0
  129. package/dist-server/service/financial-statement/event-subscriber.js.map +1 -0
  130. package/dist-server/service/financial-statement/financial-statement-history.js +126 -0
  131. package/dist-server/service/financial-statement/financial-statement-history.js.map +1 -0
  132. package/dist-server/service/financial-statement/financial-statement-mutation.js +132 -0
  133. package/dist-server/service/financial-statement/financial-statement-mutation.js.map +1 -0
  134. package/dist-server/service/financial-statement/financial-statement-query.js +79 -0
  135. package/dist-server/service/financial-statement/financial-statement-query.js.map +1 -0
  136. package/dist-server/service/financial-statement/financial-statement-type.js +77 -0
  137. package/dist-server/service/financial-statement/financial-statement-type.js.map +1 -0
  138. package/dist-server/service/financial-statement/financial-statement.js +111 -0
  139. package/dist-server/service/financial-statement/financial-statement.js.map +1 -0
  140. package/dist-server/service/financial-statement/index.js +12 -0
  141. package/dist-server/service/financial-statement/index.js.map +1 -0
  142. package/dist-server/service/income-statement/event-subscriber.js +21 -0
  143. package/dist-server/service/income-statement/event-subscriber.js.map +1 -0
  144. package/dist-server/service/income-statement/income-statement-history.js +126 -0
  145. package/dist-server/service/income-statement/income-statement-history.js.map +1 -0
  146. package/dist-server/service/income-statement/income-statement-mutation.js +132 -0
  147. package/dist-server/service/income-statement/income-statement-mutation.js.map +1 -0
  148. package/dist-server/service/income-statement/income-statement-query.js +79 -0
  149. package/dist-server/service/income-statement/income-statement-query.js.map +1 -0
  150. package/dist-server/service/income-statement/income-statement-type.js +77 -0
  151. package/dist-server/service/income-statement/income-statement-type.js.map +1 -0
  152. package/dist-server/service/income-statement/income-statement.js +117 -0
  153. package/dist-server/service/income-statement/income-statement.js.map +1 -0
  154. package/dist-server/service/income-statement/index.js +12 -0
  155. package/dist-server/service/income-statement/index.js.map +1 -0
  156. package/dist-server/service/index.js +43 -0
  157. package/dist-server/service/index.js.map +1 -0
  158. package/dist-server/service/transaction/event-subscriber.js +21 -0
  159. package/dist-server/service/transaction/event-subscriber.js.map +1 -0
  160. package/dist-server/service/transaction/index.js +12 -0
  161. package/dist-server/service/transaction/index.js.map +1 -0
  162. package/dist-server/service/transaction/transaction-history.js +123 -0
  163. package/dist-server/service/transaction/transaction-history.js.map +1 -0
  164. package/dist-server/service/transaction/transaction-mutation.js +130 -0
  165. package/dist-server/service/transaction/transaction-mutation.js.map +1 -0
  166. package/dist-server/service/transaction/transaction-query.js +79 -0
  167. package/dist-server/service/transaction/transaction-query.js.map +1 -0
  168. package/dist-server/service/transaction/transaction-type.js +73 -0
  169. package/dist-server/service/transaction/transaction-type.js.map +1 -0
  170. package/dist-server/service/transaction/transaction.js +130 -0
  171. package/dist-server/service/transaction/transaction.js.map +1 -0
  172. package/dist-server/tsconfig.tsbuildinfo +1 -0
  173. package/helps/accounting/account.md +160 -0
  174. package/helps/accounting/accounting-category.md +160 -0
  175. package/helps/accounting/financial-accounting.md +53 -0
  176. package/helps/accounting/financial-statement.md +160 -0
  177. package/helps/accounting/income-statement.md +160 -0
  178. package/helps/accounting/transaction.md +160 -0
  179. package/package.json +36 -0
  180. package/server/activities/activity-book.ts +149 -0
  181. package/server/activities/activity-expense.ts +149 -0
  182. package/server/activities/index.ts +19 -0
  183. package/server/controllers/index.ts +0 -0
  184. package/server/index.ts +4 -0
  185. package/server/middlewares/index.ts +3 -0
  186. package/server/migrations/index.ts +9 -0
  187. package/server/routes.ts +28 -0
  188. package/server/service/account/account-history.ts +103 -0
  189. package/server/service/account/account-mutation.ts +137 -0
  190. package/server/service/account/account-query.ts +49 -0
  191. package/server/service/account/account-type.ts +44 -0
  192. package/server/service/account/account.ts +86 -0
  193. package/server/service/account/event-subscriber.ts +17 -0
  194. package/server/service/account/index.ts +9 -0
  195. package/server/service/accounting-category/accounting-category-mutation.ts +145 -0
  196. package/server/service/accounting-category/accounting-category-query.ts +51 -0
  197. package/server/service/accounting-category/accounting-category-type.ts +42 -0
  198. package/server/service/accounting-category/accounting-category.ts +80 -0
  199. package/server/service/accounting-category/index.ts +7 -0
  200. package/server/service/financial-statement/event-subscriber.ts +17 -0
  201. package/server/service/financial-statement/financial-statement-history.ts +114 -0
  202. package/server/service/financial-statement/financial-statement-mutation.ts +145 -0
  203. package/server/service/financial-statement/financial-statement-query.ts +51 -0
  204. package/server/service/financial-statement/financial-statement-type.ts +51 -0
  205. package/server/service/financial-statement/financial-statement.ts +100 -0
  206. package/server/service/financial-statement/index.ts +9 -0
  207. package/server/service/income-statement/event-subscriber.ts +17 -0
  208. package/server/service/income-statement/income-statement-history.ts +114 -0
  209. package/server/service/income-statement/income-statement-mutation.ts +145 -0
  210. package/server/service/income-statement/income-statement-query.ts +48 -0
  211. package/server/service/income-statement/income-statement-type.ts +51 -0
  212. package/server/service/income-statement/income-statement.ts +105 -0
  213. package/server/service/income-statement/index.ts +9 -0
  214. package/server/service/index.ts +62 -0
  215. package/server/service/transaction/event-subscriber.ts +17 -0
  216. package/server/service/transaction/index.ts +9 -0
  217. package/server/service/transaction/transaction-history.ts +111 -0
  218. package/server/service/transaction/transaction-mutation.ts +143 -0
  219. package/server/service/transaction/transaction-query.ts +48 -0
  220. package/server/service/transaction/transaction-type.ts +48 -0
  221. package/server/service/transaction/transaction.ts +115 -0
  222. package/server/tsconfig.json +10 -0
  223. package/things-factory.config.js +16 -0
  224. package/translations/en.json +1 -0
  225. package/translations/ko.json +1 -0
  226. package/translations/ms.json +1 -0
  227. package/translations/zh.json +1 -0
@@ -0,0 +1,332 @@
1
+ import '@operato/data-grist'
2
+
3
+ import { CommonButtonStyles, CommonGristStyles, ScrollbarStyles } from '@operato/styles'
4
+ import { PageView, store } from '@operato/shell'
5
+ import { css, html } from 'lit'
6
+ import { customElement, property, query } from 'lit/decorators.js'
7
+ import { ScopedElementsMixin } from '@open-wc/scoped-elements'
8
+ import { ColumnConfig, DataGrist, FetchOption, SortersControl } from '@operato/data-grist'
9
+ import { client } from '@operato/graphql'
10
+ import { i18next, localize } from '@operato/i18n'
11
+ import { notify, openPopup } from '@operato/layout'
12
+ import { OxPopup } from '@operato/popup'
13
+ import { isMobileDevice } from '@operato/utils'
14
+
15
+ import { connect } from 'pwa-helpers/connect-mixin'
16
+ import gql from 'graphql-tag'
17
+
18
+ import { LedgerImporter } from './ledger-importer'
19
+
20
+ @customElement('ledger-list-page')
21
+ export class LedgerListPage extends connect(store)(localize(i18next)(ScopedElementsMixin(PageView))) {
22
+ static styles = [
23
+ ScrollbarStyles,
24
+ CommonGristStyles,
25
+ css`
26
+ :host {
27
+ display: flex;
28
+
29
+ width: 100%;
30
+
31
+ --grid-record-emphasized-background-color: red;
32
+ --grid-record-emphasized-color: yellow;
33
+ }
34
+ `
35
+ ]
36
+
37
+ static get scopedElements() {
38
+ return {
39
+ 'ledger-importer': LedgerImporter
40
+ }
41
+ }
42
+
43
+ @property({ type: Object }) gristConfig: any
44
+ @property({ type: String }) mode: 'CARD' | 'GRID' | 'LIST' = isMobileDevice() ? 'CARD' : 'GRID'
45
+
46
+ @query('ox-grist') private grist!: DataGrist
47
+ @query('#sorter-control') private sortersControl!: OxPopup
48
+
49
+ get context() {
50
+ return {
51
+ search: {
52
+ handler: (search: string) => {
53
+ this.grist.searchText = search
54
+ },
55
+ placeholder: i18next.t('title.ledger list'),
56
+ value: this.grist.searchText
57
+ },
58
+ filter: {
59
+ handler: () => {
60
+ this.grist.toggleHeadroom()
61
+ }
62
+ },
63
+ help: 'accounting/ledger',
64
+ actions: [
65
+ {
66
+ title: i18next.t('button.save'),
67
+ action: this._updateLedger.bind(this),
68
+ ...CommonButtonStyles.save
69
+ },
70
+ {
71
+ title: i18next.t('button.delete'),
72
+ action: this._deleteLedger.bind(this),
73
+ ...CommonButtonStyles.delete
74
+ }
75
+ ],
76
+ exportable: {
77
+ name: i18next.t('title.ledger list'),
78
+ data: this.exportHandler.bind(this)
79
+ },
80
+ importable: {
81
+ handler: this.importHandler.bind(this)
82
+ }
83
+ }
84
+ }
85
+
86
+ render() {
87
+ const mode = this.mode || (isMobileDevice() ? 'CARD' : 'GRID')
88
+
89
+ return html`
90
+ <ox-grist .mode=${mode} .config=${this.gristConfig} .fetchHandler=${this.fetchHandler.bind(this)}>
91
+ <div slot="headroom">
92
+ <div id="filters">
93
+ <ox-filters-form autofocus></ox-filters-form>
94
+ </div>
95
+
96
+ <div id="sorters">
97
+ Sort
98
+ <mwc-icon
99
+ @click=${e => {
100
+ const target = e.currentTarget
101
+ this.sortersControl.open({
102
+ right: 0,
103
+ top: target.offsetTop + target.offsetHeight
104
+ })
105
+ }}
106
+ >expand_more</mwc-icon
107
+ >
108
+ <ox-popup id="sorter-control">
109
+ <ox-sorters-control> </ox-sorters-control>
110
+ </ox-popup>
111
+ </div>
112
+
113
+ <div id="modes">
114
+ <mwc-icon @click=${() => (this.mode = 'GRID')} ?active=${mode == 'GRID'}>grid_on</mwc-icon>
115
+ <mwc-icon @click=${() => (this.mode = 'LIST')} ?active=${mode == 'LIST'}>format_list_bulleted</mwc-icon>
116
+ <mwc-icon @click=${() => (this.mode = 'CARD')} ?active=${mode == 'CARD'}>apps</mwc-icon>
117
+ </div>
118
+ </div>
119
+ </ox-grist>
120
+ `
121
+ }
122
+
123
+ async pageInitialized(lifecycle: any) {
124
+ this.gristConfig = {
125
+ list: {
126
+ fields: ['name', 'description'],
127
+ details: ['active', 'updatedAt']
128
+ },
129
+ columns: [
130
+ { type: 'gutter', gutterName: 'sequence' },
131
+ { type: 'gutter', gutterName: 'row-selector', multiple: true },
132
+ {
133
+ type: 'string',
134
+ name: 'name',
135
+ header: i18next.t('field.name'),
136
+ record: {
137
+ editable: true
138
+ },
139
+ filter: 'search',
140
+ sortable: true,
141
+ width: 150
142
+ },
143
+ {
144
+ type: 'string',
145
+ name: 'description',
146
+ header: i18next.t('field.description'),
147
+ record: {
148
+ editable: true
149
+ },
150
+ filter: 'search',
151
+ width: 200
152
+ },
153
+ {
154
+ type: 'checkbox',
155
+ name: 'active',
156
+ label: true,
157
+ header: i18next.t('field.active'),
158
+ record: {
159
+ editable: true
160
+ },
161
+ filter: true,
162
+ sortable: true,
163
+ width: 60
164
+ },
165
+ {
166
+ type: 'resource-object',
167
+ name: 'updater',
168
+ header: i18next.t('field.updater'),
169
+ record: {
170
+ editable: false
171
+ },
172
+ sortable: true,
173
+ width: 120
174
+ },
175
+ {
176
+ type: 'datetime',
177
+ name: 'updatedAt',
178
+ header: i18next.t('field.updated_at'),
179
+ record: {
180
+ editable: false
181
+ },
182
+ sortable: true,
183
+ width: 180
184
+ }
185
+ ],
186
+ rows: {
187
+ selectable: {
188
+ multiple: true
189
+ }
190
+ },
191
+ sorters: [
192
+ {
193
+ name: 'name'
194
+ }
195
+ ]
196
+ }
197
+ }
198
+
199
+ async pageUpdated(changes: any, lifecycle: any) {
200
+ if (this.active) {
201
+ // do something here when this page just became as active
202
+ }
203
+ }
204
+
205
+ async fetchHandler({ page = 1, limit = 100, sortings = [], filters = [] }: FetchOption) {
206
+ const response = await client.query({
207
+ query: gql`
208
+ query ($filters: [Filter!], $pagination: Pagination, $sortings: [Sorting!]) {
209
+ responses: ledgers(filters: $filters, pagination: $pagination, sortings: $sortings) {
210
+ items {
211
+ id
212
+ name
213
+ description
214
+ active
215
+ updater {
216
+ id
217
+ name
218
+ }
219
+ updatedAt
220
+ }
221
+ total
222
+ }
223
+ }
224
+ `,
225
+ variables: {
226
+ filters,
227
+ pagination: { page, limit },
228
+ sortings
229
+ }
230
+ })
231
+
232
+ return {
233
+ total: response.data.responses.total || 0,
234
+ records: response.data.responses.items || []
235
+ }
236
+ }
237
+
238
+ async _deleteLedger() {
239
+ if (confirm(i18next.t('text.sure_to_x', { x: i18next.t('text.delete') }))) {
240
+ const ids = this.grist.selected.map(record => record.id)
241
+ if (ids && ids.length > 0) {
242
+ const response = await client.mutate({
243
+ mutation: gql`
244
+ mutation ($ids: [String!]!) {
245
+ deleteLedgers(ids: $ids)
246
+ }
247
+ `,
248
+ variables: {
249
+ ids
250
+ }
251
+ })
252
+
253
+ if (!response.errors) {
254
+ this.grist.fetch()
255
+ notify({
256
+ message: i18next.t('text.info_x_successfully', { x: i18next.t('text.delete') })
257
+ })
258
+ }
259
+ }
260
+ }
261
+ }
262
+
263
+ async _updateLedger() {
264
+ let patches = this.grist.dirtyRecords
265
+ if (patches && patches.length) {
266
+ patches = patches.map(patch => {
267
+ let patchField: any = patch.id ? { id: patch.id } : {}
268
+ const dirtyFields = patch.__dirtyfields__
269
+ for (let key in dirtyFields) {
270
+ patchField[key] = dirtyFields[key].after
271
+ }
272
+ patchField.cuFlag = patch.__dirty__
273
+
274
+ return patchField
275
+ })
276
+
277
+ const response = await client.mutate({
278
+ mutation: gql`
279
+ mutation ($patches: [LedgerPatch!]!) {
280
+ updateMultipleLedger(patches: $patches) {
281
+ name
282
+ }
283
+ }
284
+ `,
285
+ variables: {
286
+ patches
287
+ }
288
+ })
289
+
290
+ if (!response.errors) {
291
+ this.grist.fetch()
292
+ }
293
+ }
294
+ }
295
+
296
+ async exportHandler() {
297
+ const exportTargets = this.grist.selected.length ? this.grist.selected : this.grist.dirtyData.records
298
+ const targetFieldSet = new Set(['id', 'name', 'description', 'active'])
299
+
300
+ return exportTargets.map(ledger => {
301
+ let tempObj = {}
302
+ for (const field of targetFieldSet) {
303
+ tempObj[field] = ledger[field]
304
+ }
305
+
306
+ return tempObj
307
+ })
308
+ }
309
+
310
+ async importHandler(records) {
311
+ const popup = openPopup(
312
+ html`
313
+ <ledger-importer
314
+ .ledgers=${records}
315
+ @imported=${() => {
316
+ history.back()
317
+ this.grist.fetch()
318
+ }}
319
+ ></ledger-importer>
320
+ `,
321
+ {
322
+ backdrop: true,
323
+ size: 'large',
324
+ title: i18next.t('title.import ledger')
325
+ }
326
+ )
327
+
328
+ popup.onclosed = () => {
329
+ this.grist.fetch()
330
+ }
331
+ }
332
+ }
@@ -0,0 +1,24 @@
1
+ import { html } from 'lit'
2
+ import { customElement, property } from 'lit/decorators.js'
3
+ import { connect } from 'pwa-helpers/connect-mixin.js'
4
+ import { store, PageView } from '@operato/shell'
5
+
6
+ const logo = new URL('/assets/images/hatiolab-logo.png', import.meta.url).href
7
+
8
+ @customElement('accounting-main')
9
+ class CashflowMain extends connect(store)(PageView) {
10
+ @property({ type: String }) accounting?: string
11
+
12
+ render() {
13
+ return html`
14
+ <section>
15
+ <h2>Accounting</h2>
16
+ <img src=${logo} />
17
+ </section>
18
+ `
19
+ }
20
+
21
+ stateChanged(state) {
22
+ this.accounting = state.accounting.state_main
23
+ }
24
+ }
@@ -0,0 +1,97 @@
1
+ import '@operato/data-grist'
2
+
3
+ import gql from 'graphql-tag'
4
+ import { css, html, LitElement } from 'lit'
5
+ import { property } from 'lit/decorators.js'
6
+
7
+ import { client } from '@operato/graphql'
8
+ import { i18next } from '@operato/i18n'
9
+ import { isMobileDevice } from '@operato/utils'
10
+
11
+ export class TransactionImporter extends LitElement {
12
+ static styles = [
13
+ css`
14
+ :host {
15
+ display: flex;
16
+ flex-direction: column;
17
+
18
+ background-color: #fff;
19
+ }
20
+
21
+ ox-grist {
22
+ flex: 1;
23
+ }
24
+
25
+ .button-container {
26
+ display: flex;
27
+ margin-left: auto;
28
+ padding: var(--padding-default);
29
+ }
30
+
31
+ mwc-button {
32
+ margin-left: var(--margin-default);
33
+ }
34
+ `
35
+ ]
36
+
37
+ @property({ type: Array }) transactions: any[] = []
38
+ @property({ type: Object }) columns = {
39
+ list: { fields: ['name', 'description'] },
40
+ pagination: { infinite: true },
41
+ columns: [
42
+ {
43
+ type: 'string',
44
+ name: 'name',
45
+ header: i18next.t('field.name'),
46
+ width: 150
47
+ },
48
+ {
49
+ type: 'string',
50
+ name: 'description',
51
+ header: i18next.t('field.description'),
52
+ width: 200
53
+ },
54
+ {
55
+ type: 'checkbox',
56
+ name: 'active',
57
+ header: i18next.t('field.active'),
58
+ width: 60
59
+ }
60
+ ]
61
+ }
62
+
63
+
64
+ render() {
65
+ return html`
66
+ <ox-grist
67
+ .mode=${isMobileDevice() ? 'LIST' : 'GRID'}
68
+ .config=${this.columns}
69
+ .data=${
70
+ {
71
+ records: this.transactions
72
+ }
73
+ }
74
+ ></ox-grist>
75
+
76
+ <div class="button-container">
77
+ <mwc-button raised @click="${this.save.bind(this)}">${i18next.t('button.save')}</mwc-button>
78
+ </div>
79
+ `
80
+ }
81
+
82
+ async save() {
83
+ const response = await client.mutate({
84
+ mutation: gql`
85
+ mutation importTransactions($transactions: [TransactionPatch!]!) {
86
+ importTransactions(transactions: $transactions)
87
+ }
88
+ `,
89
+ variables: { transactions: this.transactions }
90
+ })
91
+
92
+ if (response.errors?.length) return
93
+
94
+ this.dispatchEvent(new CustomEvent('imported'))
95
+ }
96
+ }
97
+