Tax model

This commit is contained in:
Hillel Coren 2023-04-18 18:27:29 +03:00
parent 9fd6481417
commit ad1a072a80
1 changed files with 92 additions and 96 deletions

View File

@ -195,8 +195,7 @@ class _TaxSettingsState extends State<TaxSettings> {
SizedBox(height: 12), SizedBox(height: 12),
...taxData.regions.keys.map((region) { ...taxData.regions.keys.map((region) {
final taxDataRegion = taxData.regions[region]; final taxDataRegion = taxData.regions[region];
return Column( return Column(children: [
children: [
Padding( Padding(
padding: const EdgeInsets.symmetric(vertical: 4), padding: const EdgeInsets.symmetric(vertical: 4),
child: Row( child: Row(
@ -208,8 +207,8 @@ class _TaxSettingsState extends State<TaxSettings> {
child: AppDropdownButton<bool>( child: AppDropdownButton<bool>(
value: taxDataRegion.taxAll, value: taxDataRegion.taxAll,
onChanged: (dynamic value) { onChanged: (dynamic value) {
viewModel.onCompanyChanged( viewModel.onCompanyChanged(company.rebuild(
company.rebuild((b) => b (b) => b
..taxData.regions[region] = ..taxData.regions[region] =
taxDataRegion.rebuild( taxDataRegion.rebuild(
(b) => b..taxAll = value))); (b) => b..taxAll = value)));
@ -249,15 +248,24 @@ class _TaxSettingsState extends State<TaxSettings> {
], ],
), ),
), ),
if (_showDetails[region]) if (_showDetails[region]) ...[
SizedBox(height: 8),
...taxDataRegion.subregions.keys.map((subregion) { ...taxDataRegion.subregions.keys.map((subregion) {
final taxDataSubregion = final taxDataSubregion =
taxDataRegion.subregions[subregion]; taxDataRegion.subregions[subregion];
return Padding( return Row(
padding: const EdgeInsets.all(8),
child: Row(
children: [ children: [
Checkbox( Expanded(
child: CheckboxListTile(
title: Text(region == kTaxRegionUnitedStates
? subregion
: (countryMap[subregion]?.name ??
subregion)),
subtitle: Text(
'${taxDataSubregion.taxName}: ${formatNumber(taxDataSubregion.taxRate, context, formatNumberType: FormatNumberType.percent) + (taxDataSubregion.reducedTaxRate != 0 ? '' + formatNumber(taxDataSubregion.reducedTaxRate, context, formatNumberType: FormatNumberType.percent) : '')}',
),
controlAffinity:
ListTileControlAffinity.leading,
value: taxDataRegion.taxAll || value: taxDataRegion.taxAll ||
taxDataSubregion.applyTax, taxDataSubregion.applyTax,
onChanged: taxDataRegion.taxAll onChanged: taxDataRegion.taxAll
@ -268,34 +276,22 @@ class _TaxSettingsState extends State<TaxSettings> {
..regions[region] = ..regions[region] =
taxDataRegion.rebuild((b) => b taxDataRegion.rebuild((b) => b
..subregions[subregion] = ..subregions[subregion] =
taxDataSubregion.rebuild((b) => b taxDataSubregion.rebuild(
..applyTax = (b) => b
value)))))); ..applyTax = value))))));
}), },
SizedBox(width: 8),
Expanded(
child: Text(region == kTaxRegionUnitedStates
? subregion
: (countryMap[subregion]?.name ??
subregion)),
),
Expanded(
child: Text(
'${taxDataSubregion.taxName}: ${formatNumber(taxDataSubregion.taxRate, context, formatNumberType: FormatNumberType.percent)}',
), ),
), ),
Expanded( TextButton(
child: Text( onPressed: () {
taxDataSubregion.reducedTaxRate != 0 //
? '${localization.reducedRate}: ${formatNumber(taxDataSubregion.reducedTaxRate, context, formatNumberType: FormatNumberType.percent)}' },
: '', child: Text(localization.edit))
)),
], ],
),
); );
}).toList(), }).toList(),
], ],
); ]);
}).toList(), }).toList(),
] ]
], ],