<?xml version="1.0" encoding="UTF-8"?>
<Export generator="Cache" version="25" zv="Cache for Windows (x86-64) 2011.1.2 (Build 701U)" ts="2011-12-06 08:29:57">
<Class name="DBUtils.ClassHelper">
<Super>%RegisteredObject</Super>
<TimeChanged>62427,55411.227482</TimeChanged>
<TimeCreated>61381,68555.719173</TimeCreated>

<Method name="ResetManyRelations">
<Description>
Löscht alle Verküpfungen von Klassen die in einer Many-Beziehung stehen
WICHTIG: Die Datensätze werden NICHT gelöscht</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>class:%String,myId:%Integer</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
	 Set Ma=##class(%Dictionary.ClassDefinition).%OpenId(class)
	 Set nPrp=Ma.Properties.Count()
	 Set res=0
	 Set sc=$$$OK
	 If (nPrp>0) {
	 	For I=1:1:nPrp {
	    	If (Ma.Properties.GetAt(I).Relationship) {
	        	If (Ma.Properties.GetAt(I).Name'=Ma.Properties.GetAt(I).ClientName) {
	               If ($ZConvert(Ma.Properties.GetAt(I).Cardinality,"U")="MANY") {
						Set relClass=Ma.Properties.GetAt(I).Type
	                    Set relInverse=Ma.Properties.GetAt(I).Inverse
	                    Set cnt=$L(relClass,".")
	                    While (cnt>2) {
	                    	Set relClass=$P(relClass,".",1)_"_"_$P(relClass,".",2,cnt)
	                        Set cnt=$L(relClass,".")
						}
	                    Set strSQL="SELECT ID FROM "_relClass_" WHERE ("_relInverse_"='"_myId_"')"
	                    Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	                    Do rs.Prepare(strSQL)
	                    Set sc=rs.Execute()
	                    IF $$$ISOK(sc) {
							While (rs.Next(.sc)) {
								Set relID=rs.Data("ID")
	                       		Set strSQLUpd="UPDATE "_relClass_" SET "_relInverse_" = NULL WHERE ID ="_relID
	                       		Set resultSet = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	                       		Do resultSet.Prepare(strSQLUpd)
	                       		Set sc = resultSet.Execute()
	                       		
								Quit:$$$ISERR(sc)
							}
						}
	                	Quit:$$$ISERR(sc)
					}
				}
			}
		}
	}
	 Quit:$$$ISERR(sc) sc      
	 Quit $$$OK
]]></Implementation>
</Method>

<Method name="DeleteManyRelations">
<Description>
Löscht alle Objekte von Klassen die in einer Many-Beziehung stehen
VORSICHT: Die Datensätze werden gelöscht!!!</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>class:%String,myId:%Integer</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
	 //w "DeleteManyRelations: ",class, !
	 Set Ma=##class(%Dictionary.ClassDefinition).%OpenId(class)
	 Set nPrp=Ma.Properties.Count()
	 Set res=0
	 Set sc=$$$OK
	 If (nPrp>0) {
	 	For I=1:1:nPrp {
	    	If (Ma.Properties.GetAt(I).Relationship) {
		    	If (Ma.Properties.GetAt(I).Name'=Ma.Properties.GetAt(I).ClientName) {
		        	//w "Propertyname"_Ma.Properties.GetAt(I).Name, !
		        	If (($ZConvert(Ma.Properties.GetAt(I).Cardinality,"U")="MANY") || ($ZConvert(Ma.Properties.GetAt(I).Cardinality,"U")="CHILDREN")) {
		                Set relClass=Ma.Properties.GetAt(I).Type
	                    Set relInverse=Ma.Properties.GetAt(I).Inverse
	                    Set cnt=$L(relClass,".")
	                    While (cnt>2) {
	                    	Set relClass=$P(relClass,".",1)_"_"_$P(relClass,".",2,cnt)
	                        Set cnt=$L(relClass,".")
						}
	                    Set strSQL="SELECT ID FROM "_relClass_" WHERE ("_relInverse_"='"_myId_"')"
	                   // w "DeleteManyRelations - "_strSQL, !
	                    Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	                    Do rs.Prepare(strSQL)
	                    Set sc=rs.Execute()
	                    IF ($$$ISOK(sc)) {
		                    While rs.Next(.sc) {
								Set relID=rs.Data("ID")
								//w !,"RELCLASS: "_relClass_" ID: "_relID,!
	                       		Set sc=..DeleteRelations(relClass, relID)
								Quit:$$$ISERR(sc)
							}
						}
	                	Quit:$$$ISERR(sc)
					}
				}
			}
		}
	}
	//w "Finish Delete Many Relations", !
	Quit:$$$ISERR(sc) sc      
	Quit $$$OK
]]></Implementation>
</Method>

<Method name="DeleteRelations">
<Description>
HilfsMethode zu DeleteManyRelations, welche aus einer Verknüpften Class (strClass) den Datensatz strID löscht und
 alle Einträge in Referenzierten Klassen, welche auf auf die Oid (strID) verweisen
[Previously private]</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>strClass:%String,strID:%String</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
 	Set sc=$$$OK
 	// KlassenName Korrekt vornem (Falls "_" durch "." erstezen) da nicht SQL.
 	set nstrClass = $Replace(strClass,"_",".")
 	// Klasse öffnen
    Set cd=##class(%Dictionary.ClassDefinition).%OpenId(nstrClass)
    // Anzahl Properties der klasse auslessen
    Set nPrp=cd.Properties.Count()
    Set res=0
    If (nPrp>0) {
    	// Für Anzahl Properties die schlaufe durchlaufen und Index i setzen
    	For I=1:1:nPrp {
	    	// Wenn es sich um eine Beziehung handelt
			If (cd.Properties.GetAt(I).Relationship) {
				// und diese Beziehung nicht auf sich selbst referenziert
				If ((cd.Properties.GetAt(I).Name'=cd.Properties.GetAt(I).ClientName) && (cd.Properties.GetAt(I).Type'=strClass)) {
					// und auf der unser seite das Many attribut steht
					If (($ZConvert(cd.Properties.GetAt(I).Cardinality,"U")="MANY") || ($ZConvert(cd.Properties.GetAt(I).Cardinality,"U")="CHILDREN")) {
						// Referenzierte Klasse auslesen
						Set relClass=cd.Properties.GetAt(I).Type
						// Name der Eigenschaft in der Referenzierten Klasse auslesen
                        Set relInverse=cd.Properties.GetAt(I).Inverse
                        // Falls es mehr als 2 "." hat muss der Klassenname umgeformt werden für SQL
                        Set cnt=$L(relClass,".")
                        While (cnt>2) {
                        	Set relClass=$P(relClass,".",1)_"_"_$P(relClass,".",2,cnt)
                            Set cnt=$L(relClass,".")
                        }
                        // SQL statement zusammensetzen in welchem abgefragt wird ob eine Verknüpfung auf den zu löschenden
                        // Datensatz vorhanden ist
                        Set strSQL="SELECT ID FROM "_relClass_" WHERE ("_relInverse_"='"_strID_"')"
                        Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
                        Do rs.Prepare(strSQL)
                        Set sc=rs.Execute()
                        // Wenn statement erfolgreich ausgeführt
                        IF ($$$ISOK(sc)) {
	                        // für jede gefunde verküpfung
							While (rs.Next(.sc)) {
                            	Set relID=rs.Data("ID")
                            	// die verküfungen zur Datensatz in der Referenzierten Klasse löschen
								//w !,"RELCLASS: "_relClass_" ID: "_relID,!
								Set sc=..DeleteRelations(relClass, relID)
								Quit:$$$ISERR(sc)
							}
						}
						Quit:$$$ISERR(sc)
					}
				}
			}
		}
    }
    // Wenn alle Verküpften Datensätze auf Datensatz gelöscht wurden
	If ($$$ISOK(sc)) {
		// Datensatz selbst löschen
	    Set strSQL="DELETE FROM "_strClass_" WHERE (ID='"_strID_"')"
	    w strSQL,!
	    Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	    Do rs.Prepare(strSQL)
	    Set sc=rs.Execute()
	}
   Quit:$$$ISERR(sc) sc      
   Quit $$$OK
]]></Implementation>
</Method>

<Method name="DelArray">
<Description>
[Previously private]</Description>
<Final>1</Final>
<ClassMethod>1</ClassMethod>
<FormalSpec>tClass:%String,tId:%String</FormalSpec>
<Implementation><![CDATA[
	Set tCD=##Class(%Dictionary.ClassDefinition).%OpenId(tClass)
 	Set cls=$System.OBJ.OpenId(tClass,tId)
 	if ((tCD'="") && (tCD'=$c(0)) && (tCD'=$$$NULLOREF) && (cls'="") && (cls'=$c(0)) && (cls'=$$$NULLOREF)) {
		For i=1:1:tCD.Properties.Count() {
			Set tPName=tCD.Properties.GetAt(i).Name
			Set tPType=tCD.Properties.GetAt(i).Collection
			If (tPType="array")||(tPType="list") {
				Do $METHOD($PROPERTY(cls, tPName), "Clear")
			}
		}
		Do cls.%Save()
	}
]]></Implementation>
</Method>

<Method name="OverwriteObjectValues">
<ClassMethod>1</ClassMethod>
<FormalSpec>className:%String,srcOid:%String,dstOid:%String</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
	set cd =##Class(%Dictionary.ClassDefinition).%OpenId(className)
	set src = $System.OBJ.OpenId(className,srcOid)
	set dst = $System.OBJ.OpenId(className,dstOid)
	
	for i = 1:1:cd.Properties.Count() {
		set card = cd.Properties.GetAt(i).Cardinality
		set isPrivate = cd.Properties.GetAt(i).Private
		
		if ((isPrivate = 0) && ((card = "") || (card = "one") || (card = "parent"))) {
			set pName = cd.Properties.GetAt(i).Name
			set $PROPERTY(dst, pName) = $PROPERTY(src, pName) 
		}		
	}
	Quit dst.%Save()
]]></Implementation>
</Method>

<Method name="DeleteMandantFKRelations">
<ClassMethod>1</ClassMethod>
<FormalSpec>MandantOid:%String</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
	Set tSQL="Select ID, Super From %Dictionary.ClassDefinition Where Super Like '%DBCore.MandantRel%'"
    Set trsC=##Class(%Library.ResultSet).%New("%DynamicQuery:SQL")
    Set tsc=trsC.Prepare(tSQL)
	Quit:$$$ISERR(tsc) $System.Status.GetErrorText(tsc) 
	Set tsc=trsC.Execute()
	Quit:$$$ISERR(tsc) $System.Status.GetErrorText(tsc) 
	While trsC.Next(.tsc) {
		//Klassennamen auslesen, welcher von MandantRel erbt
		Set tCName=trsC.ID
		Set tC=$System.OBJ.New(tCName)
		//Umformung des Namespace für SQL
        Set tCNameSQL = $REPLACE(tCName, ".SD.", "_SD.")
		//Sämtliche Ids auslesen, welchen diesen Mandanten betreffen
		//und Daten dazu löschen
		
		//Property, auf welches der FK auf DBCore.Mandant gesetzt ist auslesen
		set propName = ""
		set propSQL = "SELECT Properties from %Dictionary.ForeignKeyDefinition where parent = '"_tCName_"' AND ReferencedClass = 'DBCore.Mandant'"
		Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
        Do rs.Prepare(propSQL)
        Set sc=rs.Execute()
        If ($$$ISOK(sc)) {
		 	If rs.Next(.sc) {
				Set propName = rs.Data("Properties")
		 	}
        }
		
		Set strSQL="SELECT ID FROM "_tCNameSQL_" WHERE "_propName_" = '"_MandantOid_"'"
        Set rs2 = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
        Do rs2.Prepare(strSQL)
        Set sc2=rs2.Execute()
        IF ($$$ISOK(sc2)) {
            While (rs2.Next(.sc2)) {
	            Set objId = rs2.Data("ID")
	            //Many Beziehungen löschen
 	       		Set tsc = ##class(DBUtils.ClassHelper).DeleteManyRelations(tCName, objId)
        		if ($$$ISOK(tsc)) {
        			//Datensatz selber löschen
        			set tsc = $CLASSMETHOD(tCName, "%DeleteId", objId)
        		}
            }
        }
	}
	Quit:$$$ISERR(tsc) $System.Status.GetErrorText(tsc)
	Quit tsc
]]></Implementation>
</Method>
</Class>


<Class name="DBUtils.CspCompileTask">
<Description>
Dieser Task kompiliert alle CSP Dateien in einem Namespace neu</Description>
<Super>%SYS.Task.Definition</Super>
<TimeChanged>62235,41606.058905</TimeChanged>
<TimeCreated>62235,40195.272647</TimeCreated>

<Method name="OnTask">
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
	
	set status = $$$OK
	
	Set tSQL="Select ID From %Dictionary.ClassDefinition where ID like 'csp.%' AND (super ='Alliance.Agris.Web.SecurePage' or super = 'Alliance.Agris.Web.BasePage')"
    Set trsC=##Class(%Library.ResultSet).%New("%DynamicQuery:SQL")
    Set tsc=trsC.Prepare(tSQL)
    Quit:$$$ISERR(tsc) $System.Status.GetErrorText(tsc) 
    Set tsc=trsC.Execute()
    Quit:$$$ISERR(tsc) $System.Status.GetErrorText(tsc) 
    While trsC.Next(.tsc) {
	    Set classname = trsC.ID
	    w $system.OBJ.Compile(classname,"dcuk -u",.sc)
    }

	//	Always return OK, otherwise the taks breaks and stops when an error occurs.
	quit $$$OK
]]></Implementation>
</Method>
</Class>


<Class name="DBUtils.DateTime">
<Description>
	Instances of this class represent a date + time value (without fractional seconds).

		Last change: 10.03.2010 by Lem
</Description>
<Super>%SerialObject,%XML.Adaptor</Super>
<TimeChanged>62024,42665.411013</TimeChanged>
<TimeCreated>61792,27098.343</TimeCreated>
<Inheritance>right</Inheritance>

<Parameter name="SecsPerDay">
<Description>
	The number of seconds per day (is needed for arithmetic)</Description>
<Default>86400</Default>
</Parameter>

<Parameter name="SecsPerMinute">
<Description>
	The number of seconds per minute (is needed for arithmetic)</Description>
<Default>60</Default>
</Parameter>

<Parameter name="MinsPerHour">
<Description>
	The number of minutes per hour (is needed for arithmetic)</Description>
<Default>60</Default>
</Parameter>

<Parameter name="HoursPerDay">
<Description>
	The number of hours per day (is needed for arithmetic)</Description>
<Default>24</Default>
</Parameter>

<Parameter name="DaysPerWeek">
<Description>
	The number of days per week (is needed for arithmetic)</Description>
<Default>7</Default>
</Parameter>

<Parameter name="StandardDateFormat">
<Description>
	The date format used for the toString() method</Description>
<Default>4</Default>
</Parameter>

<Parameter name="StandardTimeFormat">
<Description>
	The time format used for the toString() method</Description>
<Default>1</Default>
</Parameter>

<Parameter name="InternalDateFormat">
<Description>
	The internal date format. Don't change, otherwise many functions won't work any more!</Description>
<Default>3</Default>
</Parameter>

<Parameter name="InternalTimeFormat">
<Description>
	The internal time format. Don't change, otherwise many functions won't work any more!</Description>
<Default>1</Default>
</Parameter>

<UDLText name="T">
<Content><![CDATA[
//

]]></Content>
</UDLText>

<Property name="horolog">
<Description>
	Internal date/time representation is in horolog format. It's capable of arithmetic and is very slim.</Description>
<Type>%String</Type>
</Property>

<UDLText name="T">
<Content><![CDATA[
//	-----	Instance Creation	-----------------------------------------------

]]></Content>
</UDLText>

<Method name="%OnNew">
<Description>
	Create a new instance. If a horolog is supplied, take this, otherwise take $horolog (= now)</Description>
<FormalSpec>horolog:%String=""</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
	set ..horolog = $case(horolog,"":$horolog,:horolog)
	quit $$$OK
]]></Implementation>
</Method>

<Method name="newFromHorolog">
<Description>
	Convenience method, easier to read</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>horolog:%String</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[	quit ..%New(horolog)
]]></Implementation>
</Method>

<Method name="newFromDate">
<Description>
	Create a new instance according to date and dFormat.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>date:%String,dFormat:%Integer=..#StandardDateFormat</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[	quit ..%New($zdateh(date, dFormat))
]]></Implementation>
</Method>

<Method name="newFromDateTime">
<Description>
	Create a new instance according to datetime, dFormat, and tFormat.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>datetime:%String,dFormat:%Integer=..#StandardDateFormat,tFormat:%Integer=..#StandardTimeFormat</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[	quit ..%New($zdatetimeh(datetime, dFormat, tFormat))
]]></Implementation>
</Method>

<Method name="new">
<Description>
	Create a new instance with the given data. hour, minute and second are optional.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>year:%Integer,month:%Integer,day:%Integer,hour:%Integer=0,minute:%Integer=0,second:%Integer=0</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[
	set odbcString = year _ "-"
					_ ..fillLeftWithZeros(month) _ "-"
					_ ..fillLeftWithZeros(day) _ " "
					_ ..fillLeftWithZeros(hour) _ ":"
					_ ..fillLeftWithZeros(minute) _ ":"
					_ ..fillLeftWithZeros(second)
	quit ..%New($zdatetimeh(odbcString, ..#InternalDateFormat, ..#InternalTimeFormat))
]]></Implementation>
</Method>

<Method name="now">
<Description>
	Convenience method, easy to read. Create a new instance representing the date and time NOW.</Description>
<ClassMethod>1</ClassMethod>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[	quit ..%New()
]]></Implementation>
</Method>

<Method name="nowUTC">
<Description>
	Create a new instance representing the date and time NOW in UTC.</Description>
<ClassMethod>1</ClassMethod>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[	quit ..%New($piece($ztimestamp, ".", 1))	//	Cut off fractional seconds
]]></Implementation>
</Method>

<Method name="today">
<Description>
	Create a new instance representing today at 00:00:00.</Description>
<ClassMethod>1</ClassMethod>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[	quit ..%New(..horologDatePart($horolog))
]]></Implementation>
</Method>

<Method name="tomorrow">
<Description>
	Create a new instance representing tomorrow at 00:00:00.</Description>
<ClassMethod>1</ClassMethod>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[	quit ..inDays(1)
]]></Implementation>
</Method>

<Method name="yesterday">
<Description>
	Create a new instance representing yesterday at 00:00:00.</Description>
<ClassMethod>1</ClassMethod>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[	quit ..beforeDays(1)
]]></Implementation>
</Method>

<Method name="inDays">
<Description>
	Create a new instance representing the day in 'in' days at 00:00:00. 'in' can be negative, too.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>in:%Integer</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[	quit ..%New(..horologDatePart($horolog) + in)
]]></Implementation>
</Method>

<Method name="beforeDays">
<Description>
	Create a new instance representing the day before 'before' days at 00:00:00. 'before' can be negative, too.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>before:%Integer</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[	quit ..inDays(-before)
]]></Implementation>
</Method>

<Method name="copy">
<Description>
	Make a copy of this instance.</Description>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[	quit ..%New(..horolog)
]]></Implementation>
</Method>

<UDLText name="T">
<Content><![CDATA[
//	-----	Getter				-----------------------------------------------

]]></Content>
</UDLText>

<Method name="getYear">
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[	quit $inumber($piece(..toDate(), "-", 1), "")
]]></Implementation>
</Method>

<Method name="getMonth">
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[	quit $inumber($piece(..toDate(), "-", 2), "")
]]></Implementation>
</Method>

<Method name="getDay">
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[	quit $inumber($piece(..toDate(), "-", 3), "")
]]></Implementation>
</Method>

<Method name="getHour">
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[	quit $inumber($piece(..toTime(), ":", 1), "")
]]></Implementation>
</Method>

<Method name="getMinute">
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[	quit $inumber($piece(..toTime(), ":", 2), "")
]]></Implementation>
</Method>

<Method name="getSecond">
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[	quit $inumber($piece(..toTime(), ":", 3), "")
]]></Implementation>
</Method>

<UDLText name="T">
<Content><![CDATA[
//	-----	Setter				-----------------------------------------------

]]></Content>
</UDLText>

<Method name="setYear">
<Description>
	Set the year. If out of range, raise an error.</Description>
<FormalSpec>year:%Integer</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[
	set odbcString = ..toDate()
	set $piece(odbcString, "-", 1) = year
	set ..horolog = $zdateh(odbcString, ..#InternalDateFormat) _ "," _ ..getTimePart()

	quit ##this
]]></Implementation>
</Method>

<Method name="setMonth">
<Description>
	Set the month. If out of range, raise an error.</Description>
<FormalSpec>month:%Integer</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[
	set odbcString = ..toDate()
	set $piece(odbcString, "-", 2) = month
	set ..horolog = $zdateh(odbcString, ..#InternalDateFormat) _ "," _ ..getTimePart()

	quit ##this
]]></Implementation>
</Method>

<Method name="setDay">
<Description>
	Set the day. If out of range, raise an error.</Description>
<FormalSpec>day:%Integer</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[
	set odbcString = ..toDate()
	set $piece(odbcString, "-", 3) = day
	set ..horolog = $zdateh(odbcString, ..#InternalDateFormat) _ "," _ ..getTimePart()

	quit ##this
]]></Implementation>
</Method>

<Method name="setHour">
<Description>
	Set the hours. If out of range, raise an error.</Description>
<FormalSpec>hour:%Integer</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[
	set odbcString = ..toTime()
	set $piece(odbcString, ":", 1) = hour
	set ..horolog = ..getDatePart() _ "," _ $ztimeh(odbcString, ..#InternalTimeFormat)

	quit ##this
]]></Implementation>
</Method>

<Method name="setMinute">
<Description>
	Set the minutes. If out of range, raise an error.</Description>
<FormalSpec>min:%Integer</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[
	set odbcString = ..toTime()
	set $piece(odbcString, ":", 2) = min
	set ..horolog = ..getDatePart() _ "," _ $ztimeh(odbcString, ..#InternalTimeFormat)

	quit ##this
]]></Implementation>
</Method>

<Method name="setSecond">
<Description>
	Set the seconds. If out of range, raise an error.</Description>
<FormalSpec>sex:%Integer</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[
	set odbcString = ..toTime()
	set $piece(odbcString, ":", 3) = sex
	set ..horolog = ..getDatePart() _ "," _ $ztimeh(odbcString, ..#InternalTimeFormat)

	quit ##this
]]></Implementation>
</Method>

<UDLText name="T">
<Content><![CDATA[
//	-----	Arithmetic			-----------------------------------------------

]]></Content>
</UDLText>

<Method name="addYears">
<Description>
	Add years to the current instance. Negative values are allowed, too.</Description>
<FormalSpec>years:%Integer</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[
	//	The implementation is different than the other add* methods because:
	//		nr. of days is not constant due to leap years
	//		over- and underflow can not happen
	quit ..setYear(..getYear() + years)
]]></Implementation>
</Method>

<Method name="addMonths">
<Description>
	Add months to the current instance. Negative values are allowed, too.</Description>
<FormalSpec>months:%Integer</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[	quit $$$ERROR("Not yet implemented")
]]></Implementation>
</Method>

<Method name="addWeeks">
<Description>
	Add weeks to the current instance. Negative values are allowed, too.</Description>
<FormalSpec>weeks:%Integer</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[	quit ..addDays(weeks * ..#DaysPerWeek)
]]></Implementation>
</Method>

<Method name="addDays">
<Description>
	Add days to the current instance. Negative values are allowed, too.</Description>
<FormalSpec>days:%Integer</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[	quit ..addHours(days * ..#HoursPerDay)
]]></Implementation>
</Method>

<Method name="addHours">
<Description>
	Add hours to the current instance. Negative values are allowed, too.</Description>
<FormalSpec>hours:%Integer</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[	quit ..addMinutes(hours * ..#MinsPerHour)
]]></Implementation>
</Method>

<Method name="addMinutes">
<Description>
	Add minutes to the current instance. Negative values are allowed, too.</Description>
<FormalSpec>mins:%Integer</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[	quit ..addSeconds(mins * ..#SecsPerMinute)
]]></Implementation>
</Method>

<Method name="addSeconds">
<Description>
	Add seconds to the current instance. Negative values are allowed, too.</Description>
<FormalSpec>secs:%Integer</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[
	set newSecs = ..getTimePart() + secs
	set overflow = newSecs \ ..#SecsPerDay
	set remainder = newSecs # ..#SecsPerDay
	
	if ((newSecs < 0) && (remainder > 0))		set overflow = overflow - 1

	set newDatePart = ..getDatePart() + overflow
	set newTimePart = remainder

	set ..horolog = newDatePart _ "," _ newTimePart
	
	quit ##this
]]></Implementation>
</Method>

<Method name="addDuration">
<Description>
	Add the duration to the current instance.
	Since durations are never negative, use subtractDuration(duration) for subtraction.</Description>
<FormalSpec>duration:DBUtils.Duration</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[	quit ..addSeconds(duration.seconds)
]]></Implementation>
</Method>

<Method name="subtractDuration">
<Description>
	Subtract the duration from the current instance (durations are never negative).</Description>
<FormalSpec>duration:DBUtils.Duration</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[	quit ..addSeconds(-duration.seconds)
]]></Implementation>
</Method>

<Method name="durationBetween">
<Description>
	Return the duration between the current instance and dateTime.
	The duration returned is never negative, so it's actually the 'absolute' duration.</Description>
<FormalSpec>dateTime:DBUtils.DateTime</FormalSpec>
<ReturnType>DBUtils.Duration</ReturnType>
<Implementation><![CDATA[
	//	dayDiff is always positive, secsDiff might be negative.

	if (..isBefore(dateTime))
	{
		set dayDiff = dateTime.getDatePart() - ..getDatePart()
		set secsDiff = dateTime.getTimePart() - ..getTimePart()
	}
	else
	{
		set dayDiff = ..getDatePart() - dateTime.getDatePart()
		set secsDiff = ..getTimePart() - dateTime.getTimePart()
	}

	quit ##class(DBUtils.Duration).%New((dayDiff * ..#SecsPerDay) + secsDiff)
]]></Implementation>
</Method>

<UDLText name="T">
<Content><![CDATA[
//	-----	Comparing			-----------------------------------------------

]]></Content>
</UDLText>

<Method name="isEqual">
<Description>
	Return true if the current instance and dateTime are equal, false otherwise.</Description>
<FormalSpec>dateTime:DBUtils.DateTime</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[	quit (..horolog = dateTime.horolog)
]]></Implementation>
</Method>

<Method name="isNotEqual">
<Description>
	Return true if the current instance and dateTime are not equal, false otherwise.</Description>
<FormalSpec>dateTime:DBUtils.DateTime</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[	quit '(..isEqual(dateTime))
]]></Implementation>
</Method>

<Method name="isBefore">
<Description>
	Return true if the current instance is before dateTime, false otherwise.</Description>
