$(function () { getWorkOrderCollapsed(); $('#addfollowerpopupdialog').dialog(function () { showmaskbg(false); }); $('#dialog_completedstatus').dialog(function () { showmaskbg(false); }); $('#selfollower_search').bind('input propertychange', function () { searchFollower(false); }); $('#selfollower_search').keydown(function () { searchFollower(false); }); }); function getWorkOrderCollapsed() { worequest("GetWorkOrderCollapsed", '', function (data) { if (typeof (data) === "string") { return; } if (data) { for (var i = 0; i < data.length; i++) { var item = data[i]; if (item.Value == "1" && $("#span" + item.Key).is(":visible")) { $("#span" + item.Key).removeClass("iconchevronright").addClass("iconchevrondown"); $("#tb" + item.Key).show(); //if ("customer" == item.Key) // grid_dtcontact && grid_dtcontact.resize(); //else if ("follower" == item.Key) // grid_dtfollower && grid_dtfollower.resize(); } else { $("#span" + item.Key).removeClass("iconchevrondown").addClass("iconchevronright"); $("#tb" + item.Key).hide(); } if (!AllowCustomer && item.Key === "customer") { $("#tb" + item.Key).hide(); } } } }, function (err) { }); } function saveWorkOrderCollapsed() { var items = []; items.push({ 'Key': 'asset', 'Value': $("#spanasset").hasClass('iconchevrondown') ? "1" : "0" }); items.push({ 'Key': 'customer', 'Value': $("#spancustomer").hasClass('iconchevrondown') ? "1" : "0" }); items.push({ 'Key': 'follower', 'Value': $("#spanfollower").hasClass('iconchevrondown') ? "1" : "0" }); items.push({ 'Key': 'summary', 'Value': $("#spansummary").hasClass('iconchevrondown') ? "1" : "0" }); items.push({ 'Key': 'cost', 'Value': $("#spancost").hasClass('iconchevrondown') ? "1" : "0" }); var param = JSON.stringify(items); param = htmlencode(param); worequest("SetWorkOrderCollapsed", param, function (data) { }, function (err) { }); } /*************************Customer********************************/ var customerid; var grid_dtcustomer; function InitGridCustomers() { grid_dtcustomer = new GridView('#customerlist'); grid_dtcustomer.lang = { all: GetTextByKey("P_GRID_ALL", "(All)"), ok: GetTextByKey("P_GRID_OK", "OK"), reset: GetTextByKey("P_GRID_RESET", "Reset") }; var list_columns = [ { name: 'Code', caption: GetTextByKey("P_CR_CODE", "Code"), valueIndex: 'Code', css: { 'width': 120, 'text-align': 'left' } }, { name: 'Name', caption: GetTextByKey("P_CR_COMPANYNAME", "Company Name"), valueIndex: 'Name', css: { 'width': 200, 'text-align': 'left' } }, { name: 'Address', caption: GetTextByKey("P_CR_ADDRESS", "Address"), valueIndex: 'Address', css: { 'width': 150, 'text-align': 'left' } }, { name: 'Notes', caption: GetTextByKey("P_CR_NOTES", "Notes"), valueIndex: 'Notes', css: { 'width': 200, 'text-align': 'left' } } ]; var columns = []; 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; columns.push(col); } grid_dtcustomer.canMultiSelect = true; grid_dtcustomer.columns = columns; grid_dtcustomer.init(); grid_dtcustomer.rowdblclick = function (rowindex) { var rowdata = grid_dtcustomer.source[rowindex]; if (rowdata) { //setCustomerData(rowdata.Values); OnSetSelectCustomer(); } }; } function showCustomerList(data) { var rows = []; for (var i = 0; i < data.length; i++) { var r = data[i]; var fr = { Values: r }; rows.push(fr); } grid_dtcustomer.setData(rows); } function onSelectCustomer() { grid_dtcustomer.setData([]); $('#txt_customer_key').val(''); $('#txt_customer_key').attr('disabled', true); $('#chkshowallcust').attr('checked', false); $('#dialog_customer .dialog-title span.title').text(GetTextByKey("P_WO_SELECTCUSTOMER", 'Select Customer')); showmaskbg(true); $('#dialog_customer') .attr('act', 'edit') .css({ 'top': (document.documentElement.clientHeight - $('#dialog_customer').height()) / 3, 'left': (document.documentElement.clientWidth - $('#dialog_customer').width()) / 2 }) .showDialog(); GetCustomerList(); } var allcustomers; function GetCustomerList() { grid_dtcustomer.setData([]); var chk = $('#chkshowallcust').prop('checked'); if (chk) { $('#txt_customer_key').attr('disabled', false); getAllCustomer(); } else { $('#txt_customer_key').attr('disabled', true); $('#txt_customer_key').val(''); getAssetCustomer(); } } function getAllCustomer() { if (allcustomers) getMatchCustomers(); else { customerquery('GetPartners', '', function (data) { if (typeof (data) === "string") { showAlert(data, GetTextByKey('P_CUSTOMERRECORD', "Customer Record")); showmaskbg(false); return; } allcustomers = data; getMatchCustomers(); }, function (err) { }); } } function getAssetCustomer() { if (!machineid) return; customerquery('GetAssignedPartnersByMachine', machineid, function (data) { if (typeof (data) === "string") { showAlert(data, GetTextByKey('P_CUSTOMERRECORD', "Customer Record")); showmaskbg(false); return; } showCustomerList(data); }, function (err) { }); } function getMatchCustomers() { var filter = $('#txt_customer_key').val().toLowerCase(); var _availablecustomers = []; if (allcustomers) { for (var i = 0; i < allcustomers.length; i++) { var m = allcustomers[i]; if (filter == "" || m.Code.toLowerCase().indexOf(filter) >= 0 || m.Name.toLowerCase().indexOf(filter) >= 0) { _availablecustomers.push(m); } } } showCustomerList(_availablecustomers); } function onCustomerKeyPress(e) { if (e.keyCode === 13) { GetCustomerList(); } }; function OnSetSelectCustomer() { var index = grid_dtcustomer.selectedIndex; if (index < 0) { showAlert(GetTextByKey("P_WO_PLEASESELECTACUSTOMER", "Please select a customer."), GetTextByKey("P_WO_SELECTCUSTOMER", "Select Customer")); return; } var cust = grid_dtcustomer.source[index].Values; setCustomerData(cust); } function setCustomerData(cust) { customerid = cust.Id; $('#dialog_salesperson').dropdownVal(cust.SalespersonIID); $('#dialog_custcustomername').text(cust.Name); $('#dialog_custcustomercode').text(cust.Code); $(".custcode").show(); if (typeof customer !== 'undefined') { customer.companyName = cust.Name; customer.companyCode = cust.Code; customer.setData('companyCode', cust.Code); } getCustomerContacts(cust.Id); getCustomerFollowers(cust.Id); $('#dialog_customer').hideDialog(); showmaskbg(false); } function OnAddCustomer() { execIframeFunc("init", [null, machineid], "iframeuser"); $('#contatcmask').show(); $('#dialog_addcustomer') .showDialogRight(); } function CloseCustomerDialog(type) { $('#dialog_addcustomer').hideDialog(); allcustomers = null; GetCustomerList(); $('#contatcmask').hide(); } /************************* Customer********************************/ //*************************Contact********************************// function getWorkOrderContacts(woid) { worequest('GetWorkOrderContacts', woid, function (data) { if (typeof (data) === "string") { showAlert(data, GetTextByKey('P_CUSTOMERRECORD', "Customer Record")); showmaskbg(false); return; } customercontacts = data || []; showCustomerContacts(customercontacts); }, function (err) { }); } var contact; function getCustomerContacts(custid, next) { worequest('GetCustomerContacts', custid, function (data) { if (typeof (data) === "string") { showAlert(data, GetTextByKey('P_CUSTOMERRECORD', "Customer Record")); if (next) next([]);//next 在Communication选Contacts时传入 else showcontatcmask(false); return; } if (next) { next(data);//next 在Communication选Contacts时传入 return; } showCustomerContacts(data); SaveWorkorderContact(); }, function (err) { }); } function showCustomerContacts(data) { if (customercontacts) { var temp = []; for (var i = 0; i < customercontacts.length; i++) {//移除上一个Customer的Contacts if (customercontacts[i].Id > 0) continue; temp.push(customercontacts[i]); } customercontacts = temp; } for (var i = 0; i < data.length; i++) { var r = data[i]; var item = { ...r }; var contactexists = false; if (customercontacts) { for (var j = 0; j < customercontacts.length; j++) { var ct = customercontacts[j]; if (ct.Name === item.Name && ct.MobilePhone === item.MobilePhone) { ct.Id = item.Id; contactexists = true; break; } } } if (!contactexists) customercontacts.push(item); } if (customer) { customer.setData('contacts', customercontacts); customer.contacts = customercontacts; } woestimateobj?.updatecontact(customercontacts); woinvoiceobj?.updatecontact(customercontacts); setPhoneNumber_statuschange(); } function SaveWorkorderContact(data, next) { if (!workorderid || workorderid == "") return; var custid = customerid; if (!custid) custid = -1; var param = JSON.stringify([workorderid, custid, JSON.stringify(data ?? customercontacts)]); param = htmlencode(param); worequest("SaveWorkOrderContact", param, function (data) { if (typeof next === 'function') { next(data); return; } if (typeof data === "string") { showAlert(data, GetTextByKey("P_WO_ERROR", 'Error')); return; } }, function (err) { //showmaskbg(false); }); } /*************************End Contact********************************/ //*************************Follwer********************************// function showWorkOrderFollowers(data) { if (typeof customer !== 'undefined') { customer.followers = data; } } function getWorkOrderFollowers(woid) { worequest('GetWorkOrderFollowers', woid, function (data) { if (typeof (data) === "string") { showAlert(data, GetTextByKey('P_CUSTOMERRECORD', "Customer Record")); showmaskbg(false); return; } followers = data; showWorkOrderFollowers(followers); }, function (err) { }); } function getCustomerFollowers(custid) { worequest('GetCustomerFollowers', custid, function (data) { if (typeof (data) === "string") { showAlert(data, GetTextByKey('P_CUSTOMERRECORD', "Customer Record")); showcontatcmask(false); return; } for (var i = 0; i < data.length; i++) { var fl = data[i]; var item = {}; item.Id = -1; item.UserIID = fl.UserIID; item.Name = fl.Name; item.Email = fl.Email; item.MobilePhone = fl.MobilePhone; item.SendEmail = fl.SendEmail; item.SendText = fl.SendText; var followerexists = false; if (followers) { for (var j = 0; j < followers.length; j++) { var ct = followers[j]; if (ct.UserIID === item.UserIID) { followerexists = true; break; } } } if (!followerexists) followers.push(item); } SaveWorkOrderFollower(); showWorkOrderFollowers(followers); }, function (err) { }); } var isloadfollower = false; var allfollowers = []; function getAllFollowers(next) { worequest('GetAllFollowers', '', function (data) { if (typeof next === 'function') { next(data); } else { if (typeof (data) === "string") { showAlert(data, GetTextByKey('P_CUSTOMERRECORD', "Customer Record")); showmaskbg(false); return; } isloadfollower = true; allfollowers = data; showAllFollower(data); } }, function (err) { }); } function showAllFollower(data) { if (typeof customer !== 'undefined') { customer.setData('allfollowers', data); } } function SaveWorkOrderFollower(next) { if (!workorderid || workorderid == "") return; var param = JSON.stringify([workorderid, JSON.stringify(followers)]); param = htmlencode(param); worequest("SaveWorkOrderFollower", param, function (data) { if (typeof next === 'function') { next(data); } else { if (data !== "OK") { showAlert(data, GetTextByKey("P_WO_ERROR", 'Error')); return; } } }, function (err) { //showmaskbg(false); }); } /*************************End Follwer********************************/ /*****************************************Begin Completed Status**************************************************/ var cur_exit = 0; var cur_callback = undefined; function openCompletedStatusDialog(exit, callback) { cur_exit = exit; cur_callback = callback; $('#dialog_completed_status').dropdownVal(''); showmaskbg(true); $('#dialog_completedstatus').css({ 'top': (document.documentElement.clientHeight - $('#dialog_completedstatus').height()) / 3, 'left': (document.documentElement.clientWidth - $('#dialog_completedstatus').width()) / 2 }).showDialogfixed(); } function hideCompletedStatusPopup() { showmaskbg(false); $('#dialog_completedstatus').hide(); } function onSaveCompletedStatus() { var s = $('#dialog_completed_status').dropdownVal(); $('#dialog_status').dropdownVal(s); $('.span_required').show(); hideCompletedStatusPopup(); OnSave(cur_exit, cur_callback); } /*****************************************End Completed Status**************************************************/