-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathEOMStockLinesProc.sql
More file actions
235 lines (222 loc) · 11.1 KB
/
EOMStockLinesProc.sql
File metadata and controls
235 lines (222 loc) · 11.1 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
/* First run this file with variables set in header - declare variables - drop tables, recreate tables, insert into tables - then query tables */
/* EOM_INVOICING_CREATE_TABLES.sql */
--Admin Order Data by Parent or Customer
/*decalre variables These are being declared via the stored procedure - just need to redeclare cust so as we can get the rates*/
var cust varchar2(20)
exec :cust := 'LUXOTTICA'
var cust2 varchar2(20)
exec :cust := 'TABCORP'
var ordernum varchar2(20)
exec :ordernum := '1363806'
var stock varchar2(20)
exec :stock := 'COURIER'
var stock2 VARCHAR2(50)
EXEC :stock2 := 'FEE*'
var source varchar2(20)
exec :source := 'BSPRINTNSW'
var sAnalysis varchar2(20) /*VerbalOrderEntryFee*/
exec SELECT RM_ANAL INTO :sAnalysis FROM RM where RM_CUST = :cust;
var anal varchar2(20)
exec :anal := '49'
var start_date varchar2(20)
exec :start_date := To_Date('31-Mar-2014')
var end_date varchar2(20)
exec :end_date := To_Date('1-Apr-2014')
var nx NUMBER
EXEC :nx := 1810105
PROCEDURE GROUP_CUST_GET AS
(gc_customer_in IN rm.rm_cust%TYPE)
CURSOR gc_cur IS
SELECT r.rm_cust, r.rm_name
FROM rm r
WHERE r.rm_cust = gc_customer_in
ORDER BY r.rm_cust;
gc_rec gc_cur%ROWTYPE;
BEGIN
OPEN gc_cur;
FETCH gc_cur INTO gc_rec;
WHILE(gc_cur%FOUND)
LOOP
DBMS_OUTPUT.PUT_LINE(gc_rec.rm_cust || ' ' || gc_rec.rm_name);
FETCH gc_cur INTO gc_rec;
END LOOP;
CLOSE gc_cur;
END GROUP_CUST_GET
/*Stocks*/
PROCEDURE CUST_DESP_STOCK_GET AS (
cdsg_stock_cust_in IN i.IM_CUST%TYPE,
cdsg_nx_in IN NI_NV_EXT_TYPE%TYPE,
cdsg_line_stock_in IN d.SD_STOCK%TYPE,
cdsg_date_from_in IN t.ST_DESP_DATE%TYPE,
cdsg_date_to_in IN t.ST_DESP_DATE%TYPE,
cdsg_cust_in IN i.IM_CUST%TYPE
)
CURSOR cdsg_cur IS
SELECT s.SH_CUST AS "Customer",
r.RM_PARENT AS "Parent",
CASE WHEN i.IM_CUST <> cdsg_stock_cust_in THEN s.SH_SPARE_STR_4
WHEN i.IM_CUST = cdsg_stock_cust_in THEN i.IM_XX_COST_CENTRE01
ELSE i.IM_XX_COST_CENTRE01
END AS "CostCentre",
s.SH_ORDER AS "Order",
s.SH_SPARE_STR_5 AS "OrderwareNum",
s.SH_CUST_REF AS "CustomerRef",
t.ST_PICK AS "Pickslip",
d.SD_XX_PICKLIST_NUM AS "PickNum",
t.ST_PSLIP AS "DespatchNote",
substr(To_Char(t.ST_DESP_DATE),0,10) AS "DespatchDate",
CASE WHEN d.SD_STOCK IS NOT NULL THEN d.SD_STOCK
ELSE NULL
END AS "FeeType",
d.SD_STOCK AS "Item",
d.SD_DESC AS "Description",
l.SL_PSLIP_QTY AS "Qty",
d.SD_QTY_UNIT AS "UOI",
CASE WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST <> cdsg_stock_cust_in AND i.IM_OWNED_BY = 0 THEN d.SD_SELL_PRICE
WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST <> cdsg_stock_cust_in AND i.IM_OWNED_BY = 1 THEN n.NI_SELL_VALUE/n.NI_NX_QUANTITY
WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST = cdsg_stock_cust_in AND eom_report_pkg.BREAK_UNIT_PRICE(r.RM_GROUP_CUST,d.SD_STOCK) IS NOT NULL THEN eom_report_pkg.BREAK_UNIT_PRICE(r.RM_GROUP_CUST,d.SD_STOCK)
WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST = cdsg_stock_cust_in AND eom_report_pkg.BREAK_UNIT_PRICE(r.RM_GROUP_CUST,d.SD_STOCK) IS NULL THEN d.SD_XX_OW_UNIT_PRICE
ELSE NULL
END AS "Batch/UnitPrice",
CASE WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST <> cdsg_stock_cust_in THEN To_Number(i.IM_REPORTING_PRICE)
WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST = cdsg_stock_cust_in THEN eom_report_pkg.BREAK_UNIT_PRICE(r.RM_GROUP_CUST,d.SD_STOCK)
WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST = cdsg_stock_cust_in AND (SELECT vUnitPrice FROM Tmp_Admin_Data_BreakPrices WHERE vIIStock = d.SD_STOCK AND vIICust = r.RM_GROUP_CUST) IS NULL THEN d.SD_XX_OW_UNIT_PRICE
ELSE NULL
END AS "OWUnitPrice",
CASE WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST <> cdsg_stock_cust_in AND i.IM_OWNED_BY = 0 THEN d.SD_SELL_PRICE * d.SD_QTY_DESP
WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST <> cdsg_stock_cust_in AND i.IM_OWNED_BY = 1 THEN (n.NI_SELL_VALUE/n.NI_NX_QUANTITY) * d.SD_QTY_DESP
WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST = cdsg_stock_cust_in AND eom_report_pkg.BREAK_UNIT_PRICE(r.RM_GROUP_CUST,d.SD_STOCK) IS NOT NULL THEN eom_report_pkg.BREAK_UNIT_PRICE(r.RM_GROUP_CUST,d.SD_STOCK) * d.SD_QTY_DESP
WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST = cdsg_stock_cust_in AND eom_report_pkg.BREAK_UNIT_PRICE(r.RM_GROUP_CUST,d.SD_STOCK) IS NULL THEN d.SD_XX_OW_UNIT_PRICE * d.SD_QTY_DESP
ELSE NULL
END AS "DExcl",
CASE WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST <> cdsg_stock_cust_in THEN To_Number(i.IM_REPORTING_PRICE)
WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST = cdsg_stock_cust_in THEN eom_report_pkg.BREAK_UNIT_PRICE(r.RM_GROUP_CUST,d.SD_STOCK)
WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST = cdsg_stock_cust_in AND eom_report_pkg.BREAK_UNIT_PRICE(r.RM_GROUP_CUST,d.SD_STOCK) IS NULL THEN d.SD_XX_OW_UNIT_PRICE
ELSE NULL
END AS "Excl_Total",
CASE WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST <> cdsg_stock_cust_in AND i.IM_OWNED_BY = 0 THEN (d.SD_SELL_PRICE * d.SD_QTY_DESP) * 1.1
WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST <> cdsg_stock_cust_in AND i.IM_OWNED_BY = 1 THEN ((n.NI_SELL_VALUE/n.NI_NX_QUANTITY) * d.SD_QTY_DESP) * 1.1
WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST = cdsg_stock_cust_in AND eom_report_pkg.BREAK_UNIT_PRICE(r.RM_GROUP_CUST,d.SD_STOCK) IS NOT NULL THEN (eom_report_pkg.BREAK_UNIT_PRICE(r.RM_GROUP_CUST,d.SD_STOCK) * d.SD_QTY_DESP) * 1.1
WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST = cdsg_stock_cust_in AND eom_report_pkg.BREAK_UNIT_PRICE(r.RM_GROUP_CUST,d.SD_STOCK) IS NULL THEN (d.SD_XX_OW_UNIT_PRICE * d.SD_QTY_DESP) * 1.1
ELSE NULL
END AS "DIncl",
CASE WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST <> cdsg_stock_cust_in AND i.IM_OWNED_BY = 0 THEN (d.SD_SELL_PRICE * d.SD_QTY_DESP) * 1.1
WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST <> cdsg_stock_cust_in AND i.IM_OWNED_BY = 1 THEN ((n.NI_SELL_VALUE/n.NI_NX_QUANTITY) * d.SD_QTY_DESP) * 1.1
WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST = cdsg_stock_cust_in AND eom_report_pkg.BREAK_UNIT_PRICE(r.RM_GROUP_CUST,d.SD_STOCK) IS NOT NULL THEN (eom_report_pkg.BREAK_UNIT_PRICE(r.RM_GROUP_CUST,d.SD_STOCK) * d.SD_QTY_DESP) * 1.1
WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST = cdsg_stock_cust_in AND eom_report_pkg.BREAK_UNIT_PRICE(r.RM_GROUP_CUST,d.SD_STOCK) IS NULL THEN (d.SD_XX_OW_UNIT_PRICE * d.SD_QTY_DESP) * 1.1
ELSE NULL
END AS "Incl_Total",
CASE WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST <> cdsg_stock_cust_in THEN To_Number(i.IM_REPORTING_PRICE)
WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST = cdsg_stock_cust_in THEN eom_report_pkg.BREAK_UNIT_PRICE(r.RM_GROUP_CUST,d.SD_STOCK)
WHEN d.SD_STOCK IS NOT NULL AND i.IM_CUST = cdsg_stock_cust_in AND eom_report_pkg.BREAK_UNIT_PRICE(r.RM_GROUP_CUST,d.SD_STOCK) IS NULL THEN d.SD_XX_OW_UNIT_PRICE
ELSE NULL
END AS "ReportingPrice",
s.SH_ADDRESS AS "Address",
s.SH_SUBURB AS "Address2",
s.SH_CITY AS "Suburb",
s.SH_STATE AS "State",
s.SH_POST_CODE AS "Postcode",
s.SH_NOTE_1 AS "DeliverTo",
s.SH_NOTE_2 AS "AttentionTo" ,
t.ST_WEIGHT AS "Weight",
t.ST_PACKAGES AS "Packages",
s.SH_SPARE_DBL_9 AS "OrderSource",
NULL AS "Pallet/Shelf Space", /*Pallet/Space*/
NULL AS "Locn", /*Locn*/
0 AS "AvailSOH",/*Avail SOH*/
0 AS "CountOfStocks",
/*CASE WHEN regexp_substr(s.SH_SPARE_STR_3,'[a-z]+', 1, 2) IS NOT NULL THEN s.SH_SPARE_STR_3 || '@' || s.SH_SPARE_STR_1
ELSE ''
END AS Email,*/
i.IM_BRAND AS Brand
FROM PWIN175.SD d
INNER JOIN PWIN175.SH s ON s.SH_ORDER = d.SD_ORDER
INNER JOIN PWIN175.ST t ON t.ST_ORDER = s.SH_ORDER
INNER JOIN PWIN175.SL l ON l.SL_PICK = t.ST_PICK
INNER JOIN PWIN175.RM r ON r.RM_CUST = s.SH_CUST
INNER JOIN PWIN175.IM i ON i.IM_STOCK = d.SD_STOCK
INNER JOIN PWIN175.NI n ON n.NI_NV_EXT_KEY = l.SL_UID
WHERE NI_NV_EXT_TYPE = cdsg_nx_in AND NI_STRENGTH = 3 AND NI_DATE = t.ST_DESP_DATE AND NI_STOCK = d.SD_STOCK AND NI_STATUS <> 0
AND s.SH_STATUS <> 3
AND i.IM_CUST = cdsg_cust_in
AND s.SH_ORDER = t.ST_ORDER
AND d.SD_STOCK NOT LIKE cdsg_line_stock_in
AND t.ST_DESP_DATE >= cdsg_date_from_in AND t.ST_DESP_DATE <= cdsg_date_to_in
AND d.SD_LAST_PICK_NUM = t.ST_PICK
GROUP BY s.SH_CUST,
s.SH_NOTE_1,
s.SH_CAMPAIGN,
s.SH_SPARE_STR_4,
i.IM_XX_COST_CENTRE01,
i.IM_CUST,
r.RM_PARENT,
s.SH_ORDER,
t.ST_PICK,
d.SD_XX_PICKLIST_NUM,
i.IM_REPORTING_PRICE,
i.IM_NOMINAL_VALUE,
t.ST_PSLIP,
t.ST_DESP_DATE,
d.SD_QTY_ORDER,
d.SD_QTY_UNIT,
d.SD_STOCK,
d.SD_DESC,
d.SD_LINE,
d.SD_EXCL,
d.SD_INCL,
d.SD_SELL_PRICE,
d.SD_XX_OW_UNIT_PRICE,
d.SD_QTY_ORDER,
d.SD_QTY_ORDER,
s.SH_ADDRESS,
s.SH_SUBURB,
s.SH_CITY,
s.SH_STATE,
s.SH_POST_CODE,
s.SH_NOTE_1,
s.SH_NOTE_2,
t.ST_WEIGHT,
t.ST_PACKAGES,
s.SH_SPARE_DBL_9,
r.RM_GROUP_CUST,
r.RM_PARENT,
s.SH_SPARE_STR_5,
s.SH_CUST_REF,s.SH_SPARE_STR_3,s.SH_SPARE_STR_1,
d.SD_SELL_PRICE,
i.IM_OWNED_BY,
d.SD_QTY_DESP,
n.NI_SELL_VALUE,
n.NI_NX_QUANTITY,
i.IM_BRAND,
l.SL_PSLIP_QTY;
cdsg_rec cdsg_cur%ROWTYPE;
BEGIN
OPEN cdsg_cur;
FETCH cdsg_cur INTO cdsg_rec;
WHILE cdsg_cur%FOUND
LOOP
DBMS_OUTPUT.PUT_LINE(cdsg_rec.Customer || ',' || cdsg_rec.Parent || ',' || cdsg_rec.OrderwareNum || ',' || "cdsg_rec.Order" || ',' || cdsg_rec.PickNum || ',' || cdsg_rec.FeeType || ',' || cdsg_rec.Item || ',' || cdsg_rec.Description );
FETCH cdsg_cur INTO cdsg_rec;
END LOOP;
CLOSE cdsg_cur;
END CUST_DESP_STOCK_GET;
/* OPEN gc_cur;
FETCH gc_cur INTO gc_rec;
WHILE(gc_cur%FOUND)
LOOP
DBMS_OUTPUT.PUT_LINE(gc_rec.Customer || ',' || gc_rec.Parent || ',' || gc_rec.OrderwareNum || ',' || "gc_rec.Order" || ',' || gc_rec.PickNum || ',' || gc_rec.FeeType || ',' || gc_rec.Item || ',' || gc_rec.Description );
FETCH gc_cur INTO gc_rec;
END LOOP;
CLOSE gc_cur;
END CUST_DESP_STOCK_GET; */
--Customer Parent CostCentre Order OrderwareNum CustomerRef Pickslip PickNum DespatchNote DespatchDate FeeType Item Description Qty UOI Batch/UnitPrice OWUnitPrice DExcl Excl_Total DIncl Incl_Total ReportingPrice Address Address2 Suburb State Postcode DeliverTo AttentionTo Weight Packages OrderSource Pallet/Shelf Space Locn AvailSOH CountOfStocks EMAIL BRAND
BEGIN
OPEN gc_cur;
FETCH gc_cur INTO gc_rec;
WHILE(gc_cur%FOUND)
LOOP
DBMS_OUTPUT.PUT_LINE(gc_rec.rm_cust || '-' || gc_rec.rm_name);
FETCH gc_cur INTO gc_rec;
END LOOP;
CLOSE gc_cur;
END GROUP_CUST_GET;