Skip to content

Commit

Permalink
feat: add paid amount attr and formatting to SaleReceipt transformer
Browse files Browse the repository at this point in the history
  • Loading branch information
abouolia committed Dec 8, 2024
1 parent 11d7a40 commit 0a5115f
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 5 deletions.
19 changes: 19 additions & 0 deletions packages/server/src/models/SaleReceipt.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ export default class SaleReceipt extends mixin(TenantModel, [
'discountAmount',
'discountPercentage',

'paid',
'paidLocal',

'isClosed',
'isDraft',
];
Expand Down Expand Up @@ -130,6 +133,22 @@ export default class SaleReceipt extends mixin(TenantModel, [
return this.adjustment * this.exchangeRate;
}

/**
* Receipt paid amount.
* @returns {number}
*/
get paid() {
return this.total;
}

/**
* Receipt paid amount in local currency.
* @returns {number}
*/
get paidLocal() {
return this.paid * this.exchangeRate;
}

/**
* Detarmine whether the sale receipt closed.
* @return {boolean}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export class SaleReceiptTransformer extends Transformer {
'formattedReceiptDate',
'formattedClosedAtDate',
'formattedCreatedAt',
'paidFormatted',
'entries',
'attachments',
];
Expand Down Expand Up @@ -130,6 +131,18 @@ export class SaleReceiptTransformer extends Transformer {
return receipt.discountPercentage ? `${receipt.discountPercentage}%` : '';
};

/**
* Retrieves formatted paid amount.
* @param receipt
* @returns {string}
*/
protected paidFormatted = (receipt: ISaleReceipt): string => {
return formatNumber(receipt.paid, {
currencyCode: receipt.currencyCode,
excerptZero: true,
});
};

/**
* Retrieves formatted adjustment amount.
* @param receipt
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,12 @@ import styled from 'styled-components';
import { defaultTo } from 'lodash';

import {
ButtonLink,
CustomerDrawerLink,
CommercialDocHeader,
CommercialDocTopHeader,
ExchangeRateDetailItem,
Row,
Col,
FormatDate,
DetailsMenu,
DetailItem,
} from '@/components';
Expand Down Expand Up @@ -66,6 +64,7 @@ export default function ReceiptDetailHeader() {
/>
</DetailsMenu>
</Col>

<Col xs={6}>
<DetailsMenu
direction={'horizantal'}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import {
TotalLine,
TotalLineBorderStyle,
TotalLineTextStyle,
FormatNumber,
} from '@/components';
import { useReceiptDetailDrawerContext } from './ReceiptDetailDrawerProvider';

Expand Down Expand Up @@ -51,8 +50,8 @@ export default function ReceiptDetailTableFooter() {
/>
<TotalLine
title={<T id={'receipt.details.payment_amount'} />}
value={receipt.formatted_amount}
borderStyle={TotalLineBorderStyle.DoubleDark}
value={receipt.paid_formatted}
borderStyle={TotalLineBorderStyle.SingleDark}
/>
<TotalLine
title={<T id={'receipt.details.due_amount'} />}
Expand Down

0 comments on commit 0a5115f

Please sign in to comment.