function pad(num, n) {
if (!num || isNaN(num))
return num;
return Array(n > num.length ? (n - num.length + 1) : 0).join(0) + num;
}
function showWorkOrders(wos) {
var rows = [];
for (var i = 0; i < wos.length; i++) {
var r = wos[i];
for (var j in r) {
if (j === "Id") {
r[j] = { DisplayValue: r["Id"] > 0 ? r["Id"] : "MR", Value: r[j] };
}
else if (j === "WorkOrderNumber") {
r[j] = { DisplayValue: r["WorkOrderNumber"], Value: pad(r[j], 50) };
}
else if (j === "DueDate") {
r[j] = { DisplayValue: r["DueDateStr"], Value: r[j] };
}
else if (j === "CompleteDate") {
r[j] = { DisplayValue: r["CompleteDateStr"], Value: r[j] };
}
else if (j === "NextFollowUpDate") {
r[j] = { DisplayValue: r["NextFollowUpDateStr"], Value: r[j] };
}
else if (j === "CreateDate") {
r[j] = { DisplayValue: r["CreateDateStr"], Value: r[j] };
}
else if (j === "CreationDate") {
r[j] = { DisplayValue: r["CreationDateStr"], Value: r[j] };
}
else if (j === "LastCommunicationDate") {
r[j] = { DisplayValue: r["LastCommunicationDateStr"], Value: r[j] };
}
else if (j === "LastInternalCommunicationDate") {
r[j] = { DisplayValue: r["LastInternalCommunicationDateStr"], Value: r[j] };
}
else if (j === "PartsExpectedDate") {
r[j] = { DisplayValue: r["PartsExpectedDateStr"], Value: r[j] };
}
else if (j === "LastLaborDate") {
r[j] = { DisplayValue: r["LastLaborDateStr"], Value: r[j] };
}
else if (j === "InspectionRequired") {
r[j] = { DisplayValue: r["InspectionRequired"] ? "Yes" : "No", Value: r[j] };
}
else if (j === "AutoText") {
r[j] = { DisplayValue: r["AutoText"] ? "Yes" : "No", Value: r[j] };
}
else if (j === "WorkOrderType") {
var wotype = r[j];
if (wotype == "Maintenance Expense")
wotype = GetTextByKey("P_WO_MAINTENANCEEXPENSE", "Maintenance Expense");
else if (wotype == "Repair Expense")
wotype = GetTextByKey("P_WO_REPAIREXPENSE", "Repair Expense");
else if (wotype == "Capitalized Expense")
wotype = GetTextByKey("P_WO_CAPITALIZEDEXPENSE", "Capitalized Expense");
r[j] = wotype;
}
else if (j === "EstimateStatus") {
r[j] = getEstimateStatus(r[j]);
}
else if (j === "Billable") {
r[j] = { DisplayValue: r.Id > 0 ? (r["Billable"] ? "Yes" : "No") : "", Value: r[j] };
}
if (r.MaintenanceID && (j === "InspectionCount" || j === "InspectionRequired" || j === "EstimateStatus"
|| j === "PublishedEstimates" || j === "ApprovedEstimates" || j === "RejectedEstimates" || j === "PendingEstimates"
|| j === "AutoText" || j === "Billable")) {
r[j] = { DisplayValue: "", Value: r[j] };
}
}
var fr = { Values: r };
rows.push(fr);
}
grid_dt.virtualCount = 30;
grid_dt.setData(rows);
}
function getEstimateStatus(s) {
var text = "";
if (s === 0)
text = GetTextByKey('P_WO_DRAFT', 'Draft');
else if (s === 1)
text = GetTextByKey('P_WO_AWAITINGCUSTOMERAPPROVAL', 'Awaiting Customer Approval');
else if (s === 2)
text = GetTextByKey('P_WO_CANCELLEDBYDEALER', 'Cancelled by Dealer');
else if (s === 3)
text = GetTextByKey('P_WO_CUSTOMERREJECTED', 'Customer Rejected');
else if (s === 4)
text = GetTextByKey('P_WO_CUSTOMERAPPROVED', 'Customer Approved');
else if (s === 100)
text = "";
return text;
}
function OnResetPivots() {
if (grid_dt && grid_dt.columns) {
for (var i = 0; i < grid_dt.columns.length; i++) {
if (grid_dt.columns[i].filterValues)
grid_dt.columns[i].filterValues = null;
}
grid_dt.refreshGrid();
}
}
var grid_dt;
function InitGridData() {
grid_dt = new GridView('#workorderlist');
grid_dt.lang = {
all: GetTextByKey("P_GRID_ALL", "(All)"),
ok: GetTextByKey("P_GRID_OK", "OK"),
reset: GetTextByKey("P_GRID_RESET", "Reset")
};
grid_dt.isEditable = true;
var list_columns = [
{ name: 'Id', caption: GetTextByKey("P_WO_WORKORDERNUMBER", "Work Order Number"), valueIndex: 'WorkOrderNumber', allowFilter: true, css: { 'width': 130, 'text-align': 'left' } },
{ name: 'WorkOrderType', caption: GetTextByKey("P_WO_WORKORDERTYPE", "Work Order Type"), valueIndex: 'WorkOrderType', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
{ name: 'AssignedToName', caption: GetTextByKey("P_WO_ASSIGNEDTO", "Assigned To"), valueIndex: 'AssignedToName', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
{ name: 'StatusName', caption: GetTextByKey("P_WO_STATUS", "Status"), valueIndex: 'StatusName', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
{ name: 'Description', caption: GetTextByKey("P_WO_DESCRIPTION", "Description"), valueIndex: 'Description', allowFilter: true, css: { 'width': 320, 'text-align': 'left' } },
{ name: 'AssetName', caption: GetTextByKey("P_WO_ASSET", "Asset"), valueIndex: 'AssetName', allowFilter: true, css: { 'width': 200, 'text-align': 'left' } },
{ name: 'VIN', caption: GetTextByKey("P_WO_VIN", "VIN"), valueIndex: 'VIN', allowFilter: true, css: { 'width': 200, 'text-align': 'left' } },
{ name: 'Make', caption: GetTextByKey("P_WO_MAKE", "Make"), valueIndex: 'Make', allowFilter: true, css: { 'width': 100, 'text-align': 'left' } },
{ name: 'Model', caption: GetTextByKey("P_WO_MODEL", "Model"), valueIndex: 'Model', allowFilter: true, css: { 'width': 100, 'text-align': 'left' } },
{ name: 'CustomerCode', caption: GetTextByKey("P_WO_CUSTOMERCODE", "Customer Code"), valueIndex: 'CustomerCode', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
{ name: 'Customer', caption: GetTextByKey("P_CR_COMPANYNAME", "Company Name"), valueIndex: 'CustomerName', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
{ name: 'LastCommunication', caption: GetTextByKey("P_WO_LASTCOMMUNICATIONTEXT", "Last Communication Text"), valueIndex: 'LastCommunication', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
{ name: 'LastCommunicationBy', caption: GetTextByKey("P_WO_LASTCOMMUNICATIONBY", "Last Communication By"), valueIndex: 'LastCommunicationBy', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
{ name: 'LastCommunicationDate', caption: GetTextByKey("P_WO_LASTCOMMUNICATIONDATE", "Last Communication Date"), valueIndex: 'LastCommunicationDate', allowFilter: true, css: { 'width': 155, 'text-align': 'left' } },
{ name: 'Department', caption: GetTextByKey("P_WO_DEPARTMENT", "Department"), valueIndex: 'Department', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
{ name: 'Location', caption: GetTextByKey("P_WO_LOCATION", "Location"), valueIndex: 'Location', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
{ name: 'Advisor', caption: GetTextByKey("P_WO_ADVISOR", "Advisor"), valueIndex: 'AdvisorName', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
{ name: 'SalespersonName', caption: GetTextByKey("P_WO_XXX", "Salesperson"), valueIndex: 'SalespersonName', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
{ name: 'CurrentJobsites', caption: GetTextByKey("P_WO_CURRJOBSITE", "Current Jobsite"), valueIndex: 'CurrentJobsites', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
{ name: 'CreateDate', caption: GetTextByKey("P_WO_CREATEDDATE", "Created Date"), valueIndex: 'CreateDate', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
{ name: 'CreationDate', caption: GetTextByKey("P_WO_CREATIONDATE", "Creation Date"), valueIndex: 'CreationDate', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
{ name: 'DueDate', caption: GetTextByKey("P_WO_DUEDATE", "Due Date"), valueIndex: 'DueDate', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
{ name: 'NextFollowUpDate', caption: GetTextByKey("P_WO_NEXTFOLLOWUPDATE", "Next Follow Up Date"), valueIndex: 'NextFollowUpDate', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
{ name: 'PartsExpectedDate', caption: GetTextByKey("P_WO_PARTSEXPECTEDDATE", "Parts Expected Date"), valueIndex: 'PartsExpectedDate', allowFilter: true, css: { 'width': 130, 'text-align': 'right' } },
{ name: 'LastLaborDate', caption: GetTextByKey("P_WO_LASTLABORDATE", "Last Labor Date"), valueIndex: 'LastLaborDate', allowFilter: true, css: { 'width': 120, 'text-align': 'right' } },
{ name: 'CompleteDate', caption: GetTextByKey("P_WO_COMPLETEDDATE", "Completed Date"), valueIndex: 'CompleteDate', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
{ name: 'InvoiceNumber', caption: GetTextByKey("P_WO_INVOICENUMBER", "Invoice Number"), valueIndex: 'InvoiceNumber', allowFilter: true, css: { 'width': 200, 'text-align': 'left' } },
{ name: 'AlternateStatus', caption: GetTextByKey("P_WO_ALTERNATESTATUS", "Alternate Status"), valueIndex: 'AlternateStatus', allowFilter: true, css: { 'width': 140, 'text-align': 'left' } },
{ name: 'InspectionCount', caption: GetTextByKey("P_WO_INSPECTIONS", "Inspections"), valueIndex: 'InspectionCount', allowFilter: true, css: { 'width': 110, 'text-align': 'right' } },
{ name: 'InspectionRequired', caption: GetTextByKey("P_WO_INSPECTIONREQUIRED", "Inspection Required"), valueIndex: 'InspectionRequired', type: 3, allowFilter: true, css: { 'width': 140, 'text-align': 'center' } },
{ name: 'AutoText', caption: GetTextByKey("P_WO_AUTOSENDCOMMUNICATIONENABLED", "Auto-send Communication Enabled"), valueIndex: 'AutoText', type: 3, allowFilter: true, css: { 'width': 140, 'text-align': 'center' } },
{ name: 'Notes', caption: GetTextByKey("P_WO_NOTES", "Notes"), valueIndex: 'Notes', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
{ name: 'Contacts', caption: GetTextByKey("P_WO_CONTACTS", "Contacts"), valueIndex: 'Contacts', css: { 'width': 200, 'text-align': 'left' } },
{ name: 'EstimateStatus', caption: GetTextByKey("P_WO_ESTIMATESTATUS", "Estimate Status"), allowFilter: true, valueIndex: 'EstimateStatus', css: { 'width': 180, 'text-align': 'left' } },
{ name: 'PublishedEstimates', caption: GetTextByKey("P_WO_PUBLISHEDESTIMATES", "Published Estimates"), valueIndex: 'PublishedEstimates', allowFilter: true, css: { 'width': 110, 'text-align': 'right' } },
{ name: 'ApprovedEstimates', caption: GetTextByKey("P_WO_APPROVEDESTIMATES", "Approved Estimates"), valueIndex: 'ApprovedEstimates', allowFilter: true, css: { 'width': 110, 'text-align': 'right' } },
{ name: 'RejectedEstimates', caption: GetTextByKey("P_WO_REJECTEDESTIMATES", "Rejected Estimates"), valueIndex: 'RejectedEstimates', allowFilter: true, css: { 'width': 110, 'text-align': 'right' } },
{ name: 'PendingEstimates', caption: GetTextByKey("P_WO_PENDINGESTIMATES", "Pending Estimates"), valueIndex: 'PendingEstimates', allowFilter: true, css: { 'width': 110, 'text-align': 'right' } },
{ name: 'Component', caption: GetTextByKey("P_WO_XXXXXX", "Component"), valueIndex: 'Component', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
{ name: 'Billable', caption: GetTextByKey("P_WO_XXXXXX", "Billable"), valueIndex: 'Billable', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
{ name: 'BillToJob', caption: GetTextByKey("P_WO_XXXXXX", "Bill to job"), valueIndex: 'BillToJobName', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
{ name: 'PartsOrderNumber', caption: GetTextByKey("P_WO_XXXXXX", "Parts Order Number"), valueIndex: 'PartsOrderNumber', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
{ name: 'PartsStatus', caption: GetTextByKey("P_WO_XXXXXX", "Parts Status"), valueIndex: 'PartsStatus', allowFilter: true, css: { 'width': 120, 'text-align': 'left' } },
{ name: 'LastInternalCommunication', caption: GetTextByKey("P_WO_XXXXXX", "Last Internal Communication"), valueIndex: 'LastInternalCommunication', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
{ name: 'LastInternalCommunicationBy', caption: GetTextByKey("P_WO_XXXXXX", "Last Internal Communication By"), valueIndex: 'LastInternalCommunicationBy', allowFilter: true, css: { 'width': 150, 'text-align': 'left' } },
{ name: 'LastInternalCommunicationDate', caption: GetTextByKey("P_WO_XXXXXX", "Last Internal Communication Date"), valueIndex: 'LastInternalCommunicationDate', allowFilter: true, css: { 'width': 155, 'text-align': 'left' } },
{ name: 'Edit', caption: "", alwaysshow: true, css: { 'width': 30, 'text-align': 'center' } },
{ name: 'Print', caption: "", alwaysshow: true, css: { 'width': 30, 'text-align': 'center' } },
{ name: 'Delete', caption: "", alwaysshow: true, css: { 'width': 30, 'text-align': 'center' } },
{ name: 'AssetAlert', caption: "", alwaysshow: true, css: { 'width': 30, 'text-align': 'center' } }
//{ name: 'Surveys', caption: "", alwaysshow: true, css: { 'width': 30, 'text-align': 'center' } }
];
var columns = [];
// head
for (var hd in list_columns) {
var col = {};
col.name = list_columns[hd].name;
col.caption = list_columns[hd].caption;
col.visible = true;
col.sortable = true;
col.width = list_columns[hd].css.width;
col.align = list_columns[hd].css["text-align"]
col.key = list_columns[hd].valueIndex;
col.allowFilter = list_columns[hd].allowFilter;
col.oldFilterValues = col.filterValues;
col.alwaysshow = list_columns[hd].alwaysshow;
col.bgFilter = function (item) {
if (item.Id.Value > 0 && IsAdvisor) {
if (item.TextMessageStatus == 0//Undelivered
|| item.TextMessageStatus == 9//Failed
|| item.TextMessageStatus == 10//Opt-Out
|| item.TextMessageStatus == 412)//Landline
return '#FFC107';
if (!item.CommunicationAcknowledged)
return '#79B6FF';
if (!item.EstimateAcknowledged) {
if (item.ApprovedEstimates > 0)
return '#07FF93';
if (item.RejectedEstimates > 0)
return '#D81B1B';//rgb(216 27 27)
}
}
};
var styleFilter = function (item) {
if (item.Id.Value > 0 && IsAdvisor) {
if (item.TextMessageStatus == 0//Undelivered
|| item.TextMessageStatus == 9//Failed
|| item.TextMessageStatus == 10//Opt-Out
|| item.TextMessageStatus == 412//Landline
|| !item.CommunicationAcknowledged
|| (!item.EstimateAcknowledged && (item.ApprovedEstimates > 0 || item.RejectedEstimates > 0))
)
return { "font-weight": "bold" };
}
return {};
}
if (col.name !== 'Edit' && col.name !== "Print" && col.name !== "Delete" && col.name !== "AssetAlert")
col.styleFilter = styleFilter;
if (!IsCustomerRecordAllow && (col.name === "Customer")) {
continue;
}
if (!AllowWorkOrderSurveys && (col.name === "Surveys")) {
continue;
}
if (!AllowCustomer && (col.name === "Advisor" || col.name === "CustomerCode" || col.name === "Contacts"
|| col.name === "LastCommunication" || col.name === "LastCommunicationDate" || col.name === "LastCommunicationBy"
|| col.name === "AlternateStatus" || col.name === "EstimateStatus" || col.name === "Surveys"
|| col.name === "PublishedEstimates" || col.name === "ApprovedEstimates" || col.name === "RejectedEstimates" || col.name === "PendingEstimates"
|| col.name === "AutoText")) {
continue;
}
if (col.name === "StatusName") {
//col.bgFilter = function (item) {
// if (item.StatusColor && item.StatusColor != null)
// return item.StatusColor.toLowerCase()
//}
col.allowHtml = true;
col.filterCustom = true;
col.filter = function (item) {
return $('').css('background-color', item.StatusColor).text(item.StatusName || '');
};
col.editFilter = function (item) {
if (WOReadOnly || item.Id.Value <= 0)
return $('').css('background-color', item.StatusColor).text(item.StatusName || '');
var source = [];
if (workOrderStatus) {
var exists = false;
for (var i = 0; i < workOrderStatus.length; i++) {
var s = workOrderStatus[i];
if (!item.CanClose && (s.Status === 100 || s.StatusType === 100))
continue;
//option.css('background-color', 'white');
if (item.Status == s.Id) {
exists = true;
}
source.push(s);
}
if (!exists && !isNaN(item.Status)) {
var s = {
Id: item.Status,
Name: item.StatusName,
Color: item.StatusColor,
StatusType: item.StatusType
};
//option.css('background-color', 'white');
source.push(s);
}
}
var selector = $('
');
selector.dropdown(source, {
search: false,
textKey: 'Name',
valueKey: 'Id',
selected: item.Status,
disabled: !IsAdmin && item.Completed && !AllowReopenWorkorders
}).on('select', function (_e, it) {
if (it) {
if ((!AllowCommunicate || COMMReadOnly) && (it.Id !== 100 && it.StatusType !== 100)) {
item.Status = it.Id;
item.StatusName = it.Name;
item.StatusColor = it.Color;
item.StatusType = it.StatusType;
//selector.css('background-color', it.Color);
updateWorkOrder(item);
}
else {
onStatusChange(item, it, function () {
item.Status = it.Id;
item.StatusName = it.Name;
item.StatusColor = it.Color;
item.StatusType = it.StatusType;
//selector.css('background-color', it.Color);
}, function () {
var dropdown = selector.data('dropdown');
if (dropdown)
dropdown.select(item.Status);
});
}
}
});
if (item.StatusColor && item.StatusColor != null)
selector.css('background-color', item.StatusColor.toLowerCase());
return selector;
}
col.styleFilter = function (item) {
return Object.assign({}, styleFilter(item), { "width": "100%", 'padding': 0 });
}
}
else if (col.name === "WorkOrderType") {
col.allowHtml = true;
col.filterCustom = true;
col.filter = function (item) {
return $('').text(item.WorkOrderType || '');
};
col.editFilter = function (item) {
if (WOReadOnly || item.Id.Value <= 0)
return $('').text(item.WorkOrderType || '');
var source = [];
if (workOrderTypes) {
if (item.WorkOrderType && workOrderTypes.indexOf(item.WorkOrderType) < 0) {
workOrderTypes.push(item.WorkOrderType);
workOrderTypes.sort(function (s, t) {
let a = s.toLowerCase();
let b = t.toLowerCase();
if (a < b) return -1;
if (a > b) return 1;
return 0;
});
}
for (var i = 0; i < workOrderTypes.length; i++) {
var t = workOrderTypes[i];
var kv = { value: t, text: t };
source.push(kv);
}
}
return $('').dropdown(source, {
search: false,
selected: item.WorkOrderType,
disabled: !IsAdmin && item.Completed && !AllowReopenWorkorders
}).on('select', function (_e, it) {
item.WorkOrderType = it.value;
updateWorkOrder(item);
});
}
col.styleFilter = function (item) {
return Object.assign({}, styleFilter(item), { "width": "100%", 'padding': 0 });
}
}
else if (col.name === "Advisor") {
col.allowHtml = true;
col.filterCustom = true;
col.filter = function (item) {
return $('').text(item.AdvisorName || '');
};
col.editFilter = function (item) {
if (WOReadOnly || item.Id.Value <= 0)
return $('').text(item.AdvisorName || ''); // changed from "AssignedToName"
var source = [{ Key: '', Value: ' ' }];
var selected;
if (woAdvisors) {
for (var i = 0; i < woAdvisors.length; i++) {
var a = woAdvisors[i];
source.push(a);
if (item.AdvisorId.toLowerCase() == a.Key.toLowerCase()) {
selected = a.Key;
}
}
}
if (selected == null && item.AdvisorId != '' && item.AdvisorId != '-1') {
source.push({ Key: item.AdvisorId, Value: item.AdvisorName });
selected = item.AdvisorId;
}
return $('').dropdown(source, {
search: false,
selected: selected,
textKey: 'Value',
valueKey: 'Key',
disabled: !IsAdmin && item.Completed && !AllowReopenWorkorders
}).on('select', function (_e, a) {
if (a) {
item.AdvisorId = a.Key;
item.AdvisorName = a.Value;
updateWorkOrder(item);
}
});
}
col.styleFilter = function (item) {
return Object.assign({}, styleFilter(item), { "width": "100%", 'padding': 0 });
}
}
else if (col.name === "AssignedToName") {
col.allowHtml = true;
col.filterCustom = true;
col.filter = function (item) {
return $('').text(item.AssignedToName || '');
};
col.editFilter = function (item) {
if (WOReadOnly || item.Id.Value <= 0)
return $('').text(item.AssignedToName || '');
var source = [];
var selected;
if (item.AssignedToUsers) {
for (var i = 0; i < item.AssignedToUsers.length; i++) {
var u = item.AssignedToUsers[i];
//option.css('background-color', 'white');
source.push(u);
if (item.AssignedTo.toLowerCase() == u.IID.toLowerCase())
selected = u.IID;
}
} else {
source.push({ IID: '', DisplayName: ' ' });
}
var selector = $('');
selector.dropdown(source, {
search: true,
textKey: 'DisplayName',
valueKey: 'IID',
selected: selected,
disabled: !IsAdmin && item.Completed && !AllowReopenWorkorders
}).on('select', function (_e, u) {
if (u) {
item.AssignedTo = u.IID;
item.AssignedToName = u.DisplayName;
if (u.ContactType === 6)
item.HourlyRate = u.HourlyRate;
updateWorkOrder(item);
}
}).on('expand', function () {
if (!item.AssignedToUsersLoaded) {
item.AssignedToUsersLoaded = true;
worequest("GetContacts", JSON.stringify([item.AssetId, item.LocationId, item.DepartmentId]), function (data) {
if (data && data.length > 0) {
var source = [
{ IID: '', DisplayName: ' ' }
];
var sel = null;
var exists = false;
var selected;
if (item.AssignedToUsers && item.AssignedToUsers.length == 1)
sel = item.AssignedToUsers[0];
else
exists = true;
for (var i = 0; i < data.length; i++) {
var u = data[i];
source.push(u);
if (item.AssignedTo.toUpperCase() == u.IID.toUpperCase())
selected = u.IID;
if (sel && sel.IID.toUpperCase() == u.IID.toUpperCase())
exists = true;
}
if (!exists) {
source.push(sel);
}
item.AssignedToUsers = data;
var dropdown = selector.data('dropdown');
dropdown.setSource(source);
if (selected != null) {
dropdown.select(selected);
}
}
}, function (err) {
});
}
});
return selector;
}
col.styleFilter = function (item) {
return Object.assign({}, styleFilter(item), { "width": "100%", 'padding': 0 });
}
}
else if (col.name === "DueDate") {
col.allowHtml = true;
col.filterCustom = true;
col.filter = function (item) {
return $('').text(item.DueDateStr);
};
col.editFilter = function (item) {
if (WOReadOnly || item.Id.Value <= 0)
return $('').text(item.DueDateStr);
var ipt = $('');
setTimeout(function () {
ipt.datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false,
scrollMonth: false,
scrollTime: false,
scrollInput: false,
onSelectDate: function (v, inp) {
item.DueDate.Value = v;
var date = new DateFormatter().formatDate(v, 'm/d/Y');
item.DueDateStr = date;
item.DueDate.DisplayValue = date;
updateWorkOrder(item);
}
});
});
ipt.val(item.DueDateStr);
if (!IsAdmin && item.Completed && !AllowReopenWorkorders) {
ipt.attr('disabled', true);
}
return ipt;
}
col.styleFilter = function (item) {
return Object.assign({}, styleFilter(item), { "width": "100%", 'padding': 0 });
}
}
else if (col.name === "CompleteDate") {
col.allowHtml = true;
col.filterCustom = true;
col.filter = function (item) {
return $('').text(item.CompleteDateStr);
};
col.editFilter = function (item) {
if (WOReadOnly || item.Id.Value <= 0)
return $('').text(item.CompleteDateStr);
var ipt = $('');
setTimeout(function () {
ipt.datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false,
scrollMonth: false,
scrollTime: false,
scrollInput: false,
onSelectDate: function (v, inp) {
getAssetDetailInfo(item.AssetId, item, v, inp);
}
});
});
ipt.val(item.CompleteDateStr);
ipt.prop('disabled', !item.Completed);
if (!IsAdmin && item.Completed && !AllowReopenWorkorders) {
ipt.attr('disabled', true);
}
return ipt;
}
col.styleFilter = function (item) {
return Object.assign({}, styleFilter(item), { "width": "100%", 'padding': 0 });
}
}
else if (col.name === "NextFollowUpDate") {
//col.bgFilter = function (item) {
// if (!item.Completed && item.NextFollowUpDate.Value && new Date(item.NextFollowUpDate.Value) < new Date(currentdate))
// return 'red';
//}
col.allowHtml = true;
col.filterCustom = true;
col.filter = function (item) {
var color = !item.Completed && item.NextFollowUpDate.Value && new Date(item.NextFollowUpDate.Value) < new Date(currentdate) ? 'red' : null;
return $('').css({
'background-color': color,
//'color': 'white'
}).text(item.NextFollowUpDateStr);
};
col.editFilter = function (item) {
if (WOReadOnly || item.Id.Value <= 0) {
var color = !item.Completed && item.NextFollowUpDate.Value && new Date(item.NextFollowUpDate.Value) < new Date(currentdate) ? 'red' : null;
return $('').css({
'background-color': color,
//'color': 'white'
}).text(item.NextFollowUpDateStr);
}
var ipt = $('');
setTimeout(function () {
ipt.datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false,
scrollMonth: false,
scrollTime: false,
scrollInput: false,
onSelectDate: function (v, inp) {
item.NextFollowUpDate.Value = v;
var date = new DateFormatter().formatDate(v, 'm/d/Y');
item.NextFollowUpDateStr = date;
item.NextFollowUpDate.DisplayValue = date;
if (!item.Completed && item.NextFollowUpDate.Value && new Date(item.NextFollowUpDate.Value) < new Date(currentdate)) {
ipt.css('background-color', 'red');
ipt.parents('td:first').css('background-color', 'red');
}
updateWorkOrder(item);
}
});
});
if (!item.Completed && item.NextFollowUpDate.Value && new Date(item.NextFollowUpDate.Value) < new Date(currentdate))
ipt.css('background-color', 'red');
ipt.val(item.NextFollowUpDateStr);
if (!IsAdmin && item.Completed && !AllowReopenWorkorders) {
ipt.attr('disabled', true);
}
return ipt;
}
col.styleFilter = function (item) {
return Object.assign({}, styleFilter(item), { "width": "100%", 'padding': 0 });
}
}
else if (col.name === "Description") {
col.allowHtml = true;
col.filterCustom = true;
col.filter = function (item) {
return $('').append(
$('
'),
$('
').html(converthtmlurl(item.Description || ''))
);
};
col.editFilter = function (item) {
if (WOReadOnly || item.Id.Value <= 0)
return $('
').append(
$('
'),
$('
').html(converthtmlurl(item.Description || ''))
);
//var span = $('
')
//var pre = $('
');
//pre.text(item.Description);
//span.append(pre);
//var iconedit = $('
');
//iconedit.click(function () {
// onEditText(item, 1, function () {
// pre.text(item.Description);
// });
//});
//span.append(iconedit);
//return span;
var flex = $('
');
var iconedit = $('
');
iconedit.click(function () {
onEditText(item, 1, function () {
flex.children('.cell-flex-memo').html(converthtmlurl(item.Description));
});
});
if (!IsAdmin && item.Completed && !AllowReopenWorkorders) {
iconedit.hide();
}
flex.append(
iconedit,
$('
').html(converthtmlurl(item.Description))
);
return flex;
}
}
else if (col.name === 'AssetName') {
col.styleFilter = function (item) {
return Object.assign({}, styleFilter(item), { 'white-space': 'pre-line', 'line-height': '20px' });
}
}
else if (col.name === 'InspectionCount') {
col.styleFilter = function (item) {
if (item.InspectionRequired.Value && item.InspectionCount > 0 && item.InspectionTemplateId > 0) {
return { 'color': item.RequiredInspectionCompleted ? '#2eda2e' : "red", 'font-weight': 'bold' };
}
};
}
else if (col.name === "Notes") {
col.allowHtml = true;
col.filterCustom = true;
col.filter = function (item) {
return $('
').append(
$('
'),
$('
').html(item.Notes || '')
);
};
col.editFilter = function (item) {
if (WOReadOnly || item.Id.Value <= 0)
return $('
').append(
$('
'),
$('
').html(item.Notes || '')
);
//var span = $('
')
//var pre = $('
');
//pre.text(item.Notes);
//span.append(pre);
//var iconedit = $('
');
//iconedit.click(function () {
// onEditText(item, 2, function () {
// pre.text(item.Notes);
// });
//});
//span.append(iconedit);
//return span;
var flex = $('
');
var iconedit = $('
');
iconedit.click(function () {
onEditText(item, 2, function () {
flex.children('.cell-flex-memo').text(item.Notes);
});
});
if (!IsAdmin && item.Completed && !AllowReopenWorkorders) {
iconedit.hide();
}
flex.append(
iconedit,
$('
').text(item.Notes)
);
return flex;
}
}
else if (col.name === "Edit") {
col.sortable = false;
col.isurl = true;
col.text = "\uf044";
col.events = {
onclick: function () {
OnEdit();
}
};
col.classFilter = function (e) {
return "icon-col";
}
col.attrs = { 'title': GetTextByKey("P_WO_EDIT", 'Edit') };
}
else if (col.name === "Print") {
col.sortable = false;
col.isurl = true;
col.visible = canExport;
col.text = "\uf02f";
col.events = {
onclick: function () {
OnPrint();
}
};
col.classFilter = function (e) {
return "icon-col";
}
col.styleFilter = function (e) {
return {
display: (e.MaintenanceID) ? 'none' : ''
};
};
col.attrs = { 'title': GetTextByKey("P_WO_PRINT", 'Print') };
}
else if (col.name === "Delete") {
col.sortable = false;
col.isurl = true;
col.text = "\uf00d";
col.events = {
onclick: function () {
OnDelete(this);
}
};
col.classFilter = function (e) {
return "icon-col";
};
col.styleFilter = function (e) {
return {
display: (WOReadOnly || e.Completed || e.MaintenanceID || !e.CanDeleteAndRestore) ? 'none' : ''
};
};
col.attrs = { 'title': GetTextByKey("P_WO_DELETE", 'Delete') };
}
else if (col.name === "AssetAlert") {
col.sortable = false;
col.isurl = true;
col.text = "\uf071";
col.events = {
onclick: function () {
ManageAlerts(this);
}
};
col.classFilter = function (e) {
return "icon-col";
};
col.styleFilter = function (e) {
return {
display: (e.Completed || e.MaintenanceID) ? 'none' : ''
};
};
col.attrs = { 'title': GetTextByKey("P_WO_ASSETALERT", 'Asset Alert') };
}
else if (col.name === "Surveys") {
col.sortable = false;
col.isurl = true;
col.text = "\uf15c";
col.events = {
onclick: function () {
onSendWOSurveys(this);
}
};
col.classFilter = function (e) {
return "icon-col";
};
col.styleFilter = function (e) {
return {
display: (!e.Completed || e.MaintenanceID || !e.Contacts || e.Contacts.length == 0) ? 'none' : ''
};
};
col.attrs = { 'title': GetTextByKey("P_WO_SENDWORKORDERSURVEYS", 'Send Work Order Surveys') };
}
else if (col.name === "Contacts") {
col.sortable = false;
col.allowHtml = true;
col.filter = function (item) {
if (item.Contacts && item.Contacts.length > 0) {
var tb = $('
');
for (var i = 0; i < item.Contacts.length; i++) {
var contact = item.Contacts[i];
var ptext = contact.Name;
if (contact.ContactPreference === 0) {
ptext += " – T";
if (contact.MobilePhone !== "")
ptext += " – " + contact.MobilePhoneDisplayText;
}
else if (contact.ContactPreference === 1) {
if (contact.Email !== "")
ptext += " - " + contact.Email;
}
else if (contact.ContactPreference === 2) {
ptext += " – P";
if (contact.MobilePhone !== "")
ptext += " – " + contact.MobilePhoneDisplayText;
}
var tr = $('
|
');
var td = $('
| ').text(ptext);
tr.append(td).appendTo(tb);
}
return tb;
}
};
col.styleFilter = function (item) {
return Object.assign({}, styleFilter(item), {
'margin-top': '3px',
'margin-bottom': '0px',
});
};
}
else if (col.name === "PartsExpectedDate") {
col.allowHtml = true;
col.filterCustom = true;
col.filter = function (item) {
return $('
').text(item.PartsExpectedDateStr);
};
col.editFilter = function (item) {
if (WOReadOnly || item.Id.Value <= 0)
return $('
').text(item.PartsExpectedDateStr);
var ipt = $('
');
setTimeout(function () {
ipt.datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false,
scrollMonth: false,
scrollTime: false,
scrollInput: false,
onSelectDate: function (v, inp) {
item.PartsExpectedDate.Value = v;
var date = new DateFormatter().formatDate(v, 'm/d/Y');
item.PartsExpectedDateStr = date;
item.PartsExpectedDate.DisplayValue = date;
updateWorkOrder(item);
}
});
});
ipt.val(item.PartsExpectedDateStr);
if (!IsAdmin && item.Completed && !AllowReopenWorkorders) {
ipt.attr('disabled', true);
}
return ipt;
}
col.styleFilter = function (item) {
return Object.assign({}, styleFilter(item), { "width": "100%", 'padding': 0 });
}
}
else if (col.name === "LastLaborDate") {
col.allowHtml = true;
col.filterCustom = true;
col.filter = function (item) {
return $('
').text(item.LastLaborDateStr);
};
col.editFilter = function (item) {
if (WOReadOnly || item.Id.Value <= 0)
return $('
').text(item.LastLaborDateStr);
var ipt = $('
');
setTimeout(function () {
ipt.datetimepicker({
timepicker: false,
format: 'm/d/Y',
enterLikeTab: false,
scrollMonth: false,
scrollTime: false,
scrollInput: false,
onSelectDate: function (v, inp) {
item.LastLaborDate.Value = v;
var date = new DateFormatter().formatDate(v, 'm/d/Y');
item.LastLaborDateStr = date;
item.LastLaborDate.DisplayValue = date;
updateWorkOrder(item);
}
});
});
ipt.val(item.LastLaborDateStr);
if (!IsAdmin && item.Completed && !AllowReopenWorkorders) {
ipt.attr('disabled', true);
}
return ipt;
}
col.styleFilter = function (item) {
return Object.assign({}, styleFilter(item), { "width": "100%", 'padding': 0 });
}
}
else if (col.name === "InspectionRequired") {
col.allowHtml = true;
col.filterCustom = true;
col.filter = function (item) {
return $('
').text(item.InspectionRequired.DisplayValue);
};
col.editFilter = function (item) {
if (WOReadOnly || item.Id.Value <= 0)
return "";
var ipt = $('
').change(function () {
var checked = $(this).prop("checked");
item.InspectionRequired.Value = checked;
item.InspectionRequired.DisplayValue = checked ? 'Yes' : 'No';
updateWorkOrder(item);
});
ipt.prop('checked', item.InspectionRequired.Value);
if (!IsAdmin && item.Completed && !AllowReopenWorkorders) {
ipt.attr('disabled', true);
}
return ipt;
}
col.styleFilter = function (item) {
return Object.assign({}, styleFilter(item), { "width": "100%" });
}
}
else if (col.name === "AutoText") {
col.allowHtml = true;
col.filterCustom = true;
col.filter = function (item) {
return $('
').text(item.AutoText.DisplayValue);
};
col.editFilter = function (item) {
if (WOReadOnly || item.Id.Value <= 0)
return "";
var ipt = $('
').change(function () {
var checked = $(this).prop("checked");
item.AutoText.Value = checked;
item.AutoText.DisplayValue = checked ? 'Yes' : 'No';
updateWorkOrder(item);
});
ipt.prop('checked', item.AutoText.Value);
if (!IsAdmin && item.Completed && !AllowReopenWorkorders) {
ipt.attr('disabled', true);
}
return ipt;
}
col.styleFilter = function (item) {
return Object.assign({}, styleFilter(item), { "width": "100%" });
}
}
else if (col.name === "Department") {
col.allowHtml = true;
col.filterCustom = true;
col.filter = function (item) {
return $('
').text(item.Department || '');
};
col.editFilter = function (item) {
if (WOReadOnly || item.Id.Value <= 0)
return $('
').text(item.Department || '');
var source = [];
if (item.Departments) {
for (var i = 0; i < item.Departments.length; i++) {
var dept = item.Departments[i];
source.push(dept);
}
} else {
source.push({ Id: '', Name: ' ' });
}
var selector = $('
');
selector.dropdown(source, {
search: true,
valueKey: 'Id',
textKey: 'Name',
selected: item.DepartmentId,
disabled: !IsAdmin && item.Completed && !AllowReopenWorkorders
}).on('select', function (_e, dept) {
if (dept) {
item.DepartmentId = dept.Id;
item.Department = dept.Name;
item.AssignedToUsersLoaded = false;
updateWorkOrder(item);
}
}).on('expand', function () {
if (!item.DepartmentsLoaded) {
item.DepartmentsLoaded = true;
worequest("GetDepartments", '', function (data) {
if (data && data.length > 0) {
var source = [{ Id: '-1', Name: ' ' }];
var sel = null;
var exists = false;
var selected;
if (item.Departments && item.Departments.length == 1)
sel = item.Departments[0];
else
exists = true;
for (var i = 0; i < data.length; i++) {
var dept = data[i];
if (dept.PId > 0) {
dept.html = ' ' + dept.Name;
} else {
dept.html = dept.Name;
}
source.push(dept);
if (item.DepartmentId == dept.Id)
selected = dept.Id;
if (sel && sel.Id == dept.Id)
exists = true;
}
if (!exists) {
if (sel.PId > 0) {
sel.html = ' ' + sel.Name;
} else {
sel.html = sel.Name;
}
source.push(sel);
}
item.Departments = data;
var dropdown = selector.data('dropdown');
dropdown.setSource(source);
if (selected != null) {
dropdown.select(selected);
}
}
}, function () {
});
}
});
return selector;
}
col.styleFilter = function (item) {
return Object.assign({}, styleFilter(item), { "width": "100%", 'padding': 0 });
}
}
else if (col.name === "Location") {
col.allowHtml = true;
col.filterCustom = true;
col.filter = function (item) {
return $('
').text(item.Location || '');
};
col.editFilter = function (item) {
if (WOReadOnly || item.Id.Value <= 0)
return $('
').text(item.Location || '');
var source = [];
if (item.Locations) {
for (var i = 0; i < item.Locations.length; i++) {
var loc = item.Locations[i];
source.push(loc);
}
} else {
source.push({ ID: '', Name: ' ' });
}
var selector = $('
');
selector.dropdown(source, {
search: true,
valueKey: 'ID',
textKey: 'Name',
selected: item.LocationId,
disabled: !IsAdmin && item.Completed && !AllowReopenWorkorders
}).on('select', function (_e, loc) {
if (loc) {
item.LocationId = loc.ID;
item.Location = loc.Name;
item.AssignedToUsersLoaded = false;
updateWorkOrder(item);
}
}).on('expand', function () {
if (!item.LocationsLoaded) {
item.LocationsLoaded = true;
worequest("GetLocations", '', function (data) {
if (data && data.length > 0) {
var source = [{ ID: '-1', Name: ' ' }];
var sel = null;
var exists = false;
var selected;
if (item.Locations && item.Locations.length == 1)
sel = item.Locations[0];
else
exists = true;
for (var i = 0; i < data.length; i++) {
var loc = data[i];
if (loc.PId > 0) {
loc.html = ' ' + loc.Name;
} else {
loc.html = loc.Name;
}
source.push(loc);
if (item.LocationId == loc.ID)
selected = loc.ID;
if (sel && sel.ID == loc.ID)
exists = true;
}
if (!exists) {
if (sel.PId > 0) {
sel.html = ' ' + sel.Name;
} else {
sel.html = sel.Name;
}
source.push(sel);
}
item.Locations = data;
var dropdown = selector.data('dropdown');
dropdown.setSource(source);
if (selected != null) {
dropdown.select(selected);
}
}
}, function () {
});
}
});
return selector;
}
col.styleFilter = function (item) {
return Object.assign({}, styleFilter(item), { "width": "100%", 'padding': 0 });
}
}
else if (col.name === "SalespersonName") {
col.allowHtml = true;
col.filterCustom = true;
col.filter = function (item) {
return $('
').text(item.SalespersonName || '');
};
col.editFilter = function (item) {
if (WOReadOnly || item.Id.Value <= 0)
return $('
').text(item.SalespersonName || '');
var source = [];
if (item.Salespersons) {
for (var i = 0; i < item.Salespersons.length; i++) {
var s = item.Salespersons[i];
source.push(s);
}
} else {
source.push({ Key: '', Value: ' ' });
}
var selector = $('
');
selector.dropdown(source, {
search: true,
valueKey: 'Key',
textKey: 'Value',
selected: item.SalespersonId,
disabled: !IsAdmin && item.Completed && !AllowReopenWorkorders
}).on('select', function (_e, s) {
if (s) {
item.SalespersonId = s.Key;
item.SalespersonName = s.Value;
updateWorkOrder(item);
}
}).on('expand', function () {
if (!item.SalespersonsLoaded) {
item.SalespersonsLoaded = true;
worequest("GetSalespersons", '', function (data) {
if (data && data.length > 0) {
var source = [{ Key: '', Value: ' ' }];
var exists = false;
if (!item.SalespersonId || item.SalespersonId == "")
exists = true;
for (var i = 0; i < data.length; i++) {
var s = data[i];
source.push(s);
if (!exists && item.SalespersonId == s.ID)
exists = true;
}
if (!exists) {
source.push({ Key: item.SalespersonId, Value: item.SalespersonName });
}
item.Salespersons = data;
var dropdown = selector.data('dropdown');
dropdown.setSource(source);
if (item.SalespersonId && item.SalespersonId != "") {
dropdown.select(item.SalespersonId);
}
}
}, function () {
});
}
});
return selector;
}
col.styleFilter = function (item) {
return Object.assign({}, styleFilter(item), { "width": "100%", 'padding': 0 });
}
}
else if (col.name === "LastCommunication") {
col.allowHtml = true;
col.filterCustom = true;
col.filter = function (item) {
return $('
').append(
$('
'),
$('
').text(item.LastCommunication || '')
);
};
col.editFilter = function (item) {
if (WOReadOnly || item.Id.Value <= 0)
return $('
').append(
$('
'),
$('
').text(item.LastCommunication || '')
);
var flex = $('
');
var iconedit;
if (!IsAdvisor || item.CommunicationAcknowledged) {
iconedit = $('
');
} else {
iconedit = $('
');
iconedit.click(function () {
updateCommunicationAcknowledged(item.Id.Value, true);
item.CommunicationAcknowledged = true;
grid_dt && grid_dt.reload();
});
}
flex.append(
iconedit,
$('
').text(item.LastCommunication)
);
return flex;
}
}
columns.push(col);
}
grid_dt.canMultiSelect = false;
//grid_dt.columns = columns;
//grid_dt.init();
//grid_dt.rowdblclick = OnEdit;
grid_dt.celldblclick = function (rowindex, colindex) {
if (colindex >= 0) {
var col = grid_dt.columns[colindex];
if (!col.allowHtml)
OnEdit();
if (col.name == "Description" || col.name == "Notes") {
var index = grid_dt.selectedIndex;
if (index < 0) return;
var wo = grid_dt.source[index].Values;
if (wo.Id.Value <= 0) return;
if (!IsAdmin && wo.Completed && !AllowReopenWorkorders)
return;
onEditText(wo, col.name == "Description" ? 1 : 2, function () {
grid_dt.refresh();
});
}
}
};
grid_dt.selectedrowchanged = function (rowindex) {
var rowdata = grid_dt.source[rowindex];
if (rowdata && rowdata.Values.Id.Value > 0) {
if (!wowidgetobj) {
wowidgetobj = new WorkOrderWidget();
wowidgetobj.changeWorkOrder(rowdata.Values);
} else {
wowidgetobj.changeWorkOrder(rowdata.Values);
}
}
}
grid_dt.allcolumns = columns;
getGridLayout(gridLayoutID, grid_dt, GetLocationsAndDepartments);
}
function updateWorkOrder(wo, sendtextmsg) {
var item = {
'Id': wo.Id.Value || wo.Id,
'AssetID': wo.AssetId,
'WorkOrderType': wo.WorkOrderType,
'AdvisorId': wo.AdvisorId,
'Status': wo.Status,
'StatusType': wo.StatusType,
'AssignedTo': wo.AssignedTo,
'Description': wo.Description,
'DueDate': wo.DueDateStr,
'CompleteDate': wo.CompleteDateStr,
'NextFollowUpDate': wo.NextFollowUpDateStr,
'Notes': wo.Notes,
'MeterType': wo.MeterType,
'HourMeter': wo.HourMeter,
'Odometer': wo.Odometer,
'OdometerUnits': wo.OdometerUnits,
'WorkOrderNumber': wo.WorkOrderNumber.DisplayValue,
'HourlyRate': wo.HourlyRate,
'PartsExpectedDate': wo.PartsExpectedDateStr,
'LastLaborDate': wo.LastLaborDateStr,
'InspectionRequired': wo.InspectionRequired.Value,
'AutoText': wo.AutoText.Value,
'DepartmentId': wo.DepartmentId,
'LocationId': wo.LocationId,
'SalespersonId': wo.SalespersonId
};
var alerttitle = GetTextByKey('P_WO_SAVEWORKORDER', 'Save Work Order');
if (item.NextFollowUpDate.length > 0) {
if (!checkDate(item.NextFollowUpDate)) {
showAlert(GetTextByKey("P_WO_NEXTFOLLOWUPDATEFORMATERROR", "Next Follow Up Date format error."), alerttitle);
return false;
}
}
else {
item.NextFollowUpDate = "";
}
if (item.DueDate.length > 0) {
if (!checkDate(item.DueDate)) {
showAlert(GetTextByKey("P_WO_DUEDATEFORMATERROR", "Due Date format error."), alerttitle);
return false;
}
}
else {
item.DueDate = "";
}
if (item.CompleteDate.length > 0) {
if (!checkDate(item.CompleteDate)) {
showAlert(GetTextByKey("P_WO_COMPLETEDDATEFORMATERROR", "Completed Date format error."), alerttitle);
return false;
}
}
else {
item.CompleteDate = "";
}
if (item.PartsExpectedDate.length > 0) {
if (!checkDate(item.PartsExpectedDate)) {
showAlert(GetTextByKey("P_WO_PARTSEXPECTEDDATEFORMATERROR", "Parts Expected Date format error."), alerttitle);
return false;
}
}
else {
item.PartsExpectedDate = "";
}
if (item.LastLaborDate.length > 0) {
if (!checkDate(item.LastLaborDate)) {
showAlert(GetTextByKey("P_WO_LASTLABORDATEFORMATERROR", "Last Labor Date format error."), alerttitle);
return false;
}
}
else {
item.LastLaborDate = "";
}
if (!item.Description || item.Description.length == 0) {
showAlert(GetTextByKey("P_WO_DESCRIPTIONCANNOTBEEMPTY", 'Description cannot be empty.'), alerttitle);
$('#dialog_description').focus();
return;
}
if (isNaN(item.Status))
item.Status = -1;
var param = JSON.stringify(item);
param = htmlencode(param);
worequest("UpdateWorkOrder", param, function (data) {
if (typeof (data) === "string") {
//showmaskbg(false);
showAlert(data, alerttitle);
return;
}
if (!wo.CompleteDate || wo.CompleteDate == "") {
wo.CompleteDate = data.CompleteDate;
wo.CompleteDateStr = data.CompleteDateStr;
}
grid_dt.refresh();
if (sendtextmsg)
SendTextMsg(wo);
}, function (err) {
showAlert(GetTextByKey("P_WO_FAILEDTOSAVEWORKORDER", 'Failed to save Work Order.'), alerttitle);
});
}
function onStatusChange(wo, tostatus, next, cancel) {
cur_asset = null;
if (!AllowCommunicate || COMMReadOnly) {
$('.tr_sendmsg').hide();
}
else {
$('.tr_sendmsg').show();
}
$('#dialog_statuschange').data("wo", wo);
$('#dialog_statuschange').data("tostatus", tostatus);
$('#dialog_statuschange').data("next", next);
$('#dialog_statuschange').data("cancel", cancel);
if (wo.InspectionRequired.Value && wo.InspectionCount == 0 && (tostatus.Id === 100 || tostatus.StatusType === 100)) {
showAlert(GetTextByKey('P_WO_INSPECTIONREQUIREDTIP', 'The work order cannot be updated Until an inspection is completed.'), GetTextByKey("P_WO_ERROR", "Error"));
if (cancel)
cancel();
return;
}
var iscompleted = false;
if (tostatus.Id === 100 || tostatus.StatusType === 100)
iscompleted = true;
setPhoneNumber(wo);
$('#dialog_variables').val('');
if (tostatus.AutoText && !COMMReadOnly) {
$('#dialog_textmsg').val(tostatus.Message);
$('#dialog_chksendtextmsg').prop('checked', true);
$('#txtphonenum').prop('disabled', false);
$('#dialog_chkIncludeStatusLink').prop('disabled', false);
$('#dialog_textmsg').prop('disabled', false);
$('#dialog_variables').prop('disabled', false);
$('#dialog_insertfield').prop('disabled', false);
} else {
$('#dialog_textmsg').val("");
$('#dialog_chksendtextmsg').prop('checked', false).prop('disabled', COMMReadOnly);
$('#txtphonenum').prop('disabled', true);
$('#dialog_chkIncludeStatusLink').prop('disabled', true);
$('#dialog_textmsg').prop('disabled', true);
$('#dialog_variables').prop('disabled', true);
$('#dialog_insertfield').prop('disabled', true);
}
if (iscompleted) {
getAssetDetailInfo(wo.AssetId);
$('.statuscompleted').show();
$('#btn_sendtextandsave').show();
$('#btn_sendtext').hide();
$('#dialog_completeddate').val(nowDate);
meterType = wo.MeterType;
$('#dialog_metertype').val(meterType);
setMeterType();
$('#dialog_hourmeter').val(wo.HourMeter < 0 ? "" : wo.HourMeter);
$('#dialog_odometer').val(wo.Odometer < 0 ? "" : wo.Odometer);
$('#dig_odometeruom').val(wo.OdometerUnits);
}
else {
$('.statuscompleted').hide();
$('#btn_sendtextandsave').hide();
$('#btn_sendtext').show();
}
showmaskbg(true, true);
$('#dialog_statuschange .dialog-title span.title').text(GetTextByKey("P_WO_STATUSCHANGE", 'Status Change') + " - " + tostatus.Name);
$('#dialog_statuschange')
.attr('act', 'add')
.css({
'top': (document.documentElement.clientHeight - $('#dialog_statuschange').height()) / 3,
'left': (document.documentElement.clientWidth - $('#dialog_statuschange').width()) / 2
})
.showDialogfixed();
}
var cur_asset = null;
function getAssetDetailInfo(mid, wo, v, ipt) {
cur_asset = null;
worequest("GetAssetDetailInfo", "" + String.fromCharCode(170) + mid, function (data) {
if (typeof (data) === "string") {
return;
}
if (data.ID != mid)
return;
var asset = data;
cur_asset = asset;
if ($('#dialog_odometer').val() === "" || $('#dialog_odometer').val() === "0") {
if (asset.CurrentOdometer && asset.CurrentOdometer.Corrected > 0)
$("#dialog_odometer").val(Math.round(asset.CurrentOdometer.Corrected));
else
$("#dialog_odometer").val("");
}
if ($('#dialog_hourmeter').val() === "" || $('#dialog_hourmeter').val() === "0") {
if (asset.CurrentHours && asset.CurrentHours.Corrected)
$("#dialog_hourmeter").val(Math.round(asset.CurrentHours.Corrected));
else
$("#dialog_hourmeter").val("");
}
if (wo) {
var item = wo;
var date = new DateFormatter().formatDate(v, 'm/d/Y');
if (date !== "" && date !== nowDate) {
var rst = false;
var msg = "";
if ((item.MeterType === "Odometer" || item.MeterType === "Both")
&& cur_asset.CurrentOdometer && parseFloat(item.Odometer) === Math.round(cur_asset.CurrentOdometer.Corrected)) {
if ((item.OdometerUnits.toLowerCase() === "mile" && ['mi', 'm'].indexOf(cur_asset.CurrentOdometer.UOM) >= 0)
|| (item.OdometerUnits.toLowerCase() === "kilometre" && ['km', 'Kilometres'].indexOf(cur_asset.CurrentOdometer.UOM) >= 0)
) {
rst = true;
var odoumits = (item.OdometerUnits == "Mile" ? "miles" : "kilometers");
msg = 'mileage (' + item.Odometer.toLocaleString() + ' ' + odoumits + ')';
}
}
if ((item.MeterType === "HourMeter" || item.MeterType === "Both")
&& cur_asset.CurrentHours && parseFloat(item.HourMeter) === Math.round(cur_asset.CurrentHours.Corrected)) {
rst = true;
msg = 'hours (' + item.HourMeter.toLocaleString() + ' hours)';
}
if (rst) {
showConfirm(GetTextByKey("P_WO_XXX", "This work order was completed on {1} but is using the current {0} is this correct? ").replace('{0}', msg).replace('{1}', date), GetTextByKey('P_WO_SAVEWORKORDER', 'Save Work Order'), function () {
item.CompleteDate.Value = v;
item.CompleteDateStr = date;
item.CompleteDate.DisplayValue = date;
updateWorkOrder(item);
}, function (err) {
ipt.val(item.CompleteDateStr);
});
}
else {
item.CompleteDate.Value = v;
item.CompleteDateStr = date;
item.CompleteDate.DisplayValue = date;
updateWorkOrder(item);
}
}
else {
item.CompleteDate.Value = v;
item.CompleteDateStr = date;
item.CompleteDate.DisplayValue = date;
updateWorkOrder(item);
}
}
}, function (err) {
});
}
function SaveStatusChange() {
var wo = $('#dialog_statuschange').data("wo");
if (!wo) return;
var tostatus = $('#dialog_statuschange').data("tostatus");
if (tostatus.Id === 100 || tostatus.StatusType === 100) {
wo.CompleteDateStr = $('#dialog_completeddate').val();
wo.MeterType = $('#dialog_metertype').val();
wo.HourMeter = $('#dialog_hourmeter').val();
wo.Odometer = $('#dialog_odometer').val();
wo.OdometerUnits = $('#dig_odometeruom').val();
var alerttitle = GetTextByKey("P_WO_ERROR", "Error");
if (wo.CompleteDateStr === "") {
showAlert(GetTextByKey("P_WO_COMPLETEDDATECANNOTBEEMPTY", 'Completed Date cannot be empty.'), alerttitle);
return;
}
if (wo.MeterType === "HourMeter") {
if (wo.HourMeter === "") {
showAlert(GetTextByKey("P_WO_HOURMETERCANNOTBEEMPTY", 'Hour Meter cannot be empty.'), alerttitle);
$('#dialog_hourmeter').focus();
return;
}
wo.Odometer = -1;
wo.OdometerUnits = "";
}
else if (wo.MeterType === "Odometer") {
if (wo.Odometer === "") {
showAlert(GetTextByKey("P_WO_ODOMETERCANNOTBEEMPTY", 'Odometer cannot be empty.'), alerttitle);
$('#dialog_odometer').focus();
return;
}
wo.HourMeter = -1;
}
else if (wo.MeterType === "Both") {
if (wo.HourMeter === "") {
showAlert(GetTextByKey("P_WO_HOURMETERCANNOTBEEMPTY", 'Hour Meter cannot be empty.'), alerttitle);
$('#dialog_hourmeter').focus();
return;
}
if (wo.Odometer === "") {
showAlert(GetTextByKey("P_WO_ODOMETERCANNOTBEEMPTY", 'Odometer cannot be empty.'), alerttitle);
$('#dialog_odometer').focus();
return;
}
}
if (wo.CompleteDateStr !== "" && wo.CompleteDateStr !== nowDate && cur_asset) {
var rst = false;
var msg = "";
if ((wo.MeterType === "Odometer" || wo.MeterType === "Both")
&& cur_asset.CurrentOdometer && parseFloat(wo.Odometer) === Math.round(cur_asset.CurrentOdometer.Corrected)) {
if ((wo.OdometerUnits.toLowerCase() === "mile" && ['mi', 'm'].indexOf(cur_asset.CurrentOdometer.UOM) >= 0)
|| (wo.OdometerUnits.toLowerCase() === "kilometre" && ['km', 'Kilometres'].indexOf(cur_asset.CurrentOdometer.UOM) >= 0)
) {
rst = true;
var odoumits = (wo.OdometerUnits == "Mile" ? "miles" : "kilometers");
msg = 'mileage (' + parseFloat(wo.Odometer).toLocaleString() + ' ' + odoumits + ')';
}
}
if ((wo.MeterType === "HourMeter" || wo.MeterType === "Both")
&& cur_asset.CurrentHours && parseFloat(wo.HourMeter) === Math.round(cur_asset.CurrentHours.Corrected)) {
rst = true;
msg = 'hours (' + parseFloat(wo.HourMeter).toLocaleString() + ' hours)';
}
if (rst) {
showConfirm1(GetTextByKey("P_WO_XXX", "This work order was completed on {1} but is using the current {0} is this correct? ").replace('{0}', msg).replace('{1}', wo.CompleteDateStr), GetTextByKey('P_WO_SAVEWORKORDER', 'Save Work Order'), function () {
onSaveStatusChange(wo);
}, function (err) {
});
}
else
onSaveStatusChange(wo);
}
else {
onSaveStatusChange(wo);
}
}
else
onSaveStatusChange(wo);
}
function onSaveStatusChange(wo) {
var next = $('#dialog_statuschange').data("next");
if (next)
next();
var sendtextmsg = $('#dialog_chksendtextmsg').prop('checked');
if (!AllowCommunicate || COMMReadOnly)
sendtextmsg = false;
updateWorkOrder(wo, sendtextmsg);
$('#dialog_statuschange').hideDialog();
showmaskbg(false);
}
function SendTextMsg(wo) {
var phoneemail = $('#txtphonenum').val();
if ($.trim(phoneemail) == "") {
return;
}
var phoneemails = phoneemail.split(';');
var pmemails = [];
for (var i = 0; i < phoneemails.length; i++) {
var pm = phoneemails[i];
if (checkPhoneNumber(pm) || isEmail(pm)) {
pmemails.push({ 'Key': pm, 'Value': pm });
}
else {
if (wo && wo.Contacts) {
for (var j = 0; j < wo.Contacts.length; j++) {
var c = wo.Contacts[j];
if (c.OptOut || c.OptOut_BC) continue;
var mp = $.trim(c.MobilePhone);
var email = $.trim(c.Email);
if (c.Name === pm) {
if (c.ContactPreference == "0" && checkPhoneNumber(mp)) {
pmemails.push({ 'Key': mp, 'Value': pm });
break;
}
if (c.ContactPreference == "1" && isEmail(email)) {
pmemails.push({ 'Key': email, 'Value': pm });
break;
}
}
}
}
}
}
var comm = $('#dialog_textmsg').val();
if ($.trim(comm) == "") {
//showAlert(GetTextByKey("P_WO_PLEASEINPUTTHEMESSAGE", "Please input the message."), GetTextByKey("P_WO_ERROR", 'Error'));
return;
}
var includeStatusLink = $('#dialog_chkIncludeStatusLink').prop("checked");
var param = JSON.stringify([wo.Id.Value || wo.Id, JSON.stringify(pmemails), comm, (includeStatusLink ? "1" : "0")]);
param = htmlencode(param);
worequest("AddWorkOrderCommunication", param, function (data) {
if (data !== "") {
showAlert(data, GetTextByKey("P_WO_ERROR", 'Error'));
return;
}
}, function (err) {
//showmaskbg(false);
});
}
function setPhoneNumber(wo) {
if (wo && wo.Contacts && !COMMReadOnly) {
var names = "";
for (var i = 0; i < wo.Contacts.length; i++) {
var c = wo.Contacts[i];
if (c.OptOut || c.OptOut_BC) continue;
var mp = $.trim(c.MobilePhone);
var email = $.trim(c.Email);
if ((c.ContactPreference == "0" && (checkPhoneNumber(mp))
|| (c.ContactPreference == "1" && isEmail(email)))) {
if (names == "")
names = c.Name;
else
names += ";" + c.Name;
}
}
$('#txtphonenum').val(names);
}
else
$('#txtphonenum').val("");
}
function convert_url_text(text) {
var $words = text.split(' ');
for (i in $words) {
if ($words[i].indexOf('http://') == 0 || $words[i].indexOf('https://') == 0) {
$words[i] = '
' + $words[i] + '';
}
}
return $words.join(' ');
}
function checkPhoneNumber(num) {
if ((/^[1-9]\d{9,}$/.test(num))) {
return true;
}
return false;
}
function onEditText(wo, type, next) {
showmaskbg(true);
if (type == 1) {
$('#dialog_edittext .dialog-title span.title').text(GetTextByKey("P_WO_EDITDESCRIPTION", 'Edit Description'));
$('#dialog_text').val(wo.Description);
}
else {
$('#dialog_edittext .dialog-title span.title').text(GetTextByKey("P_WO_EDITNOTES", 'Edit Notes'));
$('#dialog_text').val(wo.Notes);
}
$('#dialog_edittext').data('type', type).data('wo', wo).data('next', next)
.css({
'top': (document.documentElement.clientHeight - $('#dialog_edittext').height()) / 3,
'left': (document.documentElement.clientWidth - $('#dialog_edittext').width()) / 2
}).showDialogfixed();
}
function SaveText() {
var type = $('#dialog_edittext').data("type");
var text = $('#dialog_text').val();
var wo = $('#dialog_edittext').data("wo");
var next = $('#dialog_edittext').data("next");
if (type == 1) {
if (!text || text.length == 0) {
showAlert(GetTextByKey("P_WO_DESCRIPTIONCANNOTBEEMPTY", 'Description cannot be empty.'), GetTextByKey("P_WO_EDITDESCRIPTION", 'Edit Description'));
$('#dialog_text').focus();
return;
}
wo.Description = text;
}
else
wo.Notes = text;
if (next)
next();
$('#dialog_edittext').hideDialog();
showmaskbg(false);
updateWorkOrder(wo);
}
var surveytemplatedata;
function GetSurveyTemplateItems() {
$('#dialog_wosurveytemplates').empty();
worequest('GetSurveyTemplateItems', '', function (data) {
$('#dialog_wosurveytemplates').empty();
if (typeof (data) === "string") {
showAlert(data, GetTextByKey("P_WO_ERROR", 'Error'));
return;
}
surveytemplatedata = data;
if (data && data.length > 0) {
for (var i = 0; i < data.length; i++) {
var op = $("
").val(data[i].Id).text(data[i].Name);
$('#dialog_wosurveytemplates').append(op);
}
}
});
}
function onSendWOSurveys(wo) {
$('#dialog_wosurveytemplates').val('');
showmaskbg(true);
$('#dialog_sendwosurveys .dialog-title span.title').text(GetTextByKey("P_WO_SENDWORKORDERSURVEYS", 'Send Work Order Surveys'));
if (!surveytemplatedata) {
GetSurveyTemplateItems();
}
if (wo.Contacts && wo.Contacts.length > 0) {
var tb = $('
');
for (var i = 0; i < wo.Contacts.length; i++) {
var contact = wo.Contacts[i];
var mp = $.trim(contact.MobilePhone);
var email = $.trim(contact.Email);
if ((contact.ContactPreference == "0" && !checkPhoneNumber(mp))
|| (contact.ContactPreference == "1" && !isEmail(email))
|| contact.ContactPreference == "2")
continue;
var ptext = contact.Name;
if (contact.ContactPreference === 0)
ptext += " – " + contact.MobilePhoneDisplayText;
else if (contact.ContactPreference === 1)
ptext += " - " + contact.Email;
var tr = $('
|
');
var td = $('
| ');
var chk = $('
').data('contact', contact);
var span = $('
').text(ptext);
td.append(chk).append(span);
tr.append(td).appendTo(tb);
}
$("#dialog_wosurveyscontacts").empty().append(tb);
}
$('#dialog_sendwosurveys').data('wo', wo)
.css({
'top': (document.documentElement.clientHeight - $('#dialog_sendwosurveys').height()) / 3,
'left': (document.documentElement.clientWidth - $('#dialog_sendwosurveys').width()) / 2
}).showDialogfixed();
}
function SendWOSurveys() {
var tempid = $('#dialog_wosurveytemplates').val();
var wo = $('#dialog_sendwosurveys').data('wo');
if (!tempid || tempid == "") {
showAlert(GetTextByKey("P_WO_XXXXXX", 'Please select a template.'), GetTextByKey("P_WO_SENDWORKORDERSURVEYS", 'Send Work Order Surveys'));
return;
}
var contacts = [];
$('#dialog_sendwosurveys input:checkbox[name=wocontactsurvey]:checked').each(function (i, chk) {
var contact = $(chk).data('contact');
var key = "";
if (contact.ContactPreference === 0)
key = contact.MobilePhone;
else if (contact.ContactPreference === 1)
key = contact.Email;
contacts.push({ Key: key, Value: contact.Name });
});
var param = JSON.stringify([wo.Id.Value, tempid, JSON.stringify(contacts)]);
param = htmlencode(param);
worequest("SendWorkOrderSurveys", param, function (data) {
if (data !== "") {
showAlert(data, GetTextByKey("P_WO_ERROR", 'Error'));
return;
}
}, function (err) {
showAlert(err, GetTextByKey("P_WO_ERROR", 'Error'));
showmaskbg(false);
});
$('#dialog_sendwosurveys').hideDialog();
showmaskbg(false);
}
function updateCommunicationAcknowledged(id, chk) {
var item = [id, chk];
var param = JSON.stringify(item);
param = htmlencode(param);
worequest('UpdateCommunicationAcknowledged', param, function (data) {
if (data !== 'OK') {
showAlert(data, GetTextByKey("P_WORKORDER", 'Work Order'));
}
}, function (err) {
});
}