Git Repository Public Repository

namibia

URLs

Copy to Clipboard
 
df0489e1eeeeab5a9bd44e1d84fce49924fe1bac
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
;(function(){

    window._w.stock = {

        ti : null,
        dfrom : '',
        dto   : '',
        gridStatus : null,

        onPageDestruct : function()
        {
            App.Event.removeListener('stockGridSuFilter', 'SuChange');

        },

        onStockPageTemplateReady : function( template, event, eventData )
        {
            _w.stock.ti = _t[template];
            App.DataStore.loadSelectListData('filtermakes', true, 'Stock', 'Make.SelectList');
            if (App.companyData.tC)
            {
                App.DataStore.setData('stockstatuses',
                    [
                        {"value":"Stock", "label":"Stock"},
                        {"value":"Auction", "label":"Auction"},
                        {"value":"Trade Center", "label":"Trade Center"},
                        {"value":"Sold", "label":"Sold"},
                        {"value":"Relist", "label":"Relist"},
                        {"value":"Price Guide", "label":"Price Guide"},
                        {"value":"Retail", "label":"Retail"},
                        {"value":"Archived", "label":"Archived"}
                    ]
                );
            }
            else
            {
                App.DataStore.setData('stockstatuses',
                    [
                        {"value":"Stock", "label":"Stock"},
                        {"value":"Auction", "label":"Auction"},
                        {"value":"Sold", "label":"Sold"},
                        {"value":"Relist", "label":"Relist"},
                        {"value":"Price Guide", "label":"Price Guide"},
                        {"value":"Retail", "label":"Retail"},
                        {"value":"Archived", "label":"Archived"}
                    ]
                );
            }
            _w.stock.ti.hydrate({
                'gridTitle': 'Stock Control',
                'gridTitleSubtext': 'Please use the filters below to narrow down the view',
                'gridTitleButtons': {
                    constructor: 'Button',
                    items: {
                        BulkImporter: {
                            preset: 'BulkImporter',
                            id: 'bulkImporterStockGrid',
                            handler: _w.stock.bulkImporterStockGrid
                        },
                        AuctionReport: {
                            preset: 'AuctionReport',
                            id: 'auctionReportStockGrid',
                            handler: _w.stock.auctionReportStockGrid
                        },
                        Export: {
                            preset: 'GridExport',
                            id: 'exportStockGrid',
                            handler: _w.stock.exportStockGrid
                        },
                        New: {
                            preset: 'NewStock',
                            id: 'newStock',
                            handler: _w.stock.newStock
                        }
                    }
                },
                'gridContextFilter': {
                    constructor: 'GridContextFilter',
                    items: {
                        RefNum: {
                            title: 'Search here:',
                            style: 'filter-input-wrapper',
                            id: 'gridStockContext_RefNo',
                            placeholder: 'Ref number',
                            context: 'gridStockContext'
                        },
                        RegNum: {
                            style: 'filter-input-wrapper',
                            id: 'gridStockContext_RegNo',
                            placeholder: 'Registration number',
                            context: 'gridStockContext'
                        },
                        DateFrom: {
                            style : 'input-append date filter-input-wrapper-date mobile-width12p dfrom',
                            title: 'Search date created here',
                            id: 'gridStockContext_DateFrom',
                            placeholder: 'From',
                            context: 'gridStockContext',
                            append: '<i class="icon-calendar"></i>',
                            readonly: true,
                            bind: function() {
                                $('#gridStockContext_DateFrom').change(function() {
                                    _w.stock.dFrom = $(this).val();
                                });
                            }
                        },
                        DateTo: {
                            style : 'input-append date filter-input-wrapper-date mobile-width12p dto',
                            id: 'gridStockContext_DateTo',
                            placeholder: 'To',
                            context: 'gridStockContext',
                            append: '<i class="icon-calendar"></i>',
                            readonly: true,
                            bind: function() {
                                $('#gridStockContext_DateTo').change(function() {
                                    _w.stock.dTo = $(this).val();
                                });
                            }
                        },
                        Buttons: {
                            actions: true,
                            searchId: 'searchStockGrid',
                            bindSearch: _w.stock.searchStockGrid,
                            clearId: 'clearStockGridContext',
                            bindClear: _w.stock.clearStockGridContext

                        },
                        RelistFilter: {
                            style : 'filter-input-wrapper hidden',
                            id: 'gridStockContext_RelistFilter',
                            placeholder: 'Relist Filter',
                            context: 'gridStockContext',
                            value: 'Relist,Undone'
                        }
                    }
                },
                'gridColumnHeaders': {
                    constructor: 'GridColumnHeader',
                    items: {
                        VIN: {
                            id: 'gridStockColumn_VIN',
                            title: 'VIN',
                            orderAsc: {
                                id: 'gridStockOrder_VinAsc',
                                bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.vinNumber', 'ASC')
                            },
                            orderDesc: {
                                id: 'gridStockOrder_VinDesc',
                                bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.vinNumber', 'DESC')
                            },
                            style: 'hidden-phone'
                        },
                        Make: {
                            id: 'gridStockColumn_Make',
                            title: 'MAKE',
                            orderAsc: {
                                id: 'gridStockOrder_MakeAsc',
                                bind: $.proxy(_w.stock.orderStockGrid, this, 'make.name', 'ASC')
                            },
                            orderDesc: {
                                id: 'gridStockOrder_MakeDesc',
                                bind: $.proxy(_w.stock.orderStockGrid, this, 'make.name', 'DESC')
                            },
                            style: 'make'
                        },
                        Model: {
                            id: 'gridStockColumn_Model',
                            title: 'MODEL',
                            orderAsc: {
                                id: 'gridStockOrder_ModelAsc',
                                bind: $.proxy(_w.stock.orderStockGrid, this, 'model.name', 'ASC')
                            },
                            orderDesc: {
                                id: 'gridStockOrder_ModelDesc',
                                bind: $.proxy(_w.stock.orderStockGrid, this, 'model.name', 'DESC')
                            },
                            style: 'hidden-phone'
                        },
                        Type: {
                            id: 'gridStockColumn_Type',
                            title: 'TYPE',
                            orderAsc: {
                                id: 'gridStockOrder_TypeAsc',
                                bind: $.proxy(_w.stock.orderStockGrid, this, 'type.name', 'ASC')
                            },
                            orderDesc: {
                                id: 'gridStockOrder_TypeDesc',
                                bind: $.proxy(_w.stock.orderStockGrid, this, 'type.name', 'DESC')
                            },
                            style: 'type'
                        },
                        Year: {
                            id: 'gridStockColumn_Year',
                            title: 'YEAR',
                            orderAsc: {
                                id: 'gridStockOrder_YearAsc',
                                bind: $.proxy(_w.stock.orderStockGrid, this, 'vehicleYear.name', 'ASC')
                            },
                            orderDesc: {
                                id: 'gridStockOrder_YearDesc',
                                bind: $.proxy(_w.stock.orderStockGrid, this, 'vehicleYear.name', 'DESC')
                            },
                            style: 'year'
                        },
                        KM: {
                            id: 'gridStockColumn_KM',
                            title: 'KM&#39;S',
                            orderAsc: {
                                id: 'gridStockOrder_KmAsc',
                                bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.km', 'ASC')
                            },
                            orderDesc: {
                                id: 'gridStockOrder_KmDesc',
                                bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.km', 'DESC')
                            },
                            style: 'kms hidden-phone'
                        },
                        Trade: {
                            id: 'gridStockColumn_Trade',
                            title: 'TRADE',
                            orderAsc: {
                                id: 'gridStockOrder_TradeAsc',
                                bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.tradePrice', 'ASC')
                            },
                            orderDesc: {
                                id: 'gridStockOrder_TradeDesc',
                                bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.tradePrice', 'DESC')
                            },
                            style: 'hidden-phone'
                        },
                        Retail: {
                            id: 'gridStockColumn_Retail',
                            title: 'RETAIL',
                            orderAsc: {
                                id: 'gridStockOrder_RetailAsc',
                                bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.retailPrice', 'ASC')
                            },
                            orderDesc: {
                                id: 'gridStockOrder_RetailDesc',
                                bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.retailPrice', 'DESC')
                            },
                            style: 'hidden-phone'
                        },
                        Offer: {
                            id: 'gridStockColumn_Offer',
                            title: 'OFFER',
                            orderAsc: {
                                id: 'gridStockOrder_OfferAsc',
                                bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.highestOffer', 'ASC')
                            },
                            orderDesc: {
                                id: 'gridStockOrder_OfferDesc',
                                bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.highestOffer', 'DESC')
                            },
                            style: 'hidden-phone'
                        },
                        Bid: {
                            id: 'gridStockColumn_Bid',
                            title: 'BID',
                            orderAsc: {
                                id: 'gridStockOrder_BidAsc',
                                bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.highestBid', 'ASC')
                            },
                            orderDesc: {
                                id: 'gridStockOrder_BidDesc',
                                bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.highestBid', 'DESC')
                            },
                            style: 'hidden-phone'
                        },
                        Status: {
                            id: 'gridStockColumn_Status',
                            title: 'STATUS',
                            orderAsc: {
                                id: 'gridStockOrder_JobstateAsc',
                                bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.jobState', 'ASC')
                            },
                            orderDesc: {
                                id: 'gridStockOrder_JobstateDesc',
                                bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.jobState', 'DESC')
                            }
                        }
                    }
                },
                'gridColumnFilters': {
                    constructor: 'GridColumnFilter',
                    items: {
                        VIN: {
                            id: 'gridStockFilter_VIN',
                            context: 'gridStockFilter'
                        },
                        Make: {
                            id: 'gridStockFilter_Make',
                            context: 'gridStockFilter',
                            dataStoreId : 'filtermakes',
                            selectEmpty : 'All',
                            bind : function(meta){
                                _w.stock.changes = 0;
                                $('#' + meta.id).change(function(){
                                    _w.stock.changes++;
                                    if (1 == _w.stock.changes || 'Active' != _w.stock.gridStatus)
                                    {
                                        return;
                                    }
                                    _w.stock.searchStockGrid();
                                });
                            }
                        },
                        Model: {
                            id: 'gridStockFilter_Model',
                            context: 'gridStockFilter'
                        },
                        Type: {
                            id: 'gridStockFilter_Type',
                            context: 'gridStockFilter'
                        },
                        Year: {
                            id: 'gridStockFilter_Year',
                            context: 'gridStockFilter'
                        },
                        KM: {
                            id: 'gridStockFilter_KM',
                            context: 'gridStockFilter'
                        },
                        Trade: {
                            id: 'gridStockFilter_Trade',
                            context: 'gridStockFilter'
                        },
                        Retail: {
                            id: 'gridStockFilter_Retail',
                            context: 'gridStockFilter'
                        },
                        Offer: {
                            id: 'gridStockFilter_Offer',
                            context: 'gridStockFilter'
                        },
                        Bid: {
                            id: 'gridStockFilter_Bid',
                            context: 'gridStockFilter'
                        },
                        Status: {
                            id: 'gridStockFilter_Status',
                            context: 'gridStockFilter',
                            dataStoreId : 'stockstatuses',
                            selectEmpty : 'All',
                            bind : function(meta){
                                _w.stock.changes = 0;
                                $('#' + meta.id).change(function(){
                                    _w.stock.changes++;
                                    if (1 == _w.stock.changes || 'Active' != _w.stock.gridStatus)
                                    {
                                        return;
                                    }
                                    _w.stock.searchStockGrid();
                                });
                            }
                        }
                    }
                },
                'gridRowRepeater': {},
                'gridPager': {}
            });

            // Retrieve initial grid data.
            if (null == App.API.taskContract('gridStock'))
            {
                App.API.getTask(
                    'gridStock', 'Stock', 'Stock.Grid', null,
                    {}, _w.stock.loadStockGrid, _w.taskContractError
                );
            }
            else
            {
                _w.stock.loadStockGrid( null, {}, {} );
            }
        },

        onStockPublished : function()
        {

            $(".gridStockFilter").keyup(function (evt) {
                var charCode = evt.charCode || evt.keyCode;
                if (charCode  == 13) { //Enter key's keycode
                    $('#searchStockGrid').click();
                }
            });

            $(".gridStockContext").keyup(function (evt) {
                var charCode = evt.charCode || evt.keyCode;
                if (charCode  == 13) { //Enter key's keycode
                    $('#searchStockGrid').click();
                }
            });

            var _p = App.permissions;
            var _createStockDisabled = false == _p.stockCreateNew && false == _p.stockCreateAuction
                ? true : false;
            $('#newStock').prop('disabled', _createStockDisabled);
            $('#exportStockGrid').prop('disabled', !App.permissions.stockGridExport);

            $('#bulkImporterStockGrid').prop('disabled', !App.permissions.stockBulkImportDrive || !App.permissions.stockBulkImportPinnacle);
            $('#bulkImporterStockGrid').hide();
            if(App.permissions.stockBulkImportDrive || App.permissions.stockBulkImportPinnacle)
            {
                $('#bulkImporterStockGrid').show();
            }

            $('#auctionReportStockGrid').prop('disabled', !App.permissions.stockAuctionReportGridExport);
            $('#auctionReportStockGrid').hide();
            if(App.permissions.stockAuctionReportGridExport)
            {
                $('#auctionReportStockGrid').show();
            }

            App.Event.listen('stockGridSuFilter', 'SuChange', $.proxy(_w.stock.loadStockGrid, this), 'Recurring');
            $('.dfrom').datepicker({format:"yyyy-mm-dd"});
            $('.dto').datepicker({format:"yyyy-mm-dd"});
            $('#gridStockContext_DateFrom').val(_w.stock.dFrom);
            $('#gridStockContext_DateTo').val(_w.stock.dTo);

            //setTimeout(_w.stock.refreshGrid, 120000);
        },

        refreshGrid : function()
        {
            return;
            if ('stock' != App.activePage)
            {
                return;
            }
            _w.stock.loadStockGrid( null, {}, {} );
            setTimeout(_w.stock.refreshGrid, 120000);
        },

        pageStockGrid : function( page )
        {
            _w.stock.loadStockGrid( {}, {"Grid":{"Page":page}} );
        },

        loadStockGrid : function( contract, data, options )
        {
            App.API.execTask(
                'gridStock', data, options,
                _w.stock._onStockGridDataReceived, _w.taskExecError
            );
        },

        _onStockGridDataReceived : function( response )
        {
            _w.stock.gridStatus = 'Active';
            _w.stock.ti.hydrateParam('gridRowRepeater', {});
            if (undefined != response.Data.Meta.Filters['auction.jobState'])
            {
                _w.populateFilters(response.Data.Meta.Filters, {
                    'stock.registrationNumber': 'gridStockContext_RegNo',
                    'stock.referenceNumber': 'gridStockContext_RefNo',
                    'stock.vinNumber': 'gridStockFilter_VIN',
                    'make.id': 'gridStockFilter_Make',
                    'model.name': 'gridStockFilter_Model',
                    'type.name': 'gridStockFilter_Type',
                    'vehicleYear.name': 'gridStockFilter_Year',
                    'stock.km': 'gridStockFilter_KM',
                    'stock.tradePrice': 'gridStockFilter_Trade',
                    'stock.retailPrice': 'gridStockFilter_Retail',
                    'stock.highestOffer': 'gridStockFilter_Offer',
                    'stock.highestBid': 'gridStockFilter_Bid',
                    'auction.jobState': 'gridStockFilter_Status'
                });
            }
            else
            {
                _w.populateFilters(response.Data.Meta.Filters, {
                    'stock.registrationNumber': 'gridStockContext_RegNo',
                    'stock.referenceNumber': 'gridStockContext_RefNo',
                    'stock.vinNumber': 'gridStockFilter_VIN',
                    'make.id': 'gridStockFilter_Make',
                    'model.name': 'gridStockFilter_Model',
                    'type.name': 'gridStockFilter_Type',
                    'vehicleYear.name': 'gridStockFilter_Year',
                    'stock.km': 'gridStockFilter_KM',
                    'stock.tradePrice': 'gridStockFilter_Trade',
                    'stock.retailPrice': 'gridStockFilter_Retail',
                    'stock.highestOffer': 'gridStockFilter_Offer',
                    'stock.highestBid': 'gridStockFilter_Bid',
                    'stock.jobState': 'gridStockFilter_Status'
                });
            }
            $('select.gridStockFilter').each(function(i, elem) {
                $(elem).selectpicker('refresh');
            });
            var gridData = [];
            for (var i = 0; i < response.Data.DataSet.length; i++)
            {
                var row = response.Data.DataSet[i];

                //console.log('row',row);

                gridData.push({
                    lineClass: 'handy',
                    surl: ('Stock' == row.jobState || ('Auction' == row.jobState && "0.00" == row.highestBid) || 'Relist' == row.jobState)

                        ? 'stockview' : 'limitedstockview',
                    prepend: {
                        Trade  : 'R ',
                        Retail : 'R ',
                        Offer  : 'R '
                    },
                    rowId: row.id,
                    pgId: row.priceGuide ? row.priceGuide.id : false,
                    offers:  row.priceGuide && row.priceGuide.offers
                        ? row.priceGuide.offers[0]
                        : null,
                    bind: function(meta) {
                        $('#row' +  meta.rowId).click(function(e){
                            window.location='#/' + meta.surl + '?id=' + meta.rowId;
                        });

                        $('#ofr' + meta.rowId).click(function(e) {
                            _w.PopUp = true;
                            e.preventDefault();
                            e.stopPropagation();
                            if (!meta.pgId)
                            {
                                var modalbody = '<div style="font-weight:bold;color:#9B2022;">There are no offers!</div>';
                                $('#modalbody').html(modalbody);
                                return;
                            }
                            else
                            {
                                $('#modalbody').html('<center>Loading offers...</center>');
                                $('#myModal').modal('toggle');
                            }
                            App.API.getTask(
                                'offerList', 'PriceGuide', 'Offer.List',
                                meta.pgId, {}, function(){
                                    App.API.execTask(
                                        'offerList', {}, {},
                                        function(response)
                                        {
                                            var offers = response.Data;
                                            if (offers.length)
                                            {
                                                var modalbody = '<table class="table table-bordered table-condensed table-striped">';
                                                modalbody += '<tr><td>Company</td><td>Date Offered</td><td>Amount</td></tr>';
                                                for (var x in offers)
                                                {
                                                    var isOwn = offers[x].company.id == App.companyData.id
                                                        ? true
                                                        : false;
                                                    modalbody +=
                                                        '<tr class="modalrow ' + (isOwn ? 'red' : 'black') + '">'
                                                        + '<td class="date">' + offers[x].company.name + '</td>'
                                                        + '<td class="date">' + offers[x].created + '</td>'
                                                        + '<td class="wide">' + offers[x].amount + '</td>'
                                                        + '</tr>';
                                                }
                                                modalbody += '</table>';
                                            }
                                            else
                                            {
                                                var modalbody = '<div style="font-weight:bold;color:#9B2022;">There are no offers!</div>';
                                            }
                                            $('#modalbody').html(modalbody);
                                        }, _w.taskExecError
                                    );
                                }, _w.taskContractError
                            );
                        });
                    },
                    style: {
                        VIN		: 'hidden-phone',
                        Make	: 'make',
                        Model	: 'hidden-phone',
                        Type	: 'type',
                        Year	: 'year',
                        KM		: 'hidden-phone',
                        Trade	: 'hidden-phone',
                        Retail	: 'hidden-phone',
                        Offer	: 'hidden-phone offer',
                        Bid		: 'hidden-phone',
                        Status	: 'status'

                    },
                    items: {
                        'id'     : row.id,
                        'VIN'    : row.vinNumber,
                        'Make'   : row.type.model.make.name,
                        'Model'  : row.type.model.name,
                        'Type'   : row.type.name,
                        'Year'   : row.vehicleYear.name,
                        'KM'     : row.km,
                        'Trade'  : row.tradePrice,
                        'Retail' : row.retailPrice,
                        'Offer'  : row.highestOffer + '&nbsp;&nbsp;&nbsp;<span id="ofr' + row.id + '">' + row.numberOfOffers + '</span>',
                        'Bid'    : row.highestBid,
                        'Status' : ('Stock' == row.jobState || 'Trade Center' == row.jobState) && row.auction && (row.auction.jobState == 'Undone' || row.auction.jobState == 'Relist') ? 'Relist' : row.jobState
                        //'Status' : row.auction.jobState == 'Undone' || row.auction.jobState == 'Relist' ? 'Relist' : row.jobState // Made this the same as portal-workspace/tcstock.js
                    }
                });
            }
            _w.stock.ti.hydrateParam('gridRowRepeater', {
                constructor : 'GridDataRow',
                items       : gridData
            });
            response.Data.Meta.itemName = 'stockPager';
            response.Data.Meta.bind = _w.stock.pageStockGrid;
            _w.stock.ti.hydrateParam('gridPager', {
                constructor : 'GridPager',
                items       : [response.Data.Meta]
            });
        },

        exportStockGrid : function()
        {
            App.API.execTask(
                'gridStock', {}, {'ExportToExcel': true},
                _w.stock._onExportReceived, _w.taskExecError,
                'EXPORT', true
            );
        },
        bulkImporterStockGrid  : function()
        {
            window.location.hash = '/stockbulkimporter';
        },
        auctionReportStockGrid : function()
        {
            window.location.hash = '/stockauctionreport';
        },

        newStock : function()
        {
            window.location.hash = '/stockview?id=0';
        },

        _onExportReceived : function( response )
        {
            var win = window.open();
            win.document.write(response);
        },

        clearStockGridContext : function()
        {
            _w.stock.gridStatus = 'Inactive';
            try
            {
                $('select.gridStockFilter').each(function(i, elem) {
                    $(elem).selectpicker('val', '');
                    $(elem).selectpicker('refresh');
                });
            }
            catch (err) { console.log(err); }
            $('.gridStockContext').val('');
            $('.gridStockFilter').val('');
            _w.stock.searchStockGrid(true);
        },

        searchStockGrid : function(resetOrder)
        {
            _w.stock.gridStatus = 'Inactive';
            var filter = {
                count: 0,
                filters: {}
            };
            filter = _w.filterIfnotEmpty(filter, 'gridStockContext_RegNo', 'stock.registrationNumber');
            filter = _w.filterIfnotEmpty(filter, 'gridStockContext_RefNo', 'stock.referenceNumber');
            filter = _w.filterIfnotEmpty(filter, 'gridStockContext_DateFrom', 'stock.created', '>=');
            filter = _w.filterIfnotEmpty(filter, 'gridStockContext_DateTo', 'stock.created', '<=', ' 23:59:59');

            filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_VIN', 'stock.vinNumber');
            filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Make', 'make.id');
            filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Model', 'model.name');
            filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Type', 'type.name');
            filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Year', 'vehicleYear.name');
            filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_KM', 'stock.km');
            filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Trade', 'stock.tradePrice');
            filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Retail', 'stock.retailPrice');
            filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Offer', 'stock.highestOffer');
            var status = $('#gridStockFilter_Status').val();
            if ('Undone' == status || 'Relist' == status)
            {
                $('#gridValuationContext_notArchived').val('Relist,Undone');
                filter = _w.filterIfnotEmpty(filter, 'gridStockContext_RelistFilter', 'auction.jobState', 'IN');
            }
            else
            {
                filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Status', 'stock.jobState');
            }
            var request = {"Grid":{
                "Page": 1,
                "Filter": filter.filters
            }};
            if (resetOrder)
            {
                request.Grid.OrderBy = {'stock.created': 'DESC'};
            }
            _w.stock.loadStockGrid( null, request, {} );
        },

        orderStockGrid : function(field, direction)
        {
            var order = {};
            order[field] = direction;
            _w.stock.loadStockGrid( {}, {"Grid":{"Page": 1, "OrderBy": order}} );
        }

    };

})();

Commits for namibiapublic/js/app/portal-workspace/stock.js

Diff revisions: vs.
Revision Author Commited Message
df0489 ... Mark Fri 14 Oct, 2016 10:01:00 +0000

initial commit