How do I Loop through a schedule in Crystal Reports - crystal-reports

I'm building a report in Crystal Reports 2008. The report is dealing with employee's schedules. There are time slots where the schedule is open, and time slots where the schedule is unavailable.
Currently, I've built my logic so that it finds the start and end of an unavailable time. The report them tells me how many hours that particular staff person was unavailable.
My issue is that sometimes, staff people have a block at the beginning of their schedule marked as 'unavailable', and a block at the end of the day as 'unavailable', but between the two they are 'open'. Thus, the report says that particular staff person was out the whole day, but they actually worked. It isn't an option to tell these particular staff people how to schedule their day - they decide their own schedule, and I write the report to accomodate their needs.
SCHEDULE_TIME EMP_ID UNAVAILABLE_CODE WORK_LENGTH
7/5/2011 11:00 100 NULL 15
7/5/2011 11:15 100 NULL 15
7/5/2011 11:30 100 NULL 15
7/5/2011 11:45 100 NULL 15
7/5/2011 12:00 100 15 5
7/5/2011 17:00 100 15 5
This example shows how somebody would have a 5 hour block calculated for unavailable time, but it's only 2 appointments. For the code, I'm using DATEDIFF between appointment times.
(Essentially, they have built in more than one 'unavailable' block, and my logic will only accomodate one 'unavailable' block per day).
I'm pretty sure that I need to run a type of DO...WHILE loop within the report in order to calculate the total hours unavailable. I'm just not sure how to structure the loop in Crystal Reports.

