Company gateway view

This commit is contained in:
Hillel Coren 2020-08-12 17:57:50 +03:00
parent 1295cc23bd
commit c63669d7b0
5 changed files with 50 additions and 60 deletions

View File

@ -238,6 +238,7 @@ const kNotificationEvents = [
]; ];
const String kGatewayStripe = 'd14dd26a37cecc30fdd65700bfb55b23'; const String kGatewayStripe = 'd14dd26a37cecc30fdd65700bfb55b23';
const String kGatewayCustom = '54faab2ab6e3223dbe848b1686490baa';
const String kClientPortalModeSubdomain = 'subdomain'; const String kClientPortalModeSubdomain = 'subdomain';
const String kClientPortalModeDomain = 'domain'; const String kClientPortalModeDomain = 'domain';

View File

@ -140,6 +140,8 @@ abstract class CompanyGatewayEntity extends Object
return gateway.name; return gateway.name;
} }
bool get isCustom => gatewayId == kGatewayCustom;
bool supportsCard(int cardType) => acceptedCreditCards & cardType > 0; bool supportsCard(int cardType) => acceptedCreditCards & cardType > 0;
CompanyGatewayEntity addCard(int cardType) => CompanyGatewayEntity addCard(int cardType) =>

View File

@ -278,18 +278,13 @@ abstract class CompanyEntity extends Object
} }
return matchesStrings( return matchesStrings(
haystacks: [ haystacks: [subdomain, displayName, companyKey],
subdomain,
displayName,
companyKey
],
needle: filter, needle: filter,
); );
} }
@override @override
String matchesFilterValue(String filter) { String matchesFilterValue(String filter) {
for (final user in users) { for (final user in users) {
final value = user.matchesFilterValue(filter); final value = user.matchesFilterValue(filter);
if (value != null) { if (value != null) {
@ -310,11 +305,7 @@ abstract class CompanyEntity extends Object
} }
return matchesStringsValue( return matchesStringsValue(
haystacks: [ haystacks: [subdomain, displayName, companyKey],
subdomain,
displayName,
companyKey
],
needle: filter, needle: filter,
); );
} }
@ -350,15 +341,13 @@ abstract class CompanyEntity extends Object
bool get hasCustomSurcharge => bool get hasCustomSurcharge =>
hasCustomField(CustomFieldType.surcharge1) || hasCustomField(CustomFieldType.surcharge1) ||
hasCustomField(CustomFieldType.surcharge2) || hasCustomField(CustomFieldType.surcharge2) ||
hasCustomField(CustomFieldType.surcharge3) || hasCustomField(CustomFieldType.surcharge3) ||
hasCustomField(CustomFieldType.surcharge4); hasCustomField(CustomFieldType.surcharge4);
String getCustomFieldLabel(String field) { String getCustomFieldLabel(String field) {
if (customFields.containsKey(field)) { if (customFields.containsKey(field)) {
return customFields[field] return customFields[field].split('|').first;
.split('|')
.first;
} else { } else {
return ''; return '';
} }
@ -366,9 +355,7 @@ abstract class CompanyEntity extends Object
String getCustomFieldType(String field) { String getCustomFieldType(String field) {
if ((customFields[field] ?? '').contains('|')) { if ((customFields[field] ?? '').contains('|')) {
final value = customFields[field] final value = customFields[field].split('|').last;
.split('|')
.last;
if ([kFieldTypeSingleLineText, kFieldTypeDate, kFieldTypeSwitch] if ([kFieldTypeSingleLineText, kFieldTypeDate, kFieldTypeSwitch]
.contains(value)) { .contains(value)) {
return value; return value;
@ -405,9 +392,7 @@ abstract class CompanyEntity extends Object
} }
// TODO make sure to clear everything // TODO make sure to clear everything
CompanyEntity get coreCompany => CompanyEntity get coreCompany => rebuild((b) => b
rebuild((b) =>
b
..clients.clear() ..clients.clear()
..products.clear() ..products.clear()
..invoices.clear() ..invoices.clear()
@ -418,8 +403,8 @@ abstract class CompanyEntity extends Object
..projects.clear() ..projects.clear()
..vendors.clear() ..vendors.clear()
..expenses.clear() ..expenses.clear()
//..designs.clear() //..designs.clear()
//..companyGateways.clear() //..companyGateways.clear()
); );
bool isModuleEnabled(EntityType entityType) { bool isModuleEnabled(EntityType entityType) {
@ -435,7 +420,7 @@ abstract class CompanyEntity extends Object
} }
if ((entityType == EntityType.invoice || if ((entityType == EntityType.invoice ||
entityType == EntityType.payment) && entityType == EntityType.payment) &&
enabledModules & kModuleInvoices == 0) { enabledModules & kModuleInvoices == 0) {
return false; return false;
} else if (entityType == EntityType.credit && } else if (entityType == EntityType.credit &&
@ -503,6 +488,8 @@ abstract class GatewayEntity extends Object
String get fields; String get fields;
bool get supportsTokenBilling => [kGatewayStripe].contains(id);
Map<String, dynamic> get parsedFields => Map<String, dynamic> get parsedFields =>
fields.isEmpty ? <String, dynamic>{} : jsonDecode(fields); fields.isEmpty ? <String, dynamic>{} : jsonDecode(fields);
@ -571,7 +558,6 @@ abstract class GatewayEntity extends Object
FormatNumberType get listDisplayAmountType => null; FormatNumberType get listDisplayAmountType => null;
} }
abstract class UserCompanyEntity abstract class UserCompanyEntity
implements Built<UserCompanyEntity, UserCompanyEntityBuilder> { implements Built<UserCompanyEntity, UserCompanyEntityBuilder> {
factory UserCompanyEntity() { factory UserCompanyEntity() {
@ -583,10 +569,9 @@ abstract class UserCompanyEntity
user: UserEntity(), user: UserEntity(),
token: TokenEntity(), token: TokenEntity(),
account: AccountEntity(), account: AccountEntity(),
notifications: BuiltMap<String, BuiltList<String>>().rebuild((b) => notifications: BuiltMap<String, BuiltList<String>>().rebuild((b) => b
b
..[kNotificationChannelEmail] = ..[kNotificationChannelEmail] =
BuiltList<String>(<String>[kNotificationsAll])), BuiltList<String>(<String>[kNotificationsAll])),
); );
} }
@ -656,7 +641,7 @@ abstract class UserCompanyEntity
bool receivesAllNotifications(String channel) => bool receivesAllNotifications(String channel) =>
notifications.containsKey(channel) && notifications.containsKey(channel) &&
notifications[channel].contains(kNotificationsAll); notifications[channel].contains(kNotificationsAll);
bool canView(EntityType entityType) => can(UserPermission.view, entityType); bool canView(EntityType entityType) => can(UserPermission.view, entityType);
@ -861,9 +846,9 @@ abstract class SettingsEntity
groupSettings?.customMessagePaidInvoice ?? groupSettings?.customMessagePaidInvoice ??
companySettings?.customMessagePaidInvoice, companySettings?.customMessagePaidInvoice,
customMessageUnapprovedQuote: customMessageUnapprovedQuote:
clientSettings?.customMessageUnapprovedQuote ?? clientSettings?.customMessageUnapprovedQuote ??
groupSettings?.customMessageUnapprovedQuote ?? groupSettings?.customMessageUnapprovedQuote ??
companySettings?.customMessageUnapprovedQuote, companySettings?.customMessageUnapprovedQuote,
lockSentInvoices: clientSettings?.lockSentInvoices ?? lockSentInvoices: clientSettings?.lockSentInvoices ??
groupSettings?.lockSentInvoices ?? groupSettings?.lockSentInvoices ??
companySettings?.lockSentInvoices, companySettings?.lockSentInvoices,
@ -1069,7 +1054,7 @@ abstract class SettingsEntity
groupSettings?.requireQuoteSignature ?? groupSettings?.requireQuoteSignature ??
companySettings?.requireQuoteSignature, companySettings?.requireQuoteSignature,
name: name:
clientSettings?.name ?? groupSettings?.name ?? companySettings?.name, clientSettings?.name ?? groupSettings?.name ?? companySettings?.name,
companyLogo: clientSettings?.companyLogo ?? companyLogo: clientSettings?.companyLogo ??
groupSettings?.companyLogo ?? groupSettings?.companyLogo ??
companySettings?.companyLogo, companySettings?.companyLogo,
@ -1083,7 +1068,7 @@ abstract class SettingsEntity
groupSettings?.address2 ?? groupSettings?.address2 ??
companySettings?.address2, companySettings?.address2,
city: city:
clientSettings?.city ?? groupSettings?.city ?? companySettings?.city, clientSettings?.city ?? groupSettings?.city ?? companySettings?.city,
state: clientSettings?.state ?? state: clientSettings?.state ??
groupSettings?.state ?? groupSettings?.state ??
companySettings?.state, companySettings?.state,
@ -1966,7 +1951,7 @@ abstract class SettingsEntity
abstract class CompanyItemResponse abstract class CompanyItemResponse
implements Built<CompanyItemResponse, CompanyItemResponseBuilder> { implements Built<CompanyItemResponse, CompanyItemResponseBuilder> {
factory CompanyItemResponse([void updates(CompanyItemResponseBuilder b)]) = factory CompanyItemResponse([void updates(CompanyItemResponseBuilder b)]) =
_$CompanyItemResponse; _$CompanyItemResponse;
CompanyItemResponse._(); CompanyItemResponse._();

View File

@ -633,6 +633,7 @@ abstract class AppState implements Built<AppState, AppStateBuilder> {
//return 'Invitations: ${uiState.invoiceUIState.editing.invitations}'; //return 'Invitations: ${uiState.invoiceUIState.editing.invitations}';
//return 'Selection: ${clientUIState.selectedId}'; //return 'Selection: ${clientUIState.selectedId}';
//return '${clientState.map[clientUIState.selectedId].gatewayTokens}'; //return '${clientState.map[clientUIState.selectedId].gatewayTokens}';
//return 'gatewayId: ${companyGatewayState.map[companyGatewayUIState.selectedId].gatewayId}';
return '\n\nURL: ${authState.url}\nRoute: ${uiState.currentRoute}\nPrev: ${uiState.previousRoute}\nIs Loaded: ${isLoaded ? 'Yes' : 'No'}\nis Large: ${(company?.isLarge ?? false) ? 'Yes' : 'No'}\nCompany: $companyUpdated${userCompanyState.isStale ? ' [S]' : ''}\nStatic: $staticUpdated${staticState.isStale ? ' [S]' : ''}\n'; return '\n\nURL: ${authState.url}\nRoute: ${uiState.currentRoute}\nPrev: ${uiState.previousRoute}\nIs Loaded: ${isLoaded ? 'Yes' : 'No'}\nis Large: ${(company?.isLarge ?? false) ? 'Yes' : 'No'}\nCompany: $companyUpdated${userCompanyState.isStale ? ' [S]' : ''}\nStatic: $staticUpdated${staticState.isStale ? ' [S]' : ''}\n';
} }
} }

View File

@ -7,6 +7,7 @@ import 'package:invoiceninja_flutter/redux/company_gateway/company_gateway_selec
import 'package:invoiceninja_flutter/ui/app/FieldGrid.dart'; import 'package:invoiceninja_flutter/ui/app/FieldGrid.dart';
import 'package:invoiceninja_flutter/ui/app/entities/entity_list_tile.dart'; import 'package:invoiceninja_flutter/ui/app/entities/entity_list_tile.dart';
import 'package:invoiceninja_flutter/ui/app/entity_header.dart'; import 'package:invoiceninja_flutter/ui/app/entity_header.dart';
import 'package:invoiceninja_flutter/ui/app/icon_message.dart';
import 'package:invoiceninja_flutter/ui/app/lists/list_divider.dart'; import 'package:invoiceninja_flutter/ui/app/lists/list_divider.dart';
import 'package:invoiceninja_flutter/ui/app/view_scaffold.dart'; import 'package:invoiceninja_flutter/ui/app/view_scaffold.dart';
import 'package:invoiceninja_flutter/ui/company_gateway/view/company_gateway_view_vm.dart'; import 'package:invoiceninja_flutter/ui/company_gateway/view/company_gateway_view_vm.dart';
@ -64,13 +65,13 @@ class _CompanyGatewayViewState extends State<CompanyGatewayView> {
isFilter: widget.isFilter, isFilter: widget.isFilter,
entity: companyGateway, entity: companyGateway,
onBackPressed: () => viewModel.onBackPressed(), onBackPressed: () => viewModel.onBackPressed(),
body: ListView( body: ListView(children: <Widget>[
children: <Widget>[ EntityHeader(
EntityHeader( entity: companyGateway,
entity: companyGateway, label: localization.processed,
label: localization.processed, value: formatNumber(processed, context)),
value: formatNumber(processed, context)), ListDivider(),
ListDivider(), if (companyGateway.gateway.supportsTokenBilling) ...[
EntitiesListTile( EntitiesListTile(
isFilter: widget.isFilter, isFilter: widget.isFilter,
entityType: EntityType.client, entityType: EntityType.client,
@ -83,23 +84,23 @@ class _CompanyGatewayViewState extends State<CompanyGatewayView> {
companyGateway.id, state.clientState.map) companyGateway.id, state.clientState.map)
.present(localization.active, localization.archived), .present(localization.active, localization.archived),
), ),
ListDivider(),
EntitiesListTile(
isFilter: widget.isFilter,
entityType: EntityType.payment,
title: localization.payments,
onTap: () => viewEntitiesByType(
context: context,
entityType: EntityType.payment,
filterEntity: companyGateway),
subtitle: memoizedPaymentStatsForCompanyGateway(
companyGateway.id, state.paymentState.map)
.present(localization.active, localization.archived),
),
ListDivider(),
FieldGrid(fields),
], ],
), ListDivider(),
EntitiesListTile(
isFilter: widget.isFilter,
entityType: EntityType.payment,
title: localization.payments,
onTap: () => viewEntitiesByType(
context: context,
entityType: EntityType.payment,
filterEntity: companyGateway),
subtitle: memoizedPaymentStatsForCompanyGateway(
companyGateway.id, state.paymentState.map)
.present(localization.active, localization.archived),
),
ListDivider(),
FieldGrid(fields),
]),
); );
} }
} }