<FormalSpec>dateTime:DBUtils.DateTime</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[
	//	Compare the dates. If they are equal, compare the times:
	if (..getDatePart() = dateTime.getDatePart())
	{
		quit (..getTimePart() < dateTime.getTimePart())
	}
	else
	{
		quit (..getDatePart() < dateTime.getDatePart())
	}
]]></Implementation>
</Method>

<Method name="isAfter">
<Description>
	Return true if the current instance is after dateTime, false otherwise.</Description>
<FormalSpec>dateTime:DBUtils.DateTime</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[	quit dateTime.isBefore(##this)
]]></Implementation>
</Method>

<Method name="isBetween">
<Description>
	Return true if the current instance is between (excluding) the two dateTimes, false otherwise.</Description>
<FormalSpec>from:DBUtils.DateTime,to:DBUtils.DateTime</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[	quit (from.isBefore(##this) && to.isAfter(##this))
]]></Implementation>
</Method>

<Method name="isNotBetween">
<Description>
	Return true if the current instance is not between (including) the two dateTimes, false otherwise.</Description>
<FormalSpec>from:DBUtils.DateTime,to:DBUtils.DateTime</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[	quit '(..isBetween(from, to))
]]></Implementation>
</Method>

<UDLText name="T">
<Content><![CDATA[
//	-----	Converting			-----------------------------------------------

]]></Content>
</UDLText>

<UDLText name="T">
<Content><![CDATA[
//	-----	To			-----------------------------------------------

]]></Content>
</UDLText>

<Method name="toHorolog">
<Description>
	Return the horolog</Description>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[	quit ..horolog
]]></Implementation>
</Method>

<Method name="toDate">
<Description>
	Return the date in the given format</Description>
<FormalSpec>dFormat:%Integer=..#InternalDateFormat</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[	quit $zdate(..horolog, dFormat)
]]></Implementation>
</Method>

<Method name="toTime">
<Description>
	Return the time in the given format</Description>
<FormalSpec>tFormat:%Integer=..#InternalTimeFormat</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[	quit $ztime(..getTimePart(), tFormat)
]]></Implementation>
</Method>

<Method name="toDateTime">
<Description>
	Return the date and time in the given format</Description>
<FormalSpec>dFormat:%Integer=..#InternalDateFormat,tFormat:%Integer=..#InternalTimeFormat</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[	quit $zdatetime(..horolog, dFormat, tFormat)
]]></Implementation>
</Method>

<UDLText name="T">
<Content><![CDATA[
//	-----	From		-----------------------------------------------

]]></Content>
</UDLText>

<Method name="fromHorolog">
<Description>
	Set the date and time according to the given horolog.</Description>
<FormalSpec>horolog:%String</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[
	set ..horolog = horolog
	quit ##this
]]></Implementation>
</Method>

<Method name="fromDate">
<Description>
	Set the date according to the given date. Time is set to 00:00:00</Description>
<FormalSpec>date:%String,dFormat:%Integer=..#StandardDateFormat</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[
	set ..horolog = $zdateh(date, dFormat)
	quit ##this
]]></Implementation>
</Method>

<Method name="fromDateTime">
<Description>
	Set the date and time according to the given date and time.</Description>
<FormalSpec>datetime:%String,dFormat:%Integer=..#StandardDateFormat,tFormat:%Integer=..#StandardTimeFormat</FormalSpec>
<ReturnType>DBUtils.DateTime</ReturnType>
<Implementation><![CDATA[
	set ..horolog = $zdatetimeh(datetime, dFormat, tFormat)
	quit ##this
]]></Implementation>
</Method>

<UDLText name="T">
<Content><![CDATA[
//	-----	Support				-----------------------------------------------

]]></Content>
</UDLText>

<Method name="toString">
<Description>
	For easy testing.</Description>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[	quit "[DateTime:" _ $zdatetime(..horolog, ..#StandardDateFormat, ..#StandardTimeFormat) _ "]"
]]></Implementation>
</Method>

<Method name="write">
<Description>
	For easy testing.</Description>
<Implementation><![CDATA[	write ..toString()
]]></Implementation>
</Method>

<UDLText name="T">
<Content><![CDATA[
//	-----	Private				-----------------------------------------------

]]></Content>
</UDLText>

<UDLText name="T">
<Content><![CDATA[
//	-----	Instance	-----------------------------------------------

]]></Content>
</UDLText>

<Method name="getDatePart">
<Internal>1</Internal>
<Private>1</Private>
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[	quit ..horologDatePart(..horolog)
]]></Implementation>
</Method>

<Method name="getTimePart">
<Internal>1</Internal>
<Private>1</Private>
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[	quit ..horologTimePart(..horolog)
]]></Implementation>
</Method>

<UDLText name="T">
<Content><![CDATA[
//	-----	Class		-----------------------------------------------

]]></Content>
</UDLText>

<Method name="horologDatePart">
<Description>
[Previously private]</Description>
<Internal>1</Internal>
<ClassMethod>1</ClassMethod>
<FormalSpec>horolog</FormalSpec>
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[	quit $piece(horolog, ",", 1)
]]></Implementation>
</Method>

<Method name="horologTimePart">
<Description>
[Previously private]</Description>
<Internal>1</Internal>
<ClassMethod>1</ClassMethod>
<FormalSpec>horolog</FormalSpec>
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[	quit $piece(horolog, ",", 2)
]]></Implementation>
</Method>

<Method name="fillLeftWithZeros">
<Description>
[Previously private]</Description>
<Internal>1</Internal>
<ClassMethod>1</ClassMethod>
<FormalSpec>value:%Integer,size:%Integer=2</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[	quit $translate($justify(value, size), " ", "0")
]]></Implementation>
</Method>

<Storage name="Default">
<Type>%Library.CacheSerialState</Type>
<State>DateTimeState</State>
<StreamLocation>^DBUtils.DateTimeS</StreamLocation>
<Data name="DateTimeState">
<Structure>listnode</Structure>
<Subscript/>
<Value name="1">
<Value>horolog</Value>
</Value>
</Data>
</Storage>
</Class>


<Class name="DBUtils.DateUtils">
<Super>%RegisteredObject</Super>
<TimeChanged>62073,57107.545238</TimeChanged>
<TimeCreated>61346,51311.809701</TimeCreated>

<Parameter name="WeeksSinceBeginningYear">
<Default>ww</Default>
</Parameter>

<Parameter name="WeekDay">
<Default>w</Default>
</Parameter>

<Method name="CalcPeriode">
<ClassMethod>1</ClassMethod>
<FormalSpec>dtEnde:%Date,valuta:%Date</FormalSpec>
<ReturnType>%Integer</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[
      Set periode=12
      Set tEnde=$ZD(dtEnde)
      Set vMonth=+$P($ZD(valuta),"/",1)
      Set vYear=+$P($ZD(valuta),"/",3)
      
      While ((periode>1)&&
             ((+$P(tEnde,"/",1)'=vMonth)||
              (+$P(tEnde,"/",3)'=vYear))) 
      {
            Set tEnde=..MonthAdd(tEnde,-1)
            Set periode=periode-1
      }
      quit periode
]]></Implementation>
</Method>

<Method name="YearAdd">
<ClassMethod>1</ClassMethod>
<FormalSpec>tDate:%Date,tYear:%Integer</FormalSpec>
<Language>basic</Language>
<ReturnType>%Date</ReturnType>
<Implementation><![CDATA[      return DateAdd("yyyy",tYear,tDate)
]]></Implementation>
</Method>

<Method name="MonthAdd">
<ClassMethod>1</ClassMethod>
<FormalSpec>tDate:%Date,tMonth:%Integer</FormalSpec>
<Language>basic</Language>
<ReturnType>%Date</ReturnType>
<Implementation><![CDATA[      return DateAdd("m",tMonth,tDate)
]]></Implementation>
</Method>

<Method name="DayAdd">
<ClassMethod>1</ClassMethod>
<FormalSpec>tDate:%Date,tDay:%Integer</FormalSpec>
<Language>basic</Language>
<ReturnType>%Date</ReturnType>
<Implementation><![CDATA[    return DateAdd("y",tDay,tDate)
]]></Implementation>
</Method>

<Method name="DateDiffInDays">
<ClassMethod>1</ClassMethod>
<FormalSpec>tDate1:%Date,tDate2:%Date</FormalSpec>
<Language>basic</Language>
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[    return DateDiff("y",tDate1,tDate2)
]]></Implementation>
</Method>

<Method name="GetYearFromDate">
<ClassMethod>1</ClassMethod>
<FormalSpec>Date:%Date,EndeGeschJahr:%Date=0</FormalSpec>
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[
	//gem aw nicht mehr nötig - 08.12.2010 
	/*if (EndeGeschJahr '= 0) {
		if (Date = 0) {
			set Date = $H
		}
		if ((EndeGeschJahr '= 0) && (Date > EndeGeschJahr)) {
			set Date = EndeGeschJahr
		}
	}*/
    quit +$Piece($ZD(Date, 3),"-",1)
]]></Implementation>
</Method>

<Method name="DatePart">
<Description>
für Info der Parameter siehe Caché Dokumentation [DatePart Function] strDate = "mm/dd/yyyy"</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>interval:%String,strDate:%String,firstDayOfWeek:%Integer=1,firstWeekOfYear:%Integer=2</FormalSpec>
<Language>basic</Language>
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[    return DatePart(interval,strDate,firstDayOfWeek, firstWeekOfYear)
]]></Implementation>
</Method>

<Method name="GetWeekByAgrisEinst">
<Description>
Gets the weeknumber of the year corresponding the setting in agris</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>date:%Date</FormalSpec>
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[
	
	set kWGemUSA = (##class(DBCore.AppEinstellung).GetShortEinst(##class(DBCore.Konst).KALENDERWOCHENART()) = ##class(DBCore.Konst).KALENDERWOCHEGEMUSA())
	set woBeginnSO = (##class(DBCore.AppEinstellung).GetShortEinst(##class(DBCore.Konst).WOCHENBEGINN()) = ##class(DBCore.Konst).WOCHENBEGINNSONNTAG()) 
		
	set wo = 0
	if (kWGemUSA = $$$YES) {
		//sunday
		if (woBeginnSO = $$$YES) {
			// 1 = Sunday, 2 = Monday
			set wo = ##class(DBUtils.DateUtils).DatePart(..#WeeksSinceBeginningYear, $zd(date), 1,1)
		
		//monday
		} else {
			set wo = ##class(DBUtils.DateUtils).DatePart(..#WeeksSinceBeginningYear, $zd(date), 2,1)
		}
		
		
	} else {
		//sunday
		if (woBeginnSO = $$$YES) {
			// 1 = Sunday, 2 = Monday
			set wo = ##class(DBUtils.DateUtils).DatePart(..#WeeksSinceBeginningYear, $zd(date), 1,2)
		
		//monday
		} else {
			set wo = ##class(DBUtils.DateUtils).DatePart(..#WeeksSinceBeginningYear, $zd(date), 2,2)
		}
	}
	Quit wo
]]></Implementation>
</Method>

<Method name="GetFirstDateOfWeek">
<Description><![CDATA[
returns the first date of the given year and week (minvalue if week is < 1)
this function belongs to the agris settings (week day start, week calculation)]]></Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>year:%Integer,week:%Integer</FormalSpec>
<ReturnType>%Date</ReturnType>
<Implementation><![CDATA[
	
    #dim jan1 As DBUtils.DateTime
    
    set kWGemUSA = (##class(DBCore.AppEinstellung).GetShortEinst(##class(DBCore.Konst).KALENDERWOCHENART()) = ##class(DBCore.Konst).KALENDERWOCHEGEMUSA())
	set woBeginnSO = (##class(DBCore.AppEinstellung).GetShortEinst(##class(DBCore.Konst).WOCHENBEGINN()) = ##class(DBCore.Konst).WOCHENBEGINNSONNTAG()) 
    
    //result date in horolog
    set result = 0
    
    //weeks have to be greater than 0
    if (week >= 1) {
	    
	    //agris just supports weekstart on sunday or monday
		//if week starts on monday, thursday is 4, if it starts un sunday
		//thursday is 5
		set thursday = 4
		set monday = 1
		if (woBeginnSO = $$$YES) {
			set monday = 2
			set thursday = 5
		}
	    
	    set jan1 = ##class(DBUtils.DateTime).new(year,1,1)
		set tmp = jan1.copy()
	
	    set paraFirstDay = ..GetCacheParamFirstDayOfWeek()
	    set paraFirstWeek = ..GetCacheParamFirstWeekOfYear()
	    
	    set weekday1Jan = ..DatePart(..#WeekDay, jan1.toDate(1), paraFirstDay, paraFirstWeek)
	    
	    set dayOffset = 0
	    set mondayIsAfter1Jan = $$$NO
	    if (kWGemUSA = $$$YES) {
		 	set dayOffset = monday - weekday1Jan   
	    } else {
		   
		    //1 jan is in first week -> first monday is before 1. jan
		    if (weekday1Jan <= thursday) {
				set dayOffset = monday - weekday1Jan   
			    
			//1 jan is last week of year before -> first monday is after 1. jan
		    } else {
			    set mondayIsAfter1Jan = $$$YES
			    set dayOffset = ((7 - weekday1Jan) + monday)
		    }
	    }
	   
		set firstMonday = jan1.addDays(dayOffset)
		
		//w "First Monday of WO1 Year "_year_": "_firstMonday.toDate(4),!
		
		set woJan1 = ..GetWeekByAgrisEinst(+tmp.toHorolog())
		
		if ((woJan1 <= 1) || (mondayIsAfter1Jan = $$$YES)) {
			set week = week - 1	
		}
		
		do firstMonday.addDays(week * 7)
		
		if (woBeginnSO = $$$YES) {
			do firstMonday.addDays(-1)
		}
		    
		Quit $zd(firstMonday.toHorolog(),4)

	    
    }

	//return minvalue
	Quit $zd(0,4)
]]></Implementation>
</Method>

<Method name="GetCacheParamFirstDayOfWeek">
<Description>
Cache Param for the first day of a week by agris settings</Description>
<ClassMethod>1</ClassMethod>
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[
	
	//get agris settings
	set woBeginnSO = (##class(DBCore.AppEinstellung).GetShortEinst(##class(DBCore.Konst).WOCHENBEGINN()) = ##class(DBCore.Konst).WOCHENBEGINNSONNTAG()) 
       
    //sunday
	if (woBeginnSO = $$$YES) {
		Quit 1
	}
	//monday
	else {
		Quit 2
	}
]]></Implementation>
</Method>

<Method name="GetCacheParamFirstWeekOfYear">
<Description>
Cache Param for the first week of year by agris settings</Description>
<ClassMethod>1</ClassMethod>
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[
	
	//get agris settings
	set kWGemUSA = (##class(DBCore.AppEinstellung).GetShortEinst(##class(DBCore.Konst).KALENDERWOCHENART()) = ##class(DBCore.Konst).KALENDERWOCHEGEMUSA())
       
    //american
	if (kWGemUSA = $$$YES) {
		Quit 1
	}
	//european
	else {
		Quit 2
	}
]]></Implementation>
</Method>

<Method name="CheckValidWeek">
<Description>
Check if the week with the year is valid, true = valid, false = invalid</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>year:%Integer,week:%Integer</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[
	
	set retval = $$$NO
	set firstWeekNextYear = year + 1
	
	//first week date of first week of the following year
	set firstDateWeek = ..GetFirstDateOfWeek(firstWeekNextYear, 1)
	set firstDateWeekHorolog = $zdh(firstDateWeek,4)
	
	if (firstDateWeekHorolog '= 0) {
		set lastDateOfLastWeek = firstDateWeekHorolog - 1
		    
	    //max week number of the year
	    set weekno = ..GetWeekByAgrisEinst(lastDateOfLastWeek)
	    
	    if ((week <= weekno) && (week > 0)) {
			set retval = $$$YES    
	    } else {
			set retval = $$$NO
	    }
	}
	
	Quit retval
]]></Implementation>
</Method>
</Class>


<Class name="DBUtils.Dev">
<Super>%RegisteredObject</Super>
<TimeChanged>62417,33834</TimeChanged>
<TimeCreated>61350,33391.28803</TimeCreated>

<Method name="DoLang">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
	Set rset = ##class(%ResultSet).%New("DBUtils.StringUtils.ListeGesamt")
	Do rset.Execute()
	While (rset.Next()) {
	   Set artikel = ##class(DBAgrofresh.Artikel).%OpenId(rset.Data("ID"))
	   Set text = artikel.Artikeltext.GetAt("it")
	   Do artikel.Artikeltext.SetAt(text,"de")
	   Do artikel.Artikeltext.SetAt(text,"fr")
	   Do artikel.Artikeltext.SetAt(text,"en")
	   DO artikel.%Save()
	   k artikel
	}
]]></Implementation>
</Method>

<Query name="ListeGesamt">
<Type>%SQLQuery</Type>
<SqlProc>1</SqlProc>
<SqlQuery>	SELECT %ID FROM DBAgrofresh.Artikel</SqlQuery>
</Query>

<Method name="RebuildIndices">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
      Set tSQL="Select ID, Super, Abstract From %Dictionary.ClassDefinition Where ID LIKE 'DB%' AND Super Like '%Persistent%'"
      Set trsC=##Class(%Library.ResultSet).%New("%DynamicQuery:SQL")
      Set tsc=trsC.Prepare(tSQL)
      Quit:$$$ISERR(tsc) $System.Status.GetErrorText(tsc) 
      Set tsc=trsC.Execute()
      Quit:$$$ISERR(tsc) $System.Status.GetErrorText(tsc) 
      While trsC.Next(.tsc) {
	        If (trsC.Data("Abstract") = 0) {
                  Set tCName=trsC.ID
                  Set tC=$System.OBJ.New(tCName)
                  Set delim = "."
                  Set depth = $LENGTH(tCName, delim)
                  set tmpStr = $PIECE(tCName, delim, 1)
                  For i = 1:1:depth {
	              	if (i '= 1) {
	              		if (i '= depth) {
		            	 	set tmpStr = tmpStr_"_"_$PIECE(tCName,delim,i)  	
	              		} else {
		              		set tmpStr = tmpStr_delim_$PIECE(tCName,delim,i)  	
	              		}
	              	}
                  }
                  Set tCName = tmpStr
                  Do $SYSTEM.SQL.PurgeForTable(tCName)
                  Do tC.%PurgeIndices()
                  Do tC.%BuildIndices() 
                  Do $SYSTEM.SQL.TuneTable(tCName,1,0,.tsc,1)
            }
      }
      Quit:$$$ISERR(tsc) $System.Status.GetErrorText(tsc) 
      Quit tsc
]]></Implementation>
</Method>

<Method name="SetDecimal">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
	Set rs=##Class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	//Set sc=rs.Prepare("Select ID From %Dictionary.ClassDefinition Where ID Like 'DB%'")
	Set sc=rs.Prepare("Select ID From %Dictionary.ClassDefinition Where ID %STARTSWITH 'DB'")
	If $$$ISERR(sc) Do $System.Status.DisplayError(sc) Quit
	Set sc=rs.Execute()
	If $$$ISERR(sc) Do $System.Status.DisplayError(sc) Quit
	Set tcnt=0
	While rs.Next(.sc) {
		// open the Class-Defination
		Set tClassName=rs.ID
		Set cdef=##Class(%Dictionary.ClassDefinition).%OpenId(tClassName)
		Set tcnt=tcnt+1
		//w !,tcnt," ", cdef.Name
    	Set prop=##Class(%Dictionary.PropertyDefinition).%New()
    	Set meth=##Class(%Dictionary.MethodDefinition).%New()
    	Set qryd=##Class(%Dictionary.QueryDefinition).%New()
		Set tCompile=0
		Set pcnt=cdef.Properties.Count()
		Set mcnt=cdef.Methods.Count()
		Set qcnt=cdef.Queries.Count()
		For i=1:1:pcnt {
			Set prop=cdef.Properties.GetAt(i)
			Set ptype=prop.Type
			If ((ptype="%Double")||(ptype="%Library.Double")) {
				Set tCompile=1
				Set prop.Type="%Decimal"
				Do prop.Parameters.SetAt(5,"SCALE")
			}
		}
		For i=1:1:mcnt {
			Set meth=cdef.Methods.GetAt(i)
			Set tfs=meth.FormalSpec
			If ($L(tfs,"%Double")>1)||($L(tfs,"%Library.Double")>1) {
				Set tfs=$Replace(tfs,"%Double","%Decimal(SCALE=5)")
				Set tfs=$Replace(tfs,"%Library.Double","%Decimal(SCALE=5)")
				Set meth.FormalSpec=tfs
				Set tCompile=1
			}
			set tmrt=$ZStrip(meth.ReturnType, "<>W")
			If (tmrt="%Double") {
				w !,cdef.Name,"/",meth.Name,": ",tmrt
				Set meth.ReturnType="%Decimal"
				Set meth.ReturnTypeParams="SCALE=5"
				Set tCompile=1
			}
			//(tmrt="%Library.Double")
		}
		For i=1:1:qcnt {
			Set qryd=cdef.Queries.GetAt(i)
			Set tfs=qryd.FormalSpec
			If ($L(tfs,"%Double")>1)||($L(tfs,"%Library.Double")>1) {
				Set tfs=$Replace(tfs,"%Double","%Decimal(SCALE=5)")
				Set tfs=$Replace(tfs,"%Library.Double","%Decimal(SCALE=5)")
				Set qryd.FormalSpec=tfs
				Set tCompile=1
			}
		}
		If tCompile {
			Set sc=cdef.%Save()
			Quit:$$$ISERR(sc)
			Do $system.OBJ.Compile(tClassName,"k",.sc)
			Do:$$$ISERR(sc) $System.Status.DisplayError(sc)
		}
		/*
		If $$$ISERR(sc) {
			Do $System.Status.DisplayError(sc) 
			Quit
		}
		*/
	}
]]></Implementation>
</Method>

<Method name="RoundDecimals">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
	Set rs=##Class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Set sc=rs.Prepare("Select ID From %Dictionary.ClassDefinition Where ID %STARTSWITH 'DB'")
	If $$$ISERR(sc) Do $System.Status.DisplayError(sc) Quit
	Set sc=rs.Execute()
	If $$$ISERR(sc) Do $System.Status.DisplayError(sc) Quit
	Set tcnt=0
	While rs.Next(.sc) {
		// open the Class-Defination
		Set tClassName=rs.ID
		Set cdef=##Class(%Dictionary.ClassDefinition).%OpenId(tClassName)
		Set prop=##Class(%Dictionary.PropertyDefinition).%New()
    	Set pcnt=cdef.Properties.Count()
		For i=1:1:pcnt {
			Set prop=cdef.Properties.GetAt(i)
			Set ptype=prop.Type
			If ((ptype="%Decimal")||(ptype="%Library.Decimal")) {
				if ((prop.Calculated=0)&&(prop.Collection'="array")) {
					Set tClassName = $REPLACE(tClassName, ".SD.", "_SD.")
					Set ustatement = "UPDATE "_tClassName_" SET "_prop.Name_"=ROUND(CAST("_prop.Name_" As DECIMAL(18,5)),5)"
					
					//w tClassName_"."_prop.Name
					
					Set urs=##Class(%Library.ResultSet).%New("%DynamicQuery:SQL")
					Set usc=urs.Prepare(ustatement)
					//w "  "_$$$ISOK(usc)
					if ($$$ISERR(usc)) {
						w prop.Collection, !
						w prop.MultiDimensional, !
						w ustatement,!
						w tClassName_"."_prop.Name, " : ", usc, !, !
					}
					Set usc=urs.Execute()
					//w "  "_$$$ISOK(usc),!
					if ($$$ISERR(usc)) {
						w prop.Collection, !
						w prop.MultiDimensional, !
						w ustatement,!
						w tClassName_"."_prop.Name, " : ", usc, !, !
					}
				}
			}
		}		
	}
]]></Implementation>
</Method>

<Method name="ShowObjects">
<ClassMethod>1</ClassMethod>
<FormalSpec>detailed:%Boolean</FormalSpec>
<Implementation><![CDATA[
	if (detailed) {
		w $SYSTEM.OBJ.ShowObjects("d")
	} else {
		w $SYSTEM.OBJ.ShowObjects()
	}
]]></Implementation>
</Method>

<Method name="ListeObjects">
<ClassMethod>1</ClassMethod>
<ReturnType>%List</ReturnType>
<Implementation><![CDATA[
	
	set retval = ""
	set result = ##class(%Library.ResultSet).%New("%SYSTEM.OBJ:ObjectList")
	set mands = result.%Execute()
	
	while (result.Next(.mands)) {
		set retval = retval_$lb(result.Data("OREF")_":"_result.Data("ClassName"))
	}
	
	quit retval
]]></Implementation>
</Method>

<Method name="GetDescriptions">
<ClassMethod>1</ClassMethod>
<FormalSpec>OrderLineId:%String</FormalSpec>
<ReturnType>%String</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[
	set retval = ""
	/*
	set order = ##class(Order.OrderLine).%OpenId(OrderLineId)
	
	Set key = ""
 	Do {
    	Set line = order.ItemDescriptions.GetNext(.key)
    	If (line '= "") {
	    	if (line.Ident = "CU") {
	        	set retval = retval_line.Textline1_line.Textline2
	    	}
	    }
 	} While (key '= "")
 	*/
 	Quit retval
]]></Implementation>
</Method>

