1 (edited by reteinformatica 2023-04-06 20:35:53)

Topic: Who is on vacation?

Hello everyone and thank you for your interest in my dilemma. I created a crude program to enter the vacation days of a company's employees. In Form1 I put a search form and I would like it to search for employees who are on vacation on that day by entering a specific day.
I created a table with the employee's first and last name and from what day to what day he is on vacation. What I would like is for the program, by entering a given day, to give me a list of those employees who are on vacation, if obviously that given day someone is on vacation.
Could I have a hand please? Thank you all and goodbye.

Post's attachments

Attachment icon Ferie.zip 323.35 kb, 116 downloads since 2023-04-06 

Re: Who is on vacation?

Hi,


Something like this

Post's attachments

Attachment icon Ferie1.zip 334.59 kb, 104 downloads since 2023-04-07 

3 (edited by reteinformatica 2023-04-08 18:23:36)

Re: Who is on vacation?

Hi sparrow, sorry for the delay but I had to make a move. It was just what I needed. I would like to ask your advice: in your opinion,from the point of view of accuracy, is it better to make two tables,one with the person's biographical data and one with the vacation days or is a single table as I have done okay?

Re: Who is on vacation?

Hi Fabio, Sparrow,
100% better to use 2 tables - one for 'employee' and one for 'vacation' otherwise you will have data redundancy and run the risk of misspelling employee names and so not being able to see how much vacation they have had.  (I don't want to speak for Sparrow but I'm pretty sure he'd say the same).
Attached is an old project that was for the same thing you are looking at - I've just copied Sparrow's code so that you can search for who has taken vacation on a specific day.
Just remove any bits that aren't what you need.
Regards,
Derek.

Post's attachments

Attachment icon holidayentitlement.zip 441.28 kb, 114 downloads since 2023-04-08 

Re: Who is on vacation?

Hi Derek, Fabio


Derek is right.

I want to note that it will be necessary to think more about the correct calculation. Next year is coming...

Re: Who is on vacation?

Hello to both of you,
I had wondered whether it would have been better to create two tables. Thank you derek for the project.
Happy Easter to both of you.

Re: Who is on vacation?

Hi friends, I'm trying "to steal" great ideas that I wouldn't have come up with from derek's project.
I studied the project and I'm creating one from scratch because I would like to understand and above all learn. Unfortunately I've been stuck in something stupid for two days.
It took me so long to write because I was stubborn in wanting to understand on my own but I surrendered to the evidence of my ignorance.
I know that the project I am attaching is crude from every point of view, even the aesthetic one, I need a lot to learn.
The question is this and I repeat it will also be very stupid for you experts: by inserting the start and end dates of holidays I assign them to all employees instead of a specific one.
Thanks for your patience.

Post's attachments

Attachment icon Ferie.zip 324.63 kb, 80 downloads since 2023-04-12 

Re: Who is on vacation?

Hi Fabio,
It is assigning the holidays to ALL employees because you haven't specified a relationship between the 'employees' and 'holidays' tables which would restrict the row in the 'holiday' table to a specific employee (see the screenshot in the attachment).
I've added the relationship to your project and you should see it working correctly.
Regards,
Derek.

Post's attachments

Attachment icon Ferie2.zip 363.5 kb, 94 downloads since 2023-04-12 

9 (edited by reteinformatica 2023-04-12 19:47:58)

Re: Who is on vacation?

Hi Derek, you won't believe this but I didn't check this because I was convinced that I set the field with the relationship. I've spent the last two weeks moving house, I must be stoned. Thank you!

Re: Who is on vacation?

Hello, I'm continuing to study derek's project and apply it to my creation from scratch.
In the "employees" table I managed to get the 'cftaken' field to work but I tried to write, wrongly, the code for the 'cfleft' field, i.e. to put the number of days left until the end of the holidays.
I imagine that it would take an instruction like "end date of holidays minus today" but I don't quite understand how to write this instruction.
Thank you!

Post's attachments

Attachment icon Ferie.zip 324.86 kb, 91 downloads since 2023-04-13 

Re: Who is on vacation?

You first need to create a field in your 'employees' table to hold how many days holiday an employee  is entitled to.
Once you have done that, the calculation for 'days left' is

holidayentitlement - (select sum(abs(julianday(start) - julianday(end)) +1) from holidays where holidays.id_employees = employees.id)  

(where 'holidayentitlement is the name of the new field).
You also need to consider (as Sparrow mentioned in an earlier post) what the business process is when the employees go from one holiday year (2023) to the next holiday year (2024) etc;  the example I attached earlier was simple because all employees had their holiday entitlement re-negotiated on January 1st each year but your project might need to use something like an additional 'holiday year' table.
It might be worth your while spending a bit of time with a more straightforward  'test' project to help familiarise yourself with MVD before moving on to something that is a bit more complicated;  it's what I did when I first started using MVD and in the long run, it was time well spent.
Derek.

Re: Who is on vacation?

Hi Derek, I had seen that field in your project and amazingly I also figured it out. But I wonder, I don't know if I'm talking about science fiction, if there was a way for you to read the date from the Windows clock and subtract the starting day of the holidays without adding a specific field with the duration of the holidays.

Re: Who is on vacation?

The calculation is the same as you are already doing.
But instead of using 'start' and 'end' date, you used the reserved word 'now' to represent the current date (today)

(abs(julianday('now', 'localtime')) - (julianday(startdate))) + 1  

See attached.
Derek.

Post's attachments

Attachment icon current date.zip 437.22 kb, 111 downloads since 2023-04-14 

Re: Who is on vacation?

Hi Derek and as always many thanks.
In the case of what I built I tried to put this instruction in the 'cfleft' field trying to follow your instructions but something didn't work.


(abs(julianday('now', 'localtime')) - (julianday(start))) + 1  from holidays where holidays.id_employees = employees.id)

Re: Who is on vacation?

Hi,
Fixed (see attached).
But you also need to consider how the calculation works when you have more than one entry per employee in the 'holidays' table - there will be more than one 'start' date so which 'start' date should you use (in the attachment, I have assumed it is the most recent one (and so I use the 'max' function) but I'm really not sure what your calculation is trying to show).
Derek.

Post's attachments

Attachment icon Ferie2a.zip 337.72 kb, 82 downloads since 2023-04-14 

16 (edited by sparrow 2023-04-14 13:01:52)

Re: Who is on vacation?

Hi all,

You will generously excuse me, but it seems to me that "there are days of vacation left until the end" you do not calculate that way.
In addition, using max in a query does not guarantee that you are calculating the correct period, as a future period may already have been entered.
Such a calculated field is proposed. Where in the WHERE clause is the record that is included in the "TODAY between START and FINISH" clause.

(SELECT (julianday(date(end))) - (julianday(date( 'now', 'localtime')))    
FROM holidays
WHERE holidays.id_employees = employees.id
AND date('now', 'localtime') BETWEEN date(start) and date(end)
ORDER BY id DESC
LIMIT 1)

And something like this (an event after pressing the button) to update the first table on the main form after changing the vacation dates.

procedure frmDate_Button1_OnAfterClick (Sender: TObject);
begin
  frmEmployees.TableGrid1.dbUpdate;
end;
Post's attachments

Attachment icon Ferie2b.zip 327.22 kb, 87 downloads since 2023-04-14 

Re: Who is on vacation?

Hello to both of you and thanks again for the effort to help me.
More or less or understood, more less than more, but I'm thinking about it. Now I would like to understand, always starting from derek's project, how to set the grand total of days taken by an employee at the bottom of the tablegrid as it is in derek's project. Honestly, I've looked and looked but I can't figure out which part produces this result.
Thank you very much.

Re: Who is on vacation?

Look

Post's attachments

Attachment icon Buttton4.jpg 93.66 kb, 31 downloads since 2023-04-14 

Re: Who is on vacation?

Thanks sparrow, that was easy in itself but I would never get there.

Re: Who is on vacation?

Hello everyone again. I've made a few tweaks to the project based on what I think I need.
Looking at sparrow's project I really can't understand what are the instructions to show in the 'tablegrid1' of my project the employees who are on vacation by selecting a day from the 'datepicker1'. I ask you for help again. Thank you.

Post's attachments

Attachment icon Ferie.zip 325.21 kb, 79 downloads since 2023-04-15 

Re: Who is on vacation?

Hi all,

look example

Post's attachments

Attachment icon Ferie3a.zip 327.91 kb, 83 downloads since 2023-04-15 

Re: Who is on vacation?

Hi friends, sorry for the delay but I just couldn't understand sparrow's corrections. I lacked knowledge of the TimePicker's "Increm. Search" property.
It took me but I finally got there. Thank you very much.

Re: Who is on vacation?

Hello everyone, you won't get rid of me, I immediately have a question:
I inserted a button to print, then I created the report but it doesn't work as I would like.
For employees who have multiple vacation sessions, the first and last name is replicated for each vacation session.
What I'd like you to do instead is put the employee's name, for example as the title, and then all the sessions, without always replying name and surname.
Can you give me a hand please?
Thank you!

Post's attachments

Attachment icon Ferie3a.zip 326.99 kb, 73 downloads since 2023-04-18 

Re: Who is on vacation?

Hi Fabio,
You need to insert a 'group header' band to group sections of data together.
Have a look at the attached example.
Derek.

Post's attachments

Attachment icon Ferie3B.zip 340.36 kb, 106 downloads since 2023-04-18 

25 (edited by reteinformatica 2023-04-18 19:30:28)

Re: Who is on vacation?

Thanks derek, that's exactly what I wanted to know. What does that Calculated field 'cfname' you added?