Skip to content

Commit

Permalink
Merge pull request #762 from bigcapitalhq/fix-discount-adjustment-bugs
Browse files Browse the repository at this point in the history
fix: discount & adjustment sale transactions bugs
  • Loading branch information
abouolia authored Dec 5, 2024
2 parents 391dc77 + beec097 commit 14ae978
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 19 deletions.
2 changes: 1 addition & 1 deletion packages/server/src/services/Sales/Estimates/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ export const transformEstimateToPdfTemplate = (
quantity: entry.quantityFormatted,
total: entry.totalFormatted,
})),
total: estimate.formattedSubtotal,
total: estimate.totalFormatted,
subtotal: estimate.formattedSubtotal,
adjustment: estimate.adjustmentFormatted,
customerNote: estimate.note,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,21 +82,21 @@ export class GetSaleReceiptMailStateTransformer extends SaleReceiptTransformer {
};

/**
*
* Retrieves the total amount.
* @param receipt
* @returns
*/
protected total = (receipt) => {
return receipt.amount;
return receipt.total;
};

/**
*
* Retrieves the formatted total amount.
* @param receipt
* @returns
* @returns {string}
*/
protected totalFormatted = (receipt) => {
return this.formatMoney(receipt.amount, {
return this.formatMoney(receipt.total, {
currencyCode: receipt.currencyCode,
});
};
Expand All @@ -118,7 +118,7 @@ export class GetSaleReceiptMailStateTransformer extends SaleReceiptTransformer {
* @returns
*/
protected subtotal = (receipt) => {
return receipt.amount;
return receipt.subtotal;
};

/**
Expand All @@ -127,7 +127,7 @@ export class GetSaleReceiptMailStateTransformer extends SaleReceiptTransformer {
* @returns
*/
protected subtotalFormatted = (receipt) => {
return this.formatMoney(receipt.amount, {
return this.formatMoney(receipt.subtotal, {
currencyCode: receipt.currencyCode,
});
};
Expand Down
5 changes: 4 additions & 1 deletion packages/server/src/utils/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,10 @@ export const formatSmsMessage = (message: string, args) => {
const variable = `{${key}}`;
const value = _.defaultTo(args[key], '');

formattedMessage = formattedMessage.replace(variable, value);
formattedMessage = formattedMessage.replace(
new RegExp(variable, 'g'),
value
);
});
return formattedMessage;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ export const withEstimateMailReceiptPreviewProps = <
estimateNumber: estimateMailState?.estimateNumber,
estimateDate: estimateMailState?.estimateDateFormatted,
subtotal: estimateMailState?.subtotalFormatted,
discount: estimateMailState?.discountFormatted,
discount: estimateMailState?.discountAmountFormatted,
adjustment: estimateMailState?.adjustmentFormatted,
items,
message,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ export const formatSmsMessage = (
const variable = `{${key}}`;
const value = defaultTo(args[key], '');

formattedMessage = formattedMessage.replace(variable, value);
formattedMessage = formattedMessage.replaceAll(variable, value);
});
return formattedMessage;
};
4 changes: 2 additions & 2 deletions packages/webapp/src/hooks/query/estimates.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -284,8 +284,8 @@ export interface SaleEstimateMailStateResponse {
subtotal: number;
subtotalFormatted: string;

discount: number;
discountFormatted: string;
discountAmount: number;
discountAmountFormatted: string;
discountLabel: string;
discountPercentage: number | null;
discountPercentageFormatted: string;
Expand Down
6 changes: 4 additions & 2 deletions shared/pdf-templates/src/components/EstimatePaperTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
PaperTemplateProps,
PaperTemplateTotalBorder,
} from './PaperTemplate';
import { theme } from '../constants';

export interface EstimatePaperTemplateProps extends PaperTemplateProps {
// # Company
Expand Down Expand Up @@ -173,6 +174,7 @@ export function EstimatePaperTemplate({
lineRateLabel = 'Rate',
lineTotalLabel = 'Total',
}: EstimatePaperTemplateProps) {

return (
<PaperTemplate primaryColor={primaryColor} secondaryColor={secondaryColor}>
<Stack spacing={24}>
Expand Down Expand Up @@ -228,13 +230,13 @@ export function EstimatePaperTemplate({
<Text>{data.item}</Text>
<Text
fontSize={'12px'}
// className={Classes.TEXT_MUTED}
// style={{ fontSize: 12 }}
color={theme.colors['cool-gray-500']}
>
{data.description}
</Text>
</Stack>
),
thStyle: { width: '60%' },
},
{ label: lineQuantityLabel, accessor: 'quantity' },
{ label: lineRateLabel, accessor: 'rate', align: 'right' },
Expand Down
7 changes: 6 additions & 1 deletion shared/pdf-templates/src/components/InvoicePaperTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -118,23 +118,27 @@ export interface InvoicePaperTemplateProps extends PaperTemplateProps {
}

export function InvoicePaperTemplate({
// # Colors
primaryColor,
secondaryColor,

// # Company.
companyName = 'Bigcapital Technology, Inc.',

showCompanyLogo = true,
companyLogoUri = '',

// # Due date
dueDate = 'September 3, 2024',
dueDateLabel = 'Date due',
showDueDate = true,

// # Issue date.
dateIssue = 'September 3, 2024',
dateIssueLabel = 'Date of issue',
showDateIssue = true,

// dateIssue,
// Invoice #,
invoiceNumberLabel = 'Invoice number',
invoiceNumber = '346D3D40-0001',
showInvoiceNumber = true,
Expand Down Expand Up @@ -197,6 +201,7 @@ export function InvoicePaperTemplate({
{ label: 'Sample Tax2 (7.00%)', amount: '21.74' },
],

// # Statement
statementLabel = 'Statement',
showStatement = true,
statement = DefaultPdfTemplateStatement,
Expand Down
6 changes: 3 additions & 3 deletions shared/pdf-templates/src/components/ReceiptPaperTemplate.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
DefaultPdfTemplateAddressBilledTo,
DefaultPdfTemplateAddressBilledFrom,
} from './_constants';
import { theme } from '../constants';

export interface ReceiptPaperTemplateProps extends PaperTemplateProps {
// # Company logo
Expand Down Expand Up @@ -216,8 +217,7 @@ export function ReceiptPaperTemplate({
<Text>{data.item}</Text>
<Text
fontSize={'12px'}
// className={Classes.TEXT_MUTED}
// style={{ fontSize: 12 }}
color={theme.colors['cool-gray-500']}
>
{data.description}
</Text>
Expand Down Expand Up @@ -255,7 +255,7 @@ export function ReceiptPaperTemplate({
<PaperTemplate.TotalLine
label={totalLabel}
amount={total}
border={PaperTemplateTotalBorder.Gray}
border={PaperTemplateTotalBorder.Dark}
style={{ fontWeight: 500 }}
/>
)}
Expand Down
6 changes: 6 additions & 0 deletions shared/pdf-templates/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
import { defaultTheme } from "@xstyled/system";

export const OpenSansFontLink = `
<link rel="preconnect" href="https://fonts.googleapis.com">
<link rel="preconnect" href="https://fonts.gstatic.com" crossorigin>
<link href="https://fonts.googleapis.com/css2?family=Open+Sans:ital,wght@0,300..800;1,300..800&family=Roboto:ital,wght@0,100;0,300;0,400;0,500;0,700;0,900;1,100;1,300;1,400;1,500;1,700;1,900&display=swap" rel="stylesheet">
`;

export const theme = {
...defaultTheme,
}

0 comments on commit 14ae978

Please sign in to comment.