0

I'm developping a borrowing website for my job. We have some equipments that we can borrow for certain period(s) of time. I have a MySql dataBase with a table Article(id,name,stockQuantity,...) and Rent(id,id_user,date_start,date_end,quantity)

After days of fighting with FullCalendar, i don't know how to handle my problems. I need to handle the quantity for some equipments, and I don't know how to lock certains days if there is not available equipements.

Example: Article => PC DELL 720, stockQuantity => 3 , if this Article is borrowed by 3 persons the same day of different days, I need to lock this(ese) days, and handle overlapings times and quantities...

And how to manage this "quantity" parameters in FullCalendar ... I could easily use this calendar if I had only a quantity equal to 1.

If someone had faced a similar problem(s) :D

Thanks and sorry for my english.

My current code:

$(document).ready(function()

{

let calendarEl = document.getElementById('calendrier');
let today = new Date();
let calendar = new FullCalendar.Calendar(calendarEl, {
    // On charge le composant "dayGrid"
    plugins: [ 'dayGrid', 'list', 'interaction' ],
    locale: 'fr',
    buttonText: {
        today:    'Aujourd\'hui',
    },
    events:"/location/loadAllById/"+$('#calendrier').attr('id_article'),
    dayRender: function(day){

        //console.warn(day.el)
        
        if (day.date < today){
            $(day.el).addClass('date-disabled');
            $(day.el).addClass('editable = false');

            
        }
        
    },
    eventDrop: function(eventDropInfo) {
        console.log('event start' + eventDropInfo.event.start,'currentDate ' + today)
        console.log(eventDropInfo.event.start < today);
        if(eventDropInfo.event.start < today) {
            eventDropInfo.revert();
        }
    },
    select: function(selectionInfo) {
        if(selectionInfo.start < today) {
           calendar.unselect()
            return false;
        }
    },
    eventRender: function(info) {
      //  console.warn(info)
    },
    
    dayClick : function(info)
    {
        alert('Event: ' + info.event.title);
        alert('Coordinates: ' + info.jsEvent.pageX + ',' + info.jsEvent.pageY);
        alert('View: ' + info.view.type);
    },
    eventClick: function(info) {    

        alert('Event: ' + info.event);
        
    },
    editable: true,
    selectable: true,
})

// On affiche le calendrier
calendar.render();
Lec.Gael
  • 31
  • 4
  • Take a look at https://fullcalendar.io/docs/date-clicking-selecting - in particular the "selectOverlap", "selectConstraint" and "selectAllow" options - these can help you to restrict where new events can be added. – ADyson Jun 24 '20 at 09:48
  • Also you may wish to send an AJAX request to your server to check numbers available for the requested item on the requested date, before allowing the user to add the booking. – ADyson Jun 24 '20 at 09:49
  • Alternatively, you could try using the "Scheduler" features where you can add "resources" to the calendar. If you had one "resource" for each item (e.g. for PC Dell 720 you'd have 3 resources, one for each physical item) then you'd effectively have a separate booking calendar for each item, so you can see when each one is available, but you can show them all together on one fullCalendar screen. N.B. This feature is a premium product so you'd probably have to buy a license for commercial use - there's more info on the license page on the fullCalendar website. – ADyson Jun 24 '20 at 09:51
  • Problem is I want to disabled days at loading first, and then control user interactions. – Lec.Gael Jun 24 '20 at 09:57
  • That's not really going to work. What if the user loads a page, it shows an enabled day, but then for some reason they wait some time before trying to make a booking, and someone else books it in the meantime? For that reason you'll always need to check on the server anyway before confirming the booking, so you might as well design it like that to begin with. Or if you use the idea with the Scheduler, then it would be automatically obvious what was available and not available, because unavailable slots would already contain a booking – ADyson Jun 24 '20 at 10:00
  • If you can't use Scheduler, then of course you need to at least attempt to show available / unavailable times. So maybe you could generate an event to cover a time when there is a booking, and show within the event title how many items of that type are taken at that time (and/or how many are still available). If bookings overlap then it gets a bit more tricky, but with some good coding on the server side when you pull your booking data from the database, it should be possible to represent all situations. – ADyson Jun 24 '20 at 10:02
  • That way, if you have an event which shows all items are taken a a particular time, then you can make it that the user would be unable to click on it to make a new booking during that time. Or if there is still one available, it would be clickable. If there are no bookings at all during a given time, you could either display an event saying that, or just leave a blank selectable space on the calendar – ADyson Jun 24 '20 at 10:04
  • I could check and refresh. And how can I handle day per day, because an item can be available. In my database I can retrieve quantity available per day: – Lec.Gael Jun 24 '20 at 10:04
  • Woaw this problem is SUPER tricky :O – Lec.Gael Jun 24 '20 at 10:05
  • I really think Scheduler would be the better solution here. Even if you have to buy a license I don't think it is very expensive for a company. (P.S. I am not part of the fullCalendar project, I have no connection to it, so I'm not trying to do a sales pitch here, I just genuinely think it would be a lot simpler to implement than the alternatives). – ADyson Jun 24 '20 at 10:32
  • Yeah... but I can't afford it... I will have to find another solution ... I find this problem really complicated... how others soft handle it... I mean there is a lot of apps like that and I can't find a good tutorial about a problem like that – Lec.Gael Jun 24 '20 at 13:48
  • They probably spent quite a bit of time and effort and money creating a workable solution. It's not a simple problem, you're right. By the time you've worked on it for a while, you might have spent the cost of a scheduler license anyway in terms of what your own time is worth. – ADyson Jun 24 '20 at 14:18
  • True, I'm beginner but I'll try to find anyway. – Lec.Gael Jun 25 '20 at 06:15

0 Answers0