在收费系统上未正确计算收费时遇到问题。
下面是代码,如果您在一个日期范围内运行,而不是以 1 个价格给出 2 天,然后以另一个价格说 1 天,则它不会。以下是代码示例:
$(function () {
function change_charges() {
var checkin_mon = Number($("#checkindate_Month_ID").val());
var checkin_day = Number($("#checkindate_Day_ID").val());
var checkin_year = Number($("#checkindate_Year_ID").val());
var checkout_mon = Number($("#checkoutdate_Month_ID").val());
var checkout_day = Number($("#checkoutdate_Day_ID").val());
var checkout_year = Number($("#checkoutdate_Year_ID").val());
var checkin_date = new Date();
checkin_date.setFullYear(checkin_year, checkin_mon, checkin_day);
var checkout_date = new Date();
checkout_date.setFullYear(checkout_year, checkout_mon, checkout_day);
var one_day = 1000 * 60 * 60 * 24
//Calculate difference btw the two dates, and convert to days
var stay = Math.ceil((checkout_date.getTime() - checkin_date.getTime()) / (one_day));
var room_type = $("#room_type").val();
var charges = 0;
var n_charges = 0;
var st_date = new Date();
var end_date = new Date();
var mon_stay = 0;
var rem_stay = 0;
if (room_type == "Villa") {
st_date.setFullYear(checkin_year, 4, 1);
end_date.setFullYear(checkin_year, 9, 31);
if (checkin_date >= st_date && checkin_date <= end_date) {
charges = 1995;
n_charges = 2995;
if (checkout_date > end_date) mon_stay = Math.ceil((end_date.getTime() - checkin_date.getTime()) / (one_day));
}
st_date.setFullYear(checkin_year, 10, 1);
end_date.setFullYear(checkin_year, 11, 15);
if (checkin_date >= st_date && checkin_date <= end_date) {
charges = 2995;
n_charges = 2995;
if (checkout_date > end_date) mon_stay = Math.ceil((end_date.getTime() - checkin_date.getTime()) / (one_day));
}
st_date.setFullYear(checkin_year, 11, 16);
end_date.setFullYear(checkin_year, 11, 31);
if (checkin_date >= st_date && checkin_date <= end_date) {
charges = 5900;
n_charges = 5900;
if (checkout_date > end_date) mon_stay = Math.ceil((end_date.getTime() - checkin_date.getTime()) / (one_day));
}
st_date.setFullYear(checkin_year, 0, 1);
end_date.setFullYear(checkin_year, 0, 15);
if (checkin_date >= st_date && checkin_date <= end_date) {
charges = 5900;
n_charges = 3900;
if (checkout_date > end_date) mon_stay = Math.ceil((end_date.getTime() - checkin_date.getTime()) / (one_day));
}
st_date.setFullYear(2013, 0, 16);
end_date.setFullYear(2013, 3, 30);
if (checkin_date >= st_date && checkin_date <= end_date) {
charges = 3900;
n_charges = 2223;
if (checkout_date > end_date) mon_stay = Math.ceil((end_date.getTime() - checkin_date.getTime()) / (one_day));
}
如果(保持 > 1){
if(mon_stay == 0)mon_stay = 1;
if(mon_stay != 0){
rem_stay = stay - mon_stay;
charges = (mon_stay*charges) + (rem_stay*n_charges);
}
else
charges*=stay;
}
var 今天 = 新日期();
if(checkin_date < 今天 || checkout_date < 今天 || checkout_date < checkin_date){
charges = 0;
}
$("#tot_charges").html(charges.toFixed(2));
}
$("#checkindate_Month_ID").change(function() {
change_charges();
});
$("#checkindate_Day_ID").change(function() {
change_charges();
});
$("#checkindate_Year_ID").change(function() {
change_charges();
});
$("#checkoutdate_Month_ID").change(function() {
change_charges();
});
$("#checkoutdate_Day_ID").change(function() {
change_charges();
});
$("#checkoutdate_Year_ID").change(function() {
change_charges();
});
$("#room_type").change(function() {
change_charges();
});