idata 0.1.29 → 0.1.30

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/bin/iload +2 -2
  3. data/full.sh +580 -0
  4. data/lib/idata/version.rb +1 -1
  5. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: d37af89a0b0962c026e20d63637f3a750030429f
4
- data.tar.gz: a67cdfd07638f57788c837667c01e4f259867fa6
3
+ metadata.gz: 13ad27d50840b035ef83001024e8845ded2952cb
4
+ data.tar.gz: 84385db902e4ea8a32b550530087235bd3381a1f
5
5
  SHA512:
6
- metadata.gz: 58eec49a072286d87b643f58be7c456e0d9140c7341b0816fc46b790241a9ef07fff0c2e86f72b2eda17f3c76defebb3259bd0fc50f912a9e90ff0fda2cd0511
7
- data.tar.gz: bd83cd1f605863ed36bdf6c71236233bed41a0830013683b6906c9834fe23b12d482807eef38d318f6dec364ab14d55d8017734555ec01a63b6faa0270d67f10
6
+ metadata.gz: 1859b4bb2dbf3ed6de6f592e7f9a61bbaefeaef2afcaed3ecafbae566e7f1152c1bbd214f8d95e0113cfdc358036fc36e8319348bfbfed2a73948e993bd853ec
7
+ data.tar.gz: a2a5984979e156aaa75048eade81ec31de2a90052758c03557f71875727a4fa6576459c5b34f565a3493b3a3a52a9ae66c501ee008acff80fe28f7cfe8dcaedc
data/bin/iload CHANGED
@@ -177,8 +177,8 @@ $csv_converters = []
177
177
  $csv_converters << :null_converter if $options[:null]
178
178
 
179
179
  CSV::Converters[:null_converter] = lambda{ |s|
180
- return nil if s == $options[:null] or s == ""
181
- return s
180
+ return nil if s == $options[:null] or s == "" or s.nil?
181
+ return s.strip
182
182
  }
183
183
 
184
184
  class String
data/full.sh ADDED
@@ -0,0 +1,580 @@
1
+ #!/bin/bash
2
+
3
+ # SHARED VARIABLES
4
+ # ---------------------------------------------------------------------------------
5
+ # Database to store data tables
6
+ ORGNAME="sample"
7
+
8
+ # ENV variables used by the validation command
9
+ export HOST="localhost"
10
+ export USERNAME="postgres"
11
+ export PASSWORD="extr!me"
12
+ export DATABASE="$ORGNAME"
13
+ export LISTEN=5432
14
+
15
+ # Create temporary output folder
16
+ OUTPUT_DIR="/tmp/$ORGNAME" && test -e $OUTPUT_DIR || mkdir $OUTPUT_DIR
17
+
18
+ # Input files and correspondings names
19
+ FCONTRACTO="ContractMaster.csv"
20
+ FVENDOR="VendorMaster.csv"
21
+ FITEM="ItemMaster.csv"
22
+ FINVOICE="InvoiceHistory.csv"
23
+ FMFR="MfrMaster.csv"
24
+ FPO="PurchaseOrder.csv"
25
+ FUSER="User.csv"
26
+ FLOCATION="Location.csv"
27
+ FITEMCOST="ItemCostCenterAcctExceptions.csv"
28
+ FREQ="ReqHistoryLoad.csv"
29
+ FGL="GLAccount.csv"
30
+ FINVENTORY="Inventory.csv"
31
+
32
+ CONTRACTO="contracts"
33
+ VENDOR="vendors"
34
+ ITEM="items"
35
+ INVOICE="invoices"
36
+ MFR="manufacturers"
37
+ PO="purchase_orders"
38
+ USER="users"
39
+ LOCATION="locations"
40
+ ITEMCOST="item_costs"
41
+ REQ="reqs"
42
+ GL="gls"
43
+ INVENTORY="inventory"
44
+
45
+ # Standard UOM for reference
46
+ FUOMSTD="stduom.txt"
47
+ UOMSTD="uomstd"
48
+
49
+ # ---------------------------------------------------------------------------------
50
+ # LOAD
51
+ # ---------------------------------------------------------------------------------
52
+ # Sanitize input files
53
+ #isanitize --strip-newline --remove=65279 "$FCONTRACTO" "$FVENDOR" "$FITEM" "$FINVOICE" "$FMFR" "$FPO" \
54
+ # "$FTMPL" "$FUSER" "$FITEMEXPO" "$FUSEREQ" "$FLOCATION" "$FITEMCOST" "$FREQ" \
55
+ # "$FGL" "$FUSERCOST" "$FINVENTORY" "$FUSERCREATEREQ"
56
+
57
+ # Load
58
+ iload -i "$FCONTRACTO" -t "$CONTRACTO" -f csv
59
+ iload -i "$FVENDOR" -t "$VENDOR" -f csv
60
+ iload -i "$FITEM" -t "$ITEM" -f csv
61
+ iload -i "$FINVOICE" -t "$INVOICE" -f csv
62
+ iload -i "$FMFR" -t "$MFR" -f csv
63
+ iload -i "$FPO" -t "$PO" -f csv
64
+ iload -i "$FUSER" -t "$USER" -f csv
65
+ iload -i "$FLOCATION" -t "$LOCATION" -f csv
66
+ iload -i "$FITEMCOST" -t "$ITEMCOST" -f csv
67
+ iload -i "$FREQ" -t "$REQ" -f csv
68
+ iload -i "$FGL" -t "$GL" -f csv
69
+ iload -i "$FINVENTORY" -t "$INVENTORY" -f csv
70
+
71
+ # Load UOM STANDARD for reference
72
+ iload -i "$FUOMSTD" -t "$UOMSTD" -f csv
73
+
74
+ # ---------------------------------------------------------------------------------
75
+ # INDEXING (for speeding up validation queries)
76
+ # ---------------------------------------------------------------------------------
77
+ ipatch -q "drop index if exists items_item_id_index; create index items_item_id_index on $ITEM(item_id)"
78
+ ipatch -q "drop index if exists pos_item_id_index; create index pos_item_id_index on $PO(item_id)"
79
+ ipatch -q "drop index if exists gls_corp_acct_no_index; create index gls_corp_acct_no_index on $GL(corp_acct_no)"
80
+ ipatch -q "drop index if exists gls_corp_acct_name_index; create index gls_corp_acct_name_index on $GL(corp_acct_name)"
81
+ ipatch -q "drop index if exists gls_cc_acct_no_index; create index gls_cc_acct_no_index on $GL(cc_acct_no)"
82
+ ipatch -q "drop index if exists gls_cc_acct_name_index; create index gls_cc_acct_name_index on $GL(cc_acct_name)"
83
+ ipatch -q "drop index if exists locations_name_index; create index locations_name_index on $LOCATION(name)"
84
+
85
+ # ---------------------------------------------------------------------------------
86
+ # Some adjustment
87
+ # ---------------------------------------------------------------------------------
88
+ ipatch -q "
89
+ -- Normalize values
90
+ UPDATE $ITEM set active = '1' where active = 'Y';
91
+ UPDATE items set active = '3' where active = 'N';
92
+ "
93
+
94
+ ipatch -q "
95
+ -- Extract FIRST_NAME, LAST_NAME from NAME
96
+ ALTER TABLE $USER ADD COLUMN first_name varchar;
97
+ ALTER TABLE $USER ADD COLUMN last_name varchar;
98
+ UPDATE $USER SET username = trim(regexp_replace(username, '\s+', ' ', 'g'));
99
+ UPDATE $USER SET first_name = username, last_name = username
100
+ WHERE array_length(string_to_array(username, ' '), 1) = 1;
101
+ UPDATE $USER SET first_name = substring(username, '^[^\s]+'),
102
+ last_name = regexp_replace(username, '^[^\s]+\s', '', 'g')
103
+ WHERE array_length(string_to_array(username, ' '), 1) >= 2;
104
+ "
105
+
106
+ ipatch -q "
107
+ -- ADD EMAIL COLUMN
108
+ ALTER TABLE $USER ADD COLUMN email VARCHAR;
109
+ UPDATE $USER SET email = userlogin;
110
+ "
111
+
112
+ ipatch -q "
113
+ -- FIX ISSUE WITH linebreak
114
+ update items set vendor_item_id = (string_to_array(regexp_replace(replace(vendor_item_id, E'\r\n', ' '), '\s+', ' ', 'g'), ' '))[1]
115
+ where vendor_item_id like E'%\r\n%';
116
+ update purchase_orders set vendor_item_id = (string_to_array(regexp_replace(replace(vendor_item_id, E'\r\n', ' '), '\s+', ' ', 'g'), ' '))[1]
117
+ where vendor_item_id like E'%\r\n%';
118
+ update purchase_orders set vendor_item_id = (string_to_array(regexp_replace(replace(vendor_item_id, E'\n', ' '), '\s+', ' ', 'g'), ' '))[1]
119
+ where vendor_item_id like E'%\n%';
120
+ "
121
+
122
+ ipatch -q "
123
+ -- Normalize DATE
124
+ UPDATE $PO SET po_date = to_char(to_date(po_date, 'MM/DD/YYYY'), 'YYYY-MM-DD')
125
+ WHERE po_date IS NOT NULL AND po_date != '';
126
+ UPDATE $CONTRACTO SET contract_start = to_char(to_date(contract_start, 'MM/DD/YYYY'), 'YYYY-MM-DD')
127
+ WHERE contract_start like '%/%/%';
128
+ UPDATE $CONTRACTO SET contract_end = to_char(to_date(contract_end, 'MM/DD/YYYY'), 'YYYY-MM-DD')
129
+ WHERE contract_end like '%/%/%';
130
+
131
+ -- ADD MORE EMPTY FIELD (for validation)
132
+ -- ALTER TABLE $LOCATION ADD COLUMN corp_id varchar;
133
+
134
+ -- FILL EMPTY FIELDS WITH DEFAULT VALUE
135
+ UPDATE $LOCATION SET ship_to_ind = 'N' WHERE ship_to_ind IS NULL OR LENGTH(trim(ship_to_ind)) = 0;
136
+ UPDATE $LOCATION SET bill_to_ind = 'N' WHERE bill_to_ind IS NULL OR LENGTH(trim(bill_to_ind)) = 0;
137
+ UPDATE $LOCATION SET stockless_ind = 'N' WHERE stockless_ind IS NULL OR LENGTH(trim(stockless_ind)) = 0;
138
+ "
139
+
140
+ # Convert A2A2A2 to A2-A2-A2
141
+ # Manual check and comment out the following to speed up validating
142
+ # @todo IEVAL performance is very poor, avoid using it (use IPATCH instead) unless there is no better way
143
+ ieval -t $GL --eval="
144
+ if item.corp_acct_fmt && item.corp_acct_fmt[/^[A-Z][0-9][A-Z][0-9][A-Z][0-9]$/]
145
+ item.corp_acct_fmt = item.corp_acct_fmt.unpack('a2a2a2').join('-')
146
+ end
147
+ "
148
+
149
+ # ---------------------------------------------------------------------------------
150
+ # VALIDATE
151
+ # ---------------------------------------------------------------------------------
152
+ # validate VENDORS
153
+ ivalidate --case-insensitive --pretty -t $VENDOR \
154
+ --log-to=validation_errors \
155
+ --not-null="vendor_code" \
156
+ --not-null="vendor_name" \
157
+ --unique="vendor_code" \
158
+ --unique="vendor_name" \
159
+ --match="vendor_code/[a-zA-Z0-9]/" \
160
+ --match="vendor_name/[a-zA-Z0-9]/" \
161
+ --consistent-by="vendor_code|vendor_name" \
162
+ --consistent-by="vendor_name|vendor_code" \
163
+ --consistent-by="country_code|country_name" \
164
+ --consistent-by="country_name|country_code"
165
+
166
+ # validate MANUFACTURERS
167
+ ivalidate --case-insensitive --pretty -t $MFR \
168
+ --log-to=validation_errors \
169
+ --not-null="mfr_number" \
170
+ --not-null="mfr_name" \
171
+ --match="mfr_number/[a-zA-Z0-9]/" \
172
+ --match="mfr_name/[a-zA-Z0-9]/" \
173
+ --consistent-by="mfr_number|mfr_name" \
174
+ --consistent-by="mfr_name|mfr_number" \
175
+ --consistent-by="country_code|country_name" \
176
+ --consistent-by="country_name|country_code"
177
+
178
+ # validate GL
179
+ ivalidate --case-insensitive --pretty -t $GL \
180
+ --log-to=validation_errors \
181
+ --not-null=corp_acct_no \
182
+ --match="corp_acct_no/[a-zA-Z0-9]/" \
183
+ --not-null=corp_acct_name \
184
+ --match="corp_acct_name/[a-zA-Z0-9]/" \
185
+ --not-null=corp_acct_fmt \
186
+ --match="corp_acct_fmt/^[A-Z][0-9]-[A-Z][0-9]-[A-Z][0-9]$/" \
187
+ --not-null=cc_acct_no \
188
+ --match="cc_acct_no/[a-zA-Z0-9]/" \
189
+ --not-null=cc_acct_name \
190
+ --match="cc_acct_name/[a-zA-Z0-9]/" \
191
+ --not-null=cc_acct_type \
192
+ --match="cc_acct_type/^(1|2|3|4|5|Asset|Liability|Equity|Income\sStatement|Expense|Income)$/" \
193
+ --not-null=exp_acct_no \
194
+ --match="exp_acct_no/[a-zA-Z0-9]/" \
195
+ --not-null=exp_acct_name \
196
+ --match="exp_acct_name/[a-zA-Z0-9]/" \
197
+ --consistent-by="corp_acct_no|corp_acct_name" \
198
+ --consistent-by="corp_acct_name|corp_acct_no" \
199
+ --consistent-by="exp_acct_no|corp_acct_no, corp_acct_name, cc_acct_no, cc_acct_name, exp_acct_name" \
200
+ --consistent-by="exp_acct_name|corp_acct_no, corp_acct_name, cc_acct_no, cc_acct_name, exp_acct_no" \
201
+ --consistent-by="cc_acct_no|corp_acct_no, corp_acct_name, cc_acct_name" \
202
+ --consistent-by="cc_acct_name|corp_acct_no, corp_acct_name, cc_acct_no" \
203
+ --not-null=exp_acct_type \
204
+ --match="exp_acct_type/^(1|2|3|4|5|Asset|Liability|Equity|Income\sStatement|Expense|Income)$/"
205
+
206
+ # validate LOCATION
207
+ ivalidate --case-insensitive --pretty -t $LOCATION \
208
+ --log-to=validation_errors \
209
+ --not-null=loc_id \
210
+ --match="loc_id/[a-zA-Z0-9]/" \
211
+ --not-null="name" \
212
+ --match="name/[a-zA-Z0-9]/" \
213
+ --not-null=facility_code \
214
+ --match="facility_code/[a-zA-Z0-9]/" \
215
+ --not-null=facility_desc \
216
+ --match="facility_desc/[a-zA-Z0-9]/" \
217
+ --match="ship_to_ind/^(Y|N)$/" \
218
+ --match="bill_to_ind/^(Y|N)$/" \
219
+ --match="stockless_ind/^(Y|N)$/" \
220
+ --not-null=loc_type \
221
+ --match="loc_type/^(C|S|LOC_TYPE_SUPPLY|LOC_TYPE_CONSUME)$/" \
222
+ --not-null=inventory_path_name \
223
+ --not-null=inventory_location_name \
224
+ --query="(route_no is null or route_no = '' or regexp_replace(route_no, '[,\.]', '', 'g') ~ '^[1-9][0-9]+$') -- invalid route_no" \
225
+ --rquery="(loc_type ~* '^(LOC_TYPE_SUPPLY|S)$' and (corp_acct_no is null or corp_name is null or corp_id is null)) -- either corp id/name or corp_acct_no is null" \
226
+ --not-null=active \
227
+ --match="active/^(Y|N)$/" \
228
+ --not-null=corp_acct_no \
229
+ --match="corp_acct_no/[a-zA-Z0-9]/" \
230
+ --not-null=inventory_loc_seq_no \
231
+ --match="inventory_loc_seq_no/^[1-9][0-9]*$/" \
232
+ --match="route_no/^[1-9][0-9]*$/" \
233
+ --match="route_name/[a-zA-Z0-9]/" \
234
+ --match="corp_name/[a-zA-Z0-9]/" \
235
+ --consistent-by="corp_name|corp_id" \
236
+ --consistent-by="corp_id|corp_name" \
237
+ --consistent-by="name|facility_code, loc_id" \
238
+ --consistent-by="loc_id|facility_code, name" \
239
+ --cross-reference="inventory_path_name|$LOCATION.name" \
240
+ --cross-reference="inventory_location_name|$LOCATION.name" \
241
+ --cross-reference="corp_id|$GL.corp_acct_no" \
242
+ --cross-reference="corp_name|$GL.corp_acct_name"
243
+
244
+
245
+ # validate CONTRACTS ORIGINAL
246
+ ivalidate --case-insensitive --pretty -t $CONTRACTO \
247
+ --log-to=validation_errors \
248
+ --not-null=contract_number \
249
+ --not-null=contract_start \
250
+ --not-null=contract_end \
251
+ --not-null=vendor_name \
252
+ --not-null=mfr_item_id \
253
+ --not-null=mfr_name \
254
+ --not-null=item_uom \
255
+ --not-null=item_qoe \
256
+ --not-null=contract_price \
257
+ --not-null=contract_gpo_name \
258
+ --match="contract_number/[a-zA-Z0-9]/" \
259
+ --match="corp_name/[a-zA-Z0-9]/" \
260
+ --match="vendor_item_id/[a-zA-Z0-9]/" \
261
+ --match="vendor_name/[a-zA-Z0-9]/" \
262
+ --match="mfr_item_id/[a-zA-Z0-9]/" \
263
+ --match="mfr_name/[a-zA-Z0-9]/" \
264
+ --query="to_date(contract_end, 'YYYY-MM-DD') >= to_date(contract_start, 'YYYY-MM-DD') -- Contract end-date goes before start-date" \
265
+ --match="contract_status/^(1|2|3|A|I|Inactive|Active|Y)$/" \
266
+ --match="item_status/^(1|2|3|A|I|Inactive|Active|Y)$/" \
267
+ --consistent-by="corp_id|corp_name" \
268
+ --consistent-by="corp_name|corp_id" \
269
+ --consistent-by="mfr_number|mfr_name" \
270
+ --consistent-by="mfr_name|mfr_number" \
271
+ --consistent-by="vendor_code|vendor_name" \
272
+ --consistent-by="vendor_name|vendor_code" \
273
+ --cross-reference="vendor_name|$VENDOR.vendor_name" \
274
+ --cross-reference="mfr_name|$MFR.mfr_name" \
275
+ --cross-reference="corp_id|$GL.corp_acct_no" \
276
+ --cross-reference="corp_name|$GL.corp_acct_name" \
277
+ --match="contract_price/^[0-9]+(\.{0,1}[0-9]+|[0-9]*)$/" \
278
+ --match="item_qoe/^[0-9]+(\.{0,1}[0-9]+|[0-9]*)$/" \
279
+ --rquery="(item_uom NOT IN (SELECT code FROM uomstd) AND item_uom !~ '^[a-zA-Z0-9]{1,3}$') -- invalid item_uom" \
280
+ --unique="contract_gpo_name, contract_number, contract_start, contract_end, vendor_name, mfr_item_id, mfr_name, item_uom, corp_id" \
281
+
282
+ # validate ITEM
283
+ # Accepted:
284
+ # --rquery="mfr_name IN (SELECT mfr_name FROM $ITEM WHERE mfr_name IS NOT NULL GROUP BY mfr_name HAVING count(DISTINCT mfr_number) > 1) -- same mfr_name but with different mfr_number" \
285
+ ivalidate --case-insensitive --pretty -t $ITEM \
286
+ --log-to=validation_errors \
287
+ --not-null="item_id" \
288
+ --match="item_id/[a-zA-Z0-9]/" \
289
+ --not-null="item_descr" \
290
+ --match="item_descr/[a-zA-Z0-9]/" \
291
+ --not-null="item_uom" \
292
+ --not-null="default_uom" \
293
+ --not-null="item_price" \
294
+ --not-null="item_qoe" \
295
+ --not-null="corp_id" \
296
+ --not-null="corp_name" \
297
+ --not-null="vendor_code" \
298
+ --not-null="vendor_name" \
299
+ --not-null="mfr_number" \
300
+ --not-null="mfr_name" \
301
+ --not-null="active" \
302
+ --match="corp_id/[a-zA-Z0-9]/" \
303
+ --match="corp_name/[a-zA-Z0-9]/" \
304
+ --match="vendor_code/[a-zA-Z0-9]/" \
305
+ --match="vendor_name/[a-zA-Z0-9]/" \
306
+ --match="mfr_number/[a-zA-Z0-9]/" \
307
+ --match="mfr_name/[a-zA-Z0-9]/" \
308
+ --match="active/^(1|2|3|A|I)$/" \
309
+ --cross-reference="vendor_code|$VENDOR.vendor_code" \
310
+ --cross-reference="vendor_name|$VENDOR.vendor_name" \
311
+ --cross-reference="mfr_number|$MFR.mfr_number" \
312
+ --cross-reference="mfr_name|$MFR.mfr_name" \
313
+ --cross-reference="corp_id|$GL.corp_acct_no" \
314
+ --cross-reference="corp_name|$GL.corp_acct_name" \
315
+ --consistent-by="corp_id|corp_name" \
316
+ --consistent-by="corp_name|corp_id" \
317
+ --consistent-by="mfr_number|mfr_name" \
318
+ --consistent-by="mfr_name|mfr_number" \
319
+ --consistent-by="vendor_code|vendor_name" \
320
+ --consistent-by="vendor_name|vendor_code" \
321
+ --rquery="(item_uom NOT IN (SELECT code FROM uomstd) AND item_uom !~ '^[a-zA-Z0-9]{1,3}$') -- invalid item_uom" \
322
+ --rquery="(default_uom NOT IN (SELECT code FROM uomstd) AND default_uom !~ '^[a-zA-Z0-9]{1,3}$') -- invalid default_uom" \
323
+ --match="item_price/^[0-9]+(\.{0,1}[0-9]+|[0-9]*)$/" \
324
+ --match="item_qoe/^[0-9]+(\.{0,1}[0-9]+|[0-9]*)$/"
325
+
326
+ # validate PO
327
+ ivalidate --case-insensitive --pretty -t $PO \
328
+ --log-to=validation_errors \
329
+ --not-null=po_no \
330
+ --match="po_no/[a-zA-Z0-9]/" \
331
+ --not-null=po_date \
332
+ --not-null=corp_id \
333
+ --match="corp_id/[a-zA-Z0-9]/" \
334
+ --not-null=corp_name \
335
+ --match="corp_name/[a-zA-Z0-9]/" \
336
+ --not-null=cost_center_id \
337
+ --match="cost_center_id/[a-zA-Z0-9]/" \
338
+ --not-null=cost_center_name \
339
+ --match="cost_center_name/[a-zA-Z0-9]/" \
340
+ --not-null=po_line_number \
341
+ --match="po_line_number/^[1-9][0-9]*$/" \
342
+ --not-null=item_id \
343
+ --match="item_id/[a-zA-Z0-9]/" \
344
+ --not-null=vendor_name \
345
+ --match="vendor_name/[a-zA-Z0-9]/" \
346
+ --not-null=vendor_code \
347
+ --match="vendor_code/[a-zA-Z0-9]/" \
348
+ --not-null=mfr_name \
349
+ --match="mfr_name/[a-zA-Z0-9]/" \
350
+ --not-null=mfr_number \
351
+ --match="mfr_number/[a-zA-Z0-9]/" \
352
+ --not-null=item_descr \
353
+ --consistent-by="corp_id|corp_name" \
354
+ --consistent-by="corp_name|corp_id" \
355
+ --consistent-by="vendor_code|vendor_name" \
356
+ --consistent-by="vendor_name|vendor_code" \
357
+ --consistent-by="mfr_name|mfr_number" \
358
+ --unique="po_no, po_line_number" \
359
+ --rquery="(item_id not like '%~%' and item_id not in (select item_id from items)) -- item_id does not reference items.item_id" \
360
+ --cross-reference="vendor_code|$VENDOR.vendor_code" \
361
+ --cross-reference="vendor_name|$VENDOR.vendor_name" \
362
+ --cross-reference="mfr_number|$MFR.mfr_number" \
363
+ --cross-reference="mfr_name|$MFR.mfr_name" \
364
+ --cross-reference="corp_id|$GL.corp_acct_no" \
365
+ --cross-reference="corp_name|$GL.corp_acct_name" \
366
+ --cross-reference="cost_center_id|$GL.cc_acct_no" \
367
+ --cross-reference="cost_center_name|$GL.cc_acct_name" \
368
+ --rquery="(purchase_uom NOT IN (SELECT code FROM uomstd) AND purchase_uom !~ '^[a-zA-Z0-9]{1,3}$') -- invalid purchase_uom" \
369
+ --rquery="(item_id IS NOT NULL AND (vendor_code IS NOT NULL OR vendor_name IS NOT NULL) AND vendor_item_id IS NULL) -- vendor_item_id is null" \
370
+ --match="purchase_price/^[0-9]+(\.{0,1}[0-9]+|[0-9]*)$/" \
371
+ --match="purchase_qoe/^[0-9]+(\.{0,1}[0-9]+|[0-9]*)$/"
372
+
373
+ # do not check --match="item_descr/[a-zA-Z0-9]/" \
374
+
375
+ # validate Req
376
+ ivalidate --case-insensitive --pretty -t $REQ \
377
+ --log-to=validation_errors \
378
+ --not-null="req_no" \
379
+ --match="req_no/[a-zA-Z0-9]/" \
380
+ --not-null="req_date" \
381
+ --match="req_date/[a-zA-Z0-9]/" \
382
+ --not-null="corp_id" \
383
+ --match="corp_id/[a-zA-Z0-9]/" \
384
+ --not-null="corp_name" \
385
+ --match="corp_name/[a-zA-Z0-9]/" \
386
+ --not-null="req_line_number" \
387
+ --match="req_line_number/^[1-9][0-9]*$/" \
388
+ --not-null="item_id" \
389
+ --match="item_id/[a-zA-Z0-9]/" \
390
+ --not-null="vendor_name" \
391
+ --match="vendor_name/[a-zA-Z0-9]/" \
392
+ --not-null="vendor_code" \
393
+ --match="vendor_code/[a-zA-Z0-9]/" \
394
+ --not-null="mfr_name" \
395
+ --match="mfr_name/[a-zA-Z0-9]/" \
396
+ --not-null="item_descr" \
397
+ --match="item_descr/[a-zA-Z0-9]/" \
398
+ --consistent-by="corp_id|corp_name" \
399
+ --consistent-by="corp_name|corp_id" \
400
+ --rquery="(item_id not like '%~[%' and item_id not in (select item_id from items)) -- item_id does not reference items.item_id" \
401
+ --cross-reference="corp_id|$GL.corp_acct_no" \
402
+ --cross-reference="corp_name|$GL.corp_acct_name" \
403
+ --cross-reference="vendor_name|$VENDOR.vendor_name" \
404
+ --cross-reference="vendor_code|$VENDOR.vendor_code" \
405
+ --cross-reference="mfr_name|$MFR.mfr_name" \
406
+ --cross-reference="costcenter_id|$GL.cc_acct_no" \
407
+ --cross-reference="costcenter_name|$GL.cc_acct_name" \
408
+ --unique="req_no, req_line_number" \
409
+
410
+ # validate USERS
411
+ ivalidate --case-insensitive --pretty -t $USER \
412
+ --log-to=validation_errors \
413
+ --not-null="email" \
414
+ --unique="email" \
415
+ --query="lower(email) ~* '[a-z0-9][a-z0-9_\.]+@[a-z0-9][a-z0-9_\.\-]+\.[a-z0-9_\.\-]+' -- invalid email address"
416
+
417
+ # validate INVENTORY
418
+ ivalidate --case-insensitive --pretty -t $INVENTORY \
419
+ --log-to=validation_errors \
420
+ --not-null="item_id" \
421
+ --match="item_id/[a-zA-Z0-9]/" \
422
+ --not-null="loc_id" \
423
+ --match="loc_id/[a-zA-Z0-9]/" \
424
+ --not-null="vendor_code" \
425
+ --match="vendor_code/[a-zA-Z0-9]/" \
426
+ --not-null="vendor_name" \
427
+ --match="vendor_name/[a-zA-Z0-9]/" \
428
+ --not-null="corp_id" \
429
+ --match="corp_name/[a-zA-Z0-9]/" \
430
+ --not-null="location_name" \
431
+ --match="location_name/[a-zA-Z0-9]/" \
432
+ --not-null="item_id" \
433
+ --match="item_id/[a-zA-Z0-9]/" \
434
+ --match="inventory_status/^(Active|Pending Inactive|Inactive)$/" \
435
+ --cross-reference="item_id|$ITEM.item_id" \
436
+ --cross-reference="location_name|$LOCATION.name" \
437
+ --cross-reference="vendor_code|$VENDOR.vendor_code" \
438
+ --cross-reference="vendor_name|$VENDOR.vendor_name" \
439
+ --cross-reference="corp_id|$GL.corp_acct_no" \
440
+ --cross-reference="corp_name|$GL.corp_acct_name"
441
+
442
+ # validate
443
+ ivalidate --case-insensitive --pretty -t $ITEMCOST \
444
+ --log-to=validation_errors \
445
+ --not-null="corp_acct_no" \
446
+ --match="corp_acct_no/[a-zA-Z0-9]/" \
447
+ --not-null="item_no" \
448
+ --match="item_no/[a-zA-Z0-9]/" \
449
+ --not-null="excp_type" \
450
+ --match="excp_type/^(A|R)$/" \
451
+ --cross-reference="corp_acct_no|$GL.corp_acct_no" \
452
+ --cross-reference="item_no|$ITEM.item_id" \
453
+ --cross-reference="exp_acct_no|$GL.exp_acct_no"
454
+
455
+
456
+
457
+ ####################################################
458
+ # Create report file for every table (extract 1000 records for every error)
459
+ # These file will then be used for the Validation Report
460
+ ####################################################
461
+
462
+ iexport -t $ITEMCOST \
463
+ -o "$OUTPUT_DIR/$ITEMCOST.csv" -f csv --no-quote-empty --quotes --headers \
464
+ --query="select * from (select ROW_NUMBER() OVER (PARTITION BY error) AS group_index, *
465
+ FROM ( select unnest(string_to_array(validation_errors, ' || ')) as error, * from
466
+ $ITEMCOST order by id ) as main) as tmp
467
+ where group_index <= 1000" \
468
+ --exclude="id, validation_errors, group_index"
469
+
470
+ iexport -t $CONTRACTO \
471
+ -o "$OUTPUT_DIR/$CONTRACTO.csv" -f csv --no-quote-empty --quotes --headers \
472
+ --query="select * from (select ROW_NUMBER() OVER (PARTITION BY error) AS group_index, *
473
+ FROM ( select unnest(string_to_array(validation_errors, ' || ')) as error, * from
474
+ $CONTRACTO order by id ) as main) as tmp
475
+ where group_index <= 1000" \
476
+ --exclude="id, validation_errors, group_index"
477
+
478
+ iexport -t $VENDOR \
479
+ -o "$OUTPUT_DIR/$VENDOR.csv" -f csv --no-quote-empty --quotes --headers \
480
+ --query="select * from (select ROW_NUMBER() OVER (PARTITION BY error) AS group_index, *
481
+ FROM ( select unnest(string_to_array(validation_errors, ' || ')) as error, * from
482
+ $VENDOR order by id ) as main) as tmp
483
+ where group_index <= 1000" \
484
+ --exclude="id, validation_errors, group_index"
485
+
486
+ iexport -t $MFR \
487
+ -o "$OUTPUT_DIR/$MFR.csv" -f csv --no-quote-empty --quotes --headers \
488
+ --query="select * from (select ROW_NUMBER() OVER (PARTITION BY error) AS group_index, *
489
+ FROM ( select unnest(string_to_array(validation_errors, ' || ')) as error, * from
490
+ $MFR order by id ) as main) as tmp
491
+ where group_index <= 1000" \
492
+ --exclude="id, validation_errors, group_index"
493
+
494
+ iexport -t $GL \
495
+ -o "$OUTPUT_DIR/$GL.csv" -f csv --no-quote-empty --quotes --headers \
496
+ --query="select * from (select ROW_NUMBER() OVER (PARTITION BY error) AS group_index, *
497
+ FROM ( select unnest(string_to_array(validation_errors, ' || ')) as error, * from
498
+ $GL order by id ) as main) as tmp
499
+ where group_index <= 1000" \
500
+ --exclude="id, validation_errors, group_index"
501
+
502
+ iexport -t $PO \
503
+ -o "$OUTPUT_DIR/$PO.csv" -f csv --no-quote-empty --quotes --headers \
504
+ --query="select * from (select ROW_NUMBER() OVER (PARTITION BY error) AS group_index, *
505
+ FROM ( select unnest(string_to_array(validation_errors, ' || ')) as error, * from
506
+ $PO order by id ) as main) as tmp
507
+ where group_index <= 1000" \
508
+ --exclude="id, validation_errors, group_index"
509
+
510
+ iexport -t $INVENTORY \
511
+ -o "$OUTPUT_DIR/$INVENTORY.csv" -f csv --no-quote-empty --quotes --headers \
512
+ --query="select * from (select ROW_NUMBER() OVER (PARTITION BY error) AS group_index, *
513
+ FROM ( select unnest(string_to_array(validation_errors, ' || ')) as error, * from
514
+ $INVENTORY order by id ) as main) as tmp
515
+ where group_index <= 1000" \
516
+ --exclude="id, validation_errors, group_index"
517
+
518
+ iexport -t $REQ \
519
+ -o "$OUTPUT_DIR/$REQ.csv" -f csv --no-quote-empty --quotes --headers \
520
+ --query="select * from (select ROW_NUMBER() OVER (PARTITION BY error) AS group_index, *
521
+ FROM ( select unnest(string_to_array(validation_errors, ' || ')) as error, * from
522
+ $REQ order by id ) as main) as tmp
523
+ where group_index <= 1000" \
524
+ --exclude="id, validation_errors, group_index"
525
+
526
+ iexport -t $ITEM \
527
+ -o "$OUTPUT_DIR/$ITEM.csv" -f csv --no-quote-empty --quotes --headers \
528
+ --query="select * from (select ROW_NUMBER() OVER (PARTITION BY error) AS group_index, *
529
+ FROM ( select unnest(string_to_array(validation_errors, ' || ')) as error, * from
530
+ $ITEM order by id ) as main) as tmp
531
+ where group_index <= 1000" \
532
+ --exclude="id, validation_errors, group_index"
533
+
534
+ iexport -t $USER \
535
+ -o "$OUTPUT_DIR/$USER.csv" -f csv --no-quote-empty --quotes --headers \
536
+ --query="select * from (select ROW_NUMBER() OVER (PARTITION BY error) AS group_index, *
537
+ FROM ( select unnest(string_to_array(validation_errors, ' || ')) as error, * from
538
+ $USER order by id ) as main) as tmp
539
+ where group_index <= 1000" \
540
+ --exclude="id, validation_errors, group_index"
541
+
542
+ iexport -t $LOCATION \
543
+ -o "$OUTPUT_DIR/$LOCATION.csv" -f csv --no-quote-empty --quotes --headers \
544
+ --query="select * from (select ROW_NUMBER() OVER (PARTITION BY error) AS group_index, *
545
+ FROM ( select unnest(string_to_array(validation_errors, ' || ')) as error, * from
546
+ $LOCATION order by id ) as main) as tmp
547
+ where group_index <= 1000" \
548
+ --exclude="id, validation_errors, group_index"
549
+
550
+
551
+ # Use SQL to compute the summary, write the outputs to summary.csv
552
+ # --------------------------------------------------------------
553
+ iexport --output="$OUTPUT_DIR/summary.csv" -f csv --no-quote-empty --quotes --headers \
554
+ --query="(select 'ContractMaster' as input_file, unnest(string_to_array(validation_errors, ' || ')) as error, count(*), round((count(*) * 100)::numeric / (select count(*) from $CONTRACTO), 2)::varchar || '%' as percentage from $CONTRACTO group by error order by error) union
555
+ (select 'VendorMaster' as input_file, unnest(string_to_array(validation_errors, ' || ')) as error, count(*), round((count(*) * 100)::numeric / (select count(*) from $VENDOR), 2)::varchar || '%' as percentage from $VENDOR group by error order by error) union
556
+ (select 'ItemMaster' as input_file, unnest(string_to_array(validation_errors, ' || ')) as error, count(*), round((count(*) * 100)::numeric / (select count(*) from $ITEM), 2)::varchar || '%' as percentage from $ITEM group by error order by error) union
557
+ (select 'ReqHistoryLoad' as input_file, unnest(string_to_array(validation_errors, ' || ')) as error, count(*), round((count(*) * 100)::numeric / (select count(*) from $REQ), 2)::varchar || '%' as percentage from $REQ group by error order by error) union
558
+ (select 'MfrMaster' as input_file, unnest(string_to_array(validation_errors, ' || ')) as error, count(*), round((count(*) * 100)::numeric / (select count(*) from $MFR), 2)::varchar || '%' as percentage from $MFR group by error order by error) union
559
+ (select 'PurchaseOrder' as input_file, unnest(string_to_array(validation_errors, ' || ')) as error, count(*), round((count(*) * 100)::numeric / (select count(*) from $PO), 2)::varchar || '%' as percentage from $PO group by error order by error) union
560
+ (select 'Inventory' as input_file, unnest(string_to_array(validation_errors, ' || ')) as error, count(*), round((count(*) * 100)::numeric / (select count(*) from $INVENTORY), 2)::varchar || '%' as percentage from $INVENTORY group by error order by error) union
561
+ (select 'User' as input_file, unnest(string_to_array(validation_errors, ' || ')) as error, count(*), round((count(*) * 100)::numeric / (select count(*) from $USER), 2)::varchar || '%' as percentage from $USER group by error order by error) union
562
+ (select 'Location' as input_file, unnest(string_to_array(validation_errors, ' || ')) as error, count(*), round((count(*) * 100)::numeric / (select count(*) from $LOCATION), 2)::varchar || '%' as percentage from $LOCATION group by error order by error) union
563
+ (select 'ItemCost' as input_file, unnest(string_to_array(validation_errors, ' || ')) as error, count(*), round((count(*) * 100)::numeric / (select count(*) from $ITEMCOST), 2)::varchar || '%' as percentage from $ITEMCOST group by error order by error) union
564
+ (select 'GLAccount' as input_file, unnest(string_to_array(validation_errors, ' || ')) as error, count(*), round((count(*) * 100)::numeric / (select count(*) from $GL), 2)::varchar || '%' as percentage from $GL group by error order by error)"
565
+
566
+ # Merge summary.xls and report files into one single file with several tabs
567
+ imerge --output=$OUTPUT_DIR/$ORGNAME.xls \
568
+ --input="Summary:$OUTPUT_DIR/summary.csv" \
569
+ --input="ItemCostCenterAcctExceptions:$OUTPUT_DIR/$ITEMCOST.csv" \
570
+ --input="ContractMaster:$OUTPUT_DIR/$CONTRACTO.csv" \
571
+ --input="ItemMaster:$OUTPUT_DIR/$ITEM.csv" \
572
+ --input="MfrMaster:$OUTPUT_DIR/$MFR.csv" \
573
+ --input="PurchaseOrder:$OUTPUT_DIR/$PO.csv" \
574
+ --input="User:$OUTPUT_DIR/$USER.csv" \
575
+ --input="Location:$OUTPUT_DIR/$LOCATION.csv" \
576
+ --input="ReqHistoryLoad:$OUTPUT_DIR/$REQ.csv" \
577
+ --input="GLAccount:$OUTPUT_DIR/$GL.csv" \
578
+ --input="Inventory:$OUTPUT_DIR/$INVENTORY.csv"
579
+
580
+ exit
data/lib/idata/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Idata
2
- VERSION = "0.1.29"
2
+ VERSION = "0.1.30"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: idata
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.29
4
+ version: 0.1.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nghi Pham
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-07-24 00:00:00.000000000 Z
11
+ date: 2014-07-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -92,6 +92,7 @@ files:
92
92
  - bin/ipatch
93
93
  - bin/isanitize
94
94
  - bin/ivalidate
95
+ - full.sh
95
96
  - idata.gemspec
96
97
  - lib/idata.rb
97
98
  - lib/idata/version.rb