51: -- Figure out each number of buckets of each type
52: -- ----------------------------------------------
53: IF (arg_bucket_type = DAILY_BUCKET) OR (arg_bucket_type = -1) THEN
54:
55: dbms_output.put_line('Creating daily buckets');
56: var_num_days := MAX_BUCKETS;
57: var_num_weeks := 0;
58: var_num_periods := 0;
59: ELSIF (arg_bucket_type = WEEKLY_BUCKET) OR (arg_bucket_type = -2) THEN
57: var_num_weeks := 0;
58: var_num_periods := 0;
59: ELSIF (arg_bucket_type = WEEKLY_BUCKET) OR (arg_bucket_type = -2) THEN
60:
61: dbms_output.put_line('Creating weekly buckets');
62: var_num_days := 0;
63: var_num_weeks := MAX_BUCKETS;
64: var_num_periods := 0;
65: ELSIF (arg_bucket_type = PERIODIC_BUCKET) OR (arg_bucket_type = -3) THEN
63: var_num_weeks := MAX_BUCKETS;
64: var_num_periods := 0;
65: ELSIF (arg_bucket_type = PERIODIC_BUCKET) OR (arg_bucket_type = -3) THEN
66:
67: dbms_output.put_line('Creating periodic buckets');
68: var_num_days := 0;
69: var_num_weeks := 0;
70: var_num_periods := MAX_BUCKETS;
71: ELSE
69: var_num_weeks := 0;
70: var_num_periods := MAX_BUCKETS;
71: ELSE
72:
73: dbms_output.put_line('Creating customized buckets');
74: DECLARE dummy NUMBER;
75: BEGIN
76: SELECT count(*)
77: INTO dummy
82: IF dummy = 0 THEN
83: -- -------------------------------------
84: -- The bucket type is not in MFG_LOOKUPS
85: -- -------------------------------------
86: dbms_output.put_line('Creating new lookup');
87: INSERT INTO mfg_lookups
88: (lookup_type,
89: lookup_code,
90: last_update_date,
125: var_num_periods := MAX_BUCKETS - var_num_days - var_num_weeks;
126:
127: END IF;
128:
129: dbms_output.put_line('Number of days :'||var_num_days);
130: dbms_output.put_line('Number of weeks :'||var_num_weeks);
131: dbms_output.put_line('Number of periods:'||var_num_periods);
132:
133: var_the_date := var_plan_start_date;
126:
127: END IF;
128:
129: dbms_output.put_line('Number of days :'||var_num_days);
130: dbms_output.put_line('Number of weeks :'||var_num_weeks);
131: dbms_output.put_line('Number of periods:'||var_num_periods);
132:
133: var_the_date := var_plan_start_date;
134:
127: END IF;
128:
129: dbms_output.put_line('Number of days :'||var_num_days);
130: dbms_output.put_line('Number of weeks :'||var_num_weeks);
131: dbms_output.put_line('Number of periods:'||var_num_periods);
132:
133: var_the_date := var_plan_start_date;
134:
135: IF var_num_days > 0 THEN
150:
151: BEGIN
152:
153: OPEN DAYS;
154: dbms_output.put_line('Getting the daily buckets');
155: -- -------------------------------------------------------------
156: -- Get the days portion and place it in the front section of the
157: -- array var_the_dates
158: -- -------------------------------------------------------------
160: counter := counter + 1;
161: FETCH DAYS INTO var_dates(counter);
162: EXIT WHEN DAYS%NOTFOUND;
163: var_the_date := var_dates(counter);
164: dbms_output.put_line('Got date '||counter||': '||var_dates(counter));
165: END LOOP;
166: counter := counter - 1;
167: CLOSE DAYS;
168: END;
191: BEGIN
192:
193: IF counter = 0 THEN
194:
195: dbms_output.put_line('Weeks only');
196: var_the_date := mrp_calendar.prev_work_day(arg_organization_id,
197: WEEKLY_BUCKET,
198: var_the_date);
199: dbms_output.put_line('Reset var_the_date to:'||var_the_date);
195: dbms_output.put_line('Weeks only');
196: var_the_date := mrp_calendar.prev_work_day(arg_organization_id,
197: WEEKLY_BUCKET,
198: var_the_date);
199: dbms_output.put_line('Reset var_the_date to:'||var_the_date);
200: END IF;
201: OPEN WEEKS;
202: dbms_output.put_line('Getting the weekly buckets');
203: -- --------------------------------------------------------------
198: var_the_date);
199: dbms_output.put_line('Reset var_the_date to:'||var_the_date);
200: END IF;
201: OPEN WEEKS;
202: dbms_output.put_line('Getting the weekly buckets');
203: -- --------------------------------------------------------------
204: -- Get the weeks portion and place it in the front section of the
205: -- array var_the_dates
206: -- --------------------------------------------------------------
208: counter := counter + 1;
209: FETCH WEEKS INTO var_dates(counter);
210: EXIT WHEN WEEKS%NOTFOUND;
211: var_the_date := var_dates(counter);
212: dbms_output.put_line('Got date '||counter||': '||var_dates(counter));
213: END LOOP;
214: CLOSE WEEKS;
215: counter := counter - 1;
216: END;
233:
234: BEGIN
235:
236: IF counter = 0 THEN
237: dbms_output.put_line('Periodic only');
238: var_the_date := mrp_calendar.prev_work_day(arg_organization_id,
239: PERIODIC_BUCKET,
240: var_the_date);
241: dbms_output.put_line('Reset var_the_date to:'||var_the_date);
237: dbms_output.put_line('Periodic only');
238: var_the_date := mrp_calendar.prev_work_day(arg_organization_id,
239: PERIODIC_BUCKET,
240: var_the_date);
241: dbms_output.put_line('Reset var_the_date to:'||var_the_date);
242: END IF;
243:
244: OPEN PERIODS;
245: dbms_output.put_line('Getting the periodic buckets');
241: dbms_output.put_line('Reset var_the_date to:'||var_the_date);
242: END IF;
243:
244: OPEN PERIODS;
245: dbms_output.put_line('Getting the periodic buckets');
246: -- --------------------------------------------------------------
247: -- Get the weeks portion and place it in the front section of the
248: -- array var_the_dates
249: -- --------------------------------------------------------------
251: counter := counter + 1;
252: FETCH PERIODS INTO var_dates(counter);
253: EXIT WHEN PERIODS%NOTFOUND;
254: var_the_date := var_dates(counter);
255: dbms_output.put_line('Got date '||counter||': '||var_dates(counter));
256: END LOOP;
257: counter := counter - 1;
258: CLOSE PERIODS;
259: END;
265: -- This means that there weren't enough days ,weeks and months
266: -- to fill out all the columns in the table. We will set the
267: -- remaining columns with one day increment from the last date
268: -- -----------------------------------------------------------
269: dbms_output.put_line('There were not enough dates');
270: dbms_output.put_line('The date counter is: '||counter);
271: IF counter <= 1 THEN
272:
273: -- ----------------------------------------------------
266: -- to fill out all the columns in the table. We will set the
267: -- remaining columns with one day increment from the last date
268: -- -----------------------------------------------------------
269: dbms_output.put_line('There were not enough dates');
270: dbms_output.put_line('The date counter is: '||counter);
271: IF counter <= 1 THEN
272:
273: -- ----------------------------------------------------
274: -- We found no dates at all. Set the first entry in the
274: -- We found no dates at all. Set the first entry in the
275: -- var_dates array to avoid an out of bounds exception
276: -- in the loop bellow.
277: -- ----------------------------------------------------
278: dbms_output.put_line('There were no dates');
279: counter := 1;
280: var_dates(counter) := var_the_date;
281: dbms_output.put_line('Set first date to '||var_dates(counter));
282: END IF;
277: -- ----------------------------------------------------
278: dbms_output.put_line('There were no dates');
279: counter := 1;
280: var_dates(counter) := var_the_date;
281: dbms_output.put_line('Set first date to '||var_dates(counter));
282: END IF;
283:
284: FOR j IN (counter + 1) .. MAX_BUCKETS + 1 LOOP
285:
287: -- Set the current element of the var_dates array to one plus
288: -- the previous elemnt
289: -- ----------------------------------------------------------
290: var_dates(j) := var_dates(j - 1) + 1;
291: dbms_output.put_line('Set date '||j||' to:'||var_dates(j));
292: END LOOP;
293: END IF; -- < MAX_BUCKETS
294:
295: -- ----------------------------------------------------------
359: WHERE compile_designator = arg_compile_designator
360: AND organization_id = arg_organization_id
361: AND bucket_type = DAILY_BUCKET;
362:
363: dbms_output.put_line('Current start date is '||var_current_start_date);
364:
365: EXCEPTION WHEN NO_DATA_FOUND THEN
366:
367: -- -------------------------------------------
367: -- -------------------------------------------
368: -- There are no rows so we need to create them
369: -- -------------------------------------------
370: recreate := TRUE;
371: dbms_output.put_line('No rows exist. Will recreate them');
372:
373: END;
374:
375: -- ------------------------------------------------------
383: WHERE compile_designator = arg_compile_designator
384: AND organization_id = arg_organization_id
385: AND bucket_type = -1;
386:
387: dbms_output.put_line('Current Start Date for Current Data is '||
388: var_curr_start_date1);
389: EXCEPTION WHEN NO_DATA_FOUND THEN
390: recreate1 := TRUE;
391: dbms_output.put_line('No rows exist for Current Data Buckets.
387: dbms_output.put_line('Current Start Date for Current Data is '||
388: var_curr_start_date1);
389: EXCEPTION WHEN NO_DATA_FOUND THEN
390: recreate1 := TRUE;
391: dbms_output.put_line('No rows exist for Current Data Buckets.
392: Will recreate them');
393: END;
394:
395:
402: var_plan_start_date := mrp_calendar.next_work_day(arg_organization_id,
403: DAILY_BUCKET,
404: var_plan_start_date);
405:
406: dbms_output.put_line('Plan start date is: '||var_plan_start_date);
407:
408: IF (var_plan_start_date <> var_current_start_date) THEN
409:
410: -- ------------------------------------------------------------------
411: -- The plan start date has changed since the last time the rows where
412: -- created so we need to recreate them
413: -- ------------------------------------------------------------------
414: recreate := TRUE;
415: dbms_output.put_line('Plan start date has changed will recreate');
416:
417: END IF;
418:
419: IF (var_curr_start_date1 <> TRUNC(sysdate)) THEN
421: -- The start date for current data buckets is changed so we need to
422: -- recreate them
423: -- -------------------------------------------------------------------
424: recreate1 := TRUE;
425: dbms_output.put_line('Plan start date has changed will
426: recreate for Current Data');
427: END IF;
428:
429: IF recreate = TRUE THEN
456: ELSE
457: -- ----------------------------------
458: -- Return because nothing has changed
459: -- ----------------------------------
460: dbms_output.put_line('Nothing has changed');
461: END IF;
462:
463: -- ------------------------------------------
464: -- We will recreate buckets for current data
484: AND organization_id = arg_organization_id;
485: EXCEPTION WHEN NO_DATA_FOUND THEN
486: NULL;
487: END;
488: dbms_output.put_line('creating buckets for current data');
489:
490: mrp_wb_bucket_dates.populate_row(arg_organization_id,
491: arg_compile_designator,
492: -1);
502: mrp_custom_wb.mrp_custom_wb_bucket_dates(arg_organization_id,
503: arg_compile_designator);
504: ELSE
505:
506: dbms_output.put_line('Nothing has changed for Current data');
507:
508: END IF;
509: COMMIT WORK;
510: END populate_bucket_dates;