Maybe i'm missing something but what you want to do looks straight forward. Two obvious options:
Running total:
Set the field to {TABLE.WORK_LENGTH}
Set the type to sum
Set the evaluation formula to not(isnull({TABLE.UNAVAILABLE_CODE}))
Set the reset on change of group/field {TABLE.EMP_ID} (assuming you're looking for totals per employee)
Formula/sum:
Create a formula field unavailable_time with if not(isnull({TABLE.UNAVAILABLE_CODE})) then {TABLE.WORK_LENGTH} else 0
Create a group on {TABLE.EMP_ID}
Create a sum on your formula field in the group footer

Related

How to calculate YTD hours on a Crystal Report?

My company has a payroll program that prints payroll checks and pay stubs using Crystal Reports. The report selects payroll data from a table that has these columns: Hours, PeriodAmount, and YTDAmount. The hours are based on payroll period ending date. The report selects records based on a single pay period end date. So, hours would be selected for a single pay period only. However, we would like to print YTD hours on the pay stub. In other words, hours accumulated from beginning of year to current pay period. Since YTD hours is not a column in the table, would we need to include a sub report to accumulate hours? I don't think running totals would work since we are selecting a single period only. Any thoughts? Thanks.
Yes, a subreport is one option.
Another option is to select all pay periods in the current year and compute the total for the current period using a conditional total. For example, create af ormula that returns the hours if the record belongs to the current period and zero otherwise. Then, SUM that formula per employee. That SUM would give you the hours in the current period.

SRSS 2016/Report Builder 2016 - row groups not able to collate by date?

I'm trying to make a report of daily work for a group of users in a database.
it's filtered by a date range, start date and end date. It then shows a list of the users and a total of things they did during that date range.
My boss wants it to then be expandable to show a breakdown of daily totals.
I can get it to open up and show a breakdown, but it's showing like this example here:
7-1-2018 to 7-2-2018
Jane Doe 5
7/1/2018 1
7/1/2018 1
7/1/2018 1
7/2/2018 1
7/2/2018 1
I've tried to mess with the groups of which there are currenlty only two, the name and the 'dateindexed' which is the entry in the database for when they do what they do. IT has a time stamp on it was well, but need to just have date and total.
I've tried to aggregate it and it then throws an error about no aggregation being allowed when there are filters present in the report.
Any tips or tricks to get this to collapse down on just the date and give a total for the days?
Thank you in advance.

How to set the SQL Query for a Report?

Crystal Reports 2011.
Database is MS Access 2003
I have the following tables:
Calendar
has Date entries for the current and next Year, for every Day of the Year, plus some Status Fields marking certain days as "Special" (Joining this table so I have a record for Days with no activity.
Staff table
StaffNo
Name
.
.
.
DayResults
Date
StaffNo
Status
.
.
.
The DayResults table has one entry per Day and Staff.
Entries are only made when the staff gets an entry by the Program for Status or other events. Staff that does not log in the system has no entry for this Day.
So, in case of John not showing up on July 2nd, i have no entry for him for this Day. But I need an entry for my report!
I need to create a Report that fetches Data from the DayResults Table and make calculations on the Parameters here, in order to calculate a Daily as ell as Period Bonus.
The rules for this Bonus require that a Day without activity (i.e. No Show) results in a negative bonus amount.
Therefore I need to have a select statement which creates an entry FOR EACH DAY FOR EACH STAFF.
This should look like this:
Date StaffNo Name Status
2016/07/01 1 Jim 1
2016/07/01 2 John 2
2016/07/02 1 Jim 2
2016/07/02 2 John NULL
(John did not show up on 2016/07/02 ...)
SELECT Calendar.Date, Staff.StaffNo, Staff.NickName, DayResults.Status
FROM Staff LEFT JOIN (Calendar RIGHT JOIN DayResults ON Calendar.Date = DayResults.Date) ON Staff.StaffNo = DayResults.StaffNo;
Unfortunately, no entry here for John on July 2nd?
Any idea how to proceed?
Manfred

Hide Total Row in Rep[orting services

I have a report with total lines after a show is being reported.
A show may run a week or several weeks. I want to hide the total line when there is only 1 week for the show but display the total line when there are more than one week. The example below should hide the Total row for "An American In Paris" but show for the other shows because they run for more than 1 week.I group by performance, week, start date.
I have tried:
=IIF(SUM(Fields!week_performance.Value)<=1,True,False)
and
=IIF((Fields!week_performance.Value)<=1,True,False)
neither seems to work, even if week = 1 the total line still shows
Performance week sales
A Gentlemens guide to Love & Murder 1 1500
2 2000
Total 3500
An American in Paris 1 1800
Total 1800
First Date 1 1900
2 2100
3 1800
Total 58000
I think what you need is the CountRows() function. In this case, using it as follows will default to the current scope (i.e., the group of the showing, in this case) and should count just 1.
=IIF(CountRows() = 1,true,false)
In addition to CountRows(), if you had some unique value per showing, you could use the following:
=IIF(CountDistinct(Fields!UniqueID.Value) = 1,true,false)
If this doesn't work, reply as a comment and I'll do my best to help.

How can I schedule bi-weekly jobs?

My app requires users to schedule recurring events that can recur daily, weekly, monthly, or bi-weekly.
By bi-weekly, I mean every fortnight (14 days) starting from an arbitrary date value provided at the time of creation.
My jobs table has two columns to support this: job_frequency_id and job_frequency_value. I'm able to schedule all types except for bi-weekly.
The first col is an FK to the job_frequencies table; it contains daily, weekly, monthy, bi-weekly values. The job_frequency_value contains the value corresponding to the frequency.
For example: If a job has a job_frquency_id == 3 and job_frequency_value == 10, it will run every 10th day of the month.
How do I add bi-weekly support without tampering with my db structure? I will use the job_frequency_value col to store the start date of the 14 day period, but I'm unsure of the calculation going forward.
Say your starting date is stored as a variable named 'createdDate'.
nextFortnight = DateAdd("ww", job_frequency_value*2, createdDate);
can you wrap your scheduled task in a and set it to run every week?
Something like
<cfif DateDiff('ww',CreateDate(2011,01,01),Today'sDate) MOD 2 EQ 1>
That way if the weeks are odd your scheduled task runs completely and if it's an odd week then it runs the scheduled task, but ignore all your code.