Add credit mark paid action
This commit is contained in:
parent
ed19c885b0
commit
17694e30c7
|
|
@ -878,6 +878,8 @@ abstract class InvoiceEntity extends Object
|
||||||
|
|
||||||
if (isPayable && isInvoice) {
|
if (isPayable && isInvoice) {
|
||||||
actions.add(EntityAction.markPaid);
|
actions.add(EntityAction.markPaid);
|
||||||
|
} else if (isCredit && balanceOrAmount > 0) {
|
||||||
|
//actions.add(EntityAction.markPaid);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isPayable && userCompany.canCreate(EntityType.payment)) {
|
if (isPayable && userCompany.canCreate(EntityType.payment)) {
|
||||||
|
|
|
||||||
|
|
@ -277,6 +277,25 @@ class BulkEmailCreditsFailure implements StopSaving {
|
||||||
final dynamic error;
|
final dynamic error;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class MarkCreditsPaidRequest implements StartSaving {
|
||||||
|
MarkCreditsPaidRequest(this.completer, this.invoiceIds);
|
||||||
|
|
||||||
|
final Completer completer;
|
||||||
|
final List<String> invoiceIds;
|
||||||
|
}
|
||||||
|
|
||||||
|
class MarkCreditsPaidSuccess implements StopSaving {
|
||||||
|
MarkCreditsPaidSuccess(this.invoices);
|
||||||
|
|
||||||
|
final List<InvoiceEntity> invoices;
|
||||||
|
}
|
||||||
|
|
||||||
|
class MarkCreditsPaidFailure implements StopSaving {
|
||||||
|
MarkCreditsPaidFailure(this.error);
|
||||||
|
|
||||||
|
final dynamic error;
|
||||||
|
}
|
||||||
|
|
||||||
class ArchiveCreditsRequest implements StartSaving {
|
class ArchiveCreditsRequest implements StartSaving {
|
||||||
ArchiveCreditsRequest(this.completer, this.creditIds);
|
ArchiveCreditsRequest(this.completer, this.creditIds);
|
||||||
|
|
||||||
|
|
@ -536,6 +555,15 @@ Future handleCreditAction(
|
||||||
..entityType = EntityType.recurringInvoice
|
..entityType = EntityType.recurringInvoice
|
||||||
..designId = designId));
|
..designId = designId));
|
||||||
break;
|
break;
|
||||||
|
case EntityAction.markPaid:
|
||||||
|
store.dispatch(MarkCreditsPaidRequest(
|
||||||
|
snackBarCompleter<Null>(
|
||||||
|
context,
|
||||||
|
credits.length == 1
|
||||||
|
? localization.markedCreditAsPaid
|
||||||
|
: localization.markedCreditsAsPaid),
|
||||||
|
creditIds));
|
||||||
|
break;
|
||||||
case EntityAction.applyCredit:
|
case EntityAction.applyCredit:
|
||||||
createEntity(
|
createEntity(
|
||||||
context: context,
|
context: context,
|
||||||
|
|
|
||||||
|
|
@ -35,6 +35,7 @@ List<Middleware<AppState>> createStoreCreditsMiddleware([
|
||||||
final restoreCredit = _restoreCredit(repository);
|
final restoreCredit = _restoreCredit(repository);
|
||||||
final emailCredit = _emailCredit(repository);
|
final emailCredit = _emailCredit(repository);
|
||||||
final bulkEmailCredits = _bulkEmailCredits(repository);
|
final bulkEmailCredits = _bulkEmailCredits(repository);
|
||||||
|
final markPaidCredit = _markPaidCredit(repository);
|
||||||
final markSentCredit = _markSentCredit(repository);
|
final markSentCredit = _markSentCredit(repository);
|
||||||
final downloadCredits = _downloadCredits(repository);
|
final downloadCredits = _downloadCredits(repository);
|
||||||
final saveDocument = _saveDocument(repository);
|
final saveDocument = _saveDocument(repository);
|
||||||
|
|
@ -54,6 +55,7 @@ List<Middleware<AppState>> createStoreCreditsMiddleware([
|
||||||
TypedMiddleware<AppState, EmailCreditRequest>(emailCredit),
|
TypedMiddleware<AppState, EmailCreditRequest>(emailCredit),
|
||||||
TypedMiddleware<AppState, BulkEmailCreditsRequest>(bulkEmailCredits),
|
TypedMiddleware<AppState, BulkEmailCreditsRequest>(bulkEmailCredits),
|
||||||
TypedMiddleware<AppState, MarkSentCreditRequest>(markSentCredit),
|
TypedMiddleware<AppState, MarkSentCreditRequest>(markSentCredit),
|
||||||
|
TypedMiddleware<AppState, MarkCreditsPaidRequest>(markPaidCredit),
|
||||||
TypedMiddleware<AppState, DownloadCreditsRequest>(downloadCredits),
|
TypedMiddleware<AppState, DownloadCreditsRequest>(downloadCredits),
|
||||||
TypedMiddleware<AppState, SaveCreditDocumentRequest>(saveDocument),
|
TypedMiddleware<AppState, SaveCreditDocumentRequest>(saveDocument),
|
||||||
];
|
];
|
||||||
|
|
@ -242,6 +244,30 @@ Middleware<AppState> _markSentCredit(CreditRepository repository) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Middleware<AppState> _markPaidCredit(CreditRepository repository) {
|
||||||
|
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||||
|
final action = dynamicAction as MarkCreditsPaidRequest;
|
||||||
|
repository
|
||||||
|
.bulkAction(
|
||||||
|
store.state.credentials, action.invoiceIds, EntityAction.markPaid)
|
||||||
|
.then((invoices) {
|
||||||
|
store.dispatch(MarkCreditsPaidSuccess(invoices));
|
||||||
|
store.dispatch(RefreshData());
|
||||||
|
if (action.completer != null) {
|
||||||
|
action.completer.complete(null);
|
||||||
|
}
|
||||||
|
}).catchError((Object error) {
|
||||||
|
print(error);
|
||||||
|
store.dispatch(MarkCreditsPaidFailure(error));
|
||||||
|
if (action.completer != null) {
|
||||||
|
action.completer.completeError(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
next(action);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
Middleware<AppState> _emailCredit(CreditRepository repository) {
|
Middleware<AppState> _emailCredit(CreditRepository repository) {
|
||||||
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||||
final action = dynamicAction as EmailCreditRequest;
|
final action = dynamicAction as EmailCreditRequest;
|
||||||
|
|
|
||||||
|
|
@ -16,6 +16,8 @@ mixin LocalizationsProvider on LocaleCodeAware {
|
||||||
static final Map<String, Map<String, String>> _localizedValues = {
|
static final Map<String, Map<String, String>> _localizedValues = {
|
||||||
'en': {
|
'en': {
|
||||||
// STARTER: lang key - do not remove comment
|
// STARTER: lang key - do not remove comment
|
||||||
|
'marked_credit_as_paid': 'Successfully marked credit as paid',
|
||||||
|
'marked_credits_as_paid': 'Successfully marked credits as paid',
|
||||||
'wait_for_loading': 'Data loading - please wait for it to complete',
|
'wait_for_loading': 'Data loading - please wait for it to complete',
|
||||||
'wait_for_saving': 'Data saving - please wait for it to complete',
|
'wait_for_saving': 'Data saving - please wait for it to complete',
|
||||||
'html_preview_warning':
|
'html_preview_warning':
|
||||||
|
|
@ -70935,6 +70937,15 @@ mixin LocalizationsProvider on LocaleCodeAware {
|
||||||
_localizedValues[localeCode]['wait_for_saving'] ??
|
_localizedValues[localeCode]['wait_for_saving'] ??
|
||||||
_localizedValues['en']['wait_for_saving'];
|
_localizedValues['en']['wait_for_saving'];
|
||||||
|
|
||||||
|
|
||||||
|
String get markedCreditAsPaid =>
|
||||||
|
_localizedValues[localeCode]['marked_credit_as_paid'] ??
|
||||||
|
_localizedValues['en']['marked_credit_as_paid'];
|
||||||
|
|
||||||
|
String get markedCreditsAsPaid =>
|
||||||
|
_localizedValues[localeCode]['marked_credits_as_paid'] ??
|
||||||
|
_localizedValues['en']['marked_credits_as_paid'];
|
||||||
|
|
||||||
// STARTER: lang field - do not remove comment
|
// STARTER: lang field - do not remove comment
|
||||||
|
|
||||||
String lookup(String key) {
|
String lookup(String key) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue