#
#
#			ITSV GmbH
#	CCDB - Command and Control Database
#
#	FILE:			dquerymfile_genpersworkplan.txt
#	DESCRIPTION:	DQUERY Definition of DQUERY genpersworkplan
#
#	QUERY_DESCRIPTION:	genpersworkplan generates a work plan for the person with USKURZZ in <kurzz>
#						generating a work plan is done by generating daily entries in CCILVPLAN
#						for each work day in the range including <fromday> until including <untilday>
#						work days are all days except:
#						- day is saturday or sunday
#						- day is holiday: has an entry in CCRW of type HOLIDAY 
#
@querytitle				Arbeitsplan für Person erzeugen
@querydescription		erzeugt einen Arbeits-Auslastungsplan für eine Person
@group					ILVPLAN
@attributenames			kurzz:uskurzz,fromday:serialdate:{{fromdayopts}},untilday:serialdate:{{untildayopts}},opts:string:{{optsopts}}
@fromdayopts			{"labeltext":"Beginntag","typedesc":"erster Tag der Periode, für die der Arbeitsplan erstellt werden soll, in der Form YYYYMMDD"}
@untildayopts			{"labeltext":"Endetag","typedesc":"letzter Tag der Periode, für die der Arbeitsplan erstellt werden soll, in der Form YYYYMMDD"}
@optsopts {
	labeltext: 	"Weitere Optionen",
	typedesc:	"zusätzliche Steuer-Optionen für die Berechnung in JSON- oder JS-Form" }
@querytype				function
@function				seqtrans.seqtrans

~query.tsteps

#
# 0: initialize
#
qexpression
	this.copyqvars("kurzz,fromday,untilday");
	this.qopts = aux.txtObjDecode(this.query.opts);

#
# 1: verify person by USKURZZ
#
sql						select * from CCVUS where uskurzz=::kurzz::
named_params			kurzz
result_varname			usres
post_qexpression
	if (this.usres.getRowCount()<1) {
		this.errcoll.collect(null,"User with Kurzzeichen "+this.kurzz+" is unknown",this.usres);
	} else {
		this.userinfo = {};
		let cr;
		for (let ri=0; ri<this.usres.getRowCount(); ri++) {
			cr = this.usres.getRowObject(ri);
			if (cr.ATTNAME) {
				this.userinfo[cr.ATTNAME] = cr.ATTWERT;
			}
		}
		if (!this.userinfo["ILV/ILV_PP_USATT_NORMARBEITSZEIT"])	this.userinfo["ILV/ILV_PP_USATT_NORMARBEITSZEIT"] = 7.7;
		if (!this.userinfo["ILV/ILV_PP_USATT_SOLLJAHRPH"]) 		this.userinfo["ILV/ILV_PP_USATT_SOLLJAHRPH"] = 1480;
		if (!this.userinfo["ILV/ILV_PP_USATT_URLAUBJAHRPT"]) 	this.userinfo["ILV/ILV_PP_USATT_URLAUBJAHRPT"] = 25;
		this.normaz = this.userinfo["ILV/ILV_PP_USATT_NORMARBEITSZEIT"];
		this.jahraz = this.userinfo["ILV/ILV_PP_USATT_SOLLJAHRPH"];
		this.urlaubjahrpt = this.userinfo["ILV/ILV_PP_USATT_URLAUBJAHRPT"];
		this.query.title = "Arbeitsplan für "+this.userinfo.NAME+" von "+this.fromday+" bis "+this.untilday;
	}
	
#
# 2: determine work days to cover
#
query.dataname			infoquery
query.infotype			workdays
query.p1				{fromday: "@@fromday@@", untilday: "@@untilday@@"}
result_varname			wdres
post_qexpression
	this.ppush("Arbeitstage im Bereich: "+this.wdres.resultobject.attributes.workdays.value);
	this.ppush("Arbeitstage mit Abwesenheit (Urlaub): "+this.urlaubjahrpt);
	this.workdays = this.wdres.resultobject.attributes.workdays.value;
	this.accdays = this.workdays-this.urlaubjahrpt;
	this.ppush("Arbeitstage an denen Aufwand gebucht wird: "+this.accdays);
	this.ppush("Normal-Arbeitszeit pro Arbeitstag: "+this.normaz);
	this.accphperday = this.jahraz/this.accdays;
	this.ppush("Mittelwert an gebuchten Ph an jedem Buchungstag: "+this.accphperday+" um "+this.jahraz+" gebuchte Ph von "+this.fromday+" bis "+this.untilday+" zu erreichen");