<Method name="TransferFormDataAgrofresh">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
	
	&sql(Delete from DBAgrofresh_SD.TblKopf)
	&sql(Delete from DBAgrofresh_SD.TblKopfEntry)
	&sql(Delete from DBAgrofresh_SD.TblDataEntry)
	&sql(Delete from DBAgrofresh_SD.TblSREntry)
	&sql(Delete from DBAgrofresh_SD.TblSRgkEntry)
	&sql(Delete from DBAgrofresh_SD.TblSRvlEntry)
	&sql(Delete from DBAgrofresh_SD.TblFuss)
	&sql(Delete from DBAgrofresh_SD.TblFussEntry)
	&sql(Delete from DBAgrofresh_SD.TblFussSkntE)
	
	Set strSQL="SELECT ID FROM DBAgrofresh_SD.FormKopf"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set pos = ##class(DBAgrofresh.SD.FormKopf).%OpenId(rs.Data("ID"))
		if (pos '= "") {	
			set neu = ##class(DBAgrofresh.SD.TblKopf).%New()
			set neu.Bezeichnung = pos.Bezeichnung
			
			set neu.DataGenFont.Aktiv = pos.DataGenFontAktiv
			set neu.DataGenFont.Bold = pos.DataGenFontBold
			set neu.DataGenFont.Color = pos.DataGenFontColor
			set neu.DataGenFont.Italic = pos.DataGenFontItalic
			set neu.DataGenFont.Name = pos.DataGenFontName
			set neu.DataGenFont.Size = pos.DataGenFontSize
			set neu.DataGenFont.Strikeout = pos.DataGenFontStrikeout
			
			set neu.DataGenRahmen.AbstandLinks = pos.DataGenRahmenAbstandLinks
			set neu.DataGenRahmen.AbstandOben = pos.DataGenRahmenAbstandOben
			set neu.DataGenRahmen.AbstandRechts = pos.DataGenRahmenAbstandRechts
			set neu.DataGenRahmen.AbstandUnten = pos.DataGenRahmenAbstandUnten
			set neu.DataGenRahmen.Aktiv = pos.DataGenRahmenAktiv
			set neu.DataGenRahmen.AktivLinks = pos.DataGenRahmenAktivLinks
			set neu.DataGenRahmen.AktivOben = pos.DataGenRahmenAktivOben
			set neu.DataGenRahmen.AktivRechts = pos.DataGenRahmenAktivRechts
			set neu.DataGenRahmen.AktivUnten = pos.DataGenRahmenAktivUnten
			set neu.DataGenRahmen.BreiteLinks = pos.DataGenRahmenBreiteLinks
			set neu.DataGenRahmen.BreiteOben = pos.DataGenRahmenBreiteOben
			set neu.DataGenRahmen.BreiteRechts = pos.DataGenRahmenBreiteRechts
			set neu.DataGenRahmen.BreiteUnten = pos.DataGenRahmenBreiteUnten
			
			set neu.GenFont.Aktiv = pos.GenFontAktiv
			set neu.GenFont.Bold = pos.GenFontBold
			set neu.GenFont.Color = pos.GenFontColor
			set neu.GenFont.Italic = pos.GenFontItalic
			set neu.GenFont.Name = pos.GenFontName
			set neu.GenFont.Size = pos.GenFontSize
			set neu.GenFont.Strikeout = pos.GenFontStrikeout
		
			set neu.GenRahmen.AbstandLinks = pos.GenRahmenAbstandLinks
			set neu.GenRahmen.AbstandOben = pos.GenRahmenAbstandOben
			set neu.GenRahmen.AbstandRechts = pos.GenRahmenAbstandRechts
			set neu.GenRahmen.AbstandUnten = pos.GenRahmenAbstandUnten
			set neu.GenRahmen.Aktiv = pos.GenRahmenAktiv
			set neu.GenRahmen.AktivLinks = pos.GenRahmenAktivLinks
			set neu.GenRahmen.AktivOben = pos.GenRahmenAktivOben
			set neu.GenRahmen.AktivRechts = pos.GenRahmenAktivRechts
			set neu.GenRahmen.AktivUnten = pos.GenRahmenAktivUnten
			set neu.GenRahmen.BreiteLinks = pos.GenRahmenBreiteLinks
			set neu.GenRahmen.BreiteOben = pos.GenRahmenBreiteOben
			set neu.GenRahmen.BreiteRechts = pos.GenRahmenBreiteRechts
			set neu.GenRahmen.BreiteUnten = pos.GenRahmenBreiteUnten
			
			set neu.Mandant = pos.Mandant
			set neu.Nummer = pos.Nummer
			
			set neu.SrGenFont.Aktiv = pos.SrGenFontAktiv
			set neu.SrGenFont.Bold = pos.SrGenFontBold
			set neu.SrGenFont.Color = pos.SrGenFontColor
			set neu.SrGenFont.Italic = pos.SrGenFontItalic
			set neu.SrGenFont.Name = pos.SrGenFontName
			set neu.SrGenFont.Size = pos.SrGenFontSize
			set neu.SrGenFont.Strikeout = pos.SrGenFontStrikeout
			
			set neu.SrGenRahmen.AbstandLinks = pos.SrGenRahmenAbstandLinks
			set neu.SrGenRahmen.AbstandOben = pos.SrGenRahmenAbstandOben
			set neu.SrGenRahmen.AbstandRechts = pos.SrGenRahmenAbstandRechts
			set neu.SrGenRahmen.AbstandUnten = pos.SrGenRahmenAbstandUnten
			set neu.SrGenRahmen.Aktiv = pos.SrGenRahmenAktiv
			set neu.SrGenRahmen.AktivLinks = pos.SrGenRahmenAktivLinks
			set neu.SrGenRahmen.AktivOben = pos.SrGenRahmenAktivOben
			set neu.SrGenRahmen.AktivRechts = pos.SrGenRahmenAktivRechts
			set neu.SrGenRahmen.AktivUnten = pos.SrGenRahmenAktivUnten
			set neu.SrGenRahmen.BreiteLinks = pos.SrGenRahmenBreiteLinks
			set neu.SrGenRahmen.BreiteOben = pos.SrGenRahmenBreiteOben
			set neu.SrGenRahmen.BreiteRechts = pos.SrGenRahmenBreiteRechts
			set neu.SrGenRahmen.BreiteUnten = pos.SrGenRahmenBreiteUnten
			
			set neu.SrKopfGenFont.Aktiv = pos.SrKopfGenFontAktiv
			set neu.SrKopfGenFont.Bold = pos.SrKopfGenFontBold
			set neu.SrKopfGenFont.Color = pos.SrKopfGenFontColor
			set neu.SrKopfGenFont.Italic = pos.SrKopfGenFontItalic
			set neu.SrKopfGenFont.Name = pos.SrKopfGenFontName
			set neu.SrKopfGenFont.Size = pos.SrKopfGenFontSize
			set neu.SrKopfGenFont.Strikeout = pos.SrKopfGenFontStrikeout
			
			set neu.SrKopfGenRahmen.AbstandLinks = pos.SrKopfGenRahmenAbstandLinks
			set neu.SrKopfGenRahmen.AbstandOben = pos.SrKopfGenRahmenAbstandOben
			set neu.SrKopfGenRahmen.AbstandRechts = pos.SrKopfGenRahmenAbstandRechts
			set neu.SrKopfGenRahmen.AbstandUnten = pos.SrKopfGenRahmenAbstandUnten
			set neu.SrKopfGenRahmen.Aktiv = pos.SrKopfGenRahmenAktiv
			set neu.SrKopfGenRahmen.AktivLinks = pos.SrKopfGenRahmenAktivLinks
			set neu.SrKopfGenRahmen.AktivOben = pos.SrKopfGenRahmenAktivOben
			set neu.SrKopfGenRahmen.AktivRechts = pos.SrKopfGenRahmenAktivRechts
			set neu.SrKopfGenRahmen.AktivUnten = pos.SrKopfGenRahmenAktivUnten
			set neu.SrKopfGenRahmen.BreiteLinks = pos.SrKopfGenRahmenBreiteLinks
			set neu.SrKopfGenRahmen.BreiteOben = pos.SrKopfGenRahmenBreiteOben
			set neu.SrKopfGenRahmen.BreiteRechts = pos.SrKopfGenRahmenBreiteRechts
			set neu.SrKopfGenRahmen.BreiteUnten = pos.SrKopfGenRahmenBreiteUnten
		
			set sc = neu.%Save()
			
			if ($$$ISERR(sc)) {
				w "Saveerror Kopf: "_sc,!
			}

		}
	}
		
	Set strSQL="SELECT ID, Formularkopf->Nummer as KNummer, Formularkopf->Mandant as Mandant FROM DBAgrofresh_SD.FormKopfEntry"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set posE = ##class(DBAgrofresh.SD.FormKopfEntry).%OpenId(rs.Data("ID"))
		if (posE '= "") {	
			set neuE = ##class(DBAgrofresh.SD.TblKopfEntry).%New()
			set neuE.Aktiv = posE.Aktiv
			set neuE.Ausrichtung = posE.Ausrichtung
			set neuE.Breite = posE.Breite
			set neuE.Index = posE.Index
			set neuE.Nummer = posE.Nummer
			set neuE.Text = posE.Text
									
			set neuE.Font.Bold = posE.FontBold
			set neuE.Font.Color = posE.FontColor
			set neuE.FontColor = posE.FontColor
			set neuE.Font.Italic = posE.FontItalic
			set neuE.Font.Name = posE.FontName
			set neuE.Font.Size = posE.FontSize
			set neuE.Font.Strikeout = posE.FontStrikeout
				
			set neuE.Rahmen.AbstandLinks = posE.RahmenAbstandLinks
			set neuE.Rahmen.AbstandOben = posE.RahmenAbstandOben
			set neuE.Rahmen.AbstandRechts = posE.RahmenAbstandRechts
			set neuE.Rahmen.AbstandUnten = posE.RahmenAbstandUnten
			set neuE.Rahmen.AktivLinks =posE.RahmenAktivLinks
			set neuE.Rahmen.AktivOben = posE.RahmenAktivOben
			set neuE.Rahmen.AktivRechts = posE.RahmenAktivRechts
			set neuE.Rahmen.AktivUnten = posE.RahmenAktivUnten
			set neuE.Rahmen.BreiteLinks = posE.RahmenBreiteLinks
			set neuE.Rahmen.BreiteOben = posE.RahmenBreiteOben
			set neuE.Rahmen.BreiteRechts = posE.RahmenBreiteRechts
			set neuE.Rahmen.BreiteUnten = posE.RahmenBreiteUnten
		
			set kid = ##Class(DBAgrofresh.SD.TblKopf).GetTblKopfOidByCode(rs.Data("Mandant"), rs.Data("KNummer"))
		
			if (kid '= "") {
				set neuE.Tabellenkopf = ##Class(DBAgrofresh.SD.TblKopf).%OpenId(kid)
		
				set sc = neuE.%Save()
			
				if ($$$ISERR(sc)) {
					w "Saveerror KopfEntry: "_sc,!
				}
			} else {
				w "KopfEntry nicht gefunden",!
			}

		}
	}
	
	Set strSQL="SELECT ID, Formularkopf->Nummer as KNummer, Formularkopf->Mandant as Mandant FROM DBAgrofresh_SD.FormDataEntry"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set posD = ##class(DBAgrofresh.SD.FormDataEntry).%OpenId(rs.Data("ID"))
		if (posD '= "") {	
			set neuD = ##class(DBAgrofresh.SD.TblDataEntry).%New()
			set neuD.Aktiv = posD.Aktiv
			set neuD.Ausrichtung = posD.Ausrichtung
			set neuD.Breite = posD.Breite
			set neuD.Index = posD.Index
			set neuD.Nummer = posD.Nummer
									
			set neuD.Font.Bold = posD.FontBold
			set neuD.Font.Color = posD.FontColor
			set neuD.Font.Italic = posD.FontItalic
			set neuD.Font.Name = posD.FontName
			set neuD.Font.Size = posD.FontSize
			set neuD.Font.Strikeout = posD.FontStrikeout
				
			set neuD.Rahmen.AbstandLinks = posD.RahmenAbstandLinks
			set neuD.Rahmen.AbstandOben = posD.RahmenAbstandOben
			set neuD.Rahmen.AbstandRechts = posD.RahmenAbstandRechts
			set neuD.Rahmen.AbstandUnten = posD.RahmenAbstandUnten
			set neuD.Rahmen.AktivLinks =posD.RahmenAktivLinks
			set neuD.Rahmen.AktivOben = posD.RahmenAktivOben
			set neuD.Rahmen.AktivRechts = posD.RahmenAktivRechts
			set neuD.Rahmen.AktivUnten = posD.RahmenAktivUnten
			set neuD.Rahmen.BreiteLinks = posD.RahmenBreiteLinks
			set neuD.Rahmen.BreiteOben = posD.RahmenBreiteOben
			set neuD.Rahmen.BreiteRechts = posD.RahmenBreiteRechts
			set neuD.Rahmen.BreiteUnten = posD.RahmenBreiteUnten

			set neuD.Format.AnzDezStellen = posD.FormatAnzDezStellen
			set neuD.Format.Datum = posD.FormatDatum
			set neuD.Format.Einheit = posD.FormatEinheit
			set neuD.Format.TextFallsLeer = posD.FormatTextFallsLeer
			set neuD.Format.KeineAusgabe = posD.FormatKeineAusgabe
			set neuD.Format.Totalisieren = posD.FormatTotalisieren
		
			set kid = ##Class(DBAgrofresh.SD.TblKopf).GetTblKopfOidByCode(rs.Data("Mandant"), rs.Data("KNummer"))
		
			if (kid '= "") {
				set neuD.Tabellenkopf = ##Class(DBAgrofresh.SD.TblKopf).%OpenId(kid)
		
				set sc = neuD.%Save()
			
				if ($$$ISERR(sc)) {
					w "Saveerror DateEntry: "_sc,!
				}
			} else {
				w "DateEntry nicht gefunden",!
			}

		}
		
	}
	
	Set strSQL="SELECT ID, Formularkopf->Nummer as KNummer, Formularkopf->Mandant as Mandant FROM DBAgrofresh_SD.FormSREntry"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set posD = ##class(DBAgrofresh.SD.FormSREntry).%OpenId(rs.Data("ID"))
		if (posD '= "") {	
			set neuD = ##class(DBAgrofresh.SD.TblSREntry).%New()
			set neuD.Aktiv = posD.Aktiv
			set neuD.Ausrichtung = posD.Ausrichtung
			set neuD.Breite = posD.Breite
			set neuD.Index = posD.Index
			set neuD.Nummer = posD.Nummer
			set neuD.Text = posD.Text
									
			set neuD.Font.Bold = posD.FontBold
			set neuD.Font.Color = posD.FontColor
			set neuD.Font.Italic = posD.FontItalic
			set neuD.Font.Name = posD.FontName
			set neuD.Font.Size = posD.FontSize
			set neuD.Font.Strikeout = posD.FontStrikeout
				
			set neuD.Rahmen.AbstandLinks = posD.RahmenAbstandLinks
			set neuD.Rahmen.AbstandOben = posD.RahmenAbstandOben
			set neuD.Rahmen.AbstandRechts = posD.RahmenAbstandRechts
			set neuD.Rahmen.AbstandUnten = posD.RahmenAbstandUnten
			set neuD.Rahmen.AktivLinks =posD.RahmenAktivLinks
			set neuD.Rahmen.AktivOben = posD.RahmenAktivOben
			set neuD.Rahmen.AktivRechts = posD.RahmenAktivRechts
			set neuD.Rahmen.AktivUnten = posD.RahmenAktivUnten
			set neuD.Rahmen.BreiteLinks = posD.RahmenBreiteLinks
			set neuD.Rahmen.BreiteOben = posD.RahmenBreiteOben
			set neuD.Rahmen.BreiteRechts = posD.RahmenBreiteRechts
			set neuD.Rahmen.BreiteUnten = posD.RahmenBreiteUnten

			set neuD.DetailFormat.AnzDezStellen = posD.FormatAnzDezStellen
			set neuD.DetailFormat.Datum = posD.FormatDatum
			set neuD.DetailFormat.Einheit = posD.FormatEinheit
			set neuD.DetailFormat.TextFallsLeer = posD.FormatTextFallsLeer
			set neuD.DetailFormat.KeineAusgabe = posD.FormatKeineAusgabe
			set neuD.DetailFormat.Totalisieren = posD.FormatTotalisieren
			
			set neuD.DetailFont.Bold = posD.DetailFontBold
			set neuD.DetailFont.Color = posD.DetailFontColor
			set neuD.DetailFont.Italic = posD.DetailFontItalic
			set neuD.DetailFont.Name = posD.DetailFontName
			set neuD.DetailFont.Size = posD.DetailFontSize
			set neuD.DetailFont.Strikeout = posD.DetailFontStrikeout
				
			set neuD.DetailRahmen.AbstandLinks = posD.DetailRahmenAbstandLinks
			set neuD.DetailRahmen.AbstandOben = posD.DetailRahmenAbstandOben
			set neuD.DetailRahmen.AbstandRechts = posD.DetailRahmenAbstandRechts
			set neuD.DetailRahmen.AbstandUnten = posD.DetailRahmenAbstandUnten
			set neuD.DetailRahmen.AktivLinks =posD.DetailRahmenAktivLinks
			set neuD.DetailRahmen.AktivOben = posD.DetailRahmenAktivOben
			set neuD.DetailRahmen.AktivRechts = posD.DetailRahmenAktivRechts
			set neuD.DetailRahmen.AktivUnten = posD.DetailRahmenAktivUnten
			set neuD.DetailRahmen.BreiteLinks = posD.DetailRahmenBreiteLinks
			set neuD.DetailRahmen.BreiteOben = posD.DetailRahmenBreiteOben
			set neuD.DetailRahmen.BreiteRechts = posD.DetailRahmenBreiteRechts
			set neuD.DetailRahmen.BreiteUnten = posD.DetailRahmenBreiteUnten
		
			set kid = ##Class(DBAgrofresh.SD.TblKopf).GetTblKopfOidByCode(rs.Data("Mandant"), rs.Data("KNummer"))
		
			if (kid '= "") {
				set neuD.Tabellenkopf = ##Class(DBAgrofresh.SD.TblKopf).%OpenId(kid)
		
				set sc = neuD.%Save()
			
				if ($$$ISERR(sc)) {
					w "Saveerror SREntry: "_sc,!
				}
			} else {
				w "SREntryKopf nicht gefunden",!
			}
		}
	}
	
	Set strSQL="SELECT ID, Formularkopf->Nummer as KNummer, Formularkopf->Mandant as Mandant FROM DBAgrofresh_SD.FormSRgkEntry"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set posD = ##class(DBAgrofresh.SD.FormSRgkEntry).%OpenId(rs.Data("ID"))
		if (posD '= "") {	
			set neuD = ##class(DBAgrofresh.SD.TblSRgkEntry).%New()
			set neuD.Aktiv = posD.Aktiv
			set neuD.Ausrichtung = posD.Ausrichtung
			set neuD.Breite = posD.Breite
			set neuD.Index = posD.Index
			set neuD.Nummer = posD.Nummer
			set neuD.Text = posD.Text
									
			set neuD.Font.Bold = posD.FontBold
			set neuD.Font.Color = posD.FontColor
			set neuD.Font.Italic = posD.FontItalic
			set neuD.Font.Name = posD.FontName
			set neuD.Font.Size = posD.FontSize
			set neuD.Font.Strikeout = posD.FontStrikeout
				
			set neuD.Rahmen.AbstandLinks = posD.RahmenAbstandLinks
			set neuD.Rahmen.AbstandOben = posD.RahmenAbstandOben
			set neuD.Rahmen.AbstandRechts = posD.RahmenAbstandRechts
			set neuD.Rahmen.AbstandUnten = posD.RahmenAbstandUnten
			set neuD.Rahmen.AktivLinks =posD.RahmenAktivLinks
			set neuD.Rahmen.AktivOben = posD.RahmenAktivOben
			set neuD.Rahmen.AktivRechts = posD.RahmenAktivRechts
			set neuD.Rahmen.AktivUnten = posD.RahmenAktivUnten
			set neuD.Rahmen.BreiteLinks = posD.RahmenBreiteLinks
			set neuD.Rahmen.BreiteOben = posD.RahmenBreiteOben
			set neuD.Rahmen.BreiteRechts = posD.RahmenBreiteRechts
			set neuD.Rahmen.BreiteUnten = posD.RahmenBreiteUnten

			set neuD.Format.AnzDezStellen = posD.FormatAnzDezStellen
			set neuD.Format.Datum = posD.FormatDatum
			set neuD.Format.Einheit = posD.FormatEinheit
			set neuD.Format.TextFallsLeer = posD.FormatTextFallsLeer
			set neuD.Format.KeineAusgabe = posD.FormatKeineAusgabe
			set neuD.Format.Totalisieren = posD.FormatTotalisieren
		
			set kid = ##Class(DBAgrofresh.SD.TblKopf).GetTblKopfOidByCode(rs.Data("Mandant"), rs.Data("KNummer"))
		
			if (kid '= "") {
				set neuD.Tabellenkopf = ##Class(DBAgrofresh.SD.TblKopf).%OpenId(kid)
		
				set sc = neuD.%Save()
			
				if ($$$ISERR(sc)) {
					w "Saveerror SRgkEntry: "_sc,!
				}
			} else {
				w "SRgkEntryKopf nicht gefunden",!
			}
		}
	}
	
		Set strSQL="SELECT ID, Formularkopf->Nummer as KNummer, Formularkopf->Mandant as Mandant FROM DBAgrofresh_SD.FormSRvlEntry"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set posD = ##class(DBAgrofresh.SD.FormSRvlEntry).%OpenId(rs.Data("ID"))
		if (posD '= "") {	
			set neuD = ##class(DBAgrofresh.SD.TblSRvlEntry).%New()
			set neuD.Aktiv = posD.Aktiv
			set neuD.Ausrichtung = posD.Ausrichtung
			set neuD.Breite = posD.Breite
			set neuD.Index = posD.Index
			set neuD.Nummer = posD.Nummer
			set neuD.Text = posD.Text
									
			set neuD.Font.Bold = posD.FontBold
			set neuD.Font.Color = posD.FontColor
			set neuD.Font.Italic = posD.FontItalic
			set neuD.Font.Name = posD.FontName
			set neuD.Font.Size = posD.FontSize
			set neuD.Font.Strikeout = posD.FontStrikeout
				
			set neuD.Rahmen.AbstandLinks = posD.RahmenAbstandLinks
			set neuD.Rahmen.AbstandOben = posD.RahmenAbstandOben
			set neuD.Rahmen.AbstandRechts = posD.RahmenAbstandRechts
			set neuD.Rahmen.AbstandUnten = posD.RahmenAbstandUnten
			set neuD.Rahmen.AktivLinks =posD.RahmenAktivLinks
			set neuD.Rahmen.AktivOben = posD.RahmenAktivOben
			set neuD.Rahmen.AktivRechts = posD.RahmenAktivRechts
			set neuD.Rahmen.AktivUnten = posD.RahmenAktivUnten
			set neuD.Rahmen.BreiteLinks = posD.RahmenBreiteLinks
			set neuD.Rahmen.BreiteOben = posD.RahmenBreiteOben
			set neuD.Rahmen.BreiteRechts = posD.RahmenBreiteRechts
			set neuD.Rahmen.BreiteUnten = posD.RahmenBreiteUnten

			set neuD.Format.AnzDezStellen = posD.FormatAnzDezStellen
			set neuD.Format.Datum = posD.FormatDatum
			set neuD.Format.Einheit = posD.FormatEinheit
			set neuD.Format.TextFallsLeer = posD.FormatTextFallsLeer
			set neuD.Format.KeineAusgabe = posD.FormatKeineAusgabe
			set neuD.Format.Totalisieren = posD.FormatTotalisieren
			
			set neuD.DetailFont.Bold = posD.DetailFontBold
			set neuD.DetailFont.Color = posD.DetailFontColor
			set neuD.DetailFont.Italic = posD.DetailFontItalic
			set neuD.DetailFont.Name = posD.DetailFontName
			set neuD.DetailFont.Size = posD.DetailFontSize
			set neuD.DetailFont.Strikeout = posD.DetailFontStrikeout
				
			set neuD.DetailRahmen.AbstandLinks = posD.DetailRahmenAbstandLinks
			set neuD.DetailRahmen.AbstandOben = posD.DetailRahmenAbstandOben
			set neuD.DetailRahmen.AbstandRechts = posD.DetailRahmenAbstandRechts
			set neuD.DetailRahmen.AbstandUnten = posD.DetailRahmenAbstandUnten
			set neuD.DetailRahmen.AktivLinks =posD.DetailRahmenAktivLinks
			set neuD.DetailRahmen.AktivOben = posD.DetailRahmenAktivOben
			set neuD.DetailRahmen.AktivRechts = posD.DetailRahmenAktivRechts
			set neuD.DetailRahmen.AktivUnten = posD.DetailRahmenAktivUnten
			set neuD.DetailRahmen.BreiteLinks = posD.DetailRahmenBreiteLinks
			set neuD.DetailRahmen.BreiteOben = posD.DetailRahmenBreiteOben
			set neuD.DetailRahmen.BreiteRechts = posD.DetailRahmenBreiteRechts
			set neuD.DetailRahmen.BreiteUnten = posD.DetailRahmenBreiteUnten
		
			set kid = ##Class(DBAgrofresh.SD.TblKopf).GetTblKopfOidByCode(rs.Data("Mandant"), rs.Data("KNummer"))
		
			if (kid '= "") {
				set neuD.Tabellenkopf = ##Class(DBAgrofresh.SD.TblKopf).%OpenId(kid)
		
				set sc = neuD.%Save()
			
				if ($$$ISERR(sc)) {
					w "Saveerror SRvlEntry: "_sc,!
				}
			} else {
				w "SRvlEntryKopf nicht gefunden",!
			}
		}
	}
	
	Set strSQL="SELECT ID FROM DBAgrofresh_SD.FormFuss"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set posF = ##class(DBAgrofresh.SD.FormFuss).%OpenId(rs.Data("ID"))
		if (posF '= "") {	
			set neuF = ##class(DBAgrofresh.SD.TblFuss).%New()
			set neuF.Bezeichnung = posF.Bezeichnung
			
			set neuF.GenFont.Aktiv = posF.GenFontAktiv
			set neuF.GenFont.Bold = posF.GenFontBold
			set neuF.GenFont.Color = posF.GenFontColor
			set neuF.GenFont.Italic = posF.GenFontItalic
			set neuF.GenFont.Name = posF.GenFontName
			set neuF.GenFont.Size = posF.GenFontSize
			set neuF.GenFont.Strikeout = posF.GenFontStrikeout
		
			set neuF.GenRahmen.AbstandLinks = posF.GenRahmenAbstandLinks
			set neuF.GenRahmen.AbstandOben = posF.GenRahmenAbstandOben
			set neuF.GenRahmen.AbstandRechts = posF.GenRahmenAbstandRechts
			set neuF.GenRahmen.AbstandUnten = posF.GenRahmenAbstandUnten
			set neuF.GenRahmen.Aktiv = posF.GenRahmenAktiv
			set neuF.GenRahmen.AktivLinks = posF.GenRahmenAktivLinks
			set neuF.GenRahmen.AktivOben = posF.GenRahmenAktivOben
			set neuF.GenRahmen.AktivRechts = posF.GenRahmenAktivRechts
			set neuF.GenRahmen.AktivUnten = posF.GenRahmenAktivUnten
			set neuF.GenRahmen.BreiteLinks = posF.GenRahmenBreiteLinks
			set neuF.GenRahmen.BreiteOben = posF.GenRahmenBreiteOben
			set neuF.GenRahmen.BreiteRechts = posF.GenRahmenBreiteRechts
			set neuF.GenRahmen.BreiteUnten = posF.GenRahmenBreiteUnten
			
			set neuF.Mandant = posF.Mandant
			set neuF.Nummer = posF.Nummer
		
			set sc = neuF.%Save()
			
			if ($$$ISERR(sc)) {
				w "Saveerror Fuss: "_sc,!
			}

		}
	}
	
	Set strSQL="SELECT ID, Formularfuss->Nummer as KNummer, Formularfuss->Mandant as Mandant FROM DBAgrofresh_SD.FormFussEntry"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set posD = ##class(DBAgrofresh.SD.FormFussEntry).%OpenId(rs.Data("ID"))
		if (posD '= "") {	
			set neuD = ##class(DBAgrofresh.SD.TblFussEntry).%New()
			set neuD.Aktiv = posD.Aktiv
			set neuD.Ausrichtung = posD.Ausrichtung
			set neuD.Breite = posD.Breite
			set neuD.Index = posD.Index
			set neuD.Nummer = posD.Nummer
			set neuD.Text = posD.Text
			set neuD.TotalText = posD.TotalText
									
			set neuD.Font.Bold = posD.FontBold
			set neuD.Font.Color = posD.FontColor
			set neuD.Font.Italic = posD.FontItalic
			set neuD.Font.Name = posD.FontName
			set neuD.Font.Size = posD.FontSize
			set neuD.Font.Strikeout = posD.FontStrikeout
				
			set neuD.Rahmen.AbstandLinks = posD.RahmenAbstandLinks
			set neuD.Rahmen.AbstandOben = posD.RahmenAbstandOben
			set neuD.Rahmen.AbstandRechts = posD.RahmenAbstandRechts
			set neuD.Rahmen.AbstandUnten = posD.RahmenAbstandUnten
			set neuD.Rahmen.AktivLinks =posD.RahmenAktivLinks
			set neuD.Rahmen.AktivOben = posD.RahmenAktivOben
			set neuD.Rahmen.AktivRechts = posD.RahmenAktivRechts
			set neuD.Rahmen.AktivUnten = posD.RahmenAktivUnten
			set neuD.Rahmen.BreiteLinks = posD.RahmenBreiteLinks
			set neuD.Rahmen.BreiteOben = posD.RahmenBreiteOben
			set neuD.Rahmen.BreiteRechts = posD.RahmenBreiteRechts
			set neuD.Rahmen.BreiteUnten = posD.RahmenBreiteUnten
			
			set neuD.DetailFont.Bold = posD.DetailFontBold
			set neuD.DetailFont.Color = posD.DetailFontColor
			set neuD.DetailFont.Italic = posD.DetailFontItalic
			set neuD.DetailFont.Name = posD.DetailFontName
			set neuD.DetailFont.Size = posD.DetailFontSize
			set neuD.DetailFont.Strikeout = posD.DetailFontStrikeout
				
			set neuD.DetailRahmen.AbstandLinks = posD.DetailRahmenAbstandLinks
			set neuD.DetailRahmen.AbstandOben = posD.DetailRahmenAbstandOben
			set neuD.DetailRahmen.AbstandRechts = posD.DetailRahmenAbstandRechts
			set neuD.DetailRahmen.AbstandUnten = posD.DetailRahmenAbstandUnten
			set neuD.DetailRahmen.AktivLinks =posD.DetailRahmenAktivLinks
			set neuD.DetailRahmen.AktivOben = posD.DetailRahmenAktivOben
			set neuD.DetailRahmen.AktivRechts = posD.DetailRahmenAktivRechts
			set neuD.DetailRahmen.AktivUnten = posD.DetailRahmenAktivUnten
			set neuD.DetailRahmen.BreiteLinks = posD.DetailRahmenBreiteLinks
			set neuD.DetailRahmen.BreiteOben = posD.DetailRahmenBreiteOben
			set neuD.DetailRahmen.BreiteRechts = posD.DetailRahmenBreiteRechts
			set neuD.DetailRahmen.BreiteUnten = posD.DetailRahmenBreiteUnten
		
			set neuD.TotalFont.Bold = posD.TotalFontBold
			set neuD.TotalFont.Color = posD.TotalFontColor
			set neuD.TotalFont.Italic = posD.TotalFontItalic
			set neuD.TotalFont.Name = posD.TotalFontName
			set neuD.TotalFont.Size = posD.TotalFontSize
			set neuD.TotalFont.Strikeout = posD.TotalFontStrikeout
				
			set neuD.TotalRahmen.AbstandLinks = posD.TotalRahmenAbstandLinks
			set neuD.TotalRahmen.AbstandOben = posD.TotalRahmenAbstandOben
			set neuD.TotalRahmen.AbstandRechts = posD.TotalRahmenAbstandRechts
			set neuD.TotalRahmen.AbstandUnten = posD.TotalRahmenAbstandUnten
			set neuD.TotalRahmen.AktivLinks =posD.TotalRahmenAktivLinks
			set neuD.TotalRahmen.AktivOben = posD.TotalRahmenAktivOben
			set neuD.TotalRahmen.AktivRechts = posD.TotalRahmenAktivRechts
			set neuD.TotalRahmen.AktivUnten = posD.TotalRahmenAktivUnten
			set neuD.TotalRahmen.BreiteLinks = posD.TotalRahmenBreiteLinks
			set neuD.TotalRahmen.BreiteOben = posD.TotalRahmenBreiteOben
			set neuD.TotalRahmen.BreiteRechts = posD.TotalRahmenBreiteRechts
			set neuD.TotalRahmen.BreiteUnten = posD.TotalRahmenBreiteUnten
			
			set kid = ##Class(DBAgrofresh.SD.TblFuss).GetTblFussOidByCode(rs.Data("Mandant"), rs.Data("KNummer"))
		
			if (kid '= "") {
				set neuD.Tabellenfuss = ##Class(DBAgrofresh.SD.TblFuss).%OpenId(kid)
		
				set sc = neuD.%Save()
			
				if ($$$ISERR(sc)) {
					w "Saveerror FussEntry: "_sc,!
				}
			} else {
				w "FussEntryKopf nicht gefunden",!
			}
		}
	}
	
	Set strSQL="SELECT ID, Formularfuss->Nummer as KNummer, Formularfuss->Mandant as Mandant FROM DBAgrofresh_SD.FormFussSkontoE"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set posD = ##class(DBAgrofresh.SD.FormFussSkontoE).%OpenId(rs.Data("ID"))
		if (posD '= "") {	
			set neuD = ##class(DBAgrofresh.SD.TblFussSkntE).%New()
			set neuD.Aktiv = posD.Aktiv
			set neuD.Ausrichtung = posD.Ausrichtung
			set neuD.Breite = posD.Breite
			set neuD.Index = posD.Index
			set neuD.Nummer = posD.Nummer
			set neuD.Text = posD.Text
									
			set neuD.Font.Bold = posD.FontBold
			set neuD.Font.Color = posD.FontColor
			set neuD.Font.Italic = posD.FontItalic
			set neuD.Font.Name = posD.FontName
			set neuD.Font.Size = posD.FontSize
			set neuD.Font.Strikeout = posD.FontStrikeout
				
			set neuD.Rahmen.AbstandLinks = posD.RahmenAbstandLinks
			set neuD.Rahmen.AbstandOben = posD.RahmenAbstandOben
			set neuD.Rahmen.AbstandRechts = posD.RahmenAbstandRechts
			set neuD.Rahmen.AbstandUnten = posD.RahmenAbstandUnten
			set neuD.Rahmen.AktivLinks =posD.RahmenAktivLinks
			set neuD.Rahmen.AktivOben = posD.RahmenAktivOben
			set neuD.Rahmen.AktivRechts = posD.RahmenAktivRechts
			set neuD.Rahmen.AktivUnten = posD.RahmenAktivUnten
			set neuD.Rahmen.BreiteLinks = posD.RahmenBreiteLinks
			set neuD.Rahmen.BreiteOben = posD.RahmenBreiteOben
			set neuD.Rahmen.BreiteRechts = posD.RahmenBreiteRechts
			set neuD.Rahmen.BreiteUnten = posD.RahmenBreiteUnten
			
			set kid = ##Class(DBAgrofresh.SD.TblFuss).GetTblFussOidByCode(rs.Data("Mandant"), rs.Data("KNummer"))
		
			if (kid '= "") {
				set neuD.Tabellenfuss = ##Class(DBAgrofresh.SD.TblFuss).%OpenId(kid)
		
				set sc = neuD.%Save()
			
				if ($$$ISERR(sc)) {
					w "Saveerror FussSkontoEntry: "_sc,!
				}
			} else {
				w "FussSkontoEntryKopf nicht gefunden",!
			}
		}
	}
]]></Implementation>
</Method>

