use AlplaPROD_test1


/**
check if we have any new alpla bols that were created
*/

SELECT  
x.idladeplanung
,e.idjournal 
,e.journalNummer as bol
,e.idjournalstatus
,e.ladeDatum as loadDate
,e.bemerkung
,e.ereporting_idwerk
,e.journalDatum
,a.idadressen as addressId
,a.bezeichnung as addressDescription
,a.strasse as streetAddress
,a.ort as cityState
,a.plz as zipcode
,idauftrag as releaseNumber
--,*
  FROM [dbo].[T_EAIJournal] as e with (nolock) 


  -- pull in the address so we only pull in florence data
left join
 [dbo].[T_EAIJournalAdresse] as a with (nolock) on
  a.[IdJournalAdresse] = [IdJournalKundenAdresse]

-- get the table to link the pallets to the bol
left join
[dbo].[T_EAIJournalPosition] as x with (nolock) on
x.idjournal = e.idjournal

where idjournalStatus = 62 
  --and idadressen = 270 
  --and a.bezeichnung like '%Alpla%' -- we only want to monitor for addresses that are linked to alpla.
  and JournalDatum > DATEADD(MINUTE, -[timeCheck], GETDATE())
  and e.idjournal not in ([ignoreBols])
  and idauftrag > 1 -- this will ignore all incoming goodsv as we are really only looking for outbound deliveries
order by JournalDatum desc