Add subtotals and total to bottom of invoice view

This commit is contained in:
Hillel Coren 2020-06-17 23:37:11 +03:00
parent def638d549
commit 55691ba610
6 changed files with 40 additions and 14 deletions

View File

@ -4,21 +4,39 @@ import 'package:invoiceninja_flutter/utils/formatting.dart';
abstract class CalculateInvoiceTotal {
bool get isAmountDiscount;
String get taxName1;
double get taxRate1;
String get taxName2;
double get taxRate2;
String get taxName3;
double get taxRate3;
double get discount;
double get customSurcharge1;
double get customSurcharge2;
double get customSurcharge3;
double get customSurcharge4;
bool get customTaxes1;
bool get customTaxes2;
bool get customTaxes3;
bool get customTaxes4;
bool get usesInclusiveTaxes;
BuiltList<InvoiceItemEntity> get lineItems;
double _calculateTaxAmount(
@ -33,7 +51,7 @@ abstract class CalculateInvoiceTotal {
}
Map<String, double> calculateTaxes(bool useInclusiveTaxes) {
double total = baseTotal;
double total = subtotal;
double taxAmount;
final map = <String, double>{};
@ -122,8 +140,8 @@ abstract class CalculateInvoiceTotal {
return round(lineTotal, 2);
}
double calculateTotal(bool useInclusiveTaxes) {
double total = baseTotal;
double get calculateTotal {
double total = subtotal;
double itemTax = 0.0;
lineItems.forEach((item) {
@ -174,7 +192,7 @@ abstract class CalculateInvoiceTotal {
total += round(customSurcharge2, 2);
}
if (!useInclusiveTaxes) {
if (!usesInclusiveTaxes) {
final double taxAmount1 = round(total * taxRate1 / 100, 2);
final double taxAmount2 = round(total * taxRate2 / 100, 2);
@ -192,7 +210,7 @@ abstract class CalculateInvoiceTotal {
return total;
}
double get baseTotal {
double get subtotal {
var total = 0.0;
lineItems.forEach((item) {

View File

@ -120,7 +120,7 @@ class _CreditEditState extends State<CreditEdit>
child: Padding(
padding: const EdgeInsets.all(14.0),
child: Text(
'${localization.total}: ${formatNumber(invoice.calculateTotal(viewModel.company.settings.enableInclusiveTaxes ?? false), context, clientId: viewModel.invoice.clientId)}',
'${localization.total}: ${formatNumber(invoice.calculateTotal, context, clientId: viewModel.invoice.clientId)}',
style: TextStyle(
//color: Theme.of(context).selectedRowColor,
color: Colors.white,

View File

@ -131,7 +131,7 @@ class _InvoiceEditState extends State<InvoiceEdit>
child: Padding(
padding: const EdgeInsets.all(14.0),
child: Text(
'${localization.total}: ${formatNumber(invoice.calculateTotal(viewModel.company.settings.enableInclusiveTaxes ?? false), context, clientId: viewModel.invoice.clientId)}',
'${localization.total}: ${formatNumber(invoice.calculateTotal, context, clientId: viewModel.invoice.clientId)}',
style: TextStyle(
//color: Theme.of(context).selectedRowColor,
color: state.prefState.enableDarkMode

View File

@ -40,16 +40,16 @@ class InvoiceOverview extends StatelessWidget {
: memoizedPaymentsByInvoice(
invoice.id, state.paymentState.map, state.paymentState.list);
Map<String, String> stauses;
Map<String, String> statuses;
Map<String, Color> colors;
if (invoice.entityType == EntityType.quote) {
stauses = kQuoteStatuses;
statuses = kQuoteStatuses;
colors = QuoteStatusColors.colors;
} else if (invoice.entityType == EntityType.credit) {
stauses = kCreditStatuses;
statuses = kCreditStatuses;
colors = CreditStatusColors.colors;
} else {
stauses = kInvoiceStatuses;
statuses = kInvoiceStatuses;
colors = InvoiceStatusColors.colors;
}
@ -60,7 +60,7 @@ class InvoiceOverview extends StatelessWidget {
EntityHeader(
entity: invoice,
statusColor: color,
statusLabel: localization.lookup(stauses[invoice.calculatedStatusId]),
statusLabel: localization.lookup(statuses[invoice.calculatedStatusId]),
label: invoice.subEntityType == EntityType.credit
? localization.creditAmount
: invoice.subEntityType == EntityType.invoice
@ -226,6 +226,11 @@ class InvoiceOverview extends StatelessWidget {
);
}
widgets.addAll([
SizedBox(height: 8),
surchargeRow(localization.calculateSubtotal, invoice.calculateTotal)
]);
if (invoice.customSurcharge1 != 0 && company.enableCustomSurchargeTaxes1) {
widgets.add(surchargeRow(
company.getCustomFieldLabel(CustomFieldType.surcharge1),
@ -268,6 +273,8 @@ class InvoiceOverview extends StatelessWidget {
invoice.customSurcharge4));
}
widgets.add(surchargeRow(localization.total, invoice.calculateTotal));
return ListView(
children: widgets,
);

View File

@ -32,6 +32,7 @@ class _QuoteEditState extends State<QuoteEdit>
static const kDetailsScreen = 0;
static const kItemScreen = 1;
//static const kNotesScreen = 2;
@override
@ -119,7 +120,7 @@ class _QuoteEditState extends State<QuoteEdit>
child: Padding(
padding: const EdgeInsets.all(14.0),
child: Text(
'${localization.total}: ${formatNumber(invoice.calculateTotal(viewModel.company.settings.enableInclusiveTaxes ?? false), context, clientId: viewModel.invoice.clientId)}',
'${localization.total}: ${formatNumber(invoice.calculateTotal, context, clientId: viewModel.invoice.clientId)}',
style: TextStyle(
//color: Theme.of(context).selectedRowColor,
color: Colors.white,

View File

@ -3157,7 +3157,7 @@ mixin LocalizationsProvider on LocaleCodeAware {
String get lineTotal => _localizedValues[localeCode]['line_total'] ?? '';
String get subtotal => _localizedValues[localeCode]['subtotal'] ?? '';
String get calculateSubtotal => _localizedValues[localeCode]['subtotal'] ?? '';
String get contactUs => _localizedValues[localeCode]['contact_us'] ?? '';