<Method name="TransferFormDataAgrofreshEK">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
	
	&sql(Delete from DBAgrofreshEK_SD.TblKopf)
	&sql(Delete from DBAgrofreshEK_SD.TblKopfE)
	&sql(Delete from DBAgrofreshEK_SD.TblDataE)
	&sql(Delete from DBAgrofreshEK_SD.TblFuss)
	&sql(Delete from DBAgrofreshEK_SD.TblFussE)
	&sql(Delete from DBAgrofreshEK_SD.TblFussSktE)
	
	Set strSQL="SELECT ID FROM DBAgrofreshEK_SD.FormKopf"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set pos = ##class(DBAgrofreshEK.SD.FormKopf).%OpenId(rs.Data("ID"))
		if (pos '= "") {	
			set neu = ##class(DBAgrofreshEK.SD.TblKopf).%New()
			set neu.Bezeichnung = pos.Bezeichnung	
			set neu.Mandant = pos.Mandant
			set neu.Nummer = pos.Nummer
		
			set sc = neu.%Save()
			
			if ($$$ISERR(sc)) {
				w "Saveerror Kopf: "_sc,!
			}

		}
	}
		
	Set strSQL="SELECT ID, Formularkopf->Nummer as KNummer, Formularkopf->Mandant as Mandant FROM DBAgrofreshEK_SD.FormKopfEntry"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set posE = ##class(DBAgrofreshEK.SD.FormKopfEntry).%OpenId(rs.Data("ID"))
		if (posE '= "") {	
			set neuE = ##class(DBAgrofreshEK.SD.TblKopfE).%New()
			set neuE.Aktiv = posE.Aktiv
			set neuE.Ausrichtung = posE.Ausrichtung
			set neuE.Breite = posE.Breite
			set neuE.Index = posE.Index
			set neuE.Nummer = posE.Nummer
			set neuE.Text = posE.Text
									
			set neuE.Font.Bold = posE.FontBold
			set neuE.Font.Color = posE.FontColor
			set neuE.FontColor = posE.FontColor
			set neuE.Font.Italic = posE.FontItalic
			set neuE.Font.Name = posE.FontName
			set neuE.Font.Size = posE.FontSize
			set neuE.Font.Strikeout = posE.FontStrikeout
				
			set neuE.Rahmen.AbstandLinks = posE.RahmenAbstandLinks
			set neuE.Rahmen.AbstandOben = posE.RahmenAbstandOben
			set neuE.Rahmen.AbstandRechts = posE.RahmenAbstandRechts
			set neuE.Rahmen.AbstandUnten = posE.RahmenAbstandUnten
			set neuE.Rahmen.AktivLinks =posE.RahmenAktivLinks
			set neuE.Rahmen.AktivOben = posE.RahmenAktivOben
			set neuE.Rahmen.AktivRechts = posE.RahmenAktivRechts
			set neuE.Rahmen.AktivUnten = posE.RahmenAktivUnten
			set neuE.Rahmen.BreiteLinks = posE.RahmenBreiteLinks
			set neuE.Rahmen.BreiteOben = posE.RahmenBreiteOben
			set neuE.Rahmen.BreiteRechts = posE.RahmenBreiteRechts
			set neuE.Rahmen.BreiteUnten = posE.RahmenBreiteUnten
		
			set kid = ##Class(DBAgrofreshEK.SD.TblKopf).GetTblKopfOidByCode(rs.Data("Mandant"), rs.Data("KNummer"))
		
			if (kid '= "") {
				set neuE.Tabellenkopf = ##Class(DBAgrofreshEK.SD.TblKopf).%OpenId(kid)
		
				set sc = neuE.%Save()
			
				if ($$$ISERR(sc)) {
					w "Saveerror KopfEntry: "_sc,!
				}
			} else {
				w "KopfEntry nicht gefunden",!
			}

		}
	}
	
	Set strSQL="SELECT ID, Formularkopf->Nummer as KNummer, Formularkopf->Mandant as Mandant FROM DBAgrofreshEK_SD.FormDataEntry"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set posD = ##class(DBAgrofreshEK.SD.FormDataEntry).%OpenId(rs.Data("ID"))
		if (posD '= "") {	
			set neuD = ##class(DBAgrofreshEK.SD.TblDataE).%New()
			set neuD.Aktiv = posD.Aktiv
			set neuD.Ausrichtung = posD.Ausrichtung
			set neuD.Breite = posD.Breite
			set neuD.Index = posD.Index
			set neuD.Nummer = posD.Nummer
									
			set neuD.Font.Bold = posD.FontBold
			set neuD.Font.Color = posD.FontColor
			set neuD.Font.Italic = posD.FontItalic
			set neuD.Font.Name = posD.FontName
			set neuD.Font.Size = posD.FontSize
			set neuD.Font.Strikeout = posD.FontStrikeout
				
			set neuD.Rahmen.AbstandLinks = posD.RahmenAbstandLinks
			set neuD.Rahmen.AbstandOben = posD.RahmenAbstandOben
			set neuD.Rahmen.AbstandRechts = posD.RahmenAbstandRechts
			set neuD.Rahmen.AbstandUnten = posD.RahmenAbstandUnten
			set neuD.Rahmen.AktivLinks =posD.RahmenAktivLinks
			set neuD.Rahmen.AktivOben = posD.RahmenAktivOben
			set neuD.Rahmen.AktivRechts = posD.RahmenAktivRechts
			set neuD.Rahmen.AktivUnten = posD.RahmenAktivUnten
			set neuD.Rahmen.BreiteLinks = posD.RahmenBreiteLinks
			set neuD.Rahmen.BreiteOben = posD.RahmenBreiteOben
			set neuD.Rahmen.BreiteRechts = posD.RahmenBreiteRechts
			set neuD.Rahmen.BreiteUnten = posD.RahmenBreiteUnten

			set neuD.Format.AnzDezStellen = posD.FormatAnzDezStellen
			set neuD.Format.Datum = posD.FormatDatum
			set neuD.Format.Einheit = posD.FormatEinheit
			set neuD.Format.TextFallsLeer = posD.FormatTextFallsLeer
			set neuD.Format.KeineAusgabe = posD.FormatKeineAusgabe
			set neuD.Format.Totalisieren = posD.FormatTotalisieren
		
			set kid = ##Class(DBAgrofreshEK.SD.TblKopf).GetTblKopfOidByCode(rs.Data("Mandant"), rs.Data("KNummer"))
		
			if (kid '= "") {
				set neuD.Tabellenkopf = ##Class(DBAgrofreshEK.SD.TblKopf).%OpenId(kid)
		
				set sc = neuD.%Save()
			
				if ($$$ISERR(sc)) {
					w "Saveerror DateEntry: "_sc,!
				}
			} else {
				w "DateEntry nicht gefunden",!
			}

		}
		
	}
	
	Set strSQL="SELECT ID FROM DBAgrofreshEK_SD.FormFuss"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set posF = ##class(DBAgrofreshEK.SD.FormFuss).%OpenId(rs.Data("ID"))
		if (posF '= "") {	
			set neuF = ##class(DBAgrofreshEK.SD.TblFuss).%New()
			set neuF.Bezeichnung = posF.Bezeichnung	
			set neuF.Mandant = posF.Mandant
			set neuF.Nummer = posF.Nummer
		
			set sc = neuF.%Save()
			
			if ($$$ISERR(sc)) {
				w "Saveerror Fuss: "_sc,!
			}

		}
	}
	
	Set strSQL="SELECT ID, Formularfuss->Nummer as KNummer, Formularfuss->Mandant as Mandant FROM DBAgrofreshEK_SD.FormFussEntry"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set posD = ##class(DBAgrofreshEK.SD.FormFussEntry).%OpenId(rs.Data("ID"))
		if (posD '= "") {	
			set neuD = ##class(DBAgrofreshEK.SD.TblFussE).%New()
			set neuD.Aktiv = posD.Aktiv
			set neuD.Ausrichtung = posD.Ausrichtung
			set neuD.Breite = posD.Breite
			set neuD.Index = posD.Index
			set neuD.Nummer = posD.Nummer
			set neuD.Text = posD.Text
			set neuD.TotalText = posD.TotalText
									
			set neuD.Font.Bold = posD.FontBold
			set neuD.Font.Color = posD.FontColor
			set neuD.Font.Italic = posD.FontItalic
			set neuD.Font.Name = posD.FontName
			set neuD.Font.Size = posD.FontSize
			set neuD.Font.Strikeout = posD.FontStrikeout
				
			set neuD.Rahmen.AbstandLinks = posD.RahmenAbstandLinks
			set neuD.Rahmen.AbstandOben = posD.RahmenAbstandOben
			set neuD.Rahmen.AbstandRechts = posD.RahmenAbstandRechts
			set neuD.Rahmen.AbstandUnten = posD.RahmenAbstandUnten
			set neuD.Rahmen.AktivLinks =posD.RahmenAktivLinks
			set neuD.Rahmen.AktivOben = posD.RahmenAktivOben
			set neuD.Rahmen.AktivRechts = posD.RahmenAktivRechts
			set neuD.Rahmen.AktivUnten = posD.RahmenAktivUnten
			set neuD.Rahmen.BreiteLinks = posD.RahmenBreiteLinks
			set neuD.Rahmen.BreiteOben = posD.RahmenBreiteOben
			set neuD.Rahmen.BreiteRechts = posD.RahmenBreiteRechts
			set neuD.Rahmen.BreiteUnten = posD.RahmenBreiteUnten
			
			set neuD.DetailFont.Bold = posD.DetailFontBold
			set neuD.DetailFont.Color = posD.DetailFontColor
			set neuD.DetailFont.Italic = posD.DetailFontItalic
			set neuD.DetailFont.Name = posD.DetailFontName
			set neuD.DetailFont.Size = posD.DetailFontSize
			set neuD.DetailFont.Strikeout = posD.DetailFontStrikeout
				
			set neuD.DetailRahmen.AbstandLinks = posD.DetailRahmenAbstandLinks
			set neuD.DetailRahmen.AbstandOben = posD.DetailRahmenAbstandOben
			set neuD.DetailRahmen.AbstandRechts = posD.DetailRahmenAbstandRechts
			set neuD.DetailRahmen.AbstandUnten = posD.DetailRahmenAbstandUnten
			set neuD.DetailRahmen.AktivLinks =posD.DetailRahmenAktivLinks
			set neuD.DetailRahmen.AktivOben = posD.DetailRahmenAktivOben
			set neuD.DetailRahmen.AktivRechts = posD.DetailRahmenAktivRechts
			set neuD.DetailRahmen.AktivUnten = posD.DetailRahmenAktivUnten
			set neuD.DetailRahmen.BreiteLinks = posD.DetailRahmenBreiteLinks
			set neuD.DetailRahmen.BreiteOben = posD.DetailRahmenBreiteOben
			set neuD.DetailRahmen.BreiteRechts = posD.DetailRahmenBreiteRechts
			set neuD.DetailRahmen.BreiteUnten = posD.DetailRahmenBreiteUnten
		
			set neuD.TotalFont.Bold = posD.TotalFontBold
			set neuD.TotalFont.Color = posD.TotalFontColor
			set neuD.TotalFont.Italic = posD.TotalFontItalic
			set neuD.TotalFont.Name = posD.TotalFontName
			set neuD.TotalFont.Size = posD.TotalFontSize
			set neuD.TotalFont.Strikeout = posD.TotalFontStrikeout
				
			set neuD.TotalRahmen.AbstandLinks = posD.TotalRahmenAbstandLinks
			set neuD.TotalRahmen.AbstandOben = posD.TotalRahmenAbstandOben
			set neuD.TotalRahmen.AbstandRechts = posD.TotalRahmenAbstandRechts
			set neuD.TotalRahmen.AbstandUnten = posD.TotalRahmenAbstandUnten
			set neuD.TotalRahmen.AktivLinks =posD.TotalRahmenAktivLinks
			set neuD.TotalRahmen.AktivOben = posD.TotalRahmenAktivOben
			set neuD.TotalRahmen.AktivRechts = posD.TotalRahmenAktivRechts
			set neuD.TotalRahmen.AktivUnten = posD.TotalRahmenAktivUnten
			set neuD.TotalRahmen.BreiteLinks = posD.TotalRahmenBreiteLinks
			set neuD.TotalRahmen.BreiteOben = posD.TotalRahmenBreiteOben
			set neuD.TotalRahmen.BreiteRechts = posD.TotalRahmenBreiteRechts
			set neuD.TotalRahmen.BreiteUnten = posD.TotalRahmenBreiteUnten
			
			set kid = ##Class(DBAgrofreshEK.SD.TblFuss).GetTblFussOidByCode(rs.Data("Mandant"), rs.Data("KNummer"))
		
			if (kid '= "") {
				set neuD.Tabellenfuss = ##Class(DBAgrofreshEK.SD.TblFuss).%OpenId(kid)
		
				set sc = neuD.%Save()
			
				if ($$$ISERR(sc)) {
					w "Saveerror FussEntry: "_sc,!
				}
			} else {
				w "FussEntryKopf nicht gefunden",!
			}
		}
	}
	
	Set strSQL="SELECT ID, Formularfuss->Nummer as KNummer, Formularfuss->Mandant as Mandant FROM DBAgrofreshEK_SD.FormFussSkontoE"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set posD = ##class(DBAgrofreshEK.SD.FormFussSkontoE).%OpenId(rs.Data("ID"))
		if (posD '= "") {	
			set neuD = ##class(DBAgrofreshEK.SD.TblFussSktE).%New()
			set neuD.Aktiv = posD.Aktiv
			set neuD.Ausrichtung = posD.Ausrichtung
			set neuD.Breite = posD.Breite
			set neuD.Index = posD.Index
			set neuD.Nummer = posD.Nummer
			set neuD.Text = posD.Text
									
			set neuD.Font.Bold = posD.FontBold
			set neuD.Font.Color = posD.FontColor
			set neuD.Font.Italic = posD.FontItalic
			set neuD.Font.Name = posD.FontName
			set neuD.Font.Size = posD.FontSize
			set neuD.Font.Strikeout = posD.FontStrikeout
				
			set neuD.Rahmen.AbstandLinks = posD.RahmenAbstandLinks
			set neuD.Rahmen.AbstandOben = posD.RahmenAbstandOben
			set neuD.Rahmen.AbstandRechts = posD.RahmenAbstandRechts
			set neuD.Rahmen.AbstandUnten = posD.RahmenAbstandUnten
			set neuD.Rahmen.AktivLinks =posD.RahmenAktivLinks
			set neuD.Rahmen.AktivOben = posD.RahmenAktivOben
			set neuD.Rahmen.AktivRechts = posD.RahmenAktivRechts
			set neuD.Rahmen.AktivUnten = posD.RahmenAktivUnten
			set neuD.Rahmen.BreiteLinks = posD.RahmenBreiteLinks
			set neuD.Rahmen.BreiteOben = posD.RahmenBreiteOben
			set neuD.Rahmen.BreiteRechts = posD.RahmenBreiteRechts
			set neuD.Rahmen.BreiteUnten = posD.RahmenBreiteUnten
			
			set kid = ##Class(DBAgrofreshEK.SD.TblFuss).GetTblFussOidByCode(rs.Data("Mandant"), rs.Data("KNummer"))
		
			if (kid '= "") {
				set neuD.Tabellenfuss = ##Class(DBAgrofreshEK.SD.TblFuss).%OpenId(kid)
		
				set sc = neuD.%Save()
			
				if ($$$ISERR(sc)) {
					w "Saveerror FussSkontoEntry: "_sc,!
				}
			} else {
				w "FussSkontoEntryKopf nicht gefunden",!
			}
		}
	}
]]></Implementation>
</Method>

