define(['quote/quote'], function (quote) {
quote.controller('FinalSummary', ['$scope', '$http', '$mdDialog', function ($scope, $http,$mdDialog) {
$scope.isBrokerQuote = false;
$scope.isBrokerFeeWaived = false;
$scope.showWaiveBrokerFee = true;
if (window.location.href.indexOf("quote") > -1 && window.location.href.indexOf("brokers") > -1)
$scope.isBrokerQuote = true;
eval(document.getElementById("mvdInit").innerHTML);
$scope.mvdActive = _mvdActive;
$scope.DiscountList = $scope.Quote.DiscountDetails;
$scope.DiscTotals = $scope.Quote.DiscountTotal;
$scope.discountDisplay = true;
$scope.Final = {
Loading: true
};
$scope.SetIsFinalSummary(true);
$scope.$watch('Final.Loading', function (val) {
if (val == true) {
$scope.SetStepLoading();
$scope.SetStepHeader('
Your insurance quote is almost ready.
', 'In a moment you\'ll receive a tailor-made quote for insurance that is behind you every step of the way.');
}
else if (val == false) {
$scope.SetStepHeader('Here\'s your final quote
','Your reference number is:'+$scope.Quote.ReferenceNumberDisplay+'. This quote will be valid for 30 days.');
$scope.SetStepLoaded();
}
});
$scope.setVehicleDescription = function () {
$scope.Quote.Vehicles.forEach(function (value) {
if (value.VehicleType == 'GolfCart' || value.VehicleType == 'Caravan' || value.VehicleType == 'Trailer') {
var desc = $scope.QuoteDetail.Vehicles.filter(function (v) { return v.SequenceNumber == value.VehicleSequenceNumber });
if (desc.length == 0) return;
value.VehicleDescription.Description = desc[0].Description;
}
});
}
// Functions
$scope.GetQuoteDetails = function () {
$scope.Final.Loading = true;
var referenceNumber = $scope.Quote && $scope.Quote.ReferenceNumber;
$http({
method: 'POST',
url: '/Quote/FinalSummary/GetDetails',
data: { currentState: $scope.Quote }
}).success(function (data, status, headers, config) {
$scope.QuoteDetail = data;
if ($scope.Quote.Type === 'Amendment' && $scope.QuoteDetail.Vehicles.length > 0) $scope.setVehicleDescription();
$scope.DiscountList = data.DiscountDetail;
$scope.DiscTotals = data.DiscountTotals;
if ($scope.QuoteDetail.TotalPremium <= 30 && $scope.Quote.Type == "Lead")
window.location = "/quote/" + $scope.Quote.ReferenceNumberDisplay + "#/refertomanager";
else
$scope.Final.Loading = false;
if ($scope.isBrokerQuote)
$scope.GetBrokerFee();
});
};
$scope.ReQuote = function (removeBorehole) {
$scope.Final.Loading = true;
if ($scope.QuoteDetail)
$scope.currentPremium = $scope.QuoteDetail.CurrentPremiumDisplay;
$http({
method: 'POST',
url: '/Quote/FinalSummary/ReQuote',
data: {
currentState: $scope.Quote,
removeBorehole: removeBorehole
}
}).success(function (data, status, headers, config) {
$scope.QuoteDetail = data;
$scope.QuoteDetail.CurrentPremiumDisplay = $scope.currentPremium;
//var count = 0;
//for (var i = 0; i < $scope.Quote.Vehicles.length; i++) {
// ($scope.Quote.Vehicles[i].CoverType == "A" || $scope.Quote.Vehicles[i].CoverType == "D" || $scope.Quote.Vehicles[i].CoverType == null) ? count++ : count;
//}
//count > 1 ? $scope.discountDisplay = true : $scope.discountDisplay = false;
$scope.DiscountList = data.DiscountDetail;
$scope.DiscTotals = data.DiscountTotals;
$scope.Final.Loading = false;
});
};
$scope.MaritalDisplay = function (code) {
// todo: MaritalDisplay() wants to be a helper function that can be used all over.
// It also wants to read its data from the backend, but not too often
switch (code) {
case "A": code = "Separated"; break;
case "D": code = "Divorced"; break;
case "M": code = "Married"; break;
case "P": code = "Cohabiting/Partnered"; break;
case "S": code = "Single"; break;
case "W": code = "Widowed"; break;
}
return code;
};
var RemoveDialog = function (ev, message) {
return $mdDialog.confirm()
.title('Are you sure?')
.content(message || 'Are you sure you want to remove this risk item? This action cannot be undone. If you want to add a risk item you will have to start the buy process over again.')
.ok('Remove')
.cancel('Cancel')
.disableParentScroll(false)
.targetEvent(ev);
};
$scope.RemoveHome = function RemoveHome(ev) {
// Appending dialog to document.body to cover sidenav in docs app
var msg = "";
var isCarCounter = 0;
if ($scope.Quote.PortablePossessions.Bicycles.length > 0 || $scope.Quote.PortablePossessions.Cellphone.length > 0 || $scope.Quote.PortablePossessions.SpecifiedItems.length > 0 || $scope.Quote.PortablePossessions.PrescriptionGlasses.length > 0)
for (var a = 0; a < $scope.Quote.Vehicles.length; a++) {
if ($scope.Quote.Vehicles[a].IsCar && $scope.Quote.Vehicles[a].TrueAndCorrect == true)
isCarCounter ++;
}
if (isCarCounter > 0) {
msg = "Removing home content may affect the amount of portable possessions you can insure.";
}
else {
msg = "Removing this home contents cover will remove any linked portable possession.";
}
var confirm = RemoveDialog(ev, msg);
$mdDialog.show(confirm).then(function () {
$scope.Quote.HomeContent.TrueAndCorrect = false;
// Reload the quote
if (isCarCounter > 0) {
$scope.Final.Loading = true;
$scope.CheckPortablesWhenDeletingHome();
}
else {
$scope.ReQuote();
}
});
};
$scope.RemoveBuilding = function (ev) {
if (($scope.Quote.HomeContent.HomeContentsValue && $scope.Quote.HomeContent.HomeContentsValue > 0) || !($scope.Quote.HomeContent.HomeBoreholePoolValue && $scope.Quote.HomeContent.HomeBoreholePoolValue > 0))
msg = "Are you sure you want to remove this building? This action cannot be undone. If you want to add a risk item you will have to start the buy process over again.";
else
msg = "Are you sure you want to remove this building (borehole and swimming pool equipment will also be removed)? This action cannot be undone. If you want to add a risk item you will have to start the buy process over again.";
var confirm = RemoveDialog(ev, msg);
$mdDialog.show(confirm).then(function () {
$scope.Quote.Building.TrueAndCorrect = false;
$scope.ReQuote();
});
};
$scope.RemoveVehicle = function (ev, sequenceNumber) {
var vehicleCheck = $scope.DiscountList.filter(function (x) { return x.vehicleSequenceNumber == sequenceNumber.toString() });
var mvdMessage = vehicleCheck.length > 0 && vehicleCheck[0].hasDiscount == "1" && $scope.Quote.DiscountAmounts.length != 0 ? "By removing a vehicle, you may affect the comprehensive vehicle insurance discount you qualified for, which works as follows: " + $scope.Quote.DiscountAmounts[0].NumberOfVehicles + " car = no discount, " + $scope.Quote.DiscountAmounts[1].NumberOfVehicles + " cars = up to " + $scope.Quote.DiscountAmounts[1].DiscountPercentage + "%, " + $scope.Quote.DiscountAmounts[2].NumberOfVehicles + " cars = up to " + $scope.Quote.DiscountAmounts[2].DiscountPercentage + "%, " + $scope.Quote.DiscountAmounts[3].NumberOfVehicles + " cars = up to " + $scope.Quote.DiscountAmounts[3].DiscountPercentage + "% each." : "";
var confirm = RemoveDialog(ev, 'Are you sure you want to remove this risk item? This action cannot be undone. If you want to add a risk item you will have to start the buy process over again.' + mvdMessage);
$mdDialog.show(confirm).then(function () {
// find and flag the vehicle to remove
if ($scope.Quote.Vehicles) {
angular.forEach($scope.Quote.Vehicles, function (value, key) {
if (value.VehicleSequenceNumber == sequenceNumber) {
value.TrueAndCorrect = false; // flag for removal
}
});
}
$scope.ReQuote();
});
};
$scope.RemoveBorehole = function (ev) {
var confirm = RemoveDialog(ev);
$mdDialog.show(confirm).then(function () {
$scope.Quote.HomeContent.HomeBoreholePoolValue = null;
$scope.ReQuote(true);
});
};
$scope.RemoveItem = function (ev) {
$mdDialog.show(
$mdDialog.alert()
.clickOutsideToClose(true)
.disableParentScroll(false)
.title('Remove Unsupported')
.content('Removing this content item is not yet supported')
.ok('Got it!')
.targetEvent(ev)
);
};
$scope.Print = function () {
var oldname = document.title;
document.title = "Auto and General - Quote " + $scope.Quote.ReferenceNumberDisplay;
window.print();
document.title = oldname;
}
$scope.Email = function (ev) {
$http({
method: 'POST',
url: '/Quote/FinalSummary/Email',
params: { referenceNumber: $scope.Quote.ReferenceNumber }
}).success(function (data, status, headers, config) {
$mdDialog.show(
$mdDialog.alert().clickOutsideToClose(true).disableParentScroll(false)
.title('Email Delivered')
.content('Your quotation has been emailed to: ' + $scope.Quote.Personal.Email)
.ok('Thanks!')
.targetEvent(ev)
);
});
};
$scope.GetBrokerFee = function () {
$http({
method: 'POST',
url: '/Quote/FinalSummary/GetBrokerFee'
}).success(function (data) {
$scope.BrokerFee = data;
$scope.TotalPremiumWithBrokerFee = $scope.QuoteDetail.TotalPremium + data;
if ($scope.CurrentBrokerFee === 0)
$scope.showWaiveBrokerFee = false;
});
}
$scope.WaiveBrokerFee = function () {
$scope.isBrokerFeeWaived = !$scope.isBrokerFeeWaived;
if ($scope.isBrokerFeeWaived) {
$scope.BrokerFeeBeforeWaive = $scope.BrokerFee;
$scope.TotalPremiumWithBrokerFee = $scope.TotalPremiumWithBrokerFee - $scope.BrokerFee;
$scope.BrokerFee = 0;
}
else {
$scope.BrokerFee = $scope.BrokerFeeBeforeWaive;
$scope.TotalPremiumWithBrokerFee = $scope.TotalPremiumWithBrokerFee + $scope.BrokerFee;
}
}
// Initialize things
$scope.GetQuoteDetails();
}]);
});