Skip to content

Commit

Permalink
Merge branch 'develop' into feature/mock_setting
Browse files Browse the repository at this point in the history
  • Loading branch information
Luphia authored Sep 26, 2024
2 parents 1ae941a + de86bbc commit 0049b60
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 30 deletions.
70 changes: 45 additions & 25 deletions src/lib/utils/report/balance_sheet_generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,46 +68,66 @@ export default class BalanceSheetGenerator extends FinancialReportGenerator {
SPECIAL_ACCOUNTS.OTHER_COMPREHENSIVE_INCOME.code
);

const netIncomeInEquity = await findUniqueAccountByCodeInPrisma(
SPECIAL_ACCOUNTS.NET_INCOME_IN_EQUITY.code
);

const otherEquityOther = await findUniqueAccountByCodeInPrisma(
SPECIAL_ACCOUNTS.OTHER_EQUITY_OTHER.code
);

closeAccount.push({
id: -1,
id: netIncomeInEquity?.id || -1,
amount: curPeriod ? netIncome.curPeriodAmount : netIncome.prePeriodAmount,
description: SPECIAL_ACCOUNTS.NET_INCOME.name,
debit: SPECIAL_ACCOUNTS.NET_INCOME.debit,
accountId: netIncomeAccount?.id || -1,
description: SPECIAL_ACCOUNTS.NET_INCOME_IN_EQUITY.name,
debit: SPECIAL_ACCOUNTS.NET_INCOME_IN_EQUITY.debit,
accountId: netIncomeInEquity?.id || -1,
voucherId: -1,
createdAt: 1,
updatedAt: 1,
deletedAt: null,
account: netIncomeAccount || {
...SPECIAL_ACCOUNTS.NET_INCOME,
id: -1,
companyId: this.companyId,
createdAt: 1,
updatedAt: 1,
deletedAt: null,
},
account: netIncomeAccount
? {
...netIncomeAccount,
code: SPECIAL_ACCOUNTS.NET_INCOME_IN_EQUITY.code,
debit: SPECIAL_ACCOUNTS.NET_INCOME_IN_EQUITY.debit,
}
: {
...SPECIAL_ACCOUNTS.NET_INCOME_IN_EQUITY,
id: -1,
companyId: this.companyId,
createdAt: 1,
updatedAt: 1,
deletedAt: null,
},
});

closeAccount.push({
id: -1,
id: otherEquityOther?.id || -1,
amount: curPeriod
? otherComprehensiveIncome.curPeriodAmount
: otherComprehensiveIncome.prePeriodAmount,
description: SPECIAL_ACCOUNTS.OTHER_COMPREHENSIVE_INCOME.name,
debit: SPECIAL_ACCOUNTS.OTHER_COMPREHENSIVE_INCOME.debit,
accountId: otherComprehensiveIncomeAccount?.id || -1,
description: SPECIAL_ACCOUNTS.OTHER_EQUITY_OTHER.name,
debit: SPECIAL_ACCOUNTS.OTHER_EQUITY_OTHER.debit,
accountId: otherEquityOther?.id || -1,
voucherId: -1,
createdAt: 1,
updatedAt: 1,
deletedAt: null,
account: otherComprehensiveIncomeAccount || {
...SPECIAL_ACCOUNTS.OTHER_COMPREHENSIVE_INCOME,
id: -1,
companyId: this.companyId,
createdAt: 1,
updatedAt: 1,
deletedAt: null,
},
account: otherComprehensiveIncomeAccount
? {
...otherComprehensiveIncomeAccount,
code: SPECIAL_ACCOUNTS.OTHER_EQUITY_OTHER.code,
debit: SPECIAL_ACCOUNTS.OTHER_EQUITY_OTHER.debit,
}
: {
...SPECIAL_ACCOUNTS.OTHER_EQUITY_OTHER,
id: -1,
companyId: this.companyId,
createdAt: 1,
updatedAt: 1,
deletedAt: null,
},
});

return closeAccount;
Expand All @@ -118,12 +138,12 @@ export default class BalanceSheetGenerator extends FinancialReportGenerator {

// Info: (20240801 - Murky) 暫時關閉本期損益和其他其他綜合損益權益
const closeAccount = await this.closeAccountFromIncomeStatement(curPeriod);

lineItemsFromDB = lineItemsFromDB.concat(closeAccount);

const accountForest = await this.getAccountForestByReportSheet();

const lineItemsMap = transformLineItemsFromDBToMap(lineItemsFromDB);

const updatedAccountForest = updateAccountAmounts(accountForest, lineItemsMap);

return updatedAccountForest;
Expand Down
15 changes: 10 additions & 5 deletions src/pages/api/v1/company/[companyId]/voucher/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,11 +49,16 @@ async function handleVoucherCreatePrismaLogic(

const newVoucherNo = await getLatestVoucherNoInPrisma(companyId);
const voucherData = await createVoucherInPrisma(newVoucherNo, journal.id);
await Promise.all(
voucher.lineItems.map(async (lineItem) => {
return createLineItemInPrisma(lineItem, voucherData.id, companyId);
})
);
// Info: (20240925 - Murky) I need to make sure lineitems is created in order
// Deprecated: (20240926 - Murky) Need to find better way to sort line items
/* eslint-disable no-restricted-syntax */
for (const lineItem of voucher.lineItems) {
// Deprecated: (20240926 - Murky) Need to find better way to sort line items
/* eslint-disable no-await-in-loop */
await createLineItemInPrisma(lineItem, voucherData.id, companyId);
/* eslint-enable no-await-in-loop */
}
/* eslint-enable no-restricted-syntax */

// Info: ( 20240613 - Murky)Get the voucher data again after creating the line items
updatedVoucher = await findUniqueVoucherInPrisma(voucherData.id);
Expand Down

0 comments on commit 0049b60

Please sign in to comment.