Add client.payment_balance
This commit is contained in:
parent
c872271793
commit
04857ad5e4
|
|
@ -162,39 +162,6 @@ SettingsEntity getVendorSettings(AppState state, VendorEntity vendor) {
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
var memoizedGetClientUnappliedPayments = memo2(
|
|
||||||
(String clientId, BuiltMap<String, PaymentEntity> paymentMap) =>
|
|
||||||
getClientUnappliedPayments(clientId: clientId, paymentMap: paymentMap));
|
|
||||||
|
|
||||||
double getClientUnappliedPayments(
|
|
||||||
{String clientId, BuiltMap<String, PaymentEntity> paymentMap}) {
|
|
||||||
double amount = 0;
|
|
||||||
|
|
||||||
paymentMap.forEach((paymentId, payment) {
|
|
||||||
if (!payment.isDeleted && payment.clientId == clientId) {
|
|
||||||
amount += payment.amount - payment.applied;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
var memoizedGetClientAvailableCredits = memo2(
|
|
||||||
(String clientId, BuiltMap<String, InvoiceEntity> creditMap) =>
|
|
||||||
getClientAvailableCredits(clientId: clientId, creditMap: creditMap));
|
|
||||||
|
|
||||||
double getClientAvailableCredits(
|
|
||||||
{String clientId, BuiltMap<String, InvoiceEntity> creditMap}) {
|
|
||||||
double amount = 0;
|
|
||||||
|
|
||||||
creditMap.forEach((creditId, credit) {
|
|
||||||
if (!credit.isDeleted && credit.clientId == clientId) {
|
|
||||||
amount += credit.balance;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
return amount;
|
|
||||||
}
|
|
||||||
|
|
||||||
bool hasClientChanges(
|
bool hasClientChanges(
|
||||||
ClientEntity client, BuiltMap<String, ClientEntity> clientMap) =>
|
ClientEntity client, BuiltMap<String, ClientEntity> clientMap) =>
|
||||||
|
|
|
||||||
|
|
@ -77,11 +77,6 @@ class _ClientViewFullwidthState extends State<ClientViewFullwidth>
|
||||||
!state.uiState.isEditing &&
|
!state.uiState.isEditing &&
|
||||||
state.prefState.isModuleTable;
|
state.prefState.isModuleTable;
|
||||||
|
|
||||||
final availableCredits =
|
|
||||||
memoizedGetClientAvailableCredits(client.id, state.creditState.map);
|
|
||||||
final unappliedPayments =
|
|
||||||
memoizedGetClientUnappliedPayments(client.id, state.paymentState.map);
|
|
||||||
|
|
||||||
// Group gateway tokens by the customerReference
|
// Group gateway tokens by the customerReference
|
||||||
final tokenMap = <String, List<GatewayTokenEntity>>{};
|
final tokenMap = <String, List<GatewayTokenEntity>>{};
|
||||||
final gatewayMap = <String, CompanyGatewayEntity>{};
|
final gatewayMap = <String, CompanyGatewayEntity>{};
|
||||||
|
|
@ -132,15 +127,15 @@ class _ClientViewFullwidthState extends State<ClientViewFullwidth>
|
||||||
style: Theme.of(context).textTheme.headline6,
|
style: Theme.of(context).textTheme.headline6,
|
||||||
),
|
),
|
||||||
SizedBox(height: 8),
|
SizedBox(height: 8),
|
||||||
if (availableCredits != 0)
|
if (client.paymentBalance != 0)
|
||||||
Text(localization.credit +
|
|
||||||
': ' +
|
|
||||||
formatNumber(availableCredits, context,
|
|
||||||
clientId: client.id)),
|
|
||||||
if (unappliedPayments != 0)
|
|
||||||
Text(localization.payments +
|
Text(localization.payments +
|
||||||
': ' +
|
': ' +
|
||||||
formatNumber(unappliedPayments, context,
|
formatNumber(client.paymentBalance, context,
|
||||||
|
clientId: client.id)),
|
||||||
|
if (client.creditBalance != 0)
|
||||||
|
Text(localization.credit +
|
||||||
|
': ' +
|
||||||
|
formatNumber(client.creditBalance, context,
|
||||||
clientId: client.id)),
|
clientId: client.id)),
|
||||||
if (client.idNumber.isNotEmpty)
|
if (client.idNumber.isNotEmpty)
|
||||||
Padding(
|
Padding(
|
||||||
|
|
|
||||||
|
|
@ -119,11 +119,6 @@ class ClientOverview extends StatelessWidget {
|
||||||
value: client.customValue4);
|
value: client.customValue4);
|
||||||
}
|
}
|
||||||
|
|
||||||
final availableCredits =
|
|
||||||
memoizedGetClientAvailableCredits(client.id, state.creditState.map);
|
|
||||||
final unappliedPayments =
|
|
||||||
memoizedGetClientUnappliedPayments(client.id, state.paymentState.map);
|
|
||||||
|
|
||||||
return ScrollableListView(
|
return ScrollableListView(
|
||||||
children: <Widget>[
|
children: <Widget>[
|
||||||
EntityHeader(
|
EntityHeader(
|
||||||
|
|
@ -135,20 +130,20 @@ class ClientOverview extends StatelessWidget {
|
||||||
formatNumber(client.balance, context, clientId: client.id),
|
formatNumber(client.balance, context, clientId: client.id),
|
||||||
),
|
),
|
||||||
ListDivider(),
|
ListDivider(),
|
||||||
if (availableCredits != 0 || unappliedPayments != 0) ...[
|
if (client.creditBalance != 0 || client.paymentBalance != 0) ...[
|
||||||
Padding(
|
Padding(
|
||||||
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
padding: const EdgeInsets.symmetric(horizontal: 20, vertical: 12),
|
||||||
child:
|
child:
|
||||||
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
|
||||||
if (availableCredits != 0)
|
if (client.paymentBalance != 0)
|
||||||
Text(localization.credit +
|
|
||||||
': ' +
|
|
||||||
formatNumber(availableCredits, context,
|
|
||||||
clientId: client.id)),
|
|
||||||
if (unappliedPayments != 0)
|
|
||||||
Text(localization.payments +
|
Text(localization.payments +
|
||||||
': ' +
|
': ' +
|
||||||
formatNumber(unappliedPayments, context,
|
formatNumber(client.paymentBalance, context,
|
||||||
|
clientId: client.id)),
|
||||||
|
if (client.creditBalance != 0)
|
||||||
|
Text(localization.credit +
|
||||||
|
': ' +
|
||||||
|
formatNumber(client.creditBalance, context,
|
||||||
clientId: client.id)),
|
clientId: client.id)),
|
||||||
]),
|
]),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue