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( Future<InvoiceEntity> emailCredit(
Credentials credentials, Credentials credentials,
InvoiceEntity credit, InvoiceEntity credit,
EmailTemplate template, EmailTemplate template,
String subject, String subject,
String body) async { String body,
String ccEmail,
) async {
final data = { final data = {
'entity': '${credit.entityType}', 'entity': '${credit.entityType}',
'entity_id': credit.id, 'entity_id': credit.id,
'template': 'email_template_$template', 'template': 'email_template_$template',
'body': body, 'body': body,
'subject': subject, 'subject': subject,
'cc_email': ccEmail,
}; };
final dynamic response = await webClient.post( final dynamic response = await webClient.post(

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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