<Method name="TransferFormDataFakturierung">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
	
	&sql(Delete from DBFakturierung_SD.TblKopf)
	&sql(Delete from DBFakturierung_SD.TblKopfE)
	&sql(Delete from DBFakturierung_SD.TblDataE)
	&sql(Delete from DBFakturierung_SD.TblSREntry)
	&sql(Delete from DBFakturierung_SD.TblSRgkE)
	&sql(Delete from DBFakturierung_SD.TblFuss)
	&sql(Delete from DBFakturierung_SD.TblFussE)
	&sql(Delete from DBFakturierung_SD.TblFussSktE)
	
	Set strSQL="SELECT ID FROM DBFakturierung_SD.FormKopf"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set pos = ##class(DBFakturierung.SD.FormKopf).%OpenId(rs.Data("ID"))
		if (pos '= "") {	
			set neu = ##class(DBFakturierung.SD.TblKopf).%New()
			set neu.Bezeichnung = pos.Bezeichnung
			
			set neu.DataGenFont.Aktiv = pos.DataGenFontAktiv
			set neu.DataGenFont.Bold = pos.DataGenFontBold
			set neu.DataGenFont.Color = pos.DataGenFontColor
			set neu.DataGenFont.Italic = pos.DataGenFontItalic
			set neu.DataGenFont.Name = pos.DataGenFontName
			set neu.DataGenFont.Size = pos.DataGenFontSize
			set neu.DataGenFont.Strikeout = pos.DataGenFontStrikeout
			
			set neu.DataGenRahmen.AbstandLinks = pos.DataGenRahmenAbstandLinks
			set neu.DataGenRahmen.AbstandOben = pos.DataGenRahmenAbstandOben
			set neu.DataGenRahmen.AbstandRechts = pos.DataGenRahmenAbstandRechts
			set neu.DataGenRahmen.AbstandUnten = pos.DataGenRahmenAbstandUnten
			set neu.DataGenRahmen.Aktiv = pos.DataGenRahmenAktiv
			set neu.DataGenRahmen.AktivLinks = pos.DataGenRahmenAktivLinks
			set neu.DataGenRahmen.AktivOben = pos.DataGenRahmenAktivOben
			set neu.DataGenRahmen.AktivRechts = pos.DataGenRahmenAktivRechts
			set neu.DataGenRahmen.AktivUnten = pos.DataGenRahmenAktivUnten
			set neu.DataGenRahmen.BreiteLinks = pos.DataGenRahmenBreiteLinks
			set neu.DataGenRahmen.BreiteOben = pos.DataGenRahmenBreiteOben
			set neu.DataGenRahmen.BreiteRechts = pos.DataGenRahmenBreiteRechts
			set neu.DataGenRahmen.BreiteUnten = pos.DataGenRahmenBreiteUnten
			
			set neu.GenFont.Aktiv = pos.GenFontAktiv
			set neu.GenFont.Bold = pos.GenFontBold
			set neu.GenFont.Color = pos.GenFontColor
			set neu.GenFont.Italic = pos.GenFontItalic
			set neu.GenFont.Name = pos.GenFontName
			set neu.GenFont.Size = pos.GenFontSize
			set neu.GenFont.Strikeout = pos.GenFontStrikeout
		
			set neu.GenRahmen.AbstandLinks = pos.GenRahmenAbstandLinks
			set neu.GenRahmen.AbstandOben = pos.GenRahmenAbstandOben
			set neu.GenRahmen.AbstandRechts = pos.GenRahmenAbstandRechts
			set neu.GenRahmen.AbstandUnten = pos.GenRahmenAbstandUnten
			set neu.GenRahmen.Aktiv = pos.GenRahmenAktiv
			set neu.GenRahmen.AktivLinks = pos.GenRahmenAktivLinks
			set neu.GenRahmen.AktivOben = pos.GenRahmenAktivOben
			set neu.GenRahmen.AktivRechts = pos.GenRahmenAktivRechts
			set neu.GenRahmen.AktivUnten = pos.GenRahmenAktivUnten
			set neu.GenRahmen.BreiteLinks = pos.GenRahmenBreiteLinks
			set neu.GenRahmen.BreiteOben = pos.GenRahmenBreiteOben
			set neu.GenRahmen.BreiteRechts = pos.GenRahmenBreiteRechts
			set neu.GenRahmen.BreiteUnten = pos.GenRahmenBreiteUnten
			
			set neu.Mandant = pos.Mandant
			set neu.Nummer = pos.Nummer
			
			set neu.SrGenFont.Aktiv = pos.SrGenFontAktiv
			set neu.SrGenFont.Bold = pos.SrGenFontBold
			set neu.SrGenFont.Color = pos.SrGenFontColor
			set neu.SrGenFont.Italic = pos.SrGenFontItalic
			set neu.SrGenFont.Name = pos.SrGenFontName
			set neu.SrGenFont.Size = pos.SrGenFontSize
			set neu.SrGenFont.Strikeout = pos.SrGenFontStrikeout
			
			set neu.SrGenRahmen.AbstandLinks = pos.SrGenRahmenAbstandLinks
			set neu.SrGenRahmen.AbstandOben = pos.SrGenRahmenAbstandOben
			set neu.SrGenRahmen.AbstandRechts = pos.SrGenRahmenAbstandRechts
			set neu.SrGenRahmen.AbstandUnten = pos.SrGenRahmenAbstandUnten
			set neu.SrGenRahmen.Aktiv = pos.SrGenRahmenAktiv
			set neu.SrGenRahmen.AktivLinks = pos.SrGenRahmenAktivLinks
			set neu.SrGenRahmen.AktivOben = pos.SrGenRahmenAktivOben
			set neu.SrGenRahmen.AktivRechts = pos.SrGenRahmenAktivRechts
			set neu.SrGenRahmen.AktivUnten = pos.SrGenRahmenAktivUnten
			set neu.SrGenRahmen.BreiteLinks = pos.SrGenRahmenBreiteLinks
			set neu.SrGenRahmen.BreiteOben = pos.SrGenRahmenBreiteOben
			set neu.SrGenRahmen.BreiteRechts = pos.SrGenRahmenBreiteRechts
			set neu.SrGenRahmen.BreiteUnten = pos.SrGenRahmenBreiteUnten
			
			set neu.SrKopfGenFont.Aktiv = pos.SrKopfGenFontAktiv
			set neu.SrKopfGenFont.Bold = pos.SrKopfGenFontBold
			set neu.SrKopfGenFont.Color = pos.SrKopfGenFontColor
			set neu.SrKopfGenFont.Italic = pos.SrKopfGenFontItalic
			set neu.SrKopfGenFont.Name = pos.SrKopfGenFontName
			set neu.SrKopfGenFont.Size = pos.SrKopfGenFontSize
			set neu.SrKopfGenFont.Strikeout = pos.SrKopfGenFontStrikeout
			
			set neu.SrKopfGenRahmen.AbstandLinks = pos.SrKopfGenRahmenAbstandLinks
			set neu.SrKopfGenRahmen.AbstandOben = pos.SrKopfGenRahmenAbstandOben
			set neu.SrKopfGenRahmen.AbstandRechts = pos.SrKopfGenRahmenAbstandRechts
			set neu.SrKopfGenRahmen.AbstandUnten = pos.SrKopfGenRahmenAbstandUnten
			set neu.SrKopfGenRahmen.Aktiv = pos.SrKopfGenRahmenAktiv
			set neu.SrKopfGenRahmen.AktivLinks = pos.SrKopfGenRahmenAktivLinks
			set neu.SrKopfGenRahmen.AktivOben = pos.SrKopfGenRahmenAktivOben
			set neu.SrKopfGenRahmen.AktivRechts = pos.SrKopfGenRahmenAktivRechts
			set neu.SrKopfGenRahmen.AktivUnten = pos.SrKopfGenRahmenAktivUnten
			set neu.SrKopfGenRahmen.BreiteLinks = pos.SrKopfGenRahmenBreiteLinks
			set neu.SrKopfGenRahmen.BreiteOben = pos.SrKopfGenRahmenBreiteOben
			set neu.SrKopfGenRahmen.BreiteRechts = pos.SrKopfGenRahmenBreiteRechts
			set neu.SrKopfGenRahmen.BreiteUnten = pos.SrKopfGenRahmenBreiteUnten
		
			set sc = neu.%Save()
			
			if ($$$ISERR(sc)) {
				w "Saveerror Kopf: "_sc,!
			}

		}
	}
		
	Set strSQL="SELECT ID, Formularkopf->Nummer as KNummer, Formularkopf->Mandant as Mandant FROM DBFakturierung_SD.FormKopfEntry"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set posE = ##class(DBFakturierung.SD.FormKopfEntry).%OpenId(rs.Data("ID"))
		if (posE '= "") {	
			set neuE = ##class(DBFakturierung.SD.TblKopfE).%New()
			set neuE.Aktiv = posE.Aktiv
			set neuE.Ausrichtung = posE.Ausrichtung
			set neuE.Breite = posE.Breite
			set neuE.Index = posE.Index
			set neuE.Nummer = posE.Nummer
			set neuE.Text = posE.Text
									
			set neuE.Font.Bold = posE.FontBold
			set neuE.Font.Color = posE.FontColor
			set neuE.FontColor = posE.FontColor
			set neuE.Font.Italic = posE.FontItalic
			set neuE.Font.Name = posE.FontName
			set neuE.Font.Size = posE.FontSize
			set neuE.Font.Strikeout = posE.FontStrikeout
				
			set neuE.Rahmen.AbstandLinks = posE.RahmenAbstandLinks
			set neuE.Rahmen.AbstandOben = posE.RahmenAbstandOben
			set neuE.Rahmen.AbstandRechts = posE.RahmenAbstandRechts
			set neuE.Rahmen.AbstandUnten = posE.RahmenAbstandUnten
			set neuE.Rahmen.AktivLinks =posE.RahmenAktivLinks
			set neuE.Rahmen.AktivOben = posE.RahmenAktivOben
			set neuE.Rahmen.AktivRechts = posE.RahmenAktivRechts
			set neuE.Rahmen.AktivUnten = posE.RahmenAktivUnten
			set neuE.Rahmen.BreiteLinks = posE.RahmenBreiteLinks
			set neuE.Rahmen.BreiteOben = posE.RahmenBreiteOben
			set neuE.Rahmen.BreiteRechts = posE.RahmenBreiteRechts
			set neuE.Rahmen.BreiteUnten = posE.RahmenBreiteUnten
		
			set kid = ##Class(DBFakturierung.SD.TblKopf).GetTblKopfOidByCode(rs.Data("Mandant"), rs.Data("KNummer"))
		
			if (kid '= "") {
				set neuE.Tabellenkopf = ##Class(DBFakturierung.SD.TblKopf).%OpenId(kid)
		
				set sc = neuE.%Save()
			
				if ($$$ISERR(sc)) {
					w "Saveerror KopfEntry: "_sc,!
				}
			} else {
				w "KopfEntry nicht gefunden",!
			}

		}
	}
	
	Set strSQL="SELECT ID, Formularkopf->Nummer as KNummer, Formularkopf->Mandant as Mandant FROM DBFakturierung_SD.FormDataEntry"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set posD = ##class(DBFakturierung.SD.FormDataEntry).%OpenId(rs.Data("ID"))
		if (posD '= "") {	
			set neuD = ##class(DBFakturierung.SD.TblDataE).%New()
			set neuD.Aktiv = posD.Aktiv
			set neuD.Ausrichtung = posD.Ausrichtung
			set neuD.Breite = posD.Breite
			set neuD.Index = posD.Index
			set neuD.Nummer = posD.Nummer
									
			set neuD.Font.Bold = posD.FontBold
			set neuD.Font.Color = posD.FontColor
			set neuD.Font.Italic = posD.FontItalic
			set neuD.Font.Name = posD.FontName
			set neuD.Font.Size = posD.FontSize
			set neuD.Font.Strikeout = posD.FontStrikeout
				
			set neuD.Rahmen.AbstandLinks = posD.RahmenAbstandLinks
			set neuD.Rahmen.AbstandOben = posD.RahmenAbstandOben
			set neuD.Rahmen.AbstandRechts = posD.RahmenAbstandRechts
			set neuD.Rahmen.AbstandUnten = posD.RahmenAbstandUnten
			set neuD.Rahmen.AktivLinks =posD.RahmenAktivLinks
			set neuD.Rahmen.AktivOben = posD.RahmenAktivOben
			set neuD.Rahmen.AktivRechts = posD.RahmenAktivRechts
			set neuD.Rahmen.AktivUnten = posD.RahmenAktivUnten
			set neuD.Rahmen.BreiteLinks = posD.RahmenBreiteLinks
			set neuD.Rahmen.BreiteOben = posD.RahmenBreiteOben
			set neuD.Rahmen.BreiteRechts = posD.RahmenBreiteRechts
			set neuD.Rahmen.BreiteUnten = posD.RahmenBreiteUnten

			set neuD.Format.AnzDezStellen = posD.FormatAnzDezStellen
			set neuD.Format.Datum = posD.FormatDatum
			set neuD.Format.Einheit = posD.FormatEinheit
			set neuD.Format.TextFallsLeer = posD.FormatTextFallsLeer
			set neuD.Format.KeineAusgabe = posD.FormatKeineAusgabe
			set neuD.Format.Totalisieren = posD.FormatTotalisieren
		
			set kid = ##Class(DBFakturierung.SD.TblKopf).GetTblKopfOidByCode(rs.Data("Mandant"), rs.Data("KNummer"))
		
			if (kid '= "") {
				set neuD.Tabellenkopf = ##Class(DBFakturierung.SD.TblKopf).%OpenId(kid)
		
				set sc = neuD.%Save()
			
				if ($$$ISERR(sc)) {
					w "Saveerror DateEntry: "_sc,!
				}
			} else {
				w "DateEntry nicht gefunden",!
			}

		}
		
	}
	
	Set strSQL="SELECT ID, Formularkopf->Nummer as KNummer, Formularkopf->Mandant as Mandant FROM DBFakturierung_SD.FormSREntry"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set posD = ##class(DBFakturierung.SD.FormSREntry).%OpenId(rs.Data("ID"))
		if (posD '= "") {	
			set neuD = ##class(DBFakturierung.SD.TblSREntry).%New()
			set neuD.Aktiv = posD.Aktiv
			set neuD.Ausrichtung = posD.Ausrichtung
			set neuD.Breite = posD.Breite
			set neuD.Index = posD.Index
			set neuD.Nummer = posD.Nummer
			set neuD.Text = posD.Text
									
			set neuD.Font.Bold = posD.FontBold
			set neuD.Font.Color = posD.FontColor
			set neuD.Font.Italic = posD.FontItalic
			set neuD.Font.Name = posD.FontName
			set neuD.Font.Size = posD.FontSize
			set neuD.Font.Strikeout = posD.FontStrikeout
				
			set neuD.Rahmen.AbstandLinks = posD.RahmenAbstandLinks
			set neuD.Rahmen.AbstandOben = posD.RahmenAbstandOben
			set neuD.Rahmen.AbstandRechts = posD.RahmenAbstandRechts
			set neuD.Rahmen.AbstandUnten = posD.RahmenAbstandUnten
			set neuD.Rahmen.AktivLinks =posD.RahmenAktivLinks
			set neuD.Rahmen.AktivOben = posD.RahmenAktivOben
			set neuD.Rahmen.AktivRechts = posD.RahmenAktivRechts
			set neuD.Rahmen.AktivUnten = posD.RahmenAktivUnten
			set neuD.Rahmen.BreiteLinks = posD.RahmenBreiteLinks
			set neuD.Rahmen.BreiteOben = posD.RahmenBreiteOben
			set neuD.Rahmen.BreiteRechts = posD.RahmenBreiteRechts
			set neuD.Rahmen.BreiteUnten = posD.RahmenBreiteUnten

			set neuD.Format.AnzDezStellen = posD.FormatAnzDezStellen
			set neuD.Format.Datum = posD.FormatDatum
			set neuD.Format.Einheit = posD.FormatEinheit
			set neuD.Format.TextFallsLeer = posD.FormatTextFallsLeer
			set neuD.Format.KeineAusgabe = posD.FormatKeineAusgabe
			set neuD.Format.Totalisieren = posD.FormatTotalisieren
			
			set neuD.DetailFont.Bold = posD.DetailFontBold
			set neuD.DetailFont.Color = posD.DetailFontColor
			set neuD.DetailFont.Italic = posD.DetailFontItalic
			set neuD.DetailFont.Name = posD.DetailFontName
			set neuD.DetailFont.Size = posD.DetailFontSize
			set neuD.DetailFont.Strikeout = posD.DetailFontStrikeout
				
			set neuD.DetailRahmen.AbstandLinks = posD.DetailRahmenAbstandLinks
			set neuD.DetailRahmen.AbstandOben = posD.DetailRahmenAbstandOben
			set neuD.DetailRahmen.AbstandRechts = posD.DetailRahmenAbstandRechts
			set neuD.DetailRahmen.AbstandUnten = posD.DetailRahmenAbstandUnten
			set neuD.DetailRahmen.AktivLinks =posD.DetailRahmenAktivLinks
			set neuD.DetailRahmen.AktivOben = posD.DetailRahmenAktivOben
			set neuD.DetailRahmen.AktivRechts = posD.DetailRahmenAktivRechts
			set neuD.DetailRahmen.AktivUnten = posD.DetailRahmenAktivUnten
			set neuD.DetailRahmen.BreiteLinks = posD.DetailRahmenBreiteLinks
			set neuD.DetailRahmen.BreiteOben = posD.DetailRahmenBreiteOben
			set neuD.DetailRahmen.BreiteRechts = posD.DetailRahmenBreiteRechts
			set neuD.DetailRahmen.BreiteUnten = posD.DetailRahmenBreiteUnten
		
			set kid = ##Class(DBFakturierung.SD.TblKopf).GetTblKopfOidByCode(rs.Data("Mandant"), rs.Data("KNummer"))
		
			if (kid '= "") {
				set neuD.Tabellenkopf = ##Class(DBFakturierung.SD.TblKopf).%OpenId(kid)
		
				set sc = neuD.%Save()
			
				if ($$$ISERR(sc)) {
					w "Saveerror SREntry: "_sc,!
				}
			} else {
				w "SREntryKopf nicht gefunden",!
			}
		}
	}
	
	Set strSQL="SELECT ID, Formularkopf->Nummer as KNummer, Formularkopf->Mandant as Mandant FROM DBFakturierung_SD.FormSRgkEntry"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set posD = ##class(DBFakturierung.SD.FormSRgkEntry).%OpenId(rs.Data("ID"))
		if (posD '= "") {	
			set neuD = ##class(DBFakturierung.SD.TblSRgkE).%New()
			set neuD.Aktiv = posD.Aktiv
			set neuD.Ausrichtung = posD.Ausrichtung
			set neuD.Breite = posD.Breite
			set neuD.Index = posD.Index
			set neuD.Nummer = posD.Nummer
			set neuD.Text = posD.Text
									
			set neuD.Font.Bold = posD.FontBold
			set neuD.Font.Color = posD.FontColor
			set neuD.Font.Italic = posD.FontItalic
			set neuD.Font.Name = posD.FontName
			set neuD.Font.Size = posD.FontSize
			set neuD.Font.Strikeout = posD.FontStrikeout
				
			set neuD.Rahmen.AbstandLinks = posD.RahmenAbstandLinks
			set neuD.Rahmen.AbstandOben = posD.RahmenAbstandOben
			set neuD.Rahmen.AbstandRechts = posD.RahmenAbstandRechts
			set neuD.Rahmen.AbstandUnten = posD.RahmenAbstandUnten
			set neuD.Rahmen.AktivLinks =posD.RahmenAktivLinks
			set neuD.Rahmen.AktivOben = posD.RahmenAktivOben
			set neuD.Rahmen.AktivRechts = posD.RahmenAktivRechts
			set neuD.Rahmen.AktivUnten = posD.RahmenAktivUnten
			set neuD.Rahmen.BreiteLinks = posD.RahmenBreiteLinks
			set neuD.Rahmen.BreiteOben = posD.RahmenBreiteOben
			set neuD.Rahmen.BreiteRechts = posD.RahmenBreiteRechts
			set neuD.Rahmen.BreiteUnten = posD.RahmenBreiteUnten

			set neuD.Format.AnzDezStellen = posD.FormatAnzDezStellen
			set neuD.Format.Datum = posD.FormatDatum
			set neuD.Format.Einheit = posD.FormatEinheit
			set neuD.Format.TextFallsLeer = posD.FormatTextFallsLeer
			set neuD.Format.KeineAusgabe = posD.FormatKeineAusgabe
			set neuD.Format.Totalisieren = posD.FormatTotalisieren
		
			set kid = ##Class(DBFakturierung.SD.TblKopf).GetTblKopfOidByCode(rs.Data("Mandant"), rs.Data("KNummer"))
		
			if (kid '= "") {
				set neuD.Tabellenkopf = ##Class(DBFakturierung.SD.TblKopf).%OpenId(kid)
		
				set sc = neuD.%Save()
			
				if ($$$ISERR(sc)) {
					w "Saveerror SRgkEntry: "_sc,!
				}
			} else {
				w "SRgkEntryKopf nicht gefunden",!
			}
		}
	}
	
	Set strSQL="SELECT ID FROM DBFakturierung_SD.FormFuss"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set posF = ##class(DBFakturierung.SD.FormFuss).%OpenId(rs.Data("ID"))
		if (posF '= "") {	
			set neuF = ##class(DBFakturierung.SD.TblFuss).%New()
			set neuF.Bezeichnung = posF.Bezeichnung
			
			set neuF.GenFont.Aktiv = posF.GenFontAktiv
			set neuF.GenFont.Bold = posF.GenFontBold
			set neuF.GenFont.Color = posF.GenFontColor
			set neuF.GenFont.Italic = posF.GenFontItalic
			set neuF.GenFont.Name = posF.GenFontName
			set neuF.GenFont.Size = posF.GenFontSize
			set neuF.GenFont.Strikeout = posF.GenFontStrikeout
		
			set neuF.GenRahmen.AbstandLinks = posF.GenRahmenAbstandLinks
			set neuF.GenRahmen.AbstandOben = posF.GenRahmenAbstandOben
			set neuF.GenRahmen.AbstandRechts = posF.GenRahmenAbstandRechts
			set neuF.GenRahmen.AbstandUnten = posF.GenRahmenAbstandUnten
			set neuF.GenRahmen.Aktiv = posF.GenRahmenAktiv
			set neuF.GenRahmen.AktivLinks = posF.GenRahmenAktivLinks
			set neuF.GenRahmen.AktivOben = posF.GenRahmenAktivOben
			set neuF.GenRahmen.AktivRechts = posF.GenRahmenAktivRechts
			set neuF.GenRahmen.AktivUnten = posF.GenRahmenAktivUnten
			set neuF.GenRahmen.BreiteLinks = posF.GenRahmenBreiteLinks
			set neuF.GenRahmen.BreiteOben = posF.GenRahmenBreiteOben
			set neuF.GenRahmen.BreiteRechts = posF.GenRahmenBreiteRechts
			set neuF.GenRahmen.BreiteUnten = posF.GenRahmenBreiteUnten
			
			set neuF.Mandant = posF.Mandant
			set neuF.Nummer = posF.Nummer
		
			set sc = neuF.%Save()
			
			if ($$$ISERR(sc)) {
				w "Saveerror Fuss: "_sc,!
			}

		}
	}
	
	Set strSQL="SELECT ID, Formularfuss->Nummer as KNummer, Formularfuss->Mandant as Mandant FROM DBFakturierung_SD.FormFussEntry"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set posD = ##class(DBFakturierung.SD.FormFussEntry).%OpenId(rs.Data("ID"))
		if (posD '= "") {	
			set neuD = ##class(DBFakturierung.SD.TblFussE).%New()
			set neuD.Aktiv = posD.Aktiv
			set neuD.Ausrichtung = posD.Ausrichtung
			set neuD.Breite = posD.Breite
			set neuD.Index = posD.Index
			set neuD.Nummer = posD.Nummer
			set neuD.Text = posD.Text
			set neuD.TotalText = posD.TotalText
									
			set neuD.Font.Bold = posD.FontBold
			set neuD.Font.Color = posD.FontColor
			set neuD.Font.Italic = posD.FontItalic
			set neuD.Font.Name = posD.FontName
			set neuD.Font.Size = posD.FontSize
			set neuD.Font.Strikeout = posD.FontStrikeout
				
			set neuD.Rahmen.AbstandLinks = posD.RahmenAbstandLinks
			set neuD.Rahmen.AbstandOben = posD.RahmenAbstandOben
			set neuD.Rahmen.AbstandRechts = posD.RahmenAbstandRechts
			set neuD.Rahmen.AbstandUnten = posD.RahmenAbstandUnten
			set neuD.Rahmen.AktivLinks =posD.RahmenAktivLinks
			set neuD.Rahmen.AktivOben = posD.RahmenAktivOben
			set neuD.Rahmen.AktivRechts = posD.RahmenAktivRechts
			set neuD.Rahmen.AktivUnten = posD.RahmenAktivUnten
			set neuD.Rahmen.BreiteLinks = posD.RahmenBreiteLinks
			set neuD.Rahmen.BreiteOben = posD.RahmenBreiteOben
			set neuD.Rahmen.BreiteRechts = posD.RahmenBreiteRechts
			set neuD.Rahmen.BreiteUnten = posD.RahmenBreiteUnten
			
			set neuD.DetailFont.Bold = posD.DetailFontBold
			set neuD.DetailFont.Color = posD.DetailFontColor
			set neuD.DetailFont.Italic = posD.DetailFontItalic
			set neuD.DetailFont.Name = posD.DetailFontName
			set neuD.DetailFont.Size = posD.DetailFontSize
			set neuD.DetailFont.Strikeout = posD.DetailFontStrikeout
				
			set neuD.DetailRahmen.AbstandLinks = posD.DetailRahmenAbstandLinks
			set neuD.DetailRahmen.AbstandOben = posD.DetailRahmenAbstandOben
			set neuD.DetailRahmen.AbstandRechts = posD.DetailRahmenAbstandRechts
			set neuD.DetailRahmen.AbstandUnten = posD.DetailRahmenAbstandUnten
			set neuD.DetailRahmen.AktivLinks =posD.DetailRahmenAktivLinks
			set neuD.DetailRahmen.AktivOben = posD.DetailRahmenAktivOben
			set neuD.DetailRahmen.AktivRechts = posD.DetailRahmenAktivRechts
			set neuD.DetailRahmen.AktivUnten = posD.DetailRahmenAktivUnten
			set neuD.DetailRahmen.BreiteLinks = posD.DetailRahmenBreiteLinks
			set neuD.DetailRahmen.BreiteOben = posD.DetailRahmenBreiteOben
			set neuD.DetailRahmen.BreiteRechts = posD.DetailRahmenBreiteRechts
			set neuD.DetailRahmen.BreiteUnten = posD.DetailRahmenBreiteUnten
		
			set neuD.TotalFont.Bold = posD.TotalFontBold
			set neuD.TotalFont.Color = posD.TotalFontColor
			set neuD.TotalFont.Italic = posD.TotalFontItalic
			set neuD.TotalFont.Name = posD.TotalFontName
			set neuD.TotalFont.Size = posD.TotalFontSize
			set neuD.TotalFont.Strikeout = posD.TotalFontStrikeout
				
			set neuD.TotalRahmen.AbstandLinks = posD.TotalRahmenAbstandLinks
			set neuD.TotalRahmen.AbstandOben = posD.TotalRahmenAbstandOben
			set neuD.TotalRahmen.AbstandRechts = posD.TotalRahmenAbstandRechts
			set neuD.TotalRahmen.AbstandUnten = posD.TotalRahmenAbstandUnten
			set neuD.TotalRahmen.AktivLinks =posD.TotalRahmenAktivLinks
			set neuD.TotalRahmen.AktivOben = posD.TotalRahmenAktivOben
			set neuD.TotalRahmen.AktivRechts = posD.TotalRahmenAktivRechts
			set neuD.TotalRahmen.AktivUnten = posD.TotalRahmenAktivUnten
			set neuD.TotalRahmen.BreiteLinks = posD.TotalRahmenBreiteLinks
			set neuD.TotalRahmen.BreiteOben = posD.TotalRahmenBreiteOben
			set neuD.TotalRahmen.BreiteRechts = posD.TotalRahmenBreiteRechts
			set neuD.TotalRahmen.BreiteUnten = posD.TotalRahmenBreiteUnten
			
			set kid = ##Class(DBFakturierung.SD.TblFuss).GetTblFussOidByCode(rs.Data("Mandant"), rs.Data("KNummer"))
		
			if (kid '= "") {
				set neuD.Tabellenfuss = ##Class(DBFakturierung.SD.TblFuss).%OpenId(kid)
		
				set sc = neuD.%Save()
			
				if ($$$ISERR(sc)) {
					w "Saveerror FussEntry: "_sc,!
				}
			} else {
				w "FussEntryKopf nicht gefunden",!
			}
		}
	}
	
	Set strSQL="SELECT ID, Formularfuss->Nummer as KNummer, Formularfuss->Mandant as Mandant FROM DBFakturierung_SD.FormFussSkontoE"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set posD = ##class(DBFakturierung.SD.FormFussSkontoE).%OpenId(rs.Data("ID"))
		if (posD '= "") {	
			set neuD = ##class(DBFakturierung.SD.TblFussSktE).%New()
			set neuD.Aktiv = posD.Aktiv
			set neuD.Ausrichtung = posD.Ausrichtung
			set neuD.Breite = posD.Breite
			set neuD.Index = posD.Index
			set neuD.Nummer = posD.Nummer
			set neuD.Text = posD.Text
									
			set neuD.Font.Bold = posD.FontBold
			set neuD.Font.Color = posD.FontColor
			set neuD.Font.Italic = posD.FontItalic
			set neuD.Font.Name = posD.FontName
			set neuD.Font.Size = posD.FontSize
			set neuD.Font.Strikeout = posD.FontStrikeout
				
			set neuD.Rahmen.AbstandLinks = posD.RahmenAbstandLinks
			set neuD.Rahmen.AbstandOben = posD.RahmenAbstandOben
			set neuD.Rahmen.AbstandRechts = posD.RahmenAbstandRechts
			set neuD.Rahmen.AbstandUnten = posD.RahmenAbstandUnten
			set neuD.Rahmen.AktivLinks =posD.RahmenAktivLinks
			set neuD.Rahmen.AktivOben = posD.RahmenAktivOben
			set neuD.Rahmen.AktivRechts = posD.RahmenAktivRechts
			set neuD.Rahmen.AktivUnten = posD.RahmenAktivUnten
			set neuD.Rahmen.BreiteLinks = posD.RahmenBreiteLinks
			set neuD.Rahmen.BreiteOben = posD.RahmenBreiteOben
			set neuD.Rahmen.BreiteRechts = posD.RahmenBreiteRechts
			set neuD.Rahmen.BreiteUnten = posD.RahmenBreiteUnten
			
			set kid = ##Class(DBFakturierung.SD.TblFuss).GetTblFussOidByCode(rs.Data("Mandant"), rs.Data("KNummer"))
		
			if (kid '= "") {
				set neuD.Tabellenfuss = ##Class(DBFakturierung.SD.TblFuss).%OpenId(kid)
		
				set sc = neuD.%Save()
			
				if ($$$ISERR(sc)) {
					w "Saveerror FussSkontoEntry: "_sc,!
				}
			} else {
				w "FussSkontoEntryKopf nicht gefunden",!
			}
		}
	}
]]></Implementation>
</Method>

<Method name="KillDoppelteMandEinst">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
		
	Set strSQL="SELECT ID, Einstellung, Mandant  FROM DBCore.MandantEinstellung order by ID desc"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set einstOid = rs.Data("ID")
		Set found = 0
		set einstNr = rs.Data("Einstellung")
		set mand = rs.Data("Mandant")
		&sql(Select Count(ID) INTO :found from DBCore.MandantEinstellung where Einstellung = :einstNr and Mandant = :mand)
		w "found"_found,!
		if (found > 1) {
			w ##class(DBCore.MandantEinstellung).%DeleteId(einstOid)
		}
		KILL einst
	}
]]></Implementation>
</Method>

<Method name="KillDoppelteMandUserEinst">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
		
	Set strSQL="SELECT ID, Einstellung, Benutzer, Mandant FROM DBCore.MandantUserEinstellung order by ID desc"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set einstOid = rs.Data("ID")
		Set found = 0
		set einstNr = rs.Data("Einstellung")
		set mand = rs.Data("Mandant")
		set user = rs.Data("Benutzer")
		&sql(Select Count(ID) INTO :found from DBCore.MandantUserEinstellung where Einstellung = :einstNr and Mandant = :mand and Benutzer = :user)
		w "found"_found,!
		if (found > 1) {
			w ##class(DBCore.MandantEinstellung).%DeleteId(einstOid)
		}
		KILL einst
	}
]]></Implementation>
</Method>

<Method name="SetMengeAbArtikel">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
		
	Set strSQL="SELECT ID, Auftragskopf, Artikel->Mengeneinheit As Mengeneinheit FROM DBAgrofresh.Auftragspos"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	while (rs.Next()) {
		set posOid = rs.Data("ID")
		set aufOid = rs.Data("Auftragskopf")
		set mengOid = rs.Data("Mengeneinheit")
		
		do ##class(DBAgrofresh.Auftragskopf).SetFlagAutoMutiert(aufOid,1)
		
		set pos = ##class(DBAgrofresh.Auftragspos).%OpenId(posOid)
		set pos.Mengeneinheit = ##class(DBAgrofresh.SD.Mengencode).%OpenId(mengOid)
		set sc = pos.%Save()
		if ($$$ISERR(sc)) {
			w "Error: "_sc,!
		}
		
		do ##class(DBAgrofresh.Auftragskopf).SetFlagAutoMutiert(aufOid,0)
	}
]]></Implementation>
</Method>

<Method name="SetArtikeltext">
<ClassMethod>1</ClassMethod>
<FormalSpec>mandOid:%String</FormalSpec>
<Implementation><![CDATA[
		
	Set strSQL="SELECT ID, DBAgrofresh.Artikel_GetArtikeltextClass(ID, '"_mandOid_"','de') As Artikeltext, DBAgrofresh.Artikel_GetArtikeltext2Class(ID, '"_mandOid_"','de') As Artikeltext2 FROM DBAgrofresh.Artikel"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	
	set count = 0
	set error = 0
	while (rs.Next()) {
		set artOid = rs.Data("ID")
		set artText = rs.Data("Artikeltext")
		set artText2 = rs.Data("Artikeltext2")
		
		set art = ##class(DBAgrofresh.Artikel).%OpenId(artOid)
		do art.SetArtikeltext(mandOid,"fr",artText)
		do art.SetArtikeltext(mandOid,"it",artText)
		do art.SetArtikeltext(mandOid,"en",artText)
		
		do art.SetArtikeltext2(mandOid,"fr",artText2)
		do art.SetArtikeltext2(mandOid,"it",artText2)
		do art.SetArtikeltext2(mandOid,"en",artText2)
		
		set sc = art.%Save()
		set count = count + 1
		if ($$$ISERR(sc)) {
			set error = error + 1
			w "Error: "_sc,!
		}
		w "."
	}
	
	w !
	w "-----------------------------------",!
	w count_" Artikeltexte übertragen",!	
	if (error > 0) {
		w error_" FEHLERHAFT",!	
	}
]]></Implementation>
</Method>

<Method name="ResetRabattFakturierung">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[
		
	Set strSQL="SELECT Auftragskopf->ZahlAdresse->Adresse->Adressnummer, Auftragskopf->ZahlAdresse->Adresse, Auftragskopf->Auftragsnr, Artikel->Artikelnr, Detailtext, Positionsnr, ID, DBAdressen.RgInfoPos_GetPosOid(Auftragskopf->ZahlAdresse->Adresse, Auftragskopf->Auftragsnr, Positionsnr) As PosOid FROM DBFakturierung.Auftragspos WHERE  RabattBetrag<>0 AND RabattProzent=0"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	
	set count = 0
	while (rs.Next()) {
		set posOid = rs.Data("ID")
		set rgInfoPosOid = rs.Data("PosOid")
		
		set pos = ##class(DBFakturierung.Auftragspos).%OpenId(posOid)
		
		do ##class(DBFakturierung.Auftragskopf).SetFlagAutoMutiert(pos.Auftragskopf.%Id(),1)
		
		set pos.RabattBetrag = 0
		
		set sc = pos.%Save()
		if ($$$ISERR(sc)) {
			w "Error: "_sc,!
		}
		
		do ##class(DBFakturierung.Auftragskopf).SetFlagAutoMutiert(pos.Auftragskopf.%Id(),0)
		
		if (rgInfoPosOid'="") {
			set rgInfoPos = ##class(DBAdressen.RgInfoPos).%OpenId(rgInfoPosOid)
		
			set rgInfoPos.RabattBetrag = 0
		
			set sc = rgInfoPos.%Save()
			if ($$$ISERR(sc)) {
				w "Error: "_sc,!
			}
		}
		
		w "."
		set count = count + 1
	}
	
	w !,"-----------------------------------------",!
	w count_" korrigiert",!
]]></Implementation>
</Method>

<Method name="CheckGebindeVerrechnetFlag">
<ClassMethod>1</ClassMethod>
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[
	
	w !,"-------CheckGebindeVerrechnetFlag---------",!
	Set strSQL="SELECT ID FROM DBAgrofresh.GebDetail WHERE Auftrag->Auftragsstatus>=5 AND Auftrag->GebindeVerrechnung >= 3 AND NVL(Verrechnet,0)<>1 AND DBAgrofresh.Auftragskopf_IsStatusGedruckt(Auftrag->BearbeitungsstatusRG) = 1 AND NVL(NieVerrechnen,0) = 0"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	
	set count = 0
	while (rs.Next()) {
		set gebDet = rs.Data("ID")
		
		set pos = ##class(DBAgrofresh.GebDetail).%OpenId(gebDet)
		
		do ##class(DBAgrofresh.Auftragskopf).SetFlagAutoMutiert(pos.Auftrag.%Id(),1)
		
		set pos.Verrechnet = 1
		
		set sc = pos.%Save()
		if ($$$ISERR(sc)) {
			w "Error: "_sc,!
		}
		
		do ##class(DBAgrofresh.Auftragskopf).SetFlagAutoMutiert(pos.Auftrag.%Id(),0)
		
		w "."
		set count = count + 1
	}
	
	w !,"-----------------------------------------",!
	w count_" korrigiert",!
		
	w !,"-------CheckGebindeVerrechnetFlag2---------",!
	Set strSQL="SELECT ID FROM DBAgrofresh.GebDetail WHERE NVL(Verrechnet,0)=1 AND NVL(NieVerrechnen,0) = 1"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	
	set count = 0
	while (rs.Next()) {
		set gebDet = rs.Data("ID")
		
		set pos = ##class(DBAgrofresh.GebDetail).%OpenId(gebDet)
		
		do ##class(DBAgrofresh.Auftragskopf).SetFlagAutoMutiert(pos.Auftrag.%Id(),1)
		
		set pos.Verrechnet = 0
		
		set sc = pos.%Save()
		if ($$$ISERR(sc)) {
			w "Error: "_sc,!
		}
		
		do ##class(DBAgrofresh.Auftragskopf).SetFlagAutoMutiert(pos.Auftrag.%Id(),0)
		
		w "."
		set count = count + 1
	}
	
	w !,"-----------------------------------------",!
	w count_" korrigiert",!
	quit count
]]></Implementation>
</Method>

<Method name="GebindeSaldoKorrigierenVK">
<ClassMethod>1</ClassMethod>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[
		
	w !,"-------GebindeSaldoKorrigieren---------",!
	&sql(UPDATE DBAgrofresh.GebKontr kontr SET Lieferung = (Select SUM(NVL(LieferungMenge,0)) FROM DBAgrofresh.GebDetail det WHERE NVL(Verrechnet,0) = 0 AND GebKontr = kontr.Id),
	Retouren = (Select SUM(NVL(RetourenMenge,0)) FROM DBAgrofresh.GebDetail det WHERE NVL(Verrechnet,0) = 0 AND GebKontr = kontr.Id)
	WHERE Lieferung  <> (Select NVL(SUM(NVL(LieferungMenge,0)),0) FROM DBAgrofresh.GebDetail det WHERE NVL(Verrechnet,0) = 0 AND GebKontr = kontr.Id) OR
	Retouren  <> (Select NVL(SUM(NVL(RetourenMenge,0)),0) FROM DBAgrofresh.GebDetail det WHERE NVL(Verrechnet,0) = 0 AND GebKontr = kontr.Id))
	w "SQL Status: ", SQLCODE, !
	
	quit SQLCODE = 0
]]></Implementation>
</Method>

<Method name="GebindeSaldoKorrigierenEK">
<ClassMethod>1</ClassMethod>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[
		
	w !,"-------GebindeSaldoKorrigieren---------",!
	&sql(UPDATE DBAgrofreshEK.GebKontr kontr SET Auslieferungen = (Select SUM(NVL(AuslieferungMenge,0)) FROM DBAgrofreshEK.GebDetail det WHERE NVL(Verrechnet,0) = 0 AND GebKontr = kontr.Id),
	Anlieferungen = (Select SUM(NVL(AnlieferungMenge,0)) FROM DBAgrofreshEK.GebDetail det WHERE NVL(Verrechnet,0) = 0 AND GebKontr = kontr.Id)
	WHERE Auslieferungen  <> (Select SUM(NVL(AuslieferungMenge,0)) FROM DBAgrofreshEK.GebDetail det WHERE NVL(Verrechnet,0) = 0 AND GebKontr = kontr.Id) OR
	Anlieferungen  <>  (Select SUM(NVL(AnlieferungMenge,0)) FROM DBAgrofreshEK.GebDetail det WHERE NVL(Verrechnet,0) = 0 AND GebKontr = kontr.Id))
	w "SQL Status: ", SQLCODE, !
	
	quit SQLCODE = 0
]]></Implementation>
</Method>

<Method name="CheckGebindeVerrechnetEKFlag">
<ClassMethod>1</ClassMethod>
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[
	w !,"-------CheckGebindeVerrechnetFlag---------",!
	Set strSQL="SELECT ID FROM DBAgrofreshEK.GebDetail WHERE Bestellung->Bestellstatus >=5 AND Bestellung->GebindeVerrechnung >= 3 AND NVL(Verrechnet, 0) = 0 AND DBAgrofreshEK.BestellungsKopf_IsStatusGedruckt(Bestellung->BearbeitungsstatusAR) = 1 AND NVL(NieVerrechnen,0) = 0"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	
	set count = 0
	while (rs.Next()) {
		set gebDet = rs.Data("ID")
		
		set pos = ##class(DBAgrofreshEK.GebDetail).%OpenId(gebDet)
		
		do ##class(DBAgrofreshEK.BestellungsKopf).SetFlagAutoMutiert(pos.Bestellung.%Id(),1)
		
		set pos.Verrechnet = 1
		
		set sc = pos.%Save()
		if ($$$ISERR(sc)) {
			w "Error: "_sc,!
		}
		
		do ##class(DBAgrofreshEK.BestellungsKopf).SetFlagAutoMutiert(pos.Bestellung.%Id(),0)
		
		w "."
		set count = count + 1
	}
	
	w !,"-----------------------------------------",!
	w count_" korrigiert",!
		
	w !,"-------CheckGebindeVerrechnetFlag2---------",!
	Set strSQL="SELECT ID FROM DBAgrofreshEK.GebDetail WHERE NVL(Verrechnet, 0) = 1 AND NVL(NieVerrechnen,0) = 1"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	
	set count = 0
	while (rs.Next()) {
		set gebDet = rs.Data("ID")
		
		set pos = ##class(DBAgrofreshEK.GebDetail).%OpenId(gebDet)
		
		do ##class(DBAgrofreshEK.BestellungsKopf).SetFlagAutoMutiert(pos.Bestellung.%Id(),1)
		
		set pos.Verrechnet = 0
		
		set sc = pos.%Save()
		if ($$$ISERR(sc)) {
			w "Error: "_sc,!
		}
		
		do ##class(DBAgrofreshEK.BestellungsKopf).SetFlagAutoMutiert(pos.Bestellung.%Id(),0)
		
		w "."
		set count = count + 1
	}
	
	w !,"-----------------------------------------",!
	w count_" korrigiert",!
	quit count
]]></Implementation>
</Method>

<Method name="SetLieferantOnAuftragsposHeute">
<ClassMethod>1</ClassMethod>
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[
		
	w !,"-------Setze Lieferanten---------",!
	Set strSQL="SELECT ID FROM DBAgrofresh.Auftragspos WHERE Auftragskopf->Auftragsdatum = CURRENT_DATE AND Artikel is not null"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	
	set count = 0
	while (rs.Next()) {
		set posId = rs.Data("ID")
		w posId, "  "
		set pos = ##class(DBAgrofresh.Auftragspos).%OpenId(posId)
		if ((pos '= "") && (pos '= $c(0))) {
			set preis =  ##class(DBAgrofresh.Preis).GetPreis(pos.Auftragskopf.Mandant, pos.Auftragskopf.Adresse.Adresse.%Id(), pos.Artikel.%Id(), 0, 0)
			w preis, !
			if ((preis '= "") && (preis '= $c(0))) {
		
				do ##class(DBAgrofresh.Auftragskopf).SetFlagAutoMutiert(pos.Auftragskopf.%Id(),1)
				w "old Lieferant: ", pos.Lieferant, !
				if ((pos.Lieferant = "") || (pos.Lieferant = $c(0))) {
					set pos.Lieferant = preis.Lieferant
					set state = pos.%Save()
					w "new Lieferant: ", pos.Lieferant, !
					w "Speichere neuen satz: ", state
				}
				do ##class(DBAgrofresh.Auftragskopf).SetFlagAutoMutiert(pos.Auftragskopf.%Id(),0)
			}
		}
	}
]]></Implementation>
</Method>

<Method name="SetAnfangszahlenAgrofresh">
<ClassMethod>1</ClassMethod>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[
	
	w !,"-------Setze SetAnfangszahlenAgrofresh---------",!
	Set strSQL="SELECT ID FROM DBCore.Mandant"
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	
	set count = 0
	while (rs.Next()) {
		set mandId = rs.Data("ID")
		w "Bearbeite MandantId:",mandId,!
		set auftragNr = ##class(DBCore.MandantEinstellung).GetIntEinst(mandId, 1180007)
		set lieferscheinNr = ##class(DBCore.MandantEinstellung).GetIntEinst(mandId, 1180006)
		set rechnungsNr = ##class(DBCore.MandantEinstellung).GetIntEinst(mandId, 1180008)
		set verteillistenNr = ##class(DBCore.MandantEinstellung).GetIntEinst(mandId, 1180009)
		
		set bestellungNr = ##class(DBCore.MandantEinstellung).GetIntEinst(mandId, 1210005)
		set annahmeNr = ##class(DBCore.MandantEinstellung).GetIntEinst(mandId, 1210051)
		set abrechnungsNr = ##class(DBCore.MandantEinstellung).GetIntEinst(mandId, 1210007)
		
		d ##class(DBCore.FormularNr).SetAktuelleNr(mandId, ##class(DBCore.FormularNr).FormNrAgrofreshAuftrag(), auftragNr)
		d ##class(DBCore.FormularNr).SetAktuelleNr(mandId, ##class(DBCore.FormularNr).FormNrAgrofreshLieferung(), lieferscheinNr)
		d ##class(DBCore.FormularNr).SetAktuelleNr(mandId, ##class(DBCore.FormularNr).FormNrAgrofreshRechnung(), rechnungsNr)
		d ##class(DBCore.FormularNr).SetAktuelleNr(mandId, ##class(DBCore.FormularNr).FormNrAgrofreshVerteilliste(), verteillistenNr)
		d ##class(DBCore.FormularNr).SetAktuelleNr(mandId, ##class(DBCore.FormularNr).FormNrAgrofreshEKBestellung(), bestellungNr)
		d ##class(DBCore.FormularNr).SetAktuelleNr(mandId, ##class(DBCore.FormularNr).FormNrAgrofreshEKAnnahme(), annahmeNr)
		d ##class(DBCore.FormularNr).SetAktuelleNr(mandId, ##class(DBCore.FormularNr).FormNrAgrofreshEKAbrechnung(), abrechnungsNr)
		
	}
	quit 1
]]></Implementation>
</Method>

<Method name="SetNummernAgrofreshMand">
<ClassMethod>1</ClassMethod>
<FormalSpec>mandant:%String</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[
	set mandId = mandant
	w "Bearbeite MandantId:",mandId,!
	set auftragNr = ##class(DBCore.MandantEinstellung).GetIntEinst(mandId, 1180007)
	set lieferscheinNr = ##class(DBCore.MandantEinstellung).GetIntEinst(mandId, 1180006)
	set rechnungsNr = ##class(DBCore.MandantEinstellung).GetIntEinst(mandId, 1180008)
	set verteillistenNr = ##class(DBCore.MandantEinstellung).GetIntEinst(mandId, 1180009)
	
	set bestellungNr = ##class(DBCore.MandantEinstellung).GetIntEinst(mandId, 1210005)
	set annahmeNr = ##class(DBCore.MandantEinstellung).GetIntEinst(mandId, 1210006)
	set abrechnungsNr = ##class(DBCore.MandantEinstellung).GetIntEinst(mandId, 1210007)
	
	d ##class(DBCore.FormularNr).SetAktuelleNr(mandId, ##class(DBCore.FormularNr).FormNrAgrofreshAuftrag(), auftragNr)
	d ##class(DBCore.FormularNr).SetAktuelleNr(mandId, ##class(DBCore.FormularNr).FormNrAgrofreshLieferung(), lieferscheinNr)
	d ##class(DBCore.FormularNr).SetAktuelleNr(mandId, ##class(DBCore.FormularNr).FormNrAgrofreshRechnung(), rechnungsNr)
	d ##class(DBCore.FormularNr).SetAktuelleNr(mandId, ##class(DBCore.FormularNr).FormNrAgrofreshVerteilliste(), verteillistenNr)
	d ##class(DBCore.FormularNr).SetAktuelleNr(mandId, ##class(DBCore.FormularNr).FormNrAgrofreshEKBestellung(), bestellungNr)
	d ##class(DBCore.FormularNr).SetAktuelleNr(mandId, ##class(DBCore.FormularNr).FormNrAgrofreshEKAnnahme(), annahmeNr)
	d ##class(DBCore.FormularNr).SetAktuelleNr(mandId, ##class(DBCore.FormularNr).FormNrAgrofreshEKAbrechnung(), abrechnungsNr)
		
	quit 1
]]></Implementation>
</Method>

<Method name="CalcGebinde">
<ClassMethod>1</ClassMethod>
<FormalSpec>AnzJeGeb:%Decimal,Menge:%Decimal</FormalSpec>
<ReturnType>%Integer</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[
	if (+AnzJeGeb <= 0) {
		set AnzJeGeb = 1
	}
	set anzGeb = Menge / AnzJeGeb
	if ((Menge # AnzJeGeb) '= 0) {
		set anzGeb = anzGeb -(anzGeb # 1) + 1
	}
	quit anzGeb
]]></Implementation>
</Method>

<Method name="SetNummernFakturierungMand">
<ClassMethod>1</ClassMethod>
<FormalSpec>mandant:%String</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[
	set mandId = mandant
	w "Bearbeite MandantId:",mandId,!
	set auftragNr = ##class(DBCore.MandantEinstellung).GetIntEinst(mandId, 1150007)
	set lieferscheinNr = ##class(DBCore.MandantEinstellung).GetIntEinst(mandId, 1150006)
	set rechnungsNr = ##class(DBCore.MandantEinstellung).GetIntEinst(mandId, 1150008)
	
	d ##class(DBCore.FormularNr).SetAktuelleNr(mandId, ##class(DBCore.FormularNr).FormNrFaktAuftrag(), auftragNr)
	d ##class(DBCore.FormularNr).SetAktuelleNr(mandId, ##class(DBCore.FormularNr).FormNrFaktLieferung(), lieferscheinNr)
	d ##class(DBCore.FormularNr).SetAktuelleNr(mandId, ##class(DBCore.FormularNr).FormNrFaktRechnung(), rechnungsNr)
	
	quit 1
]]></Implementation>
</Method>

<Method name="SetArtikelLagerGebinde">
<ClassMethod>1</ClassMethod>
<FormalSpec>mandOid:%String</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[
	
	Set strSQL="SELECT ID FROM DBAgrofresh.ArtikelLager WHERE Artikel->Mandant = "_mandOid
	Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
	Do rs.Prepare(strSQL)
	Set sc=rs.Execute()
	
	set count = 0
	while (rs.Next()) {
		set id = rs.Data("ID")
		set artLager = ##class(DBAgrofresh.ArtikelLager).%OpenId(id)
		set mengeJeGeb = artLager.Artikel.AnzahlJeGebinde
		if (+mengeJeGeb = 0) {
			set mengeJeGeb = 1
		}
		
		set artLager.LagerbestandGebinde = ##class(DBUtils.Dev).CalcAnzGeb(artLager.Lagerbestand, mengeJeGeb)
		set artLager.ReservationGebinde = ##class(DBUtils.Dev).CalcAnzGeb(artLager.Reservation, mengeJeGeb)
		set artLager.MindestbestandGebinde = ##class(DBUtils.Dev).CalcAnzGeb(artLager.Mindestbestand, mengeJeGeb)
		set artLager.OffeneBestellungenGebinde = ##class(DBUtils.Dev).CalcAnzGeb(artLager.OffeneBestellungen, mengeJeGeb)
		set artLager.OptimaleBestellmengeGebinde = ##class(DBUtils.Dev).CalcAnzGeb(artLager.OptimaleBestellmenge, mengeJeGeb)
		
		d artLager.%Save()
		k artLager
	}
	quit 1
]]></Implementation>
</Method>

