Add CC email

This commit is contained in:
Hillel Coren 2023-03-20 16:26:43 +02:00
parent ad51025af5
commit cc4a36d83e
17 changed files with 124 additions and 49 deletions

View File

@ -107,17 +107,20 @@ class CreditRepository {
}
Future<InvoiceEntity> emailCredit(
Credentials credentials,
InvoiceEntity credit,
EmailTemplate template,
String subject,
String body) async {
Credentials credentials,
InvoiceEntity credit,
EmailTemplate template,
String subject,
String body,
String ccEmail,
) async {
final data = {
'entity': '${credit.entityType}',
'entity_id': credit.id,
'template': 'email_template_$template',
'body': body,
'subject': subject,
'cc_email': ccEmail,
};
final dynamic response = await webClient.post(

View File

@ -121,17 +121,20 @@ class InvoiceRepository {
}
Future<InvoiceEntity> emailInvoice(
Credentials credentials,
InvoiceEntity invoice,
EmailTemplate template,
String subject,
String body) async {
Credentials credentials,
InvoiceEntity invoice,
EmailTemplate template,
String subject,
String body,
String ccEmail,
) async {
final data = {
'entity': '${invoice.entityType}',
'entity_id': invoice.id,
'template': 'email_template_$template',
'body': body,
'subject': subject,
'cc_email': ccEmail,
};
final dynamic response = await webClient.post(

View File

@ -115,17 +115,20 @@ class PurchaseOrderRepository {
}
Future<InvoiceEntity> emailPurchaseOrder(
Credentials credentials,
InvoiceEntity purchaseOrder,
EmailTemplate template,
String subject,
String body) async {
Credentials credentials,
InvoiceEntity purchaseOrder,
EmailTemplate template,
String subject,
String body,
String ccEmail,
) async {
final data = {
'entity': '${purchaseOrder.entityType}',
'entity_id': purchaseOrder.id,
'template': 'email_template_$template',
'body': body,
'subject': subject,
'cc_email': ccEmail,
};
final dynamic response = await webClient.post(

View File

@ -117,14 +117,21 @@ class QuoteRepository {
return quoteResponse.data;
}
Future<InvoiceEntity> emailQuote(Credentials credentials, InvoiceEntity quote,
EmailTemplate template, String subject, String body) async {
Future<InvoiceEntity> emailQuote(
Credentials credentials,
InvoiceEntity quote,
EmailTemplate template,
String subject,
String body,
String ccEmail,
) async {
final data = {
'entity': '${quote.entityType}',
'entity_id': quote.id,
'template': 'email_template_$template',
'body': body,
'subject': subject,
'cc_email': ccEmail,
};
final dynamic response = await webClient.post(

View File

@ -227,14 +227,21 @@ class SaveCreditFailure implements StopSaving {
}
class EmailCreditRequest implements StartSaving {
EmailCreditRequest(
{this.completer, this.creditId, this.template, this.subject, this.body});
EmailCreditRequest({
@required this.completer,
@required this.creditId,
@required this.template,
@required this.subject,
@required this.body,
@required this.ccEmail,
});
final Completer completer;
final String creditId;
final EmailTemplate template;
final String subject;
final String body;
final String ccEmail;
}
class EmailCreditSuccess implements StopSaving, PersistData {}

View File

@ -273,8 +273,14 @@ Middleware<AppState> _emailCredit(CreditRepository repository) {
final action = dynamicAction as EmailCreditRequest;
final origCredit = store.state.creditState.map[action.creditId];
repository
.emailCredit(store.state.credentials, origCredit, action.template,
action.subject, action.body)
.emailCredit(
store.state.credentials,
origCredit,
action.template,
action.subject,
action.body,
action.ccEmail,
)
.then((void _) {
store.dispatch(EmailCreditSuccess());
if (action.completer != null) {

View File

@ -228,14 +228,21 @@ class SaveInvoiceFailure implements StopSaving {
}
class EmailInvoiceRequest implements StartSaving {
EmailInvoiceRequest(
{this.completer, this.invoiceId, this.template, this.subject, this.body});
EmailInvoiceRequest({
@required this.completer,
@required this.invoiceId,
@required this.template,
@required this.subject,
@required this.body,
@required this.ccEmail,
});
final Completer completer;
final String invoiceId;
final EmailTemplate template;
final String subject;
final String body;
final String ccEmail;
}
class EmailInvoiceSuccess implements StopSaving, PersistData {

View File

@ -353,8 +353,14 @@ Middleware<AppState> _emailInvoice(InvoiceRepository repository) {
final action = dynamicAction as EmailInvoiceRequest;
final origInvoice = store.state.invoiceState.map[action.invoiceId];
repository
.emailInvoice(store.state.credentials, origInvoice, action.template,
action.subject, action.body)
.emailInvoice(
store.state.credentials,
origInvoice,
action.template,
action.subject,
action.body,
action.ccEmail,
)
.then((InvoiceEntity invoice) {
store.dispatch(EmailInvoiceSuccess(invoice: invoice));
store.dispatch(RefreshData());

View File

@ -336,18 +336,21 @@ class RestorePurchaseOrdersFailure implements StopSaving {
}
class EmailPurchaseOrderRequest implements StartSaving {
EmailPurchaseOrderRequest(
{this.completer,
this.purchaseOrderId,
this.template,
this.subject,
this.body});
EmailPurchaseOrderRequest({
@required this.completer,
@required this.purchaseOrderId,
@required this.template,
@required this.subject,
@required this.body,
@required this.ccEmail,
});
final Completer completer;
final String purchaseOrderId;
final EmailTemplate template;
final String subject;
final String body;
final String ccEmail;
}
class EmailPurchaseOrderSuccess implements StopSaving, PersistData {

View File

@ -391,8 +391,14 @@ Middleware<AppState> _emailPurchaseOrder(PurchaseOrderRepository repository) {
final origPurchaseOrder =
store.state.purchaseOrderState.map[action.purchaseOrderId];
repository
.emailPurchaseOrder(store.state.credentials, origPurchaseOrder,
action.template, action.subject, action.body)
.emailPurchaseOrder(
store.state.credentials,
origPurchaseOrder,
action.template,
action.subject,
action.body,
action.ccEmail,
)
.then((purchaseOrder) {
store.dispatch(EmailPurchaseOrderSuccess(purchaseOrder));
if (action.completer != null) {

View File

@ -227,14 +227,21 @@ class SaveQuoteFailure implements StopSaving {
}
class EmailQuoteRequest implements StartSaving {
EmailQuoteRequest(
{this.completer, this.quoteId, this.template, this.subject, this.body});
EmailQuoteRequest({
@required this.completer,
@required this.quoteId,
@required this.template,
@required this.subject,
@required this.body,
@required this.ccEmail,
});
final Completer completer;
final String quoteId;
final EmailTemplate template;
final String subject;
final String body;
final String ccEmail;
}
class EmailQuoteSuccess implements StopSaving, PersistData {

View File

@ -315,7 +315,7 @@ Middleware<AppState> _emailQuote(QuoteRepository repository) {
final origQuote = store.state.quoteState.map[action.quoteId];
repository
.emailQuote(store.state.credentials, origQuote, action.template,
action.subject, action.body)
action.subject, action.body, action.ccEmail,)
.then((quote) {
store.dispatch(EmailQuoteSuccess(quote));
if (action.completer != null) {

View File

@ -420,8 +420,13 @@ class _InvoiceEmailViewState extends State<InvoiceEmailView>
saveLabel: localization.send,
onSavePressed: (context) {
if (state.account.accountSmsVerified || state.isSelfHosted) {
viewModel.onSendPressed(context, selectedTemplate,
_subjectController.text, _bodyController.text);
viewModel.onSendPressed(
context,
selectedTemplate,
_subjectController.text,
_bodyController.text,
'',
);
} else {
showMessageDialog(
context: context, message: localization.verifyPhoneNumberHelp);
@ -506,8 +511,13 @@ class _InvoiceEmailViewState extends State<InvoiceEmailView>
),
saveLabel: localization.send,
onSavePressed: (context) {
viewModel.onSendPressed(context, selectedTemplate,
_subjectController.text, _bodyController.text);
viewModel.onSendPressed(
context,
selectedTemplate,
_subjectController.text,
_bodyController.text,
'',
);
},
body: TabBarView(
controller: _controller,

View File

@ -59,7 +59,7 @@ class EmailCreditVM extends EmailEntityVM {
ClientEntity client,
VendorEntity vendor,
Function loadClient,
Function(BuildContext, EmailTemplate, String, String) onSendPressed,
Function(BuildContext, EmailTemplate, String, String, String) onSendPressed,
}) : super(
state: state,
isLoading: isLoading,
@ -84,7 +84,7 @@ class EmailCreditVM extends EmailEntityVM {
loadClient: () {
store.dispatch(LoadClient(clientId: credit.clientId));
},
onSendPressed: (context, template, subject, body) {
onSendPressed: (context, template, subject, body, ccEmail) {
final completer = snackBarCompleter<Null>(
context, AppLocalization.of(context).emailedCredit,
shouldPop: isMobile(context));
@ -99,6 +99,7 @@ class EmailCreditVM extends EmailEntityVM {
template: template,
subject: subject,
body: body,
ccEmail: ccEmail,
));
},
);

View File

@ -68,7 +68,8 @@ abstract class EmailEntityVM {
final InvoiceEntity invoice;
final ClientEntity client;
final VendorEntity vendor;
final Function(BuildContext, EmailTemplate, String, String) onSendPressed;
final Function(BuildContext, EmailTemplate, String, String, String)
onSendPressed;
}
class EmailInvoiceVM extends EmailEntityVM {
@ -80,7 +81,7 @@ class EmailInvoiceVM extends EmailEntityVM {
InvoiceEntity invoice,
ClientEntity client,
VendorEntity vendor,
Function(BuildContext, EmailTemplate, String, String) onSendPressed,
Function(BuildContext, EmailTemplate, String, String, String) onSendPressed,
}) : super(
state: state,
isLoading: isLoading,
@ -104,7 +105,7 @@ class EmailInvoiceVM extends EmailEntityVM {
invoice: invoice,
client: state.clientState.map[invoice.clientId] ??
ClientEntity(id: invoice.clientId),
onSendPressed: (context, template, subject, body) {
onSendPressed: (context, template, subject, body, ccEmail) {
final completer = snackBarCompleter<Null>(
context, AppLocalization.of(context).emailedInvoice,
shouldPop: isMobile(context));
@ -119,6 +120,7 @@ class EmailInvoiceVM extends EmailEntityVM {
template: template,
subject: subject,
body: body,
ccEmail: ccEmail,
));
},
);

View File

@ -59,7 +59,8 @@ class EmailPurchaseOrderVM extends EmailEntityVM {
@required ClientEntity client,
@required VendorEntity vendor,
@required
Function(BuildContext, EmailTemplate, String, String) onSendPressed,
Function(BuildContext, EmailTemplate, String, String, String)
onSendPressed,
}) : super(
state: state,
isLoading: isLoading,
@ -83,7 +84,7 @@ class EmailPurchaseOrderVM extends EmailEntityVM {
invoice: purchaseOrder,
client: state.clientState.map[purchaseOrder.clientId],
vendor: state.vendorState.map[purchaseOrder.vendorId],
onSendPressed: (context, template, subject, body) {
onSendPressed: (context, template, subject, body, ccEmail) {
final completer = snackBarCompleter<Null>(
context, AppLocalization.of(context).emailedPurchaseOrder,
shouldPop: isMobile(context));
@ -98,6 +99,7 @@ class EmailPurchaseOrderVM extends EmailEntityVM {
template: template,
subject: subject,
body: body,
ccEmail: ccEmail,
));
},
);

View File

@ -59,7 +59,8 @@ class EmailQuoteVM extends EmailEntityVM {
@required ClientEntity client,
@required VendorEntity vendor,
@required
Function(BuildContext, EmailTemplate, String, String) onSendPressed,
Function(BuildContext, EmailTemplate, String, String, String)
onSendPressed,
}) : super(
state: state,
isLoading: isLoading,
@ -82,7 +83,7 @@ class EmailQuoteVM extends EmailEntityVM {
invoice: quote,
client: state.clientState.map[quote.clientId],
vendor: state.vendorState.map[quote.vendorId],
onSendPressed: (context, template, subject, body) {
onSendPressed: (context, template, subject, body, ccEmail) {
final completer = snackBarCompleter<Null>(
context, AppLocalization.of(context).emailedQuote,
shouldPop: isMobile(context));
@ -97,6 +98,7 @@ class EmailQuoteVM extends EmailEntityVM {
template: template,
subject: subject,
body: body,
ccEmail: ccEmail,
));
},
);