@things-factory/accounting 8.0.0-alpha.1 → 8.0.0-alpha.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (279) hide show
  1. package/client/bootstrap.ts +10 -1
  2. package/client/components/accounting-category-selector.ts +136 -0
  3. package/client/components/accounting-category-view.ts +75 -0
  4. package/client/grist-editors/grist-editor-accounting-category-object.ts +83 -0
  5. package/client/grist-editors/grist-renderer-accounting-category-object.ts +13 -0
  6. package/client/pages/account/account-list-page.ts +33 -2
  7. package/client/pages/accounting-category/accounting-category-list-page.ts +31 -1
  8. package/client/pages/accounting-category/accounting-category-tree-page.ts +338 -0
  9. package/client/pages/accounting-document/accounting-document-importer.ts +90 -0
  10. package/client/pages/accounting-document/accounting-document-list-page.ts +398 -0
  11. package/client/pages/{ledger/ledger-importer.ts → payment/payment-importer.ts} +10 -17
  12. package/client/pages/{ledger/ledger-list-page.ts → payment/payment-list-page.ts} +118 -57
  13. package/client/route.ts +0 -4
  14. package/client/types/accounting-category.ts +23 -0
  15. package/client/types/index.ts +1 -0
  16. package/dist-client/bootstrap.js +7 -1
  17. package/dist-client/bootstrap.js.map +1 -1
  18. package/dist-client/components/accounting-category-selector.d.ts +16 -0
  19. package/dist-client/components/accounting-category-selector.js +134 -0
  20. package/dist-client/components/accounting-category-selector.js.map +1 -0
  21. package/dist-client/components/accounting-category-view.d.ts +14 -0
  22. package/dist-client/components/accounting-category-view.js +81 -0
  23. package/dist-client/components/accounting-category-view.js.map +1 -0
  24. package/dist-client/grist-editors/grist-editor-accounting-category-object.d.ts +11 -0
  25. package/dist-client/grist-editors/grist-editor-accounting-category-object.js +71 -0
  26. package/dist-client/grist-editors/grist-editor-accounting-category-object.js.map +1 -0
  27. package/dist-client/grist-editors/grist-renderer-accounting-category-object.d.ts +2 -0
  28. package/dist-client/grist-editors/grist-renderer-accounting-category-object.js +9 -0
  29. package/dist-client/grist-editors/grist-renderer-accounting-category-object.js.map +1 -0
  30. package/dist-client/pages/account/account-list-page.js +33 -2
  31. package/dist-client/pages/account/account-list-page.js.map +1 -1
  32. package/dist-client/pages/accounting-category/accounting-category-list-page.js +31 -1
  33. package/dist-client/pages/accounting-category/accounting-category-list-page.js.map +1 -1
  34. package/dist-client/pages/accounting-category/accounting-category-tree-page.d.ts +46 -0
  35. package/dist-client/pages/accounting-category/accounting-category-tree-page.js +329 -0
  36. package/dist-client/pages/accounting-category/accounting-category-tree-page.js.map +1 -0
  37. package/dist-client/pages/accounting-document/accounting-document-importer.d.ts +23 -0
  38. package/dist-client/pages/accounting-document/accounting-document-importer.js +93 -0
  39. package/dist-client/pages/accounting-document/accounting-document-importer.js.map +1 -0
  40. package/dist-client/pages/accounting-document/accounting-document-list-page.d.ts +66 -0
  41. package/dist-client/pages/accounting-document/accounting-document-list-page.js +370 -0
  42. package/dist-client/pages/accounting-document/accounting-document-list-page.js.map +1 -0
  43. package/dist-client/pages/{ledger/ledger-importer.d.ts → payment/payment-importer.d.ts} +3 -2
  44. package/dist-client/pages/{ledger/ledger-importer.js → payment/payment-importer.js} +14 -21
  45. package/dist-client/pages/payment/payment-importer.js.map +1 -0
  46. package/dist-client/pages/{ledger/ledger-list-page.d.ts → payment/payment-list-page.d.ts} +12 -8
  47. package/dist-client/pages/{ledger/ledger-list-page.js → payment/payment-list-page.js} +114 -67
  48. package/dist-client/pages/payment/payment-list-page.js.map +1 -0
  49. package/dist-client/route.d.ts +1 -1
  50. package/dist-client/route.js +0 -3
  51. package/dist-client/route.js.map +1 -1
  52. package/dist-client/tsconfig.tsbuildinfo +1 -1
  53. package/dist-client/types/accounting-category.d.ts +16 -0
  54. package/dist-client/types/accounting-category.js +3 -0
  55. package/dist-client/types/accounting-category.js.map +1 -0
  56. package/dist-client/types/index.d.ts +1 -0
  57. package/dist-client/types/index.js +2 -0
  58. package/dist-client/types/index.js.map +1 -0
  59. package/dist-server/activities/activity-book.js +31 -19
  60. package/dist-server/activities/activity-book.js.map +1 -1
  61. package/dist-server/controllers/summary-statements.js +13 -7
  62. package/dist-server/controllers/summary-statements.js.map +1 -1
  63. package/dist-server/index.d.ts +1 -0
  64. package/dist-server/index.js +1 -0
  65. package/dist-server/index.js.map +1 -1
  66. package/dist-server/migrations/1725200507196-seed-fiscal-entities.js +3 -3
  67. package/dist-server/migrations/1725200507196-seed-fiscal-entities.js.map +1 -1
  68. package/dist-server/migrations/1725201467183-seed-accounts.js +31 -31
  69. package/dist-server/migrations/1725201467183-seed-accounts.js.map +1 -1
  70. package/dist-server/routes.d.ts +0 -1
  71. package/dist-server/routes.js +0 -1
  72. package/dist-server/routes.js.map +1 -1
  73. package/dist-server/service/account/account-history.d.ts +4 -1
  74. package/dist-server/service/account/account-history.js +14 -4
  75. package/dist-server/service/account/account-history.js.map +1 -1
  76. package/dist-server/service/account/account-mutation.js +13 -9
  77. package/dist-server/service/account/account-mutation.js.map +1 -1
  78. package/dist-server/service/account/account-query.js +2 -0
  79. package/dist-server/service/account/account-query.js.map +1 -1
  80. package/dist-server/service/account/account.d.ts +1 -1
  81. package/dist-server/service/account/account.js +15 -4
  82. package/dist-server/service/account/account.js.map +1 -1
  83. package/dist-server/service/account/index.d.ts +1 -2
  84. package/dist-server/service/accounting-category/accounting-category-history.d.ts +26 -0
  85. package/dist-server/service/accounting-category/accounting-category-history.js +136 -0
  86. package/dist-server/service/accounting-category/accounting-category-history.js.map +1 -0
  87. package/dist-server/service/accounting-category/accounting-category-mutation.js +12 -8
  88. package/dist-server/service/accounting-category/accounting-category-mutation.js.map +1 -1
  89. package/dist-server/service/accounting-category/accounting-category-query.d.ts +1 -0
  90. package/dist-server/service/accounting-category/accounting-category-query.js +23 -0
  91. package/dist-server/service/accounting-category/accounting-category-query.js.map +1 -1
  92. package/dist-server/service/accounting-category/accounting-category.d.ts +1 -0
  93. package/dist-server/service/accounting-category/accounting-category.js +14 -3
  94. package/dist-server/service/accounting-category/accounting-category.js.map +1 -1
  95. package/dist-server/service/accounting-category/event-subscriber.d.ts +7 -0
  96. package/dist-server/service/accounting-category/event-subscriber.js +21 -0
  97. package/dist-server/service/accounting-category/event-subscriber.js.map +1 -0
  98. package/dist-server/service/accounting-category/index.d.ts +2 -1
  99. package/dist-server/service/accounting-category/index.js +4 -2
  100. package/dist-server/service/accounting-category/index.js.map +1 -1
  101. package/dist-server/service/accounting-document/accounting-document-history.d.ts +26 -0
  102. package/dist-server/service/accounting-document/accounting-document-history.js +129 -0
  103. package/dist-server/service/accounting-document/accounting-document-history.js.map +1 -0
  104. package/dist-server/service/accounting-document/accounting-document-mutation.d.ts +10 -0
  105. package/dist-server/service/accounting-document/accounting-document-mutation.js +128 -0
  106. package/dist-server/service/accounting-document/accounting-document-mutation.js.map +1 -0
  107. package/dist-server/service/accounting-document/accounting-document-query.d.ts +11 -0
  108. package/dist-server/service/accounting-document/accounting-document-query.js +79 -0
  109. package/dist-server/service/accounting-document/accounting-document-query.js.map +1 -0
  110. package/dist-server/service/accounting-document/accounting-document-type.d.ts +20 -0
  111. package/dist-server/service/accounting-document/accounting-document-type.js +74 -0
  112. package/dist-server/service/accounting-document/accounting-document-type.js.map +1 -0
  113. package/dist-server/service/accounting-document/accounting-document.d.ts +21 -0
  114. package/dist-server/service/accounting-document/accounting-document.js +104 -0
  115. package/dist-server/service/accounting-document/accounting-document.js.map +1 -0
  116. package/dist-server/service/accounting-document/event-subscriber.d.ts +7 -0
  117. package/dist-server/service/accounting-document/event-subscriber.js +21 -0
  118. package/dist-server/service/accounting-document/event-subscriber.js.map +1 -0
  119. package/dist-server/service/accounting-document/index.d.ts +7 -0
  120. package/dist-server/service/accounting-document/index.js +12 -0
  121. package/dist-server/service/accounting-document/index.js.map +1 -0
  122. package/dist-server/service/financial-statement/financial-statement-history.d.ts +9 -6
  123. package/dist-server/service/financial-statement/financial-statement-history.js +30 -20
  124. package/dist-server/service/financial-statement/financial-statement-history.js.map +1 -1
  125. package/dist-server/service/financial-statement/financial-statement-line-item.d.ts +19 -0
  126. package/dist-server/service/financial-statement/financial-statement-line-item.js +94 -0
  127. package/dist-server/service/financial-statement/financial-statement-line-item.js.map +1 -0
  128. package/dist-server/service/financial-statement/financial-statement-mutation.js +12 -8
  129. package/dist-server/service/financial-statement/financial-statement-mutation.js.map +1 -1
  130. package/dist-server/service/financial-statement/financial-statement-query.js +2 -0
  131. package/dist-server/service/financial-statement/financial-statement-query.js.map +1 -1
  132. package/dist-server/service/financial-statement/financial-statement.d.ts +2 -0
  133. package/dist-server/service/financial-statement/financial-statement.js +45 -24
  134. package/dist-server/service/financial-statement/financial-statement.js.map +1 -1
  135. package/dist-server/service/financial-statement/index.d.ts +2 -2
  136. package/dist-server/service/financial-statement/index.js +2 -1
  137. package/dist-server/service/financial-statement/index.js.map +1 -1
  138. package/dist-server/service/fiscal-month/fiscal-month-mutation.js +6 -0
  139. package/dist-server/service/fiscal-month/fiscal-month-mutation.js.map +1 -1
  140. package/dist-server/service/fiscal-month/fiscal-month-query.js +2 -0
  141. package/dist-server/service/fiscal-month/fiscal-month-query.js.map +1 -1
  142. package/dist-server/service/fiscal-month/fiscal-month.js +1 -1
  143. package/dist-server/service/fiscal-month/fiscal-month.js.map +1 -1
  144. package/dist-server/service/fiscal-quarter/fiscal-quarter-mutation.js +6 -0
  145. package/dist-server/service/fiscal-quarter/fiscal-quarter-mutation.js.map +1 -1
  146. package/dist-server/service/fiscal-quarter/fiscal-quarter-query.js +2 -0
  147. package/dist-server/service/fiscal-quarter/fiscal-quarter-query.js.map +1 -1
  148. package/dist-server/service/fiscal-quarter/fiscal-quarter.js +1 -1
  149. package/dist-server/service/fiscal-quarter/fiscal-quarter.js.map +1 -1
  150. package/dist-server/service/fiscal-year/fiscal-year-mutation.js +6 -0
  151. package/dist-server/service/fiscal-year/fiscal-year-mutation.js.map +1 -1
  152. package/dist-server/service/fiscal-year/fiscal-year-query.js +2 -0
  153. package/dist-server/service/fiscal-year/fiscal-year-query.js.map +1 -1
  154. package/dist-server/service/fiscal-year/fiscal-year.js +1 -1
  155. package/dist-server/service/fiscal-year/fiscal-year.js.map +1 -1
  156. package/dist-server/service/income-statement/income-statement-history.d.ts +9 -5
  157. package/dist-server/service/income-statement/income-statement-history.js +35 -20
  158. package/dist-server/service/income-statement/income-statement-history.js.map +1 -1
  159. package/dist-server/service/income-statement/income-statement-line-item.d.ts +19 -0
  160. package/dist-server/service/income-statement/income-statement-line-item.js +96 -0
  161. package/dist-server/service/income-statement/income-statement-line-item.js.map +1 -0
  162. package/dist-server/service/income-statement/income-statement-mutation.js +12 -8
  163. package/dist-server/service/income-statement/income-statement-mutation.js.map +1 -1
  164. package/dist-server/service/income-statement/income-statement-query.js +2 -0
  165. package/dist-server/service/income-statement/income-statement-query.js.map +1 -1
  166. package/dist-server/service/income-statement/income-statement.d.ts +2 -0
  167. package/dist-server/service/income-statement/income-statement.js +46 -26
  168. package/dist-server/service/income-statement/income-statement.js.map +1 -1
  169. package/dist-server/service/income-statement/index.d.ts +2 -2
  170. package/dist-server/service/income-statement/index.js +2 -1
  171. package/dist-server/service/income-statement/index.js.map +1 -1
  172. package/dist-server/service/index.d.ts +4 -2
  173. package/dist-server/service/index.js +10 -0
  174. package/dist-server/service/index.js.map +1 -1
  175. package/dist-server/service/payment/event-subscriber.d.ts +7 -0
  176. package/dist-server/service/payment/event-subscriber.js +21 -0
  177. package/dist-server/service/payment/event-subscriber.js.map +1 -0
  178. package/dist-server/service/payment/index.d.ts +8 -0
  179. package/dist-server/service/payment/index.js +12 -0
  180. package/dist-server/service/payment/index.js.map +1 -0
  181. package/dist-server/service/payment/payment-history.d.ts +30 -0
  182. package/dist-server/service/payment/payment-history.js +143 -0
  183. package/dist-server/service/payment/payment-history.js.map +1 -0
  184. package/dist-server/service/payment/payment-mutation.d.ts +10 -0
  185. package/dist-server/service/payment/payment-mutation.js +134 -0
  186. package/dist-server/service/payment/payment-mutation.js.map +1 -0
  187. package/dist-server/service/payment/payment-query.d.ts +11 -0
  188. package/dist-server/service/payment/payment-query.js +81 -0
  189. package/dist-server/service/payment/payment-query.js.map +1 -0
  190. package/dist-server/service/payment/payment-type.d.ts +24 -0
  191. package/dist-server/service/payment/payment-type.js +90 -0
  192. package/dist-server/service/payment/payment-type.js.map +1 -0
  193. package/dist-server/service/payment/payment.d.ts +30 -0
  194. package/dist-server/service/payment/payment.js +146 -0
  195. package/dist-server/service/payment/payment.js.map +1 -0
  196. package/dist-server/service/transaction/index.d.ts +2 -1
  197. package/dist-server/service/transaction/transaction-history.d.ts +6 -2
  198. package/dist-server/service/transaction/transaction-history.js +28 -9
  199. package/dist-server/service/transaction/transaction-history.js.map +1 -1
  200. package/dist-server/service/transaction/transaction-mutation.js +13 -9
  201. package/dist-server/service/transaction/transaction-mutation.js.map +1 -1
  202. package/dist-server/service/transaction/transaction-query.js +2 -0
  203. package/dist-server/service/transaction/transaction-query.js.map +1 -1
  204. package/dist-server/service/transaction/transaction.d.ts +28 -6
  205. package/dist-server/service/transaction/transaction.js +119 -31
  206. package/dist-server/service/transaction/transaction.js.map +1 -1
  207. package/dist-server/tsconfig.tsbuildinfo +1 -1
  208. package/helps/accounting/accounting-document.md +160 -0
  209. package/helps/accounting/contract.md +160 -0
  210. package/helps/accounting/payment.md +160 -0
  211. package/package.json +5 -5
  212. package/server/activities/activity-book.ts +31 -19
  213. package/server/controllers/summary-statements.ts +13 -7
  214. package/server/index.ts +1 -0
  215. package/server/migrations/1725200507196-seed-fiscal-entities.ts +3 -3
  216. package/server/migrations/1725201467183-seed-accounts.ts +31 -31
  217. package/server/routes.ts +0 -2
  218. package/server/service/account/account-history.ts +14 -6
  219. package/server/service/account/account-mutation.ts +13 -10
  220. package/server/service/account/account-query.ts +2 -0
  221. package/server/service/account/account.ts +15 -4
  222. package/server/service/accounting-category/accounting-category-history.ts +123 -0
  223. package/server/service/accounting-category/accounting-category-mutation.ts +12 -9
  224. package/server/service/accounting-category/accounting-category-query.ts +23 -0
  225. package/server/service/accounting-category/accounting-category.ts +14 -3
  226. package/server/service/accounting-category/event-subscriber.ts +20 -0
  227. package/server/service/accounting-category/index.ts +4 -2
  228. package/server/service/accounting-document/accounting-document-history.ts +117 -0
  229. package/server/service/accounting-document/accounting-document-mutation.ts +137 -0
  230. package/server/service/accounting-document/accounting-document-query.ts +48 -0
  231. package/server/service/accounting-document/accounting-document-type.ts +52 -0
  232. package/server/service/accounting-document/accounting-document.ts +93 -0
  233. package/server/service/accounting-document/event-subscriber.ts +17 -0
  234. package/server/service/accounting-document/index.ts +9 -0
  235. package/server/service/financial-statement/financial-statement-history.ts +27 -18
  236. package/server/service/financial-statement/financial-statement-line-item.ts +82 -0
  237. package/server/service/financial-statement/financial-statement-mutation.ts +12 -9
  238. package/server/service/financial-statement/financial-statement-query.ts +2 -0
  239. package/server/service/financial-statement/financial-statement.ts +52 -36
  240. package/server/service/financial-statement/index.ts +2 -1
  241. package/server/service/fiscal-month/fiscal-month-mutation.ts +10 -2
  242. package/server/service/fiscal-month/fiscal-month-query.ts +3 -1
  243. package/server/service/fiscal-month/fiscal-month.ts +1 -1
  244. package/server/service/fiscal-quarter/fiscal-quarter-mutation.ts +14 -3
  245. package/server/service/fiscal-quarter/fiscal-quarter-query.ts +2 -0
  246. package/server/service/fiscal-quarter/fiscal-quarter.ts +1 -1
  247. package/server/service/fiscal-year/fiscal-year-mutation.ts +10 -2
  248. package/server/service/fiscal-year/fiscal-year-query.ts +2 -0
  249. package/server/service/fiscal-year/fiscal-year.ts +1 -1
  250. package/server/service/income-statement/income-statement-history.ts +30 -17
  251. package/server/service/income-statement/income-statement-line-item.ts +84 -0
  252. package/server/service/income-statement/income-statement-mutation.ts +12 -10
  253. package/server/service/income-statement/income-statement-query.ts +2 -0
  254. package/server/service/income-statement/income-statement.ts +54 -39
  255. package/server/service/income-statement/index.ts +2 -1
  256. package/server/service/index.ts +18 -0
  257. package/server/service/payment/event-subscriber.ts +17 -0
  258. package/server/service/payment/index.ts +9 -0
  259. package/server/service/payment/payment-history.ts +126 -0
  260. package/server/service/payment/payment-mutation.ts +139 -0
  261. package/server/service/payment/payment-query.ts +50 -0
  262. package/server/service/payment/payment-type.ts +64 -0
  263. package/server/service/payment/payment.ts +123 -0
  264. package/server/service/transaction/transaction-history.ts +24 -8
  265. package/server/service/transaction/transaction-mutation.ts +13 -10
  266. package/server/service/transaction/transaction-query.ts +2 -0
  267. package/server/service/transaction/transaction.ts +130 -34
  268. package/things-factory.config.js +0 -1
  269. package/translations/en.json +9 -1
  270. package/translations/ja.json +9 -1
  271. package/translations/ko.json +9 -1
  272. package/translations/ms.json +9 -1
  273. package/translations/zh.json +9 -1
  274. package/client/pages/main.ts +0 -24
  275. package/dist-client/pages/ledger/ledger-importer.js.map +0 -1
  276. package/dist-client/pages/ledger/ledger-list-page.js.map +0 -1
  277. package/dist-client/pages/main.d.ts +0 -1
  278. package/dist-client/pages/main.js +0 -27
  279. package/dist-client/pages/main.js.map +0 -1