<Method name="CalcAnzGeb">
<ClassMethod>1</ClassMethod>
<FormalSpec>Menge:%Decimal,MengeJeGeb:%Decimal</FormalSpec>
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[
	set retval = Menge / MengeJeGeb
	if ((Menge # MengeJeGeb) '= 0) {
		set retval = retval -(retval # 1) + 1
	}
	quit retval
]]></Implementation>
</Method>

<Method name="CopyAbteilungToAllMandant">
<ClassMethod>1</ClassMethod>
<ReturnType>%Integer</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[
	set firstMandantOid = ""
	&sql(SELECT TOP 1 ID InTo :firstMandantOid 
			FROM DBCore.Mandant
			ORDER BY MandantNr)
	
	set abteilungOid = ""
	&sql(DECLARE AbteilungCursor CURSOR FOR 
			SELECT ID InTo :abteilungOid 
			FROM DBCore.Abteilung
			ORDER BY Abteilungnr)
	
	&sql(OPEN AbteilungCursor)
	&sql(FETCH AbteilungCursor)
	
   	While (SQLCODE = 0) {
  		
  		set abt = ##class(DBCore.Abteilung).%OpenId(abteilungOid)
  		set abt.Mandant = firstMandantOid
  		d abt.%Save()
  		
  		&sql(FETCH AbteilungCursor)
   	}
   	
   	&sql(CLOSE AbteilungCursor)
   	
   	
   	set mandantOid = ""
	&sql(DECLARE MandantCursor CURSOR FOR 
			SELECT ID InTo :mandantOid 
			FROM DBCore.Mandant
			WHERE ID<>:firstMandantOid
			ORDER BY MandantNr)
	
	&sql(OPEN MandantCursor)
	&sql(FETCH MandantCursor)
	
   	While (SQLCODE = 0) {
  	
	   	set abteilungOid = ""
		&sql(DECLARE AbteilungCursor2 CURSOR FOR 
				SELECT ID InTo :abteilungOid 
				FROM DBCore.Abteilung
				WHERE Mandant=:firstMandantOid
				ORDER BY Abteilungnr)
	
		&sql(OPEN AbteilungCursor2)
		&sql(FETCH AbteilungCursor2)
	
	   	While (SQLCODE = 0) {
  		
	  		set sAbt = ##class(DBCore.Abteilung).%OpenId(abteilungOid)
	  		set abtOid = ##class(DBCore.Abteilung).GetAbteilungOidByAbteilungnr(mandantOid,sAbt.Abteilungnr)
	  		if ((abtOid="") || (abtOid=$c(0))) {
		  		set dAbt = ##class(DBCore.Abteilung).%New()
	  		
		  		set dAbt.Abteilungnr = sAbt.Abteilungnr
		  		set dAbt.Bezeichnung = sAbt.Bezeichnung
		  		set dAbt.Barkonto = ""
		  		set dAbt.VerbuchungMandantNr = 0
	  		
		  		set dAbt.Mandant = mandantOid
	  		
		  		d dAbt.%Save()
	  		}
	  		
	  		&sql(FETCH AbteilungCursor2)
	   	}
   	
	   	&sql(CLOSE AbteilungCursor2)
	   	
	   	&sql(FETCH MandantCursor)
	}
   	
   	&sql(CLOSE MandantCursor)
   	
   	// MoveFirst
   	set list = $ListBuild()
	set id = ""
	set id = $Order(^DBCore.BenutzerD(id),1,list)
	while (id'="") {
		if ((list'="") && (list'="")) {
           if ($LISTDATA(list,17)'=0) {
				set abteilungOid = $LIST(list,17)
				if ((abteilungOid'="") && (abteilungOid'=$c(0))) {
			
					set mandantOid = ""
					&sql(DECLARE MandantCursor2 CURSOR FOR 
							SELECT ID InTo :mandantOid 
							FROM DBCore.Mandant
							ORDER BY MandantNr)
	
					&sql(OPEN MandantCursor2)
					&sql(FETCH MandantCursor2)
	
				   	While (SQLCODE = 0) {
  	
						set maOid = ##class(DBCore.Mitarbeiter).GetMitarbeiterIdByUser(mandantOid,id)
						w "maOid:",maOid,!
						set ma = ##class(DBCore.Mitarbeiter).%OpenId(maOid)
						if ((ma'="") && (ma'=$c(0))) {
							set abteilung = ##class(DBCore.Abteilung).%OpenId(abteilungOid)
							set mandAbtOid = ##class(DBCore.Abteilung).GetAbteilungOidByAbteilungnr(mandantOid,abteilung.Abteilungnr)
							if ((mandAbtOid'="") && (mandAbtOid'=$c(0))) {
								w "MandAbtOid:", mandAbtOid,!
								do ma.AbteilungSetObjectId(mandAbtOid)
								do ma.%Save()
							}
						}
					   	&sql(FETCH MandantCursor2)
					}
   	
				   	&sql(CLOSE MandantCursor2)
				}
           }
		}
		set id = $Order(^DBCore.BenutzerD(id),1,list)
	}
	
	
	// DBAgrofresh.BenAbzuege
	// Bezieht sich nur auf die Abteilung (somit automatisch nun auf richtiger Abteilung)

	// DBAgrofresh.SD.GebTransKosten
	// Bezieht sich nur auf die Abteilung (somit automatisch nun auf richtiger Abteilung)

	// DBAgrofreshEK.SD.MargeAbt
	// Bezieht sich nur auf die Abteilung (somit automatisch nun auf richtiger Abteilung)
	
	w "DBAgrofresh.Auftragskopf",!
	&sql(update %NOTRIGGER dbagrofresh.auftragskopf set abteilung=DBCore.Abteilung_GetAbteilungOidByAbteilungnr(Mandant,Abteilung->AbteilungNr))
	
	w "DBAgrofreshEK.BestellungsKopf",!
	&sql(update %NOTRIGGER DBAgrofreshEK.BestellungsKopf set abteilung=DBCore.Abteilung_GetAbteilungOidByAbteilungnr(Mandant,Abteilung->AbteilungNr))
	
	w "DBAgrofreshEK.BestStrg",!
	&sql(update DBAgrofreshEK.BestStrg set VorschlagAbteilung=DBCore.Abteilung_GetAbteilungOidByAbteilungnr(Mandant,VorschlagAbteilung->AbteilungNr))
	
	w "DBAgrofreshEK.QsMeldung",!
	&sql(update DBAgrofreshEK.QSMeldung set EkAbteilung=DBCore.Abteilung_GetAbteilungOidByAbteilungnr(Charge->Mandant,EkAbteilung->AbteilungNr))
	&sql(update DBAgrofreshEK.QSMeldung set VkAbteilung=DBCore.Abteilung_GetAbteilungOidByAbteilungnr(Charge->Mandant,VkAbteilung->AbteilungNr))
	
	w "DBAgrofreshEK.ChargenEingang",!
	&sql(update DBAgrofreshEK.ChargenEingang set Abteilung=DBCore.Abteilung_GetAbteilungOidByAbteilungnr(Mandant,Abteilung->AbteilungNr))
		
	w "DBAgrofreshEK.ChargenAusgang",!
	&sql(update DBAgrofreshEK.ChargenAusgang set Abteilung=DBCore.Abteilung_GetAbteilungOidByAbteilungnr(Charge->Mandant,Abteilung->AbteilungNr))
	
	w "DBFakturierung.Auftragspos",!
	&sql(update %NOTRIGGER DBFakturierung.Auftragspos set Abteilung=DBCore.Abteilung_GetAbteilungOidByAbteilungnr(Auftragskopf->Mandant,Abteilung->AbteilungNr))
	
	w "DBFakturierung.Auftragskopf",!
	&sql(update %NOTRIGGER DBFakturierung.Auftragskopf set Abteilung=DBCore.Abteilung_GetAbteilungOidByAbteilungnr(Mandant,Abteilung->AbteilungNr))
	
	w "DBCore.Abteilung",!
	&sql(update DBCore.Abteilung set Barkonto=DBFibu.Konto_GetOidByKontoNr(Mandant,Barkonto->KontoNr))
	
	w "DBAgrofresh.ArtikelInventar",!
	&sql(update DBAgrofresh.ArtikelInventar set Abteilung=DBCore.Abteilung_GetAbteilungOidByAbteilungnr(Artikel->Mandant,Abteilung->AbteilungNr))
	
	w "DBAgrofresh.GebindeInventar",!
	&sql(update DBAgrofresh.GebindeInventar set Abteilung=DBCore.Abteilung_GetAbteilungOidByAbteilungnr(Gebinde->Mandant,Abteilung->AbteilungNr))
	
	quit 1
]]></Implementation>
</Method>

<Method name="SetLagerortToMitarbeiter">
<ClassMethod>1</ClassMethod>
<ReturnType>%Integer</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[
	set list = $ListBuild()
	set id = ""
	set id = $Order(^DBCore.BenutzerD(id),1,list)
	while (id'="") {
		if ((list'="") && (list'="")) {
           if ($LISTDATA(list,19)'=0) {
				set lagerortOid = $LIST(list,19)
				if ((lagerortOid'="") && (lagerortOid'=$c(0))) {
			
					set mandantOid = ""
					&sql(DECLARE MandantCursor3 CURSOR FOR 
							SELECT ID InTo :mandantOid 
							FROM DBCore.Mandant
							ORDER BY MandantNr)
	
					&sql(OPEN MandantCursor3)
					&sql(FETCH MandantCursor3)
	
				   	While (SQLCODE = 0) {
  	
						set maOid = ##class(DBCore.Mitarbeiter).GetMitarbeiterIdByUser(mandantOid,id)
						w "maOid:",maOid,!
						set ma = ##class(DBCore.Mitarbeiter).%OpenId(maOid)
						if ((ma'="") && (ma'=$c(0))) {
							set lagerort = ##class(DBAgrofresh.SD.Lagerort).%OpenId(lagerortOid)
							set mandLagerortOid = ##class(DBAgrofresh.SD.Lagerort).GetIdByPosNrOnMandant(mandantOid,lagerort.PositionsNr)
							if ((mandLagerortOid'="") && (mandLagerortOid'=$c(0))) {
								w "mandLagerortOid:", mandLagerortOid,!
								do ma.LagerortSetObjectId(mandLagerortOid)
								do ma.%Save()
							}
						}
					   	&sql(FETCH MandantCursor3)
					}
   	
				   	&sql(CLOSE MandantCursor3)
				}
           }
		}
		set id = $Order(^DBCore.BenutzerD(id),1,list)
	}
	
	quit 1
]]></Implementation>
</Method>

<Method name="SetMitarbeiterToKorrespondenz">
<ClassMethod>1</ClassMethod>
<ReturnType>%Integer</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[
    set list = $ListBuild()
    set id = ""
    set id = $Order(^DBAdressen.KorrespondenzD(id),1,list)
    while (id'="") {
       set korrespondenz = ##class(DBAdressen.Korrespondenz).%OpenId(id)
       if ((list'="") && (list'="")) {
           if ($LISTDATA(list,11)'=0) {
              set userOid = $LIST(list,11)
              if ((userOid'="") && (userOid'=$c(0))) {
	              set mandantOid = korrespondenz.Adresse.Mandant
	              set maOid = ##class(DBCore.Mitarbeiter).GetMitarbeiterIdByUser(mandantOid,userOid)

	              w "maOid:",maOid,!

	              if ((maOid'="") && (maOid'=$c(0))) {
					do korrespondenz.MitarbeiterSetObjectId(maOid)
	              }

	              do korrespondenz.%Save()
			  }
           } else {
				w "NULL auf KorrespondenzId:", id, !
           }
       } else {
           w "NULL auf KorrespondenzId:", id, !
       }
       set id = $Order(^DBAdressen.KorrespondenzD(id),1,list)
    }
    
    quit 1
]]></Implementation>
</Method>

<Method name="ImportFile">
<ClassMethod>1</ClassMethod>
<FormalSpec>PathFileName:%String</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[
     // öffne File
     Set stream=##class(%FileCharacterStream).%New()
     Set stream.Filename=PathFileName
     // Abbruch, wenn keine Daten vorhanden
     Quit:stream.Size=0
     
     set lc = 1
     While 'stream.AtEnd {
	     set line=stream.ReadLine()
         set oid = $P(line, ";", 1)
         
         set zahlung = ##class(DBDebiKredi.Zahlung).%OpenId(oid)
         if ((zahlung'=$c(0)) && (zahlung'="") && (zahlung'=$$$NULLOREF)) {
	         w "Line: ", lc, ", OID: ", oid
	         
	         set fibuBuchungOid = $P(line, ";", 2)
	         w ", fibuBuchungOid: ", fibuBuchungOid
	         if ((fibuBuchungOid'=$c(0)) && (fibuBuchungOid'="") && (fibuBuchungOid'=$$$NULLOREF)) {
	         	do zahlung.FibuBuchungSetObjectId(fibuBuchungOid)
	         } else {
		         set zahlung.FibuBuchung = ""
	         }
	         
	         set valutadatum = $P(line, ";", 3)
	         w ", valutadatum: ", valutadatum
	         set zahlung.Valutadatum = valutadatum
	         
	         set belegdatum = $P(line, ";", 4)
	         w ", belegdatum: ", belegdatum
	         set zahlung.Belegdatum = belegdatum
	         
	         set status = zahlung.%Save()
	         w ", status: ", status, !
	         
         } else {
	         w "Line: ", lc, ", OID: ", oid, " nicht gefunden!",!
         }
         
         set lc = lc + 1
     }
     
     // schliesse Stream
     Set stream=""
     
     Quit 1
]]></Implementation>
</Method>
</Class>


<Class name="DBUtils.Duration">
<Description>
	Instances of this class represent a duration (days, hours, minutes and seconds, without fractional seconds).
		It's not possible to create a negative duration. If you try, the resulting duration is 0:00:00:00.

		Last change: 09.03.2010 by Lem
</Description>
<Super>%SerialObject,%XML.Adaptor</Super>
<TimeChanged>61800,58319.220014</TimeChanged>
<TimeCreated>61792,70922.875</TimeCreated>
<Inheritance>right</Inheritance>

<Parameter name="SecsPerDay">
<Description>
	The number of seconds per day (is needed for arithmetic)</Description>
<Default>86400</Default>
</Parameter>

<Parameter name="SecsPerHour">
<Description>
	The number of seconds per hour (is needed for arithmetic)</Description>
<Default>3600</Default>
</Parameter>

<Parameter name="SecsPerMinute">
<Description>
	The number of seconds per minute (is needed for arithmetic)</Description>
<Default>60</Default>
</Parameter>

<Parameter name="DurationStringSeparator">
<Description>
	The internal separator. Don't change, otherwise many functions won't work any more!</Description>
<Default>:</Default>
</Parameter>

<UDLText name="T">
<Content><![CDATA[
//

]]></Content>
</UDLText>

<Property name="seconds">
<Description>
	Internal duration representation is the number of seconds. It's capable of arithmetic and is very slim.</Description>
<Type>%Integer</Type>
<Parameter name="MINVAL" value="0"/>
</Property>

<UDLText name="T">
<Content><![CDATA[
//	-----	Instance Creation	-----------------------------------------------

]]></Content>
</UDLText>

<Method name="%OnNew">
<Description>
	Create a new instance.</Description>
<FormalSpec>seconds:%Integer=0</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
	do ..basicSetSeconds(seconds)
	quit $$$OK
]]></Implementation>
</Method>

<Method name="new">
<Description>
	Create a new instance with the given data. All are optional.</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>days:%Integer=0,hours:%Integer=0,minutes:%Integer=0,seconds:%Integer=0</FormalSpec>
