Tax model

This commit is contained in:
Hillel Coren 2023-04-18 15:06:55 +03:00
parent a51787bf14
commit f0b6174e91
4 changed files with 66 additions and 13 deletions

View File

@ -649,6 +649,10 @@ const String kDefaultLightSelectedColorMenu = '#f2faff';
const String kDefaultLightSelectedColor = '#e5f5ff'; const String kDefaultLightSelectedColor = '#e5f5ff';
const String kDefaultLightBorderColor = '#dfdfdf'; const String kDefaultLightBorderColor = '#dfdfdf';
const String kTaxRegionUnitedStates = 'US';
const String kTaxRegionEurope = 'EU';
const String kTaxRegionAustralia = 'AU';
const String kReportGroupDay = 'day'; const String kReportGroupDay = 'day';
const String kReportGroupWeek = 'week'; const String kReportGroupWeek = 'week';
const String kReportGroupMonth = 'month'; const String kReportGroupMonth = 'month';

View File

@ -20,6 +20,19 @@ List<String> countryList(BuiltMap<String, CountryEntity> countryMap) {
return list; return list;
} }
var memoizedCountryIso2Map = memo1(
(BuiltMap<String, CountryEntity> countryMap) => countryIso2Map(countryMap));
Map<String, CountryEntity> countryIso2Map(
BuiltMap<String, CountryEntity> countryMap) {
final map = <String, CountryEntity>{};
countryMap.keys.forEach((countryId) {
final country = countryMap[countryId];
map[country.iso2] = country;
});
return map;
}
var memoizedGroupList = var memoizedGroupList =
memo1((BuiltMap<String, GroupEntity> groupMap) => groupList(groupMap)); memo1((BuiltMap<String, GroupEntity> groupMap) => groupList(groupMap));

View File

@ -1,6 +1,7 @@
// Flutter imports: // Flutter imports:
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:invoiceninja_flutter/constants.dart'; import 'package:invoiceninja_flutter/constants.dart';
import 'package:invoiceninja_flutter/redux/static/static_selectors.dart';
// Package imports: // Package imports:
import 'package:material_design_icons_flutter/material_design_icons_flutter.dart'; import 'package:material_design_icons_flutter/material_design_icons_flutter.dart';
@ -32,6 +33,11 @@ class _TaxSettingsState extends State<TaxSettings> {
static final GlobalKey<FormState> _formKey = static final GlobalKey<FormState> _formKey =
GlobalKey<FormState>(debugLabel: '_taxSettings'); GlobalKey<FormState>(debugLabel: '_taxSettings');
FocusScopeNode _focusNode; FocusScopeNode _focusNode;
final Map<String, bool> _showDetails = {
kTaxRegionUnitedStates: false,
kTaxRegionEurope: false,
kTaxRegionAustralia: false,
};
@override @override
void initState() { void initState() {
@ -54,12 +60,13 @@ class _TaxSettingsState extends State<TaxSettings> {
final state = viewModel.state; final state = viewModel.state;
final taxData = company.taxData; final taxData = company.taxData;
final countryMap = memoizedCountryIso2Map(state.staticState.countryMap);
List<String> subregions = []; List<String> subregions = [];
String region = 'EU'; String region = kTaxRegionEurope;
if (company.settings.countryId == kCountryUnitedStates) { if (company.settings.countryId == kCountryUnitedStates) {
region = 'US'; region = kTaxRegionUnitedStates;
} else if (company.settings.countryId == kCountryAustralia) { } else if (company.settings.countryId == kCountryAustralia) {
region = 'AU'; region = kTaxRegionAustralia;
} }
subregions = taxData.regions[region].subregions.keys.toList(); subregions = taxData.regions[region].subregions.keys.toList();
@ -179,18 +186,37 @@ class _TaxSettingsState extends State<TaxSettings> {
.map((code) => .map((code) =>
DropdownMenuItem(child: Text(code), value: code)) DropdownMenuItem(child: Text(code), value: code))
.toList()), .toList()),
...taxData.regions.keys SizedBox(height: 12),
.map((region) => Column( ...taxData.regions.keys.map((region) {
return Column(
children: [
Padding(
padding: const EdgeInsets.symmetric(vertical: 8),
child: Row(
children: [ children: [
Text(region), Expanded(
/* child:
...taxData.regions[region].subregions.keys Text(countryMap[region]?.name ?? region)),
.map((subregion) => Text(subregion)) TextButton(
.toList(), onPressed: () {
*/ setState(() {
_showDetails[region] =
!_showDetails[region];
});
},
child: Text(_showDetails[region]
? localization.hideDetails
: localization.showDetails))
], ],
)) ),
.toList(), ),
if (_showDetails[region])
...taxData.regions[region].subregions.keys
.map((subregion) => Text(subregion))
.toList(),
],
);
}).toList(),
] ]
], ],
) )

View File

@ -18,6 +18,8 @@ mixin LocalizationsProvider on LocaleCodeAware {
static final Map<String, Map<String, String>> _localizedValues = { static final Map<String, Map<String, String>> _localizedValues = {
'en': { 'en': {
// STARTER: lang key - do not remove comment // STARTER: lang key - do not remove comment
'hide_details': 'Hide Details',
'show_details': 'Show Details',
'version': 'version', 'version': 'version',
'seller_subregion': 'Seller Subregion', 'seller_subregion': 'Seller Subregion',
'calculate_taxes': 'Calculate Taxes', 'calculate_taxes': 'Calculate Taxes',
@ -98328,6 +98330,14 @@ mixin LocalizationsProvider on LocaleCodeAware {
_localizedValues[localeCode]['version'] ?? _localizedValues[localeCode]['version'] ??
_localizedValues['en']['version']; _localizedValues['en']['version'];
String get hideDetails =>
_localizedValues[localeCode]['hide_details'] ??
_localizedValues['en']['hide_details'];
String get showDetails =>
_localizedValues[localeCode]['show_details'] ??
_localizedValues['en']['show_details'];
// STARTER: lang field - do not remove comment // STARTER: lang field - do not remove comment
String lookup(String key) { String lookup(String key) {