#include %VHMacro #include %occInclude ValidatePR() ; Parameters: arValidPR New Key,DItem New okPR ;d WL^vhDBG($$$ArrayTT3("Prod.LU(""PL"")",%this,"LookUp")) Set okPR=1 Kill arValidPR Set Key="" For Set DItem=..DataItems.GetNext(.Key) Quit:(Key="") Do:(DItem.IsActief()) . If DItem.ValidatePR() Do .. Set arValidPR(1,Key)="" . Else Do .. Set arValidPR(0,Key)="" ; DItem.Get("PRNr") .. Set okPR=0 Quit okPR /* OnBeforeSave() ; Parameters: IsNew Quit $$$OK */ TTrace ; Parameters: Msg #define Prefix "GAProd: " #define Prefix2 "" Do WL^vhDBG($$$Prefix_$G(Msg)) ;Do WLS^vhDBG($$$Prefix2_$G(Msg),1) Quit ClearDataParams ; Parameters: ClearMode New Key,DItem Set Key="" For Set DItem=..DataItems.GetNext(.Key) Quit:(Key="") Do DItem.ClearDataParams(.ClearMode) Quit UseTurbo() Quit 0 AutosFromTemplate ; Parameters: Templ,Action #define IsTemplateProduct $IsObject(..Template) Quit:($$$IsTemplateProduct) If Action="CLEAR" Do Quit . Do aftClearDAutos Set:('$G(Templ)) Templ=..TemplateTmp If (Action="FILL")&&($IsObject(Templ)) Do . Do aftClearDAutos . Quit:('$IsObject(Templ.Product)) . New PKey,IKey,TPDItem,DItem,TPAuto . Set IKey="" . For Set DItem=..DataItems.GetNext(.IKey) Quit:(IKey="") Do .. Set TPDItem=Templ.Product.DataItemsGetChildAt(DItem.Code) .. Quit:('$IsObject(TPDItem)) .. Set PKey="" .. For Set TPAuto=TPDItem.Autos.GetNext(.PKey) Quit:(PKey="") Do DItem.Autos.SetAt(TPAuto,PKey) /* . For Set TPDItem=Templ.Product.DataItems.GetNext(.IKey) Quit:(IKey="") Do .. Set DItem=..DataItemsGetChildAt(TPDItem.Code) .. Quit:('$IsObject(DItem)) .. Set PKey="" .. For Set TPAuto=TPDItem.Autos.GetNext(.PKey) Quit:(PKey="") Do DItem.Autos.SetAt(TPAuto,PKey) */ Quit aftClearDAutos New IKey,DItem Set IKey="" For Set DItem=..DataItems.GetNext(.IKey) Quit:(IKey="") Do DItem.Autos.Clear() Quit UpdateLookUp ; Parameters: Node,arItems ; Update de waarden voor de Items in de gegeven Node van ..LookUp #define NodePL "PL" Quit:($G(Node)'="PL") New i,iP,DItem,MParam ;,ParamVal Set i="" For Set i=$O(arItems(i)) Quit:(i="") Do . Set DItem=arItems(i) . Set iP="" . For Set MParam=DItem.MetaItem.Parameters.GetNext(.iP) Quit:(iP="") Do:(iP?1"ProgLabel".E) .. ;d ..TTrace(DItem.Code_" UpdateLU Begin "_DItem.Get(iP)_" iP="_iP) .. Set %this.LookUp($$$NodePL,DItem.Get(iP))=DItem.EvalMetaAuto(iP) ; Waarde v/e ProgLabel steeds via MetaExec (MParam.Auto) .. ;d ..TTrace("UpdateLU End") Quit UpdateLookUpClean ; Parameters: Node,arItems ; Verwijder de waarden van de Items uit de gegeven Node van ..LookUp #define NodePL "PL" Quit:($G(Node)'="PL") New i,iP,DItem,MParam ;,ParamVal ;For i=1:1:$LL(lbItems) Do ;. Set DItem=$LI(lbItems,i) Set i="" For Set i=$O(arItems(i)) Quit:(i="") Do . Set DItem=arItems(i) . Set iP="" . For Set MParam=DItem.MetaItem.Parameters.GetNext(.iP) Quit:(iP="") Do:(iP?1"ProgLabel".E) .. Kill ..LookUp($$$NodePL,DItem.Get(iP)) Quit CalcAll ; Parameters: (geen) #define DEP "DEP" #define GroepID "TB" #define Recalc 1 New arTree,arSort,iG,iS,iI,DItem,SGCode d StartTimer^vhLib Do ..ClearDataParams($$$Recalc) Kill ..Cumuls d WLFMT^vhDBG("Na Clear ParamData : "_$$RestartTimer^vhLib,"B") Do ..BuildTreeDeps("arTree") d WL^vhDBG("Na BuildTreeDeps : "_$$RestartTimer^vhLib) Set iG="" For Set iG=$O(arTree($$$DEP,iG)) Quit:(iG="") Do . Set iS="" . For Set iS=$O(arTree($$$DEP,iG,iS)) Quit:(iS="") Do .. Set iI="" .. For Set iI=$O(arTree($$$DEP,iG,iS,iI)) Quit:(iI="") Do ... Set DItem=arTree($$$DEP,iG,iS,iI) ... Do DItem.CalcAll() ... Do:(DItem.IsActief()) calCumuls ;. d WL^vhDBG("Na Groep "_iG_" : "_$$RestartTimer^vhLib) d WL^vhDBG("Na CalcAll : "_$$RestartTimer^vhLib) ;merge cumul=..Cumuls ;d WL^vhDBG("Cumuls : "_$$ArrayToText^vhLib("cumul")) ;d WL^vhDBG("arTree : "_$$ArrayToText^vhLib("arTree")) Quit calCumuls Quit:(DItem.MetaItem.Code["PARAM") New Key,Val For Key="KPrijs","TijdWerk","TijdKost","GNetto","GTarra" Do:(DItem.MetaItem.Parameters.IsDefined(Key)) . Set Val=DItem.Get(Key) . ;Quit:(Val="") . Set ..Cumuls(Key,iG,iS,iI)=Val . Set ..Cumuls(Key,iG,iS)=$G(..Cumuls(Key,iG,iS))+Val . Set ..Cumuls(Key,iG)=$G(..Cumuls(Key,iG))+Val . Set ..Cumuls(Key)=$G(..Cumuls(Key))+Val Quit CalcKostAll() ; Parameters: Aantal Quit $G(..Cumuls("KPrijs")) BuildHierarch ; Parameters: Ref Do:(..MetaStruct) ..MetaStruct.BuildHierarch(Ref,%this) Quit BuildTreeDeps ; Parameters: Ref #define DEP "DEP" Kill @Ref Kill ..arTree($$$DEP) Quit:('..MetaStruct) New tmpAr New iG,iS,iI,MetaHG,MetaG,MetaS,MetaI,DItem,Key New PKey,PrmVal,MParam,tmpLB,i ;Do %this.BuildLookUp() Do %this.BuildLookUp($LB("SG","ICode","ISort")) Set MetaHG=..MetaStruct Set Key="" For Set DItem=..DataItems.GetNext(.Key) Quit:(Key="") Do . Quit:(DItem.SubGroepCode="") . Set MetaI=DItem.MetaItem . Set MetaS=$G(..LookUp("SG",DItem.SubGroepCode)) ; $LG( ... ,1) . Set MetaG=MetaS.Groep ; $G(..LookUp("SG",DItem.SubGroepCode,"GR")) . Set iI=DItem.VolgNr . Set iS=$LF($$btd2ExprToList(MetaG.ChildExpr),MetaS.Code) . Set iG=$LF($$btd2ExprToList(MetaHG.ChildExpr),MetaG.Code) . Set tmpAr($$$DEP,iG,iS,iI)=DItem . Set tmpAr($$$DEP,iG,iS)=MetaS . Set tmpAr($$$DEP,iG)=MetaG Merge @Ref=tmpAr Merge %this.arTree=tmpAr Quit btd2ExprToList(sExpr) ; Convert Child Expression to $LB() Set tmpLB="" For i=1:1:$L(sExpr,"+") Set tmpLB=tmpLB_$LB($P(sExpr,"+",i)) Quit tmpLB BuildTreeData ; Parameters: Ref,blnShowPrijs #define DATA 1 #define OBJ "OBJ" #define FMT "FMT" #define ShowValueIf(%cond,%val,%else) $S(%cond:%val ,1:%else) Kill @Ref Kill ..arTree($$$DATA) Kill ..arTree($$$OBJ) Kill ..arTree($$$FMT) Quit:('..MetaStruct) New tmpAr,tmpAr2 New iG,iS,iI,MetaHG,MetaG,MetaS,MetaI,DItem,Key New PKey,PrmVal,MParam,tmpLB,i,iK Do %this.BuildLookUp() Set MetaHG=..MetaStruct Set tmpAr($$$DATA)=$LB(MetaHG.Omschrijving) Set Key="" ;d CLS^vhDBG ;d ..TTrace($$ArrayToText^vhLib("%this.LookUp")) For Set DItem=..DataItems.GetNext(.Key) Quit:(Key="") Do . Quit:('DItem.IsActief(0)) . Quit:(DItem.SubGroepCode="") . Set MetaI=DItem.MetaItem . Set MetaS=$G(..LookUp("SG",DItem.SubGroepCode)) ; $LG( ... ,1) . Set MetaG=MetaS.Groep . Set iI=DItem.VolgNr . Set iS=$LF($$btdExprToList(MetaG.ChildExpr),MetaS.Code) . Set iG=$LF($$btdExprToList(MetaHG.ChildExpr),MetaG.Code) . Set tmpAr($$$DATA,iG)=$LB(MetaG.Omschrijving,+$J($G(..Cumuls("TijdWerk",iG)),0,2),$$$ShowValueIf(blnShowPrijs,+$J($G(..Cumuls("KPrijs",iG)),0,6),"")) . Set tmpAr($$$DATA,iG,iS)=$LB(MetaS.Omschrijving,+$J($G(..Cumuls("TijdWerk",iG,iS)),0,2),$$$ShowValueIf(blnShowPrijs,+$J($G(..Cumuls("KPrijs",iG,iS)),0,6),"")) . ;Set:(iI="") iI="999" . Do btdBuildColumnData . Do btdBuildKostDtls . Set tmpAr($$$FMT,iG,iS,iI)=$LB(MetaI.RijFormat) . Set tmpAr2("OREF",iG,iS,iI)=DItem Merge @Ref=tmpAr Merge @Ref=tmpAr2 Merge ..arTree=tmpAr Quit btdExprToList(sExpr) ; Convert Child Expression to $LB() Set tmpLB="" For i=1:1:$L(sExpr,"+") Set tmpLB=tmpLB_$LB($P(sExpr,"+",i)) Quit tmpLB btdBuildColumnData Set tmpLB="" ;d:(DItem.Code="PRKENM001") ..TTrace("Begin ColumnData") Set PKey="" For Set MParam=MetaI.Parameters.GetNext(.PKey) Quit:(PKey="") Do:(MParam.ShowInTree'="") . Set $LI(tmpLB,MParam.KolomNr)=$$$ShowValueIf(blnShowPrijs||(PKey'="KPrijs"),DItem.Get(PKey),"") For i=$LL(tmpLB):-1:1 $$$DoLBDeleteAtIf('$LD(tmpLB,i),tmpLB,i) ; Lege ListItems verwijderen ; OLD: Set:('$LD(tmpLB,i)) tmpLB=$$$LBDeleteAt(tmpLB,i) Set tmpAr($$$DATA,iG,iS,iI)=tmpLB ;d:(DItem.Code="PRKENM001") ..TTrace("End ColumnData") Quit btdBuildKostDtls #define KDelim "-" #define NOT(%v) '(%v) New ChildID,Templ,TPDItem,KostArray,KKey,MKost,lbIDs,KeyKDtl ; ,blnDtlExist,blnDtlOther ; ,blnLoopList New KeyBegin,LoopID,Num,FirstSpace Set ChildID=DItem.Code Set Templ=DItem.Product.TemplateTmp ;Quit:('Templ) "" Set TPDItem=Templ.Product.DataItemsGetChildAt(ChildID) ;Quit:('TPDItem) "" Do btdKostDtlData("T",$$$KDelim_ChildID) Do btdKostDtlData("M",$$$KDelim_ChildID) Quit btdKostDtlData(KostType,LoopKey) #define NumWithZeros(%v) $TR($J(%v,3)," ","0") #define StartsWith(%T,%t) ($P(%T_" ",%t,1)="") #define LoopKostArray Set MKost=KostArray.GetNext(.KKey) Quit:(KKey="") #define AddWaarde(%i,%v) $$btdAddValToText($LG($G(arKDtl(KeyKDtl)),%i),%v) #define KOms MKost.Omschrijving #define KMulti MKost.Multiplicant #define KReduc MKost.Reductie #define KPropts MKost.KostPlaatsGetObjectId(),MKost.AParam,MKost.BParam,MKost.Min,MKost.StaffelMin,MKost.StaffelMax ; Debug: waarden van Multiplic, Reduct en totaal toevoegen #define KOmsX $$$AddWaarde(1,MKost.Omschrijving) #define KMultiX $$$AddWaarde(2,MKost.Multiplicant) #define KReducX $$$AddWaarde(3,MKost.Reductie) #define LoopID $S($L(LoopID):"i="_$E(LoopID,1,5)_" ",1:FirstSpace) #define blnNoOtherDtls ('$$$StartsWith($O(arKDtl(KeyKDtl)),KeyKDtl)) Set KKey="" Set KostArray=$S(KostType="M":TPDItem.KostMat, 1:TPDItem.KostTijd) ; Materiaal of Tijd - array of objects If 'blnShowPrijs Do . For $$$LoopKostArray Do .. Set tmpAr($$$DATA,iG,iS,iI,MKost.VolgNr)=$LB($$$KOms,KKey,KostType,$$$KMulti,$$$KReduc,$$$KPropts) Else Do ; Show Dtls met Prijs . Set FirstSpace="" . For $$$LoopKostArray Do .. Set KeyKDtl=KKey_LoopKey .. Set:($L($G(arKDtl(KeyKDtl))))||($$$blnNoOtherDtls) tmpAr($$$DATA,iG,iS,iI,MKost.VolgNr)=$LB($$$KOmsX,KKey,KostType,$$$KMultiX,$$$KReducX,$$$KPropts) .. Quit:($$$blnNoOtherDtls) .. ; Else Do ; KostParams worden herhaald binnen het DItem .. Set KeyBegin=KeyKDtl .. For Set KeyKDtl=$O(arKDtl(KeyKDtl)) Quit:('$$$StartsWith(KeyKDtl,KeyBegin)) Do ... Set LoopID=$P($P(KeyKDtl,LoopKey_"#",2),$$$KDelim,2) ... Set Num=$$$TextBetween(KeyKDtl,LoopKey_"#",$$$KDelim) ... Set Num=$S($IsValidNum(Num):+(Num_"."_$$$NumWithZeros(MKost.VolgNr)), 1:MKost.VolgNr) ... Set tmpAr($$$DATA,iG,iS,iI,Num)=$LB($$$LoopID_$$$KOmsX,KKey,KostType,$$$KMultiX,$$$KReducX,$$$KPropts) .. Set FirstSpace=" " Quit btdAddValToText(Val,Text) Quit $S(('$IsValidNum(Text)&&($L(Val))):"["_(+$J(Val,0,4))_"] ", 1:"")_Text NewDataItem() ; Parameters: MetaItem,SGCode,Code,VolgNr ; Create new DataItem New DItem Set DItem=##class(Prod.GAData.Item).%New() Set DItem.Product=%this Do DItem.%Close() Set:(+MetaItem) DItem.MetaItem=MetaItem Set:($L($G(SGCode))) DItem.SubGroepCode=SGCode Set DItem.Code=$S($L($G(Code)):Code, 1:DItem.CalcCode()) ; Code v/h DataItem (==> OId): Set DItem.VolgNr=$S($G(VolgNr)>0:VolgNr, 1:DItem.CalcVolgNr()) ; VolgNr v/h DataItem: Do %this.BuildLookUp($LB("ISort")) Quit DItem CopyItemsFromProduct ; Parameters: Prod,ItemsCopyMode Quit:('$G(Prod)) New TItem,NewItem,Key Set Key="" For Set TItem=Prod.DataItems.GetNext(.Key) Quit:(Key="") Do . Set NewItem=TItem.CopyObject(ItemsCopyMode) . Set NewItem.Product=%this . Do NewItem.%Close() Quit BuildLookUp ; Parameters: lbNodes #define NodeSG "SG" #define NodePL "PL" #define NodeIC "IC" #define NodeIL "IL" #define NodePLItem "PLItem" #define NodeISort "ISort" Set:('$D(lbNodes)) lbNodes=$LB("SG","PL","ICode","ISort") ;d WL^vhDBG("BuildLookUp: "_$$ArrayToText^vhLib("%this.LookUp")) Quit:(lbNodes="") Do:($LF(lbNodes,"SG")) bluSG Do:($LF(lbNodes,"PL")) bluPL Do:($LF(lbNodes,"ICode")) bluICode Do:($LF(lbNodes,"ISort")) bluISort Quit bluSG ; ..LookUp("SG",SubGroepCode) =Oref SubGroep New tmpAr,tmpLU New MetaH,MetaG,MetaS,iG,iS Kill ..LookUp($$$NodeSG) Set MetaH=..MetaStruct Quit:('MetaH) Set iG="" For Set MetaG=MetaH.Groepen.GetNext(.iG) Quit:(iG="") Do . Set iS="" . For Set MetaS=MetaG.SubGroepen.GetNext(.iS) Quit:(iS="") Do .. Set tmpLU(MetaS.Code)=MetaS ; $LB(MetaS) Merge %this.LookUp($$$NodeSG)=tmpLU Quit bluPL ; ..LookUp("PL",ProgLabel)=ParamVal New tmpLU,iI,iP,DItem,ProgLabel,MParam ; ParamVal Kill ..LookUp($$$NodePL) Set iI="" For Set DItem=..DataItems.GetNext(.iI) Quit:(iI="") Do . Quit:('DItem.IsActief()) . Set iP="" . For Set MParam=DItem.MetaItem.Parameters.GetNext(.iP) Quit:(iP="") Do:(iP?1"ProgLabel".E) .. Set ProgLabel=DItem.Get(iP) .. ;d ..TTrace(DItem.Code_" "_DItem.Get("Oms")_" bluPL Begin "_ProgLabel) .. Set:($L(ProgLabel)) tmpLU(ProgLabel)=DItem.EvalMetaAuto(iP) ; Waarde v/e ProgLabel steeds via MetaExec (MParam.Auto) .. ;d ..TTrace("bluPL End") Merge %this.LookUp($$$NodePL)=tmpLU Quit bluICode ; ..LookUp("IC",DItem.Code,"PL",ProgLabel)=ParamKey ; ..LookUp("PLItem",ProgLabel,"IC")=DItem.Code ; ..LookUp("PLItem",ProgLabel,"IOref")=Oref DItem ; ..LookUp("PLItem",ProgLabel,"PKey")=ParamKey ; ..LookUp("IL",DItem.Label)=Oref DItem New tmpLU,tmpLU2,tmpLU3,iI,iP,DItem,ProgLabel Kill ..LookUp($$$NodeIC) Kill ..LookUp($$$NodePLItem) Kill ..LookUp($$$NodeIL) Set iI="" For Set DItem=..DataItems.GetNext(.iI) Quit:(iI="") Do . Set:($L(DItem.Label)) tmpLU3(DItem.Label)=DItem . Set iP="" . Quit:('DItem.MetaItem) . For Set iP=DItem.MetaItem.Parameters.Next(iP) Quit:(iP="") Do:(iP?1"ProgLabel".E) .. Set ProgLabel=DItem.Get(iP) .. Quit:(ProgLabel="") .. Set tmpLU(DItem.Code,"PL",ProgLabel)=iP .. Set tmpLU2(ProgLabel,"IC")=DItem.Code .. Set tmpLU2(ProgLabel,"IOref")=DItem .. Set tmpLU2(ProgLabel,"PKey")=iP Merge %this.LookUp($$$NodeIC)=tmpLU Merge %this.LookUp($$$NodePLItem)=tmpLU2 Merge %this.LookUp($$$NodeIL)=tmpLU3 Quit bluISort ; ..LookUp("ISort","Code",DItem.Code)=Oref DItem ; ..LookUp("ISort","VNr",SubGroepCode,DItem.VolgNr)=Oref DItem New tmpLU,iI,DItem Kill ..LookUp($$$NodeISort) Set iI="" For Set DItem=..DataItems.GetNext(.iI) Quit:(iI="") Do . Quit:(DItem.SubGroepCode="") . Set tmpLU("Code",DItem.Code)=DItem . Set tmpLU("VNr",DItem.SubGroepCode,DItem.VolgNr)=DItem Merge %this.LookUp($$$NodeISort)=tmpLU Quit // ========================================================================================================================================== /// AnalyseConditions : kiezen tussen "AND" of "OR" /// Oproepen via GGDP^WV() GetGADataProd(arPR) New PRNr,PRID,Itm,Prm,Condition,blnAND,blnOR,blnMatch,blnNoMatch Kill arPR Do ggdAnalyseConditions Set PRID="" For Set PRID=$O(^Prod.GAData.ProductD(PRID)) Quit:(PRID="") Do . Quit:($LG($G(^Prod.GAData.ProductD(PRID)),1)'="TBX||1") . Set:(blnAND) CntMatch=0 . Set blnContinue=1 . Set Itm="" . For Set Itm=$O(^Prod.GAData.ProductD(PRID,"I",Itm)) Quit:(Itm="") Do Quit:('blnContinue) . . Set blnContinue=$$ggdCheckLoopItems($LG($G(^Prod.GAData.ProductD(PRID,"I",Itm)),1),$G(^Prod.GAData.ProductD(PRID,"I",Itm,"P","Val"))) . Set:(blnAND) blnMatch=(blnContinue)&&(CntMatch=QtyCond) ; AND : if Continue=0 : a condition did NOT match --> OK . Set:(blnOR) blnMatch=('blnContinue) ; OR : if Continue=0 : a condition did match --> OK . Quit:('blnMatch) . Set PRNr=$LG($G(^Prod.GAData.ProductD(PRID)),7) . Set arPR($I(arPR))=$LB(PRID,PRNr) . w $J(arPR,4)_". GADataID="_PRID_" PRNr="_PRNr_" "_##class(Prod.Product).GetPropViaNr(PRNr,"KortTekst"),! Quit ggdAnalyseConditions Set Condition="AND" Set QtyCond=3 Set Condition=$$$UCase(Condition) Set blnAND=(Condition="AND") Set blnOR=(Condition="OR") Quit ggdCheckLoopItemsAND(Label,Val) ; ------------------------------------------------- ; !!! Aan te passen in ggdAnalyseConditions() !!! ; ------------------------------------------------- ; Set Condition="AND" ; Set QtyCond=3 ; ------------------------------------------------- If ( Label="LC") Set blnMatch=(Val="K") Else If (Label="LD") Set blnMatch=(Val=500) Else If (Label="IB") Set blnMatch=(Val=564) Else Quit 1 Set:(blnMatch) CntMatch=CntMatch+1 Quit blnMatch ggdCheckLoopItemsOR(Label,Val) ; ------------------------------------------------- ; !!! Aan te passen in ggdAnalyseConditions() !!! ; ------------------------------------------------- ; Set Condition="OR" ; ------------------------------------------------- Quit:(Label="LC")&&(Val="K") 1 ;Quit:(Label="LD")&&(Val=350) 1 Quit:(Label="IB")&&(Val=664) 1 Quit 0 ggdCheckLoopItems(Label,Val) Quit:(blnAND) $$ggdCheckLoopItemsAND(.Label,.Val) Quit:(blnOR) '$$ggdCheckLoopItemsOR(.Label,.Val) Quit 0 CountGADataParams() New PRNr,PRID,Itm,Prm,blnMatch,blnNoMatch,cnt d RestartTimer^vhLib() Set cnt=0 Set PRID="" For Set PRID=$O(^Prod.GAData.ProductD(PRID)) Quit:(PRID="") Do . Set Itm="" . For Set Itm=$O(^Prod.GAData.ProductD(PRID,"I",Itm)) Quit:(Itm="") Do . . Do ggdCountParams . ;w cnt,! w "Time needed: "_$$TimeFromStart^vhLib() Quit ggdCountParams Set Prm="" For Set Prm=$O(^Prod.GAData.ProductD(PRID,"I",Itm,"P",Prm)) Quit:(Prm="") Do . Set cnt=cnt+1 Quit