<ReturnType>DBUtils.Duration</ReturnType>
<Implementation><![CDATA[	quit ..%New((days * ..#SecsPerDay) + (hours * ..#SecsPerHour) + (minutes * ..#SecsPerMinute) + seconds)
]]></Implementation>
</Method>

<Method name="copy">
<Description>
	Make a copy of this instance.</Description>
<ReturnType>DBUtils.Duration</ReturnType>
<Implementation><![CDATA[	quit ..%New(..seconds)
]]></Implementation>
</Method>

<UDLText name="T">
<Content><![CDATA[
//	-----	Getter				-----------------------------------------------

]]></Content>
</UDLText>

<Method name="getDays">
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[	quit $inumber($piece(..toDurationString(), ..#DurationStringSeparator, 1), "")
]]></Implementation>
</Method>

<Method name="getHours">
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[	quit $inumber($piece(..toDurationString(), ..#DurationStringSeparator, 2), "")
]]></Implementation>
</Method>

<Method name="getMinutes">
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[	quit $inumber($piece(..toDurationString(), ..#DurationStringSeparator, 3), "")
]]></Implementation>
</Method>

<Method name="getSeconds">
<ReturnType>%Integer</ReturnType>
<Implementation><![CDATA[	quit $inumber($piece(..toDurationString(), ..#DurationStringSeparator, 4), "")
]]></Implementation>
</Method>

<UDLText name="T">
<Content><![CDATA[
//	-----	Setter				-----------------------------------------------

]]></Content>
</UDLText>

<Method name="setDays">
<Description>
	Set the days</Description>
<FormalSpec>days:%Integer</FormalSpec>
<ReturnType>DBUtils.Duration</ReturnType>
<Implementation><![CDATA[
	set durationString = ..toDurationString()
	set $piece(durationString, ..#DurationStringSeparator, 1) = days
	quit ..fromDurationString(durationString)
]]></Implementation>
</Method>

<Method name="setHours">
<Description>
	Set the hours.</Description>
<FormalSpec>hours:%Integer</FormalSpec>
<ReturnType>DBUtils.Duration</ReturnType>
<Implementation><![CDATA[
	set durationString = ..toDurationString()
	set $piece(durationString, ..#DurationStringSeparator, 2) = hours
	quit ..fromDurationString(durationString)
]]></Implementation>
</Method>

<Method name="setMinutes">
<Description>
	Set the minutes.</Description>
<FormalSpec>mins:%Integer</FormalSpec>
<ReturnType>DBUtils.Duration</ReturnType>
<Implementation><![CDATA[
	set durationString = ..toDurationString()
	set $piece(durationString, ..#DurationStringSeparator, 3) = mins
	quit ..fromDurationString(durationString)
]]></Implementation>
</Method>

<Method name="setSeconds">
<Description>
	Set the seconds.</Description>
<FormalSpec>sex:%Integer</FormalSpec>
<ReturnType>DBUtils.Duration</ReturnType>
<Implementation><![CDATA[
	set durationString = ..toDurationString()
	set $piece(durationString, ..#DurationStringSeparator, 4) = sex
	quit ..fromDurationString(durationString)
]]></Implementation>
</Method>

<UDLText name="T">
<Content><![CDATA[
//	-----	Arithmetic			-----------------------------------------------

]]></Content>
</UDLText>

<Method name="addDays">
<Description>
	Add days to the current instance. Negative values are allowed, too.</Description>
<FormalSpec>days:%Integer</FormalSpec>
<ReturnType>DBUtils.Duration</ReturnType>
<Implementation><![CDATA[	quit ..addSeconds(days * ..#SecsPerDay)
]]></Implementation>
</Method>

<Method name="addHours">
<Description>
	Add hours to the current instance. Negative values are allowed, too.</Description>
<FormalSpec>hours:%Integer</FormalSpec>
<ReturnType>DBUtils.Duration</ReturnType>
<Implementation><![CDATA[	quit ..addSeconds(hours * ..#SecsPerHour)
]]></Implementation>
</Method>

<Method name="addMinutes">
<Description>
	Add minutes to the current instance. Negative values are allowed, too.</Description>
<FormalSpec>mins:%Integer</FormalSpec>
<ReturnType>DBUtils.Duration</ReturnType>
<Implementation><![CDATA[	quit ..addSeconds(mins * ..#SecsPerMinute)
]]></Implementation>
</Method>

<Method name="addSeconds">
<Description>
	Add seconds to the current instance. Negative values are allowed, too.</Description>
<FormalSpec>secs:%Integer</FormalSpec>
<ReturnType>DBUtils.Duration</ReturnType>
<Implementation><![CDATA[	quit ..basicSetSeconds(..seconds + secs)
]]></Implementation>
</Method>

<UDLText name="T">
<Content><![CDATA[
//	-----	Comparing			-----------------------------------------------

]]></Content>
</UDLText>

<Method name="isEqual">
<Description>
	Return true if the current instance and duration are equal, false otherwise.</Description>
<FormalSpec>duration:DBUtils.Duration</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[	quit (..seconds = duration.seconds)
]]></Implementation>
</Method>

<Method name="isNotEqual">
<Description>
	Return true if the current instance and duration are not equal, false otherwise.</Description>
<FormalSpec>duration:DBUtils.Duration</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[	quit '(..isEqual(duration))
]]></Implementation>
</Method>

<Method name="isShorterThan">
<Description>
	Return true if the current instance is shorter than duration, false otherwise.</Description>
<FormalSpec>duration:DBUtils.Duration</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[	quit (..seconds < duration.seconds)
]]></Implementation>
</Method>

<Method name="isLongerThan">
<Description>
	Return true if the current instance is longer than duration, false otherwise.</Description>
<FormalSpec>duration:DBUtils.Duration</FormalSpec>
<ReturnType>%Boolean</ReturnType>
<Implementation><![CDATA[	quit (..seconds > duration.seconds)
]]></Implementation>
</Method>

<UDLText name="T">
<Content><![CDATA[
//	-----	Converting			-----------------------------------------------

]]></Content>
</UDLText>

<UDLText name="T">
<Content><![CDATA[
//	-----	To			-----------------------------------------------

]]></Content>
</UDLText>

<Method name="toDurationString">
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
	set days = ..seconds \ ..#SecsPerDay
	set remainder = ..seconds # ..#SecsPerDay
	set hours = remainder \ ..#SecsPerHour
	set remainder = remainder # ..#SecsPerHour
	set minutes = remainder \ ..#SecsPerMinute
	set seconds = remainder # ..#SecsPerMinute

	quit days _ ..#DurationStringSeparator _
		..fillLeftWithZeros(hours) _ ..#DurationStringSeparator _
		..fillLeftWithZeros(minutes) _ ..#DurationStringSeparator _
		..fillLeftWithZeros(seconds)
]]></Implementation>
</Method>

<UDLText name="T">
<Content><![CDATA[
//	-----	From		-----------------------------------------------

]]></Content>
</UDLText>

<Method name="fromDurationString">
<FormalSpec>durationString:%String</FormalSpec>
<ReturnType>DBUtils.Duration</ReturnType>
<Implementation><![CDATA[
	set days = $inumber($piece(durationString, ..#DurationStringSeparator, 1), "")
	set hours = $inumber($piece(durationString, ..#DurationStringSeparator, 2), "")
	set minutes = $inumber($piece(durationString, ..#DurationStringSeparator, 3), "")
	set seconds = $inumber($piece(durationString, ..#DurationStringSeparator, 4), "")
	quit ..basicSetSeconds((days * ..#SecsPerDay) + (hours * ..#SecsPerHour) + (minutes * ..#SecsPerMinute) + seconds)
]]></Implementation>
</Method>

<UDLText name="T">
<Content><![CDATA[
//	-----	Support				-----------------------------------------------

]]></Content>
</UDLText>

<Method name="toString">
<Description>
	For easy testing.</Description>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[	quit "[Duration:" _ ..toDurationString() _ "]"
]]></Implementation>
</Method>

<Method name="write">
<Description>
	For easy testing.</Description>
<Implementation><![CDATA[	write ..toString()
]]></Implementation>
</Method>

<UDLText name="T">
<Content><![CDATA[
//	-----	Private				-----------------------------------------------

]]></Content>
</UDLText>

<UDLText name="T">
<Content><![CDATA[
//	-----	Instance	-----------------------------------------------

]]></Content>
</UDLText>

<Method name="basicSetSeconds">
<Internal>1</Internal>
<FormalSpec>seconds:%Integer</FormalSpec>
<Private>1</Private>
<ReturnType>DBUtils.Duration</ReturnType>
<Implementation><![CDATA[
	set ..seconds = $select(seconds > 0: seconds, 1: 0)
	quit ##this
]]></Implementation>
</Method>

<UDLText name="T">
<Content><![CDATA[
//	-----	Class		-----------------------------------------------

]]></Content>
</UDLText>

<Method name="fillLeftWithZeros">
<Description>
[Previously private]</Description>
<Internal>1</Internal>
<ClassMethod>1</ClassMethod>
<FormalSpec>value:%Integer,size:%Integer=2</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[	quit $translate($justify(value, size), " ", "0")
]]></Implementation>
</Method>

<Storage name="Default">
<Type>%Library.CacheSerialState</Type>
<State>DurationState</State>
<StreamLocation>^DBUtils.DurationS</StreamLocation>
<Data name="DurationState">
<Structure>listnode</Structure>
<Subscript/>
<Value name="1">
<Value>seconds</Value>
</Value>
</Data>
</Storage>
</Class>


<Class name="DBUtils.ImpExp">
<Super>%RegisteredObject</Super>
<TimeChanged>62427,55441.030917</TimeChanged>
<TimeCreated>61436,51909.272789</TimeCreated>

<Parameter name="GLOBALENDING">
<Default>D.gbl</Default>
</Parameter>

<Parameter name="STREAMGLOBALENDING">
<Default>S.gbl</Default>
</Parameter>

<Method name="ExportDrucktypen">
<Description>
Exportiert ein Objekt mit allen seinen Abhängigkeiten und 
in Beziehung stehenden Klassen in ein XML-File.
ACHTUNG: die Klassen-OREF (ID) werden nicht ausgegeben</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>myPathFile:%String,MandantOid:%String</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
    Quit:($L(myPathFile,"\")<=1)||(MandantOid="") 0
    Set xmlWriter=##class(%XML.Writer).%New()
    Set xmlWriter.Indent=1
    Set sc=xmlWriter.OutputToFile(myPathFile)
    Set:$$$ISOK(sc) sc=xmlWriter.RootElement("Daten")
    If $$$ISOK(sc) {
	    
	    // FormFuss
	    Set strSQL="SELECT ID FROM DBAgrofresh_SD.FormFuss WHERE Mandant ='"_MandantOid_"'"
		Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
		Do rs.Prepare(strSQL)
		Set sc=rs.Execute()
		IF $$$ISOK(sc) {
			While rs.Next(.sc) {
				Set oid=rs.Data("ID")
				w !,"Export DBAgrofresh.SD.FormFuss, ID:",oid
				Set myObj = ##class(DBAgrofresh.SD.FormFuss).%OpenId(oid)
				Set scObj=xmlWriter.Object(myObj)
				w "    ... ", $$$ISOK(scObj),!
				Do:$$$ISERR(scObj) $System.Status.DisplayError(scObj)
			}
		}
		
		// FormGebFuss
	    Set strSQL="SELECT ID FROM DBAgrofresh_SD.FormGebFuss WHERE Mandant ='"_MandantOid_"'"
		Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
		Do rs.Prepare(strSQL)
		Set sc=rs.Execute()
		IF $$$ISOK(sc) {
			While rs.Next(.sc) {
				Set oid=rs.Data("ID")
				w !,"Export DBAgrofresh.SD.FormGebFuss, ID:",oid
				Set myObj = ##class(DBAgrofresh.SD.FormGebFuss).%OpenId(oid)
				Set scObj=xmlWriter.Object(myObj)
				w "    ... ", $$$ISOK(scObj),!
				Do:$$$ISERR(scObj) $System.Status.DisplayError(scObj)
			}
		}
		
		// FormKopf
	    Set strSQL="SELECT ID FROM DBAgrofresh_SD.FormKopf WHERE Mandant ='"_MandantOid_"'"
		Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
		Do rs.Prepare(strSQL)
		Set sc=rs.Execute()
		IF $$$ISOK(sc) {
			While rs.Next(.sc) {
				Set oid=rs.Data("ID")
				w !,"Export DBAgrofresh.SD.FormKopf, ID:",oid
				Set myObj = ##class(DBAgrofresh.SD.FormKopf).%OpenId(oid)
				Set scObj=xmlWriter.Object(myObj)
				w "    ... ", $$$ISOK(scObj),!
				Do:$$$ISERR(scObj) $System.Status.DisplayError(scObj)
			}
		}
		
		// Formular
	    Set strSQL="SELECT ID FROM DBAgrofresh_SD.Formular WHERE Mandant ='"_MandantOid_"'"
		Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
		Do rs.Prepare(strSQL)
		Set sc=rs.Execute()
		IF $$$ISOK(sc) {
			While rs.Next(.sc) {
				Set oid=rs.Data("ID")
				w !,"Export DBAgrofresh.SD.Formular, ID:",oid
				Set myObj = ##class(DBAgrofresh.SD.Formular).%OpenId(oid)
				Set scObj=xmlWriter.Object(myObj)
				w "    ... ", $$$ISOK(scObj),!
				Do:$$$ISERR(scObj) $System.Status.DisplayError(scObj)
			}
		}
		
		// Drucktyp
	    Set strSQL="SELECT ID FROM DBAgrofresh_SD.Drucktyp WHERE Mandant ='"_MandantOid_"'"
		Set rs = ##class(%Library.ResultSet).%New("%DynamicQuery:SQL")
		Do rs.Prepare(strSQL)
		Set sc=rs.Execute()
		IF $$$ISOK(sc) {
			While rs.Next(.sc) {
				Set oid=rs.Data("ID")
				w !,"Export DBAgrofresh.SD.Drucktyp, ID:",oid
				Set myObj = ##class(DBAgrofresh.SD.Drucktyp).%OpenId(oid)
				Set scObj=xmlWriter.Object(myObj)
				w "    ... ", $$$ISOK(scObj),!
				Do:$$$ISERR(scObj) $System.Status.DisplayError(scObj)
			}
		}
    }
    Set sc=xmlWriter.EndRootElement()
    Do:$$$ISERR(sc) $System.Status.DisplayError(sc)
    Quit sc
]]></Implementation>
</Method>

<Method name="ExportXml">
<Description>
Exportiert ein Objekt mit allen seinen Abhängigkeiten und 
in Beziehung stehenden Klassen in ein XML-File.
ACHTUNG: die Klassen-OREF (ID) werden nicht ausgegeben</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>myPathFile:%String,myObj:%Persistent</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
    Quit:($L(myPathFile,"\")<=1)||(myObj="") 0
    Set xmlWriter=##class(%XML.Writer).%New()
    Set xmlWriter.Indent=1
    Set sc=xmlWriter.OutputToFile(myPathFile)
    Set:$$$ISOK(sc) sc=xmlWriter.RootElement("Daten")
    If $$$ISOK(sc) {
	    Set sc=xmlWriter.Object(myObj)
    }
    Set:$$$ISOK(sc) sc=xmlWriter.EndRootElement()
    Do:$$$ISERR(sc) $System.Status.DisplayError(sc)
    Quit sc
]]></Implementation>
</Method>

<Method name="ImportDrucktyp">
<ClassMethod>1</ClassMethod>
<FormalSpec>myfile:%String,oldMandantOid:%String,newMandantOid:%String</FormalSpec>
<Implementation><![CDATA[
    Kill ^XmlImportID
    Set ^XmlImportID("DBCore.Mandant",oldMandantOid)=newMandantOid
    
    //Set myNode=$P(myClass,".",$L(myClass,"."))
    Set status=##class(%XML.TextReader).ParseFile(myfile,.myXml)
    //check status
    If $$$ISERR(status) Do $System.Status.DisplayError(status) Quit
    //iterate through document, node by node
    Set myName=""
    While myXml.Read() {
	    Set myName=myXml.Name
	    If myName="FormFuss" {
		    w "---------",!
		    w "DBAgrofresh.SD.FormFuss",!
		    w "---------",!
			Do ..WriteNode(.myXml,myName,"DBAgrofresh.SD.FormFuss")
	    
	    } elseIf myName="FormGebFuss" {
			w "---------",!
		    w "DBAgrofresh.SD.FormGebFuss",!
		    w "---------",!
			Do ..WriteNode(.myXml,myName,"DBAgrofresh.SD.FormGebFuss")
	    
	    } elseIf myName="FormKopf" {
			w "---------",!
		    w "DBAgrofresh.SD.FormKopf",!
		    w "---------",!
			Do ..WriteNode(.myXml,myName,"DBAgrofresh.SD.FormKopf")
			
	    } elseIf myName="Formular" {
			w "---------",!
		    w "DBAgrofresh.SD.Formular",!
		    w "---------",!
			Do ..WriteNode(.myXml,myName,"DBAgrofresh.SD.Formular")
			
	    } elseIf myName="Drucktyp" {
			w "---------",!
		    w "DBAgrofresh.SD.Drucktyp",!
		    w "---------",!
			Do ..WriteNode(.myXml,myName,"DBAgrofresh.SD.Drucktyp")
		}
    }
    
    //Kill ^XmlImportID
]]></Implementation>
</Method>

<Method name="ImportXmlFile">
<ClassMethod>1</ClassMethod>
<FormalSpec>myfile:%String,myClass:%String</FormalSpec>
<Implementation><![CDATA[
    Kill ^XmlImportID
    Set myNode=$P(myClass,".",$L(myClass,"."))
    Set status=##class(%XML.TextReader).ParseFile(myfile,.myXml)
    //check status
    If $$$ISERR(status) Do $System.Status.DisplayError(status) Quit
    //iterate through document, node by node
    Set myName=""
    While myXml.Read() {
	    Set myName=myXml.Name
	    If myName=myNode {
		    Do ..WriteNode(.myXml,myName,myClass)
	    }
    }
    //Kill ^XmlImportID
]]></Implementation>
</Method>

<Method name="WriteNode">
<Description>
[Previously private]</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec><![CDATA[&myXml:%XML.TextReader,myNode:%String,myClass:%String]]></FormalSpec>
<Implementation><![CDATA[
	Set cdef=##Class(%Dictionary.ClassDefinition).%OpenId(myClass)
    Set prop=##Class(%Dictionary.PropertyDefinition).%New()
	Set myNode1=$P(myClass,".",$L(myClass,"."))
	Set myIndex="", myName="", myType="", myElement=""
	Set myID=0
	// Get ID and other ONE-Relations from Attribut
    If myXml.HasAttributes {
	    //======== Attribute auslesen ================================
	    Kill myAttrib  ;temp Array for Relations
	    // for each Attribut of Node (Lookup for ID and other Attributes)
	    For a=1:1:myXml.AttributeCount {
	    	Do myXml.MoveToAttributeIndex(a)
	        If myXml.Name="ID" {
		        Set myID=myXml.Value
	        } Else {
		        Set myAttrib(myXml.Name)=myXml.Value   ;myAttrib(AktMandant)=1 Store for the Attribute the old Relation-ID
	        }
	    }
	    //======== Attribute auslesen Ende ===========================
    }
    // if still imported or invalid ID...
    If $DATA(^XmlImportID(myClass,myID))||($Get(myID,0)=0) {
	    // read up to the end of this Node
	    While myXml.Read() {
		    Quit:(myXml.NodeType="endelement")&&(myNode1=myXml.Name) 
	    }
    } Else {
	    Set cls=$System.OBJ.New(myClass) ; new Object
    	While myXml.Read() {
		    Set myType=myXml.NodeType
		    //w "myType: ",myType,!
		    
		    // =========  Endelement =====================================================================
		    If (myType="endelement") {
			    // leaf, if this is the end-tag of Node
			    If (myXml.Name=myNode1) {
				    //w "Endelement ", myClass, !
					Do ..SaveImportedObject(myClass, .myID, .myAttrib, .cdef, .cls) 
				    Quit
			    }
			// ========= Element =====================================================================
		    } ElseIf (myType="element") {
			    Set myName=myXml.Name
			    Set myIndex=""
			    // Search for valid Property
			    Set pName=..LookupProperty(myName, .cdef, .prop, .pType)
			    // Only if this Property found...
			    If (pName=myName) {
				    Set mypType=pType
				    If prop.Relationship {
					    //w "Element: ", myClass, !
						Do ..SaveImportedObject(myClass, .myID, .myAttrib, .cdef, .cls)
						Set myNode2=$P(pType,".",$L(pType,"."))
					    // For each (Record) Object
					    While myXml.Read() {
						    // If Node = related class
						    // Read Object (Sub-Class)
					    	Do:(myXml.NodeType="element")&&(myNode2=myXml.Name) ..WriteNode(.myXml,myName,pType) ; recursive call
						    // exit While, when current node=End and if it has the same name as the node of Relation
						    Quit:(myXml.NodeType="endelement")&&(myName=myXml.Name) 
					    }
				    } else {
					    // store Name of Property as Element
		            	Set myElement=myName
			        }
			    
			    } ElseIf (myXml.HasAttributes)&&(myElement_"Item"=myName_"") {
				    //w "If Node is an Array-Value of an Element...",!
				    //w "store the attribute for this array-Element node",!
				    For a=1:1:myXml.AttributeCount {
				    	Do myXml.MoveToAttributeIndex(a)
				        Set myIndex=myXml.Value
				    }
				} Else {
					//w "no Property or Array of Property found...",!
		            //w "it could not be a valid Element",!
			        Set myElement=""
		        }
		    // ========= Value =====================================================================
		    } ElseIf (myType="chars") {
			    // Only if valid Element found...
			    If ($L(myElement)'=0) {
				    // read Value
				    Set myValue=myXml.Value
				    // translate Boolean
			     	If ((mypType="%Boolean")||(mypType="%Library.Boolean")) {
				     	// lookup for the Property of this Element
					    Set myValue=("true"[myValue)
					} ElseIf ((mypType="%Library.Date")||(mypType="%Date")) {
						Set myValue=$ZDATEH(myValue,3)
					}
					If ($L(myIndex)'=0) {
						/*
						w "cls: ",cls,!
						w "myElement: ",myElement,!
						w "myValue: ",myValue,!
						w "myIndex: ",myIndex,!
						*/
					 	// Add Array-Value
						Do $METHOD($PROPERTY(cls, myElement), "SetAt", myValue, myIndex)
					} Else {
						// Add Value
						Set $PROPERTY(cls, myElement)=myValue
					}
					Set myIndex=""
			    }
		    }
	    }
    }
]]></Implementation>
</Method>

<Method name="SaveImportedObject">
<Description>
[Previously private]</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec><![CDATA[myClass:%String,&myID:%Integer,&myAttrib,&cdef:%Dictionary.ClassDefinition,&cls:%CacheObject]]></FormalSpec>
<Implementation><![CDATA[
    // Set Relations
    If $DATA(myAttrib)&&(myID'=0) {
		Set key=$Order(myAttrib("")) ;Get the first Index (i.e. "AktMandant")
		// For each ONE-Relation
	    While (key'="") {
		    w "SaveImportedObject - Key: ", key, !
		    // Search for Property-Definition (search for the Relation)
		    Set pName=..LookupProperty(key,.cdef,.prop,.pType)
		    /*
		    w "SaveImportedObject - pName: ", pName, !
		    w "SaveImportedObject - pType: ", pType, !
		    w "SaveImportedObject - myAttrib(key): ", myAttrib(key), !
		    
		    // Save new Relation / prop.Type = Full-Class-Name (i.e. DBCore.Mandant)
		    w "SaveImportedObject - ID: ", ^XmlImportID(pType, myAttrib(key)), !
		    */
		    Set:(pName=key) $PROPERTY(cls, key)=$System.OBJ.OpenId(pType,^XmlImportID(pType, myAttrib(key)))
		    // look up next
	     	Set key=$Order(myAttrib(key))
	    }
    } ;-- End set Relations
    // Save new Object
    Set sc=cls.%Save()
    w "Save von Klasse: "_myClass
    If $$$ISERR(sc) {
	    Do $System.Status.DisplayError(sc) 
	    Quit
    }
    w " ... OK",!
    // Store reference to new ID
    Quit:(myID=0)
    
    w "Set ^XmlImportID(", myClass, ",", myID, ")", !		    
	Set ^XmlImportID(myClass,myID)=cls.%Id(), myID=0
]]></Implementation>
</Method>

<Method name="LookupProperty">
<Description>
[Previously private]</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec><![CDATA[myName:%String,&cdef:%Dictionary.ClassDefinition,&prop:%Dictionary.PropertyDefinition,&pType:%String]]></FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
    Set pName="", cnt=cdef.Properties.Count()
    For i=1:1:cnt {
    	Set prop=cdef.Properties.GetAt(i)
    	Set pType=prop.Type
    	Set pName=prop.Name
    	// Stop when found
    	Quit:pName=myName
    }
    // if not found: check also the super classes
    If (pName'=myName) {
		For s=1:1:$L(cdef.Super,",") {
			Set sub=$P(cdef.Super,",",s)
			If ($E(sub)'="%") {
		    	Set scdef=##class(%Dictionary.ClassDefinition).%OpenId(sub)
			    For i=1:1:scdef.Properties.Count() {
			    	Set prop=scdef.Properties.GetAt(i)
			    	Set pType=prop.Type
			    	Set pName=prop.Name
			    	// Stop when found
			    	Quit:pName=myName
			    }
		    }
	    }
    	//Kill scdef
    }
    Quit pName
]]></Implementation>
</Method>

<Method name="ExportHilfe">
<ClassMethod>1</ClassMethod>
<FormalSpec>filename:%String</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
	
	Quit:($L(filename,"\")<=1) 0
	
	set error = ""
	
	set globalStr = ..GetHilfeGlobalString()
	
	//export Feldhilfe
	set sc = $system.OBJ.Export(globalStr, .filename, "", .error, "")
	Quit sc
]]></Implementation>
</Method>

<Method name="ImportHilfe">
<ClassMethod>1</ClassMethod>
<FormalSpec>filename:%String</FormalSpec>
<ReturnType>%Status</ReturnType>
<Implementation><![CDATA[
	Quit:($Length(filename)=0)
	
	//first delete old globals
	do ##class(DBCore.FeldhilfeFeld).%DeleteExtent()
	do ##class(DBCore.FeldhilfeStream).%DeleteExtent()
	do ##class(DBCore.HelpMenuEntry).%DeleteExtent()
	
	//import globals
	set globalStr = ..GetHilfeGlobalString()
	set sc = $system.OBJ.Load(filename,"",.error,.loaded,$$$NO,globalStr,"","")
	do ..ReindexHilfeGlobals()
	
	Quit sc
]]></Implementation>
</Method>

<Method name="GetHilfeGlobalString">
<Description>
[Previously private]</Description>
<ClassMethod>1</ClassMethod>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
	
	set feldhilfeCName = ##class(DBCore.FeldhilfeFeld).%PackageName()_"."_ 
					   	 ##class(DBCore.FeldhilfeFeld).%ClassName() _ ..#GLOBALENDING
	set feldhilfeStreamCName = ##class(DBCore.FeldhilfeStream).%PackageName()_"."_
							   ##class(DBCore.FeldhilfeStream).%ClassName() _ ..#GLOBALENDING
	set feldhilfeStreamDataCName = ##class(DBCore.FeldhilfeStream).%PackageName()_"."_
							   ##class(DBCore.FeldhilfeStream).%ClassName() _ ..#STREAMGLOBALENDING
	set helpMnuCName = ##class(DBCore.HelpMenuEntry).%PackageName()_"."_ 
					   	 ##class(DBCore.HelpMenuEntry).%ClassName() _ ..#GLOBALENDING
					   	 
	Quit (feldhilfeCName_","_feldhilfeStreamCName_","_feldhilfeStreamDataCName_","_helpMnuCName)
]]></Implementation>
</Method>

<Method name="ReindexHilfeGlobals">
<ClassMethod>1</ClassMethod>
<Implementation><![CDATA[

	do ##class(DBCore.FeldhilfeFeld).%PurgeIndices()	
	do ##class(DBCore.FeldhilfeFeld).%BuildIndices()
	
	do ##class(DBCore.FeldhilfeStream).%PurgeIndices()	
	do ##class(DBCore.FeldhilfeStream).%BuildIndices()
	
	do ##class(DBCore.HelpMenuEntry).%PurgeIndices()	
	do ##class(DBCore.HelpMenuEntry).%BuildIndices()
]]></Implementation>
</Method>
</Class>


<Class name="DBUtils.LicenseUtils">
<Super>%RegisteredObject</Super>
<TimeChanged>61473,42681.512247</TimeChanged>
<TimeCreated>61473,32041.195746</TimeCreated>

<Method name="GetKeyCustomerName">
<ClassMethod>1</ClassMethod>
<ReturnType>%String</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[      quit ##class(%SYSTEM.License).KeyCustomerName()
]]></Implementation>
</Method>

<Method name="GetKeyExpirationDate">
<ClassMethod>1</ClassMethod>
<ReturnType>%Date</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[      quit ##class(%SYSTEM.License).KeyExpirationDate()
]]></Implementation>
</Method>

<Method name="GetKeyLicenseType">
<ClassMethod>1</ClassMethod>
<ReturnType>%String</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[      quit ##class(%SYSTEM.License).KeyLicenseType()
]]></Implementation>
</Method>

<Method name="GetKeyLicenseUnits">
<ClassMethod>1</ClassMethod>
<ReturnType>%Integer</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[      quit ##class(%SYSTEM.License).KeyLicenseUnits()
]]></Implementation>
</Method>

<Method name="GetKeyMachineID">
<ClassMethod>1</ClassMethod>
<ReturnType>%String</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[      quit ##class(%SYSTEM.License).KeyMachineID()
]]></Implementation>
</Method>

<Method name="GetKeyOrderNumber">
<ClassMethod>1</ClassMethod>
<ReturnType>%String</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[      quit ##class(%SYSTEM.License).KeyOrderNumber()
]]></Implementation>
</Method>

<Method name="GetKeyPlatform">
<ClassMethod>1</ClassMethod>
<ReturnType>%String</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[      quit ##class(%SYSTEM.License).KeyPlatform()
]]></Implementation>
</Method>

<Method name="GetKeyProduct">
<ClassMethod>1</ClassMethod>
<ReturnType>%String</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[      quit ##class(%SYSTEM.License).KeyProduct()
]]></Implementation>
</Method>

<Method name="GetVersion">
<ClassMethod>1</ClassMethod>
<ReturnType>%String</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[
	// Format 4 - Product (Platform) Version (Build) 
	quit ##class(%SYSTEM.Version).Format(4)
]]></Implementation>
</Method>

<Method name="GetVersionIs64Bits">
<ClassMethod>1</ClassMethod>
<ReturnType>%Boolean</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[	quit ##class(%SYSTEM.Version).Is64Bits()
]]></Implementation>
</Method>

<Method name="GetVersionIsSingleUser">
<ClassMethod>1</ClassMethod>
<ReturnType>%Boolean</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[	quit ##class(%SYSTEM.Version).IsSingleUser()
]]></Implementation>
</Method>
</Class>


<Class name="DBUtils.NumberUtils">
<Super>%RegisteredObject</Super>
<TimeChanged>62235,33066.391256</TimeChanged>
<TimeCreated>61577,32797.760497</TimeCreated>

<Method name="Round">
<Description>
Rundet die übergebene zahl auf die Anzahl Nachkomastellen welche
durch anzStellen übergeben werden. Bsp, value 1.567 und anzStellen 2 = 1.57</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>value:%Decimal,anzStellen:%Integer</FormalSpec>
<ReturnType>%Decimal</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[    Quit $NORMALIZE(value,anzStellen)
]]></Implementation>
</Method>

<Method name="RoundGemEinst">
<Description>
Rundet die übergebene zahl auf die Anzahl Nachkomastellen welche
durch anzStellen übergeben werden. Bsp, value 1.567 und anzStellen 2 = 1.57</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>mandOid:%String,value:%Decimal</FormalSpec>
<ReturnType>%Decimal</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[
	set einst = ##class(DBCore.MandantEinstellung).GetShortEinst(mandOid, ##class(DBCore.Konst).STAMMDATENSTAMMRUNDUNG())
	
    Quit ##class(DBUtils.NumberUtils).RoundWithEinst(einst, value)
]]></Implementation>
</Method>

<Method name="RoundWithEinst">
<Description>
Rundet die übergebene zahl auf die Anzahl Nachkomastellen welche
durch anzStellen übergeben werden. Bsp, value 1.567 und anzStellen 2 = 1.57</Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>einst:%Integer,value:%Decimal</FormalSpec>
<ReturnType>%Decimal</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[
	//Rundung auf Rappen
	if (einst = ##class(DBCore.Konst).RUNDUNG1()) {
    	Quit ##class(DBUtils.NumberUtils).Round(value,2)
    	
	//Rundung auf 5Rappen
	} elseif (einst = ##class(DBCore.Konst).RUNDUNG5()) {
    	Quit ##class(DBUtils.NumberUtils).RoundWithFaktor(value,20)
    	
	//Rundung auf Franken
	} elseif (einst = ##class(DBCore.Konst).RUNDUNG1FR()) {
    	Quit ##class(DBUtils.NumberUtils).Round(value,0)
	}
]]></Implementation>
</Method>

<Method name="RoundWithFaktor">
<Description><![CDATA[
Rundet den Wert auf die gewünschten Anzahl Stellen 
<param name="wert">zu rundenden Wert</param>
<param name="faktor">Faktor (1 = 0 Stellen, 10 = 1 Stelle, 100 = 2 Stellen, usw., 0.1 = 10er, 0.01 = 100er, usw.</param>
<returns>gerundeter Wert</returns>
[Previously private]]]></Description>
<ClassMethod>1</ClassMethod>
<FormalSpec>wert:%Decimal,faktor:%Integer</FormalSpec>
<ReturnType>%Decimal</ReturnType>
<Implementation><![CDATA[
	set wertFaktor = wert * faktor
	if (wert >= 0) {
		set wertFaktor = wertFaktor + 0.5
	} else {
		set wertFaktor = wertFaktor - 0.5
	}
	set abgeschnitten = $P(wertFaktor, ".",1)
    Quit abgeschnitten / faktor
]]></Implementation>
</Method>

<Method name="GetBetragEWbyWaehrung">
<ClassMethod>1</ClassMethod>
<FormalSpec>wert:%Decimal,waehrung:DBFibu.SD.Fremdwaehrung</FormalSpec>
<ReturnType>%Decimal</ReturnType>
<Implementation><![CDATA[
	if (waehrung = "") {
		quit 0
	}
	quit ##class(DBUtils.NumberUtils).GetBetragEW(wert, waehrung.KursVK, waehrung.Faktor)
]]></Implementation>
</Method>

<Method name="GetBetragEW">
<ClassMethod>1</ClassMethod>
<FormalSpec>wert:%Decimal,kurs:%Decimal,faktor:%Decimal</FormalSpec>
<ReturnType>%Decimal</ReturnType>
<Implementation><![CDATA[
	if (faktor = 0) {
		set faktor = 1
	}
	set ew = ##class(DBUtils.NumberUtils).Round(((wert * kurs) / faktor), 2)
	quit ew
]]></Implementation>
</Method>

<Method name="GetBetragFWbyWaehrung">
<ClassMethod>1</ClassMethod>
<FormalSpec>wert:%Decimal,waehrung:DBFibu.SD.Fremdwaehrung</FormalSpec>
<ReturnType>%Decimal</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[
	if ((waehrung = "") || (waehrung = $c(0))) {
		quit 0
	}
	quit ##class(DBUtils.NumberUtils).GetBetragFW(wert, waehrung.KursVK, waehrung.Faktor)
]]></Implementation>
</Method>

<Method name="GetBetragFW">
<ClassMethod>1</ClassMethod>
<FormalSpec>wert:%Decimal,kurs:%Decimal,faktor:%Decimal</FormalSpec>
<ReturnType>%Decimal</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[
	if (kurs = 0) || (faktor = 0) || (kurs = "") || (kurs = $c(0)) {
		quit 0
	}
	set fw =  ##class(DBUtils.NumberUtils).Round(((wert / kurs) * faktor),2)
	quit fw
]]></Implementation>
</Method>

<Method name="GenerateSSCC">
<ClassMethod>1</ClassMethod>
<FormalSpec>gcp:%String,ssccPart:%String</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
			set retval = ""
			set checkValue = 0
			if (gcp '= "") {
				if ($L(gcp) = 9) {
					set retval = $Extract(gcp,1,9)
					while ($L(retval) '= 9) {
						set retval = retval_"0"
					}
					set retval = "3"_retval

					set sscc = $Extract(ssccPart, 1,7)
					while ($L(sscc) '= 7) {
						set sscc = "0"_sscc
					}
				} elseif ($L(gcp) = 11) {
					set retval = $Extract(gcp,1,11)
					while ($L(retval) '= 11) {
						set retval = retval_"0"
					}
					set retval = "3"_retval

					set sscc = $Extract(ssccPart, 1,5)
					while ($L(sscc) '= 5) {
						set sscc = "0"_sscc
					}
				}
				
				set retval = retval_sscc

				if ($L(retval) '= 17) {
					w "Die SSCC ist nicht 17 Zeichen lange. Nr: "_retval,!
				}


				///Prüffzifferberechnen
				for i = 0:1:17 {
					set digits(i) = $Extract(retval, i, i)
				}
								
				set checkValue = 10 - ((((digits(1) + digits(3) + digits(5) + digits(7)
					+ digits(9) + digits(11) + digits(13) + digits(15) + digits(17)) * 3) + (digits(2) + digits(4) + digits(6)
					+ digits(8) + digits(10) + digits(12) + digits(14) + digits(16))) # 10)
				

				if (checkValue = 10) {
					set checkValue = 0
				}

			} else {
				set retval = "00000000000000000"
			}

		
			set retval = retval_checkValue
			

			quit retval
]]></Implementation>
</Method>
</Class>


<Project name="DBUtils" Target="##class(%SYSTEM.SQL).TuneTable()" TargetType="2">
  <Items>
    <ProjectItem name="DBUtils.ClassHelper" type="CLS"></ProjectItem>
    <ProjectItem name="DBUtils.CspCompileTask" type="CLS"></ProjectItem>
    <ProjectItem name="DBUtils.DateTime" type="CLS"></ProjectItem>
    <ProjectItem name="DBUtils.DateUtils" type="CLS"></ProjectItem>
    <ProjectItem name="DBUtils.Dev" type="CLS"></ProjectItem>
    <ProjectItem name="DBUtils.Duration" type="CLS"></ProjectItem>
    <ProjectItem name="DBUtils.ImpExp" type="CLS"></ProjectItem>
    <ProjectItem name="DBUtils.LicenseUtils" type="CLS"></ProjectItem>
    <ProjectItem name="DBUtils.NumberUtils" type="CLS"></ProjectItem>
    <ProjectItem name="DBUtils.StringUtils" type="CLS"></ProjectItem>
  </Items>
</Project>


<Class name="DBUtils.StringUtils">
<Super>%RegisteredObject</Super>
<TimeChanged>62186,34321.657941</TimeChanged>
<TimeCreated>61348,62509.275683</TimeCreated>

<Method name="GetText">
<ClassMethod>1</ClassMethod>
<FormalSpec>text:%ArrayOfDataTypes,lang:%String,MandOid:%String</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
	Set res = ""
	if (text'="") {
		Set res = text.GetAt(lang)
			if ((res="")|| (res = $c(0))) {	
			if (MandOid'="") {
				Set lang=##Class(DBCore.Mandant).GetSprachcode(MandOid)
				Set res = text.GetAt(lang)
			}
			
			if ((res="")|| (res = $c(0))) {	
				Set res = text.GetNext()
			}
		}
	}
	Quit res
]]></Implementation>
</Method>

<Method name="GetExactLangText">
<ClassMethod>1</ClassMethod>
<FormalSpec>Text:%ArrayOfDataTypes,Lang:%String</FormalSpec>
<ReturnType>%String</ReturnType>
<Implementation><![CDATA[
	Set res = ""
	if (Text'="") {
		Set res = Text.GetAt(Lang)
	}
	Quit res
]]></Implementation>
</Method>

<Method name="SetText">
<ClassMethod>1</ClassMethod>
<FormalSpec><![CDATA[&texte:%ArrayOfDataTypes,newText:%String,lang:%String,MandOid:%String]]></FormalSpec>
<Implementation><![CDATA[
	if (lang'="") {
		do texte.SetAt(newText, lang)
		
		Set result=##class(%ResultSet).%New("%DynamicQuery:SQL")
		Set sc=result.Prepare("SELECT Sprachkey FROM DBCore.MandantSprache WHERE Mandant = ?")
		Set sc=result.Execute(MandOid)
		While result.Next(.sc) {
			Set key = result.Data("Sprachkey")
			if (texte.GetAt(key)="") {
				do texte.SetAt(newText, key)
			}
		}
	}
]]></Implementation>
</Method>

<Method name="StripPhoneNumber">
<ClassMethod>1</ClassMethod>
<FormalSpec>number:%String</FormalSpec>
<ReturnType>%String</ReturnType>
<SqlProc>1</SqlProc>
<Implementation><![CDATA[	Quit $ZSTRIP(number, "*P")
]]></Implementation>
</Method>
</Class>
</Export>
