text changes to registration mail content
[namibia] / public / js / app / portal-workspace / stock.js
1 ;(function(){
2
3     window._w.stock = {
4
5         ti : null,
6         dfrom : '',
7         dto   : '',
8         gridStatus : null,
9
10         onPageDestruct : function()
11         {
12             App.Event.removeListener('stockGridSuFilter', 'SuChange');
13
14         },
15
16         onStockPageTemplateReady : function( template, event, eventData )
17         {
18             _w.stock.ti = _t[template];
19             App.DataStore.loadSelectListData('filtermakes', true, 'Stock', 'Make.SelectList');
20             if (App.companyData.tC)
21             {
22                 App.DataStore.setData('stockstatuses',
23                     [
24                         {"value":"Stock", "label":"Stock"},
25                         {"value":"Auction", "label":"Auction"},
26                         {"value":"Trade Center", "label":"Trade Center"},
27                         {"value":"Sold", "label":"Sold"},
28                         {"value":"Relist", "label":"Relist"},
29                         {"value":"Price Guide", "label":"Price Guide"},
30                         {"value":"Retail", "label":"Retail"},
31                         {"value":"Archived", "label":"Archived"}
32                     ]
33                 );
34             }
35             else
36             {
37                 App.DataStore.setData('stockstatuses',
38                     [
39                         {"value":"Stock", "label":"Stock"},
40                         {"value":"Auction", "label":"Auction"},
41                         {"value":"Sold", "label":"Sold"},
42                         {"value":"Relist", "label":"Relist"},
43                         {"value":"Price Guide", "label":"Price Guide"},
44                         {"value":"Retail", "label":"Retail"},
45                         {"value":"Archived", "label":"Archived"}
46                     ]
47                 );
48             }
49             _w.stock.ti.hydrate({
50                 'gridTitle': 'Stock Control',
51                 'gridTitleSubtext': 'Please use the filters below to narrow down the view',
52                 'gridTitleButtons': {
53                     constructor: 'Button',
54                     items: {
55                         BulkImporter: {
56                             preset: 'BulkImporter',
57                             id: 'bulkImporterStockGrid',
58                             handler: _w.stock.bulkImporterStockGrid
59                         },
60                         AuctionReport: {
61                             preset: 'AuctionReport',
62                             id: 'auctionReportStockGrid',
63                             handler: _w.stock.auctionReportStockGrid
64                         },
65                         Export: {
66                             preset: 'GridExport',
67                             id: 'exportStockGrid',
68                             handler: _w.stock.exportStockGrid
69                         },
70                         New: {
71                             preset: 'NewStock',
72                             id: 'newStock',
73                             handler: _w.stock.newStock
74                         }
75                     }
76                 },
77                 'gridContextFilter': {
78                     constructor: 'GridContextFilter',
79                     items: {
80                         RefNum: {
81                             title: 'Search here:',
82                             style: 'filter-input-wrapper',
83                             id: 'gridStockContext_RefNo',
84                             placeholder: 'Ref number',
85                             context: 'gridStockContext'
86                         },
87                         RegNum: {
88                             style: 'filter-input-wrapper',
89                             id: 'gridStockContext_RegNo',
90                             placeholder: 'Registration number',
91                             context: 'gridStockContext'
92                         },
93                         DateFrom: {
94                             style : 'input-append date filter-input-wrapper-date mobile-width12p dfrom',
95                             title: 'Search date created here',
96                             id: 'gridStockContext_DateFrom',
97                             placeholder: 'From',
98                             context: 'gridStockContext',
99                             append: '<i class="icon-calendar"></i>',
100                             readonly: true,
101                             bind: function() {
102                                 $('#gridStockContext_DateFrom').change(function() {
103                                     _w.stock.dFrom = $(this).val();
104                                 });
105                             }
106                         },
107                         DateTo: {
108                             style : 'input-append date filter-input-wrapper-date mobile-width12p dto',
109                             id: 'gridStockContext_DateTo',
110                             placeholder: 'To',
111                             context: 'gridStockContext',
112                             append: '<i class="icon-calendar"></i>',
113                             readonly: true,
114                             bind: function() {
115                                 $('#gridStockContext_DateTo').change(function() {
116                                     _w.stock.dTo = $(this).val();
117                                 });
118                             }
119                         },
120                         Buttons: {
121                             actions: true,
122                             searchId: 'searchStockGrid',
123                             bindSearch: _w.stock.searchStockGrid,
124                             clearId: 'clearStockGridContext',
125                             bindClear: _w.stock.clearStockGridContext
126
127                         },
128                         RelistFilter: {
129                             style : 'filter-input-wrapper hidden',
130                             id: 'gridStockContext_RelistFilter',
131                             placeholder: 'Relist Filter',
132                             context: 'gridStockContext',
133                             value: 'Relist,Undone'
134                         }
135                     }
136                 },
137                 'gridColumnHeaders': {
138                     constructor: 'GridColumnHeader',
139                     items: {
140                         VIN: {
141                             id: 'gridStockColumn_VIN',
142                             title: 'VIN',
143                             orderAsc: {
144                                 id: 'gridStockOrder_VinAsc',
145                                 bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.vinNumber', 'ASC')
146                             },
147                             orderDesc: {
148                                 id: 'gridStockOrder_VinDesc',
149                                 bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.vinNumber', 'DESC')
150                             },
151                             style: 'hidden-phone'
152                         },
153                         Make: {
154                             id: 'gridStockColumn_Make',
155                             title: 'MAKE',
156                             orderAsc: {
157                                 id: 'gridStockOrder_MakeAsc',
158                                 bind: $.proxy(_w.stock.orderStockGrid, this, 'make.name', 'ASC')
159                             },
160                             orderDesc: {
161                                 id: 'gridStockOrder_MakeDesc',
162                                 bind: $.proxy(_w.stock.orderStockGrid, this, 'make.name', 'DESC')
163                             },
164                             style: 'make'
165                         },
166                         Model: {
167                             id: 'gridStockColumn_Model',
168                             title: 'MODEL',
169                             orderAsc: {
170                                 id: 'gridStockOrder_ModelAsc',
171                                 bind: $.proxy(_w.stock.orderStockGrid, this, 'model.name', 'ASC')
172                             },
173                             orderDesc: {
174                                 id: 'gridStockOrder_ModelDesc',
175                                 bind: $.proxy(_w.stock.orderStockGrid, this, 'model.name', 'DESC')
176                             },
177                             style: 'hidden-phone'
178                         },
179                         Type: {
180                             id: 'gridStockColumn_Type',
181                             title: 'TYPE',
182                             orderAsc: {
183                                 id: 'gridStockOrder_TypeAsc',
184                                 bind: $.proxy(_w.stock.orderStockGrid, this, 'type.name', 'ASC')
185                             },
186                             orderDesc: {
187                                 id: 'gridStockOrder_TypeDesc',
188                                 bind: $.proxy(_w.stock.orderStockGrid, this, 'type.name', 'DESC')
189                             },
190                             style: 'type'
191                         },
192                         Year: {
193                             id: 'gridStockColumn_Year',
194                             title: 'YEAR',
195                             orderAsc: {
196                                 id: 'gridStockOrder_YearAsc',
197                                 bind: $.proxy(_w.stock.orderStockGrid, this, 'vehicleYear.name', 'ASC')
198                             },
199                             orderDesc: {
200                                 id: 'gridStockOrder_YearDesc',
201                                 bind: $.proxy(_w.stock.orderStockGrid, this, 'vehicleYear.name', 'DESC')
202                             },
203                             style: 'year'
204                         },
205                         KM: {
206                             id: 'gridStockColumn_KM',
207                             title: 'KM&#39;S',
208                             orderAsc: {
209                                 id: 'gridStockOrder_KmAsc',
210                                 bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.km', 'ASC')
211                             },
212                             orderDesc: {
213                                 id: 'gridStockOrder_KmDesc',
214                                 bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.km', 'DESC')
215                             },
216                             style: 'kms hidden-phone'
217                         },
218                         Trade: {
219                             id: 'gridStockColumn_Trade',
220                             title: 'TRADE',
221                             orderAsc: {
222                                 id: 'gridStockOrder_TradeAsc',
223                                 bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.tradePrice', 'ASC')
224                             },
225                             orderDesc: {
226                                 id: 'gridStockOrder_TradeDesc',
227                                 bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.tradePrice', 'DESC')
228                             },
229                             style: 'hidden-phone'
230                         },
231                         Retail: {
232                             id: 'gridStockColumn_Retail',
233                             title: 'RETAIL',
234                             orderAsc: {
235                                 id: 'gridStockOrder_RetailAsc',
236                                 bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.retailPrice', 'ASC')
237                             },
238                             orderDesc: {
239                                 id: 'gridStockOrder_RetailDesc',
240                                 bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.retailPrice', 'DESC')
241                             },
242                             style: 'hidden-phone'
243                         },
244                         Offer: {
245                             id: 'gridStockColumn_Offer',
246                             title: 'OFFER',
247                             orderAsc: {
248                                 id: 'gridStockOrder_OfferAsc',
249                                 bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.highestOffer', 'ASC')
250                             },
251                             orderDesc: {
252                                 id: 'gridStockOrder_OfferDesc',
253                                 bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.highestOffer', 'DESC')
254                             },
255                             style: 'hidden-phone'
256                         },
257                         Bid: {
258                             id: 'gridStockColumn_Bid',
259                             title: 'BID',
260                             orderAsc: {
261                                 id: 'gridStockOrder_BidAsc',
262                                 bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.highestBid', 'ASC')
263                             },
264                             orderDesc: {
265                                 id: 'gridStockOrder_BidDesc',
266                                 bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.highestBid', 'DESC')
267                             },
268                             style: 'hidden-phone'
269                         },
270                         Status: {
271                             id: 'gridStockColumn_Status',
272                             title: 'STATUS',
273                             orderAsc: {
274                                 id: 'gridStockOrder_JobstateAsc',
275                                 bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.jobState', 'ASC')
276                             },
277                             orderDesc: {
278                                 id: 'gridStockOrder_JobstateDesc',
279                                 bind: $.proxy(_w.stock.orderStockGrid, this, 'stock.jobState', 'DESC')
280                             }
281                         }
282                     }
283                 },
284                 'gridColumnFilters': {
285                     constructor: 'GridColumnFilter',
286                     items: {
287                         VIN: {
288                             id: 'gridStockFilter_VIN',
289                             context: 'gridStockFilter'
290                         },
291                         Make: {
292                             id: 'gridStockFilter_Make',
293                             context: 'gridStockFilter',
294                             dataStoreId : 'filtermakes',
295                             selectEmpty : 'All',
296                             bind : function(meta){
297                                 _w.stock.changes = 0;
298                                 $('#' + meta.id).change(function(){
299                                     _w.stock.changes++;
300                                     if (1 == _w.stock.changes || 'Active' != _w.stock.gridStatus)
301                                     {
302                                         return;
303                                     }
304                                     _w.stock.searchStockGrid();
305                                 });
306                             }
307                         },
308                         Model: {
309                             id: 'gridStockFilter_Model',
310                             context: 'gridStockFilter'
311                         },
312                         Type: {
313                             id: 'gridStockFilter_Type',
314                             context: 'gridStockFilter'
315                         },
316                         Year: {
317                             id: 'gridStockFilter_Year',
318                             context: 'gridStockFilter'
319                         },
320                         KM: {
321                             id: 'gridStockFilter_KM',
322                             context: 'gridStockFilter'
323                         },
324                         Trade: {
325                             id: 'gridStockFilter_Trade',
326                             context: 'gridStockFilter'
327                         },
328                         Retail: {
329                             id: 'gridStockFilter_Retail',
330                             context: 'gridStockFilter'
331                         },
332                         Offer: {
333                             id: 'gridStockFilter_Offer',
334                             context: 'gridStockFilter'
335                         },
336                         Bid: {
337                             id: 'gridStockFilter_Bid',
338                             context: 'gridStockFilter'
339                         },
340                         Status: {
341                             id: 'gridStockFilter_Status',
342                             context: 'gridStockFilter',
343                             dataStoreId : 'stockstatuses',
344                             selectEmpty : 'All',
345                             bind : function(meta){
346                                 _w.stock.changes = 0;
347                                 $('#' + meta.id).change(function(){
348                                     _w.stock.changes++;
349                                     if (1 == _w.stock.changes || 'Active' != _w.stock.gridStatus)
350                                     {
351                                         return;
352                                     }
353                                     _w.stock.searchStockGrid();
354                                 });
355                             }
356                         }
357                     }
358                 },
359                 'gridRowRepeater': {},
360                 'gridPager': {}
361             });
362
363             // Retrieve initial grid data.
364             if (null == App.API.taskContract('gridStock'))
365             {
366                 App.API.getTask(
367                     'gridStock', 'Stock', 'Stock.Grid', null,
368                     {}, _w.stock.loadStockGrid, _w.taskContractError
369                 );
370             }
371             else
372             {
373                 _w.stock.loadStockGrid( null, {}, {} );
374             }
375         },
376
377         onStockPublished : function()
378         {
379
380             $(".gridStockFilter").keyup(function (evt) {
381                 var charCode = evt.charCode || evt.keyCode;
382                 if (charCode  == 13) { //Enter key's keycode
383                     $('#searchStockGrid').click();
384                 }
385             });
386
387             $(".gridStockContext").keyup(function (evt) {
388                 var charCode = evt.charCode || evt.keyCode;
389                 if (charCode  == 13) { //Enter key's keycode
390                     $('#searchStockGrid').click();
391                 }
392             });
393
394             var _p = App.permissions;
395             var _createStockDisabled = false == _p.stockCreateNew && false == _p.stockCreateAuction
396                 ? true : false;
397             $('#newStock').prop('disabled', _createStockDisabled);
398             $('#exportStockGrid').prop('disabled', !App.permissions.stockGridExport);
399
400             $('#bulkImporterStockGrid').prop('disabled', !App.permissions.stockBulkImportDrive || !App.permissions.stockBulkImportPinnacle);
401             $('#bulkImporterStockGrid').hide();
402             if(App.permissions.stockBulkImportDrive || App.permissions.stockBulkImportPinnacle)
403             {
404                 $('#bulkImporterStockGrid').show();
405             }
406
407             $('#auctionReportStockGrid').prop('disabled', !App.permissions.stockAuctionReportGridExport);
408             $('#auctionReportStockGrid').hide();
409             if(App.permissions.stockAuctionReportGridExport)
410             {
411                 $('#auctionReportStockGrid').show();
412             }
413
414             App.Event.listen('stockGridSuFilter', 'SuChange', $.proxy(_w.stock.loadStockGrid, this), 'Recurring');
415             $('.dfrom').datepicker({format:"yyyy-mm-dd"});
416             $('.dto').datepicker({format:"yyyy-mm-dd"});
417             $('#gridStockContext_DateFrom').val(_w.stock.dFrom);
418             $('#gridStockContext_DateTo').val(_w.stock.dTo);
419
420             //setTimeout(_w.stock.refreshGrid, 120000);
421         },
422
423         refreshGrid : function()
424         {
425             return;
426             if ('stock' != App.activePage)
427             {
428                 return;
429             }
430             _w.stock.loadStockGrid( null, {}, {} );
431             setTimeout(_w.stock.refreshGrid, 120000);
432         },
433
434         pageStockGrid : function( page )
435         {
436             _w.stock.loadStockGrid( {}, {"Grid":{"Page":page}} );
437         },
438
439         loadStockGrid : function( contract, data, options )
440         {
441             App.API.execTask(
442                 'gridStock', data, options,
443                 _w.stock._onStockGridDataReceived, _w.taskExecError
444             );
445         },
446
447         _onStockGridDataReceived : function( response )
448         {
449             _w.stock.gridStatus = 'Active';
450             _w.stock.ti.hydrateParam('gridRowRepeater', {});
451             if (undefined != response.Data.Meta.Filters['auction.jobState'])
452             {
453                 _w.populateFilters(response.Data.Meta.Filters, {
454                     'stock.registrationNumber': 'gridStockContext_RegNo',
455                     'stock.referenceNumber': 'gridStockContext_RefNo',
456                     'stock.vinNumber': 'gridStockFilter_VIN',
457                     'make.id': 'gridStockFilter_Make',
458                     'model.name': 'gridStockFilter_Model',
459                     'type.name': 'gridStockFilter_Type',
460                     'vehicleYear.name': 'gridStockFilter_Year',
461                     'stock.km': 'gridStockFilter_KM',
462                     'stock.tradePrice': 'gridStockFilter_Trade',
463                     'stock.retailPrice': 'gridStockFilter_Retail',
464                     'stock.highestOffer': 'gridStockFilter_Offer',
465                     'stock.highestBid': 'gridStockFilter_Bid',
466                     'auction.jobState': 'gridStockFilter_Status'
467                 });
468             }
469             else
470             {
471                 _w.populateFilters(response.Data.Meta.Filters, {
472                     'stock.registrationNumber': 'gridStockContext_RegNo',
473                     'stock.referenceNumber': 'gridStockContext_RefNo',
474                     'stock.vinNumber': 'gridStockFilter_VIN',
475                     'make.id': 'gridStockFilter_Make',
476                     'model.name': 'gridStockFilter_Model',
477                     'type.name': 'gridStockFilter_Type',
478                     'vehicleYear.name': 'gridStockFilter_Year',
479                     'stock.km': 'gridStockFilter_KM',
480                     'stock.tradePrice': 'gridStockFilter_Trade',
481                     'stock.retailPrice': 'gridStockFilter_Retail',
482                     'stock.highestOffer': 'gridStockFilter_Offer',
483                     'stock.highestBid': 'gridStockFilter_Bid',
484                     'stock.jobState': 'gridStockFilter_Status'
485                 });
486             }
487             $('select.gridStockFilter').each(function(i, elem) {
488                 $(elem).selectpicker('refresh');
489             });
490             var gridData = [];
491             for (var i = 0; i < response.Data.DataSet.length; i++)
492             {
493                 var row = response.Data.DataSet[i];
494
495                 //console.log('row',row);
496
497                 gridData.push({
498                     lineClass: 'handy',
499                     surl: ('Stock' == row.jobState || ('Auction' == row.jobState && "0.00" == row.highestBid) || 'Relist' == row.jobState)
500
501                         ? 'stockview' : 'limitedstockview',
502                     prepend: {
503                         Trade  : 'R ',
504                         Retail : 'R ',
505                         Offer  : 'R '
506                     },
507                     rowId: row.id,
508                     pgId: row.priceGuide ? row.priceGuide.id : false,
509                     offers:  row.priceGuide && row.priceGuide.offers
510                         ? row.priceGuide.offers[0]
511                         : null,
512                     bind: function(meta) {
513                         $('#row' +  meta.rowId).click(function(e){
514                             window.location='#/' + meta.surl + '?id=' + meta.rowId;
515                         });
516
517                         $('#ofr' + meta.rowId).click(function(e) {
518                             _w.PopUp = true;
519                             e.preventDefault();
520                             e.stopPropagation();
521                             if (!meta.pgId)
522                             {
523                                 var modalbody = '<div style="font-weight:bold;color:#9B2022;">There are no offers!</div>';
524                                 $('#modalbody').html(modalbody);
525                                 return;
526                             }
527                             else
528                             {
529                                 $('#modalbody').html('<center>Loading offers...</center>');
530                                 $('#myModal').modal('toggle');
531                             }
532                             App.API.getTask(
533                                 'offerList', 'PriceGuide', 'Offer.List',
534                                 meta.pgId, {}, function(){
535                                     App.API.execTask(
536                                         'offerList', {}, {},
537                                         function(response)
538                                         {
539                                             var offers = response.Data;
540                                             if (offers.length)
541                                             {
542                                                 var modalbody = '<table class="table table-bordered table-condensed table-striped">';
543                                                 modalbody += '<tr><td>Company</td><td>Date Offered</td><td>Amount</td></tr>';
544                                                 for (var x in offers)
545                                                 {
546                                                     var isOwn = offers[x].company.id == App.companyData.id
547                                                         ? true
548                                                         : false;
549                                                     modalbody +=
550                                                         '<tr class="modalrow ' + (isOwn ? 'red' : 'black') + '">'
551                                                         + '<td class="date">' + offers[x].company.name + '</td>'
552                                                         + '<td class="date">' + offers[x].created + '</td>'
553                                                         + '<td class="wide">' + offers[x].amount + '</td>'
554                                                         + '</tr>';
555                                                 }
556                                                 modalbody += '</table>';
557                                             }
558                                             else
559                                             {
560                                                 var modalbody = '<div style="font-weight:bold;color:#9B2022;">There are no offers!</div>';
561                                             }
562                                             $('#modalbody').html(modalbody);
563                                         }, _w.taskExecError
564                                     );
565                                 }, _w.taskContractError
566                             );
567                         });
568                     },
569                     style: {
570                         VIN             : 'hidden-phone',
571                         Make    : 'make',
572                         Model   : 'hidden-phone',
573                         Type    : 'type',
574                         Year    : 'year',
575                         KM              : 'hidden-phone',
576                         Trade   : 'hidden-phone',
577                         Retail  : 'hidden-phone',
578                         Offer   : 'hidden-phone offer',
579                         Bid             : 'hidden-phone',
580                         Status  : 'status'
581
582                     },
583                     items: {
584                         'id'     : row.id,
585                         'VIN'    : row.vinNumber,
586                         'Make'   : row.type.model.make.name,
587                         'Model'  : row.type.model.name,
588                         'Type'   : row.type.name,
589                         'Year'   : row.vehicleYear.name,
590                         'KM'     : row.km,
591                         'Trade'  : row.tradePrice,
592                         'Retail' : row.retailPrice,
593                         'Offer'  : row.highestOffer + '&nbsp;&nbsp;&nbsp;<span id="ofr' + row.id + '">' + row.numberOfOffers + '</span>',
594                         'Bid'    : row.highestBid,
595                         'Status' : ('Stock' == row.jobState || 'Trade Center' == row.jobState) && row.auction && (row.auction.jobState == 'Undone' || row.auction.jobState == 'Relist') ? 'Relist' : row.jobState
596                         //'Status' : row.auction.jobState == 'Undone' || row.auction.jobState == 'Relist' ? 'Relist' : row.jobState // Made this the same as portal-workspace/tcstock.js
597                     }
598                 });
599             }
600             _w.stock.ti.hydrateParam('gridRowRepeater', {
601                 constructor : 'GridDataRow',
602                 items       : gridData
603             });
604             response.Data.Meta.itemName = 'stockPager';
605             response.Data.Meta.bind = _w.stock.pageStockGrid;
606             _w.stock.ti.hydrateParam('gridPager', {
607                 constructor : 'GridPager',
608                 items       : [response.Data.Meta]
609             });
610         },
611
612         exportStockGrid : function()
613         {
614             App.API.execTask(
615                 'gridStock', {}, {'ExportToExcel': true},
616                 _w.stock._onExportReceived, _w.taskExecError,
617                 'EXPORT', true
618             );
619         },
620         bulkImporterStockGrid  : function()
621         {
622             window.location.hash = '/stockbulkimporter';
623         },
624         auctionReportStockGrid : function()
625         {
626             window.location.hash = '/stockauctionreport';
627         },
628
629         newStock : function()
630         {
631             window.location.hash = '/stockview?id=0';
632         },
633
634         _onExportReceived : function( response )
635         {
636             var win = window.open();
637             win.document.write(response);
638         },
639
640         clearStockGridContext : function()
641         {
642             _w.stock.gridStatus = 'Inactive';
643             try
644             {
645                 $('select.gridStockFilter').each(function(i, elem) {
646                     $(elem).selectpicker('val', '');
647                     $(elem).selectpicker('refresh');
648                 });
649             }
650             catch (err) { console.log(err); }
651             $('.gridStockContext').val('');
652             $('.gridStockFilter').val('');
653             _w.stock.searchStockGrid(true);
654         },
655
656         searchStockGrid : function(resetOrder)
657         {
658             _w.stock.gridStatus = 'Inactive';
659             var filter = {
660                 count: 0,
661                 filters: {}
662             };
663             filter = _w.filterIfnotEmpty(filter, 'gridStockContext_RegNo', 'stock.registrationNumber');
664             filter = _w.filterIfnotEmpty(filter, 'gridStockContext_RefNo', 'stock.referenceNumber');
665             filter = _w.filterIfnotEmpty(filter, 'gridStockContext_DateFrom', 'stock.created', '>=');
666             filter = _w.filterIfnotEmpty(filter, 'gridStockContext_DateTo', 'stock.created', '<=', ' 23:59:59');
667
668             filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_VIN', 'stock.vinNumber');
669             filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Make', 'make.id');
670             filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Model', 'model.name');
671             filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Type', 'type.name');
672             filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Year', 'vehicleYear.name');
673             filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_KM', 'stock.km');
674             filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Trade', 'stock.tradePrice');
675             filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Retail', 'stock.retailPrice');
676             filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Offer', 'stock.highestOffer');
677             var status = $('#gridStockFilter_Status').val();
678             if ('Undone' == status || 'Relist' == status)
679             {
680                 $('#gridValuationContext_notArchived').val('Relist,Undone');
681                 filter = _w.filterIfnotEmpty(filter, 'gridStockContext_RelistFilter', 'auction.jobState', 'IN');
682             }
683             else
684             {
685                 filter = _w.filterIfnotEmpty(filter, 'gridStockFilter_Status', 'stock.jobState');
686             }
687             var request = {"Grid":{
688                 "Page": 1,
689                 "Filter": filter.filters
690             }};
691             if (resetOrder)
692             {
693                 request.Grid.OrderBy = {'stock.created': 'DESC'};
694             }
695             _w.stock.loadStockGrid( null, request, {} );
696         },
697
698         orderStockGrid : function(field, direction)
699         {
700             var order = {};
701             order[field] = direction;
702             _w.stock.loadStockGrid( {}, {"Grid":{"Page": 1, "OrderBy": order}} );
703         }
704
705     };
706
707 })();