Skip to content

Commit

Permalink
Merge pull request #867 from DGB-UNAM-FOLIO/UNAM
Browse files Browse the repository at this point in the history
Add fee/fine fixes
  • Loading branch information
mkuklis authored Jun 11, 2019
2 parents f6dbfe6 + e916024 commit f63c9d5
Show file tree
Hide file tree
Showing 13 changed files with 96 additions and 67 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
* Fix field label for manual charges settings. Fix UIU-950.
* Fix default Fee/Fine Owner Desk. Fix UIU-948.
* Fix ability to edit users with "can edit users permission". Fixes UIU-1066.
* Fixes fees/fines.
* Fix UX Consistency for New Fee/Fine. Fix UIU-1052.

## [2.22.0](https://github.com/folio-org/ui-users/tree/v2.22.0) (2019-05-10)
[Full Changelog](https://github.com/folio-org/ui-users/compare/v2.22.0...v2.22.0)
Expand Down
18 changes: 12 additions & 6 deletions src/AccountActionsHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class AccountActionsHistory extends React.Component {
account: PropTypes.object,
num: PropTypes.number.isRequired,
user: PropTypes.object,
currentUser: PropTypes.object,
history: PropTypes.object,
patronGroup: PropTypes.object,
onCancel: PropTypes.func.isRequired,
Expand Down Expand Up @@ -227,14 +228,15 @@ class AccountActionsHistory extends React.Component {
const {
handleAddRecords,
onCancel,
currentUser,
onClickViewLoanActionsHistory,
patronGroup: patron,
resources,
stripes,
user,
} = this.props;

const account = _.get(resources, ['accountHistory', 'records', 0]) || this.props.account;
const account = _.get(resources, ['accountHistory', 'records', 0]) || {};
account.remaining = this.state.remaining;

const columnMapping = {
Expand Down Expand Up @@ -271,11 +273,14 @@ class AccountActionsHistory extends React.Component {
comments: action => (action.comments ? (<div>{action.comments.split('\n').map(c => (<Row><Col>{c}</Col></Row>))}</div>) : ''),
};

const isAccountsPending = _.get(resources, ['accountHistory', 'isPending'], true);
const isActionsPending = _.get(resources, ['accountActions', 'isPending'], true);

const actions = this.state.data || [];
const actionsSort = _.orderBy(actions, [this.sortMap[sortOrder[0]], this.sortMap[sortOrder[1]]], sortDirection);
const amount = (account.amount) ? parseFloat(account.amount).toFixed(2) : '-';
const loanId = account.loanId || '';
const disabled = (_.get(account, ['status', 'name'], '') === 'Closed');
const disabled = account.remaining === 0;
const isAccountId = actions[0] && actions[0].accountId === account.id;
const buttonDisabled = !this.props.stripes.hasPerm('ui-users.feesfines.actions.all');

Expand All @@ -296,15 +301,15 @@ class AccountActionsHistory extends React.Component {
<Col xs={12}>
<Button
id="payAccountActionsHistory"
disabled={!((disabled === false) && (buttonDisabled === false))}
disabled={disabled || buttonDisabled || isActionsPending || isAccountsPending}
buttonStyle="primary"
onClick={this.pay}
>
<FormattedMessage id="ui-users.accounts.history.button.pay" />
</Button>
<Button
id="waveAccountActionsHistory"
disabled={!((disabled === false) && (buttonDisabled === false))}
disabled={disabled || buttonDisabled || isActionsPending || isAccountsPending}
buttonStyle="primary"
onClick={this.waive}
>
Expand All @@ -319,15 +324,15 @@ class AccountActionsHistory extends React.Component {
</Button>
<Button
id="transferAccountActionsHistory"
disabled={!((disabled === false) && (buttonDisabled === false))}
disabled={disabled || buttonDisabled || isActionsPending || isAccountsPending}
buttonStyle="primary"
onClick={this.transfer}
>
<FormattedMessage id="ui-users.accounts.history.button.transfer" />
</Button>
<Button
id="errorAccountActionsHistory"
disabled={!((disabled === false) && (buttonDisabled === false))}
disabled={disabled || buttonDisabled || isActionsPending || isAccountsPending}
buttonStyle="primary"
onClick={this.error}
>
Expand Down Expand Up @@ -493,6 +498,7 @@ class AccountActionsHistory extends React.Component {
actions={this.state.actions}
onChangeActions={this.onChangeActions}
user={user}
currentUser={currentUser}
stripes={stripes}
balance={account.remaining || 0}
accounts={[account]}
Expand Down
13 changes: 9 additions & 4 deletions src/AccountsHistory.js
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ class AccountsHistory extends React.Component {
records: 'accounts',
path: 'accounts',
recordsRequired: '%{activeRecord.records}',
perRequest: 50,
perRequest: 100,
GET: {
params: {
query: queryFunction(
Expand All @@ -142,7 +142,7 @@ class AccountsHistory extends React.Component {
staticFallback: { params: {} },
},
},
activeRecord: { records: 50 },
activeRecord: { records: 100 },
user: {},
});

Expand Down Expand Up @@ -217,7 +217,7 @@ class AccountsHistory extends React.Component {
this.connectedActions = props.stripes.connect(Actions);

this.accounts = [];
this.addRecord = 50;
this.addRecord = 100;
this.editRecord = 0;

this.transitionToParams = values => this.props.parentMutator.query.update(values);
Expand All @@ -234,7 +234,7 @@ class AccountsHistory extends React.Component {
}

componentDidMount() {
this.props.mutator.activeRecord.update({ records: 50, comments: 200, userId: this.props.user.id });
this.props.mutator.activeRecord.update({ records: 100, comments: 200, userId: this.props.user.id });
args[0].value = this.props.user.id;
}

Expand Down Expand Up @@ -360,6 +360,7 @@ class AccountsHistory extends React.Component {

onChangeSelectedAccounts(selectedAccounts) {
this.setState({ selectedAccounts });
this.accounts = selectedAccounts;
}

toggleFilterPane = () => {
Expand Down Expand Up @@ -418,6 +419,7 @@ class AccountsHistory extends React.Component {
const {
location,
user,
currentUser,
patronGroup,
resources,
intl,
Expand Down Expand Up @@ -589,6 +591,7 @@ class AccountsHistory extends React.Component {
{...this.props}
accounts={(user.id === (accounts[0] || {}).userId) ? open : []}
visibleColumns={visibleColumns}
selectedAccounts={selectedAccounts}
onChangeSelected={this.onChangeSelected}
onChangeActions={this.onChangeActions}
/>) : ''
Expand All @@ -598,6 +601,7 @@ class AccountsHistory extends React.Component {
{...this.props}
accounts={(user.id === (accounts[0] || {}).userId) ? closed : []}
visibleColumns={visibleColumns}
selectedAccounts={selectedAccounts}
onChangeSelected={this.onChangeSelected}
onChangeActions={this.onChangeActions}
/>) : ''
Expand All @@ -618,6 +622,7 @@ class AccountsHistory extends React.Component {
layer={query.layer}
onChangeActions={this.onChangeActions}
user={user}
currentUser={currentUser}
accounts={this.accounts}
selectedAccounts={selectedAccounts}
onChangeSelectedAccounts={this.onChangeSelectedAccounts}
Expand Down
2 changes: 2 additions & 0 deletions src/ViewUser.js
Original file line number Diff line number Diff line change
Expand Up @@ -649,6 +649,7 @@ class ViewUser extends React.Component {
num={(this.state.addRecord ? 51 : 50)}
onClickViewLoanActionsHistory={this.onClickViewLoanActionsHistory}
user={user}
currentUser={currentUser}
parentMutator={mutator}
patronGroup={patronGroup}
stripes={stripes}
Expand Down Expand Up @@ -700,6 +701,7 @@ class ViewUser extends React.Component {
>
<this.connectedAccountActionsHistory
user={user}
currentUser={currentUser}
patronGroup={patronGroup}
account={this.state.selectedAccount}
accountid={this.state.selectedAccount.id}
Expand Down
4 changes: 2 additions & 2 deletions src/components/Accounts/Actions/Actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class Actions extends React.Component {
},
curUserServicePoint: {
type: 'okapi',
path: 'service-points-users?query=(userId==!{user.id})',
path: 'service-points-users?query=(userId==!{currentUser.id})',
records: 'servicePointsUsers',
},
activeRecord: {},
Expand Down Expand Up @@ -595,7 +595,7 @@ class Actions extends React.Component {
const defaultServicePointId = _.get(resources, ['curUserServicePoint', 'records', 0, 'defaultServicePointId'], '-');
const servicePointsIds = _.get(resources, ['curUserServicePoint', 'records', 0, 'servicePointsIds'], []);
const payments = _.get(resources, ['payments', 'records'], []);
const owners = _.get(resources, ['owners', 'records'], []);
const owners = _.get(resources, ['owners', 'records'], []).filter(o => o.owner !== 'Shared');
const feefines = _.get(resources, ['feefineTypes', 'records'], []);
const waives = _.get(resources, ['waives', 'records'], []);
const transfers = _.get(resources, ['transfers', 'records'], []);
Expand Down
17 changes: 9 additions & 8 deletions src/components/Accounts/Actions/PayManyModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -117,18 +117,19 @@ class PayModal extends React.Component {
const servicePoint = this.props.defaultServicePointId;
const servicePoints = this.props.servicePointsIds;
const owners = this.props.owners || [];
let ownerId = 0;
if (servicePoint && servicePoint !== '-') {
owners.forEach(o => {
if (o.servicePointOwner && o.servicePointOwner.find(s => s.value === servicePoint)) {
this.props.initialize({ ownerId: o.id, ...initial });
ownerId = o.id;
this.onChangeOwner({ target: { value: o.id } });
}
});
} else if (servicePoints.length === 1) {
const sp = servicePoints[0];
owners.forEach(o => {
if (o.servicePointOwner && o.servicePointOwner.find(s => s.value === sp)) {
this.props.initialize({ ownerId: o.id, ...initial });
ownerId = o.id;
this.onChangeOwner({ target: { value: o.id } });
}
});
Expand All @@ -137,11 +138,12 @@ class PayModal extends React.Component {
const sp2 = servicePoints[1];
owners.forEach(o => {
if (o.servicePointOwner && o.servicePointOwner.find(s => s.value === sp1) && o.servicePointOwner.find(s => s.value === sp2)) {
this.props.initialize({ ownerId: o.id, ...initial });
ownerId = o.id;
this.onChangeOwner({ target: { value: o.id } });
}
});
}
this.props.initialize(ownerId ? { ownerId, ...initial } : { ...initial });
}

onChangeAmount = (e) => {
Expand All @@ -158,23 +160,23 @@ class PayModal extends React.Component {

onClose = () => {
const {
accounts,
onClose,
reset,
} = this.props;

const selected = this.calculateSelectedAmount(accounts);
this.setState({ amount: selected });
onClose();
reset();
}

onSubmit = () => {
const {
handleSubmit,
reset,
} = this.props;

handleSubmit();
reset();
this.setState({ amount: this.initialAmount });
}

onChangeOwner = (e) => {
Expand Down Expand Up @@ -232,7 +234,6 @@ class PayModal extends React.Component {
submitting,
invalid,
pristine,
onClose,
open,
owners,
payments,
Expand All @@ -256,7 +257,7 @@ class PayModal extends React.Component {
<Modal
open={open}
label={<FormattedMessage id="ui-users.accounts.pay.payFeeFine" />}
onClose={onClose}
onClose={this.onClose}
size="medium"
dismissible
>
Expand Down
30 changes: 15 additions & 15 deletions src/components/Accounts/Actions/PayModal.js
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,10 @@ class PayModal extends React.Component {
shouldComponentUpdate(nextProps, nextState) {
if (!_.isEqual(this.props.accounts, nextProps.accounts)) {
const accounts = nextProps.accounts || [];
let selected = parseFloat(0);
let showNotify = false;
let notify = false;
const selected = this.calculateSelectedAmount(accounts);
accounts.forEach(a => {
selected += parseFloat(a.remaining);
const feefine = this.props.feefines.find(f => f.id === a.feeFineId.substring(0, 36)) || {};
const owner = this.props.owners.find(o => o.id === a.ownerId) || {};
if (feefine.actionNoticeId || owner.defaultActionNoticeId) {
Expand All @@ -100,13 +99,13 @@ class PayModal extends React.Component {
}
});
this.setState({
amount: parseFloat(selected).toFixed(2),
amount: selected,
showNotify,
notify
});

this.initialAmount = parseFloat(selected).toFixed(2);
this.props.initialize({ amount: parseFloat(selected).toFixed(2), notify: true });
this.initialAmount = selected;
this.props.initialize({ amount: selected, notify: true });
}

return (this.props.accounts !== nextProps.accounts
Expand All @@ -130,10 +129,13 @@ class PayModal extends React.Component {

onClose = () => {
const {
accounts,
onClose,
reset,
} = this.props;

const selected = this.calculateSelectedAmount(accounts);
this.setState({ amount: selected });
onClose();
reset();
}
Expand All @@ -144,24 +146,24 @@ class PayModal extends React.Component {
} = this.props;

handleSubmit();
this.setState({ amount: this.initialAmount });
}

calculateSelectedAmount() {
const { accounts } = this.props;
return accounts.reduce((selected, { remaining }) => {
return selected + parseFloat(remaining);
calculateSelectedAmount(accounts) {
const selected = accounts.reduce((s, { remaining }) => {
return s + parseFloat(remaining * 100);
}, 0);
return parseFloat(selected / 100).toFixed(2);
}

renderFormMessage() {
const {
accounts = [],
} = this.props;


const { amount } = this.state;

const selected = this.calculateSelectedAmount();
const selected = this.calculateSelectedAmount(accounts);
const payAmount = amount === ''
? 0.00
: amount;
Expand Down Expand Up @@ -197,16 +199,14 @@ class PayModal extends React.Component {
submitting,
invalid,
pristine,
onClose,
open,
payments,
commentRequired,
balance: totalAmount,
} = this.props;

const { amount } = this.state;

const selected = this.calculateSelectedAmount();
const selected = this.calculateSelectedAmount(accounts);
const account = (accounts[0] || {});
const remaining = parseFloat(totalAmount - amount).toFixed(2);
let dataOptions = payments.filter(p => p.ownerId === account.ownerId);
Expand All @@ -222,7 +222,7 @@ class PayModal extends React.Component {
id="pay-modal"
open={open}
label={<FormattedMessage id="ui-users.accounts.pay.payFeeFine" />}
onClose={onClose}
onClose={this.onClose}
size="medium"
dismissible
>
Expand Down
Loading

0 comments on commit f63c9d5

Please sign in to comment.