Skip to content

Commit

Permalink
Merge pull request #506 from bigcapitalhq/BIG-206
Browse files Browse the repository at this point in the history
feat: Setting up the date format in the whole system dates
  • Loading branch information
abouolia authored Jun 17, 2024
2 parents c1fc708 + 2ad7710 commit 1e53a8e
Show file tree
Hide file tree
Showing 40 changed files with 207 additions and 83 deletions.
2 changes: 1 addition & 1 deletion packages/server/src/api/controllers/Dashboard/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import DashboardService from '@/services/Dashboard/DashboardService';
@Service()
export default class DashboardMetaController {
@Inject()
dashboardService: DashboardService;
private dashboardService: DashboardService;

/**
* Constructor router.
Expand Down
9 changes: 8 additions & 1 deletion packages/server/src/lib/Transformer/Transformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -149,13 +149,19 @@ export class Transformer {
return this.excludeAttributes().length > 0;
};

private dateFormat = 'YYYY MMM DD';

setDateFormat(format: string) {
this.dateFormat = format;
}

/**
*
* @param date
* @returns
*/
protected formatDate(date) {
return date ? moment(date).format('YYYY/MM/DD') : '';
return date ? moment(date).format(this.dateFormat) : '';
}

/**
Expand Down Expand Up @@ -193,6 +199,7 @@ export class Transformer {
) {
transformer.setOptions(options);
transformer.setContext(this.context);
transformer.setDateFormat(this.dateFormat);

return transformer.work(obj);
}
Expand Down
15 changes: 15 additions & 0 deletions packages/server/src/lib/Transformer/TransformerInjectable.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ export class TransformerInjectable {
};
}

/**
* Retrieves the given tenatn date format.
* @param {number} tenantId
* @returns {string}
*/
async getTenantDateFormat(tenantId: number) {
const metadata = await TenantMetadata.query().findOne('tenantId', tenantId);

return metadata.dateFormat;
}

/**
* Transformes the given transformer after inject the tenant context.
* @param {number} tenantId
Expand All @@ -41,7 +52,11 @@ export class TransformerInjectable {
if (!isNull(tenantId)) {
const context = await this.getApplicationContext(tenantId);
transformer.setContext(context);

const dateFormat = await this.getTenantDateFormat(tenantId);
transformer.setDateFormat(dateFormat);
}

transformer.setOptions(options);

return transformer.work(object);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,12 @@ export class CashflowTransactionTransformer extends Transformer {
* @returns {string[]}
*/
public includeAttributes = (): string[] => {
return ['formattedAmount', 'transactionTypeFormatted'];
return [
'formattedAmount',
'transactionTypeFormatted',
'formattedDate',
'formattedCreatedAt',
];
};

/**
Expand All @@ -24,10 +29,28 @@ export class CashflowTransactionTransformer extends Transformer {

/**
* Formatted transaction type.
* @param transaction
* @param transaction
* @returns {string}
*/
protected transactionTypeFormatted = (transaction) => {
return this.context.i18n.__(transaction.transactionTypeFormatted);
}
};

/**
* Retrieve the formatted transaction date.
* @param invoice
* @returns {string}
*/
protected formattedDate = (invoice): string => {
return this.formatDate(invoice.date);
};

