diff --git a/pages/api/shiftgenerate.ts b/pages/api/shiftgenerate.ts index 2a35b75..784bc9e 100644 --- a/pages/api/shiftgenerate.ts +++ b/pages/api/shiftgenerate.ts @@ -60,6 +60,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { var autoFill = common.parseBool(req.query.autoFill); var forDay = common.parseBool(req.query.forDay); var type = parseInt(req.query.type) || 0; + var repeat = common.parseBool(req.query.repeat); if (type == 2) { // var result = await GenerateOptimalSchedule(axios, date, copyFromPreviousMonth, autoFill, forDay, type); var result = await GenerateScheduleNew(axios, date, copyFromPreviousMonth, autoFill, forDay, type); @@ -76,7 +77,7 @@ async function handler(req: NextApiRequest, res: NextApiResponse) { originalConsoleLog.apply(console, arguments); }; - var result = await GenerateSchedule(axios, date, copyFromPreviousMonth, autoFill, forDay, type); + var result = await GenerateSchedule(axios, date, copyFromPreviousMonth, autoFill, forDay, type, undefined, repeat); // Restore the original console.log console.log = originalConsoleLog; @@ -183,7 +184,7 @@ function updatePublishersWithCurrentCounts(publishers) { } -async function GenerateSchedule(axios, date, copyFromPreviousMonth = false, autoFill = false, forDay, algType = 0, until) { +async function GenerateSchedule(axios, date, copyFromPreviousMonth = false, autoFill = false, forDay, algType = 0, until, doRepeatLast = true) { let missingPublishers = []; let publishersWithChangedPref = []; @@ -287,25 +288,27 @@ async function GenerateSchedule(axios, date, copyFromPreviousMonth = false, auto //--------------------------------------------------- // // COMMENT TO DISABLE COPY FROM LAST MONTH - // if (availability && copyFromPreviousMonth && !publishersThisWeek.includes(publisher.id)) { - // const transportCount = shiftAssignments.filter(a => a.isWithTransport).length; - // const isWithTransport = availability.isWithTransportIn || availability.isWithTransportOut; + if (doRepeatLast) { + if (availability && copyFromPreviousMonth && !publishersThisWeek.includes(publisher.id)) { + const transportCount = shiftAssignments.filter(a => a.isWithTransport).length; + const isWithTransport = availability.isWithTransportIn || availability.isWithTransportOut; - // if (!isWithTransport || transportCount < 2) { - // shiftAssignments.push({ - // publisherId: publisher.id, - // isConfirmed: true, - // isBySystem: true, - // isWithTransport: isWithTransport - // }); - // publishersThisWeek.push(publisher.id); - // updateRegistry(publisher.id, day, weekNr); - // publisher.currentMonthAssignments += 1; - // } - // else { - // console.log(" " + publisher.firstName + " " + publisher.lastName + " skipped (transport already assigned)"); - // } - // } + if (!isWithTransport || transportCount < 2) { + shiftAssignments.push({ + publisherId: publisher.id, + isConfirmed: true, + isBySystem: true, + isWithTransport: isWithTransport + }); + publishersThisWeek.push(publisher.id); + updateRegistry(publisher.id, day, weekNr); + publisher.currentMonthAssignments += 1; + } + else { + console.log(" " + publisher.firstName + " " + publisher.lastName + " skipped (transport already assigned)"); + } + } + } //--------------------------------------------------- } diff --git a/pages/cart/calendar/index.tsx b/pages/cart/calendar/index.tsx index 70fb116..48d84b1 100644 --- a/pages/cart/calendar/index.tsx +++ b/pages/cart/calendar/index.tsx @@ -86,6 +86,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) { const handleCheckboxChange = (event) => { setFilterShowWithoutAssignments(!filterShowWithoutAssignments); // Toggle the checkbox state }; + const [repeatEnabled, setRepeatEnabled] = useState(true); useEffect(() => { console.log("checkbox checked: " + filterShowWithoutAssignments); @@ -445,7 +446,7 @@ export default function CalendarPage({ initialEvents, initialShifts }) { const generateShifts = async (buttonId, copyFromPrevious = false, autoFill = false, forDay?: Boolean | null, type = 0) => { try { setActiveButton(buttonId); - const endpoint = `/api/shiftgenerate?action=generate&date=${common.getISODateOnly(value)}©FromPreviousMonth=${copyFromPrevious}&autoFill=${autoFill}&forDay=${forDay}&type=${type}`; + const endpoint = `/api/shiftgenerate?action=generate&date=${common.getISODateOnly(value)}©FromPreviousMonth=${copyFromPrevious}&autoFill=${autoFill}&forDay=${forDay}&type=${type}&repeat=${repeatEnabled}`; const { shifts } = await axiosInstance.get(endpoint); toast.success('Готово!', { autoClose: 1000 }); setIsMenuOpen(false); @@ -728,9 +729,22 @@ export default function CalendarPage({ initialEvents, initialShifts }) { - + {/* ✧✨ */} {/*