3 window._w.valuationview = {
12 highestOfferId : false,
15 onValuationViewTemplateReady : function( template, event, eventData )
17 _w.valuationview.itemData = null;
18 _w.valuationview.ti = _t[template];
19 _w.valuationview.limited = ('limitedvaluationview' == template)
23 App.DataStore.setData('departments', [{"value":"New", "label":"New"}, {"value":"Used", "label":"Used"}]);
24 App.DataStore.setData('sparekeys', [{"value":"1", "label":"Yes"}, {"value":"0", "label":"No"}]);
25 App.DataStore.loadSelectListData('years', true, 'Stock', 'Year.SelectList');
26 App.DataStore.loadSelectListData('categories', true, 'Stock', 'Category.SelectList');
27 App.DataStore.loadSelectListData('conditions', true, 'Stock', 'Condition.SelectList');
28 App.DataStore.loadSelectListData('exteriorColours', true, 'Stock', 'ExteriorColour.SelectList');
29 App.DataStore.loadSelectListData('interiorColours', true, 'Stock', 'InteriorColour.SelectList');
30 App.DataStore.loadSelectListData('upholsteries', true, 'Stock', 'Upholstery.SelectList');
31 App.DataStore.loadSelectListData('papers', true, 'Stock', 'Paper.SelectList');
32 App.DataStore.loadSelectListData('natis', true, 'Stock', 'Natis.SelectList');
33 App.DataStore.loadSelectListData('fsh', true, 'Stock', 'FullServiceHistory.SelectList');
34 App.DataStore.loadSelectListData('fuelTypes', true, 'Stock', 'FuelType.SelectList');
35 App.DataStore.loadSelectListData('transmissionTypes', true, 'Stock', 'TransmissionType.SelectList');
36 App.DataStore.loadSelectListData('damages', true, 'Stock', 'Damage.SelectList');
37 App.DataStore.loadSelectListData('accessories', true, 'Stock', 'Accessory.SelectList');
38 App.DataStore.loadSelectListData('clubs', true, 'PriceGuide', 'Club.SelectList');
39 App.DataStore.loadSelectListData('valuators', true, 'User', 'Profile.ValuatorList');
40 App.DataStore.loadSelectListData('sales', true, 'User', 'Profile.SalesList');
44 _w.valuationview.setValuationViewFormMeta();
45 _w.valuationview.ti.hydrate(_w.valuationview.formMeta);
46 // Retrieve initial view data.
47 _w.valuationview.itemId = App.Util.getUrlParam('id');
48 if (0 == _w.valuationview.itemId || null == _w.valuationview.itemId)
50 _w.valuationview.newItem = true;
51 _w.valuationview.itemData = {stock:{}};
53 'createValuationNew', 'Valuation', 'Valuation.CreateNew',
54 null, {}, function(){}, _w.taskContractError
57 'createValuationPending', 'Valuation', 'Valuation.CreatePending',
58 null, {}, function(){}, _w.taskContractError
61 'createValuationComplete', 'Valuation', 'Valuation.CreateComplete',
62 null, {}, function(){}, _w.taskContractError
65 'createValuationPriceGuide', 'Valuation', 'Valuation.CreatePriceGuide',
66 null, {}, function(){}, _w.taskContractError
69 'createValuationStock', 'Valuation', 'Valuation.CreateStock',
70 null, {}, function(){}, _w.taskContractError
76 _w.valuationview.newItem = false;
77 var task = _w.valuationview.limited
78 ? 'Valuation.LimitedUpdate'
81 'updateValuation:' + _w.valuationview.itemId, 'Valuation', task, _w.valuationview.itemId,
82 {}, $.proxy( _w.valuationview._onValuationViewDataReceived, this ), _w.taskContractError
88 onValuationViewPublished : function( template, event, eventData )
90 _w.valuationview.limited = ('limitedvaluationview' == template)
94 if (_w.valuationview.newItem)
96 _w.valuationview._setupValidation();
97 $('#btnSaveAsSales').show();
98 $('#btnSaveAsPending').show();
99 $('#optSendToSales').show();
100 $('#optSendToPg').show();
101 $('#btnSendToStock').show();
102 $('#btnUpdate').prop('disabled', false);
103 $('#printValuationPdf').hide();
109 true == App.permissions.valuationCreateSales ? $('#sectionSelectValuator').show() : $('#sectionSelectValuator').hide();
110 true == App.permissions.valuationCreatePriceguide ? $('#optSendToPg').show() : $('#optSendToPg').hide();
111 true == App.permissions.valuationCreateComplete ? $('#optSendToSales').show() : $('#optSendToSales').hide();
112 true == App.permissions.valuationCreateNew ? $('#btnUpdate').show() : $('#btnUpdate').hide();
113 true == App.permissions.valuationCreateStock ? $('#btnSendToStock').show() : $('#btnSendToStock').hide();
114 true == App.permissions.valuationCreatePending ? $('#btnSaveAsPending').show() : $('#btnSaveAsPending').hide();
116 true == App.permissions.valuationPricingDetails ? $('#' + _w.valuationview.ti.tid + '_overAllowance').show() : $('#' + _w.valuationview.ti.tid + '_overAllowance').hide();
117 true == App.permissions.valuationPricingDetails ? $('#' + _w.valuationview.ti.tid + '_standInValue').show() : $('#' + _w.valuationview.ti.tid + '_standInValue').hide();
118 true == App.permissions.valuationPricingDetails ? $('#' + _w.valuationview.ti.tid + '_projectedRetail').show() : $('#' + _w.valuationview.ti.tid + '_projectedRetail').hide();
119 true == App.permissions.valuationPricingDetails ? $('#' + _w.valuationview.ti.tid + '_plannedMargin').show() : $('#' + _w.valuationview.ti.tid + '_plannedMargin').hide();
121 if (!App.permissions.valuationUpdateDamages)
123 $('.damages-form').hide();
125 if (!App.permissions.valuationUploadPhotos)
127 $('.photos-form').hide();
130 $('#btnUpdate').prop('disabled', true);
131 $('#btnFetchTu').click(function () {
132 if (!$('#vehicleYear').val()
133 || !$('#vehicleType').val())
135 alert('Vehicle year and type is required to fetch Trade and Retail pricing.');
138 $('#btnFetchTu').prop('disabled', true);
140 'TransUnionFromMmCode', 'Stock', 'Utility.TransUnionFromMmCode', null,
141 {}, _w.valuationview._onTuReady, _w.taskContractError
144 $('#doAcceptOffer').click(function () {
145 if (!$('#frmValuationView').valid())
150 highestOfferId : false,
151 priceGuideId : false, */
152 $('#btnUpdate').prop('disabled', true);
153 $('#btnSendToDealDone').prop('disabled', true);
154 $('#btnSendToDealNotDone').prop('disabled', true);
155 var data = _w.valuationview._prepValuationUpdateData();
157 'updateValuation:' + _w.valuationview.itemId, data, {},
160 'offerAcceptedOnValuation:' + _w.valuationview.priceGuideId, 'PriceGuide', 'Offer.AcceptOffer', _w.valuationview.priceGuideId,
161 {id: _w.valuationview.highestOfferId}, function() {
163 'offerAcceptedOnValuation:' + _w.valuationview.priceGuideId, {}, {},
164 _w.valuationview._onValuationUpdated, _w.taskExecError
166 }, _w.taskContractError
172 $('#btnSendToDealNotDone').click(function () {
173 if (!$('#frmValuationView').valid())
177 $('#btnUpdate').prop('disabled', true);
178 $('#btnSendToDealDone').prop('disabled', true);
179 $('#btnSendToDealNotDone').prop('disabled', true);
180 var data = _w.valuationview._prepValuationUpdateData();
182 'updateValuation:' + _w.valuationview.itemId, data, {},
185 'dealnotdoneonValuation:' + _w.valuationview.itemId,
186 'Valuation', 'Valuation.MoveToDealNotDone', _w.valuationview.itemId, {},
187 _w.valuationview._onValuationUpdated, _w.taskExecError
193 $('#btnArchive').click(function () {
195 'archiveValuation:' + _w.valuationview.itemId,
196 'Valuation', 'Valuation.MoveToArchive', _w.valuationview.itemId, {},
197 _w.valuationview._onValuationUpdated, _w.taskExecError
200 $('#btnUnarchive').click(function () {
202 'unarchiveValuation:' + _w.valuationview.itemId,
203 'Valuation', 'Valuation.UnArchive', _w.valuationview.itemId, {},
204 _w.valuationview._onValuationUpdated, _w.taskExecError
207 $('#btnSaveAsPending').click(function () {
208 if (!$('#frmValuationView').valid())
212 $('#btnUpdate').prop('disabled', true);
213 $('#btnSendToSales').prop('disabled', true);
214 $('#btnSaveAsPending').prop('disabled', true);
215 $('#doSendToStock').prop('disabled', true);
216 $('#btnSendToPg').prop('disabled', true);
217 if (_w.valuationview.newItem)
219 var data = _w.valuationview._prepValuationUpdateData();
221 'createValuationPending', data, {},
222 _w.valuationview._onValuationUpdated, _w.taskExecError
227 _w.valuationview._routeToPending();
230 $('#btnSaveAsSales').click(function () {
231 var valuators = $('#valuators').val();
232 if (null == valuators)
234 alert('Please select at least one valuator.');
237 if (!$('#frmValuationView').valid())
241 $('#btnUpdate').prop('disabled', true);
242 $('#btnSendToSales').prop('disabled', true);
243 $('#btnSaveAsPending').prop('disabled', true);
244 $('#doSendToStock').prop('disabled', true);
245 $('#btnSendToPg').prop('disabled', true);
246 if (_w.valuationview.newItem)
248 var data = _w.valuationview._prepValuationUpdateData();
249 var valuators = $('#valuators').val();
250 data.Valuation.valuators = [];
251 for (var i = 0; i < valuators.length; i++)
253 data.Valuation.valuators.push({id: valuators[i]});
256 'createValuationNew', data, {},
257 _w.valuationview._onValuationUpdated, _w.taskExecError
262 var data = _w.valuationview._prepValuationUpdateData();
263 var valuators = $('#valuators').val();
264 data.Valuation.valuators = [];
265 for (var i = 0; i < valuators.length; i++)
267 data.Valuation.valuators.push({id: valuators[i]});
270 'updateValuation:' + _w.valuationview.itemId, data, {},
271 _w.valuationview._onValuationUpdated, _w.taskExecError
275 $('#btnSendToSales').click(function () {
276 var profile = $('#salesProfile').val();
277 var amount = $('#salesAmountOffered').val();
278 if (null == profile || '' == amount)
280 alert('Please select Sales person and enter an Amount.');
283 if (!$('#frmValuationView').valid())
287 $('#btnUpdate').prop('disabled', true);
288 $('#btnSendToSales').prop('disabled', true);
289 $('#btnSaveAsPending').prop('disabled', true);
290 $('#doSendToStock').prop('disabled', true);
291 $('#btnSendToPg').prop('disabled', true);
292 if (_w.valuationview.newItem)
294 var data = _w.valuationview._prepValuationUpdateData();
295 data.Valuation.amountOffered = amount;
297 'createValuationComplete', data, {},
298 _w.valuationview._onValuationUpdated, _w.taskExecError
303 if ('Price Guide' == _w.valuationview.itemData.jobState)
306 'sendToSalesFull:' + _w.valuationview.itemId, 'Valuation', 'Valuation.SendToSalesFull', _w.valuationview.itemId,
308 var data = _w.valuationview._prepValuationUpdateData();
309 data.Valuation.amountOffered = $('#salesAmountOffered').val();
311 'sendToSalesFull:' + _w.valuationview.itemId, data, {},
312 _w.valuationview._onValuationUpdated, _w.taskExecError
314 }, _w.taskContractError
319 _w.valuationview._routeToComplete();
323 $('#doSendToStock').click(function () {
324 var stockNo = $('#stockNumber').val();
325 if (null == stockNo || '' == stockNo)
327 alert('Please enter a stock number.');
330 if (!$('#frmValuationView').valid())
334 $('#btnUpdate').prop('disabled', true);
335 $('#btnSendToSales').prop('disabled', true);
336 $('#btnSaveAsPending').prop('disabled', true);
337 $('#doSendToStock').prop('disabled', true);
338 $('#btnSendToPg').prop('disabled', true);
339 if (_w.valuationview.newItem)
341 var data = _w.valuationview._prepValuationUpdateData();
343 'createValuationStock', data, {},
344 _w.valuationview._onValuationUpdated, _w.taskExecError
349 _w.valuationview._routeToStock();
352 $('#btnSendToPg').click(function () {
353 var clubs = $('#clubs').val();
356 alert('Please select at least one club.');
359 if (!$('#frmValuationView').valid())
363 $('#btnUpdate').prop('disabled', true);
364 $('#btnSendToSales').prop('disabled', true);
365 $('#btnSaveAsPending').prop('disabled', true);
366 $('#doSendToStock').prop('disabled', true);
367 $('#btnSendToPg').prop('disabled', true);
368 if (_w.valuationview.newItem)
370 var data = _w.valuationview._prepValuationUpdateData();
371 data.Context = {clubs:[]};
372 var clubList = $('#clubs').val();
373 for (var i = 0; i < clubList.length; i++)
375 data.Context.clubs.push({id: clubList[i]});
378 'createValuationPriceGuide', data, {},
379 _w.valuationview._onValuationUpdated, _w.taskExecError
384 _w.valuationview._routeToPg();
388 $('.back-btn').on('click', function(){
389 window.history.back();
392 if (!_w.valuationview.newItem && null != _w.valuationview.itemData)
394 _w.valuationview._onDataAndTemplate();
398 _routeToPg : function()
401 'sendToPg:' + _w.valuationview.itemId, 'Valuation', 'Valuation.SendToPriceGuide', _w.valuationview.itemId,
403 var data = _w.valuationview._prepValuationUpdateData();
404 data.Context = {clubs:[]};
405 var clubList = $('#clubs').val();
406 for (var i = 0; i < clubList.length; i++)
408 data.Context.clubs.push({id: clubList[i]});
411 'sendToPg:' + _w.valuationview.itemId, data, {},
412 _w.valuationview._onValuationUpdated, _w.taskExecError
414 }, _w.taskContractError
418 _routeToPending : function()
421 'sendToPending:' + _w.valuationview.itemId, 'Valuation', 'Valuation.MoveToPending', _w.valuationview.itemId,
423 var data = _w.valuationview._prepValuationUpdateData();
425 'sendToPending:' + _w.valuationview.itemId, data, {},
426 _w.valuationview._onValuationUpdated, _w.taskExecError
428 }, _w.taskContractError
432 _routeToComplete : function()
435 'sendToComplete:' + _w.valuationview.itemId, 'Valuation', 'Valuation.MoveToComplete', _w.valuationview.itemId,
437 var data = _w.valuationview._prepValuationUpdateData();
438 data.Valuation.amountOffered = $('#salesAmountOffered').val();
440 'sendToComplete:' + _w.valuationview.itemId, data, {},
441 _w.valuationview._onValuationUpdated, _w.taskExecError
443 }, _w.taskContractError
447 _routeToStock : function()
450 'sendToStock:' + _w.valuationview.itemId, 'Valuation', 'Valuation.SendToStock', _w.valuationview.itemId,
452 var data = _w.valuationview._prepValuationUpdateData();
454 'sendToStock:' + _w.valuationview.itemId, data, {},
455 _w.valuationview._onValuationUpdated, _w.taskExecError
457 }, _w.taskContractError
464 setValuationViewFormMeta : function( data )
469 if (undefined != data && undefined != data.stock)
471 for (var i = 0; i < data.stock.damages.length; i++)
473 damages['d' + data.stock.damages[i].damage] = data.stock.damages[i].amount;
481 _w.valuationview.formMeta = {
486 dataStoreId : 'years',
487 value : data.stock.vehicleYear ? data.stock.vehicleYear : '',
488 onChange : function () {
489 if (!App.DataStore.getItem('BuildSelect:vehicleYear', false))
491 _w.valuationview._listMakesModelsTypes(false, function () {
492 if ($('#vehicleYear').val() && $('#vehicleType').val())
495 'TransUnionFromMmCode', 'Stock', 'Utility.TransUnionFromMmCode', null,
496 {}, _w.valuationview._onTuReady, _w.taskContractError
505 id : 'vehicleCategory',
507 dataStoreId : 'categories',
508 value : data.stock.type ? data.stock.type.category.id : '',
509 onChange : function () {
512 if ($(this).val() == 8 && _w.valuationview.itemId == 0) {
513 // show the hidden input fields
514 $("#manualVehicle").show();
515 $("#selectionVehicle").hide();
516 $('#mmCode').html("Other");
518 if ($(this).val() != 8 && _w.valuationview.itemId != 0) {
519 // show the hidden input fields
520 $("#manualVehicle").hide();
521 $("#selectionVehicle").show();
522 $('#mmCode').html("");
525 if (!App.DataStore.getItem('BuildSelect:vehicleCategory', false) && $(this).val() != 8)
527 _w.valuationview._listMakesModelsTypes();
534 title : 'Vehicle Make',
535 dataStoreId : 'makes',
536 value : data.stock.type ? data.stock.type.model.make.id : '',
537 onChange : function () {
538 if (!App.DataStore.getItem('BuildSelect:vehicleMake', false))
540 _w.valuationview._listMakesModelsTypes();
547 title : 'Vehicle Model',
548 dataStoreId : 'models',
549 value : data.stock.type ? data.stock.type.model.id : '',
550 onChange : function () {
551 if (!App.DataStore.getItem('BuildSelect:vehicleModel', false))
553 _w.valuationview._listMakesModelsTypes();
560 title : 'Vehicle Type',
561 dataStoreId : 'types',
562 value : data.stock.type ? data.stock.type.id : '',
563 onChange : function () {
564 if ('' != $(this).val() && null != $(this).val())
567 'GetMmCode' + $(this).val(), 'Stock', 'Type.GetMmCode', null,
568 {id:$(this).val()}, function(response){
569 $('#mmCode').html(response.Data.mmCode);
570 }, _w.taskContractError
575 $('#mmCode').html('');
577 if (!App.DataStore.getItem('BuildSelect:vehicleType', false)
578 && $('#vehicleYear').val()
579 && $('#vehicleType').val())
581 $('#btnFetchTu').prop('disabled', true);
583 'TransUnionFromMmCode', 'Stock', 'Utility.TransUnionFromMmCode', null,
584 {}, _w.valuationview._onTuReady, _w.taskContractError
593 id : 'vehicleMakeManual',
594 title : 'Vehicle Make',
595 //dataStoreId : 'makes',
596 value : data.stock.type ? data.stock.type.model.make.id : '',
601 id : 'vehicleModelManual',
602 title : 'Vehicle Model',
603 //dataStoreId : 'models',
604 value : data.stock.type ? data.stock.type.model.id : '',
609 id : 'vehicleTypeManual',
610 title : 'Vehicle Type',
611 //dataStoreId : 'types',
612 value : data.stock.type ? data.stock.type.id : '',
623 setAttrib : 'readonly',
624 value : data.stock.type ? data.stock.type.mmCode : ''
628 id : 'vehicleFuelType',
630 dataStoreId : 'fuelTypes',
631 value : data.stock.fuelType ? data.stock.fuelType : ''
633 'transmissionType' : {
635 id : 'vehicleTransmissionType',
636 title : 'Transmission Type',
637 dataStoreId : 'transmissionTypes',
638 value : data.stock.transmissionType ? data.stock.transmissionType : ''
640 'registrationNumber' : {
642 id : 'registrationNumber',
643 title : 'Registration no',
644 value : data.stock.registrationNumber ? data.stock.registrationNumber : ''
650 value : data.stock.vinNumber ? data.stock.vinNumber : ''
656 value : data.stock.engineNumber ? data.stock.engineNumber : ''
662 value : data.stock.km ? data.stock.km : ''
666 id : 'vehicleCondition',
668 dataStoreId : 'conditions',
669 value : data.stock.condition ? data.stock.condition : ''
673 id : 'exteriorColour',
674 title : 'Main ext. colour',
675 dataStoreId : 'exteriorColours',
676 value : data.stock.exteriorColour ? data.stock.exteriorColour : ''
680 id : 'interiorColour',
681 title : 'Main int. colour',
682 dataStoreId : 'interiorColours',
683 value : data.stock.interiorColour ? data.stock.interiorColour : ''
687 id : 'vehicleUpholstery',
688 title : 'Upholstery',
689 dataStoreId : 'upholsteries',
690 value : data.stock.upholstery ? data.stock.upholstery : ''
694 id : 'vehiclePapers',
696 dataStoreId : 'papers',
697 value : data.stock.papers ? data.stock.papers : ''
703 dataStoreId : 'natis',
704 value : data.stock.natis ? data.stock.natis : ''
709 title : 'Spare keys',
710 dataStoreId : 'sparekeys',
711 value : undefined != data.stock.spareKeys && null != data.stock.spareKeys
712 ? (data.stock.spareKeys == true ? "1" : "0")
715 'fullServiceHistory' : {
717 id : 'fullServiceHistory',
718 title : 'Full service history',
720 value : data.stock.fullServiceHistory ? data.stock.fullServiceHistory : ''
723 type : 'textarea-small',
726 value : data.stock.fshNotes ? data.stock.fshNotes : ''
729 type : 'damageDetails',
730 disabled : !App.permissions.valuationUpdateDamages,
732 dataStoreId : 'damages',
733 data : data.stock.damages ? data.stock.damages : {}
735 'damageTotal' : 'R 0.00',
737 type : 'textarea-styled',
738 disabled : !App.permissions.valuationUpdateDamages,
740 title : 'Damages comments',
741 style : 'damages-comments',
742 value : data.stock.damageNotes ? data.stock.damageNotes : ''
745 'previousRepairsNoted' : {
747 id : 'previousRepairsNoted',
748 title : 'Previous repairs',
749 style : 'damages-comments',
750 value : data.stock.previousRepairsNoted ? data.stock.previousRepairsNoted : false
752 'previousRepairsNotes' : {
753 type : 'textarea-styled',
754 disabled : !App.permissions.valuationUpdateDamages,
755 id : 'previousRepairsNotes',
756 title : 'Previous repairs notes',
757 style : 'damages-comments',
758 value : data.stock.previousRepairsNotes ? data.stock.previousRepairsNotes : '',
759 onChange: function(){
760 var haveData = ('' != $(this).val() ? true : false);
761 $('#previousRepairsNoted').prop('checked', haveData);
767 dataStoreId : 'accessories',
768 itemName : 'accessory',
769 data : data.stock.accessories ? data.stock.accessories : {}
772 type : 'textarea-styled',
773 id : 'accessoryNotes',
775 style : 'comment mobile-comment',
776 areaStyle : 'comment-text-box',
777 value : data.stock.accessoryNotes ? data.stock.accessoryNotes : ''
782 baseImage : 'main_img_car.jpg',
783 view : !App.permissions.valuationUploadPhotos,
784 value : data.stock.mainImage ? data.stock.mainImage : ''
789 baseImage : 'front_car.jpg',
790 view : !App.permissions.valuationUploadPhotos,
791 value : data.stock.frontImage ? data.stock.frontImage : ''
796 baseImage : 'left_car.jpg',
797 view : !App.permissions.valuationUploadPhotos,
798 value : data.stock.leftImage ? data.stock.leftImage : ''
803 baseImage : 'right_car.jpg',
804 view : !App.permissions.valuationUploadPhotos,
805 value : data.stock.rightImage ? data.stock.rightImage : ''
810 baseImage : 'back_car.jpg',
811 view : !App.permissions.valuationUploadPhotos,
812 value : data.stock.backImage ? data.stock.backImage : ''
816 id : 'interiorImage',
817 baseImage : 'interior_car.jpg',
818 view : !App.permissions.valuationUploadPhotos,
819 value : data.stock.interiorImage ? data.stock.interiorImage : ''
824 baseImage : 'engine_car.jpg',
825 view : !App.permissions.valuationUploadPhotos,
826 value : data.stock.engineImage ? data.stock.engineImage : ''
831 baseImage : 'copy_of_natis_car.jpg',
832 view : !App.permissions.valuationUploadPhotos,
833 value : data.stock.natisImage ? data.stock.natisImage : ''
838 title : 'Select clubs',
839 dataStoreId : 'clubs',
844 constructor: 'Button',
845 items: ('New Valuation' == data.jobState
846 && 'Dealership Valuator' != App.permissions.name
847 && 'Dealership Sales' != App.permissions.name)
851 id: 'printValuationPdf',
852 handler: _w.valuationview.printValuationPdf
856 id: 'printValuationPdfTC',
857 handler: _w.valuationview.printValuationPdfTC
863 id: 'printValuationPdf',
864 handler: _w.valuationview.printValuationPdf
869 'infCreated': data.created ? ((data.created).split(' '))[0] : '',
870 'infValuationNumber': data.valuationNumber ? data.valuationNumber : '',
871 'infReferenceNumber': data.stock.referenceNumber ? data.stock.referenceNumber : '',
872 'infStatus': data.jobState ? data.jobState : '',
873 'infCreatedBy': data.createdBy && data.createdBy.firstName
874 ? data.createdBy.firstName + ' ' + data.createdBy.familyName
876 'infValuator': data.valuatedBy && data.valuatedBy.firstName
877 ? data.valuatedBy.firstName + ' ' + data.valuatedBy.familyName
879 'infSalesUser': data.salesProfile && data.salesProfile.firstName
880 ? data.salesProfile.firstName + ' ' + data.salesProfile.familyName
882 'infLoadedOnPriceGuide': data.stock.loadedOnPriceGuide
883 ? ((data.stock.loadedOnPriceGuide).split(' '))[0] : '',
884 'infTradePrice': data.stock.tradePrice ? 'R ' + data.stock.tradePrice : '0.00',
885 'infRetailPrice': data.stock.retailPrice ? 'R ' + data.stock.retailPrice : '0.00',
889 title : 'Customer name',
890 value : data.firstName ? data.firstName : ''
895 title : 'Customer surname',
896 value : data.familyName ? data.familyName : ''
902 value : data.idNumber ? data.idNumber : ''
908 value : data.mobile ? data.mobile : ''
914 value : data.email ? data.email : ''
919 title : 'Department',
920 dataStoreId : 'departments',
921 value : data.department ? data.department : ''
927 style : 'rand-input',
928 id : 'amountOffered',
929 title : 'Amount offered',
930 value : data.amountOffered ? data.amountOffered : '0.00'
934 style : 'rand-input',
935 id : 'overAllowance',
937 value : data.overAllowance ? data.overAllowance : '0.00'
941 style : 'rand-input',
943 title : 'Stand-in-value',
944 value : data.standInValue ? data.standInValue : '0.00'
946 'projectedRetail' : {
948 style : 'rand-input',
949 id : 'projectedRetail',
950 title : 'Projected retail',
951 value : data.projectedRetail ? data.projectedRetail : '0.00'
955 style : 'rand-input',
956 id : 'plannedMargin',
957 title : 'Planned margin',
958 value : data.plannedMargin ? data.plannedMargin : '0.00'
963 title : 'Select valuator',
964 dataStoreId : 'valuators',
966 value : data.valuators ? data.valuators : []
971 title : 'Sales person',
972 dataStoreId : 'sales',
975 'salesAmountOffered' : {
977 style : 'rand-inputs',
978 id : 'salesAmountOffered',
980 value : data.amountOffered ? data.amountOffered : '0.00',
983 var $_this = $(this),
984 value = $_this.val();
986 if( value == '0.00' )
993 var $_this = $(this),
994 value = $_this.val();
1003 type : 'textarea-styled',
1004 id : 'salesComments',
1007 areaStyle : 'comment-text-box',
1008 value : data.salesComments ? data.salesComments : ''
1013 title : 'Stock number',
1014 value : data.stock.stockNumber ? data.stock.stockNumber : ''
1019 printValuationPdf : function()
1021 var task = 'Pdf.Print003';
1022 if ('New Valuation' == _w.valuationview.itemData.jobState
1023 && ('Dealership Valuator' == App.permissions.name
1024 || 'Dealership Sales' == App.permissions.name))
1027 var task = 'Pdf.Print001';
1029 else if ('Dealership Valuator' == App.permissions.name
1030 || 'Dealership Sales' == App.permissions.name)
1032 var task = 'Pdf.Print002';
1035 'printValuation:' + _w.valuationview.itemData.stock.id,
1036 'Valuation', task, _w.valuationview.itemId,
1039 'printValuation:' + _w.valuationview.itemData.stock.id, {}, {},
1040 _w.valuationview._onExportReceived, _w.taskExecError,
1043 }, _w.taskContractError
1047 printValuationPdfTC : function()
1049 // Consider the T&C requirement.
1050 var task = 'Pdf.Print001';
1052 'printValuation:' + _w.valuationview.itemData.stock.id,
1053 'Valuation', task, _w.valuationview.itemId,
1056 'printValuation:' + _w.valuationview.itemData.stock.id, {}, {},
1057 _w.valuationview._onExportReceived, _w.taskExecError,
1060 }, _w.taskContractError
1064 _listMakesModelsTypes : function( fromItemData, callback )
1068 var year = _w.valuationview.itemData.stock.vehicleYear;
1069 var category = _w.valuationview.itemData.stock.type.category.id;
1070 var make = _w.valuationview.itemData.stock.type.model.make.id;
1071 var model = _w.valuationview.itemData.stock.type.model.id;
1072 var type = _w.valuationview.itemData.stock.type.id;
1073 var mmcode = _w.valuationview.itemData.stock.type.mmcode;
1077 var year = $('#vehicleYear').val();
1078 var category = $('#vehicleCategory').val();
1079 var make = $('#vehicleMake').val();
1080 var model = $('#vehicleModel').val();
1081 var type = $('#vehicleType').val();
1082 var mmcode = $('#mmCode').val();
1084 if (year && category)
1086 App.DataStore.loadSelectListData(
1087 'makes', false, 'Stock', 'Utility.ListMakes', null,
1089 "category" : category,
1094 if (make && year && category)
1096 App.DataStore.loadSelectListData(
1097 'models', false, 'Stock', 'Utility.ListModels', null,
1100 "category" : category,
1105 if (model && year && category)
1107 App.DataStore.loadSelectListData(
1108 'types', false, 'Stock', 'Utility.ListTypes', null,
1111 "category" : category,
1118 _onDataAndTemplate : function()
1121 $.each($.find('.damage-input'), function(i, input) {
1122 total += parseFloat($(input).val());
1124 $('#' + _w.valuationview.ti.tid + '_damageTotal').html('R ' + total);
1125 $('#doAcceptOffer').prop('disabled', true);
1126 if (null != _w.valuationview.itemData.stock.priceGuide
1127 && 0 < _w.valuationview.itemData.stock.highestOffer)
1129 _w.valuationview.priceGuideId = _w.valuationview.itemData.stock.priceGuide;
1131 'offerList', 'PriceGuide', 'Offer.List',
1132 _w.valuationview.itemData.stock.priceGuide, {}, function(){
1134 'offerList', {}, {},
1137 var offers = response.Data;
1144 for (var x in offers)
1146 if ('Valid Offer' != offers[x].status)
1151 var dateInt = parseInt(
1152 offers[x].created.split(' ')[0].split('-').join('')
1153 + offers[x].created.split(' ')[1].split(':').join('')
1155 if ( (parseInt(offers[x].amount) == highest && dateInt < lowestDate)
1156 || parseInt(offers[x].amount) > highest)
1158 highest = parseInt(offers[x].amount);
1160 lowestDate = dateInt;
1165 var modalbody = '<div style="font-weight:bold;color:#9B2022;">There are no valid offers!</div>';
1166 $('#dealDoneOfferList').html(modalbody);
1169 _w.valuationview.highestOfferId = highestId;
1170 var modalbody = '<table class="table table-bordered table-condensed table-striped">';
1171 modalbody += '<tr class="table-header-red"><td>Company</td><td>Date Offered</td><td>Amount</td></tr>';
1172 for (var x in offers)
1174 if ('Valid Offer' != offers[x].status)
1178 var isOwn = highestId == x
1182 '<tr class="modalrow ' + (isOwn ? 'red' : 'black') + '">'
1183 + '<td class="date">' + offers[x].company.name + '</td>'
1184 + '<td class="date">' + offers[x].created.split(' ')[0] + '</td>'
1185 + '<td class="wide">R' + offers[x].amount.split('.')[0] + '</td>'
1188 modalbody += '</table>';
1189 $('#doAcceptOffer').prop('disabled', false);
1193 var modalbody = '<div style="font-weight:bold;color:#9B2022;">There are no valid offers!</div>';
1195 $('#dealDoneOfferList').html(modalbody);
1198 }, _w.taskContractError
1202 if (_w.valuationview.limited)
1204 $('input').prop('disabled', true);
1205 $('button').prop('disabled', true);
1206 $('checkbox').prop('disabled', true);
1207 $('textarea').prop('disabled', true);
1208 $('#btnUnarchive').prop('disabled', false);
1209 $('#printValuationPdf').prop('disabled', false);
1210 $('#optSendToSales').prop('disabled', false);
1211 $('#salesProfile').prop('disabled', false);
1212 $('button[data-id="salesProfile"]').prop('disabled', false);
1213 $('#salesAmountOffered').prop('disabled', false);
1214 $('#salesComments').prop('disabled', false);
1215 $('#btnSendToSales').prop('disabled', false);
1216 $('#printValuationPdf').prop('disabled', false);
1219 $('#mobiAuctionBtn').prop('disabled', false);
1220 $('#mobiPriceGuideBtn').prop('disabled', false);
1221 $('#mobiValuationsBtn').prop('disabled', false);
1223 $('#sectionSelectValuator').hide();
1224 if (!_w.valuationview.newItem)
1226 $('#retailPrice').val(_w.valuationview.itemData.stock.retailPrice);
1227 $('#tradePrice').val(_w.valuationview.itemData.stock.tradePrice);
1228 switch (_w.valuationview.itemData.jobState)
1230 case 'New Valuation':
1231 $('#btnSaveAsSales').show();
1232 $('#btnSaveAsPending').show();
1233 $('#optSendToPg').show();
1234 $('#btnSendToStock').show();
1235 $('#btnArchive').show();
1236 true == App.permissions.valuationCreateSales
1237 ? $('#sectionSelectValuator').show()
1238 : $('#sectionSelectValuator').hide();
1239 if (!App.permissions.valuationUpdateDamages)
1241 $('.damages-form').hide();
1243 if (!App.permissions.valuationUploadPhotos)
1245 $('.photos-form').hide();
1248 case 'Pending Valuation':
1249 $('#optSendToSales').show();
1250 $('#optSendToPg').show();
1251 $('#btnSendToStock').show();
1252 $('#btnArchive').show();
1253 if (null != _w.valuationview.itemData.stock.priceGuide
1254 && 0 < _w.valuationview.itemData.stock.highestOffer)
1256 $('#btnSendToDealDone').show();
1257 $('#btnSendToDealNotDone').show();
1259 if (!App.permissions.valuationUpdateDamages)
1261 $('.damages-form').hide();
1263 if (!App.permissions.valuationUploadPhotos)
1265 $('.photos-form').hide();
1268 case 'Complete Valuation':
1269 $('#optSendToSales').show();
1270 $('#optSendToPg').show();
1271 $('#btnSendToStock').show();
1272 $('#btnArchive').show();
1273 if (null != _w.valuationview.itemData.stock.priceGuide
1274 && 0 < _w.valuationview.itemData.stock.highestOffer)
1276 $('#btnSendToDealDone').show();
1277 $('#btnSendToDealNotDone').show();
1280 case 'Offer Accepted':
1281 $('#btnSendToStock').show();
1282 $('#btnSendToStock').prop('disabled', false);
1283 $('#stockNumber').prop('disabled', false);
1284 $('#doSendToStock').prop('disabled', false);
1285 $('#btnArchive').show();
1286 $('#btnArchive').prop('disabled', false);
1289 $('#btnSendToStock').show();
1290 $('#btnSendToStock').prop('disabled', false);
1291 $('#stockNumber').prop('disabled', false);
1292 $('#doSendToStock').prop('disabled', false);
1293 $('#btnArchive').show();
1294 $('#btnArchive').prop('disabled', false);
1296 case 'Deal Not Done':
1297 $('#btnSaveAsPending').show();
1298 $('#optSendToPg').show();
1299 $('#btnSendToStock').show();
1300 $('#btnArchive').show();
1303 $('#btnUnarchive').show();
1306 $('#optSendToSales').show();
1314 $('#optSendToPg').prop('disabled', true == App.permissions.valuationRoutePriceguide ? false : true);
1315 $('#optSendToSales').prop('disabled', true == App.permissions.valuationRouteComplete ? false : true);
1316 $('#btnUpdate').prop('disabled', true == App.permissions.valuationUpdate ? false : true);
1317 $('#btnSendToStock').prop('disabled', true == App.permissions.valuationRouteStock ? false : true);
1318 $('#btnSaveAsPending').prop('disabled', true == App.permissions.valuationRoutePending ? false : true);
1319 $('#btnSendToDealDone').prop('disabled', true == App.permissions.valuationRouteDealDone ? false : true);
1320 $('#btnSendToDealNotDone').prop('disabled', true == App.permissions.valuationRouteDealNotDone ? false : true);
1321 if ('Dealership Sales' == App.permissions.name && !_w.valuationview.newItem)
1323 $('#btnSaveAsPending').hide();
1326 $('#btnArchive').prop('disabled', true == App.permissions.valuationArchive ? false : true);
1327 $('#printValuationPdf').prop('disabled', true == App.permissions.valuationPrint ? false : true);
1328 $('#btnB4cAccidentReport').prop('disabled', true == App.permissions.valuationB4cReport ? false : true);
1329 $('#btnBwmAccidentReport').prop('disabled', true == App.permissions.valuationBmw ? false : true);
1333 true == App.permissions.valuationPricingDetails ? $('#' + _w.valuationview.ti.tid + '_overAllowance').show() : $('#' + _w.valuationview.ti.tid + '_overAllowance').hide();
1334 true == App.permissions.valuationPricingDetails ? $('#' + _w.valuationview.ti.tid + '_standInValue').show() : $('#' + _w.valuationview.ti.tid + '_standInValue').hide();
1335 true == App.permissions.valuationPricingDetails ? $('#' + _w.valuationview.ti.tid + '_projectedRetail').show() : $('#' + _w.valuationview.ti.tid + '_projectedRetail').hide();
1336 true == App.permissions.valuationPricingDetails ? $('#' + _w.valuationview.ti.tid + '_plannedMargin').show() : $('#' + _w.valuationview.ti.tid + '_plannedMargin').hide();
1339 _w.valuationview._setupValidation();
1342 _onValuationViewDataReceived : function( response )
1344 _w.valuationview.itemId = response.Data.id;
1345 _w.valuationview.itemData = response.Data;
1346 _w.valuationview._listMakesModelsTypes(true);
1347 _w.valuationview.setValuationViewFormMeta(response.Data);
1348 _w.valuationview.ti.hydrate(_w.valuationview.formMeta);
1349 if (_w.valuationview.ti.published)
1351 _w.valuationview._onDataAndTemplate();
1355 _setupValidation : function ()
1357 App.DataStore.listen('regValidation', 'damages', function(id, damages) {
1359 firstName: {required: true, minlength: 3},
1360 familyName: {required: true, minlength: 3},
1361 idNumber: {required: false, minlength: 13, maxlength: 13, digits: true},
1362 mobile: {required: true, mobile: true},
1363 salesAmountOffered: {number: true},
1364 overAllowance: {number: true},
1365 standInValue: {number: true},
1366 projectedRetail: {number: true},
1367 plannedMargin: {number: true},
1368 vehicleYear: "required",
1369 vehicleCategory: "required",
1371 vehicleMake: { required: function(){ return $('#vehicleCategory').val() != '8'; } },
1372 vehicleModel: { required: function(){ return $('#vehicleCategory').val() != '8'; } },
1373 vehicleType: { required: function(){ return $('#vehicleCategory').val() != '8'; } },
1375 vehicleMakeManual: { required: function(){ return $('#vehicleCategory').val() == '8' && _w.valuationview.itemId == 0; } },
1376 vehicleModelManual: { required: function(){ return $('#vehicleCategory').val() == '8' && _w.valuationview.itemId == 0; } },
1377 vehicleTypeManual: { required: function(){ return $('#vehicleCategory').val() == '8' && _w.valuationview.itemId == 0; } },
1380 vehicleFuelType: "required",
1381 vehicleTransmissionType: "required",
1382 registrationNumber: "required",
1383 km: { required: true, digits: true }
1385 for (var i = 0; i < damages.length; i++)
1387 rules['damage' + damages[i].value + 'Amount'] = {number: true};
1389 $('#frmValuationView').validate({
1393 minlength: "This field is required."
1396 minlength: "This field is required."
1399 minlength: "Must be 13 digits.",
1400 maxlength: "Must be 13 digits."
1402 vehicleYear : "This field is required.",
1403 vehicleCategory : "This field is required.",
1405 vehicleMake : "This field is required.",
1406 vehicleModel : "This field is required.",
1407 vehicleType : "This field is required.",
1409 vehicleMakeManual : "This field is required.",
1410 vehicleModelManual : "This field is required.",
1411 vehicleTypeManual : "This field is required.",
1414 vehicleFuelType : "This field is required.",
1415 vehicleTransmissionType : "This field is required.",
1416 registrationNumber : "This field is required.",
1417 km : {required: "This field is required."}
1419 invalidHandler: function(event, validator) {
1420 var errors = validator.numberOfInvalids();
1421 if (0 < _w.valuationview.validations && errors) {
1422 var message = errors == 1
1423 ? 'You missed 1 field. It has been highlighted'
1424 : 'You missed ' + errors + ' fields. They have been highlighted';
1427 _w.valuationview.validations++;
1429 submitHandler: function( form ) {
1430 $('#btnUpdate').prop('disabled', true);
1431 var data = _w.valuationview._prepValuationUpdateData();
1433 'updateValuation:' + _w.valuationview.itemId, data, {},
1434 _w.valuationview._onValuationUpdated, _w.taskExecError
1439 _w.valuationview.validations = 0;
1440 $('#frmValuationView').valid();
1442 $('label.error').remove();
1443 $('.valid').removeClass('valid');
1447 _onTuReady : function ()
1450 'TransUnionFromMmCode', {
1452 vehicleYear : parseInt($('#vehicleYear').val()),
1453 type : parseInt($('#vehicleType').val())
1456 _w.valuationview._onTuReceived
1460 _onTuReceived : function ( response )
1462 $('#btnFetchTu').prop('disabled', false);
1463 if ('Success' != response.Data.Status)
1465 alert(response.Data.Status);
1468 var vals = response.Data.VehicleDetails[0].Value;
1469 $('#retailPrice').val(vals.RetailPrice);
1470 $('#tradePrice').val(vals.TradePrice);
1471 $('#MmCode').val(vals.MmCode);
1472 _w.valuationview.ti.hydrateParam('infRetailPrice', 'R ' + vals.RetailPrice);
1473 _w.valuationview.ti.hydrateParam('infTradePrice', 'R ' + vals.TradePrice);
1474 _w.valuationview.ti.hydrateParam('infMmCode', ' ' + vals.MmCode);
1478 _prepValuationUpdateData : function()
1480 var data = _w.valuationview.ti.harvest();
1481 data.km = '' == data.km
1483 : parseInt(data.km);
1484 var retailPrice = $('#retailPrice').val();
1485 var tradePrice = $('#tradePrice').val();
1486 var mmCode = $('#MmCode').val();
1488 data.retailPrice = ('' == retailPrice)
1490 : parseFloat(retailPrice);
1491 data.tradePrice = ('' == tradePrice)
1493 : parseFloat(tradePrice);
1494 delete data.damageTotal;
1496 delete data.amountOffered;
1497 // if ('' == data.overAllowance)
1499 // delete data.overAllowance;
1502 if ('' == data.overAllowance)
1504 delete data.overAllowance;
1508 data.overAllowance = parseFloat(data.overAllowance);
1511 if ('' == data.standInValue)
1513 delete data.standInValue;
1517 data.standInValue = parseFloat(data.standInValue);
1520 if ('' == data.projectedRetail)
1522 delete data.projectedRetail;
1526 data.projectedRetail = parseFloat(data.projectedRetail);
1529 if ('' == data.plannedMargin)
1531 delete data.plannedMargin;
1535 data.plannedMargin = parseFloat(data.plannedMargin);
1538 if ('' == data.mainImage)
1540 delete data.mainImage;
1542 if ('' == data.leftImage)
1544 delete data.leftImage;
1546 if ('' == data.backImage)
1548 delete data.backImage;
1550 if ('' == data.engineImage)
1552 delete data.engineImage;
1554 if ('' == data.frontImage)
1556 delete data.frontImage;
1558 if ('' == data.rightImage)
1560 delete data.rightImage;
1562 if ('' == data.interiorImage)
1564 delete data.interiorImage;
1566 if ('' == data.natisImage)
1568 delete data.natisImage;
1573 var postData = {Stock:{}, Valuation:{}};
1574 var valuationFields = [
1575 "firstName","familyName","idNumber","mobile",
1576 "email","department","amountOffered","overAllowance",
1577 "standInValue","projectedRetail","plannedMargin",
1578 "salesProfile","amountOffered","salesComments"
1580 for (var field in data)
1582 if (-1 == valuationFields.indexOf(field))
1584 postData.Stock[field] = data[field];
1588 postData.Valuation[field] = data[field];
1591 if ('' == postData.Valuation.idNumber)
1593 delete postData.Valuation.idNumber;
1595 if ('' == postData.Valuation.email)
1597 delete postData.Valuation.email;
1603 _onValuationUpdated : function( response )
1605 window.location.hash = '/valuations';