testFiddle
Just test
by OVK2015
HTML
<script src="https://getfirebug.com/firebug-lite-debug.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/moment.js/2.11.2/moment.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-datepicker/1.6.0/js/bootstrap-datepicker.min.js"></script>
<div class="col-lg-4 col-lg-offset-4">
<h2 class="text-center">Калькулятор оплаты</h2>
<table class="table table-bordered">
<tr>
<td><p class="text-right form-control-static">На счету абонента, руб.:</p></td>
<td><input class="form-control" type="number" id="currentBalance" value="0" placeholder="укажите сумму"/></td>
</tr>
<tr>
<td><p class="text-right form-control">Сегодня:</p></td>
<td><input id="currentDay" type="text" class="form-control"/></td>
</tr>
<tr>
<td><p class="form-control" >До какого числа желают оплатить?</p></td>
<td>
<input id="targetDay" type="text" class="form-control">
</td>
<tr>
<td><p class="text-right form-control-static">Тариф абонента:</p></td>
<td>
<select class="form-control" id="tarif">
<option value="0">Тариф "Мини"</option>
<option value="1">Тариф "Безлим 4"</option>
<option value="2">Тариф "Безлим 10"</option>
<option value="3">Тариф "Безлим 35"</option>
<option value="4">Тариф "Безлим 100"</option>
<option value="5">Тариф "Jump 5"</option>
<option value="6">Тариф "Jump 10"</option>
<option value="7">Тариф "Jump 35"</option>
<option value="8">Тариф "Jump 70"</option>
</select>
</td>
</tr>
<tr>
<td><p class="text-right form-control-static">К оплате, руб:</p></td>
<td><input class="form-control" type="text" id="sum" readonly/></td>
</tr>
<tr>
<td colspan="2" class="text-right">
<button class="btn btn-info">Поехали!</button>
</td>
</tr>
</table>
JavaScript
var tarifs = new Array(150, 225, 261, 297, 378, 150+57.60, 225+54, 261+48, 297+42, 378+18, 306, 360, 405, 522, 57.60);
function evalResult()
{
// var payByMonth = tarifs[$('.form-control option:selected').val()];
var startDateInterval = moment($('#currentDay').val(), 'DD.MM.YYYY');
var endDateInterval = moment($('#targetDay').val(), 'DD.MM.YYYY');
// console.log('Начало интервала: ' + startDateInterval.format('YYYY-MM-DD'));
// console.log('Окончание интервала: ' + endDateInterval.format('YYYY-MM-DD'));
var currentBalance;
if(($('#currentBalance').val() == '') || (parseFloat($('#currentBalance').val()) == NaN))
{
currentBalance = 0;
}
else
{
currentBalance = parseFloat($('#currentBalance').val());
}
var summaP;
if(($('#summa2').val() == '') || (parseFloat($('#summa2').val()) == NaN))
{
summaP = 0;
}
else
{
summaP = parseFloat($('#summa2').val());
}
if(
(startDateInterval > endDateInterval) ||
(endDateInterval._d == 'Invalid Date') ||
(startDateInterval._d == 'Invalid Date')
)
{return false;}
console.log('Сумма в рублях: ' + summaP);
console.log('Сумма в рублях: ' + currentBalance);
var timeInterval = parseInt(endDateInterval.diff(startDateInterval, 'days'));
console.log('Длина интервала: ' + timeInterval);
// var dayInCurrentMonth = moment($('#targetDay').val().substr(0, $('#targetDay').val().lastIndexOf('-')), "YYYY-MM").daysInMonth();
// console.log('Дней в месяце: ' + dayInCurrentMonth);
// var payByDay = payByMonth / dayInCurrentMonth;
var payByDay = tarifs[$('.form-control option:selected').val()] / 30;
console.log('Оплата за день: ' + payByDay);
var totalAmount = timeInterval * payByDay - currentBalance;
console.log('Остаток на счету: ' + currentBalance);
// console.log('Тариф: ' +...