@hed-hog/finance 0.0.319 → 0.0.321
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/dto/create-currency.dto.d.ts +6 -0
- package/dist/dto/create-currency.dto.d.ts.map +1 -0
- package/dist/dto/create-currency.dto.js +37 -0
- package/dist/dto/create-currency.dto.js.map +1 -0
- package/dist/dto/update-currency.dto.d.ts +7 -0
- package/dist/dto/update-currency.dto.d.ts.map +1 -0
- package/dist/dto/update-currency.dto.js +47 -0
- package/dist/dto/update-currency.dto.js.map +1 -0
- package/dist/finance-currencies.controller.d.ts +36 -0
- package/dist/finance-currencies.controller.d.ts.map +1 -0
- package/dist/finance-currencies.controller.js +74 -0
- package/dist/finance-currencies.controller.js.map +1 -0
- package/dist/finance.module.d.ts.map +1 -1
- package/dist/finance.module.js +2 -0
- package/dist/finance.module.js.map +1 -1
- package/dist/finance.service.d.ts +29 -0
- package/dist/finance.service.d.ts.map +1 -1
- package/dist/finance.service.js +79 -0
- package/dist/finance.service.js.map +1 -1
- package/hedhog/data/currency.yaml +14 -0
- package/hedhog/data/menu.yaml +16 -0
- package/hedhog/data/route.yaml +36 -0
- package/hedhog/frontend/app/administration/currencies/page.tsx.ejs +490 -0
- package/hedhog/frontend/app/cash-and-banks/bank-accounts/page.tsx.ejs +143 -48
- package/hedhog/frontend/messages/en.json +58 -0
- package/hedhog/frontend/messages/pt.json +58 -0
- package/hedhog/table/bank_account.yaml +8 -0
- package/hedhog/table/currency.yaml +21 -0
- package/package.json +6 -6
- package/src/dto/create-currency.dto.ts +21 -0
- package/src/dto/update-currency.dto.ts +31 -0
- package/src/finance-currencies.controller.ts +44 -0
- package/src/finance.module.ts +2 -0
- package/src/finance.service.ts +127 -31
package/src/finance.service.ts
CHANGED
|
@@ -22,6 +22,7 @@ import { CreateBankReconciliationDto } from './dto/create-bank-reconciliation.dt
|
|
|
22
22
|
import { CreateBankStatementAdjustmentDto } from './dto/create-bank-statement-adjustment.dto';
|
|
23
23
|
import { CreateBankStatementEntryDto } from './dto/create-bank-statement-entry.dto';
|
|
24
24
|
import { CreateCostCenterDto } from './dto/create-cost-center.dto';
|
|
25
|
+
import { CreateCurrencyDto } from './dto/create-currency.dto';
|
|
25
26
|
import { CreateFinanceCategoryDto } from './dto/create-finance-category.dto';
|
|
26
27
|
import { CreateFinanceTagDto } from './dto/create-finance-tag.dto';
|
|
27
28
|
import { CreateFinancialTitleDto } from './dto/create-financial-title.dto';
|
|
@@ -36,6 +37,7 @@ import { SettleInstallmentDto } from './dto/settle-installment.dto';
|
|
|
36
37
|
import { UpdateBankAccountDto } from './dto/update-bank-account.dto';
|
|
37
38
|
import { UpdateBankStatementEntryDto } from './dto/update-bank-statement-entry.dto';
|
|
38
39
|
import { UpdateCostCenterDto } from './dto/update-cost-center.dto';
|
|
40
|
+
import { UpdateCurrencyDto } from './dto/update-currency.dto';
|
|
39
41
|
import { UpdateFinanceCategoryDto } from './dto/update-finance-category.dto';
|
|
40
42
|
|
|
41
43
|
type TitleType = 'payable' | 'receivable';
|
|
@@ -806,14 +808,14 @@ export class FinanceService {
|
|
|
806
808
|
this.loadCategories(),
|
|
807
809
|
this.loadCostCenters(),
|
|
808
810
|
this.loadBankAccounts(),
|
|
809
|
-
this.listBankStatements({
|
|
810
|
-
page: 1,
|
|
811
|
-
pageSize: 1000,
|
|
812
|
-
search: undefined,
|
|
813
|
-
sortField: undefined,
|
|
814
|
-
sortOrder: undefined,
|
|
815
|
-
fields: undefined,
|
|
816
|
-
}),
|
|
811
|
+
this.listBankStatements({
|
|
812
|
+
page: 1,
|
|
813
|
+
pageSize: 1000,
|
|
814
|
+
search: undefined,
|
|
815
|
+
sortField: undefined,
|
|
816
|
+
sortOrder: undefined,
|
|
817
|
+
fields: undefined,
|
|
818
|
+
}),
|
|
817
819
|
this.getAccountsReceivableCollectionsDefault(),
|
|
818
820
|
this.loadTags(),
|
|
819
821
|
this.loadAuditLogs(),
|
|
@@ -832,10 +834,10 @@ export class FinanceService {
|
|
|
832
834
|
costCentersResult.status === 'fulfilled' ? costCentersResult.value : [];
|
|
833
835
|
const bankAccounts =
|
|
834
836
|
bankAccountsResult.status === 'fulfilled' ? bankAccountsResult.value : [];
|
|
835
|
-
const bankStatements =
|
|
836
|
-
bankStatementsResult.status === 'fulfilled'
|
|
837
|
-
? bankStatementsResult.value.data
|
|
838
|
-
: [];
|
|
837
|
+
const bankStatements =
|
|
838
|
+
bankStatementsResult.status === 'fulfilled'
|
|
839
|
+
? bankStatementsResult.value.data
|
|
840
|
+
: [];
|
|
839
841
|
const collectionsDefault =
|
|
840
842
|
collectionsDefaultResult.status === 'fulfilled'
|
|
841
843
|
? collectionsDefaultResult.value
|
|
@@ -3553,20 +3555,20 @@ export class FinanceService {
|
|
|
3553
3555
|
to?: string;
|
|
3554
3556
|
},
|
|
3555
3557
|
) {
|
|
3556
|
-
const statementsResult = await this.listBankStatements(
|
|
3557
|
-
{
|
|
3558
|
-
page: 1,
|
|
3559
|
-
pageSize: 100000,
|
|
3560
|
-
search: undefined,
|
|
3561
|
-
sortField: undefined,
|
|
3562
|
-
sortOrder: undefined,
|
|
3563
|
-
fields: undefined,
|
|
3564
|
-
},
|
|
3565
|
-
bankAccountId,
|
|
3566
|
-
search,
|
|
3567
|
-
filters,
|
|
3568
|
-
);
|
|
3569
|
-
const statements = statementsResult.data;
|
|
3558
|
+
const statementsResult = await this.listBankStatements(
|
|
3559
|
+
{
|
|
3560
|
+
page: 1,
|
|
3561
|
+
pageSize: 100000,
|
|
3562
|
+
search: undefined,
|
|
3563
|
+
sortField: undefined,
|
|
3564
|
+
sortOrder: undefined,
|
|
3565
|
+
fields: undefined,
|
|
3566
|
+
},
|
|
3567
|
+
bankAccountId,
|
|
3568
|
+
search,
|
|
3569
|
+
filters,
|
|
3570
|
+
);
|
|
3571
|
+
const statements = statementsResult.data;
|
|
3570
3572
|
|
|
3571
3573
|
const headers = [
|
|
3572
3574
|
'id',
|
|
@@ -4740,6 +4742,100 @@ export class FinanceService {
|
|
|
4740
4742
|
return { success: true };
|
|
4741
4743
|
}
|
|
4742
4744
|
|
|
4745
|
+
async listCurrencies(paginationParams: PaginationDTO) {
|
|
4746
|
+
const currencies = await this.prisma.currency.findMany({
|
|
4747
|
+
orderBy: [{ code: 'asc' }],
|
|
4748
|
+
});
|
|
4749
|
+
|
|
4750
|
+
return currencies.map((c) => ({
|
|
4751
|
+
id: String(c.id),
|
|
4752
|
+
code: c.code,
|
|
4753
|
+
name: c.name,
|
|
4754
|
+
symbol: c.symbol,
|
|
4755
|
+
status: c.status,
|
|
4756
|
+
ativo: c.status === 'active',
|
|
4757
|
+
}));
|
|
4758
|
+
}
|
|
4759
|
+
|
|
4760
|
+
async createCurrency(data: CreateCurrencyDto) {
|
|
4761
|
+
const existing = await this.prisma.currency.findUnique({
|
|
4762
|
+
where: { code: data.code.toUpperCase() },
|
|
4763
|
+
select: { id: true },
|
|
4764
|
+
});
|
|
4765
|
+
|
|
4766
|
+
if (existing) {
|
|
4767
|
+
throw new ConflictException(
|
|
4768
|
+
`Currency with code ${data.code.toUpperCase()} already exists`,
|
|
4769
|
+
);
|
|
4770
|
+
}
|
|
4771
|
+
|
|
4772
|
+
const created = await this.prisma.currency.create({
|
|
4773
|
+
data: {
|
|
4774
|
+
code: data.code.toUpperCase(),
|
|
4775
|
+
name: data.name.trim(),
|
|
4776
|
+
symbol: data.symbol.trim(),
|
|
4777
|
+
status: 'active',
|
|
4778
|
+
},
|
|
4779
|
+
});
|
|
4780
|
+
|
|
4781
|
+
return {
|
|
4782
|
+
id: String(created.id),
|
|
4783
|
+
code: created.code,
|
|
4784
|
+
name: created.name,
|
|
4785
|
+
symbol: created.symbol,
|
|
4786
|
+
status: created.status,
|
|
4787
|
+
ativo: created.status === 'active',
|
|
4788
|
+
};
|
|
4789
|
+
}
|
|
4790
|
+
|
|
4791
|
+
async updateCurrency(id: number, data: UpdateCurrencyDto) {
|
|
4792
|
+
const current = await this.prisma.currency.findUnique({
|
|
4793
|
+
where: { id },
|
|
4794
|
+
select: { id: true },
|
|
4795
|
+
});
|
|
4796
|
+
|
|
4797
|
+
if (!current) {
|
|
4798
|
+
throw new NotFoundException('Currency not found');
|
|
4799
|
+
}
|
|
4800
|
+
|
|
4801
|
+
const updated = await this.prisma.currency.update({
|
|
4802
|
+
where: { id },
|
|
4803
|
+
data: {
|
|
4804
|
+
code: data.code?.toUpperCase(),
|
|
4805
|
+
name: data.name?.trim(),
|
|
4806
|
+
symbol: data.symbol?.trim(),
|
|
4807
|
+
status: data.status,
|
|
4808
|
+
},
|
|
4809
|
+
});
|
|
4810
|
+
|
|
4811
|
+
return {
|
|
4812
|
+
id: String(updated.id),
|
|
4813
|
+
code: updated.code,
|
|
4814
|
+
name: updated.name,
|
|
4815
|
+
symbol: updated.symbol,
|
|
4816
|
+
status: updated.status,
|
|
4817
|
+
ativo: updated.status === 'active',
|
|
4818
|
+
};
|
|
4819
|
+
}
|
|
4820
|
+
|
|
4821
|
+
async deleteCurrency(id: number) {
|
|
4822
|
+
const current = await this.prisma.currency.findUnique({
|
|
4823
|
+
where: { id },
|
|
4824
|
+
select: { id: true },
|
|
4825
|
+
});
|
|
4826
|
+
|
|
4827
|
+
if (!current) {
|
|
4828
|
+
throw new NotFoundException('Currency not found');
|
|
4829
|
+
}
|
|
4830
|
+
|
|
4831
|
+
await this.prisma.currency.update({
|
|
4832
|
+
where: { id },
|
|
4833
|
+
data: { status: 'inactive' },
|
|
4834
|
+
});
|
|
4835
|
+
|
|
4836
|
+
return { success: true };
|
|
4837
|
+
}
|
|
4838
|
+
|
|
4743
4839
|
async deleteFinanceCategory(id: number) {
|
|
4744
4840
|
const current = await this.prisma.finance_category.findUnique({
|
|
4745
4841
|
where: { id },
|
|
@@ -5833,11 +5929,11 @@ export class FinanceService {
|
|
|
5833
5929
|
throw new NotFoundException('Installment not found');
|
|
5834
5930
|
}
|
|
5835
5931
|
|
|
5836
|
-
const nextInstallmentStatus = this.resolveInstallmentStatus(
|
|
5837
|
-
Number(updatedInstallment.amount_cents),
|
|
5838
|
-
Number(updatedInstallment.open_amount_cents),
|
|
5839
|
-
updatedInstallment.due_date,
|
|
5840
|
-
);
|
|
5932
|
+
const nextInstallmentStatus = this.resolveInstallmentStatus(
|
|
5933
|
+
Number(updatedInstallment.amount_cents),
|
|
5934
|
+
Number(updatedInstallment.open_amount_cents),
|
|
5935
|
+
updatedInstallment.due_date,
|
|
5936
|
+
);
|
|
5841
5937
|
|
|
5842
5938
|
if (updatedInstallment.status !== nextInstallmentStatus) {
|
|
5843
5939
|
await tx.financial_installment.update({
|