Purchase orders
This commit is contained in:
parent
4992223ba8
commit
1f255fbb9f
|
|
@ -116,6 +116,7 @@ class EntityAction extends EnumClass {
|
||||||
static const EntityAction addToInvoice = _$addToInvoice;
|
static const EntityAction addToInvoice = _$addToInvoice;
|
||||||
static const EntityAction cancel = _$cancel;
|
static const EntityAction cancel = _$cancel;
|
||||||
static const EntityAction save = _$save;
|
static const EntityAction save = _$save;
|
||||||
|
static const EntityAction accept = _$accept;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
|
|
|
||||||
|
|
@ -86,6 +86,7 @@ const EntityAction _$changeStatus = const EntityAction._('changeStatus');
|
||||||
const EntityAction _$addToInvoice = const EntityAction._('addToInvoice');
|
const EntityAction _$addToInvoice = const EntityAction._('addToInvoice');
|
||||||
const EntityAction _$cancel = const EntityAction._('cancel');
|
const EntityAction _$cancel = const EntityAction._('cancel');
|
||||||
const EntityAction _$save = const EntityAction._('save');
|
const EntityAction _$save = const EntityAction._('save');
|
||||||
|
const EntityAction _$accept = const EntityAction._('accept');
|
||||||
|
|
||||||
EntityAction _$valueOf(String name) {
|
EntityAction _$valueOf(String name) {
|
||||||
switch (name) {
|
switch (name) {
|
||||||
|
|
@ -227,6 +228,8 @@ EntityAction _$valueOf(String name) {
|
||||||
return _$cancel;
|
return _$cancel;
|
||||||
case 'save':
|
case 'save':
|
||||||
return _$save;
|
return _$save;
|
||||||
|
case 'accept':
|
||||||
|
return _$accept;
|
||||||
default:
|
default:
|
||||||
throw new ArgumentError(name);
|
throw new ArgumentError(name);
|
||||||
}
|
}
|
||||||
|
|
@ -303,6 +306,7 @@ final BuiltSet<EntityAction> _$values =
|
||||||
_$addToInvoice,
|
_$addToInvoice,
|
||||||
_$cancel,
|
_$cancel,
|
||||||
_$save,
|
_$save,
|
||||||
|
_$accept,
|
||||||
]);
|
]);
|
||||||
|
|
||||||
Serializer<EntityAction> _$entityActionSerializer =
|
Serializer<EntityAction> _$entityActionSerializer =
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,7 @@
|
||||||
import 'dart:convert';
|
import 'dart:convert';
|
||||||
import 'dart:core';
|
import 'dart:core';
|
||||||
import 'package:built_collection/built_collection.dart';
|
import 'package:built_collection/built_collection.dart';
|
||||||
|
import 'package:http/http.dart';
|
||||||
import 'package:invoiceninja_flutter/constants.dart';
|
import 'package:invoiceninja_flutter/constants.dart';
|
||||||
import 'package:invoiceninja_flutter/data/models/serializers.dart';
|
import 'package:invoiceninja_flutter/data/models/serializers.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
||||||
|
|
@ -25,8 +26,20 @@ class PurchaseOrderRepository {
|
||||||
return purchaseOrderResponse.data;
|
return purchaseOrderResponse.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<BuiltList<InvoiceEntity>> loadList(Credentials credentials) async {
|
Future<BuiltList<InvoiceEntity>> loadList(
|
||||||
final String url = credentials.url + '/purchase_orders?';
|
Credentials credentials,
|
||||||
|
int page,
|
||||||
|
int createdAt,
|
||||||
|
bool filterDeleted,
|
||||||
|
int recordsPerPage,
|
||||||
|
) async {
|
||||||
|
String url = credentials.url +
|
||||||
|
'/purchase_orders?per_page=$recordsPerPage&page=$page&created_at=$createdAt';
|
||||||
|
|
||||||
|
if (filterDeleted) {
|
||||||
|
url += '&filter_deleted_clients=true';
|
||||||
|
}
|
||||||
|
|
||||||
final dynamic response = await webClient.get(url, credentials.token);
|
final dynamic response = await webClient.get(url, credentials.token);
|
||||||
|
|
||||||
final InvoiceListResponse purchaseOrderResponse =
|
final InvoiceListResponse purchaseOrderResponse =
|
||||||
|
|
@ -52,17 +65,32 @@ class PurchaseOrderRepository {
|
||||||
}
|
}
|
||||||
|
|
||||||
Future<InvoiceEntity> saveData(
|
Future<InvoiceEntity> saveData(
|
||||||
Credentials credentials, InvoiceEntity purchaseOrder) async {
|
Credentials credentials,
|
||||||
|
InvoiceEntity purchaseOrder,
|
||||||
|
EntityAction action,
|
||||||
|
) async {
|
||||||
|
purchaseOrder = purchaseOrder.rebuild((b) => b..documents.clear());
|
||||||
final data =
|
final data =
|
||||||
serializers.serializeWith(InvoiceEntity.serializer, purchaseOrder);
|
serializers.serializeWith(InvoiceEntity.serializer, purchaseOrder);
|
||||||
|
String url;
|
||||||
dynamic response;
|
dynamic response;
|
||||||
|
|
||||||
if (purchaseOrder.isNew) {
|
if (purchaseOrder.isNew) {
|
||||||
response = await webClient.post(
|
url = credentials.url + '/purchase_orders';
|
||||||
credentials.url + '/purchase_orders', credentials.token,
|
} else {
|
||||||
data: json.encode(data));
|
url = '${credentials.url}/purchase_orders/${purchaseOrder.id}';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (action == EntityAction.markSent) {
|
||||||
|
url += '&mark_sent=true';
|
||||||
|
} else if (action == EntityAction.accept) {
|
||||||
|
url += '&accept=true';
|
||||||
|
}
|
||||||
|
|
||||||
|
if (purchaseOrder.isNew) {
|
||||||
|
response =
|
||||||
|
await webClient.post(url, credentials.token, data: json.encode(data));
|
||||||
} else {
|
} else {
|
||||||
final url = '${credentials.url}/purchase_orders/${purchaseOrder.id}';
|
|
||||||
response =
|
response =
|
||||||
await webClient.put(url, credentials.token, data: json.encode(data));
|
await webClient.put(url, credentials.token, data: json.encode(data));
|
||||||
}
|
}
|
||||||
|
|
@ -72,4 +100,46 @@ class PurchaseOrderRepository {
|
||||||
|
|
||||||
return purchaseOrderResponse.data;
|
return purchaseOrderResponse.data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Future<InvoiceEntity> emailPurchaseOrder(
|
||||||
|
Credentials credentials,
|
||||||
|
InvoiceEntity purchaseOrder,
|
||||||
|
EmailTemplate template,
|
||||||
|
String subject,
|
||||||
|
String body) async {
|
||||||
|
final data = {
|
||||||
|
'entity': '${purchaseOrder.entityType}',
|
||||||
|
'entity_id': purchaseOrder.id,
|
||||||
|
'template': 'email_template_$template',
|
||||||
|
'body': body,
|
||||||
|
'subject': subject,
|
||||||
|
};
|
||||||
|
|
||||||
|
final dynamic response = await webClient.post(
|
||||||
|
credentials.url + '/emails', credentials.token,
|
||||||
|
data: json.encode(data));
|
||||||
|
|
||||||
|
final InvoiceItemResponse invoiceResponse =
|
||||||
|
serializers.deserializeWith(InvoiceItemResponse.serializer, response);
|
||||||
|
|
||||||
|
return invoiceResponse.data;
|
||||||
|
}
|
||||||
|
|
||||||
|
Future<InvoiceEntity> uploadDocument(Credentials credentials,
|
||||||
|
BaseEntity entity, MultipartFile multipartFile) async {
|
||||||
|
final fields = <String, String>{
|
||||||
|
'_method': 'put',
|
||||||
|
};
|
||||||
|
|
||||||
|
final dynamic response = await webClient.post(
|
||||||
|
'${credentials.url}/purchase_orders/${entity.id}/upload',
|
||||||
|
credentials.token,
|
||||||
|
data: fields,
|
||||||
|
multipartFiles: [multipartFile]);
|
||||||
|
|
||||||
|
final InvoiceItemResponse invoiceResponse =
|
||||||
|
serializers.deserializeWith(InvoiceItemResponse.serializer, response);
|
||||||
|
|
||||||
|
return invoiceResponse.data;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -2,6 +2,7 @@ import 'dart:async';
|
||||||
import 'package:built_collection/built_collection.dart';
|
import 'package:built_collection/built_collection.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter_redux/flutter_redux.dart';
|
import 'package:flutter_redux/flutter_redux.dart';
|
||||||
|
import 'package:http/http.dart';
|
||||||
import 'package:invoiceninja_flutter/data/models/models.dart';
|
import 'package:invoiceninja_flutter/data/models/models.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
|
import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
||||||
|
|
@ -92,9 +93,10 @@ class LoadPurchaseOrderActivity {
|
||||||
}
|
}
|
||||||
|
|
||||||
class LoadPurchaseOrders {
|
class LoadPurchaseOrders {
|
||||||
LoadPurchaseOrders({this.completer});
|
LoadPurchaseOrders({this.completer, this.page = 1});
|
||||||
|
|
||||||
final Completer completer;
|
final Completer completer;
|
||||||
|
final int page;
|
||||||
}
|
}
|
||||||
|
|
||||||
class LoadPurchaseOrderRequest implements StartLoading {}
|
class LoadPurchaseOrderRequest implements StartLoading {}
|
||||||
|
|
@ -145,6 +147,31 @@ class LoadPurchaseOrdersSuccess implements StopLoading {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class SavePurchaseOrderDocumentRequest implements StartSaving {
|
||||||
|
SavePurchaseOrderDocumentRequest({
|
||||||
|
@required this.completer,
|
||||||
|
@required this.multipartFile,
|
||||||
|
@required this.purchaseOrder,
|
||||||
|
});
|
||||||
|
|
||||||
|
final Completer completer;
|
||||||
|
final MultipartFile multipartFile;
|
||||||
|
final InvoiceEntity purchaseOrder;
|
||||||
|
}
|
||||||
|
|
||||||
|
class SavePurchaseOrderDocumentSuccess
|
||||||
|
implements StopSaving, PersistData, PersistUI {
|
||||||
|
SavePurchaseOrderDocumentSuccess(this.document);
|
||||||
|
|
||||||
|
final DocumentEntity document;
|
||||||
|
}
|
||||||
|
|
||||||
|
class SavePurchaseOrderDocumentFailure implements StopSaving {
|
||||||
|
SavePurchaseOrderDocumentFailure(this.error);
|
||||||
|
|
||||||
|
final Object error;
|
||||||
|
}
|
||||||
|
|
||||||
class SavePurchaseOrderRequest implements StartSaving {
|
class SavePurchaseOrderRequest implements StartSaving {
|
||||||
SavePurchaseOrderRequest({
|
SavePurchaseOrderRequest({
|
||||||
this.completer,
|
this.completer,
|
||||||
|
|
|
||||||
|
|
@ -1,16 +1,23 @@
|
||||||
|
// Flutter imports:
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:flutter/widgets.dart';
|
import 'package:invoiceninja_flutter/data/repositories/purchase_order_repository.dart';
|
||||||
|
import 'package:invoiceninja_flutter/redux/purchase_order/purchase_order_actions.dart';
|
||||||
|
import 'package:invoiceninja_flutter/ui/purchase_order/edit/purchase_order_edit_vm.dart';
|
||||||
|
import 'package:invoiceninja_flutter/ui/purchase_order/purchase_order_email_vm.dart';
|
||||||
|
import 'package:invoiceninja_flutter/ui/purchase_order/purchase_order_pdf_vm.dart';
|
||||||
|
import 'package:invoiceninja_flutter/ui/purchase_order/purchase_order_screen.dart';
|
||||||
|
import 'package:invoiceninja_flutter/ui/purchase_order/view/purchase_order_view_vm.dart';
|
||||||
|
|
||||||
|
// Package imports:
|
||||||
import 'package:redux/redux.dart';
|
import 'package:redux/redux.dart';
|
||||||
|
|
||||||
|
// Project imports:
|
||||||
|
import 'package:invoiceninja_flutter/data/models/models.dart';
|
||||||
import 'package:invoiceninja_flutter/main_app.dart';
|
import 'package:invoiceninja_flutter/main_app.dart';
|
||||||
import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
|
import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
|
||||||
import 'package:invoiceninja_flutter/data/models/models.dart';
|
|
||||||
import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart';
|
|
||||||
import 'package:invoiceninja_flutter/ui/purchase_order/purchase_order_screen.dart';
|
|
||||||
import 'package:invoiceninja_flutter/ui/purchase_order/edit/purchase_order_edit_vm.dart';
|
|
||||||
import 'package:invoiceninja_flutter/ui/purchase_order/view/purchase_order_view_vm.dart';
|
|
||||||
import 'package:invoiceninja_flutter/redux/purchase_order/purchase_order_actions.dart';
|
|
||||||
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
|
||||||
import 'package:invoiceninja_flutter/data/repositories/purchase_order_repository.dart';
|
import 'package:invoiceninja_flutter/redux/credit/credit_actions.dart';
|
||||||
|
import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart';
|
||||||
|
|
||||||
List<Middleware<AppState>> createStorePurchaseOrdersMiddleware([
|
List<Middleware<AppState>> createStorePurchaseOrdersMiddleware([
|
||||||
PurchaseOrderRepository repository = const PurchaseOrderRepository(),
|
PurchaseOrderRepository repository = const PurchaseOrderRepository(),
|
||||||
|
|
@ -18,17 +25,28 @@ List<Middleware<AppState>> createStorePurchaseOrdersMiddleware([
|
||||||
final viewPurchaseOrderList = _viewPurchaseOrderList();
|
final viewPurchaseOrderList = _viewPurchaseOrderList();
|
||||||
final viewPurchaseOrder = _viewPurchaseOrder();
|
final viewPurchaseOrder = _viewPurchaseOrder();
|
||||||
final editPurchaseOrder = _editPurchaseOrder();
|
final editPurchaseOrder = _editPurchaseOrder();
|
||||||
|
final showEmailPurchaseOrder = _showEmailPurchaseOrder();
|
||||||
|
final showPdfPurchaseOrder = _showPdfPurchaseOrder();
|
||||||
|
final approvePurchaseOrder = _approvePurchaseOrder(repository);
|
||||||
final loadPurchaseOrders = _loadPurchaseOrders(repository);
|
final loadPurchaseOrders = _loadPurchaseOrders(repository);
|
||||||
final loadPurchaseOrder = _loadPurchaseOrder(repository);
|
final loadPurchaseOrder = _loadPurchaseOrder(repository);
|
||||||
final savePurchaseOrder = _savePurchaseOrder(repository);
|
final savePurchaseOrder = _savePurchaseOrder(repository);
|
||||||
final archivePurchaseOrder = _archivePurchaseOrder(repository);
|
final archivePurchaseOrder = _archivePurchaseOrder(repository);
|
||||||
final deletePurchaseOrder = _deletePurchaseOrder(repository);
|
final deletePurchaseOrder = _deletePurchaseOrder(repository);
|
||||||
final restorePurchaseOrder = _restorePurchaseOrder(repository);
|
final restorePurchaseOrder = _restorePurchaseOrder(repository);
|
||||||
|
final emailPurchaseOrder = _emailPurchaseOrder(repository);
|
||||||
|
final bulkEmailPurchaseOrders = _bulkEmailPurchaseOrders(repository);
|
||||||
|
final markSentPurchaseOrder = _markSentPurchaseOrder(repository);
|
||||||
|
final downloadPurchaseOrders = _downloadPurchaseOrders(repository);
|
||||||
|
final saveDocument = _saveDocument(repository);
|
||||||
|
|
||||||
return [
|
return [
|
||||||
TypedMiddleware<AppState, ViewPurchaseOrderList>(viewPurchaseOrderList),
|
TypedMiddleware<AppState, ViewPurchaseOrderList>(viewPurchaseOrderList),
|
||||||
TypedMiddleware<AppState, ViewPurchaseOrder>(viewPurchaseOrder),
|
TypedMiddleware<AppState, ViewPurchaseOrder>(viewPurchaseOrder),
|
||||||
TypedMiddleware<AppState, EditPurchaseOrder>(editPurchaseOrder),
|
TypedMiddleware<AppState, EditPurchaseOrder>(editPurchaseOrder),
|
||||||
|
TypedMiddleware<AppState, ApprovePurchaseOrders>(approvePurchaseOrder),
|
||||||
|
TypedMiddleware<AppState, ShowEmailPurchaseOrder>(showEmailPurchaseOrder),
|
||||||
|
TypedMiddleware<AppState, ShowPdfPurchaseOrder>(showPdfPurchaseOrder),
|
||||||
TypedMiddleware<AppState, LoadPurchaseOrders>(loadPurchaseOrders),
|
TypedMiddleware<AppState, LoadPurchaseOrders>(loadPurchaseOrders),
|
||||||
TypedMiddleware<AppState, LoadPurchaseOrder>(loadPurchaseOrder),
|
TypedMiddleware<AppState, LoadPurchaseOrder>(loadPurchaseOrder),
|
||||||
TypedMiddleware<AppState, SavePurchaseOrderRequest>(savePurchaseOrder),
|
TypedMiddleware<AppState, SavePurchaseOrderRequest>(savePurchaseOrder),
|
||||||
|
|
@ -37,9 +55,51 @@ List<Middleware<AppState>> createStorePurchaseOrdersMiddleware([
|
||||||
TypedMiddleware<AppState, DeletePurchaseOrdersRequest>(deletePurchaseOrder),
|
TypedMiddleware<AppState, DeletePurchaseOrdersRequest>(deletePurchaseOrder),
|
||||||
TypedMiddleware<AppState, RestorePurchaseOrdersRequest>(
|
TypedMiddleware<AppState, RestorePurchaseOrdersRequest>(
|
||||||
restorePurchaseOrder),
|
restorePurchaseOrder),
|
||||||
|
TypedMiddleware<AppState, EmailPurchaseOrderRequest>(emailPurchaseOrder),
|
||||||
|
TypedMiddleware<AppState, BulkEmailPurchaseOrdersRequest>(
|
||||||
|
bulkEmailPurchaseOrders),
|
||||||
|
TypedMiddleware<AppState, MarkPurchaseOrdersSentRequest>(
|
||||||
|
markSentPurchaseOrder),
|
||||||
|
TypedMiddleware<AppState, DownloadPurchaseOrdersRequest>(
|
||||||
|
downloadPurchaseOrders),
|
||||||
|
TypedMiddleware<AppState, SavePurchaseOrderDocumentRequest>(saveDocument),
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Middleware<AppState> _viewPurchaseOrder() {
|
||||||
|
return (Store<AppState> store, dynamic dynamicAction,
|
||||||
|
NextDispatcher next) async {
|
||||||
|
final action = dynamicAction as ViewPurchaseOrder;
|
||||||
|
|
||||||
|
next(action);
|
||||||
|
|
||||||
|
store.dispatch(UpdateCurrentRoute(PurchaseOrderViewScreen.route));
|
||||||
|
|
||||||
|
if (store.state.prefState.isMobile) {
|
||||||
|
await navigatorKey.currentState.pushNamed(PurchaseOrderViewScreen.route);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Middleware<AppState> _viewPurchaseOrderList() {
|
||||||
|
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||||
|
final action = dynamicAction as ViewPurchaseOrderList;
|
||||||
|
|
||||||
|
next(action);
|
||||||
|
|
||||||
|
if (store.state.isStale) {
|
||||||
|
store.dispatch(RefreshData());
|
||||||
|
}
|
||||||
|
|
||||||
|
store.dispatch(UpdateCurrentRoute(PurchaseOrderScreen.route));
|
||||||
|
|
||||||
|
if (store.state.prefState.isMobile) {
|
||||||
|
navigatorKey.currentState.pushNamedAndRemoveUntil(
|
||||||
|
PurchaseOrderScreen.route, (Route<dynamic> route) => false);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
Middleware<AppState> _editPurchaseOrder() {
|
Middleware<AppState> _editPurchaseOrder() {
|
||||||
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||||
final action = dynamicAction as EditPurchaseOrder;
|
final action = dynamicAction as EditPurchaseOrder;
|
||||||
|
|
@ -54,36 +114,37 @@ Middleware<AppState> _editPurchaseOrder() {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Middleware<AppState> _viewPurchaseOrder() {
|
Middleware<AppState> _showEmailPurchaseOrder() {
|
||||||
return (Store<AppState> store, dynamic dynamicAction,
|
return (Store<AppState> store, dynamic dynamicAction,
|
||||||
NextDispatcher next) async {
|
NextDispatcher next) async {
|
||||||
final action = dynamicAction as ViewPurchaseOrder;
|
final action = dynamicAction as ShowEmailPurchaseOrder;
|
||||||
|
|
||||||
next(action);
|
next(action);
|
||||||
|
|
||||||
store.dispatch(UpdateCurrentRoute(PurchaseOrderViewScreen.route));
|
store.dispatch(UpdateCurrentRoute(PurchaseOrderEmailScreen.route));
|
||||||
|
|
||||||
if (store.state.prefState.isMobile) {
|
if (store.state.prefState.isMobile) {
|
||||||
navigatorKey.currentState.pushNamed(PurchaseOrderViewScreen.route);
|
final emailWasSent = await navigatorKey.currentState
|
||||||
|
.pushNamed(PurchaseOrderEmailScreen.route);
|
||||||
|
|
||||||
|
if (action.completer != null && emailWasSent != null && emailWasSent) {
|
||||||
|
action.completer.complete(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Middleware<AppState> _viewPurchaseOrderList() {
|
Middleware<AppState> _showPdfPurchaseOrder() {
|
||||||
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
return (Store<AppState> store, dynamic dynamicAction,
|
||||||
final action = dynamicAction as ViewPurchaseOrderList;
|
NextDispatcher next) async {
|
||||||
|
final action = dynamicAction as ShowPdfPurchaseOrder;
|
||||||
|
|
||||||
next(action);
|
next(action);
|
||||||
|
|
||||||
if (store.state.staticState.isStale) {
|
store.dispatch(UpdateCurrentRoute(PurchaseOrderPdfScreen.route));
|
||||||
store.dispatch(RefreshData());
|
|
||||||
}
|
|
||||||
|
|
||||||
store.dispatch(UpdateCurrentRoute(PurchaseOrderScreen.route));
|
|
||||||
|
|
||||||
if (store.state.prefState.isMobile) {
|
if (store.state.prefState.isMobile) {
|
||||||
navigatorKey.currentState.pushNamedAndRemoveUntil(
|
navigatorKey.currentState.pushNamed(PurchaseOrderPdfScreen.route);
|
||||||
PurchaseOrderScreen.route, (Route<dynamic> route) => false);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
@ -120,6 +181,7 @@ Middleware<AppState> _deletePurchaseOrder(PurchaseOrderRepository repository) {
|
||||||
final prevPurchaseOrders = action.purchaseOrderIds
|
final prevPurchaseOrders = action.purchaseOrderIds
|
||||||
.map((id) => store.state.purchaseOrderState.map[id])
|
.map((id) => store.state.purchaseOrderState.map[id])
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
repository
|
repository
|
||||||
.bulkAction(store.state.credentials, action.purchaseOrderIds,
|
.bulkAction(store.state.credentials, action.purchaseOrderIds,
|
||||||
EntityAction.delete)
|
EntityAction.delete)
|
||||||
|
|
@ -146,6 +208,7 @@ Middleware<AppState> _restorePurchaseOrder(PurchaseOrderRepository repository) {
|
||||||
final prevPurchaseOrders = action.purchaseOrderIds
|
final prevPurchaseOrders = action.purchaseOrderIds
|
||||||
.map((id) => store.state.purchaseOrderState.map[id])
|
.map((id) => store.state.purchaseOrderState.map[id])
|
||||||
.toList();
|
.toList();
|
||||||
|
|
||||||
repository
|
repository
|
||||||
.bulkAction(store.state.credentials, action.purchaseOrderIds,
|
.bulkAction(store.state.credentials, action.purchaseOrderIds,
|
||||||
EntityAction.restore)
|
EntityAction.restore)
|
||||||
|
|
@ -166,18 +229,96 @@ Middleware<AppState> _restorePurchaseOrder(PurchaseOrderRepository repository) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Middleware<AppState> _approvePurchaseOrder(PurchaseOrderRepository repository) {
|
||||||
|
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||||
|
final action = dynamicAction as ApprovePurchaseOrders;
|
||||||
|
repository
|
||||||
|
.bulkAction(store.state.credentials, action.purchaseOrderIds,
|
||||||
|
EntityAction.approve)
|
||||||
|
.then((purchaseOrders) {
|
||||||
|
store.dispatch(
|
||||||
|
ApprovePurchaseOrderSuccess(purchaseOrders: purchaseOrders));
|
||||||
|
store.dispatch(RefreshData());
|
||||||
|
action.completer.complete(null);
|
||||||
|
}).catchError((Object error) {
|
||||||
|
print(error);
|
||||||
|
store.dispatch(ApprovePurchaseOrderFailure(error));
|
||||||
|
action.completer.completeError(error);
|
||||||
|
});
|
||||||
|
|
||||||
|
next(action);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Middleware<AppState> _markSentPurchaseOrder(
|
||||||
|
PurchaseOrderRepository repository) {
|
||||||
|
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||||
|
final action = dynamicAction as MarkPurchaseOrdersSentRequest;
|
||||||
|
repository
|
||||||
|
.bulkAction(store.state.credentials, action.purchaseOrderIds,
|
||||||
|
EntityAction.markSent)
|
||||||
|
.then((purchaseOrders) {
|
||||||
|
store.dispatch(MarkPurchaseOrderSentSuccess(purchaseOrders));
|
||||||
|
if (action.completer != null) {
|
||||||
|
action.completer.complete(null);
|
||||||
|
}
|
||||||
|
}).catchError((Object error) {
|
||||||
|
print(error);
|
||||||
|
store.dispatch(MarkPurchaseOrderSentFailure(error));
|
||||||
|
if (action.completer != null) {
|
||||||
|
action.completer.completeError(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
next(action);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Middleware<AppState> _emailPurchaseOrder(PurchaseOrderRepository repository) {
|
||||||
|
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||||
|
final action = dynamicAction as EmailPurchaseOrderRequest;
|
||||||
|
final origPurchaseOrder =
|
||||||
|
store.state.purchaseOrderState.map[action.purchaseOrderId];
|
||||||
|
repository
|
||||||
|
.emailPurchaseOrder(store.state.credentials, origPurchaseOrder,
|
||||||
|
action.template, action.subject, action.body)
|
||||||
|
.then((purchaseOrder) {
|
||||||
|
store.dispatch(EmailPurchaseOrderSuccess(purchaseOrder));
|
||||||
|
if (action.completer != null) {
|
||||||
|
action.completer.complete(null);
|
||||||
|
}
|
||||||
|
}).catchError((Object error) {
|
||||||
|
print(error);
|
||||||
|
store.dispatch(EmailPurchaseOrderFailure(error));
|
||||||
|
if (action.completer != null) {
|
||||||
|
action.completer.completeError(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
next(action);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
Middleware<AppState> _savePurchaseOrder(PurchaseOrderRepository repository) {
|
Middleware<AppState> _savePurchaseOrder(PurchaseOrderRepository repository) {
|
||||||
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||||
final action = dynamicAction as SavePurchaseOrderRequest;
|
final action = dynamicAction as SavePurchaseOrderRequest;
|
||||||
|
|
||||||
|
// remove any empty line items
|
||||||
|
final updatedPurchaseOrder = action.purchaseOrder.rebuild((b) => b
|
||||||
|
..lineItems.replace(
|
||||||
|
action.purchaseOrder.lineItems.where((item) => !item.isEmpty)));
|
||||||
|
|
||||||
repository
|
repository
|
||||||
.saveData(store.state.credentials, action.purchaseOrder)
|
.saveData(store.state.credentials, updatedPurchaseOrder, action.action)
|
||||||
.then((InvoiceEntity purchaseOrder) {
|
.then((InvoiceEntity purchaseOrder) {
|
||||||
if (action.purchaseOrder.isNew) {
|
if (action.purchaseOrder.isNew) {
|
||||||
store.dispatch(AddPurchaseOrderSuccess(purchaseOrder));
|
store.dispatch(AddPurchaseOrderSuccess(purchaseOrder));
|
||||||
} else {
|
} else {
|
||||||
store.dispatch(SavePurchaseOrderSuccess(purchaseOrder));
|
store.dispatch(SavePurchaseOrderSuccess(purchaseOrder));
|
||||||
}
|
}
|
||||||
|
if (action.action == EntityAction.convertToInvoice) {
|
||||||
|
store.dispatch(RefreshData());
|
||||||
|
}
|
||||||
action.completer.complete(purchaseOrder);
|
action.completer.complete(purchaseOrder);
|
||||||
}).catchError((Object error) {
|
}).catchError((Object error) {
|
||||||
print(error);
|
print(error);
|
||||||
|
|
@ -192,11 +333,10 @@ Middleware<AppState> _savePurchaseOrder(PurchaseOrderRepository repository) {
|
||||||
Middleware<AppState> _loadPurchaseOrder(PurchaseOrderRepository repository) {
|
Middleware<AppState> _loadPurchaseOrder(PurchaseOrderRepository repository) {
|
||||||
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||||
final action = dynamicAction as LoadPurchaseOrder;
|
final action = dynamicAction as LoadPurchaseOrder;
|
||||||
final AppState state = store.state;
|
|
||||||
|
|
||||||
store.dispatch(LoadPurchaseOrderRequest());
|
store.dispatch(LoadPurchaseOrderRequest());
|
||||||
repository
|
repository
|
||||||
.loadItem(state.credentials, action.purchaseOrderId)
|
.loadItem(store.state.credentials, action.purchaseOrderId)
|
||||||
.then((purchaseOrder) {
|
.then((purchaseOrder) {
|
||||||
store.dispatch(LoadPurchaseOrderSuccess(purchaseOrder));
|
store.dispatch(LoadPurchaseOrderSuccess(purchaseOrder));
|
||||||
|
|
||||||
|
|
@ -215,23 +355,82 @@ Middleware<AppState> _loadPurchaseOrder(PurchaseOrderRepository repository) {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
Middleware<AppState> _loadPurchaseOrders(PurchaseOrderRepository repository) {
|
Middleware<AppState> _downloadPurchaseOrders(
|
||||||
|
PurchaseOrderRepository repository) {
|
||||||
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||||
final action = dynamicAction as LoadPurchaseOrders;
|
final action = dynamicAction as DownloadPurchaseOrdersRequest;
|
||||||
final AppState state = store.state;
|
repository
|
||||||
|
.bulkAction(store.state.credentials, action.invoiceIds,
|
||||||
store.dispatch(LoadPurchaseOrdersRequest());
|
EntityAction.bulkDownload)
|
||||||
repository.loadList(state.credentials).then((data) {
|
.then((invoices) {
|
||||||
store.dispatch(LoadPurchaseOrdersSuccess(data));
|
store.dispatch(DownloadPurchaseOrdersSuccess());
|
||||||
|
|
||||||
if (action.completer != null) {
|
if (action.completer != null) {
|
||||||
action.completer.complete(null);
|
action.completer.complete(null);
|
||||||
}
|
}
|
||||||
/*
|
}).catchError((Object error) {
|
||||||
if (state.productState.isStale) {
|
print(error);
|
||||||
store.dispatch(LoadProducts());
|
store.dispatch(DownloadPurchaseOrdersFailure(error));
|
||||||
|
if (action.completer != null) {
|
||||||
|
action.completer.completeError(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
next(action);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Middleware<AppState> _bulkEmailPurchaseOrders(
|
||||||
|
PurchaseOrderRepository repository) {
|
||||||
|
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||||
|
final action = dynamicAction as BulkEmailPurchaseOrdersRequest;
|
||||||
|
|
||||||
|
repository
|
||||||
|
.bulkAction(store.state.credentials, action.purchaseOrderIds,
|
||||||
|
EntityAction.emailPurchaseOrder)
|
||||||
|
.then((List<InvoiceEntity> purchaseOrders) {
|
||||||
|
store.dispatch(BulkEmailPurchaseOrdersSuccess(purchaseOrders));
|
||||||
|
if (action.completer != null) {
|
||||||
|
action.completer.complete(null);
|
||||||
|
}
|
||||||
|
}).catchError((Object error) {
|
||||||
|
print(error);
|
||||||
|
store.dispatch(BulkEmailPurchaseOrdersFailure(error));
|
||||||
|
if (action.completer != null) {
|
||||||
|
action.completer.completeError(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
next(action);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
Middleware<AppState> _loadPurchaseOrders(PurchaseOrderRepository repository) {
|
||||||
|
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||||
|
final action = dynamicAction as LoadPurchaseOrders;
|
||||||
|
final state = store.state;
|
||||||
|
|
||||||
|
store.dispatch(LoadPurchaseOrdersRequest());
|
||||||
|
repository
|
||||||
|
.loadList(
|
||||||
|
state.credentials,
|
||||||
|
action.page,
|
||||||
|
state.createdAtLimit,
|
||||||
|
state.filterDeletedClients,
|
||||||
|
state.recordsPerPage,
|
||||||
|
)
|
||||||
|
.then((data) {
|
||||||
|
store.dispatch(LoadPurchaseOrdersSuccess(data));
|
||||||
|
if (data.length == state.recordsPerPage) {
|
||||||
|
store.dispatch(LoadPurchaseOrders(
|
||||||
|
completer: action.completer,
|
||||||
|
page: action.page + 1,
|
||||||
|
));
|
||||||
|
} else {
|
||||||
|
if (action.completer != null) {
|
||||||
|
action.completer.complete(null);
|
||||||
|
}
|
||||||
|
store.dispatch(LoadCredits());
|
||||||
}
|
}
|
||||||
*/
|
|
||||||
}).catchError((Object error) {
|
}).catchError((Object error) {
|
||||||
print(error);
|
print(error);
|
||||||
store.dispatch(LoadPurchaseOrdersFailure(error));
|
store.dispatch(LoadPurchaseOrdersFailure(error));
|
||||||
|
|
@ -243,3 +442,28 @@ Middleware<AppState> _loadPurchaseOrders(PurchaseOrderRepository repository) {
|
||||||
next(action);
|
next(action);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Middleware<AppState> _saveDocument(PurchaseOrderRepository repository) {
|
||||||
|
return (Store<AppState> store, dynamic dynamicAction, NextDispatcher next) {
|
||||||
|
final action = dynamicAction as SavePurchaseOrderDocumentRequest;
|
||||||
|
if (store.state.isEnterprisePlan) {
|
||||||
|
repository
|
||||||
|
.uploadDocument(store.state.credentials, action.purchaseOrder,
|
||||||
|
action.multipartFile)
|
||||||
|
.then((purchaseOrder) {
|
||||||
|
store.dispatch(SavePurchaseOrderSuccess(purchaseOrder));
|
||||||
|
action.completer.complete(null);
|
||||||
|
}).catchError((Object error) {
|
||||||
|
print(error);
|
||||||
|
store.dispatch(SavePurchaseOrderDocumentFailure(error));
|
||||||
|
action.completer.completeError(error);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
const error = 'Uploading documents requires an enterprise plan';
|
||||||
|
store.dispatch(SavePurchaseOrderDocumentFailure(error));
|
||||||
|
action.completer.completeError(error);
|
||||||
|
}
|
||||||
|
|
||||||
|
next(action);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue