From 7c90152bbe490ff0850f8c0e09835bfef4751d75 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 12 May 2024 17:46:29 +0300 Subject: [PATCH 1/6] e-invoice --- lib/data/repositories/auth_repository.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/data/repositories/auth_repository.dart b/lib/data/repositories/auth_repository.dart index 6fec421dc2c..c7e3d789225 100644 --- a/lib/data/repositories/auth_repository.dart +++ b/lib/data/repositories/auth_repository.dart @@ -233,7 +233,7 @@ class AuthRepository { url += 'first_load=true'; if (includeStatic) { - url += '&include_static=true'; + url += '&include_static=true&einvoice=true'; } dynamic response; From 7731c65dc9bef4c1695b906e91ff5ac704cf76e4 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Sun, 12 May 2024 18:22:31 +0300 Subject: [PATCH 2/6] e-invoice --- lib/data/models/e_invoice_model.dart | 68 ++++ lib/data/models/e_invoice_model.g.dart | 446 +++++++++++++++++++++++++ 2 files changed, 514 insertions(+) create mode 100644 lib/data/models/e_invoice_model.dart create mode 100644 lib/data/models/e_invoice_model.g.dart diff --git a/lib/data/models/e_invoice_model.dart b/lib/data/models/e_invoice_model.dart new file mode 100644 index 00000000000..71c2da04b41 --- /dev/null +++ b/lib/data/models/e_invoice_model.dart @@ -0,0 +1,68 @@ +// Package imports: +import 'package:built_collection/built_collection.dart'; +import 'package:built_value/built_value.dart'; +import 'package:built_value/serializer.dart'; + +// Project imports: +import 'package:invoiceninja_flutter/data/models/entities.dart'; + +part 'e_invoice_model.g.dart'; + +abstract class EInvoiceFieldEntity + implements Built { + factory EInvoiceFieldEntity() { + return _$EInvoiceFieldEntity._( + type: '', + help: '', + choices: BuiltList(), + ); + } + EInvoiceFieldEntity._(); + + @override + @memoized + int get hashCode; + + String get type; + + String get help; + + BuiltList get choices; + + static Serializer get serializer => + _$eInvoiceFieldEntitySerializer; +} + +abstract class EInvoiceElementEntity + implements Built { + factory EInvoiceElementEntity() { + return _$EInvoiceElementEntity._( + baseType: '', + help: '', + maxLength: 0, + name: '', + resource: BuiltList(), + ); + } + + EInvoiceElementEntity._(); + + @override + @memoized + int get hashCode; + + String get name; + + @BuiltValueField(wireName: 'base_type') + String get baseType; + + BuiltList get resource; + + @BuiltValueField(wireName: 'max_length') + int get maxLength; + + String get help; + + static Serializer get serializer => + _$eInvoiceElementEntitySerializer; +} diff --git a/lib/data/models/e_invoice_model.g.dart b/lib/data/models/e_invoice_model.g.dart new file mode 100644 index 00000000000..9e939b6597b --- /dev/null +++ b/lib/data/models/e_invoice_model.g.dart @@ -0,0 +1,446 @@ +// GENERATED CODE - DO NOT MODIFY BY HAND + +part of 'e_invoice_model.dart'; + +// ************************************************************************** +// BuiltValueGenerator +// ************************************************************************** + +Serializer _$eInvoiceFieldEntitySerializer = + new _$EInvoiceFieldEntitySerializer(); +Serializer _$eInvoiceElementEntitySerializer = + new _$EInvoiceElementEntitySerializer(); + +class _$EInvoiceFieldEntitySerializer + implements StructuredSerializer { + @override + final Iterable types = const [ + EInvoiceFieldEntity, + _$EInvoiceFieldEntity + ]; + @override + final String wireName = 'EInvoiceFieldEntity'; + + @override + Iterable serialize( + Serializers serializers, EInvoiceFieldEntity object, + {FullType specifiedType = FullType.unspecified}) { + final result = [ + 'type', + serializers.serialize(object.type, specifiedType: const FullType(String)), + 'help', + serializers.serialize(object.help, specifiedType: const FullType(String)), + 'choices', + serializers.serialize(object.choices, + specifiedType: + const FullType(BuiltList, const [const FullType(String)])), + ]; + + return result; + } + + @override + EInvoiceFieldEntity deserialize( + Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = new EInvoiceFieldEntityBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current! as String; + iterator.moveNext(); + final Object? value = iterator.current; + switch (key) { + case 'type': + result.type = serializers.deserialize(value, + specifiedType: const FullType(String))! as String; + break; + case 'help': + result.help = serializers.deserialize(value, + specifiedType: const FullType(String))! as String; + break; + case 'choices': + result.choices.replace(serializers.deserialize(value, + specifiedType: const FullType( + BuiltList, const [const FullType(String)]))! + as BuiltList); + break; + } + } + + return result.build(); + } +} + +class _$EInvoiceElementEntitySerializer + implements StructuredSerializer { + @override + final Iterable types = const [ + EInvoiceElementEntity, + _$EInvoiceElementEntity + ]; + @override + final String wireName = 'EInvoiceElementEntity'; + + @override + Iterable serialize( + Serializers serializers, EInvoiceElementEntity object, + {FullType specifiedType = FullType.unspecified}) { + final result = [ + 'name', + serializers.serialize(object.name, specifiedType: const FullType(String)), + 'base_type', + serializers.serialize(object.baseType, + specifiedType: const FullType(String)), + 'resource', + serializers.serialize(object.resource, + specifiedType: + const FullType(BuiltList, const [const FullType(String)])), + 'max_length', + serializers.serialize(object.maxLength, + specifiedType: const FullType(int)), + 'help', + serializers.serialize(object.help, specifiedType: const FullType(String)), + ]; + + return result; + } + + @override + EInvoiceElementEntity deserialize( + Serializers serializers, Iterable serialized, + {FullType specifiedType = FullType.unspecified}) { + final result = new EInvoiceElementEntityBuilder(); + + final iterator = serialized.iterator; + while (iterator.moveNext()) { + final key = iterator.current! as String; + iterator.moveNext(); + final Object? value = iterator.current; + switch (key) { + case 'name': + result.name = serializers.deserialize(value, + specifiedType: const FullType(String))! as String; + break; + case 'base_type': + result.baseType = serializers.deserialize(value, + specifiedType: const FullType(String))! as String; + break; + case 'resource': + result.resource.replace(serializers.deserialize(value, + specifiedType: const FullType( + BuiltList, const [const FullType(String)]))! + as BuiltList); + break; + case 'max_length': + result.maxLength = serializers.deserialize(value, + specifiedType: const FullType(int))! as int; + break; + case 'help': + result.help = serializers.deserialize(value, + specifiedType: const FullType(String))! as String; + break; + } + } + + return result.build(); + } +} + +class _$EInvoiceFieldEntity extends EInvoiceFieldEntity { + @override + final String type; + @override + final String help; + @override + final BuiltList choices; + + factory _$EInvoiceFieldEntity( + [void Function(EInvoiceFieldEntityBuilder)? updates]) => + (new EInvoiceFieldEntityBuilder()..update(updates))._build(); + + _$EInvoiceFieldEntity._( + {required this.type, required this.help, required this.choices}) + : super._() { + BuiltValueNullFieldError.checkNotNull(type, r'EInvoiceFieldEntity', 'type'); + BuiltValueNullFieldError.checkNotNull(help, r'EInvoiceFieldEntity', 'help'); + BuiltValueNullFieldError.checkNotNull( + choices, r'EInvoiceFieldEntity', 'choices'); + } + + @override + EInvoiceFieldEntity rebuild( + void Function(EInvoiceFieldEntityBuilder) updates) => + (toBuilder()..update(updates)).build(); + + @override + EInvoiceFieldEntityBuilder toBuilder() => + new EInvoiceFieldEntityBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is EInvoiceFieldEntity && + type == other.type && + help == other.help && + choices == other.choices; + } + + int? __hashCode; + @override + int get hashCode { + if (__hashCode != null) return __hashCode!; + var _$hash = 0; + _$hash = $jc(_$hash, type.hashCode); + _$hash = $jc(_$hash, help.hashCode); + _$hash = $jc(_$hash, choices.hashCode); + _$hash = $jf(_$hash); + return __hashCode ??= _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'EInvoiceFieldEntity') + ..add('type', type) + ..add('help', help) + ..add('choices', choices)) + .toString(); + } +} + +class EInvoiceFieldEntityBuilder + implements Builder { + _$EInvoiceFieldEntity? _$v; + + String? _type; + String? get type => _$this._type; + set type(String? type) => _$this._type = type; + + String? _help; + String? get help => _$this._help; + set help(String? help) => _$this._help = help; + + ListBuilder? _choices; + ListBuilder get choices => + _$this._choices ??= new ListBuilder(); + set choices(ListBuilder? choices) => _$this._choices = choices; + + EInvoiceFieldEntityBuilder(); + + EInvoiceFieldEntityBuilder get _$this { + final $v = _$v; + if ($v != null) { + _type = $v.type; + _help = $v.help; + _choices = $v.choices.toBuilder(); + _$v = null; + } + return this; + } + + @override + void replace(EInvoiceFieldEntity other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other as _$EInvoiceFieldEntity; + } + + @override + void update(void Function(EInvoiceFieldEntityBuilder)? updates) { + if (updates != null) updates(this); + } + + @override + EInvoiceFieldEntity build() => _build(); + + _$EInvoiceFieldEntity _build() { + _$EInvoiceFieldEntity _$result; + try { + _$result = _$v ?? + new _$EInvoiceFieldEntity._( + type: BuiltValueNullFieldError.checkNotNull( + type, r'EInvoiceFieldEntity', 'type'), + help: BuiltValueNullFieldError.checkNotNull( + help, r'EInvoiceFieldEntity', 'help'), + choices: choices.build()); + } catch (_) { + late String _$failedField; + try { + _$failedField = 'choices'; + choices.build(); + } catch (e) { + throw new BuiltValueNestedFieldError( + r'EInvoiceFieldEntity', _$failedField, e.toString()); + } + rethrow; + } + replace(_$result); + return _$result; + } +} + +class _$EInvoiceElementEntity extends EInvoiceElementEntity { + @override + final String name; + @override + final String baseType; + @override + final BuiltList resource; + @override + final int maxLength; + @override + final String help; + + factory _$EInvoiceElementEntity( + [void Function(EInvoiceElementEntityBuilder)? updates]) => + (new EInvoiceElementEntityBuilder()..update(updates))._build(); + + _$EInvoiceElementEntity._( + {required this.name, + required this.baseType, + required this.resource, + required this.maxLength, + required this.help}) + : super._() { + BuiltValueNullFieldError.checkNotNull( + name, r'EInvoiceElementEntity', 'name'); + BuiltValueNullFieldError.checkNotNull( + baseType, r'EInvoiceElementEntity', 'baseType'); + BuiltValueNullFieldError.checkNotNull( + resource, r'EInvoiceElementEntity', 'resource'); + BuiltValueNullFieldError.checkNotNull( + maxLength, r'EInvoiceElementEntity', 'maxLength'); + BuiltValueNullFieldError.checkNotNull( + help, r'EInvoiceElementEntity', 'help'); + } + + @override + EInvoiceElementEntity rebuild( + void Function(EInvoiceElementEntityBuilder) updates) => + (toBuilder()..update(updates)).build(); + + @override + EInvoiceElementEntityBuilder toBuilder() => + new EInvoiceElementEntityBuilder()..replace(this); + + @override + bool operator ==(Object other) { + if (identical(other, this)) return true; + return other is EInvoiceElementEntity && + name == other.name && + baseType == other.baseType && + resource == other.resource && + maxLength == other.maxLength && + help == other.help; + } + + int? __hashCode; + @override + int get hashCode { + if (__hashCode != null) return __hashCode!; + var _$hash = 0; + _$hash = $jc(_$hash, name.hashCode); + _$hash = $jc(_$hash, baseType.hashCode); + _$hash = $jc(_$hash, resource.hashCode); + _$hash = $jc(_$hash, maxLength.hashCode); + _$hash = $jc(_$hash, help.hashCode); + _$hash = $jf(_$hash); + return __hashCode ??= _$hash; + } + + @override + String toString() { + return (newBuiltValueToStringHelper(r'EInvoiceElementEntity') + ..add('name', name) + ..add('baseType', baseType) + ..add('resource', resource) + ..add('maxLength', maxLength) + ..add('help', help)) + .toString(); + } +} + +class EInvoiceElementEntityBuilder + implements Builder { + _$EInvoiceElementEntity? _$v; + + String? _name; + String? get name => _$this._name; + set name(String? name) => _$this._name = name; + + String? _baseType; + String? get baseType => _$this._baseType; + set baseType(String? baseType) => _$this._baseType = baseType; + + ListBuilder? _resource; + ListBuilder get resource => + _$this._resource ??= new ListBuilder(); + set resource(ListBuilder? resource) => _$this._resource = resource; + + int? _maxLength; + int? get maxLength => _$this._maxLength; + set maxLength(int? maxLength) => _$this._maxLength = maxLength; + + String? _help; + String? get help => _$this._help; + set help(String? help) => _$this._help = help; + + EInvoiceElementEntityBuilder(); + + EInvoiceElementEntityBuilder get _$this { + final $v = _$v; + if ($v != null) { + _name = $v.name; + _baseType = $v.baseType; + _resource = $v.resource.toBuilder(); + _maxLength = $v.maxLength; + _help = $v.help; + _$v = null; + } + return this; + } + + @override + void replace(EInvoiceElementEntity other) { + ArgumentError.checkNotNull(other, 'other'); + _$v = other as _$EInvoiceElementEntity; + } + + @override + void update(void Function(EInvoiceElementEntityBuilder)? updates) { + if (updates != null) updates(this); + } + + @override + EInvoiceElementEntity build() => _build(); + + _$EInvoiceElementEntity _build() { + _$EInvoiceElementEntity _$result; + try { + _$result = _$v ?? + new _$EInvoiceElementEntity._( + name: BuiltValueNullFieldError.checkNotNull( + name, r'EInvoiceElementEntity', 'name'), + baseType: BuiltValueNullFieldError.checkNotNull( + baseType, r'EInvoiceElementEntity', 'baseType'), + resource: resource.build(), + maxLength: BuiltValueNullFieldError.checkNotNull( + maxLength, r'EInvoiceElementEntity', 'maxLength'), + help: BuiltValueNullFieldError.checkNotNull( + help, r'EInvoiceElementEntity', 'help')); + } catch (_) { + late String _$failedField; + try { + _$failedField = 'resource'; + resource.build(); + } catch (e) { + throw new BuiltValueNestedFieldError( + r'EInvoiceElementEntity', _$failedField, e.toString()); + } + rethrow; + } + replace(_$result); + return _$result; + } +} + +// ignore_for_file: deprecated_member_use_from_same_package,type=lint From 7ba28a47af9f4bdfad9acf7c479b4bf67eba5fe6 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 13 May 2024 11:54:39 +0300 Subject: [PATCH 3/6] e-invoice --- lib/data/models/e_invoice_model.dart | 24 ++- lib/data/models/e_invoice_model.g.dart | 164 +++++++++++++++--- lib/data/models/serializers.dart | 2 + lib/data/models/serializers.g.dart | 20 +++ lib/data/models/static/static_data_model.dart | 10 +- .../models/static/static_data_model.g.dart | 39 ++++- 6 files changed, 227 insertions(+), 32 deletions(-) diff --git a/lib/data/models/e_invoice_model.dart b/lib/data/models/e_invoice_model.dart index 71c2da04b41..69391543087 100644 --- a/lib/data/models/e_invoice_model.dart +++ b/lib/data/models/e_invoice_model.dart @@ -3,9 +3,6 @@ import 'package:built_collection/built_collection.dart'; import 'package:built_value/built_value.dart'; import 'package:built_value/serializer.dart'; -// Project imports: -import 'package:invoiceninja_flutter/data/models/entities.dart'; - part 'e_invoice_model.g.dart'; abstract class EInvoiceFieldEntity @@ -15,6 +12,7 @@ abstract class EInvoiceFieldEntity type: '', help: '', choices: BuiltList(), + elements: BuiltMap(), ); } EInvoiceFieldEntity._(); @@ -29,6 +27,8 @@ abstract class EInvoiceFieldEntity BuiltList get choices; + BuiltMap get elements; + static Serializer get serializer => _$eInvoiceFieldEntitySerializer; } @@ -39,8 +39,9 @@ abstract class EInvoiceElementEntity return _$EInvoiceElementEntity._( baseType: '', help: '', - maxLength: 0, name: '', + maxOccurs: 0, + minOccurs: 0, resource: BuiltList(), ); } @@ -58,10 +59,21 @@ abstract class EInvoiceElementEntity BuiltList get resource; + @BuiltValueField(wireName: 'min_length') + int? get minLength; + @BuiltValueField(wireName: 'max_length') - int get maxLength; + int? get maxLength; - String get help; + @BuiltValueField(wireName: 'min_occurs') + int get minOccurs; + + @BuiltValueField(wireName: 'max_occurs') + int get maxOccurs; + + String? get pattern; + + String? get help; static Serializer get serializer => _$eInvoiceElementEntitySerializer; diff --git a/lib/data/models/e_invoice_model.g.dart b/lib/data/models/e_invoice_model.g.dart index 9e939b6597b..a5572756df2 100644 --- a/lib/data/models/e_invoice_model.g.dart +++ b/lib/data/models/e_invoice_model.g.dart @@ -34,6 +34,12 @@ class _$EInvoiceFieldEntitySerializer serializers.serialize(object.choices, specifiedType: const FullType(BuiltList, const [const FullType(String)])), + 'elements', + serializers.serialize(object.elements, + specifiedType: const FullType(BuiltMap, const [ + const FullType(String), + const FullType(EInvoiceElementEntity) + ])), ]; return result; @@ -65,6 +71,13 @@ class _$EInvoiceFieldEntitySerializer BuiltList, const [const FullType(String)]))! as BuiltList); break; + case 'elements': + result.elements.replace(serializers.deserialize(value, + specifiedType: const FullType(BuiltMap, const [ + const FullType(String), + const FullType(EInvoiceElementEntity) + ]))!); + break; } } @@ -96,13 +109,40 @@ class _$EInvoiceElementEntitySerializer serializers.serialize(object.resource, specifiedType: const FullType(BuiltList, const [const FullType(String)])), - 'max_length', - serializers.serialize(object.maxLength, + 'min_occurs', + serializers.serialize(object.minOccurs, + specifiedType: const FullType(int)), + 'max_occurs', + serializers.serialize(object.maxOccurs, specifiedType: const FullType(int)), - 'help', - serializers.serialize(object.help, specifiedType: const FullType(String)), ]; - + Object? value; + value = object.minLength; + if (value != null) { + result + ..add('min_length') + ..add(serializers.serialize(value, specifiedType: const FullType(int))); + } + value = object.maxLength; + if (value != null) { + result + ..add('max_length') + ..add(serializers.serialize(value, specifiedType: const FullType(int))); + } + value = object.pattern; + if (value != null) { + result + ..add('pattern') + ..add(serializers.serialize(value, + specifiedType: const FullType(String))); + } + value = object.help; + if (value != null) { + result + ..add('help') + ..add(serializers.serialize(value, + specifiedType: const FullType(String))); + } return result; } @@ -132,13 +172,29 @@ class _$EInvoiceElementEntitySerializer BuiltList, const [const FullType(String)]))! as BuiltList); break; + case 'min_length': + result.minLength = serializers.deserialize(value, + specifiedType: const FullType(int)) as int?; + break; case 'max_length': result.maxLength = serializers.deserialize(value, + specifiedType: const FullType(int)) as int?; + break; + case 'min_occurs': + result.minOccurs = serializers.deserialize(value, specifiedType: const FullType(int))! as int; break; + case 'max_occurs': + result.maxOccurs = serializers.deserialize(value, + specifiedType: const FullType(int))! as int; + break; + case 'pattern': + result.pattern = serializers.deserialize(value, + specifiedType: const FullType(String)) as String?; + break; case 'help': result.help = serializers.deserialize(value, - specifiedType: const FullType(String))! as String; + specifiedType: const FullType(String)) as String?; break; } } @@ -154,18 +210,25 @@ class _$EInvoiceFieldEntity extends EInvoiceFieldEntity { final String help; @override final BuiltList choices; + @override + final BuiltMap elements; factory _$EInvoiceFieldEntity( [void Function(EInvoiceFieldEntityBuilder)? updates]) => (new EInvoiceFieldEntityBuilder()..update(updates))._build(); _$EInvoiceFieldEntity._( - {required this.type, required this.help, required this.choices}) + {required this.type, + required this.help, + required this.choices, + required this.elements}) : super._() { BuiltValueNullFieldError.checkNotNull(type, r'EInvoiceFieldEntity', 'type'); BuiltValueNullFieldError.checkNotNull(help, r'EInvoiceFieldEntity', 'help'); BuiltValueNullFieldError.checkNotNull( choices, r'EInvoiceFieldEntity', 'choices'); + BuiltValueNullFieldError.checkNotNull( + elements, r'EInvoiceFieldEntity', 'elements'); } @override @@ -183,7 +246,8 @@ class _$EInvoiceFieldEntity extends EInvoiceFieldEntity { return other is EInvoiceFieldEntity && type == other.type && help == other.help && - choices == other.choices; + choices == other.choices && + elements == other.elements; } int? __hashCode; @@ -194,6 +258,7 @@ class _$EInvoiceFieldEntity extends EInvoiceFieldEntity { _$hash = $jc(_$hash, type.hashCode); _$hash = $jc(_$hash, help.hashCode); _$hash = $jc(_$hash, choices.hashCode); + _$hash = $jc(_$hash, elements.hashCode); _$hash = $jf(_$hash); return __hashCode ??= _$hash; } @@ -203,7 +268,8 @@ class _$EInvoiceFieldEntity extends EInvoiceFieldEntity { return (newBuiltValueToStringHelper(r'EInvoiceFieldEntity') ..add('type', type) ..add('help', help) - ..add('choices', choices)) + ..add('choices', choices) + ..add('elements', elements)) .toString(); } } @@ -225,6 +291,12 @@ class EInvoiceFieldEntityBuilder _$this._choices ??= new ListBuilder(); set choices(ListBuilder? choices) => _$this._choices = choices; + MapBuilder? _elements; + MapBuilder get elements => + _$this._elements ??= new MapBuilder(); + set elements(MapBuilder? elements) => + _$this._elements = elements; + EInvoiceFieldEntityBuilder(); EInvoiceFieldEntityBuilder get _$this { @@ -233,6 +305,7 @@ class EInvoiceFieldEntityBuilder _type = $v.type; _help = $v.help; _choices = $v.choices.toBuilder(); + _elements = $v.elements.toBuilder(); _$v = null; } return this; @@ -261,12 +334,15 @@ class EInvoiceFieldEntityBuilder type, r'EInvoiceFieldEntity', 'type'), help: BuiltValueNullFieldError.checkNotNull( help, r'EInvoiceFieldEntity', 'help'), - choices: choices.build()); + choices: choices.build(), + elements: elements.build()); } catch (_) { late String _$failedField; try { _$failedField = 'choices'; choices.build(); + _$failedField = 'elements'; + elements.build(); } catch (e) { throw new BuiltValueNestedFieldError( r'EInvoiceFieldEntity', _$failedField, e.toString()); @@ -286,9 +362,17 @@ class _$EInvoiceElementEntity extends EInvoiceElementEntity { @override final BuiltList resource; @override - final int maxLength; + final int? minLength; @override - final String help; + final int? maxLength; + @override + final int minOccurs; + @override + final int maxOccurs; + @override + final String? pattern; + @override + final String? help; factory _$EInvoiceElementEntity( [void Function(EInvoiceElementEntityBuilder)? updates]) => @@ -298,8 +382,12 @@ class _$EInvoiceElementEntity extends EInvoiceElementEntity { {required this.name, required this.baseType, required this.resource, - required this.maxLength, - required this.help}) + this.minLength, + this.maxLength, + required this.minOccurs, + required this.maxOccurs, + this.pattern, + this.help}) : super._() { BuiltValueNullFieldError.checkNotNull( name, r'EInvoiceElementEntity', 'name'); @@ -308,9 +396,9 @@ class _$EInvoiceElementEntity extends EInvoiceElementEntity { BuiltValueNullFieldError.checkNotNull( resource, r'EInvoiceElementEntity', 'resource'); BuiltValueNullFieldError.checkNotNull( - maxLength, r'EInvoiceElementEntity', 'maxLength'); + minOccurs, r'EInvoiceElementEntity', 'minOccurs'); BuiltValueNullFieldError.checkNotNull( - help, r'EInvoiceElementEntity', 'help'); + maxOccurs, r'EInvoiceElementEntity', 'maxOccurs'); } @override @@ -329,7 +417,11 @@ class _$EInvoiceElementEntity extends EInvoiceElementEntity { name == other.name && baseType == other.baseType && resource == other.resource && + minLength == other.minLength && maxLength == other.maxLength && + minOccurs == other.minOccurs && + maxOccurs == other.maxOccurs && + pattern == other.pattern && help == other.help; } @@ -341,7 +433,11 @@ class _$EInvoiceElementEntity extends EInvoiceElementEntity { _$hash = $jc(_$hash, name.hashCode); _$hash = $jc(_$hash, baseType.hashCode); _$hash = $jc(_$hash, resource.hashCode); + _$hash = $jc(_$hash, minLength.hashCode); _$hash = $jc(_$hash, maxLength.hashCode); + _$hash = $jc(_$hash, minOccurs.hashCode); + _$hash = $jc(_$hash, maxOccurs.hashCode); + _$hash = $jc(_$hash, pattern.hashCode); _$hash = $jc(_$hash, help.hashCode); _$hash = $jf(_$hash); return __hashCode ??= _$hash; @@ -353,7 +449,11 @@ class _$EInvoiceElementEntity extends EInvoiceElementEntity { ..add('name', name) ..add('baseType', baseType) ..add('resource', resource) + ..add('minLength', minLength) ..add('maxLength', maxLength) + ..add('minOccurs', minOccurs) + ..add('maxOccurs', maxOccurs) + ..add('pattern', pattern) ..add('help', help)) .toString(); } @@ -376,10 +476,26 @@ class EInvoiceElementEntityBuilder _$this._resource ??= new ListBuilder(); set resource(ListBuilder? resource) => _$this._resource = resource; + int? _minLength; + int? get minLength => _$this._minLength; + set minLength(int? minLength) => _$this._minLength = minLength; + int? _maxLength; int? get maxLength => _$this._maxLength; set maxLength(int? maxLength) => _$this._maxLength = maxLength; + int? _minOccurs; + int? get minOccurs => _$this._minOccurs; + set minOccurs(int? minOccurs) => _$this._minOccurs = minOccurs; + + int? _maxOccurs; + int? get maxOccurs => _$this._maxOccurs; + set maxOccurs(int? maxOccurs) => _$this._maxOccurs = maxOccurs; + + String? _pattern; + String? get pattern => _$this._pattern; + set pattern(String? pattern) => _$this._pattern = pattern; + String? _help; String? get help => _$this._help; set help(String? help) => _$this._help = help; @@ -392,7 +508,11 @@ class EInvoiceElementEntityBuilder _name = $v.name; _baseType = $v.baseType; _resource = $v.resource.toBuilder(); + _minLength = $v.minLength; _maxLength = $v.maxLength; + _minOccurs = $v.minOccurs; + _maxOccurs = $v.maxOccurs; + _pattern = $v.pattern; _help = $v.help; _$v = null; } @@ -423,10 +543,14 @@ class EInvoiceElementEntityBuilder baseType: BuiltValueNullFieldError.checkNotNull( baseType, r'EInvoiceElementEntity', 'baseType'), resource: resource.build(), - maxLength: BuiltValueNullFieldError.checkNotNull( - maxLength, r'EInvoiceElementEntity', 'maxLength'), - help: BuiltValueNullFieldError.checkNotNull( - help, r'EInvoiceElementEntity', 'help')); + minLength: minLength, + maxLength: maxLength, + minOccurs: BuiltValueNullFieldError.checkNotNull( + minOccurs, r'EInvoiceElementEntity', 'minOccurs'), + maxOccurs: BuiltValueNullFieldError.checkNotNull( + maxOccurs, r'EInvoiceElementEntity', 'maxOccurs'), + pattern: pattern, + help: help); } catch (_) { late String _$failedField; try { diff --git a/lib/data/models/serializers.dart b/lib/data/models/serializers.dart index 9f9b4bbd362..853d576db58 100644 --- a/lib/data/models/serializers.dart +++ b/lib/data/models/serializers.dart @@ -7,6 +7,7 @@ import 'package:built_value/standard_json_plugin.dart'; import 'package:invoiceninja_flutter/data/models/account_model.dart'; import 'package:invoiceninja_flutter/data/models/company_gateway_model.dart'; import 'package:invoiceninja_flutter/data/models/dashboard_model.dart'; +import 'package:invoiceninja_flutter/data/models/e_invoice_model.dart'; import 'package:invoiceninja_flutter/data/models/gateway_token_model.dart'; import 'package:invoiceninja_flutter/data/models/group_model.dart'; import 'package:invoiceninja_flutter/data/models/health_check_model.dart'; @@ -177,6 +178,7 @@ part 'serializers.g.dart'; UserTwoFactorResponse, PdfPreviewRequest, TaxDataEntity, + EInvoiceFieldEntity, ]) final Serializers serializers = (_$serializers.toBuilder()..addPlugin(StandardJsonPlugin())).build(); diff --git a/lib/data/models/serializers.g.dart b/lib/data/models/serializers.g.dart index 02e8ed30487..329362c9978 100644 --- a/lib/data/models/serializers.g.dart +++ b/lib/data/models/serializers.g.dart @@ -64,6 +64,8 @@ Serializers _$serializers = (new Serializers().toBuilder() ..add(DocumentListResponse.serializer) ..add(DocumentState.serializer) ..add(DocumentUIState.serializer) + ..add(EInvoiceElementEntity.serializer) + ..add(EInvoiceFieldEntity.serializer) ..add(EmailTemplate.serializer) ..add(EntityState.serializer) ..add(EntityType.serializer) @@ -316,6 +318,12 @@ Serializers _$serializers = (new Serializers().toBuilder() const FullType(BuiltMap, const [const FullType(String), const FullType(TemplateEntity)]), () => new MapBuilder()) + ..addBuilderFactory( + const FullType(BuiltMap, const [ + const FullType(String), + const FullType(EInvoiceFieldEntity) + ]), + () => new MapBuilder()) ..addBuilderFactory( const FullType(BuiltList, const [const FullType(DateFormatEntity)]), () => new ListBuilder()) @@ -572,11 +580,23 @@ Serializers _$serializers = (new Serializers().toBuilder() ..addBuilderFactory( const FullType(BuiltList, const [const FullType(String)]), () => new ListBuilder()) + ..addBuilderFactory( + const FullType(BuiltList, const [const FullType(String)]), + () => new ListBuilder()) ..addBuilderFactory( const FullType(BuiltList, const [ const FullType(BuiltList, const [const FullType(String)]) ]), () => new ListBuilder>()) + ..addBuilderFactory( + const FullType(BuiltList, const [const FullType(String)]), + () => new ListBuilder()) + ..addBuilderFactory( + const FullType(BuiltMap, const [ + const FullType(String), + const FullType(EInvoiceElementEntity) + ]), + () => new MapBuilder()) ..addBuilderFactory( const FullType(BuiltList, const [const FullType(SubscriptionEntity)]), () => new ListBuilder()) diff --git a/lib/data/models/static/static_data_model.dart b/lib/data/models/static/static_data_model.dart index 35d96fc9cf4..17eacfdd8c6 100644 --- a/lib/data/models/static/static_data_model.dart +++ b/lib/data/models/static/static_data_model.dart @@ -5,6 +5,7 @@ import 'package:built_value/serializer.dart'; // Project imports: import 'package:invoiceninja_flutter/data/models/company_model.dart'; +import 'package:invoiceninja_flutter/data/models/e_invoice_model.dart'; import 'package:invoiceninja_flutter/data/models/static/country_model.dart'; import 'package:invoiceninja_flutter/data/models/static/currency_model.dart'; import 'package:invoiceninja_flutter/data/models/static/date_format_model.dart'; @@ -88,6 +89,7 @@ abstract class StaticDataEntity invoiceStatus: BuiltList(), templates: BuiltMap(), bulkUpdates: BuiltMap>(), + eInvoiceSchema: BuiltMap(), ); } @@ -125,9 +127,13 @@ abstract class StaticDataEntity BuiltMap get templates; + @BuiltValueField(wireName: 'einvoice_schema') + BuiltMap get eInvoiceSchema; + // ignore: unused_element - static void _initializeBuilder(StaticDataEntityBuilder builder) => - builder..bulkUpdates.replace(BuiltMap>()); + static void _initializeBuilder(StaticDataEntityBuilder builder) => builder + ..bulkUpdates.replace(BuiltMap>()) + ..eInvoiceSchema.replace(BuiltMap()); static Serializer get serializer => _$staticDataEntitySerializer; diff --git a/lib/data/models/static/static_data_model.g.dart b/lib/data/models/static/static_data_model.g.dart index a733f2c03f9..37dd1addacd 100644 --- a/lib/data/models/static/static_data_model.g.dart +++ b/lib/data/models/static/static_data_model.g.dart @@ -172,6 +172,12 @@ class _$StaticDataEntitySerializer serializers.serialize(object.templates, specifiedType: const FullType(BuiltMap, const [const FullType(String), const FullType(TemplateEntity)])), + 'einvoice_schema', + serializers.serialize(object.eInvoiceSchema, + specifiedType: const FullType(BuiltMap, const [ + const FullType(String), + const FullType(EInvoiceFieldEntity) + ])), ]; return result; @@ -263,6 +269,13 @@ class _$StaticDataEntitySerializer const FullType(TemplateEntity) ]))!); break; + case 'einvoice_schema': + result.eInvoiceSchema.replace(serializers.deserialize(value, + specifiedType: const FullType(BuiltMap, const [ + const FullType(String), + const FullType(EInvoiceFieldEntity) + ]))!); + break; } } @@ -543,6 +556,8 @@ class _$StaticDataEntity extends StaticDataEntity { final BuiltMap> bulkUpdates; @override final BuiltMap templates; + @override + final BuiltMap eInvoiceSchema; factory _$StaticDataEntity( [void Function(StaticDataEntityBuilder)? updates]) => @@ -560,7 +575,8 @@ class _$StaticDataEntity extends StaticDataEntity { required this.countries, required this.invoiceStatus, required this.bulkUpdates, - required this.templates}) + required this.templates, + required this.eInvoiceSchema}) : super._() { BuiltValueNullFieldError.checkNotNull( currencies, r'StaticDataEntity', 'currencies'); @@ -585,6 +601,8 @@ class _$StaticDataEntity extends StaticDataEntity { bulkUpdates, r'StaticDataEntity', 'bulkUpdates'); BuiltValueNullFieldError.checkNotNull( templates, r'StaticDataEntity', 'templates'); + BuiltValueNullFieldError.checkNotNull( + eInvoiceSchema, r'StaticDataEntity', 'eInvoiceSchema'); } @override @@ -610,7 +628,8 @@ class _$StaticDataEntity extends StaticDataEntity { countries == other.countries && invoiceStatus == other.invoiceStatus && bulkUpdates == other.bulkUpdates && - templates == other.templates; + templates == other.templates && + eInvoiceSchema == other.eInvoiceSchema; } int? __hashCode; @@ -630,6 +649,7 @@ class _$StaticDataEntity extends StaticDataEntity { _$hash = $jc(_$hash, invoiceStatus.hashCode); _$hash = $jc(_$hash, bulkUpdates.hashCode); _$hash = $jc(_$hash, templates.hashCode); + _$hash = $jc(_$hash, eInvoiceSchema.hashCode); _$hash = $jf(_$hash); return __hashCode ??= _$hash; } @@ -648,7 +668,8 @@ class _$StaticDataEntity extends StaticDataEntity { ..add('countries', countries) ..add('invoiceStatus', invoiceStatus) ..add('bulkUpdates', bulkUpdates) - ..add('templates', templates)) + ..add('templates', templates) + ..add('eInvoiceSchema', eInvoiceSchema)) .toString(); } } @@ -728,6 +749,12 @@ class StaticDataEntityBuilder set templates(MapBuilder? templates) => _$this._templates = templates; + MapBuilder? _eInvoiceSchema; + MapBuilder get eInvoiceSchema => + _$this._eInvoiceSchema ??= new MapBuilder(); + set eInvoiceSchema(MapBuilder? eInvoiceSchema) => + _$this._eInvoiceSchema = eInvoiceSchema; + StaticDataEntityBuilder() { StaticDataEntity._initializeBuilder(this); } @@ -747,6 +774,7 @@ class StaticDataEntityBuilder _invoiceStatus = $v.invoiceStatus.toBuilder(); _bulkUpdates = $v.bulkUpdates.toBuilder(); _templates = $v.templates.toBuilder(); + _eInvoiceSchema = $v.eInvoiceSchema.toBuilder(); _$v = null; } return this; @@ -782,7 +810,8 @@ class StaticDataEntityBuilder countries: countries.build(), invoiceStatus: invoiceStatus.build(), bulkUpdates: bulkUpdates.build(), - templates: templates.build()); + templates: templates.build(), + eInvoiceSchema: eInvoiceSchema.build()); } catch (_) { late String _$failedField; try { @@ -810,6 +839,8 @@ class StaticDataEntityBuilder bulkUpdates.build(); _$failedField = 'templates'; templates.build(); + _$failedField = 'eInvoiceSchema'; + eInvoiceSchema.build(); } catch (e) { throw new BuiltValueNestedFieldError( r'StaticDataEntity', _$failedField, e.toString()); From aa213bfe3ad61648dd812bb62dbf93c29d6670d2 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 13 May 2024 12:02:53 +0300 Subject: [PATCH 4/6] e-invoice --- lib/data/models/serializers.g.dart | 6 +++++ lib/redux/static/static_reducer.dart | 1 + lib/redux/static/static_state.dart | 9 +++++-- lib/redux/static/static_state.g.dart | 39 +++++++++++++++++++++++++--- lib/ui/settings/device_settings.dart | 2 ++ 5 files changed, 51 insertions(+), 6 deletions(-) diff --git a/lib/data/models/serializers.g.dart b/lib/data/models/serializers.g.dart index 329362c9978..dfec141aeff 100644 --- a/lib/data/models/serializers.g.dart +++ b/lib/data/models/serializers.g.dart @@ -774,6 +774,12 @@ Serializers _$serializers = (new Serializers().toBuilder() const FullType(BuiltList, const [const FullType(String)]) ]), () => new MapBuilder>()) + ..addBuilderFactory( + const FullType(BuiltMap, const [ + const FullType(String), + const FullType(EInvoiceFieldEntity) + ]), + () => new MapBuilder()) ..addBuilderFactory( const FullType(BuiltMap, const [const FullType(String), const FullType(DesignEntity)]), diff --git a/lib/redux/static/static_reducer.dart b/lib/redux/static/static_reducer.dart index f25299d2a22..a49d327f96e 100644 --- a/lib/redux/static/static_reducer.dart +++ b/lib/redux/static/static_reducer.dart @@ -17,6 +17,7 @@ StaticState staticLoadedReducer( ..updatedAt = DateTime.now().millisecondsSinceEpoch ..templateMap.replace(data.templates) ..bulkUpdates.replace(data.bulkUpdates) + ..eInvoiceSchema.replace(data.eInvoiceSchema) ..currencyMap.addAll(Map.fromIterable( data.currencies, key: (dynamic item) => item.id, diff --git a/lib/redux/static/static_state.dart b/lib/redux/static/static_state.dart index ae10b048177..4c45acd8ea3 100644 --- a/lib/redux/static/static_state.dart +++ b/lib/redux/static/static_state.dart @@ -5,6 +5,7 @@ import 'package:built_value/serializer.dart'; // Project imports: import 'package:invoiceninja_flutter/constants.dart'; +import 'package:invoiceninja_flutter/data/models/e_invoice_model.dart'; import 'package:invoiceninja_flutter/data/models/models.dart'; part 'static_state.g.dart'; @@ -23,6 +24,7 @@ abstract class StaticState implements Built { countryMap: BuiltMap(), templateMap: BuiltMap(), bulkUpdates: BuiltMap>(), + eInvoiceSchema: BuiltMap(), ); } @@ -67,9 +69,12 @@ abstract class StaticState implements Built { BuiltMap> get bulkUpdates; + BuiltMap get eInvoiceSchema; + // ignore: unused_element - static void _initializeBuilder(StaticStateBuilder builder) => - builder..bulkUpdates.replace(BuiltMap>()); + static void _initializeBuilder(StaticStateBuilder builder) => builder + ..bulkUpdates.replace(BuiltMap>()) + ..eInvoiceSchema.replace(BuiltMap()); static Serializer get serializer => _$staticStateSerializer; } diff --git a/lib/redux/static/static_state.g.dart b/lib/redux/static/static_state.g.dart index 26ac5a1747d..2ec647bade7 100644 --- a/lib/redux/static/static_state.g.dart +++ b/lib/redux/static/static_state.g.dart @@ -68,6 +68,12 @@ class _$StaticStateSerializer implements StructuredSerializer { const FullType(String), const FullType(BuiltList, const [const FullType(String)]) ])), + 'eInvoiceSchema', + serializers.serialize(object.eInvoiceSchema, + specifiedType: const FullType(BuiltMap, const [ + const FullType(String), + const FullType(EInvoiceFieldEntity) + ])), ]; Object? value; value = object.updatedAt; @@ -171,6 +177,13 @@ class _$StaticStateSerializer implements StructuredSerializer { const FullType(BuiltList, const [const FullType(String)]) ]))!); break; + case 'eInvoiceSchema': + result.eInvoiceSchema.replace(serializers.deserialize(value, + specifiedType: const FullType(BuiltMap, const [ + const FullType(String), + const FullType(EInvoiceFieldEntity) + ]))!); + break; } } @@ -203,6 +216,8 @@ class _$StaticState extends StaticState { final BuiltMap templateMap; @override final BuiltMap> bulkUpdates; + @override + final BuiltMap eInvoiceSchema; factory _$StaticState([void Function(StaticStateBuilder)? updates]) => (new StaticStateBuilder()..update(updates))._build(); @@ -219,7 +234,8 @@ class _$StaticState extends StaticState { required this.paymentTypeMap, required this.countryMap, required this.templateMap, - required this.bulkUpdates}) + required this.bulkUpdates, + required this.eInvoiceSchema}) : super._() { BuiltValueNullFieldError.checkNotNull( currencyMap, r'StaticState', 'currencyMap'); @@ -242,6 +258,8 @@ class _$StaticState extends StaticState { templateMap, r'StaticState', 'templateMap'); BuiltValueNullFieldError.checkNotNull( bulkUpdates, r'StaticState', 'bulkUpdates'); + BuiltValueNullFieldError.checkNotNull( + eInvoiceSchema, r'StaticState', 'eInvoiceSchema'); } @override @@ -266,7 +284,8 @@ class _$StaticState extends StaticState { paymentTypeMap == other.paymentTypeMap && countryMap == other.countryMap && templateMap == other.templateMap && - bulkUpdates == other.bulkUpdates; + bulkUpdates == other.bulkUpdates && + eInvoiceSchema == other.eInvoiceSchema; } int? __hashCode; @@ -286,6 +305,7 @@ class _$StaticState extends StaticState { _$hash = $jc(_$hash, countryMap.hashCode); _$hash = $jc(_$hash, templateMap.hashCode); _$hash = $jc(_$hash, bulkUpdates.hashCode); + _$hash = $jc(_$hash, eInvoiceSchema.hashCode); _$hash = $jf(_$hash); return __hashCode ??= _$hash; } @@ -304,7 +324,8 @@ class _$StaticState extends StaticState { ..add('paymentTypeMap', paymentTypeMap) ..add('countryMap', countryMap) ..add('templateMap', templateMap) - ..add('bulkUpdates', bulkUpdates)) + ..add('bulkUpdates', bulkUpdates) + ..add('eInvoiceSchema', eInvoiceSchema)) .toString(); } } @@ -382,6 +403,12 @@ class StaticStateBuilder implements Builder { set bulkUpdates(MapBuilder>? bulkUpdates) => _$this._bulkUpdates = bulkUpdates; + MapBuilder? _eInvoiceSchema; + MapBuilder get eInvoiceSchema => + _$this._eInvoiceSchema ??= new MapBuilder(); + set eInvoiceSchema(MapBuilder? eInvoiceSchema) => + _$this._eInvoiceSchema = eInvoiceSchema; + StaticStateBuilder() { StaticState._initializeBuilder(this); } @@ -401,6 +428,7 @@ class StaticStateBuilder implements Builder { _countryMap = $v.countryMap.toBuilder(); _templateMap = $v.templateMap.toBuilder(); _bulkUpdates = $v.bulkUpdates.toBuilder(); + _eInvoiceSchema = $v.eInvoiceSchema.toBuilder(); _$v = null; } return this; @@ -436,7 +464,8 @@ class StaticStateBuilder implements Builder { paymentTypeMap: paymentTypeMap.build(), countryMap: countryMap.build(), templateMap: templateMap.build(), - bulkUpdates: bulkUpdates.build()); + bulkUpdates: bulkUpdates.build(), + eInvoiceSchema: eInvoiceSchema.build()); } catch (_) { late String _$failedField; try { @@ -462,6 +491,8 @@ class StaticStateBuilder implements Builder { templateMap.build(); _$failedField = 'bulkUpdates'; bulkUpdates.build(); + _$failedField = 'eInvoiceSchema'; + eInvoiceSchema.build(); } catch (e) { throw new BuiltValueNestedFieldError( r'StaticState', _$failedField, e.toString()); diff --git a/lib/ui/settings/device_settings.dart b/lib/ui/settings/device_settings.dart index 0707724cdec..7f11342b0cb 100644 --- a/lib/ui/settings/device_settings.dart +++ b/lib/ui/settings/device_settings.dart @@ -122,6 +122,8 @@ class _DeviceSettingsState extends State final state = viewModel.state; final prefState = state.prefState; + //print('## e-invoice: ${state.staticState.}'); + /* final countSessions = state.tokenState.list .map((tokenId) => state.tokenState.map[tokenId]) From a9b737cc593a16f2ed8f9c194108d6693ecf0e3d Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 13 May 2024 12:04:09 +0300 Subject: [PATCH 5/6] e-invoice --- lib/ui/settings/device_settings.dart | 2 -- 1 file changed, 2 deletions(-) diff --git a/lib/ui/settings/device_settings.dart b/lib/ui/settings/device_settings.dart index 7f11342b0cb..0707724cdec 100644 --- a/lib/ui/settings/device_settings.dart +++ b/lib/ui/settings/device_settings.dart @@ -122,8 +122,6 @@ class _DeviceSettingsState extends State final state = viewModel.state; final prefState = state.prefState; - //print('## e-invoice: ${state.staticState.}'); - /* final countSessions = state.tokenState.list .map((tokenId) => state.tokenState.map[tokenId]) From 0c6498a59a402042ad8c5bc3d4f4784c07295bf9 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Tue, 14 May 2024 12:52:55 +0300 Subject: [PATCH 6/6] Fix for invoice/credit check on new payment screen --- lib/ui/payment/edit/payment_edit_vm.dart | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/lib/ui/payment/edit/payment_edit_vm.dart b/lib/ui/payment/edit/payment_edit_vm.dart index bb2d3e7a6a0..2d8168b9c7a 100644 --- a/lib/ui/payment/edit/payment_edit_vm.dart +++ b/lib/ui/payment/edit/payment_edit_vm.dart @@ -7,6 +7,7 @@ import 'package:flutter/material.dart'; // Package imports: import 'package:flutter_redux/flutter_redux.dart'; import 'package:flutter_styled_toast/flutter_styled_toast.dart'; +import 'package:invoiceninja_flutter/utils/formatting.dart'; import 'package:redux/redux.dart'; // Project imports: @@ -79,12 +80,21 @@ class PaymentEditVM { }, onSavePressed: (BuildContext context) { Debouncer.runOnComplete(() { - final payment = store.state.paymentUIState.editing!; + final state = store.state; + final payment = state.paymentUIState.editing!; + final client = state.clientState.get(payment.clientId); + final currency = state.staticState.currencyMap[client.currencyId]!; final localization = navigatorKey.localization!; final navigator = navigatorKey.currentState; + double amount = 0; - payment.invoices.forEach((invoice) => amount += invoice.amount); - payment.credits.forEach((credit) => amount -= credit.amount); + payment.invoices.forEach((invoice) { + amount = round(amount + invoice.amount, currency.precision); + }); + payment.credits.forEach((credit) { + amount = round(amount - credit.amount, currency.precision); + }); + if (amount < 0) { showDialog( context: navigatorKey.currentContext!,