Skip to content
This repository has been archived by the owner on Dec 26, 2024. It is now read-only.

Commit

Permalink
Merge pull request #44 from Cassianky/update-vendor-price
Browse files Browse the repository at this point in the history
[Vendor/Client] Update add cart to save activity price rules
  • Loading branch information
ayangler authored Oct 29, 2023
2 parents f8f347d + bc2b48f commit ba38144
Show file tree
Hide file tree
Showing 11 changed files with 255 additions and 24 deletions.
2 changes: 1 addition & 1 deletion admin-frontend/src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ import AdminNotificationPage from "./components/notification/AdminNotificationPa
import VerifyEmailPage from "./components/VerifyEmailPage";
import ViewActiveBookingsPage from "./components/booking/ViewActiveBookingsPage";
import ViewPastBookingsPage from "./components/booking/ViewPastBookingsPage";
import ActivityThemesPage from "./components/activitythemes/ActivityThemesPage";
import ActivityThemesPage from "./components/activitytheme/ActivityThemesPage";

function App() {
return (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ const ActivityDetailsPage = () => {
const calculateWeekendAddOn = (
selectedDate,
weekendPricing,
totalBasePrice,
totalBasePrice
) => {
if (
weekendPricing.amount !== null &&
Expand All @@ -175,7 +175,7 @@ const ActivityDetailsPage = () => {
return 0;
};

const calculateOnlineAddOn = (location, onlinePricing, totalBasePrice) => {
const calculateOfflineAddOn = (location, onlinePricing, totalBasePrice) => {
if (
onlinePricing.amount !== null &&
(location.toLowerCase().includes("off-site") ||
Expand All @@ -190,7 +190,7 @@ const ActivityDetailsPage = () => {
return 0;
};

const calculateOfflineAddOn = (location, offlinePricing, totalBasePrice) => {
const calculateOnlineAddOn = (location, offlinePricing, totalBasePrice) => {
if (
offlinePricing.amount !== null &&
location.toLowerCase().includes("virtual")
Expand All @@ -211,16 +211,19 @@ const ActivityDetailsPage = () => {
const weekendAddOn = calculateWeekendAddOn(
selectedDate,
currentActivity.weekendPricing,
totalBasePrice
);

const onlineAddOn = calculateOnlineAddOn(
const offlineAddOn = calculateOfflineAddOn(
location,
currentActivity.offlinePricing,
totalBasePrice
);

const offlineAddOn = calculateOfflineAddOn(
const onlineAddOn = calculateOnlineAddOn(
location,
currentActivity.onlinePricing,
totalBasePrice
);

const totalPriceCalculated =
Expand All @@ -241,15 +244,24 @@ const ActivityDetailsPage = () => {
const weekendAddOn = calculateWeekendAddOn(
selectedDate,
currentActivity.weekendPricing,
totalBasePrice
);
const onlineAddOn = calculateOnlineAddOn(
const offlineAddOn = calculateOfflineAddOn(
location,
currentActivity.offlinePricing,
totalBasePrice
);
const offlineAddOn = calculateOfflineAddOn(
const onlineAddOn = calculateOnlineAddOn(
location,
currentActivity.onlinePricing,
totalBasePrice
);
let activityPricingRule;
for (const pricingRule of currentActivity?.activityPricingRules) {
if (pax >= pricingRule.start && pax <= pricingRule.end) {
activityPricingRule = pricingRule;
}
}
const timeParts = time.split(",");
const cartItem = {
activityId: currentActivity._id,
Expand All @@ -262,6 +274,7 @@ const ActivityDetailsPage = () => {
offlineAddOnCost: offlineAddOn,
startDateTime: timeParts[0],
endDateTime: timeParts[1],
activityPricingRule: activityPricingRule._id,
};
if (
cartItem.activityId !== null &&
Expand Down Expand Up @@ -435,7 +448,7 @@ const ActivityDetailsPage = () => {
format="DD/MM/YYYY"
minDate={dayjs().add(
currentActivity?.bookingNotice,
"days",
"days"
)}
shouldDisableDate={shouldDisableDate}
sx={{ marginRight: "12px" }}
Expand Down Expand Up @@ -593,8 +606,9 @@ const ActivityDetailsPage = () => {
? "-"
: ""}
{currentActivity?.weekendPricing?.amount?.toFixed(
2,
2
)}
%
</Typography>
</Box>
</Box>
Expand All @@ -615,8 +629,9 @@ const ActivityDetailsPage = () => {
: "+"}
{""}
{currentActivity?.offlinePricing?.amount?.toFixed(
2,
)}
2
)}{" "}
%
</Typography>
</Box>
</Box>
Expand All @@ -636,8 +651,9 @@ const ActivityDetailsPage = () => {
: "+"}
{""}
{currentActivity?.onlinePricing?.amount?.toFixed(
2,
2
)}
%
</Typography>
</Box>
</Box>
Expand Down
132 changes: 132 additions & 0 deletions client-frontend/src/containers/Vendor/Booking/BookingDetailsForm.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ import PaidIcon from "@mui/icons-material/Paid";
import ThumbUpAltIcon from "@mui/icons-material/ThumbUpAlt";
import {
Grid,
InputAdornment,
List,
ListItem,
ListItemIcon,
ListItemText,
Paper,
Table,
TableBody,
TableCell,
TableContainer,
TableHead,
TableRow,
TextField,
Typography,
useTheme,
Expand Down Expand Up @@ -39,6 +47,36 @@ const BookingDetailsForm = ({ appointmentData }) => {
PENDING_PAYMENT: "Updated to Pending Payment",
PAID: "Updated to Paid",
};
const totalPrice = () => {
return (
appointmentData?.totalPax *
appointmentData?.activityPricingRule?.pricePerPax
);
};

const addons = {
weekendPricing: {
name: "Weekend Pricing",
vendor: "vendorWeekendAddOnCost",
},
onlinePricing: { name: "Online Pricing", vendor: "vendorOnlineAddOnCost" },
offlinePricing: {
name: "Offline Pricing",
vendor: "vendorOfflineAddOnCost",
},
};

const addOnNaming = (addon) => {
return addons[addon]?.name;
};

const vendorNaming = (addon) => {
return addons[addon]?.vendor;
};

const calculateTotal = () => {
return;
};
return (
<Grid
container
Expand Down Expand Up @@ -133,6 +171,100 @@ const BookingDetailsForm = ({ appointmentData }) => {
fullWidth
/>
</Grid>
<Grid item xs={12} paddingTop={2}>
<TableContainer
component={Paper}
sx={{
borderRadius: "10px",
}}
>
<Table>
<TableHead>
<TableRow sx={{ backgroundColor: "rgba(159 145 204 / 0.12)" }}>
<TableCell width={"33%"} sx={{ fontSize: "1rem" }}>
<span style={{ color: "#3D246C" }}>Num. pax</span>
</TableCell>
<TableCell width={"33%"} sx={{ fontSize: "1rem" }}>
<span style={{ color: "#3D246C" }}>Price per Pax</span>
</TableCell>
<TableCell width={"33%"} sx={{ fontSize: "1rem" }}>
<span style={{ color: "#3D246C" }}>Total Price</span>
</TableCell>
</TableRow>
</TableHead>
<TableBody>
<TableRow>
<TableCell sx={{ fontSize: "0.875rem" }}>
<span style={{ color: "#3D246C" }}>
{appointmentData?.totalPax} pax
</span>
</TableCell>
<TableCell sx={{ fontSize: "0.875rem" }}>
<span style={{ color: "#3D246C" }}>
${appointmentData?.activityPricingRule?.pricePerPax}
</span>
</TableCell>
<TableCell sx={{ fontSize: "0.875rem" }}>
<span style={{ color: "#3D246C" }}>${totalPrice()}</span>
</TableCell>
</TableRow>

{appointmentData?.activityId &&
Object.keys(appointmentData?.activityId)?.map(
(addon, index) => {
return (
appointmentData[vendorNaming(addon)] != 0 &&
!isNaN(appointmentData[vendorNaming(addon)]) &&
appointmentData?.activityId[addon].amount && (
<TableRow key={index}>
<TableCell />
<TableCell sx={{ fontSize: "1rem" }}>
<span style={{ color: "#3D246C" }}>
{addOnNaming(addon)}
{appointmentData?.activityId[addon].isDiscount
? " Discount"
: " Add-on"}
</span>
</TableCell>
<TableCell sx={{ fontSize: "0.875rem" }}>
<span style={{ color: "#3D246C" }}>
{appointmentData?.activityId[addon].isDiscount
? "-"
: "+"}
{appointmentData?.activityId[addon].amount}%{" "}
<span
style={{ color: theme.palette.primary.main }}
>
(
{appointmentData?.activityId[addon].isDiscount
? "-"
: "+"}{" "}
$
{Math.abs(appointmentData[vendorNaming(addon)])}
)
</span>
</span>
</TableCell>
</TableRow>
)
);
}
)}
<TableRow>
<TableCell />
<TableCell sx={{ fontSize: "1rem" }}>
<span style={{ color: "#3D246C" }}>Total Price</span>
</TableCell>
<TableCell sx={{ fontSize: "0.875rem" }}>
<span style={{ color: "#3D246C" }}>
${appointmentData?.totalVendorAmount}
</span>
</TableCell>
</TableRow>
</TableBody>
</Table>
</TableContainer>
</Grid>
<Grid item xs={12}>
<Typography fontSize={"1.5rem"} color={theme.palette.primary.main}>
Status Changelog
Expand Down
Loading

0 comments on commit ba38144

Please sign in to comment.