Only one event at a time range

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • ShulzR
    Member
    • Aug 2022
    • 32

    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
  • ShulzR
    Member
    • Aug 2022
    • 32

    #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

    • eymen-elkum
      Active Community Member
      • Nov 2014
      • 472

      #3
      You may need to have custom duplicate checker class, follow this doc:

      CEO of Eblasoft
      EspoCRM Expert since 2014
      Full Stack Web Developer since 2008
      Creator of Numerous Successful Extensions & Projects​

      Comment

      • Enju
        Senior Member
        • Apr 2018
        • 128

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

        Comment

        • rabii
          Active Community Member
          • Jun 2016
          • 1250

          #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

          Comment

          • yuri
            Member
            • Mar 2014
            • 8440

            #6
            You can also utilize API before save script.
            If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

            Comment

            • yuri
              Member
              • Mar 2014
              • 8440

              #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.
              If you find EspoCRM good, we would greatly appreciate if you could give the project a star on GitHub. We believe our work truly deserves more recognition. Thanks.

              Comment

              • Enju
                Senior Member
                • Apr 2018
                • 128

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

                Comment

                Working...