Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
hillelcoren committed Jan 30, 2024
2 parents eafe0d6 + 900ddf5 commit 423ec92
Show file tree
Hide file tree
Showing 7 changed files with 41 additions and 29 deletions.
4 changes: 4 additions & 0 deletions lib/data/models/payment_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -501,6 +501,10 @@ abstract class PaymentEntity extends Object

bool get isOnline => companyGatewayId.isNotEmpty;

double get convertedExchangeRate => exchangeRate == 0 ? 1 : exchangeRate;

double get convertedAmount => completedAmount * convertedExchangeRate;

bool get isCompletedOrPartiallyRefunded => [
kPaymentStatusCompleted,
kPaymentStatusPartiallyRefunded
Expand Down
24 changes: 1 addition & 23 deletions lib/ui/app/portal_links.dart
Original file line number Diff line number Diff line change
@@ -1,15 +1,12 @@
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_redux/flutter_redux.dart';
import 'package:flutter_styled_toast/flutter_styled_toast.dart';
import 'package:invoiceninja_flutter/data/models/client_model.dart';
import 'package:invoiceninja_flutter/redux/app/app_state.dart';
import 'package:invoiceninja_flutter/ui/app/icon_text.dart';
import 'package:invoiceninja_flutter/utils/localization.dart';
import 'package:url_launcher/url_launcher.dart';

enum PortalLinkStyle {
icons,
buttons,
dropdown,
}
Expand All @@ -30,9 +27,6 @@ class PortalLinks extends StatelessWidget {

@override
Widget build(BuildContext context) {
final store = StoreProvider.of<AppState>(context);
final state = store.state;
final prefState = state.prefState;
final localization = AppLocalization.of(context);

var viewLinkWithHash = viewLink;
Expand All @@ -49,23 +43,7 @@ class PortalLinks extends StatelessWidget {
showToast(localization!.copiedToClipboard.replaceFirst(':value ', ''));
};

if (style == PortalLinkStyle.icons) {
return Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
IconButton(
onPressed: viewLinkPressed,
icon: Icon(Icons.open_in_new),
tooltip: prefState.enableTooltips ? localization!.viewPortal : '',
),
IconButton(
onPressed: copyLinkPressed,
icon: Icon(Icons.copy),
tooltip: prefState.enableTooltips ? localization!.copyLink : '',
),
],
);
} else if (style == PortalLinkStyle.dropdown) {
if (style == PortalLinkStyle.dropdown) {
return PopupMenuButton<String>(
itemBuilder: (BuildContext context) => [
PopupMenuItem(
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/client/view/client_view_fullwidth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,7 @@ class _ClientViewFullwidthState extends State<ClientViewFullwidth>
viewLink: contact.silentLink,
copyLink: contact.link,
client: client,
style: PortalLinkStyle.icons,
style: PortalLinkStyle.buttons,
),
SizedBox(height: 16),
] else
Expand Down
19 changes: 15 additions & 4 deletions lib/ui/payment/edit/payment_edit_vm.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class PaymentEditVM {
onSavePressed: (BuildContext context) {
Debouncer.runOnComplete(() {
final payment = store.state.paymentUIState.editing!;
final localization = navigatorKey.localization;
final localization = navigatorKey.localization!;
final navigator = navigatorKey.currentState;
double amount = 0;
payment.invoices.forEach((invoice) => amount += invoice.amount);
Expand All @@ -89,17 +89,28 @@ class PaymentEditVM {
showDialog<ErrorDialog>(
context: navigatorKey.currentContext!,
builder: (BuildContext context) {
return ErrorDialog(localization!.creditPaymentError);
return ErrorDialog(localization.creditPaymentError);
});
return null;
} else if (!state.company.enableApplyingPayments &&
payment.invoices.isEmpty &&
payment.credits.isEmpty) {
showDialog<ErrorDialog>(
context: navigatorKey.currentContext!,
builder: (BuildContext context) {
return ErrorDialog(
localization.pleaseSelectAnInvoiceOrCredit);
});
return null;
}

final Completer<PaymentEntity> completer = Completer<PaymentEntity>();
store.dispatch(
SavePaymentRequest(completer: completer, payment: payment));
return completer.future.then((savedPayment) {
showToast(payment.isNew
? localization!.createdPayment
: localization!.updatedPayment);
? localization.createdPayment
: localization.updatedPayment);
if (state.prefState.isMobile) {
store.dispatch(UpdateCurrentRoute(PaymentViewScreen.route));
if (payment.isNew) {
Expand Down
13 changes: 13 additions & 0 deletions lib/ui/reports/profit_loss_report.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ enum ProfitAndLossReportFields {
currency,
transaction_reference,
record_state,
converted_amount,
}

var memoizedProfitAndLossReport = memo9((
Expand Down Expand Up @@ -179,6 +180,9 @@ ReportResult profitAndLossReport(
value = AppLocalization.of(navigatorKey.currentContext!)!
.lookup(payment.entityState);
break;
case ProfitAndLossReportFields.converted_amount:
value = payment.convertedAmount;
break;
}

if (!ReportResult.matchField(
Expand All @@ -194,6 +198,9 @@ ReportResult profitAndLossReport(
row.add(payment.getReportEntityType());
} else if (value.runtimeType == bool) {
row.add(payment.getReportBool(value: value));
} else if (column == ProfitAndLossReportFields.converted_amount) {
row.add(payment.getReportDouble(
value: value, currencyId: userCompany.company.currencyId));
} else if (value.runtimeType == double || value.runtimeType == int) {
row.add(payment.getReportDouble(
value: value, currencyId: client.currencyId));
Expand Down Expand Up @@ -286,6 +293,9 @@ ReportResult profitAndLossReport(
value = AppLocalization.of(navigatorKey.currentContext!)!
.lookup(expense.entityState);
break;
case ProfitAndLossReportFields.converted_amount:
value = expense.convertedAmount;
break;
}

if (!ReportResult.matchField(
Expand All @@ -301,6 +311,9 @@ ReportResult profitAndLossReport(
row.add(expense.getReportEntityType());
} else if (value.runtimeType == bool) {
row.add(expense.getReportBool(value: value));
} else if (column == ProfitAndLossReportFields.converted_amount) {
row.add(expense.getReportDouble(
value: value, currencyId: userCompany.company.currencyId));
} else if (value.runtimeType == double || value.runtimeType == int) {
row.add(expense.getReportDouble(
value: value, currencyId: expense.currencyId));
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/vendor/view/vendor_view_fullwidth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class _VendorViewFullwidthState extends State<VendorViewFullwidth>
viewLink: contact.silentLink,
copyLink: contact.link,
client: null,
style: PortalLinkStyle.icons,
style: PortalLinkStyle.buttons,
),
SizedBox(height: 16),
] else
Expand Down
6 changes: 6 additions & 0 deletions lib/utils/i18n.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ mixin LocalizationsProvider on LocaleCodeAware {
static final Map<String, Map<String, String>> _localizedValues = {
'en': {
// STARTER: lang key - do not remove comment
'please_select_an_invoice_or_credit':
'Please select an invoice or credit',
'mobile_version': 'Mobile Version',
'venmo': 'Venmo',
'mercado_pago': 'Mercado Pago',
Expand Down Expand Up @@ -114273,6 +114275,10 @@ mixin LocalizationsProvider on LocaleCodeAware {
_localizedValues[localeCode]!['mobile_version'] ??
_localizedValues['en']!['mobile_version']!;

String get pleaseSelectAnInvoiceOrCredit =>
_localizedValues[localeCode]!['please_select_an_invoice_or_credit'] ??
_localizedValues['en']!['please_select_an_invoice_or_credit']!;

// STARTER: lang field - do not remove comment

String lookup(String? key) {
Expand Down

0 comments on commit 423ec92

Please sign in to comment.