Announcement

Collapse
No announcement yet.

Only one event at a time range

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Only one event at a time range

    Hello,
    I create new event entity ' Rooms Reservation'. Do you have any way to make it impossible to book one room at the same time?
    Possibly any warning that there is a reservation in a certain period of time?​

    Regards,​
    Robert

  • #2
    Manage bookings, marketing and invoicing with EspoCRM Currently, the hotel industry is one of the fastest-growing, competitive sectors. As guests become more digitalized and price-conscious, building loyal relationships and attracting new guests becomes an increasingly complicated process.

    I see record: "Monitor the availability of rooms & services"
    Somone can help?

    Comment


    • #4
      Has anyone managed to write such a class? I'm looking for a solution too.

      Comment


      • #5
        There is no such a class, you just need to add your own logic. there are many ways to achieve this depend on your business logic.
        Rabii
        Web Dev | Freelancer

        Comment


        • #6
          You can also utilize API before save script.

          Comment


          • #7
            API Before Save script:

            Code:
            $message = "An event on the same time slot already exists.";
            
            if (entity\isNew() && assignedUserId) {
                $existingId = record\findOne(
                    'Event',
                    null,
                    null,
                    'assignedUserId=', assignedUserId,
                    'dateEnd>', dateEnd,
                    'dateStart<', dateEnd
                );
                
                
                if ($existingId) {
                    recordService\throwConflict($message);  
                }
                
                $existingId = record\findOne(
                    'Event',
                    null,
                    null,
                    'assignedUserId=', assignedUserId,
                    'dateEnd>', dateStart,
                    'dateStart<', dateStart
                );
                
                
                if ($existingId) {
                    recordService\throwConflict($message);  
                }
                
                $existingId = record\findOne(
                    'Event',
                    null,
                    null,
                    'assignedUserId=', assignedUserId,
                    'dateEnd<=', dateEnd,
                    'dateStart>=', dateStart
                );
                
                
                if ($existingId) {
                    recordService\throwConflict($message);  
                }
            }
            ​
            Where 'Event' should be your entity type.
            Last edited by yuri; 07-25-2023, 02:24 PM.

            Comment


            • #8
              Thank you Yuri, it work's perfect!

              Comment

              Working...
              X