3 window._w.offerview = {
15 onOfferViewTemplateReady : function( template, event, eventData )
17 _w.offerview.ti = _t[template];
18 _w.offerview.limited = ('limitedvaluationview' == template)
22 _w.offerview.setStockViewFormMeta();
23 _w.offerview.setOfferViewFormMeta();
24 _w.offerview.ti.hydrate(_w.offerview.formMeta);
26 _w.offerview.formOfferMeta = {
29 title : 'Amount offered',
33 // Retrieve initial view data.
34 _w.offerview.itemId = App.Util.getUrlParam('pgId');
35 _w.offerview.offerId = App.Util.getUrlParam('id');
38 if (0 == _w.offerview.offerId || null == _w.offerview.offerId)
40 $('#btnUnarchive').hide();
41 $('#btnArchive').hide();
42 _w.offerview.newItem = true;
43 _w.offerview.offerData = {};
47 _w.offerview.newItem = false;
51 var task = 'PriceGuide.View';
53 'viewPg:' + _w.offerview.itemId, 'PriceGuide', task, _w.offerview.itemId,
54 {}, $.proxy( _w.offerview._onStockViewDataReceived, this ), _w.taskContractError
58 loadHistoricalGrid : function( contract, data, options )
61 'gridStockHistory', {Grid:{Filter:{"PricingHistory.stockId":_w.offerview.itemData.stock.id}}}, options,
62 _w.offerview._onHistoryGridDataReceived, _w.taskExecError
66 _onHistoryGridDataReceived : function( response )
68 _w.offerview.gridStatus = 'Active';
69 _w.offerview.ti.hydrateParam('gridPricingHistoryRowRepeater', {});
72 console.log(response.Data.DataSet.length);
74 if (response.Data.DataSet.length == 0 || response.Data.DataSet.length == null) {
75 $('#pricing_history_none_found').show();
76 $('#PHColumnHeaders').hide();
79 for (var i = 0; i < response.Data.DataSet.length; i++)
81 var row = response.Data.DataSet[i];
86 PriceguideOffer : 'R ',
87 AuctionWinningBid : 'R '
95 AuctionWinningBid : '',
101 'TotalRecon' : row.totalRecon,
103 'PriceguideOffer' : row.pricegOffer,
104 'AuctionWinningBid' : row.auctionWinningBid
108 _w.offerview.ti.hydrateParam('gridPricingHistoryRowRepeater', {
109 constructor : 'GridDataRow',
112 response.Data.Meta.bind = _w.offerview.pageStockGrid;
115 onOfferViewPublished : function( template, event, eventData )
118 $('#btnRequestHPI').click(function () {
120 if ('' == $('#HPIusername').val() || '' == $('#HPIpin').val())
122 alert('Please enter a valid username and password.');
126 $('#HPIdropConfirm').slideToggle();
127 $('#HPIresponse').html('');
132 App.Util.updateCheckboxStyle($('#acceptHPIdisclaimer'));
133 $('#HPIbtnConfirm').click(function () {
134 if ( $('#engineNumber').html() == '' || $('#vinNumber').html() == '' ) {
135 alert('Cannot request report without Vehicle Engine Number and VIN Number.');
138 if (!$('#acceptHPIdisclaimer').is(':checked'))
140 alert('Please accept the conditions before sending.');
144 var user = $('#HPIusername').val();
145 var pass = $('#HPIpin').val();
148 'TransUnionForHPI', 'Stock', 'Utility.TransUnionForHPI', null,
149 {'Filter' : {'username' : user ,'pass' : pass , 'stock' : _w.offerview.itemData.stock.id}},
152 'TransUnionForHPI',{}, {},
155 $('#HPIdropConfirm').hide();
156 if ('Success' == data.Status)
158 $('#HPIresponse').html('Success on HPI Report');
159 alert('Success on HPI Report');
160 App.DataStore.loadSelectListData(
161 'tuhpi', false, 'Stock', 'Tuhpi.List', null,{"Filter":
163 "stock" : _w.offerview.itemData.stock.id,
164 "company" : App.companyData.id
167 var tuHpiData = App.DataStore.getData('tuhpi');
168 for (var i = 0; i < tuHpiData.length; i++)
170 var tuHpiId = tuHpiData[i].id
171 var tuHpiCreated = tuHpiData[i].created
174 $('#tuhpiDate').html(tuHpiCreated);
175 $('#downloadTuhpi').show();
176 $('#HPIbtnConfirm').prop('disabled', true);
181 $('#tuhpiDate').html('Not Requested Yet');
182 $('#downloadTuhpi').hide();
183 $('#HPIbtnConfirm').prop('disabled', false);
190 $('#HPIresponse').html('API call to remote host failed. No data could be retrieved from remote service.');
192 }, function(response)
194 $('#HPIbtnConfirm').prop('disabled', false);
196 undefined != response.StatusReason
197 ? response.StatusReason
198 : 'API call to remote host failed. No data could be retrieved from remote service.'
205 , _w.taskContractError
210 $('#downloadTuhpi').click(function () {
212 'printTuhpi:' + _w.offerview.itemData.stock.id, 'Stock', 'Tuhpi.Print', _w.offerview.itemData.stock.id,
215 'printTuhpi:' + _w.offerview.itemData.stock.id, {}, {},
216 function () {}, _w.taskExecError,
219 }, _w.taskContractError
225 $('#btnMakeOffer').click(function () {
226 amount = $('#amountOffered').val();
227 if ('' == amount || isNaN(amount) || parseFloat(amount) <= 0 )
229 alert('Please enter a valid amount.');
233 if(amount.indexOf(".")==-1)
235 amount = amount+'.00'
238 _w.offerview.ti.hydrateParam('infAmountOffered', amount);
239 $('#dropCmp').slideToggle();
240 $('#dropConfirm').slideToggle();
243 $('#btnConfirm').click(function () {
246 "amount": $('#amountOffered').val()
249 if ('' == data.Offer.amount || isNaN(data.Offer.amount))
251 alert('Please enter a valid amount.');
254 var oldOffer = parseFloat( _w.offerview.offerData.amount);
255 var newOffer = parseFloat( data.Offer.amount);
256 console.log('old vs new', '.' + oldOffer + '...' + newOffer + '.');
257 if (!_w.offerview.newItem && (newOffer <= oldOffer))
259 alert('Your updated offer must be higher than your previous offer.');
262 if (_w.offerview.newItem)
265 'createOffer', data, {},
266 _w.offerview._onOfferUpdated, _w.taskExecError
272 'updateOffer:' + _w.offerview.offerId, data, {},
273 _w.offerview._onOfferUpdated, _w.taskExecError
278 $('.mobile-header-bottom .bottom-heading').text('OFFER DETAILS');
280 $('#btnArchive').click(function () {
282 'archivePriceGuide:' + _w.offerview.offerId,
283 'PriceGuide', 'Offer.Archive', _w.offerview.itemId,
284 {"id":_w.offerview.offerId},
287 'archivePriceGuide:' + _w.offerview.offerId, {}, {},
288 _w.offerview._onOfferUpdated, _w.taskExecError
294 $('#btnUnarchive').click(function () {
296 'unarchivePriceGuide:' + _w.offerview.offerId,
297 'PriceGuide', 'Offer.Unarchive', _w.offerview.itemId,
298 {"id":_w.offerview.offerId},
301 'unarchivePriceGuide:' + _w.offerview.offerId, {}, {},
302 _w.offerview._onOfferUpdated, _w.taskExecError
309 $('.back-btn').on('click', function(){
310 window.history.back();
313 //console.log(_w.offerview.newItem);
316 _w.offerview.ti.hydrate({
317 'gridPricingHistoryColumnHeaders': {
318 constructor: 'GridColumnHeader',
321 id: 'gridPricingHistoryColumn_Date',
325 id: 'gridPricingHistoryColumn_Trade',
329 id: 'gridPricingHistoryColumn_totalRecon',
330 title: 'Total Recon',
333 id: 'gridPricingHistoryColumn_km',
337 id: 'gridPricingHistoryColumn_pricegOffer',
338 title: 'Priceguide Offer',
341 id: 'gridPricingHistoryColumn_auctionWinningBid',
342 title: 'Auction Winning Bid',
347 'gridPricingHistoryRowRepeater': {}
358 if (0 == _w.offerview.offerId || null == _w.offerview.offerId)
360 true == App.permissions.pgMakeOffer ? $('#optMakeOffer').show() : $('#optMakeOffer').hide();
364 true == App.permissions.pgUpdateOffer ? $('#optMakeOffer').show() : $('#optMakeOffer').hide();
367 true == App.permissions.pgPrint ? $('#printPriceGuidePdf').show() : $('#printPriceGuidePdf').hide();
370 if (_w.offerview.newItem)
372 _w.offerview.setOfferViewFormMeta();
374 if (!_w.offerview.newItem && null != _w.offerview.itemData)
376 _w.offerview._onStockDataAndTemplate();
378 if (!_w.offerview.newItem && null != _w.offerview.offerData)
380 _w.offerview._onOfferDataAndTemplate();
384 setStockViewFormMeta : function( data )
386 data = (undefined == data)
389 var damagesHtml = '';
390 var accessoriesHtml = '';
391 if (undefined != data && undefined != data.stock && undefined != data.stock.damages)
393 for (var i = 0; i < data.stock.damages.length; i++)
395 damagesHtml += '<div class="control-group">';
396 damagesHtml += '<label class="control-label valuation-line">' + data.stock.damages[i].damage.name + ':</label>';
397 damagesHtml += '<div class="controls">';
398 damagesHtml += '<p class="information-lines">R ' + data.stock.damages[i].amount + '</p>';
399 damagesHtml += '</div>';
400 damagesHtml += '</div>';
403 if (undefined != data && undefined != data.stock && undefined != data.stock.accessories)
405 for (var i = 0; i < data.stock.accessories.length; i+=2)
407 var acc1 = data.stock.accessories[i]
408 ? data.stock.accessories[i].accessory.name
410 var acc2 = data.stock.accessories[i+1]
411 ? data.stock.accessories[i+1].accessory.name
413 accessoriesHtml += '<div class="row-fluid">';
414 accessoriesHtml += '<div class="span6 textshow">' + acc1 + '</div>';
415 accessoriesHtml += '<div class="span6 textshow">' + acc2 + '</div>';
416 accessoriesHtml += '</div>';
422 _w.offerview.formMeta = {
426 'vehicle' : data.stock.type
427 ? data.stock.type.model.make.name + ', '
428 + data.stock.type.model.name + ', '
429 + data.stock.type.name
432 title : 'Reference Number',
433 value : data.stock.referenceNumber
437 value : data.stock.vehicleYear ? data.stock.vehicleYear.name : ''
441 value : data.stock.type ? data.stock.type.category.name : ''
444 title : 'Vehicle Make',
445 value : data.stock.type ? data.stock.type.model.make.name : ''
449 title : 'Vehicle Model',
450 value : data.stock.type ? data.stock.type.model.name : ''
453 title : 'Vehicle Type',
454 value : data.stock.type ? data.stock.type.name : ''
458 value : data.stock.type ? data.stock.type.mmCode : ''
462 value : data.stock.fuelType ? data.stock.fuelType.name : ''
464 'transmissionType' : {
465 title : 'Transmission Type',
466 value : data.stock.transmissionType ? data.stock.transmissionType.name : ''
470 value : data.stock.condition ? data.stock.condition.name : ''
473 title : 'Main ext. colour',
474 value : data.stock.exteriorColour ? data.stock.exteriorColour.name : ''
477 title : 'Main int. colour',
478 value : data.stock.interiorColour ? data.stock.interiorColour.name : ''
481 title : 'Upholstery',
482 value : data.stock.upholstery ? data.stock.upholstery.name : ''
486 value : data.stock.papers ? data.stock.papers.name : ''
490 value : data.stock.natis ? data.stock.natis.name : ''
493 title : 'Spare keys',
494 value : undefined == data.stock.spareKeys
496 : (data.stock.spareKeys ? 'Yes' : 'No')
498 'fullServiceHistory' : {
499 title : 'Full service history',
500 value : undefined == data.stock.fullServiceHistory
502 : data.stock.fullServiceHistory.name
504 'registrationNumber' : {
505 title : 'Registration no',
506 value : data.stock.registrationNumber ? data.stock.registrationNumber : ''
510 value : data.stock.vinNumber ? data.stock.vinNumber : ''
514 value : data.stock.engineNumber ? data.stock.engineNumber : ''
518 value : data.stock.km ? data.stock.km : ''
522 value : data.stock.fshNotes ? data.stock.fshNotes : ''
524 'damages' : damagesHtml,
526 title : 'Total estimated repair price',
527 value : 'R ' + (data.stock ? data.stock.damageTotal : '0.00')
530 title : 'Damages comments',
531 value : data.stock.damageNotes ? data.stock.damageNotes : ''
533 'previousRepairsNoted' : {
534 title : 'Previous repairs noted',
535 value : data.stock.previousRepairsNoted ? 'Yes' : 'No'
537 'previousRepairsNotes' : {
538 title : 'Previous repairs comments',
539 value : data.stock.previousRepairsNotes ? data.stock.previousRepairsNotes : ''
541 'accessories' : accessoriesHtml,
544 value : data.stock.accessoryNotes ? data.stock.accessoryNotes : ''
550 baseImage : 'main_img_car.jpg',
551 value : data.stock.mainImage ? data.stock.mainImage : ''
557 baseImage : 'front_car.jpg',
558 value : data.stock.frontImage ? data.stock.frontImage : ''
564 baseImage : 'left_car.jpg',
565 value : data.stock.leftImage ? data.stock.leftImage : ''
571 baseImage : 'right_car.jpg',
572 value : data.stock.rightImage ? data.stock.rightImage : ''
578 baseImage : 'back_car.jpg',
579 value : data.stock.backImage ? data.stock.backImage : ''
584 id : 'interiorImage',
585 baseImage : 'interior_car.jpg',
586 value : data.stock.interiorImage ? data.stock.interiorImage : ''
592 baseImage : 'engine_car.jpg',
593 value : data.stock.engineImage ? data.stock.engineImage : ''
599 baseImage : 'copy_of_natis_car.jpg',
600 value : data.stock.natisImage ? data.stock.natisImage : ''
603 'coverReceived': data.stock.coverReceived ? data.stock.coverReceived : '',
605 'infCreated': data.created ? ((data.created).split(' '))[0] : '',
606 'infLoadedOnPriceGuide': data.stock.loadedOnPriceGuide
607 ? ((data.stock.loadedOnPriceGuide).split(' '))[0] : '',
610 value : data.stock.tradePrice ? 'R ' + data.stock.tradePrice : '0.00'
614 value : data.stock.retailPrice ? 'R ' + data.stock.retailPrice : '0.00'
617 title : 'New list price',
618 value : data.stock.listPrice ? 'R ' + data.stock.listPrice : '0.00'
620 'infCustomerPrice': {
621 title : 'Customer Request',
622 value : data.stock.valuation && data.stock.valuation.requiredPrice
623 ? 'R ' + data.stock.valuation.requiredPrice
629 value : data.stock.valuation && data.stock.valuation.sighted
630 ? (data.stock.valuation.sighted == true ? "Yes" : "No")
633 'infLicenseDiscExpired': {
634 title : 'License Disc Expired',
635 value : data.stock.valuation && data.stock.valuation.licenseDiscExpired
636 ? (data.stock.valuation.licenseDiscExpired == true ? "Yes" : "No")
641 title : 'Dealership name',
642 value : data.company ? data.company.name : ''
645 title : 'Name and surname',
646 value : data.company && data.company.contact
647 ? data.company.contact.firstName + ' ' + data.company.contact.familyName
652 value : data.company && data.company.contact
653 ? data.company.contact.mobile
658 value : data.company && data.company.contact
659 ? data.company.contact.email
666 value : data.stock && data.stock.company
667 ? data.stock.company.region.name
671 'amountOffered' : _w.offerview.formOfferMeta ? _w.offerview.formOfferMeta : {},
672 'infAmountOffered' : _w.offerview.formOfferMeta ? _w.offerview.formOfferMeta.value : '0.00',
674 constructor: 'Button',
678 id: 'printPriceGuidePdf',
679 handler: _w.offerview.printPriceGuidePdf
686 printPriceGuidePdf : function()
689 'printPriceGuidePdf:' + _w.offerview.itemId, 'PriceGuide', 'Pdf.Print', _w.offerview.itemId,
692 'printPriceGuidePdf:' + _w.offerview.itemId, {}, {},
693 function () {}, _w.offerview,
696 }, _w.taskContractError
700 setOfferViewFormMeta : function( data )
702 data = (undefined == data)
705 _w.offerview.formOfferMeta = {
707 id : 'amountOffered',
709 value : data.amount ? data.amount : '0.00',
710 onChange : function () {
711 _w.offerview.ti.hydrateParam('infAmountOffered', $(this).val());
715 var $_this = $(this),
716 value = $_this.val();
718 if( value == '0.00' )
725 var $_this = $(this),
726 value = $_this.val();
734 _w.offerview.ti.hydrateParam('amountOffered', _w.offerview.formOfferMeta);
735 _w.offerview.ti.hydrateParam('infAmountOffered', _w.offerview.formOfferMeta.value);
739 _onOfferDataAndTemplate : function ()
743 if ('Archived' == _w.offerview.offerData.status)
745 true == App.permissions.pgUnArchive ? $('#btnUnarchive').show() : $('#btnUnarchive').hide();
746 $('#btnArchive').hide();
747 $('#optMakeOffer').hide();
751 true == App.permissions.pgArchive ? $('#btnArchive').show() : $('#btnArchive').hide();
752 $('#btnUnarchive').hide();
756 _onOfferViewDataReceived : function( response )
758 _w.offerview.offerId = response.Data.id;
759 _w.offerview.offerData = response.Data;
760 _w.offerview.setOfferViewFormMeta(response.Data);
761 if (_w.offerview.ti.published)
763 _w.offerview._onOfferDataAndTemplate();
767 _onStockDataAndTemplate : function ()
769 App.DataStore.loadSelectListData(
770 'tuhpi', false, 'Stock', 'Tuhpi.List', null,{"Filter":
772 "stock" : _w.offerview.itemData.stock.id,
773 "company" : App.companyData.id
777 var tuHpiData = App.DataStore.getData('tuhpi');
778 for (var i = 0; i < tuHpiData.length; i++)
780 var tuHpiId = tuHpiData[i].id
781 var tuHpiCreated = tuHpiData[i].created
785 $('#tuhpiDate').html(tuHpiCreated);
786 $('#downloadTuhpi').show();
790 $('#tuhpiDate').html('Not Requested Yet');
791 $('#downloadTuhpi').hide();
796 if (App.permissions.settingsHpiReport == false)
798 $('#requestHPIreport').hide();
802 if (App.permissions.settingsHpiReport)
804 $('#requestHPIreport').show();
806 if (_w.offerview.newItem)
808 if ('Open4Offers' == _w.offerview.itemData.jobState
809 || 'Updateable Offers' == _w.offerview.itemData.jobState)
812 'createOffer', 'PriceGuide', 'Offer.Create',
813 _w.offerview.itemId, {}, function(){}, _w.taskContractError
819 if ('Updateable Offers' == _w.offerview.itemData.jobState)
822 'updateOffer:' + _w.offerview.offerId, 'PriceGuide', 'Offer.Update', _w.offerview.itemId,
823 {"id":_w.offerview.offerId}, $.proxy( _w.offerview._onOfferViewDataReceived, this ), _w.taskContractError
827 if ('Open4Offers' != _w.offerview.itemData.jobState
828 && 'Updateable Offers' != _w.offerview.itemData.jobState)
830 $('#optMakeOffer').hide();
832 true == App.permissions.pgPrint ? $('#printPriceGuidePdf').show() : $('#printPriceGuidePdf').hide();
833 if (null == App.API.taskContract('gridStockHistory'))
836 'gridStockHistory', 'Stock', 'PricingHistory.Grid', null,
837 {}, _w.offerview.loadHistoricalGrid, _w.taskContractError
842 _w.offerview.loadHistoricalGrid( null, {}, {} );
846 _onStockViewDataReceived : function( response )
848 _w.offerview.itemId = response.Data.id;
849 _w.offerview.itemData = response.Data;
850 _w.offerview.setStockViewFormMeta(response.Data);
851 _w.offerview.ti.hydrate(_w.offerview.formMeta);
852 if (_w.offerview.ti.published)
854 _w.offerview._onStockDataAndTemplate();
858 _onOfferUpdated : function( response )
860 window.location.hash = '/priceguide';