How would a db be designed to accept reservations everyday except holidays? - sql

Hope the titel of my question makes sense.
We are building reservations app.
The key stumbling block right now is how to handle reservation dates.
For instance, accordding to their specs, users can make reservations everyday except during holidays.
So, if a user makes a reservation for say, 11/20/2014, if that date is available, it is presented to user for booking.
If that date is not avaialble, the next 30 available dates are presented to the user to choose from.
I have the code to do this check but my question, how do I include the date information that users can compare to the the date they selected?
Sorry guys because I am using an old browser? it won't allow me to add my comments.
So, I am adding it here.
I am just trying to clarify that what I am confused about is how to handle dates that need to be stored on the database.
For instance, whatever date a user selected as preferred event date will need to be compared to the date on our database to see if that date is available for the event.
Where and how should I store that date on the database?

One option might be a secondary table with blackout dates. Outer join to this table and then check if a date returns that is within the range of dates being requested. No joined data, then clear to book.

Related

How do I add new rows to SQL automatically by time?

I'm a pretty new programmer and I'm working on a project that I'm not sure how to make work. I'm hoping for some advice please.
Part of the project I'm working on will be used by a company to allow employees to sign up for lunch from their computers. I'm doing the project in MVC ASP.NET
The interface will look something like this:
----------------------
|1200 | Employee Dropdown Name 1
| Employee Dropdown Name 2
|---------------------
|1230 | Employee Dropdown Name 1
| Employee Dropdown Name 2
|---------------------
and on and on and on.
With this company, everything has to be recorded and stored. So, I already have a table with employee information. That will populate the drop down areas. Lunch times need to be stored in the database so it can be searched years down the line. So it has to be in a table.
The table get more tricky because not every time of the day is available for lunch (i.e. - no lunches after 0430 and before 0800).
My question is about how to create the future time slots in the database.
I could obviously make the table with all of these rows already in places for several years down the line. That's time-consuming, though, and I'll have to go back in in several years and fix it. Horrible idea.
What I'd LOVE to do is make it so every 24 hours, the database just automatically adds new rows with the next days times available - so just increment (at midnight, the program will just add the next day's times associated with that date (so at midnight on February 6, 2020, it will create February 7, 2020 0000, February 7, 2020 0030, etc. I've studied a lot but I'm still beside myself on how to make this work.
Thanks in advance everyone!!!
As I understand, you want to drive your interface from the database table so that the user can select Name 1 and Name 2 and a time slot and submit.
It sounds like you also want the available timeslots to be driven by the database also (ie, timeslot in table without names with it is availlable). This is not a good idea. As you mentioned, you would be inserting data that is not actually a record but a placeholder. That will be very confusing down the track when you come to query the data.
My approach would be to do the following:
* add NOT NULL constraints to all columns in your database (if your database supports this feature) or have your app complain very much about NULLS in any of the columns. There is no need for NULLS in your use case by the look of it.
the database should have a CHECK constraint that the time is within the allowable time range, and (assuming employees can not double book time slots) a CHECK constraint that there is no overlapping time slots, and also a UNIQUE constraint that ensures no duplicate times.... adjust to suit your needs.
your app populates times between 0800 and 1630 (8AM and 4:30PM) and also query the database for all records matching the current day so those booked slots can be removed from the list of available time slots... adjust to suit.
your app sends the user request of name and time slot to the DB. All the critical requirements are accepted or rejected by the DB schema and if there is something wrong, display an appropriate error in the app.
This way, your database is literally storing records of booked lunches.
I would NOT go down the path of pre inserting as then it becomes more complex as some records are "real" and some are artificially generated records to drive a GUI...
If you can't do the time slot calculations in your app rather than in the DB, then at least use a separate table that is maintained by a worker thread in your app OR if your DB supports it, a Stored Procedure which returns a table of available time slots.
I would use the stored procedure if I was avoiding doing complex time calculations in my app (also avoids need to worry about time zones - if you make sure to only store and display UTC times in your DB).
Having in mind structure like this:
LunchTimeSlots (id, time_slot)
Employee (id, name, preferred_time_slot_id, etc)
Lunches(employee_id, time_slot_id, date)
You need a scheduled job to add records to the "Lunches" table every midnight. How to define the job depends on your database vendor. But most of the popular rdbms have this feature. (f.e. mssql)
Despite it's possible to do what you want with db schedulers or any other scheduler, i would recommend to avoid such db design. It's always better to write real facts to the database like a list of employees or fact that lunch was served
to employee at 1pm today.
Unlike real facts, virtual data can be always generated "on-the-fly" by sql queries. F.e. by joining employees to list of dates from today till year 2100, we can get planned lunches for all employees for next 80 years.

Jira birthday JQL query

I have multiple issues (people) in a Jira cloud instance and they all have a birthday field.
Now, I'ld like to run a JQL to find out if anyone have a birthday today, so I can remind everyone else. Is this possible?
I also have access to the automation for jira plugin if that helps.
Assuming that your birthday field is a valid date, try birthday_field >= startOfDay() AND birthday_field < endOfDay which should give you a result set of people/issues with birthday field value that fall today. For additional references, checkout Function Reference page.
I'm afraid this won't be easily possible.
If the field is date field (e.g. 11/Dec/1979), the birthday is probably stored including year of birth and therefore time functions (now(), startOfDay(), ...) won't work.
If the field is string field (1979-12-11), then you won't be able to compare it with today as you can get now() as a string.
One idea - if you have ScriptRunner installed, create a simple custom scripted field (e.g. Birthday Anniversary) and recalculate original birthday to birthday anniversary this year (11/Dec/2019). You will be then able to compare this field with today, e.g.:
"Birthday Anniversary" = now()
On top of that, once you are able to create such filter, you can create a custom dashboard with today's birthdays and you can subscribe to this filter and get daily overview of today's birthdays.
In my team we send notification about tickets in the following ways:
Jira filters subscription for cases where we need plain(to one person/lead/manager) notification, but without fields analysis
https://confluence.atlassian.com/jira064/receiving-search-results-via-email-720416706.html?_ga=2.134616433.1430628443.1592459825-259335427.1591590509
https://confluence.atlassian.com/jira064/receiving-search-results-via-email-720416706.html?_ga=2.134616433.1430628443.1592459825-259335427.1591590509
https://github.com/dgroup/lazylead for cases where we need automatically check ticket fields, comments, links and alert corresponding person, assignee or reporter.
Please note that i'm author of https://github.com/dgroup/lazylead app.

Find All 'Rental' that dont have 'Bookings' within a given DateRange

Proposal
What im trying to do, is allow people to input a date range, and find all 'Rentals' places that have open days between the provided date range from the user.
My Rentals have a has_many association with "bookings" which contain a start and end date.
What would be the best possible way to get every rental article that has a day that is open within that range.
Issue
I can find all the Rentals that have Bookings that dont overlap with the given time, but that doesnt account for each day. So if there was a booking from 7 Sept to 10 Sept, and the User entered the range 5 Sept to 9 Sept, that record would simply not be included, but in theory there is the 5th-7th open.
My Possible Solution
Im still thinking this problem through, so i have not started coding. But what i was going to do, is find all the Rentals that DONT have bookings that overlap with the provided Date Range, store those in a variable(because these are correct results, because it means not a single day overlaps).
Then i will find all the Rentals that have bookings that DO overlap with the provided Date Range. I will then loop through those bookings, and within that, loop through the Range of Dates provided by the user(DateRange.Each) and check if each single day is within that bookings date ranges, as soon as a single day results in a false value(meaning at least one day doesnt overlap) it will end the loop and add the associated "rental" article to the articles collected early with no overlaps at all.
Concerns
The only issue i have with this solution, is i feel it might not be very optimized or run well, im not sure. At the worst case, i would have hundreds of "rentals' and im not sure how many different "Bookings". I dont think something like this could be done in a single SQL query could it ?
Sample data
Rentals Model
name: string
has_many Bookings
Bookings Model
rental_id: integer
start_date: Date
end_date: Date
The user inputs a DateRange, i want all Rentals that have open days(none taken by a 'Booking' in the range provided.
EDIT
I have been thinking, and i think the best solution is using postgres db, which allows for arrays. Ill then store all the dates of the booking, in the array, instead of storing the range.
Postgres supports checking if all the values in an given array is present in an array in the DB. So i could check if the array of 'wanted days' is 'contained' by a DB array, if it is, it means none of the days are free.

MAQL - Select all records that enclose a list of dates

I'm a bit of a noob in MAQL so I would like to know if it is possible to do the following thing :
I got a list of reservations with a Start Date and a End Date
I would like to be able to compute a metric that would give me (for reservations that match some criteria) the number of reservations that include a given night.
In the end, I want my metric to exist for each date x:
MyMetric(x) = Number of reservations with Start > x and End < x
I tried to do the following request:
SELECT COUNT(Voucher) WHERE Date(Start)<THIS AND Date(End)>THIS
but I'm having trouble setting up a report saying "Well now I want THIS to take all the values in the calendar".
(Voucher is just an attribute from my "Reservation" dimension).
Anyone knows how I can proceed ? The user manual is very difficult to read for someone who does not have an extensive experience with MAQL.
I unfortunately don't believe that what you're trying to achieve is possible with the data model you have. The reason behind this is because each date is associated with a specific action, such as the date in which a trip begins and when it ends. In order for this to work exactly how you want, it would be necessary to add a date dimension in the project that has a record for each date between the Begin and End date (e.g. Event date=generic date to capture a range of different events or snapshot date).
Hope this helps!

Recurring Orders

Hi everyone I'm working on a school project, and for my project I chose to create an ecommerce system that can process recurring orders. This is for my final project, I'll be graduating in May with an associates in computer science.
Keep in mind this is no where a final solution and it's basically a jumping off point for this database design.
A little background on the business processes.
- Customer will order a product, and will specify during checkout whether it is a one time order or a weekly/monthly order.
- Customer will specify a location in which to pick up their order (this location is specific only to the order)
- If the value of the order > 25.00 then it is accepted otherwise it is rejected.
- This will populate the orders_test and order_products_test tables respectively
Person on the back end will have a report generated for deliveries for the day based on these two tables.
They will be able to print it off and it will generate a list of what items go to what location.
Based on the following criteria.
date_of_next_scheduled_delivery = current date
remaining_deliveries > 0
Once they are satisfied with the delivery list they will press "Process Deliveries" button.
This will adjust the order_products_test table as follows
Subtract 1 from remaining_deliveries
Insert current date into date_of_last_delivery_processed
Based on delivery_frequency (i.e. once, weekly, monthly) it will change the date_of_next_scheduled_delivery
status values in the order_products_test table can either be active, hold, or canceled, expired
I just would like some opinions if I am approaching this correctly or if I should scratch this approach and start over again.
A few thoughts, though not necessarily complete (there's a lot to your question, but hopefully these points help):
I don't think you need to keep track of remaining deliveries. You only have 2 options - a one time order, or a recurring order. In both cases, there's no sense in calculating remaining deliveries. It's never leveraged.
In terms of tracking the next delivery date, you can just keep track of the day of the order. If it's recurring -- monthly or weekly, regardless -- everything is calculable from that first date. Most DB systems (MySQL, SQL Server, Oracle, etc) support more than enough date computation flexibility so that you can calculate this on the fly, as opposed to maintaining such a known schedule.
If the delivery location is only specific to the order, I see no use in creating a separate table for it -- it's functionally dependent on the order, you should keep it in the same table as the order. For most e-commerce systems, this is not the case because they tend to associate a list of delivery locations with accounts, which they prompt you about when you order more than once (e.g., Amazon).
Given the above, I bet you can just get away with 2 of your 4 tables above -- Account and Order. But again, if delivery locations are associated with Accounts, I would indeed break that out. (but your question above doesn't suggest that)
Do not name your tables with a "_test" suffix -- it's confusing.