-
-
Notifications
You must be signed in to change notification settings - Fork 251
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: wip send estimate mail preview
- Loading branch information
Showing
34 changed files
with
405 additions
and
459 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
packages/server/src/services/Sales/Estimates/GetSaleEstimateMailState.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { Inject } from 'typedi'; | ||
import { SendSaleEstimateMail } from './SendSaleEstimateMail'; | ||
import HasTenancyService from '@/services/Tenancy/TenancyService'; | ||
import { GetSaleEstimateMailStateTransformer } from './GetSaleEstimateMailStateTransformer'; | ||
import { TransformerInjectable } from '@/lib/Transformer/TransformerInjectable'; | ||
|
||
export class GetSaleEstimateMailState { | ||
@Inject() | ||
private estimateMail: SendSaleEstimateMail; | ||
|
||
@Inject() | ||
private tenancy: HasTenancyService; | ||
|
||
@Inject() | ||
private transformer: TransformerInjectable; | ||
|
||
/** | ||
* Retrieves the estimate mail state of the given sale estimate. | ||
* Estimate mail state includes the mail options, branding attributes and the estimate details. | ||
* @param {number} tenantId | ||
* @param {number} saleEstimateId | ||
* @returns {Promise<SaleEstimateMailState>} | ||
*/ | ||
async getEstimateMailState( | ||
tenantId: number, | ||
saleEstimateId: number | ||
): Promise<SaleEstimateMailState> { | ||
const { SaleEstimate } = this.tenancy.models(tenantId); | ||
|
||
const saleEstimate = await SaleEstimate.query() | ||
.findById(saleEstimateId) | ||
.withGraphFetched('customer') | ||
.withGraphFetched('entries.item') | ||
.withGraphFetched('pdfTemplate') | ||
.throwIfNotFound(); | ||
|
||
const mailOptions = await this.estimateMail.getMailOptions( | ||
tenantId, | ||
saleEstimateId | ||
); | ||
const transformed = await this.transformer.transform( | ||
tenantId, | ||
saleEstimate, | ||
new GetSaleEstimateMailStateTransformer(), | ||
{ | ||
mailOptions, | ||
} | ||
); | ||
return transformed; | ||
} | ||
} |
105 changes: 105 additions & 0 deletions
105
packages/server/src/services/Sales/Estimates/GetSaleEstimateMailStateTransformer.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
import { ItemEntryTransformer } from '../Invoices/ItemEntryTransformer'; | ||
import { SaleEstimateTransfromer } from './SaleEstimateTransformer'; | ||
|
||
export class GetSaleEstimateMailStateTransformer extends SaleEstimateTransfromer { | ||
public excludeAttributes = (): string[] => { | ||
return ['*']; | ||
}; | ||
|
||
public includeAttributes = (): string[] => { | ||
return [ | ||
'estimateDate', | ||
'formattedEstimateDate', | ||
|
||
'total', | ||
'totalFormatted', | ||
|
||
'subtotal', | ||
'subtotalFormatted', | ||
|
||
'estimateNo', | ||
|
||
'entries', | ||
|
||
'companyName', | ||
'companyLogoUri', | ||
|
||
'primaryColor', | ||
'customerName', | ||
]; | ||
}; | ||
|
||
/** | ||
* Retrieves the customer name of the invoice. | ||
* @returns {string} | ||
*/ | ||
protected customerName = (invoice) => { | ||
return invoice.customer.displayName; | ||
}; | ||
|
||
/** | ||
* Retrieves the company name. | ||
* @returns {string} | ||
*/ | ||
protected companyName = () => { | ||
return this.context.organization.name; | ||
}; | ||
|
||
/** | ||
* Retrieves the company logo uri. | ||
* @returns {string | null} | ||
*/ | ||
protected companyLogoUri = (invoice) => { | ||
return invoice.pdfTemplate?.companyLogoUri; | ||
}; | ||
|
||
/** | ||
* Retrieves the primary color. | ||
* @returns {string} | ||
*/ | ||
protected primaryColor = (invoice) => { | ||
return invoice.pdfTemplate?.attributes?.primaryColor; | ||
}; | ||
|
||
/** | ||
* | ||
* @param invoice | ||
* @returns | ||
*/ | ||
protected entries = (invoice) => { | ||
return this.item( | ||
invoice.entries, | ||
new GetSaleEstimateMailStateEntryTransformer(), | ||
{ | ||
currencyCode: invoice.currencyCode, | ||
} | ||
); | ||
}; | ||
|
||
/** | ||
* Merges the mail options with the invoice object. | ||
*/ | ||
public transform = (object: any) => { | ||
return { | ||
...this.options.mailOptions, | ||
...object, | ||
}; | ||
}; | ||
} | ||
|
||
class GetSaleEstimateMailStateEntryTransformer extends ItemEntryTransformer { | ||
public excludeAttributes = (): string[] => { | ||
return ['*']; | ||
}; | ||
|
||
public includeAttributes = (): string[] => { | ||
return [ | ||
'description', | ||
'quantity', | ||
'unitPrice', | ||
'unitPriceFormatted', | ||
'total', | ||
'totalFormatted', | ||
]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 0 additions & 39 deletions
39
...app/src/containers/Sales/Estimates/EstimateForm/Dialogs/EstimateFormMailDeliverDialog.tsx
This file was deleted.
Oops, something went wrong.
40 changes: 0 additions & 40 deletions
40
.../containers/Sales/Estimates/EstimateForm/Dialogs/EstimateFormMailDeliverDialogContent.tsx
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.