Simplify credits

This commit is contained in:
Hillel Coren 2021-11-09 16:11:59 +02:00
parent 22611711ba
commit 7f7fcb8768
10 changed files with 38 additions and 20 deletions

View File

@ -130,6 +130,7 @@ const String kPaymentTypeMasterCard = '6';
const String kPaymentTypeAmEx = '7'; const String kPaymentTypeAmEx = '7';
const String kPaymentTypeDiners = '9'; const String kPaymentTypeDiners = '9';
const String kPaymentTypeDiscover = '8'; const String kPaymentTypeDiscover = '8';
const String kPaymentTypeCredit = '32';
const String kPlanFree = ''; const String kPlanFree = '';
const String kPlanPro = 'pro'; const String kPlanPro = 'pro';

View File

@ -868,8 +868,12 @@ abstract class InvoiceEntity extends Object
} }
if (isPayable && userCompany.canCreate(EntityType.payment)) { if (isPayable && userCompany.canCreate(EntityType.payment)) {
if (isCredit) {
actions.add(EntityAction.applyCredit);
} else {
actions.add(EntityAction.newPayment); actions.add(EntityAction.newPayment);
} }
}
if (!isSent && !isRecurring) { if (!isSent && !isRecurring) {
actions.add(EntityAction.markSent); actions.add(EntityAction.markSent);

View File

@ -57,7 +57,8 @@ class EntityAction extends EnumClass {
static const EntityAction cloneToRecurring = _$cloneToRecurring; static const EntityAction cloneToRecurring = _$cloneToRecurring;
static const EntityAction convertToInvoice = _$convertToInvoice; static const EntityAction convertToInvoice = _$convertToInvoice;
static const EntityAction approve = _$approve; static const EntityAction approve = _$approve;
static const EntityAction apply = _$apply; static const EntityAction applyCredit = _$applyCredit;
static const EntityAction applyPayment = _$applyPayment;
static const EntityAction download = _$download; static const EntityAction download = _$download;
static const EntityAction bulkDownload = _$bulkDownload; static const EntityAction bulkDownload = _$bulkDownload;
static const EntityAction emailInvoice = _$emailInvoice; static const EntityAction emailInvoice = _$emailInvoice;
@ -83,7 +84,7 @@ class EntityAction extends EnumClass {
static const EntityAction clientPortal = _$clientPortal; static const EntityAction clientPortal = _$clientPortal;
static const EntityAction newPayment = _$newPayment; static const EntityAction newPayment = _$newPayment;
static const EntityAction settings = _$settings; static const EntityAction settings = _$settings;
static const EntityAction refund = _$refund; static const EntityAction refundPayment = _$refundPayment;
static const EntityAction viewPdf = _$viewPdf; static const EntityAction viewPdf = _$viewPdf;
static const EntityAction viewStatement = _$viewStatement; static const EntityAction viewStatement = _$viewStatement;
static const EntityAction more = _$more; static const EntityAction more = _$more;

View File

@ -22,7 +22,8 @@ const EntityAction _$cloneToRecurring =
const EntityAction _$convertToInvoice = const EntityAction _$convertToInvoice =
const EntityAction._('convertToInvoice'); const EntityAction._('convertToInvoice');
const EntityAction _$approve = const EntityAction._('approve'); const EntityAction _$approve = const EntityAction._('approve');
const EntityAction _$apply = const EntityAction._('apply'); const EntityAction _$applyCredit = const EntityAction._('applyCredit');
const EntityAction _$applyPayment = const EntityAction._('applyPayment');
const EntityAction _$download = const EntityAction._('download'); const EntityAction _$download = const EntityAction._('download');
const EntityAction _$bulkDownload = const EntityAction._('bulkDownload'); const EntityAction _$bulkDownload = const EntityAction._('bulkDownload');
const EntityAction _$emailInvoice = const EntityAction._('emailInvoice'); const EntityAction _$emailInvoice = const EntityAction._('emailInvoice');
@ -52,7 +53,7 @@ const EntityAction _$newVendor = const EntityAction._('newVendor');
const EntityAction _$clientPortal = const EntityAction._('clientPortal'); const EntityAction _$clientPortal = const EntityAction._('clientPortal');
const EntityAction _$newPayment = const EntityAction._('newPayment'); const EntityAction _$newPayment = const EntityAction._('newPayment');
const EntityAction _$settings = const EntityAction._('settings'); const EntityAction _$settings = const EntityAction._('settings');
const EntityAction _$refund = const EntityAction._('refund'); const EntityAction _$refundPayment = const EntityAction._('refundPayment');
const EntityAction _$viewPdf = const EntityAction._('viewPdf'); const EntityAction _$viewPdf = const EntityAction._('viewPdf');
const EntityAction _$viewStatement = const EntityAction._('viewStatement'); const EntityAction _$viewStatement = const EntityAction._('viewStatement');
const EntityAction _$more = const EntityAction._('more'); const EntityAction _$more = const EntityAction._('more');
@ -100,8 +101,10 @@ EntityAction _$valueOf(String name) {
return _$convertToInvoice; return _$convertToInvoice;
case 'approve': case 'approve':
return _$approve; return _$approve;
case 'apply': case 'applyCredit':
return _$apply; return _$applyCredit;
case 'applyPayment':
return _$applyPayment;
case 'download': case 'download':
return _$download; return _$download;
case 'bulkDownload': case 'bulkDownload':
@ -152,8 +155,8 @@ EntityAction _$valueOf(String name) {
return _$newPayment; return _$newPayment;
case 'settings': case 'settings':
return _$settings; return _$settings;
case 'refund': case 'refundPayment':
return _$refund; return _$refundPayment;
case 'viewPdf': case 'viewPdf':
return _$viewPdf; return _$viewPdf;
case 'viewStatement': case 'viewStatement':
@ -205,7 +208,8 @@ final BuiltSet<EntityAction> _$values =
_$cloneToRecurring, _$cloneToRecurring,
_$convertToInvoice, _$convertToInvoice,
_$approve, _$approve,
_$apply, _$applyCredit,
_$applyPayment,
_$download, _$download,
_$bulkDownload, _$bulkDownload,
_$emailInvoice, _$emailInvoice,
@ -231,7 +235,7 @@ final BuiltSet<EntityAction> _$values =
_$clientPortal, _$clientPortal,
_$newPayment, _$newPayment,
_$settings, _$settings,
_$refund, _$refundPayment,
_$viewPdf, _$viewPdf,
_$viewStatement, _$viewStatement,
_$more, _$more,

View File

@ -393,11 +393,11 @@ abstract class PaymentEntity extends Object
} }
if (applied < amount) { if (applied < amount) {
actions.add(EntityAction.apply); actions.add(EntityAction.applyPayment);
} }
if (completedAmount > 0) { if (completedAmount > 0) {
actions.add(EntityAction.refund); actions.add(EntityAction.refundPayment);
} }
} }

View File

@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/widgets.dart'; import 'package:flutter/widgets.dart';
import 'package:flutter_redux/flutter_redux.dart'; import 'package:flutter_redux/flutter_redux.dart';
import 'package:http/http.dart'; import 'package:http/http.dart';
import 'package:invoiceninja_flutter/constants.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';
@ -530,10 +531,11 @@ Future handleCreditAction(
..entityType = EntityType.recurringInvoice ..entityType = EntityType.recurringInvoice
..designId = designId)); ..designId = designId));
break; break;
case EntityAction.newPayment: case EntityAction.applyCredit:
createEntity( createEntity(
context: context, context: context,
entity: PaymentEntity(state: state).rebuild((b) => b entity: PaymentEntity(state: state).rebuild((b) => b
..typeId = kPaymentTypeCredit
..clientId = credit.clientId ..clientId = credit.clientId
..credits.addAll(credits ..credits.addAll(credits
.map((credit) => PaymentableEntity.fromCredit(credit)) .map((credit) => PaymentableEntity.fromCredit(credit))

View File

@ -320,7 +320,7 @@ void handlePaymentAction(
case EntityAction.edit: case EntityAction.edit:
editEntity(context: context, entity: payment); editEntity(context: context, entity: payment);
break; break;
case EntityAction.apply: case EntityAction.applyPayment:
viewEntity(entity: payment); viewEntity(entity: payment);
WidgetsBinding.instance.addPostFrameCallback((duration) { WidgetsBinding.instance.addPostFrameCallback((duration) {
editEntity( editEntity(
@ -328,7 +328,7 @@ void handlePaymentAction(
entity: payment.rebuild((b) => b..isApplying = true)); entity: payment.rebuild((b) => b..isApplying = true));
}); });
break; break;
case EntityAction.refund: case EntityAction.refundPayment:
viewEntity(entity: payment); viewEntity(entity: payment);
WidgetsBinding.instance.addPostFrameCallback((duration) { WidgetsBinding.instance.addPostFrameCallback((duration) {
if (payment.invoicePaymentables.length == 1) { if (payment.invoicePaymentables.length == 1) {

View File

@ -167,9 +167,9 @@ class _PaymentViewState extends State<PaymentView> {
), ),
BottomButtons( BottomButtons(
entity: payment, entity: payment,
action1: EntityAction.apply, action1: EntityAction.applyPayment,
action1Enabled: payment.applied < payment.amount, action1Enabled: payment.applied < payment.amount,
action2: EntityAction.refund, action2: EntityAction.refundPayment,
action2Enabled: payment.refunded < payment.amount, action2Enabled: payment.refunded < payment.amount,
), ),
], ],

View File

@ -573,6 +573,7 @@ mixin LocalizationsProvider on LocaleCodeAware {
'taxes': 'Taxes', 'taxes': 'Taxes',
'surcharge': 'Surcharge', 'surcharge': 'Surcharge',
'apply_payment': 'Apply Payment', 'apply_payment': 'Apply Payment',
'apply_credit': 'Apply Credit',
'apply': 'Apply', 'apply': 'Apply',
'unapplied': 'Unapplied', 'unapplied': 'Unapplied',
'select_label': 'Select Label', 'select_label': 'Select Label',
@ -62802,6 +62803,10 @@ mixin LocalizationsProvider on LocaleCodeAware {
_localizedValues[localeCode]['direct_debit'] ?? _localizedValues[localeCode]['direct_debit'] ??
_localizedValues['en']['direct_debit']; _localizedValues['en']['direct_debit'];
String get applyCredit =>
_localizedValues[localeCode]['apply_credit'] ??
_localizedValues['en']['apply_credit'];
// STARTER: lang field - do not remove comment // STARTER: lang field - do not remove comment
String lookup(String key) { String lookup(String key) {

View File

@ -70,14 +70,15 @@ IconData getEntityActionIcon(EntityAction entityAction) {
return Icons.stop; return Icons.stop;
case EntityAction.settings: case EntityAction.settings:
return Icons.settings; return Icons.settings;
case EntityAction.refund: case EntityAction.refundPayment:
case EntityAction.cancel: case EntityAction.cancel:
return Icons.remove_circle_outline; return Icons.remove_circle_outline;
case EntityAction.reverse: case EntityAction.reverse:
return Icons.undo; return Icons.undo;
case EntityAction.copy: case EntityAction.copy:
return Icons.content_copy; return Icons.content_copy;
case EntityAction.apply: case EntityAction.applyPayment:
case EntityAction.applyCredit:
return Icons.payment; return Icons.payment;
case EntityAction.disconnect: case EntityAction.disconnect:
return MdiIcons.lanDisconnect; return MdiIcons.lanDisconnect;