This commit is contained in:
Hillel Coren 2018-09-04 15:19:36 -07:00
parent d651e7fd66
commit 815c724b17
5 changed files with 42 additions and 21 deletions

View File

@ -24,8 +24,7 @@ class PaymentRepository {
url += '&updated_at=${updatedAt - kUpdatedAtBufferSeconds}';
}
final dynamic response =
await webClient.get(url, company.token);
final dynamic response = await webClient.get(url, company.token);
final PaymentListResponse paymentResponse =
serializers.deserializeWith(PaymentListResponse.serializer, response);
@ -33,14 +32,18 @@ class PaymentRepository {
return paymentResponse.data;
}
Future<PaymentEntity> saveData(CompanyEntity company, AuthState auth, PaymentEntity payment,
[EntityAction action]) async {
Future<PaymentEntity> saveData(
CompanyEntity company, AuthState auth, PaymentEntity payment,
{EntityAction action, bool sendEmail}) async {
final data = serializers.serializeWith(PaymentEntity.serializer, payment);
dynamic response;
if (payment.isNew) {
response = await webClient.post(
auth.url + '/payments', company.token, json.encode(data));
var url = auth.url + '/payments';
if (sendEmail) {
url += '?email_receipt=true';
}
response = await webClient.post(url, company.token, json.encode(data));
} else {
var url = auth.url + '/payments/' + payment.id.toString();
if (action != null) {

View File

@ -78,7 +78,7 @@ Middleware<AppState> _archivePayment(PaymentRepository repository) {
final origPayment = store.state.paymentState.map[action.paymentId];
repository
.saveData(store.state.selectedCompany, store.state.authState,
origPayment, EntityAction.archive)
origPayment, action: EntityAction.archive)
.then((PaymentEntity payment) {
store.dispatch(ArchivePaymentSuccess(payment));
if (action.completer != null) {
@ -101,7 +101,7 @@ Middleware<AppState> _deletePayment(PaymentRepository repository) {
final origPayment = store.state.paymentState.map[action.paymentId];
repository
.saveData(store.state.selectedCompany, store.state.authState,
origPayment, EntityAction.delete)
origPayment, action: EntityAction.delete)
.then((PaymentEntity payment) {
store.dispatch(DeletePaymentSuccess(payment));
store.dispatch(LoadInvoice(invoiceId: payment.invoiceId));
@ -125,7 +125,7 @@ Middleware<AppState> _restorePayment(PaymentRepository repository) {
final origPayment = store.state.paymentState.map[action.paymentId];
repository
.saveData(store.state.selectedCompany, store.state.authState,
origPayment, EntityAction.restore)
origPayment, action: EntityAction.restore)
.then((PaymentEntity payment) {
store.dispatch(RestorePaymentSuccess(payment));
store.dispatch(LoadInvoice(invoiceId: payment.invoiceId));
@ -146,9 +146,11 @@ Middleware<AppState> _restorePayment(PaymentRepository repository) {
Middleware<AppState> _savePayment(PaymentRepository repository) {
return (Store<AppState> store, dynamic action, NextDispatcher next) {
final PaymentEntity payment = action.payment;
final bool sendEmail = payment.isNew ? store.state.uiState.emailPayment : false;
repository
.saveData(
store.state.selectedCompany, store.state.authState, action.payment)
store.state.selectedCompany, store.state.authState, action.payment, sendEmail: sendEmail)
.then((PaymentEntity payment) {
if (action.payment.isNew) {
store.dispatch(AddPaymentSuccess(payment));

View File

@ -238,17 +238,15 @@ class _PaymentEditState extends State<PaymentEdit> {
),
],
),
FormCard(children: <Widget>[
payment.isNew ? FormCard(children: <Widget>[
SwitchListTile(
activeColor: Theme.of(context).accentColor,
title: Text(localization.sendEmail),
value: true,
value: viewModel.uiState.emailPayment,
subtitle: Text(localization.sendReceiptToClient),
//value: client.showTasksInPortal,
//onChanged: (value) => viewModel
//.onChanged(client.rebuild((b) => b..showTasksInPortal = value)),
onChanged: (value) => viewModel.onEmailChanged(value),
),
]),
]) : Container(),
],
),
),

View File

@ -4,10 +4,13 @@ import 'package:built_collection/built_collection.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:invoiceninja_flutter/constants.dart';
import 'package:invoiceninja_flutter/data/models/client_model.dart';
import 'package:invoiceninja_flutter/data/models/invoice_model.dart';
import 'package:invoiceninja_flutter/redux/app/app_actions.dart';
import 'package:invoiceninja_flutter/redux/static/static_state.dart';
import 'package:invoiceninja_flutter/redux/ui/ui_actions.dart';
import 'package:invoiceninja_flutter/redux/ui/ui_state.dart';
import 'package:invoiceninja_flutter/ui/payment/payment_screen.dart';
import 'package:invoiceninja_flutter/ui/payment/view/payment_view_vm.dart';
import 'package:invoiceninja_flutter/utils/completers.dart';
@ -16,6 +19,7 @@ import 'package:invoiceninja_flutter/redux/payment/payment_actions.dart';
import 'package:invoiceninja_flutter/data/models/payment_model.dart';
import 'package:invoiceninja_flutter/ui/payment/edit/payment_edit.dart';
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
import 'package:shared_preferences/shared_preferences.dart';
class PaymentEditScreen extends StatelessWidget {
static const String route = '/payment/edit';
@ -42,7 +46,9 @@ class PaymentEditVM {
final PaymentEntity origPayment;
final Function(PaymentEntity) onChanged;
final Function(BuildContext) onSavePressed;
final Function(bool) onEmailChanged;
final BuiltMap<int, InvoiceEntity> invoiceMap;
final UIState uiState;
final BuiltList<int> invoiceList;
final BuiltMap<int, ClientEntity> clientMap;
final BuiltList<int> clientList;
@ -56,6 +62,8 @@ class PaymentEditVM {
@required this.origPayment,
@required this.onChanged,
@required this.onSavePressed,
@required this.onEmailChanged,
@required this.uiState,
@required this.invoiceMap,
@required this.invoiceList,
@required this.clientMap,
@ -75,6 +83,7 @@ class PaymentEditVM {
isDirty: payment.isNew,
origPayment: state.paymentState.map[payment.id],
payment: payment,
uiState: state.uiState,
staticState: state.staticState,
invoiceMap: state.invoiceState.map,
invoiceList: state.invoiceState.list,
@ -83,6 +92,11 @@ class PaymentEditVM {
onChanged: (PaymentEntity payment) {
store.dispatch(UpdatePayment(payment));
},
onEmailChanged: (value) async {
final SharedPreferences prefs = await SharedPreferences.getInstance();
prefs.setBool(kSharedPrefEmailPayment, value);
store.dispatch(UserSettingsChanged(emailPayment: value));
},
onBackPressed: () {
store.dispatch(UpdateCurrentRoute(PaymentScreen.route));
},

View File

@ -123,12 +123,16 @@ class _PaymentViewState extends State<PaymentView> {
height: 12.0,
),
payment.privateNotes != null && payment.privateNotes.isNotEmpty
? IconMessage(payment.privateNotes)
? Column(
children: <Widget>[
IconMessage(payment.privateNotes),
Container(
color: Theme.of(context).backgroundColor,
height: 12.0,
),
],
)
: Container(),
Container(
color: Theme.of(context).backgroundColor,
height: 12.0,
),
FieldGrid(fields),
],
));