Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
hillelcoren committed Sep 15, 2022
2 parents c3f9cc8 + ce9e83a commit 5b378cc
Show file tree
Hide file tree
Showing 41 changed files with 147 additions and 208 deletions.
4 changes: 4 additions & 0 deletions lib/data/models/client_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,10 @@ abstract class ClientEntity extends Object
actions.add(EntityAction.newInvoice);
}

if (userCompany.canCreate(EntityType.quote)) {
actions.add(EntityAction.newQuote);
}

if (userCompany.canCreate(EntityType.payment)) {
actions.add(EntityAction.newPayment);
}
Expand Down
31 changes: 30 additions & 1 deletion lib/data/models/transaction_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,13 @@ abstract class TransactionEntity extends Object
}

int compareTo(
TransactionEntity transaction, String sortField, bool sortAscending) {
TransactionEntity transaction,
String sortField,
bool sortAscending,
BuiltMap<String, InvoiceEntity> invoiceMap,
BuiltMap<String, ExpenseEntity> expenseMap,
BuiltMap<String, BankAccountEntity> bankAccountMap,
) {
int response = 0;
final transactionA = sortAscending ? this : transaction;
final transactionB = sortAscending ? transaction : this;
Expand All @@ -161,6 +167,29 @@ abstract class TransactionEntity extends Object
case TransactionFields.date:
response = transactionA.date.compareTo(transactionB.date);
break;
case TransactionFields.invoice:
final invoiceA = invoiceMap[transactionA.invoiceId] ?? InvoiceEntity();
final invoiceB = invoiceMap[transactionB.invoiceId] ?? InvoiceEntity();
response = invoiceA.listDisplayName
.toLowerCase()
.compareTo(invoiceB.listDisplayName.toLowerCase());
break;
case TransactionFields.expense:
final expenseA = expenseMap[transactionA.expenseId] ?? ExpenseEntity();
final expenseB = expenseMap[transactionB.expenseId] ?? ExpenseEntity();
response = expenseA.listDisplayName
.toLowerCase()
.compareTo(expenseB.listDisplayName.toLowerCase());
break;
case TransactionFields.bankAccount:
final bankAccountA =
bankAccountMap[transactionA.bankAccountId] ?? BankAccountEntity();
final bankAccountB =
bankAccountMap[transactionB.bankAccountId] ?? BankAccountEntity();
response = bankAccountA.listDisplayName
.toLowerCase()
.compareTo(bankAccountB.listDisplayName.toLowerCase());
break;
default:
print('## ERROR: sort by transaction.$sortField is not implemented');
break;
Expand Down
85 changes: 25 additions & 60 deletions lib/redux/app/app_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,58 +17,36 @@ import 'package:invoiceninja_flutter/constants.dart';
import 'package:invoiceninja_flutter/data/models/account_model.dart';
import 'package:invoiceninja_flutter/data/models/models.dart';
import 'package:invoiceninja_flutter/redux/auth/auth_state.dart';
import 'package:invoiceninja_flutter/redux/client/client_selectors.dart';
import 'package:invoiceninja_flutter/redux/client/client_state.dart';
import 'package:invoiceninja_flutter/redux/company/company_state.dart';
import 'package:invoiceninja_flutter/redux/company_gateway/company_gateway_selectors.dart';
import 'package:invoiceninja_flutter/redux/company_gateway/company_gateway_state.dart';
import 'package:invoiceninja_flutter/redux/credit/credit_selectors.dart';
import 'package:invoiceninja_flutter/redux/credit/credit_state.dart';
import 'package:invoiceninja_flutter/redux/dashboard/dashboard_state.dart';
import 'package:invoiceninja_flutter/redux/design/design_selectors.dart';
import 'package:invoiceninja_flutter/redux/design/design_state.dart';
import 'package:invoiceninja_flutter/redux/document/document_state.dart';
import 'package:invoiceninja_flutter/redux/expense/expense_selectors.dart';
import 'package:invoiceninja_flutter/redux/expense/expense_state.dart';
import 'package:invoiceninja_flutter/redux/expense_category/expense_category_selectors.dart';
import 'package:invoiceninja_flutter/redux/expense_category/expense_category_state.dart';
import 'package:invoiceninja_flutter/redux/group/group_selectors.dart';
import 'package:invoiceninja_flutter/redux/group/group_state.dart';
import 'package:invoiceninja_flutter/redux/invoice/invoice_selectors.dart';
import 'package:invoiceninja_flutter/redux/invoice/invoice_state.dart';
import 'package:invoiceninja_flutter/redux/payment/payment_selectors.dart';
import 'package:invoiceninja_flutter/redux/payment/payment_state.dart';
import 'package:invoiceninja_flutter/redux/payment_term/payment_term_selectors.dart';
import 'package:invoiceninja_flutter/redux/payment_term/payment_term_state.dart';
import 'package:invoiceninja_flutter/redux/product/product_selectors.dart';
import 'package:invoiceninja_flutter/redux/product/product_state.dart';
import 'package:invoiceninja_flutter/redux/project/project_selectors.dart';
import 'package:invoiceninja_flutter/redux/project/project_state.dart';
import 'package:invoiceninja_flutter/redux/quote/quote_selectors.dart';
import 'package:invoiceninja_flutter/redux/quote/quote_state.dart';
import 'package:invoiceninja_flutter/redux/recurring_expense/recurring_expense_selectors.dart';
import 'package:invoiceninja_flutter/redux/recurring_expense/recurring_expense_state.dart';
import 'package:invoiceninja_flutter/redux/recurring_invoice/recurring_invoice_selectors.dart';
import 'package:invoiceninja_flutter/redux/recurring_invoice/recurring_invoice_state.dart';
import 'package:invoiceninja_flutter/redux/static/static_state.dart';
import 'package:invoiceninja_flutter/redux/subscription/subscription_selectors.dart';
import 'package:invoiceninja_flutter/redux/subscription/subscription_state.dart';
import 'package:invoiceninja_flutter/redux/task/task_selectors.dart';
import 'package:invoiceninja_flutter/redux/task/task_state.dart';
import 'package:invoiceninja_flutter/redux/task_status/task_status_selectors.dart';
import 'package:invoiceninja_flutter/redux/task_status/task_status_state.dart';
import 'package:invoiceninja_flutter/redux/tax_rate/tax_rate_selectors.dart';
import 'package:invoiceninja_flutter/redux/tax_rate/tax_rate_state.dart';
import 'package:invoiceninja_flutter/redux/token/token_selectors.dart';
import 'package:invoiceninja_flutter/redux/token/token_state.dart';
import 'package:invoiceninja_flutter/redux/ui/entity_ui_state.dart';
import 'package:invoiceninja_flutter/redux/ui/list_ui_state.dart';
import 'package:invoiceninja_flutter/redux/ui/pref_state.dart';
import 'package:invoiceninja_flutter/redux/ui/ui_state.dart';
import 'package:invoiceninja_flutter/redux/user/user_state.dart';
import 'package:invoiceninja_flutter/redux/vendor/vendor_selectors.dart';
import 'package:invoiceninja_flutter/redux/vendor/vendor_state.dart';
import 'package:invoiceninja_flutter/redux/webhook/webhook_selectors.dart';
import 'package:invoiceninja_flutter/redux/webhook/webhook_state.dart';
import 'package:invoiceninja_flutter/ui/app/screen_imports.dart';
import 'package:invoiceninja_flutter/ui/credit/credit_screen.dart';
Expand All @@ -87,15 +65,12 @@ import 'package:invoiceninja_flutter/ui/webhook/edit/webhook_edit_vm.dart';
import 'package:invoiceninja_flutter/utils/colors.dart';
import 'package:invoiceninja_flutter/utils/formatting.dart';
import 'package:invoiceninja_flutter/utils/platforms.dart';
// STARTER: import - do not remove comment
import 'package:invoiceninja_flutter/redux/transaction/transaction_state.dart';
import 'package:invoiceninja_flutter/ui/transaction/edit/transaction_edit_vm.dart';
import 'package:invoiceninja_flutter/redux/transaction/transaction_selectors.dart';

import 'package:invoiceninja_flutter/redux/bank_account/bank_account_state.dart';
import 'package:invoiceninja_flutter/redux/purchase_order/purchase_order_state.dart';
import 'package:invoiceninja_flutter/ui/purchase_order/edit/purchase_order_edit_vm.dart';
import 'package:invoiceninja_flutter/redux/purchase_order/purchase_order_selectors.dart';
// STARTER: import - do not remove comment

part 'app_state.g.dart';

Expand Down Expand Up @@ -702,64 +677,54 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
bool hasChanges() {
switch (uiState.currentRoute) {
case ClientEditScreen.route:
return hasClientChanges(clientUIState.editing, clientState.map);
return clientUIState.editing.isChanged == true;
case ProductEditScreen.route:
return hasProductChanges(productUIState.editing, productState.map);
return productUIState.editing.isChanged == true;
case InvoiceEditScreen.route:
return hasInvoiceChanges(invoiceUIState.editing, invoiceState.map);
return invoiceUIState.editing.isChanged == true;
case PaymentEditScreen.route:
return hasPaymentChanges(paymentUIState.editing, paymentState.map);
return paymentUIState.editing.isChanged == true;
case QuoteEditScreen.route:
return hasQuoteChanges(quoteUIState.editing, quoteState.map);
return quoteUIState.editing.isChanged == true;
case ProjectEditScreen.route:
return hasProjectChanges(projectUIState.editing, projectState.map);
return projectUIState.editing.isChanged == true;
case TaskEditScreen.route:
return hasTaskChanges(taskUIState.editing, taskState.map);
return taskUIState.editing.isChanged == true;
case VendorEditScreen.route:
return hasVendorChanges(vendorUIState.editing, vendorState.map);
return vendorUIState.editing.isChanged == true;
case ExpenseEditScreen.route:
return hasExpenseChanges(expenseUIState.editing, expenseState.map);
return expenseUIState.editing.isChanged == true;
case GroupEditScreen.route:
return hasGroupChanges(groupUIState.editing, groupState.map);
return groupUIState.editing.isChanged == true;
case TaxRateEditScreen.route:
return hasTaxRateChanges(taxRateUIState.editing, taxRateState.map);
return taxRateUIState.editing.isChanged == true;
case CompanyGatewayEditScreen.route:
return hasCompanyGatewayChanges(
companyGatewayUIState.editing, companyGatewayState.map);
return companyGatewayUIState.editing.isChanged == true;
case CreditEditScreen.route:
return hasCreditChanges(creditUIState.editing, creditState.map);
return creditUIState.editing.isChanged == true;
// STARTER: has changes - do not remove comment
case TransactionEditScreen.route:
return hasTransactionChanges(
transactionUIState.editing, transactionState.map);

return transactionUIState.editing.isChanged == true;
case PurchaseOrderEditScreen.route:
return hasPurchaseOrderChanges(
purchaseOrderUIState.editing, purchaseOrderState.map);
return purchaseOrderUIState.editing.isChanged == true;
case RecurringExpenseEditScreen.route:
return hasRecurringExpenseChanges(
recurringExpenseUIState.editing, recurringExpenseState.map);
return recurringExpenseUIState.editing.isChanged == true;
case SubscriptionEditScreen.route:
return hasSubscriptionChanges(
subscriptionUIState.editing, subscriptionState.map);
return subscriptionUIState.editing.isChanged == true;
case TaskStatusEditScreen.route:
return hasTaskStatusChanges(
taskStatusUIState.editing, taskStatusState.map);
return taskStatusUIState.editing.isChanged == true;
case ExpenseCategoryEditScreen.route:
return hasExpenseCategoryChanges(
expenseCategoryUIState.editing, expenseCategoryState.map);
return expenseCategoryUIState.editing.isChanged == true;
case RecurringInvoiceEditScreen.route:
return hasRecurringInvoiceChanges(
recurringInvoiceUIState.editing, recurringInvoiceState.map);
return recurringInvoiceUIState.editing.isChanged == true;
case WebhookEditScreen.route:
return hasWebhookChanges(webhookUIState.editing, webhookState.map);
return webhookUIState.editing.isChanged == true;
case TokenEditScreen.route:
return hasTokenChanges(tokenUIState.editing, tokenState.map);
return tokenUIState.editing.isChanged == true;
case PaymentTermEditScreen.route:
return hasPaymentTermChanges(
paymentTermUIState.editing, paymentTermState.map);
return paymentTermUIState.editing.isChanged == true;
case DesignEditScreen.route:
return hasDesignChanges(designUIState.editing, designState.map);
return designUIState.editing.isChanged == true;
}

if (uiState.isInSettings) {
Expand Down
6 changes: 0 additions & 6 deletions lib/redux/company_gateway/company_gateway_selectors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,6 @@ List<String> filteredCompanyGatewaysSelector(
return gatewaysIds;
}

bool hasCompanyGatewayChanges(CompanyGatewayEntity companyGateway,
BuiltMap<String, CompanyGatewayEntity> companyGatewayMap) =>
companyGateway.isNew
? companyGateway.isChanged
: companyGateway != companyGatewayMap[companyGateway.id];

var memoizedCalculateCompanyGatewayProcessed = memo2(
(String companyGatewayId, BuiltMap<String, PaymentEntity> paymentMap) =>
calculateCompanyGatewayProcessed(
Expand Down
4 changes: 0 additions & 4 deletions lib/redux/credit/credit_selectors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,3 @@ EntityStats creditStatsForUser(

return EntityStats(countActive: countActive, countArchived: countArchived);
}

bool hasCreditChanges(
InvoiceEntity credit, BuiltMap<String, InvoiceEntity> creditMap) =>
credit.isNew ? credit.isChanged : credit != creditMap[credit.id];
4 changes: 0 additions & 4 deletions lib/redux/design/design_selectors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ List<String> filteredDesignsSelector(BuiltMap<String, DesignEntity> designMap,
return list;
}

bool hasDesignChanges(
DesignEntity design, BuiltMap<String, DesignEntity> designMap) =>
design.isNew ? design.isChanged : design != designMap[design.id];

String getDesignIdForClientByEntity(
{AppState state, String clientId, EntityType entityType}) {
final client = state.clientState.get(clientId);
Expand Down
4 changes: 0 additions & 4 deletions lib/redux/expense/expense_selectors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,3 @@ EntityStats expenseStatsForUser(

return EntityStats(countActive: countActive, countArchived: countArchived);
}

bool hasExpenseChanges(
ExpenseEntity expense, BuiltMap<String, ExpenseEntity> expenseMap) =>
expense.isNew ? expense.isChanged : expense != expenseMap[expense.id];
5 changes: 0 additions & 5 deletions lib/redux/expense_category/expense_category_selectors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,8 +124,3 @@ EntityStats expenseStatsForExpenseCategory(
return EntityStats(countActive: countActive, countArchived: countArchived);
}

bool hasExpenseCategoryChanges(ExpenseCategoryEntity expenseCategory,
BuiltMap<String, ExpenseCategoryEntity> expenseCategoryMap) =>
expenseCategory.isNew
? expenseCategory.isChanged
: expenseCategory != expenseCategoryMap[expenseCategory.id];
4 changes: 0 additions & 4 deletions lib/redux/group/group_selectors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,3 @@ EntityStats clientStatsForGroup(

return EntityStats(countActive: countActive, countArchived: countArchived);
}

bool hasGroupChanges(
GroupEntity group, BuiltMap<String, GroupEntity> groupMap) =>
group.isNew ? group.isChanged : group != groupMap[group.id];
4 changes: 0 additions & 4 deletions lib/redux/invoice/invoice_selectors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,3 @@ int precisionForInvoice(AppState state, InvoiceEntity invoice) {
final currency = state.staticState.currencyMap[client.currencyId];
return currency?.precision ?? 2;
}

bool hasInvoiceChanges(
InvoiceEntity invoice, BuiltMap<String, InvoiceEntity> invoiceMap) =>
invoice.isNew ? invoice.isChanged : invoice != invoiceMap[invoice.id];
4 changes: 0 additions & 4 deletions lib/redux/payment/payment_selectors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,3 @@ EntityStats paymentStatsForUser(

return EntityStats(countActive: countActive, countArchived: countArchived);
}

bool hasPaymentChanges(
PaymentEntity payment, BuiltMap<String, PaymentEntity> paymentMap) =>
payment.isNew ? payment.isChanged : payment != paymentMap[payment.id];
6 changes: 0 additions & 6 deletions lib/redux/payment_term/payment_term_selectors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,3 @@ List<String> filteredPaymentTermsSelector(

return list;
}

bool hasPaymentTermChanges(PaymentTermEntity paymentTerm,
BuiltMap<String, PaymentTermEntity> paymentTermMap) =>
paymentTerm.isNew
? paymentTerm.isChanged
: paymentTerm != paymentTermMap[paymentTerm.id];
3 changes: 0 additions & 3 deletions lib/redux/product/product_selectors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,3 @@ List<String> filteredProductsSelector(
return list;
}

bool hasProductChanges(
ProductEntity product, BuiltMap<String, ProductEntity> productMap) =>
product.isNew ? product.isChanged : product != productMap[product.id];
4 changes: 0 additions & 4 deletions lib/redux/project/project_selectors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,3 @@ EntityStats projectStatsForUser(

return EntityStats(countActive: countActive, countArchived: countArchived);
}

bool hasProjectChanges(
ProjectEntity project, BuiltMap<String, ProjectEntity> projectMap) =>
project.isNew ? project.isChanged : project != projectMap[project.id];
5 changes: 0 additions & 5 deletions lib/redux/purchase_order/purchase_order_selectors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -198,8 +198,3 @@ EntityStats purchaseOrderStatsForVendor(
return EntityStats(countActive: countActive, countArchived: countArchived);
}

bool hasPurchaseOrderChanges(InvoiceEntity purchaseOrder,
BuiltMap<String, InvoiceEntity> purchaseOrderMap) =>
purchaseOrder.isNew
? purchaseOrder.isChanged
: purchaseOrder != purchaseOrderMap[purchaseOrder.id];
4 changes: 0 additions & 4 deletions lib/redux/quote/quote_selectors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,3 @@ EntityStats quoteStatsForUser(

return EntityStats(countActive: countActive, countArchived: countArchived);
}

bool hasQuoteChanges(
InvoiceEntity quote, BuiltMap<String, InvoiceEntity> quoteMap) =>
quote.isNew ? quote.isChanged : quote != quoteMap[quote.id];
6 changes: 0 additions & 6 deletions lib/redux/recurring_expense/recurring_expense_selectors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -271,9 +271,3 @@ EntityStats recurringExpenseStatsForExpense(

return EntityStats(countActive: countActive, countArchived: countArchived);
}

bool hasRecurringExpenseChanges(ExpenseEntity recurringExpense,
BuiltMap<String, ExpenseEntity> recurringExpenseMap) =>
recurringExpense.isNew
? recurringExpense.isChanged
: recurringExpense != recurringExpenseMap[recurringExpense.id];
6 changes: 0 additions & 6 deletions lib/redux/recurring_invoice/recurring_invoice_selectors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,9 +215,3 @@ EntityStats recurringInvoiceStatsForSubscription(

return EntityStats(countActive: countActive, countArchived: countArchived);
}

bool hasRecurringInvoiceChanges(InvoiceEntity recurringInvoice,
BuiltMap<String, InvoiceEntity> recurringInvoiceMap) =>
recurringInvoice.isNew
? recurringInvoice.isChanged
: recurringInvoice != recurringInvoiceMap[recurringInvoice.id];
6 changes: 0 additions & 6 deletions lib/redux/subscription/subscription_selectors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,3 @@ List<String> filteredSubscriptionsSelector(

return list;
}

bool hasSubscriptionChanges(SubscriptionEntity subscription,
BuiltMap<String, SubscriptionEntity> subscriptionMap) =>
subscription.isNew
? subscription.isChanged
: subscription != subscriptionMap[subscription.id];
3 changes: 0 additions & 3 deletions lib/redux/task/task_selectors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -468,6 +468,3 @@ EntityStats taskStatsForUser(

return EntityStats(countActive: countActive, countArchived: countArchived);
}

bool hasTaskChanges(TaskEntity task, BuiltMap<String, TaskEntity> taskMap) =>
task.isNew ? task.isChanged : task != taskMap[task.id];
6 changes: 0 additions & 6 deletions lib/redux/task_status/task_status_selectors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -153,12 +153,6 @@ EntityStats taskStatsForTaskStatus(
return EntityStats(countActive: countActive, countArchived: countArchived);
}

bool hasTaskStatusChanges(TaskStatusEntity taskStatus,
BuiltMap<String, TaskStatusEntity> taskStatusMap) =>
taskStatus.isNew
? taskStatus.isChanged
: taskStatus != taskStatusMap[taskStatus.id];

String defaultTaskStatusId(BuiltMap<String, TaskStatusEntity> taskStatusMap) {
final statusIds = taskStatusMap.keys.where((statusId) {
final status = taskStatusMap[statusId];
Expand Down
4 changes: 0 additions & 4 deletions lib/redux/tax_rate/tax_rate_selectors.dart
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,3 @@ List<String> filteredTaxRatesSelector(

return list;
}

bool hasTaxRateChanges(
TaxRateEntity taxRate, BuiltMap<String, TaxRateEntity> taxRateMap) =>
taxRate.isNew ? taxRate.isChanged : taxRate != taxRateMap[taxRate.id];
Loading

0 comments on commit 5b378cc

Please sign in to comment.