-
Notifications
You must be signed in to change notification settings - Fork 0
/
ForecastUtility.gs
671 lines (512 loc) · 23.8 KB
/
ForecastUtility.gs
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
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
var ForecastUtility=new function(){
/**
* gets the historical columns number
* @param {Object} sheet the sheeet
* @return {object} object with the columns number {first, last}
* @throws {InvalidArgument}
* @throws {SheetNotFound} if the given sheet is not found
*/
this.getHistoricalColNumBySheet=function(sheet){
var commodity;
if (!sheet) {
throw "InvalidArgument";
}
commodity=FirebaseConnector.getCommodityName(sheet);
return ForecastUtility.getHistoricalColNum(commodity);
};
/**
* gets the historical columns number
* @param {string} commodityName the commodity name
* @return {object} object with the columns number {first, last}
* @throws {InvalidArgument}
* @throws {SheetNotFound} if the given sheet is not found
*/
this.getHistoricalColNum=function(commodityName){
var config, firstCol, lastCol, previousForecast;
if (!commodityName) {
throw "InvalidArgument";
}
config = AmisNamedRanges.getCommodityNamedRanges(commodityName);
if (!config) {
throw "SheetNotFound";
}
previousForecast=config.previousForecast;
firstCol=ConvertA1.colA1ToIndex(previousForecast.first.split(":")[0],1);
lastCol=ConvertA1.colA1ToIndex(previousForecast.last.split(":")[0],1);
return {first:firstCol, last:lastCol};
};
/**
* check if the activeRange is in the first column of a period
* @param {string} activeRangeA1 the active range in A1A1Notation
* @param {string} commodityName (optional) the commodity name
* @return {bool} true if edited, false otherwise
* @throws {InvalidArgument}
*/
this.editedWrongForecast=function(activeRangeA1, commodity){
var blockedRanges=[], isCell=false, isRange=false;
if (!activeRangeA1) {
throw "InvalidArgument";
}
commodity=(commodity || FirebaseConnector.getCommodityName());
blockedRanges=[].concat(
ForecastUtility.getFirstFcOfPeriod(0),
ForecastUtility.getFirstFcOfPeriod(1)
);
isRange=Utility.isRange(activeRangeA1);
isCell=Utility.isCell(activeRangeA1);
for (var i = 0, blockedRanges_length=blockedRanges.length, r; r=blockedRanges[i], i<blockedRanges_length; i++) {
if (isRange && Utility.isRangesOverlap(r, activeRangeA1)) {
return true;
}else if (isCell && Utility.isInRange(r, activeRangeA1)) {
return true;
}
}
return false;
};
/**
* get the first forecast of a period
* @param {int} periodIndex period you want (EG. 0 for periodA , 1 periodB )
* @param {string} commodityName (optional) the commodity name
* @return {[string]} array of ranges of the column
*/
this.getFirstFcOfPeriod = function( periodIndex, commodity ) {
if ( !periodIndex && periodIndex!==0 ) {
throw "InvalidArgument";
}
var periodNR = Config.addNewForecastNamedRange[ periodIndex ];
if ( !periodNR ) {
throw "InvalidPeriod";
}
return AmisNamedRanges.getCommodityNamedRanges(commodity)[ periodNR[ 0 ] ];
};
/**
* ADD A NEW FORECAST on the google sheet
* @param {int} the period you want (EG. 0 for periodA , 1 periodB )
*/
this.addNewForecast= function(zeroOrOne){
//get from config the named ranges
var addNewForecastNamedRanges= Config.addNewForecastNamedRange[zeroOrOne];
//range 'where to copy'
var rangesTo =AmisNamedRanges.getCommodityNamedRanges()[addNewForecastNamedRanges[0]];
//range that contains values to be copied
var rangesFrom =AmisNamedRanges.getCommodityNamedRanges()[addNewForecastNamedRanges[1]];
ForecastUtility.copyValuesBetweenForecasts(rangesFrom,rangesTo);
ForecastUtility.blankForecast(rangesFrom);
};
/**
* copy values of the last forecast
* @param {Range}
*/
this.copyValuesBetweenForecasts= function(rangesFrom,rangesTo){
var length = rangesTo.length;
for (var i=0; i<length; i++){
SpreadSheetCache.getActiveSheet().getRange(rangesTo[i]).setValues(
SpreadSheetCache.getActiveSheet().getRange(rangesFrom[i]).getValues()
);
}
};
/**
* blank a forecast
* @param {Range}
*/
this.blankForecast= function(rangesToBeBlanked){
var length = rangesToBeBlanked.length;
for (var i=0; i<length; i++){
SpreadSheetCache.getActiveSheet().getRange(rangesToBeBlanked[i]).setValue('');
}
};
/**
* get all the namedRanges for the Forecasting notes
* @return {[string]} array of ranges in A1Notation
*/
this.getForecastingNotesRanges = function() {
var ranges = [],
cnr;
cnr = AmisNamedRanges.getCommodityNamedRanges();
ranges = [].concat(
cnr[ Config.notesNamedRanges[ 0 ] ],
cnr[ Config.notesNamedRanges[ 1 ] ]
);
return ranges;
};
/**
* check if a cell is in a ForecastMetodology of ForecastingNote range
* @param {string} cell the cell to check in A1Notation for better performance
* @return {bool} true if the cell is in a ForecastMetodology of ForecastingNote range, false otherwise
* @throws {InvalidArgument}
*/
this.isFMorFN=function(cell){
var ranges=[];
if(!cell){
throw "InvalidArgument";
}
ranges=ranges.concat(
this.getForecastingNotesRanges(),
ForecastingMethodologies.getFMRanges()
);
return Utility.isInAnyRange(ranges, cell);
};
/**
* ADD A NEW FORECAST on the google sheet
* @param {string} the period you want
*/
this.addForecastByPeriod= function(period){
SpreadSheetCache.getActiveSheet().getRange('V10:V31').copyTo( SpreadSheetCache.getActiveSheet().getRange('U10:U31'), {contentsOnly:true});
};
// END -- ADD A NEW FORECAST on the google sheet
/**
* TODO_ delete... DEPRECATED! ADD A NEW FORECAST on the google sheet
* @param {string} auth token
*/
this.addForecast16_17= function(userToken){
var period = '16-17';
ForecastUtility.addForecast(period,userToken);
};
// END -- ADD A NEW FORECAST on the google sheet
/**
* TODO_ delete... DEPRECATED! ADD A NEW FORECAST 17-18
* @param {string} auth token
*/
this.addForecast17_18= function(userToken){
var period = '17-18';
ForecastUtility.addForecast(period,userToken);
};
// END -- ADD A NEW FORECAST on the google sheet
/**
* ADD A NEW FORECAST on the google sheet FOR SECRETARIET
* @param {string} auth token
*/
this.addForecast16_17_Secretariet= function(userToken,chosenCountry){
chosenCountry = getSecretariatCountry();
var period = '16-17';
ForecastUtility.addForecastSecretariet(period,userToken,chosenCountry);
};
// END -- ADD A NEW FORECAST on the google sheet FOR SECRETARIET
/**
* ADD A NEW FORECAST 17-18 FOR SECRETARIET
* @param {string} auth token
*/
this.addForecast17_18_Secretariet= function(userToken, chosenCountry){
chosenCountry = getSecretariatCountry();
var period = '17-18';
ForecastUtility.addForecastSecretariet(period,userToken,chosenCountry);
};
// END -- ADD A NEW FORECAST on the google sheet FOR SECRETARIET
/**
* hide period's unactive columns for ALL period
* @param {string} userToken firebase token
*/
this.hideAllPeriodUnactiveColumns=function(userToken) {
var allPeriodConf, allPeriodConfNode, commodity, countryName, period;
countryName = FirebaseConnector.getCountryNameFromSheet(userToken);
commodity = FirebaseConnector.getCommodityName();
allPeriodConfNode = 'config/addForecast/' + countryName + '/' + commodity;
allPeriodConf = JSON.parse(FirebaseConnector.getFireBaseData(allPeriodConfNode, userToken));
for (var _i in allPeriodConf) {
if (allPeriodConf[_i]) {
period=allPeriodConf[_i];
ForecastUtility.hidePeriodUnactiveColumns(period);
}
}
};
/**
* hide period's unactive columns for ALL period FOR SECRETARIAT
* @param {string} userToken firebase token
*/
this.hideAllPeriodUnactiveColumnsSecretariat=function(userToken) {
var allPeriodConf, allPeriodConfNode, commodity, countryName, period;
countryName = getSecretariatCountry();
commodity = FirebaseConnector.getCommodityName();
allPeriodConfNode = 'config/addForecast/' + countryName + '/' + commodity;
allPeriodConf = JSON.parse(FirebaseConnector.getFireBaseData(allPeriodConfNode, userToken));
for (var _i in allPeriodConf) {
if (allPeriodConf[_i]) {
period=allPeriodConf[_i];
ForecastUtility.hidePeriodUnactiveColumns(period);
}
}
};
/**
* hide period's unactive columns for ALL period FOR SECRETARIAT
* @param {string} userToken firebase token
*/
this.hideAllPeriodUnactiveColumnsSecretariatWithChosenCommodityName=function(userToken,sheetChosenCommodityName) {
var allPeriodConf, allPeriodConfNode, commodity, countryName, period;
countryName = getSecretariatCountry();
commodity = FirebaseConnector.getCommodityNameSecretariat(sheetChosenCommodityName);
allPeriodConfNode = 'config/addForecast/' + countryName + '/' + commodity;
allPeriodConf = JSON.parse(FirebaseConnector.getFireBaseData(allPeriodConfNode, userToken));
for (var _i in allPeriodConf) {
if (allPeriodConf[_i]) {
period=allPeriodConf[_i];
ForecastUtility.hidePeriodUnactiveColumnsWithChosenCommodityName(period,sheetChosenCommodityName);
}
}
};
/**
* hide period's unactive columns
* @param {object} periodConf configuration of the period from the db
*/
this.hidePeriodUnactiveColumns=function(periodConf){
//last frc
var lastForecastColumnPosition = periodConf.lastForecast;
lastForecastColumnPosition = Utility.letterToColumn(lastForecastColumnPosition);
//first frc
var firstForecastColumnPosition = periodConf.firstForecast;
firstForecastColumnPosition = Utility.letterToColumn(firstForecastColumnPosition);
//actual frc
var actualForecastColumnPosition = periodConf.actualPosition;
actualForecastColumnPosition = Utility.letterToColumn(actualForecastColumnPosition);
//hide correctly the new column
ForecastUtility.hideColumnForNewForecasts(firstForecastColumnPosition,lastForecastColumnPosition, actualForecastColumnPosition);
};
/**
* hide period's unactive columns FOR SECRETARIAT WITH SHEET
* @param {object} periodConf configuration of the period from the db
* @param {sheet} the sheet chosen
*/
this.hidePeriodUnactiveColumnsWithChosenCommodityName=function(periodConf,sheetChosenCommodityName){
//last frc
var lastForecastColumnPosition = periodConf.lastForecast;
lastForecastColumnPosition = Utility.letterToColumn(lastForecastColumnPosition);
//first frc
var firstForecastColumnPosition = periodConf.firstForecast;
firstForecastColumnPosition = Utility.letterToColumn(firstForecastColumnPosition);
//actual frc
var actualForecastColumnPosition = periodConf.actualPosition;
actualForecastColumnPosition = Utility.letterToColumn(actualForecastColumnPosition);
//hide correctly the new column
ForecastUtility.hideColumnForNewForecastsWithChosenCommodityName(firstForecastColumnPosition,lastForecastColumnPosition, actualForecastColumnPosition,sheetChosenCommodityName);
};
/**
* ADD A NEW FORECAST on the google sheet
* @param {string} auth token
*/
this.addForecast= function(period,userToken){
var countryName = FirebaseConnector.getCountryNameFromSheet(userToken);
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var commodity = FirebaseConnector.getCommodityName();
//read config from firebase
var periodConfNode = 'config/addForecast/'+countryName+'/'+commodity +'/'+period;
var periodConf = JSON.parse(FirebaseConnector.getFireBaseData(periodConfNode,userToken));
//last frc
var lastForecastColumnPosition = periodConf.lastForecast;
lastForecastColumnPosition = Utility.letterToColumn(lastForecastColumnPosition);
//first frc
var firstForecastColumnPosition = periodConf.firstForecast;
firstForecastColumnPosition = Utility.letterToColumn(firstForecastColumnPosition);
//actual frc
var actualForecastColumnPosition = periodConf.actualPosition;
actualForecastColumnPosition = Utility.letterToColumn(actualForecastColumnPosition);
//if we cannot add new FRC.. break the script
if(actualForecastColumnPosition == lastForecastColumnPosition)
return 0;
//increase actual position
actualForecastColumnPosition = actualForecastColumnPosition +1;
var actualForecastColumnPositionNode = periodConfNode + '/actualPosition';
//update the actualPositon in FIREBASE
FirebaseConnector.writeOnFirebase(Utility.numToChar(actualForecastColumnPosition), actualForecastColumnPositionNode, userToken);
//hide correctly the new column
ForecastUtility.hideColumnForNewForecasts(firstForecastColumnPosition,lastForecastColumnPosition, actualForecastColumnPosition);
};
// END -- ADD A NEW FORECAST on the google sheet
/**
* ADD A NEW FORECAST on the google sheet FOR SECRETARIET
* @param {string} auth token
*/
this.addForecastSecretariet = function(period,userToken,chosenCountry){
var countryName = chosenCountry;
var sheet = SpreadsheetApp.getActiveSpreadsheet();
var commodity = FirebaseConnector.getCommodityName();
//read config from firebase
var periodConfNode = 'config/addForecast/'+countryName+'/'+commodity +'/'+period;
var periodConf = JSON.parse(FirebaseConnector.getFireBaseData(periodConfNode,userToken));
//last frc
var lastForecastColumnPosition = periodConf.lastForecast;
lastForecastColumnPosition = Utility.letterToColumn(lastForecastColumnPosition);
//first frc
var firstForecastColumnPosition = periodConf.firstForecast;
firstForecastColumnPosition = Utility.letterToColumn(firstForecastColumnPosition);
//actual frc
var actualForecastColumnPosition = periodConf.actualPosition;
actualForecastColumnPosition = Utility.letterToColumn(actualForecastColumnPosition);
//if we cannot add new FRC.. break the script
if(actualForecastColumnPosition == lastForecastColumnPosition)
return 0;
//increase actual position
actualForecastColumnPosition = actualForecastColumnPosition +1;
var actualForecastColumnPositionNode = periodConfNode + '/actualPosition';
//update the actualPositon in FIREBASE
FirebaseConnector.writeOnFirebase(Utility.numToChar(actualForecastColumnPosition), actualForecastColumnPositionNode, userToken);
//hide correctly the new column
ForecastUtility.hideColumnForNewForecasts(firstForecastColumnPosition,lastForecastColumnPosition, actualForecastColumnPosition);
};
/**
* hide old forecast except the last 2
* @param {number} beginingPosition forecast position
* @param {number} lastPosition forecast position
* @param {number} numberOfColumnVisibleInTheRange of column you want to be shown
* @param {object} sheet [optional] the sheet
*/
this.hideOldForecasts = function( beginingPosition, lastPosition, numberOfColumnVisibleInTheRange, sheet ) {
sheet = sheet || SpreadSheetCache.getActiveSheet();
var columnToBeHidden = lastPosition - beginingPosition - numberOfColumnVisibleInTheRange;
if ( columnToBeHidden > -1 ) {
sheet.hideColumns( beginingPosition, columnToBeHidden + 1 );
}
};
/**
* hide old forecast except the last 2 FOR SECRETARIAT WithChosenCommodityName
* @param {number} beginingPosition forecast position
* @param {number} lastPosition forecast position
* @param {number} numberOfColumnVisibleInTheRange of column you want to be shown
*/
this.hideOldForecastsWithChosenCommodityName= function (beginingPosition, lastPosition, numberOfColumnVisibleInTheRange, sheetChosenCommodityName){
var sheet = sheetChosenCommodityName;
var columnToBeHidden = lastPosition - beginingPosition - numberOfColumnVisibleInTheRange;
if(columnToBeHidden >-1)
sheet.hideColumns(beginingPosition, columnToBeHidden+1);
};
/**
* show old forecast
*/
this.showOldForecasts= function (){
var config, firstCol, lastCol;
var sheet = SpreadSheetCache.getActiveSheet();
//var userToken=FirebaseConnector.getToken();
config = AmisNamedRanges.getCommodityNamedRanges().previousForecast;
firstCol=ConvertA1.colA1ToIndex(config.first.split(":")[0],1);
lastCol=ConvertA1.colA1ToIndex(config.last.split(":")[0],1);
//ForecastUtility.hideAllPeriodUnactiveColumns(userToken);
sheet.showColumns(firstCol, lastCol-firstCol);
};
/**
* show old forecast FOR SECRETARIAT
*/
this.showOldForecastsSecretariat= function (){
var config, firstCol, lastCol;
var sheet = SpreadSheetCache.getActiveSheet();
var userToken=FirebaseConnector.getToken();
config = AmisNamedRanges.getCommodityNamedRanges().previousForecast;
firstCol=ConvertA1.colA1ToIndex(config.first.split(":")[0],1);
lastCol=ConvertA1.colA1ToIndex(config.last.split(":")[0],1);
ForecastUtility.hideAllPeriodUnactiveColumnsSecretariat(userToken);
sheet.showColumns(firstCol, lastCol-firstCol);
};
/**
* Solve CTRL+Z problems for 'add new forecast'
* @param {string} new forecast column index
* @param {string} last forecast position
* @param {string} user token
* @return {string} new Forecast Column Position after fixing CTRL problems
* @deprecated not needed anymore
*/
this.preventUndoConflictForNewForecast = function (newForecastColumnPosition,lastForeCastNode, userToken, orderInTheSheet,firstForecastColumnPosition,beginForeCastNode){
var countryName = FirebaseConnector.getCountryNameFromSheet(userToken);
//datanode from firebase
var labelRowNumber = 'config/addForecast/labelRowNumber';
//retrive the row containing 'Forecasting Methodology'. IT MUST BE next the last forecast.
var forecastingMethodologyRange = FirebaseConnector.getFireBaseData(labelRowNumber,userToken);
//orderInTheSheet choose what result must be consider
var forecastingMethodologyColumn = Utility.findValueIntoRowMultipeResult('Forecasting Methodology', JSON.parse(forecastingMethodologyRange))[orderInTheSheet];
//IF THERE ARE CRTL+Z PROBLEMS (the firebase index for newForecastProblem is bigger then forecasting meth column)
if(newForecastColumnPosition >= forecastingMethodologyColumn){
//in this case we have also to update firstForecast position
if(orderInTheSheet!=0){
FirebaseConnector.writeOnFirebase(Utility.numToChar(forecastingMethodologyColumn-1), lastForeCastNode, userToken);
FirebaseConnector.writeOnFirebase(Utility.numToChar(firstForecastColumnPosition-1), beginForeCastNode, userToken);
}else{
//change the value of lastForecast config on database
FirebaseConnector.writeOnFirebase(Utility.numToChar(forecastingMethodologyColumn-1), lastForeCastNode, userToken);
}
//get the A1 notation for the column
var columnLetter = Utility.numToChar(forecastingMethodologyColumn-1);
//move forecastMetodology column position on firebase (range as input)
ForecastingMethodologies.moveFMCols(columnLetter+':'+columnLetter,-1);
//refetch from firebase the configuration for forecastmetodologies
ForecastingMethodologies.getConfig(true);
return forecastingMethodologyColumn-1;
}else{
return newForecastColumnPosition;
}
};
/**
* function called to hide all the forecast for previus year except the last one
* @param {object} sheet [optional] the sheet
* @return {void}
*/
this.hideAllPreviousForecasts = function( sheet ) {
sheet = sheet || SpreadSheetCache.getActiveSheet();
var config = AmisNamedRanges.getCommodityNamedRanges().previousForecast;
ForecastUtility.hideOldForecasts( sheet.getRange( config.first ).getColumn(), sheet.getRange( config.last ).getColumn(), 1, sheet );
};
/**
* function called to hide all the forecast for previus year except the last one FOR SECRETARIAT
*/
this.hideAllPreviousForecastsSecretariat = function (userToken, isNeedingCommodityName, sheetChosenCommodityName){
var sheet;
var config=AmisNamedRanges.getCommodityNamedRanges().previousForecast;
if(isNeedingCommodityName){
sheet = sheetChosenCommodityName;
}else{
//get the google sheet
var ss = SpreadsheetApp.getActiveSpreadsheet();
sheet = ss.getActiveSheet();
}
if(isNeedingCommodityName){
//with charToNum(letterOfTheColumn) I get the column number
ForecastUtility.hideOldForecastsWithChosenCommodityName(sheet.getRange(config.first).getColumn(),sheet.getRange(config.last).getColumn(),1,sheet);
}else{
//with charToNum(letterOfTheColumn) I get the column number
ForecastUtility.hideOldForecasts(sheet.getRange(config.first).getColumn(),sheet.getRange(config.last).getColumn(),1);
}
};
// END -- function called to hide all the forecast for previus year except the last one FOR SECRETARIAT
this.hideColumnForNewForecasts= function (firstForecastColumnPosition,lastForecastColumnPosition, actualForecastColumnPosition){
var sheet = SpreadsheetApp.getActiveSpreadsheet().getActiveSheet();
//in this case just simple hide every thing after the actual position
if(actualForecastColumnPosition - firstForecastColumnPosition <2 ) {
ForecastUtility.hideOldForecasts(actualForecastColumnPosition+1, lastForecastColumnPosition,0 );
}else {
var letterClm = Utility.numToChar(actualForecastColumnPosition);
letterClm = letterClm+':'+letterClm;
//unhide the new actualPosition column. the function TAKES RANGE as paramaeter!
sheet.unhideColumn(sheet.getRange(letterClm));
//hide the previus frc
ForecastUtility.hideOldForecasts(firstForecastColumnPosition, actualForecastColumnPosition,2 );
//hide the still to much new forecast
ForecastUtility.hideOldForecasts(actualForecastColumnPosition+1, lastForecastColumnPosition,0 );
}
};
this.hideColumnForNewForecastsWithChosenCommodityName= function (firstForecastColumnPosition,lastForecastColumnPosition, actualForecastColumnPosition,sheetChosenCommodityName){
var sheet = sheetChosenCommodityName;
//in this case just simple hide every thing after the actual position
if(actualForecastColumnPosition - firstForecastColumnPosition <2 ) {
ForecastUtility.hideOldForecastsWithChosenCommodityName(actualForecastColumnPosition+1, lastForecastColumnPosition,0, sheet );
}else {
var letterClm = Utility.numToChar(actualForecastColumnPosition);
letterClm = letterClm+':'+letterClm;
//unhide the new actualPosition column. the function TAKES RANGE as paramaeter!
sheet.unhideColumn(sheet.getRange(letterClm));
//hide the previus frc
ForecastUtility.hideOldForecastsWithChosenCommodityName(firstForecastColumnPosition, actualForecastColumnPosition,2,sheet );
//hide the still to much new forecast
ForecastUtility.hideOldForecastsWithChosenCommodityName(actualForecastColumnPosition+1, lastForecastColumnPosition,0,sheet );
}
};
/**
* hide all the forecast for previus year except the last one and all unactive columns of all periods
*/
this.hideOldAndUnactiveForecast = function() {
//ForecastUtility.hideAllPeriodUnactiveColumns(userToken)
ForecastUtility.hideAllPreviousForecasts();
};
/**
* hide all the forecast for previus year except the last one and all unactive columns of all periods FOR SECRETARIAT
* @param {string} userToken firebase token FOR SECRETARIAT
*/
this.hideOldAndUnactiveForecastSecretariat = function(userToken) {
ForecastUtility.hideAllPeriodUnactiveColumnsSecretariat(userToken)
ForecastUtility.hideAllPreviousForecastsSecretariat(userToken);
};
};