/**
* Retrieve the formatted created at date.
* @param invoice
* @returns {string}
*/
protected formattedCreatedAt = (invoice): string => {
return this.formatDate(invoice.createdAt);
};
}
11 changes: 11 additions & 0 deletions packages/server/src/services/CreditNotes/CreditNoteTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ export class CreditNoteTransformer extends Transformer {
return [
'formattedCreditsRemaining',
'formattedCreditNoteDate',
'formattedCreatedAt',
'formattedCreatedAt',
'formattedAmount',
'formattedCreditsUsed',
'formattedSubtotal',
Expand All @@ -30,6 +32,15 @@ export class CreditNoteTransformer extends Transformer {
return this.formatDate(credit.creditNoteDate);
};

/**
* Retrieve formatted created at date.
* @param credit
* @returns {string}
*/
protected formattedCreatedAt = (credit): string => {
return this.formatDate(credit.createdAt);
};

/**
* Retrieve formatted invoice amount.
* @param {ICreditNote} credit
Expand Down
10 changes: 10 additions & 0 deletions packages/server/src/services/Expenses/CRUD/ExpenseTransformer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export class ExpenseTransfromer extends Transformer {
'formattedLandedCostAmount',
'formattedAllocatedCostAmount',
'formattedDate',
'formattedCreatedAt',
'categories',
'attachments',
];
Expand Down Expand Up @@ -62,6 +63,15 @@ export class ExpenseTransfromer extends Transformer {
return this.formatDate(expense.paymentDate);
};

/**
* Retrieve formatted created at date.
* @param {IExpense} expense
* @returns {string}
*/
protected formattedCreatedAt = (expense: IExpense): string => {
return this.formatDate(expense.createdAt);
}

/**
* Retrieves the transformed expense categories.
* @param {IExpense} expense
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class ManualJournalTransfromer extends Transformer {
'formattedAmount',
'formattedDate',
'formattedPublishedAt',
'formattedCreatedAt',
'attachments',
];
};
Expand All @@ -37,6 +38,15 @@ export class ManualJournalTransfromer extends Transformer {
return this.formatDate(manualJorunal.date);
};

/**
* Retrieve formatted created at date.
* @param {IManualJournal} manualJournal
* @returns {string}
*/
protected formattedCreatedAt = (manualJorunal: IManualJournal): string => {
return this.formatDate(manualJorunal.createdAt);
};

/**
* Retrieve formatted published at date.
* @param {IManualJournal} manualJournal
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ export default class OrganizationService {
): IOrganizationBuildDTO {
return {
...buildDTO,
dateFormat: defaultTo(buildDTO.dateFormat, 'DD/MM/yyyy'),
dateFormat: defaultTo(buildDTO.dateFormat, 'DD MMM yyyy'),
};
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
import { Transformer } from '@/lib/Transformer/Transformer';
import { formatNumber } from '@/utils';
import { PurchaseInvoiceTransformer } from '../Bills/PurchaseInvoiceTransformer';

export class BillPaymentEntryTransformer extends Transformer {
/**
* Include these attributes to bill payment object.
* @returns {Array}
*/
public includeAttributes = (): string[] => {
return ['paymentAmountFormatted'];
return ['paymentAmountFormatted', 'bill'];
};

/**
* Retreives the
*/
protected bill = (entry) => {
return this.item(entry.bill, new PurchaseInvoiceTransformer());
};

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class BillPaymentTransformer extends Transformer {
public includeAttributes = (): string[] => {
return [
'formattedPaymentDate',
'formattedCreatedAt',
'formattedAmount',
'entries',
'attachments',
Expand All @@ -27,6 +28,15 @@ export class BillPaymentTransformer extends Transformer {
return this.formatDate(billPayment.paymentDate);
};

/**
* Retrieve formatted created at date.
* @param {IBillPayment} billPayment
* @returns {string}
*/
protected formattedCreatedAt = (billPayment: IBillPayment): string => {
return this.formatDate(billPayment.createdAt);
}

/**
* Retrieve formatted bill amount.
* @param {IBill} invoice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class PurchaseInvoiceTransformer extends Transformer {
return [
'formattedBillDate',
'formattedDueDate',
'formattedCreatedAt',
'formattedAmount',
'formattedPaymentAmount',
'formattedBalance',
Expand Down Expand Up @@ -57,6 +58,15 @@ export class PurchaseInvoiceTransformer extends Transformer {
return this.formatDate(bill.dueDate);
};

/**
* Retrieve the formatted created at date.
* @param {IBill} bill
* @returns {string}
*/
protected formattedCreatedAt = (bill: IBill): string => {
return this.formatDate(bill.createdAt);
};

/**
* Retrieve formatted bill amount.
* @param {IBill} bill
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ export class VendorCreditTransformer extends Transformer {
'formattedAmount',
'formattedSubtotal',
'formattedVendorCreditDate',
'formattedCreatedAt',
'formattedCreditsRemaining',
'formattedInvoicedAmount',
'entries',
Expand All @@ -30,6 +31,15 @@ export class VendorCreditTransformer extends Transformer {
return this.formatDate(vendorCredit.vendorCreditDate);
};

/**
* Retireve formatted created at date.
* @param vendorCredit
* @returns {string}
*/
protected formattedCreatedAt = (vendorCredit): string => {
return this.formatDate(vendorCredit.createdAt);
};

/**
* Retrieve formatted vendor credit amount.
* @param {IVendorCredit} credit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ export class SaleEstimateTransfromer extends Transformer {
'formattedDeliveredAtDate',
'formattedApprovedAtDate',
'formattedRejectedAtDate',
'formattedCreatedAt',
'entries',
'attachments',
];
Expand All @@ -41,6 +42,15 @@ export class SaleEstimateTransfromer extends Transformer {
return this.formatDate(estimate.expirationDate);
};

/**
* Retrieves the formatted estimate created at.
* @param {ISaleEstimate} estimate -
* @returns {string}
*/
protected formattedCreatedAt = (estimate: ISaleEstimate): string => {
return this.formatDate(estimate.createdAt);
};

/**
* Retrieve formatted estimate date.
* @param {ISaleEstimate} invoice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export class SaleInvoiceTransformer extends Transformer {
return [
'invoiceDateFormatted',
'dueDateFormatted',
'createdAtFormatted',
'dueAmountFormatted',
'paymentAmountFormatted',
'balanceAmountFormatted',
Expand Down Expand Up @@ -48,6 +49,15 @@ export class SaleInvoiceTransformer extends Transformer {
return this.formatDate(invoice.dueDate);
};

/**
* Retrieve the formatted created at date.
* @param invoice
* @returns {string}
*/
protected createdAtFormatted = (invoice): string => {
return this.formatDate(invoice.createdAt);
};

/**
* Retrieve formatted invoice due amount.
* @param {ISaleInvoice} invoice
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export class PaymentReceiveTransfromer extends Transformer {
return [
'subtotalFormatted',
'formattedPaymentDate',
'formattedCreatedAt',
'formattedAmount',
'formattedExchangeRate',
'entries',
Expand All @@ -27,9 +28,18 @@ export class PaymentReceiveTransfromer extends Transformer {
return this.formatDate(payment.paymentDate);
};

/**
* Retrieves the formatted created at date.
* @param {IPaymentReceive} payment
* @returns {string}
*/
protected formattedCreatedAt = (payment: IPaymentReceive): string => {
return this.formatDate(payment.createdAt);
};

/**
* Retrieve the formatted payment subtotal.
* @param {IPaymentReceive} payment
* @param {IPaymentReceive} payment
* @returns {string}
*/
protected subtotalFormatted = (payment: IPaymentReceive): string => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ export class SaleReceiptTransformer extends Transformer {
'formattedAmount',
'formattedReceiptDate',
'formattedClosedAtDate',
'formattedCreatedAt',
'entries',
'attachments',
];
Expand All @@ -40,6 +41,15 @@ export class SaleReceiptTransformer extends Transformer {
return this.formatDate(receipt.closedAt);
};

/**
* Retrieve formatted receipt created at date.
* @param receipt
* @returns {string}
*/
protected formattedCreatedAt = (receipt: ISaleReceipt): string => {
return this.formatDate(receipt.createdAt);
};

/**
* Retrieves the estimate formatted subtotal.
* @param {ISaleReceipt} receipt
Expand Down
Loading

0 comments on commit 1e53a8e

Please sign in to comment.