Choose template to use when emailing multiple invoices at once #472
This commit is contained in:
parent
2d7123d2c7
commit
9eb4ad2019
|
|
@ -68,7 +68,7 @@ class InvoiceRepository {
|
||||||
data: json.encode({
|
data: json.encode({
|
||||||
'ids': ids,
|
'ids': ids,
|
||||||
'action': action.toApiParam(),
|
'action': action.toApiParam(),
|
||||||
if (template != null) 'email_type': 'email_template_$template',
|
if (template != null) 'email_type': '$template',
|
||||||
}));
|
}));
|
||||||
|
|
||||||
final InvoiceListResponse invoiceResponse =
|
final InvoiceListResponse invoiceResponse =
|
||||||
|
|
|
||||||
|
|
@ -670,68 +670,52 @@ void handleInvoiceAction(BuildContext context, List<BaseEntity> invoices,
|
||||||
..parameters.entityType = EntityType.invoice.apiValue
|
..parameters.entityType = EntityType.invoice.apiValue
|
||||||
..parameters.entityId = invoice.id));
|
..parameters.entityId = invoice.id));
|
||||||
} else {
|
} else {
|
||||||
confirmCallback(
|
final template = await showDialog<EmailTemplate>(
|
||||||
context: context,
|
context: context,
|
||||||
message: localization.bulkEmailInvoices,
|
builder: (context) {
|
||||||
callback: (_) {
|
final settings = getClientSettings(state, client);
|
||||||
store.dispatch(BulkEmailInvoicesRequest(
|
final templates = {
|
||||||
completer: snackBarCompleter<Null>(
|
EmailTemplate.invoice: localization.initialEmail,
|
||||||
context,
|
EmailTemplate.reminder1: localization.firstReminder,
|
||||||
invoiceIds.length == 1
|
EmailTemplate.reminder2: localization.secondReminder,
|
||||||
? localization.emailedInvoice
|
EmailTemplate.reminder3: localization.thirdReminder,
|
||||||
: localization.emailedInvoices),
|
EmailTemplate.reminder_endless: localization.endlessReminder,
|
||||||
invoiceIds: invoiceIds,
|
if ((settings.emailSubjectCustom1 ?? '').isNotEmpty)
|
||||||
));
|
EmailTemplate.custom1: localization.firstCustom,
|
||||||
});
|
if ((settings.emailSubjectCustom2 ?? '').isNotEmpty)
|
||||||
|
EmailTemplate.custom2: localization.secondCustom,
|
||||||
|
if ((settings.emailSubjectCustom3 ?? '').isNotEmpty)
|
||||||
|
EmailTemplate.custom3: localization.thirdCustom,
|
||||||
|
};
|
||||||
|
return SimpleDialog(
|
||||||
|
title: Text(
|
||||||
|
invoiceIds.length == 1
|
||||||
|
? localization.emailInvoice
|
||||||
|
: localization.emailCountInvoices
|
||||||
|
.replaceFirst(':count', '${invoiceIds.length}'),
|
||||||
|
),
|
||||||
|
children: templates.keys
|
||||||
|
.map((template) => SimpleDialogOption(
|
||||||
|
child: Text(templates[template]),
|
||||||
|
onPressed: () {
|
||||||
|
Navigator.of(context).pop(template);
|
||||||
|
},
|
||||||
|
))
|
||||||
|
.toList(),
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
|
||||||
if (false) {
|
if (template != null) {
|
||||||
final template = await showDialog<EmailTemplate>(
|
store.dispatch(BulkEmailInvoicesRequest(
|
||||||
context: context,
|
completer: snackBarCompleter<Null>(
|
||||||
builder: (context) {
|
navigatorKey.currentContext,
|
||||||
final settings = getClientSettings(state, client);
|
invoiceIds.length == 1
|
||||||
final templates = {
|
? localization.emailedInvoice
|
||||||
EmailTemplate.invoice: localization.initialEmail,
|
: localization.emailedInvoices),
|
||||||
EmailTemplate.reminder1: localization.firstReminder,
|
invoiceIds: invoiceIds,
|
||||||
EmailTemplate.reminder2: localization.secondReminder,
|
template: template,
|
||||||
EmailTemplate.reminder3: localization.thirdReminder,
|
));
|
||||||
EmailTemplate.reminder_endless: localization.endlessReminder,
|
|
||||||
if ((settings.emailSubjectCustom1 ?? '').isNotEmpty)
|
|
||||||
EmailTemplate.custom1: localization.firstCustom,
|
|
||||||
if ((settings.emailSubjectCustom2 ?? '').isNotEmpty)
|
|
||||||
EmailTemplate.custom2: localization.secondCustom,
|
|
||||||
if ((settings.emailSubjectCustom3 ?? '').isNotEmpty)
|
|
||||||
EmailTemplate.custom3: localization.thirdCustom,
|
|
||||||
};
|
|
||||||
return SimpleDialog(
|
|
||||||
title: Text(
|
|
||||||
invoiceIds.length == 1
|
|
||||||
? localization.emailInvoice
|
|
||||||
: localization.emailCountInvoices
|
|
||||||
.replaceFirst(':count', '${invoiceIds.length}'),
|
|
||||||
),
|
|
||||||
children: templates.keys
|
|
||||||
.map((template) => SimpleDialogOption(
|
|
||||||
child: Text(templates[template]),
|
|
||||||
onPressed: () {
|
|
||||||
Navigator.of(context).pop(template);
|
|
||||||
},
|
|
||||||
))
|
|
||||||
.toList(),
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
if (template != null) {
|
|
||||||
store.dispatch(BulkEmailInvoicesRequest(
|
|
||||||
completer: snackBarCompleter<Null>(
|
|
||||||
navigatorKey.currentContext,
|
|
||||||
invoiceIds.length == 1
|
|
||||||
? localization.emailedInvoice
|
|
||||||
: localization.emailedInvoices),
|
|
||||||
invoiceIds: invoiceIds,
|
|
||||||
template: template,
|
|
||||||
));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
|
|
@ -385,7 +385,11 @@ Middleware<AppState> _bulkEmailInvoices(InvoiceRepository repository) {
|
||||||
|
|
||||||
repository
|
repository
|
||||||
.bulkAction(
|
.bulkAction(
|
||||||
store.state.credentials, action.invoiceIds, EntityAction.sendEmail)
|
store.state.credentials,
|
||||||
|
action.invoiceIds,
|
||||||
|
EntityAction.sendEmail,
|
||||||
|
template: action.template,
|
||||||
|
)
|
||||||
.then((List<InvoiceEntity> invoices) {
|
.then((List<InvoiceEntity> invoices) {
|
||||||
store.dispatch(BulkEmailInvoicesSuccess(invoices));
|
store.dispatch(BulkEmailInvoicesSuccess(invoices));
|
||||||
if (action.completer != null) {
|
if (action.completer != null) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue