我一直致力于财政年度日历,它也正确地产生了一年,但我面临的问题是我想用日期限制这个,就像现在它产生当前和下一个财政年度但我想要定制年份的自定义日期。
例如,在月份字段(1月)的日期字段(01-01-2018)中 从1月开始生成所有2018年或者如果我提供月份 字段(八月)和日期字段(01-08-2019)所以它从中生成 2018年8月
Html代码
`<div class="calenderYear">
<h3 class="box-title">Calendar Year</h3>
<div class="table-responsive">
<table class="table color-bordered-table inverse-bordered-table">
<thead>
<tr>
<th>Period</th>
<th>Title</th>
<th>Start Date</th>
<th>End Date</th>
<th>GL Year</th>
<th>GL Period</th>
</tr>
</thead>
<tbody>
<tr class="remove">
<td></td>
<td></td>
<td></td>
<td></td>
<td></td>
<td><input type="button" class="btn btn-default generate" value="Generate New" /></td>
</tr>
</tbody>
</table>
</div>
</div>`
Jquery代码
$(".process").click(function(){
var month = $(".month").val();
var start_date = $(".firstDay").val();
if(start_date=='') {
swal({
title: "Default Finalcial Year Generation",
text: "Month and Start Date is required.!",
type: "info",
showCancelButton: false,
confirmButtonColor: "#DD6B55",
confirmButtonText: "OK",
closeOnConfirm: true
}, function () {
swal("Deleted!", "Your imaginary file has been deleted.", "success");
});
}else{
var offsetValue = 6;
var month = $(".month").val();
var theMonths = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"];
if(month == 'January'){
offsetValue = 0;
}else if(month == 'February'){
offsetValue = 1;
}else if(month == 'March'){
offsetValue = 2;
}else if(month == 'April'){
offsetValue = 3;
}else if(month == 'May'){
offsetValue = 4;
}else if(month == 'June'){
offsetValue = 5;
}else if(month == 'July'){
offsetValue = 6;
}else if(month == 'August'){
offsetValue = 7;
}else if(month == 'September'){
offsetValue = 8;
}else if(month == 'October'){
offsetValue = 9;
}else if(month == 'November'){
offsetValue = 10;
}else if(month == 'December'){
offsetValue = 11;
}else {
swal({
title: "Default Finalcial Year Generation",
text: "Month and Start Date is required.!",
type: "info",
showCancelButton: false,
confirmButtonColor: "#DD6B55",
confirmButtonText: "OK",
closeOnConfirm: true
}, function () {
swal("Deleted!", "Your imaginary file has been deleted.", "success");
});
}
var offset = offsetValue;
for (var i = 0; i < 12; i++) {
var j = i+1;
var date = new Date();
var currentMonth = (new Date).getMonth(); // GET current month
var currentYear = (new Date).getFullYear(); // GET current year
var financialYear = 0;
var lastYear = offset-1;
var nextYear = offset+1;
if (currentMonth <= 5) { // IF current month is June (5) or earlier use financial year pattern 2014/2015
financialYear = lastYear+"/"+currentYear;
} else { // ELSE current month is after June (5) use financial year pattern 2015/2016
financialYear = currentYear+"/"+nextYear;
}
var monthIndex = i + offset;
var firstDay = new Date(date.getFullYear(), monthIndex + 0 % theMonths.length, 1);
var firstDay = moment(firstDay).format('DD-MM-YYYY');
var lastDay = new Date(date.getFullYear(), monthIndex + 1 % theMonths.length, 0, 23, 59, 59);
var lastDay = moment(lastDay).format('DD-MM-YYYY');
var months = '<tr><td><input type="text" name="Period[]" class="form-control" value="' + j + '" size="2" /></td>';
months+='<td><input type="text" name="month[]" class="form-control month" value="' + theMonths[monthIndex % theMonths.length] + '" /></td>';
months+='<td><input type="text" name="firstDay[]" class="form-control firstDay" value="' + firstDay + '" /></td>';
months+='<td><input type="text" name="lastDay[]" class="form-control" value="' + lastDay + '" /></td>';
months+='<td><input type="text" name="year[]" class="form-control" value="' + currentYear + '" /></td>';
months+='<td><input type="text" name="GLPeriod[]" class="form-control" value="' + j + '" size="2" /></td></tr>';
$('.generate').attr('disabled',true);
$('.calenderYear .table-responsive table tbody').append(months).fadeIn(300);
}
$(".hideAfterFilledup").hide();
$('.calenderYear .table-responsive table tbody').append('<tr><td></td><td></td><td></td><td></td><td><input type="submit" class="btn btn-info process" value="Process" /></td><td><input type="submit" class="btn btn-info" value="Create New" /></td></tr>');
}
});