diff --git a/lib/data/models/invoice_model.dart b/lib/data/models/invoice_model.dart index fb174699c..05c89bbb0 100644 --- a/lib/data/models/invoice_model.dart +++ b/lib/data/models/invoice_model.dart @@ -901,6 +901,9 @@ abstract class InvoiceEntity extends Object if (isQuote) { if ((invoiceId ?? '').isEmpty) { + if (!isApproved) { + actions.add(EntityAction.approve); + } actions.add(EntityAction.convertToInvoice); } else { actions.add(EntityAction.viewInvoice); diff --git a/lib/data/models/models.dart b/lib/data/models/models.dart index de011caa1..e64d5a64c 100644 --- a/lib/data/models/models.dart +++ b/lib/data/models/models.dart @@ -122,6 +122,10 @@ class EntityAction extends EnumClass { return 'email'; } + // else if (value == 'approve') { + // return 'approved'; + // } + return value; } diff --git a/lib/redux/quote/quote_actions.dart b/lib/redux/quote/quote_actions.dart index 540476e9f..fca1d6e32 100644 --- a/lib/redux/quote/quote_actions.dart +++ b/lib/redux/quote/quote_actions.dart @@ -428,6 +428,25 @@ class ConvertQuoteFailure implements StopSaving { final dynamic error; } +class ApproveQuotes implements StartSaving { + ApproveQuotes(this.completer, this.quoteIds); + + final List quoteIds; + final Completer completer; +} + +class ApproveQuoteSuccess implements StopSaving { + ApproveQuoteSuccess({this.quotes}); + + final List quotes; +} + +class ApproveQuoteFailure implements StopSaving { + ApproveQuoteFailure(this.error); + + final dynamic error; +} + class SaveQuoteDocumentRequest implements StartSaving { SaveQuoteDocumentRequest({ @required this.completer, @@ -478,6 +497,15 @@ Future handleQuoteAction( snackBarCompleter(context, localization.convertedQuote), quoteIds)); break; + case EntityAction.approve: + store.dispatch(ApproveQuotes( + snackBarCompleter( + context, + quotes.length == 1 + ? localization.approvedQuote + : localization.approvedQuotes), + quoteIds)); + break; case EntityAction.viewInvoice: viewEntityById(entityId: quote.invoiceId, entityType: EntityType.invoice); break; diff --git a/lib/redux/quote/quote_middleware.dart b/lib/redux/quote/quote_middleware.dart index d2f6ab86e..07d31a687 100644 --- a/lib/redux/quote/quote_middleware.dart +++ b/lib/redux/quote/quote_middleware.dart @@ -28,6 +28,7 @@ List> createStoreQuotesMiddleware([ final showEmailQuote = _showEmailQuote(); final showPdfQuote = _showPdfQuote(); final convertQuote = _convertQuote(repository); + final approveQuote = _approveQuote(repository); final loadQuotes = _loadQuotes(repository); final loadQuote = _loadQuote(repository); final saveQuote = _saveQuote(repository); @@ -45,6 +46,7 @@ List> createStoreQuotesMiddleware([ TypedMiddleware(viewQuote), TypedMiddleware(editQuote), TypedMiddleware(convertQuote), + TypedMiddleware(approveQuote), TypedMiddleware(showEmailQuote), TypedMiddleware(showPdfQuote), TypedMiddleware(loadQuotes), @@ -241,6 +243,26 @@ Middleware _convertQuote(QuoteRepository repository) { }; } +Middleware _approveQuote(QuoteRepository repository) { + return (Store store, dynamic dynamicAction, NextDispatcher next) { + final action = dynamicAction as ApproveQuotes; + repository + .bulkAction( + store.state.credentials, action.quoteIds, EntityAction.approve) + .then((quotes) { + store.dispatch(ApproveQuoteSuccess(quotes: quotes)); + store.dispatch(RefreshData()); + action.completer.complete(null); + }).catchError((Object error) { + print(error); + store.dispatch(ApproveQuoteFailure(error)); + action.completer.completeError(error); + }); + + next(action); + }; +} + Middleware _markSentQuote(QuoteRepository repository) { return (Store store, dynamic dynamicAction, NextDispatcher next) { final action = dynamicAction as MarkSentQuotesRequest; diff --git a/lib/utils/i18n.dart b/lib/utils/i18n.dart index 4b410f0ab..fb859f270 100644 --- a/lib/utils/i18n.dart +++ b/lib/utils/i18n.dart @@ -16,6 +16,9 @@ mixin LocalizationsProvider on LocaleCodeAware { static final Map> _localizedValues = { 'en': { // STARTER: lang key - do not remove comment + 'approved_quote': 'Successfully apporved quote', + 'approved_quotes': 'Successfully approved quotes', + 'approve': 'Approve', 'client_website': 'Client Website', 'invalid_time': 'Invalid Time', 'client_shipping_state': 'Client Shipping State', @@ -74135,6 +74138,18 @@ mixin LocalizationsProvider on LocaleCodeAware { _localizedValues[localeCode]['client_website'] ?? _localizedValues['en']['client_website']; + String get approve => + _localizedValues[localeCode]['approve'] ?? + _localizedValues['en']['approve']; + + String get approvedQuote => + _localizedValues[localeCode]['approved_quote'] ?? + _localizedValues['en']['approved_quote']; + + String get approvedQuotes => + _localizedValues[localeCode]['approved_quotes'] ?? + _localizedValues['en']['approved_quotes']; + // STARTER: lang field - do not remove comment String lookup(String key) {