@@ -0,0 +1,338 @@
1
+ import '@operato/data-tree'
2
+ import '@operato/context/ox-context-page-toolbar.js'
3
+
4
+ import { css, html, PropertyValues } from 'lit'
5
+ import { customElement, property, query, state } from 'lit/decorators.js'
6
+ import { ScopedElementsMixin } from '@open-wc/scoped-elements'
7
+ import { client } from '@operato/graphql'
8
+ import { i18next, localize } from '@operato/i18n'
9
+ import { CommonHeaderStyles, ScrollbarStyles } from '@operato/styles'
10
+ import { CustomAlert, PageView, store } from '@operato/shell'
11
+
12
+ import { connect } from 'pwa-helpers/connect-mixin'
13
+ import gql from 'graphql-tag'
14
+
15
+ import { AccountingCategory } from '../../types/accounting-category'
16
+
17
+ import { AccountingCategoryView } from '../../components/accounting-category-view'
18
+
19
+ const SubAccountingCategoryFragment = gql`
20
+ fragment SubAccountingCategoryFragment on AccountingCategory {
21
+ id
22
+ code
23
+ name
24
+ description
25
+ active
26
+ updater {
27
+ id
28
+ name
29
+ }
30
+ updatedAt
31
+ }
32
+ `
33
+
34
+ @customElement('accounting-category-tree-page')
35
+ export class AccountingCategoryTreePage extends connect(store)(localize(i18next)(ScopedElementsMixin(PageView))) {
36
+ static styles = [
37
+ CommonHeaderStyles,
38
+ ScrollbarStyles,
39
+ css`
40
+ :host {
41
+ display: flex;
42
+ flex-direction: column;
43
+
44
+ width: 100%;
45
+ overflow: auto;
46
+ }
47
+
48
+ content {
49
+ flex: 1;
50
+ display: flex;
51
+ flex-direction: row;
52
+ }
53
+
54
+ div[editor] {
55
+ width: 300px;
56
+ display: flex;
57
+ flex-direction: column;
58
+ }
59
+
60
+ ox-tree-vertical {
61
+ flex: 1;
62
+ overflow: auto;
63
+ }
64
+
65
+ accounting-category-view {
66
+ flex: 1;
67
+ padding: var(--spacing-medium);
68
+ background-color: var(--md-sys-color-surface-variant);
69
+ overflow: auto;
70
+ }
71
+
72
+ .footer button[disabled] {
73
+ color: var(--md-sys-color-surface-dim);
74
+ background-color: transparent;
75
+ }
76
+ `
77
+ ]
78
+
79
+ @state() root?: AccountingCategory
80
+ @state() selected?: AccountingCategory
81
+ @state() accountingCategory?: AccountingCategory
82
+ @state() modified: boolean = false
83
+ @state() appendable: boolean = false
84
+
85
+ @query('accounting-category-view') accountingCategoryView!: AccountingCategoryView
86
+
87
+ get context() {
88
+ return {
89
+ title: i18next.t('title.accounting-category list'),
90
+ help: 'accounting/accounting-category',
91
+ actions: [
92
+ {
93
+ icon: 'delete',
94
+ title: i18next.t('button.delete'),
95
+ action: this.delete.bind(this),
96
+ emphasis: {
97
+ danger: true
98
+ }
99
+ }
100
+ ].filter(Boolean),
101
+ toolbar: false
102
+ }
103
+ }
104
+
105
+ render() {
106
+ return html`
107
+ <div class="header">
108
+ <ox-context-page-toolbar class="actions" .context=${this.context}></ox-context-page-toolbar>
109
+ </div>
110
+
111
+ <content>
112
+ <ox-tree-vertical
113
+ .data=${this.root}
114
+ .selected=${this.selected}
115
+ @select=${this.onSelect.bind(this)}
116
+ id-property="code"
117
+ label-property="name"
118
+ description-property="description"
119
+ ></ox-tree-vertical>
120
+
121
+ <div editor>
122
+ <accounting-category-view
123
+ .accountingCategory=${this.accountingCategory}
124
+ @property-change=${(e: CustomEvent) => {
125
+ const { code, name } = e.detail || {}
126
+
127
+ this.modified = true
128
+ this.appendable = code && code !== this.selected?.code && name !== this.selected?.name
129
+ }}
130
+ ></accounting-category-view>
131
+ <div class="footer">
132
+ <button @click=${this.reset.bind(this)}><md-icon>restart_alt</md-icon>${i18next.t('button.reset')}</button>
133
+ <div filler></div>
134
+ <button @click=${this.create.bind(this)} ?disabled=${!this.appendable}>
135
+ <md-icon>add</md-icon>${i18next.t('button.add')}
136
+ </button>
137
+ <button @click=${this.save.bind(this)} ?disabled=${!this.modified} done>
138
+ <md-icon>save</md-icon>${i18next.t('button.save')}
139
+ </button>
140
+ </div>
141
+ </div>
142
+ </content>
143
+ `
144
+ }
145
+
146
+ updated(changes: PropertyValues<this>) {
147
+ if (changes.has('selected')) {
148
+ this.modified = false
149
+ this.accountingCategory = { ...this.selected }
150
+ }
151
+ }
152
+
153
+ onSelect(e: CustomEvent) {
154
+ this.selected = e.detail as AccountingCategory
155
+ this.updateContext()
156
+ }
157
+
158
+ reset() {
159
+ this.accountingCategoryView.accountingCategory = {}
160
+ }
161
+
162
+ async create() {
163
+ const { id: parentId } = this.accountingCategory || {}
164
+ const { code, name, description, active } = this.accountingCategory || {}
165
+
166
+ var accountingCategory = {
167
+ code,
168
+ name,
169
+ description,
170
+ active
171
+ } as any
172
+
173
+ if (parentId) {
174
+ accountingCategory.parent = { id: parentId }
175
+ }
176
+
177
+ const response = await client.mutate({
178
+ mutation: gql`
179
+ mutation ($accountingCategory: NewAccountingCategory!) {
180
+ createAccountingCategory(accountingCategory: $accountingCategory) {
181
+ ...SubAccountingCategoryFragment
182
+ }
183
+ }
184
+
185
+ ${SubAccountingCategoryFragment}
186
+ `,
187
+ variables: {
188
+ accountingCategory
189
+ }
190
+ })
191
+
192
+ this.selected = response.data.createAccountingCategory
193
+ this.updateContext()
194
+
195
+ await this.fetch()
196
+ }
197
+
198
+ async save() {
199
+ const { id, code, name, description, active } = this.accountingCategory || {}
200
+
201
+ if (!id) {
202
+ await CustomAlert({
203
+ type: 'warning',
204
+ title: 'accounting-category not selected',
205
+ text: 'Please select accounting-category first.',
206
+ confirmButton: { text: i18next.t('button.confirm') }
207
+ })
208
+
209
+ return
210
+ }
211
+
212
+ var patch = {
213
+ code,
214
+ name,
215
+ description,
216
+ active
217
+ } as any
218
+
219
+ const response = await client.mutate({
220
+ mutation: gql`
221
+ mutation ($id: String!, $patch: AccountingCategoryPatch!) {
222
+ updateAccountingCategory(id: $id, patch: $patch) {
223
+ ...SubAccountingCategoryFragment
224
+ }
225
+ }
226
+
227
+ ${SubAccountingCategoryFragment}
228
+ `,
229
+ variables: {
230
+ id,
231
+ patch
232
+ },
233
+ context: {
234
+ hasUpload: true
235
+ }
236
+ })
237
+
238
+ this.selected = response.data.updateAccountingCategory
239
+
240
+ this.fetch()
241
+ }
242
+
243
+ async delete() {
244
+ if (!this.selected) {
245
+ await CustomAlert({
246
+ type: 'warning',
247
+ title: 'accounting category not selected',
248
+ text: 'Please select accounting category first.',
249
+ confirmButton: { text: i18next.t('button.confirm') }
250
+ })
251
+
252
+ return
253
+ }
254
+
255
+ const children = this.selected?.children
256
+ if (children && children.length > 0) {
257
+ await CustomAlert({
258
+ type: 'warning',
259
+ title: 'AccountingCategorys with subordinates cannot be deleted.',
260
+ text: 'AccountingCategory having children cannot be deleted.',
261
+ confirmButton: { text: i18next.t('button.confirm') }
262
+ })
263
+
264
+ return
265
+ }
266
+
267
+ if (confirm(i18next.t('text.sure_to_x', { x: i18next.t('text.delete') }))) {
268
+ const { id } = this.selected || {}
269
+
270
+ const response = await client.mutate({
271
+ mutation: gql`
272
+ mutation ($id: String!) {
273
+ deleteAccountingCategory(id: $id)
274
+ }
275
+ `,
276
+ variables: {
277
+ id
278
+ }
279
+ })
280
+
281
+ this.selected = {}
282
+ this.updateContext()
283
+
284
+ await this.fetch()
285
+ }
286
+ }
287
+
288
+ async pageInitialized(lifecycle: any) {
289
+ this.fetch()
290
+ }
291
+
292
+ async pageUpdated(changes: any, lifecycle: any) {
293
+ if (this.active) {
294
+ // do something here when this page just became as active
295
+ }
296
+ }
297
+
298
+ async fetch() {
299
+ const response = await client.query({
300
+ query: gql`
301
+ query {
302
+ responses: accountingCategoryRoots {
303
+ total
304
+ items {
305
+ ...SubAccountingCategoryFragment
306
+ children {
307
+ ...SubAccountingCategoryFragment
308
+ children {
309
+ ...SubAccountingCategoryFragment
310
+ children {
311
+ ...SubAccountingCategoryFragment
312
+ children {
313
+ ...SubAccountingCategoryFragment
314
+ children {
315
+ ...SubAccountingCategoryFragment
316
+ children {
317
+ ...SubAccountingCategoryFragment
318
+ children {
319
+ ...SubAccountingCategoryFragment
320
+ }
321
+ }
322
+ }
323
+ }
324
+ }
325
+ }
326
+ }
327
+ }
328
+ }
329
+ }
330
+
331
+ ${SubAccountingCategoryFragment}
332
+ `
333
+ })
334
+ const { items: records, total } = response.data.responses
335
+
336
+ this.root = records[0]
337
+ }
338
+ }
@@ -0,0 +1,90 @@
1
+ import '@material/web/icon/icon.js'
2
+ import '@operato/data-grist'
3
+
4
+ import gql from 'graphql-tag'
5
+ import { css, html, LitElement } from 'lit'
6
+ import { property } from 'lit/decorators.js'
7
+
8
+ import { client } from '@operato/graphql'
9
+ import { i18next } from '@operato/i18n'
10
+ import { isMobileDevice } from '@operato/utils'
11
+ import { ButtonContainerStyles } from '@operato/styles'
12
+
13
+ export class AccountingDocumentImporter extends LitElement {
14
+ static styles = [
15
+ ButtonContainerStyles,
16
+ css`
17
+ :host {
18
+ display: flex;
19
+ flex-direction: column;
20
+
21
+ background-color: #fff;
22
+ }
23
+
24
+ ox-grist {
25
+ flex: 1;
26
+ }
27
+ `
28
+ ]
29
+
30
+ @property({ type: Array }) accountingDocuments: any[] = []
31
+ @property({ type: Object }) columns = {
32
+ list: { fields: ['name', 'description'] },
33
+ pagination: { infinite: true },
34
+ columns: [
35
+ {
36
+ type: 'string',
37
+ name: 'name',
38
+ header: i18next.t('field.name'),
39
+ width: 150
40
+ },
41
+ {
42
+ type: 'string',
43
+ name: 'description',
44
+ header: i18next.t('field.description'),
45
+ width: 200
46
+ },
47
+ {
48
+ type: 'checkbox',
49
+ name: 'active',
50
+ header: i18next.t('field.active'),
51
+ width: 60
52
+ }
53
+ ]
54
+ }
55
+
56
+
57
+ render() {
58
+ return html`
59
+ <ox-grist
60
+ .mode=${isMobileDevice() ? 'LIST' : 'GRID'}
61
+ .config=${this.columns}
62
+ .data=${
63
+ {
64
+ records: this.accountingDocuments
65
+ }
66
+ }
67
+ ></ox-grist>
68
+
69
+ <div class="button-container">
70
+ <button @click="${this.save.bind(this)}"><md-icon>save</md-icon>${i18next.t('button.save')}</button>
71
+ </div>
72
+ `
73
+ }
74
+
75
+ async save() {
76
+ const response = await client.mutate({
77
+ mutation: gql`
78
+ mutation importAccountingDocuments($accountingDocuments: [AccountingDocumentPatch!]!) {
79
+ importAccountingDocuments(accountingDocuments: $accountingDocuments)
80
+ }
81
+ `,
82
+ variables: { accountingDocuments: this.accountingDocuments }
83
+ })
84
+
85
+ if (response.errors?.length) return
86
+
87
+ this.dispatchEvent(new CustomEvent('imported'))
88
+ }
89
+ }
90
+