Difference between revisions of "Timereg class"
(Created page with "{{CGscriptClass_Template |Name=Timereg |Description=Represent a registration time |Methods= {{CGscriptMethods_Template|ReturnType=empty|Name=Lock|Description=Lock the timereg...") |
|||
(3 intermediate revisions by 2 users not shown) | |||
Line 1: | Line 1: | ||
{{CGscriptClass_Template | {{CGscriptClass_Template | ||
− | |Name=Timereg | + | |Name=<nowiki>Timereg</nowiki> |
− | |Description=Represent a registration time | + | |Description=<nowiki>Represent a registration time</nowiki> |
− | + | |InheritsFrom=object|Constructors= | |
+ | {{CGscriptConstructors_Template|Parameters= | ||
+ | {{CGscriptParameters_Template|Type=DateTime|Name=<nowiki>date</nowiki>|Description=<nowiki>Date of timereg, if Empty default to Today</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>userResourceId</nowiki>|Description=<nowiki>ResourceId of user to find timereg for, if 0 defaults to current user</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=string|Name=<nowiki>statusIfCreate</nowiki>|Description=<nowiki>Name of status to set if creating new timereg</nowiki>}} | ||
+ | |Description=<nowiki>Get or create an timereg for a given date and user</nowiki>}} | ||
|Methods= | |Methods= | ||
− | {{CGscriptMethods_Template|ReturnType= | + | {{CGscriptMethods_Template|ReturnType=number|Name=<nowiki>AddHours</nowiki>|Parameters= |
− | {{CGscriptMethods_Template|ReturnType=string|Name=ToString|Description=The string representation of the object.}} | + | {{CGscriptParameters_Template|Type=int|Name=<nowiki>resourceId</nowiki>|Description=<nowiki>Id of resource to register time under</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>minutes</nowiki>|Description=<nowiki>Amount of minutes to register, may be negative to subtract</nowiki>|Comma=,}}{{CGscriptParameters_Template|Type=int|Name=<nowiki>roleId</nowiki>|Description=<nowiki>Id of role to use, use 0 to not use a role</nowiki>}} |
+ | |Description=<nowiki>Add registered hours to this timereg</nowiki>}} | ||
+ | {{CGscriptMethods_Template|ReturnType=Empty|Name=<nowiki>Lock</nowiki>|Description=<nowiki>Lock the timereg and save it</nowiki>}} | ||
+ | {{CGscriptMethods_Template|ReturnType=string|Name=<nowiki>ToString</nowiki>|Inherited=object|Description=<nowiki>The string representation of the object.</nowiki>}} | ||
+ | |Properties= | ||
+ | {{CGscriptProperties_Template|ReturnType=DateTime|Name=<nowiki>Date</nowiki>|HasGetter=1|Description=<nowiki>Get registration date</nowiki>}} | ||
+ | {{CGscriptProperties_Template|ReturnType=bool|Name=<nowiki>Locked</nowiki>|HasGetter=1|Description=<nowiki>Get if the registration is locked</nowiki>}} | ||
+ | {{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>ObjectTypeName</nowiki>|HasGetter=1|Description=<nowiki>The name of the type of object.</nowiki>}} | ||
+ | {{CGscriptProperties_Template|ReturnType=string|Name=<nowiki>Status</nowiki>|HasGetter=1|HasSetter=1|Description=<nowiki>Get registration type of day (Met, Weekend,... etc)</nowiki>}} | ||
+ | {{CGscriptProperties_Template|ReturnType=TimeregPeriod|Name=<nowiki>TimeregPeriod</nowiki>|HasGetter=1|Description=<nowiki>Get a TimePeriod object in association with the registration</nowiki>}} | ||
+ | {{CGscriptProperties_Template|ReturnType=number|Name=<nowiki>TotalHours</nowiki>|HasGetter=1|Description=<nowiki>Get total hours registered</nowiki>}} | ||
+ | {{CGscriptProperties_Template|ReturnType=TypeInformation|Name=<nowiki>TypeInformation</nowiki>|HasGetter=1|Inherited=object|Description=<nowiki>Get information about this class.</nowiki>}} | ||
+ | }} | ||
+ | === <span style="color:#DF8621">'''Examples'''</span> === | ||
+ | <span style="color:#DF8621">Examples1</span> | ||
+ | <source lang="javascript"> | ||
+ | array startDate = DateTime_fromInvariant("2015-09-10 00:00:00"); | ||
+ | array endDate = DateTime_fromInvariant("2016-09-10 00:00:00"); | ||
+ | array user = User_getCurrentUser(); | ||
+ | number urid = user[USER_RESOURCE_ID]; | ||
+ | Dictionary regtime = TimeregStatus_getByUsers({urid}, startDate, endDate); | ||
+ | print("Count regtime: " + regtime[urid].Count); | ||
+ | print("==========================================================\n"); | ||
+ | number i = 0; | ||
+ | for(i=0;i<regtime[urid].Count;i++) { | ||
+ | Timereg a = regtime[urid][i]; | ||
+ | print("Date : " + convertToString(a.Date)); | ||
+ | print("Locked: " + convertToString(a.Locked)); | ||
+ | print("ObjectTypeName: " + convertToString(a.ObjectTypeName)); | ||
+ | print("Status: " + convertToString(a.Status)); | ||
+ | print("==========================================================\n"); | ||
+ | } | ||
+ | /* | ||
+ | Count regtime: 1 | ||
+ | ========================================================== | ||
− | + | Date : 2016-03-29 00:00:00 | |
− | + | Locked: False | |
− | + | ObjectTypeName: Timereg | |
− | + | Status: Met | |
− | + | ========================================================== | |
− | + | */ | |
− | + | </source> | |
− | + | <span style="color:#DF8621">Examples for create timereg for user at given date</span> | |
+ | <source lang="javascript"> | ||
+ | array status = TimeregStatus_getAll(); | ||
+ | DateTime date = new DateTime ();//today | ||
+ | number userResourceId =0;//current user | ||
+ | string statusIfCreate = status[0]; | ||
+ | Timereg trg = new Timereg (date, userResourceId, statusIfCreate); | ||
+ | trg.AddHours(11560690, 30, 0);// reg 30m to resource 11560690 | ||
+ | trg.Status = status[4];//change status | ||
+ | print(trg.Status); | ||
+ | </source> |
Latest revision as of 08:17, 2 July 2020
Timereg
Represent a registration time
Parent class
Inherits from object
Constructors
- (DateTime date "Date of timereg, if Empty default to Today", int userResourceId "ResourceId of user to find timereg for, if 0 defaults to current user", string statusIfCreate "Name of status to set if creating new timereg") - Get or create an timereg for a given date and user
Methods
- number AddHours(int resourceId "Id of resource to register time under", int minutes "Amount of minutes to register, may be negative to subtract", int roleId "Id of role to use, use 0 to not use a role") - Add registered hours to this timereg
- Empty Lock() - Lock the timereg and save it
- (From object) string ToString() - The string representation of the object.
Properties
- DateTime Date { get; } - Get registration date
- bool Locked { get; } - Get if the registration is locked
- string ObjectTypeName { get; } - The name of the type of object.
- string Status { get; set; } - Get registration type of day (Met, Weekend,... etc)
- TimeregPeriod TimeregPeriod { get; } - Get a TimePeriod object in association with the registration
- number TotalHours { get; } - Get total hours registered
- (From object) TypeInformation TypeInformation { get; } - Get information about this class.
Examples
Examples1
array startDate = DateTime_fromInvariant("2015-09-10 00:00:00");
array endDate = DateTime_fromInvariant("2016-09-10 00:00:00");
array user = User_getCurrentUser();
number urid = user[USER_RESOURCE_ID];
Dictionary regtime = TimeregStatus_getByUsers({urid}, startDate, endDate);
print("Count regtime: " + regtime[urid].Count);
print("==========================================================\n");
number i = 0;
for(i=0;i<regtime[urid].Count;i++) {
Timereg a = regtime[urid][i];
print("Date : " + convertToString(a.Date));
print("Locked: " + convertToString(a.Locked));
print("ObjectTypeName: " + convertToString(a.ObjectTypeName));
print("Status: " + convertToString(a.Status));
print("==========================================================\n");
}
/*
Count regtime: 1
==========================================================
Date : 2016-03-29 00:00:00
Locked: False
ObjectTypeName: Timereg
Status: Met
==========================================================
*/
Examples for create timereg for user at given date
array status = TimeregStatus_getAll();
DateTime date = new DateTime ();//today
number userResourceId =0;//current user
string statusIfCreate = status[0];
Timereg trg = new Timereg (date, userResourceId, statusIfCreate);
trg.AddHours(11560690, 30, 0);// reg 30m to resource 11560690
trg.Status = status[4];//change status
print(trg.Status);