Hierarchy
- ProductionSchedule
Properties
Readonly specialCalendars
Object for working with calendars of exceptions.
Readonly workCalendars
Object for working with business calendars.
Methods
calcDate
-
The method calculates a date inside the working time interval.
The date is calculated from the specified date and with the specified duration. If a user is provided, the calculation will use the business calendar associated with that user. Otherwise, the default calendar specified for the company as a whole will be used. For example, you can calculate date within working hours will be 14 hours after the process start date:
const workingTime = await System.productionSchedule. calcDate(Context.data.__createdAt, new Duration(14, 'hours'));
Important: the
time
parameter must be a multiple of minutes. The result is an object of theTDatetime
type, with the same time zone as the input parameterfrom
.Parameters
-
from: TDatetime
Start date and time used for calculation.
-
time: number | TDuration
Time period in hours or as a TDuration value.
-
Optional user: TUser
The user that the date is calculated for.
Returns Promise<TDatetime>
-
deleteSpecialDays
-
Delete exceptions in the default business calendar.
Example of deleting short days and public holidays:
await System.productionSchedule.deleteSpecialDays([ new TDate(2023, 12, 31), new TDate(2023, 12, 30), ]);
Parameters
-
dates: TDate[]
Dates of the deleted short days and public holidays.
Returns Promise<void>
-
getGeneralSettings
-
The method returns the general settings of the business calendar.
General settings of the Business Calendar include work schedule and non- working days of the week.
const generalSettings = await System.productionSchedule.getGeneralSettings();
Returns Promise<ProductionScheduleGeneralSettings>
getSpecialDays
-
The method gets short days and public holidays from the business calendar.
Sort days and public holidays are returned for a certain period specified
in the method's arguemnts:Parameters
-
from: TDatetime | TDate
Start of the period.
-
to: TDatetime | TDate
End of the period.
const fromDate = Context.data.__createdAt; const toDate = Context.data.request_deadline const specialDays = await System.productionSchedule.getSpecialDays(fromDate, toDate);
Returns Promise<ProductionScheduleSpecialDay[]>
-
getWorkingTime
-
The method is used to get the duration of working time within a specified period.
The working hours duration is returned for the period passed in the method’ s arguments. If a user is provided, the calculation will use the business calendar associated with that user. Otherwise, the default calendar specified for the company as a whole will be used.
Parameters
-
from: TDatetime
Start of the period.
-
to: TDatetime
End of the period.
-
Optional user: TUser
The user that you want to obtain the working time duration for.
const fromDatetime = Context.data.report_start; const toDatetime = Context.data.report_end; const reportedWorkingTime = await System.productionSchedule.getWorkingTime(fromDatetime, toDatetime); const weeklyHours = new Duration(40, 'hours'); if (workingTime.hours > eightHours. hours) { Context.data.notification = 'The specified duration exceeds the working hours'; }
Returns Promise<TDuration>
-
saveGeneralSettings
-
The method allows you to modify the general settings of the default business calendar, that is, the calendar specified in the company settings.
Example of editing the settings:
const settings = await System.productionSchedule.getGeneralSettings(); settings.weekends = { monday: false, tuesday: false, wednesday: false, thursday: false, friday: false, saturday: true, // Saturday is a non- working day sunday: true, // Sunday is a non-working day } await System.productionSchedule.saveGeneralSettings(settings);
Parameters
-
settings: ProductionScheduleGeneralSettings
An object containing the edited settings.
Returns Promise<void>
-
saveSpecialDays
-
Create or edit exceptions in the default business calendar.
Example of creating short days and public holidays:
await System.productionSchedule.saveSpecialDays([ { date: new TDate(2023, 12, 30), holiday: false, from: 16 * 60 * 60, // From 4 pm to: 18 * 60 * 60, // To 6 pm }, { date: new TDate(2023, 12, 31), holiday: true, // Holiday from: 0, to: 0, }, ]);
Parameters
-
specialDays: ProductionScheduleSpecialDay[]
Saved short days and public holidays.
Returns Promise<void>
-
Business calendar object
Used to get the settings of the business calendar, such as: