-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheserver_send_810.sql
More file actions
45 lines (41 loc) · 1.59 KB
/
eserver_send_810.sql
File metadata and controls
45 lines (41 loc) · 1.59 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
-- wrap this so I can limit the number of rows
select * from (
select
distinct
a.id
from
arinvoice a,
arinvoice_detail ad,
c_ship_hist c,
ord_detail_seg o
where
a.id = ad.arinvoice_id
and ad.shipment_dtl_id = c.shipment_dtl_id
and a.invoice_no <> 'ONACCT'
-- only run on invoices with qty that have not had an EDI file sent previously
and a.invoicetotal > 0
and nvl(a.edi_created, 'N') <> 'Y'
-- make sure this is an EDI customer and that this is an 810
and a.arcusto_id IN (
SELECT arcusto_id
FROM
edi_partners ep,
edi_partners_ts ept
WHERE
ept.edi_partners_id = ep.id
AND ept.in_out_bound = 'OUTBOUND'
AND ept.transaction_set_code = '810'
-- make sure this only runs in the evening
AND (
CASE
WHEN TO_CHAR(SYSDATE, 'HH24:MI:SS') >= '19:00:00' THEN 'Y'
WHEN TO_CHAR(SYSDATE, 'HH24:MI:SS') < '04:00:00' THEN 'Y'
ELSE 'N'
END = 'Y'
)
-- ensures that the order arrived via 850
-- this is critical if a customer was NOT EDI for a time and then has EDI added as it can cause the eServer to get stuck
and c.ord_detail_id = o.ord_detail_id
)
) -- limit the number of runs as this is resource intensive
where rownum < 500