-
Notifications
You must be signed in to change notification settings - Fork 0
/
qcp-v4,ts
2822 lines (2489 loc) · 111 KB
/
qcp-v4,ts
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
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
// SET TO FALSE IN PRODUCTION
const DEBUG = true;
function debug(...args) {
if (DEBUG) {
console.log(...args);
}
}
/* #region QCP Plugin Methods */
/**
* This method is called by the calculator when the plugin is initialized.
* @param {QuoteLineModel[]} quoteLineModels An array containing JS representations of all lines in a quote
* @returns {Promise}
*/
export function onInit(quoteLineModels) {
return Promise.resolve();
}
/**
* This method is called by the calculator before calculation begins, but after formula fields have been evaluated.
* @param {QuoteModel} quoteModel JS representation of the quote being evaluated
* @param {QuoteLineModel[]} quoteLineModels An array containing JS representations of all lines in the quote
* @returns {Promise}
*/
export function onBeforeCalculate(quoteModel, quoteLineModels) {
return Promise.resolve();
}
/**
* This method is called by the calculator before price rules are evaluated.
* @param {QuoteModel} quoteModel JS representation of the quote being evaluated
* @param {QuoteLineModel[]} quoteLineModels An array containing JS representations of all lines in the quote
* @returns {Promise}
*/
export function onBeforePriceRules(quoteModel, quoteLineModels) {
return Promise.resolve();
}
/**
* This method is called by the calculator after price rules are evaluated.
* @param {QuoteModel} quoteModel JS representation of the quote being evaluated
* @param {QuoteLineModel[]} quoteLineModels An array containing JS representations of all lines in the quote
* @returns {Promise}
*/
export function onAfterPriceRules(quoteModel, quoteLineModels) {
return Promise.resolve();
}
/* #endregion */
/**
* This method is called by the calculator after calculation has completed, but before formula fields are
* re-evaluated.
* @param {QuoteModel} quoteModel JS representation of the quote being evaluated
* @param {QuoteLineModel[]} quoteLineModels An array containing JS representations of all lines in the quote
* @returns {Promise}
*/
export function onAfterCalculate(quoteModel, quoteLineModels) {
console.log('QCP: qcp_v4_gradebeams');
console.log('JJS73 onAfterCalculate');
console.dir(quoteLineModels);
console.log('JJS73 logRecords preprocess');
logRecords(quoteLineModels);
var tieredPricingInvolved = [];
tieredPricingInvolved['CMUBLOCK'] = calc_CMU_BLOCK(quoteLineModels);
calc_BOND_BEAM(quoteLineModels);
tieredPricingInvolved['LinearTrenchFootings'] = calc_LinearTrenchFootings(quoteLineModels);
tieredPricingInvolved['SpreadFootings'] = calc_SpreadFootings(quoteLineModels);
tieredPricingInvolved['GradeBeams'] = calc_GradeBeams(quoteLineModels);
calc_ConcreteSlabSF(quoteLineModels);
calc_PierFootings(quoteLineModels);
tieredPricing(quoteLineModels, tieredPricingInvolved);
rollupCPTtoParent(quoteLineModels);
populateSubbabseDescription(quoteLineModels);
console.log('JJS73 logRecords postprocess');
logRecords(quoteLineModels);
return Promise.resolve();
}
/* #region Special Case Functions */
function populateSubbabseDescription(quoteLineModels) {
if (quoteLineModels != null) {
quoteLineModels.forEach(function (line) {
if (
'SUBBASE_LVL1_IN_DEPTH' === line.record['SBQQ__ProductCode__c'] ||
'SUBBASE_LVL2_IN_DEPTH' === line.record['SBQQ__ProductCode__c']
) {
line.parentItem.record['SBQQ__Description__c'] =
line.record['SBQQ__Quantity__c'] / line.parentItem.record['SBQQ__Quantity__c'] + '" Depth';
}
});
}
}
/* #endregion */
/* #region Helper Functions */
/**
* SF PAckage Total Question
* https://success.salesforce.com/0D53A00004s13b8
*/
function rollupCPTtoParent(quoteLineModels) {
/* Roll Up Package Total to Parent */
quoteLineModels.forEach(function (line) {
line.record['Custom_Package_Total__c'] = 0;
line.record['SBQQ__ComponentVisibility__c'] = 'Always';
if (line.record['SBQQ__NetPrice__c'] > 0) {
line.record['Custom_Package_Total__c'] = line.record['SBQQ__Quantity__c'] * line.record['SBQQ__NetPrice__c'];
}
var parent = line.parentItem;
if (parent) {
/* Compute line.CPT */
if (line.record['SBQQ__NetPrice__c'] > 0) {
line.record['Custom_Package_Total__c'] = line.record['SBQQ__Quantity__c'] * line.record['SBQQ__NetPrice__c'];
} else {
line.record['Custom_Package_Total__c'] = line.record['SBQQ__PackageTotal__c'];
}
/* Add line.CPT to parent.CPT */
parent.record['Custom_Package_Total__c'] = parent.record['Custom_Package_Total__c'] + line.record['Custom_Package_Total__c'];
if (parent.parentItem) {
parent.record['Custom_Package_Total__c'] = parent.record['SBQQ__PackageTotal__c'];
}
}
});
quoteLineModels.forEach(function (line) {
/* Special Cases */
if (
'CMU_V_REBAR' == line.record['SBQQ__ProductCode__c'] ||
'DOWEL_REBAR' == line.record['SBQQ__ProductCode__c'] ||
'HORIZ_REBAR' == line.record['SBQQ__ProductCode__c'] ||
'TRANSVERSE_REBAR' == line.record['SBQQ__ProductCode__c'] ||
'CHAIR_3IN_5FT' == line.record['SBQQ__ProductCode__c'] ||
'CHAIR_6IN_5FT' == line.record['SBQQ__ProductCode__c']
) {
line.record['Custom_Package_Total__c'] = line.record['SBQQ__Quantity__c'] * line.record['SBQQ__NetPrice__c'];
}
});
}
/**
*
* @param {QuoteLineModel[]} quoteLineModels An array containing JS representations of all lines in the quote
* @returns {QuoteLineModel[]} quoteLineModels An array containing JS representations of all lines in the quote
function addCPT(quoteLineModels){
var linesToZeroQuantity = [];
return;
if (quoteLineModels != null) {
quoteLineModels.forEach(function(line) {
if(line.record['SBQQ__ProductCode__c'] === 'CMU_BLOCK_AIR_VENT'){
line.record['Custom_Package_Total__c'] = line.record['SBQQ__PackageTotal__c'];
line.record['SBQQ__NetPrice__c'] = line.record['Custom_Package_Total__c'];
line.record['Quote_Line_Item_Section__c'] = 'Block';
console.log('Components');
console.dir(line.components);
var tmpNetUnitPrice = 0;
line.components.forEach(function (lineZero) {
tmpNetUnitPrice += lineZero.record['SBQQ__NetPrice__c'];
linesToZeroQuantity.push(lineZero);
});
line.record['SBQQ__NetPrice__c'] = tmpNetUnitPrice;
}
});
setComponentZeroQuant(linesToZeroQuantity);
}
}*/
function setComponentZeroQuant(lines) {
if (lines != null) {
lines.forEach(function (line) {
line.record['SBQQ__Quantity__c'] = 0;
});
}
}
/**
* COPY/PASTE
*
* TEMPLATE FUNCTION FOR NEW calc_PRODUCT
*
*/
function TEMPLATE__calc_Product(quoteLineModels) {
var parent_Product = [];
var lineChild = [];
var inchBlock = [];
var cmuLF = [];
var courses = [];
if (quoteLineModels != null) {
quoteLineModels.forEach(function (line) {
var parent = line.parentItem;
/* Quote_Line_Item_Section__c Section */
if ('PAY_ITEM_PRODUCT_CODE' == line.record['SBQQ__ProductCode__c']) {
line.record['Quote_Line_Item_Section__c'] = 'Block';
}
/* Cost Inputs */
if (line.record['SBQQ__ProductCode__c'] === 'CONCRETE_3000_PY_COST') {
//costConcretePY = line.record['SBQQ__UnitCost__c'];
}
if (parent != null) {
var parentKey = parent.key;
var parentPC = parent.record['SBQQ__ProductCode__c'];
if ('PAY_ITEM_PRODUCT_CODE' == parentPC) {
/* store the Parent Product line */
parent_Product[parentKey] = parent;
}
/* child or grandchild of Parent Product */
if (
'PAY_ITEM_PRODUCT_CODE' == parentPC ||
(parent.parentItem && 'PAY_ITEM_PRODUCT_CODE' == parent.parentItem.record['SBQQ__ProductCode__c'])
) {
/* Set Quote_Line_Item_Section__c */
line.record['Quote_Line_Item_Section__c'] = 'Block';
/* collect inputs */
if ('NOMINAL_LENGTH' == line.record['SBQQ__ProductCode__c']) {
length[parentKey] = line.record['SBQQ__Quantity__c'];
/* Description */
line.record['SBQQ__Description__c'] = line.record['SBQQ__Quantity__c'] + ' Feet';
}
/* collect inputs of grandchildren */
if ('HORIZ_REBAR' == parent.record['SBQQ__ProductCode__c']) {
//lineHorizRebar[parent.parentItem.key] = parent;
if ('REBAR_OVERLAP_DIAMETERS' == line.record['SBQQ__ProductCode__c']) {
//intHorizRebarOD[parent.parentItem.key] = line.record['SBQQ__Quantity__c'];
}
}
}
}
}); // End of Lines
/* Calculate and Store Results */
if (parent_Product) {
parent_Product.forEach(function (parent_line, key) {
/* Pay Item Calc */
//parent_line.record['SBQQ__Quantity__c'] = Math.ceil(length[key] * width[key] * depth[key] / 27);
/* Children Calc */
if (lineChild[key]) {
//var quantChairs = Math.ceil(Math.ceil((length[key] / (intChairInOC[key] / 12)) + 1) / Math.floor(5 / (width[key] - .5)));
//lineChild[key].record['SBQQ__Quantity__c'] = quantChairs;
}
});
}
}
}
/**
*
* @param {QuoteLineModel[]} quoteLineModels An array containing JS representations of all lines in the quote
* @returns {QuoteLineModel[]} quoteLineModels An array containing JS representations of all lines in the quote
*/
function mapRecords(quoteLineModels) {
return quoteLineModels.map(model => model.record);
}
/**
*
* @param {QuoteLineModel[] || QuoteModel} quoteOrLineModel
* @returns void
*/
function logRecords(quoteOrLineModel) {
// serializing records removes proxy to make debugging easier,
// BUT is a performance hit, so make sure to disable logging in production to avoid this without code changes
if (DEBUG) {
const models = Array.isArray(quoteOrLineModel) ? quoteOrLineModel : [quoteOrLineModel];
debug(JSON.parse(JSON.stringify(mapRecords(models))));
}
}
/**
* Group all quote lines by very top level bundle
* This is useful when you need to rollup values on a bundle by bundle basis
*/
function groupByTopLevelBundle(quoteLineModels) {
const bundles = quoteLineModels.reduce((bundles, line) => {
const parentKey = getParentKey(line);
if (!bundles[parentKey]) {
bundles[parentKey] = [];
}
bundles[parentKey].push(line);
return bundles;
}, {});
debug('bundles', bundles);
return bundles;
}
/** recursively get parent key */
function getParentKey(quoteLine) {
if (quoteLine.parentItem) {
return getParentKey(quoteLine.parentItem);
} else {
return quoteLine.key;
}
}
/* #endregion */
/* #region Tiered Pricing Functions */
/**
* START: qcp_tier_functions.ts *************************************
*/
/**
* Calculate Tiered Pricing and Update QuoteLines
* @param quoteLineModels
* @param tieredPricingInvolved
*/
function tieredPricing(quoteLineModels, tieredPricingInvolved) {
if (quoteLineModels != null) {
if (tieredPricingInvolved['CMUBLOCK']) {
/* CMUBLOCK collecting variable declarations */
var tieredinfo_CMUBLOCK = new Object();
tieredinfo_CMUBLOCK['quant_CMUBLOCK_06'] = 0;
tieredinfo_CMUBLOCK['price_CMUBLOCK_06'] = 0;
tieredinfo_CMUBLOCK['line_CMUBLOCK_06'] = [];
tieredinfo_CMUBLOCK['quant_CMUBLOCK_08'] = 0;
tieredinfo_CMUBLOCK['price_CMUBLOCK_08'] = 0;
tieredinfo_CMUBLOCK['line_CMUBLOCK_08'] = [];
tieredinfo_CMUBLOCK['quant_CMUBLOCK_10'] = 0;
tieredinfo_CMUBLOCK['price_CMUBLOCK_10'] = 0;
tieredinfo_CMUBLOCK['line_CMUBLOCK_10'] = [];
tieredinfo_CMUBLOCK['quant_CMUBLOCK_12'] = 0;
tieredinfo_CMUBLOCK['price_CMUBLOCK_12'] = 0;
tieredinfo_CMUBLOCK['line_CMUBLOCK_12'] = [];
}
if (tieredPricingInvolved['LinearTrenchFootings']) {
/* LinearTrenchFootings collecting variable declarations */
var tieredinfo_LinearTrenchFootings = new Object();
tieredinfo_LinearTrenchFootings['form_labor_price'] = 0;
tieredinfo_LinearTrenchFootings['pour_labor_price'] = 0;
tieredinfo_LinearTrenchFootings['strip_labor_price'] = 0;
tieredinfo_LinearTrenchFootings['lines_form'] = new Array(0);
tieredinfo_LinearTrenchFootings['lines_pour'] = new Array(0);
tieredinfo_LinearTrenchFootings['lines_strip'] = new Array(0);
tieredinfo_LinearTrenchFootings['line_excavation'] = new Object();
tieredinfo_LinearTrenchFootings['length_lf'] = 0;
tieredinfo_LinearTrenchFootings['price_depth_excavation'] = 0.0;
}
if (tieredPricingInvolved['SpreadFootings']) {
/* LinearTrenchFootings collecting variable declarations */
var tieredinfo_SpreadFootings = new Object();
tieredinfo_SpreadFootings['form_labor_price'] = 0;
tieredinfo_SpreadFootings['pour_labor_price'] = 0;
tieredinfo_SpreadFootings['strip_labor_price'] = 0;
tieredinfo_SpreadFootings['lines_form'] = new Array(0);
tieredinfo_SpreadFootings['lines_pour'] = new Array(0);
tieredinfo_SpreadFootings['lines_strip'] = new Array(0);
tieredinfo_SpreadFootings['line_excavation'] = new Object();
tieredinfo_SpreadFootings['length_lf'] = 0;
tieredinfo_SpreadFootings['price_depth_excavation'] = 0.0;
}
if (tieredPricingInvolved['GradeBeams']) {
/* GradeBeams collecting variable declarations */
var tieredinfo_GradeBeams = new Object();
tieredinfo_GradeBeams['form_labor_price'] = 0;
tieredinfo_GradeBeams['pour_labor_price'] = 0;
tieredinfo_GradeBeams['strip_labor_price'] = 0;
tieredinfo_GradeBeams['lines_form'] = new Array(0);
tieredinfo_GradeBeams['lines_pour'] = new Array(0);
tieredinfo_GradeBeams['lines_strip'] = new Array(0);
tieredinfo_GradeBeams['line_excavation'] = new Object();
tieredinfo_GradeBeams['length_lf'] = 0;
tieredinfo_GradeBeams['price_depth_excavation'] = 0.0;
}
quoteLineModels.forEach(function (line) {
if (tieredPricingInvolved['CMUBLOCK']) {
tieredinfo_CMUBLOCK = each_CMUBLOCK(line, tieredinfo_CMUBLOCK);
}
if (tieredPricingInvolved['LinearTrenchFootings']) {
tieredinfo_LinearTrenchFootings = each_LinearTrenchFootings(line, tieredinfo_LinearTrenchFootings);
}
if (tieredPricingInvolved['SpreadFootings']) {
tieredinfo_SpreadFootings = each_SpreadFootings(line, tieredinfo_SpreadFootings);
console.log("tieredPricingInvolved['SpreadFootings'] = " + tieredPricingInvolved['SpreadFootings']);
}
if (tieredPricingInvolved['GradeBeams']) {
tieredinfo_GradeBeams = each_GradeBeams(line, tieredinfo_GradeBeams);
console.log("tieredPricingInvolved['GradeBeams'] = " + tieredPricingInvolved['GradeBeams']);
}
});
/** Calculate and Update Tiered Prices */
if (tieredPricingInvolved['CMUBLOCK']) {
updateCMUBLOCKslabprice(quoteLineModels, tieredinfo_CMUBLOCK);
}
if (tieredPricingInvolved['LinearTrenchFootings']) {
updateLinearTrenchFootingsslabprice(quoteLineModels, tieredinfo_LinearTrenchFootings);
}
if (tieredPricingInvolved['SpreadFootings']) {
updateSpreadFootingsslabprice(quoteLineModels, tieredinfo_SpreadFootings);
console.log("updateSpreadFootingsslabprice['quoteLineModels, tieredinfo_SpreadFootings'] = " + updateSpreadFootingsslabprice(quoteLineModels, tieredinfo_SpreadFootings));
}
if (tieredPricingInvolved['GradeBeams']) {
updateGradeBeamsslabprice(quoteLineModels, tieredinfo_GradeBeams);
}
}
}
/* #endregion */
/* #region LinearTrenchFootings Functions for Tiered Pricing */
/**
* ********************************************************
* START: LinearTrenchFootings Functions for Tiered Pricing
*/
/**
* Collect Length(LF) and Line array of LinearTrenchFootings
*
* @param {Object} line
* @param {Object} tieredinfo
* @returns {Object} tieredinfo_LinearTrenchFootings
*/
function each_LinearTrenchFootings(line, tieredinfo) {
/* If prices are empty get the first prices */
/* grab form labor price and store line */
if (
'LABOR_FORM_LF' == line.record['SBQQ__ProductCode__c'] &&
'LINEAR_TRENCH_FOOTINGS' == line.parentItem.record['SBQQ__ProductCode__c']
) {
tieredinfo['form_labor_price'] = line.record['SBQQ__NetPrice__c'].valueOf();
tieredinfo['lines_form'].push(line);
}
/* grab pour labor price and store line */
if (
'LABOR_POUR_LF' == line.record['SBQQ__ProductCode__c'] &&
'LINEAR_TRENCH_FOOTINGS' == line.parentItem.record['SBQQ__ProductCode__c']
) {
tieredinfo['pour_labor_price'] = line.record['SBQQ__NetPrice__c'].valueOf();
tieredinfo['lines_pour'].push(line);
}
/* grab strip labor price and store line */
if (
'LABOR_STRIP_LF' == line.record['SBQQ__ProductCode__c'] &&
'LINEAR_TRENCH_FOOTINGS' == line.parentItem.record['SBQQ__ProductCode__c']
) {
tieredinfo['strip_labor_price'] = line.record['SBQQ__NetPrice__c'].valueOf();
tieredinfo['lines_strip'].push(line);
}
/* grab length in lf of trench */
if (
'NOMINAL_LENGTH' == line.record['SBQQ__ProductCode__c'] &&
'LINEAR_TRENCH_FOOTINGS' == line.parentItem.record['SBQQ__ProductCode__c']
) {
tieredinfo['length_lf'] += line.record['SBQQ__Quantity__c'].valueOf();
}
/* store excavation line */
if (
'TRENCH_EXCAVATION_LF_MACHINE' == line.record['SBQQ__ProductCode__c'] &&
'LINEAR_TRENCH_FOOTINGS' == line.parentItem.record['SBQQ__ProductCode__c']
) {
tieredinfo['line_excavation'] = line;
}
/* store excavation depth price */
if (
'EXCAVATION_DEPTH_MACHINE_' == line.record['SBQQ__ProductCode__c'].substring(0, 25) &&
'TRENCH_EXCAVATION_LF_MACHINE' == line.parentItem.record['SBQQ__ProductCode__c']
) {
tieredinfo['price_depth_excavation'] = line.record['SBQQ__NetPrice__c'].valueOf();
}
console.log('each_LinearTrenchFootings()');
console.dir(tieredinfo);
return tieredinfo;
}
/**
* Calculate price based on tiers and update price on lines
* @param {Object} tieredinfo
*/
function updateLinearTrenchFootingsslabprice(quoteLineModels, tieredinfo) {
console.dir(tieredinfo);
/* Labor Price Tiers */
var labor_price_per_lf = tieredpricing_LaborPerFoot(
tieredinfo['length_lf'],
tieredinfo['form_labor_price'],
tieredinfo['pour_labor_price'],
tieredinfo['strip_labor_price'],
);
console.log('JJS price_per_lf Trn= ');
console.dir(labor_price_per_lf);
tieredinfo['lines_form'].forEach(function (line) {
line.record['SBQQ__NetPrice__c'] = labor_price_per_lf['form'];
line.record['Custom_Package_Total__c'] = line.record['SBQQ__Quantity__c'] * line.record['SBQQ__NetPrice__c'];
});
tieredinfo['lines_pour'].forEach(function (line) {
line.record['SBQQ__NetPrice__c'] = labor_price_per_lf['pour'];
line.record['Custom_Package_Total__c'] = line.record['SBQQ__Quantity__c'] * line.record['SBQQ__NetPrice__c'];
});
tieredinfo['lines_strip'].forEach(function (line) {
line.record['SBQQ__NetPrice__c'] = labor_price_per_lf['strip'];
line.record['Custom_Package_Total__c'] = line.record['SBQQ__Quantity__c'] * line.record['SBQQ__NetPrice__c'];
});
/* Excavation Price Tiers */
tieredpricing_FootingsExcavation(tieredinfo['line_excavation'], tieredinfo['length_lf'], tieredinfo['price_depth_excavation']);
}
/**
* END: LinearTrenchFootings Functions for Tiered Pricing
* ******************************************************
*/
/* #endregion */
/* #region GradeBeams Functions for Tiered Pricing */
/**
* ********************************************************
* START: GradeBeams Functions for Tiered Pricing
*/
/**
* Collect Length(LF) and Line array of GradeBeams
*
* @param {Object} line
* @param {Object} tieredinfo
* @returns {Object} tieredinfo_LinearTrenchFootings
*/
function each_GradeBeams(line, tieredinfo) {
/* If prices are empty get the first prices */
/* grab form labor price and store line */
if (
'LABOR_FORM_LF' == line.record['SBQQ__ProductCode__c'] &&
'GRADE_BEAMS' == line.parentItem.record['SBQQ__ProductCode__c']
) {
tieredinfo['form_labor_price'] = line.record['SBQQ__NetPrice__c'].valueOf();
tieredinfo['lines_form'].push(line);
}
/* grab pour labor price and store line */
if (
'LABOR_POUR_LF' == line.record['SBQQ__ProductCode__c'] &&
'GRADE_BEAMS' == line.parentItem.record['SBQQ__ProductCode__c']
) {
tieredinfo['pour_labor_price'] = line.record['SBQQ__NetPrice__c'].valueOf();
tieredinfo['lines_pour'].push(line);
}
/* grab strip labor price and store line */
if (
'LABOR_STRIP_LF' == line.record['SBQQ__ProductCode__c'] &&
'GRADE_BEAMS' == line.parentItem.record['SBQQ__ProductCode__c']
) {
tieredinfo['strip_labor_price'] = line.record['SBQQ__NetPrice__c'].valueOf();
tieredinfo['lines_strip'].push(line);
}
/* grab length in lf of trench */
if (
'NOMINAL_LENGTH' == line.record['SBQQ__ProductCode__c'] &&
'GRADE_BEAMS' == line.parentItem.record['SBQQ__ProductCode__c']
) {
tieredinfo['length_lf'] += line.record['SBQQ__Quantity__c'].valueOf();
}
/* store excavation line */
if (
'TRENCH_EXCAVATION_LF_MACHINE' == line.record['SBQQ__ProductCode__c'] &&
'GRADE_BEAMS' == line.parentItem.record['SBQQ__ProductCode__c']
) {
tieredinfo['line_excavation'] = line;
}
/* store excavation depth price */
if (
'EXCAVATION_DEPTH_MACHINE_' == line.record['SBQQ__ProductCode__c'].substring(0, 25) &&
'TRENCH_EXCAVATION_LF_MACHINE' == line.parentItem.record['SBQQ__ProductCode__c']
) {
tieredinfo['price_depth_excavation'] = line.record['SBQQ__NetPrice__c'].valueOf();
}
console.log('each_GradeBeams()');
console.dir(tieredinfo);
return tieredinfo;
}
/**
* Calculate price based on tiers and update price on lines
* @param {Object} tieredinfo
*/
function updateGradeBeamsslabprice(quoteLineModels, tieredinfo) {
console.dir(tieredinfo);
/* Labor Price Tiers */
var labor_price_per_lf = tieredpricing_LaborPerFoot(
tieredinfo['length_lf'],
tieredinfo['form_labor_price'],
tieredinfo['pour_labor_price'],
tieredinfo['strip_labor_price'],
);
console.log('JJS price_per_lf Trn= ');
console.dir(labor_price_per_lf);
tieredinfo['lines_form'].forEach(function (line) {
line.record['SBQQ__NetPrice__c'] = labor_price_per_lf['form'];
line.record['Custom_Package_Total__c'] = line.record['SBQQ__Quantity__c'] * line.record['SBQQ__NetPrice__c'];
});
tieredinfo['lines_pour'].forEach(function (line) {
line.record['SBQQ__NetPrice__c'] = labor_price_per_lf['pour'];
line.record['Custom_Package_Total__c'] = line.record['SBQQ__Quantity__c'] * line.record['SBQQ__NetPrice__c'];
});
tieredinfo['lines_strip'].forEach(function (line) {
line.record['SBQQ__NetPrice__c'] = labor_price_per_lf['strip'];
line.record['Custom_Package_Total__c'] = line.record['SBQQ__Quantity__c'] * line.record['SBQQ__NetPrice__c'];
});
/* Excavation Price Tiers */
tieredpricing_FootingsExcavation(tieredinfo['line_excavation'], tieredinfo['length_lf'], tieredinfo['price_depth_excavation']);
}
/**
* END: GradeBeams Functions for Tiered Pricing
* ******************************************************
*/
/* #endregion */
/* #region Common Footing Functions */
/**
* *******************************
* START: Common Footing Functions
*/
/**
* Calculate and populate tiered price for footing excavation
* @param line_excavation
* @param length_lf
* @param price_depth_excavation
*/
function tieredpricing_FootingsExcavation(line_excavation, length_lf, price_depth_excavation) {
console.log('FootingsExcavation');
console.dir(line_excavation);
if(Object.keys(line_excavation).length === 0){
return;
}
if (length_lf != 'number') {
length_lf = parseInt(length_lf);
}
if (price_depth_excavation != 'number') {
price_depth_excavation = parseFloat(price_depth_excavation);
}
var tmpTotalPrice = parseFloat('0.00');
for (var i = 1; i <= length_lf; i++) {
if (i < 11) {
tmpTotalPrice += 12.5;
} else if (i < 21) {
tmpTotalPrice += 8.32;
} else if (i < 41) {
tmpTotalPrice += 7.5;
} else {
tmpTotalPrice += 4.16 * (length_lf - 40);
break;
}
}
var price_per_lf = tmpTotalPrice / length_lf;
line_excavation.record['SBQQ__Quantity__c'] = length_lf;
line_excavation.record['SBQQ__NetPrice__c'] = price_per_lf * price_depth_excavation;
line_excavation.record['Custom_Package_Total__c'] =
line_excavation.record['SBQQ__Quantity__c'] * line_excavation.record['SBQQ__NetPrice__c'];
}
/**
* Calculate Labor per Foot price based on tiers
* @param total_length_lf
* @param form_labor_start
* @param pour_labor_start
* @param strip_labor_start
* @returns {array} price_per_lf
*/
function tieredpricing_LaborPerFoot(total_length_lf, form_labor_start, pour_labor_start, strip_labor_start) {
console.log('JJS tieredpricing_LaborPerFoot')
total_length_lf = parseFloat(total_length_lf);
form_labor_start = parseFloat(pour_labor_start);
pour_labor_start = parseFloat(pour_labor_start);
strip_labor_start = parseFloat(strip_labor_start);
console.log('total_length_lf = ' + total_length_lf);
console.log('form_labor_start = ' + form_labor_start);
console.log('pour_labor_start = ' + pour_labor_start);
console.log('strip_labor_start = ' + strip_labor_start);
var tierQuantities = [25, 50, 75, 100, 125, 150, 175, 200, 225, 250, 1000000000];
var levelDiscount = parseFloat('.06');
var totalPrice = new Object();
totalPrice['form'] = parseFloat('0.00');
totalPrice['pour'] = parseFloat('0.00');
totalPrice['strip'] = parseFloat('0.00');
var i = 0;
for (i = 0; i < tierQuantities.length - 1; i++) {
if (total_length_lf >= tierQuantities[i]) {
console.log(total_length_lf + ' >= ' + tierQuantities[i]);
totalPrice['form'] += 25.0 * (form_labor_start * Math.pow(1.0 - levelDiscount, i));
console.log(
"totalPrice['form'] " + totalPrice['form'] + 'Quant 25 * ' + (form_labor_start * Math.pow(1.0 - levelDiscount, i)).toFixed(2),
);
totalPrice['pour'] += 25.0 * (pour_labor_start * Math.pow(1.0 - levelDiscount, i));
totalPrice['strip'] += 25.0 * (strip_labor_start * Math.pow(1.0 - levelDiscount, i));
} else if (total_length_lf < tierQuantities[i] && total_length_lf > tierQuantities[i - 1]) {
totalPrice['form'] += (total_length_lf - tierQuantities[i - 1]) * (form_labor_start * Math.pow(1.0 - levelDiscount, i));
console.log(
"totalPrice['form'] " +
totalPrice['form'] +
'Quant ' +
(total_length_lf - tierQuantities[i - 1]) +
' * ' +
(form_labor_start * Math.pow(1.0 - levelDiscount, i)).toFixed(2),
);
totalPrice['pour'] += (total_length_lf - tierQuantities[i - 1]) * (pour_labor_start * Math.pow(1.0 - levelDiscount, i));
totalPrice['strip'] += (total_length_lf - tierQuantities[i - 1]) * (strip_labor_start * Math.pow(1.0 - levelDiscount, i));
}
}
var price_per_lf = [];
price_per_lf['form'] = totalPrice['form'] / total_length_lf;
price_per_lf['pour'] = totalPrice['pour'] / total_length_lf;
price_per_lf['strip'] = totalPrice['strip'] / total_length_lf;
return price_per_lf;
}
/* #endregion */
/* #region SpreadFootings Functions for Tiered Pricing */
/**
* **************************************************
* START: SpreadFootings Functions for Tiered Pricing
*/
/**
* Collect Length(LF) and Line array of SpreadFootings
*
* @param {Object} line
* @param {Object} tieredinfo
* @returns {Object} tieredinfo_LinearTrenchFootings
*/
function each_SpreadFootings(line, tieredinfo) {
/* If prices are empty get the first prices */
/* grab form labor price and store line */
if ('LABOR_FORM_LF' == line.record['SBQQ__ProductCode__c'] && 'SPREAD_FOOTINGS' == line.parentItem.record['SBQQ__ProductCode__c']) {
tieredinfo['form_labor_price'] = line.record['SBQQ__NetPrice__c'].valueOf();
tieredinfo['lines_form'].push(line);
}
/* grab pour labor price and store line */
if ('LABOR_POUR_LF' == line.record['SBQQ__ProductCode__c'] && 'SPREAD_FOOTINGS' == line.parentItem.record['SBQQ__ProductCode__c']) {
tieredinfo['pour_labor_price'] = line.record['SBQQ__NetPrice__c'].valueOf();
tieredinfo['lines_pour'].push(line);
}
/* grab strip labor price and store line */
if ('LABOR_STRIP_LF' == line.record['SBQQ__ProductCode__c'] && 'SPREAD_FOOTINGS' == line.parentItem.record['SBQQ__ProductCode__c']) {
tieredinfo['strip_labor_price'] = line.record['SBQQ__NetPrice__c'].valueOf();
tieredinfo['lines_strip'].push(line);
}
/* grab length in lf of trench */
if ('NOMINAL_LENGTH' == line.record['SBQQ__ProductCode__c'] && 'SPREAD_FOOTINGS' == line.parentItem.record['SBQQ__ProductCode__c']) {
tieredinfo['length_lf'] += line.record['SBQQ__Quantity__c'].valueOf();
}
/* store excavation line */
if (
'TRENCH_EXCAVATION_LF_MACHINE' == line.record['SBQQ__ProductCode__c'] &&
'SPREAD_FOOTINGS' == line.parentItem.record['SBQQ__ProductCode__c']
) {
tieredinfo['line_excavation'] = line;
}
/* store excavation depth price */
if (
'EXCAVATION_DEPTH_MACHINE_' == line.record['SBQQ__ProductCode__c'].substring(0, 25) &&
'TRENCH_EXCAVATION_LF_MACHINE' == line.parentItem.record['SBQQ__ProductCode__c']
) {
tieredinfo['price_depth_excavation'] = line.record['SBQQ__NetPrice__c'].valueOf();
}
return tieredinfo;
}
/**
* Calculate price based on tiers and update price on lines
* @param {Object} tieredinfo
*/
function updateSpreadFootingsslabprice(quoteLineModels, tieredinfo) {
/* Labor Price Tiers */
var labor_price_per_lf = tieredpricing_LaborPerFoot(
tieredinfo['length_lf'],
tieredinfo['form_labor_price'],
tieredinfo['pour_labor_price'],
tieredinfo['strip_labor_price'],
);
console.log('JJS price_per_lf Spr = ');
console.dir(labor_price_per_lf);
tieredinfo['lines_form'].forEach(function (line) {
line.record['SBQQ__NetPrice__c'] = labor_price_per_lf['form'];
line.record['Custom_Package_Total__c'] = line.record['SBQQ__Quantity__c'] * line.record['SBQQ__NetPrice__c'];
});
tieredinfo['lines_pour'].forEach(function (line) {
line.record['SBQQ__NetPrice__c'] = labor_price_per_lf['pour'];
line.record['Custom_Package_Total__c'] = line.record['SBQQ__Quantity__c'] * line.record['SBQQ__NetPrice__c'];
});
tieredinfo['lines_strip'].forEach(function (line) {
line.record['SBQQ__NetPrice__c'] = labor_price_per_lf['strip'];
line.record['Custom_Package_Total__c'] = line.record['SBQQ__Quantity__c'] * line.record['SBQQ__NetPrice__c'];
});
/* Excavation Price Tiers */
tieredpricing_FootingsExcavation(tieredinfo['line_excavation'], tieredinfo['length_lf'], tieredinfo['price_depth_excavation']);
}
/**
* END: SpreadFootings Functions for Tiered Pricing
* ******************************************************
*/
/* #endregion */
/* #region CMUBlock Functions for Tiered Pricing */
/**
* ********************************************
* START: CMUBlock Functions for Tiered Pricing
*/
/**
* Collect Quantity, Price and Line array of CMU Block
*
* @param line
* @param tieredinfo_CMUBLOCK
* @returns tieredinfo_CMUBLOCK
*/
function each_CMUBLOCK(line, tieredinfo_CMUBLOCK) {
if ('CMU_BLOCK_QUANT_06IN' === line.record['SBQQ__ProductCode__c']) {
tieredinfo_CMUBLOCK['quant_CMUBLOCK_06'] += line.record['SBQQ__Quantity__c'];
tieredinfo_CMUBLOCK['price_CMUBLOCK_06'] = line.record['SBQQ__NetPrice__c'];
tieredinfo_CMUBLOCK['line_CMUBLOCK_06'].push(line);
}
if ('CMU_BLOCK_QUANT_08IN' === line.record['SBQQ__ProductCode__c']) {
tieredinfo_CMUBLOCK['quant_CMUBLOCK_08'] += line.record['SBQQ__Quantity__c'];
tieredinfo_CMUBLOCK['price_CMUBLOCK_08'] = line.record['SBQQ__NetPrice__c'];
tieredinfo_CMUBLOCK['line_CMUBLOCK_08'].push(line);
}
if ('CMU_BLOCK_QUANT_10IN' === line.record['SBQQ__ProductCode__c']) {
tieredinfo_CMUBLOCK['quant_CMUBLOCK_10'] += line.record['SBQQ__Quantity__c'];
tieredinfo_CMUBLOCK['price_CMUBLOCK_10'] = line.record['SBQQ__NetPrice__c'];
tieredinfo_CMUBLOCK['line_CMUBLOCK_10'].push(line);
}
if ('CMU_BLOCK_QUANT_12IN' === line.record['SBQQ__ProductCode__c']) {
tieredinfo_CMUBLOCK['quant_CMUBLOCK_12'] += line.record['SBQQ__Quantity__c'];
tieredinfo_CMUBLOCK['price_CMUBLOCK_12'] = line.record['SBQQ__NetPrice__c'];
tieredinfo_CMUBLOCK['line_CMUBLOCK_12'].push(line);
}
return tieredinfo_CMUBLOCK;
}
function updateCMUBLOCKslabprice(quoteLineModels, tieredinfo_CMUBLOCK) {
/* CMUBLOCK calculating variable declarations */
var quant_CMUBLOCK = [];
var onePrice_CMUBLOCK = [];
var total_CMUBLOCK =
tieredinfo_CMUBLOCK['quant_CMUBLOCK_06'] +
tieredinfo_CMUBLOCK['quant_CMUBLOCK_08'] +
tieredinfo_CMUBLOCK['quant_CMUBLOCK_10'] +
tieredinfo_CMUBLOCK['quant_CMUBLOCK_12'];
quant_CMUBLOCK[6] = tieredinfo_CMUBLOCK['quant_CMUBLOCK_06'];
quant_CMUBLOCK[8] = tieredinfo_CMUBLOCK['quant_CMUBLOCK_08'];
quant_CMUBLOCK[10] = tieredinfo_CMUBLOCK['quant_CMUBLOCK_10'];
quant_CMUBLOCK[12] = tieredinfo_CMUBLOCK['quant_CMUBLOCK_12'];
onePrice_CMUBLOCK[6] = tieredinfo_CMUBLOCK['price_CMUBLOCK_06'];
onePrice_CMUBLOCK[8] = tieredinfo_CMUBLOCK['price_CMUBLOCK_08'];
onePrice_CMUBLOCK[10] = tieredinfo_CMUBLOCK['price_CMUBLOCK_10'];
onePrice_CMUBLOCK[12] = tieredinfo_CMUBLOCK['price_CMUBLOCK_12'];
var slabBlockPrice = slabBlockPriceAllTogether(quant_CMUBLOCK, onePrice_CMUBLOCK, total_CMUBLOCK);
tieredinfo_CMUBLOCK['line_CMUBLOCK_06'].forEach(function (line) {
line.record['SBQQ__NetPrice__c'] = slabBlockPrice;
line.record['Custom_Package_Total__c'] = line.record['SBQQ__Quantity__c'] * line.record['SBQQ__NetPrice__c'];
});
tieredinfo_CMUBLOCK['line_CMUBLOCK_08'].forEach(function (line) {
line.record['SBQQ__NetPrice__c'] = slabBlockPrice;
line.record['Custom_Package_Total__c'] = line.record['SBQQ__Quantity__c'] * line.record['SBQQ__NetPrice__c'];
});
tieredinfo_CMUBLOCK['line_CMUBLOCK_10'].forEach(function (line) {
line.record['SBQQ__NetPrice__c'] = slabBlockPrice;
line.record['Custom_Package_Total__c'] = line.record['SBQQ__Quantity__c'] * line.record['SBQQ__NetPrice__c'];
});
tieredinfo_CMUBLOCK['line_CMUBLOCK_12'].forEach(function (line) {
line.record['SBQQ__NetPrice__c'] = slabBlockPrice;
line.record['Custom_Package_Total__c'] = line.record['SBQQ__Quantity__c'] * line.record['SBQQ__NetPrice__c'];
});
}
/**
* Calculates the Price of Each Block based on a tiered-slab model
*
* @param quant_CMUBLOCK
* @param onePrice
* @param total
* @returns tmpTotalPrice / total
*/
function slabBlockPriceAllTogether(quant_CMUBLOCK, onePrice, total) {
var tmpTotalPrice = 0;
var i = 1;
for (i = 1; i <= total; i++) {
if (i <= 100) {
if (quant_CMUBLOCK[12] > 0) {
tmpTotalPrice = tmpTotalPrice + onePrice[12];
quant_CMUBLOCK[12] = quant_CMUBLOCK[12] - 1;
} else if (quant_CMUBLOCK[10] > 0) {
tmpTotalPrice = tmpTotalPrice + onePrice[10];
quant_CMUBLOCK[10] = quant_CMUBLOCK[10] - 1;
} else if (quant_CMUBLOCK[8] > 0) {
tmpTotalPrice = tmpTotalPrice + onePrice[8];
quant_CMUBLOCK[8] = quant_CMUBLOCK[8] - 1;
} else if (quant_CMUBLOCK[6] > 0) {
tmpTotalPrice = tmpTotalPrice + onePrice[6];
quant_CMUBLOCK[6] = quant_CMUBLOCK[6] - 1;
}
} else if (i <= 250) {
if (quant_CMUBLOCK[12] > 0) {
tmpTotalPrice = tmpTotalPrice + onePrice[12] - 1;
quant_CMUBLOCK[12] = quant_CMUBLOCK[12] - 1;
} else if (quant_CMUBLOCK[10] > 0) {
tmpTotalPrice = tmpTotalPrice + onePrice[10] - 1;
quant_CMUBLOCK[10] = quant_CMUBLOCK[10] - 1;
} else if (quant_CMUBLOCK[8] > 0) {
tmpTotalPrice = tmpTotalPrice + onePrice[8] - 1;
quant_CMUBLOCK[8] = quant_CMUBLOCK[8] - 1;
} else if (quant_CMUBLOCK[6] > 0) {
tmpTotalPrice = tmpTotalPrice + onePrice[6];
quant_CMUBLOCK[6] = quant_CMUBLOCK[6] - 1;
}
} else if (i <= 400) {
if (quant_CMUBLOCK[12] > 0) {
tmpTotalPrice = tmpTotalPrice + onePrice[12] - 2;
quant_CMUBLOCK[12] = quant_CMUBLOCK[12] - 1;
} else if (quant_CMUBLOCK[10] > 0) {
tmpTotalPrice = tmpTotalPrice + onePrice[10] - 2;
quant_CMUBLOCK[10] = quant_CMUBLOCK[10] - 1;
} else if (quant_CMUBLOCK[8] > 0) {
tmpTotalPrice = tmpTotalPrice + onePrice[8] - 2;
quant_CMUBLOCK[8] = quant_CMUBLOCK[8] - 1;
} else if (quant_CMUBLOCK[6] > 0) {
tmpTotalPrice = tmpTotalPrice + onePrice[6];
quant_CMUBLOCK[6] = quant_CMUBLOCK[6] - 1;
}
} else if (i <= 650) {
if (quant_CMUBLOCK[12] > 0) {
tmpTotalPrice = tmpTotalPrice + onePrice[12] - 3;
quant_CMUBLOCK[12] = quant_CMUBLOCK[12] - 1;
} else if (quant_CMUBLOCK[10] > 0) {
tmpTotalPrice = tmpTotalPrice + onePrice[10] - 3;
quant_CMUBLOCK[10] = quant_CMUBLOCK[10] - 1;
} else if (quant_CMUBLOCK[8] > 0) {
tmpTotalPrice = tmpTotalPrice + onePrice[8] - 3;
quant_CMUBLOCK[8] = quant_CMUBLOCK[8] - 1;
} else if (quant_CMUBLOCK[6] > 0) {
tmpTotalPrice = tmpTotalPrice + onePrice[6];
quant_CMUBLOCK[6] = quant_CMUBLOCK[6] - 1;
}
} else if (i <= 1000) {
if (quant_CMUBLOCK[12] > 0) {
tmpTotalPrice = tmpTotalPrice + onePrice[12] - 4;
quant_CMUBLOCK[12] = quant_CMUBLOCK[12] - 1;
} else if (quant_CMUBLOCK[10] > 0) {
tmpTotalPrice = tmpTotalPrice + onePrice[10] - 4;
quant_CMUBLOCK[10] = quant_CMUBLOCK[10] - 1;
} else if (quant_CMUBLOCK[8] > 0) {
tmpTotalPrice = tmpTotalPrice + onePrice[8] - 4;
quant_CMUBLOCK[8] = quant_CMUBLOCK[8] - 1;
} else if (quant_CMUBLOCK[6] > 0) {
tmpTotalPrice = tmpTotalPrice + onePrice[6];
quant_CMUBLOCK[6] = quant_CMUBLOCK[6] - 1;
}
} else {
if (quant_CMUBLOCK[12] > 0) {
tmpTotalPrice = tmpTotalPrice + onePrice[12] - 5;
quant_CMUBLOCK[12] = quant_CMUBLOCK[12] - 1;
} else if (quant_CMUBLOCK[10] > 0) {