mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-13 11:20:31 +00:00
Compare commits
40 Commits
patch-3
...
bugs-bashi
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d42a1c67a | ||
|
|
339289be9f | ||
|
|
350d229e98 | ||
|
|
8152a16fd5 | ||
|
|
00aad6e35c | ||
|
|
30d8fdb4c0 | ||
|
|
872fc661ce | ||
|
|
054cd1fae4 | ||
|
|
7cb169bce9 | ||
|
|
f2663c4af3 | ||
|
|
6fea7779da | ||
|
|
c00af18327 | ||
|
|
37f0f4e227 | ||
|
|
8662c5899e | ||
|
|
a9a7cd8617 | ||
|
|
e50fc3b523 | ||
|
|
b294a72a26 | ||
|
|
62ae49941b | ||
|
|
31f5cbf335 | ||
|
|
b22328cff9 | ||
|
|
58f609353c | ||
|
|
8a2a8eed3b | ||
|
|
636d206b0e | ||
|
|
63922c391a | ||
|
|
6ecfe1ff12 | ||
|
|
17651e0768 | ||
|
|
151b623771 | ||
|
|
2d4459c2f9 | ||
|
|
3cbdc3ec96 | ||
|
|
3cfb5cdde8 | ||
|
|
736f2c4109 | ||
|
|
2e21437056 | ||
|
|
340b78d968 | ||
|
|
d006362be2 | ||
|
|
bc21dcb37e | ||
|
|
578b0deb3e | ||
|
|
c3dc26a1e4 | ||
|
|
32d74b0413 | ||
|
|
71b1206f8a | ||
|
|
cb1bcaae77 |
@@ -168,6 +168,16 @@
|
|||||||
"contributions": [
|
"contributions": [
|
||||||
"bug"
|
"bug"
|
||||||
]
|
]
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"login": "Daniel15",
|
||||||
|
"name": "Daniel Lo Nigro",
|
||||||
|
"avatar_url": "https://avatars.githubusercontent.com/u/91933?v=4",
|
||||||
|
"profile": "https://d.sb/",
|
||||||
|
"contributions": [
|
||||||
|
"bug",
|
||||||
|
"code"
|
||||||
|
]
|
||||||
}
|
}
|
||||||
],
|
],
|
||||||
"contributorsPerLine": 7,
|
"contributorsPerLine": 7,
|
||||||
|
|||||||
@@ -135,6 +135,7 @@ Thanks goes to these wonderful people ([emoji key](https://allcontributors.org/d
|
|||||||
<td align="center" valign="top" width="14.28%"><a href="https://myself.vercel.app/"><img src="https://avatars.githubusercontent.com/u/42431274?v=4?s=100" width="100px;" alt="Sachin Mittal"/><br /><sub><b>Sachin Mittal</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/issues?q=author%3Amittalsam98" title="Bug reports">🐛</a></td>
|
<td align="center" valign="top" width="14.28%"><a href="https://myself.vercel.app/"><img src="https://avatars.githubusercontent.com/u/42431274?v=4?s=100" width="100px;" alt="Sachin Mittal"/><br /><sub><b>Sachin Mittal</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/issues?q=author%3Amittalsam98" title="Bug reports">🐛</a></td>
|
||||||
<td align="center" valign="top" width="14.28%"><a href="https://www.camilooviedo.com/"><img src="https://avatars.githubusercontent.com/u/64604272?v=4?s=100" width="100px;" alt="Camilo Oviedo"/><br /><sub><b>Camilo Oviedo</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/commits?author=Champetaman" title="Code">💻</a></td>
|
<td align="center" valign="top" width="14.28%"><a href="https://www.camilooviedo.com/"><img src="https://avatars.githubusercontent.com/u/64604272?v=4?s=100" width="100px;" alt="Camilo Oviedo"/><br /><sub><b>Camilo Oviedo</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/commits?author=Champetaman" title="Code">💻</a></td>
|
||||||
<td align="center" valign="top" width="14.28%"><a href="https://nklmantey.com/"><img src="https://avatars.githubusercontent.com/u/90279429?v=4?s=100" width="100px;" alt="Mantey"/><br /><sub><b>Mantey</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/issues?q=author%3Anklmantey" title="Bug reports">🐛</a></td>
|
<td align="center" valign="top" width="14.28%"><a href="https://nklmantey.com/"><img src="https://avatars.githubusercontent.com/u/90279429?v=4?s=100" width="100px;" alt="Mantey"/><br /><sub><b>Mantey</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/issues?q=author%3Anklmantey" title="Bug reports">🐛</a></td>
|
||||||
|
<td align="center" valign="top" width="14.28%"><a href="https://d.sb/"><img src="https://avatars.githubusercontent.com/u/91933?v=4?s=100" width="100px;" alt="Daniel Lo Nigro"/><br /><sub><b>Daniel Lo Nigro</b></sub></a><br /><a href="https://github.com/bigcapitalhq/bigcapital/issues?q=author%3ADaniel15" title="Bug reports">🐛</a> <a href="https://github.com/bigcapitalhq/bigcapital/commits?author=Daniel15" title="Code">💻</a></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tbody>
|
</tbody>
|
||||||
</table>
|
</table>
|
||||||
|
|||||||
@@ -167,6 +167,9 @@
|
|||||||
"**/*.(t|j)s"
|
"**/*.(t|j)s"
|
||||||
],
|
],
|
||||||
"coverageDirectory": "../coverage",
|
"coverageDirectory": "../coverage",
|
||||||
"testEnvironment": "node"
|
"testEnvironment": "node",
|
||||||
|
"moduleNameMapper": {
|
||||||
|
"^@/(.*)$": "<rootDir>/$1"
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
5
packages/server/src/common/config/app.ts
Normal file
5
packages/server/src/common/config/app.ts
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
import { registerAs } from '@nestjs/config';
|
||||||
|
|
||||||
|
export default registerAs('app', () => ({
|
||||||
|
baseUrl: process.env.BASE_URL,
|
||||||
|
}));
|
||||||
@@ -1,3 +1,4 @@
|
|||||||
|
import app from './app';
|
||||||
import systemDatabase from './system-database';
|
import systemDatabase from './system-database';
|
||||||
import tenantDatabase from './tenant-database';
|
import tenantDatabase from './tenant-database';
|
||||||
import signup from './signup';
|
import signup from './signup';
|
||||||
@@ -18,6 +19,7 @@ import throttle from './throttle';
|
|||||||
import cloud from './cloud';
|
import cloud from './cloud';
|
||||||
|
|
||||||
export const config = [
|
export const config = [
|
||||||
|
app,
|
||||||
systemDatabase,
|
systemDatabase,
|
||||||
cloud,
|
cloud,
|
||||||
tenantDatabase,
|
tenantDatabase,
|
||||||
|
|||||||
@@ -7,53 +7,46 @@ import {
|
|||||||
} from '@nestjs/common';
|
} from '@nestjs/common';
|
||||||
import { type Observable } from 'rxjs';
|
import { type Observable } from 'rxjs';
|
||||||
import { map } from 'rxjs/operators';
|
import { map } from 'rxjs/operators';
|
||||||
|
import { mapKeysDeep } from '@/utils/deepdash';
|
||||||
|
|
||||||
export function camelToSnake<T = any>(value: T) {
|
export function camelToSnake<T = any>(value: T): T {
|
||||||
if (value === null || value === undefined) {
|
if (value === null || value === undefined) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
if (Array.isArray(value)) {
|
return mapKeysDeep(
|
||||||
return value.map(camelToSnake);
|
value,
|
||||||
}
|
(_value: string, key: any, parent: any, context: any) => {
|
||||||
if (typeof value === 'object' && !(value instanceof Date)) {
|
if (Array.isArray(parent)) {
|
||||||
return Object.fromEntries(
|
// tell mapKeysDeep to skip mapping inside this branch
|
||||||
Object.entries(value).map(([key, value]) => [
|
context.skipChildren = true;
|
||||||
key
|
return key;
|
||||||
.split(/(?=[A-Z])/)
|
}
|
||||||
.join('_')
|
return key
|
||||||
.toLowerCase(),
|
.split(/(?=[A-Z])/)
|
||||||
camelToSnake(value),
|
.join('_')
|
||||||
]),
|
.toLowerCase();
|
||||||
);
|
},
|
||||||
}
|
) as T;
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export function snakeToCamel<T = any>(value: T) {
|
export function snakeToCamel<T = any>(value: T): T {
|
||||||
if (value === null || value === undefined) {
|
if (value === null || value === undefined) {
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
|
return mapKeysDeep(
|
||||||
if (Array.isArray(value)) {
|
value,
|
||||||
return value.map(snakeToCamel);
|
(_value: string, key: any, parent: any, context: any) => {
|
||||||
}
|
if (Array.isArray(parent)) {
|
||||||
|
// tell mapKeysDeep to skip mapping inside this branch
|
||||||
const impl = (str: string) => {
|
context.skipChildren = true;
|
||||||
const converted = str.replace(/([-_]\w)/g, (group) =>
|
return key;
|
||||||
group[1].toUpperCase(),
|
}
|
||||||
);
|
const converted = key.replace(/([-_]\w)/g, (group) =>
|
||||||
return converted[0].toLowerCase() + converted.slice(1);
|
group[1].toUpperCase(),
|
||||||
};
|
);
|
||||||
|
return converted[0].toLowerCase() + converted.slice(1);
|
||||||
if (typeof value === 'object' && !(value instanceof Date)) {
|
},
|
||||||
return Object.fromEntries(
|
) as T;
|
||||||
Object.entries(value).map(([key, value]) => [
|
|
||||||
impl(key),
|
|
||||||
snakeToCamel(value),
|
|
||||||
]),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
return value;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
export const DEFAULT_STRATEGY = {
|
export const DEFAULT_STRATEGY = {
|
||||||
@@ -63,7 +56,7 @@ export const DEFAULT_STRATEGY = {
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SerializeInterceptor implements NestInterceptor<any, any> {
|
export class SerializeInterceptor implements NestInterceptor<any, any> {
|
||||||
constructor(@Optional() readonly strategy = DEFAULT_STRATEGY) {}
|
constructor(@Optional() readonly strategy = DEFAULT_STRATEGY) { }
|
||||||
|
|
||||||
intercept(
|
intercept(
|
||||||
context: ExecutionContext,
|
context: ExecutionContext,
|
||||||
|
|||||||
@@ -1,4 +1,27 @@
|
|||||||
// import { getTransactionsLockingSettingsSchema } from '@/api/controllers/TransactionsLocking/utils';
|
import { chain, mapKeys } from 'lodash';
|
||||||
|
|
||||||
|
const getTransactionsLockingSettingsSchema = (modules: string[]) => {
|
||||||
|
const moduleSchema = {
|
||||||
|
active: { type: 'boolean' },
|
||||||
|
lock_to_date: { type: 'date' },
|
||||||
|
unlock_from_date: { type: 'date' },
|
||||||
|
unlock_to_date: { type: 'date' },
|
||||||
|
lock_reason: { type: 'string' },
|
||||||
|
unlock_reason: { type: 'string' },
|
||||||
|
};
|
||||||
|
return chain(modules)
|
||||||
|
.map((module: string) => {
|
||||||
|
return mapKeys(moduleSchema, (value, key: string) => `${module}.${key}`);
|
||||||
|
})
|
||||||
|
.flattenDeep()
|
||||||
|
.reduce((result, value) => {
|
||||||
|
return {
|
||||||
|
...result,
|
||||||
|
...value,
|
||||||
|
};
|
||||||
|
}, {})
|
||||||
|
.value();
|
||||||
|
};
|
||||||
|
|
||||||
export const SettingsOptions = {
|
export const SettingsOptions = {
|
||||||
organization: {
|
organization: {
|
||||||
@@ -223,12 +246,12 @@ export const SettingsOptions = {
|
|||||||
'locking-type': {
|
'locking-type': {
|
||||||
type: 'string',
|
type: 'string',
|
||||||
},
|
},
|
||||||
// ...getTransactionsLockingSettingsSchema([
|
...getTransactionsLockingSettingsSchema([
|
||||||
// 'all',
|
'all',
|
||||||
// 'sales',
|
'sales',
|
||||||
// 'purchases',
|
'purchases',
|
||||||
// 'financial',
|
'financial',
|
||||||
// ]),
|
]),
|
||||||
},
|
},
|
||||||
features: {
|
features: {
|
||||||
'multi-warehouses': {
|
'multi-warehouses': {
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
"field.description": "Description",
|
"field.description": "Description",
|
||||||
"field.slug": "Account slug",
|
"field.slug": "Account slug",
|
||||||
"field.code": "Account code",
|
"field.code": "Account code",
|
||||||
|
"field.code_hint": "Unique number to identify the account.",
|
||||||
"field.root_type": "Root type",
|
"field.root_type": "Root type",
|
||||||
"field.normal": "Account normal",
|
"field.normal": "Account normal",
|
||||||
"field.normal.credit": "Credit",
|
"field.normal.credit": "Credit",
|
||||||
@@ -13,5 +14,6 @@
|
|||||||
"field.balance": "Balance",
|
"field.balance": "Balance",
|
||||||
"field.bank_balance": "Bank Balance",
|
"field.bank_balance": "Bank Balance",
|
||||||
"field.parent_account": "Parent Account",
|
"field.parent_account": "Parent Account",
|
||||||
"field.created_at": "Created at"
|
"field.created_at": "Created at",
|
||||||
|
"field.account_hint": "Matches the account name or code."
|
||||||
}
|
}
|
||||||
|
|||||||
27
packages/server/src/i18n/en/bill.json
Normal file
27
packages/server/src/i18n/en/bill.json
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"field.vendor": "Vendor",
|
||||||
|
"field.bill_number": "Bill No.",
|
||||||
|
"field.bill_date": "Date",
|
||||||
|
"field.due_date": "Due Date",
|
||||||
|
"field.reference_no": "Reference No.",
|
||||||
|
"field.exchange_rate": "Exchange Rate",
|
||||||
|
"field.note": "Note",
|
||||||
|
"field.open": "Open",
|
||||||
|
"field.entries": "Entries",
|
||||||
|
"field.item": "Item",
|
||||||
|
"field.item_hint": "Matches the item name or code.",
|
||||||
|
"field.rate": "Rate",
|
||||||
|
"field.quantity": "Quantity",
|
||||||
|
"field.description": "Line Description",
|
||||||
|
"field.amount": "Amount",
|
||||||
|
"field.payment_amount": "Payment Amount",
|
||||||
|
"field.status": "Status",
|
||||||
|
"field.status.paid": "Paid",
|
||||||
|
"field.status.partially-paid": "Partially Paid",
|
||||||
|
"field.status.overdue": "Overdue",
|
||||||
|
"field.status.unpaid": "Unpaid",
|
||||||
|
"field.status.opened": "Opened",
|
||||||
|
"field.status.draft": "Draft",
|
||||||
|
"field.created_at": "Created At"
|
||||||
|
}
|
||||||
|
|
||||||
15
packages/server/src/i18n/en/bill_payment.json
Normal file
15
packages/server/src/i18n/en/bill_payment.json
Normal file
@@ -0,0 +1,15 @@
|
|||||||
|
{
|
||||||
|
"field.vendor": "Vendor",
|
||||||
|
"field.payment_date": "Payment Date",
|
||||||
|
"field.payment_number": "Payment No.",
|
||||||
|
"field.payment_account": "Payment Account",
|
||||||
|
"field.exchange_rate": "Exchange Rate",
|
||||||
|
"field.note": "Note",
|
||||||
|
"field.reference": "Reference",
|
||||||
|
"field.entries": "Entries",
|
||||||
|
"field.entries.bill": "Bill",
|
||||||
|
"field.entries.payment_amount": "Payment Amount",
|
||||||
|
"field.payment_number_hint": "The payment number should be unique.",
|
||||||
|
"field.bill_hint": "Matches the bill number."
|
||||||
|
}
|
||||||
|
|
||||||
16
packages/server/src/i18n/en/credit_note.json
Normal file
16
packages/server/src/i18n/en/credit_note.json
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
{
|
||||||
|
"field.customer": "Customer",
|
||||||
|
"field.exchange_rate": "Exchange Rate",
|
||||||
|
"field.credit_note_date": "Credit Note Date",
|
||||||
|
"field.reference_no": "Reference No.",
|
||||||
|
"field.note": "Note",
|
||||||
|
"field.terms_conditions": "Terms & Conditions",
|
||||||
|
"field.credit_note_number": "Credit Note Number",
|
||||||
|
"field.open": "Open",
|
||||||
|
"field.entries": "Entries",
|
||||||
|
"field.item": "Item",
|
||||||
|
"field.rate": "Rate",
|
||||||
|
"field.quantity": "Quantity",
|
||||||
|
"field.description": "Description"
|
||||||
|
}
|
||||||
|
|
||||||
21
packages/server/src/i18n/en/estimate.json
Normal file
21
packages/server/src/i18n/en/estimate.json
Normal file
@@ -0,0 +1,21 @@
|
|||||||
|
{
|
||||||
|
"field.customer": "Customer",
|
||||||
|
"field.estimate_date": "Estimate Date",
|
||||||
|
"field.expiration_date": "Expiration Date",
|
||||||
|
"field.estimate_number": "Estimate No.",
|
||||||
|
"field.reference_no": "Reference No.",
|
||||||
|
"field.exchange_rate": "Exchange Rate",
|
||||||
|
"field.currency": "Currency",
|
||||||
|
"field.note": "Note",
|
||||||
|
"field.terms_conditions": "Terms & Conditions",
|
||||||
|
"field.delivered": "Delivered",
|
||||||
|
"field.entries": "Entries",
|
||||||
|
"field.amount": "Amount",
|
||||||
|
"field.status": "Status",
|
||||||
|
"field.status.draft": "Draft",
|
||||||
|
"field.status.delivered": "Delivered",
|
||||||
|
"field.status.rejected": "Rejected",
|
||||||
|
"field.status.approved": "Approved",
|
||||||
|
"field.created_at": "Created At"
|
||||||
|
}
|
||||||
|
|
||||||
@@ -26,6 +26,7 @@
|
|||||||
"field.due_amount": "Due amount",
|
"field.due_amount": "Due amount",
|
||||||
"field.delivered": "Delivered",
|
"field.delivered": "Delivered",
|
||||||
"field.item_name": "Item Name",
|
"field.item_name": "Item Name",
|
||||||
|
"field.item_hint": "Matches the item name or code.",
|
||||||
"field.rate": "Rate",
|
"field.rate": "Rate",
|
||||||
"field.quantity": "Quantity",
|
"field.quantity": "Quantity",
|
||||||
"field.description": "Description",
|
"field.description": "Description",
|
||||||
@@ -38,5 +39,7 @@
|
|||||||
"field.status.draft": "Draft",
|
"field.status.draft": "Draft",
|
||||||
"field.created_at": "Created at",
|
"field.created_at": "Created at",
|
||||||
"field.currency": "Currency",
|
"field.currency": "Currency",
|
||||||
"field.entries": "Entries"
|
"field.entries": "Entries",
|
||||||
|
"field.branch": "Branch",
|
||||||
|
"field.warehouse": "Warehouse"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,6 +17,7 @@
|
|||||||
"field.quantity_on_hand": "Quantity on Hand",
|
"field.quantity_on_hand": "Quantity on Hand",
|
||||||
"field.note": "Note",
|
"field.note": "Note",
|
||||||
"field.category": "Category",
|
"field.category": "Category",
|
||||||
|
"field.category_hint": "Matches the category name.",
|
||||||
"field.active": "Active",
|
"field.active": "Active",
|
||||||
"field.created_at": "Created At"
|
"field.created_at": "Created At"
|
||||||
}
|
}
|
||||||
|
|||||||
17
packages/server/src/i18n/en/payment_receive.json
Normal file
17
packages/server/src/i18n/en/payment_receive.json
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
{
|
||||||
|
"field.customer": "Customer",
|
||||||
|
"field.payment_date": "Payment Date",
|
||||||
|
"field.amount": "Amount",
|
||||||
|
"field.reference_no": "Reference No.",
|
||||||
|
"field.deposit_account": "Deposit Account",
|
||||||
|
"field.payment_receive_no": "Payment No.",
|
||||||
|
"field.statement": "Statement",
|
||||||
|
"field.entries": "Entries",
|
||||||
|
"field.exchange_rate": "Exchange Rate",
|
||||||
|
"field.invoice": "Invoice",
|
||||||
|
"field.entries.payment_amount": "Payment Amount",
|
||||||
|
"field.created_at": "Created At",
|
||||||
|
"field.payment_no_hint": "The payment number should be unique.",
|
||||||
|
"field.invoice_hint": "Matches the invoice number."
|
||||||
|
}
|
||||||
|
|
||||||
@@ -10,5 +10,21 @@
|
|||||||
"paper.receipt_amount": "Receipt amount",
|
"paper.receipt_amount": "Receipt amount",
|
||||||
"paper.total": "Total",
|
"paper.total": "Total",
|
||||||
"paper.balance_due": "Balance Due",
|
"paper.balance_due": "Balance Due",
|
||||||
"paper.payment_amount": "Payment Amount"
|
"paper.payment_amount": "Payment Amount",
|
||||||
|
|
||||||
|
"field.receipt_date": "Receipt Date",
|
||||||
|
"field.customer": "Customer",
|
||||||
|
"field.deposit_account": "Deposit Account",
|
||||||
|
"field.exchange_rate": "Exchange Rate",
|
||||||
|
"field.receipt_number": "Receipt Number",
|
||||||
|
"field.reference_no": "Reference No.",
|
||||||
|
"field.closed": "Closed",
|
||||||
|
"field.entries": "Entries",
|
||||||
|
"field.statement": "Statement",
|
||||||
|
"field.receipt_message": "Receipt Message",
|
||||||
|
"field.amount": "Amount",
|
||||||
|
"field.status": "Status",
|
||||||
|
"field.status.draft": "Draft",
|
||||||
|
"field.status.closed": "Closed",
|
||||||
|
"field.created_at": "Created At"
|
||||||
}
|
}
|
||||||
@@ -2,5 +2,18 @@
|
|||||||
"view.draft": "Draft",
|
"view.draft": "Draft",
|
||||||
"view.published": "Published",
|
"view.published": "Published",
|
||||||
"view.open": "Open",
|
"view.open": "Open",
|
||||||
"view.closed": "Closed"
|
"view.closed": "Closed",
|
||||||
|
|
||||||
|
"field.vendor": "Vendor",
|
||||||
|
"field.vendor_credit_number": "Vendor Credit No.",
|
||||||
|
"field.vendor_credit_date": "Vendor Credit Date",
|
||||||
|
"field.reference_no": "Reference No.",
|
||||||
|
"field.exchange_rate": "Exchange Rate",
|
||||||
|
"field.note": "Note",
|
||||||
|
"field.open": "Open",
|
||||||
|
"field.entries": "Entries",
|
||||||
|
"field.item": "Item",
|
||||||
|
"field.rate": "Rate",
|
||||||
|
"field.quantity": "Quantity",
|
||||||
|
"field.description": "Description"
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { ServiceErrorFilter } from './common/filters/service-error.filter';
|
|||||||
import { ModelHasRelationsFilter } from './common/filters/model-has-relations.filter';
|
import { ModelHasRelationsFilter } from './common/filters/model-has-relations.filter';
|
||||||
import { ValidationPipe } from './common/pipes/ClassValidation.pipe';
|
import { ValidationPipe } from './common/pipes/ClassValidation.pipe';
|
||||||
import { ToJsonInterceptor } from './common/interceptors/to-json.interceptor';
|
import { ToJsonInterceptor } from './common/interceptors/to-json.interceptor';
|
||||||
|
import { NestExpressApplication } from '@nestjs/platform-express';
|
||||||
|
|
||||||
global.__public_dirname = path.join(__dirname, '..', 'public');
|
global.__public_dirname = path.join(__dirname, '..', 'public');
|
||||||
global.__static_dirname = path.join(__dirname, '../static');
|
global.__static_dirname = path.join(__dirname, '../static');
|
||||||
@@ -15,7 +16,10 @@ global.__views_dirname = path.join(global.__static_dirname, '/views');
|
|||||||
global.__images_dirname = path.join(global.__static_dirname, '/images');
|
global.__images_dirname = path.join(global.__static_dirname, '/images');
|
||||||
|
|
||||||
async function bootstrap() {
|
async function bootstrap() {
|
||||||
const app = await NestFactory.create(AppModule, { rawBody: true });
|
const app = await NestFactory.create<NestExpressApplication>(AppModule, {
|
||||||
|
rawBody: true,
|
||||||
|
});
|
||||||
|
app.set('query parser', 'extended');
|
||||||
app.setGlobalPrefix('/api');
|
app.setGlobalPrefix('/api');
|
||||||
|
|
||||||
// create and mount the middleware manually here
|
// create and mount the middleware manually here
|
||||||
|
|||||||
@@ -156,7 +156,7 @@ export const AccountMeta = {
|
|||||||
minLength: 3,
|
minLength: 3,
|
||||||
maxLength: 6,
|
maxLength: 6,
|
||||||
unique: true,
|
unique: true,
|
||||||
importHint: 'Unique number to identify the account.',
|
importHint: 'account.field.code_hint',
|
||||||
},
|
},
|
||||||
accountType: {
|
accountType: {
|
||||||
name: 'account.field.type',
|
name: 'account.field.type',
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
import { Inject, Injectable } from '@nestjs/common';
|
import { Inject, Injectable } from '@nestjs/common';
|
||||||
import { Knex } from 'knex';
|
import { Knex } from 'knex';
|
||||||
import * as yup from 'yup';
|
import * as yup from 'yup';
|
||||||
import uniqid from 'uniqid';
|
import * as uniqid from 'uniqid';
|
||||||
import { Importable } from '../../Import/Importable';
|
import { Importable } from '../../Import/Importable';
|
||||||
import { CreateUncategorizedTransactionService } from './CreateUncategorizedTransaction.service';
|
import { CreateUncategorizedTransactionService } from './CreateUncategorizedTransaction.service';
|
||||||
import { ImportableContext } from '../../Import/interfaces';
|
import { ImportableContext } from '../../Import/interfaces';
|
||||||
@@ -9,8 +9,10 @@ import { BankTransactionsSampleData } from '../../BankingTransactions/constants'
|
|||||||
import { Account } from '@/modules/Accounts/models/Account.model';
|
import { Account } from '@/modules/Accounts/models/Account.model';
|
||||||
import { CreateUncategorizedTransactionDTO } from '../types/BankingCategorize.types';
|
import { CreateUncategorizedTransactionDTO } from '../types/BankingCategorize.types';
|
||||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
|
import { ImportableService } from '../../Import/decorators/Import.decorator';
|
||||||
|
import { UncategorizedBankTransaction } from '../../BankingTransactions/models/UncategorizedBankTransaction';
|
||||||
@Injectable()
|
@Injectable()
|
||||||
|
@ImportableService({ name: UncategorizedBankTransaction.name })
|
||||||
export class UncategorizedTransactionsImportable extends Importable {
|
export class UncategorizedTransactionsImportable extends Importable {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly createUncategorizedTransaction: CreateUncategorizedTransactionService,
|
private readonly createUncategorizedTransaction: CreateUncategorizedTransactionService,
|
||||||
|
|||||||
@@ -1,6 +1,6 @@
|
|||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
import * as R from 'ramda';
|
import * as R from 'ramda';
|
||||||
import { isEmpty, sumBy } from 'lodash';
|
import { isEmpty, round, sumBy } from 'lodash';
|
||||||
import { ERRORS, MatchedTransactionPOJO } from './types';
|
import { ERRORS, MatchedTransactionPOJO } from './types';
|
||||||
import { ServiceError } from '../Items/ServiceError';
|
import { ServiceError } from '../Items/ServiceError';
|
||||||
|
|
||||||
@@ -22,18 +22,24 @@ export const sortClosestMatchTransactions = (
|
|||||||
};
|
};
|
||||||
|
|
||||||
export const sumMatchTranasctions = (transactions: Array<any>) => {
|
export const sumMatchTranasctions = (transactions: Array<any>) => {
|
||||||
return transactions.reduce(
|
const total = transactions.reduce(
|
||||||
(total, item) =>
|
(sum, item) => {
|
||||||
total +
|
const amount = parseFloat(item.amount) || 0;
|
||||||
(item.transactionNormal === 'debit' ? 1 : -1) * parseFloat(item.amount),
|
const multiplier = item.transactionNormal === 'debit' ? 1 : -1;
|
||||||
|
return sum + multiplier * amount;
|
||||||
|
},
|
||||||
0
|
0
|
||||||
);
|
);
|
||||||
|
// Round to 2 decimal places to avoid floating-point precision issues
|
||||||
|
return round(total, 2);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const sumUncategorizedTransactions = (
|
export const sumUncategorizedTransactions = (
|
||||||
uncategorizedTransactions: Array<any>
|
uncategorizedTransactions: Array<any>
|
||||||
) => {
|
) => {
|
||||||
return sumBy(uncategorizedTransactions, 'amount');
|
const total = sumBy(uncategorizedTransactions, 'amount');
|
||||||
|
// Round to 2 decimal places to avoid floating-point precision issues
|
||||||
|
return round(total, 2);
|
||||||
};
|
};
|
||||||
|
|
||||||
export const validateUncategorizedTransactionsNotMatched = (
|
export const validateUncategorizedTransactionsNotMatched = (
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ export class MatchBankTransactions {
|
|||||||
private readonly uncategorizedBankTransactionModel: TenantModelProxy<
|
private readonly uncategorizedBankTransactionModel: TenantModelProxy<
|
||||||
typeof UncategorizedBankTransaction
|
typeof UncategorizedBankTransaction
|
||||||
>,
|
>,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the match bank transactions DTO.
|
* Validates the match bank transactions DTO.
|
||||||
@@ -100,7 +100,10 @@ export class MatchBankTransactions {
|
|||||||
);
|
);
|
||||||
// Validates the total given matching transcations whether is not equal
|
// Validates the total given matching transcations whether is not equal
|
||||||
// uncategorized transaction amount.
|
// uncategorized transaction amount.
|
||||||
if (totalUncategorizedTransactions !== totalMatchedTranasctions) {
|
// Use tolerance-based comparison to handle floating-point precision issues
|
||||||
|
const tolerance = 0.01; // Allow 0.01 difference for floating-point precision
|
||||||
|
const difference = Math.abs(totalUncategorizedTransactions - totalMatchedTranasctions);
|
||||||
|
if (difference > tolerance) {
|
||||||
throw new ServiceError(ERRORS.TOTAL_MATCHING_TRANSACTIONS_INVALID);
|
throw new ServiceError(ERRORS.TOTAL_MATCHING_TRANSACTIONS_INVALID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,24 +12,30 @@ export class MatchTransactionsTypes {
|
|||||||
private static registry: MatchTransactionsTypesRegistry;
|
private static registry: MatchTransactionsTypesRegistry;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Consttuctor method.
|
* Constructor method.
|
||||||
*/
|
*/
|
||||||
constructor() {
|
constructor(
|
||||||
|
private readonly getMatchedInvoicesService: GetMatchedTransactionsByInvoices,
|
||||||
|
private readonly getMatchedBillsService: GetMatchedTransactionsByBills,
|
||||||
|
private readonly getMatchedExpensesService: GetMatchedTransactionsByExpenses,
|
||||||
|
private readonly getMatchedManualJournalsService: GetMatchedTransactionsByManualJournals,
|
||||||
|
private readonly getMatchedCashflowService: GetMatchedTransactionsByCashflow,
|
||||||
|
) {
|
||||||
this.boot();
|
this.boot();
|
||||||
}
|
}
|
||||||
|
|
||||||
get registered() {
|
get registered() {
|
||||||
return [
|
return [
|
||||||
{ type: 'SaleInvoice', service: GetMatchedTransactionsByInvoices },
|
{ type: 'SaleInvoice', service: this.getMatchedInvoicesService },
|
||||||
{ type: 'Bill', service: GetMatchedTransactionsByBills },
|
{ type: 'Bill', service: this.getMatchedBillsService },
|
||||||
{ type: 'Expense', service: GetMatchedTransactionsByExpenses },
|
{ type: 'Expense', service: this.getMatchedExpensesService },
|
||||||
{
|
{
|
||||||
type: 'ManualJournal',
|
type: 'ManualJournal',
|
||||||
service: GetMatchedTransactionsByManualJournals,
|
service: this.getMatchedManualJournalsService,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
type: 'CashflowTransaction',
|
type: 'CashflowTransaction',
|
||||||
service: GetMatchedTransactionsByCashflow,
|
service: this.getMatchedCashflowService,
|
||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@@ -50,14 +56,13 @@ export class MatchTransactionsTypes {
|
|||||||
* Boots all the registered importables.
|
* Boots all the registered importables.
|
||||||
*/
|
*/
|
||||||
public boot() {
|
public boot() {
|
||||||
if (!MatchTransactionsTypes.registry) {
|
const instance = MatchTransactionsTypesRegistry.getInstance();
|
||||||
const instance = MatchTransactionsTypesRegistry.getInstance();
|
|
||||||
|
|
||||||
this.registered.forEach((registered) => {
|
// Always register services to ensure they're available
|
||||||
// const serviceInstanace = Container.get(registered.service);
|
this.registered.forEach((registered) => {
|
||||||
// instance.register(registered.type, serviceInstanace);
|
instance.register(registered.type, registered.service);
|
||||||
});
|
});
|
||||||
MatchTransactionsTypes.registry = instance;
|
|
||||||
}
|
MatchTransactionsTypes.registry = instance;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -83,4 +83,4 @@ const models = [
|
|||||||
CreateBankTransactionService
|
CreateBankTransactionService
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
export class BankingTransactionsModule {}
|
export class BankingTransactionsModule { }
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
import { Type } from 'class-transformer';
|
import { Transform, Type } from 'class-transformer';
|
||||||
import {
|
import {
|
||||||
IsBoolean,
|
IsBoolean,
|
||||||
IsEnum,
|
IsEnum,
|
||||||
@@ -7,6 +7,7 @@ import {
|
|||||||
IsPositive,
|
IsPositive,
|
||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
import { ApiPropertyOptional } from '@nestjs/swagger';
|
import { ApiPropertyOptional } from '@nestjs/swagger';
|
||||||
|
import { parseBoolean } from '@/utils/parse-boolean';
|
||||||
|
|
||||||
export class NumberFormatQueryDto {
|
export class NumberFormatQueryDto {
|
||||||
@ApiPropertyOptional({
|
@ApiPropertyOptional({
|
||||||
@@ -24,6 +25,7 @@ export class NumberFormatQueryDto {
|
|||||||
example: false,
|
example: false,
|
||||||
})
|
})
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
|
@Transform(({ value }) => parseBoolean(value, false))
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
readonly divideOn1000: boolean;
|
readonly divideOn1000: boolean;
|
||||||
|
|
||||||
@@ -32,6 +34,7 @@ export class NumberFormatQueryDto {
|
|||||||
example: true,
|
example: true,
|
||||||
})
|
})
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
|
@Transform(({ value }) => parseBoolean(value, false))
|
||||||
@IsOptional()
|
@IsOptional()
|
||||||
readonly showZero: boolean;
|
readonly showZero: boolean;
|
||||||
|
|
||||||
|
|||||||
@@ -0,0 +1,72 @@
|
|||||||
|
export const UncategorizedBankTransactionMeta = {
|
||||||
|
defaultFilterField: 'createdAt',
|
||||||
|
defaultSort: {
|
||||||
|
sortOrder: 'DESC',
|
||||||
|
sortField: 'created_at',
|
||||||
|
},
|
||||||
|
importable: true,
|
||||||
|
fields: {
|
||||||
|
date: {
|
||||||
|
name: 'Date',
|
||||||
|
column: 'date',
|
||||||
|
fieldType: 'date',
|
||||||
|
},
|
||||||
|
payee: {
|
||||||
|
name: 'Payee',
|
||||||
|
column: 'payee',
|
||||||
|
fieldType: 'text',
|
||||||
|
},
|
||||||
|
description: {
|
||||||
|
name: 'Description',
|
||||||
|
column: 'description',
|
||||||
|
fieldType: 'text',
|
||||||
|
},
|
||||||
|
referenceNo: {
|
||||||
|
name: 'Reference No.',
|
||||||
|
column: 'reference_no',
|
||||||
|
fieldType: 'text',
|
||||||
|
},
|
||||||
|
amount: {
|
||||||
|
name: 'Amount',
|
||||||
|
column: 'Amount',
|
||||||
|
fieldType: 'numeric',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
account: {
|
||||||
|
name: 'Account',
|
||||||
|
column: 'account_id',
|
||||||
|
fieldType: 'relation',
|
||||||
|
to: { model: 'Account', to: 'id' },
|
||||||
|
},
|
||||||
|
createdAt: {
|
||||||
|
name: 'Created At',
|
||||||
|
column: 'createdAt',
|
||||||
|
fieldType: 'date',
|
||||||
|
importable: false,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
fields2: {
|
||||||
|
date: {
|
||||||
|
name: 'Date',
|
||||||
|
fieldType: 'date',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
payee: {
|
||||||
|
name: 'Payee',
|
||||||
|
fieldType: 'text',
|
||||||
|
},
|
||||||
|
description: {
|
||||||
|
name: 'Description',
|
||||||
|
fieldType: 'text',
|
||||||
|
},
|
||||||
|
referenceNo: {
|
||||||
|
name: 'Reference No.',
|
||||||
|
fieldType: 'text',
|
||||||
|
},
|
||||||
|
amount: {
|
||||||
|
name: 'Amount',
|
||||||
|
fieldType: 'number',
|
||||||
|
required: true,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
};
|
||||||
@@ -2,7 +2,10 @@
|
|||||||
import * as moment from 'moment';
|
import * as moment from 'moment';
|
||||||
import { Model } from 'objection';
|
import { Model } from 'objection';
|
||||||
import { TenantBaseModel } from '@/modules/System/models/TenantBaseModel';
|
import { TenantBaseModel } from '@/modules/System/models/TenantBaseModel';
|
||||||
|
import { UncategorizedBankTransactionMeta } from './UncategorizedBankTransaction.meta';
|
||||||
|
import { InjectModelMeta } from '@/modules/Tenancy/TenancyModels/decorators/InjectModelMeta.decorator';
|
||||||
|
|
||||||
|
@InjectModelMeta(UncategorizedBankTransactionMeta)
|
||||||
export class UncategorizedBankTransaction extends TenantBaseModel {
|
export class UncategorizedBankTransaction extends TenantBaseModel {
|
||||||
readonly amount!: number;
|
readonly amount!: number;
|
||||||
readonly date!: Date | string;
|
readonly date!: Date | string;
|
||||||
|
|||||||
@@ -104,6 +104,12 @@ export class BillPaymentResponseDto {
|
|||||||
@ApiProperty({ description: 'The formatted amount', example: '100.00 USD' })
|
@ApiProperty({ description: 'The formatted amount', example: '100.00 USD' })
|
||||||
formattedAmount: string;
|
formattedAmount: string;
|
||||||
|
|
||||||
|
@ApiProperty({ description: 'The formatted total', example: '100.00 USD' })
|
||||||
|
formattedTotal: string;
|
||||||
|
|
||||||
|
@ApiProperty({ description: 'The formatted subtotal', example: '100.00 USD' })
|
||||||
|
formattedSubtotal: string;
|
||||||
|
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
description: 'The date when the payment was created',
|
description: 'The date when the payment was created',
|
||||||
example: '2024-01-01T12:00:00Z',
|
example: '2024-01-01T12:00:00Z',
|
||||||
|
|||||||
@@ -167,7 +167,7 @@ export const BillPaymentMeta = {
|
|||||||
name: 'bill_payment.field.payment_number',
|
name: 'bill_payment.field.payment_number',
|
||||||
fieldType: 'text',
|
fieldType: 'text',
|
||||||
unique: true,
|
unique: true,
|
||||||
importHint: 'The payment number should be unique.',
|
importHint: 'bill_payment.field.payment_number_hint',
|
||||||
},
|
},
|
||||||
paymentAccountId: {
|
paymentAccountId: {
|
||||||
name: 'bill_payment.field.payment_account',
|
name: 'bill_payment.field.payment_account',
|
||||||
@@ -175,7 +175,7 @@ export const BillPaymentMeta = {
|
|||||||
relationModel: 'Account',
|
relationModel: 'Account',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
required: true,
|
required: true,
|
||||||
importHint: 'Matches the account name or code.',
|
importHint: 'account.field.account_hint',
|
||||||
},
|
},
|
||||||
exchangeRate: {
|
exchangeRate: {
|
||||||
name: 'bill_payment.field.exchange_rate',
|
name: 'bill_payment.field.exchange_rate',
|
||||||
@@ -203,7 +203,7 @@ export const BillPaymentMeta = {
|
|||||||
relationModel: 'Bill',
|
relationModel: 'Bill',
|
||||||
relationImportMatch: 'billNumber',
|
relationImportMatch: 'billNumber',
|
||||||
required: true,
|
required: true,
|
||||||
importHint: 'Matches the bill number.',
|
importHint: 'bill_payment.field.bill_hint',
|
||||||
},
|
},
|
||||||
paymentAmount: {
|
paymentAmount: {
|
||||||
name: 'bill_payment.field.entries.payment_amount',
|
name: 'bill_payment.field.entries.payment_amount',
|
||||||
@@ -213,7 +213,7 @@ export const BillPaymentMeta = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
branchId: {
|
branchId: {
|
||||||
name: 'Branch',
|
name: 'invoice.field.branch',
|
||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'Branch',
|
relationModel: 'Branch',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ export class BillPaymentTransformer extends Transformer {
|
|||||||
'formattedPaymentDate',
|
'formattedPaymentDate',
|
||||||
'formattedCreatedAt',
|
'formattedCreatedAt',
|
||||||
'formattedAmount',
|
'formattedAmount',
|
||||||
|
'formattedTotal',
|
||||||
|
'formattedSubtotal',
|
||||||
'entries',
|
'entries',
|
||||||
'attachments',
|
'attachments',
|
||||||
];
|
];
|
||||||
@@ -47,6 +49,29 @@ export class BillPaymentTransformer extends Transformer {
|
|||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the formatted total.
|
||||||
|
* @param {IBillPayment} billPayment
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
protected formattedTotal = (billPayment: BillPayment): string => {
|
||||||
|
return this.formatNumber(billPayment.amount, {
|
||||||
|
currencyCode: billPayment.currencyCode,
|
||||||
|
money: true,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the formatted subtotal.
|
||||||
|
* @param {IBillPayment} billPayment
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
protected formattedSubtotal = (billPayment: BillPayment): string => {
|
||||||
|
return this.formatNumber(billPayment.amount, {
|
||||||
|
currencyCode: billPayment.currencyCode,
|
||||||
|
});
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retreives the bill payment entries.
|
* Retreives the bill payment entries.
|
||||||
*/
|
*/
|
||||||
|
|||||||
@@ -184,76 +184,76 @@ export const BillMeta = {
|
|||||||
},
|
},
|
||||||
fields2: {
|
fields2: {
|
||||||
billNumber: {
|
billNumber: {
|
||||||
name: 'Bill No.',
|
name: 'bill.field.bill_number',
|
||||||
fieldType: 'text',
|
fieldType: 'text',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
referenceNo: {
|
referenceNo: {
|
||||||
name: 'Reference No.',
|
name: 'bill.field.reference_no',
|
||||||
fieldType: 'text',
|
fieldType: 'text',
|
||||||
},
|
},
|
||||||
billDate: {
|
billDate: {
|
||||||
name: 'Date',
|
name: 'bill.field.bill_date',
|
||||||
fieldType: 'date',
|
fieldType: 'date',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
dueDate: {
|
dueDate: {
|
||||||
name: 'Due Date',
|
name: 'bill.field.due_date',
|
||||||
fieldType: 'date',
|
fieldType: 'date',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
vendorId: {
|
vendorId: {
|
||||||
name: 'Vendor',
|
name: 'bill.field.vendor',
|
||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'Contact',
|
relationModel: 'Contact',
|
||||||
relationImportMatch: 'displayName',
|
relationImportMatch: 'displayName',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
exchangeRate: {
|
exchangeRate: {
|
||||||
name: 'Exchange Rate',
|
name: 'bill.field.exchange_rate',
|
||||||
fieldType: 'number',
|
fieldType: 'number',
|
||||||
},
|
},
|
||||||
note: {
|
note: {
|
||||||
name: 'Note',
|
name: 'bill.field.note',
|
||||||
fieldType: 'text',
|
fieldType: 'text',
|
||||||
},
|
},
|
||||||
open: {
|
open: {
|
||||||
name: 'Open',
|
name: 'bill.field.open',
|
||||||
fieldType: 'boolean',
|
fieldType: 'boolean',
|
||||||
},
|
},
|
||||||
entries: {
|
entries: {
|
||||||
name: 'Entries',
|
name: 'bill.field.entries',
|
||||||
fieldType: 'collection',
|
fieldType: 'collection',
|
||||||
collectionOf: 'object',
|
collectionOf: 'object',
|
||||||
collectionMinLength: 1,
|
collectionMinLength: 1,
|
||||||
required: true,
|
required: true,
|
||||||
fields: {
|
fields: {
|
||||||
itemId: {
|
itemId: {
|
||||||
name: 'Item',
|
name: 'bill.field.item',
|
||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'Item',
|
relationModel: 'Item',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
required: true,
|
required: true,
|
||||||
importHint: 'Matches the item name or code.',
|
importHint: 'bill.field.item_hint',
|
||||||
},
|
},
|
||||||
rate: {
|
rate: {
|
||||||
name: 'Rate',
|
name: 'bill.field.rate',
|
||||||
fieldType: 'number',
|
fieldType: 'number',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
quantity: {
|
quantity: {
|
||||||
name: 'Quantity',
|
name: 'bill.field.quantity',
|
||||||
fieldType: 'number',
|
fieldType: 'number',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
description: {
|
description: {
|
||||||
name: 'Line Description',
|
name: 'bill.field.description',
|
||||||
fieldType: 'text',
|
fieldType: 'text',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
branchId: {
|
branchId: {
|
||||||
name: 'Branch',
|
name: 'invoice.field.branch',
|
||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'Branch',
|
relationModel: 'Branch',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
@@ -261,7 +261,7 @@ export const BillMeta = {
|
|||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
warehouseId: {
|
warehouseId: {
|
||||||
name: 'Warehouse',
|
name: 'invoice.field.warehouse',
|
||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'Warehouse',
|
relationModel: 'Warehouse',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ export class BillTransformer extends Transformer {
|
|||||||
protected formattedDueAmount = (bill: Bill): string => {
|
protected formattedDueAmount = (bill: Bill): string => {
|
||||||
return this.formatNumber(bill.dueAmount, {
|
return this.formatNumber(bill.dueAmount, {
|
||||||
currencyCode: bill.currencyCode,
|
currencyCode: bill.currencyCode,
|
||||||
|
money: true,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -169,6 +170,7 @@ export class BillTransformer extends Transformer {
|
|||||||
protected totalFormatted = (bill: Bill): string => {
|
protected totalFormatted = (bill: Bill): string => {
|
||||||
return this.formatNumber(bill.total, {
|
return this.formatNumber(bill.total, {
|
||||||
currencyCode: bill.currencyCode,
|
currencyCode: bill.currencyCode,
|
||||||
|
money: true,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -164,73 +164,73 @@ export const CreditNoteMeta = {
|
|||||||
},
|
},
|
||||||
fields2: {
|
fields2: {
|
||||||
customerId: {
|
customerId: {
|
||||||
name: 'Customer',
|
name: 'credit_note.field.customer',
|
||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'Contact',
|
relationModel: 'Contact',
|
||||||
relationImportMatch: 'displayName',
|
relationImportMatch: 'displayName',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
exchangeRate: {
|
exchangeRate: {
|
||||||
name: 'Exchange Rate',
|
name: 'credit_note.field.exchange_rate',
|
||||||
fieldType: 'number',
|
fieldType: 'number',
|
||||||
},
|
},
|
||||||
creditNoteDate: {
|
creditNoteDate: {
|
||||||
name: 'Credit Note Date',
|
name: 'credit_note.field.credit_note_date',
|
||||||
fieldType: 'date',
|
fieldType: 'date',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
referenceNo: {
|
referenceNo: {
|
||||||
name: 'Reference No.',
|
name: 'credit_note.field.reference_no',
|
||||||
fieldType: 'text',
|
fieldType: 'text',
|
||||||
},
|
},
|
||||||
note: {
|
note: {
|
||||||
name: 'Note',
|
name: 'credit_note.field.note',
|
||||||
fieldType: 'text',
|
fieldType: 'text',
|
||||||
},
|
},
|
||||||
termsConditions: {
|
termsConditions: {
|
||||||
name: 'Terms & Conditions',
|
name: 'credit_note.field.terms_conditions',
|
||||||
fieldType: 'text',
|
fieldType: 'text',
|
||||||
},
|
},
|
||||||
creditNoteNumber: {
|
creditNoteNumber: {
|
||||||
name: 'Credit Note Number',
|
name: 'credit_note.field.credit_note_number',
|
||||||
fieldType: 'text',
|
fieldType: 'text',
|
||||||
},
|
},
|
||||||
open: {
|
open: {
|
||||||
name: 'Open',
|
name: 'credit_note.field.open',
|
||||||
fieldType: 'boolean',
|
fieldType: 'boolean',
|
||||||
},
|
},
|
||||||
entries: {
|
entries: {
|
||||||
name: 'Entries',
|
name: 'credit_note.field.entries',
|
||||||
fieldType: 'collection',
|
fieldType: 'collection',
|
||||||
collectionOf: 'object',
|
collectionOf: 'object',
|
||||||
collectionMinLength: 1,
|
collectionMinLength: 1,
|
||||||
fields: {
|
fields: {
|
||||||
itemId: {
|
itemId: {
|
||||||
name: 'Item',
|
name: 'credit_note.field.item',
|
||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'Item',
|
relationModel: 'Item',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
required: true,
|
required: true,
|
||||||
importHint: 'Matches the item name or code.',
|
importHint: 'invoice.field.item_hint',
|
||||||
},
|
},
|
||||||
rate: {
|
rate: {
|
||||||
name: 'Rate',
|
name: 'credit_note.field.rate',
|
||||||
fieldType: 'number',
|
fieldType: 'number',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
quantity: {
|
quantity: {
|
||||||
name: 'Quantity',
|
name: 'credit_note.field.quantity',
|
||||||
fieldType: 'number',
|
fieldType: 'number',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
description: {
|
description: {
|
||||||
name: 'Description',
|
name: 'credit_note.field.description',
|
||||||
fieldType: 'text',
|
fieldType: 'text',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
branchId: {
|
branchId: {
|
||||||
name: 'Branch',
|
name: 'invoice.field.branch',
|
||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'Branch',
|
relationModel: 'Branch',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
@@ -238,7 +238,7 @@ export const CreditNoteMeta = {
|
|||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
warehouseId: {
|
warehouseId: {
|
||||||
name: 'Warehouse',
|
name: 'invoice.field.warehouse',
|
||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'Warehouse',
|
relationModel: 'Warehouse',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
|
|||||||
@@ -90,7 +90,7 @@ export class CreditNoteTransformer extends Transformer {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
protected formattedSubtotal = (credit): string => {
|
protected formattedSubtotal = (credit): string => {
|
||||||
return this.formatNumber(credit.amount, { money: false });
|
return this.formatNumber(credit.amount);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -130,7 +130,7 @@ export class CreditNoteTransformer extends Transformer {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
protected adjustmentFormatted = (credit): string => {
|
protected adjustmentFormatted = (credit): string => {
|
||||||
return this.formatMoney(credit.adjustment, {
|
return this.formatNumber(credit.adjustment, {
|
||||||
currencyCode: credit.currencyCode,
|
currencyCode: credit.currencyCode,
|
||||||
excerptZero: true,
|
excerptZero: true,
|
||||||
});
|
});
|
||||||
@@ -156,6 +156,7 @@ export class CreditNoteTransformer extends Transformer {
|
|||||||
protected totalFormatted = (credit): string => {
|
protected totalFormatted = (credit): string => {
|
||||||
return this.formatNumber(credit.total, {
|
return this.formatNumber(credit.total, {
|
||||||
currencyCode: credit.currencyCode,
|
currencyCode: credit.currencyCode,
|
||||||
|
money: true,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -167,6 +168,7 @@ export class CreditNoteTransformer extends Transformer {
|
|||||||
protected totalLocalFormatted = (credit): string => {
|
protected totalLocalFormatted = (credit): string => {
|
||||||
return this.formatNumber(credit.totalLocal, {
|
return this.formatNumber(credit.totalLocal, {
|
||||||
currencyCode: credit.currencyCode,
|
currencyCode: credit.currencyCode,
|
||||||
|
money: true,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import { ExpensesSampleData } from './constants';
|
|||||||
import { CreateExpense } from './commands/CreateExpense.service';
|
import { CreateExpense } from './commands/CreateExpense.service';
|
||||||
import { CreateExpenseDto } from './dtos/Expense.dto';
|
import { CreateExpenseDto } from './dtos/Expense.dto';
|
||||||
import { ImportableService } from '../Import/decorators/Import.decorator';
|
import { ImportableService } from '../Import/decorators/Import.decorator';
|
||||||
import { ManualJournal } from '../ManualJournals/models/ManualJournal';
|
import { Expense } from './models/Expense.model';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ImportableService({ name: ManualJournal.name })
|
@ImportableService({ name: Expense.name })
|
||||||
export class ExpensesImportable extends Importable {
|
export class ExpensesImportable extends Importable {
|
||||||
constructor(private readonly createExpenseService: CreateExpense) {
|
constructor(private readonly createExpenseService: CreateExpense) {
|
||||||
super();
|
super();
|
||||||
|
|||||||
@@ -135,7 +135,7 @@ export const ExpenseMeta = {
|
|||||||
relationModel: 'Account',
|
relationModel: 'Account',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
required: true,
|
required: true,
|
||||||
importHint: 'Matches the account name or code.',
|
importHint: 'account.field.account_hint',
|
||||||
},
|
},
|
||||||
referenceNo: {
|
referenceNo: {
|
||||||
name: 'expense.field.reference_no',
|
name: 'expense.field.reference_no',
|
||||||
@@ -169,7 +169,7 @@ export const ExpenseMeta = {
|
|||||||
relationModel: 'Account',
|
relationModel: 'Account',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
required: true,
|
required: true,
|
||||||
importHint: 'Matches the account name or code.',
|
importHint: 'account.field.account_hint',
|
||||||
},
|
},
|
||||||
amount: {
|
amount: {
|
||||||
name: 'expense.field.amount',
|
name: 'expense.field.amount',
|
||||||
@@ -187,7 +187,7 @@ export const ExpenseMeta = {
|
|||||||
fieldType: 'boolean',
|
fieldType: 'boolean',
|
||||||
},
|
},
|
||||||
branchId: {
|
branchId: {
|
||||||
name: 'Branch',
|
name: 'invoice.field.branch',
|
||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'Branch',
|
relationModel: 'Branch',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
|
|||||||
@@ -1,14 +1,13 @@
|
|||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { ChromiumlyTenancy } from '../ChromiumlyTenancy/ChromiumlyTenancy.service';
|
import { ChromiumlyTenancy } from '../ChromiumlyTenancy/ChromiumlyTenancy.service';
|
||||||
import { TemplateInjectable } from '../TemplateInjectable/TemplateInjectable.service';
|
import { renderExportResourceTableTemplateHtml } from '@bigcapital/pdf-templates';
|
||||||
import { mapPdfRows } from './utils';
|
import { mapPdfRows } from './utils';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ExportPdf {
|
export class ExportPdf {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly templateInjectable: TemplateInjectable,
|
|
||||||
private readonly chromiumlyTenancy: ChromiumlyTenancy,
|
private readonly chromiumlyTenancy: ChromiumlyTenancy,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates the pdf table sheet for the given data and columns.
|
* Generates the pdf table sheet for the given data and columns.
|
||||||
@@ -19,21 +18,18 @@ export class ExportPdf {
|
|||||||
* @returns
|
* @returns
|
||||||
*/
|
*/
|
||||||
public async pdf(
|
public async pdf(
|
||||||
columns: { accessor: string },
|
columns: { accessor: string; name?: string; style?: string; group?: string }[],
|
||||||
data: Record<string, any>,
|
data: Record<string, any>,
|
||||||
sheetTitle: string = '',
|
sheetTitle: string = '',
|
||||||
sheetDescription: string = ''
|
sheetDescription: string = ''
|
||||||
) {
|
) {
|
||||||
const rows = mapPdfRows(columns, data);
|
const rows = mapPdfRows(columns, data);
|
||||||
|
|
||||||
const htmlContent = await this.templateInjectable.render(
|
const htmlContent = renderExportResourceTableTemplateHtml({
|
||||||
'modules/export-resource-table',
|
table: { rows, columns },
|
||||||
{
|
sheetTitle,
|
||||||
table: { rows, columns },
|
sheetDescription,
|
||||||
sheetTitle,
|
});
|
||||||
sheetDescription,
|
|
||||||
}
|
|
||||||
);
|
|
||||||
// Convert the HTML content to PDF
|
// Convert the HTML content to PDF
|
||||||
return this.chromiumlyTenancy.convertHtmlContent(htmlContent, {
|
return this.chromiumlyTenancy.convertHtmlContent(htmlContent, {
|
||||||
margins: { top: 0.2, bottom: 0.2, left: 0.2, right: 0.2 },
|
margins: { top: 0.2, bottom: 0.2, left: 0.2, right: 0.2 },
|
||||||
|
|||||||
@@ -3,29 +3,30 @@ import { ITableColumn, ITableData, ITableRow } from '../types/Table.types';
|
|||||||
import { FinancialTableStructure } from './FinancialTableStructure';
|
import { FinancialTableStructure } from './FinancialTableStructure';
|
||||||
import { tableClassNames } from '../utils';
|
import { tableClassNames } from '../utils';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { TemplateInjectable } from '../../TemplateInjectable/TemplateInjectable.service';
|
|
||||||
import { ChromiumlyTenancy } from '../../ChromiumlyTenancy/ChromiumlyTenancy.service';
|
import { ChromiumlyTenancy } from '../../ChromiumlyTenancy/ChromiumlyTenancy.service';
|
||||||
|
import { renderFinancialSheetTemplateHtml } from '@bigcapital/pdf-templates';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class TableSheetPdf {
|
export class TableSheetPdf {
|
||||||
/**
|
/**
|
||||||
* @param {TemplateInjectable} templateInjectable - The template injectable service.
|
|
||||||
* @param {ChromiumlyTenancy} chromiumlyTenancy - The chromiumly tenancy service.
|
* @param {ChromiumlyTenancy} chromiumlyTenancy - The chromiumly tenancy service.
|
||||||
*/
|
*/
|
||||||
constructor(
|
constructor(
|
||||||
private readonly templateInjectable: TemplateInjectable,
|
|
||||||
private readonly chromiumlyTenancy: ChromiumlyTenancy,
|
private readonly chromiumlyTenancy: ChromiumlyTenancy,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the table data into a PDF format.
|
* Converts the table data into a PDF format.
|
||||||
* @param {ITableData} table - The table data to be converted.
|
* @param {ITableData} table - The table data to be converted.
|
||||||
|
* @param {string} organizationName - The organization name.
|
||||||
* @param {string} sheetName - The name of the sheet.
|
* @param {string} sheetName - The name of the sheet.
|
||||||
* @param {string} sheetDate - The date of the sheet.
|
* @param {string} sheetDate - The date of the sheet.
|
||||||
|
* @param {string} customCSS - Optional custom CSS to inject.
|
||||||
* @returns A promise that resolves with the PDF conversion result.
|
* @returns A promise that resolves with the PDF conversion result.
|
||||||
*/
|
*/
|
||||||
public async convertToPdf(
|
public async convertToPdf(
|
||||||
table: ITableData,
|
table: ITableData,
|
||||||
|
organizationName: string,
|
||||||
sheetName: string,
|
sheetName: string,
|
||||||
sheetDate: string,
|
sheetDate: string,
|
||||||
customCSS?: string,
|
customCSS?: string,
|
||||||
@@ -33,19 +34,26 @@ export class TableSheetPdf {
|
|||||||
// Prepare columns and rows for PDF conversion
|
// Prepare columns and rows for PDF conversion
|
||||||
const columns = this.tablePdfColumns(table.columns);
|
const columns = this.tablePdfColumns(table.columns);
|
||||||
const rows = this.tablePdfRows(table.rows);
|
const rows = this.tablePdfRows(table.rows);
|
||||||
|
|
||||||
const landscape = columns.length > 4;
|
const landscape = columns.length > 4;
|
||||||
|
|
||||||
// Generate HTML content from the template
|
// Generate HTML content from the React template
|
||||||
const htmlContent = await this.templateInjectable.render(
|
const htmlContent = renderFinancialSheetTemplateHtml({
|
||||||
'financial-sheet',
|
organizationName,
|
||||||
{
|
sheetName,
|
||||||
table: { rows, columns },
|
sheetDate,
|
||||||
sheetName,
|
table: {
|
||||||
sheetDate,
|
columns: columns.map((col) => ({
|
||||||
customCSS,
|
key: col.key,
|
||||||
|
label: col.label,
|
||||||
|
style: (col as any).style, // style may be added during transformation
|
||||||
|
})),
|
||||||
|
rows: rows.map((row) => ({
|
||||||
|
cells: row.cells,
|
||||||
|
classNames: (row as any).classNames,
|
||||||
|
})),
|
||||||
},
|
},
|
||||||
);
|
customCSS,
|
||||||
|
});
|
||||||
// Convert the HTML content to PDF
|
// Convert the HTML content to PDF
|
||||||
return this.chromiumlyTenancy.convertHtmlContent(htmlContent, {
|
return this.chromiumlyTenancy.convertHtmlContent(htmlContent, {
|
||||||
margins: { top: 0, bottom: 0, left: 0, right: 0 },
|
margins: { top: 0, bottom: 0, left: 0, right: 0 },
|
||||||
@@ -74,7 +82,6 @@ export class TableSheetPdf {
|
|||||||
const flatNestedTree = curriedFlatNestedTree(R.__, {
|
const flatNestedTree = curriedFlatNestedTree(R.__, {
|
||||||
nestedPrefix: '<span style="padding-left: 15px;"></span>',
|
nestedPrefix: '<span style="padding-left: 15px;"></span>',
|
||||||
});
|
});
|
||||||
|
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
return R.compose(tableClassNames, flatNestedTree)(rows);
|
return R.compose(tableClassNames, flatNestedTree)(rows);
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export class APAgingSummaryPdfInjectable {
|
|||||||
|
|
||||||
return this.tableSheetPdf.convertToPdf(
|
return this.tableSheetPdf.convertToPdf(
|
||||||
table.table,
|
table.table,
|
||||||
|
table.meta.organizationName,
|
||||||
table.meta.sheetName,
|
table.meta.sheetName,
|
||||||
table.meta.formattedAsDate,
|
table.meta.formattedAsDate,
|
||||||
HtmlTableCss,
|
HtmlTableCss,
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export class ARAgingSummaryPdfInjectable {
|
|||||||
|
|
||||||
return this.tableSheetPdf.convertToPdf(
|
return this.tableSheetPdf.convertToPdf(
|
||||||
table.table,
|
table.table,
|
||||||
|
table.meta.organizationName,
|
||||||
table.meta.sheetName,
|
table.meta.sheetName,
|
||||||
table.meta.formattedDateRange,
|
table.meta.formattedDateRange,
|
||||||
HtmlTableCss,
|
HtmlTableCss,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export class BalanceSheetPdfInjectable {
|
|||||||
constructor(
|
constructor(
|
||||||
private readonly balanceSheetTable: BalanceSheetTableInjectable,
|
private readonly balanceSheetTable: BalanceSheetTableInjectable,
|
||||||
private readonly tableSheetPdf: TableSheetPdf,
|
private readonly tableSheetPdf: TableSheetPdf,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the given balance sheet table to pdf.
|
* Converts the given balance sheet table to pdf.
|
||||||
@@ -21,6 +21,7 @@ export class BalanceSheetPdfInjectable {
|
|||||||
|
|
||||||
return this.tableSheetPdf.convertToPdf(
|
return this.tableSheetPdf.convertToPdf(
|
||||||
table.table,
|
table.table,
|
||||||
|
table.meta.organizationName,
|
||||||
table.meta.sheetName,
|
table.meta.sheetName,
|
||||||
table.meta.formattedDateRange,
|
table.meta.formattedDateRange,
|
||||||
HtmlTableCustomCss,
|
HtmlTableCustomCss,
|
||||||
|
|||||||
@@ -81,6 +81,7 @@ export class CashFlowStatementQueryDto extends FinancialSheetBranchesQueryDto {
|
|||||||
})
|
})
|
||||||
@ValidateNested()
|
@ValidateNested()
|
||||||
@Type(() => NumberFormatQueryDto)
|
@Type(() => NumberFormatQueryDto)
|
||||||
|
@IsOptional()
|
||||||
numberFormat: NumberFormatQueryDto;
|
numberFormat: NumberFormatQueryDto;
|
||||||
|
|
||||||
@ApiProperty({
|
@ApiProperty({
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export class CashflowTablePdfInjectable {
|
|||||||
|
|
||||||
return this.tableSheetPdf.convertToPdf(
|
return this.tableSheetPdf.convertToPdf(
|
||||||
table.table,
|
table.table,
|
||||||
|
table.meta.organizationName,
|
||||||
table.meta.sheetName,
|
table.meta.sheetName,
|
||||||
table.meta.formattedDateRange,
|
table.meta.formattedDateRange,
|
||||||
HtmlTableCustomCss,
|
HtmlTableCustomCss,
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export class CustomerBalanceSummaryPdf {
|
|||||||
|
|
||||||
return this.tableSheetPdf.convertToPdf(
|
return this.tableSheetPdf.convertToPdf(
|
||||||
table.table,
|
table.table,
|
||||||
|
table.meta.organizationName,
|
||||||
table.meta.sheetName,
|
table.meta.sheetName,
|
||||||
table.meta.formattedDateRange,
|
table.meta.formattedDateRange,
|
||||||
HtmlTableCustomCss,
|
HtmlTableCustomCss,
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export class GeneralLedgerPdf {
|
|||||||
|
|
||||||
return this.tableSheetPdf.convertToPdf(
|
return this.tableSheetPdf.convertToPdf(
|
||||||
table.table,
|
table.table,
|
||||||
|
table.meta.organizationName,
|
||||||
table.meta.sheetName,
|
table.meta.sheetName,
|
||||||
table.meta.formattedDateRange,
|
table.meta.formattedDateRange,
|
||||||
HtmlTableCustomCss,
|
HtmlTableCustomCss,
|
||||||
|
|||||||
@@ -32,7 +32,7 @@ export class InventoryItemDetailsQueryDto {
|
|||||||
@ApiPropertyOptional({
|
@ApiPropertyOptional({
|
||||||
description: 'Number format for the inventory item details',
|
description: 'Number format for the inventory item details',
|
||||||
})
|
})
|
||||||
numberFormat: INumberFormatQuery;
|
numberFormat: NumberFormatQueryDto;
|
||||||
|
|
||||||
@Transform(({ value }) => parseBoolean(value, false))
|
@Transform(({ value }) => parseBoolean(value, false))
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ export class InventoryDetailsTablePdf {
|
|||||||
|
|
||||||
return this.tableSheetPdf.convertToPdf(
|
return this.tableSheetPdf.convertToPdf(
|
||||||
table.table,
|
table.table,
|
||||||
|
table.meta.organizationName,
|
||||||
table.meta.sheetName,
|
table.meta.sheetName,
|
||||||
table.meta.formattedDateRange,
|
table.meta.formattedDateRange,
|
||||||
HtmlTableCustomCss,
|
HtmlTableCustomCss,
|
||||||
|
|||||||
@@ -211,7 +211,7 @@ export class InventoryValuationSheet extends FinancialSheet {
|
|||||||
* Detarmines whether the items post filter is active.
|
* Detarmines whether the items post filter is active.
|
||||||
*/
|
*/
|
||||||
private isItemsPostFilter = (): boolean => {
|
private isItemsPostFilter = (): boolean => {
|
||||||
return isEmpty(this.query.itemsIds);
|
return !isEmpty(this.query.itemsIds);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -22,6 +22,7 @@ export class InventoryValuationSheetPdf {
|
|||||||
|
|
||||||
return this.tableSheetPdf.convertToPdf(
|
return this.tableSheetPdf.convertToPdf(
|
||||||
table.table,
|
table.table,
|
||||||
|
table.meta.organizationName,
|
||||||
table.meta.sheetName,
|
table.meta.sheetName,
|
||||||
table.meta.formattedDateRange,
|
table.meta.formattedDateRange,
|
||||||
HtmlTableCustomCss,
|
HtmlTableCustomCss,
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ export class InventoryValuationSheetService {
|
|||||||
private readonly inventoryValuationMeta: InventoryValuationMetaInjectable,
|
private readonly inventoryValuationMeta: InventoryValuationMetaInjectable,
|
||||||
private readonly eventPublisher: EventEmitter2,
|
private readonly eventPublisher: EventEmitter2,
|
||||||
private readonly inventoryValuationSheetRepository: InventoryValuationSheetRepository,
|
private readonly inventoryValuationSheetRepository: InventoryValuationSheetRepository,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Inventory valuation sheet.
|
* Inventory valuation sheet.
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export class JournalSheetPdfInjectable {
|
|||||||
constructor(
|
constructor(
|
||||||
private readonly journalSheetTable: JournalSheetTableInjectable,
|
private readonly journalSheetTable: JournalSheetTableInjectable,
|
||||||
private readonly tableSheetPdf: TableSheetPdf,
|
private readonly tableSheetPdf: TableSheetPdf,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the given journal sheet table to pdf.
|
* Converts the given journal sheet table to pdf.
|
||||||
@@ -22,6 +22,7 @@ export class JournalSheetPdfInjectable {
|
|||||||
|
|
||||||
return this.tableSheetPdf.convertToPdf(
|
return this.tableSheetPdf.convertToPdf(
|
||||||
table.table,
|
table.table,
|
||||||
|
table.meta.organizationName,
|
||||||
table.meta.sheetName,
|
table.meta.sheetName,
|
||||||
table.meta.formattedDateRange,
|
table.meta.formattedDateRange,
|
||||||
HtmlTableCustomCss,
|
HtmlTableCustomCss,
|
||||||
|
|||||||
@@ -7,11 +7,13 @@ import {
|
|||||||
IsEnum,
|
IsEnum,
|
||||||
IsOptional,
|
IsOptional,
|
||||||
IsString,
|
IsString,
|
||||||
|
ValidateNested,
|
||||||
} from 'class-validator';
|
} from 'class-validator';
|
||||||
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
import { ApiProperty, ApiPropertyOptional } from '@nestjs/swagger';
|
||||||
import { Transform, Type } from 'class-transformer';
|
import { Transform, Type } from 'class-transformer';
|
||||||
import { ToNumber } from '@/common/decorators/Validators';
|
import { ToNumber } from '@/common/decorators/Validators';
|
||||||
import { parseBoolean } from '@/utils/parse-boolean';
|
import { parseBoolean } from '@/utils/parse-boolean';
|
||||||
|
import { NumberFormatQueryDto } from '@/modules/BankingTransactions/dtos/NumberFormatQuery.dto';
|
||||||
|
|
||||||
export class ProfitLossSheetQueryDto extends FinancialSheetBranchesQueryDto {
|
export class ProfitLossSheetQueryDto extends FinancialSheetBranchesQueryDto {
|
||||||
@IsString()
|
@IsString()
|
||||||
@@ -30,8 +32,10 @@ export class ProfitLossSheetQueryDto extends FinancialSheetBranchesQueryDto {
|
|||||||
toDate: moment.MomentInput;
|
toDate: moment.MomentInput;
|
||||||
|
|
||||||
@ApiProperty({ description: 'Number format configuration' })
|
@ApiProperty({ description: 'Number format configuration' })
|
||||||
@Type(() => Object)
|
@ValidateNested()
|
||||||
numberFormat: INumberFormatQuery;
|
@Type(() => NumberFormatQueryDto)
|
||||||
|
@IsOptional()
|
||||||
|
numberFormat: NumberFormatQueryDto;
|
||||||
|
|
||||||
@IsBoolean()
|
@IsBoolean()
|
||||||
@Transform(({ value }) => parseBoolean(value, false))
|
@Transform(({ value }) => parseBoolean(value, false))
|
||||||
|
|||||||
@@ -21,6 +21,7 @@ export class ProfitLossTablePdfInjectable {
|
|||||||
|
|
||||||
return this.tableSheetPdf.convertToPdf(
|
return this.tableSheetPdf.convertToPdf(
|
||||||
table.table,
|
table.table,
|
||||||
|
table.meta.organizationName,
|
||||||
table.meta.sheetName,
|
table.meta.sheetName,
|
||||||
table.meta.formattedDateRange,
|
table.meta.formattedDateRange,
|
||||||
HtmlTableCustomCss,
|
HtmlTableCustomCss,
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ export class PurchasesByItemsPdf {
|
|||||||
|
|
||||||
return this.tableSheetPdf.convertToPdf(
|
return this.tableSheetPdf.convertToPdf(
|
||||||
table.table,
|
table.table,
|
||||||
|
table.meta.organizationName,
|
||||||
table.meta.sheetName,
|
table.meta.sheetName,
|
||||||
table.meta.formattedDateRange,
|
table.meta.formattedDateRange,
|
||||||
HtmlTableCustomCss,
|
HtmlTableCustomCss,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export class SalesByItemsPdfInjectable {
|
|||||||
constructor(
|
constructor(
|
||||||
private readonly salesByItemsTable: SalesByItemsTableInjectable,
|
private readonly salesByItemsTable: SalesByItemsTableInjectable,
|
||||||
private readonly tableSheetPdf: TableSheetPdf,
|
private readonly tableSheetPdf: TableSheetPdf,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the sales by items sheet in pdf format.
|
* Retrieves the sales by items sheet in pdf format.
|
||||||
@@ -23,6 +23,7 @@ export class SalesByItemsPdfInjectable {
|
|||||||
|
|
||||||
return this.tableSheetPdf.convertToPdf(
|
return this.tableSheetPdf.convertToPdf(
|
||||||
table.table,
|
table.table,
|
||||||
|
table.meta.organizationName,
|
||||||
table.meta.sheetName,
|
table.meta.sheetName,
|
||||||
table.meta.formattedDateRange,
|
table.meta.formattedDateRange,
|
||||||
HtmlTableCustomCss,
|
HtmlTableCustomCss,
|
||||||
|
|||||||
@@ -8,7 +8,7 @@ export class SalesTaxLiabiltiySummaryPdf {
|
|||||||
constructor(
|
constructor(
|
||||||
private readonly salesTaxLiabiltiySummaryTable: SalesTaxLiabilitySummaryTableInjectable,
|
private readonly salesTaxLiabiltiySummaryTable: SalesTaxLiabilitySummaryTableInjectable,
|
||||||
private readonly tableSheetPdf: TableSheetPdf,
|
private readonly tableSheetPdf: TableSheetPdf,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the given sales tax liability summary table to pdf.
|
* Converts the given sales tax liability summary table to pdf.
|
||||||
@@ -21,6 +21,7 @@ export class SalesTaxLiabiltiySummaryPdf {
|
|||||||
);
|
);
|
||||||
return this.tableSheetPdf.convertToPdf(
|
return this.tableSheetPdf.convertToPdf(
|
||||||
table.table,
|
table.table,
|
||||||
|
table.meta.organizationName,
|
||||||
table.meta.sheetName,
|
table.meta.sheetName,
|
||||||
table.meta.formattedDateRange,
|
table.meta.formattedDateRange,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ export class TransactionsByCustomersPdf {
|
|||||||
constructor(
|
constructor(
|
||||||
private readonly transactionsByCustomersTable: TransactionsByCustomersTableInjectable,
|
private readonly transactionsByCustomersTable: TransactionsByCustomersTableInjectable,
|
||||||
private readonly tableSheetPdf: TableSheetPdf,
|
private readonly tableSheetPdf: TableSheetPdf,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the transactions by customers in PDF format.
|
* Retrieves the transactions by customers in PDF format.
|
||||||
@@ -18,6 +18,7 @@ export class TransactionsByCustomersPdf {
|
|||||||
|
|
||||||
return this.tableSheetPdf.convertToPdf(
|
return this.tableSheetPdf.convertToPdf(
|
||||||
table.table,
|
table.table,
|
||||||
|
table.meta.organizationName,
|
||||||
table.meta.sheetName,
|
table.meta.sheetName,
|
||||||
table.meta.formattedDateRange,
|
table.meta.formattedDateRange,
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export class TransactionsByVendorsPdf {
|
|||||||
constructor(
|
constructor(
|
||||||
private readonly transactionsByVendorTable: TransactionsByVendorTableInjectable,
|
private readonly transactionsByVendorTable: TransactionsByVendorTableInjectable,
|
||||||
private readonly tableSheetPdf: TableSheetPdf,
|
private readonly tableSheetPdf: TableSheetPdf,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the given balance sheet table to pdf.
|
* Converts the given balance sheet table to pdf.
|
||||||
@@ -21,6 +21,7 @@ export class TransactionsByVendorsPdf {
|
|||||||
|
|
||||||
return this.tableSheetPdf.convertToPdf(
|
return this.tableSheetPdf.convertToPdf(
|
||||||
table.table,
|
table.table,
|
||||||
|
table.meta.organizationName,
|
||||||
table.meta.sheetName,
|
table.meta.sheetName,
|
||||||
table.meta.formattedDateRange,
|
table.meta.formattedDateRange,
|
||||||
HtmlTableCustomCss,
|
HtmlTableCustomCss,
|
||||||
|
|||||||
@@ -172,7 +172,10 @@ export class TrialBalanceSheet extends FinancialSheet {
|
|||||||
private filterNoneTransactions = (
|
private filterNoneTransactions = (
|
||||||
accountNode: ITrialBalanceAccount
|
accountNode: ITrialBalanceAccount
|
||||||
): boolean => {
|
): boolean => {
|
||||||
return false === this.repository.totalAccountsLedger.isEmpty();
|
const accountLedger = this.repository.totalAccountsLedger.whereAccountId(
|
||||||
|
accountNode.id,
|
||||||
|
);
|
||||||
|
return !accountLedger.isEmpty();
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export class TrialBalanceSheetPdfInjectable {
|
|||||||
constructor(
|
constructor(
|
||||||
private readonly trialBalanceSheetTable: TrialBalanceSheetTableInjectable,
|
private readonly trialBalanceSheetTable: TrialBalanceSheetTableInjectable,
|
||||||
private readonly tableSheetPdf: TableSheetPdf,
|
private readonly tableSheetPdf: TableSheetPdf,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Converts the given trial balance sheet table to pdf.
|
* Converts the given trial balance sheet table to pdf.
|
||||||
@@ -21,6 +21,7 @@ export class TrialBalanceSheetPdfInjectable {
|
|||||||
|
|
||||||
return this.tableSheetPdf.convertToPdf(
|
return this.tableSheetPdf.convertToPdf(
|
||||||
table.table,
|
table.table,
|
||||||
|
table.meta.organizationName,
|
||||||
table.meta.sheetName,
|
table.meta.sheetName,
|
||||||
table.meta.formattedDateRange,
|
table.meta.formattedDateRange,
|
||||||
HtmlTableCustomCss,
|
HtmlTableCustomCss,
|
||||||
|
|||||||
@@ -9,7 +9,7 @@ export class VendorBalanceSummaryPdf {
|
|||||||
constructor(
|
constructor(
|
||||||
private readonly vendorBalanceSummaryTable: VendorBalanceSummaryTableInjectable,
|
private readonly vendorBalanceSummaryTable: VendorBalanceSummaryTableInjectable,
|
||||||
private readonly tableSheetPdf: TableSheetPdf,
|
private readonly tableSheetPdf: TableSheetPdf,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieves the sales by items sheet in pdf format.
|
* Retrieves the sales by items sheet in pdf format.
|
||||||
@@ -23,6 +23,7 @@ export class VendorBalanceSummaryPdf {
|
|||||||
|
|
||||||
return this.tableSheetPdf.convertToPdf(
|
return this.tableSheetPdf.convertToPdf(
|
||||||
table.table,
|
table.table,
|
||||||
|
table.meta.organizationName,
|
||||||
table.meta.sheetName,
|
table.meta.sheetName,
|
||||||
table.meta.formattedAsDate,
|
table.meta.formattedAsDate,
|
||||||
HtmlTableCustomCss,
|
HtmlTableCustomCss,
|
||||||
|
|||||||
@@ -22,7 +22,7 @@ export class ImportFileCommon {
|
|||||||
private readonly importFileValidator: ImportFileDataValidator,
|
private readonly importFileValidator: ImportFileDataValidator,
|
||||||
private readonly resource: ResourceService,
|
private readonly resource: ResourceService,
|
||||||
private readonly importableRegistry: ImportableRegistry,
|
private readonly importableRegistry: ImportableRegistry,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Imports the given parsed data to the resource storage through registered importable service.
|
* Imports the given parsed data to the resource storage through registered importable service.
|
||||||
|
|||||||
@@ -18,7 +18,7 @@ import { CurrencyParsingDTOs } from './_constants';
|
|||||||
export class ImportFileDataTransformer {
|
export class ImportFileDataTransformer {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly resource: ResourceService,
|
private readonly resource: ResourceService,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the given sheet data before passing to the service layer.
|
* Parses the given sheet data before passing to the service layer.
|
||||||
@@ -55,9 +55,8 @@ export class ImportFileDataTransformer {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Aggregates parsed data based on resource metadata configuration.
|
* Aggregates parsed data based on resource metadata configuration.
|
||||||
* @param {number} tenantId
|
* @param {string} resourceName - The resource name.
|
||||||
* @param {string} resourceName
|
* @param {Record<string, any>} parsedData - The parsed data to aggregate.
|
||||||
* @param {Record<string, any>} parsedData
|
|
||||||
* @returns {Record<string, any>[]}
|
* @returns {Record<string, any>[]}
|
||||||
*/
|
*/
|
||||||
public aggregateParsedValues(
|
public aggregateParsedValues(
|
||||||
@@ -110,8 +109,11 @@ export class ImportFileDataTransformer {
|
|||||||
valueDTOs: Record<string, any>[],
|
valueDTOs: Record<string, any>[],
|
||||||
trx?: Knex.Transaction
|
trx?: Knex.Transaction
|
||||||
): Promise<Record<string, any>[]> {
|
): Promise<Record<string, any>[]> {
|
||||||
// const tenantModels = this.tenancy.models(tenantId);
|
// Create a model resolver function that uses ResourceService
|
||||||
const _valueParser = valueParser(fields, {}, trx);
|
const modelResolver = (modelName: string) => {
|
||||||
|
return this.resource.getResourceModel(modelName)();
|
||||||
|
};
|
||||||
|
const _valueParser = valueParser(fields, modelResolver, trx);
|
||||||
const _keyParser = parseKey(fields);
|
const _keyParser = parseKey(fields);
|
||||||
|
|
||||||
const parseAsync = async (valueDTO) => {
|
const parseAsync = async (valueDTO) => {
|
||||||
|
|||||||
@@ -19,7 +19,8 @@ export class ImportFileDataValidator {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Validates the given mapped DTOs and returns errors with their index.
|
* Validates the given mapped DTOs and returns errors with their index.
|
||||||
* @param {Record<string, any>} mappedDTOs
|
* @param {ResourceMetaFieldsMap} importableFields - Already localized fields from ResourceService
|
||||||
|
* @param {Record<string, any>} data
|
||||||
* @returns {Promise<void | ImportInsertError[]>}
|
* @returns {Promise<void | ImportInsertError[]>}
|
||||||
*/
|
*/
|
||||||
public async validateData(
|
public async validateData(
|
||||||
|
|||||||
@@ -24,7 +24,7 @@ export class ImportFileUploadService {
|
|||||||
|
|
||||||
@Inject(ImportModel.name)
|
@Inject(ImportModel.name)
|
||||||
private readonly importModel: typeof ImportModel,
|
private readonly importModel: typeof ImportModel,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Imports the specified file for the given resource.
|
* Imports the specified file for the given resource.
|
||||||
@@ -84,7 +84,7 @@ export class ImportFileUploadService {
|
|||||||
} catch (error) {
|
} catch (error) {
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
const _params = this.importFileCommon.transformParams(resource, params);
|
const _params = await this.importFileCommon.transformParams(resource, params);
|
||||||
const paramsStringified = JSON.stringify(_params);
|
const paramsStringified = JSON.stringify(_params);
|
||||||
|
|
||||||
const tenant = await this.tenancyContext.getTenant();
|
const tenant = await this.tenancyContext.getTenant();
|
||||||
|
|||||||
@@ -6,7 +6,7 @@ import { ContextIdFactory, ModuleRef } from '@nestjs/core';
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class ImportableRegistry {
|
export class ImportableRegistry {
|
||||||
constructor(private readonly moduleRef: ModuleRef) {}
|
constructor(private readonly moduleRef: ModuleRef) { }
|
||||||
/**
|
/**
|
||||||
* Retrieves the importable service instance of the given resource name.
|
* Retrieves the importable service instance of the given resource name.
|
||||||
* @param {string} name
|
* @param {string} name
|
||||||
@@ -15,6 +15,12 @@ export class ImportableRegistry {
|
|||||||
public async getImportable(name: string) {
|
public async getImportable(name: string) {
|
||||||
const _name = this.sanitizeResourceName(name);
|
const _name = this.sanitizeResourceName(name);
|
||||||
const importable = getImportableService(_name);
|
const importable = getImportableService(_name);
|
||||||
|
|
||||||
|
if (!importable) {
|
||||||
|
throw new Error(
|
||||||
|
`No importable service found for resource "${_name}". Make sure the resource has an @ImportableService decorator registered.`,
|
||||||
|
);
|
||||||
|
}
|
||||||
const contextId = ContextIdFactory.create();
|
const contextId = ContextIdFactory.create();
|
||||||
|
|
||||||
const importableInstance = await this.moduleRef.resolve(importable, contextId, {
|
const importableInstance = await this.moduleRef.resolve(importable, contextId, {
|
||||||
|
|||||||
287
packages/server/src/modules/Import/_utils.spec.ts
Normal file
287
packages/server/src/modules/Import/_utils.spec.ts
Normal file
@@ -0,0 +1,287 @@
|
|||||||
|
import { aggregate } from './_utils';
|
||||||
|
|
||||||
|
describe('aggregate', () => {
|
||||||
|
describe('basic aggregation', () => {
|
||||||
|
it('should aggregate entries with matching comparator attribute', () => {
|
||||||
|
const input = [
|
||||||
|
{ id: 1, name: 'John', entries: ['entry1'] },
|
||||||
|
{ id: 2, name: 'Jane', entries: ['entry2'] },
|
||||||
|
{ id: 1, name: 'John', entries: ['entry3'] },
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = aggregate(input, 'id', 'entries');
|
||||||
|
|
||||||
|
expect(result).toHaveLength(2);
|
||||||
|
expect(result[0]).toEqual({
|
||||||
|
id: 1,
|
||||||
|
name: 'John',
|
||||||
|
entries: ['entry1', 'entry3'],
|
||||||
|
});
|
||||||
|
expect(result[1]).toEqual({
|
||||||
|
id: 2,
|
||||||
|
name: 'Jane',
|
||||||
|
entries: ['entry2'],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should preserve order of first occurrence', () => {
|
||||||
|
const input = [
|
||||||
|
{ id: 2, entries: ['a'] },
|
||||||
|
{ id: 1, entries: ['b'] },
|
||||||
|
{ id: 2, entries: ['c'] },
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = aggregate(input, 'id', 'entries');
|
||||||
|
|
||||||
|
expect(result[0].id).toBe(2);
|
||||||
|
expect(result[1].id).toBe(1);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('no matching entries', () => {
|
||||||
|
it('should return all entries unchanged when no comparator matches', () => {
|
||||||
|
const input = [
|
||||||
|
{ id: 1, name: 'John', entries: ['entry1'] },
|
||||||
|
{ id: 2, name: 'Jane', entries: ['entry2'] },
|
||||||
|
{ id: 3, name: 'Bob', entries: ['entry3'] },
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = aggregate(input, 'id', 'entries');
|
||||||
|
|
||||||
|
expect(result).toHaveLength(3);
|
||||||
|
expect(result).toEqual(input);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('edge cases', () => {
|
||||||
|
it('should return empty array when input is empty', () => {
|
||||||
|
const result = aggregate([], 'id', 'entries');
|
||||||
|
|
||||||
|
expect(result).toEqual([]);
|
||||||
|
expect(result).toHaveLength(0);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should return single entry unchanged when input has one item', () => {
|
||||||
|
const input = [{ id: 1, name: 'John', entries: ['entry1'] }];
|
||||||
|
|
||||||
|
const result = aggregate(input, 'id', 'entries');
|
||||||
|
|
||||||
|
expect(result).toHaveLength(1);
|
||||||
|
expect(result[0]).toEqual({
|
||||||
|
id: 1,
|
||||||
|
name: 'John',
|
||||||
|
entries: ['entry1'],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle multiple entries with same comparator value', () => {
|
||||||
|
const input = [
|
||||||
|
{ id: 1, entries: ['a'] },
|
||||||
|
{ id: 1, entries: ['b'] },
|
||||||
|
{ id: 1, entries: ['c'] },
|
||||||
|
{ id: 1, entries: ['d'] },
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = aggregate(input, 'id', 'entries');
|
||||||
|
|
||||||
|
expect(result).toHaveLength(1);
|
||||||
|
expect(result[0].entries).toEqual(['a', 'b', 'c', 'd']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('different comparator attributes', () => {
|
||||||
|
it('should work with string comparator attribute', () => {
|
||||||
|
const input = [
|
||||||
|
{ name: 'Product A', category: 'Electronics', entries: ['item1'] },
|
||||||
|
{ name: 'Product B', category: 'Books', entries: ['item2'] },
|
||||||
|
{ name: 'Product C', category: 'Electronics', entries: ['item3'] },
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = aggregate(input, 'category', 'entries');
|
||||||
|
|
||||||
|
expect(result).toHaveLength(2);
|
||||||
|
expect(result[0]).toEqual({
|
||||||
|
name: 'Product A',
|
||||||
|
category: 'Electronics',
|
||||||
|
entries: ['item1', 'item3'],
|
||||||
|
});
|
||||||
|
expect(result[1]).toEqual({
|
||||||
|
name: 'Product B',
|
||||||
|
category: 'Books',
|
||||||
|
entries: ['item2'],
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not aggregate items with undefined comparator values', () => {
|
||||||
|
const input = [
|
||||||
|
{ id: undefined, entries: ['a'] },
|
||||||
|
{ id: 1, entries: ['b'] },
|
||||||
|
{ id: undefined, entries: ['c'] },
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = aggregate(input, 'id', 'entries');
|
||||||
|
|
||||||
|
expect(result).toHaveLength(3);
|
||||||
|
// Items with undefined id are NOT aggregated - each remains separate
|
||||||
|
expect(result[0].entries).toEqual(['a']);
|
||||||
|
expect(result[1].entries).toEqual(['b']);
|
||||||
|
expect(result[2].entries).toEqual(['c']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle null comparator values separately', () => {
|
||||||
|
const input = [
|
||||||
|
{ id: null, entries: ['a'] },
|
||||||
|
{ id: 1, entries: ['b'] },
|
||||||
|
{ id: null, entries: ['c'] },
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = aggregate(input, 'id', 'entries');
|
||||||
|
|
||||||
|
expect(result).toHaveLength(3);
|
||||||
|
expect(result[0].entries).toEqual(['a']);
|
||||||
|
expect(result[1].entries).toEqual(['b']);
|
||||||
|
expect(result[2].entries).toEqual(['c']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should not aggregate items missing the comparatorAttr property', () => {
|
||||||
|
const input = [
|
||||||
|
{ id: 1, entries: ['a'] },
|
||||||
|
{ name: 'No ID', entries: ['b'] }, // missing 'id' property
|
||||||
|
{ id: 1, entries: ['c'] },
|
||||||
|
{ entries: ['d'] }, // also missing 'id' property
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = aggregate(input, 'id', 'entries');
|
||||||
|
|
||||||
|
// 3 entries: aggregated id:1, and two separate items without 'id' property
|
||||||
|
expect(result).toHaveLength(3);
|
||||||
|
// Items with id: 1 are aggregated
|
||||||
|
expect(result[0]).toEqual({ id: 1, entries: ['a', 'c'] });
|
||||||
|
// Items missing 'id' are NOT aggregated - each remains separate
|
||||||
|
expect(result[1]).toEqual({ name: 'No ID', entries: ['b'] });
|
||||||
|
expect(result[2]).toEqual({ entries: ['d'] });
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('different group attributes', () => {
|
||||||
|
it('should work with different groupOn attribute name', () => {
|
||||||
|
const input = [
|
||||||
|
{ id: 1, items: ['item1'] },
|
||||||
|
{ id: 1, items: ['item2'] },
|
||||||
|
{ id: 2, items: ['item3'] },
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = aggregate(input, 'id', 'items');
|
||||||
|
|
||||||
|
expect(result).toHaveLength(2);
|
||||||
|
expect(result[0].items).toEqual(['item1', 'item2']);
|
||||||
|
expect(result[1].items).toEqual(['item3']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('complex entries', () => {
|
||||||
|
it('should aggregate entries containing objects', () => {
|
||||||
|
const input = [
|
||||||
|
{ invoiceId: 'INV-001', entries: [{ itemId: 1, quantity: 2 }] },
|
||||||
|
{ invoiceId: 'INV-002', entries: [{ itemId: 2, quantity: 1 }] },
|
||||||
|
{ invoiceId: 'INV-001', entries: [{ itemId: 3, quantity: 5 }] },
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = aggregate(input, 'invoiceId', 'entries');
|
||||||
|
|
||||||
|
expect(result).toHaveLength(2);
|
||||||
|
expect(result[0].entries).toEqual([
|
||||||
|
{ itemId: 1, quantity: 2 },
|
||||||
|
{ itemId: 3, quantity: 5 },
|
||||||
|
]);
|
||||||
|
expect(result[1].entries).toEqual([{ itemId: 2, quantity: 1 }]);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should aggregate entries with multiple items in each entry', () => {
|
||||||
|
const input = [
|
||||||
|
{ id: 1, entries: ['a', 'b'] },
|
||||||
|
{ id: 1, entries: ['c', 'd'] },
|
||||||
|
{ id: 2, entries: ['e'] },
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = aggregate(input, 'id', 'entries');
|
||||||
|
|
||||||
|
expect(result).toHaveLength(2);
|
||||||
|
expect(result[0].entries).toEqual(['a', 'b', 'c', 'd']);
|
||||||
|
expect(result[1].entries).toEqual(['e']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('numeric comparator values', () => {
|
||||||
|
it('should correctly compare numeric values', () => {
|
||||||
|
const input = [
|
||||||
|
{ id: 1, entries: ['a'] },
|
||||||
|
{ id: 2, entries: ['b'] },
|
||||||
|
{ id: 1, entries: ['c'] },
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = aggregate(input, 'id', 'entries');
|
||||||
|
|
||||||
|
expect(result).toHaveLength(2);
|
||||||
|
expect(result.find((r) => r.id === 1).entries).toEqual(['a', 'c']);
|
||||||
|
expect(result.find((r) => r.id === 2).entries).toEqual(['b']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should treat 0 as a valid comparator value', () => {
|
||||||
|
const input = [
|
||||||
|
{ id: 0, entries: ['a'] },
|
||||||
|
{ id: 1, entries: ['b'] },
|
||||||
|
{ id: 0, entries: ['c'] },
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = aggregate(input, 'id', 'entries');
|
||||||
|
|
||||||
|
expect(result).toHaveLength(2);
|
||||||
|
expect(result[0].entries).toEqual(['a', 'c']);
|
||||||
|
expect(result[1].entries).toEqual(['b']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('preserving other properties', () => {
|
||||||
|
it('should preserve all properties from the first matching entry', () => {
|
||||||
|
const input = [
|
||||||
|
{ id: 1, name: 'First', extra: 'data1', entries: ['a'] },
|
||||||
|
{ id: 1, name: 'Second', extra: 'data2', entries: ['b'] },
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = aggregate(input, 'id', 'entries');
|
||||||
|
|
||||||
|
expect(result).toHaveLength(1);
|
||||||
|
expect(result[0].name).toBe('First');
|
||||||
|
expect(result[0].extra).toBe('data1');
|
||||||
|
expect(result[0].entries).toEqual(['a', 'b']);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe('empty entries arrays', () => {
|
||||||
|
it('should handle empty entries arrays', () => {
|
||||||
|
const input = [
|
||||||
|
{ id: 1, entries: [] },
|
||||||
|
{ id: 1, entries: ['a'] },
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = aggregate(input, 'id', 'entries');
|
||||||
|
|
||||||
|
expect(result).toHaveLength(1);
|
||||||
|
expect(result[0].entries).toEqual(['a']);
|
||||||
|
});
|
||||||
|
|
||||||
|
it('should handle all empty entries arrays', () => {
|
||||||
|
const input = [
|
||||||
|
{ id: 1, entries: [] },
|
||||||
|
{ id: 1, entries: [] },
|
||||||
|
];
|
||||||
|
|
||||||
|
const result = aggregate(input, 'id', 'entries');
|
||||||
|
|
||||||
|
expect(result).toHaveLength(1);
|
||||||
|
expect(result[0].entries).toEqual([]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
@@ -253,28 +253,28 @@ export const getResourceColumns = (resourceColumns: {
|
|||||||
}) => {
|
}) => {
|
||||||
const mapColumn =
|
const mapColumn =
|
||||||
(group: string) =>
|
(group: string) =>
|
||||||
([fieldKey, { name, importHint, required, order, ...field }]: [
|
([fieldKey, { name, importHint, required, order, ...field }]: [
|
||||||
string,
|
string,
|
||||||
IModelMetaField2,
|
IModelMetaField2,
|
||||||
]) => {
|
]) => {
|
||||||
const extra: Record<string, any> = {};
|
const extra: Record<string, any> = {};
|
||||||
const key = fieldKey;
|
const key = fieldKey;
|
||||||
|
|
||||||
if (group) {
|
if (group) {
|
||||||
extra.group = group;
|
extra.group = group;
|
||||||
}
|
}
|
||||||
if (field.fieldType === 'collection') {
|
if (field.fieldType === 'collection') {
|
||||||
extra.fields = mapColumns(field.fields, key);
|
extra.fields = mapColumns(field.fields, key);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
key,
|
key,
|
||||||
name,
|
name,
|
||||||
required,
|
required,
|
||||||
hint: importHint,
|
hint: importHint,
|
||||||
order,
|
order,
|
||||||
...extra,
|
...extra,
|
||||||
|
};
|
||||||
};
|
};
|
||||||
};
|
|
||||||
const sortColumn = (a, b) =>
|
const sortColumn = (a, b) =>
|
||||||
a.order && b.order ? a.order - b.order : a.order ? -1 : b.order ? 1 : 0;
|
a.order && b.order ? a.order - b.order : a.order ? -1 : b.order ? 1 : 0;
|
||||||
|
|
||||||
@@ -284,52 +284,54 @@ export const getResourceColumns = (resourceColumns: {
|
|||||||
return R.compose(transformInputToGroupedFields, mapColumns)(resourceColumns);
|
return R.compose(transformInputToGroupedFields, mapColumns)(resourceColumns);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
export type ModelResolver = (modelName: string) => any;
|
||||||
|
|
||||||
// Prases the given object value based on the field key type.
|
// Prases the given object value based on the field key type.
|
||||||
export const valueParser =
|
export const valueParser =
|
||||||
(fields: ResourceMetaFieldsMap, tenantModels: any, trx?: Knex.Transaction) =>
|
(fields: ResourceMetaFieldsMap, modelResolver: ModelResolver, trx?: Knex.Transaction) =>
|
||||||
async (value: any, key: string, group = '') => {
|
async (value: any, key: string, group = '') => {
|
||||||
let _value = value;
|
let _value = value;
|
||||||
|
|
||||||
const fieldKey = key.includes('.') ? key.split('.')[0] : key;
|
const fieldKey = key.includes('.') ? key.split('.')[0] : key;
|
||||||
const field = group ? fields[group]?.fields[fieldKey] : fields[fieldKey];
|
const field = group ? fields[group]?.fields[fieldKey] : fields[fieldKey];
|
||||||
|
|
||||||
// Parses the boolean value.
|
// Parses the boolean value.
|
||||||
if (field.fieldType === 'boolean') {
|
if (field.fieldType === 'boolean') {
|
||||||
_value = parseBoolean(value);
|
_value = parseBoolean(value);
|
||||||
|
|
||||||
// Parses the enumeration value.
|
// Parses the enumeration value.
|
||||||
} else if (field.fieldType === 'enumeration') {
|
} else if (field.fieldType === 'enumeration') {
|
||||||
const option = get(field, 'options', []).find(
|
const option = get(field, 'options', []).find(
|
||||||
(option) => option.label?.toLowerCase() === value?.toLowerCase(),
|
(option) => option.label?.toLowerCase() === value?.toLowerCase(),
|
||||||
);
|
);
|
||||||
_value = get(option, 'key');
|
_value = get(option, 'key');
|
||||||
// Parses the numeric value.
|
// Parses the numeric value.
|
||||||
} else if (field.fieldType === 'number') {
|
} else if (field.fieldType === 'number') {
|
||||||
_value = multiNumberParse(value);
|
_value = multiNumberParse(value);
|
||||||
// Parses the relation value.
|
// Parses the relation value.
|
||||||
} else if (field.fieldType === 'relation') {
|
} else if (field.fieldType === 'relation') {
|
||||||
const RelationModel = tenantModels[field.relationModel];
|
const RelationModel = modelResolver(field.relationModel);
|
||||||
|
|
||||||
if (!RelationModel) {
|
if (!RelationModel) {
|
||||||
throw new Error(`The relation model of ${key} field is not exist.`);
|
throw new Error(`The relation model of ${key} field is not exist.`);
|
||||||
}
|
}
|
||||||
const relationQuery = RelationModel.query(trx);
|
const relationQuery = RelationModel.query(trx);
|
||||||
const relationKeys = castArray(field?.relationImportMatch);
|
const relationKeys = castArray(field?.relationImportMatch);
|
||||||
|
|
||||||
relationQuery.where(function () {
|
relationQuery.where(function () {
|
||||||
relationKeys.forEach((relationKey: string) => {
|
relationKeys.forEach((relationKey: string) => {
|
||||||
this.orWhereRaw('LOWER(??) = LOWER(?)', [relationKey, value]);
|
this.orWhereRaw('LOWER(??) = LOWER(?)', [relationKey, value]);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
const result = await relationQuery.first();
|
||||||
const result = await relationQuery.first();
|
_value = get(result, 'id');
|
||||||
_value = get(result, 'id');
|
} else if (field.fieldType === 'collection') {
|
||||||
} else if (field.fieldType === 'collection') {
|
const ObjectFieldKey = key.includes('.') ? key.split('.')[1] : key;
|
||||||
const ObjectFieldKey = key.includes('.') ? key.split('.')[1] : key;
|
const _valueParser = valueParser(fields, modelResolver);
|
||||||
const _valueParser = valueParser(fields, tenantModels);
|
_value = await _valueParser(value, ObjectFieldKey, fieldKey);
|
||||||
_value = await _valueParser(value, ObjectFieldKey, fieldKey);
|
}
|
||||||
}
|
return _value;
|
||||||
return _value;
|
};
|
||||||
};
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Parses the field key and detarmines the key path.
|
* Parses the field key and detarmines the key path.
|
||||||
@@ -402,12 +404,17 @@ export function aggregate(
|
|||||||
groupOn: string,
|
groupOn: string,
|
||||||
): Array<Record<string, any>> {
|
): Array<Record<string, any>> {
|
||||||
return input.reduce((acc, curr) => {
|
return input.reduce((acc, curr) => {
|
||||||
|
// Skip aggregation if the current item doesn't have the comparator attribute
|
||||||
|
if (curr[comparatorAttr] === undefined || curr[comparatorAttr] === null) {
|
||||||
|
acc.push({ ...curr });
|
||||||
|
return acc;
|
||||||
|
}
|
||||||
const existingEntry = acc.find(
|
const existingEntry = acc.find(
|
||||||
(entry) => entry[comparatorAttr] === curr[comparatorAttr],
|
(entry) => entry[comparatorAttr] === curr[comparatorAttr],
|
||||||
);
|
);
|
||||||
|
|
||||||
if (existingEntry) {
|
if (existingEntry) {
|
||||||
existingEntry[groupOn].push(...curr.entries);
|
existingEntry[groupOn].push(...curr[groupOn]);
|
||||||
} else {
|
} else {
|
||||||
acc.push({ ...curr });
|
acc.push({ ...curr });
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -93,7 +93,7 @@ export class InventoryComputeCostService {
|
|||||||
*/
|
*/
|
||||||
async scheduleComputeItemCost(itemId: number, startingDate: Date | string) {
|
async scheduleComputeItemCost(itemId: number, startingDate: Date | string) {
|
||||||
const debounceKey = `inventory-cost-compute-debounce:${itemId}`;
|
const debounceKey = `inventory-cost-compute-debounce:${itemId}`;
|
||||||
const debounceTime = 1000 * 60; // 1 minute
|
const debounceTime = 1000 * 10; // 10 seconds
|
||||||
|
|
||||||
// Generate a unique job ID or use a custom identifier
|
// Generate a unique job ID or use a custom identifier
|
||||||
const jobId = `task-${Date.now()}-${Math.random().toString(36).substring(2)}`;
|
const jobId = `task-${Date.now()}-${Math.random().toString(36).substring(2)}`;
|
||||||
|
|||||||
@@ -2,7 +2,8 @@ import { EventEmitter2 } from '@nestjs/event-emitter';
|
|||||||
import { Processor, WorkerHost } from '@nestjs/bullmq';
|
import { Processor, WorkerHost } from '@nestjs/bullmq';
|
||||||
import { Scope } from '@nestjs/common';
|
import { Scope } from '@nestjs/common';
|
||||||
import { Job } from 'bullmq';
|
import { Job } from 'bullmq';
|
||||||
import { ClsService } from 'nestjs-cls';
|
import { ClsService, UseCls } from 'nestjs-cls';
|
||||||
|
import * as moment from 'moment';
|
||||||
import { TenantJobPayload } from '@/interfaces/Tenant';
|
import { TenantJobPayload } from '@/interfaces/Tenant';
|
||||||
import { InventoryComputeCostService } from '../commands/InventoryComputeCost.service';
|
import { InventoryComputeCostService } from '../commands/InventoryComputeCost.service';
|
||||||
import { events } from '@/common/events/events';
|
import { events } from '@/common/events/events';
|
||||||
@@ -14,7 +15,7 @@ import { Process } from '@nestjs/bull';
|
|||||||
|
|
||||||
interface ComputeItemCostJobPayload extends TenantJobPayload {
|
interface ComputeItemCostJobPayload extends TenantJobPayload {
|
||||||
itemId: number;
|
itemId: number;
|
||||||
startingDate: Date;
|
startingDate: Date | string;
|
||||||
}
|
}
|
||||||
@Processor({
|
@Processor({
|
||||||
name: ComputeItemCostQueue,
|
name: ComputeItemCostQueue,
|
||||||
@@ -39,28 +40,34 @@ export class ComputeItemCostProcessor extends WorkerHost {
|
|||||||
* @param {Job<ComputeItemCostJobPayload>} job - The job to process
|
* @param {Job<ComputeItemCostJobPayload>} job - The job to process
|
||||||
*/
|
*/
|
||||||
@Process(ComputeItemCostQueueJob)
|
@Process(ComputeItemCostQueueJob)
|
||||||
|
@UseCls()
|
||||||
async process(job: Job<ComputeItemCostJobPayload>) {
|
async process(job: Job<ComputeItemCostJobPayload>) {
|
||||||
const { itemId, startingDate, organizationId, userId } = job.data;
|
const { itemId, startingDate, organizationId, userId } = job.data;
|
||||||
|
|
||||||
console.log(`Compute item cost for item ${itemId} started`);
|
// Parse startingDate using moment to handle both Date and string formats
|
||||||
|
const startingDateObj = moment(startingDate).toDate();
|
||||||
|
|
||||||
|
console.log(`[info] Compute item cost for item ${itemId} started`, {
|
||||||
|
payload: job.data,
|
||||||
|
jobId: job.id
|
||||||
|
});
|
||||||
this.clsService.set('organizationId', organizationId);
|
this.clsService.set('organizationId', organizationId);
|
||||||
this.clsService.set('userId', userId);
|
this.clsService.set('userId', userId);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.inventoryComputeCostService.computeItemCost(
|
await this.inventoryComputeCostService.computeItemCost(
|
||||||
startingDate,
|
startingDateObj,
|
||||||
itemId,
|
itemId,
|
||||||
);
|
);
|
||||||
// Emit job completed event
|
// Emit job completed event
|
||||||
await this.eventEmitter.emitAsync(
|
await this.eventEmitter.emitAsync(
|
||||||
events.inventory.onComputeItemCostJobCompleted,
|
events.inventory.onComputeItemCostJobCompleted,
|
||||||
{ startingDate, itemId, organizationId, userId },
|
{ startingDate: startingDateObj, itemId, organizationId, userId },
|
||||||
);
|
);
|
||||||
|
console.log(`[info] Compute item cost for item ${itemId} completed successfully`);
|
||||||
console.log(`Compute item cost for item ${itemId} completed`);
|
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error('Error computing item cost:', error);
|
console.error(`[error] Error computing item cost for item ${itemId}:`, error);
|
||||||
|
console.error('Error stack:', error instanceof Error ? error.stack : 'No stack trace');
|
||||||
throw error;
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,16 +4,18 @@ export class ServiceError extends Error {
|
|||||||
errorType: string;
|
errorType: string;
|
||||||
message: string;
|
message: string;
|
||||||
payload: any;
|
payload: any;
|
||||||
|
httpStatus: HttpStatus;
|
||||||
|
|
||||||
constructor(errorType: string, message?: string, payload?: any) {
|
constructor(errorType: string, message?: string, payload?: any, httpStatus?: HttpStatus) {
|
||||||
super(message);
|
super(message);
|
||||||
|
|
||||||
this.errorType = errorType;
|
this.errorType = errorType;
|
||||||
this.message = message || null;
|
this.message = message || null;
|
||||||
this.payload = payload;
|
this.payload = payload;
|
||||||
|
this.httpStatus = httpStatus || HttpStatus.BAD_REQUEST;
|
||||||
}
|
}
|
||||||
|
|
||||||
getStatus(): HttpStatus {
|
getStatus(): HttpStatus {
|
||||||
return HttpStatus.INTERNAL_SERVER_ERROR;
|
return this.httpStatus;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -267,28 +267,28 @@ export const ItemMeta = {
|
|||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'Account',
|
relationModel: 'Account',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
importHint: 'Matches the account name or code.',
|
importHint: 'account.field.account_hint',
|
||||||
},
|
},
|
||||||
sellAccountId: {
|
sellAccountId: {
|
||||||
name: 'item.field.sell_account',
|
name: 'item.field.sell_account',
|
||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'Account',
|
relationModel: 'Account',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
importHint: 'Matches the account name or code.',
|
importHint: 'account.field.account_hint',
|
||||||
},
|
},
|
||||||
inventoryAccountId: {
|
inventoryAccountId: {
|
||||||
name: 'item.field.inventory_account',
|
name: 'item.field.inventory_account',
|
||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'Account',
|
relationModel: 'Account',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
importHint: 'Matches the account name or code.',
|
importHint: 'account.field.account_hint',
|
||||||
},
|
},
|
||||||
sellDescription: {
|
sellDescription: {
|
||||||
name: 'Sell Description',
|
name: 'item.field.sell_description',
|
||||||
fieldType: 'text',
|
fieldType: 'text',
|
||||||
},
|
},
|
||||||
purchaseDescription: {
|
purchaseDescription: {
|
||||||
name: 'Purchase Description',
|
name: 'item.field.purchase_description',
|
||||||
fieldType: 'text',
|
fieldType: 'text',
|
||||||
},
|
},
|
||||||
note: {
|
note: {
|
||||||
@@ -300,7 +300,7 @@ export const ItemMeta = {
|
|||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'ItemCategory',
|
relationModel: 'ItemCategory',
|
||||||
relationImportMatch: ['name'],
|
relationImportMatch: ['name'],
|
||||||
importHint: 'Matches the category name.',
|
importHint: 'item.field.category_hint',
|
||||||
},
|
},
|
||||||
active: {
|
active: {
|
||||||
name: 'item.field.active',
|
name: 'item.field.active',
|
||||||
|
|||||||
@@ -74,6 +74,9 @@ export class PaymentReceivedResponseDto {
|
|||||||
@ApiProperty({ description: 'The formatted amount', example: '100.00' })
|
@ApiProperty({ description: 'The formatted amount', example: '100.00' })
|
||||||
formattedAmount: string;
|
formattedAmount: string;
|
||||||
|
|
||||||
|
@ApiProperty({ description: 'The formatted total', example: '100.00 USD' })
|
||||||
|
formattedTotal: string;
|
||||||
|
|
||||||
@ApiProperty({ description: 'The currency code', example: 'USD' })
|
@ApiProperty({ description: 'The currency code', example: 'USD' })
|
||||||
currencyCode: string;
|
currencyCode: string;
|
||||||
|
|
||||||
|
|||||||
@@ -165,12 +165,12 @@ export const PaymentReceivedMeta = {
|
|||||||
relationModel: 'Account',
|
relationModel: 'Account',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
required: true,
|
required: true,
|
||||||
importHint: 'Matches the account name or code.',
|
importHint: 'account.field.account_hint',
|
||||||
},
|
},
|
||||||
paymentReceiveNo: {
|
paymentReceiveNo: {
|
||||||
name: 'payment_receive.field.payment_receive_no',
|
name: 'payment_receive.field.payment_receive_no',
|
||||||
fieldType: 'text',
|
fieldType: 'text',
|
||||||
importHint: 'The payment number should be unique.',
|
importHint: 'payment_receive.field.payment_no_hint',
|
||||||
},
|
},
|
||||||
statement: {
|
statement: {
|
||||||
name: 'payment_receive.field.statement',
|
name: 'payment_receive.field.statement',
|
||||||
@@ -189,7 +189,7 @@ export const PaymentReceivedMeta = {
|
|||||||
relationModel: 'SaleInvoice',
|
relationModel: 'SaleInvoice',
|
||||||
relationImportMatch: 'invoiceNo',
|
relationImportMatch: 'invoiceNo',
|
||||||
required: true,
|
required: true,
|
||||||
importHint: 'Matches the invoice number.',
|
importHint: 'payment_receive.field.invoice_hint',
|
||||||
},
|
},
|
||||||
paymentAmount: {
|
paymentAmount: {
|
||||||
name: 'payment_receive.field.entries.payment_amount',
|
name: 'payment_receive.field.entries.payment_amount',
|
||||||
@@ -199,7 +199,7 @@ export const PaymentReceivedMeta = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
branchId: {
|
branchId: {
|
||||||
name: 'Branch',
|
name: 'invoice.field.branch',
|
||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'Branch',
|
relationModel: 'Branch',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
|
|||||||
@@ -1,12 +1,11 @@
|
|||||||
import { JOB_REF, Process, Processor } from '@nestjs/bull';
|
import { JOB_REF, Process, Processor } from '@nestjs/bull';
|
||||||
import { Job } from 'bull';
|
import { Job } from 'bull';
|
||||||
|
import { Inject, Scope } from '@nestjs/common';
|
||||||
|
import { ClsService, UseCls } from 'nestjs-cls';
|
||||||
import {
|
import {
|
||||||
SEND_PAYMENT_RECEIVED_MAIL_JOB,
|
SEND_PAYMENT_RECEIVED_MAIL_JOB,
|
||||||
SEND_PAYMENT_RECEIVED_MAIL_QUEUE,
|
SEND_PAYMENT_RECEIVED_MAIL_QUEUE,
|
||||||
} from '../constants';
|
} from '../constants';
|
||||||
import { Inject, Scope } from '@nestjs/common';
|
|
||||||
import { REQUEST } from '@nestjs/core';
|
|
||||||
import { ClsService } from 'nestjs-cls';
|
|
||||||
import { SendPaymentReceiveMailNotification } from '../commands/PaymentReceivedMailNotification';
|
import { SendPaymentReceiveMailNotification } from '../commands/PaymentReceivedMailNotification';
|
||||||
import { SendPaymentReceivedMailPayload } from '../types/PaymentReceived.types';
|
import { SendPaymentReceivedMailPayload } from '../types/PaymentReceived.types';
|
||||||
|
|
||||||
@@ -21,9 +20,10 @@ export class SendPaymentReceivedMailProcessor {
|
|||||||
|
|
||||||
@Inject(JOB_REF)
|
@Inject(JOB_REF)
|
||||||
private readonly jobRef: Job<SendPaymentReceivedMailPayload>,
|
private readonly jobRef: Job<SendPaymentReceivedMailPayload>,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
@Process(SEND_PAYMENT_RECEIVED_MAIL_JOB)
|
@Process(SEND_PAYMENT_RECEIVED_MAIL_JOB)
|
||||||
|
@UseCls()
|
||||||
async handleSendMail() {
|
async handleSendMail() {
|
||||||
const { messageOptions, paymentReceivedId, organizationId, userId } =
|
const { messageOptions, paymentReceivedId, organizationId, userId } =
|
||||||
this.jobRef.data;
|
this.jobRef.data;
|
||||||
@@ -37,7 +37,8 @@ export class SendPaymentReceivedMailProcessor {
|
|||||||
messageOptions,
|
messageOptions,
|
||||||
);
|
);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error('Failed to process payment received mail job:', error);
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,6 +11,7 @@ export class PaymentReceiveTransfromer extends Transformer {
|
|||||||
public includeAttributes = (): string[] => {
|
public includeAttributes = (): string[] => {
|
||||||
return [
|
return [
|
||||||
'subtotalFormatted',
|
'subtotalFormatted',
|
||||||
|
'formatttedTotal',
|
||||||
'formattedPaymentDate',
|
'formattedPaymentDate',
|
||||||
'formattedCreatedAt',
|
'formattedCreatedAt',
|
||||||
'formattedAmount',
|
'formattedAmount',
|
||||||
@@ -45,7 +46,18 @@ export class PaymentReceiveTransfromer extends Transformer {
|
|||||||
protected subtotalFormatted = (payment: PaymentReceived): string => {
|
protected subtotalFormatted = (payment: PaymentReceived): string => {
|
||||||
return this.formatNumber(payment.amount, {
|
return this.formatNumber(payment.amount, {
|
||||||
currencyCode: payment.currencyCode,
|
currencyCode: payment.currencyCode,
|
||||||
money: false,
|
});
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieves the formatted total.
|
||||||
|
* @param {PaymentReceived} payment
|
||||||
|
* @returns {string}
|
||||||
|
*/
|
||||||
|
protected formatttedTotal = (payment: PaymentReceived): string => {
|
||||||
|
return this.formatNumber(payment.amount, {
|
||||||
|
currencyCode: payment.currencyCode,
|
||||||
|
money: true,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -66,7 +78,7 @@ export class PaymentReceiveTransfromer extends Transformer {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
protected formattedExchangeRate = (payment: PaymentReceived): string => {
|
protected formattedExchangeRate = (payment: PaymentReceived): string => {
|
||||||
return this.formatNumber(payment.exchangeRate, { money: false });
|
return this.formatNumber(payment.exchangeRate);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
import { ModuleRef } from '@nestjs/core';
|
import { ModuleRef } from '@nestjs/core';
|
||||||
import { pickBy } from 'lodash';
|
import { pickBy, mapValues } from 'lodash';
|
||||||
|
import { I18nService } from 'nestjs-i18n';
|
||||||
import { WarehousesSettings } from '../Warehouses/WarehousesSettings';
|
import { WarehousesSettings } from '../Warehouses/WarehousesSettings';
|
||||||
import { Injectable } from '@nestjs/common';
|
import { Injectable } from '@nestjs/common';
|
||||||
import { BranchesSettingsService } from '../Branches/BranchesSettings';
|
import { BranchesSettingsService } from '../Branches/BranchesSettings';
|
||||||
@@ -20,7 +21,8 @@ export class ResourceService {
|
|||||||
private readonly branchesSettings: BranchesSettingsService,
|
private readonly branchesSettings: BranchesSettingsService,
|
||||||
private readonly warehousesSettings: WarehousesSettings,
|
private readonly warehousesSettings: WarehousesSettings,
|
||||||
private readonly moduleRef: ModuleRef,
|
private readonly moduleRef: ModuleRef,
|
||||||
) {}
|
private readonly i18nService: I18nService,
|
||||||
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve resource model object.
|
* Retrieve resource model object.
|
||||||
@@ -96,7 +98,45 @@ export class ResourceService {
|
|||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Retrieve the resource fields.
|
* Localizes a single field by translating its name and importHint.
|
||||||
|
* @param {IModelMetaField2} field - The field to localize.
|
||||||
|
* @returns {IModelMetaField2} - The localized field.
|
||||||
|
*/
|
||||||
|
private localizeField(field: IModelMetaField2): IModelMetaField2 {
|
||||||
|
const localizedField = {
|
||||||
|
...field,
|
||||||
|
name: this.i18nService.t(field.name, { defaultValue: field.name }),
|
||||||
|
} as IModelMetaField2;
|
||||||
|
|
||||||
|
if (field.importHint) {
|
||||||
|
localizedField.importHint = this.i18nService.t(field.importHint, {
|
||||||
|
defaultValue: field.importHint,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// Recursively localize nested fields (for collection types)
|
||||||
|
if (field.fields) {
|
||||||
|
localizedField.fields = this.localizeFields(
|
||||||
|
field.fields as unknown as Record<string, IModelMetaField2>,
|
||||||
|
) as unknown as typeof field.fields;
|
||||||
|
}
|
||||||
|
|
||||||
|
return localizedField;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Localizes all fields in a fields map.
|
||||||
|
* @param {Record<string, IModelMetaField2>} fields - The fields to localize.
|
||||||
|
* @returns {Record<string, IModelMetaField2>} - The localized fields.
|
||||||
|
*/
|
||||||
|
private localizeFields(
|
||||||
|
fields: Record<string, IModelMetaField2>,
|
||||||
|
): Record<string, IModelMetaField2> {
|
||||||
|
return mapValues(fields, (field) => this.localizeField(field));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Retrieve the resource fields with localized names and hints.
|
||||||
* @param {string} modelName
|
* @param {string} modelName
|
||||||
* @returns {IModelMetaField2}
|
* @returns {IModelMetaField2}
|
||||||
*/
|
*/
|
||||||
@@ -104,8 +144,11 @@ export class ResourceService {
|
|||||||
[key: string]: IModelMetaField2;
|
[key: string]: IModelMetaField2;
|
||||||
} {
|
} {
|
||||||
const meta = this.getResourceMeta(modelName);
|
const meta = this.getResourceMeta(modelName);
|
||||||
|
const filteredFields = this.filterSupportFeatures(meta.fields2);
|
||||||
|
|
||||||
return this.filterSupportFeatures(meta.fields2);
|
return this.localizeFields(
|
||||||
|
filteredFields as Record<string, IModelMetaField2>,
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -42,6 +42,7 @@ import { GetSaleEstimateMailTemplateService } from './queries/GetSaleEstimateMai
|
|||||||
import { SaleEstimateAutoIncrementSubscriber } from './subscribers/SaleEstimateAutoIncrementSubscriber';
|
import { SaleEstimateAutoIncrementSubscriber } from './subscribers/SaleEstimateAutoIncrementSubscriber';
|
||||||
import { BulkDeleteSaleEstimatesService } from './BulkDeleteSaleEstimates.service';
|
import { BulkDeleteSaleEstimatesService } from './BulkDeleteSaleEstimates.service';
|
||||||
import { ValidateBulkDeleteSaleEstimatesService } from './ValidateBulkDeleteSaleEstimates.service';
|
import { ValidateBulkDeleteSaleEstimatesService } from './ValidateBulkDeleteSaleEstimates.service';
|
||||||
|
import { SendSaleEstimateMailProcess } from './processes/SendSaleEstimateMail.process';
|
||||||
|
|
||||||
@Module({
|
@Module({
|
||||||
imports: [
|
imports: [
|
||||||
@@ -89,6 +90,7 @@ import { ValidateBulkDeleteSaleEstimatesService } from './ValidateBulkDeleteSale
|
|||||||
SaleEstimateAutoIncrementSubscriber,
|
SaleEstimateAutoIncrementSubscriber,
|
||||||
BulkDeleteSaleEstimatesService,
|
BulkDeleteSaleEstimatesService,
|
||||||
ValidateBulkDeleteSaleEstimatesService,
|
ValidateBulkDeleteSaleEstimatesService,
|
||||||
|
SendSaleEstimateMailProcess,
|
||||||
],
|
],
|
||||||
exports: [
|
exports: [
|
||||||
SaleEstimatesExportable,
|
SaleEstimatesExportable,
|
||||||
|
|||||||
@@ -24,6 +24,7 @@ import { Mail } from '@/modules/Mail/Mail';
|
|||||||
import { MailTransporter } from '@/modules/Mail/MailTransporter.service';
|
import { MailTransporter } from '@/modules/Mail/MailTransporter.service';
|
||||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
import { GetSaleEstimateMailTemplateService } from '../queries/GetSaleEstimateMailTemplate.service';
|
import { GetSaleEstimateMailTemplateService } from '../queries/GetSaleEstimateMailTemplate.service';
|
||||||
|
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class SendSaleEstimateMail {
|
export class SendSaleEstimateMail {
|
||||||
@@ -42,13 +43,14 @@ export class SendSaleEstimateMail {
|
|||||||
private readonly getEstimateMailTemplate: GetSaleEstimateMailTemplateService,
|
private readonly getEstimateMailTemplate: GetSaleEstimateMailTemplateService,
|
||||||
private readonly eventPublisher: EventEmitter2,
|
private readonly eventPublisher: EventEmitter2,
|
||||||
private readonly mailTransporter: MailTransporter,
|
private readonly mailTransporter: MailTransporter,
|
||||||
|
private readonly tenancyContext: TenancyContext,
|
||||||
|
|
||||||
@Inject(SaleEstimate.name)
|
@Inject(SaleEstimate.name)
|
||||||
private readonly saleEstimateModel: TenantModelProxy<typeof SaleEstimate>,
|
private readonly saleEstimateModel: TenantModelProxy<typeof SaleEstimate>,
|
||||||
|
|
||||||
@InjectQueue(SendSaleEstimateMailQueue)
|
@InjectQueue(SendSaleEstimateMailQueue)
|
||||||
private readonly sendEstimateMailQueue: Queue,
|
private readonly sendEstimateMailQueue: Queue,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Triggers the reminder mail of the given sale estimate.
|
* Triggers the reminder mail of the given sale estimate.
|
||||||
@@ -60,10 +62,19 @@ export class SendSaleEstimateMail {
|
|||||||
saleEstimateId: number,
|
saleEstimateId: number,
|
||||||
messageOptions: SaleEstimateMailOptionsDTO,
|
messageOptions: SaleEstimateMailOptionsDTO,
|
||||||
): Promise<void> {
|
): Promise<void> {
|
||||||
|
const tenant = await this.tenancyContext.getTenant();
|
||||||
|
const user = await this.tenancyContext.getSystemUser();
|
||||||
|
|
||||||
|
const organizationId = tenant.organizationId;
|
||||||
|
const userId = user.id;
|
||||||
|
|
||||||
const payload = {
|
const payload = {
|
||||||
saleEstimateId,
|
saleEstimateId,
|
||||||
messageOptions,
|
messageOptions,
|
||||||
|
userId,
|
||||||
|
organizationId,
|
||||||
};
|
};
|
||||||
|
|
||||||
await this.sendEstimateMailQueue.add(SendSaleEstimateMailJob, payload);
|
await this.sendEstimateMailQueue.add(SendSaleEstimateMailJob, payload);
|
||||||
|
|
||||||
// Triggers `onSaleEstimatePreMailSend` event.
|
// Triggers `onSaleEstimatePreMailSend` event.
|
||||||
|
|||||||
@@ -191,52 +191,52 @@ export const SaleEstimateMeta = {
|
|||||||
},
|
},
|
||||||
fields2: {
|
fields2: {
|
||||||
customerId: {
|
customerId: {
|
||||||
name: 'Customer',
|
name: 'estimate.field.customer',
|
||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'Contact',
|
relationModel: 'Contact',
|
||||||
relationImportMatch: ['displayName'],
|
relationImportMatch: ['displayName'],
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
estimateDate: {
|
estimateDate: {
|
||||||
name: 'Estimate Date',
|
name: 'estimate.field.estimate_date',
|
||||||
fieldType: 'date',
|
fieldType: 'date',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
expirationDate: {
|
expirationDate: {
|
||||||
name: 'Expiration Date',
|
name: 'estimate.field.expiration_date',
|
||||||
fieldType: 'date',
|
fieldType: 'date',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
estimateNumber: {
|
estimateNumber: {
|
||||||
name: 'Estimate No.',
|
name: 'estimate.field.estimate_number',
|
||||||
fieldType: 'text',
|
fieldType: 'text',
|
||||||
},
|
},
|
||||||
reference: {
|
reference: {
|
||||||
name: 'Reference No.',
|
name: 'estimate.field.reference_no',
|
||||||
fieldType: 'text',
|
fieldType: 'text',
|
||||||
},
|
},
|
||||||
exchangeRate: {
|
exchangeRate: {
|
||||||
name: 'Exchange Rate',
|
name: 'estimate.field.exchange_rate',
|
||||||
fieldType: 'number',
|
fieldType: 'number',
|
||||||
},
|
},
|
||||||
currencyCode: {
|
currencyCode: {
|
||||||
name: 'Currency',
|
name: 'estimate.field.currency',
|
||||||
fieldType: 'text',
|
fieldType: 'text',
|
||||||
},
|
},
|
||||||
note: {
|
note: {
|
||||||
name: 'Note',
|
name: 'estimate.field.note',
|
||||||
fieldType: 'text',
|
fieldType: 'text',
|
||||||
},
|
},
|
||||||
termsConditions: {
|
termsConditions: {
|
||||||
name: 'Terms & Conditions',
|
name: 'estimate.field.terms_conditions',
|
||||||
fieldType: 'text',
|
fieldType: 'text',
|
||||||
},
|
},
|
||||||
delivered: {
|
delivered: {
|
||||||
name: 'Delivered',
|
name: 'estimate.field.delivered',
|
||||||
type: 'boolean',
|
type: 'boolean',
|
||||||
},
|
},
|
||||||
entries: {
|
entries: {
|
||||||
name: 'Entries',
|
name: 'estimate.field.entries',
|
||||||
fieldType: 'collection',
|
fieldType: 'collection',
|
||||||
collectionOf: 'object',
|
collectionOf: 'object',
|
||||||
collectionMinLength: 1,
|
collectionMinLength: 1,
|
||||||
@@ -248,7 +248,7 @@ export const SaleEstimateMeta = {
|
|||||||
relationModel: 'Item',
|
relationModel: 'Item',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
required: true,
|
required: true,
|
||||||
importHint: 'Matches the item name or code.',
|
importHint: 'invoice.field.item_hint',
|
||||||
},
|
},
|
||||||
rate: {
|
rate: {
|
||||||
name: 'invoice.field.rate',
|
name: 'invoice.field.rate',
|
||||||
@@ -261,13 +261,13 @@ export const SaleEstimateMeta = {
|
|||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
description: {
|
description: {
|
||||||
name: 'Line Description',
|
name: 'invoice.field.description',
|
||||||
fieldType: 'text',
|
fieldType: 'text',
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
branchId: {
|
branchId: {
|
||||||
name: 'Branch',
|
name: 'invoice.field.branch',
|
||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'Branch',
|
relationModel: 'Branch',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
@@ -275,7 +275,7 @@ export const SaleEstimateMeta = {
|
|||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
warehouseId: {
|
warehouseId: {
|
||||||
name: 'Warehouse',
|
name: 'invoice.field.warehouse',
|
||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'Warehouse',
|
relationModel: 'Warehouse',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
|
|||||||
@@ -1,19 +1,39 @@
|
|||||||
import { Process, Processor } from '@nestjs/bull';
|
import { Process, Processor } from '@nestjs/bull';
|
||||||
import { Job } from 'bull';
|
import { Job } from 'bull';
|
||||||
|
import { Inject, Scope } from '@nestjs/common';
|
||||||
|
import { JOB_REF } from '@nestjs/bull';
|
||||||
import {
|
import {
|
||||||
SendSaleEstimateMailJob,
|
SendSaleEstimateMailJob,
|
||||||
SendSaleEstimateMailQueue,
|
SendSaleEstimateMailQueue,
|
||||||
} from '../types/SaleEstimates.types';
|
} from '../types/SaleEstimates.types';
|
||||||
import { SendSaleEstimateMail } from '../commands/SendSaleEstimateMail';
|
import { SendSaleEstimateMail } from '../commands/SendSaleEstimateMail';
|
||||||
|
import { ClsService, UseCls } from 'nestjs-cls';
|
||||||
|
|
||||||
@Processor(SendSaleEstimateMailQueue)
|
@Processor({
|
||||||
|
name: SendSaleEstimateMailQueue,
|
||||||
|
scope: Scope.REQUEST,
|
||||||
|
})
|
||||||
export class SendSaleEstimateMailProcess {
|
export class SendSaleEstimateMailProcess {
|
||||||
constructor(private readonly sendEstimateMailService: SendSaleEstimateMail) {}
|
constructor(
|
||||||
|
private readonly sendEstimateMailService: SendSaleEstimateMail,
|
||||||
|
private readonly clsService: ClsService,
|
||||||
|
@Inject(JOB_REF)
|
||||||
|
private readonly jobRef: Job,
|
||||||
|
) { }
|
||||||
|
|
||||||
@Process(SendSaleEstimateMailJob)
|
@Process(SendSaleEstimateMailJob)
|
||||||
async handleSendMail(job: Job) {
|
@UseCls()
|
||||||
const { saleEstimateId, messageOptions } = job.data;
|
async handleSendMail() {
|
||||||
|
const { saleEstimateId, messageOptions, organizationId, userId } = this.jobRef.data;
|
||||||
|
|
||||||
await this.sendEstimateMailService.sendMail(saleEstimateId, messageOptions);
|
this.clsService.set('organizationId', organizationId);
|
||||||
|
this.clsService.set('userId', userId);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await this.sendEstimateMailService.sendMail(saleEstimateId, messageOptions);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to process estimate mail job:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -17,7 +17,7 @@ export class SaleEstimateTransfromer extends Transformer {
|
|||||||
'formattedDeliveredAtDate',
|
'formattedDeliveredAtDate',
|
||||||
'formattedApprovedAtDate',
|
'formattedApprovedAtDate',
|
||||||
'formattedRejectedAtDate',
|
'formattedRejectedAtDate',
|
||||||
|
|
||||||
'discountAmountFormatted',
|
'discountAmountFormatted',
|
||||||
'discountPercentageFormatted',
|
'discountPercentageFormatted',
|
||||||
'adjustmentFormatted',
|
'adjustmentFormatted',
|
||||||
@@ -135,7 +135,7 @@ export class SaleEstimateTransfromer extends Transformer {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
protected adjustmentFormatted = (estimate: SaleEstimate): string => {
|
protected adjustmentFormatted = (estimate: SaleEstimate): string => {
|
||||||
return this.formatMoney(estimate.adjustment, {
|
return this.formatNumber(estimate.adjustment, {
|
||||||
currencyCode: estimate.currencyCode,
|
currencyCode: estimate.currencyCode,
|
||||||
excerptZero: true,
|
excerptZero: true,
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -19,7 +19,7 @@ export class SaleInvoiceCostGLEntries {
|
|||||||
private readonly inventoryCostLotTracker: TenantModelProxy<
|
private readonly inventoryCostLotTracker: TenantModelProxy<
|
||||||
typeof InventoryCostLotTracker
|
typeof InventoryCostLotTracker
|
||||||
>,
|
>,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Writes journal entries from sales invoices.
|
* Writes journal entries from sales invoices.
|
||||||
|
|||||||
@@ -99,7 +99,8 @@ export class SaleInvoicesController {
|
|||||||
return this.saleInvoiceApplication.createSaleInvoice(saleInvoiceDTO);
|
return this.saleInvoiceApplication.createSaleInvoice(saleInvoiceDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put(':id/mail')
|
@Post(':id/mail')
|
||||||
|
@HttpCode(200)
|
||||||
@ApiOperation({ summary: 'Send the sale invoice mail.' })
|
@ApiOperation({ summary: 'Send the sale invoice mail.' })
|
||||||
@ApiResponse({
|
@ApiResponse({
|
||||||
status: 200,
|
status: 200,
|
||||||
|
|||||||
@@ -10,6 +10,7 @@ import { PaymentLink } from '@/modules/PaymentLinks/models/PaymentLink';
|
|||||||
import { SaleInvoice } from '../models/SaleInvoice';
|
import { SaleInvoice } from '../models/SaleInvoice';
|
||||||
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
import { TenantModelProxy } from '@/modules/System/models/TenantBaseModel';
|
||||||
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';
|
import { TenancyContext } from '@/modules/Tenancy/TenancyContext.service';
|
||||||
|
import { ConfigService } from '@nestjs/config';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class GenerateShareLink {
|
export class GenerateShareLink {
|
||||||
@@ -18,13 +19,14 @@ export class GenerateShareLink {
|
|||||||
private eventPublisher: EventEmitter2,
|
private eventPublisher: EventEmitter2,
|
||||||
private transformer: TransformerInjectable,
|
private transformer: TransformerInjectable,
|
||||||
private tenancyContext: TenancyContext,
|
private tenancyContext: TenancyContext,
|
||||||
|
private configService: ConfigService,
|
||||||
|
|
||||||
@Inject(SaleInvoice.name)
|
@Inject(SaleInvoice.name)
|
||||||
private saleInvoiceModel: TenantModelProxy<typeof SaleInvoice>,
|
private saleInvoiceModel: TenantModelProxy<typeof SaleInvoice>,
|
||||||
|
|
||||||
@Inject(PaymentLink.name)
|
@Inject(PaymentLink.name)
|
||||||
private paymentLinkModel: typeof PaymentLink,
|
private paymentLinkModel: typeof PaymentLink,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates private or public payment link for the given sale invoice.
|
* Generates private or public payment link for the given sale invoice.
|
||||||
@@ -75,6 +77,9 @@ export class GenerateShareLink {
|
|||||||
return this.transformer.transform(
|
return this.transformer.transform(
|
||||||
paymentLink,
|
paymentLink,
|
||||||
new GeneratePaymentLinkTransformer(),
|
new GeneratePaymentLinkTransformer(),
|
||||||
|
{
|
||||||
|
baseUrl: this.configService.get('app.baseUrl'),
|
||||||
|
}
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,7 +1,10 @@
|
|||||||
import { Transformer } from '@/modules/Transformer/Transformer';
|
import { Transformer } from '@/modules/Transformer/Transformer';
|
||||||
import { PUBLIC_PAYMENT_LINK } from '../constants';
|
import { PUBLIC_PAYMENT_LINK } from '../constants';
|
||||||
|
|
||||||
export class GeneratePaymentLinkTransformer extends Transformer {
|
interface GeneratePaymentLinkTransformerOptions {
|
||||||
|
baseUrl: string;
|
||||||
|
}
|
||||||
|
export class GeneratePaymentLinkTransformer extends Transformer<GeneratePaymentLinkTransformerOptions> {
|
||||||
/**
|
/**
|
||||||
* Exclude these attributes from payment link object.
|
* Exclude these attributes from payment link object.
|
||||||
* @returns {Array}
|
* @returns {Array}
|
||||||
@@ -23,6 +26,9 @@ export class GeneratePaymentLinkTransformer extends Transformer {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
public link(link) {
|
public link(link) {
|
||||||
return PUBLIC_PAYMENT_LINK?.replace('{PAYMENT_LINK_ID}', link.linkId);
|
return PUBLIC_PAYMENT_LINK?.replace(
|
||||||
|
'{BASE_URL}',
|
||||||
|
this.options.baseUrl,
|
||||||
|
).replace('{PAYMENT_LINK_ID}', link.linkId);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -5,10 +5,10 @@ import { Importable } from '@/modules/Import/Importable';
|
|||||||
import { CreateSaleInvoiceDto } from '../dtos/SaleInvoice.dto';
|
import { CreateSaleInvoiceDto } from '../dtos/SaleInvoice.dto';
|
||||||
import { SaleInvoicesSampleData } from '../constants';
|
import { SaleInvoicesSampleData } from '../constants';
|
||||||
import { ImportableService } from '@/modules/Import/decorators/Import.decorator';
|
import { ImportableService } from '@/modules/Import/decorators/Import.decorator';
|
||||||
import { ManualJournal } from '@/modules/ManualJournals/models/ManualJournal';
|
import { SaleInvoice } from '../models/SaleInvoice';
|
||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
@ImportableService({ name: ManualJournal.name })
|
@ImportableService({ name: SaleInvoice.name })
|
||||||
export class SaleInvoicesImportable extends Importable {
|
export class SaleInvoicesImportable extends Importable {
|
||||||
constructor(private readonly createInvoiceService: CreateSaleInvoice) {
|
constructor(private readonly createInvoiceService: CreateSaleInvoice) {
|
||||||
super();
|
super();
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export class SendSaleInvoiceMail {
|
|||||||
private readonly tenancyContect: TenancyContext,
|
private readonly tenancyContect: TenancyContext,
|
||||||
|
|
||||||
@InjectQueue(SendSaleInvoiceQueue) private readonly sendInvoiceQueue: Queue,
|
@InjectQueue(SendSaleInvoiceQueue) private readonly sendInvoiceQueue: Queue,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Sends the invoice mail of the given sale invoice.
|
* Sends the invoice mail of the given sale invoice.
|
||||||
@@ -132,7 +132,13 @@ export class SendSaleInvoiceMail {
|
|||||||
events.saleInvoice.onMailSend,
|
events.saleInvoice.onMailSend,
|
||||||
eventPayload,
|
eventPayload,
|
||||||
);
|
);
|
||||||
await this.mailTransporter.send(mail);
|
|
||||||
|
try {
|
||||||
|
await this.mailTransporter.send(mail);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to send invoice mail:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
|
|
||||||
// Triggers the event `onSaleInvoiceSend`.
|
// Triggers the event `onSaleInvoiceSend`.
|
||||||
await this.eventEmitter.emitAsync(
|
await this.eventEmitter.emitAsync(
|
||||||
|
|||||||
@@ -3,10 +3,9 @@
|
|||||||
export const SendSaleInvoiceQueue = 'SendSaleInvoiceQueue';
|
export const SendSaleInvoiceQueue = 'SendSaleInvoiceQueue';
|
||||||
export const SendSaleInvoiceMailJob = 'SendSaleInvoiceMailJob';
|
export const SendSaleInvoiceMailJob = 'SendSaleInvoiceMailJob';
|
||||||
|
|
||||||
const BASE_URL = 'http://localhost:3000';
|
|
||||||
|
|
||||||
export const DEFAULT_INVOICE_MAIL_SUBJECT =
|
export const DEFAULT_INVOICE_MAIL_SUBJECT =
|
||||||
'Invoice {Invoice Number} from {Company Name} for {Customer Name}';
|
'Invoice {Invoice Number} from {Company Name} for {Customer Name}';
|
||||||
export const DEFAULT_INVOICE_MAIL_CONTENT = `Hi {Customer Name},
|
export const DEFAULT_INVOICE_MAIL_CONTENT = `Hi {Customer Name},
|
||||||
|
|
||||||
Here's invoice # {Invoice Number} for {Invoice Amount}
|
Here's invoice # {Invoice Number} for {Invoice Amount}
|
||||||
@@ -23,8 +22,8 @@ Thanks,
|
|||||||
|
|
||||||
export const DEFAULT_INVOICE_REMINDER_MAIL_SUBJECT =
|
export const DEFAULT_INVOICE_REMINDER_MAIL_SUBJECT =
|
||||||
'Invoice {InvoiceNumber} reminder from {CompanyName}';
|
'Invoice {InvoiceNumber} reminder from {CompanyName}';
|
||||||
export const DEFAULT_INVOICE_REMINDER_MAIL_CONTENT = `
|
export const DEFAULT_INVOICE_REMINDER_MAIL_CONTENT = `
|
||||||
<p>Dear {CustomerName}</p>
|
<p>Dear {CustomerName}</p>
|
||||||
<p>You might have missed the payment date and the invoice is now overdue by {OverdueDays} days.</p>
|
<p>You might have missed the payment date and the invoice is now overdue by {OverdueDays} days.</p>
|
||||||
<p>Invoice <strong>#{InvoiceNumber}</strong><br />
|
<p>Invoice <strong>#{InvoiceNumber}</strong><br />
|
||||||
Due Date : <strong>{InvoiceDueDate}</strong><br />
|
Due Date : <strong>{InvoiceDueDate}</strong><br />
|
||||||
@@ -36,7 +35,7 @@ Amount : <strong>{InvoiceAmount}</strong></p>
|
|||||||
</p>
|
</p>
|
||||||
`;
|
`;
|
||||||
|
|
||||||
export const PUBLIC_PAYMENT_LINK = `${BASE_URL}/payment/{PAYMENT_LINK_ID}`;
|
export const PUBLIC_PAYMENT_LINK = "{BASE_URL}/payment/{PAYMENT_LINK_ID}";
|
||||||
|
|
||||||
export const ERRORS = {
|
export const ERRORS = {
|
||||||
INVOICE_NUMBER_NOT_UNIQUE: 'INVOICE_NUMBER_NOT_UNIQUE',
|
INVOICE_NUMBER_NOT_UNIQUE: 'INVOICE_NUMBER_NOT_UNIQUE',
|
||||||
|
|||||||
@@ -259,7 +259,7 @@ export const SaleInvoiceMeta = {
|
|||||||
relationModel: 'Item',
|
relationModel: 'Item',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
required: true,
|
required: true,
|
||||||
importHint: 'Matches the item name or code.',
|
importHint: 'invoice.field.item_hint',
|
||||||
},
|
},
|
||||||
rate: {
|
rate: {
|
||||||
name: 'invoice.field.rate',
|
name: 'invoice.field.rate',
|
||||||
@@ -283,7 +283,7 @@ export const SaleInvoiceMeta = {
|
|||||||
printable: false,
|
printable: false,
|
||||||
},
|
},
|
||||||
branchId: {
|
branchId: {
|
||||||
name: 'Branch',
|
name: 'invoice.field.branch',
|
||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'Branch',
|
relationModel: 'Branch',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
@@ -291,7 +291,7 @@ export const SaleInvoiceMeta = {
|
|||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
warehouseId: {
|
warehouseId: {
|
||||||
name: 'Warehouse',
|
name: 'invoice.field.warehouse',
|
||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'Warehouse',
|
relationModel: 'Warehouse',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
|
|||||||
@@ -18,9 +18,10 @@ export class SendSaleInvoiceMailProcessor {
|
|||||||
@Inject(JOB_REF)
|
@Inject(JOB_REF)
|
||||||
private readonly jobRef: Job<SendSaleInvoiceMailJobPayload>,
|
private readonly jobRef: Job<SendSaleInvoiceMailJobPayload>,
|
||||||
private readonly clsService: ClsService,
|
private readonly clsService: ClsService,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
@Process(SendSaleInvoiceMailJob)
|
@Process(SendSaleInvoiceMailJob)
|
||||||
|
@UseCls()
|
||||||
async handleSendInvoice() {
|
async handleSendInvoice() {
|
||||||
const { messageOptions, saleInvoiceId, organizationId, userId } =
|
const { messageOptions, saleInvoiceId, organizationId, userId } =
|
||||||
this.jobRef.data;
|
this.jobRef.data;
|
||||||
@@ -31,7 +32,8 @@ export class SendSaleInvoiceMailProcessor {
|
|||||||
try {
|
try {
|
||||||
await this.sendSaleInvoiceMail.sendMail(saleInvoiceId, messageOptions);
|
await this.sendSaleInvoiceMail.sendMail(saleInvoiceId, messageOptions);
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.log(error);
|
console.error('Failed to process invoice mail job:', error);
|
||||||
|
throw error;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -209,7 +209,7 @@ class GetInvoicePaymentLinkTaxEntryTransformer extends SaleInvoiceTaxEntryTransf
|
|||||||
|
|
||||||
class GetInvoicePaymentLinkBrandingTemplate extends GetPdfTemplateTransformer {
|
class GetInvoicePaymentLinkBrandingTemplate extends GetPdfTemplateTransformer {
|
||||||
public includeAttributes = (): string[] => {
|
public includeAttributes = (): string[] => {
|
||||||
return ['companyLogoUri', 'primaryColor'];
|
return ['companyLogoUri', 'primaryColor', 'secondaryColor'];
|
||||||
};
|
};
|
||||||
|
|
||||||
public excludeAttributes = (): string[] => {
|
public excludeAttributes = (): string[] => {
|
||||||
@@ -219,4 +219,8 @@ class GetInvoicePaymentLinkBrandingTemplate extends GetPdfTemplateTransformer {
|
|||||||
primaryColor = (template) => {
|
primaryColor = (template) => {
|
||||||
return template.attributes?.primaryColor;
|
return template.attributes?.primaryColor;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
secondaryColor = (template) => {
|
||||||
|
return template.attributes?.secondaryColor;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ export class SaleInvoiceTransformer extends Transformer {
|
|||||||
protected dueAmountFormatted = (invoice: SaleInvoice): string => {
|
protected dueAmountFormatted = (invoice: SaleInvoice): string => {
|
||||||
return this.formatNumber(invoice.dueAmount, {
|
return this.formatNumber(invoice.dueAmount, {
|
||||||
currencyCode: invoice.currencyCode,
|
currencyCode: invoice.currencyCode,
|
||||||
|
money: true
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -113,7 +114,6 @@ export class SaleInvoiceTransformer extends Transformer {
|
|||||||
protected subtotalFormatted = (invoice: SaleInvoice): string => {
|
protected subtotalFormatted = (invoice: SaleInvoice): string => {
|
||||||
return this.formatNumber(invoice.subtotal, {
|
return this.formatNumber(invoice.subtotal, {
|
||||||
currencyCode: this.context.organization.baseCurrency,
|
currencyCode: this.context.organization.baseCurrency,
|
||||||
money: false,
|
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -170,6 +170,7 @@ export class SaleInvoiceTransformer extends Transformer {
|
|||||||
protected totalFormatted = (invoice: SaleInvoice): string => {
|
protected totalFormatted = (invoice: SaleInvoice): string => {
|
||||||
return this.formatNumber(invoice.total, {
|
return this.formatNumber(invoice.total, {
|
||||||
currencyCode: invoice.currencyCode,
|
currencyCode: invoice.currencyCode,
|
||||||
|
money: true
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -212,7 +213,7 @@ export class SaleInvoiceTransformer extends Transformer {
|
|||||||
* @returns {string}
|
* @returns {string}
|
||||||
*/
|
*/
|
||||||
protected adjustmentFormatted = (invoice: SaleInvoice): string => {
|
protected adjustmentFormatted = (invoice: SaleInvoice): string => {
|
||||||
return this.formatMoney(invoice.adjustment, {
|
return this.formatNumber(invoice.adjustment, {
|
||||||
currencyCode: invoice.currencyCode,
|
currencyCode: invoice.currencyCode,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { events } from '@/common/events/events';
|
|||||||
|
|
||||||
@Injectable()
|
@Injectable()
|
||||||
export class InvoiceGLEntriesSubscriber {
|
export class InvoiceGLEntriesSubscriber {
|
||||||
constructor(public readonly saleInvoiceGLEntries: SaleInvoiceGLEntries) {}
|
constructor(public readonly saleInvoiceGLEntries: SaleInvoiceGLEntries) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Records journal entries of the non-inventory invoice.
|
* Records journal entries of the non-inventory invoice.
|
||||||
|
|||||||
@@ -25,7 +25,10 @@ import {
|
|||||||
CreateSaleReceiptDto,
|
CreateSaleReceiptDto,
|
||||||
EditSaleReceiptDto,
|
EditSaleReceiptDto,
|
||||||
} from './dtos/SaleReceipt.dto';
|
} from './dtos/SaleReceipt.dto';
|
||||||
import { ISalesReceiptsFilter } from './types/SaleReceipts.types';
|
import {
|
||||||
|
ISalesReceiptsFilter,
|
||||||
|
SaleReceiptMailOptsDTO,
|
||||||
|
} from './types/SaleReceipts.types';
|
||||||
import { AcceptType } from '@/constants/accept-type';
|
import { AcceptType } from '@/constants/accept-type';
|
||||||
import { Response } from 'express';
|
import { Response } from 'express';
|
||||||
import { SaleReceiptResponseDto } from './dtos/SaleReceiptResponse.dto';
|
import { SaleReceiptResponseDto } from './dtos/SaleReceiptResponse.dto';
|
||||||
@@ -87,7 +90,7 @@ export class SaleReceiptsController {
|
|||||||
return this.saleReceiptApplication.createSaleReceipt(saleReceiptDTO);
|
return this.saleReceiptApplication.createSaleReceipt(saleReceiptDTO);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Put(':id/mail')
|
@Post(':id/mail')
|
||||||
@HttpCode(200)
|
@HttpCode(200)
|
||||||
@ApiOperation({ summary: 'Send the sale receipt mail.' })
|
@ApiOperation({ summary: 'Send the sale receipt mail.' })
|
||||||
@ApiParam({
|
@ApiParam({
|
||||||
@@ -96,8 +99,11 @@ export class SaleReceiptsController {
|
|||||||
type: Number,
|
type: Number,
|
||||||
description: 'The sale receipt id',
|
description: 'The sale receipt id',
|
||||||
})
|
})
|
||||||
sendSaleReceiptMail(@Param('id', ParseIntPipe) id: number) {
|
sendSaleReceiptMail(
|
||||||
return this.saleReceiptApplication.getSaleReceiptMail(id);
|
@Param('id', ParseIntPipe) id: number,
|
||||||
|
@Body() messageOpts: SaleReceiptMailOptsDTO,
|
||||||
|
) {
|
||||||
|
return this.saleReceiptApplication.sendSaleReceiptMail(id, messageOpts);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Get('state')
|
@Get('state')
|
||||||
|
|||||||
@@ -186,42 +186,42 @@ export const SaleReceiptMeta = {
|
|||||||
},
|
},
|
||||||
fields2: {
|
fields2: {
|
||||||
receiptDate: {
|
receiptDate: {
|
||||||
name: 'Receipt Date',
|
name: 'receipt.field.receipt_date',
|
||||||
fieldType: 'date',
|
fieldType: 'date',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
customerId: {
|
customerId: {
|
||||||
name: 'Customer',
|
name: 'receipt.field.customer',
|
||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'Contact',
|
relationModel: 'Contact',
|
||||||
relationImportMatch: 'displayName',
|
relationImportMatch: 'displayName',
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
depositAccountId: {
|
depositAccountId: {
|
||||||
name: 'Deposit Account',
|
name: 'receipt.field.deposit_account',
|
||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'Account',
|
relationModel: 'Account',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
exchangeRate: {
|
exchangeRate: {
|
||||||
name: 'Exchange Rate',
|
name: 'receipt.field.exchange_rate',
|
||||||
fieldType: 'number',
|
fieldType: 'number',
|
||||||
},
|
},
|
||||||
receiptNumber: {
|
receiptNumber: {
|
||||||
name: 'Receipt Number',
|
name: 'receipt.field.receipt_number',
|
||||||
fieldType: 'text',
|
fieldType: 'text',
|
||||||
},
|
},
|
||||||
referenceNo: {
|
referenceNo: {
|
||||||
name: 'Reference No.',
|
name: 'receipt.field.reference_no',
|
||||||
fieldType: 'text',
|
fieldType: 'text',
|
||||||
},
|
},
|
||||||
closed: {
|
closed: {
|
||||||
name: 'Closed',
|
name: 'receipt.field.closed',
|
||||||
fieldType: 'boolean',
|
fieldType: 'boolean',
|
||||||
},
|
},
|
||||||
entries: {
|
entries: {
|
||||||
name: 'Entries',
|
name: 'receipt.field.entries',
|
||||||
fieldType: 'collection',
|
fieldType: 'collection',
|
||||||
collectionOf: 'object',
|
collectionOf: 'object',
|
||||||
collectionMinLength: 1,
|
collectionMinLength: 1,
|
||||||
@@ -233,7 +233,7 @@ export const SaleReceiptMeta = {
|
|||||||
relationModel: 'Item',
|
relationModel: 'Item',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
required: true,
|
required: true,
|
||||||
importHint: 'Matches the item name or code.',
|
importHint: 'invoice.field.item_hint',
|
||||||
},
|
},
|
||||||
rate: {
|
rate: {
|
||||||
name: 'invoice.field.rate',
|
name: 'invoice.field.rate',
|
||||||
@@ -252,15 +252,15 @@ export const SaleReceiptMeta = {
|
|||||||
},
|
},
|
||||||
},
|
},
|
||||||
statement: {
|
statement: {
|
||||||
name: 'Statement',
|
name: 'receipt.field.statement',
|
||||||
fieldType: 'text',
|
fieldType: 'text',
|
||||||
},
|
},
|
||||||
receiptMessage: {
|
receiptMessage: {
|
||||||
name: 'Receipt Message',
|
name: 'receipt.field.receipt_message',
|
||||||
fieldType: 'text',
|
fieldType: 'text',
|
||||||
},
|
},
|
||||||
branchId: {
|
branchId: {
|
||||||
name: 'Branch',
|
name: 'invoice.field.branch',
|
||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'Branch',
|
relationModel: 'Branch',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
@@ -268,7 +268,7 @@ export const SaleReceiptMeta = {
|
|||||||
required: true,
|
required: true,
|
||||||
},
|
},
|
||||||
warehouseId: {
|
warehouseId: {
|
||||||
name: 'Warehouse',
|
name: 'invoice.field.warehouse',
|
||||||
fieldType: 'relation',
|
fieldType: 'relation',
|
||||||
relationModel: 'Warehouse',
|
relationModel: 'Warehouse',
|
||||||
relationImportMatch: ['name', 'code'],
|
relationImportMatch: ['name', 'code'],
|
||||||
|
|||||||
@@ -1,24 +1,42 @@
|
|||||||
import { Process, Processor } from '@nestjs/bull';
|
import { Process, Processor } from '@nestjs/bull';
|
||||||
import { Job } from 'bull';
|
import { Job } from 'bull';
|
||||||
import { SendSaleReceiptMailQueue } from '../constants';
|
import { Inject, Scope } from '@nestjs/common';
|
||||||
|
import { JOB_REF } from '@nestjs/bull';
|
||||||
|
import { SendSaleReceiptMailQueue, SendSaleReceiptMailJob } from '../constants';
|
||||||
import { SaleReceiptMailNotification } from '../commands/SaleReceiptMailNotification';
|
import { SaleReceiptMailNotification } from '../commands/SaleReceiptMailNotification';
|
||||||
import { SaleReceiptSendMailPayload } from '../types/SaleReceipts.types';
|
import { SaleReceiptSendMailPayload } from '../types/SaleReceipts.types';
|
||||||
import { ClsService } from 'nestjs-cls';
|
import { ClsService, UseCls } from 'nestjs-cls';
|
||||||
|
|
||||||
@Processor(SendSaleReceiptMailQueue)
|
@Processor({
|
||||||
|
name: SendSaleReceiptMailQueue,
|
||||||
|
scope: Scope.REQUEST,
|
||||||
|
})
|
||||||
export class SendSaleReceiptMailProcess {
|
export class SendSaleReceiptMailProcess {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly saleReceiptMailNotification: SaleReceiptMailNotification,
|
private readonly saleReceiptMailNotification: SaleReceiptMailNotification,
|
||||||
private readonly clsService: ClsService,
|
private readonly clsService: ClsService,
|
||||||
) {}
|
|
||||||
|
|
||||||
@Process(SendSaleReceiptMailQueue)
|
@Inject(JOB_REF)
|
||||||
async handleSendMailJob(job: Job<SaleReceiptSendMailPayload>) {
|
private readonly jobRef: Job<SaleReceiptSendMailPayload>,
|
||||||
const { messageOpts, saleReceiptId, organizationId, userId } = job.data;
|
) { }
|
||||||
|
|
||||||
|
@Process(SendSaleReceiptMailJob)
|
||||||
|
@UseCls()
|
||||||
|
async handleSendMailJob() {
|
||||||
|
const { messageOpts, saleReceiptId, organizationId, userId } =
|
||||||
|
this.jobRef.data;
|
||||||
|
|
||||||
this.clsService.set('organizationId', organizationId);
|
this.clsService.set('organizationId', organizationId);
|
||||||
this.clsService.set('userId', userId);
|
this.clsService.set('userId', userId);
|
||||||
|
|
||||||
await this.saleReceiptMailNotification.sendMail(saleReceiptId, messageOpts);
|
try {
|
||||||
|
await this.saleReceiptMailNotification.sendMail(
|
||||||
|
saleReceiptId,
|
||||||
|
messageOpts,
|
||||||
|
);
|
||||||
|
} catch (error) {
|
||||||
|
console.error('Failed to process receipt mail job:', error);
|
||||||
|
throw error;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -107,4 +107,4 @@ const modelProviders = models.map((model) => RegisterTenancyModel(model));
|
|||||||
imports: [...modelProviders],
|
imports: [...modelProviders],
|
||||||
exports: [...modelProviders],
|
exports: [...modelProviders],
|
||||||
})
|
})
|
||||||
export class TenancyModelsModule {}
|
export class TenancyModelsModule { }
|
||||||
|
|||||||
@@ -26,7 +26,7 @@ export class TransactionsLockingService {
|
|||||||
constructor(
|
constructor(
|
||||||
private readonly transactionsLockingRepo: TransactionsLockingRepository,
|
private readonly transactionsLockingRepo: TransactionsLockingRepository,
|
||||||
private readonly eventPublisher: EventEmitter2,
|
private readonly eventPublisher: EventEmitter2,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Enable/disable all transacations locking.
|
* Enable/disable all transacations locking.
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ import { ServiceError } from '@/modules/Items/ServiceError';
|
|||||||
export class TransactionsLockingGuard {
|
export class TransactionsLockingGuard {
|
||||||
constructor(
|
constructor(
|
||||||
private readonly transactionsLockingRepo: TransactionsLockingRepository,
|
private readonly transactionsLockingRepo: TransactionsLockingRepository,
|
||||||
) {}
|
) { }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Detarmines whether the transaction date between the locking date period.
|
* Detarmines whether the transaction date between the locking date period.
|
||||||
@@ -31,7 +31,7 @@ export class TransactionsLockingGuard {
|
|||||||
const inUnlockDate =
|
const inUnlockDate =
|
||||||
unlockFromDate && unlockToDate
|
unlockFromDate && unlockToDate
|
||||||
? moment(transactionDate).isSameOrAfter(unlockFromDate) &&
|
? moment(transactionDate).isSameOrAfter(unlockFromDate) &&
|
||||||
moment(transactionDate).isSameOrBefore(unlockFromDate)
|
moment(transactionDate).isSameOrBefore(unlockFromDate)
|
||||||
: false;
|
: false;
|
||||||
|
|
||||||
// Retruns true in case the transaction date between locking date
|
// Retruns true in case the transaction date between locking date
|
||||||
@@ -57,7 +57,7 @@ export class TransactionsLockingGuard {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (isLocked) {
|
if (isLocked) {
|
||||||
this.throwTransactionsLockError(lockingGroup);
|
await this.throwTransactionsLockError(lockingGroup);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -90,11 +90,12 @@ export class TransactionsLockingGuard {
|
|||||||
await this.transactionsLockingRepo.getTransactionsLockingType();
|
await this.transactionsLockingRepo.getTransactionsLockingType();
|
||||||
|
|
||||||
if (lockingType === TransactionsLockingGroup.All) {
|
if (lockingType === TransactionsLockingGroup.All) {
|
||||||
return this.validateTransactionsLocking(
|
await this.validateTransactionsLocking(
|
||||||
transactionDate,
|
transactionDate,
|
||||||
TransactionsLockingGroup.All,
|
TransactionsLockingGroup.All,
|
||||||
);
|
);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
return this.validateTransactionsLocking(transactionDate, moduleType);
|
await this.validateTransactionsLocking(transactionDate, moduleType);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user