Hello!
I am having a ticket system where workers can clock-in during their worktime. The app looks like this: https://gyazo.com/c8761eaa962db09ceb8dff502ba24321
Database looks like this:
https://gyazo.com/bccfff0f750091f347877325f6d67d82
Whenever the column tijdtotaal of the day they are wanting to fill in a ticket, is higher than 8, I want it to make a new ticket with the rest of the hours.
This is what we need to do:
-Everytime a new ticket gets created, we need to filter the database on the date of today and see how many rows are there. It then needs to check if TijdTotaal is over 8. When it is over 8, I want it to match up exactly to 8. This may be confusing so I will explain it with a screenshot.
How it is now: https://gyazo.com/b979d3d96597e7eeb8a351dfd4b8a433
How it should look like: https://gyazo.com/f256e7f855acaf9419592bae5bbbe3ff
It needs to calculate it to 8 and use the rest of the time to make a new ticket with the same information as the last ticket. How can we get this?
Just using this code to send the form away: SubmitForm(EditForm1)
I hope I have explained this well enough, if I didn't, let me know and I will try and explain it better.
Code we have tried right now:
ClearCollect(colUrenRegistratie, Filter(
UrenRegistratie,
Datum = Text(
Today (),
"dd/mm/yyyyy"
) And varcurrentuser = Werknemer
));
With(
{
sumTijdTotaal: Sum(colUrenRegistratie,TijdTotaal)
},
With(
{
remainder: 8-Mod(sumTijdTotaal,8)
},
If(
EditForm1.Updates.TijdTotaal<=8,
SubmitForm(EditForm1),
If(
!EditForm1.Valid,
Notify("One or more fields in the form were not entered correctly.",NotificationType.Error),
Patch(UrenRegistratie,Defaults(UrenRegistratie),EditForm1.Updates,{TijdTotaal: remainder});
Patch(UrenRegistratie,Defaults(UrenRegistratie),EditForm1.Updates,{TijdTotaal: EditForm1.Updates.TijdTotaal-remainder});
If(
!IsEmpty(Errors(UrenRegistratie)),
Notify("There was an error submitting the form and records may not have been submitted successfully.",NotificationType.Error);
ResetForm(EditForm1);
Navigate([@Overzicht],Fade)
)
)
)
)
)