Taxes
This commit is contained in:
parent
fec547a41f
commit
47663af151
|
|
@ -8,5 +8,7 @@
|
|||
|
||||
build/
|
||||
|
||||
.android/
|
||||
.ios/
|
||||
.flutter-plugins
|
||||
.env.dart
|
||||
|
|
|
|||
|
|
@ -127,6 +127,65 @@ abstract class CalculateInvoiceTotal {
|
|||
bool get customTaxes2;
|
||||
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 total = baseTotal;
|
||||
double itemTax = 0.0;
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ class _InvoiceViewState extends State<InvoiceView> {
|
|||
final localization = AppLocalization.of(context);
|
||||
final store = StoreProvider.of<AppState>(context);
|
||||
final viewModel = widget.viewModel;
|
||||
final appState = viewModel.appState;
|
||||
final appState = viewModel.state;
|
||||
final invoice = viewModel.invoice;
|
||||
final client = viewModel.client;
|
||||
|
||||
|
|
@ -59,7 +59,7 @@ class _InvoiceViewState extends State<InvoiceView> {
|
|||
InvoiceFields.partialDueDate: invoice.partialDueDate,
|
||||
InvoiceFields.poNumber: invoice.poNumber,
|
||||
InvoiceFields.discount: formatNumber(
|
||||
invoice.discount, widget.viewModel.appState,
|
||||
invoice.discount, widget.viewModel.state,
|
||||
clientId: invoice.clientId,
|
||||
zeroIsNull: true,
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -34,7 +34,7 @@ class InvoiceViewScreen extends StatelessWidget {
|
|||
}
|
||||
|
||||
class InvoiceViewVM {
|
||||
final AppState appState;
|
||||
final AppState state;
|
||||
final InvoiceEntity invoice;
|
||||
final ClientEntity client;
|
||||
final Function(BuildContext, EntityAction) onActionSelected;
|
||||
|
|
@ -45,7 +45,7 @@ class InvoiceViewVM {
|
|||
final bool isDirty;
|
||||
|
||||
InvoiceViewVM({
|
||||
@required this.appState,
|
||||
@required this.state,
|
||||
@required this.invoice,
|
||||
@required this.client,
|
||||
@required this.onActionSelected,
|
||||
|
|
@ -82,7 +82,7 @@ class InvoiceViewVM {
|
|||
}
|
||||
|
||||
return InvoiceViewVM(
|
||||
appState: store.state,
|
||||
state: store.state,
|
||||
isLoading: store.state.isLoading,
|
||||
isDirty: invoice.isNew,
|
||||
invoice: invoice,
|
||||
|
|
|
|||
54
pubspec.lock
54
pubspec.lock
|
|
@ -77,14 +77,14 @@ packages:
|
|||
name: built_value
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "5.4.5"
|
||||
version: "5.5.3"
|
||||
built_value_generator:
|
||||
dependency: "direct dev"
|
||||
description:
|
||||
name: built_value_generator
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "5.4.5"
|
||||
version: "5.5.0"
|
||||
cached_network_image:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
|
@ -112,7 +112,7 @@ packages:
|
|||
name: code_builder
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "3.0.3"
|
||||
version: "3.1.1"
|
||||
collection:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -154,7 +154,7 @@ packages:
|
|||
name: file
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "5.0.0"
|
||||
version: "5.0.1"
|
||||
fixnum:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -190,7 +190,7 @@ packages:
|
|||
name: flutter_redux
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.5.0"
|
||||
version: "0.5.2"
|
||||
flutter_test:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
|
|
@ -237,7 +237,7 @@ packages:
|
|||
name: html
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.13.3"
|
||||
version: "0.13.3+1"
|
||||
http:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
|
|
@ -251,7 +251,7 @@ packages:
|
|||
name: http_multi_server
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.4"
|
||||
version: "2.0.5"
|
||||
http_parser:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -286,7 +286,7 @@ packages:
|
|||
name: json_rpc_2
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.0.7"
|
||||
version: "2.0.8"
|
||||
kernel:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -328,7 +328,7 @@ packages:
|
|||
name: mime
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.9.6"
|
||||
version: "0.9.6+1"
|
||||
multi_server_socket:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -342,7 +342,7 @@ packages:
|
|||
name: node_preamble
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.4.1"
|
||||
version: "1.4.2"
|
||||
package_config:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -356,21 +356,21 @@ packages:
|
|||
name: package_resolver
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.2"
|
||||
version: "1.0.3"
|
||||
path:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: path
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.5.1"
|
||||
version: "1.6.0"
|
||||
path_provider:
|
||||
dependency: "direct main"
|
||||
description:
|
||||
name: path_provider
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.4.0"
|
||||
version: "0.4.1"
|
||||
plugin:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -384,7 +384,7 @@ packages:
|
|||
name: pool
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.3.4"
|
||||
version: "1.3.5"
|
||||
pub_semver:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -426,14 +426,14 @@ packages:
|
|||
name: shared_preferences
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.4.1"
|
||||
version: "0.4.2"
|
||||
shelf:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shelf
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.7.3"
|
||||
version: "0.7.3+1"
|
||||
shelf_packages_handler:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -447,14 +447,14 @@ packages:
|
|||
name: shelf_static
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.7"
|
||||
version: "0.2.7+1"
|
||||
shelf_web_socket:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: shelf_web_socket
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.2"
|
||||
version: "0.2.2+2"
|
||||
sky_engine:
|
||||
dependency: transitive
|
||||
description: flutter
|
||||
|
|
@ -466,7 +466,7 @@ packages:
|
|||
name: source_gen
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.8.1+3"
|
||||
version: "0.8.3"
|
||||
source_map_stack_trace:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -501,14 +501,14 @@ packages:
|
|||
name: stream_channel
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.6.6"
|
||||
version: "1.6.7+1"
|
||||
stream_transform:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: stream_transform
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.0.11"
|
||||
version: "0.0.14"
|
||||
string_scanner:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -536,7 +536,7 @@ packages:
|
|||
name: test
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.12.37"
|
||||
version: "0.12.40"
|
||||
typed_data:
|
||||
dependency: transitive
|
||||
description:
|
||||
|
|
@ -578,28 +578,28 @@ packages:
|
|||
name: vm_service_client
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.2.4+1"
|
||||
version: "0.2.4+3"
|
||||
watcher:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: watcher
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "0.9.7+7"
|
||||
version: "0.9.7+8"
|
||||
web_socket_channel:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: web_socket_channel
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "1.0.7"
|
||||
version: "1.0.8"
|
||||
yaml:
|
||||
dependency: transitive
|
||||
description:
|
||||
name: yaml
|
||||
url: "https://pub.dartlang.org"
|
||||
source: hosted
|
||||
version: "2.1.13"
|
||||
version: "2.1.14"
|
||||
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"
|
||||
|
|
|
|||
Loading…
Reference in New Issue