From 4dc4c624f4c03acdf797e13a6efb052c7a07edfb Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Wed, 6 Nov 2019 17:43:25 +0200 Subject: [PATCH] Settings --- lib/data/models/company_model.dart | 4 ---- lib/data/models/company_model.g.dart | 24 +----------------------- lib/ui/settings/localization_vm.dart | 2 +- lib/ui/settings/tax_settings.dart | 27 ++++++++++++++++++++++++++- lib/ui/settings/tax_settings_vm.dart | 8 ++++++++ lib/utils/i18n.dart | 17 +++++++++++++++-- 6 files changed, 51 insertions(+), 31 deletions(-) diff --git a/lib/data/models/company_model.dart b/lib/data/models/company_model.dart index b5601f5f2..69f139a1d 100644 --- a/lib/data/models/company_model.dart +++ b/lib/data/models/company_model.dart @@ -736,10 +736,6 @@ abstract class SettingsEntity @BuiltValueField(wireName: 'invoice_labels') String get invoiceLabels; - @nullable - @BuiltValueField(wireName: 'show_item_taxes') - bool get showInvoiceItemTaxes; - @nullable @BuiltValueField(wireName: 'tax_name1') String get defaultTaxName1; diff --git a/lib/data/models/company_model.g.dart b/lib/data/models/company_model.g.dart index 659a2c40d..b2b23000e 100644 --- a/lib/data/models/company_model.g.dart +++ b/lib/data/models/company_model.g.dart @@ -1071,12 +1071,6 @@ class _$SettingsEntitySerializer ..add(serializers.serialize(object.invoiceLabels, specifiedType: const FullType(String))); } - if (object.showInvoiceItemTaxes != null) { - result - ..add('show_item_taxes') - ..add(serializers.serialize(object.showInvoiceItemTaxes, - specifiedType: const FullType(bool))); - } if (object.defaultTaxName1 != null) { result ..add('tax_name1') @@ -1812,10 +1806,6 @@ class _$SettingsEntitySerializer result.invoiceLabels = serializers.deserialize(value, specifiedType: const FullType(String)) as String; break; - case 'show_item_taxes': - result.showInvoiceItemTaxes = serializers.deserialize(value, - specifiedType: const FullType(bool)) as bool; - break; case 'tax_name1': result.defaultTaxName1 = serializers.deserialize(value, specifiedType: const FullType(String)) as String; @@ -3352,8 +3342,6 @@ class _$SettingsEntity extends SettingsEntity { @override final String invoiceLabels; @override - final bool showInvoiceItemTaxes; - @override final String defaultTaxName1; @override final double defaultTaxRate1; @@ -3575,7 +3563,6 @@ class _$SettingsEntity extends SettingsEntity { this.defaultQuoteDesignId, this.defaultInvoiceFooter, this.invoiceLabels, - this.showInvoiceItemTaxes, this.defaultTaxName1, this.defaultTaxRate1, this.defaultTaxName2, @@ -3731,7 +3718,6 @@ class _$SettingsEntity extends SettingsEntity { defaultQuoteDesignId == other.defaultQuoteDesignId && defaultInvoiceFooter == other.defaultInvoiceFooter && invoiceLabels == other.invoiceLabels && - showInvoiceItemTaxes == other.showInvoiceItemTaxes && defaultTaxName1 == other.defaultTaxName1 && defaultTaxRate1 == other.defaultTaxRate1 && defaultTaxName2 == other.defaultTaxName2 && @@ -3830,7 +3816,7 @@ class _$SettingsEntity extends SettingsEntity { $jc( $jc( $jc( - $jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc(0, timezoneId.hashCode), dateFormatId.hashCode), enableMilitaryTime.hashCode), languageId.hashCode), showCurrencyCode.hashCode), currencyId.hashCode), customValue1.hashCode), customValue2.hashCode), customValue3.hashCode), customValue4.hashCode), defaultPaymentTerms.hashCode), companyGatewayIds.hashCode), defaultTaskRate.hashCode), sendReminders.hashCode), showTasksInPortal.hashCode), emailStyle.hashCode), replyToEmail.hashCode), bccEmail.hashCode), pdfEmailAttachment.hashCode), ublEmailAttachment.hashCode), documentEmailAttachment.hashCode), emailStyleCustom.hashCode), customMessageDashboard.hashCode), customMessageUnpaidInvoice.hashCode), customMessagePaidInvoice.hashCode), customMessageUnapprovedQuote.hashCode), lockSentInvoices.hashCode), autoArchiveInvoice.hashCode), autoArchiveQuote.hashCode), autoEmailInvoice.hashCode), autoConvertQuote.hashCode), enableInclusiveTaxes.hashCode), translations.hashCode), taskNumberPattern.hashCode), taskNumberCounter.hashCode), expenseNumberPattern.hashCode), expenseNumberCounter.hashCode), vendorNumberPattern.hashCode), vendorNumberCounter.hashCode), ticketNumberPattern.hashCode), ticketNumberCounter.hashCode), paymentNumberPattern.hashCode), paymentNumberCounter.hashCode), invoiceNumberPattern.hashCode), invoiceNumberCounter.hashCode), quoteNumberPattern.hashCode), quoteNumberCounter.hashCode), clientNumberPattern.hashCode), clientNumberCounter.hashCode), creditNumberPattern.hashCode), creditNumberCounter.hashCode), recurringInvoiceNumberPrefix.hashCode), resetCounterFrequencyId.hashCode), resetCounterDate.hashCode), counterPadding.hashCode), sharedInvoiceQuoteCounter.hashCode), defaultInvoiceTerms.hashCode), defaultQuoteTerms.hashCode), defaultQuoteFooter.hashCode), enableInvoiceTaxes.hashCode), enableInvoiceItemTaxes.hashCode), defaultInvoiceDesignId.hashCode), defaultQuoteDesignId.hashCode), defaultInvoiceFooter.hashCode), invoiceLabels.hashCode), showInvoiceItemTaxes.hashCode), defaultTaxName1.hashCode), defaultTaxRate1.hashCode), defaultTaxName2.hashCode), defaultTaxRate2.hashCode), defaultTaxName3.hashCode), defaultTaxRate3.hashCode), defaultPaymentTypeId.hashCode), enableSecondTaxRate.hashCode), invoiceFields.hashCode), emailFooter.hashCode), emailSubjectInvoice.hashCode), emailSubjectQuote.hashCode), emailSubjectPayment.hashCode), emailBodyInvoice.hashCode), emailBodyQuote.hashCode), emailBodyPayment.hashCode), emailSubjectReminder1.hashCode), emailSubjectReminder2.hashCode), emailSubjectReminder3.hashCode), emailBodyReminder1.hashCode), emailBodyReminder2.hashCode), emailBodyReminder3.hashCode), enablePortalPassword.hashCode), sendPortalPassword.hashCode), signatureOnPdf.hashCode), enableEmailMarkup.hashCode), showAcceptInvoiceTerms.hashCode), showAcceptQuoteTerms.hashCode), requireInvoiceSignature.hashCode), requireQuoteSignature.hashCode), name.hashCode), companyLogo.hashCode), website.hashCode), address1.hashCode), address2.hashCode), city.hashCode), state.hashCode), postalCode.hashCode), phone.hashCode), email.hashCode), countryId.hashCode), vatNumber.hashCode), idNumber.hashCode), pageSize.hashCode), fontSize.hashCode), primaryColor.hashCode), secondaryColor.hashCode), primaryFont.hashCode), secondaryFont.hashCode), hidePaidToDate.hashCode), embedDocuments.hashCode), allPagesHeader.hashCode), allPagesFooter.hashCode), enableReminder1.hashCode), enableReminder2.hashCode), enableReminder3.hashCode), enableReminder4.hashCode), + $jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc($jc(0, timezoneId.hashCode), dateFormatId.hashCode), enableMilitaryTime.hashCode), languageId.hashCode), showCurrencyCode.hashCode), currencyId.hashCode), customValue1.hashCode), customValue2.hashCode), customValue3.hashCode), customValue4.hashCode), defaultPaymentTerms.hashCode), companyGatewayIds.hashCode), defaultTaskRate.hashCode), sendReminders.hashCode), showTasksInPortal.hashCode), emailStyle.hashCode), replyToEmail.hashCode), bccEmail.hashCode), pdfEmailAttachment.hashCode), ublEmailAttachment.hashCode), documentEmailAttachment.hashCode), emailStyleCustom.hashCode), customMessageDashboard.hashCode), customMessageUnpaidInvoice.hashCode), customMessagePaidInvoice.hashCode), customMessageUnapprovedQuote.hashCode), lockSentInvoices.hashCode), autoArchiveInvoice.hashCode), autoArchiveQuote.hashCode), autoEmailInvoice.hashCode), autoConvertQuote.hashCode), enableInclusiveTaxes.hashCode), translations.hashCode), taskNumberPattern.hashCode), taskNumberCounter.hashCode), expenseNumberPattern.hashCode), expenseNumberCounter.hashCode), vendorNumberPattern.hashCode), vendorNumberCounter.hashCode), ticketNumberPattern.hashCode), ticketNumberCounter.hashCode), paymentNumberPattern.hashCode), paymentNumberCounter.hashCode), invoiceNumberPattern.hashCode), invoiceNumberCounter.hashCode), quoteNumberPattern.hashCode), quoteNumberCounter.hashCode), clientNumberPattern.hashCode), clientNumberCounter.hashCode), creditNumberPattern.hashCode), creditNumberCounter.hashCode), recurringInvoiceNumberPrefix.hashCode), resetCounterFrequencyId.hashCode), resetCounterDate.hashCode), counterPadding.hashCode), sharedInvoiceQuoteCounter.hashCode), defaultInvoiceTerms.hashCode), defaultQuoteTerms.hashCode), defaultQuoteFooter.hashCode), enableInvoiceTaxes.hashCode), enableInvoiceItemTaxes.hashCode), defaultInvoiceDesignId.hashCode), defaultQuoteDesignId.hashCode), defaultInvoiceFooter.hashCode), invoiceLabels.hashCode), defaultTaxName1.hashCode), defaultTaxRate1.hashCode), defaultTaxName2.hashCode), defaultTaxRate2.hashCode), defaultTaxName3.hashCode), defaultTaxRate3.hashCode), defaultPaymentTypeId.hashCode), enableSecondTaxRate.hashCode), invoiceFields.hashCode), emailFooter.hashCode), emailSubjectInvoice.hashCode), emailSubjectQuote.hashCode), emailSubjectPayment.hashCode), emailBodyInvoice.hashCode), emailBodyQuote.hashCode), emailBodyPayment.hashCode), emailSubjectReminder1.hashCode), emailSubjectReminder2.hashCode), emailSubjectReminder3.hashCode), emailBodyReminder1.hashCode), emailBodyReminder2.hashCode), emailBodyReminder3.hashCode), enablePortalPassword.hashCode), sendPortalPassword.hashCode), signatureOnPdf.hashCode), enableEmailMarkup.hashCode), showAcceptInvoiceTerms.hashCode), showAcceptQuoteTerms.hashCode), requireInvoiceSignature.hashCode), requireQuoteSignature.hashCode), name.hashCode), companyLogo.hashCode), website.hashCode), address1.hashCode), address2.hashCode), city.hashCode), state.hashCode), postalCode.hashCode), phone.hashCode), email.hashCode), countryId.hashCode), vatNumber.hashCode), idNumber.hashCode), pageSize.hashCode), fontSize.hashCode), primaryColor.hashCode), secondaryColor.hashCode), primaryFont.hashCode), secondaryFont.hashCode), hidePaidToDate.hashCode), embedDocuments.hashCode), allPagesHeader.hashCode), allPagesFooter.hashCode), enableReminder1.hashCode), enableReminder2.hashCode), enableReminder3.hashCode), enableReminder4.hashCode), numDaysReminder1.hashCode), numDaysReminder2.hashCode), numDaysReminder3.hashCode), @@ -3920,7 +3906,6 @@ class _$SettingsEntity extends SettingsEntity { ..add('defaultQuoteDesignId', defaultQuoteDesignId) ..add('defaultInvoiceFooter', defaultInvoiceFooter) ..add('invoiceLabels', invoiceLabels) - ..add('showInvoiceItemTaxes', showInvoiceItemTaxes) ..add('defaultTaxName1', defaultTaxName1) ..add('defaultTaxRate1', defaultTaxRate1) ..add('defaultTaxName2', defaultTaxName2) @@ -4322,11 +4307,6 @@ class SettingsEntityBuilder set invoiceLabels(String invoiceLabels) => _$this._invoiceLabels = invoiceLabels; - bool _showInvoiceItemTaxes; - bool get showInvoiceItemTaxes => _$this._showInvoiceItemTaxes; - set showInvoiceItemTaxes(bool showInvoiceItemTaxes) => - _$this._showInvoiceItemTaxes = showInvoiceItemTaxes; - String _defaultTaxName1; String get defaultTaxName1 => _$this._defaultTaxName1; set defaultTaxName1(String defaultTaxName1) => @@ -4759,7 +4739,6 @@ class SettingsEntityBuilder _defaultQuoteDesignId = _$v.defaultQuoteDesignId; _defaultInvoiceFooter = _$v.defaultInvoiceFooter; _invoiceLabels = _$v.invoiceLabels; - _showInvoiceItemTaxes = _$v.showInvoiceItemTaxes; _defaultTaxName1 = _$v.defaultTaxName1; _defaultTaxRate1 = _$v.defaultTaxRate1; _defaultTaxName2 = _$v.defaultTaxName2; @@ -4925,7 +4904,6 @@ class SettingsEntityBuilder defaultQuoteDesignId: defaultQuoteDesignId, defaultInvoiceFooter: defaultInvoiceFooter, invoiceLabels: invoiceLabels, - showInvoiceItemTaxes: showInvoiceItemTaxes, defaultTaxName1: defaultTaxName1, defaultTaxRate1: defaultTaxRate1, defaultTaxName2: defaultTaxName2, diff --git a/lib/ui/settings/localization_vm.dart b/lib/ui/settings/localization_vm.dart index c1a8376d5..f57eea5ff 100644 --- a/lib/ui/settings/localization_vm.dart +++ b/lib/ui/settings/localization_vm.dart @@ -79,8 +79,8 @@ class LocalizationSettingsVM { final AppState state; final CompanyEntity company; - final SettingsEntity settings; final Function(CompanyEntity) onCompanyChanged; + final SettingsEntity settings; final Function(SettingsEntity) onSettingsChanged; final Function(BuildContext) onSavePressed; final Function(BuildContext) onCancelPressed; diff --git a/lib/ui/settings/tax_settings.dart b/lib/ui/settings/tax_settings.dart index ca80d70c6..a5e4cc29c 100644 --- a/lib/ui/settings/tax_settings.dart +++ b/lib/ui/settings/tax_settings.dart @@ -1,8 +1,10 @@ import 'package:flutter/foundation.dart'; import 'package:flutter/material.dart'; +import 'package:font_awesome_flutter/font_awesome_flutter.dart'; import 'package:invoiceninja_flutter/ui/app/buttons/elevated_button.dart'; import 'package:invoiceninja_flutter/ui/app/form_card.dart'; import 'package:invoiceninja_flutter/ui/app/forms/app_form.dart'; +import 'package:invoiceninja_flutter/ui/app/forms/bool_dropdown_button.dart'; import 'package:invoiceninja_flutter/ui/settings/settings_scaffold.dart'; import 'package:invoiceninja_flutter/ui/settings/tax_settings_vm.dart'; import 'package:invoiceninja_flutter/utils/localization.dart'; @@ -26,6 +28,7 @@ class _TaxSettingsState extends State { Widget build(BuildContext context) { final localization = AppLocalization.of(context); final viewModel = widget.viewModel; + final settings = viewModel.settings; return SettingsScaffold( title: localization.taxSettings, @@ -34,7 +37,29 @@ class _TaxSettingsState extends State { formKey: _formKey, children: [ FormCard( - children: [], + children: [ + BoolDropdownButton( + iconData: FontAwesomeIcons.fileInvoice, + label: localization.invoiceTax, + value: settings.enableInvoiceTaxes, + onChanged: (value) => viewModel.onSettingsChanged( + settings.rebuild((b) => b..enableInvoiceTaxes = value)), + ), + BoolDropdownButton( + iconData: FontAwesomeIcons.cubes, + label: localization.lineItemTax, + value: settings.enableInvoiceItemTaxes, + onChanged: (value) => viewModel.onSettingsChanged( + settings.rebuild((b) => b..enableInvoiceItemTaxes = value)), + ), + BoolDropdownButton( + iconData: FontAwesomeIcons.percent, + label: localization.inclusiveTaxes, + value: settings.enableInclusiveTaxes, + onChanged: (value) => viewModel.onSettingsChanged( + settings.rebuild((b) => b..enableInclusiveTaxes = value)), + ), + ], ), Padding( padding: const EdgeInsets.symmetric(horizontal: 16.0), diff --git a/lib/ui/settings/tax_settings_vm.dart b/lib/ui/settings/tax_settings_vm.dart index a6437b87a..d20cc4d55 100644 --- a/lib/ui/settings/tax_settings_vm.dart +++ b/lib/ui/settings/tax_settings_vm.dart @@ -32,6 +32,8 @@ class TaxSettingsVM { TaxSettingsVM({ @required this.state, @required this.company, + @required this.settings, + @required this.onSettingsChanged, @required this.onCompanyChanged, @required this.onSavePressed, @required this.onCancelPressed, @@ -43,7 +45,11 @@ class TaxSettingsVM { return TaxSettingsVM( state: state, + settings: state.uiState.settingsUIState.settings, company: state.uiState.settingsUIState.userCompany.company, + onSettingsChanged: (settings) { + store.dispatch(UpdateSettings(settings: settings)); + }, onCompanyChanged: (company) => store.dispatch(UpdateCompany(company: company)), onCancelPressed: (context) => store.dispatch(ResetSettings()), @@ -63,6 +69,8 @@ class TaxSettingsVM { final AppState state; final Function(BuildContext) onSavePressed; final Function(BuildContext) onCancelPressed; + final SettingsEntity settings; + final Function(SettingsEntity) onSettingsChanged; final CompanyEntity company; final Function(CompanyEntity) onCompanyChanged; final Function(BuildContext) onConfigureRatesPressed; diff --git a/lib/utils/i18n.dart b/lib/utils/i18n.dart index 81ba5d572..11ca167fe 100644 --- a/lib/utils/i18n.dart +++ b/lib/utils/i18n.dart @@ -14,6 +14,10 @@ abstract class LocaleCodeAware { mixin LocalizationsProvider on LocaleCodeAware { static final Map> _localizedValues = { 'en': { + 'invoice_tax': 'Invoice Tax', + 'line_item_tax': 'Line Item Tax', + 'inclusive_taxes': 'Inclusive Taxes', + 'number_of_rates': 'Number of Rates', 'no_client_selected': 'No client selected', 'configure_rates': 'Configure rates', 'tax_settings': 'Tax Settings', @@ -15494,10 +15498,19 @@ mixin LocalizationsProvider on LocaleCodeAware { String get configureRates => _localizedValues[localeCode]['configure_rates']; - String get taxSettingsRates => _localizedValues[localeCode]['tax_settings_rates']; + String get taxSettingsRates => + _localizedValues[localeCode]['tax_settings_rates']; - String get noClientSelected => _localizedValues[localeCode]['no_client_selected']; + String get noClientSelected => + _localizedValues[localeCode]['no_client_selected']; + String get invoiceTax => _localizedValues[localeCode]['invoice_tax']; + + String get lineItemTax => _localizedValues[localeCode]['line_item_tax']; + + String get inclusiveTaxes => _localizedValues[localeCode]['inclusive_taxes']; + + String get numberOfRates => _localizedValues[localeCode]['number_of_rates']; String lookup(String key) { final lookupKey = toSnakeCase(key);