mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-22 07:40:32 +00:00
Compare commits
103 Commits
big-80-ent
...
v0.14.0
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6b77bda77f | ||
|
|
ba387e81f7 | ||
|
|
0414c090ea | ||
|
|
a52f3a933f | ||
|
|
d01eacf8d9 | ||
|
|
0da151faaa | ||
|
|
f93c8b46dc | ||
|
|
59c5c8979d | ||
|
|
74a07847a4 | ||
|
|
1740226294 | ||
|
|
1b20d1b073 | ||
|
|
ac7175d83b | ||
|
|
d72d8e60d6 | ||
|
|
de5920f910 | ||
|
|
475c4e9967 | ||
|
|
21eb88ef53 | ||
|
|
429159acf9 | ||
|
|
7eb84474a5 | ||
|
|
e42adcae63 | ||
|
|
abffdd1029 | ||
|
|
d052c23560 | ||
|
|
f02afd3c9f | ||
|
|
3df17390e2 | ||
|
|
df38f8893d | ||
|
|
8882bc677e | ||
|
|
f03d01113c | ||
|
|
8f431597d9 | ||
|
|
03bc78a068 | ||
|
|
ecf5d60db0 | ||
|
|
3a5fd2782a | ||
|
|
1d8416ebfe | ||
|
|
3672abe7a5 | ||
|
|
2753908b83 | ||
|
|
8495990ec2 | ||
|
|
471ce1b7af | ||
|
|
4a920176f4 | ||
|
|
74fd76ce77 | ||
|
|
c9f57d9a75 | ||
|
|
6c9810ea4c | ||
|
|
1e4b29f83c | ||
|
|
2b03ac7f16 | ||
|
|
2cb8c2932f | ||
|
|
2814d23f75 | ||
|
|
35fa2389e1 | ||
|
|
c18b450129 | ||
|
|
8db6e9f049 | ||
|
|
b63a2006d3 | ||
|
|
8c1ca503bd | ||
|
|
0ac79e661c | ||
|
|
66ba4d35aa | ||
|
|
46d25dff4c | ||
|
|
5ef99f2cb3 | ||
|
|
7aee76e461 | ||
|
|
79f3f1b63d | ||
|
|
26e104b9f1 | ||
|
|
c71836ec27 | ||
|
|
60b1bc9ed7 | ||
|
|
e6a3daa2c3 | ||
|
|
276ef1c907 | ||
|
|
83e48cce42 | ||
|
|
99ca683d13 | ||
|
|
5062d891e1 | ||
|
|
92d1fc670b | ||
|
|
ab7abfea35 | ||
|
|
0d15c16d40 | ||
|
|
2a85fe2f3c | ||
|
|
dc762567b5 | ||
|
|
a676e09537 | ||
|
|
c46948049c | ||
|
|
de1b7f132c | ||
|
|
90b552d5c9 | ||
|
|
39115b3000 | ||
|
|
3c8c3d8253 | ||
|
|
657400c671 | ||
|
|
6356cb5e63 | ||
|
|
13c6e7a62d | ||
|
|
b6d99b1d4b | ||
|
|
f0e15d43d3 | ||
|
|
50d5ddba8e | ||
|
|
d2c63878ed | ||
|
|
ef52eaf91a | ||
|
|
cd71900bdd | ||
|
|
34e97fc56b | ||
|
|
e6e119682b | ||
|
|
e096db2ab8 | ||
|
|
cdff641cdb | ||
|
|
d0126ffc2c | ||
|
|
fe043eb594 | ||
|
|
eb1ff7c151 | ||
|
|
a862ee9ccf | ||
|
|
6953f7c4a3 | ||
|
|
ad53ddb9dd | ||
|
|
cfd4540a65 | ||
|
|
217321380a | ||
|
|
33e5d1a979 | ||
|
|
e5bcb1c19a | ||
|
|
bf2dc844d2 | ||
|
|
c9d3a3cd7c | ||
|
|
30b5f8120a | ||
|
|
5a958cc9fa | ||
|
|
b75d44a3dd | ||
|
|
6634144d82 | ||
|
|
9531730d7a |
@@ -69,6 +69,42 @@
|
|||||||
"contributions": [
|
"contributions": [
|
||||||
"code"
|
"code"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "cschuijt",
|
||||||
|
"name": "Casper Schuijt",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/5460015?v=4",
|
||||||
|
"profile": "http://cschuijt.nl",
|
||||||
|
"contributions": [
|
||||||
|
"bug"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "ANasouf",
|
||||||
|
"name": "ANasouf",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/19536487?v=4",
|
||||||
|
"profile": "https://github.com/ANasouf",
|
||||||
|
"contributions": [
|
||||||
|
"code"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "xprnio",
|
||||||
|
"name": "Ragnar Laud",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/3042904?v=4",
|
||||||
|
"profile": "https://ragnarlaud.dev",
|
||||||
|
"contributions": [
|
||||||
|
"bug"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "asenawritescode",
|
||||||
|
"name": "Asena",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/67445192?v=4",
|
||||||
|
"profile": "https://github.com/asenawritescode",
|
||||||
|
"contributions": [
|
||||||
|
"bug"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"contributorsPerLine": 7,
|
"contributorsPerLine": 7,
|
||||||
|
|||||||
16
.env.example
16
.env.example
@@ -49,4 +49,18 @@ SIGNUP_ALLOWED_DOMAINS=
|
|||||||
SIGNUP_ALLOWED_EMAILS=
|
SIGNUP_ALLOWED_EMAILS=
|
||||||
|
|
||||||
# API rate limit (points,duration,block duration).
|
# API rate limit (points,duration,block duration).
|
||||||
API_RATE_LIMIT=120,60,600
|
API_RATE_LIMIT=120,60,600
|
||||||
|
|
||||||
|
# Gotenberg API for PDF printing - (production).
|
||||||
|
GOTENBERG_URL=http://gotenberg:3000
|
||||||
|
GOTENBERG_DOCS_URL=http://server:3000/public/
|
||||||
|
|
||||||
|
# Gotenberg API - (development)
|
||||||
|
# GOTENBERG_URL=http://localhost:9000
|
||||||
|
# GOTENBERG_DOCS_URL=http://host.docker.internal:3000/public/
|
||||||
|
|
||||||
|
# Exchange Rate Service
|
||||||
|
EXCHANGE_RATE_SERVICE=open-exchange-rate
|
||||||
|
|
||||||
|
# Open Exchange Rate
|
||||||
|
OPEN_EXCHANGE_RATE_APP_ID=
|
||||||
72
CHANGELOG.md
72
CHANGELOG.md
@@ -2,11 +2,69 @@
|
|||||||
|
|
||||||
All notable changes to Bigcapital server-side will be in this file.
|
All notable changes to Bigcapital server-side will be in this file.
|
||||||
|
|
||||||
# [0.10.1] - 25-09-2023
|
## [0.13.3] - 22-01-2024
|
||||||
|
|
||||||
|
* hotfix(server): Unhandled thrown errors of services by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/329
|
||||||
|
|
||||||
|
## [0.13.2] - 21-01-2024
|
||||||
|
|
||||||
|
* feat: show customer / vendor balance. by @asenawritescode in https://github.com/bigcapitalhq/bigcapital/pull/311
|
||||||
|
* feat: inventory valuation csv and xlsx export by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/308
|
||||||
|
* feat: sales by items export csv & xlsx by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/310
|
||||||
|
* fix(server): the invoice and payment receipt printing by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/315
|
||||||
|
* fix: get cashflow transaction broken cause transaction type by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/318
|
||||||
|
* fix: `AccountActivateAlert` import by @xprnio in https://github.com/bigcapitalhq/bigcapital/pull/322
|
||||||
|
|
||||||
|
## [0.13.1] - 15-01-2024
|
||||||
|
|
||||||
|
* feat(webapp): add approve/reject to action bar of estimate details dr… by @ANasouf in https://github.com/bigcapitalhq/bigcapital/pull/304
|
||||||
|
* docs: add ANasouf as a contributor for code by @allcontributors in https://github.com/bigcapitalhq/bigcapital/pull/305
|
||||||
|
* feat: Export general ledger & Journal to CSV and XLSX by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/303
|
||||||
|
* feat: Auto re-calculate the items rate once changing the invoice exchange rate. by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/270
|
||||||
|
|
||||||
|
## [0.13.0] - 31-12-2023
|
||||||
|
|
||||||
|
* feat: Send an invoice mail the customer email by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/292
|
||||||
|
* fix: Allow non-numeric postal codes by @cschuijt in https://github.com/bigcapitalhq/bigcapital/pull/294
|
||||||
|
* docs: add cschuijt as a contributor for bug by @allcontributors in https://github.com/bigcapitalhq/bigcapital/pull/295
|
||||||
|
|
||||||
|
## [0.12.1] - 17-11-2023
|
||||||
|
|
||||||
|
* feat: Add default customer message and terms conditions to the transactions by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/291
|
||||||
|
* fix: The currency code of transaction tax rate entry by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/293
|
||||||
|
|
||||||
|
## [0.12.0] - 04-11-2023
|
||||||
|
|
||||||
|
* feat: Export reports via CSV and XLSX by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/286
|
||||||
|
* fix: Axios upgrade by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/288
|
||||||
|
* fix(server): Allow decimal amount in sale/purchase transactions. by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/289
|
||||||
|
* feat: Optimize invoice documents printing by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/280
|
||||||
|
* chore(deps): bump axios from 0.20.0 to 1.6.0 in /packages/server by @dependabot in https://github.com/bigcapitalhq/bigcapital/pull/284
|
||||||
|
* chore(deps): bump axios from 0.20.0 to 1.6.0 by @dependabot in https://github.com/bigcapitalhq/bigcapital/pull/283
|
||||||
|
|
||||||
|
## [0.11.0] - 28-10-2023
|
||||||
|
|
||||||
|
* feat: Migrate to pnpm by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/253
|
||||||
|
* feat: Integrate tax rates to bills by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/260
|
||||||
|
* feat: Assign default sell/purchase tax rates to items by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/261
|
||||||
|
* chore(deps-dev): bump @babel/traverse from 7.23.0 to 7.23.2 in /packages/server by @dependabot in https://github.com/bigcapitalhq/bigcapital/pull/272
|
||||||
|
* feat: Improve financial statements rows color by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/276
|
||||||
|
* fix: Trial balance sheet adjusted balance by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/273
|
||||||
|
* feat: Adds tax numbers to organization and customers by @kochie in https://github.com/bigcapitalhq/bigcapital/pull/269
|
||||||
|
* docs: Add kochie as a contributor for code by @allcontributors in https://github.com/bigcapitalhq/bigcapital/pull/277
|
||||||
|
* feat: Computed Net Income under Equity in Balance Sheet report. by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/271
|
||||||
|
* fix: Change Dockerfile files with new pnpm by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/278
|
||||||
|
|
||||||
|
## [0.10.2] - 02-10-2023
|
||||||
|
|
||||||
|
fix(webapp): Disable tax rates from item entries editor table services do not support tax rates (https://github.com/bigcapitalhq/bigcapital/commit/69afa07e3ba45495a4cab3490c15f2b0c40c4790) by @abouolia
|
||||||
|
fix(server): Add missing method in ItemEntry model (https://github.com/bigcapitalhq/bigcapital/commit/07628ddc37f46c98959ced0323f28752e0a98944) by @abouolia
|
||||||
|
|
||||||
|
## [0.10.1] - 25-09-2023
|
||||||
|
|
||||||
* Fix: Running tenants migration on Docker migration container by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/242
|
* Fix: Running tenants migration on Docker migration container by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/242
|
||||||
|
|
||||||
# [0.10.0] - 24-09-2023
|
## [0.10.0] - 24-09-2023
|
||||||
|
|
||||||
* Added: Tax rates service by @abouolia @elforjani13 in https://github.com/bigcapitalhq/bigcapital/pull/204
|
* Added: Tax rates service by @abouolia @elforjani13 in https://github.com/bigcapitalhq/bigcapital/pull/204
|
||||||
* Added: Sales Tax Liability Summary report by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/204
|
* Added: Sales Tax Liability Summary report by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/204
|
||||||
@@ -16,7 +74,7 @@ All notable changes to Bigcapital server-side will be in this file.
|
|||||||
* chore(deps): bump word-wrap from 1.2.3 to 1.2.4 in /packages/webapp by @dependabot in https://github.com/bigcapitalhq/bigcapital/pull/199
|
* chore(deps): bump word-wrap from 1.2.3 to 1.2.4 in /packages/webapp by @dependabot in https://github.com/bigcapitalhq/bigcapital/pull/199
|
||||||
* chore(deps): bump mongoose from 5.13.15 to 5.13.20 by @dependabot in https://github.com/bigcapitalhq/bigcapital/pull/197
|
* chore(deps): bump mongoose from 5.13.15 to 5.13.20 by @dependabot in https://github.com/bigcapitalhq/bigcapital/pull/197
|
||||||
|
|
||||||
# [0.9.12] - 29-08-2023
|
## [0.9.12] - 29-08-2023
|
||||||
|
|
||||||
* Refactor: split the services to multiple service classes. (by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/202)
|
* Refactor: split the services to multiple service classes. (by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/202)
|
||||||
* Fix: create quick customer/vendor by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/206
|
* Fix: create quick customer/vendor by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/206
|
||||||
@@ -30,18 +88,18 @@ All notable changes to Bigcapital server-side will be in this file.
|
|||||||
* Fix: filter by customers, vendors and items in reports do not work by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/224
|
* Fix: filter by customers, vendors and items in reports do not work by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/224
|
||||||
https://github.com/bigcapitalhq/bigcapital/pull/225
|
https://github.com/bigcapitalhq/bigcapital/pull/225
|
||||||
|
|
||||||
# [0.9.11] - 23-07-2023
|
## [0.9.11] - 23-07-2023
|
||||||
|
|
||||||
* added: Restart policy to docker compose files. by @suhaibaffan in https://github.com/bigcapitalhq/bigcapital/pull/198
|
* added: Restart policy to docker compose files. by @suhaibaffan in https://github.com/bigcapitalhq/bigcapital/pull/198
|
||||||
* fix: Expose and expand the rate limit to the env variables by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/195
|
* fix: Expose and expand the rate limit to the env variables by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/195
|
||||||
|
|
||||||
# [0.9.10] - 18-07-2023
|
## [0.9.10] - 18-07-2023
|
||||||
|
|
||||||
* feat(e2e): E2E onboarding process by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/176
|
* feat(e2e): E2E onboarding process by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/176
|
||||||
* fix(webapp): Show loading message of cost computing job on financial reports by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/196
|
* fix(webapp): Show loading message of cost computing job on financial reports by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/196
|
||||||
* fix(webapp): Change the currency code of sales and purchases transactions with foreign contacts.
|
* fix(webapp): Change the currency code of sales and purchases transactions with foreign contacts.
|
||||||
|
|
||||||
# [0.9.9] - 28-06-2023
|
## [0.9.9] - 28-06-2023
|
||||||
|
|
||||||
* refactor: Customer and vendor select component by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/171
|
* refactor: Customer and vendor select component by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/171
|
||||||
* chore: Move auto-increment components in separate files by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/170
|
* chore: Move auto-increment components in separate files by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/170
|
||||||
@@ -53,7 +111,7 @@ https://github.com/bigcapitalhq/bigcapital/pull/225
|
|||||||
* fix: No currency in amount field on money in/out dialogs by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/179
|
* fix: No currency in amount field on money in/out dialogs by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/179
|
||||||
* fix: No default branch for customer/vendor opening balance branch by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/182
|
* fix: No default branch for customer/vendor opening balance branch by @abouolia in https://github.com/bigcapitalhq/bigcapital/pull/182
|
||||||
|
|
||||||
# [0.9.8] - 19-06-2023
|
## [0.9.8] - 19-06-2023
|
||||||
|
|
||||||
`bigcapitalhq/webapp`
|
`bigcapitalhq/webapp`
|
||||||
|
|
||||||
|
|||||||
12
README.md
12
README.md
@@ -62,6 +62,12 @@ To get started locally, we have a [guide to help you](https://github.com/bigcapi
|
|||||||
|
|
||||||
[](https://gitpod.io/new/#https://github.com/bigcapitalhq/bigcapital)
|
[](https://gitpod.io/new/#https://github.com/bigcapitalhq/bigcapital)
|
||||||
|
|
||||||
|
## Headless Accounting
|
||||||
|
|
||||||
|
You can integrate Bigcapital API with your system to organize your transactions in double-entry system to get the best financial reports.
|
||||||
|
|
||||||
|
[](https://www.postman.com/bigcapital/workspace/bigcapital-api)
|
||||||
|
|
||||||
# Resources
|
# Resources
|
||||||
|
|
||||||
- [Documentation](https://docs.bigcapital.ly/) - Learn how to use.
|
- [Documentation](https://docs.bigcapital.ly/) - Learn how to use.
|
||||||
@@ -107,6 +113,12 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|||||||
<td align="center" valign="top" width="14.28%"><a href="https://github.com/KalliopiPliogka"><img src="https://avatars.githubusercontent.com/u/81677549?v=4?s=100" width="100px;" alt="Kalliopi Pliogka"/><br /><sub><b>Kalliopi Pliogka</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/issues?q=author%3AKalliopiPliogka" title="Bug reports">🐛</a></td>
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/KalliopiPliogka"><img src="https://avatars.githubusercontent.com/u/81677549?v=4?s=100" width="100px;" alt="Kalliopi Pliogka"/><br /><sub><b>Kalliopi Pliogka</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/issues?q=author%3AKalliopiPliogka" title="Bug reports">🐛</a></td>
|
||||||
<td align="center" valign="top" width="14.28%"><a href="https://me.kochie.io"><img src="https://avatars.githubusercontent.com/u/10809884?v=4?s=100" width="100px;" alt="Robert Koch"/><br /><sub><b>Robert Koch</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/commits?author=kochie" title="Code">💻</a></td>
|
<td align="center" valign="top" width="14.28%"><a href="https://me.kochie.io"><img src="https://avatars.githubusercontent.com/u/10809884?v=4?s=100" width="100px;" alt="Robert Koch"/><br /><sub><b>Robert Koch</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/commits?author=kochie" title="Code">💻</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<td align="center" valign="top" width="14.28%"><a href="http://cschuijt.nl"><img src="https://avatars.githubusercontent.com/u/5460015?v=4?s=100" width="100px;" alt="Casper Schuijt"/><br /><sub><b>Casper Schuijt</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/issues?q=author%3Acschuijt" title="Bug reports">🐛</a></td>
|
||||||
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/ANasouf"><img src="https://avatars.githubusercontent.com/u/19536487?v=4?s=100" width="100px;" alt="ANasouf"/><br /><sub><b>ANasouf</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/commits?author=ANasouf" title="Code">💻</a></td>
|
||||||
|
<td align="center" valign="top" width="14.28%"><a href="https://ragnarlaud.dev"><img src="https://avatars.githubusercontent.com/u/3042904?v=4?s=100" width="100px;" alt="Ragnar Laud"/><br /><sub><b>Ragnar Laud</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/issues?q=author%3Axprnio" title="Bug reports">🐛</a></td>
|
||||||
|
<td align="center" valign="top" width="14.28%"><a href="https://github.com/asenawritescode"><img src="https://avatars.githubusercontent.com/u/67445192?v=4?s=100" width="100px;" alt="Asena"/><br /><sub><b>Asena</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/issues?q=author%3Aasenawritescode" title="Bug reports">🐛</a></td>
|
||||||
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|
||||||
|
|||||||
@@ -35,6 +35,8 @@ services:
|
|||||||
server:
|
server:
|
||||||
container_name: bigcapital-server
|
container_name: bigcapital-server
|
||||||
image: ghcr.io/bigcapitalhq/server:latest
|
image: ghcr.io/bigcapitalhq/server:latest
|
||||||
|
expose:
|
||||||
|
- '3000'
|
||||||
links:
|
links:
|
||||||
- mysql
|
- mysql
|
||||||
- mongo
|
- mongo
|
||||||
@@ -86,6 +88,10 @@ services:
|
|||||||
- SIGNUP_ALLOWED_DOMAINS=${SIGNUP_ALLOWED_DOMAINS}
|
- SIGNUP_ALLOWED_DOMAINS=${SIGNUP_ALLOWED_DOMAINS}
|
||||||
- SIGNUP_ALLOWED_EMAILS=${SIGNUP_ALLOWED_EMAILS}
|
- SIGNUP_ALLOWED_EMAILS=${SIGNUP_ALLOWED_EMAILS}
|
||||||
|
|
||||||
|
# Gotenberg (Pdf generator)
|
||||||
|
- GOTENBERG_URL=${GOTENBERG_URL}
|
||||||
|
- GOTENBERG_DOCS_URL=${GOTENBERG_DOCS_URL}
|
||||||
|
|
||||||
database_migration:
|
database_migration:
|
||||||
container_name: bigcapital-database-migration
|
container_name: bigcapital-database-migration
|
||||||
build:
|
build:
|
||||||
@@ -143,6 +149,11 @@ services:
|
|||||||
volumes:
|
volumes:
|
||||||
- redis:/data
|
- redis:/data
|
||||||
|
|
||||||
|
gotenberg:
|
||||||
|
image: gotenberg/gotenberg:7
|
||||||
|
expose:
|
||||||
|
- '9000'
|
||||||
|
|
||||||
# Volumes
|
# Volumes
|
||||||
volumes:
|
volumes:
|
||||||
mysql:
|
mysql:
|
||||||
|
|||||||
@@ -47,6 +47,11 @@ services:
|
|||||||
restart_policy:
|
restart_policy:
|
||||||
condition: unless-stopped
|
condition: unless-stopped
|
||||||
|
|
||||||
|
gotenberg:
|
||||||
|
image: gotenberg/gotenberg:7
|
||||||
|
ports:
|
||||||
|
- "9000:3000"
|
||||||
|
|
||||||
# Volumes
|
# Volumes
|
||||||
volumes:
|
volumes:
|
||||||
mysql:
|
mysql:
|
||||||
|
|||||||
1
packages/server/.gitignore
vendored
1
packages/server/.gitignore
vendored
@@ -1,6 +1,5 @@
|
|||||||
/node_modules/
|
/node_modules/
|
||||||
/.env
|
/.env
|
||||||
/storage
|
|
||||||
stdout.log
|
stdout.log
|
||||||
/dist
|
/dist
|
||||||
/build
|
/build
|
||||||
|
|||||||
15633
packages/server/package-lock.json
generated
15633
packages/server/package-lock.json
generated
File diff suppressed because it is too large
Load Diff
@@ -56,6 +56,7 @@
|
|||||||
"express-fileupload": "^1.1.7-alpha.3",
|
"express-fileupload": "^1.1.7-alpha.3",
|
||||||
"express-oauth-server": "^2.0.0",
|
"express-oauth-server": "^2.0.0",
|
||||||
"express-validator": "^6.12.2",
|
"express-validator": "^6.12.2",
|
||||||
|
"form-data": "^4.0.0",
|
||||||
"gulp": "^4.0.2",
|
"gulp": "^4.0.2",
|
||||||
"gulp-sass": "^5.0.0",
|
"gulp-sass": "^5.0.0",
|
||||||
"helmet": "^3.21.0",
|
"helmet": "^3.21.0",
|
||||||
@@ -96,6 +97,7 @@
|
|||||||
"reflect-metadata": "^0.1.13",
|
"reflect-metadata": "^0.1.13",
|
||||||
"rtl-detect": "^1.0.4",
|
"rtl-detect": "^1.0.4",
|
||||||
"source-map-loader": "^4.0.1",
|
"source-map-loader": "^4.0.1",
|
||||||
|
"tmp-promise": "^3.0.3",
|
||||||
"ts-transformer-keys": "^0.4.2",
|
"ts-transformer-keys": "^0.4.2",
|
||||||
"tsyringe": "^4.3.0",
|
"tsyringe": "^4.3.0",
|
||||||
"typedi": "^0.8.0",
|
"typedi": "^0.8.0",
|
||||||
|
|||||||
@@ -176,6 +176,7 @@
|
|||||||
"invoice.paper.conditions_title": "Conditions & terms",
|
"invoice.paper.conditions_title": "Conditions & terms",
|
||||||
"invoice.paper.notes_title": "Notes",
|
"invoice.paper.notes_title": "Notes",
|
||||||
"invoice.paper.total": "Total",
|
"invoice.paper.total": "Total",
|
||||||
|
"invoice.paper.subtotal": "Subtotal",
|
||||||
"invoice.paper.payment_amount": "Payment Amount",
|
"invoice.paper.payment_amount": "Payment Amount",
|
||||||
"invoice.paper.balance_due": "Balance Due",
|
"invoice.paper.balance_due": "Balance Due",
|
||||||
|
|
||||||
|
|||||||
@@ -137,10 +137,14 @@
|
|||||||
tbody tr.payment-amount td:last-child {
|
tbody tr.payment-amount td:last-child {
|
||||||
color: red
|
color: red
|
||||||
}
|
}
|
||||||
tbody tr.blanace-due td {
|
tbody tr.blanace-due td{
|
||||||
border-top: 3px double #666;
|
border-top: 3px double #666;
|
||||||
font-weight: bold;
|
font-weight: bold;
|
||||||
}
|
}
|
||||||
|
tbody tr.total td {
|
||||||
|
border-top: 1px solid #666;
|
||||||
|
font-weight: bold;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -22,12 +22,12 @@ block content
|
|||||||
|
|
||||||
div.invoice__due-amount
|
div.invoice__due-amount
|
||||||
div.label #{__('invoice.paper.invoice_amount')}
|
div.label #{__('invoice.paper.invoice_amount')}
|
||||||
div.amount #{saleInvoice.formattedAmount}
|
div.amount #{saleInvoice.totalFormatted}
|
||||||
|
|
||||||
div.invoice__meta
|
div.invoice__meta
|
||||||
div.invoice__meta-item.invoice__meta-item--amount
|
div.invoice__meta-item.invoice__meta-item--amount
|
||||||
span.label #{__('invoice.paper.due_amount')}
|
span.label #{__('invoice.paper.due_amount')}
|
||||||
span.value #{saleInvoice.formattedDueAmount}
|
span.value #{saleInvoice.dueAmountFormatted}
|
||||||
|
|
||||||
div.invoice__meta-item.invoice__meta-item--billed-to
|
div.invoice__meta-item.invoice__meta-item--billed-to
|
||||||
span.label #{__("invoice.paper.billed_to")}
|
span.label #{__("invoice.paper.billed_to")}
|
||||||
@@ -35,11 +35,11 @@ block content
|
|||||||
|
|
||||||
div.invoice__meta-item.invoice__meta-item--invoice-date
|
div.invoice__meta-item.invoice__meta-item--invoice-date
|
||||||
span.label #{__("invoice.paper.invoice_date")}
|
span.label #{__("invoice.paper.invoice_date")}
|
||||||
span.value #{saleInvoice.formattedInvoiceDate}
|
span.value #{saleInvoice.invoiceDateFormatted}
|
||||||
|
|
||||||
div.invoice__meta-item.invoice__meta-item--due-date
|
div.invoice__meta-item.invoice__meta-item--due-date
|
||||||
span.label #{__("invoice.paper.due_date")}
|
span.label #{__("invoice.paper.due_date")}
|
||||||
span.value #{saleInvoice.formattedDueDate}
|
span.value #{saleInvoice.dueDateFormatted}
|
||||||
|
|
||||||
div.invoice__table
|
div.invoice__table
|
||||||
table
|
table
|
||||||
@@ -63,15 +63,22 @@ block content
|
|||||||
div.invoice__table-total
|
div.invoice__table-total
|
||||||
table
|
table
|
||||||
tbody
|
tbody
|
||||||
|
tr.subtotal
|
||||||
|
td #{__('invoice.paper.subtotal')}
|
||||||
|
td #{saleInvoice.subtotalFormatted}
|
||||||
|
each tax in saleInvoice.taxes
|
||||||
|
tr.tax_line
|
||||||
|
td #{tax.name} [#{tax.taxRate}%]
|
||||||
|
td #{tax.taxRateAmountFormatted}
|
||||||
tr.total
|
tr.total
|
||||||
td #{__('invoice.paper.total')}
|
td #{__('invoice.paper.total')}
|
||||||
td #{saleInvoice.formattedAmount}
|
td #{saleInvoice.totalFormatted}
|
||||||
tr.payment-amount
|
tr.payment-amount
|
||||||
td #{__('invoice.paper.payment_amount')}
|
td #{__('invoice.paper.payment_amount')}
|
||||||
td #{saleInvoice.formattedPaymentAmount}
|
td #{saleInvoice.paymentAmountFormatted}
|
||||||
tr.blanace-due
|
tr.blanace-due
|
||||||
td #{__('invoice.paper.balance_due')}
|
td #{__('invoice.paper.balance_due')}
|
||||||
td #{saleInvoice.formattedDueAmount}
|
td #{saleInvoice.dueAmountFormatted}
|
||||||
|
|
||||||
div.invoice__footer
|
div.invoice__footer
|
||||||
if saleInvoice.termsConditions
|
if saleInvoice.termsConditions
|
||||||
|
|||||||
@@ -45,9 +45,9 @@ block content
|
|||||||
each entry in paymentReceive.entries
|
each entry in paymentReceive.entries
|
||||||
tr
|
tr
|
||||||
td.item=entry.invoice.invoiceNo
|
td.item=entry.invoice.invoiceNo
|
||||||
td.date=entry.invoice.formattedInvoiceDate
|
td.date=entry.invoice.invoiceDateFormatted
|
||||||
td.invoiceAmount=entry.invoice.formattedAmount
|
td.invoiceAmount=entry.invoice.totalFormatted
|
||||||
td.paymentAmount=entry.invoice.formattedPaymentAmount
|
td.paymentAmount=entry.invoice.paymentAmountFormatted
|
||||||
|
|
||||||
div.payment__table-after
|
div.payment__table-after
|
||||||
div.payment__table-total
|
div.payment__table-total
|
||||||
|
|||||||
@@ -1,19 +1,16 @@
|
|||||||
import { Service, Inject } from 'typedi';
|
import { Service, Inject } from 'typedi';
|
||||||
import { Router, Request, Response, NextFunction } from 'express';
|
import { Router, Request, Response, NextFunction } from 'express';
|
||||||
import { check, param, query } from 'express-validator';
|
import { query, oneOf } from 'express-validator';
|
||||||
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
||||||
import BaseController from './BaseController';
|
import BaseController from './BaseController';
|
||||||
import { ServiceError } from '@/exceptions';
|
import { ServiceError } from '@/exceptions';
|
||||||
import ExchangeRatesService from '@/services/ExchangeRates/ExchangeRatesService';
|
import { EchangeRateErrors } from '@/lib/ExchangeRate/types';
|
||||||
import DynamicListingService from '@/services/DynamicListing/DynamicListService';
|
import { ExchangeRateApplication } from '@/services/ExchangeRates/ExchangeRateApplication';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class ExchangeRatesController extends BaseController {
|
export default class ExchangeRatesController extends BaseController {
|
||||||
@Inject()
|
@Inject()
|
||||||
exchangeRatesService: ExchangeRatesService;
|
private exchangeRatesApp: ExchangeRateApplication;
|
||||||
|
|
||||||
@Inject()
|
|
||||||
dynamicListService: DynamicListingService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor method.
|
* Constructor method.
|
||||||
@@ -22,164 +19,40 @@ export default class ExchangeRatesController extends BaseController {
|
|||||||
const router = Router();
|
const router = Router();
|
||||||
|
|
||||||
router.get(
|
router.get(
|
||||||
'/',
|
'/latest',
|
||||||
[...this.exchangeRatesListSchema],
|
[
|
||||||
|
oneOf([
|
||||||
|
query('to_currency').exists().isString().isISO4217(),
|
||||||
|
query('from_currency').exists().isString().isISO4217(),
|
||||||
|
]),
|
||||||
|
],
|
||||||
this.validationResult,
|
this.validationResult,
|
||||||
asyncMiddleware(this.exchangeRates.bind(this)),
|
asyncMiddleware(this.latestExchangeRate.bind(this)),
|
||||||
this.dynamicListService.handlerErrorsToResponse,
|
|
||||||
this.handleServiceError,
|
|
||||||
);
|
|
||||||
router.post(
|
|
||||||
'/',
|
|
||||||
[...this.exchangeRateDTOSchema],
|
|
||||||
this.validationResult,
|
|
||||||
asyncMiddleware(this.addExchangeRate.bind(this)),
|
|
||||||
this.handleServiceError
|
|
||||||
);
|
|
||||||
router.post(
|
|
||||||
'/:id',
|
|
||||||
[...this.exchangeRateEditDTOSchema, ...this.exchangeRateIdSchema],
|
|
||||||
this.validationResult,
|
|
||||||
asyncMiddleware(this.editExchangeRate.bind(this)),
|
|
||||||
this.handleServiceError
|
|
||||||
);
|
|
||||||
router.delete(
|
|
||||||
'/:id',
|
|
||||||
[...this.exchangeRateIdSchema],
|
|
||||||
this.validationResult,
|
|
||||||
asyncMiddleware(this.deleteExchangeRate.bind(this)),
|
|
||||||
this.handleServiceError
|
this.handleServiceError
|
||||||
);
|
);
|
||||||
return router;
|
return router;
|
||||||
}
|
}
|
||||||
|
|
||||||
get exchangeRatesListSchema() {
|
|
||||||
return [
|
|
||||||
query('page').optional().isNumeric().toInt(),
|
|
||||||
query('page_size').optional().isNumeric().toInt(),
|
|
||||||
|
|
||||||
query('column_sort_by').optional(),
|
|
||||||
query('sort_order').optional().isIn(['desc', 'asc']),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
get exchangeRateDTOSchema() {
|
|
||||||
return [
|
|
||||||
check('exchange_rate').exists().isNumeric().toFloat(),
|
|
||||||
check('currency_code').exists().trim().escape(),
|
|
||||||
check('date').exists().isISO8601(),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
get exchangeRateEditDTOSchema() {
|
|
||||||
return [check('exchange_rate').exists().isNumeric().toFloat()];
|
|
||||||
}
|
|
||||||
|
|
||||||
get exchangeRateIdSchema() {
|
|
||||||
return [param('id').isNumeric().toInt()];
|
|
||||||
}
|
|
||||||
|
|
||||||
get exchangeRatesIdsSchema() {
|
|
||||||
return [
|
|
||||||
query('ids').isArray({ min: 2 }),
|
|
||||||
query('ids.*').isNumeric().toInt(),
|
|
||||||
];
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve exchange rates.
|
* Retrieve exchange rates.
|
||||||
* @param {Request} req
|
* @param {Request} req
|
||||||
* @param {Response} res
|
* @param {Response} res
|
||||||
* @param {NextFunction} next
|
* @param {NextFunction} next
|
||||||
*/
|
*/
|
||||||
async exchangeRates(req: Request, res: Response, next: NextFunction) {
|
private async latestExchangeRate(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
) {
|
||||||
const { tenantId } = req;
|
const { tenantId } = req;
|
||||||
const filter = {
|
const exchangeRateQuery = this.matchedQueryData(req);
|
||||||
page: 1,
|
|
||||||
pageSize: 12,
|
|
||||||
filterRoles: [],
|
|
||||||
columnSortBy: 'created_at',
|
|
||||||
sortOrder: 'asc',
|
|
||||||
...this.matchedQueryData(req),
|
|
||||||
};
|
|
||||||
if (filter.stringifiedFilterRoles) {
|
|
||||||
filter.filterRoles = JSON.parse(filter.stringifiedFilterRoles);
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
const exchangeRates = await this.exchangeRatesService.listExchangeRates(
|
|
||||||
tenantId,
|
|
||||||
filter
|
|
||||||
);
|
|
||||||
return res.status(200).send({ exchange_rates: exchangeRates });
|
|
||||||
} catch (error) {
|
|
||||||
next(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Adds a new exchange rate on the given date.
|
|
||||||
* @param {Request} req
|
|
||||||
* @param {Response} res
|
|
||||||
* @param {NextFunction} next
|
|
||||||
*/
|
|
||||||
async addExchangeRate(req: Request, res: Response, next: NextFunction) {
|
|
||||||
const { tenantId } = req;
|
|
||||||
const exchangeRateDTO = this.matchedBodyData(req);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const exchangeRate = await this.exchangeRatesService.newExchangeRate(
|
const exchangeRate = await this.exchangeRatesApp.latest(
|
||||||
tenantId,
|
tenantId,
|
||||||
exchangeRateDTO
|
exchangeRateQuery
|
||||||
);
|
);
|
||||||
return res.status(200).send({ id: exchangeRate.id });
|
return res.status(200).send(exchangeRate);
|
||||||
} catch (error) {
|
|
||||||
next(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Edit the given exchange rate.
|
|
||||||
* @param {Request} req
|
|
||||||
* @param {Response} res
|
|
||||||
* @param {NextFunction} next
|
|
||||||
*/
|
|
||||||
async editExchangeRate(req: Request, res: Response, next: NextFunction) {
|
|
||||||
const { tenantId } = req;
|
|
||||||
const { id: exchangeRateId } = req.params;
|
|
||||||
const exchangeRateDTO = this.matchedBodyData(req);
|
|
||||||
|
|
||||||
try {
|
|
||||||
const exchangeRate = await this.exchangeRatesService.editExchangeRate(
|
|
||||||
tenantId,
|
|
||||||
exchangeRateId,
|
|
||||||
exchangeRateDTO
|
|
||||||
);
|
|
||||||
|
|
||||||
return res.status(200).send({
|
|
||||||
id: exchangeRateId,
|
|
||||||
message: 'The exchange rate has been edited successfully.',
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
next(error);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Delete the given exchange rate from the storage.
|
|
||||||
* @param {Request} req
|
|
||||||
* @param {Response} res
|
|
||||||
* @param {NextFunction} next
|
|
||||||
*/
|
|
||||||
async deleteExchangeRate(req: Request, res: Response, next: NextFunction) {
|
|
||||||
const { tenantId } = req;
|
|
||||||
const { id: exchangeRateId } = req.params;
|
|
||||||
|
|
||||||
try {
|
|
||||||
await this.exchangeRatesService.deleteExchangeRate(
|
|
||||||
tenantId,
|
|
||||||
exchangeRateId
|
|
||||||
);
|
|
||||||
return res.status(200).send({ id: exchangeRateId });
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
@@ -192,26 +65,56 @@ export default class ExchangeRatesController extends BaseController {
|
|||||||
* @param {Response} res
|
* @param {Response} res
|
||||||
* @param {NextFunction} next
|
* @param {NextFunction} next
|
||||||
*/
|
*/
|
||||||
handleServiceError(
|
private handleServiceError(
|
||||||
error: Error,
|
error: Error,
|
||||||
req: Request,
|
req: Request,
|
||||||
res: Response,
|
res: Response,
|
||||||
next: NextFunction
|
next: NextFunction
|
||||||
) {
|
) {
|
||||||
if (error instanceof ServiceError) {
|
if (error instanceof ServiceError) {
|
||||||
if (error.errorType === 'EXCHANGE_RATE_NOT_FOUND') {
|
if (EchangeRateErrors.EX_RATE_INVALID_BASE_CURRENCY === error.errorType) {
|
||||||
return res.status(404).send({
|
|
||||||
errors: [{ type: 'EXCHANGE.RATE.NOT.FOUND', code: 200 }],
|
|
||||||
});
|
|
||||||
}
|
|
||||||
if (error.errorType === 'NOT_FOUND_EXCHANGE_RATES') {
|
|
||||||
return res.status(400).send({
|
return res.status(400).send({
|
||||||
errors: [{ type: 'EXCHANGE.RATES.IS.NOT.FOUND', code: 100 }],
|
errors: [
|
||||||
|
{
|
||||||
|
type: EchangeRateErrors.EX_RATE_INVALID_BASE_CURRENCY,
|
||||||
|
code: 100,
|
||||||
|
message: 'The given base currency is invalid.',
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
}
|
} else if (
|
||||||
if (error.errorType === 'EXCHANGE_RATE_PERIOD_EXISTS') {
|
EchangeRateErrors.EX_RATE_SERVICE_NOT_ALLOWED === error.errorType
|
||||||
|
) {
|
||||||
return res.status(400).send({
|
return res.status(400).send({
|
||||||
errors: [{ type: 'EXCHANGE.RATE.PERIOD.EXISTS', code: 300 }],
|
errors: [
|
||||||
|
{
|
||||||
|
type: EchangeRateErrors.EX_RATE_SERVICE_NOT_ALLOWED,
|
||||||
|
code: 200,
|
||||||
|
message: 'The service is not allowed',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
} else if (
|
||||||
|
EchangeRateErrors.EX_RATE_SERVICE_API_KEY_REQUIRED === error.errorType
|
||||||
|
) {
|
||||||
|
return res.status(400).send({
|
||||||
|
errors: [
|
||||||
|
{
|
||||||
|
type: EchangeRateErrors.EX_RATE_SERVICE_API_KEY_REQUIRED,
|
||||||
|
code: 300,
|
||||||
|
message: 'The API key is required',
|
||||||
|
},
|
||||||
|
],
|
||||||
|
});
|
||||||
|
} else if (EchangeRateErrors.EX_RATE_LIMIT_EXCEEDED === error.errorType) {
|
||||||
|
return res.status(400).send({
|
||||||
|
errors: [
|
||||||
|
{
|
||||||
|
type: EchangeRateErrors.EX_RATE_LIMIT_EXCEEDED,
|
||||||
|
code: 400,
|
||||||
|
message: 'The API rate limit has been exceeded',
|
||||||
|
},
|
||||||
|
],
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,15 +2,16 @@ import { Router, Request, Response, NextFunction } from 'express';
|
|||||||
import { query, ValidationChain } from 'express-validator';
|
import { query, ValidationChain } from 'express-validator';
|
||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
||||||
import GeneralLedgerService from '@/services/FinancialStatements/GeneralLedger/GeneralLedgerService';
|
|
||||||
import BaseFinancialReportController from './BaseFinancialReportController';
|
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||||
import { AbilitySubject, ReportsAction } from '@/interfaces';
|
import { AbilitySubject, ReportsAction } from '@/interfaces';
|
||||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||||
|
import { ACCEPT_TYPE } from '@/interfaces/Http';
|
||||||
|
import { GeneralLedgerApplication } from '@/services/FinancialStatements/GeneralLedger/GeneralLedgerApplication';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class GeneralLedgerReportController extends BaseFinancialReportController {
|
export default class GeneralLedgerReportController extends BaseFinancialReportController {
|
||||||
@Inject()
|
@Inject()
|
||||||
generalLedgetService: GeneralLedgerService;
|
private generalLedgerApplication: GeneralLedgerApplication;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Router constructor.
|
* Router constructor.
|
||||||
@@ -61,20 +62,43 @@ export default class GeneralLedgerReportController extends BaseFinancialReportCo
|
|||||||
* @param {Response} res -
|
* @param {Response} res -
|
||||||
*/
|
*/
|
||||||
async generalLedger(req: Request, res: Response, next: NextFunction) {
|
async generalLedger(req: Request, res: Response, next: NextFunction) {
|
||||||
const { tenantId, settings } = req;
|
const { tenantId } = req;
|
||||||
const filter = this.matchedQueryData(req);
|
const filter = this.matchedQueryData(req);
|
||||||
|
const accept = this.accepts(req);
|
||||||
|
|
||||||
try {
|
const acceptType = accept.types([
|
||||||
const { data, query, meta } =
|
ACCEPT_TYPE.APPLICATION_JSON,
|
||||||
await this.generalLedgetService.generalLedger(tenantId, filter);
|
ACCEPT_TYPE.APPLICATION_JSON_TABLE,
|
||||||
|
ACCEPT_TYPE.APPLICATION_XLSX,
|
||||||
|
ACCEPT_TYPE.APPLICATION_CSV,
|
||||||
|
]);
|
||||||
|
// Retrieves the table format.
|
||||||
|
if (ACCEPT_TYPE.APPLICATION_JSON_TABLE === acceptType) {
|
||||||
|
const table = await this.generalLedgerApplication.table(tenantId, filter);
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send(table);
|
||||||
meta: this.transfromToResponse(meta),
|
// Retrieves the csv format.
|
||||||
data: this.transfromToResponse(data),
|
} else if (ACCEPT_TYPE.APPLICATION_CSV === acceptType) {
|
||||||
query: this.transfromToResponse(query),
|
const buffer = await this.generalLedgerApplication.csv(tenantId, filter);
|
||||||
});
|
|
||||||
} catch (error) {
|
res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
|
||||||
next(error);
|
res.setHeader('Content-Type', 'text/csv');
|
||||||
|
|
||||||
|
return res.send(buffer);
|
||||||
|
// Retrieves the xlsx format.
|
||||||
|
} else if (ACCEPT_TYPE.APPLICATION_XLSX === acceptType) {
|
||||||
|
const buffer = await this.generalLedgerApplication.xlsx(tenantId, filter);
|
||||||
|
|
||||||
|
res.setHeader('Content-Disposition', 'attachment; filename=output.xlsx');
|
||||||
|
res.setHeader(
|
||||||
|
'Content-Type',
|
||||||
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||||
|
);
|
||||||
|
return res.send(buffer);
|
||||||
|
// Retrieves the json format.
|
||||||
|
} else {
|
||||||
|
const sheet = await this.generalLedgerApplication.sheet(tenantId, filter);
|
||||||
|
return res.status(200).send(sheet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,15 @@ import { query, ValidationChain } from 'express-validator';
|
|||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
||||||
import BaseFinancialReportController from './BaseFinancialReportController';
|
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||||
import InventoryValuationService from '@/services/FinancialStatements/InventoryValuationSheet/InventoryValuationSheetService';
|
|
||||||
import { AbilitySubject, ReportsAction } from '@/interfaces';
|
import { AbilitySubject, ReportsAction } from '@/interfaces';
|
||||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||||
|
import { InventoryValuationSheetApplication } from '@/services/FinancialStatements/InventoryValuationSheet/InventoryValuationSheetApplication';
|
||||||
|
import { ACCEPT_TYPE } from '@/interfaces/Http';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class InventoryValuationReportController extends BaseFinancialReportController {
|
export default class InventoryValuationReportController extends BaseFinancialReportController {
|
||||||
@Inject()
|
@Inject()
|
||||||
inventoryValuationService: InventoryValuationService;
|
private inventoryValuationApp: InventoryValuationSheetApplication;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Router constructor.
|
* Router constructor.
|
||||||
@@ -71,19 +72,45 @@ export default class InventoryValuationReportController extends BaseFinancialRep
|
|||||||
const { tenantId } = req;
|
const { tenantId } = req;
|
||||||
const filter = this.matchedQueryData(req);
|
const filter = this.matchedQueryData(req);
|
||||||
|
|
||||||
try {
|
const accept = this.accepts(req);
|
||||||
const { data, query, meta } =
|
|
||||||
await this.inventoryValuationService.inventoryValuationSheet(
|
const acceptType = accept.types([
|
||||||
tenantId,
|
ACCEPT_TYPE.APPLICATION_JSON,
|
||||||
filter
|
ACCEPT_TYPE.APPLICATION_JSON_TABLE,
|
||||||
);
|
ACCEPT_TYPE.APPLICATION_XLSX,
|
||||||
return res.status(200).send({
|
ACCEPT_TYPE.APPLICATION_CSV,
|
||||||
meta: this.transfromToResponse(meta),
|
]);
|
||||||
data: this.transfromToResponse(data),
|
|
||||||
query: this.transfromToResponse(query),
|
// Retrieves the json table format.
|
||||||
});
|
if (ACCEPT_TYPE.APPLICATION_JSON_TABLE === acceptType) {
|
||||||
} catch (error) {
|
const table = await this.inventoryValuationApp.table(tenantId, filter);
|
||||||
next(error);
|
|
||||||
|
return res.status(200).send(table);
|
||||||
|
// Retrieves the csv format.
|
||||||
|
} else if (ACCEPT_TYPE.APPLICATION_CSV == acceptType) {
|
||||||
|
const buffer = await this.inventoryValuationApp.csv(tenantId, filter);
|
||||||
|
|
||||||
|
res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
|
||||||
|
res.setHeader('Content-Type', 'text/csv');
|
||||||
|
|
||||||
|
return res.send(buffer);
|
||||||
|
// Retrieves the xslx buffer format.
|
||||||
|
} else if (ACCEPT_TYPE.APPLICATION_XLSX === acceptType) {
|
||||||
|
const buffer = await this.inventoryValuationApp.xlsx(tenantId, filter);
|
||||||
|
|
||||||
|
res.setHeader('Content-Disposition', 'attachment; filename=output.xlsx');
|
||||||
|
res.setHeader(
|
||||||
|
'Content-Type',
|
||||||
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||||
|
);
|
||||||
|
return res.send(buffer);
|
||||||
|
// Retrieves the json format.
|
||||||
|
} else {
|
||||||
|
const { data, query, meta } = await this.inventoryValuationApp.sheet(
|
||||||
|
tenantId,
|
||||||
|
filter
|
||||||
|
);
|
||||||
|
return res.status(200).send({ meta, data, query });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -3,14 +3,15 @@ import { Request, Response, Router, NextFunction } from 'express';
|
|||||||
import { castArray } from 'lodash';
|
import { castArray } from 'lodash';
|
||||||
import { query, oneOf } from 'express-validator';
|
import { query, oneOf } from 'express-validator';
|
||||||
import BaseFinancialReportController from './BaseFinancialReportController';
|
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||||
import JournalSheetService from '@/services/FinancialStatements/JournalSheet/JournalSheetService';
|
|
||||||
import { AbilitySubject, ReportsAction } from '@/interfaces';
|
import { AbilitySubject, ReportsAction } from '@/interfaces';
|
||||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||||
|
import { ACCEPT_TYPE } from '@/interfaces/Http';
|
||||||
|
import { JournalSheetApplication } from '@/services/FinancialStatements/JournalSheet/JournalSheetApplication';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class JournalSheetController extends BaseFinancialReportController {
|
export default class JournalSheetController extends BaseFinancialReportController {
|
||||||
@Inject()
|
@Inject()
|
||||||
journalService: JournalSheetService;
|
private journalSheetApp: JournalSheetApplication;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Router constructor.
|
* Router constructor.
|
||||||
@@ -57,28 +58,49 @@ export default class JournalSheetController extends BaseFinancialReportControlle
|
|||||||
* @param {Request} req -
|
* @param {Request} req -
|
||||||
* @param {Response} res -
|
* @param {Response} res -
|
||||||
*/
|
*/
|
||||||
async journal(req: Request, res: Response, next: NextFunction) {
|
private async journal(req: Request, res: Response, next: NextFunction) {
|
||||||
const { tenantId, settings } = req;
|
const { tenantId } = req;
|
||||||
let filter = this.matchedQueryData(req);
|
let filter = this.matchedQueryData(req);
|
||||||
|
|
||||||
filter = {
|
filter = {
|
||||||
...filter,
|
...filter,
|
||||||
accountsIds: castArray(filter.accountsIds),
|
accountsIds: castArray(filter.accountsIds),
|
||||||
};
|
};
|
||||||
|
const accept = this.accepts(req);
|
||||||
|
const acceptType = accept.types([
|
||||||
|
ACCEPT_TYPE.APPLICATION_JSON,
|
||||||
|
ACCEPT_TYPE.APPLICATION_JSON_TABLE,
|
||||||
|
ACCEPT_TYPE.APPLICATION_XLSX,
|
||||||
|
ACCEPT_TYPE.APPLICATION_CSV,
|
||||||
|
]);
|
||||||
|
|
||||||
try {
|
// Retrieves the json table format.
|
||||||
const { data, query, meta } = await this.journalService.journalSheet(
|
if (ACCEPT_TYPE.APPLICATION_JSON_TABLE === acceptType) {
|
||||||
tenantId,
|
const table = await this.journalSheetApp.table(tenantId, filter);
|
||||||
filter
|
return res.status(200).send(table);
|
||||||
|
// Retrieves the csv format.
|
||||||
|
} else if (ACCEPT_TYPE.APPLICATION_CSV === acceptType) {
|
||||||
|
const buffer = await this.journalSheetApp.csv(tenantId, filter);
|
||||||
|
|
||||||
|
res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
|
||||||
|
res.setHeader('Content-Type', 'text/csv');
|
||||||
|
|
||||||
|
return res.send(buffer);
|
||||||
|
// Retrieves the xlsx format.
|
||||||
|
} else if (ACCEPT_TYPE.APPLICATION_XLSX === acceptType) {
|
||||||
|
const buffer = await this.journalSheetApp.xlsx(tenantId, filter);
|
||||||
|
|
||||||
|
res.setHeader('Content-Disposition', 'attachment; filename=output.xlsx');
|
||||||
|
res.setHeader(
|
||||||
|
'Content-Type',
|
||||||
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||||
);
|
);
|
||||||
|
return res.send(buffer);
|
||||||
|
// Retrieves the json format.
|
||||||
|
} else {
|
||||||
|
const sheet = await this.journalSheetApp.sheet(tenantId, filter);
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send(sheet);
|
||||||
data: this.transfromToResponse(data),
|
|
||||||
query: this.transfromToResponse(query),
|
|
||||||
meta: this.transfromToResponse(meta),
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
next(error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,18 @@
|
|||||||
import { Router, Request, Response, NextFunction } from 'express';
|
import { Router, Request, Response, NextFunction } from 'express';
|
||||||
import { query, ValidationChain } from 'express-validator';
|
import { query, ValidationChain } from 'express-validator';
|
||||||
import moment from 'moment';
|
|
||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
||||||
import BaseFinancialReportController from './BaseFinancialReportController';
|
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||||
import PurchasesByItemsService from '@/services/FinancialStatements/PurchasesByItems/PurchasesByItemsService';
|
import { PurchasesByItemsService } from '@/services/FinancialStatements/PurchasesByItems/PurchasesByItemsService';
|
||||||
import { AbilitySubject, ReportsAction } from '@/interfaces';
|
import { AbilitySubject, ReportsAction } from '@/interfaces';
|
||||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||||
|
import { ACCEPT_TYPE } from '@/interfaces/Http';
|
||||||
|
import { PurcahsesByItemsApplication } from '@/services/FinancialStatements/PurchasesByItems/PurchasesByItemsApplication';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class PurchasesByItemReportController extends BaseFinancialReportController {
|
export default class PurchasesByItemReportController extends BaseFinancialReportController {
|
||||||
@Inject()
|
@Inject()
|
||||||
purchasesByItemsService: PurchasesByItemsService;
|
private purchasesByItemsApp: PurcahsesByItemsApplication;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Router constructor.
|
* Router constructor.
|
||||||
@@ -63,20 +64,47 @@ export default class PurchasesByItemReportController extends BaseFinancialReport
|
|||||||
* @param {Request} req -
|
* @param {Request} req -
|
||||||
* @param {Response} res -
|
* @param {Response} res -
|
||||||
*/
|
*/
|
||||||
async purchasesByItems(req: Request, res: Response, next: NextFunction) {
|
public async purchasesByItems(req: Request, res: Response) {
|
||||||
const { tenantId } = req;
|
const { tenantId } = req;
|
||||||
const filter = this.matchedQueryData(req);
|
const filter = this.matchedQueryData(req);
|
||||||
|
|
||||||
try {
|
const accept = this.accepts(req);
|
||||||
const { data, query, meta } =
|
|
||||||
await this.purchasesByItemsService.purchasesByItems(tenantId, filter);
|
const acceptType = accept.types([
|
||||||
return res.status(200).send({
|
ACCEPT_TYPE.APPLICATION_JSON,
|
||||||
meta: this.transfromToResponse(meta),
|
ACCEPT_TYPE.APPLICATION_JSON_TABLE,
|
||||||
data: this.transfromToResponse(data),
|
ACCEPT_TYPE.APPLICATION_XLSX,
|
||||||
query: this.transfromToResponse(query),
|
ACCEPT_TYPE.APPLICATION_CSV,
|
||||||
});
|
]);
|
||||||
} catch (error) {
|
|
||||||
next(error);
|
// JSON table response format.
|
||||||
|
if (ACCEPT_TYPE.APPLICATION_JSON_TABLE === acceptType) {
|
||||||
|
const table = await this.purchasesByItemsApp.table(tenantId, filter);
|
||||||
|
|
||||||
|
return res.status(200).send(table);
|
||||||
|
// CSV response format.
|
||||||
|
} else if (ACCEPT_TYPE.APPLICATION_CSV === acceptType) {
|
||||||
|
const buffer = await this.purchasesByItemsApp.csv(tenantId, filter);
|
||||||
|
|
||||||
|
res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
|
||||||
|
res.setHeader('Content-Type', 'text/csv');
|
||||||
|
|
||||||
|
return res.send(buffer);
|
||||||
|
// Xlsx response format.
|
||||||
|
} else if (ACCEPT_TYPE.APPLICATION_XLSX === acceptType) {
|
||||||
|
const buffer = await this.purchasesByItemsApp.xlsx(tenantId, filter);
|
||||||
|
|
||||||
|
res.setHeader('Content-Disposition', 'attachment; filename=output.xlsx');
|
||||||
|
res.setHeader(
|
||||||
|
'Content-Type',
|
||||||
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||||
|
);
|
||||||
|
return res.send(buffer);
|
||||||
|
// Json response format.
|
||||||
|
} else {
|
||||||
|
const sheet = await this.purchasesByItemsApp.sheet(tenantId, filter);
|
||||||
|
|
||||||
|
return res.status(200).send(sheet);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,17 +1,17 @@
|
|||||||
import { Router, Request, Response, NextFunction } from 'express';
|
import { Router, Request, Response, NextFunction } from 'express';
|
||||||
import { query, ValidationChain } from 'express-validator';
|
import { query, ValidationChain, ValidationSchema } from 'express-validator';
|
||||||
import moment from 'moment';
|
|
||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
||||||
import BaseFinancialReportController from './BaseFinancialReportController';
|
import BaseFinancialReportController from './BaseFinancialReportController';
|
||||||
import SalesByItemsReportService from '@/services/FinancialStatements/SalesByItems/SalesByItemsService';
|
|
||||||
import { AbilitySubject, ReportsAction } from '@/interfaces';
|
import { AbilitySubject, ReportsAction } from '@/interfaces';
|
||||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||||
|
import { ACCEPT_TYPE } from '@/interfaces/Http';
|
||||||
|
import { SalesByItemsApplication } from '@/services/FinancialStatements/SalesByItems/SalesByItemsApplication';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class SalesByItemsReportController extends BaseFinancialReportController {
|
export default class SalesByItemsReportController extends BaseFinancialReportController {
|
||||||
@Inject()
|
@Inject()
|
||||||
salesByItemsService: SalesByItemsReportService;
|
salesByItemsApp: SalesByItemsApplication;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Router constructor.
|
* Router constructor.
|
||||||
@@ -24,13 +24,14 @@ export default class SalesByItemsReportController extends BaseFinancialReportCon
|
|||||||
CheckPolicies(ReportsAction.READ_SALES_BY_ITEMS, AbilitySubject.Report),
|
CheckPolicies(ReportsAction.READ_SALES_BY_ITEMS, AbilitySubject.Report),
|
||||||
this.validationSchema,
|
this.validationSchema,
|
||||||
this.validationResult,
|
this.validationResult,
|
||||||
asyncMiddleware(this.purchasesByItems.bind(this))
|
asyncMiddleware(this.salesByItems.bind(this))
|
||||||
);
|
);
|
||||||
return router;
|
return router;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validation schema.
|
* Validation schema.
|
||||||
|
* @returns {ValidationChain[]}
|
||||||
*/
|
*/
|
||||||
private get validationSchema(): ValidationChain[] {
|
private get validationSchema(): ValidationChain[] {
|
||||||
return [
|
return [
|
||||||
@@ -60,26 +61,44 @@ export default class SalesByItemsReportController extends BaseFinancialReportCon
|
|||||||
* @param {Request} req -
|
* @param {Request} req -
|
||||||
* @param {Response} res -
|
* @param {Response} res -
|
||||||
*/
|
*/
|
||||||
private async purchasesByItems(
|
private async salesByItems(req: Request, res: Response, next: NextFunction) {
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
next: NextFunction
|
|
||||||
) {
|
|
||||||
const { tenantId } = req;
|
const { tenantId } = req;
|
||||||
const filter = this.matchedQueryData(req);
|
const filter = this.matchedQueryData(req);
|
||||||
|
const accept = this.accepts(req);
|
||||||
|
|
||||||
try {
|
const acceptType = accept.types([
|
||||||
const { data, query, meta } = await this.salesByItemsService.salesByItems(
|
ACCEPT_TYPE.APPLICATION_JSON,
|
||||||
tenantId,
|
ACCEPT_TYPE.APPLICATION_JSON_TABLE,
|
||||||
filter
|
ACCEPT_TYPE.APPLICATION_CSV,
|
||||||
|
ACCEPT_TYPE.APPLICATION_XLSX,
|
||||||
|
]);
|
||||||
|
// Retrieves the csv format.
|
||||||
|
if (ACCEPT_TYPE.APPLICATION_CSV === acceptType) {
|
||||||
|
const buffer = await this.salesByItemsApp.csv(tenantId, filter);
|
||||||
|
|
||||||
|
res.setHeader('Content-Disposition', 'attachment; filename=output.csv');
|
||||||
|
res.setHeader('Content-Type', 'text/csv');
|
||||||
|
|
||||||
|
return res.send(buffer);
|
||||||
|
// Retrieves the json table format.
|
||||||
|
} else if (ACCEPT_TYPE.APPLICATION_JSON_TABLE === acceptType) {
|
||||||
|
const table = await this.salesByItemsApp.table(tenantId, filter);
|
||||||
|
|
||||||
|
return res.status(200).send(table);
|
||||||
|
// Retrieves the xlsx format.
|
||||||
|
} else if (ACCEPT_TYPE.APPLICATION_XLSX === acceptType) {
|
||||||
|
const buffer = this.salesByItemsApp.xlsx(tenantId, filter);
|
||||||
|
|
||||||
|
res.setHeader('Content-Disposition', 'attachment; filename=output.xlsx');
|
||||||
|
res.setHeader(
|
||||||
|
'Content-Type',
|
||||||
|
'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet'
|
||||||
);
|
);
|
||||||
return res.status(200).send({
|
return res.send(buffer);
|
||||||
meta: this.transfromToResponse(meta),
|
// Retrieves the json format.
|
||||||
data: this.transfromToResponse(data),
|
} else {
|
||||||
query: this.transfromToResponse(query),
|
const sheet = await this.salesByItemsApp.sheet(tenantId, filter);
|
||||||
});
|
return res.status(200).send(sheet);
|
||||||
} catch (error) {
|
|
||||||
next(error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -303,7 +303,7 @@ export default class BillsController extends BaseController {
|
|||||||
try {
|
try {
|
||||||
const bill = await this.billsApplication.getBill(tenantId, billId);
|
const bill = await this.billsApplication.getBill(tenantId, billId);
|
||||||
|
|
||||||
return res.status(200).send(this.transfromToResponse({ bill }));
|
return res.status(200).send({ bill });
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
@@ -348,14 +348,11 @@ export default class BillsController extends BaseController {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { bills, pagination, filterMeta } =
|
const billsWithPagination = await this.billsApplication.getBills(
|
||||||
await this.billsApplication.getBills(tenantId, filter);
|
tenantId,
|
||||||
|
filter
|
||||||
return res.status(200).send({
|
);
|
||||||
bills: this.transfromToResponse(bills),
|
return res.status(200).send(billsWithPagination);
|
||||||
pagination: this.transfromToResponse(pagination),
|
|
||||||
filter_meta: this.transfromToResponse(filterMeta),
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -158,15 +158,11 @@ export default class BillsPayments extends BaseController {
|
|||||||
const { tenantId } = req;
|
const { tenantId } = req;
|
||||||
const { vendorId } = this.matchedQueryData(req);
|
const { vendorId } = this.matchedQueryData(req);
|
||||||
|
|
||||||
try {
|
const entries = await this.billPaymentsPages.getNewPageEntries(
|
||||||
const entries = await this.billPaymentsPages.getNewPageEntries(
|
tenantId,
|
||||||
tenantId,
|
vendorId
|
||||||
vendorId
|
);
|
||||||
);
|
return res.status(200).send({ entries });
|
||||||
return res.status(200).send({
|
|
||||||
entries: this.transfromToResponse(entries),
|
|
||||||
});
|
|
||||||
} catch (error) {}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -183,16 +179,12 @@ export default class BillsPayments extends BaseController {
|
|||||||
const { id: paymentReceiveId } = req.params;
|
const { id: paymentReceiveId } = req.params;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { billPayment, entries } =
|
const billPaymentsWithEditEntries =
|
||||||
await this.billPaymentsPages.getBillPaymentEditPage(
|
await this.billPaymentsPages.getBillPaymentEditPage(
|
||||||
tenantId,
|
tenantId,
|
||||||
paymentReceiveId
|
paymentReceiveId
|
||||||
);
|
);
|
||||||
|
return res.status(200).send(billPaymentsWithEditEntries);
|
||||||
return res.status(200).send({
|
|
||||||
bill_payment: this.transfromToResponse(billPayment),
|
|
||||||
entries: this.transfromToResponse(entries),
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
@@ -304,9 +296,7 @@ export default class BillsPayments extends BaseController {
|
|||||||
tenantId,
|
tenantId,
|
||||||
billPaymentId
|
billPaymentId
|
||||||
);
|
);
|
||||||
return res.status(200).send({
|
return res.status(200).send({ billPayment });
|
||||||
bill_payment: this.transfromToResponse(billPayment),
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
@@ -359,17 +349,12 @@ export default class BillsPayments extends BaseController {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { billPayments, pagination, filterMeta } =
|
const billPaymentsWithPagination =
|
||||||
await this.billPaymentsApplication.getBillPayments(
|
await this.billPaymentsApplication.getBillPayments(
|
||||||
tenantId,
|
tenantId,
|
||||||
billPaymentsFilter
|
billPaymentsFilter
|
||||||
);
|
);
|
||||||
|
return res.status(200).send(billPaymentsWithPagination);
|
||||||
return res.status(200).send({
|
|
||||||
bill_payments: this.transfromToResponse(billPayments),
|
|
||||||
pagination: this.transfromToResponse(pagination),
|
|
||||||
filter_meta: this.transfromToResponse(filterMeta),
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -320,20 +320,19 @@ export default class VendorCreditController extends BaseController {
|
|||||||
res: Response,
|
res: Response,
|
||||||
next: NextFunction
|
next: NextFunction
|
||||||
) => {
|
) => {
|
||||||
const { id: billId } = req.params;
|
const { id: vendorCreditId } = req.params;
|
||||||
const { tenantId, user } = req;
|
const { tenantId, user } = req;
|
||||||
const vendorCreditEditDTO: IVendorCreditEditDTO = this.matchedBodyData(req);
|
const vendorCreditEditDTO: IVendorCreditEditDTO = this.matchedBodyData(req);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.editVendorCreditService.editVendorCredit(
|
await this.editVendorCreditService.editVendorCredit(
|
||||||
tenantId,
|
tenantId,
|
||||||
billId,
|
vendorCreditId,
|
||||||
vendorCreditEditDTO,
|
vendorCreditEditDTO
|
||||||
user
|
|
||||||
);
|
);
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
id: billId,
|
id: vendorCreditId,
|
||||||
message: 'The vendor credit has been edited successfully.',
|
message: 'The vendor credit has been edited successfully.',
|
||||||
});
|
});
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ import GetCreditNoteAssociatedInvoicesToApply from '@/services/CreditNotes/GetCr
|
|||||||
import GetCreditNoteAssociatedAppliedInvoices from '@/services/CreditNotes/GetCreditNoteAssociatedAppliedInvoices';
|
import GetCreditNoteAssociatedAppliedInvoices from '@/services/CreditNotes/GetCreditNoteAssociatedAppliedInvoices';
|
||||||
import GetRefundCreditTransaction from '@/services/CreditNotes/GetRefundCreditNoteTransaction';
|
import GetRefundCreditTransaction from '@/services/CreditNotes/GetRefundCreditNoteTransaction';
|
||||||
import GetCreditNotePdf from '../../../services/CreditNotes/GetCreditNotePdf';
|
import GetCreditNotePdf from '../../../services/CreditNotes/GetCreditNotePdf';
|
||||||
|
import { ACCEPT_TYPE } from '@/interfaces/Http';
|
||||||
/**
|
/**
|
||||||
* Credit notes controller.
|
* Credit notes controller.
|
||||||
* @service
|
* @service
|
||||||
@@ -293,7 +294,7 @@ export default class PaymentReceivesController extends BaseController {
|
|||||||
return [
|
return [
|
||||||
check('from_account_id').exists().isNumeric().toInt(),
|
check('from_account_id').exists().isNumeric().toInt(),
|
||||||
check('description').optional(),
|
check('description').optional(),
|
||||||
|
|
||||||
check('amount').exists().isNumeric().toFloat(),
|
check('amount').exists().isNumeric().toFloat(),
|
||||||
check('exchange_rate').optional().isFloat({ gt: 0 }).toFloat(),
|
check('exchange_rate').optional().isFloat({ gt: 0 }).toFloat(),
|
||||||
|
|
||||||
@@ -438,7 +439,7 @@ export default class PaymentReceivesController extends BaseController {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the payment receive details.
|
* Retrieve the credit note details.
|
||||||
* @param {Request} req
|
* @param {Request} req
|
||||||
* @param {Response} res
|
* @param {Response} res
|
||||||
* @param {NextFunction} next
|
* @param {NextFunction} next
|
||||||
@@ -451,38 +452,28 @@ export default class PaymentReceivesController extends BaseController {
|
|||||||
const { tenantId } = req;
|
const { tenantId } = req;
|
||||||
const { id: creditNoteId } = req.params;
|
const { id: creditNoteId } = req.params;
|
||||||
|
|
||||||
try {
|
const accept = this.accepts(req);
|
||||||
|
|
||||||
|
const acceptType = accept.types([
|
||||||
|
ACCEPT_TYPE.APPLICATION_JSON,
|
||||||
|
ACCEPT_TYPE.APPLICATION_PDF,
|
||||||
|
]);
|
||||||
|
if (ACCEPT_TYPE.APPLICATION_PDF === acceptType) {
|
||||||
|
const pdfContent = await this.creditNotePdf.getCreditNotePdf(
|
||||||
|
tenantId,
|
||||||
|
creditNoteId
|
||||||
|
);
|
||||||
|
res.set({
|
||||||
|
'Content-Type': 'application/pdf',
|
||||||
|
'Content-Length': pdfContent.length,
|
||||||
|
});
|
||||||
|
res.send(pdfContent);
|
||||||
|
} else {
|
||||||
const creditNote = await this.getCreditNoteService.getCreditNote(
|
const creditNote = await this.getCreditNoteService.getCreditNote(
|
||||||
tenantId,
|
tenantId,
|
||||||
creditNoteId
|
creditNoteId
|
||||||
);
|
);
|
||||||
const ACCEPT_TYPE = {
|
return res.status(200).send({ creditNote });
|
||||||
APPLICATION_PDF: 'application/pdf',
|
|
||||||
APPLICATION_JSON: 'application/json',
|
|
||||||
};
|
|
||||||
// Response formatter.
|
|
||||||
res.format({
|
|
||||||
// Json content type.
|
|
||||||
[ACCEPT_TYPE.APPLICATION_JSON]: () => {
|
|
||||||
return res
|
|
||||||
.status(200)
|
|
||||||
.send({ credit_note: this.transfromToResponse(creditNote) });
|
|
||||||
},
|
|
||||||
// Pdf content type.
|
|
||||||
[ACCEPT_TYPE.APPLICATION_PDF]: async () => {
|
|
||||||
const pdfContent = await this.creditNotePdf.getCreditNotePdf(
|
|
||||||
tenantId,
|
|
||||||
creditNote
|
|
||||||
);
|
|
||||||
res.set({
|
|
||||||
'Content-Type': 'application/pdf',
|
|
||||||
'Content-Length': pdfContent.length,
|
|
||||||
});
|
|
||||||
res.send(pdfContent);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
next(error);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
import { Router, Request, Response, NextFunction } from 'express';
|
import { Router, Request, Response, NextFunction } from 'express';
|
||||||
import { check, param, query, ValidationChain } from 'express-validator';
|
import { body, check, param, query, ValidationChain } from 'express-validator';
|
||||||
import {
|
import {
|
||||||
AbilitySubject,
|
AbilitySubject,
|
||||||
IPaymentReceiveDTO,
|
IPaymentReceiveDTO,
|
||||||
PaymentReceiveAction,
|
PaymentReceiveAction,
|
||||||
|
PaymentReceiveMailOptsDTO,
|
||||||
} from '@/interfaces';
|
} from '@/interfaces';
|
||||||
import BaseController from '@/api/controllers/BaseController';
|
import BaseController from '@/api/controllers/BaseController';
|
||||||
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
||||||
@@ -13,6 +14,7 @@ import DynamicListingService from '@/services/DynamicListing/DynamicListService'
|
|||||||
import { PaymentReceivesApplication } from '@/services/Sales/PaymentReceives/PaymentReceivesApplication';
|
import { PaymentReceivesApplication } from '@/services/Sales/PaymentReceives/PaymentReceivesApplication';
|
||||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||||
import { ServiceError } from '@/exceptions';
|
import { ServiceError } from '@/exceptions';
|
||||||
|
import { ACCEPT_TYPE } from '@/interfaces/Http';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class PaymentReceivesController extends BaseController {
|
export default class PaymentReceivesController extends BaseController {
|
||||||
@@ -117,6 +119,25 @@ export default class PaymentReceivesController extends BaseController {
|
|||||||
asyncMiddleware(this.deletePaymentReceive.bind(this)),
|
asyncMiddleware(this.deletePaymentReceive.bind(this)),
|
||||||
this.handleServiceErrors
|
this.handleServiceErrors
|
||||||
);
|
);
|
||||||
|
router.post(
|
||||||
|
'/:id/mail',
|
||||||
|
[
|
||||||
|
...this.paymentReceiveValidation,
|
||||||
|
body('subject').isString().optional(),
|
||||||
|
body('from').isString().optional(),
|
||||||
|
body('to').isString().optional(),
|
||||||
|
body('body').isString().optional(),
|
||||||
|
body('attach_invoice').optional().isBoolean().toBoolean(),
|
||||||
|
],
|
||||||
|
this.sendPaymentReceiveByMail.bind(this),
|
||||||
|
this.handleServiceErrors
|
||||||
|
);
|
||||||
|
router.get(
|
||||||
|
'/:id/mail',
|
||||||
|
[...this.paymentReceiveValidation],
|
||||||
|
asyncMiddleware(this.getPaymentDefaultMail.bind(this)),
|
||||||
|
this.handleServiceErrors
|
||||||
|
);
|
||||||
return router;
|
return router;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -328,17 +349,12 @@ export default class PaymentReceivesController extends BaseController {
|
|||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { paymentReceives, pagination, filterMeta } =
|
const paymentsReceivedWithPagination =
|
||||||
await this.paymentReceiveApplication.getPaymentReceives(
|
await this.paymentReceiveApplication.getPaymentReceives(
|
||||||
tenantId,
|
tenantId,
|
||||||
filter
|
filter
|
||||||
);
|
);
|
||||||
|
return res.status(200).send(paymentsReceivedWithPagination);
|
||||||
return res.status(200).send({
|
|
||||||
payment_receives: this.transfromToResponse(paymentReceives),
|
|
||||||
pagination: this.transfromToResponse(pagination),
|
|
||||||
filter_meta: this.transfromToResponse(filterMeta),
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
@@ -415,38 +431,34 @@ export default class PaymentReceivesController extends BaseController {
|
|||||||
const { tenantId } = req;
|
const { tenantId } = req;
|
||||||
const { id: paymentReceiveId } = req.params;
|
const { id: paymentReceiveId } = req.params;
|
||||||
|
|
||||||
try {
|
const accept = this.accepts(req);
|
||||||
|
|
||||||
|
const acceptType = accept.types([
|
||||||
|
ACCEPT_TYPE.APPLICATION_JSON,
|
||||||
|
ACCEPT_TYPE.APPLICATION_PDF,
|
||||||
|
]);
|
||||||
|
// Response in pdf format.
|
||||||
|
if (ACCEPT_TYPE.APPLICATION_PDF === acceptType) {
|
||||||
|
const pdfContent =
|
||||||
|
await this.paymentReceiveApplication.getPaymentReceivePdf(
|
||||||
|
tenantId,
|
||||||
|
paymentReceiveId
|
||||||
|
);
|
||||||
|
res.set({
|
||||||
|
'Content-Type': 'application/pdf',
|
||||||
|
'Content-Length': pdfContent.length,
|
||||||
|
});
|
||||||
|
res.send(pdfContent);
|
||||||
|
// Response in json format.
|
||||||
|
} else {
|
||||||
const paymentReceive =
|
const paymentReceive =
|
||||||
await this.paymentReceiveApplication.getPaymentReceive(
|
await this.paymentReceiveApplication.getPaymentReceive(
|
||||||
tenantId,
|
tenantId,
|
||||||
paymentReceiveId
|
paymentReceiveId
|
||||||
);
|
);
|
||||||
|
return res.status(200).send({
|
||||||
const ACCEPT_TYPE = {
|
payment_receive: paymentReceive,
|
||||||
APPLICATION_PDF: 'application/pdf',
|
|
||||||
APPLICATION_JSON: 'application/json',
|
|
||||||
};
|
|
||||||
res.format({
|
|
||||||
[ACCEPT_TYPE.APPLICATION_JSON]: () => {
|
|
||||||
return res.status(200).send({
|
|
||||||
payment_receive: this.transfromToResponse(paymentReceive),
|
|
||||||
});
|
|
||||||
},
|
|
||||||
[ACCEPT_TYPE.APPLICATION_PDF]: async () => {
|
|
||||||
const pdfContent =
|
|
||||||
await this.paymentReceiveApplication.getPaymentReceivePdf(
|
|
||||||
tenantId,
|
|
||||||
paymentReceive
|
|
||||||
);
|
|
||||||
res.set({
|
|
||||||
'Content-Type': 'application/pdf',
|
|
||||||
'Content-Length': pdfContent.length,
|
|
||||||
});
|
|
||||||
res.send(pdfContent);
|
|
||||||
},
|
|
||||||
});
|
});
|
||||||
} catch (error) {
|
|
||||||
next(error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -480,7 +492,7 @@ export default class PaymentReceivesController extends BaseController {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
* Retrieves the sms details of the given payment receive.
|
||||||
* @param {Request} req
|
* @param {Request} req
|
||||||
* @param {Response} res
|
* @param {Response} res
|
||||||
* @param {NextFunction} next
|
* @param {NextFunction} next
|
||||||
@@ -508,13 +520,73 @@ export default class PaymentReceivesController extends BaseController {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles service errors.
|
* Sends mail invoice of the given sale invoice.
|
||||||
* @param error
|
* @param {Request} req
|
||||||
* @param req
|
* @param {Response} res
|
||||||
* @param res
|
* @param {NextFunction} next
|
||||||
* @param next
|
|
||||||
*/
|
*/
|
||||||
handleServiceErrors(
|
public sendPaymentReceiveByMail = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
) => {
|
||||||
|
const { tenantId } = req;
|
||||||
|
const { id: paymentReceiveId } = req.params;
|
||||||
|
const paymentMailDTO: PaymentReceiveMailOptsDTO = this.matchedBodyData(
|
||||||
|
req,
|
||||||
|
{
|
||||||
|
includeOptionals: false,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this.paymentReceiveApplication.notifyPaymentByMail(
|
||||||
|
tenantId,
|
||||||
|
paymentReceiveId,
|
||||||
|
paymentMailDTO
|
||||||
|
);
|
||||||
|
return res.status(200).send({
|
||||||
|
code: 200,
|
||||||
|
message: 'The payment notification has been sent successfully.',
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the default mail options of the given payment transaction.
|
||||||
|
* @param {Request} req
|
||||||
|
* @param {Response} res
|
||||||
|
* @param {NextFunction} next
|
||||||
|
*/
|
||||||
|
public getPaymentDefaultMail = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
) => {
|
||||||
|
const { tenantId } = req;
|
||||||
|
const { id: paymentReceiveId } = req.params;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await this.paymentReceiveApplication.getPaymentMailOptions(
|
||||||
|
tenantId,
|
||||||
|
paymentReceiveId
|
||||||
|
);
|
||||||
|
return res.status(200).send({ data });
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles service errors.
|
||||||
|
* @param {Error} error
|
||||||
|
* @param {Request} req
|
||||||
|
* @param {Response} res
|
||||||
|
* @param {NextFunction} next
|
||||||
|
*/
|
||||||
|
private handleServiceErrors(
|
||||||
error: Error,
|
error: Error,
|
||||||
req: Request,
|
req: Request,
|
||||||
res: Response,
|
res: Response,
|
||||||
|
|||||||
@@ -1,10 +1,11 @@
|
|||||||
import { Router, Request, Response, NextFunction } from 'express';
|
import { Router, Request, Response, NextFunction } from 'express';
|
||||||
import { check, param, query } from 'express-validator';
|
import { body, check, param, query } from 'express-validator';
|
||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
import {
|
import {
|
||||||
AbilitySubject,
|
AbilitySubject,
|
||||||
ISaleEstimateDTO,
|
ISaleEstimateDTO,
|
||||||
SaleEstimateAction,
|
SaleEstimateAction,
|
||||||
|
SaleEstimateMailOptionsDTO,
|
||||||
} from '@/interfaces';
|
} from '@/interfaces';
|
||||||
import BaseController from '@/api/controllers/BaseController';
|
import BaseController from '@/api/controllers/BaseController';
|
||||||
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
||||||
@@ -121,6 +122,27 @@ export default class SalesEstimatesController extends BaseController {
|
|||||||
this.handleServiceErrors,
|
this.handleServiceErrors,
|
||||||
this.dynamicListService.handlerErrorsToResponse
|
this.dynamicListService.handlerErrorsToResponse
|
||||||
);
|
);
|
||||||
|
router.post(
|
||||||
|
'/:id/mail',
|
||||||
|
[
|
||||||
|
...this.validateSpecificEstimateSchema,
|
||||||
|
body('subject').isString().optional(),
|
||||||
|
body('from').isString().optional(),
|
||||||
|
body('to').isString().optional(),
|
||||||
|
body('body').isString().optional(),
|
||||||
|
body('attach_invoice').optional().isBoolean().toBoolean(),
|
||||||
|
],
|
||||||
|
this.validationResult,
|
||||||
|
asyncMiddleware(this.sendSaleEstimateMail.bind(this)),
|
||||||
|
this.handleServiceErrors
|
||||||
|
);
|
||||||
|
router.get(
|
||||||
|
'/:id/mail',
|
||||||
|
[...this.validateSpecificEstimateSchema],
|
||||||
|
this.validationResult,
|
||||||
|
asyncMiddleware(this.getSaleEstimateMail.bind(this)),
|
||||||
|
this.handleServiceErrors
|
||||||
|
);
|
||||||
return router;
|
return router;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -312,7 +334,6 @@ export default class SalesEstimatesController extends BaseController {
|
|||||||
tenantId,
|
tenantId,
|
||||||
estimateId
|
estimateId
|
||||||
);
|
);
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
id: estimateId,
|
id: estimateId,
|
||||||
message: 'The sale estimate has been approved successfully.',
|
message: 'The sale estimate has been approved successfully.',
|
||||||
@@ -341,7 +362,6 @@ export default class SalesEstimatesController extends BaseController {
|
|||||||
tenantId,
|
tenantId,
|
||||||
estimateId
|
estimateId
|
||||||
);
|
);
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
id: estimateId,
|
id: estimateId,
|
||||||
message: 'The sale estimate has been rejected successfully.',
|
message: 'The sale estimate has been rejected successfully.',
|
||||||
@@ -361,33 +381,30 @@ export default class SalesEstimatesController extends BaseController {
|
|||||||
const { id: estimateId } = req.params;
|
const { id: estimateId } = req.params;
|
||||||
const { tenantId } = req;
|
const { tenantId } = req;
|
||||||
|
|
||||||
try {
|
const accept = this.accepts(req);
|
||||||
|
|
||||||
|
const acceptType = accept.types([
|
||||||
|
ACCEPT_TYPE.APPLICATION_JSON,
|
||||||
|
ACCEPT_TYPE.APPLICATION_PDF,
|
||||||
|
]);
|
||||||
|
// Retrieves estimate in pdf format.
|
||||||
|
if (ACCEPT_TYPE.APPLICATION_PDF == acceptType) {
|
||||||
|
const pdfContent = await this.saleEstimatesApplication.getSaleEstimatePdf(
|
||||||
|
tenantId,
|
||||||
|
estimateId
|
||||||
|
);
|
||||||
|
res.set({
|
||||||
|
'Content-Type': 'application/pdf',
|
||||||
|
'Content-Length': pdfContent.length,
|
||||||
|
});
|
||||||
|
res.send(pdfContent);
|
||||||
|
// Retrieves estimates in json format.
|
||||||
|
} else {
|
||||||
const estimate = await this.saleEstimatesApplication.getSaleEstimate(
|
const estimate = await this.saleEstimatesApplication.getSaleEstimate(
|
||||||
tenantId,
|
tenantId,
|
||||||
estimateId
|
estimateId
|
||||||
);
|
);
|
||||||
// Response formatter.
|
return res.status(200).send({ estimate });
|
||||||
res.format({
|
|
||||||
// JSON content type.
|
|
||||||
[ACCEPT_TYPE.APPLICATION_JSON]: () => {
|
|
||||||
return res.status(200).send(this.transfromToResponse({ estimate }));
|
|
||||||
},
|
|
||||||
// PDF content type.
|
|
||||||
[ACCEPT_TYPE.APPLICATION_PDF]: async () => {
|
|
||||||
const pdfContent =
|
|
||||||
await this.saleEstimatesApplication.getSaleEstimatePdf(
|
|
||||||
tenantId,
|
|
||||||
estimate
|
|
||||||
);
|
|
||||||
res.set({
|
|
||||||
'Content-Type': 'application/pdf',
|
|
||||||
'Content-Length': pdfContent.length,
|
|
||||||
});
|
|
||||||
res.send(pdfContent);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
next(error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,22 +422,11 @@ export default class SalesEstimatesController extends BaseController {
|
|||||||
pageSize: 12,
|
pageSize: 12,
|
||||||
...this.matchedQueryData(req),
|
...this.matchedQueryData(req),
|
||||||
};
|
};
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const { salesEstimates, pagination, filterMeta } =
|
const salesEstimatesWithPagination =
|
||||||
await this.saleEstimatesApplication.getSaleEstimates(tenantId, filter);
|
await this.saleEstimatesApplication.getSaleEstimates(tenantId, filter);
|
||||||
|
|
||||||
res.format({
|
return res.status(200).send(salesEstimatesWithPagination);
|
||||||
[ACCEPT_TYPE.APPLICATION_JSON]: () => {
|
|
||||||
return res.status(200).send(
|
|
||||||
this.transfromToResponse({
|
|
||||||
salesEstimates,
|
|
||||||
pagination,
|
|
||||||
filterMeta,
|
|
||||||
})
|
|
||||||
);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
@@ -478,6 +484,65 @@ export default class SalesEstimatesController extends BaseController {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Send the sale estimate mail.
|
||||||
|
* @param {Request} req
|
||||||
|
* @param {Response} res
|
||||||
|
* @param {NextFunction} next
|
||||||
|
*/
|
||||||
|
private sendSaleEstimateMail = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
) => {
|
||||||
|
const { tenantId } = req;
|
||||||
|
const { id: invoiceId } = req.params;
|
||||||
|
const saleEstimateDTO: SaleEstimateMailOptionsDTO = this.matchedBodyData(
|
||||||
|
req,
|
||||||
|
{
|
||||||
|
includeOptionals: false,
|
||||||
|
}
|
||||||
|
);
|
||||||
|
try {
|
||||||
|
await this.saleEstimatesApplication.sendSaleEstimateMail(
|
||||||
|
tenantId,
|
||||||
|
invoiceId,
|
||||||
|
saleEstimateDTO
|
||||||
|
);
|
||||||
|
return res.status(200).send({
|
||||||
|
code: 200,
|
||||||
|
message: 'The sale estimate mail has been sent successfully.',
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the default mail options of the given sale estimate.
|
||||||
|
* @param {Request} req
|
||||||
|
* @param {Response} res
|
||||||
|
* @param {NextFunction} next
|
||||||
|
*/
|
||||||
|
private getSaleEstimateMail = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
) => {
|
||||||
|
const { tenantId } = req;
|
||||||
|
const { id: invoiceId } = req.params;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await this.saleEstimatesApplication.getSaleEstimateMail(
|
||||||
|
tenantId,
|
||||||
|
invoiceId
|
||||||
|
);
|
||||||
|
return res.status(200).send({ data });
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles service errors.
|
* Handles service errors.
|
||||||
* @param {Error} error
|
* @param {Error} error
|
||||||
|
|||||||
@@ -1,5 +1,5 @@
|
|||||||
import { Router, Request, Response, NextFunction } from 'express';
|
import { Router, Request, Response, NextFunction } from 'express';
|
||||||
import { check, param, query } from 'express-validator';
|
import { body, check, param, query } from 'express-validator';
|
||||||
import { Service, Inject } from 'typedi';
|
import { Service, Inject } from 'typedi';
|
||||||
import BaseController from '../BaseController';
|
import BaseController from '../BaseController';
|
||||||
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
||||||
@@ -10,14 +10,12 @@ import {
|
|||||||
ISaleInvoiceCreateDTO,
|
ISaleInvoiceCreateDTO,
|
||||||
SaleInvoiceAction,
|
SaleInvoiceAction,
|
||||||
AbilitySubject,
|
AbilitySubject,
|
||||||
|
SendInvoiceMailDTO,
|
||||||
} from '@/interfaces';
|
} from '@/interfaces';
|
||||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||||
import { SaleInvoiceApplication } from '@/services/Sales/Invoices/SaleInvoicesApplication';
|
import { SaleInvoiceApplication } from '@/services/Sales/Invoices/SaleInvoicesApplication';
|
||||||
|
import { ACCEPT_TYPE } from '@/interfaces/Http';
|
||||||
|
|
||||||
const ACCEPT_TYPE = {
|
|
||||||
APPLICATION_PDF: 'application/pdf',
|
|
||||||
APPLICATION_JSON: 'application/json',
|
|
||||||
};
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class SaleInvoicesController extends BaseController {
|
export default class SaleInvoicesController extends BaseController {
|
||||||
@Inject()
|
@Inject()
|
||||||
@@ -145,6 +143,48 @@ export default class SaleInvoicesController extends BaseController {
|
|||||||
this.handleServiceErrors,
|
this.handleServiceErrors,
|
||||||
this.dynamicListService.handlerErrorsToResponse
|
this.dynamicListService.handlerErrorsToResponse
|
||||||
);
|
);
|
||||||
|
router.get(
|
||||||
|
'/:id/mail-reminder',
|
||||||
|
this.specificSaleInvoiceValidation,
|
||||||
|
this.validationResult,
|
||||||
|
asyncMiddleware(this.getSaleInvoiceMailReminder.bind(this)),
|
||||||
|
this.handleServiceErrors
|
||||||
|
);
|
||||||
|
router.post(
|
||||||
|
'/:id/mail-reminder',
|
||||||
|
[
|
||||||
|
...this.specificSaleInvoiceValidation,
|
||||||
|
body('subject').isString().optional(),
|
||||||
|
body('from').isString().optional(),
|
||||||
|
body('to').isString().optional(),
|
||||||
|
body('body').isString().optional(),
|
||||||
|
body('attach_invoice').optional().isBoolean().toBoolean(),
|
||||||
|
],
|
||||||
|
this.validationResult,
|
||||||
|
asyncMiddleware(this.sendSaleInvoiceMailReminder.bind(this)),
|
||||||
|
this.handleServiceErrors
|
||||||
|
);
|
||||||
|
router.post(
|
||||||
|
'/:id/mail',
|
||||||
|
[
|
||||||
|
...this.specificSaleInvoiceValidation,
|
||||||
|
body('subject').isString().optional(),
|
||||||
|
body('from').isString().optional(),
|
||||||
|
body('to').isString().optional(),
|
||||||
|
body('body').isString().optional(),
|
||||||
|
body('attach_invoice').optional().isBoolean().toBoolean(),
|
||||||
|
],
|
||||||
|
this.validationResult,
|
||||||
|
asyncMiddleware(this.sendSaleInvoiceMail.bind(this)),
|
||||||
|
this.handleServiceErrors
|
||||||
|
);
|
||||||
|
router.get(
|
||||||
|
'/:id/mail',
|
||||||
|
[...this.specificSaleInvoiceValidation],
|
||||||
|
this.validationResult,
|
||||||
|
asyncMiddleware(this.getSaleInvoiceMail.bind(this)),
|
||||||
|
this.handleServiceErrors
|
||||||
|
);
|
||||||
return router;
|
return router;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,7 +400,6 @@ export default class SaleInvoicesController extends BaseController {
|
|||||||
saleInvoiceId,
|
saleInvoiceId,
|
||||||
user
|
user
|
||||||
);
|
);
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
id: saleInvoiceId,
|
id: saleInvoiceId,
|
||||||
message: 'The sale invoice has been deleted successfully.',
|
message: 'The sale invoice has been deleted successfully.',
|
||||||
@@ -375,43 +414,35 @@ export default class SaleInvoicesController extends BaseController {
|
|||||||
* @param {Request} req - Request object.
|
* @param {Request} req - Request object.
|
||||||
* @param {Response} res - Response object.
|
* @param {Response} res - Response object.
|
||||||
*/
|
*/
|
||||||
private async getSaleInvoice(
|
private async getSaleInvoice(req: Request, res: Response) {
|
||||||
req: Request,
|
|
||||||
res: Response,
|
|
||||||
next: NextFunction
|
|
||||||
) {
|
|
||||||
const { id: saleInvoiceId } = req.params;
|
const { id: saleInvoiceId } = req.params;
|
||||||
const { tenantId, user } = req;
|
const { tenantId, user } = req;
|
||||||
|
|
||||||
try {
|
const accept = this.accepts(req);
|
||||||
|
|
||||||
|
const acceptType = accept.types([
|
||||||
|
ACCEPT_TYPE.APPLICATION_JSON,
|
||||||
|
ACCEPT_TYPE.APPLICATION_PDF,
|
||||||
|
]);
|
||||||
|
// Retrieves invoice in pdf format.
|
||||||
|
if (ACCEPT_TYPE.APPLICATION_PDF == acceptType) {
|
||||||
|
const pdfContent = await this.saleInvoiceApplication.saleInvoicePdf(
|
||||||
|
tenantId,
|
||||||
|
saleInvoiceId
|
||||||
|
);
|
||||||
|
res.set({
|
||||||
|
'Content-Type': 'application/pdf',
|
||||||
|
'Content-Length': pdfContent.length,
|
||||||
|
});
|
||||||
|
res.send(pdfContent);
|
||||||
|
// Retrieves invoice in json format.
|
||||||
|
} else {
|
||||||
const saleInvoice = await this.saleInvoiceApplication.getSaleInvoice(
|
const saleInvoice = await this.saleInvoiceApplication.getSaleInvoice(
|
||||||
tenantId,
|
tenantId,
|
||||||
saleInvoiceId,
|
saleInvoiceId,
|
||||||
user
|
user
|
||||||
);
|
);
|
||||||
// Response formatter.
|
return res.status(200).send({ saleInvoice });
|
||||||
res.format({
|
|
||||||
// JSON content type.
|
|
||||||
[ACCEPT_TYPE.APPLICATION_JSON]: () => {
|
|
||||||
return res
|
|
||||||
.status(200)
|
|
||||||
.send(this.transfromToResponse({ saleInvoice }));
|
|
||||||
},
|
|
||||||
// PDF content type.
|
|
||||||
[ACCEPT_TYPE.APPLICATION_PDF]: async () => {
|
|
||||||
const pdfContent = await this.saleInvoiceApplication.saleInvoicePdf(
|
|
||||||
tenantId,
|
|
||||||
saleInvoice
|
|
||||||
);
|
|
||||||
res.set({
|
|
||||||
'Content-Type': 'application/pdf',
|
|
||||||
'Content-Length': pdfContent.length,
|
|
||||||
});
|
|
||||||
res.send(pdfContent);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
next(error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
@@ -434,14 +465,10 @@ export default class SaleInvoicesController extends BaseController {
|
|||||||
...this.matchedQueryData(req),
|
...this.matchedQueryData(req),
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const { salesInvoices, filterMeta, pagination } =
|
const salesInvoicesWithPagination =
|
||||||
await this.saleInvoiceApplication.getSaleInvoices(tenantId, filter);
|
await this.saleInvoiceApplication.getSaleInvoices(tenantId, filter);
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send(salesInvoicesWithPagination);
|
||||||
sales_invoices: this.transfromToResponse(salesInvoices),
|
|
||||||
pagination: this.transfromToResponse(pagination),
|
|
||||||
filter_meta: this.transfromToResponse(filterMeta),
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
@@ -468,9 +495,7 @@ export default class SaleInvoicesController extends BaseController {
|
|||||||
tenantId,
|
tenantId,
|
||||||
customerId
|
customerId
|
||||||
);
|
);
|
||||||
return res.status(200).send({
|
return res.status(200).send({ salesInvoices });
|
||||||
sales_invoices: this.transfromToResponse(salesInvoices),
|
|
||||||
});
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
@@ -498,7 +523,6 @@ export default class SaleInvoicesController extends BaseController {
|
|||||||
invoiceId,
|
invoiceId,
|
||||||
writeoffDTO
|
writeoffDTO
|
||||||
);
|
);
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
id: saleInvoice.id,
|
id: saleInvoice.id,
|
||||||
message: 'The given sale invoice has been written-off successfully.',
|
message: 'The given sale invoice has been written-off successfully.',
|
||||||
@@ -630,6 +654,119 @@ export default class SaleInvoicesController extends BaseController {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends mail invoice of the given sale invoice.
|
||||||
|
* @param {Request} req
|
||||||
|
* @param {Response} res
|
||||||
|
* @param {NextFunction} next
|
||||||
|
*/
|
||||||
|
public async sendSaleInvoiceMail(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
) {
|
||||||
|
const { tenantId } = req;
|
||||||
|
const { id: invoiceId } = req.params;
|
||||||
|
const invoiceMailDTO: SendInvoiceMailDTO = this.matchedBodyData(req, {
|
||||||
|
includeOptionals: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this.saleInvoiceApplication.sendSaleInvoiceMail(
|
||||||
|
tenantId,
|
||||||
|
invoiceId,
|
||||||
|
invoiceMailDTO
|
||||||
|
);
|
||||||
|
return res.status(200).send({
|
||||||
|
code: 200,
|
||||||
|
message: 'The sale invoice mail has been sent successfully.',
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retreivers the sale invoice reminder options.
|
||||||
|
* @param {Request} req
|
||||||
|
* @param {Response} res
|
||||||
|
* @param {NextFunction} next
|
||||||
|
*/
|
||||||
|
public async getSaleInvoiceMailReminder(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
) {
|
||||||
|
const { tenantId } = req;
|
||||||
|
const { id: invoiceId } = req.params;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await this.saleInvoiceApplication.getSaleInvoiceMailReminder(
|
||||||
|
tenantId,
|
||||||
|
invoiceId
|
||||||
|
);
|
||||||
|
return res.status(200).send(data);
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends mail invoice of the given sale invoice.
|
||||||
|
* @param {Request} req
|
||||||
|
* @param {Response} res
|
||||||
|
* @param {NextFunction} next
|
||||||
|
*/
|
||||||
|
public async sendSaleInvoiceMailReminder(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
) {
|
||||||
|
const { tenantId } = req;
|
||||||
|
const { id: invoiceId } = req.params;
|
||||||
|
const invoiceMailDTO: SendInvoiceMailDTO = this.matchedBodyData(req, {
|
||||||
|
includeOptionals: false,
|
||||||
|
});
|
||||||
|
try {
|
||||||
|
await this.saleInvoiceApplication.sendSaleInvoiceMailReminder(
|
||||||
|
tenantId,
|
||||||
|
invoiceId,
|
||||||
|
invoiceMailDTO
|
||||||
|
);
|
||||||
|
return res.status(200).send({
|
||||||
|
code: 200,
|
||||||
|
message: 'The sale invoice mail reminder has been sent successfully.',
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the default mail options of the given sale invoice.
|
||||||
|
* @param {Request} req
|
||||||
|
* @param {Response} res
|
||||||
|
* @param {NextFunction} next
|
||||||
|
*/
|
||||||
|
public async getSaleInvoiceMail(
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
) {
|
||||||
|
const { tenantId } = req;
|
||||||
|
const { id: invoiceId } = req.params;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await this.saleInvoiceApplication.getSaleInvoiceMail(
|
||||||
|
tenantId,
|
||||||
|
invoiceId
|
||||||
|
);
|
||||||
|
return res.status(200).send({ data });
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles service errors.
|
* Handles service errors.
|
||||||
* @param {Error} error
|
* @param {Error} error
|
||||||
|
|||||||
@@ -1,14 +1,19 @@
|
|||||||
import { Router, Request, Response, NextFunction } from 'express';
|
import { Router, Request, Response, NextFunction } from 'express';
|
||||||
import { check, param, query } from 'express-validator';
|
import { body, check, param, query } from 'express-validator';
|
||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
import asyncMiddleware from '@/api/middleware/asyncMiddleware';
|
||||||
import BaseController from '../BaseController';
|
import BaseController from '../BaseController';
|
||||||
import { ISaleReceiptDTO } from '@/interfaces/SaleReceipt';
|
import {
|
||||||
|
ISaleReceiptDTO,
|
||||||
|
SaleReceiptMailOpts,
|
||||||
|
SaleReceiptMailOptsDTO,
|
||||||
|
} from '@/interfaces/SaleReceipt';
|
||||||
import { ServiceError } from '@/exceptions';
|
import { ServiceError } from '@/exceptions';
|
||||||
import DynamicListingService from '@/services/DynamicListing/DynamicListService';
|
import DynamicListingService from '@/services/DynamicListing/DynamicListService';
|
||||||
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
import CheckPolicies from '@/api/middleware/CheckPolicies';
|
||||||
import { AbilitySubject, SaleReceiptAction } from '@/interfaces';
|
import { AbilitySubject, SaleReceiptAction } from '@/interfaces';
|
||||||
import { SaleReceiptApplication } from '@/services/Sales/Receipts/SaleReceiptApplication';
|
import { SaleReceiptApplication } from '@/services/Sales/Receipts/SaleReceiptApplication';
|
||||||
|
import { ACCEPT_TYPE } from '@/interfaces/Http';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class SalesReceiptsController extends BaseController {
|
export default class SalesReceiptsController extends BaseController {
|
||||||
@@ -46,6 +51,27 @@ export default class SalesReceiptsController extends BaseController {
|
|||||||
this.saleReceiptSmsDetails,
|
this.saleReceiptSmsDetails,
|
||||||
this.handleServiceErrors
|
this.handleServiceErrors
|
||||||
);
|
);
|
||||||
|
router.post(
|
||||||
|
'/:id/mail',
|
||||||
|
[
|
||||||
|
...this.specificReceiptValidationSchema,
|
||||||
|
body('subject').isString().optional(),
|
||||||
|
body('from').isString().optional(),
|
||||||
|
body('to').isString().optional(),
|
||||||
|
body('body').isString().optional(),
|
||||||
|
body('attach_receipt').optional().isBoolean().toBoolean(),
|
||||||
|
],
|
||||||
|
this.validationResult,
|
||||||
|
asyncMiddleware(this.sendSaleReceiptMail.bind(this)),
|
||||||
|
this.handleServiceErrors
|
||||||
|
);
|
||||||
|
router.get(
|
||||||
|
'/:id/mail',
|
||||||
|
[...this.specificReceiptValidationSchema],
|
||||||
|
this.validationResult,
|
||||||
|
asyncMiddleware(this.getSaleReceiptMail.bind(this)),
|
||||||
|
this.handleServiceErrors
|
||||||
|
);
|
||||||
router.post(
|
router.post(
|
||||||
'/:id',
|
'/:id',
|
||||||
CheckPolicies(SaleReceiptAction.Edit, AbilitySubject.SaleReceipt),
|
CheckPolicies(SaleReceiptAction.Edit, AbilitySubject.SaleReceipt),
|
||||||
@@ -205,7 +231,6 @@ export default class SalesReceiptsController extends BaseController {
|
|||||||
tenantId,
|
tenantId,
|
||||||
saleReceiptId
|
saleReceiptId
|
||||||
);
|
);
|
||||||
|
|
||||||
return res.status(200).send({
|
return res.status(200).send({
|
||||||
id: saleReceiptId,
|
id: saleReceiptId,
|
||||||
message: 'Sale receipt has been deleted successfully.',
|
message: 'Sale receipt has been deleted successfully.',
|
||||||
@@ -294,15 +319,10 @@ export default class SalesReceiptsController extends BaseController {
|
|||||||
...this.matchedQueryData(req),
|
...this.matchedQueryData(req),
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const { data, pagination, filterMeta } =
|
const salesReceiptsWithPagination =
|
||||||
await this.saleReceiptsApplication.getSaleReceipts(tenantId, filter);
|
await this.saleReceiptsApplication.getSaleReceipts(tenantId, filter);
|
||||||
|
|
||||||
const response = this.transfromToResponse({
|
return res.status(200).send(salesReceiptsWithPagination);
|
||||||
data,
|
|
||||||
pagination,
|
|
||||||
filterMeta,
|
|
||||||
});
|
|
||||||
return res.status(200).send(response);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
next(error);
|
next(error);
|
||||||
}
|
}
|
||||||
@@ -314,36 +334,34 @@ export default class SalesReceiptsController extends BaseController {
|
|||||||
* @param {Response} res
|
* @param {Response} res
|
||||||
* @param {NextFunction} next
|
* @param {NextFunction} next
|
||||||
*/
|
*/
|
||||||
async getSaleReceipt(req: Request, res: Response, next: NextFunction) {
|
public async getSaleReceipt(req: Request, res: Response) {
|
||||||
const { id: saleReceiptId } = req.params;
|
const { id: saleReceiptId } = req.params;
|
||||||
const { tenantId } = req;
|
const { tenantId } = req;
|
||||||
|
|
||||||
try {
|
const accept = this.accepts(req);
|
||||||
|
|
||||||
|
const acceptType = accept.types([
|
||||||
|
ACCEPT_TYPE.APPLICATION_JSON,
|
||||||
|
ACCEPT_TYPE.APPLICATION_PDF,
|
||||||
|
]);
|
||||||
|
// Retrieves receipt in pdf format.
|
||||||
|
if (ACCEPT_TYPE.APPLICATION_PDF == acceptType) {
|
||||||
|
const pdfContent = await this.saleReceiptsApplication.getSaleReceiptPdf(
|
||||||
|
tenantId,
|
||||||
|
saleReceiptId
|
||||||
|
);
|
||||||
|
res.set({
|
||||||
|
'Content-Type': 'application/pdf',
|
||||||
|
'Content-Length': pdfContent.length,
|
||||||
|
});
|
||||||
|
res.send(pdfContent);
|
||||||
|
// Retrieves receipt in json format.
|
||||||
|
} else {
|
||||||
const saleReceipt = await this.saleReceiptsApplication.getSaleReceipt(
|
const saleReceipt = await this.saleReceiptsApplication.getSaleReceipt(
|
||||||
tenantId,
|
tenantId,
|
||||||
saleReceiptId
|
saleReceiptId
|
||||||
);
|
);
|
||||||
res.format({
|
return res.status(200).send({ saleReceipt });
|
||||||
'application/json': () => {
|
|
||||||
return res
|
|
||||||
.status(200)
|
|
||||||
.send(this.transfromToResponse({ saleReceipt }));
|
|
||||||
},
|
|
||||||
'application/pdf': async () => {
|
|
||||||
const pdfContent =
|
|
||||||
await this.saleReceiptsApplication.getSaleReceiptPdf(
|
|
||||||
tenantId,
|
|
||||||
saleReceipt
|
|
||||||
);
|
|
||||||
res.set({
|
|
||||||
'Content-Type': 'application/pdf',
|
|
||||||
'Content-Length': pdfContent.length,
|
|
||||||
});
|
|
||||||
res.send(pdfContent);
|
|
||||||
},
|
|
||||||
});
|
|
||||||
} catch (error) {
|
|
||||||
next(error);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -405,6 +423,64 @@ export default class SalesReceiptsController extends BaseController {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sends mail notification of the given sale receipt.
|
||||||
|
* @param {Request} req
|
||||||
|
* @param {Response} res
|
||||||
|
* @param {NextFunction} next
|
||||||
|
*/
|
||||||
|
public sendSaleReceiptMail = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
) => {
|
||||||
|
const { tenantId } = req;
|
||||||
|
const { id: receiptId } = req.params;
|
||||||
|
const receiptMailDTO: SaleReceiptMailOptsDTO = this.matchedBodyData(req, {
|
||||||
|
includeOptionals: false,
|
||||||
|
});
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this.saleReceiptsApplication.sendSaleReceiptMail(
|
||||||
|
tenantId,
|
||||||
|
receiptId,
|
||||||
|
receiptMailDTO
|
||||||
|
);
|
||||||
|
return res.status(200).send({
|
||||||
|
code: 200,
|
||||||
|
message:
|
||||||
|
'The sale receipt notification via sms has been sent successfully.',
|
||||||
|
});
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the default mail options of the given sale receipt.
|
||||||
|
* @param {Request} req
|
||||||
|
* @param {Response} res
|
||||||
|
* @param {NextFunction} next
|
||||||
|
*/
|
||||||
|
public getSaleReceiptMail = async (
|
||||||
|
req: Request,
|
||||||
|
res: Response,
|
||||||
|
next: NextFunction
|
||||||
|
) => {
|
||||||
|
const { tenantId } = req;
|
||||||
|
const { id: receiptId } = req.params;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const data = await this.saleReceiptsApplication.getSaleReceiptMail(
|
||||||
|
tenantId,
|
||||||
|
receiptId
|
||||||
|
);
|
||||||
|
return res.status(200).send({ data });
|
||||||
|
} catch (error) {
|
||||||
|
next(error);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Handles service errors.
|
* Handles service errors.
|
||||||
* @param {Error} error
|
* @param {Error} error
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ global.__root_dir = path.join(__dirname, '..');
|
|||||||
global.__resources_dir = path.join(global.__root_dir, 'resources');
|
global.__resources_dir = path.join(global.__root_dir, 'resources');
|
||||||
global.__locales_dir = path.join(global.__resources_dir, 'locales');
|
global.__locales_dir = path.join(global.__resources_dir, 'locales');
|
||||||
global.__views_dir = path.join(global.__root_dir, 'views');
|
global.__views_dir = path.join(global.__root_dir, 'views');
|
||||||
|
global.__storage_dir = path.join(global.__root_dir, 'storage');
|
||||||
|
|
||||||
moment.prototype.toMySqlDateTime = function () {
|
moment.prototype.toMySqlDateTime = function () {
|
||||||
return this.format('YYYY-MM-DD HH:mm:ss');
|
return this.format('YYYY-MM-DD HH:mm:ss');
|
||||||
|
|||||||
@@ -58,6 +58,7 @@ module.exports = {
|
|||||||
secure: !!parseInt(process.env.MAIL_SECURE, 10),
|
secure: !!parseInt(process.env.MAIL_SECURE, 10),
|
||||||
username: process.env.MAIL_USERNAME,
|
username: process.env.MAIL_USERNAME,
|
||||||
password: process.env.MAIL_PASSWORD,
|
password: process.env.MAIL_PASSWORD,
|
||||||
|
from: process.env.MAIL_FROM_ADDRESS,
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -168,4 +169,14 @@ module.exports = {
|
|||||||
* to application detarmines to upgrade.
|
* to application detarmines to upgrade.
|
||||||
*/
|
*/
|
||||||
databaseBatch: 4,
|
databaseBatch: 4,
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Exchange rate.
|
||||||
|
*/
|
||||||
|
exchangeRate: {
|
||||||
|
service: 'open-exchange-rate',
|
||||||
|
openExchangeRate: {
|
||||||
|
appId: process.env.OPEN_EXCHANGE_RATE_APP_ID,
|
||||||
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -59,6 +59,12 @@ export default {
|
|||||||
auto_increment: {
|
auto_increment: {
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
},
|
},
|
||||||
|
customer_notes: {
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
terms_conditions: {
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
sales_receipts: {
|
sales_receipts: {
|
||||||
next_number: {
|
next_number: {
|
||||||
@@ -73,6 +79,12 @@ export default {
|
|||||||
preferred_deposit_account: {
|
preferred_deposit_account: {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
},
|
},
|
||||||
|
receipt_message: {
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
terms_conditions: {
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
sales_invoices: {
|
sales_invoices: {
|
||||||
next_number: {
|
next_number: {
|
||||||
@@ -84,6 +96,12 @@ export default {
|
|||||||
auto_increment: {
|
auto_increment: {
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
},
|
},
|
||||||
|
customer_notes: {
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
terms_conditions: {
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
payment_receives: {
|
payment_receives: {
|
||||||
next_number: {
|
next_number: {
|
||||||
@@ -147,6 +165,12 @@ export default {
|
|||||||
auto_increment: {
|
auto_increment: {
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
},
|
},
|
||||||
|
customer_notes: {
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
|
terms_conditions: {
|
||||||
|
type: 'string',
|
||||||
|
},
|
||||||
},
|
},
|
||||||
vendor_credit: {
|
vendor_credit: {
|
||||||
next_number: {
|
next_number: {
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
exports.up = function (knex) {
|
||||||
|
return knex.schema.createTable('storage', (table) => {
|
||||||
|
table.increments('id').primary();
|
||||||
|
table.string('key').notNullable();
|
||||||
|
table.string('path').notNullable();
|
||||||
|
table.string('extension').notNullable();
|
||||||
|
table.integer('expire_in');
|
||||||
|
table.timestamps();
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
exports.down = function (knex) {
|
||||||
|
return knex.schema.dropTableIfExists('storage');
|
||||||
|
};
|
||||||
@@ -1,13 +1,10 @@
|
|||||||
import {
|
import {
|
||||||
IAgingPeriod,
|
IAgingPeriod,
|
||||||
IAgingPeriodTotal,
|
|
||||||
IAgingAmount,
|
|
||||||
IAgingSummaryQuery,
|
IAgingSummaryQuery,
|
||||||
IAgingSummaryTotal,
|
IAgingSummaryTotal,
|
||||||
IAgingSummaryContact,
|
IAgingSummaryContact,
|
||||||
IAgingSummaryData,
|
IAgingSummaryData,
|
||||||
} from './AgingReport';
|
} from './AgingReport';
|
||||||
import { INumberFormatQuery } from './FinancialStatements';
|
|
||||||
import { IFinancialTable } from './Table';
|
import { IFinancialTable } from './Table';
|
||||||
|
|
||||||
export interface IAPAgingSummaryQuery extends IAgingSummaryQuery {
|
export interface IAPAgingSummaryQuery extends IAgingSummaryQuery {
|
||||||
|
|||||||
@@ -1,36 +1,10 @@
|
|||||||
import { IFilterRole } from './DynamicFilter';
|
export interface ExchangeRateLatestDTO {
|
||||||
|
toCurrency: string;
|
||||||
|
fromCurrency: string;
|
||||||
|
}
|
||||||
|
|
||||||
export interface IExchangeRate {
|
export interface EchangeRateLatestPOJO {
|
||||||
id: number,
|
baseCurrency: string;
|
||||||
currencyCode: string,
|
toCurrency: string;
|
||||||
exchangeRate: number,
|
exchangeRate: number;
|
||||||
date: Date,
|
}
|
||||||
createdAt: Date,
|
|
||||||
updatedAt: Date,
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface IExchangeRateDTO {
|
|
||||||
currencyCode: string,
|
|
||||||
exchangeRate: number,
|
|
||||||
date: Date,
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface IExchangeRateEditDTO {
|
|
||||||
exchangeRate: number,
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface IExchangeRateFilter {
|
|
||||||
page: number,
|
|
||||||
pageSize: number,
|
|
||||||
filterRoles?: IFilterRole[];
|
|
||||||
columnSortBy: string;
|
|
||||||
sortOrder: string;
|
|
||||||
};
|
|
||||||
|
|
||||||
export interface IExchangeRatesService {
|
|
||||||
newExchangeRate(tenantId: number, exchangeRateDTO: IExchangeRateDTO): Promise<IExchangeRate>;
|
|
||||||
editExchangeRate(tenantId: number, exchangeRateId: number, editExRateDTO: IExchangeRateEditDTO): Promise<void>;
|
|
||||||
|
|
||||||
deleteExchangeRate(tenantId: number, exchangeRateId: number): Promise<void>;
|
|
||||||
listExchangeRates(tenantId: number, exchangeRateFilter: IExchangeRateFilter): Promise<void>;
|
|
||||||
};
|
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import { IFinancialTable } from "./Table";
|
||||||
|
|
||||||
|
|
||||||
export interface IGeneralLedgerSheetQuery {
|
export interface IGeneralLedgerSheetQuery {
|
||||||
@@ -36,6 +37,7 @@ export interface IGeneralLedgerSheetAccountTransaction {
|
|||||||
referenceType?: string,
|
referenceType?: string,
|
||||||
|
|
||||||
date: Date|string,
|
date: Date|string,
|
||||||
|
dateFormatted: string;
|
||||||
};
|
};
|
||||||
|
|
||||||
export interface IGeneralLedgerSheetAccountBalance {
|
export interface IGeneralLedgerSheetAccountBalance {
|
||||||
@@ -56,6 +58,8 @@ export interface IGeneralLedgerSheetAccount {
|
|||||||
closingBalance: IGeneralLedgerSheetAccountBalance,
|
closingBalance: IGeneralLedgerSheetAccountBalance,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export type IGeneralLedgerSheetData = IGeneralLedgerSheetAccount[];
|
||||||
|
|
||||||
export interface IAccountTransaction {
|
export interface IAccountTransaction {
|
||||||
id: number,
|
id: number,
|
||||||
index: number,
|
index: number,
|
||||||
@@ -78,4 +82,11 @@ export interface IGeneralLedgerMeta {
|
|||||||
isCostComputeRunning: boolean,
|
isCostComputeRunning: boolean,
|
||||||
organizationName: string,
|
organizationName: string,
|
||||||
baseCurrency: string,
|
baseCurrency: string,
|
||||||
};
|
fromDate: string;
|
||||||
|
toDate: string;
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface IGeneralLedgerTableData extends IFinancialTable {
|
||||||
|
meta: IGeneralLedgerMeta;
|
||||||
|
query: IGeneralLedgerSheetQuery;
|
||||||
|
}
|
||||||
@@ -1,4 +1,5 @@
|
|||||||
import { INumberFormatQuery } from './FinancialStatements';
|
import { INumberFormatQuery } from './FinancialStatements';
|
||||||
|
import { IFinancialTable } from './Table';
|
||||||
|
|
||||||
export interface IInventoryValuationReportQuery {
|
export interface IInventoryValuationReportQuery {
|
||||||
asDate: Date | string;
|
asDate: Date | string;
|
||||||
@@ -39,9 +40,19 @@ export interface IInventoryValuationTotal {
|
|||||||
quantityFormatted: string;
|
quantityFormatted: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type IInventoryValuationStatement =
|
export type IInventoryValuationStatement = {
|
||||||
| {
|
items: IInventoryValuationItem[];
|
||||||
items: IInventoryValuationItem[];
|
total: IInventoryValuationTotal;
|
||||||
total: IInventoryValuationTotal;
|
};
|
||||||
}
|
export type IInventoryValuationSheetData = IInventoryValuationStatement;
|
||||||
| {};
|
|
||||||
|
export interface IInventoryValuationSheet {
|
||||||
|
data: IInventoryValuationStatement;
|
||||||
|
meta: IInventoryValuationSheetMeta;
|
||||||
|
query: IInventoryValuationReportQuery;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IInventoryValuationTable extends IFinancialTable {
|
||||||
|
meta: IInventoryValuationSheetMeta;
|
||||||
|
query: IInventoryValuationReportQuery;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,36 +1,52 @@
|
|||||||
import { IJournalEntry } from './Journal';
|
import { IJournalEntry } from './Journal';
|
||||||
|
import { IFinancialTable } from './Table';
|
||||||
|
|
||||||
export interface IJournalReportQuery {
|
export interface IJournalReportQuery {
|
||||||
fromDate: Date | string,
|
fromDate: Date | string;
|
||||||
toDate: Date | string,
|
toDate: Date | string;
|
||||||
numberFormat: {
|
numberFormat: {
|
||||||
noCents: boolean,
|
noCents: boolean;
|
||||||
divideOn1000: boolean,
|
divideOn1000: boolean;
|
||||||
},
|
};
|
||||||
transactionType: string,
|
transactionType: string;
|
||||||
transactionId: string,
|
transactionId: string;
|
||||||
|
|
||||||
accountsIds: number | number[],
|
accountsIds: number | number[];
|
||||||
fromRange: number,
|
fromRange: number;
|
||||||
toRange: number,
|
toRange: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IJournalReportEntriesGroup {
|
export interface IJournalReportEntriesGroup {
|
||||||
id: string,
|
id: string;
|
||||||
entries: IJournalEntry[],
|
date: Date;
|
||||||
currencyCode: string,
|
dateFormatted: string;
|
||||||
credit: number,
|
entries: IJournalEntry[];
|
||||||
debit: number,
|
currencyCode: string;
|
||||||
formattedCredit: string,
|
credit: number;
|
||||||
formattedDebit: string,
|
debit: number;
|
||||||
|
formattedCredit: string;
|
||||||
|
formattedDebit: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IJournalReport {
|
export interface IJournalReport {
|
||||||
entries: IJournalReportEntriesGroup[],
|
entries: IJournalReportEntriesGroup[];
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface IJournalSheetMeta {
|
export interface IJournalSheetMeta {
|
||||||
isCostComputeRunning: boolean,
|
isCostComputeRunning: boolean;
|
||||||
organizationName: string,
|
organizationName: string;
|
||||||
baseCurrency: string,
|
baseCurrency: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface IJournalTable extends IFinancialTable {
|
||||||
|
query: IJournalReportQuery;
|
||||||
|
meta: IJournalSheetMeta;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type IJournalTableData = IJournalReportEntriesGroup[];
|
||||||
|
|
||||||
|
export interface IJournalSheet {
|
||||||
|
data: IJournalTableData;
|
||||||
|
query: IJournalReportQuery;
|
||||||
|
meta: IJournalSheetMeta;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,9 +1,17 @@
|
|||||||
|
export type IMailAttachment = MailAttachmentPath | MailAttachmentContent;
|
||||||
|
|
||||||
|
export interface MailAttachmentPath {
|
||||||
|
filename: string;
|
||||||
|
path: string;
|
||||||
|
cid: string;
|
||||||
|
}
|
||||||
|
export interface MailAttachmentContent {
|
||||||
|
filename: string;
|
||||||
|
content: Buffer;
|
||||||
|
}
|
||||||
|
|
||||||
export interface IMailable {
|
export interface IMailable {
|
||||||
constructor(
|
constructor(view: string, data?: { [key: string]: string | number });
|
||||||
view: string,
|
|
||||||
data?: { [key: string]: string | number },
|
|
||||||
);
|
|
||||||
send(): Promise<any>;
|
send(): Promise<any>;
|
||||||
build(): void;
|
build(): void;
|
||||||
setData(data: { [key: string]: string | number }): IMailable;
|
setData(data: { [key: string]: string | number }): IMailable;
|
||||||
@@ -13,4 +21,27 @@ export interface IMailable {
|
|||||||
setView(view: string): IMailable;
|
setView(view: string): IMailable;
|
||||||
render(data?: { [key: string]: string | number }): string;
|
render(data?: { [key: string]: string | number }): string;
|
||||||
getViewContent(): string;
|
getViewContent(): string;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface AddressItem {
|
||||||
|
label: string;
|
||||||
|
mail: string;
|
||||||
|
primary?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CommonMailOptions {
|
||||||
|
toAddresses: AddressItem[];
|
||||||
|
fromAddresses: AddressItem[];
|
||||||
|
from: string;
|
||||||
|
to: string | string[];
|
||||||
|
subject: string;
|
||||||
|
body: string;
|
||||||
|
data?: Record<string, any>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface CommonMailOptionsDTO {
|
||||||
|
to?: string | string[];
|
||||||
|
from?: string;
|
||||||
|
subject?: string;
|
||||||
|
body?: string;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
import { ISystemUser } from '@/interfaces';
|
import {
|
||||||
|
CommonMailOptions,
|
||||||
|
CommonMailOptionsDTO,
|
||||||
|
ISystemUser,
|
||||||
|
} from '@/interfaces';
|
||||||
import { ILedgerEntry } from './Ledger';
|
import { ILedgerEntry } from './Ledger';
|
||||||
import { ISaleInvoice } from './SaleInvoice';
|
import { ISaleInvoice } from './SaleInvoice';
|
||||||
|
|
||||||
@@ -19,7 +23,7 @@ export interface IPaymentReceive {
|
|||||||
createdAt: Date;
|
createdAt: Date;
|
||||||
updatedAt: Date;
|
updatedAt: Date;
|
||||||
localAmount?: number;
|
localAmount?: number;
|
||||||
branchId?: number
|
branchId?: number;
|
||||||
}
|
}
|
||||||
export interface IPaymentReceiveCreateDTO {
|
export interface IPaymentReceiveCreateDTO {
|
||||||
customerId: number;
|
customerId: number;
|
||||||
@@ -165,3 +169,7 @@ export type IPaymentReceiveGLCommonEntry = Pick<
|
|||||||
| 'createdAt'
|
| 'createdAt'
|
||||||
| 'branchId'
|
| 'branchId'
|
||||||
>;
|
>;
|
||||||
|
|
||||||
|
export interface PaymentReceiveMailOpts extends CommonMailOptions {}
|
||||||
|
|
||||||
|
export interface PaymentReceiveMailOptsDTO extends CommonMailOptionsDTO {}
|
||||||
|
|||||||
54
packages/server/src/interfaces/PurchasesByItemsSheet.ts
Normal file
54
packages/server/src/interfaces/PurchasesByItemsSheet.ts
Normal file
@@ -0,0 +1,54 @@
|
|||||||
|
import { INumberFormatQuery } from './FinancialStatements';
|
||||||
|
import { IFinancialTable } from './Table';
|
||||||
|
|
||||||
|
export interface IPurchasesByItemsReportQuery {
|
||||||
|
fromDate: Date | string;
|
||||||
|
toDate: Date | string;
|
||||||
|
itemsIds: number[];
|
||||||
|
numberFormat: INumberFormatQuery;
|
||||||
|
noneTransactions: boolean;
|
||||||
|
onlyActive: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IPurchasesByItemsSheetMeta {
|
||||||
|
organizationName: string;
|
||||||
|
baseCurrency: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IPurchasesByItemsItem {
|
||||||
|
id: number;
|
||||||
|
name: string;
|
||||||
|
code: string;
|
||||||
|
quantitySold: number;
|
||||||
|
soldCost: number;
|
||||||
|
averageSellPrice: number;
|
||||||
|
|
||||||
|
quantitySoldFormatted: string;
|
||||||
|
soldCostFormatted: string;
|
||||||
|
averageSellPriceFormatted: string;
|
||||||
|
currencyCode: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IPurchasesByItemsTotal {
|
||||||
|
quantitySold: number;
|
||||||
|
soldCost: number;
|
||||||
|
quantitySoldFormatted: string;
|
||||||
|
soldCostFormatted: string;
|
||||||
|
currencyCode: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type IPurchasesByItemsSheetData = {
|
||||||
|
items: IPurchasesByItemsItem[];
|
||||||
|
total: IPurchasesByItemsTotal;
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface IPurchasesByItemsSheet {
|
||||||
|
data: IPurchasesByItemsSheetData;
|
||||||
|
query: IPurchasesByItemsReportQuery;
|
||||||
|
meta: IPurchasesByItemsSheetMeta;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface IPurchasesByItemsTable extends IFinancialTable {
|
||||||
|
query: IPurchasesByItemsReportQuery;
|
||||||
|
meta: IPurchasesByItemsSheetMeta;
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
import { IItemEntry, IItemEntryDTO } from './ItemEntry';
|
import { IItemEntry, IItemEntryDTO } from './ItemEntry';
|
||||||
import { IDynamicListFilterDTO } from '@/interfaces/DynamicFilter';
|
import { IDynamicListFilterDTO } from '@/interfaces/DynamicFilter';
|
||||||
|
import { CommonMailOptions, CommonMailOptionsDTO } from './Mailable';
|
||||||
|
|
||||||
export interface ISaleEstimate {
|
export interface ISaleEstimate {
|
||||||
id?: number;
|
id?: number;
|
||||||
@@ -124,3 +125,11 @@ export interface ISaleEstimateApprovedEvent {
|
|||||||
saleEstimate: ISaleEstimate;
|
saleEstimate: ISaleEstimate;
|
||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SaleEstimateMailOptions extends CommonMailOptions {
|
||||||
|
attachEstimate?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SaleEstimateMailOptionsDTO extends CommonMailOptionsDTO {
|
||||||
|
attachEstimate?: boolean;
|
||||||
|
}
|
||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
import { ISystemUser, IAccount, ITaxTransaction } from '@/interfaces';
|
import { ISystemUser, IAccount, ITaxTransaction } from '@/interfaces';
|
||||||
|
import { CommonMailOptions, CommonMailOptionsDTO } from './Mailable';
|
||||||
import { IDynamicListFilter } from '@/interfaces/DynamicFilter';
|
import { IDynamicListFilter } from '@/interfaces/DynamicFilter';
|
||||||
import { IItemEntry, IItemEntryDTO } from './ItemEntry';
|
import { IItemEntry, IItemEntryDTO } from './ItemEntry';
|
||||||
|
|
||||||
@@ -186,3 +187,17 @@ export enum SaleInvoiceAction {
|
|||||||
Writeoff = 'Writeoff',
|
Writeoff = 'Writeoff',
|
||||||
NotifyBySms = 'NotifyBySms',
|
NotifyBySms = 'NotifyBySms',
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SaleInvoiceMailOptions extends CommonMailOptions {
|
||||||
|
attachInvoice: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SendInvoiceMailDTO extends CommonMailOptionsDTO {
|
||||||
|
attachInvoice?: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ISaleInvoiceNotifyPayload {
|
||||||
|
tenantId: number;
|
||||||
|
saleInvoiceId: number;
|
||||||
|
messageDTO: SendInvoiceMailDTO;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
import { IItemEntry } from './ItemEntry';
|
import { IItemEntry } from './ItemEntry';
|
||||||
|
import { CommonMailOptions, CommonMailOptionsDTO } from './Mailable';
|
||||||
|
|
||||||
export interface ISaleReceipt {
|
export interface ISaleReceipt {
|
||||||
id?: number;
|
id?: number;
|
||||||
@@ -134,3 +135,11 @@ export interface ISaleReceiptDeletingPayload {
|
|||||||
oldSaleReceipt: ISaleReceipt;
|
oldSaleReceipt: ISaleReceipt;
|
||||||
trx: Knex.Transaction;
|
trx: Knex.Transaction;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface SaleReceiptMailOpts extends CommonMailOptions {
|
||||||
|
attachReceipt: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface SaleReceiptMailOptsDTO extends CommonMailOptionsDTO {
|
||||||
|
attachReceipt?: boolean;
|
||||||
|
}
|
||||||
|
|||||||
@@ -1,45 +1,54 @@
|
|||||||
import {
|
import { INumberFormatQuery } from './FinancialStatements';
|
||||||
INumberFormatQuery,
|
import { IFinancialTable } from './Table';
|
||||||
} from './FinancialStatements';
|
|
||||||
|
|
||||||
export interface ISalesByItemsReportQuery {
|
export interface ISalesByItemsReportQuery {
|
||||||
fromDate: Date | string;
|
fromDate: Date | string;
|
||||||
toDate: Date | string;
|
toDate: Date | string;
|
||||||
itemsIds: number[],
|
itemsIds: number[];
|
||||||
numberFormat: INumberFormatQuery;
|
numberFormat: INumberFormatQuery;
|
||||||
noneTransactions: boolean;
|
noneTransactions: boolean;
|
||||||
onlyActive: boolean;
|
onlyActive: boolean;
|
||||||
};
|
}
|
||||||
|
|
||||||
export interface ISalesByItemsSheetMeta {
|
export interface ISalesByItemsSheetMeta {
|
||||||
organizationName: string,
|
organizationName: string;
|
||||||
baseCurrency: string,
|
baseCurrency: string;
|
||||||
};
|
}
|
||||||
|
|
||||||
export interface ISalesByItemsItem {
|
export interface ISalesByItemsItem {
|
||||||
id: number,
|
id: number;
|
||||||
name: string,
|
name: string;
|
||||||
code: string,
|
code: string;
|
||||||
quantitySold: number,
|
quantitySold: number;
|
||||||
soldCost: number,
|
soldCost: number;
|
||||||
averageSellPrice: number,
|
averageSellPrice: number;
|
||||||
|
|
||||||
quantitySoldFormatted: string,
|
quantitySoldFormatted: string;
|
||||||
soldCostFormatted: string,
|
soldCostFormatted: string;
|
||||||
averageSellPriceFormatted: string,
|
averageSellPriceFormatted: string;
|
||||||
currencyCode: string,
|
currencyCode: string;
|
||||||
};
|
}
|
||||||
|
|
||||||
export interface ISalesByItemsTotal {
|
export interface ISalesByItemsTotal {
|
||||||
quantitySold: number,
|
quantitySold: number;
|
||||||
soldCost: number,
|
soldCost: number;
|
||||||
quantitySoldFormatted: string,
|
quantitySoldFormatted: string;
|
||||||
soldCostFormatted: string,
|
soldCostFormatted: string;
|
||||||
currencyCode: string,
|
currencyCode: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export type ISalesByItemsSheetData = {
|
||||||
|
items: ISalesByItemsItem[];
|
||||||
|
total: ISalesByItemsTotal;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type ISalesByItemsSheetStatement = {
|
export interface ISalesByItemsSheet {
|
||||||
items: ISalesByItemsItem[],
|
data: ISalesByItemsSheetData;
|
||||||
total: ISalesByItemsTotal
|
query: ISalesByItemsReportQuery;
|
||||||
} | {};
|
meta: ISalesByItemsSheetMeta;
|
||||||
|
}
|
||||||
|
|
||||||
|
export interface ISalesByItemsTable extends IFinancialTable {
|
||||||
|
query: ISalesByItemsReportQuery;
|
||||||
|
meta: ISalesByItemsSheetMeta;
|
||||||
|
}
|
||||||
26
packages/server/src/lib/Chromiumly/Chromiumly.ts
Normal file
26
packages/server/src/lib/Chromiumly/Chromiumly.ts
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
import { ChromiumRoute, LibreOfficeRoute, PdfEngineRoute } from './_types';
|
||||||
|
|
||||||
|
export class Chromiumly {
|
||||||
|
public static readonly GOTENBERG_ENDPOINT = process.env.GOTENBERG_URL || '';
|
||||||
|
|
||||||
|
public static readonly CHROMIUM_PATH = 'forms/chromium/convert';
|
||||||
|
public static readonly PDF_ENGINES_PATH = 'forms/pdfengines';
|
||||||
|
public static readonly LIBRE_OFFICE_PATH = 'forms/libreoffice';
|
||||||
|
|
||||||
|
public static readonly GOTENBERG_DOCS_ENDPOINT =
|
||||||
|
process.env.GOTENBERG_DOCS_URL || '';
|
||||||
|
|
||||||
|
public static readonly CHROMIUM_ROUTES = {
|
||||||
|
url: ChromiumRoute.URL,
|
||||||
|
html: ChromiumRoute.HTML,
|
||||||
|
markdown: ChromiumRoute.MARKDOWN,
|
||||||
|
};
|
||||||
|
|
||||||
|
public static readonly PDF_ENGINE_ROUTES = {
|
||||||
|
merge: PdfEngineRoute.MERGE,
|
||||||
|
};
|
||||||
|
|
||||||
|
public static readonly LIBRE_OFFICE_ROUTES = {
|
||||||
|
convert: LibreOfficeRoute.CONVERT,
|
||||||
|
};
|
||||||
|
}
|
||||||
66
packages/server/src/lib/Chromiumly/ConvertUtils.ts
Normal file
66
packages/server/src/lib/Chromiumly/ConvertUtils.ts
Normal file
@@ -0,0 +1,66 @@
|
|||||||
|
import FormData from 'form-data';
|
||||||
|
import { GotenbergUtils } from './GotenbergUtils';
|
||||||
|
import { PageProperties } from './_types';
|
||||||
|
|
||||||
|
export class ConverterUtils {
|
||||||
|
public static injectPageProperties(
|
||||||
|
data: FormData,
|
||||||
|
pageProperties: PageProperties
|
||||||
|
): void {
|
||||||
|
if (pageProperties.size) {
|
||||||
|
GotenbergUtils.assert(
|
||||||
|
pageProperties.size.width >= 1.0 && pageProperties.size.height >= 1.5,
|
||||||
|
'size is smaller than the minimum printing requirements (i.e. 1.0 x 1.5 in)'
|
||||||
|
);
|
||||||
|
|
||||||
|
data.append('paperWidth', pageProperties.size.width);
|
||||||
|
data.append('paperHeight', pageProperties.size.height);
|
||||||
|
}
|
||||||
|
if (pageProperties.margins) {
|
||||||
|
GotenbergUtils.assert(
|
||||||
|
pageProperties.margins.top >= 0 &&
|
||||||
|
pageProperties.margins.bottom >= 0 &&
|
||||||
|
pageProperties.margins.left >= 0 &&
|
||||||
|
pageProperties.margins.left >= 0,
|
||||||
|
'negative margins are not allowed'
|
||||||
|
);
|
||||||
|
data.append('marginTop', pageProperties.margins.top);
|
||||||
|
data.append('marginBottom', pageProperties.margins.bottom);
|
||||||
|
data.append('marginLeft', pageProperties.margins.left);
|
||||||
|
data.append('marginRight', pageProperties.margins.right);
|
||||||
|
}
|
||||||
|
if (pageProperties.preferCssPageSize) {
|
||||||
|
data.append(
|
||||||
|
'preferCssPageSize',
|
||||||
|
String(pageProperties.preferCssPageSize)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
if (pageProperties.printBackground) {
|
||||||
|
data.append('printBackground', String(pageProperties.printBackground));
|
||||||
|
}
|
||||||
|
if (pageProperties.landscape) {
|
||||||
|
data.append('landscape', String(pageProperties.landscape));
|
||||||
|
}
|
||||||
|
if (pageProperties.scale) {
|
||||||
|
GotenbergUtils.assert(
|
||||||
|
pageProperties.scale >= 0.1 && pageProperties.scale <= 2.0,
|
||||||
|
'scale is outside of [0.1 - 2] range'
|
||||||
|
);
|
||||||
|
data.append('scale', pageProperties.scale);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pageProperties.nativePageRanges) {
|
||||||
|
GotenbergUtils.assert(
|
||||||
|
pageProperties.nativePageRanges.from > 0 &&
|
||||||
|
pageProperties.nativePageRanges.to > 0 &&
|
||||||
|
pageProperties.nativePageRanges.to >=
|
||||||
|
pageProperties.nativePageRanges.from,
|
||||||
|
'page ranges syntax error'
|
||||||
|
);
|
||||||
|
data.append(
|
||||||
|
'nativePageRanges',
|
||||||
|
`${pageProperties.nativePageRanges.from}-${pageProperties.nativePageRanges.to}`
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
10
packages/server/src/lib/Chromiumly/Converter.ts
Normal file
10
packages/server/src/lib/Chromiumly/Converter.ts
Normal file
@@ -0,0 +1,10 @@
|
|||||||
|
import { Chromiumly } from './Chromiumly';
|
||||||
|
import { ChromiumRoute } from './_types';
|
||||||
|
|
||||||
|
export abstract class Converter {
|
||||||
|
readonly endpoint: string;
|
||||||
|
|
||||||
|
constructor(route: ChromiumRoute) {
|
||||||
|
this.endpoint = `${Chromiumly.GOTENBERG_ENDPOINT}/${Chromiumly.CHROMIUM_PATH}/${Chromiumly.CHROMIUM_ROUTES[route]}`;
|
||||||
|
}
|
||||||
|
}
|
||||||
24
packages/server/src/lib/Chromiumly/GotenbergUtils.ts
Normal file
24
packages/server/src/lib/Chromiumly/GotenbergUtils.ts
Normal file
@@ -0,0 +1,24 @@
|
|||||||
|
import FormData from 'form-data';
|
||||||
|
import Axios from 'axios';
|
||||||
|
|
||||||
|
export class GotenbergUtils {
|
||||||
|
public static assert(condition: boolean, message: string): asserts condition {
|
||||||
|
if (!condition) {
|
||||||
|
throw new Error(message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static async fetch(endpoint: string, data: FormData): Promise<Buffer> {
|
||||||
|
try {
|
||||||
|
const response = await Axios.post(endpoint, data, {
|
||||||
|
headers: {
|
||||||
|
...data.getHeaders(),
|
||||||
|
},
|
||||||
|
responseType: 'arraybuffer', // This ensures you get a Buffer bac
|
||||||
|
});
|
||||||
|
return response.data;
|
||||||
|
} catch (error) {
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
38
packages/server/src/lib/Chromiumly/HTMLConvert.ts
Normal file
38
packages/server/src/lib/Chromiumly/HTMLConvert.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import { constants, createReadStream, PathLike, promises } from 'fs';
|
||||||
|
import FormData from 'form-data';
|
||||||
|
import { GotenbergUtils } from './GotenbergUtils';
|
||||||
|
import { IConverter, PageProperties } from './_types';
|
||||||
|
import { PdfFormat, ChromiumRoute } from './_types';
|
||||||
|
import { ConverterUtils } from './ConvertUtils';
|
||||||
|
import { Converter } from './Converter';
|
||||||
|
|
||||||
|
export class HtmlConverter extends Converter implements IConverter {
|
||||||
|
constructor() {
|
||||||
|
super(ChromiumRoute.HTML);
|
||||||
|
}
|
||||||
|
|
||||||
|
async convert({
|
||||||
|
html,
|
||||||
|
properties,
|
||||||
|
pdfFormat,
|
||||||
|
}: {
|
||||||
|
html: PathLike;
|
||||||
|
properties?: PageProperties;
|
||||||
|
pdfFormat?: PdfFormat;
|
||||||
|
}): Promise<Buffer> {
|
||||||
|
try {
|
||||||
|
await promises.access(html, constants.R_OK);
|
||||||
|
const data = new FormData();
|
||||||
|
if (pdfFormat) {
|
||||||
|
data.append('pdfFormat', pdfFormat);
|
||||||
|
}
|
||||||
|
data.append('index.html', createReadStream(html));
|
||||||
|
if (properties) {
|
||||||
|
ConverterUtils.injectPageProperties(data, properties);
|
||||||
|
}
|
||||||
|
return GotenbergUtils.fetch(this.endpoint, data);
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
38
packages/server/src/lib/Chromiumly/UrlConvert.ts
Normal file
38
packages/server/src/lib/Chromiumly/UrlConvert.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
import FormData from 'form-data';
|
||||||
|
import { IConverter, PageProperties, PdfFormat, ChromiumRoute } from './_types';
|
||||||
|
import { ConverterUtils } from './ConvertUtils';
|
||||||
|
import { Converter } from './Converter';
|
||||||
|
import { GotenbergUtils } from './GotenbergUtils';
|
||||||
|
|
||||||
|
export class UrlConverter extends Converter implements IConverter {
|
||||||
|
constructor() {
|
||||||
|
super(ChromiumRoute.URL);
|
||||||
|
}
|
||||||
|
|
||||||
|
async convert({
|
||||||
|
url,
|
||||||
|
properties,
|
||||||
|
pdfFormat,
|
||||||
|
}: {
|
||||||
|
url: string;
|
||||||
|
properties?: PageProperties;
|
||||||
|
pdfFormat?: PdfFormat;
|
||||||
|
}): Promise<Buffer> {
|
||||||
|
try {
|
||||||
|
const _url = new URL(url);
|
||||||
|
const data = new FormData();
|
||||||
|
|
||||||
|
if (pdfFormat) {
|
||||||
|
data.append('pdfFormat', pdfFormat);
|
||||||
|
}
|
||||||
|
data.append('url', _url.href);
|
||||||
|
|
||||||
|
if (properties) {
|
||||||
|
ConverterUtils.injectPageProperties(data, properties);
|
||||||
|
}
|
||||||
|
return GotenbergUtils.fetch(this.endpoint, data);
|
||||||
|
} catch (error) {
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
51
packages/server/src/lib/Chromiumly/_types.ts
Normal file
51
packages/server/src/lib/Chromiumly/_types.ts
Normal file
@@ -0,0 +1,51 @@
|
|||||||
|
import { PathLike } from 'fs';
|
||||||
|
|
||||||
|
export type PageSize = {
|
||||||
|
width: number; // Paper width, in inches (default 8.5)
|
||||||
|
height: number; //Paper height, in inches (default 11)
|
||||||
|
};
|
||||||
|
|
||||||
|
export type PageMargins = {
|
||||||
|
top: number; // Top margin, in inches (default 0.39)
|
||||||
|
bottom: number; // Bottom margin, in inches (default 0.39)
|
||||||
|
left: number; // Left margin, in inches (default 0.39)
|
||||||
|
right: number; // Right margin, in inches (default 0.39)
|
||||||
|
};
|
||||||
|
|
||||||
|
export type PageProperties = {
|
||||||
|
size?: PageSize;
|
||||||
|
margins?: PageMargins;
|
||||||
|
preferCssPageSize?: boolean; // Define whether to prefer page size as defined by CSS (default false)
|
||||||
|
printBackground?: boolean; // Print the background graphics (default false)
|
||||||
|
landscape?: boolean; // Set the paper orientation to landscape (default false)
|
||||||
|
scale?: number; // The scale of the page rendering (default 1.0)
|
||||||
|
nativePageRanges?: { from: number; to: number }; // Page ranges to print
|
||||||
|
};
|
||||||
|
|
||||||
|
export interface IConverter {
|
||||||
|
convert({
|
||||||
|
...args
|
||||||
|
}: {
|
||||||
|
[x: string]: string | PathLike | PageProperties | PdfFormat;
|
||||||
|
}): Promise<Buffer>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum PdfFormat {
|
||||||
|
A_1a = 'PDF/A-1a',
|
||||||
|
A_2b = 'PDF/A-2b',
|
||||||
|
A_3b = 'PDF/A-3b',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum ChromiumRoute {
|
||||||
|
URL = 'url',
|
||||||
|
HTML = 'html',
|
||||||
|
MARKDOWN = 'markdown',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum PdfEngineRoute {
|
||||||
|
MERGE = 'merge',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum LibreOfficeRoute {
|
||||||
|
CONVERT = 'convert',
|
||||||
|
}
|
||||||
45
packages/server/src/lib/ExchangeRate/ExchangeRate.ts
Normal file
45
packages/server/src/lib/ExchangeRate/ExchangeRate.ts
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
import { OpenExchangeRate } from './OpenExchangeRate';
|
||||||
|
import { ExchangeRateServiceType, IExchangeRateService } from './types';
|
||||||
|
|
||||||
|
export class ExchangeRate {
|
||||||
|
private exchangeRateService: IExchangeRateService;
|
||||||
|
private exchangeRateServiceType: ExchangeRateServiceType;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor method.
|
||||||
|
* @param {ExchangeRateServiceType} service
|
||||||
|
*/
|
||||||
|
constructor(service: ExchangeRateServiceType) {
|
||||||
|
this.exchangeRateServiceType = service;
|
||||||
|
this.initService();
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Initialize the exchange rate service based on the service type.
|
||||||
|
*/
|
||||||
|
private initService() {
|
||||||
|
if (
|
||||||
|
this.exchangeRateServiceType === ExchangeRateServiceType.OpenExchangeRate
|
||||||
|
) {
|
||||||
|
this.setExchangeRateService(new OpenExchangeRate());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets the exchange rate service.
|
||||||
|
* @param {IExchangeRateService} service
|
||||||
|
*/
|
||||||
|
private setExchangeRateService(service: IExchangeRateService) {
|
||||||
|
this.exchangeRateService = service;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the latest exchange rate.
|
||||||
|
* @param {string} baseCurrency
|
||||||
|
* @param {string} toCurrency
|
||||||
|
* @returns {number}
|
||||||
|
*/
|
||||||
|
public latest(baseCurrency: string, toCurrency: string): Promise<number> {
|
||||||
|
return this.exchangeRateService.latest(baseCurrency, toCurrency);
|
||||||
|
}
|
||||||
|
}
|
||||||
81
packages/server/src/lib/ExchangeRate/OpenExchangeRate.ts
Normal file
81
packages/server/src/lib/ExchangeRate/OpenExchangeRate.ts
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
import Axios, { AxiosError } from 'axios';
|
||||||
|
import {
|
||||||
|
EchangeRateErrors,
|
||||||
|
IExchangeRateService,
|
||||||
|
OPEN_EXCHANGE_RATE_LATEST_URL,
|
||||||
|
} from './types';
|
||||||
|
import config from '@/config';
|
||||||
|
import { ServiceError } from '@/exceptions';
|
||||||
|
|
||||||
|
export class OpenExchangeRate implements IExchangeRateService {
|
||||||
|
/**
|
||||||
|
* Gets the latest exchange rate.
|
||||||
|
* @param {string} baseCurrency
|
||||||
|
* @param {string} toCurrency
|
||||||
|
* @returns {Promise<number}
|
||||||
|
*/
|
||||||
|
public async latest(
|
||||||
|
baseCurrency: string,
|
||||||
|
toCurrency: string
|
||||||
|
): Promise<number> {
|
||||||
|
// Vaclidates the Open Exchange Rate api id early.
|
||||||
|
this.validateApiIdExistance();
|
||||||
|
|
||||||
|
try {
|
||||||
|
const result = await Axios.get(OPEN_EXCHANGE_RATE_LATEST_URL, {
|
||||||
|
params: {
|
||||||
|
app_id: config.exchangeRate.openExchangeRate.appId,
|
||||||
|
base: baseCurrency,
|
||||||
|
symbols: toCurrency,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
return result.data.rates[toCurrency] || (1 as number);
|
||||||
|
} catch (error) {
|
||||||
|
this.handleLatestErrors(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Validates the Open Exchange Rate api id.
|
||||||
|
* @throws {ServiceError}
|
||||||
|
*/
|
||||||
|
private validateApiIdExistance() {
|
||||||
|
const apiId = config.exchangeRate.openExchangeRate.appId;
|
||||||
|
|
||||||
|
if (!apiId) {
|
||||||
|
throw new ServiceError(
|
||||||
|
EchangeRateErrors.EX_RATE_SERVICE_API_KEY_REQUIRED,
|
||||||
|
'Invalid App ID provided. Please sign up at https://openexchangerates.org/signup, or contact support@openexchangerates.org.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Handles the latest errors.
|
||||||
|
* @param {any} error
|
||||||
|
* @throws {ServiceError}
|
||||||
|
*/
|
||||||
|
private handleLatestErrors(error: any) {
|
||||||
|
if (error.response.data?.message === 'missing_app_id') {
|
||||||
|
throw new ServiceError(
|
||||||
|
EchangeRateErrors.EX_RATE_SERVICE_API_KEY_REQUIRED,
|
||||||
|
'Invalid App ID provided. Please sign up at https://openexchangerates.org/signup, or contact support@openexchangerates.org.'
|
||||||
|
);
|
||||||
|
} else if (error.response.data?.message === 'invalid_app_id') {
|
||||||
|
throw new ServiceError(
|
||||||
|
EchangeRateErrors.EX_RATE_SERVICE_API_KEY_REQUIRED,
|
||||||
|
'Invalid App ID provided. Please sign up at https://openexchangerates.org/signup, or contact support@openexchangerates.org.'
|
||||||
|
);
|
||||||
|
} else if (error.response.data?.message === 'not_allowed') {
|
||||||
|
throw new ServiceError(
|
||||||
|
EchangeRateErrors.EX_RATE_SERVICE_NOT_ALLOWED,
|
||||||
|
'Getting the exchange rate from the given base currency to the given currency is not allowed.'
|
||||||
|
);
|
||||||
|
} else if (error.response.data?.message === 'invalid_base') {
|
||||||
|
throw new ServiceError(
|
||||||
|
EchangeRateErrors.EX_RATE_INVALID_BASE_CURRENCY,
|
||||||
|
'The given base currency is invalid.'
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
17
packages/server/src/lib/ExchangeRate/types.ts
Normal file
17
packages/server/src/lib/ExchangeRate/types.ts
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
export interface IExchangeRateService {
|
||||||
|
latest(baseCurrency: string, toCurrency: string): Promise<number>;
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum ExchangeRateServiceType {
|
||||||
|
OpenExchangeRate = 'OpenExchangeRate',
|
||||||
|
}
|
||||||
|
|
||||||
|
export enum EchangeRateErrors {
|
||||||
|
EX_RATE_SERVICE_NOT_ALLOWED = 'EX_RATE_SERVICE_NOT_ALLOWED',
|
||||||
|
EX_RATE_LIMIT_EXCEEDED = 'EX_RATE_LIMIT_EXCEEDED',
|
||||||
|
EX_RATE_SERVICE_API_KEY_REQUIRED = 'EX_RATE_SERVICE_API_KEY_REQUIRED',
|
||||||
|
EX_RATE_INVALID_BASE_CURRENCY = 'EX_RATE_INVALID_BASE_CURRENCY',
|
||||||
|
}
|
||||||
|
|
||||||
|
export const OPEN_EXCHANGE_RATE_LATEST_URL =
|
||||||
|
'https://openexchangerates.org/api/latest.json';
|
||||||
@@ -2,18 +2,13 @@ import fs from 'fs';
|
|||||||
import Mustache from 'mustache';
|
import Mustache from 'mustache';
|
||||||
import { Container } from 'typedi';
|
import { Container } from 'typedi';
|
||||||
import path from 'path';
|
import path from 'path';
|
||||||
import { IMailable } from '@/interfaces';
|
import { IMailAttachment } from '@/interfaces';
|
||||||
|
|
||||||
interface IMailAttachment {
|
|
||||||
filename: string;
|
|
||||||
path: string;
|
|
||||||
cid: string;
|
|
||||||
}
|
|
||||||
|
|
||||||
export default class Mail {
|
export default class Mail {
|
||||||
view: string;
|
view: string;
|
||||||
subject: string;
|
subject: string = '';
|
||||||
to: string;
|
content: string = '';
|
||||||
|
to: string | string[];
|
||||||
from: string = `${process.env.MAIL_FROM_NAME} ${process.env.MAIL_FROM_ADDRESS}`;
|
from: string = `${process.env.MAIL_FROM_NAME} ${process.env.MAIL_FROM_ADDRESS}`;
|
||||||
data: { [key: string]: string | number };
|
data: { [key: string]: string | number };
|
||||||
attachments: IMailAttachment[];
|
attachments: IMailAttachment[];
|
||||||
@@ -21,16 +16,24 @@ export default class Mail {
|
|||||||
/**
|
/**
|
||||||
* Mail options.
|
* Mail options.
|
||||||
*/
|
*/
|
||||||
private get mailOptions() {
|
public get mailOptions() {
|
||||||
return {
|
return {
|
||||||
to: this.to,
|
to: this.to,
|
||||||
from: this.from,
|
from: this.from,
|
||||||
subject: this.subject,
|
subject: this.subject,
|
||||||
html: this.render(this.data),
|
html: this.html,
|
||||||
attachments: this.attachments,
|
attachments: this.attachments,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the html content of the mail.
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
public get html() {
|
||||||
|
return this.view ? Mail.render(this.view, this.data) : this.content;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the given mail to the target address.
|
* Sends the given mail to the target address.
|
||||||
*/
|
*/
|
||||||
@@ -52,7 +55,7 @@ export default class Mail {
|
|||||||
* Set send mail to address.
|
* Set send mail to address.
|
||||||
* @param {string} to -
|
* @param {string} to -
|
||||||
*/
|
*/
|
||||||
setTo(to: string) {
|
setTo(to: string | string[]) {
|
||||||
this.to = to;
|
this.to = to;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
@@ -62,11 +65,16 @@ export default class Mail {
|
|||||||
* @param {string} from
|
* @param {string} from
|
||||||
* @return {}
|
* @return {}
|
||||||
*/
|
*/
|
||||||
private setFrom(from: string) {
|
setFrom(from: string) {
|
||||||
this.from = from;
|
this.from = from;
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set attachments to the mail.
|
||||||
|
* @param {IMailAttachment[]} attachments
|
||||||
|
* @returns {Mail}
|
||||||
|
*/
|
||||||
setAttachments(attachments: IMailAttachment[]) {
|
setAttachments(attachments: IMailAttachment[]) {
|
||||||
this.attachments = attachments;
|
this.attachments = attachments;
|
||||||
return this;
|
return this;
|
||||||
@@ -95,21 +103,26 @@ export default class Mail {
|
|||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
setContent(content: string) {
|
||||||
|
this.content = content;
|
||||||
|
return this;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Renders the view template with the given data.
|
* Renders the view template with the given data.
|
||||||
* @param {object} data
|
* @param {object} data
|
||||||
* @return {string}
|
* @return {string}
|
||||||
*/
|
*/
|
||||||
render(data): string {
|
static render(view: string, data: Record<string, any>): string {
|
||||||
const viewContent = this.getViewContent();
|
const viewContent = Mail.getViewContent(view);
|
||||||
return Mustache.render(viewContent, data);
|
return Mustache.render(viewContent, data);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve view content from the view directory.
|
* Retrieve view content from the view directory.
|
||||||
*/
|
*/
|
||||||
private getViewContent(): string {
|
static getViewContent(view: string): string {
|
||||||
const filePath = path.join(global.__views_dir, `/${this.view}`);
|
const filePath = path.join(global.__views_dir, `/${view}`);
|
||||||
return fs.readFileSync(filePath, 'utf8');
|
return fs.readFileSync(filePath, 'utf8');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,4 +1,5 @@
|
|||||||
import { json, Request, Response, NextFunction } from 'express';
|
import { json, Request, Response, NextFunction } from 'express';
|
||||||
|
import express from 'express';
|
||||||
import helmet from 'helmet';
|
import helmet from 'helmet';
|
||||||
import boom from 'express-boom';
|
import boom from 'express-boom';
|
||||||
import errorHandler from 'errorhandler';
|
import errorHandler from 'errorhandler';
|
||||||
@@ -42,6 +43,8 @@ export default ({ app }) => {
|
|||||||
// Middleware for intercepting and transforming json responses.
|
// Middleware for intercepting and transforming json responses.
|
||||||
app.use(JSONResponseTransformer(snakecaseResponseTransformer));
|
app.use(JSONResponseTransformer(snakecaseResponseTransformer));
|
||||||
|
|
||||||
|
app.use('/public', express.static(path.join(global.__storage_dir)));
|
||||||
|
|
||||||
// Handle multi-media requests.
|
// Handle multi-media requests.
|
||||||
app.use(
|
app.use(
|
||||||
fileUpload({
|
fileUpload({
|
||||||
|
|||||||
@@ -5,6 +5,11 @@ import RewriteInvoicesJournalEntries from 'jobs/WriteInvoicesJEntries';
|
|||||||
import UserInviteMailJob from 'jobs/UserInviteMail';
|
import UserInviteMailJob from 'jobs/UserInviteMail';
|
||||||
import OrganizationSetupJob from 'jobs/OrganizationSetup';
|
import OrganizationSetupJob from 'jobs/OrganizationSetup';
|
||||||
import OrganizationUpgrade from 'jobs/OrganizationUpgrade';
|
import OrganizationUpgrade from 'jobs/OrganizationUpgrade';
|
||||||
|
import { SendSaleInvoiceMailJob } from '@/services/Sales/Invoices/SendSaleInvoiceMailJob';
|
||||||
|
import { SendSaleInvoiceReminderMailJob } from '@/services/Sales/Invoices/SendSaleInvoiceMailReminderJob';
|
||||||
|
import { SendSaleEstimateMailJob } from '@/services/Sales/Estimates/SendSaleEstimateMailJob';
|
||||||
|
import { SaleReceiptMailNotificationJob } from '@/services/Sales/Receipts/SaleReceiptMailNotificationJob';
|
||||||
|
import { PaymentReceiveMailNotificationJob } from '@/services/Sales/PaymentReceives/PaymentReceiveMailNotificationJob';
|
||||||
|
|
||||||
export default ({ agenda }: { agenda: Agenda }) => {
|
export default ({ agenda }: { agenda: Agenda }) => {
|
||||||
new ResetPasswordMailJob(agenda);
|
new ResetPasswordMailJob(agenda);
|
||||||
@@ -13,6 +18,11 @@ export default ({ agenda }: { agenda: Agenda }) => {
|
|||||||
new RewriteInvoicesJournalEntries(agenda);
|
new RewriteInvoicesJournalEntries(agenda);
|
||||||
new OrganizationSetupJob(agenda);
|
new OrganizationSetupJob(agenda);
|
||||||
new OrganizationUpgrade(agenda);
|
new OrganizationUpgrade(agenda);
|
||||||
|
new SendSaleInvoiceMailJob(agenda);
|
||||||
|
new SendSaleInvoiceReminderMailJob(agenda);
|
||||||
|
new SendSaleEstimateMailJob(agenda);
|
||||||
|
new SaleReceiptMailNotificationJob(agenda);
|
||||||
|
new PaymentReceiveMailNotificationJob(agenda);
|
||||||
|
|
||||||
agenda.start();
|
agenda.start();
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -60,6 +60,7 @@ import Time from 'models/Time';
|
|||||||
import Task from 'models/Task';
|
import Task from 'models/Task';
|
||||||
import TaxRate from 'models/TaxRate';
|
import TaxRate from 'models/TaxRate';
|
||||||
import TaxRateTransaction from 'models/TaxRateTransaction';
|
import TaxRateTransaction from 'models/TaxRateTransaction';
|
||||||
|
import Attachment from 'models/Attachment';
|
||||||
|
|
||||||
export default (knex) => {
|
export default (knex) => {
|
||||||
const models = {
|
const models = {
|
||||||
@@ -123,6 +124,7 @@ export default (knex) => {
|
|||||||
Task,
|
Task,
|
||||||
TaxRate,
|
TaxRate,
|
||||||
TaxRateTransaction,
|
TaxRateTransaction,
|
||||||
|
Attachment
|
||||||
};
|
};
|
||||||
return mapValues(models, (model) => model.bindKnex(knex));
|
return mapValues(models, (model) => model.bindKnex(knex));
|
||||||
};
|
};
|
||||||
|
|||||||
23
packages/server/src/models/Attachment.ts
Normal file
23
packages/server/src/models/Attachment.ts
Normal file
@@ -0,0 +1,23 @@
|
|||||||
|
import { mixin } from 'objection';
|
||||||
|
import TenantModel from 'models/TenantModel';
|
||||||
|
import ModelSetting from './ModelSetting';
|
||||||
|
import ModelSearchable from './ModelSearchable';
|
||||||
|
|
||||||
|
export default class Attachment extends mixin(TenantModel, [
|
||||||
|
ModelSetting,
|
||||||
|
ModelSearchable,
|
||||||
|
]) {
|
||||||
|
/**
|
||||||
|
* Table name
|
||||||
|
*/
|
||||||
|
static get tableName() {
|
||||||
|
return 'storage';
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Model timestamps.
|
||||||
|
*/
|
||||||
|
get timestamps() {
|
||||||
|
return ['createdAt', 'updatedAt'];
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -7,8 +7,12 @@ import {
|
|||||||
} from '@/services/Cashflow/utils';
|
} from '@/services/Cashflow/utils';
|
||||||
import AccountTransaction from './AccountTransaction';
|
import AccountTransaction from './AccountTransaction';
|
||||||
import { CASHFLOW_DIRECTION } from '@/services/Cashflow/constants';
|
import { CASHFLOW_DIRECTION } from '@/services/Cashflow/constants';
|
||||||
|
import { getTransactionTypeLabel } from '@/utils/transactions-types';
|
||||||
export default class CashflowTransaction extends TenantModel {
|
export default class CashflowTransaction extends TenantModel {
|
||||||
|
transactionType: string;
|
||||||
|
amount: number;
|
||||||
|
exchangeRate: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table name.
|
* Table name.
|
||||||
*/
|
*/
|
||||||
@@ -55,9 +59,10 @@ export default class CashflowTransaction extends TenantModel {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Transaction type formatted.
|
* Transaction type formatted.
|
||||||
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
get transactionTypeFormatted() {
|
get transactionTypeFormatted() {
|
||||||
return AccountTransaction.getReferenceTypeFormatted(this.transactionType);
|
return getTransactionTypeLabel(this.transactionType);
|
||||||
}
|
}
|
||||||
|
|
||||||
get typeMeta() {
|
get typeMeta() {
|
||||||
|
|||||||
@@ -2,6 +2,9 @@ import { Model } from 'objection';
|
|||||||
import TenantModel from 'models/TenantModel';
|
import TenantModel from 'models/TenantModel';
|
||||||
|
|
||||||
export default class Contact extends TenantModel {
|
export default class Contact extends TenantModel {
|
||||||
|
email: string;
|
||||||
|
displayName: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table name
|
* Table name
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -24,6 +24,9 @@ export default class Customer extends mixin(TenantModel, [
|
|||||||
CustomViewBaseModel,
|
CustomViewBaseModel,
|
||||||
ModelSearchable,
|
ModelSearchable,
|
||||||
]) {
|
]) {
|
||||||
|
email: string;
|
||||||
|
displayName: string;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Query builder.
|
* Query builder.
|
||||||
*/
|
*/
|
||||||
@@ -76,6 +79,19 @@ export default class Customer extends mixin(TenantModel, [
|
|||||||
return 'debit';
|
return 'debit';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
get contactAddresses() {
|
||||||
|
return [
|
||||||
|
{
|
||||||
|
mail: this.email,
|
||||||
|
label: this.displayName,
|
||||||
|
primary: true
|
||||||
|
},
|
||||||
|
].filter((c) => c.mail);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Model modifiers.
|
* Model modifiers.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -2,6 +2,8 @@ import { Model } from 'objection';
|
|||||||
import TenantModel from 'models/TenantModel';
|
import TenantModel from 'models/TenantModel';
|
||||||
|
|
||||||
export default class ExpenseCategory extends TenantModel {
|
export default class ExpenseCategory extends TenantModel {
|
||||||
|
amount: number;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Table name
|
* Table name
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -3,8 +3,10 @@ import {
|
|||||||
IAccount,
|
IAccount,
|
||||||
IAccountCreateDTO,
|
IAccountCreateDTO,
|
||||||
IAccountEditDTO,
|
IAccountEditDTO,
|
||||||
|
IAccountResponse,
|
||||||
IAccountsFilter,
|
IAccountsFilter,
|
||||||
IAccountsTransactionsFilter,
|
IAccountsTransactionsFilter,
|
||||||
|
IFilterMeta,
|
||||||
IGetAccountTransactionPOJO,
|
IGetAccountTransactionPOJO,
|
||||||
} from '@/interfaces';
|
} from '@/interfaces';
|
||||||
import { CreateAccount } from './CreateAccount';
|
import { CreateAccount } from './CreateAccount';
|
||||||
@@ -14,6 +16,7 @@ import { ActivateAccount } from './ActivateAccount';
|
|||||||
import { GetAccounts } from './GetAccounts';
|
import { GetAccounts } from './GetAccounts';
|
||||||
import { GetAccount } from './GetAccount';
|
import { GetAccount } from './GetAccount';
|
||||||
import { GetAccountTransactions } from './GetAccountTransactions';
|
import { GetAccountTransactions } from './GetAccountTransactions';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export class AccountsApplication {
|
export class AccountsApplication {
|
||||||
@Inject()
|
@Inject()
|
||||||
@@ -113,19 +116,22 @@ export class AccountsApplication {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the accounts list.
|
* Retrieves the accounts list.
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
* @param {IAccountsFilter} filterDTO
|
* @param {IAccountsFilter} filterDTO
|
||||||
* @returns
|
* @returns {Promise<{ accounts: IAccountResponse[]; filterMeta: IFilterMeta }>}
|
||||||
*/
|
*/
|
||||||
public getAccounts = (tenantId: number, filterDTO: IAccountsFilter) => {
|
public getAccounts = (
|
||||||
|
tenantId: number,
|
||||||
|
filterDTO: IAccountsFilter
|
||||||
|
): Promise<{ accounts: IAccountResponse[]; filterMeta: IFilterMeta }> => {
|
||||||
return this.getAccountsService.getAccountsList(tenantId, filterDTO);
|
return this.getAccountsService.getAccountsList(tenantId, filterDTO);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the given account transactions.
|
* Retrieves the given account transactions.
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
* @param {IAccountsTransactionsFilter} filter
|
* @param {IAccountsTransactionsFilter} filter
|
||||||
* @returns {Promise<IGetAccountTransactionPOJO[]>}
|
* @returns {Promise<IGetAccountTransactionPOJO[]>}
|
||||||
*/
|
*/
|
||||||
public getAccountsTransactions = (
|
public getAccountsTransactions = (
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
|
|||||||
@@ -0,0 +1,75 @@
|
|||||||
|
import { Inject, Service } from 'typedi';
|
||||||
|
import path from 'path';
|
||||||
|
import { promises as fs } from 'fs';
|
||||||
|
import { PageProperties, PdfFormat } from '@/lib/Chromiumly/_types';
|
||||||
|
import { UrlConverter } from '@/lib/Chromiumly/UrlConvert';
|
||||||
|
import HasTenancyService from '../Tenancy/TenancyService';
|
||||||
|
import { Chromiumly } from '@/lib/Chromiumly/Chromiumly';
|
||||||
|
import { PDF_FILE_EXPIRE_IN, getPdfFilesStorageDir } from './utils';
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export class ChromiumlyHtmlConvert {
|
||||||
|
@Inject()
|
||||||
|
private tenancy: HasTenancyService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Write HTML content to temporary file.
|
||||||
|
* @param {number} tenantId - Tenant id.
|
||||||
|
* @param {string} content - HTML content.
|
||||||
|
* @returns {Promise<[string, () => Promise<void>]>}
|
||||||
|
*/
|
||||||
|
async writeTempHtmlFile(
|
||||||
|
tenantId: number,
|
||||||
|
content: string
|
||||||
|
): Promise<[string, () => Promise<void>]> {
|
||||||
|
const { Attachment } = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
|
const filename = `document-${Date.now()}.html`;
|
||||||
|
const storageDir = getPdfFilesStorageDir(filename);
|
||||||
|
const filePath = path.join(global.__storage_dir, storageDir);
|
||||||
|
|
||||||
|
await fs.writeFile(filePath, content);
|
||||||
|
await Attachment.query().insert({
|
||||||
|
key: filename,
|
||||||
|
path: storageDir,
|
||||||
|
expire_in: PDF_FILE_EXPIRE_IN, // ms
|
||||||
|
extension: 'html',
|
||||||
|
});
|
||||||
|
const cleanup = async () => {
|
||||||
|
await fs.unlink(filePath);
|
||||||
|
await Attachment.query().where('key', filename).delete();
|
||||||
|
};
|
||||||
|
return [filename, cleanup];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the given HTML content to PDF.
|
||||||
|
* @param {string} html
|
||||||
|
* @param {PageProperties} properties
|
||||||
|
* @param {PdfFormat} pdfFormat
|
||||||
|
* @returns {Array<Buffer>}
|
||||||
|
*/
|
||||||
|
async convert(
|
||||||
|
tenantId: number,
|
||||||
|
html: string,
|
||||||
|
properties?: PageProperties,
|
||||||
|
pdfFormat?: PdfFormat
|
||||||
|
): Promise<Buffer> {
|
||||||
|
const [filename, cleanupTempFile] = await this.writeTempHtmlFile(
|
||||||
|
tenantId,
|
||||||
|
html
|
||||||
|
);
|
||||||
|
const fileDir = getPdfFilesStorageDir(filename);
|
||||||
|
const url = path.join(Chromiumly.GOTENBERG_DOCS_ENDPOINT, fileDir);
|
||||||
|
const urlConverter = new UrlConverter();
|
||||||
|
|
||||||
|
const buffer = await urlConverter.convert({
|
||||||
|
url,
|
||||||
|
properties,
|
||||||
|
pdfFormat,
|
||||||
|
});
|
||||||
|
await cleanupTempFile();
|
||||||
|
|
||||||
|
return buffer;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { Inject, Service } from 'typedi';
|
||||||
|
import { PageProperties, PdfFormat } from '@/lib/Chromiumly/_types';
|
||||||
|
import { ChromiumlyHtmlConvert } from './ChromiumlyHtmlConvert';
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export class ChromiumlyTenancy {
|
||||||
|
@Inject()
|
||||||
|
private htmlConvert: ChromiumlyHtmlConvert;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts the given HTML content to PDF.
|
||||||
|
* @param {string} content
|
||||||
|
* @param {PageProperties} properties
|
||||||
|
* @param {PdfFormat} pdfFormat
|
||||||
|
* @returns {Promise<Buffer>}
|
||||||
|
*/
|
||||||
|
public convertHtmlContent(
|
||||||
|
tenantId: number,
|
||||||
|
content: string,
|
||||||
|
properties?: PageProperties,
|
||||||
|
pdfFormat?: PdfFormat
|
||||||
|
) {
|
||||||
|
return this.htmlConvert.convert(tenantId, content, properties, pdfFormat);
|
||||||
|
}
|
||||||
|
}
|
||||||
8
packages/server/src/services/ChromiumlyTenancy/utils.ts
Normal file
8
packages/server/src/services/ChromiumlyTenancy/utils.ts
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
import path from 'path';
|
||||||
|
|
||||||
|
export const PDF_FILE_SUB_DIR = '/pdf';
|
||||||
|
export const PDF_FILE_EXPIRE_IN = 40; // ms
|
||||||
|
|
||||||
|
export const getPdfFilesStorageDir = (filename: string) => {
|
||||||
|
return path.join(PDF_FILE_SUB_DIR, filename);
|
||||||
|
}
|
||||||
@@ -80,7 +80,7 @@ export default class EditCreditNote extends BaseCreditNotes {
|
|||||||
} as ICreditNoteEditingPayload);
|
} as ICreditNoteEditingPayload);
|
||||||
|
|
||||||
// Saves the credit note graph to the storage.
|
// Saves the credit note graph to the storage.
|
||||||
const creditNote = await CreditNote.query(trx).upsertGraph({
|
const creditNote = await CreditNote.query(trx).upsertGraphAndFetch({
|
||||||
id: creditNoteId,
|
id: creditNoteId,
|
||||||
...creditNoteModel,
|
...creditNoteModel,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,37 +1,38 @@
|
|||||||
import { Inject, Service } from 'typedi';
|
import { Inject, Service } from 'typedi';
|
||||||
import PdfService from '@/services/PDF/PdfService';
|
import { ChromiumlyTenancy } from '../ChromiumlyTenancy/ChromiumlyTenancy';
|
||||||
import { templateRender } from 'utils';
|
import { TemplateInjectable } from '../TemplateInjectable/TemplateInjectable';
|
||||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import GetCreditNote from './GetCreditNote';
|
||||||
import { Tenant } from '@/system/models';
|
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class GetCreditNotePdf {
|
export default class GetCreditNotePdf {
|
||||||
@Inject()
|
@Inject()
|
||||||
pdfService: PdfService;
|
private chromiumlyTenancy: ChromiumlyTenancy;
|
||||||
|
|
||||||
@Inject()
|
@Inject()
|
||||||
tenancy: HasTenancyService;
|
private templateInjectable: TemplateInjectable;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private getCreditNoteService: GetCreditNote;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve sale invoice pdf content.
|
* Retrieve sale invoice pdf content.
|
||||||
* @param {} saleInvoice -
|
* @param {number} tenantId - Tenant id.
|
||||||
|
* @param {number} creditNoteId - Credit note id.
|
||||||
*/
|
*/
|
||||||
async getCreditNotePdf(tenantId: number, creditNote) {
|
public async getCreditNotePdf(tenantId: number, creditNoteId: number) {
|
||||||
const i18n = this.tenancy.i18n(tenantId);
|
const creditNote = await this.getCreditNoteService.getCreditNote(
|
||||||
|
tenantId,
|
||||||
const organization = await Tenant.query()
|
creditNoteId
|
||||||
.findById(tenantId)
|
);
|
||||||
.withGraphFetched('metadata');
|
const htmlContent = await this.templateInjectable.render(
|
||||||
|
tenantId,
|
||||||
const htmlContent = templateRender('modules/credit-note-standard', {
|
'modules/credit-note-standard',
|
||||||
organization,
|
{
|
||||||
organizationName: organization.metadata.name,
|
creditNote,
|
||||||
organizationEmail: organization.metadata.email,
|
}
|
||||||
creditNote,
|
);
|
||||||
...i18n,
|
return this.chromiumlyTenancy.convertHtmlContent(tenantId, htmlContent, {
|
||||||
|
margins: { top: 0, bottom: 0, left: 0, right: 0 },
|
||||||
});
|
});
|
||||||
const pdfContent = await this.pdfService.pdfDocument(htmlContent);
|
|
||||||
|
|
||||||
return pdfContent;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,21 @@
|
|||||||
|
import { Inject } from 'typedi';
|
||||||
|
import { ExchangeRatesService } from './ExchangeRatesService';
|
||||||
|
import { EchangeRateLatestPOJO, ExchangeRateLatestDTO } from '@/interfaces';
|
||||||
|
|
||||||
|
export class ExchangeRateApplication {
|
||||||
|
@Inject()
|
||||||
|
private exchangeRateService: ExchangeRatesService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets the latest exchange rate.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {ExchangeRateLatestDTO} exchangeRateLatestDTO
|
||||||
|
* @returns {Promise<EchangeRateLatestPOJO>}
|
||||||
|
*/
|
||||||
|
public latest(
|
||||||
|
tenantId: number,
|
||||||
|
exchangeRateLatestDTO: ExchangeRateLatestDTO
|
||||||
|
): Promise<EchangeRateLatestPOJO> {
|
||||||
|
return this.exchangeRateService.latest(tenantId, exchangeRateLatestDTO);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,193 +1,37 @@
|
|||||||
import moment from 'moment';
|
import { Service } from 'typedi';
|
||||||
import { difference } from 'lodash';
|
import { ExchangeRate } from '@/lib/ExchangeRate/ExchangeRate';
|
||||||
import { Service, Inject } from 'typedi';
|
import { ExchangeRateServiceType } from '@/lib/ExchangeRate/types';
|
||||||
import { ServiceError } from '@/exceptions';
|
import { EchangeRateLatestPOJO, ExchangeRateLatestDTO } from '@/interfaces';
|
||||||
import DynamicListingService from '@/services/DynamicListing/DynamicListService';
|
import { TenantMetadata } from '@/system/models';
|
||||||
import {
|
|
||||||
EventDispatcher,
|
|
||||||
EventDispatcherInterface,
|
|
||||||
} from 'decorators/eventDispatcher';
|
|
||||||
import {
|
|
||||||
IExchangeRateDTO,
|
|
||||||
IExchangeRate,
|
|
||||||
IExchangeRatesService,
|
|
||||||
IExchangeRateEditDTO,
|
|
||||||
IExchangeRateFilter,
|
|
||||||
} from '@/interfaces';
|
|
||||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
|
||||||
|
|
||||||
const ERRORS = {
|
|
||||||
NOT_FOUND_EXCHANGE_RATES: 'NOT_FOUND_EXCHANGE_RATES',
|
|
||||||
EXCHANGE_RATE_PERIOD_EXISTS: 'EXCHANGE_RATE_PERIOD_EXISTS',
|
|
||||||
EXCHANGE_RATE_NOT_FOUND: 'EXCHANGE_RATE_NOT_FOUND',
|
|
||||||
};
|
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class ExchangeRatesService implements IExchangeRatesService {
|
export class ExchangeRatesService {
|
||||||
@Inject('logger')
|
|
||||||
logger: any;
|
|
||||||
|
|
||||||
@EventDispatcher()
|
|
||||||
eventDispatcher: EventDispatcherInterface;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
tenancy: TenancyService;
|
|
||||||
|
|
||||||
@Inject()
|
|
||||||
dynamicListService: DynamicListingService;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new exchange rate.
|
* Gets the latest exchange rate.
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
* @param {IExchangeRateDTO} exchangeRateDTO
|
* @param {number} exchangeRateLatestDTO
|
||||||
* @returns {Promise<IExchangeRate>}
|
* @returns {EchangeRateLatestPOJO}
|
||||||
*/
|
*/
|
||||||
public async newExchangeRate(
|
public async latest(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
exchangeRateDTO: IExchangeRateDTO
|
exchangeRateLatestDTO: ExchangeRateLatestDTO
|
||||||
): Promise<IExchangeRate> {
|
): Promise<EchangeRateLatestPOJO> {
|
||||||
const { ExchangeRate } = this.tenancy.models(tenantId);
|
const organization = await TenantMetadata.query().findOne({ tenantId });
|
||||||
|
|
||||||
this.logger.info('[exchange_rates] trying to insert new exchange rate.', {
|
// Assign the organization base currency as a default currency
|
||||||
tenantId,
|
// if no currency is provided
|
||||||
exchangeRateDTO,
|
const fromCurrency =
|
||||||
});
|
exchangeRateLatestDTO.fromCurrency || organization.baseCurrency;
|
||||||
await this.validateExchangeRatePeriodExistance(tenantId, exchangeRateDTO);
|
const toCurrency =
|
||||||
|
exchangeRateLatestDTO.toCurrency || organization.baseCurrency;
|
||||||
|
|
||||||
const exchangeRate = await ExchangeRate.query().insertAndFetch({
|
const exchange = new ExchangeRate(ExchangeRateServiceType.OpenExchangeRate);
|
||||||
...exchangeRateDTO,
|
const exchangeRate = await exchange.latest(fromCurrency, toCurrency);
|
||||||
date: moment(exchangeRateDTO.date).format('YYYY-MM-DD'),
|
|
||||||
});
|
|
||||||
this.logger.info('[exchange_rates] inserted successfully.', {
|
|
||||||
tenantId,
|
|
||||||
exchangeRateDTO,
|
|
||||||
});
|
|
||||||
return exchangeRate;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
return {
|
||||||
* Edits the exchange rate details.
|
baseCurrency: fromCurrency,
|
||||||
* @param {number} tenantId - Tenant id.
|
toCurrency: exchangeRateLatestDTO.toCurrency,
|
||||||
* @param {number} exchangeRateId - Exchange rate id.
|
exchangeRate,
|
||||||
* @param {IExchangeRateEditDTO} editExRateDTO - Edit exchange rate DTO.
|
};
|
||||||
*/
|
|
||||||
public async editExchangeRate(
|
|
||||||
tenantId: number,
|
|
||||||
exchangeRateId: number,
|
|
||||||
editExRateDTO: IExchangeRateEditDTO
|
|
||||||
): Promise<void> {
|
|
||||||
const { ExchangeRate } = this.tenancy.models(tenantId);
|
|
||||||
|
|
||||||
this.logger.info('[exchange_rates] trying to edit exchange rate.', {
|
|
||||||
tenantId,
|
|
||||||
exchangeRateId,
|
|
||||||
editExRateDTO,
|
|
||||||
});
|
|
||||||
await this.validateExchangeRateExistance(tenantId, exchangeRateId);
|
|
||||||
|
|
||||||
await ExchangeRate.query()
|
|
||||||
.where('id', exchangeRateId)
|
|
||||||
.update({ ...editExRateDTO });
|
|
||||||
this.logger.info('[exchange_rates] exchange rate edited successfully.', {
|
|
||||||
tenantId,
|
|
||||||
exchangeRateId,
|
|
||||||
editExRateDTO,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Deletes the given exchange rate.
|
|
||||||
* @param {number} tenantId - Tenant id.
|
|
||||||
* @param {number} exchangeRateId - Exchange rate id.
|
|
||||||
*/
|
|
||||||
public async deleteExchangeRate(
|
|
||||||
tenantId: number,
|
|
||||||
exchangeRateId: number
|
|
||||||
): Promise<void> {
|
|
||||||
const { ExchangeRate } = this.tenancy.models(tenantId);
|
|
||||||
await this.validateExchangeRateExistance(tenantId, exchangeRateId);
|
|
||||||
|
|
||||||
await ExchangeRate.query().findById(exchangeRateId).delete();
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Listing exchange rates details.
|
|
||||||
* @param {number} tenantId - Tenant id.
|
|
||||||
* @param {IExchangeRateFilter} exchangeRateFilter - Exchange rates list filter.
|
|
||||||
*/
|
|
||||||
public async listExchangeRates(
|
|
||||||
tenantId: number,
|
|
||||||
exchangeRateFilter: IExchangeRateFilter
|
|
||||||
): Promise<void> {
|
|
||||||
const { ExchangeRate } = this.tenancy.models(tenantId);
|
|
||||||
const dynamicFilter = await this.dynamicListService.dynamicList(
|
|
||||||
tenantId,
|
|
||||||
ExchangeRate,
|
|
||||||
exchangeRateFilter
|
|
||||||
);
|
|
||||||
// Retrieve exchange rates by the given query.
|
|
||||||
const exchangeRates = await ExchangeRate.query()
|
|
||||||
.onBuild((query) => {
|
|
||||||
dynamicFilter.buildQuery()(query);
|
|
||||||
})
|
|
||||||
.pagination(exchangeRateFilter.page - 1, exchangeRateFilter.pageSize);
|
|
||||||
|
|
||||||
return exchangeRates;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validates period of the exchange rate existance.
|
|
||||||
* @param {number} tenantId - Tenant id.
|
|
||||||
* @param {IExchangeRateDTO} exchangeRateDTO - Exchange rate DTO.
|
|
||||||
* @return {Promise<void>}
|
|
||||||
*/
|
|
||||||
private async validateExchangeRatePeriodExistance(
|
|
||||||
tenantId: number,
|
|
||||||
exchangeRateDTO: IExchangeRateDTO
|
|
||||||
): Promise<void> {
|
|
||||||
const { ExchangeRate } = this.tenancy.models(tenantId);
|
|
||||||
|
|
||||||
this.logger.info('[exchange_rates] trying to validate period existance.', {
|
|
||||||
tenantId,
|
|
||||||
});
|
|
||||||
const foundExchangeRate = await ExchangeRate.query()
|
|
||||||
.where('currency_code', exchangeRateDTO.currencyCode)
|
|
||||||
.where('date', exchangeRateDTO.date);
|
|
||||||
|
|
||||||
if (foundExchangeRate.length > 0) {
|
|
||||||
this.logger.info('[exchange_rates] given exchange rate period exists.', {
|
|
||||||
tenantId,
|
|
||||||
});
|
|
||||||
throw new ServiceError(ERRORS.EXCHANGE_RATE_PERIOD_EXISTS);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Validate the given echange rate id existance.
|
|
||||||
* @param {number} tenantId - Tenant id.
|
|
||||||
* @param {number} exchangeRateId - Exchange rate id.
|
|
||||||
* @returns {Promise<void>}
|
|
||||||
*/
|
|
||||||
private async validateExchangeRateExistance(
|
|
||||||
tenantId: number,
|
|
||||||
exchangeRateId: number
|
|
||||||
) {
|
|
||||||
const { ExchangeRate } = this.tenancy.models(tenantId);
|
|
||||||
|
|
||||||
this.logger.info(
|
|
||||||
'[exchange_rates] trying to validate exchange rate id existance.',
|
|
||||||
{ tenantId, exchangeRateId }
|
|
||||||
);
|
|
||||||
const foundExchangeRate = await ExchangeRate.query().findById(
|
|
||||||
exchangeRateId
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!foundExchangeRate) {
|
|
||||||
this.logger.info('[exchange_rates] exchange rate not found.', {
|
|
||||||
tenantId,
|
|
||||||
exchangeRateId,
|
|
||||||
});
|
|
||||||
throw new ServiceError(ERRORS.EXCHANGE_RATE_NOT_FOUND);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -136,7 +136,7 @@ export class EditExpense {
|
|||||||
} as IExpenseEventEditingPayload);
|
} as IExpenseEventEditingPayload);
|
||||||
|
|
||||||
// Upsert the expense object with expense entries.
|
// Upsert the expense object with expense entries.
|
||||||
const expense: IExpense = await Expense.query(trx).upsertGraph({
|
const expense: IExpense = await Expense.query(trx).upsertGraphAndFetch({
|
||||||
id: expenseId,
|
id: expenseId,
|
||||||
...expenseObj,
|
...expenseObj,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -0,0 +1,25 @@
|
|||||||
|
import { Transformer } from '@/lib/Transformer/Transformer';
|
||||||
|
import { ExpenseCategory } from '@/models';
|
||||||
|
import { formatNumber } from '@/utils';
|
||||||
|
|
||||||
|
export class ExpenseCategoryTransformer extends Transformer {
|
||||||
|
/**
|
||||||
|
* Include these attributes to expense object.
|
||||||
|
* @returns {Array}
|
||||||
|
*/
|
||||||
|
public includeAttributes = (): string[] => {
|
||||||
|
return ['amountFormatted'];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the formatted amount.
|
||||||
|
* @param {ExpenseCategory} category
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
protected amountFormatted(category: ExpenseCategory) {
|
||||||
|
return formatNumber(category.amount, {
|
||||||
|
currencyCode: this.context.currencyCode,
|
||||||
|
money: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,6 +1,7 @@
|
|||||||
import { Transformer } from '@/lib/Transformer/Transformer';
|
import { Transformer } from '@/lib/Transformer/Transformer';
|
||||||
import { formatNumber } from 'utils';
|
import { formatNumber } from 'utils';
|
||||||
import { IExpense } from '@/interfaces';
|
import { IExpense } from '@/interfaces';
|
||||||
|
import { ExpenseCategoryTransformer } from './ExpenseCategoryTransformer';
|
||||||
|
|
||||||
export class ExpenseTransfromer extends Transformer {
|
export class ExpenseTransfromer extends Transformer {
|
||||||
/**
|
/**
|
||||||
@@ -12,7 +13,8 @@ export class ExpenseTransfromer extends Transformer {
|
|||||||
'formattedAmount',
|
'formattedAmount',
|
||||||
'formattedLandedCostAmount',
|
'formattedLandedCostAmount',
|
||||||
'formattedAllocatedCostAmount',
|
'formattedAllocatedCostAmount',
|
||||||
'formattedDate'
|
'formattedDate',
|
||||||
|
'categories',
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -56,5 +58,16 @@ export class ExpenseTransfromer extends Transformer {
|
|||||||
*/
|
*/
|
||||||
protected formattedDate = (expense: IExpense): string => {
|
protected formattedDate = (expense: IExpense): string => {
|
||||||
return this.formatDate(expense.paymentDate);
|
return this.formatDate(expense.paymentDate);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the transformed expense categories.
|
||||||
|
* @param {IExpense} expense
|
||||||
|
* @returns {}
|
||||||
|
*/
|
||||||
|
protected categories = (expense: IExpense) => {
|
||||||
|
return this.item(expense.categories, new ExpenseCategoryTransformer(), {
|
||||||
|
currencyCode: expense.currencyCode,
|
||||||
|
});
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
|
import { Service, Inject } from 'typedi';
|
||||||
import LedgerStorageService from '@/services/Accounting/LedgerStorageService';
|
import LedgerStorageService from '@/services/Accounting/LedgerStorageService';
|
||||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||||
import { Service, Inject } from 'typedi';
|
|
||||||
import { ExpenseGLEntries } from './ExpenseGLEntries';
|
import { ExpenseGLEntries } from './ExpenseGLEntries';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
|
|||||||
@@ -70,10 +70,10 @@ export class ExpensesWriteGLSubscriber {
|
|||||||
authorizedUser,
|
authorizedUser,
|
||||||
trx,
|
trx,
|
||||||
}: IExpenseEventEditPayload) => {
|
}: IExpenseEventEditPayload) => {
|
||||||
// In case expense published, write journal entries.
|
// Cannot continue if the expense is not published.
|
||||||
if (expense.publishedAt) return;
|
if (!expense.publishedAt) return;
|
||||||
|
|
||||||
await this.expenseGLEntries.writeExpenseGLEntries(
|
await this.expenseGLEntries.rewriteExpenseGLEntries(
|
||||||
tenantId,
|
tenantId,
|
||||||
expense.id,
|
expense.id,
|
||||||
trx
|
trx
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import {
|
|||||||
IContact,
|
IContact,
|
||||||
} from '@/interfaces';
|
} from '@/interfaces';
|
||||||
import FinancialSheet from '../FinancialSheet';
|
import FinancialSheet from '../FinancialSheet';
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* General ledger sheet.
|
* General ledger sheet.
|
||||||
@@ -88,8 +89,10 @@ export default class GeneralLedgerSheet extends FinancialSheet {
|
|||||||
|
|
||||||
const newEntry = {
|
const newEntry = {
|
||||||
date: entry.date,
|
date: entry.date,
|
||||||
|
dateFormatted: moment(entry.date).format('YYYY MMM DD'),
|
||||||
entryId: entry.id,
|
entryId: entry.id,
|
||||||
|
|
||||||
|
transactionNumber: entry.transactionNumber,
|
||||||
referenceType: entry.referenceType,
|
referenceType: entry.referenceType,
|
||||||
referenceId: entry.referenceId,
|
referenceId: entry.referenceId,
|
||||||
referenceTypeFormatted: this.i18n.__(entry.referenceTypeFormatted),
|
referenceTypeFormatted: this.i18n.__(entry.referenceTypeFormatted),
|
||||||
|
|||||||
@@ -0,0 +1,66 @@
|
|||||||
|
import { Inject } from 'typedi';
|
||||||
|
import {
|
||||||
|
IGeneralLedgerSheetQuery,
|
||||||
|
IGeneralLedgerTableData,
|
||||||
|
} from '@/interfaces';
|
||||||
|
import { GeneralLedgerTableInjectable } from './GeneralLedgerTableInjectable';
|
||||||
|
import { GeneralLedgerExportInjectable } from './GeneralLedgerExport';
|
||||||
|
import { GeneralLedgerService } from './GeneralLedgerService';
|
||||||
|
|
||||||
|
export class GeneralLedgerApplication {
|
||||||
|
@Inject()
|
||||||
|
private GLTable: GeneralLedgerTableInjectable;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private GLExport: GeneralLedgerExportInjectable;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private GLSheet: GeneralLedgerService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the G/L sheet in json format.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IGeneralLedgerSheetQuery} query
|
||||||
|
*/
|
||||||
|
public sheet(tenantId: number, query: IGeneralLedgerSheetQuery) {
|
||||||
|
return this.GLSheet.generalLedger(tenantId, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the G/L sheet in table format.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IGeneralLedgerSheetQuery} query
|
||||||
|
* @returns {Promise<IGeneralLedgerTableData>}
|
||||||
|
*/
|
||||||
|
public table(
|
||||||
|
tenantId: number,
|
||||||
|
query: IGeneralLedgerSheetQuery
|
||||||
|
): Promise<IGeneralLedgerTableData> {
|
||||||
|
return this.GLTable.table(tenantId, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the G/L sheet in xlsx format.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IGeneralLedgerSheetQuery} query
|
||||||
|
* @returns {}
|
||||||
|
*/
|
||||||
|
public xlsx(
|
||||||
|
tenantId: number,
|
||||||
|
query: IGeneralLedgerSheetQuery
|
||||||
|
): Promise<Buffer> {
|
||||||
|
return this.GLExport.xlsx(tenantId, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the G/L sheet in csv format.
|
||||||
|
* @param {number} tenantId -
|
||||||
|
* @param {IGeneralLedgerSheetQuery} query -
|
||||||
|
*/
|
||||||
|
public csv(
|
||||||
|
tenantId: number,
|
||||||
|
query: IGeneralLedgerSheetQuery
|
||||||
|
): Promise<string> {
|
||||||
|
return this.GLExport.csv(tenantId, query);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import { IGeneralLedgerSheetQuery } from '@/interfaces';
|
||||||
|
import { TableSheet } from '@/lib/Xlsx/TableSheet';
|
||||||
|
import { Inject, Service } from 'typedi';
|
||||||
|
import { GeneralLedgerTableInjectable } from './GeneralLedgerTableInjectable';
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export class GeneralLedgerExportInjectable {
|
||||||
|
@Inject()
|
||||||
|
private generalLedgerTable: GeneralLedgerTableInjectable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the general ledger sheet in XLSX format.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IGeneralLedgerSheetQuery} query
|
||||||
|
* @returns {Promise<Buffer>}
|
||||||
|
*/
|
||||||
|
public async xlsx(tenantId: number, query: IGeneralLedgerSheetQuery) {
|
||||||
|
const table = await this.generalLedgerTable.table(tenantId, query);
|
||||||
|
|
||||||
|
const tableSheet = new TableSheet(table.table);
|
||||||
|
const tableCsv = tableSheet.convertToXLSX();
|
||||||
|
|
||||||
|
return tableSheet.convertToBuffer(tableCsv, 'xlsx');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the general ledger sheet in CSV format.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IGeneralLedgerSheetQuery} query
|
||||||
|
* @returns {Promise<Buffer>}
|
||||||
|
*/
|
||||||
|
public async csv(
|
||||||
|
tenantId: number,
|
||||||
|
query: IGeneralLedgerSheetQuery
|
||||||
|
): Promise<string> {
|
||||||
|
const table = await this.generalLedgerTable.table(tenantId, query);
|
||||||
|
|
||||||
|
const tableSheet = new TableSheet(table.table);
|
||||||
|
const tableCsv = tableSheet.convertToCSV();
|
||||||
|
|
||||||
|
return tableCsv;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -15,7 +15,7 @@ const ERRORS = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class GeneralLedgerService {
|
export class GeneralLedgerService {
|
||||||
@Inject()
|
@Inject()
|
||||||
tenancy: TenancyService;
|
tenancy: TenancyService;
|
||||||
|
|
||||||
@@ -64,7 +64,7 @@ export default class GeneralLedgerService {
|
|||||||
* @param {number} tenantId -
|
* @param {number} tenantId -
|
||||||
* @returns {IGeneralLedgerMeta}
|
* @returns {IGeneralLedgerMeta}
|
||||||
*/
|
*/
|
||||||
reportMetadata(tenantId: number): IGeneralLedgerMeta {
|
reportMetadata(tenantId: number, filter): IGeneralLedgerMeta {
|
||||||
const settings = this.tenancy.settings(tenantId);
|
const settings = this.tenancy.settings(tenantId);
|
||||||
|
|
||||||
const isCostComputeRunning = this.inventoryService
|
const isCostComputeRunning = this.inventoryService
|
||||||
@@ -78,11 +78,15 @@ export default class GeneralLedgerService {
|
|||||||
group: 'organization',
|
group: 'organization',
|
||||||
key: 'base_currency',
|
key: 'base_currency',
|
||||||
});
|
});
|
||||||
|
const fromDate = moment(filter.fromDate).format('YYYY MMM DD');
|
||||||
|
const toDate = moment(filter.toDate).format('YYYY MMM DD');
|
||||||
|
|
||||||
return {
|
return {
|
||||||
isCostComputeRunning: parseBoolean(isCostComputeRunning, false),
|
isCostComputeRunning: parseBoolean(isCostComputeRunning, false),
|
||||||
organizationName,
|
organizationName,
|
||||||
baseCurrency
|
baseCurrency,
|
||||||
|
fromDate,
|
||||||
|
toDate
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -166,7 +170,7 @@ export default class GeneralLedgerService {
|
|||||||
return {
|
return {
|
||||||
data: reportData,
|
data: reportData,
|
||||||
query: filter,
|
query: filter,
|
||||||
meta: this.reportMetadata(tenantId),
|
meta: this.reportMetadata(tenantId, filter),
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,256 @@
|
|||||||
|
import * as R from 'ramda';
|
||||||
|
import {
|
||||||
|
IColumnMapperMeta,
|
||||||
|
IGeneralLedgerMeta,
|
||||||
|
IGeneralLedgerSheetAccount,
|
||||||
|
IGeneralLedgerSheetAccountTransaction,
|
||||||
|
IGeneralLedgerSheetData,
|
||||||
|
IGeneralLedgerSheetQuery,
|
||||||
|
ITableColumn,
|
||||||
|
ITableColumnAccessor,
|
||||||
|
ITableRow,
|
||||||
|
} from '@/interfaces';
|
||||||
|
import FinancialSheet from '../FinancialSheet';
|
||||||
|
import { FinancialSheetStructure } from '../FinancialSheetStructure';
|
||||||
|
import { FinancialTable } from '../FinancialTable';
|
||||||
|
import { tableRowMapper } from '@/utils';
|
||||||
|
import { ROW_TYPE } from './utils';
|
||||||
|
|
||||||
|
export class GeneralLedgerTable extends R.compose(
|
||||||
|
FinancialTable,
|
||||||
|
FinancialSheetStructure
|
||||||
|
)(FinancialSheet) {
|
||||||
|
private data: IGeneralLedgerSheetData;
|
||||||
|
private query: IGeneralLedgerSheetQuery;
|
||||||
|
private meta: IGeneralLedgerMeta;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Creates an instance of `GeneralLedgerTable`.
|
||||||
|
* @param {IGeneralLedgerSheetData} data
|
||||||
|
* @param {IGeneralLedgerSheetQuery} query
|
||||||
|
*/
|
||||||
|
constructor(
|
||||||
|
data: IGeneralLedgerSheetData,
|
||||||
|
query: IGeneralLedgerSheetQuery,
|
||||||
|
meta: IGeneralLedgerMeta
|
||||||
|
) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.data = data;
|
||||||
|
this.query = query;
|
||||||
|
this.meta = meta;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the common table accessors.
|
||||||
|
* @returns {ITableColumnAccessor[]}
|
||||||
|
*/
|
||||||
|
private accountColumnsAccessors(): ITableColumnAccessor[] {
|
||||||
|
return [
|
||||||
|
{ key: 'date', accessor: 'name' },
|
||||||
|
{ key: 'account_name', accessor: '_empty_' },
|
||||||
|
{ key: 'reference_type', accessor: '_empty_' },
|
||||||
|
{ key: 'reference_number', accessor: '_empty_' },
|
||||||
|
{ key: 'description', accessor: 'description' },
|
||||||
|
{ key: 'credit', accessor: '_empty_' },
|
||||||
|
{ key: 'debit', accessor: '_empty_' },
|
||||||
|
{ key: 'amount', accessor: 'amount.formattedAmount' },
|
||||||
|
{ key: 'running_balance', accessor: 'closingBalance.formattedAmount' },
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the transaction column accessors.
|
||||||
|
* @returns {ITableColumnAccessor[]}
|
||||||
|
*/
|
||||||
|
private transactionColumnAccessors(): ITableColumnAccessor[] {
|
||||||
|
return [
|
||||||
|
{ key: 'date', accessor: 'dateFormatted' },
|
||||||
|
{ key: 'account_name', accessor: 'account.name' },
|
||||||
|
{ key: 'reference_type', accessor: 'referenceTypeFormatted' },
|
||||||
|
{ key: 'reference_number', accessor: 'transactionNumber' },
|
||||||
|
{ key: 'description', accessor: 'note' },
|
||||||
|
{ key: 'credit', accessor: 'formattedCredit' },
|
||||||
|
{ key: 'debit', accessor: 'formattedDebit' },
|
||||||
|
{ key: 'amount', accessor: 'formattedAmount' },
|
||||||
|
{ key: 'running_balance', accessor: 'formattedRunningBalance' },
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the opening row column accessors.
|
||||||
|
* @returns {ITableRowIColumnMapperMeta[]}
|
||||||
|
*/
|
||||||
|
private openingBalanceColumnsAccessors(): IColumnMapperMeta[] {
|
||||||
|
return [
|
||||||
|
{ key: 'date', value: this.meta.fromDate },
|
||||||
|
{ key: 'account_name', value: 'Opening Balance' },
|
||||||
|
{ key: 'reference_type', accessor: '_empty_' },
|
||||||
|
{ key: 'reference_number', accessor: '_empty_' },
|
||||||
|
{ key: 'description', accessor: 'description' },
|
||||||
|
{ key: 'credit', accessor: '_empty_' },
|
||||||
|
{ key: 'debit', accessor: '_empty_' },
|
||||||
|
{ key: 'amount', accessor: 'openingBalance.formattedAmount' },
|
||||||
|
{ key: 'running_balance', accessor: 'openingBalance.formattedAmount' },
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Closing balance row column accessors.
|
||||||
|
* @returns {ITableColumnAccessor[]}
|
||||||
|
*/
|
||||||
|
private closingBalanceColumnAccessors(): IColumnMapperMeta[] {
|
||||||
|
return [
|
||||||
|
{ key: 'date', value: this.meta.toDate },
|
||||||
|
{ key: 'account_name', value: 'Closing Balance' },
|
||||||
|
{ key: 'reference_type', accessor: '_empty_' },
|
||||||
|
{ key: 'reference_number', accessor: '_empty_' },
|
||||||
|
{ key: 'description', accessor: '_empty_' },
|
||||||
|
{ key: 'credit', accessor: '_empty_' },
|
||||||
|
{ key: 'debit', accessor: '_empty_' },
|
||||||
|
{ key: 'amount', accessor: 'closingBalance.formattedAmount' },
|
||||||
|
{ key: 'running_balance', accessor: 'closingBalance.formattedAmount' },
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the common table columns.
|
||||||
|
* @returns {ITableColumn[]}
|
||||||
|
*/
|
||||||
|
private commonColumns(): ITableColumn[] {
|
||||||
|
return [
|
||||||
|
{ key: 'date', label: 'Date' },
|
||||||
|
{ key: 'account_name', label: 'Account Name' },
|
||||||
|
{ key: 'reference_type', label: 'Transaction Type' },
|
||||||
|
{ key: 'reference_number', label: 'Transaction #' },
|
||||||
|
{ key: 'description', label: 'Description' },
|
||||||
|
{ key: 'credit', label: 'Credit' },
|
||||||
|
{ key: 'debit', label: 'Debit' },
|
||||||
|
{ key: 'amount', label: 'Amount' },
|
||||||
|
{ key: 'running_balance', label: 'Running Balance' },
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the given transaction node to table row.
|
||||||
|
* @param {IGeneralLedgerSheetAccountTransaction} transaction
|
||||||
|
* @returns {ITableRow}
|
||||||
|
*/
|
||||||
|
private transactionMapper = R.curry(
|
||||||
|
(
|
||||||
|
account: IGeneralLedgerSheetAccount,
|
||||||
|
transaction: IGeneralLedgerSheetAccountTransaction
|
||||||
|
): ITableRow => {
|
||||||
|
const columns = this.transactionColumnAccessors();
|
||||||
|
const data = { ...transaction, account };
|
||||||
|
const meta = {
|
||||||
|
rowTypes: [ROW_TYPE.TRANSACTION],
|
||||||
|
};
|
||||||
|
return tableRowMapper(data, columns, meta);
|
||||||
|
}
|
||||||
|
);
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the given transactions nodes to table rows.
|
||||||
|
* @param {IGeneralLedgerSheetAccountTransaction[]} transactions
|
||||||
|
* @returns {ITableRow[]}
|
||||||
|
*/
|
||||||
|
private transactionsMapper = (
|
||||||
|
account: IGeneralLedgerSheetAccount
|
||||||
|
): ITableRow[] => {
|
||||||
|
const transactionMapper = this.transactionMapper(account);
|
||||||
|
|
||||||
|
return R.map(transactionMapper)(account.transactions);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the given account node to opening balance table row.
|
||||||
|
* @param {IGeneralLedgerSheetAccount} account
|
||||||
|
* @returns {ITableRow}
|
||||||
|
*/
|
||||||
|
private openingBalanceMapper = (
|
||||||
|
account: IGeneralLedgerSheetAccount
|
||||||
|
): ITableRow => {
|
||||||
|
const columns = this.openingBalanceColumnsAccessors();
|
||||||
|
const meta = {
|
||||||
|
rowTypes: [ROW_TYPE.OPENING_BALANCE],
|
||||||
|
};
|
||||||
|
return tableRowMapper(account, columns, meta);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the given account node to closing balance table row.
|
||||||
|
* @param {IGeneralLedgerSheetAccount} account
|
||||||
|
* @returns {ITableRow}
|
||||||
|
*/
|
||||||
|
private closingBalanceMapper = (account: IGeneralLedgerSheetAccount) => {
|
||||||
|
const columns = this.closingBalanceColumnAccessors();
|
||||||
|
const meta = {
|
||||||
|
rowTypes: [ROW_TYPE.CLOSING_BALANCE],
|
||||||
|
};
|
||||||
|
return tableRowMapper(account, columns, meta);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the given account node to transactions table rows.
|
||||||
|
* @param {IGeneralLedgerSheetAccount} account
|
||||||
|
* @returns {ITableRow[]}
|
||||||
|
*/
|
||||||
|
private transactionsNode = (
|
||||||
|
account: IGeneralLedgerSheetAccount
|
||||||
|
): ITableRow[] => {
|
||||||
|
const openingBalance = this.openingBalanceMapper(account);
|
||||||
|
const transactions = this.transactionsMapper(account);
|
||||||
|
const closingBalance = this.closingBalanceMapper(account);
|
||||||
|
|
||||||
|
return R.when(
|
||||||
|
R.always(R.not(R.isEmpty(transactions))),
|
||||||
|
R.prepend(openingBalance)
|
||||||
|
)([...transactions, closingBalance]) as ITableRow[];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the given account node to the table rows.
|
||||||
|
* @param {IGeneralLedgerSheetAccount} account
|
||||||
|
* @returns {ITableRow}
|
||||||
|
*/
|
||||||
|
private accountMapper = (account: IGeneralLedgerSheetAccount): ITableRow => {
|
||||||
|
const columns = this.accountColumnsAccessors();
|
||||||
|
const transactions = this.transactionsNode(account);
|
||||||
|
const meta = {
|
||||||
|
rowTypes: [ROW_TYPE.ACCOUNT],
|
||||||
|
};
|
||||||
|
const row = tableRowMapper(account, columns, meta);
|
||||||
|
|
||||||
|
return R.assoc('children', transactions)(row);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the given account node to table rows.
|
||||||
|
* @param {IGeneralLedgerSheetAccount[]} accounts
|
||||||
|
* @returns {ITableRow[]}
|
||||||
|
*/
|
||||||
|
private accountsMapper = (
|
||||||
|
accounts: IGeneralLedgerSheetAccount[]
|
||||||
|
): ITableRow[] => {
|
||||||
|
return this.mapNodesDeep(accounts, this.accountMapper);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the table rows.
|
||||||
|
* @returns {ITableRow[]}
|
||||||
|
*/
|
||||||
|
public tableRows(): ITableRow[] {
|
||||||
|
return R.compose(this.accountsMapper)(this.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the table columns.
|
||||||
|
* @returns {ITableColumn[]}
|
||||||
|
*/
|
||||||
|
public tableColumns(): ITableColumn[] {
|
||||||
|
const columns = this.commonColumns();
|
||||||
|
|
||||||
|
return R.compose(this.tableColumnsCellIndexing)(columns);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,45 @@
|
|||||||
|
import {
|
||||||
|
IGeneralLedgerSheetQuery,
|
||||||
|
IGeneralLedgerTableData,
|
||||||
|
} from '@/interfaces';
|
||||||
|
import { Inject, Service } from 'typedi';
|
||||||
|
import { GeneralLedgerService } from './GeneralLedgerService';
|
||||||
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||||
|
import { GeneralLedgerTable } from './GeneralLedgerTable';
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export class GeneralLedgerTableInjectable {
|
||||||
|
@Inject()
|
||||||
|
private tenancy: HasTenancyService;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private GLSheet: GeneralLedgerService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the G/L table.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IGeneralLedgerSheetQuery} query
|
||||||
|
* @returns {Promise<IGeneralLedgerTableData>}
|
||||||
|
*/
|
||||||
|
public async table(
|
||||||
|
tenantId: number,
|
||||||
|
query: IGeneralLedgerSheetQuery
|
||||||
|
): Promise<IGeneralLedgerTableData> {
|
||||||
|
const {
|
||||||
|
data: sheetData,
|
||||||
|
query: sheetQuery,
|
||||||
|
meta: sheetMeta,
|
||||||
|
} = await this.GLSheet.generalLedger(tenantId, query);
|
||||||
|
|
||||||
|
const table = new GeneralLedgerTable(sheetData, sheetQuery, sheetMeta);
|
||||||
|
|
||||||
|
return {
|
||||||
|
table: {
|
||||||
|
columns: table.tableColumns(),
|
||||||
|
rows: table.tableRows(),
|
||||||
|
},
|
||||||
|
query: sheetQuery,
|
||||||
|
meta: sheetMeta,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,6 @@
|
|||||||
|
export enum ROW_TYPE {
|
||||||
|
ACCOUNT = 'ACCOUNT',
|
||||||
|
OPENING_BALANCE = 'OPENING_BALANCE',
|
||||||
|
TRANSACTION = 'TRANSACTION',
|
||||||
|
CLOSING_BALANCE = 'CLOSING_BALANCE',
|
||||||
|
}
|
||||||
@@ -11,7 +11,7 @@ import {
|
|||||||
} from '@/interfaces';
|
} from '@/interfaces';
|
||||||
import { allPassedConditionsPass, transformToMap } from 'utils';
|
import { allPassedConditionsPass, transformToMap } from 'utils';
|
||||||
|
|
||||||
export default class InventoryValuationSheet extends FinancialSheet {
|
export class InventoryValuationSheet extends FinancialSheet {
|
||||||
readonly query: IInventoryValuationReportQuery;
|
readonly query: IInventoryValuationReportQuery;
|
||||||
readonly items: IItem[];
|
readonly items: IItem[];
|
||||||
readonly INInventoryCostLots: Map<number, InventoryCostLotTracker>;
|
readonly INInventoryCostLots: Map<number, InventoryCostLotTracker>;
|
||||||
@@ -259,6 +259,6 @@ export default class InventoryValuationSheet extends FinancialSheet {
|
|||||||
const items = this.itemsSection();
|
const items = this.itemsSection();
|
||||||
const total = this.totalSection(items);
|
const total = this.totalSection(items);
|
||||||
|
|
||||||
return items.length > 0 ? { items, total } : {};
|
return { items, total };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,76 @@
|
|||||||
|
import {
|
||||||
|
IInventoryValuationReportQuery,
|
||||||
|
IInventoryValuationSheet,
|
||||||
|
IInventoryValuationTable,
|
||||||
|
} from '@/interfaces';
|
||||||
|
import { Inject, Service } from 'typedi';
|
||||||
|
import { InventoryValuationSheetService } from './InventoryValuationSheetService';
|
||||||
|
import { InventoryValuationSheetTableInjectable } from './InventoryValuationSheetTableInjectable';
|
||||||
|
import { InventoryValuationSheetExportable } from './InventoryValuationSheetExportable';
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export class InventoryValuationSheetApplication {
|
||||||
|
@Inject()
|
||||||
|
private inventoryValuationSheet: InventoryValuationSheetService;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private inventoryValuationTable: InventoryValuationSheetTableInjectable;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private inventoryValuationExport: InventoryValuationSheetExportable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the inventory valuation json format.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IInventoryValuationReportQuery} query
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
public sheet(
|
||||||
|
tenantId: number,
|
||||||
|
query: IInventoryValuationReportQuery
|
||||||
|
): Promise<IInventoryValuationSheet> {
|
||||||
|
return this.inventoryValuationSheet.inventoryValuationSheet(
|
||||||
|
tenantId,
|
||||||
|
query
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the inventory valuation json table format.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IInventoryValuationReportQuery} query
|
||||||
|
* @returns {Promise<IInventoryValuationTable>}
|
||||||
|
*/
|
||||||
|
public table(
|
||||||
|
tenantId: number,
|
||||||
|
query: IInventoryValuationReportQuery
|
||||||
|
): Promise<IInventoryValuationTable> {
|
||||||
|
return this.inventoryValuationTable.table(tenantId, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the inventory valuation xlsx format.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IInventoryValuationReportQuery} query
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
public xlsx(
|
||||||
|
tenantId: number,
|
||||||
|
query: IInventoryValuationReportQuery
|
||||||
|
): Promise<Buffer> {
|
||||||
|
return this.inventoryValuationExport.xlsx(tenantId, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the inventory valuation csv format.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IInventoryValuationReportQuery} query
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
public csv(
|
||||||
|
tenantId: number,
|
||||||
|
query: IInventoryValuationReportQuery
|
||||||
|
): Promise<string> {
|
||||||
|
return this.inventoryValuationExport.csv(tenantId, query);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import { Inject, Service } from 'typedi';
|
||||||
|
import { IInventoryValuationReportQuery } from '@/interfaces';
|
||||||
|
import { InventoryValuationSheetTableInjectable } from './InventoryValuationSheetTableInjectable';
|
||||||
|
import { TableSheet } from '@/lib/Xlsx/TableSheet';
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export class InventoryValuationSheetExportable {
|
||||||
|
@Inject()
|
||||||
|
private inventoryValuationTable: InventoryValuationSheetTableInjectable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the trial balance sheet in XLSX format.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IInventoryValuationReportQuery} query
|
||||||
|
* @returns {Promise<Buffer>}
|
||||||
|
*/
|
||||||
|
public async xlsx(
|
||||||
|
tenantId: number,
|
||||||
|
query: IInventoryValuationReportQuery
|
||||||
|
): Promise<Buffer> {
|
||||||
|
const table = await this.inventoryValuationTable.table(tenantId, query);
|
||||||
|
|
||||||
|
const tableSheet = new TableSheet(table.table);
|
||||||
|
const tableCsv = tableSheet.convertToXLSX();
|
||||||
|
|
||||||
|
return tableSheet.convertToBuffer(tableCsv, 'xlsx');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the trial balance sheet in CSV format.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IInventoryValuationReportQuery} query
|
||||||
|
* @returns {Promise<Buffer>}
|
||||||
|
*/
|
||||||
|
public async csv(
|
||||||
|
tenantId: number,
|
||||||
|
query: IInventoryValuationReportQuery
|
||||||
|
): Promise<string> {
|
||||||
|
const table = await this.inventoryValuationTable.table(tenantId, query);
|
||||||
|
|
||||||
|
const tableSheet = new TableSheet(table.table);
|
||||||
|
const tableCsv = tableSheet.convertToCSV();
|
||||||
|
|
||||||
|
return tableCsv;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,15 +3,16 @@ import moment from 'moment';
|
|||||||
import { isEmpty } from 'lodash';
|
import { isEmpty } from 'lodash';
|
||||||
import {
|
import {
|
||||||
IInventoryValuationReportQuery,
|
IInventoryValuationReportQuery,
|
||||||
|
IInventoryValuationSheet,
|
||||||
IInventoryValuationSheetMeta,
|
IInventoryValuationSheetMeta,
|
||||||
} from '@/interfaces';
|
} from '@/interfaces';
|
||||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||||
import InventoryValuationSheet from './InventoryValuationSheet';
|
import { InventoryValuationSheet } from './InventoryValuationSheet';
|
||||||
import InventoryService from '@/services/Inventory/Inventory';
|
import InventoryService from '@/services/Inventory/Inventory';
|
||||||
import { Tenant } from '@/system/models';
|
import { Tenant } from '@/system/models';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class InventoryValuationSheetService {
|
export class InventoryValuationSheetService {
|
||||||
@Inject()
|
@Inject()
|
||||||
tenancy: TenancyService;
|
tenancy: TenancyService;
|
||||||
|
|
||||||
@@ -80,7 +81,7 @@ export default class InventoryValuationSheetService {
|
|||||||
public async inventoryValuationSheet(
|
public async inventoryValuationSheet(
|
||||||
tenantId: number,
|
tenantId: number,
|
||||||
query: IInventoryValuationReportQuery
|
query: IInventoryValuationReportQuery
|
||||||
) {
|
): Promise<IInventoryValuationSheet> {
|
||||||
const { Item, InventoryCostLotTracker } = this.tenancy.models(tenantId);
|
const { Item, InventoryCostLotTracker } = this.tenancy.models(tenantId);
|
||||||
|
|
||||||
const tenant = await Tenant.query()
|
const tenant = await Tenant.query()
|
||||||
|
|||||||
@@ -0,0 +1,105 @@
|
|||||||
|
import * as R from 'ramda';
|
||||||
|
import {
|
||||||
|
IInventoryValuationItem,
|
||||||
|
IInventoryValuationSheetData,
|
||||||
|
IInventoryValuationTotal,
|
||||||
|
ITableColumn,
|
||||||
|
ITableColumnAccessor,
|
||||||
|
ITableRow,
|
||||||
|
} from '@/interfaces';
|
||||||
|
import { tableRowMapper } from '@/utils';
|
||||||
|
import FinancialSheet from '../FinancialSheet';
|
||||||
|
import { FinancialSheetStructure } from '../FinancialSheetStructure';
|
||||||
|
import { FinancialTable } from '../FinancialTable';
|
||||||
|
import { ROW_TYPE } from './_constants';
|
||||||
|
|
||||||
|
export class InventoryValuationSheetTable extends R.compose(
|
||||||
|
FinancialTable,
|
||||||
|
FinancialSheetStructure
|
||||||
|
)(FinancialSheet) {
|
||||||
|
private readonly data: IInventoryValuationSheetData;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor method.
|
||||||
|
* @param {IInventoryValuationSheetData} data
|
||||||
|
*/
|
||||||
|
constructor(data: IInventoryValuationSheetData) {
|
||||||
|
super();
|
||||||
|
this.data = data;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the common columns accessors.
|
||||||
|
* @returns {ITableColumnAccessor}
|
||||||
|
*/
|
||||||
|
private commonColumnsAccessors(): ITableColumnAccessor[] {
|
||||||
|
return [
|
||||||
|
{ key: 'item_name', accessor: 'name' },
|
||||||
|
{ key: 'quantity', accessor: 'quantityFormatted' },
|
||||||
|
{ key: 'valuation', accessor: 'valuationFormatted' },
|
||||||
|
{ key: 'average', accessor: 'averageFormatted' },
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the given total node to table row.
|
||||||
|
* @param {IInventoryValuationTotal} total
|
||||||
|
* @returns {ITableRow}
|
||||||
|
*/
|
||||||
|
private totalRowMapper = (total: IInventoryValuationTotal): ITableRow => {
|
||||||
|
const accessors = this.commonColumnsAccessors();
|
||||||
|
const meta = {
|
||||||
|
rowTypes: [ROW_TYPE.TOTAL],
|
||||||
|
};
|
||||||
|
return tableRowMapper(total, accessors, meta);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the given item node to table row.
|
||||||
|
* @param {IInventoryValuationItem} item
|
||||||
|
* @returns {ITableRow}
|
||||||
|
*/
|
||||||
|
private itemRowMapper = (item: IInventoryValuationItem): ITableRow => {
|
||||||
|
const accessors = this.commonColumnsAccessors();
|
||||||
|
const meta = {
|
||||||
|
rowTypes: [ROW_TYPE.ITEM],
|
||||||
|
};
|
||||||
|
return tableRowMapper(item, accessors, meta);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the given items nodes to table rowes.
|
||||||
|
* @param {IInventoryValuationItem[]} items
|
||||||
|
* @returns {ITableRow[]}
|
||||||
|
*/
|
||||||
|
private itemsRowsMapper = (items: IInventoryValuationItem[]): ITableRow[] => {
|
||||||
|
return R.map(this.itemRowMapper)(items);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the table rows.
|
||||||
|
* @returns {ITableRow[]}
|
||||||
|
*/
|
||||||
|
public tableRows(): ITableRow[] {
|
||||||
|
const itemsRows = this.itemsRowsMapper(this.data.items);
|
||||||
|
const totalRow = this.totalRowMapper(this.data.total);
|
||||||
|
|
||||||
|
return R.compose(
|
||||||
|
R.when(R.always(R.not(R.isEmpty(itemsRows))), R.append(totalRow))
|
||||||
|
)([...itemsRows]) as ITableRow[];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the table columns.
|
||||||
|
* @returns {ITableColumn[]}
|
||||||
|
*/
|
||||||
|
public tableColumns(): ITableColumn[] {
|
||||||
|
const columns = [
|
||||||
|
{ key: 'item_name', label: 'Item Name' },
|
||||||
|
{ key: 'quantity', label: 'Quantity' },
|
||||||
|
{ key: 'valuation', label: 'Valuation' },
|
||||||
|
{ key: 'average', label: 'Average' },
|
||||||
|
];
|
||||||
|
return R.compose(this.tableColumnsCellIndexing)(columns);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import { Inject, Service } from 'typedi';
|
||||||
|
import { InventoryValuationSheetService } from './InventoryValuationSheetService';
|
||||||
|
import {
|
||||||
|
IInventoryValuationReportQuery,
|
||||||
|
IInventoryValuationTable,
|
||||||
|
} from '@/interfaces';
|
||||||
|
import { InventoryValuationSheetTable } from './InventoryValuationSheetTable';
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export class InventoryValuationSheetTableInjectable {
|
||||||
|
@Inject()
|
||||||
|
private sheet: InventoryValuationSheetService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the inventory valuation json table format.
|
||||||
|
* @param {number} tenantId -
|
||||||
|
* @param {IInventoryValuationReportQuery} filter -
|
||||||
|
* @returns {Promise<IInventoryValuationTable>}
|
||||||
|
*/
|
||||||
|
public async table(
|
||||||
|
tenantId: number,
|
||||||
|
filter: IInventoryValuationReportQuery
|
||||||
|
): Promise<IInventoryValuationTable> {
|
||||||
|
const { data, query, meta } = await this.sheet.inventoryValuationSheet(
|
||||||
|
tenantId,
|
||||||
|
filter
|
||||||
|
);
|
||||||
|
const table = new InventoryValuationSheetTable(data);
|
||||||
|
|
||||||
|
return {
|
||||||
|
table: {
|
||||||
|
columns: table.tableColumns(),
|
||||||
|
rows: table.tableRows(),
|
||||||
|
},
|
||||||
|
query,
|
||||||
|
meta,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,4 @@
|
|||||||
|
export enum ROW_TYPE {
|
||||||
|
ITEM = 'ITEM',
|
||||||
|
TOTAL = 'TOTAL',
|
||||||
|
}
|
||||||
@@ -6,8 +6,10 @@ import {
|
|||||||
IJournalReportQuery,
|
IJournalReportQuery,
|
||||||
IJournalReport,
|
IJournalReport,
|
||||||
IContact,
|
IContact,
|
||||||
|
IJournalTableData,
|
||||||
} from '@/interfaces';
|
} from '@/interfaces';
|
||||||
import FinancialSheet from '../FinancialSheet';
|
import FinancialSheet from '../FinancialSheet';
|
||||||
|
import moment from 'moment';
|
||||||
|
|
||||||
export default class JournalSheet extends FinancialSheet {
|
export default class JournalSheet extends FinancialSheet {
|
||||||
readonly tenantId: number;
|
readonly tenantId: number;
|
||||||
@@ -96,6 +98,8 @@ export default class JournalSheet extends FinancialSheet {
|
|||||||
|
|
||||||
return {
|
return {
|
||||||
date: groupEntry.date,
|
date: groupEntry.date,
|
||||||
|
dateFormatted: moment(groupEntry.date).format('YYYY MMM DD'),
|
||||||
|
|
||||||
referenceType: groupEntry.referenceType,
|
referenceType: groupEntry.referenceType,
|
||||||
referenceId: groupEntry.referenceId,
|
referenceId: groupEntry.referenceId,
|
||||||
referenceTypeFormatted: this.i18n.__(groupEntry.referenceTypeFormatted),
|
referenceTypeFormatted: this.i18n.__(groupEntry.referenceTypeFormatted),
|
||||||
@@ -131,7 +135,7 @@ export default class JournalSheet extends FinancialSheet {
|
|||||||
* Retrieve journal report.
|
* Retrieve journal report.
|
||||||
* @return {IJournalReport}
|
* @return {IJournalReport}
|
||||||
*/
|
*/
|
||||||
reportData(): IJournalReport {
|
reportData(): IJournalTableData {
|
||||||
return this.entriesWalker(this.journal.entries);
|
return this.entriesWalker(this.journal.entries);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,59 @@
|
|||||||
|
import { Inject } from 'typedi';
|
||||||
|
import { JournalSheetService } from './JournalSheetService';
|
||||||
|
import { JournalSheetTableInjectable } from './JournalSheetTableInjectable';
|
||||||
|
import { IJournalReportQuery, IJournalTable } from '@/interfaces';
|
||||||
|
import { JournalSheetExportInjectable } from './JournalSheetExport';
|
||||||
|
|
||||||
|
export class JournalSheetApplication {
|
||||||
|
@Inject()
|
||||||
|
private journalSheetTable: JournalSheetTableInjectable;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private journalSheet: JournalSheetService;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private journalExport: JournalSheetExportInjectable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the journal sheet.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IJournalReportQuery} query
|
||||||
|
* @returns {}
|
||||||
|
*/
|
||||||
|
public sheet(tenantId: number, query: IJournalReportQuery) {
|
||||||
|
return this.journalSheet.journalSheet(tenantId, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the journal sheet in table format.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IJournalReportQuery} query
|
||||||
|
* @returns {Promise<IJournalTable>}
|
||||||
|
*/
|
||||||
|
public table(
|
||||||
|
tenantId: number,
|
||||||
|
query: IJournalReportQuery
|
||||||
|
): Promise<IJournalTable> {
|
||||||
|
return this.journalSheetTable.table(tenantId, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the journal sheet in xlsx format.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IJournalReportQuery} query
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
public xlsx(tenantId: number, query: IJournalReportQuery) {
|
||||||
|
return this.journalExport.xlsx(tenantId, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the journal sheet in csv format.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IJournalReportQuery} query
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
public csv(tenantId: number, query: IJournalReportQuery) {
|
||||||
|
return this.journalExport.csv(tenantId, query);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,43 @@
|
|||||||
|
import { Inject, Service } from 'typedi';
|
||||||
|
import { TableSheet } from '@/lib/Xlsx/TableSheet';
|
||||||
|
import { IJournalReportQuery } from '@/interfaces';
|
||||||
|
import { JournalSheetTableInjectable } from './JournalSheetTableInjectable';
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export class JournalSheetExportInjectable {
|
||||||
|
@Inject()
|
||||||
|
private journalSheetTable: JournalSheetTableInjectable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the trial balance sheet in XLSX format.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IJournalReportQuery} query
|
||||||
|
* @returns {Promise<Buffer>}
|
||||||
|
*/
|
||||||
|
public async xlsx(tenantId: number, query: IJournalReportQuery) {
|
||||||
|
const table = await this.journalSheetTable.table(tenantId, query);
|
||||||
|
|
||||||
|
const tableSheet = new TableSheet(table.table);
|
||||||
|
const tableCsv = tableSheet.convertToXLSX();
|
||||||
|
|
||||||
|
return tableSheet.convertToBuffer(tableCsv, 'xlsx');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the trial balance sheet in CSV format.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IJournalReportQuery} query
|
||||||
|
* @returns {Promise<Buffer>}
|
||||||
|
*/
|
||||||
|
public async csv(
|
||||||
|
tenantId: number,
|
||||||
|
query: IJournalReportQuery
|
||||||
|
): Promise<string> {
|
||||||
|
const table = await this.journalSheetTable.table(tenantId, query);
|
||||||
|
|
||||||
|
const tableSheet = new TableSheet(table.table);
|
||||||
|
const tableCsv = tableSheet.convertToCSV();
|
||||||
|
|
||||||
|
return tableCsv;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -1,24 +1,25 @@
|
|||||||
import { Service, Inject } from 'typedi';
|
import { Service, Inject } from 'typedi';
|
||||||
import moment from 'moment';
|
import moment from 'moment';
|
||||||
import { IJournalReportQuery, IJournalSheetMeta } from '@/interfaces';
|
import {
|
||||||
|
IJournalReportQuery,
|
||||||
|
IJournalSheet,
|
||||||
|
IJournalSheetMeta,
|
||||||
|
IJournalTableData,
|
||||||
|
} from '@/interfaces';
|
||||||
import JournalSheet from './JournalSheet';
|
import JournalSheet from './JournalSheet';
|
||||||
import TenancyService from '@/services/Tenancy/TenancyService';
|
import TenancyService from '@/services/Tenancy/TenancyService';
|
||||||
import Journal from '@/services/Accounting/JournalPoster';
|
import Journal from '@/services/Accounting/JournalPoster';
|
||||||
import InventoryService from '@/services/Inventory/Inventory';
|
import InventoryService from '@/services/Inventory/Inventory';
|
||||||
import { parseBoolean, transformToMap } from 'utils';
|
|
||||||
import { Tenant } from '@/system/models';
|
import { Tenant } from '@/system/models';
|
||||||
|
import { parseBoolean, transformToMap } from 'utils';
|
||||||
|
|
||||||
@Service()
|
@Service()
|
||||||
export default class JournalSheetService {
|
export class JournalSheetService {
|
||||||
@Inject()
|
@Inject()
|
||||||
tenancy: TenancyService;
|
private tenancy: TenancyService;
|
||||||
|
|
||||||
@Inject()
|
@Inject()
|
||||||
inventoryService: InventoryService;
|
private inventoryService: InventoryService;
|
||||||
|
|
||||||
@Inject('logger')
|
|
||||||
logger: any;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Default journal sheet filter queyr.
|
* Default journal sheet filter queyr.
|
||||||
@@ -67,9 +68,13 @@ export default class JournalSheetService {
|
|||||||
/**
|
/**
|
||||||
* Journal sheet.
|
* Journal sheet.
|
||||||
* @param {number} tenantId
|
* @param {number} tenantId
|
||||||
* @param {IJournalSheetFilterQuery} query
|
* @param {IJournalReportQuery} query
|
||||||
|
* @returns {Promise<IJournalSheet>}
|
||||||
*/
|
*/
|
||||||
async journalSheet(tenantId: number, query: IJournalReportQuery) {
|
async journalSheet(
|
||||||
|
tenantId: number,
|
||||||
|
query: IJournalReportQuery
|
||||||
|
): Promise<IJournalSheet> {
|
||||||
const i18n = this.tenancy.i18n(tenantId);
|
const i18n = this.tenancy.i18n(tenantId);
|
||||||
const { accountRepository, transactionsRepository, contactRepository } =
|
const { accountRepository, transactionsRepository, contactRepository } =
|
||||||
this.tenancy.repositories(tenantId);
|
this.tenancy.repositories(tenantId);
|
||||||
@@ -80,11 +85,6 @@ export default class JournalSheetService {
|
|||||||
...this.defaultQuery,
|
...this.defaultQuery,
|
||||||
...query,
|
...query,
|
||||||
};
|
};
|
||||||
this.logger.info('[journal] trying to calculate the report.', {
|
|
||||||
tenantId,
|
|
||||||
filter,
|
|
||||||
});
|
|
||||||
|
|
||||||
const tenant = await Tenant.query()
|
const tenant = await Tenant.query()
|
||||||
.findById(tenantId)
|
.findById(tenantId)
|
||||||
.withGraphFetched('metadata');
|
.withGraphFetched('metadata');
|
||||||
|
|||||||
@@ -0,0 +1,232 @@
|
|||||||
|
import * as R from 'ramda';
|
||||||
|
import { first } from 'lodash';
|
||||||
|
import {
|
||||||
|
IColumnMapperMeta,
|
||||||
|
IJournalEntry,
|
||||||
|
IJournalReportEntriesGroup,
|
||||||
|
IJournalReportQuery,
|
||||||
|
IJournalTableData,
|
||||||
|
ITableColumn,
|
||||||
|
ITableColumnAccessor,
|
||||||
|
ITableRow,
|
||||||
|
} from '@/interfaces';
|
||||||
|
import { tableRowMapper } from '@/utils';
|
||||||
|
import { FinancialTable } from '../FinancialTable';
|
||||||
|
import { FinancialSheetStructure } from '../FinancialSheetStructure';
|
||||||
|
import FinancialSheet from '../FinancialSheet';
|
||||||
|
import { ROW_TYPE } from './types';
|
||||||
|
|
||||||
|
export class JournalSheetTable extends R.compose(
|
||||||
|
FinancialTable,
|
||||||
|
FinancialSheetStructure
|
||||||
|
)(FinancialSheet) {
|
||||||
|
private data: IJournalTableData;
|
||||||
|
private query: IJournalReportQuery;
|
||||||
|
private i18n: any;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Constructor method.
|
||||||
|
* @param {IJournalTableData} data
|
||||||
|
* @param {IJournalReportQuery} query
|
||||||
|
* @param i18n
|
||||||
|
*/
|
||||||
|
constructor(data: IJournalTableData, query: IJournalReportQuery, i18n: any) {
|
||||||
|
super();
|
||||||
|
|
||||||
|
this.data = data;
|
||||||
|
this.query = query;
|
||||||
|
this.i18n = i18n;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the common table accessors.
|
||||||
|
* @returns {ITableColumnAccessor[]}
|
||||||
|
*/
|
||||||
|
private groupColumnsAccessors = (): ITableColumnAccessor[] => {
|
||||||
|
return [
|
||||||
|
{ key: 'date', accessor: 'dateFormatted' },
|
||||||
|
{ key: 'transaction_type', accessor: 'referenceTypeFormatted' },
|
||||||
|
{ key: 'transaction_number', accessor: 'entry.transactionNumber' },
|
||||||
|
{ key: 'description', accessor: 'entry.note' },
|
||||||
|
{ key: 'account_code', accessor: 'entry.accountCode' },
|
||||||
|
{ key: 'account_name', accessor: 'entry.accountName' },
|
||||||
|
{ key: 'credit', accessor: 'entry.formattedCredit' },
|
||||||
|
{ key: 'debit', accessor: 'entry.formattedDebit' },
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the group entry accessors.
|
||||||
|
* @returns {ITableColumnAccessor[]}
|
||||||
|
*/
|
||||||
|
private entryColumnsAccessors = (): ITableColumnAccessor[] => {
|
||||||
|
return [
|
||||||
|
{ key: 'date', accessor: '_empty_' },
|
||||||
|
{ key: 'transaction_type', accessor: '_empty_' },
|
||||||
|
{ key: 'transaction_number', accessor: 'transactionNumber' },
|
||||||
|
{ key: 'description', accessor: 'note' },
|
||||||
|
{ key: 'account_code', accessor: 'accountCode' },
|
||||||
|
{ key: 'account_name', accessor: 'accountName' },
|
||||||
|
{ key: 'credit', accessor: 'formattedCredit' },
|
||||||
|
{ key: 'debit', accessor: 'formattedDebit' },
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the total entry column accessors.
|
||||||
|
* @returns {ITableColumnAccessor[]}
|
||||||
|
*/
|
||||||
|
private totalEntryColumnAccessors = (): ITableColumnAccessor[] => {
|
||||||
|
return [
|
||||||
|
{ key: 'date', accessor: '_empty_' },
|
||||||
|
{ key: 'transaction_type', accessor: '_empty_' },
|
||||||
|
{ key: 'transaction_number', accessor: '_empty_' },
|
||||||
|
{ key: 'description', accessor: '_empty_' },
|
||||||
|
{ key: 'account_code', accessor: '_empty_' },
|
||||||
|
{ key: 'account_name', accessor: '_empty_' },
|
||||||
|
{ key: 'credit', accessor: 'formattedCredit' },
|
||||||
|
{ key: 'debit', accessor: 'formattedDebit' },
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the total entry column accessors.
|
||||||
|
* @returns {IColumnMapperMeta[]}
|
||||||
|
*/
|
||||||
|
private blankEnrtyColumnAccessors = (): IColumnMapperMeta[] => {
|
||||||
|
return [
|
||||||
|
{ key: 'date', value: '' },
|
||||||
|
{ key: 'transaction_type', value: '' },
|
||||||
|
{ key: 'transaction_number', value: '' },
|
||||||
|
{ key: 'description', value: '' },
|
||||||
|
{ key: 'account_code', value: '' },
|
||||||
|
{ key: 'account_name', value: '' },
|
||||||
|
{ key: 'credit', value: '' },
|
||||||
|
{ key: 'debit', value: '' },
|
||||||
|
];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the common columns.
|
||||||
|
* @returns {ITableColumn[]}
|
||||||
|
*/
|
||||||
|
private commonColumns(): ITableColumn[] {
|
||||||
|
return [
|
||||||
|
{ key: 'date', label: 'Date' },
|
||||||
|
{ key: 'transaction_type', label: 'Transaction Type' },
|
||||||
|
{ key: 'transaction_number', label: 'Num.' },
|
||||||
|
{ key: 'description', label: 'Description' },
|
||||||
|
{ key: 'account_code', label: 'Acc. Code' },
|
||||||
|
{ key: 'account_name', label: 'Account' },
|
||||||
|
{ key: 'credit', label: 'Credit' },
|
||||||
|
{ key: 'debit', label: 'Debit' },
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the group and first entry to table row.
|
||||||
|
* @param {IJournalReportEntriesGroup} group
|
||||||
|
* @returns {ITableRow}
|
||||||
|
*/
|
||||||
|
private firstEntryGroupMapper = (
|
||||||
|
group: IJournalReportEntriesGroup
|
||||||
|
): ITableRow => {
|
||||||
|
const meta = {
|
||||||
|
rowTypes: [ROW_TYPE.ENTRY],
|
||||||
|
};
|
||||||
|
const computedGroup = { ...group, entry: first(group.entries) };
|
||||||
|
const columns = this.groupColumnsAccessors();
|
||||||
|
|
||||||
|
return tableRowMapper(computedGroup, columns, meta);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the given group entry to table rows.
|
||||||
|
* @param {IJournalEntry} entry
|
||||||
|
* @returns {ITableRow}
|
||||||
|
*/
|
||||||
|
private entryMapper = (entry: IJournalEntry): ITableRow => {
|
||||||
|
const columns = this.entryColumnsAccessors();
|
||||||
|
const meta = {
|
||||||
|
rowTypes: [ROW_TYPE.ENTRY],
|
||||||
|
};
|
||||||
|
return tableRowMapper(entry, columns, meta);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the given group entries to table rows.
|
||||||
|
* @param {IJournalReportEntriesGroup} group
|
||||||
|
* @returns {ITableRow[]}
|
||||||
|
*/
|
||||||
|
private entriesMapper = (group: IJournalReportEntriesGroup): ITableRow[] => {
|
||||||
|
const entries = R.remove(0, 1, group.entries);
|
||||||
|
|
||||||
|
return R.map(this.entryMapper, entries);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the given group entry to total table row.
|
||||||
|
* @param {IJournalReportEntriesGroup} group
|
||||||
|
* @returns {ITableRow}
|
||||||
|
*/
|
||||||
|
public totalEntryMapper = (group: IJournalReportEntriesGroup): ITableRow => {
|
||||||
|
const total = this.totalEntryColumnAccessors();
|
||||||
|
const meta = {
|
||||||
|
rowTypes: [ROW_TYPE.TOTAL],
|
||||||
|
};
|
||||||
|
return tableRowMapper(group, total, meta);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the blank entry row.
|
||||||
|
* @returns {ITableRow}
|
||||||
|
*/
|
||||||
|
private blankEntryMapper = (): ITableRow => {
|
||||||
|
const columns = this.blankEnrtyColumnAccessors();
|
||||||
|
const meta = {};
|
||||||
|
return tableRowMapper({} as IJournalEntry, columns, meta);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the entry group to table rows.
|
||||||
|
* @param {IJournalReportEntriesGroup} group -
|
||||||
|
* @returns {ITableRow}
|
||||||
|
*/
|
||||||
|
private groupMapper = (group: IJournalReportEntriesGroup): ITableRow[] => {
|
||||||
|
const firstRow = this.firstEntryGroupMapper(group);
|
||||||
|
const lastRows = this.entriesMapper(group);
|
||||||
|
const totalRow = this.totalEntryMapper(group);
|
||||||
|
const blankRow = this.blankEntryMapper();
|
||||||
|
|
||||||
|
return [firstRow, ...lastRows, totalRow, blankRow];
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Maps the given group entries to table rows.
|
||||||
|
* @param {IJournalReportEntriesGroup[]} entries -
|
||||||
|
* @returns {ITableRow[]}
|
||||||
|
*/
|
||||||
|
private groupsMapper = (
|
||||||
|
entries: IJournalReportEntriesGroup[]
|
||||||
|
): ITableRow[] => {
|
||||||
|
return R.compose(R.flatten, R.map(this.groupMapper))(entries);
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the table data rows.
|
||||||
|
* @returns {ITableRow[]}
|
||||||
|
*/
|
||||||
|
public tableData(): ITableRow[] {
|
||||||
|
return R.compose(this.groupsMapper)(this.data);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the table columns.
|
||||||
|
* @returns {ITableColumn[]}
|
||||||
|
*/
|
||||||
|
public tableColumns(): ITableColumn[] {
|
||||||
|
const columns = this.commonColumns();
|
||||||
|
|
||||||
|
return R.compose(this.tableColumnsCellIndexing)(columns);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,39 @@
|
|||||||
|
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||||
|
import { Inject } from 'typedi';
|
||||||
|
import { JournalSheetService } from './JournalSheetService';
|
||||||
|
import { IJournalReportQuery, IJournalTable } from '@/interfaces';
|
||||||
|
import { JournalSheetTable } from './JournalSheetTable';
|
||||||
|
|
||||||
|
export class JournalSheetTableInjectable {
|
||||||
|
@Inject()
|
||||||
|
private tenancy: HasTenancyService;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private journalSheetService: JournalSheetService;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the journal sheet in table format.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IJournalReportQuery} query
|
||||||
|
* @returns {Promise<IJournalTable>}
|
||||||
|
*/
|
||||||
|
public async table(
|
||||||
|
tenantId: number,
|
||||||
|
query: IJournalReportQuery
|
||||||
|
): Promise<IJournalTable> {
|
||||||
|
const journal = await this.journalSheetService.journalSheet(
|
||||||
|
tenantId,
|
||||||
|
query
|
||||||
|
);
|
||||||
|
const table = new JournalSheetTable(journal.data, journal.query, {});
|
||||||
|
|
||||||
|
return {
|
||||||
|
table: {
|
||||||
|
columns: table.tableColumns(),
|
||||||
|
rows: table.tableData(),
|
||||||
|
},
|
||||||
|
query: journal.query,
|
||||||
|
meta: journal.meta,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,5 @@
|
|||||||
|
|
||||||
|
export enum ROW_TYPE {
|
||||||
|
ENTRY = 'ENTRY',
|
||||||
|
TOTAL = 'TOTAL'
|
||||||
|
};
|
||||||
@@ -2,36 +2,34 @@ import { get, isEmpty, sumBy } from 'lodash';
|
|||||||
import * as R from 'ramda';
|
import * as R from 'ramda';
|
||||||
import FinancialSheet from '../FinancialSheet';
|
import FinancialSheet from '../FinancialSheet';
|
||||||
import { allPassedConditionsPass, transformToMap } from 'utils';
|
import { allPassedConditionsPass, transformToMap } from 'utils';
|
||||||
|
import { IAccountTransaction, IItem } from '@/interfaces';
|
||||||
import {
|
import {
|
||||||
IAccountTransaction,
|
IPurchasesByItemsItem,
|
||||||
IInventoryValuationTotal,
|
IPurchasesByItemsReportQuery,
|
||||||
IInventoryValuationItem,
|
IPurchasesByItemsSheetData,
|
||||||
IInventoryValuationReportQuery,
|
IPurchasesByItemsTotal,
|
||||||
IInventoryValuationStatement,
|
} from '@/interfaces/PurchasesByItemsSheet';
|
||||||
IItem,
|
|
||||||
} from '@/interfaces';
|
|
||||||
|
|
||||||
export default class InventoryValuationReport extends FinancialSheet {
|
export class PurchasesByItems extends FinancialSheet {
|
||||||
readonly baseCurrency: string;
|
readonly baseCurrency: string;
|
||||||
readonly items: IItem[];
|
readonly items: IItem[];
|
||||||
readonly itemsTransactions: Map<number, IAccountTransaction>;
|
readonly itemsTransactions: Map<number, IAccountTransaction>;
|
||||||
readonly query: IInventoryValuationReportQuery;
|
readonly query: IPurchasesByItemsReportQuery;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Constructor method.
|
* Constructor method.
|
||||||
* @param {IInventoryValuationReportQuery} query
|
* @param {IPurchasesByItemsReportQuery} query
|
||||||
* @param {IItem[]} items
|
* @param {IItem[]} items
|
||||||
* @param {IAccountTransaction[]} itemsTransactions
|
* @param {IAccountTransaction[]} itemsTransactions
|
||||||
* @param {string} baseCurrency
|
* @param {string} baseCurrency
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
query: IInventoryValuationReportQuery,
|
query: IPurchasesByItemsReportQuery,
|
||||||
items: IItem[],
|
items: IItem[],
|
||||||
itemsTransactions: IAccountTransaction[],
|
itemsTransactions: IAccountTransaction[],
|
||||||
baseCurrency: string
|
baseCurrency: string
|
||||||
) {
|
) {
|
||||||
super();
|
super();
|
||||||
|
|
||||||
this.baseCurrency = baseCurrency;
|
this.baseCurrency = baseCurrency;
|
||||||
this.items = items;
|
this.items = items;
|
||||||
this.itemsTransactions = transformToMap(itemsTransactions, 'itemId');
|
this.itemsTransactions = transformToMap(itemsTransactions, 'itemId');
|
||||||
@@ -98,7 +96,7 @@ export default class InventoryValuationReport extends FinancialSheet {
|
|||||||
* @param {IInventoryValuationItem} item
|
* @param {IInventoryValuationItem} item
|
||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
private itemSectionMapper = (item: IItem): IInventoryValuationItem => {
|
private itemSectionMapper = (item: IItem): IPurchasesByItemsItem => {
|
||||||
const meta = this.getItemTransaction(item.id);
|
const meta = this.getItemTransaction(item.id);
|
||||||
|
|
||||||
return {
|
return {
|
||||||
@@ -145,9 +143,9 @@ export default class InventoryValuationReport extends FinancialSheet {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the items sections.
|
* Retrieve the items sections.
|
||||||
* @returns {IInventoryValuationItem[]}
|
* @returns {IPurchasesByItemsItem[]}
|
||||||
*/
|
*/
|
||||||
private itemsSection = (): IInventoryValuationItem[] => {
|
private itemsSection = (): IPurchasesByItemsItem[] => {
|
||||||
return R.compose(
|
return R.compose(
|
||||||
R.when(this.isItemsPostFilter, this.itemsFilter),
|
R.when(this.isItemsPostFilter, this.itemsFilter),
|
||||||
this.itemsMapper
|
this.itemsMapper
|
||||||
@@ -156,10 +154,10 @@ export default class InventoryValuationReport extends FinancialSheet {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the total section of the sheet.
|
* Retrieve the total section of the sheet.
|
||||||
* @param {IInventoryValuationItem[]} items
|
* @param {IPurchasesByItemsItem[]} items
|
||||||
* @returns {IInventoryValuationTotal}
|
* @returns {IPurchasesByItemsTotal}
|
||||||
*/
|
*/
|
||||||
totalSection(items: IInventoryValuationItem[]): IInventoryValuationTotal {
|
private totalSection(items: IPurchasesByItemsItem[]): IPurchasesByItemsTotal {
|
||||||
const quantityPurchased = sumBy(items, (item) => item.quantityPurchased);
|
const quantityPurchased = sumBy(items, (item) => item.quantityPurchased);
|
||||||
const purchaseCost = sumBy(items, (item) => item.purchaseCost);
|
const purchaseCost = sumBy(items, (item) => item.purchaseCost);
|
||||||
|
|
||||||
@@ -176,12 +174,12 @@ export default class InventoryValuationReport extends FinancialSheet {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the sheet data.
|
* Retrieve the sheet data.
|
||||||
* @returns
|
* @returns {IInventoryValuationStatement}
|
||||||
*/
|
*/
|
||||||
reportData(): IInventoryValuationStatement {
|
public reportData(): IPurchasesByItemsSheetData {
|
||||||
const items = this.itemsSection();
|
const items = this.itemsSection();
|
||||||
const total = this.totalSection(items);
|
const total = this.totalSection(items);
|
||||||
|
|
||||||
return items.length > 0 ? { items, total } : {};
|
return { items, total };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,73 @@
|
|||||||
|
import { Service, Inject } from 'typedi';
|
||||||
|
import { PurchasesByItemsExport } from './PurchasesByItemsExport';
|
||||||
|
import {
|
||||||
|
IPurchasesByItemsReportQuery,
|
||||||
|
IPurchasesByItemsSheet,
|
||||||
|
IPurchasesByItemsTable,
|
||||||
|
} from '@/interfaces/PurchasesByItemsSheet';
|
||||||
|
import { PurchasesByItemsTableInjectable } from './PurchasesByItemsTableInjectable';
|
||||||
|
import { PurchasesByItemsService } from './PurchasesByItemsService';
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export class PurcahsesByItemsApplication {
|
||||||
|
@Inject()
|
||||||
|
private purchasesByItemsSheet: PurchasesByItemsService;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private purchasesByItemsTable: PurchasesByItemsTableInjectable;
|
||||||
|
|
||||||
|
@Inject()
|
||||||
|
private purchasesByItemsExport: PurchasesByItemsExport;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the purchases by items in json format.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IPurchasesByItemsReportQuery} query
|
||||||
|
* @returns
|
||||||
|
*/
|
||||||
|
public sheet(
|
||||||
|
tenantId: number,
|
||||||
|
query: IPurchasesByItemsReportQuery
|
||||||
|
): Promise<IPurchasesByItemsSheet> {
|
||||||
|
return this.purchasesByItemsSheet.purchasesByItems(tenantId, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the purchases by items in table format.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IPurchasesByItemsReportQuery} query
|
||||||
|
* @returns {Promise<IPurchasesByItemsTable>}
|
||||||
|
*/
|
||||||
|
public table(
|
||||||
|
tenantId: number,
|
||||||
|
query: IPurchasesByItemsReportQuery
|
||||||
|
): Promise<IPurchasesByItemsTable> {
|
||||||
|
return this.purchasesByItemsTable.table(tenantId, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the purchases by items in csv format.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IPurchasesByItemsReportQuery} query
|
||||||
|
* @returns {Promise<string>}
|
||||||
|
*/
|
||||||
|
public csv(
|
||||||
|
tenantId: number,
|
||||||
|
query: IPurchasesByItemsReportQuery
|
||||||
|
): Promise<string> {
|
||||||
|
return this.purchasesByItemsExport.csv(tenantId, query);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the purchases by items in xlsx format.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IPurchasesByItemsReportQuery} query
|
||||||
|
* @returns {Promise<Buffer>}
|
||||||
|
*/
|
||||||
|
public xlsx(
|
||||||
|
tenantId: number,
|
||||||
|
query: IPurchasesByItemsReportQuery
|
||||||
|
): Promise<Buffer> {
|
||||||
|
return this.purchasesByItemsExport.xlsx(tenantId, query);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -0,0 +1,46 @@
|
|||||||
|
import { Inject, Service } from 'typedi';
|
||||||
|
import { TableSheet } from '@/lib/Xlsx/TableSheet';
|
||||||
|
import { PurchasesByItemsTableInjectable } from './PurchasesByItemsTableInjectable';
|
||||||
|
import { IPurchasesByItemsReportQuery } from '@/interfaces/PurchasesByItemsSheet';
|
||||||
|
|
||||||
|
@Service()
|
||||||
|
export class PurchasesByItemsExport {
|
||||||
|
@Inject()
|
||||||
|
private purchasesByItemsTable: PurchasesByItemsTableInjectable;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the purchases by items sheet in XLSX format.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IPurchasesByItemsReportQuery} query
|
||||||
|
* @returns {Promise<Buffer>}
|
||||||
|
*/
|
||||||
|
public async xlsx(
|
||||||
|
tenantId: number,
|
||||||
|
query: IPurchasesByItemsReportQuery
|
||||||
|
): Promise<Buffer> {
|
||||||
|
const table = await this.purchasesByItemsTable.table(tenantId, query);
|
||||||
|
|
||||||
|
const tableSheet = new TableSheet(table.table);
|
||||||
|
const tableCsv = tableSheet.convertToXLSX();
|
||||||
|
|
||||||
|
return tableSheet.convertToBuffer(tableCsv, 'xlsx');
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the purchases by items sheet in CSV format.
|
||||||
|
* @param {number} tenantId
|
||||||
|
* @param {IPurchasesByItemsReportQuery} query
|
||||||
|
* @returns {Promise<Buffer>}
|
||||||
|
*/
|
||||||
|
public async csv(
|
||||||
|
tenantId: number,
|
||||||
|
query: IPurchasesByItemsReportQuery
|
||||||
|
): Promise<string> {
|
||||||
|
const table = await this.purchasesByItemsTable.table(tenantId, query);
|
||||||
|
|
||||||
|
const tableSheet = new TableSheet(table.table);
|
||||||
|
const tableCsv = tableSheet.convertToCSV();
|
||||||
|
|
||||||
|
return tableCsv;
|
||||||
|
}
|
||||||
|
}
|
||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user