2024-03-26 15:56:31 +08:00

575 lines
26 KiB
Plaintext

<%@ Page Title="" Language="C#" MasterPageFile="~/MachineDeviceManagement/DeviceManagementBase.master" AutoEventWireup="true" CodeFile="AddRental.aspx.cs" Inherits="AddRental" %>
<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">
<style type="text/css">
::-ms-clear, ::-ms-reveal {
display: none;
}
.a {
text-decoration: none;
color: #2140fb;
}
.subtitle {
margin: 20px 40px 5px 0px;
font-size: 16px;
color: gray;
}
.subtitle span {
margin-left: 10px;
}
.subtitle hr {
background-color: #d8d8d8;
border: none;
height: 1px;
}
.machinetd {
white-space: nowrap;
text-overflow: ellipsis;
overflow: hidden;
}
</style>
<link href="<%=GetFileUrlWithVersion("../css/jquery.datetimepicker.css")%>" rel="stylesheet" />
<script src="<%=GetFileUrlWithVersion("../Maintenance/js/inputdatactr.js")%>" type="text/javascript"></script>
<script src="<%=GetFileUrlWithVersion("../js/jquery.datetimepicker.full.js")%>"></script>
<script type="text/javascript">
var IsDealer = <%=IsDealer ?"true":"false"%>;
var IsAdmin =<%=IsAdmin ?"true":"false"%>;
var contractorid = "<%=ContractorID %>";
var rentalid = "<%=RentalID %>";
var machineid = "<%=MachineID %>";
var rentalsdata = [];
var machines;
function devicerequest(method, param, callback, error) {
_network.request("MachineDeviceManagement/AddRental.aspx", -1, method, param, callback, error || function (e) {
console.log(e);
showmaskbg(false, true);
showAlert(GetTextByKey('P_MR_PAGEERROR', 'An unknown error occurred. Please refresh page.'), GetTextByKey('P_MR_QUERY', 'Query'));
});
}
function OnAdd() {
$('#dialog_machine').val('');
$('#dialog_outside').val('');
$('#dialog_vendor').val('');
$('#dialog_rentalrate').val('');
$('#dialog_term').val('');
$('#dialog_termunit').val('');
$('#dialog_rentaldata').val('');
$('#dialog_projectreturndate').val('');
$('#dialog_returndate').val('');
$('#dialog_ponumber').val('');
$('#dialog_comments').val('');
$('#dialog_rentaltermbillingdate').val('');
$('#dialog_billingcycledays').val('');
$('#dialog_insuredvalue').val('');
$('#dialog_name').focus();
}
function getRentalInfo() {
showloading(true);
devicerequest("GetRentalInfo", contractorid + String.fromCharCode(170) + rentalid, function (data) {
showloading(false);
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_MR_ERROR", 'Error'));
return;
}
var rental = data;
$('#dialog_machine').attr('disabled', true);
$('#dialog_machine').val(rental.MachineID);
setMachineInfo();
$('#dialog_outside').val(rental.Outside);
$('#dialog_vendor').val(rental.Vendor);
$('#dialog_rentalrate').val(rental.RentalRate);
$('#dialog_term').val(rental.Term);
$('#dialog_termunit').val(rental.TermUnit);
$('#dialog_rentaldata').val(rental.RentalDateStr);
$('#dialog_projectreturndate').val(rental.ProjectReturnDateStr);
$('#dialog_returndate').val(rental.ReturnDateStr);
$('#dialog_ponumber').val(rental.PONumber);
$('#dialog_comments').val(rental.Comments);
$('#dialog_rentaltermbillingdate').val(rental.RentalTermBillingDateStr);
$('#dialog_billingcycledays').val(rental.BillingCycleDays < 0 ? "" : rental.BillingCycleDays);
$('#dialog_insuredvalue').val(rental.InsuredValue);
}, function (err) {
console.log(err);
showloading(false);
});
}
function setMachineInfo() {
var machineid = $('#dialog_machine').val();
if (machineid) {
var machine = $('#dialog_machine option:selected').data('machine');
$('#dialog_vin').text(machine.VIN);
$('#dialog_make').text(machine.Make);
$('#dialog_model').text(machine.Model);
$('#dialog_type').text(machine.MachineType);
getRentals(machine.MachineID);
}
}
function OnEdit() {
getRentalInfo();
$('#dialog_name').focus();
}
var IsInteger = /^[0-9]+$/;
function OnSave(exit) {
var item = {
'Outside': $('#dialog_outside').val(),
'Vendor': $('#dialog_vendor').val(),
'RentalRate': $('#dialog_rentalrate').val(),
'Term': $('#dialog_term').val(),
'TermUnit': $('#dialog_termunit').val(),
'RentalDate': $('#dialog_rentaldata').val(),
'ProjectReturnDate': $('#dialog_projectreturndate').val(),
'ReturnDate': $('#dialog_returndate').val(),
'PONumber': $('#dialog_ponumber').val(),
'Comments': $('#dialog_comments').val(),
'MachineID': $('#dialog_machine').val(),
'RentalTermBillingDate': $('#dialog_rentaltermbillingdate').val(),
'BillingCycleDays': $('#dialog_billingcycledays').val(),
'InsuredValue': $('#dialog_insuredvalue').val()
};
var alerttitle;
if (rentalid) {
item.RentalID = rentalid;
alerttitle = GetTextByKey("P_MA_EDITRENTAL", "Edit Rental");
} else {
item.RentalID = -1;
alerttitle = GetTextByKey("P_MA_ADDRENTAL", "Add Rental");
}
if (!item.MachineID) {
showAlert(GetTextByKey("P_MR_ASSETNOTEMPTY", 'Asset cannot be empty.'), alerttitle);
$('#dialog_machine').focus();
return;
}
if (item.RentalRate !== "" && isNaN(item.RentalRate)) {
showAlert(GetTextByKey("P_MR_RENTALRATEFORMATERROR", 'Rental Rate format error.'), alerttitle);
return;
}
if (item.RentalRate === "") {
item.RentalRate = 0;
}
if (item.Term === "") {
item.Term = 0;
}
if (isNaN(item.Term) || !IsInteger.test(item.Term) || eval(item.Term) < 0) {
showAlert(GetTextByKey("P_MR_RENTALTERMMUSTBEANINTEGEREQUALTOORGREATERTHAN0", 'Rental Term must be an integer equal to or greater than 0. '), alerttitle);
return;
}
if (item.RentalDate.length <= 0) {
showAlert(GetTextByKey("P_MR_RENTALDATECANNOTBEEMPTY", 'Rental Date cannot be empty.'), alerttitle);
$('#dialog_rentaldata').focus();
return;
}
if (item.BillingCycleDays !== "") {
if (isNaN(item.BillingCycleDays) || !IsInteger.test(item.BillingCycleDays) || eval(item.BillingCycleDays) < 0) {
showAlert(GetTextByKey("P_MR_THENUMBEROFDAYSINBILLINGCYCLEMUSTBEANINTEGEREQUALTOORGREATERTHAN0", 'The Number of Days in Billing Cycle must be an integer equal to or greater than 0.'), alerttitle);
return;
}
}
else
item.BillingCycleDays = -1;
if (item.InsuredValue !== "" && isNaN(item.InsuredValue)) {
showAlert(GetTextByKey("P_MR_INSUREDVALUEFORMATERROR", 'Insured Value format error.'), alerttitle);
return;
}
if (item.InsuredValue === "") {
item.InsuredValue = 0;
}
var rentaldate = new Date(item.RentalDate.replace("-", "/"));
var pjdate = new Date(item.ProjectReturnDate.replace("-", "/"));
var returndate = new Date(item.ReturnDate.replace("-", "/"));
if (rentaldate > pjdate) {
showAlert(GetTextByKey("P_MR_PROJRETURNDATEMUSTBELATERTHANRENTALDATE", "Proj. Return Date must be later than than Rental Date."), alerttitle);
return false;
}
if (rentaldate > returndate) {
showAlert(GetTextByKey("P_MR_RETURNDATEBELATERRENTALDATE", "Return Date must be later than Rental Date."), alerttitle);
return false;
}
showloading(true);
var param = JSON.stringify(item);
param = htmlencode(param);
var alerttitle = GetTextByKey("P_MR_SAVERENTAL", 'Save Rental');
devicerequest("SaveRental", contractorid + String.fromCharCode(170) + param, function (data) {
showloading(false);
if (typeof (data) === "string") {
if (data === "Rental dates entered overlap with another entry. Please adjust the dates.")
data = GetTextByKey("P_MR_RENTALDATESENTEREDOVERLAPWITHANOTHERENTRY", "Rental dates entered overlap with another entry. Please adjust the dates.");
showAlert(data, alerttitle);
} else {
rentalid = data;
if (exit == 0) {
showAlert(GetTextByKey("P_MR_SAVSUCCESSFULLY", "Saved successfully."), alerttitle);
var machineid = $('#dialog_machine').val();
if (machineid) {
getRentals(machineid);
}
}
if (exit == 1)
OnExit(exit);
else
$('#dialog_machine').attr('disabled', true);
}
}, function (err) {
console.log(err);
showloading(false);
showAlert(GetTextByKey("P_MR_FAILEDTOSAVERENTAL", 'Failed to save Rental.'), alerttitle);
});
}
function OnExit(type) {
window.parent.CloseDialog(type);
}
function GetMachines(next) {
devicerequest("GetSelectMachinesByRental", contractorid, function (data) {
if (data && data.length > 0) {
machines = data;
var sel_machine = $('#dialog_machine').empty();
sel_machine.append('<option value=""></option>');
for (var i = 0; i < data.length; i++) {
var machine = data[i];
var op = $('<option></option>').val(machine.MachineID).text(machine.DisplayName).data('machine', machine);
sel_machine.append(op);
}
if (machineid !== undefined) {
$('#dialog_machine').val(machineid);
setMachineInfo();
}
}
if (next)
next();
}, function (err) {
});
}
function init() {
if (rentalid !== undefined && rentalid !== '') {
GetMachines(OnEdit);
}
else {
$('#span_a').css('display', 'none');
GetMachines();
OnAdd();
$('#dialog_machine').attr('disabled', false);
}
}
$(function () {
init();
$('#dialog_machine').change(function () {
setMachineInfo();
});
$('#dialog_rentaldata').datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false,
onSelectDate: function (v, inp) {
var date = new DateFormatter().formatDate(v, 'm/d/Y 00:00:00');
inp.parent().data('val', [date]);
}
});
$('#dialog_projectreturndate').datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false,
onSelectDate: function (v, inp) {
var date = new DateFormatter().formatDate(v, 'm/d/Y 00:00:00');
inp.parent().data('val', [date]);
}
});
$('#dialog_returndate').datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false,
onSelectDate: function (v, inp) {
var date = new DateFormatter().formatDate(v, 'm/d/Y 00:00:00');
inp.parent().data('val', [date]);
}
});
$('#dialog_rentaltermbillingdate').datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false,
onSelectDate: function (v, inp) {
var date = new DateFormatter().formatDate(v, 'm/d/Y 00:00:00');
inp.parent().data('val', [date]);
}
});
function resizeContent() {
$('#divcontent').css('height', $(window).height() - $('#divcontent').offset().top - 4);
$('.content_main').css('min-height', 0);
}
window.onresize = resizeContent;
resizeContent();
//$("#rentalsDiv").scroll(null, function (e) {
// var t = $(e.target);
// $('#tbRentals').css('margin-left', - (t.scrollLeft()));
//});
});
function getRentals(mid) {
$("#rentalListDiv").hide();
$("#lblRentalHistory").hide();
devicerequest("SearchRentals", contractorid + String.fromCharCode(170) + ""
+ String.fromCharCode(170) + '1900-1-1' + String.fromCharCode(170) + '2099-1-1'
+ String.fromCharCode(170) + mid, function (data) {
$('#tbody_rentals').empty();
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_MR_ERROR", 'Error'));
return;
}
if (data && data.length > 0) {
rentalsdata = data;
$("#rentalListDiv").show();
$("#lblRentalHistory").show();
}
else
rentalsdata = [];
sortTableData($('#tbRentals'), rentalsdata);
showRentals(rentalsdata);
}, function (err) {
});
}
function showRentals(data) {
var trs = [];
for (var i = 0; i < data.length; i++) {
var rental = data[i];
var tr = $('<tr></tr>').data('rental', rental);
tr.append($('<td class="machinetd" style="width: 10%;""></td>').html(getLangOutside(rental.Outside)));
tr.append($('<td class="machinetd" style="width: 10%;""></td>').html(replaceHtmlText(rental.Vendor)));
tr.append($('<td class="machinetd" style="width: 8%;""></td>').text(rental.RentalRate));
tr.append($('<td class="machinetd" style="width: 8%;""></td>').text(rental.Term));
tr.append($('<td class="machinetd" style="width: 8%;""></td>').text(getLangTermUnit(rental.TermUnit)));
tr.append($('<td class="machinetd" style="width: 8%;">"></td>').text(rental.RentalDateStr));
tr.append($('<td class="machinetd" style="width: 8%;""></td>').text(rental.ProjectReturnDateStr));
tr.append($('<td class="machinetd" style="width: 8%;""></td>').text(rental.ReturnDateStr));
tr.append($('<td class="machinetd" style="width: 8%;""></td>').html(replaceHtmlText(rental.PONumber)));
tr.append($('<td style="width: 24%;""></td>').attr('title', rental.Comments).html(replaceHtmlText(rental.Comments)));
trs.push(tr);
}
$('#tbody_rentals').append(trs);
}
function getLangTermUnit(text) {
var langtext = text;
if (text === "Hourly")
langtext = GetTextByKey("P_MR_HOURLY", "Hourly");
else if (text === "Daily")
langtext = GetTextByKey("P_MR_DAILY", "Daily");
else if (text === "Weekly")
langtext = GetTextByKey("P_MR_WEEKLY", "Weekly");
else if (text === "Monthly")
langtext = GetTextByKey("P_MR_MONTHLY", "Monthly");
else if (text === "Annually")
langtext = GetTextByKey("P_MR_ANNUALLY", "Annually");
return langtext;
}
function getLangOutside(text) {
var langtext = text;
if (text === "Inside")
langtext = GetTextByKey("P_MR_INSIDE", "Inside");
else if (text === "Outside")
langtext = GetTextByKey("P_MR_OUTSIDE", "Outside");
return langtext;
}
function OnViewChangeHistory() {
window.open("RentalChangeHistory.aspx?cid=" + contractorid + "&mid=" + machineid + "&rid=" + rentalid + "");
}
</script>
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="ContentPlaceHolder1" runat="Server">
<div id="mask_bg" style="display: none;">
<div class="loading c-spin"></div>
</div>
<div>
<div class="function_title">
<span class="sbutton iconsave" onclick="OnSave(0);" data-lgid="P_MR_SAVE">Save</span>
<span class="sbutton iconsave" onclick="OnSave(1);" data-lgid="P_MR_SAVE1">Save and Exit</span>
<span class="sbutton iconexit" onclick="OnExit(0);" data-lgid="P_MR_SAVE2">Exit Without Saving</span>
</div>
<div class="clear"></div>
<div id="divcontent" style="overflow: auto;">
<div class="edit-content">
<div class="subtitle">
<span data-lgid="P_MR_ASSETINFORMATION">Asset Information</span>
<hr />
</div>
<table>
<tr>
<td class="label" data-lgid="P_MR_ASSET_COLON">Asset:</td>
<td colspan="4">
<select id="dialog_machine" style="width: 322px; height: 22px;" tabindex="1" disabled="disabled"></select>
</td>
</tr>
<tr>
<td class="label" data-lgid="P_MR_VIN_COLON">VIN:</td>
<td id="dialog_vin" style="width: 200px;"></td>
<td class="label" style="width: 60px;" data-lgid="P_MR_ASSETTYPE_COLON">Type:</td>
<td id="dialog_type" style="width: 200px;"></td>
<td></td>
</tr>
<tr>
<td class="label" data-lgid="P_MR_MAKE_COLON">Make:</td>
<td id="dialog_make" style="width: 200px;"></td>
<td class="label" style="width: 60px;" data-lgid="P_MR_MODEL_COLON">Model:</td>
<td id="dialog_model" style="width: 200px;"></td>
<td></td>
</tr>
</table>
<div class="subtitle">
<span data-lgid="P_MR_RENTALINFORMATION">Rental Information</span>
<hr />
</div>
<table>
<tr>
<td class="label" data-lgid="P_MR_OUTSIDEINTERNAL_COLON">Outside/Internal:</td>
<td>
<select id="dialog_outside" style="width: 324px; height: 22px;" tabindex="4">
<option value=""></option>
<option value="Inside" data-lgid="P_MR_INSIDE">Inside</option>
<option value="Outside" data-lgid="P_MR_OUTSIDE">Outside</option>
</select>
</td>
</tr>
<tr>
<td class="label" data-lgid="P_MR_RENTALVENDOR_COLON">Rental Vendor:</td>
<td>
<input type="text" id="dialog_vendor" maxlength="200" tabindex="6" /></td>
</tr>
<tr>
<td class="label" data-lgid="P_MR_RENTALRATE_COLON">Rental Rate:</td>
<td>
<input type="text" id="dialog_rentalrate" maxlength="12" tabindex="7" /></td>
</tr>
<tr>
<td class="label" data-lgid="P_MR_RETURNTERM_COLON">Rental Term:</td>
<td>
<input type="text" id="dialog_term" maxlength="8" tabindex="8" /></td>
</tr>
<tr>
<td class="label" data-lgid="P_MR_RENTALTERMUNIT_COLON">Rental Term Unit:</td>
<td>
<select id="dialog_termunit" style="width: 324px; height: 22px;" tabindex="9">
<option value="Hourly" data-lgid="P_MR_HOURLY">Hourly</option>
<option value="Daily" data-lgid="P_MR_DAILY">Daily</option>
<option value="Weekly" data-lgid="P_MR_WEEKLY">Weekly</option>
<option value="Monthly" data-lgid="P_MR_MONTHLY">Monthly</option>
<option value="Annually" data-lgid="P_MR_ANNUALLY">Annually</option>
</select>
</td>
</tr>
<tr>
<td class="label" data-lgid="P_MR_RTBILLINGDATE_COLON">Rental Term Billing Date:</td>
<td>
<input type="text" id="dialog_rentaltermbillingdate" maxlength="50" tabindex="9" /></td>
</tr>
<tr>
<td class="label" data-lgid="P_MR_DAYSBILLINGCYCLE_COLON">Number of Days in Billing Cycle:</td>
<td>
<input type="text" id="dialog_billingcycledays" maxlength="8" tabindex="9" /></td>
</tr>
<tr>
<td class="label" data-lgid="P_MR_RENTALDATEON_COLON">Rental Date On:</td>
<td>
<input type="text" id="dialog_rentaldata" maxlength="50" tabindex="10" /></td>
</tr>
<tr>
<td class="label" data-lgid="P_MR_PROJECTRETURNDATE_COLON">Proj.Return Date:</td>
<td>
<input type="text" id="dialog_projectreturndate" maxlength="50" tabindex="11" /></td>
</tr>
<tr>
<td class="label" data-lgid="P_MR_RETURNDATE_COLON">Return Date:</td>
<td>
<input type="text" id="dialog_returndate" maxlength="50" tabindex="12" /></td>
</tr>
<tr>
<td class="label" data-lgid="P_MR_PONUMBER_COLON">P.O.#:</td>
<td>
<input type="text" id="dialog_ponumber" maxlength="100" tabindex="13" /></td>
</tr>
<tr>
<td class="label" data-lgid="P_MR_INSUREDVALUE_COLON">Insured Value:</td>
<td>
<input type="text" id="dialog_insuredvalue" maxlength="13" tabindex="68" autocomplete="off" /></td>
</tr>
<tr>
<td class="label" data-lgid="P_MR_COMMENTS_COLON">Comments:</td>
<td>
<textarea id="dialog_comments" maxlength="1000" tabindex="14" style="width: 540px; height: 120px;"></textarea>
<span id="span_a" style="margin-left: 50px;"><a href="#" onclick="OnViewChangeHistory();" data-lgid="P_MR_VIEWCHANGEHIS">View Change History</a></span>
</td>
</tr>
</table>
</div>
<div id="lblRentalHistory" class="subtitle" style="display: none;">
<span data-lgid="P_MR_RENTALHISTORY">Rental History</span>
</div>
<div class="content_main" id="rentalListDiv" style="max-height: 500px; margin-top: 10px; display: none;">
<div>
<table id="tbRentals" class="main_table" style="width: 100%; table-layout: fixed;">
<thead>
<tr>
<th style="width: 10%;" sort="Outside" data-lgid="P_MR_OUTSIDEINTERNAL">Outside/Internal</th>
<th style="width: 10%;" sort="Vendor" data-lgid="P_MR_RENTALVENDOR">Rental Vendor</th>
<th style="width: 8%;" sort="RentalRate" data-lgid="P_MR_RENTALRATE">Rental Rate</th>
<th style="width: 8%;" sort="Term" data-lgid="P_MR_TERM">Term</th>
<th style="width: 8%;" sort="TermUnit" data-lgid="P_MR_TERMUNIT">Term Unit</th>
<th style="width: 8%;" sort="RentalDate" data-lgid="P_MR_RENTALDATEON">Rental Date On</th>
<th style="width: 8%;" sort="ProjectReturnDate" data-lgid="P_MR_PROJECTEDRETURN">Projected Return</th>
<th style="width: 8%;" sort="ReturnDate" data-lgid="P_MR_RETURNDATE">Return Date</th>
<th style="width: 8%;" sort="PONumber" data-lgid="P_MR_PURCHASEORDERN">Purchase Order #</th>
<th style="width: 24%;" sort="Comments" data-lgid="P_MR_COMMENTS">Comments</th>
</tr>
</thead>
</table>
</div>
<div id="rentalsDiv" class="content_main">
<table class="main_table" style="min-width: 200px; width: 100%; table-layout: fixed;">
<tbody id="tbody_rentals">
</tbody>
</table>
</div>
</div>
</div>
</div>
</asp:Content>