Skip to content

fix bug #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
98 changes: 58 additions & 40 deletions assets/js/quote.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
$(document).ready(function () {

$("#numElev_2, #numElev_3, #elevPriceUnit, #elevTotal, #installationFee, #total_").attr('readonly', true);

var numApp, numFloors, numBase, maxOcc;
var numApp, numElev, numFloors, numBase, maxOcc;
var prodRange = {
type: null,
price: null,
Expand All @@ -13,16 +14,40 @@ $(document).ready(function () {
});


$('#standart, #premium, #excelium').on('click', function () {
document.getElementById('elevPriceUnit').value = (7565).toFixed(2) + " $";

// production range
$('#standard, #premium, #excelium').on('click', function () {
doCalc();
$("#elevPriceUnit").val(`${getProdRange().price.toFixed(2)} $`)
});

$('#residential, #commercial, #corporate, #hybrid').on('click', function () {
initialize();
});
function getProdRange() {
if ($('#standard').is(':checked')) {
prodRange.type = "standard";
prodRange.price = parseFloat(7565);
prodRange.installationFeePercentage = 0.1;
return prodRange;

} else if ($('#premium').is(':checked')) {
prodRange.type = "premium";
prodRange.price = parseFloat(12345);
prodRange.installationFeePercentage = 0.13;
return prodRange;

} else if ($('#excelium').is(':checked')) {
prodRange.type = "excelium";
prodRange.price = parseFloat(15400);
prodRange.installationFeePercentage = 0.16;
return prodRange;
} else {
prodRange.type = null,
prodRange.price = null,
prodRange.installationFeePercentage = null
return prodRange;
}
};

// initialize
function initialize() {
$('.formField').val('');
$('.productRangeBtn').prop('checked', false);
Expand All @@ -31,9 +56,10 @@ $(document).ready(function () {
function getInfoNumApp() {
numApp = $('#numApp').val();
};

function getInfoNumFloors() {
numFloors = $('#numFloors').val();

};

function getInfoNumBase() {
Expand All @@ -48,74 +74,64 @@ $(document).ready(function () {
maxOcc = $('#maxOcc').val();
};

function getProdRange() {
if ($('#standard').is(':checked')) {
prodRange.type = "standard";
prodRange.price = parseFloat(7565);
prodRange.installationFeePercentage = 0.1;
return prodRange;

} else if ($('#premium').is(':checked')) {
prodRange.type = "premium";
prodRange.price = parseFloat(123456);
prodRange.installationFeePercentage = 0.13;
return prodRange;

} else if ($('#excelium').is(':checked')) {
prodRange.type = "excelium";
prodRange.price = parseFloat(15400);
prodRange.installationFeePercentage = 0.16;
return prodRange;
} else {
prodRange.type = null,
prodRange.price = null,
prodRange.installationFeePercentage = null
return prodRange;
}
};


//Info
function GetInfos() {
getInfoNumApp();
getInfoNumFloors();
getInfoNumBase();
getInfoNumElev();
getInfoMaxOcc();
getProdRange();

};

//result
function setRequiredElevatorsResult(finNumElev) {
$("#numElev_2, #numElev_3").val(parseFloat(finNumElev));

};

function setPricesResults(finNumElev, roughTotal, installFee, total) {
$("#elevTotal").val(parseFloat(roughTotal).toFixed(2) + " $");
$("#installationFee").val(parseFloat(installFee).toFixed(2) + " $");
$("#total_").val(parseFloat(total).toFixed(2) + " $");

};

function emptyElevatorsNumberAndPricesFields() {
$('#numElev_2').val('');
$('#numElev_3').val('');
$('.priceField').val('');
};

// Output
function createFormData(projectType) {
return {
numberElev: numElev,
numberApp: numApp,
numberFloors: numFloors,
numberBase: numBase,
maximumOcc: maxOcc,
productRange: prodRange,
projectType: projectType
}

};

//Negative alert box
function negativeValues() {
if ($('#numApp').val() < 0) {

alert("Please enter a positive number!");
$('#numApp').val('');
return true

} else if ($('#numBase').val() < 0) {
} else if ($('#numFloors').val() < 0) {

alert("Please enter a positive number!");
$('#numFloors').val('');
return true

}
else if ($('#numBase').val() < 0) {

alert("Please enter a positive number!");
$('#numBase').val('');
Expand Down Expand Up @@ -178,13 +194,15 @@ $(document).ready(function () {
});
}


function doCalc() {

if ($('#residential').hasClass('active') && !negativeValues() && $('#numApp').val() && $('#numFloors').val()) {
apiCall('residential')
} else if ($('#commercial').hasClass('active') && !negativeValues() && $('#numElev').val() && $('#numPark').val()) {
apiCall('commercial')
} else if ($('#corporate').hasClass('active') && !negativeValues() && $('#numFloors').val() && $('#numBase').val() && $('#maxOcc').val()) {
}else if ($('#commercial').hasClass('active') && !negativeValues() && $('#numElev').val()) {
apiCall('commercial')
}else if ($('#corporate').hasClass('active') && !negativeValues() && $('#numFloors').val() && $('#numBase').val() && $('#maxOcc').val()) {
apiCall('corporate')
} else {
emptyElevatorsNumberAndPricesFields();
};
Expand Down