Taxes
This commit is contained in:
parent
fec547a41f
commit
47663af151
|
|
@ -8,5 +8,7 @@
|
||||||
|
|
||||||
build/
|
build/
|
||||||
|
|
||||||
|
.android/
|
||||||
|
.ios/
|
||||||
.flutter-plugins
|
.flutter-plugins
|
||||||
.env.dart
|
.env.dart
|
||||||
|
|
|
||||||
|
|
@ -127,6 +127,65 @@ abstract class CalculateInvoiceTotal {
|
||||||
bool get customTaxes2;
|
bool get customTaxes2;
|
||||||
BuiltList<InvoiceItemEntity> get invoiceItems;
|
BuiltList<InvoiceItemEntity> get invoiceItems;
|
||||||
|
|
||||||
|
Map<String, double> calculateTaxes() {
|
||||||
|
double total = baseTotal;
|
||||||
|
final map = <String, double>{};
|
||||||
|
|
||||||
|
invoiceItems.forEach((item) {
|
||||||
|
final double qty = round(item.qty, 4);
|
||||||
|
final double cost = round(item.cost, 4);
|
||||||
|
final double itemDiscount = round(item.discount, 2);
|
||||||
|
final double taxRate1 = round(item.taxRate1, 3);
|
||||||
|
final double taxRate2 = round(item.taxRate2, 3);
|
||||||
|
|
||||||
|
double lineTotal = qty * cost;
|
||||||
|
double itemTax;
|
||||||
|
|
||||||
|
if (itemDiscount != 0) {
|
||||||
|
if (isAmountDiscount) {
|
||||||
|
lineTotal -= itemDiscount;
|
||||||
|
} else {
|
||||||
|
lineTotal -= round(lineTotal * itemDiscount / 100, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (discount != 0) {
|
||||||
|
if (isAmountDiscount) {
|
||||||
|
if (total != 0) {
|
||||||
|
lineTotal -= round(lineTotal / total * discount, 4);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (taxRate1 != 0) {
|
||||||
|
itemTax = round(lineTotal * taxRate1 / 100, 2);
|
||||||
|
map.update(item.taxName1, (value) => value + itemTax, ifAbsent: () => itemTax);
|
||||||
|
}
|
||||||
|
if (taxRate2 != 0) {
|
||||||
|
itemTax = round(lineTotal * taxRate2 / 100, 2);
|
||||||
|
map.update(item.taxName2, (value) => value + itemTax, ifAbsent: () => itemTax);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
if (discount != 0.0) {
|
||||||
|
if (isAmountDiscount) {
|
||||||
|
total -= round(discount, 2);
|
||||||
|
} else {
|
||||||
|
total -= round(total * discount / 100, 2);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (customValue1 != 0.0 && customTaxes1) {
|
||||||
|
total += round(customValue1, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (customValue2 != 0.0 && customTaxes2) {
|
||||||
|
total += round(customValue2, 2);
|
||||||
|
}
|
||||||
|
|
||||||
|
return map;
|
||||||
|
}
|
||||||
|
|
||||||
double calculateTotal([bool useInclusiveTaxes = false]) {
|
double calculateTotal([bool useInclusiveTaxes = false]) {
|
||||||
double total = baseTotal;
|
double total = baseTotal;
|
||||||
double itemTax = 0.0;
|
double itemTax = 0.0;
|
||||||
|
|
|
||||||
|
|
@ -32,7 +32,7 @@ class _InvoiceViewState extends State<InvoiceView> {
|
||||||
final localization = AppLocalization.of(context);
|
final localization = AppLocalization.of(context);
|
||||||
final store = StoreProvider.of<AppState>(context);
|
final store = StoreProvider.of<AppState>(context);
|
||||||
final viewModel = widget.viewModel;
|
final viewModel = widget.viewModel;
|
||||||
final appState = viewModel.appState;
|
final appState = viewModel.state;
|
||||||
final invoice = viewModel.invoice;
|
final invoice = viewModel.invoice;
|
||||||
final client = viewModel.client;
|
final client = viewModel.client;
|
||||||
|
|
||||||
|
|
@ -59,7 +59,7 @@ class _InvoiceViewState extends State<InvoiceView> {
|
||||||
InvoiceFields.partialDueDate: invoice.partialDueDate,
|
InvoiceFields.partialDueDate: invoice.partialDueDate,
|
||||||
InvoiceFields.poNumber: invoice.poNumber,
|
InvoiceFields.poNumber: invoice.poNumber,
|
||||||
InvoiceFields.discount: formatNumber(
|
InvoiceFields.discount: formatNumber(
|
||||||
invoice.discount, widget.viewModel.appState,
|
invoice.discount, widget.viewModel.state,
|
||||||
clientId: invoice.clientId,
|
clientId: invoice.clientId,
|
||||||
zeroIsNull: true,
|
zeroIsNull: true,
|
||||||
formatNumberType: invoice.isAmountDiscount
|
formatNumberType: invoice.isAmountDiscount
|
||||||
|
|
@ -147,6 +147,32 @@ class _InvoiceViewState extends State<InvoiceView> {
|
||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
widgets.addAll([
|
||||||
|
Container(
|
||||||
|
color: Theme.of(context).backgroundColor,
|
||||||
|
height: 12.0,
|
||||||
|
),
|
||||||
|
Divider(height: 1.0),
|
||||||
|
]);
|
||||||
|
|
||||||
|
invoice.calculateTaxes().forEach((taxName, taxAmount) {
|
||||||
|
widgets.add(Padding(
|
||||||
|
padding: const EdgeInsets.all(16.0),
|
||||||
|
child: Row(
|
||||||
|
mainAxisAlignment: MainAxisAlignment.end,
|
||||||
|
children: <Widget>[
|
||||||
|
Text(taxName),
|
||||||
|
SizedBox(
|
||||||
|
width: 80.0,
|
||||||
|
child: Align(
|
||||||
|
alignment: Alignment.centerRight,
|
||||||
|
child: Text(formatNumber(taxAmount, viewModel.state, clientId: invoice.clientId))),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
));
|
||||||
|
});
|
||||||
|
|
||||||
return widgets;
|
return widgets;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -34,7 +34,7 @@ class InvoiceViewScreen extends StatelessWidget {
|
||||||
}
|
}
|
||||||
|
|
||||||
class InvoiceViewVM {
|
class InvoiceViewVM {
|
||||||
final AppState appState;
|
final AppState state;
|
||||||
final InvoiceEntity invoice;
|
final InvoiceEntity invoice;
|
||||||
final ClientEntity client;
|
final ClientEntity client;
|
||||||
final Function(BuildContext, EntityAction) onActionSelected;
|
final Function(BuildContext, EntityAction) onActionSelected;
|
||||||
|
|
@ -45,7 +45,7 @@ class InvoiceViewVM {
|
||||||
final bool isDirty;
|
final bool isDirty;
|
||||||
|
|
||||||
InvoiceViewVM({
|
InvoiceViewVM({
|
||||||
@required this.appState,
|
@required this.state,
|
||||||
@required this.invoice,
|
@required this.invoice,
|
||||||
@required this.client,
|
@required this.client,
|
||||||
@required this.onActionSelected,
|
@required this.onActionSelected,
|
||||||
|
|
@ -82,7 +82,7 @@ class InvoiceViewVM {
|
||||||
}
|
}
|
||||||
|
|
||||||
return InvoiceViewVM(
|
return InvoiceViewVM(
|
||||||
appState: store.state,
|
state: store.state,
|
||||||
isLoading: store.state.isLoading,
|
isLoading: store.state.isLoading,
|
||||||
isDirty: invoice.isNew,
|
isDirty: invoice.isNew,
|
||||||
invoice: invoice,
|
invoice: invoice,
|
||||||
|
|
|
||||||
54
pubspec.lock
54
pubspec.lock
|
|
@ -77,14 +77,14 @@ packages:
|
||||||
name: built_value
|
name: built_value
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "5.4.5"
|
version: "5.5.3"
|
||||||
built_value_generator:
|
built_value_generator:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
name: built_value_generator
|
name: built_value_generator
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "5.4.5"
|
version: "5.5.0"
|
||||||
cached_network_image:
|
cached_network_image:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|
@ -112,7 +112,7 @@ packages:
|
||||||
name: code_builder
|
name: code_builder
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "3.0.3"
|
version: "3.1.1"
|
||||||
collection:
|
collection:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -154,7 +154,7 @@ packages:
|
||||||
name: file
|
name: file
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "5.0.0"
|
version: "5.0.1"
|
||||||
fixnum:
|
fixnum:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -190,7 +190,7 @@ packages:
|
||||||
name: flutter_redux
|
name: flutter_redux
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.5.0"
|
version: "0.5.2"
|
||||||
flutter_test:
|
flutter_test:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description: flutter
|
description: flutter
|
||||||
|
|
@ -237,7 +237,7 @@ packages:
|
||||||
name: html
|
name: html
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.13.3"
|
version: "0.13.3+1"
|
||||||
http:
|
http:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
|
@ -251,7 +251,7 @@ packages:
|
||||||
name: http_multi_server
|
name: http_multi_server
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.4"
|
version: "2.0.5"
|
||||||
http_parser:
|
http_parser:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -286,7 +286,7 @@ packages:
|
||||||
name: json_rpc_2
|
name: json_rpc_2
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.0.7"
|
version: "2.0.8"
|
||||||
kernel:
|
kernel:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -328,7 +328,7 @@ packages:
|
||||||
name: mime
|
name: mime
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.9.6"
|
version: "0.9.6+1"
|
||||||
multi_server_socket:
|
multi_server_socket:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -342,7 +342,7 @@ packages:
|
||||||
name: node_preamble
|
name: node_preamble
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.4.1"
|
version: "1.4.2"
|
||||||
package_config:
|
package_config:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -356,21 +356,21 @@ packages:
|
||||||
name: package_resolver
|
name: package_resolver
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.2"
|
version: "1.0.3"
|
||||||
path:
|
path:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: path
|
name: path
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.5.1"
|
version: "1.6.0"
|
||||||
path_provider:
|
path_provider:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
name: path_provider
|
name: path_provider
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.4.0"
|
version: "0.4.1"
|
||||||
plugin:
|
plugin:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -384,7 +384,7 @@ packages:
|
||||||
name: pool
|
name: pool
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.3.4"
|
version: "1.3.5"
|
||||||
pub_semver:
|
pub_semver:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -426,14 +426,14 @@ packages:
|
||||||
name: shared_preferences
|
name: shared_preferences
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.4.1"
|
version: "0.4.2"
|
||||||
shelf:
|
shelf:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: shelf
|
name: shelf
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.7.3"
|
version: "0.7.3+1"
|
||||||
shelf_packages_handler:
|
shelf_packages_handler:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -447,14 +447,14 @@ packages:
|
||||||
name: shelf_static
|
name: shelf_static
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.2.7"
|
version: "0.2.7+1"
|
||||||
shelf_web_socket:
|
shelf_web_socket:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: shelf_web_socket
|
name: shelf_web_socket
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.2.2"
|
version: "0.2.2+2"
|
||||||
sky_engine:
|
sky_engine:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description: flutter
|
description: flutter
|
||||||
|
|
@ -466,7 +466,7 @@ packages:
|
||||||
name: source_gen
|
name: source_gen
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.8.1+3"
|
version: "0.8.3"
|
||||||
source_map_stack_trace:
|
source_map_stack_trace:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -501,14 +501,14 @@ packages:
|
||||||
name: stream_channel
|
name: stream_channel
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.6.6"
|
version: "1.6.7+1"
|
||||||
stream_transform:
|
stream_transform:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: stream_transform
|
name: stream_transform
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.0.11"
|
version: "0.0.14"
|
||||||
string_scanner:
|
string_scanner:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -536,7 +536,7 @@ packages:
|
||||||
name: test
|
name: test
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.12.37"
|
version: "0.12.40"
|
||||||
typed_data:
|
typed_data:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
|
|
@ -578,28 +578,28 @@ packages:
|
||||||
name: vm_service_client
|
name: vm_service_client
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.2.4+1"
|
version: "0.2.4+3"
|
||||||
watcher:
|
watcher:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: watcher
|
name: watcher
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.9.7+7"
|
version: "0.9.7+8"
|
||||||
web_socket_channel:
|
web_socket_channel:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: web_socket_channel
|
name: web_socket_channel
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.0.7"
|
version: "1.0.8"
|
||||||
yaml:
|
yaml:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
name: yaml
|
name: yaml
|
||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.1.13"
|
version: "2.1.14"
|
||||||
sdks:
|
sdks:
|
||||||
dart: ">=2.0.0-dev.54.0 <=2.0.0-dev.58.0.flutter-f981f09760"
|
dart: ">=2.0.0-dev.55.0 <=2.0.0-dev.61.0.flutter-c95617b19c"
|
||||||
flutter: ">=0.1.4 <2.0.0"
|
flutter: ">=0.1.4 <2.0.0"
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue