#
#	ITSV GmbH
#	CCDB - Command and Control Database
#
#	FILE:		dquermfile_xfilvaccilvd.txt
#	DESCRIPTION:	DQUERY definition for CCDB DQUERY "xfilvaccilvd"
#
@querytitle	Übertragung von Leistungserfassungsdaten aus ILVACC nach ILVD
@querydescription	
@group	ILV
@attributenames	uskurzz:ilvaccuskurzz:{{uskurzzoptions}},jahr:ilvaccjahr:{{jahroptions}},monat:ilvaccmonat:{{monatoptions}}
@uskurzzoptions	{"labeltext":"Mitarbeiter-Kurzzeichen","typedesc":"Kurzzeichen der Person, für die Daten übertragen werden sollen"}
@jahroptions	{"labeltext":"Jahr","typedesc":"4-stelliges Jahr, für das  Daten übertragen werden sollen"}
@monatoptions	{"labeltext":"Monat","typedesc":"Monat (1..12), für den  Daten übertragen werden sollen"}
@querytype	sequence
@sequence	{"name":"sxfilvaccilvd","sequence":"chkilvdtempty,xxfilvaccilvd"}

~query.tsteps

#
# <<TSTEPNUM:0>>: chkilvdtempty
#
pre_qexpression
	this.ppfx = this.fname+"("+this.query.dataname+")";
	this.cdata.uskurzz = this.query.uskurzz;
	this.cdata.jahr = this.query.jahr;
	this.cdata.monat = this.query.monat;
sql				select count(*) AS ANZAHL,USKURZZ,JAHR,MONAT from CCILVD where USKURZZ=::uskurz:: And JAHR=::jahr:: And MONAT=::monat::
named_params	uskurzz,jahr,monat
result_varname	ceres
post_qexpression
	proc: {
		if (this.ceres.getCellValue(0,0)>0) {
			this.errcoll.collect(null,"Es sind bereits "+this.ceres.getCellValue(0,0)+" Datensätze für "+
									this.ceres.getCellValue(0,1)+","+this.ceres.getCellValue(0,2)+","+this.ceres.getCellValue(0,3)+" vorhanden");
			break proc;
		} else {
			this.ceres.rows[0].push("Keine Daten in CCILVD für "+this.ceres.getCellValue(0,1)+","+this.ceres.getCellValue(0,2)+","+this.ceres.getCellValue(0,3)+" vorhanden");
			this.ceres.addMetaDataName("STATUS");
		}
		this.cbcb = {cb: this.cb};
		ppush(this,[this.ppfx+".START","CDATA: "+aux.objTxt(this.cdata),"EMPTYCHECK: "+aux.objTxt(this.ceres),""]);
	}

#
# <<TSTEPNUM:1>>: xxfilvaccilvd
#
sql	insert into CCILVD 
	select	a.JAHR, a.MONAT, a.TAG, a.PSP as PSP, '' as PSPDETAIL, a.USKURZZ as USKURZZ, 
			SUM(a.STUNDEN_ARBEIT) as STUNDEN, null as KOSTEN
	  from CCVILVACC a
	 where a.USKURZZ=::uskurzz:: and a.JAHR=::jahr:: and a.MONAT=::monat:: and a.PSP!='Pause'
	 group by a.USKURZZ, a.JAHR, a.MONAT, a.TAG, a.PSP
named_params	uskurzz,jahr,monat
result_varname	ires
post_qexpression
	ppush(this,[this.ppfx+".FINISHED","INSERT: "+aux.objTxt(this.ires),"",""]);


