Files
bigcapital/packages/server/src/modules/PaymentReceived/queries/PaymentReceivedTransformer.ts
Ahmed Bouhuolia 3575d54efa fix: add attachment support for all transaction types
Fixed attachments not showing in edit forms for various transaction types by:

1. Adding @InjectAttachable() decorator to models:
   - SaleReceipt, SaleEstimate, CreditNote, PaymentReceived
   - Bill, BillPayment, VendorCredit
   - ManualJournal, Expense

2. Fixing transformers to include attachments in API responses:
   - SaleReceiptTransformer, PaymentReceivedTransformer

3. Registering missing event subscribers in Attachment.module.ts:
   - AttachmentsOnSaleReceipts, AttachmentsOnSaleEstimates

4. Fixing DocumentLink model relation mapping:
   - Changed Document.default to Document for proper module export

5. Fixing PaymentReceived model_ref consistency:
   - Changed from 'PaymentReceive' to 'PaymentReceived' to match class name

6. Adding missing withGraphFetched('attachments') to GetPaymentReceived.service.ts

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
2026-02-26 23:16:12 +02:00

104 lines
2.9 KiB
TypeScript

import { Transformer } from '../../Transformer/Transformer';
import { PaymentReceived } from '../models/PaymentReceived';
import { PaymentReceivedEntry } from '../models/PaymentReceivedEntry';
import { PaymentReceivedEntryTransfromer } from './PaymentReceivedEntryTransformer';
import { AttachmentTransformer } from '@/modules/Attachments/Attachment.transformer';
export class PaymentReceiveTransfromer extends Transformer {
/**
* Include these attributes to payment receive object.
* @returns {Array}
*/
public includeAttributes = (): string[] => {
return [
'subtotalFormatted',
'formatttedTotal',
'formattedPaymentDate',
'formattedCreatedAt',
'formattedAmount',
'formattedExchangeRate',
'entries',
'attachments',
];
};
/**
* Retrieve formatted payment receive date.
* @param {PaymentReceived} invoice
* @returns {String}
*/
protected formattedPaymentDate = (payment: PaymentReceived): string => {
return this.formatDate(payment.paymentDate);
};
/**
* Retrieves the formatted created at date.
* @param {PaymentReceived} payment
* @returns {string}
*/
protected formattedCreatedAt = (payment: PaymentReceived): string => {
return this.formatDate(payment.createdAt);
};
/**
* Retrieve the formatted payment subtotal.
* @param {PaymentReceived} payment
* @returns {string}
*/
protected subtotalFormatted = (payment: PaymentReceived): string => {
return this.formatNumber(payment.amount, {
currencyCode: payment.currencyCode,
});
};
/**
* Retrieves the formatted total.
* @param {PaymentReceived} payment
* @returns {string}
*/
protected formatttedTotal = (payment: PaymentReceived): string => {
return this.formatNumber(payment.amount, {
currencyCode: payment.currencyCode,
money: true,
});
};
/**
* Retrieve formatted payment amount.
* @param {PaymentReceived} invoice
* @returns {string}
*/
protected formattedAmount = (payment: PaymentReceived): string => {
return this.formatNumber(payment.amount, {
currencyCode: payment.currencyCode,
});
};
/**
* Retrieve the formatted exchange rate.
* @param {PaymentReceived} payment
* @returns {string}
*/
protected formattedExchangeRate = (payment: PaymentReceived): string => {
return this.formatNumber(payment.exchangeRate);
};
/**
* Retrieves the payment entries.
* @param {PaymentReceived} payment
* @returns {IPaymentReceivedEntry[]}
*/
protected entries = (payment: PaymentReceived): PaymentReceivedEntry[] => {
return this.item(payment.entries, new PaymentReceivedEntryTransfromer());
};
/**
* Retrieves the payment received attachments.
* @param {PaymentReceived} payment
* @returns
*/
protected attachments = (payment: PaymentReceived) => {
return this.item(payment.attachments, new AttachmentTransformer());
};
}