565 lines
22 KiB
Plaintext
565 lines
22 KiB
Plaintext
@using EnVisage.Code
|
|
@using EnVisage.Models
|
|
@model FiscalCalendarModel
|
|
@{
|
|
ViewBag.Title = "Fiscal Calendar";
|
|
}
|
|
@section scripts
|
|
{
|
|
<script type="text/javascript">
|
|
emulateNavUrl = "/Calendar";
|
|
|
|
init.push(function () {
|
|
$('#holidays').dataTable({
|
|
"bProcessing": true,
|
|
"bServerSide": true,
|
|
"bAutoWidth": false,
|
|
"sAjaxSource": '@Url.Action("GetHolidayItems", "Calendar")', // document.URL,
|
|
"sServerMethod": "POST",
|
|
"aoColumns": [
|
|
{ "mDataProp": "Name" },
|
|
{ "mDataProp": "StartDateText" },
|
|
{ "mDataProp": "EndDateText" },
|
|
{ "mDataProp": "WorkingDays", "mRender": function (data, type, full) { return data === true ? "Yes" : "No" } },
|
|
{ "mDataProp": "Recurrences", "mRender": function (data, type, full) { return getReccurenceAsText(data); } },
|
|
{ "mDataProp": "EffectiveChangeDateAsText" },
|
|
{ "mDataProp": "ValidToAsText" },
|
|
{
|
|
"mData": function (data, type, full) {
|
|
@if (SecurityManager.CheckSecurityObjectPermission(Areas.FiscalCalendar, AccessLevel.Write))
|
|
{
|
|
<text>
|
|
return ('<button onclick="showHolidayHistory(\'_rplcmnt_\')" data-toggle="popover" data-placement="left" class="btn btn-sm btn-primary popover-dark"><i class="fa fa-eye"></i> History</button> ' +
|
|
'<button onclick="showEditHolidayDialog(\'_rplcmnt_\')" data-toggle="popover" data-placement="left" class="btn btn-sm btn-primary popover-warning popover-dark"><i class="fa fa-edit"></i> Edit</button> ' +
|
|
'<button onclick="deleteHoliday(\'_rplcmnt_\')" data-toggle="popover" data-placement="left" class="btn btn-sm btn-danger popover-warning popover-dark"><i class="fa fa-trash-o"></i> Delete</button>')
|
|
.replace(/_rplcmnt_/g, data.HolidayGroupId);
|
|
</text>
|
|
}
|
|
else
|
|
{
|
|
<text>
|
|
return "";
|
|
</text>
|
|
}
|
|
}
|
|
}]
|
|
});
|
|
@if (SecurityManager.CheckSecurityObjectPermission(Areas.FiscalCalendar, AccessLevel.Write))
|
|
{
|
|
<text>
|
|
$('#holidays_wrapper .table-caption').html('<button class="btn btn-primary" onclick="showCreateHolidayDialog()"><i class="fa fa-plus"></i> Add Holiday</button>');
|
|
</text>
|
|
}
|
|
$('#holidays_wrapper .dataTables_filter input').attr('placeholder', 'Search...');
|
|
$('#holidays_wrapper .dataTables_processing').addClass("table-caption");
|
|
$('#holidays_wrapper .dataTables_processing').html('<span class="h3"><img class="valign-middle" src="../Content/images/loadFA.gif"/></span>');
|
|
});
|
|
|
|
function deleteHoliday(holidayGroupId) {
|
|
if (!holidayGroupId || (holidayGroupId.length < 1))
|
|
return;
|
|
|
|
var url = "?id=" + holidayGroupId;
|
|
|
|
bootbox.confirm({
|
|
message: "Are you sure you want to delete the holiday?",
|
|
callback: function (result) {
|
|
if (result) {
|
|
StartEdit('Holiday', holidayGroupId, null, null, 'erorMsgPlaceholderIndex');
|
|
blockUI();
|
|
|
|
$.ajax({
|
|
url: '@Url.Action("DeleteHoliday", "Calendar")' + url,
|
|
cache: false,
|
|
type: "post",
|
|
error: function (response) {
|
|
StopEdit();
|
|
RemoveLock('Holiday', holidayGroupId);
|
|
showErrorModal();
|
|
},
|
|
success: function (response) {
|
|
StopEdit();
|
|
RemoveLock('Holiday', holidayGroupId);
|
|
window.location.reload();
|
|
},
|
|
complete: function () {
|
|
unblockUI();
|
|
}
|
|
});
|
|
}
|
|
},
|
|
className: "bootbox-sm"
|
|
});
|
|
}
|
|
|
|
function showHolidayHistory(holidayGroupId) {
|
|
blockUI();
|
|
var url = "?id=" + holidayGroupId;
|
|
|
|
$('#holidayHistoryReload').html("");
|
|
$.ajax({
|
|
url: '@Url.Action("ViewHolidayHistory", "Calendar")' + url,
|
|
cache: false,
|
|
dataType: "html",
|
|
success: function (data) {
|
|
$('#holidayHistoryReload').html(data);
|
|
|
|
var unpackItems = $('input.ReccurenceHidden');
|
|
$.each(unpackItems, function (index, item) {
|
|
var jsonData = $(item).val();
|
|
var recurText = getReccurenceAsText(jsonData);
|
|
$(item).parent().text(recurText);
|
|
});
|
|
|
|
$('#viewHolidayHistory').modal('show');
|
|
},
|
|
error: function () {
|
|
showErrorModal();
|
|
},
|
|
complete: function () {
|
|
unblockUI();
|
|
},
|
|
});
|
|
}
|
|
|
|
function showEditHolidayDialog(holidayGroupId) {
|
|
if (!holidayGroupId || (holidayGroupId.length < 1) || (holidayGroupId == '@Guid.Empty')) {
|
|
showCreateHolidayDialog();
|
|
}
|
|
|
|
blockUI();
|
|
var url = "?id=" + holidayGroupId;
|
|
|
|
$('#editHolidayReload').html("");
|
|
$('#editHolidayItem').off('hide.bs.modal').off('hidden.bs.modal').off('shown.bs.modal');
|
|
|
|
$.ajax({
|
|
url: '@Url.Action("EditHoliday", "Calendar")' + url,
|
|
cache: false,
|
|
dataType: "html",
|
|
success: function (data) {
|
|
$('#editHolidayReload').html(data);
|
|
|
|
initEditHolidayForm();
|
|
|
|
|
|
$('#editHolidayItem')
|
|
.on('hidden.bs.modal', function () {
|
|
StopEdit();
|
|
RemoveLock('Holiday', holidayGroupId);
|
|
})
|
|
.on('hide.bs.modal', function (e) {
|
|
var result = true;
|
|
|
|
if ($(e.target).attr('id') == 'editHolidayItem') {
|
|
// check that form has been changed
|
|
if (holidayFormDataChanged) {
|
|
// ask user for confirmation of form close
|
|
bootbox.confirm({
|
|
message: 'Form contains unsaved changes, do you want to close the form?',
|
|
callback: function (result) {
|
|
if (result) {
|
|
holidayFormDataChanged = false;
|
|
|
|
$('#editHolidayItem').modal("hide");
|
|
}
|
|
}
|
|
});
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
})
|
|
.modal('show');
|
|
},
|
|
error: function () {
|
|
showErrorModal();
|
|
},
|
|
complete: function () {
|
|
unblockUI();
|
|
}
|
|
});
|
|
}
|
|
|
|
|
|
function showCreateHolidayDialog() {
|
|
blockUI();
|
|
|
|
$('#editHolidayReload').html("");
|
|
$('#editHolidayItem').off('hide.bs.modal').off('hidden.bs.modal').off('shown.bs.modal');
|
|
|
|
$.ajax({
|
|
url: '@Url.Action("CreateHoliday", "Calendar")',
|
|
cache: false,
|
|
dataType: "html",
|
|
success: function (data) {
|
|
$('#editHolidayReload').html(data);
|
|
initEditHolidayForm();
|
|
|
|
$('#editHolidayItem')
|
|
.on('hide.bs.modal', function (e) {
|
|
var result = true;
|
|
|
|
if ($(e.target).attr('id') == 'editHolidayItem') {
|
|
// check that form has been changed
|
|
if (holidayFormDataChanged) {
|
|
// ask user for confirmation of form close
|
|
|
|
bootbox.confirm({
|
|
message: 'Form contains unsaved changes, do you want to close the form?',
|
|
callback: function (result) {
|
|
if (result) {
|
|
holidayFormDataChanged = false;
|
|
|
|
$('#editHolidayItem').modal("hide");
|
|
}
|
|
}
|
|
});
|
|
|
|
return false;
|
|
}
|
|
}
|
|
|
|
return result;
|
|
})
|
|
.modal('show');
|
|
},
|
|
error: function () {
|
|
showErrorModal();
|
|
},
|
|
complete: function () {
|
|
unblockUI();
|
|
}
|
|
});
|
|
}
|
|
|
|
function showCalendarEditDialog() {
|
|
var emptyId = '@Guid.Empty';
|
|
var url = "";
|
|
var isNewItem = true;
|
|
|
|
var itemIdSelector = '#@Html.IdFor(t => t.Id)';
|
|
var itemId = $(itemIdSelector).val();
|
|
|
|
blockUI();
|
|
|
|
if (itemId && (itemId.length > 0) && (itemId != emptyId)) {
|
|
url = "?id=" + itemId;
|
|
isNewItem = false;
|
|
}
|
|
|
|
$('#editReload').html("");
|
|
$('#editCalendarItem').off('hide.bs.modal').off('hidden.bs.modal').off('shown.bs.modal');
|
|
|
|
$.ajax({
|
|
url: '@Url.Action("EditCalendar", "Calendar")' + url,
|
|
cache: false,
|
|
dataType: "html",
|
|
success: function (data) {
|
|
$('#editReload').html(data);
|
|
initEditCalendarForm();
|
|
|
|
$('#editCalendarItem')
|
|
.on('hidden.bs.modal', function () {
|
|
if (!isNewItem) {
|
|
StopEdit();
|
|
RemoveLock('FiscalCalendarSettings', itemId);
|
|
}
|
|
})
|
|
.on('hide.bs.modal', function (e) {
|
|
var result = true;
|
|
|
|
if ($(e.target).attr('id') == 'editCalendarItem') {
|
|
// check that form has been changed
|
|
if (calendarFormDataChanged) {
|
|
// ask user for confirmation of form close
|
|
//if (!confirm("Form contains unsaved changes, do you want to close the form?")) {
|
|
// // reset change indicator
|
|
// result = false;
|
|
//};
|
|
|
|
bootbox.confirm({
|
|
message: 'Form contains unsaved changes, do you want to close the form?',
|
|
callback: function (result) {
|
|
if (result) {
|
|
calendarFormDataChanged = false;
|
|
|
|
$('#editCalendarItem').modal("hide");
|
|
}
|
|
}
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
|
}
|
|
|
|
return result;
|
|
})
|
|
.modal('show');
|
|
},
|
|
error: function () {
|
|
showErrorModal();
|
|
},
|
|
complete: function () {
|
|
unblockUI();
|
|
},
|
|
});
|
|
}
|
|
|
|
function showCalendarHistory() {
|
|
blockUI();
|
|
|
|
$('#calendarTableReload').html("");
|
|
$.ajax({
|
|
url: '@Url.Action("ViewCalendarHistory", "Calendar")',
|
|
cache: false,
|
|
dataType: "html",
|
|
success: function (data) {
|
|
$('#calendarTableReload').html(data);
|
|
$('#viewCalendarHistory').modal('show');
|
|
},
|
|
error: function () {
|
|
showErrorModal();
|
|
},
|
|
complete: function () {
|
|
unblockUI();
|
|
},
|
|
});
|
|
}
|
|
|
|
function getMonthName(id) {
|
|
var result = "";
|
|
if (!$.isNumeric(id))
|
|
return result;
|
|
|
|
switch (Number(id)) {
|
|
case 1: result = "January"; break;
|
|
case 2: result = "February"; break;
|
|
case 3: result = "March"; break;
|
|
case 4: result = "April"; break;
|
|
case 5: result = "May"; break;
|
|
case 6: result = "June"; break;
|
|
case 7: result = "July"; break;
|
|
case 8: result = "August"; break;
|
|
case 9: result = "September"; break;
|
|
case 10: result = "October"; break;
|
|
case 11: result = "November"; break;
|
|
case 12: result = "December"; break;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
function getWeekday(id) {
|
|
var result = "";
|
|
if (!$.isNumeric(id))
|
|
return result;
|
|
|
|
switch (Number(id)) {
|
|
case 0: result = "Sun"; break;
|
|
case 1: result = "Mon"; break;
|
|
case 2: result = "Tue"; break;
|
|
case 3: result = "Wed"; break;
|
|
case 4: result = "Thi"; break;
|
|
case 5: result = "Fri"; break;
|
|
case 6: result = "Sat"; break;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
function getReccurenceAsText(dataJson) {
|
|
var result = "";
|
|
|
|
if (!dataJson || (dataJson.length < 1))
|
|
return result;
|
|
|
|
var rec = JSON.parse(dataJson);
|
|
if (!$.isNumeric(rec['periodOption']))
|
|
return result;
|
|
|
|
switch (Number(rec['periodOption'])) {
|
|
case 1:
|
|
// Daily repeat
|
|
result = "Daily";
|
|
|
|
if (Number(rec['dailyOption']) == 1) {
|
|
// Every N days
|
|
result += ", every " + rec['dailyDay'] + " day(s)";
|
|
}
|
|
if (Number(rec['dailyOption']) == 2) {
|
|
// Every weekday
|
|
result += ", every weekday";
|
|
}
|
|
|
|
break;
|
|
case 2:
|
|
// Weekly repeat
|
|
result = "Weekly, Recur every " + rec['weeklyWeeks'] + " week(s) on ";
|
|
|
|
if (rec['Sunday']) result += "Sunday";
|
|
if (rec['Monday']) result += "Monday";
|
|
if (rec['Tuesday']) result += "Tuesday";
|
|
if (rec['Wednesday']) result += "Wednesday";
|
|
if (rec['Thursday']) result += "Thursday";
|
|
if (rec['Friday']) result += "Friday";
|
|
if (rec['Saturday']) result += "Saturday";
|
|
break;
|
|
case 3:
|
|
// Monthly repeat
|
|
result = "Monthly";
|
|
|
|
if (Number(rec['monthlyOption']) == 1)
|
|
result += ", Date " + rec['monthlyDate'] + " of every " + rec['monthlyMonths'] + " month(s)";
|
|
if (Number(rec['monthlyOption']) == 2) {
|
|
if (rec['monthlyOccurrence'] == '@(HolidayModel.HolidayOccurrence.SameDayEveryYear.ToString())') result += ", Each "
|
|
if (rec['monthlyOccurrence'] == '@(HolidayModel.HolidayOccurrence.FirstDayOfWeek.ToString())') result += ", First ";
|
|
if (rec['monthlyOccurrence'] == '@(HolidayModel.HolidayOccurrence.SecondDayOfWeek.ToString())') result += ", Second ";
|
|
if (rec['monthlyOccurrence'] == '@(HolidayModel.HolidayOccurrence.ThirdDayOfWeek.ToString())') result += ", Third ";
|
|
if (rec['monthlyOccurrence'] == '@(HolidayModel.HolidayOccurrence.FourthDayOfWeek.ToString())') result += ", Fourth ";
|
|
if (rec['monthlyOccurrence'] == '@(HolidayModel.HolidayOccurrence.LastDayOfWeek.ToString())') result += ", Last ";
|
|
|
|
result += getWeekday(rec['monthlyWeek']) + " of every " + rec['monthlyMonth'] + " month(s)";
|
|
}
|
|
break;
|
|
case 4:
|
|
// Yearly repeat
|
|
if ($.isNumeric(rec['yearlyYear']) && (Number(rec['yearlyYear']) == 1))
|
|
result = "Yearly, recur every year on ";
|
|
else
|
|
result = "Yearly, recur every " + rec['yearlyYear'] + " year(s) on ";
|
|
|
|
if (Number(rec['yearlyOption']) == 1) {
|
|
result += getMonthName(rec['yearlyMonth']) + ", " + rec['yearlyMonthNumber'];
|
|
}
|
|
|
|
if (Number(rec['yearlyOption']) == 2) {
|
|
if (rec['yearlyOccurrence'] == '@(HolidayModel.HolidayOccurrence.SameDayEveryYear.ToString())') result += ", Each ";
|
|
if (rec['yearlyOccurrence'] == '@(HolidayModel.HolidayOccurrence.FirstDayOfWeek.ToString())') result += ", First ";
|
|
if (rec['yearlyOccurrence'] == '@(HolidayModel.HolidayOccurrence.SecondDayOfWeek.ToString())') result += ", Second ";
|
|
if (rec['yearlyOccurrence'] == '@(HolidayModel.HolidayOccurrence.ThirdDayOfWeek.ToString())') result += ", Third ";
|
|
if (rec['yearlyOccurrence'] == '@(HolidayModel.HolidayOccurrence.FourthDayOfWeek.ToString())') result += ", Fourth ";
|
|
if (rec['yearlyOccurrence'] == '@(HolidayModel.HolidayOccurrence.LastDayOfWeek.ToString())') result += ", Last ";
|
|
|
|
result += rec['yearlyWeek'] + " of " + getMonthName(rec['yearlyMonth2']);
|
|
}
|
|
|
|
break;
|
|
}
|
|
return result;
|
|
}
|
|
|
|
</script>
|
|
}
|
|
<div class="panel form-horizontal">
|
|
<div class="panel-heading">
|
|
<span class="panel-title">Fiscal Calendar Settings</span>
|
|
</div>
|
|
<div class="panel-body">
|
|
<div id="erorMsgPlaceholderIndex"></div>
|
|
<div class="form-group">
|
|
@Html.HiddenFor(t => t.Id)
|
|
@Html.LabelFor(t => t.CalendarType, new { @class = "col-sm-2 control-label" })
|
|
<div class="col-sm-4 radio">
|
|
<span class="lbl">@Model.CalendarType.ToDisplayValue()</span>
|
|
</div>
|
|
@Html.LabelFor(t => t.StartingPoint, new { @class = "col-sm-2 control-label" })
|
|
<div class="col-sm-4 radio">
|
|
<span class="lbl">@(Model.StartingPoint.HasValue ? Model.StartingPoint.Value.ToShortDateString() : "")</span>
|
|
</div>
|
|
</div>
|
|
<div class="form-group">
|
|
@Html.LabelFor(t => t.WeekendingDay, new { @class = "col-sm-2 control-label" })
|
|
<div class="col-sm-4 radio">
|
|
<span class="lbl">@Model.WeekendingDay.ToDisplayValue()</span>
|
|
</div>
|
|
@Html.LabelFor(t => t.YearType, new { @class = "col-sm-2 control-label" })
|
|
<div class="col-sm-4 radio">
|
|
<span class="lbl">@Model.YearTypeAsText</span>
|
|
</div>
|
|
</div>
|
|
<div class="form-group">
|
|
@Html.LabelFor(t => t.EffectiveChangeDate, new { @class = "col-sm-2 control-label" })
|
|
<div class="col-sm-4 radio">
|
|
<span class="lbl">@(Model.EffectiveChangeDate.HasValue ? Model.EffectiveChangeDate.Value.ToShortDateString() : "")</span>
|
|
</div>
|
|
@if (Model.ValidTo.HasValue)
|
|
{
|
|
@Html.LabelFor(t => t.ValidTo, new { @class = "col-sm-2 control-label accented" })
|
|
<div class="col-sm-4 radio accented">
|
|
<span class="lbl">@(Model.ValidTo.HasValue ? Model.ValidTo.Value.ToShortDateString() : "")</span>
|
|
</div>}
|
|
</div>
|
|
@if (SecurityManager.CheckSecurityObjectPermission(Areas.FiscalCalendar, AccessLevel.Write))
|
|
{
|
|
<div class="form-group" style="margin-bottom: 0;">
|
|
<div class="col-sm-offset-2 col-sm-10">
|
|
<button id="btnEdit" onclick="showCalendarEditDialog()" data-toggle="popover" data-placement="left" class="btn btn-warning popover-warning popover-dark"><i class="fa fa-edit"></i> Edit</button>
|
|
<button id="btnViewHistory" onclick="showCalendarHistory()" data-toggle="popover" data-placement="left" class="btn btn-primary popover-warning popover-dark"><i class="fa fa-eye"></i> View History</button>
|
|
</div>
|
|
</div>
|
|
}
|
|
</div>
|
|
</div>
|
|
|
|
<div class="table-light table-responsive">
|
|
<table cellpadding="0" cellspacing="0" border="0" class="table table-striped table-bordered" id="holidays">
|
|
<thead>
|
|
<tr>
|
|
<th>Name</th>
|
|
<th>Start Date</th>
|
|
<th>End Date</th>
|
|
<th>Working Day</th>
|
|
<th>Recurrences</th>
|
|
<th>Effective Date of Change</th>
|
|
<th>Valid To</th>
|
|
<th></th>
|
|
</tr>
|
|
</thead>
|
|
</table>
|
|
</div>
|
|
|
|
<!-- Modal -->
|
|
<div id="editCalendarItem" class="modal fade" tabindex="-1" role="dialog" style="display: none;">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content" id="editReload">
|
|
|
|
</div> <!-- / .modal-content -->
|
|
</div> <!-- / .modal-dialog -->
|
|
</div> <!-- /.modal -->
|
|
|
|
<div id="viewCalendarHistory" class="modal fade" tabindex="-1" role="dialog" style="display: none;">
|
|
<div class="modal-dialog" id="calendarTableDialog">
|
|
<div class="modal-content" id="calendarTableReload">
|
|
|
|
</div> <!-- / .modal-content -->
|
|
</div> <!-- / .modal-dialog -->
|
|
</div> <!-- /.modal -->
|
|
<!-- Modal -->
|
|
<div id="editHolidayItem" class="modal fade" tabindex="-1" role="dialog" style="display: none;">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content" id="editHolidayReload">
|
|
|
|
</div> <!-- / .modal-content -->
|
|
</div> <!-- / .modal-dialog -->
|
|
</div> <!-- /.modal -->
|
|
<!-- Modal -->
|
|
@*<div id="editRecurrence" class="modal fade" tabindex="-1" role="dialog" style="display: none;" data-backdrop="static">
|
|
<form name="editRecurrenceForm">
|
|
<div class="modal-dialog">
|
|
<div class="modal-content">
|
|
@Html.Partial("_editRecurrence")
|
|
</div> <!-- / .modal-content -->
|
|
</div> <!-- / .modal-dialog -->
|
|
</form>
|
|
</div>*@
|
|
<!-- /.modal -->
|
|
<div id="viewHolidayHistory" class="modal fade" tabindex="-1" role="dialog" style="display: none;">
|
|
<div class="modal-dialog" id="holidayHistoryDialog">
|
|
<div class="modal-content" id="holidayHistoryReload">
|
|
|
|
</div> <!-- / .modal-content -->
|
|
</div> <!-- / .modal-dialog -->
|
|
</div> <!-- /.modal -->
|