Files
old-crm-integration/client/src/scenes/PracticeSummaryReport/components/MemberSummary.js

92 lines
3.6 KiB
JavaScript
Raw Normal View History

2019-06-20 14:18:36 +02:00
import React from 'react';
import { Loader, Grid } from 'semantic-ui-react';
2019-07-07 07:02:42 +02:00
import {
UNSCHEDULED_INCIDENT_BEFORE_RESERVATION,
UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION,
2019-07-08 20:37:14 +02:00
UNSCHEDULED_INCIDENT_AFTER_RESERVATION, UNSCHEDULED_INCIDENT_STANDALONE, UNLOCKED_INCIDENT_STANDALONE,
BOOKING_MOVED_TO_ANOTHER_DAY, BOOKING_SHORTENED,
2019-07-07 07:02:42 +02:00
} from '../../../constants/enums';
2019-06-20 14:18:36 +02:00
const MemberSummary = props => {
const { loading } = props;
const incidents = props.incidents ? props.incidents : [];
let totalUnscheduledFees = 0;
let totalUnlockedFees = 0;
2019-07-08 20:37:14 +02:00
let totalBookingChangeFees = 0;
2019-06-20 14:18:36 +02:00
incidents.forEach((incident) => {
switch (incident.incidentType) {
2019-07-07 07:02:42 +02:00
case UNSCHEDULED_INCIDENT_BEFORE_RESERVATION:
case UNSCHEDULED_INCIDENT_AFTER_RESERVATION:
case UNSCHEDULED_INCIDENT_STANDALONE:
2019-06-20 14:18:36 +02:00
totalUnscheduledFees += parseFloat(incident.totalChargeFee);
break;
2019-07-07 07:02:42 +02:00
case UNLOCKED_INCIDENT_RELATED_WITH_RESERVATION:
case UNLOCKED_INCIDENT_STANDALONE:
2019-06-20 14:18:36 +02:00
totalUnlockedFees += parseFloat(incident.incidentPrice);
break;
2019-07-08 20:37:14 +02:00
case BOOKING_MOVED_TO_ANOTHER_DAY:
case BOOKING_SHORTENED:
totalBookingChangeFees += parseFloat(incident.totalChargeFee);
break;
2019-06-25 15:44:46 +02:00
default:
break;
2019-06-20 14:18:36 +02:00
}
});
2019-07-08 20:37:14 +02:00
const grandTotal = totalUnlockedFees + totalUnscheduledFees + totalBookingChangeFees;
2019-06-20 14:18:36 +02:00
const formattedUnscheduledFees = `$ ${totalUnscheduledFees.toFixed(2)}`;
const formattedUnlockedFees = `$ ${totalUnlockedFees.toFixed(2)}`;
2019-07-08 20:37:14 +02:00
const formattedBookingChangeFees = `$ ${totalBookingChangeFees.toFixed(2)}`;
2019-06-20 14:18:36 +02:00
const formattedGrandTotalFee = `$ ${grandTotal.toFixed(2)}`;
return (
<div>
<h4>Member Summary for selected period</h4>
<Loader active={loading} />
{
!loading &&
<Grid stackable>
<Grid.Row>
2019-07-08 20:37:14 +02:00
<Grid.Column width={4}>
2019-06-20 14:18:36 +02:00
<p>Unscheduled incidents total :</p>
</Grid.Column>
<Grid.Column width={9}>
<p>{formattedUnscheduledFees}</p>
</Grid.Column>
</Grid.Row>
<Grid.Row>
2019-07-08 20:37:14 +02:00
<Grid.Column width={4}>
2019-06-20 14:18:36 +02:00
<p>Unlocked incidents total :</p>
</Grid.Column>
<Grid.Column width={9}>
<p>{formattedUnlockedFees}</p>
</Grid.Column>
</Grid.Row>
<Grid.Row>
2019-07-08 20:37:14 +02:00
<Grid.Column width={4}>
<p>Booking change charges total :</p>
</Grid.Column>
<Grid.Column width={9}>
<p>{formattedBookingChangeFees}</p>
</Grid.Column>
</Grid.Row>
<Grid.Row>
<Grid.Column width={4}>
2019-06-20 14:18:36 +02:00
<p><b>Grand Total :</b></p>
</Grid.Column>
<Grid.Column width={9}>
<p><b>{formattedGrandTotalFee}</b></p>
</Grid.Column>
</Grid.Row>
</Grid>
}
</div>
);
};
2019-06-19 11:23:58 +02:00
export default MemberSummary;