mirror of
https://github.com/bigcapitalhq/bigcapital.git
synced 2026-02-16 12:50:38 +00:00
fix: Set default index to transaction entries
This commit is contained in:
@@ -3,8 +3,8 @@ import * as R from 'ramda';
|
||||
import { omit, sumBy } from 'lodash';
|
||||
import { IBillPayment, IBillPaymentDTO, IVendor } from '@/interfaces';
|
||||
import { BranchTransactionDTOTransform } from '@/services/Branches/Integrations/BranchTransactionDTOTransform';
|
||||
import { assocItemEntriesDefaultIndex } from '@/services/Items/utils';
|
||||
import { formatDateFields } from '@/utils';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
|
||||
@Service()
|
||||
export class CommandBillPaymentDTOTransformer {
|
||||
@@ -27,6 +27,12 @@ export class CommandBillPaymentDTOTransformer {
|
||||
const amount =
|
||||
billPaymentDTO.amount ?? sumBy(billPaymentDTO.entries, 'paymentAmount');
|
||||
|
||||
// Associate the default index to each item entry.
|
||||
const entries = R.compose(
|
||||
// Associate the default index to payment entries.
|
||||
assocItemEntriesDefaultIndex
|
||||
)(billPaymentDTO.entries);
|
||||
|
||||
const initialDTO = {
|
||||
...formatDateFields(omit(billPaymentDTO, ['attachments']), [
|
||||
'paymentDate',
|
||||
@@ -34,7 +40,7 @@ export class CommandBillPaymentDTOTransformer {
|
||||
amount,
|
||||
currencyCode: vendor.currencyCode,
|
||||
exchangeRate: billPaymentDTO.exchangeRate || 1,
|
||||
entries: billPaymentDTO.entries,
|
||||
entries,
|
||||
};
|
||||
return R.compose(
|
||||
this.branchDTOTransform.transformDTO<IBillPayment>(tenantId)
|
||||
|
||||
@@ -3,7 +3,7 @@ import moment from 'moment';
|
||||
import { Inject, Service } from 'typedi';
|
||||
import * as R from 'ramda';
|
||||
import composeAsync from 'async/compose';
|
||||
import { formatDateFields } from 'utils';
|
||||
import { assocDepthLevelToObjectTree, formatDateFields } from 'utils';
|
||||
import {
|
||||
IBillDTO,
|
||||
IBill,
|
||||
@@ -15,6 +15,7 @@ import { BranchTransactionDTOTransform } from '@/services/Branches/Integrations/
|
||||
import { WarehouseTransactionDTOTransform } from '@/services/Warehouses/Integrations/WarehouseTransactionDTOTransform';
|
||||
import HasTenancyService from '@/services/Tenancy/TenancyService';
|
||||
import { ItemEntriesTaxTransactions } from '@/services/TaxRates/ItemEntriesTaxTransactions';
|
||||
import { assocItemEntriesDefaultIndex } from '@/services/Items/utils';
|
||||
|
||||
@Service()
|
||||
export class BillDTOTransformer {
|
||||
@@ -54,9 +55,9 @@ export class BillDTOTransformer {
|
||||
|
||||
/**
|
||||
* Converts create bill DTO to model.
|
||||
* @param {number} tenantId
|
||||
* @param {IBillDTO} billDTO
|
||||
* @param {IBill} oldBill
|
||||
* @param {number} tenantId
|
||||
* @param {IBillDTO} billDTO
|
||||
* @param {IBill} oldBill
|
||||
* @returns {IBill}
|
||||
*/
|
||||
public async billDTOToModel(
|
||||
@@ -92,7 +93,9 @@ export class BillDTOTransformer {
|
||||
|
||||
const entries = R.compose(
|
||||
// Remove tax code from entries.
|
||||
R.map(R.omit(['taxCode']))
|
||||
R.map(R.omit(['taxCode'])),
|
||||
// Associate the default index to each item entry line.
|
||||
assocItemEntriesDefaultIndex
|
||||
)(asyncEntries);
|
||||
|
||||
const initialDTO = {
|
||||
|
||||
@@ -9,11 +9,13 @@ import {
|
||||
IVendorCredit,
|
||||
IVendorCreditCreateDTO,
|
||||
IVendorCreditEditDTO,
|
||||
IVendorCreditEntryDTO,
|
||||
} from '@/interfaces';
|
||||
import ItemsEntriesService from '@/services/Items/ItemsEntriesService';
|
||||
import AutoIncrementOrdersService from '@/services/Sales/AutoIncrementOrdersService';
|
||||
import { BranchTransactionDTOTransform } from '@/services/Branches/Integrations/BranchTransactionDTOTransform';
|
||||
import { WarehouseTransactionDTOTransform } from '@/services/Warehouses/Integrations/WarehouseTransactionDTOTransform';
|
||||
import { assocItemEntriesDefaultIndex } from '@/services/Items/utils';
|
||||
|
||||
@Service()
|
||||
export default class BaseVendorCredit {
|
||||
@@ -50,10 +52,18 @@ export default class BaseVendorCredit {
|
||||
const amount = this.itemsEntriesService.getTotalItemsEntries(
|
||||
vendorCreditDTO.entries
|
||||
);
|
||||
const entries = vendorCreditDTO.entries.map((entry) => ({
|
||||
...entry,
|
||||
referenceType: 'VendorCredit',
|
||||
}));
|
||||
|
||||
const entries = R.compose(
|
||||
// Associate the default index to each item entry.
|
||||
assocItemEntriesDefaultIndex,
|
||||
|
||||
// Associate the reference type to item entries.
|
||||
R.map((entry: IVendorCreditEntryDTO) => ({
|
||||
referenceType: 'VendorCredit',
|
||||
...entry,
|
||||
}))
|
||||
)(vendorCreditDTO.entries);
|
||||
|
||||
// Retreive the next vendor credit number.
|
||||
const autoNextNumber = this.getNextCreditNumber(tenantId);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user