#include Prod.Product
#include BL.Derde.LevSpecifiek
BLKALPrijsVerschillenMail ;Blum KAL lijst prijsverschillen
Verwerk ; Blum KAL prijsverschillen
Set LevNr=$$$LevBlum
Set SoDo="SO" ; Standard of Direct orders
Do InitBody(LevNr,SoDo)
Do Header(LevNr,SoDo)
Set AantalVerschillen=$$VerzamelVerschillen(LevNr,SoDo)
Quit:'AantalVerschillen ; geen verschillen dus geen mail
Do EndBody
Do MailVerschillen(LevNr,SoDo)
Quit
InitBody(LevNr,SoDo)
#define fmtBeginHtml "
"
#define fmtBeginTable ""
#define fmtReferentie(%Txt) $C(10,13)_""_%Txt_"
"
Set strmBody=##class(%GlobalCharacterStream).%New()
;header van de HTML-pagina
Do strmBody.Write($$$fmtBeginHtml)
Do strmBody.Write($$$fmtReferentie("KAL Prijsverschillen "_$$EXTDATE^vhLib.DataTypes($H,"DK")))
Do strmBody.Write($$$fmtBeginTable)
Quit
EndBody
#define fmtEndHtml ""
#define fmtEndTable "
"
Do strmBody.Write($$$fmtEndTable)
Do strmBody.Write($$$fmtEndHtml)
Quit
VerzamelVerschillen(LevNr,SoDo)
New ToeNr,Cnt,VRF,FAKNr,LijnNr,PRNr,Rec,FakRec,PrijsVerschil,VerschilCode,BlumPrijs,VHPrijs
Set Cnt=0
Set ToeNr=""
For Set ToeNr=$O(^BLTO(LevNr,SoDo,ToeNr)) Quit:ToeNr="" Do
. Set LijnNr=""
. For Set LijnNr=$O(^BLTO(LevNr,SoDo,ToeNr,LijnNr)) Quit:LijnNr="" Do
. . Set TORec=^(LijnNr)
. . Quit:($P(TORec,"\",31))'["PR"
. . Set PRNr=$P(TORec,"\",2) ; via Toelevering
. . Set:'PRNr PRNr=$P(TORec,"\",35) ; via Blum
. . If PRNr Do
. . . Set Cnt=Cnt+1
. . . Set PrijsVerschil=$$PrijsVerschil^BLKALC3(PRNr,TORec)
. . . Set VerschilCode=$P(PrijsVerschil,"\",4)
. . . Set BlumPrijs=$P(PrijsVerschil,"\",2)
. . . Set VHPrijs=$P(PrijsVerschil,"\",3)
. . . Do AddVerschil2Body(ToeNr,PRNr,VerschilCode,BlumPrijs,VHPrijs)
Quit Cnt
AddVerschil2Body(ToeLevNr,PRNr,VerschilCode,BlumPrijs,VHPrijs)
#define fmtBeginRow ""
#define fmtEndRow "
"
#define fmtBeginCell(%align) ""
#define fmtEndCell " | "
#define AlignLeft "left"
#define AlignRight "right"
#define AlignMiddle "middle"
Do strmBody.Write($$$fmtBeginRow)
Do strmBody.Write($$$fmtBeginCell($$$AlignMiddle)_ToeLevNr_$$$fmtEndCell)
Do strmBody.Write($$$fmtBeginCell($$$AlignLeft)_$$$PRGet($$$KortTekst)_$$$fmtEndCell)
Do strmBody.Write($$$fmtBeginCell($$$AlignLeft)_$$$PRGet($$$IdentNummer)_$$$fmtEndCell)
Do strmBody.Write($$$fmtBeginCell($$$AlignMiddle)_VerschilCode_$$$fmtEndCell)
Do strmBody.Write($$$fmtBeginCell($$$AlignRight)_$FN(BlumPrijs,".",2)_$$$fmtEndCell)
Do strmBody.Write($$$fmtBeginCell($$$AlignRight)_$FN(VHPrijs,".",2)_$$$fmtEndCell)
Do strmBody.Write($$$fmtEndRow)
Quit
Header(LevNr,SoDo)
#define fmtBeginHeader(%align) ""
#define fmtEndHeader " | "
Do strmBody.Write($$$fmtBeginRow)
Do strmBody.Write($$$fmtBeginHeader($$$AlignMiddle)_"Toelev."_$$$fmtEndHeader)
Do strmBody.Write($$$fmtBeginHeader($$$AlignLeft)_"KortTekst"_$$$fmtEndHeader)
Do strmBody.Write($$$fmtBeginHeader($$$AlignLeft)_"IdentNr"_$$$fmtEndHeader)
Do strmBody.Write($$$fmtBeginHeader($$$AlignMiddle)_"Test"_$$$fmtEndHeader)
Do strmBody.Write($$$fmtBeginHeader($$$AlignRight)_"Blum prijs"_$$$fmtEndHeader)
Do strmBody.Write($$$fmtBeginHeader($$$AlignRight)_"VH prijs"_$$$fmtEndHeader)
Do strmBody.Write($$$fmtEndRow)
Quit
MailVerschillen(LevNr,SoDo)
Set Subject="KAL Prijsverschillen "_$$EXTDATE^vhLib.DataTypes($H,"DK")
Set From=##class(TECH.Context.RuntimeContext).Instance().GeefServerNaam()_"@VANHOECKE.BE"
Set To=$LB("PM_Administratie@vanhoecke.be")
Set X=$$SendMiniMail^vhLib(From,To,Subject,strmBody,1,1)
Quit