1 line
175 KiB
JavaScript
1 line
175 KiB
JavaScript
function locale(n,t){var r;if(!t)return n;if(r=n,typeof n!="number"&&(n=Number(n)),isNaN(n))return r;var f=n.toFixed(2),u=f.split("."),i=u[0].split("").reverse().join("").replace(/(\d{3})+?/g,function(n){return n+","}).split("").reverse().join("");return i[0]==","&&(i=i.substring(1)),i+"."+u[1]}function OnExpendInTab(n){var t=$(n),i=t.attr("target");t.hasClass("iconchevrondown")?(t.removeClass("iconchevrondown").addClass("iconchevronright"),$("#"+i).hide()):(t.removeClass("iconchevronright").addClass("iconchevrondown"),$("#"+i).show())}function getMessageStatusHistoryText(n){var t=function(n){switch(n){case 0:return GetTextByKey("P_CU_PENDING","Pending");case 1:return GetTextByKey("P_WO_SENT","Sent");case 5:return GetTextByKey("P_CU_DELIVERYCONFIRMED","Delivery Confirmed");case 6:return GetTextByKey("P_CU_RESENT","Resent");case 9:case 10:case 412:return GetTextByKey("P_MA_FAILED","Failed");default:return GetTextByKey("P_CU_UNKNOWN","Unknown")}};return GetTextByKey("P_CU_UPDATESTATUSDESC","Status changed from {0} to {1}\nBy {2} on {3}").replace("{0}",t(n.History.StatusFrom)).replace("{1}",t(n.History.StatusTo)).replace("{2}",n.History.UpdatedBy).replace("{3}",n.UpdatedOnStr)}typeof $woinspection!="function"&&($woinspection=function(n){function u(){i&&i.css("height",$(window).height()-i.offset().top-4)}function e(){(i.empty(),f=[],t.option.workorderid&&t.option.workorderid!="")&&(r||(r=!0,typeof t.option.showloading=="function"&&t.option.showloading(!0),worequest("GetWOInspectItems",JSON.stringify([t.option.workorderid,t.option.machineid]),function(n){if(r=!1,typeof t.option.showloading=="function"&&t.option.showloading(!1),typeof n=="string"){showAlert(n,GetTextByKey("P_WO_ERROR","Error"));return}if(n.WorkOrderID!=t.option.workorderid){e();return}n=n.Data;n&&n.length>0?(f=n[0].WorkOrders,o(n)):(i.empty(),i.append($('<div class="noinspection"><\/div>').text(GetTextByKey("P_WO_NOINSPECTION","No Inspection"))));u()},function(){r=!1;typeof t.option.showloading=="function"&&t.option.showloading(!1)})))}function o(n){var a=i,o,e,l,v,p;for(a.empty(),o=0;o<n.length;o++){var t=n[o],y="tbinspect_"+o,u=$('<div class="subtitle" style="position:relative;"><\/div>'),r=$('<span class="sbutton iconchevronright" target="'+y+'" style="margin-left: 0; padding-right: 5px;"><\/span>').data("iptid",t.Id).click(function(){var n=$(this),r=n.attr("target"),i,t;n.hasClass("iconchevrondown")?(n.removeClass("iconchevrondown").addClass("iconchevronright"),$("#"+r).hide()):(n.removeClass("iconchevronright").addClass("iconchevrondown"),$("#"+r).show(),i=n.data("iptid"),t=$("#iframe_"+i),t.data("load")==0&&(t.attr("src","../Inspection/ReportForWorkOrder.aspx?rid="+i),t.data("load",1)))});if(u.append(r),canExport){r=$('<span class="sbutton icondownload" style="padding: 5px 4px 6px 10px;"><\/span>');r.attr("title",GetTextByKey("P_IPT_DOWNLOAD","Download")).on("click",t,function(n){window.open("../Inspection/Inspection.aspx?rt=f&t=1&id="+n.data.Id+"&team=0","_blank")});u.append(r);r=$('<span class="sbutton iconprint" style="padding: 5px 4px 6px 10px;"><\/span>');r.attr("title",GetTextByKey("P_IPT_PRINT","Print")).on("click",t,function(n){if(navigator.userAgent.indexOf("Firefox")>=0||navigator.userAgent.indexOf("Opera")>=0){window.open("../Inspection/Inspection.aspx?rt=f&t=2&id="+n.data.Id+"&team=0","_blank");return}if($("#ifdiv").attr("src","../Inspection/Inspection.aspx?rt=f&t=2&id="+n.data.Id+"&team=0"),!$("#ifdiv").data("inited")){$("#ifdiv").on("load",function(){s()});$("#ifdiv").data("inited",1)}})}if(u.append(r),!WOReadOnly){r=$('<span class="sbutton iconview" style="padding: 5px 4px 6px 10px;"><\/span>');t.VisibleToCustomer?r.data("checked",!0).removeClass("iconnotview").addClass("iconview").attr("title",GetTextByKey("P_WO_CUSTOMERVISIBLE","Customer Visible")):r.data("checked",!1).removeClass("iconview").addClass("iconnotview").attr("title",GetTextByKey("P_WO_NOTCUSTOMERVISIBLE","Not Customer Visible"));u.append(r);r.data("checked",t.VisibleToCustomer).on("click",t,function(n){var t=$(n.target);t.data("checked")==!0?t.data("checked",!1).removeClass("iconview").addClass("iconnotview").attr("title",GetTextByKey("P_WO_NOTCUSTOMERVISIBLE","Not Customer Visible")):t.data("checked",!0).removeClass("iconnotview").addClass("iconview").attr("title",GetTextByKey("P_WO_CUSTOMERVISIBLE","Customer Visible"));c(n.data.Id,t.data("checked"))})}if(e=$('<span class="sttitle" style="width:220px;"><\/span>').text(t.TemplateName),u.append(e),e=$('<span class="sttitle" style="width:280px;"><\/span>').text(t.CommitTimeLocalStr+" by "+t.CommitedByUserName),u.append(e),u.append(e),AllowReassignWorkorders){e=$('<span style="margin-left:5px;"><\/span>').text(GetTextByKey("P_WO_WO_COLON","WO:"));u.append(e);l=$('<div style="margin-left:8px;width: 200px;display:inline-block;" class="dropdown"><\/div>');l.attr({"inspection-id":t.Id,"old-wo-id":t.WorkOrderId}).dropdown(f||[],{input:!1,valueKey:"Id",textKey:"WorkOrderNumber"}).on("select",function(n,t){var i=$(n.target),r,u;t&&t.Id!=i.attr("old-wo-id")&&(r=GetTextByKey("P_WO_AREYOUSURETHATYOUWANTTOPROCEED","Are you sure that you want to proceed ?"),u=GetTextByKey("P_WO_YOUAREREASSIGNINGTHISWORKORDER","You are reassigning this work order. ")+"<br/>"+r,t.Completed&&(u=GetTextByKey("P_WO_YOUAREREASSIGNINGTHISWORKORDERTOACLOSEDWORKORDER","You are reassigning this Work Order to a CLOSED Work Order.")+"<br/>"+r),showConfirm(u,GetTextByKey("P_WO_WORKORDERASSIGNMENT","Work Order Assignment"),function(){h(i.attr("inspection-id"),t.Id)},function(){i.dropdownVal(i.attr("old-wo-id"))}))});l.dropdownVal(t.WorkOrderId);u.append(l)}u.append("<hr />");a.append(u);v=$('<table style="display: none;width:100%;" id="'+y+'"><\/table>');tr=$("<tr><\/tr>");td=$("<td><\/td>");p=$('<iframe style="width: 100%; height:900px;; display: block; border: none;"><\/iframe>').attr("id","iframe_"+t.Id).data("load",0);td.append(p);tr.append(td);v.append(tr);a.append(v)}}function s(){var n=document.getElementById("ifdiv");n.contentWindow.focus();n.contentWindow.print()}function h(n,i){var r=JSON.stringify([n,i,t.option.workorderid]);worequest("UpdateInspectionWorkOrder",htmlencode(r),function(n){if(typeof n=="string"){showAlert(n,GetTextByKey("P_WO_WORKORDERASSIGNMENT","Work Order Assignment"));return}e()},function(){})}function c(n,t){var r=[n,t],i=JSON.stringify(r);i=htmlencode(i);worequest("UpdateInspectionVisibleToCustomer",i,function(n){n!=="OK"&&showAlert(n,GetTextByKey("P_WO_AVAILABLETOCUSTOMER","Available to Customer"))},function(){})}var t,i,f,r;this.option=n||{};t=this;i=null;this.changewo=function(n,t){this.option.workorderid=n;t&&(this.option.machineid=t);i&&i.empty();e()};this.close=function(){};this.changeasset=function(n){this.option.machineid=n};this.createInspectionDiv=function(n){i=$('<div style=" min-width: 1000px; height: 668px;"><\/div>');n.append(i);n.applyFleetLanguageText(!0)};this.createInspectionDiv(this.option.parent);this.option.inwidget||(i.addClass("overflow","auto"),window.onresize=u,u());r=!1});typeof $woestimate!="function"&&($woestimate=function(n){function lt(){var r=$('<div class="dialog" style="display: none;"><\/div>'),i,t,n,a,v,y,c,p,w,k,g,nt,tt,it,rt,ut,l,f,e,o,u,s,h;r.on("drop",function(n){ei(n.originalEvent)}).on("dragover",function(n){fi(n.originalEvent)}).on("paste",function(n){oi(n.originalEvent)});r.append('<div class="dialog-title"><span class="title" data-lgid="P_WO_ADDESTIMATE">Add Estimate<\/span><em class="dialog-close"><\/em><\/div>');i=$("<table><\/table>");r.append($('<div class="dialog-content"><\/div>').append(i));t=$("<tr><\/tr>").appendTo(i);n=$('<td class="label" data-lgid="P_WO_ESTIMATENUMBER_COLON">Estimate #:<\/td>').appendTo(t);n=$("<td><\/td>").appendTo(t);a=$('<input type="text" id="dialog_est_number" tabindex="1" maxlength="50" style="width:150px;" autocomplete="off" />').appendTo(n);n=$('<td class="label" data-lgid="P_WO_ESTIMATESTATUS_COLON">Estimate Status:<\/td>').appendTo(t);n=$("<td><\/td>").appendTo(t);v=$('<span id="dialog_est_status">Draft<\/span>').appendTo(n);t=$("<tr><\/tr>").appendTo(i);n=$('<td class="label" data-lgid="P_WO_ESTIMATETOTALCOST_COLON">Estimate Total Cost ($):<\/td>').appendTo(t);n=$('<td class="cont"><\/td>').appendTo(t);y=$('<input type="text" id="dialog_est_totalcosts" maxlength="12" style="width:150px;" tabindex="1" autocomplete="off">').appendTo(n);c=$('<span class="sbutton iconequel" style="padding: 3px 1px 3px 6px; font-size: 12px;" data-title-lgid="P_WO_CALCULATINGTOTALS" title="Calculating Totals"><\/span>').appendTo(n);c.on("click",function(){d("")});n=$('<td class="label" data-lgid="P_WO_OTHERCOST_COLON">Other Cost ($):<\/td>').appendTo(t);n=$("<td><\/td>").appendTo(t);p=$('<input type="text" id="dialog_est_othercost" maxlength="12" style="width:150px;" tabindex="1" autocomplete="off" />').appendTo(n);t=$("<tr><\/tr>").appendTo(i);n=$('<td class="label" data-lgid="P_WO_PARTSCOST_COLON">Parts Cost ($):<\/td>').appendTo(t);n=$("<td><\/td>").appendTo(t);w=$('<input type="text" id="dialog_est_partscost" maxlength="12" style="width:150px;" tabindex="1" autocomplete="off" />').appendTo(n);n=$('<td class="label" data-lgid="P_WO_TRAVELTIMECOST_COLON">Travel Time Cost ($):<\/td>').appendTo(t);n=$("<td><\/td>").appendTo(t);k=$('<input type="text" id="dialog_est_traveltimecost" maxlength="12" style="width:150px;" tabindex="1" autocomplete="off" />').appendTo(n);t=$("<tr><\/tr>").appendTo(i);n=$('<td class="label" data-lgid="P_WO_LABORCOST_COLON">Labor Cost ($):<\/td>').appendTo(t);n=$("<td><\/td>").appendTo(t);g=$('<input type="text" id="dialog_est_laborcost" maxlength="12" style="width:150px;" tabindex="1" autocomplete="off" />').appendTo(n);n=$('<td class="label" data-lgid="P_WO_TIMETOCOMPLATEHOURS_COLON">Labor Hours:<\/td>').appendTo(t);n=$("<td><\/td>").appendTo(t);nt=$('<input type="text" id="dialog_est_timetocomplete" maxlength="12" style="width:150px;" tabindex="1" autocomplete="off" />').appendTo(n);t=$("<tr><\/tr>").appendTo(i);n=$('<td class="label" data-lgid="P_WO_TAXES_COLON">Taxes ($):<\/td>').appendTo(t);n=$("<td><\/td>").appendTo(t);tt=$('<input type="text" id="dialog_est_taxes" maxlength="12" style="width:150px;" tabindex="1" autocomplete="off" />').appendTo(n);n=$('<td class="label" data-lgid="P_WO_POREQUIRED_COLON">PO Required:<\/td>').appendTo(t);n=$("<td><\/td>").appendTo(t);it=$('<input type="checkbox" id="dialog_est_porequired" style="width: auto;" tabindex="1" />').appendTo(n);t=$("<tr><\/tr>").appendTo(i);n=$('<td class="label" data-lgid="P_WO_CUSTOMERISSUES_COLON" style="vertical-align: top;">Customer Issues:<\/td>').appendTo(t);n=$('<td colspan="3"><\/td>').appendTo(t);rt=$('<textarea id="dialog_est_custissues" tabindex="1" maxlength="2000" style="height:80px;width:450px;"><\/textarea>').appendTo(n);t=$("<tr><\/tr>").appendTo(i);n=$('<td class="label" data-lgid="P_WO_TECHNICIANNOTES_COLON" style="vertical-align: top;">Technician Notes:<\/td>').appendTo(t);n=$('<td colspan="3"><\/td>').appendTo(t);ut=$('<textarea id="dialog_est_technotes" tabindex="1" maxlength="500" style="height:80px;width:450px;"><\/textarea>').appendTo(n);t=$("<tr><\/tr>").appendTo(i);n=$('<td class="label" data-lgid="P_WO_ATTACHMENTS_COLON" style="vertical-align: top;">Attachments:<\/td>').appendTo(t);n=$('<td colspan="3"><\/td>').appendTo(t);l=$('<span class="sbutton iconadd" data-lgid="P_WO_ADDFILE">Add File<\/span>').appendTo(n);l.on("click",function(){ct("")});t=$("<tr><\/tr>").appendTo(i);n=$('<td class="label"><\/td>').appendTo(t);n=$('<td colspan="3"><\/td>').appendTo(t);f=$('<table id="tab_est_attachments" style="border: 1px solid #a8a8a8; line-height: 25px; width: 320px; display: none;"><\/table>');n.append(f);e=$("<tr><\/tr>");f.append(e);o=$("<td><\/td>");e.append(o);div_att=$('<div style="max-height: 80px; overflow: auto;padding: 0 4px;"><\/div>');o.append(div_att);f=$('<table id="tab_est_atts" style="table-layout: fixed;"><\/table>');div_att.append(f);u=$('<div class="dialog-func"><\/div>');r.append(u);u.append('<input type="button" value="Cancel" data-lgid="P_WO_CANCEL" class="dialog-close" tabindex="11" />');s=$('<input type="button" value="Publish" data-lgid="P_WO_PUBLISH" tabindex="11" />');s.on("click",function(){et(-1)});u.append(s);h=$('<input type="button" value="OK" data-lgid="P_WO_OK" tabindex="11" />');h.on("click",function(){b("")});return u.append(h),u.append('<div class="clear"><\/div>'),r.append('<div class="maskbg" style="display: none;"><\/div>'),$(document.body).append(r),r.dialog(function(){showmaskbg(!1)}),r.applyFleetLanguageText(!0),r}function at(){var e=$('<div class="dialog" style="display: none;"><\/div>'),o,l,a,f,h,v,s;e.append('<div class="dialog-title"><span class="title" data-lgid="P_WO_PUBLISHESTIMATE">Publish Estimate<\/span><em class="dialog-close"><\/em><\/div>');o=$('<table style="line-height: 30px; margin-left: 10px; margin-right: 10px;"><\/table>');e.append($('<div class="dialog-content"><\/div>').append(o));var t=$("<tr><\/tr>").appendTo(o),n=$('<td style="text-align: right;"><\/td>').appendTo(t),c=$('<input id="dialog_est_chksendtextmsg" type="checkbox" checked="checked" style="width: unset;" />').appendTo(n);c.change(function(){var n=$("#dialog_est_chksendtextmsg").prop("checked");$("#dialog_est_phonenum").prop("disabled",!n);$("#dialog_est_chkIncludeStatusLink").prop("disabled",!n);$("#dialog_est_textmsg").prop("disabled",!n)});n=$("<td><\/td>").appendTo(t);$('<label for="dialog_est_chksendtextmsg" data-lgid="P_WO_SENDUPDATETOCUSTOMER" style="user-select: none;">Send Update To Customer<\/label>').appendTo(n);t=$("<tr><\/tr>").appendTo(o);n=$("<td><\/td>").appendTo(t);$('<div style="font-size: 20px; margin-right: 5px; float: right;"><em class="spanbtn iconmobile" style="font-weight: 900; font-size: 14px; cursor: default; padding-left: 0; padding-right: 3px; padding-top: 0;"><\/em><\/div>').appendTo(n);n=$("<td><\/td>").appendTo(t);l=$('<input type="text" id="dialog_est_phonenum" tabindex="1" autocomplete="off" maxlength="100" style="width: 320px;" />').appendTo(n);t=$("<tr><\/tr>").appendTo(o);n=$('<td style="text-align: right;"><\/td>').appendTo(t);a=$('<input id="dialog_est_chkIncludeStatusLink" type="checkbox" checked="checked" style="width: unset;" />').appendTo(n);n=$("<td><\/td>").appendTo(t);$('<label for="dialog_est_chkIncludeStatusLink" data-lgid="P_WO_INCLUDESTATUSLINK" style="user-select: none;">Include Status Link<\/label>').appendTo(n);t=$("<tr><\/tr>").appendTo(o);n=$('<td style="text-align: right;"><\/td>').appendTo(t);$('<input id="dialog_est_chkSendAttachment" type="checkbox" style="width: unset;" />').on("click",function(){var o,s,h,n,t,f,c;if(!this.disabled){if(o=document.querySelector("#dialog_est_spanAttachmentName"),!this.checked){r=null;o.style.display="none";return}if(s=i<=0?u.map(function(n){return{file:n.File,name:n.Notes||n.File.name,enabled:/^image\//.test(n.File.type)||n.File.size<=2097152}}):p.find(n=>n.Id===i)?.Attachments?.map(function(n){return{id:n.AttachmentId,name:n.Notes||n.FileName,enabled:!0}}),h=s.filter(function(n){return n.enabled}),h.length===1){r=h[0];o.innerText=r.name;o.style.display="block";return}r=null;n=window["lib-ui"];t=n.createElement("div");t.style.width="440px";t.style.height="300px";f=new n.Grid(t);f.columns=[{key:"selected",type:n.Grid.ColumnTypes.Checkbox,enabled:"enabled",sortable:!1,orderable:!1,resizable:!1,onchanged:function(n){for(var t of this.source)t!==n&&(t.selected=!1);this.refresh()}},{key:"name",caption:GetTextByKey("P_WO_NAME","Name"),width:340,orderable:!1}];f.init();c=new n.Popup({title:GetTextByKey("P_WO_SELECTATTACHMENT","Select Attachment"),content:t,resolve:function(){var n=document.querySelector("#dialog_est_spanAttachmentName");r==null?(document.querySelector("#dialog_est_chkSendAttachment").checked=!1,n.style.display="none"):(n.innerText=r.name,n.style.display="block")},buttons:[{text:GetTextByKey("P_WO_ATTACH","Attach"),trigger:function(){var n=f.source.filter(function(n){return n.selected})[0];n!=null&&(r=n)}},{text:GetTextByKey("P_WO_CANCEL","Cancel")}]});c.show(e[0]).then(function(){f.source=s})}}).appendTo(n);n=$("<td><\/td>").appendTo(t);$('<label for="dialog_est_chkSendAttachment" data-lgid="P_WO_SENDESTIMATEASATTACHMENT" style="user-select: none;">Send Estimate as Attachment<\/label>').appendTo(n);t=$("<tr><\/tr>").appendTo(o);n=$("<td><\/td>").appendTo(t);n=$("<td><\/td>").appendTo(t);$('<span id="dialog_est_spanAttachmentName" style="user-select: none; color: gray; display: block; white-space: nowrap; max-width: 300px; overflow: hidden; text-overflow: ellipsis; display: none"><\/span>').appendTo(n);t=$("<tr><\/tr>").appendTo(o);n=$('<td class="label" style="width: unset;"><span data-lgid="P_WO_MESSAGE_COLON">Message:<\/span><\/td>').appendTo(t);n=$("<td><\/td>").appendTo(t);f=$('<select id="dialog_est_variables" style="width: 156px;"><\/select>').appendTo(n);f.append('<option value="0">[Site_Name]<\/option>');f.append('<option value="1">[Location]<\/option>');f.append('<option value="14">[Asset]<\/option>');f.append('<option value="4">[VIN]<\/option>');f.append('<option value="2">[Make]<\/option>');f.append('<option value="3">[Model]<\/option>');f.append('<option value="5">[Id_Phone]<\/option>');f.append('<option value="6">[Advisor]<\/option>');f.append('<option value="7">[Company_Name]<\/option>');f.append('<option value="8">[Contact_Name]<\/option>');f.append('<option value="9">[Contact_First_Name]<\/option>');f.append('<option value="10">[Status_Link]<\/option>');f.append('<option value="11">[Technician_Name]<\/option>');f.append('<option value="12">[Work_Order_Number]<\/option>');f.append('<option value="13">[Parts_Order_Number]<\/option>');h=$('<input type="button" id="dialog_est_insertfield" data-lgid="P_WO_ADD" value="Add" style="width: auto; height: auto; margin-left: 5px;" tabindex="1" /><br />').appendTo(n);h.on("click",function(){yt()});v=$('<textarea id="dialog_est_textmsg" tabindex="1" style="width: 320px; height: 120px; margin-top: 6px;" maxlength="2000"><\/textarea>').appendTo(n);s=$('<div class="dialog-func"><\/div>');e.append(s);s.append('<input type="button" value="Cancel" data-lgid="P_WO_CANCEL" class="dialog-close" tabindex="11" />');btn_publish=$('<input type="button" value="Publish" data-lgid="P_WO_PUBLISH" tabindex="1" />');btn_publish.on("click",function(){ii()});return s.append(btn_publish),s.append('<div class="clear"><\/div>'),e.append('<div class="maskbg" style="display: none;"><\/div>'),$(document.body).append(e),e.dialog(function(){ft()}),e.applyFleetLanguageText(!0),e}function vt(){var i=$('<div class="dialog" style="display: none;"><\/div>'),r,n,t,h,s,u,e,o,f;i.append('<div class="dialog-title"><span class="title" data-lgid="P_WO_ADDATTACHMENT">Add Attachment<\/span><em class="dialog-close"><\/em><\/div>');r=$('<table style="line-height: 30px; margin-left: 10px; margin-right: 10px;"><\/table>');i.append($('<div class="dialog-content"><\/div>').append(r));n=$("<tr><\/tr>").appendTo(r);t=$('<td class="label" style="width: unset;"><span data-lgid="P_WO_CAPTION_COLON">Caption:<\/span><\/td>').appendTo(n);t=$("<td><\/td>").appendTo(n);h=$('<input type="text" id="dialog_estatt_notes" maxlength="200" tabindex="1" autocomplete="off" />').appendTo(t);n=$("<tr><\/tr>").appendTo(r);t=$('<td class="label" data-lgid="P_WO_ATTACHMENTS_COLON" style="vertical-align: top; width: unset;">Attachments:<\/td>').appendTo(n);t=$('<td class="cont"><\/td>').appendTo(n);s=$('<input id="dialog_woestatt_uploadattfile" type="button" value="Add File..." data-lgid="P_FR_ADDFILE" tabindex="1" style="background-color: #0099FF; color: #FFFFFF; height: 20px; width: 200px;" />').appendTo(t);s.on("click",function(){si()});n=$("<tr><\/tr>").appendTo(r);t=$('<td class="label"><\/td>').appendTo(n);t=$('<td colspan="3"><\/td>').appendTo(n);u=$('<table id="tab_woest_attachments" style="border: 1px solid #a8a8a8; line-height: 25px; width: 320px; display: none;"><\/table>');t.append(u);e=$("<tr><\/tr>");u.append(e);o=$("<td><\/td>");e.append(o);div_att=$('<div style="max-height: 80px; overflow: auto;padding: 0 4px;"><\/div>');o.append(div_att);u=$('<table id="tab_woest_atts" style="table-layout: fixed;"><\/table>');div_att.append(u);f=$('<div class="dialog-func"><\/div>');i.append(f);f.append('<input type="button" value="Cancel" data-lgid="P_WO_CANCEL" class="dialog-close" tabindex="11" />');c=$('<input type="button" value="Save" data-lgid="P_WO_SAVE" tabindex="11" />');c.on("click",function(){nt()});return f.append(c),f.append('<div class="clear"><\/div>'),i.append('<div class="maskbg" style="display: none;"><\/div>'),$(document.body).append(i),i.dialog(function(){g()}),i.applyFleetLanguageText(!0),i}function yt(){var n=$("#dialog_est_variables").find("option:selected").text();$("#dialog_est_textmsg").focus();document.execCommand("insertText",!1,n)}function pt(){showmaskbg(!0);e.css({top:(document.documentElement.clientHeight-e.height())/3,left:(document.documentElement.clientWidth-e.width())/2}).showDialogfixed()}function wt(){showmaskbg(!1);e.hide()}function h(n){(n||(t.option.parent.find(".estimates_div").remove(),t.option.parent.find(".estimates_table").remove()),t.option.workorderid&&t.option.workorderid!="")&&(v||(v=!0,typeof t.option.showloading=="function"&&t.option.showloading(!0),worequest("GetWorkOrderEstimates",t.option.workorderid,function(n){if(v=!1,typeof t.option.showloading=="function"&&t.option.showloading(!1),typeof n=="string"){showAlert(n,GetTextByKey("P_WO_ERROR","Error"));return}if(n.WorkOrderID!=t.option.workorderid){h(!1);return}if(n=n.Data,t.option.parent.find(".estimates_div").remove(),t.option.parent.find(".estimates_table").remove(),n)if(n&&n.length>0){p=n;AllowCustomer&&$("#dialog_estimatestatus").text(t.getEstimateStatus(n[n.length-1].Status));for(var i=0;i<n.length;i++)bt(n[i])}else AllowCustomer&&$("#dialog_estimatestatus").text(t.getEstimateStatus(100))},function(){v=!1;typeof t.option.showloading=="function"&&t.option.showloading(!1)})))}function tt(n){n.preventDefault();n.dataTransfer.dropEffect="link"}function it(n,t){var r,u,f,i,e,o;if(n.preventDefault(),n.stopPropagation(),r=n.dataTransfer,u=[],r.items!==undefined)for(f=0;f<r.items.length;f++)if(i=r.items[f],i.kind==="file"&&(i.webkitGetAsEntry()==null||i.webkitGetAsEntry().isFile)){if(e=i.getAsFile(),e.size==0){alert(GetTextByKey("P_WO_ATTACHMENTSTIPS","Attachment size is 0kb, uploading failed."));return}if(e.size>52428800){alert(GetTextByKey("P_WO_ATTACHMENTSTIPS1","Attachment is too large. Maximum file size is 50 MB."));return}u.push({File:e,Notes:""})}(o=$("#tabestimate"+t).data("estimate"),o)&&o.Status===0&&u.length>0&&k(u,t)}function rt(n,t){var r,u,f,i,e,o;if(n.stopPropagation(),r=n.clipboardData,u=[],r.items!==undefined)for(f=0;f<r.items.length;f++)if(i=r.items[f],i.kind==="file"&&(i.webkitGetAsEntry()==null||i.webkitGetAsEntry().isFile)){if(e=i.getAsFile(),e.size==0){alert(GetTextByKey("P_WO_ATTACHMENTSTIPS","Attachment size is 0kb, uploading failed."));return}if(e.size>52428800){alert(GetTextByKey("P_WO_ATTACHMENTSTIPS1","Attachment is too large. Maximum file size is 50 MB."));return}u.push({File:e,Notes:""})}(o=$("#tabestimate"+t).data("estimate"),o)&&o.Status===0&&u.length>0&&k(u,t)}function bt(n){var u=n.Id,nt=t.getEstimateStatus(n.Status),ut=t.option.parent,h=$('<div id="divestimate'+u+'" class="subtitle estimates_div" style="margin-right:0px;"><\/div>'),a,e,r,i,f,v,s,ft,p,ot,c,w,l,k,g;h.on("drop",u,function(n){it(n.originalEvent,n.data)}).on("dragover",u,function(n){tt(n.originalEvent,n.data)}).on("paste",u,function(n){rt(n.originalEvent,n.data)});if(h.append('<span class="sbutton iconchevronright" target="tabestimate'+u+'" onclick="OnExpendInTab(this)" style="margin-left: 0; padding-right: 5px;"><\/span>'),h.append('<span class="sttitle" id="span_estnumber'+u+'">'+n.EstimateNumber+"<\/span>"),h.append('<span class="sttitle" id="span_eststatus'+u+'" style="font-weight:bold;width:320px;">'+nt+"<\/span>"),!WOReadOnly&&(n.Status==0||n.Status===1)){a=$('<span class="sbutton icondelete" style="float:right;margin-right: 10px; padding: 0px 0px 0px 5px;"><\/span>');a.on("click",u,function(n){gt(n.data)});h.append(a)}h.append("<hr />");ut.append(h);e=$('<table id="tabestimate'+u+'" class="estimates_table"><\/table>').data("estimate",n).hide();e.on("drop",u,function(n){it(n.originalEvent,n.data)}).on("dragover",u,function(n){tt(n.originalEvent,n.data)}).on("paste",u,function(n){rt(n.originalEvent,n.data)});if(ut.append(e),r=$("<tr><\/tr>"),e.append(r),i=$('<td class="label"><\/td>').text(GetTextByKey("P_WO_ESTIMATENUMBER_COLON","Estimate #:")),r.append(i),i=$('<td style="width:150px;"><\/td>'),r.append(i),f=$('<input type="text" id="dialog_est_number'+u+'" tabindex="1" maxlength="50" autocomplete="off" />').val(n.EstimateNumber).change(function(n){return function(){o(n)}}(u)),i.append(f),i=$('<td class="label"><\/td>').text(GetTextByKey("P_WO_ESTIMATESTATUS_COLON","Estimate Status:")),r.append(i),i=$("<td><\/td>"),r.append(i),f=$('<span style="font-weight:bold;" id="dialog_est_status'+u+'"><\/span>').text(nt),i.append(f),[3,4,5].indexOf(n.Status)>=0?(i=$('<td class="label"><\/td>'),n.Status==3?i.text(GetTextByKey("P_WO_REJECTEDBY_COLON","Rejected By:")):(n.Status==4||n.Status==5)&&i.text(GetTextByKey("P_WO_APPROVEDBY_COLON","Approved By:")),r.append(i),i=$("<td><\/td>"),r.append(i),v="",n.ResponsePhoneStr!==""&&(v=" ("+n.ResponsePhoneStr+")"),f=$('<span id="dialog_est_crn'+u+'"><\/span>').text(n.ResponseName+v),i.append(f)):r.append('<td cospan="2"><\/td>'),s=n.Status===y.Pending||n.Status===y.Declined||n.Status===y.Approved||n.Status===y.Void,r=$("<tr><\/tr>"),e.append(r),i=$('<td class="label"><\/td>').text(GetTextByKey("P_WO_ESTIMATETOTALCOST_COLON","Estimate Total Cost ($):")),r.append(i),i=$('<td style="display: inline-flex;"><\/td>'),r.append(i),f=$('<input type="text" id="dialog_est_totalcosts'+u+'" tabindex="1" maxlength="12" autocomplete="off"/>').val(locale(n.TotalCost,s)),i.append(f),ft=$("<span class='sbutton iconequel' style='padding:3px 1px 3px 6px;font-size:12px;margin-left:2px;'><\/span>").click(u,function(n){d(n.data)}).attr("title",GetTextByKey("P_WO_CALCULATINGTOTALS","Calculating Totals")),i.append(ft),i=$('<td class="label"><\/td>').text(GetTextByKey("P_WO_OTHERCOST_COLON","Other Cost ($):")),r.append(i),i=$("<td><\/td>"),r.append(i),f=$('<input type="text" id="dialog_est_othercost'+u+'" tabindex="1" maxlength="12" autocomplete="off" />').val(locale(n.OtherCost,s)).change(function(n){return function(){o(n)}}(u)),i.append(f),[3,4,5].indexOf(n.Status)>=0?(i=$('<td class="label"><\/td>'),n.Status==3?i.text(GetTextByKey("P_WO_REJECTEDTIME_COLON","Rejected Time:")):(n.Status==4||n.Status==5)&&i.text(GetTextByKey("P_WO_APPROVEDTIME_COLON","Approved Time:")),r.append(i),i=$("<td><\/td>"),r.append(i),f=$('<span id="dialog_est_crt'+u+'"><\/span>').text(n.CustomerResponseTimeStr),i.append(f)):r.append('<td cospan="2"><\/td>'),r=$("<tr><\/tr>"),e.append(r),i=$('<td class="label"><\/td>').text(GetTextByKey("P_WO_PARTSCOST_COLON","Parts Cost ($):")),r.append(i),i=$("<td><\/td>"),r.append(i),f=$('<input type="text" id="dialog_est_partscost'+u+'" tabindex="1" maxlength="12" autocomplete="off" />').val(locale(n.PartsCost,s)).change(function(n){return function(){o(n)}}(u)),i.append(f),i=$('<td class="label"><\/td>').text(GetTextByKey("P_WO_TRAVELTIMECOST_COLON","Travel Time Cost ($):")),r.append(i),i=$("<td><\/td>"),r.append(i),f=$('<input type="text" id="dialog_est_traveltimecost'+u+'" tabindex="1" maxlength="12" autocomplete="off" />').val(locale(n.TravelCost,s)).change(function(n){return function(){o(n)}}(u)),i.append(f),[3,4,5].indexOf(n.Status)>=0?(i=$('<td class="label"><\/td>'),n.Status==3?i.text(GetTextByKey("P_WO_REASONFORREJECTION_COLON","Reason for Rejection:")):(n.Status==4||n.Status==5)&&i.text(GetTextByKey("P_WO_PONUMBER_COLON","PO #:")),r.append(i),i=$("<td><\/td>"),r.append(i),n.Status==3?(f=$('<span id="dialog_est_rfr'+u+'"><\/span>').text(n.RejectReason),i.append(f)):(n.Status==4||n.Status==5)&&(f=$('<span id="dialog_est_rfr'+u+'"><\/span>').text(n.PONumber),i.append(f))):r.append('<td cospan="2"><\/td>'),r=$("<tr><\/tr>"),e.append(r),i=$('<td class="label"><\/td>').text(GetTextByKey("P_WO_LABORCOST_COLON","Labor Cost ($):")),r.append(i),i=$("<td><\/td>"),r.append(i),f=$('<input type="text" id="dialog_est_laborcost'+u+'" tabindex="1" maxlength="12" autocomplete="off" />').val(locale(n.LaborCost,s)).change(function(n){return function(){o(n)}}(u)),i.append(f),i=$('<td class="label"><\/td>').text(GetTextByKey("P_WO_TIMETOCOMPLATEHOURS_COLON","Labor Hours:")),r.append(i),i=$("<td><\/td>"),r.append(i),f=$('<input type="text" id="dialog_est_timetocomplete'+u+'" tabindex="1" maxlength="12" autocomplete="off" />').val(n.HoursToComplete).change(function(n){return function(){o(n)}}(u)),i.append(f),r=$("<tr><\/tr>"),e.append(r),i=$('<td class="label"><\/td>').text(GetTextByKey("P_WO_TAXES_COLON","Taxes ($):")),r.append(i),i=$("<td><\/td>"),r.append(i),f=$('<input type="text" id="dialog_est_taxes'+u+'" tabindex="1" maxlength="12" autocomplete="off" />').val(locale(n.Taxes,s)).change(function(n){return function(){o(n)}}(u)),i.append(f),i=$('<td class="label"><\/td>').text(GetTextByKey("P_WO_POREQUIRED_COLON","PO Required:")),r.append(i),i=$("<td><\/td>"),r.append(i),f=$('<input type="checkbox" id="dialog_est_porequired'+u+'" tabindex="1" style="width: auto;" />').prop("checked",n.PORequired).change(function(n){return function(){o(n)}}(u)),i.append(f),r=$("<tr><\/tr>"),e.append(r),i=$('<td class="label" style="vertical-align:top;"><\/td>').text(GetTextByKey("P_WO_CUSTOMERISSUES_COLON","Customer Issues:")),r.append(i),i=$('<td colspan="3"><\/td>'),r.append(i),f=$('<textarea id="dialog_est_custissues'+u+'" tabindex="1" maxlength="2000" style="width: 480px; height: 80px; margin-top: 5px;"><\/textarea>').val(n.CustomerIssues).change(function(n){return function(){o(n)}}(u)),i.append(f),[3,4,5].indexOf(n.Status)>=0?(i=$('<td class="label" style="vertical-align:top;"><\/td>').text(GetTextByKey("P_WO_CUSTOMERNOTES_COLON","Customer Notes:")),r.append(i),i=$("<td><\/td>"),r.append(i),f=$('<textarea id="dialog_est_custnotes'+u+'" tabindex="1" maxlength="2000" disabled="disabled" style="width: 520px; height: 80px; margin-top: 5px;"><\/textarea>').val(n.CustomerNotes),i.append(f)):r.append('<td cospan="2"><\/td>'),r=$("<tr><\/tr>"),e.append(r),i=$('<td class="label" style="vertical-align:top;"><\/td>').text(GetTextByKey("P_WO_TECHNICIANNOTES_COLON","Technician Notes:")),r.append(i),i=$('<td colspan="3"><\/td>'),r.append(i),f=$('<textarea id="dialog_est_technotes'+u+'" tabindex="1" maxlength="2000" style="width: 480px; height: 80px; margin-top: 5px;" ><\/textarea>').val(n.TechnicianNotes).change(function(n){return function(){o(n)}}(u)),i.append(f),[3,4,5].indexOf(n.Status)>=0&&n.Signature!=null&&n.Signature&&n.Signature.length>0?(i=$('<td class="label" style="vertical-align:top;"><\/td>').text(GetTextByKey("P_WO_SIGNATURE_COLON","Signature:")),r.append(i),i=$('<td rowspan="2"><\/td>'),r.append(i),p=n.Signature,typeof n.Signature!="string"&&(p=kt(n.Signature)),ot=$('<img style="height: 110px;" />').attr("src","data:image/png;base64,"+p),i.append(ot)):r.append('<td rowspan="2"><\/td>'),n.Status===0&&(r=$("<tr><\/tr>"),e.append(r),i=$('<td class="label"><\/td>').text(GetTextByKey("P_WO_ATTACHMENTS_COLON"," Attachments:")),r.append(i),i=$('<td colspan="3"><\/td>'),r.append(i),c=$("<div><\/div>"),i.append(c),!WOReadOnly)){w=$('<span class="sbutton iconadd" />').text(GetTextByKey("P_FR_ADDFILE","Add File..."));w.on("click",u,function(n){ct(n.data)});c.append(w)}r=$('<tr id="tr_est_atts'+u+'"><\/tr>');e.append(r);i=$('<td class="label" style="vertical-align:top;"><\/td>').text(n.Status===0?"":GetTextByKey("P_WO_ATTACHMENTS_COLON","Attachments:"));r.append(i);i=$('<td colspan="3"><\/td>');r.append(i);l=$('<table id="tab_est_attachments'+u+'" style="border: 1px solid #a8a8a8; line-height: 25px; width: 480px; display: none;"><\/table>');i.append(l);k=$("<tr><\/tr>");l.append(k);g=$("<td><\/td>");k.append(g);c=$('<div style="max-height: 80px; overflow: auto;padding: 0 4px;"><\/div>');g.append(c);l=$('<table id="tab_est_atts'+u+'" style="table-layout: fixed;"><\/table>');c.append(l);ht(u);r=$("<tr><\/tr>");e.append(r);i=$('<td class="label"><\/td>');r.append(i);f=$('<lable id="lable_est_visibletocustomer'+u+'"><\/lable>').text(GetTextByKey("P_WO_AVAILABLETOCUSTOMER_COLON","Available to Customer:")).hide();i.append(f);i=$("<td><\/td>");r.append(i);f=$('<input type="checkbox" id="dialog_est_visibletocustomer'+u+'" tabindex="1" style="width: auto;" />').prop("checked",n.VisibleToCustomer).hide().change(function(n){return function(){ri(n)}}(u));i.append(f);i=$('<td style="text-align: right; height: 33px"><\/td>');r.append(i);f=$('<input type="button" style="width: 80px; height: 25px;" id="btn_estimatesave'+u+'" />').val(GetTextByKey("P_WO_SAVE","Save")).hide();f.on("click",u,function(n){b(n.data)});i.append(f);f=$('<input type="button" style="width: 80px; height: 25px;margin-left:16px;" id="btn_estimatepublish'+u+'" />').val(GetTextByKey("P_WO_PUBLISH","Publish")).hide();f.on("click",u,function(n){et(n.data)});i.append(f);f=$('<input type="button" style="width: 80px; height: 25px;" id="btn_estimaterevoke'+u+'" />').val(GetTextByKey("P_WO_REVOKE","Revoke")).hide();f.on("click",u,function(n){dt(n.data)});i.append(f);WOReadOnly||(n.Status===0&&($("#btn_estimatesave"+u).show(),$("#btn_estimatepublish"+u).show()),(n.Status===1||n.Status===4)&&$("#btn_estimaterevoke"+u).show());(s||WOReadOnly)&&ti(u,!0);n.Status===3&&($("#span_eststatus"+u).css("color","red"),$("#dialog_est_status"+u).css("color","red"));n.Status===4&&($("#span_eststatus"+u).css("color","#2eda2e"),$("#dialog_est_status"+u).css("color","#2eda2e"));[3,4,5].indexOf(n.Status)>=0&&($("#lable_est_visibletocustomer"+u).show(),$("#dialog_est_visibletocustomer"+u).show())}function kt(n){for(var i="",r=new Uint8Array(n),u=r.byteLength,t=0;t<u;t++)i+=String.fromCharCode(r[t]);return window.btoa(i)}function dt(n){n&&showConfirm(GetTextByKey("P_WO_DOYOUWANTTOREVOKETHEESTIMATE","Do you want to revoke the estimate?"),GetTextByKey("P_WO_REVOKEESTIMATE","Revoke Estimate"),function(){worequest("RevokeWorkOrderEstimate",n,function(n){n==="OK"&&h(!0)},function(){showAlert(GetTextByKey("P_WO_FAILEDTOREVOKETHISESTIMATE","Failed to revoke this estimate."),GetTextByKey("P_WO_REVOKEESTIMATE","Revoke Estimate"))})})}function gt(n){n&&showConfirm(GetTextByKey("P_WO_DOYOUWANTTODELETETHEESTIMATE","Do you want to delete the estimate?"),GetTextByKey("P_WO_DELETEESTIMATE","Delete Estimate"),function(){worequest("DeleteWorkOrderEstimate",n,function(n){n==="OK"&&h(!0)},function(){showAlert(GetTextByKey("P_WO_FAILEDTODELETETHISESTIMATE","Failed to delete this estimate."),GetTextByKey("P_WO_DELETEESTIMATE","Delete Estimate"))})})}function b(n,i){var c=-1,l=0,e=GetTextByKey("P_WO_ADDESTIMATE","Add Estimate"),o,r,f,s;if(n>0){if(e=GetTextByKey("P_WO_EDITESTIMATE","Edit Estimate"),o=$("#tabestimate"+n).data("estimate"),!o)return;c=o.Id;l=o.Status}if(r=n>0?String(n):"",f={Id:c,WorkOrderId:t.option.workorderid,Status:l,EstimateNumber:$("#dialog_est_number"+r).val(),TotalCost:$("#dialog_est_totalcosts"+r).val(),OtherCost:$("#dialog_est_othercost"+r).val(),PartsCost:$("#dialog_est_partscost"+r).val(),TravelCost:$("#dialog_est_traveltimecost"+r).val(),LaborCost:$("#dialog_est_laborcost"+r).val(),HoursToComplete:$("#dialog_est_timetocomplete"+r).val(),CustomerIssues:$("#dialog_est_custissues"+r).val(),TechnicianNotes:$("#dialog_est_technotes"+r).val(),Taxes:$("#dialog_est_taxes"+r).val(),PORequired:$("#dialog_est_porequired"+r).prop("checked")},isNaN(f.TotalCost)||f.TotalCost<0){showAlert(GetTextByKey("P_WO_TOTALCOST_INVALID","Total cost is not a valid number."),e,function(){$("#dialog_est_totalcosts"+r).focus()});return}if(isNaN(f.OtherCost)||f.OtherCost<0){showAlert(GetTextByKey("P_WO_OTHERCOST_INVALID","Other cost is not a valid number."),e,function(){$("#dialog_est_totalcosts"+r).focus()});return}if(isNaN(f.PartsCost)||f.PartsCost<0){showAlert(GetTextByKey("P_WO_PARTSCOST_INVALID","Parts cost is not a valid number."),e,function(){$("#dialog_est_partscost"+r).focus()});return}if(isNaN(f.TravelCost)||f.TravelCost<0){showAlert(GetTextByKey("P_WO_TRAVELTIMECOST_INVALID","Travel time cost is not a valid number."),e,function(){$("#dialog_est_traveltimecost"+r).focus()});return}if(isNaN(f.LaborCost)||f.LaborCost<0){showAlert(GetTextByKey("P_WO_LABORCOST_INVALID","Labor cost is not a valid number."),e,function(){$("#dialog_est_laborcost"+r).focus()});return}if(isNaN(f.HoursToComplete)||f.HoursToComplete<0){showAlert(GetTextByKey("P_WO_TIMETOCOMPLETE_INVALID","Time to complete is not a valid number."),e,function(){$("#dialog_est_timetocomplete"+r).focus()});return}if(isNaN(f.Taxes)||f.Taxes<0){showAlert(GetTextByKey("P_WO_TAXES_INVALID","Taxes is not a valid number."),e,function(){$("#dialog_est_taxes"+r).focus()});return}$("#btn_estimatesave"+r).attr("disabled",!0);s=JSON.stringify(f);s=htmlencode(s);worequest("SaveWorkOrderEstimate",s,function(t){typeof t=="string"?($("#btn_estimatesave"+r).attr("disabled",!1),showAlert(t,e)):($("#btn_estimatesave"+r).attr("disabled",!1),n<=0?(u&&u.length>0&&(k(u,t),u=[]),i?i(t):h(!0),wt()):i?i(n):(showAlert(GetTextByKey("P_WO_SAVSUCCESSFULLY","Saved successfully."),e),$("#span_estnumber"+r).text($("#dialog_est_number"+r).val())))},function(n){$("#btn_estimatesave"+r).attr("disabled",!1);console.log(n);showAlert(GetTextByKey("P_WO_FAILEDTORSAVEESTIMATE","Failed to save estimate."),e)})}function ni(){if(u=[],$("#tab_est_atts").empty(),$("#tab_est_attachments").hide(),!t.option.workorderid||t.option.workorderid===""){showAlert(GetTextByKey("P_WO_SAVEWORKORDERFIRST","Please save work order first."),GetTextByKey("P_WO_ADDESTIMATE","Add Estimate"));return}$("#dialog_est_number").val("");$("#dialog_est_status").text(GetTextByKey("P_WO_DRAFT","Draft"));$("#dialog_est_totalcosts").val("");$("#dialog_est_othercost").val("");$("#dialog_est_partscost").val("");$("#dialog_est_traveltimecost").val("");$("#dialog_est_laborcost").val("");$("#dialog_est_timetocomplete").val("");$("#dialog_est_custissues").val("");$("#dialog_est_technotes").val("");$("#dialog_est_taxes").val("");$("#dialog_est_porequired").prop("checked",WorkorderParams.DefaultPORequired);t.option.workorderdata&&($("#dialog_est_totalcosts").val(t.option.workorderdata.WorkOrderTotalCost==0?"":t.option.workorderdata.WorkOrderTotalCost),$("#dialog_est_othercost").val(t.option.workorderdata.OtherCost==0?"":t.option.workorderdata.OtherCost),$("#dialog_est_partscost").val(t.option.workorderdata.PartsCost==0?"":t.option.workorderdata.PartsCost),$("#dialog_est_traveltimecost").val(t.option.workorderdata.TravelTimeCost==0?"":t.option.workorderdata.TravelTimeCost),$("#dialog_est_laborcost").val(t.option.workorderdata.LaborCost==0?"":t.option.workorderdata.LaborCost),$("#dialog_est_timetocomplete").val(t.option.workorderdata.HoursToComplete==0?"":t.option.workorderdata.HoursToComplete),$("#dialog_est_custissues").val(t.option.workorderdata.Description),d(""));pt()}function o(n){$("#tabestimate"+n).data("changed",!0)}function ti(n,t){$("#dialog_est_number"+n).attr("disabled",t);$("#dialog_est_totalcosts"+n).attr("disabled",t);$("#dialog_est_othercost"+n).attr("disabled",t);$("#dialog_est_partscost"+n).attr("disabled",t);$("#dialog_est_traveltimecost"+n).attr("disabled",t);$("#dialog_est_laborcost"+n).attr("disabled",t);$("#dialog_est_timetocomplete"+n).attr("disabled",t);$("#dialog_est_custissues"+n).attr("disabled",t);$("#dialog_est_technotes"+n).attr("disabled",t);$("#dialog_est_taxes"+n).attr("disabled",t);$("#dialog_est_porequired"+n).attr("disabled",t)}function d(n){var i=$("#dialog_est_othercost"+n).val(),r=$("#dialog_est_partscost"+n).val(),u=$("#dialog_est_traveltimecost"+n).val(),f=$("#dialog_est_laborcost"+n).val(),e=$("#dialog_est_taxes"+n).val(),t=0;i===""||isNaN(i)||(t+=eval(i));r===""||isNaN(r)||(t+=eval(r));u===""||isNaN(u)||(t+=eval(u));f===""||isNaN(f)||(t+=eval(f));e===""||isNaN(e)||(t+=eval(e));$("#dialog_est_totalcosts"+n).val(t.toFixed(2))}function ut(){i<=0?e.find(".maskbg").show():a.fadeIn(100);$("#dialog_est_textmsg").val(WorkorderParams.EstimateMessage);$("#dialog_est_chkSendAttachment").prop("disabled",i<=0?u.length<=0:!(p.find(n=>n.Id===i)?.Attachments?.length>0)).prop("checked",!1);$("#dialog_est_spanAttachmentName").hide();r=null;s.css({top:(document.documentElement.clientHeight-s.height())/3,left:(document.documentElement.clientWidth-s.width())/2}).showDialogfixed()}function ft(){i<=0?e.find(".maskbg").hide():a.fadeOut(100);i=0;s.hide()}function et(n){n<=0?(i=n,ut()):b(n,function(){i=n;ut()})}function ii(){var n=$("#tabestimate"+i).data("changed");i<=0&&(n=!0);n?b(i<=0?"":i,ot):ot(i)}function ot(n){var f,w,a,v,o,i,c,u,y,p,d;if(n){if(f=[],w=$("#dialog_est_chksendtextmsg").prop("checked"),w&&(a=$("#dialog_est_phonenum").val(),a!==""))for(v=a.split(";"),o=0;o<v.length;o++)if(i=v[o],checkPhoneNumber(i)||isEmail(i))f.push({Key:i,Value:i});else if(t.option.customercontacts)for(c=0;c<t.option.customercontacts.length;c++)if((u=t.option.customercontacts[c],!u.OptOut&&!u.OptOut_BC)&&(y=$.trim(u.MobilePhone),p=$.trim(u.Email),u.Name===i)){if(u.ContactPreference=="0"&&checkPhoneNumber(y)){f.push({Key:y,Value:i});break}if(u.ContactPreference=="1"&&isEmail(p)){f.push({Key:p,Value:i});break}}var g=$("#dialog_est_textmsg").val(),nt=$("#dialog_est_chkIncludeStatusLink").prop("checked"),l=JSON.stringify([n,t.option.workorderid,JSON.stringify(f),g,nt?"1":"0"]);l=htmlencode(l);var b=_network.root+"Maintenance/AddWorkOrder.aspx",k="PublishEstimateToCustomer",e=new FormData;e.append("MethodName",k);e.append("ClientData",l);r!=null&&(Object.prototype.hasOwnProperty.call(r,"id")?(d={Id:r.id,Caption:r.name},e.append("AttaData",htmlencode(JSON.stringify(d)))):e.append("attachment",r.file));s.find(".maskbg").show();$.ajax({url:b,type:"POST",dataType:"json",processData:!1,contentType:!1,cache:!1,data:e,success:function(n){if(n!==""){showAlert(n,GetTextByKey("P_WO_ERROR","Error"));return}h(!0);ft()},error:function(n,t,i){showAlert(GetTextByKey("P_WO_FAILEDTOPUBLISHTHISESTIMATE","Failed to publish this estimate."),GetTextByKey("P_WO_PUBLISHESTIMATE","Publish Estimate"));n?.readyState==0?console.log(n):writelog_ironintel("PublishEstimate",b+".-1."+k+"."+JSON.stringify(l),JSON.stringify(n),t+i)},complete:function(){s.find(".maskbg").hide()}})}}function ri(n){var i=$("#tabestimate"+n).data("estimate"),r,t;i&&(r=$("#dialog_est_visibletocustomer"+n).prop("checked"),t=JSON.stringify([i.Id,r]),t=htmlencode(t),worequest("UpdateWOEstimateVisibleToCustomer",t,function(n){if(n!==""){showAlert(n,GetTextByKey("P_WO_ERROR","Error"));return}},function(){showAlert(GetTextByKey("P_WO_FAILEDTOPUBLISHTHISESTIMATE","Failed to publish this estimate."),GetTextByKey("P_WO_AVAILABLETOCUSTOMER","Available to Customer"))}))}function k(n,t){for(var f,e,r=new FormData,u=[],i=0;i<n.length;i++)r.append("iconFile"+i,n[i].File),u.push(encodeURIComponent(n[i].Notes));f=JSON.stringify([t,JSON.stringify(u)]);r.append("MethodName","AddEstimateAttachment");r.append("ClientData",f);e="AddWorkOrder.aspx";$.ajax({url:e,type:"POST",dataType:"json",processData:!1,contentType:!1,data:r,"async":!0,success:function(n){n!=="OK"?showAlert(n,GetTextByKey("P_WO_ATTACHMENTFILE","Attachment File")):t>0?(g(),st(t)):h(!0)},error:function(){showAlert(GetTextByKey("P_WO_UPLOADFAILED","Upload failed"),GetTextByKey("P_WO_ATTACHMENTFILE","Attachment File"))}})}function st(n){var t=$("#tabestimate"+n).data("estimate");t&&($("#tab_est_atts"+n).empty(),$("#tab_est_attachments"+n).hide(),worequest("GetEstimateAttachment",t.Id,function(t){if(typeof t=="string"){showAlert(t,GetTextByKey("P_WO_ERROR","Error"));return}t&&t.length>0&&ht(n,t);var i=p.find(t=>t.Id===n);i!=null&&(i.Attachments=t)},function(){}))}function ht(n,t){var f=!1,r,u,e,h;if(t)f=!0;else{if(r=$("#tabestimate"+n).data("estimate"),!r)return;t=r.Attachments;r.Status===0&&(f=!0)}if($("#tab_est_atts"+n).empty(),$("#tab_est_attachments"+n).hide(),t&&t.length>0)for($("#tab_est_attachments"+n).show(),u=0;u<t.length;u++){var i=t[u],o=$("<tr><\/tr>").attr("id",i.AttachmentId),s=$("<td><\/td>"),c=$("<label style='text-decoration: underline;color: RGB(30,144,255);cursor:pointer;'><\/label>").text(i.Notes===""?i.FileName:i.Notes).click(function(){window.open("../filesvc.ashx?attchid="+this.parentElement.parentElement.id+"&sourceType=woestimateattachment")}),l=$("<span><\/span>").text(i.AddedByName).css("margin-right",5).css("margin-left",5).css("color","black"),a=$("<span><\/span>").text(i.AddedOnLocalStr).css("color","black");s.append(c,l,a);!WOReadOnly&&f&&(e=$('<td style="width:18px;border:none;text-align:center;"><\/td>'),h=$('<span class="sbutton icondelete" style="padding:0;" ><\/span>').click(function(){ui(this.parentElement.parentElement.id,n)}),e.append(h),o.append(e));o.append(s).appendTo($("#tab_est_atts"+n))}}function ui(n,t){confirm(GetTextByKey("P_WO_DELETEATTACHMENTTIPS","Are you sure you want to delete the attachment?"))&&worequest("DeleteEstimateAttachment",n,function(n){n!=="OK"?showAlert(n,GetTextByKey("P_WO_DELETEATTACHMENT","Delete Attachment")):st(t)},function(){})}function g(){w<=0?e.find(".maskbg").hide():showmaskbg(!1);l.hide()}function ct(n){f=undefined;w=n;n<=0?e.find(".maskbg").show():showmaskbg(!0);c.attr("disabled",!1);$("#tab_woest_atts").empty();$("#tab_woest_attachments").hide();$("#dialog_estatt_notes").val("");l.css({top:(document.documentElement.clientHeight-l.height())/3,left:(document.documentElement.clientWidth-l.width())/2}).showDialogfixed()}function fi(n){n.preventDefault();n.dataTransfer.dropEffect="link"}function ei(n){var u,i,r,e,t;if(n.preventDefault(),n.stopPropagation(),u=n.dataTransfer,i=[],u.items!==undefined)for(t=0;t<u.items.length;t++)if(r=u.items[t],r.kind==="file"&&(r.webkitGetAsEntry()==null||r.webkitGetAsEntry().isFile)){if(e=r.getAsFile(),e.size==0){alert(GetTextByKey("P_WO_ATTACHMENTSTIPS","Attachment size is 0kb, uploading failed."));return}if(e.size>52428800){alert(GetTextByKey("P_WO_ATTACHMENTSTIPS1","Attachment is too large. Maximum file size is 50 MB."));return}i.push({File:e,Notes:""})}if(i.length>0)for(t=0;t<i.length;t++)f=i[t],nt()}function oi(n){var u,i,r,e,t;if(n.stopPropagation(),u=n.clipboardData,i=[],u.items!==undefined)for(t=0;t<u.items.length;t++)if(r=u.items[t],r.kind==="file"&&(r.webkitGetAsEntry()==null||r.webkitGetAsEntry().isFile)){if(e=r.getAsFile(),e.size==0){alert(GetTextByKey("P_WO_ATTACHMENTSTIPS","Attachment size is 0kb, uploading failed."));return}if(e.size>52428800){alert(GetTextByKey("P_WO_ATTACHMENTSTIPS1","Attachment is too large. Maximum file size is 50 MB."));return}i.push({File:e,Notes:""})}if(i.length>0)for(t=0;t<i.length;t++)f=i[t],nt()}function si(){var n=$('<input type="file" style="display: none;" />');n.change(function(){var n=this.files,t;if(n.length!=0){if(n[0].size==0)return alert(GetTextByKey("P_WO_ATTACHMENTSTIPS","Attachment size is 0kb, uploading failed.")),!1;if(n[0].size>52428800)return alert(GetTextByKey("P_WO_ATTACHMENTSTIPS1","Attachment is too large. Maximum file size is 50 MB.")),!1;t=$("#dialog_estatt_notes").val();f={File:n[0],Notes:t};hi(f)}}).click()}function hi(n){var t,u;$("#tab_woest_atts").empty();$("#tab_woest_attachments").show();var i=$("<tr><\/tr>"),r=$("<td><\/td>"),e=$("<label class='attalabel'><\/label>").text(n.Notes===""?n.File.name:n.Notes);r.append(e);t=$('<td style="width:18px;border:none;text-align:center;"><\/td>');u=$('<span class="sbutton icondelete" style="padding:0;" ><\/span>').click(function(){this.parentElement.parentElement.remove();f=undefined;$("#tab_woest_attachments").hide()});t.append(u);i.append(t);i.append(r).appendTo($("#tab_woest_atts"))}function nt(){if(f){c.attr("disabled",!0);var n=$("#dialog_estatt_notes").val();f.Notes=n;w<=0?(u.push(f),ci(f),g(),c.attr("disabled",!1)):k([f],w)}}function ci(n){var i=n.Notes,o=n.File,t,e;$("#tab_est_attachments").show();var r=$("<tr><\/tr>"),f=$("<td><\/td>"),s=$("<label class='attalabel'><\/label>").text(i===""?o.name:i);f.append(s);t=$('<td style="width:18px;border:none;text-align:center;"><\/td>');e=$('<span class="sbutton icondelete" style="padding:0;" ><\/span>').data("filedata",n).click(function(){this.parentElement.parentElement.remove();var n=$(this).data("filedata");u.splice(u.indexOf(n),1);u.length==0&&$("#tab_est_attachments").hide()});t.append(e);r.append(t);r.append(f).appendTo($("#tab_est_atts"))}var e,a,s,l,v;this.option=n||{};var t=this,y={Draft:0,Pending:1,Cancelled:2,Declined:3,Approved:4,Void:5,None:100},p=[],i=0,r=null,u=[],f,w=0,c=null;this.changewo=function(n){var t=this.option.workorderid===n;this.option.workorderid=n;h(t)};this.close=function(){e?.remove();a?.remove();s?.remove();l?.remove()};this.setwodata=function(n){this.option.workorderdata=n};this.updatecontact=function(n){var i,r,t,u,f;if(this.option.customercontacts=n,this.option.customercontacts){for(i="",r=0;r<this.option.customercontacts.length;r++)(t=this.option.customercontacts[r],t.OptOut||t.OptOut_BC)||(u=$.trim(t.MobilePhone),f=$.trim(t.Email),(t.ContactPreference=="0"&&checkPhoneNumber(u)||t.ContactPreference=="1"&&isEmail(f))&&(i==""?i=t.Name:i+=";"+t.Name));$("#dialog_est_phonenum").val(i)}else $("#dialog_est_phonenum").val("")};this.createEstimate=function(n){var t,i;n.addClass("tab_estimates");t=$('<div class="function_title"><\/div>');n.append(t);i=$('<span class="sbutton iconadd" data-lgid="P_WO_ADDESTIMATE">Add Estimate<\/span>');i.click(ni);t.append(i);n.applyFleetLanguageText(!0)};this.createEstimate(this.option.parent);e=lt();a=$('<div class="mask_dialog"><\/div>').hide();$(document.body).append(a);s=at();l=vt();v=!1;this.getEstimateStatus=function(n){var t="";return n===0?t=GetTextByKey("P_WO_DRAFT","Draft"):n===1?t=GetTextByKey("P_WO_AWAITINGCUSTOMERAPPROVAL","Awaiting Customer Approval"):n===2?t=GetTextByKey("P_WO_CANCELLEDBYDEALER","Cancelled by Dealer"):n===3?t=GetTextByKey("P_WO_CUSTOMERREJECTED","Customer Rejected"):n===4?t=GetTextByKey("P_WO_CUSTOMERAPPROVED","Customer Approved"):n===5?t=GetTextByKey("P_WO_VOID","Void"):n===100&&(t=""),t}});typeof $woinvoice!="function"&&($woinvoice=function(n){function vt(){var r=$('<div class="dialog" style="display: none;"><\/div>'),i,t,n,l,a,v,y,p,w,b,k,e,d,g,nt,c,u,o,s,f,h;r.on("drop",function(n){li(n.originalEvent)}).on("dragover",function(n){ci(n.originalEvent)}).on("paste",function(n){ai(n.originalEvent)});r.append('<div class="dialog-title"><span class="title" data-lgid="P_WO_ADDINVOICE">Add Invoice<\/span><em class="dialog-close"><\/em><\/div>');i=$("<table><\/table>");r.append($('<div class="dialog-content"><\/div>').append(i));t=$("<tr><\/tr>").appendTo(i);n=$('<td class="label" data-lgid="P_WO_INVOICENUMBER">Invoice #:<\/td>').appendTo(t);n=$("<td><\/td>").appendTo(t);l=$('<input type="text" id="dialog_invoice_number" tabindex="1" style="width:150px;" maxlength="50" autocomplete="off" />').appendTo(n);n=$('<td class="label" data-lgid="P_WO_OTHERCOST_COLON">Other Cost ($):<\/td>').appendTo(t);n=$("<td><\/td>").appendTo(t);a=$('<input type="text" id="dialog_invoice_othercost" maxlength="12" tabindex="1" style="width:150px;" autocomplete="off" />').appendTo(n);t=$("<tr><\/tr>").appendTo(i);n=$('<td class="label" data-lgid="P_WO_INVOICETOTALCOST">Invoice Total Cost ($):<\/td>').appendTo(t);n=$("<td><\/td>").appendTo(t);v=$('<input type="text" id="dialog_invoice_totalcosts" maxlength="12" tabindex="1" style="width:150px;" autocomplete="off" />').appendTo(n);n=$('<td class="label" data-lgid="P_WO_TRAVELTIMECOST_COLON">Travel Time Cost ($):<\/td>').appendTo(t);n=$("<td><\/td>").appendTo(t);y=$('<input type="text" id="dialog_invoice_traveltimecost" maxlength="12" tabindex="1" style="width:150px;" autocomplete="off" />').appendTo(n);t=$("<tr><\/tr>").appendTo(i);n=$('<td class="label" data-lgid="P_WO_PARTSCOST_COLON">Parts Cost ($):<\/td>').appendTo(t);n=$("<td><\/td>").appendTo(t);p=$('<input type="text" id="dialog_invoice_partscost" maxlength="12" tabindex="1" style="width:150px;" autocomplete="off" />').appendTo(n);n=$('<td class="label" data-lgid="P_WO_TAXES_COLON">Taxes ($):<\/td>').appendTo(t);n=$("<td><\/td>").appendTo(t);w=$('<input type="text" id="dialog_invoice_taxes" maxlength="12" tabindex="1" style="width:150px;" autocomplete="off" />').appendTo(n);t=$("<tr><\/tr>").appendTo(i);n=$('<td class="label" data-lgid="P_WO_LABORCOST_COLON">Labor Cost ($):<\/td>').appendTo(t);n=$("<td><\/td>").appendTo(t);b=$('<input type="text" id="dialog_invoice_laborcost" maxlength="12" tabindex="1" style="width:150px;" autocomplete="off" />').appendTo(n);n=$('<td class="label" data-lgid="P_WO_INVOICESTATUS">Invoice Status:<\/td>').appendTo(t);n=$("<td><\/td>").appendTo(t);k=$('<select id="dialog_invoice_status" style="width: 150px; height: 24px;"><option value="0">Draft<\/option><option value="1">Awaiting Payment<\/option><option value="6">Paid<\/option><option value="10">Revoked<\/option><\/select>').appendTo(n);t=$("<tr><\/tr>").appendTo(i);n=$('<td class="label" data-lgid="P_WO_PAYMENTBY_COLON">Payment By:<\/td>').appendTo(t);n=$("<td><\/td>").appendTo(t);e=$('<select id="dialog_invoice_paymentby" style="width: 150px; height: 24px;"><\/select>').appendTo(n);e.append($('<option value="Credit Card">Credit Card<\/option>').text(GetTextByKey("P_WO_CREDITCARD","Credit Card")));e.append($('<option value="Check">Check<\/option>').text(GetTextByKey("P_WO_CHECK","Check")));e.append($('<option value="Cash">Cash<\/option>').text(GetTextByKey("P_WO_CASH","Cash")));n=$('<td class="label" data-lgid="P_WO_CHECK_COLON">Check #:<\/td>').appendTo(t);n=$("<td><\/td>").appendTo(t);d=$('<input type="text" id="dialog_invoice_checknumber" maxlength="200" tabindex="1" style="width:150px;" autocomplete="off" />').appendTo(n);t=$("<tr><\/tr>").appendTo(i);n=$("<td><\/td>").appendTo(t);n=$("<td><\/td>").appendTo(t);n=$('<td class="label" data-lgid="P_WO_CUSTOMERVISIBLE_COLON">Customer Visible:<\/td>').appendTo(t);n=$("<td><\/td>").appendTo(t);g=$('<input type="checkbox" id="dialog_invoice_customervisible" tabindex="1" autocomplete="off" />').appendTo(n);t=$("<tr><\/tr>").appendTo(i);n=$('<td class="label" data-lgid="P_WOS_NOTES_COLON" style="vertical-align: top;">Notes:<\/td>').appendTo(t);n=$('<td colspan="3"><\/td>').appendTo(t);nt=$('<textarea id="dialog_invoice_notes" tabindex="1" maxlength="500" style="height:80px;width:450px;"><\/textarea>').appendTo(n);t=$("<tr><\/tr>").appendTo(i);n=$('<td class="label" data-lgid="P_WO_ATTACHMENTS_COLON" style="vertical-align: top;">Attachments:<\/td>').appendTo(t);n=$('<td colspan="3"><\/td>').appendTo(t);c=$('<span class="sbutton iconadd" data-lgid="P_WO_ADDFILE">Add File<\/span>').appendTo(n);c.on("click",function(){lt("")});t=$("<tr><\/tr>").appendTo(i);n=$('<td class="label"><\/td>').appendTo(t);n=$('<td colspan="3"><\/td>').appendTo(t);u=$('<table id="tab_invoice_attachments" style="border: 1px solid #a8a8a8; line-height: 25px; width: 320px; display: none;"><\/table>');n.append(u);o=$("<tr><\/tr>");u.append(o);s=$("<td><\/td>");o.append(s);div_att=$('<div style="max-height: 80px; overflow: auto;padding: 0 4px;"><\/div>');s.append(div_att);u=$('<table id="tab_invoice_atts" style="table-layout: fixed;"><\/table>');div_att.append(u);f=$('<div class="dialog-func"><\/div>');r.append(f);f.append('<input type="button" value="Cancel" data-lgid="P_WO_CANCEL" class="dialog-close" tabindex="11" />');h=$('<input type="button" value="OK" data-lgid="P_WO_OK" tabindex="11" />');h.on("click",function(){ui("")});return f.append(h),f.append('<div class="clear"><\/div>'),r.append('<div class="maskbg" style="display: none;"><\/div>'),$(document.body).append(r),r.dialog(function(){showmaskbg(!1)}),r.applyFleetLanguageText(!0),r}function yt(){var e=$('<div class="dialog" style="display: none;"><\/div>'),o,l,a,t,h,v,s;e.append('<div class="dialog-title"><span class="title" data-lgid="P_WO_PUBLISH_INVOICE">Publish Invoice<\/span><em class="dialog-close"><\/em><\/div>');o=$('<table style="line-height: 30px; margin-left: 10px; margin-right: 10px;"><\/table>');e.append($('<div class="dialog-content"><\/div>').append(o));var i=$("<tr><\/tr>").appendTo(o),n=$('<td style="text-align: right;"><\/td>').appendTo(i),c=$('<input id="dialog_invoice_chksendtextmsg" type="checkbox" checked="checked" style="width: unset;" />').appendTo(n);c.change(function(){var n=$("#dialog_invoice_chksendtextmsg").prop("checked");$("#dialog_invoice_phonenum").prop("disabled",!n);$("#dialog_invoice_chkIncludeStatusLink").prop("disabled",!n);$("#dialog_invoice_textmsg").prop("disabled",!n)});n=$("<td><\/td>").appendTo(i);$('<label for="dialog_invoice_chksendtextmsg" data-lgid="P_WO_SENDUPDATETOCUSTOMER" style="user-select: none;">Send Update To Customer<\/label>').appendTo(n);i=$("<tr><\/tr>").appendTo(o);n=$("<td><\/td>").appendTo(i);$('<div style="font-size: 20px; margin-right: 5px; float: right;"><em class="spanbtn iconmobile" style="font-weight: 900; font-size: 14px; cursor: default; padding-left: 0; padding-right: 3px; padding-top: 0;"><\/em><\/div>').appendTo(n);n=$("<td><\/td>").appendTo(i);l=$('<input type="text" id="dialog_invoice_phonenum" tabindex="1" autocomplete="off" maxlength="100" style="width: 320px;" />').appendTo(n);i=$("<tr><\/tr>").appendTo(o);n=$('<td style="text-align: right;"><\/td>').appendTo(i);a=$('<input id="dialog_invoice_chkIncludeStatusLink" type="checkbox" checked="checked" style="width: unset;" />').appendTo(n);n=$("<td><\/td>").appendTo(i);$('<label for="dialog_invoice_chkIncludeStatusLink" data-lgid="P_WO_INCLUDESTATUSLINK" style="user-select: none;">Include Status Link<\/label>').appendTo(n);i=$("<tr><\/tr>").appendTo(o);n=$('<td style="text-align: right;"><\/td>').appendTo(i);$('<input id="dialog_invoice_chkSendAttachment" type="checkbox" style="width: unset;" />').on("click",function(){var o,s,h,n,t,i,c;if(!this.disabled){if(o=document.querySelector("#dialog_invoice_spanAttachmentName"),!this.checked){u=null;o.style.display="none";return}if(s=r<=0?f.map(function(n){return{file:n.File,name:n.Notes||n.File.name,enabled:/^image\//.test(n.File.type)||n.File.size<=2097152}}):b.find(n=>n.Id===r)?.Attachments?.map(function(n){return{id:n.AttachmentId,name:n.Notes||n.FileName,enabled:!0}}),h=s.filter(function(n){return n.enabled}),h.length===1){u=h[0];o.innerText=u.name;o.style.display="block";return}u=null;n=window["lib-ui"];t=n.createElement("div");t.style.width="440px";t.style.height="300px";i=new n.Grid(t);i.columns=[{key:"selected",type:n.Grid.ColumnTypes.Checkbox,enabled:"enabled",sortable:!1,orderable:!1,resizable:!1,onchanged:function(n){for(var t of this.source)t!==n&&(t.selected=!1);this.refresh()}},{key:"name",caption:GetTextByKey("P_WO_NAME","Name"),width:340,orderable:!1}];i.init();c=new n.Popup({title:GetTextByKey("P_WO_SELECTATTACHMENT","Select Attachment"),content:t,resolve:function(){var n=document.querySelector("#dialog_invoice_spanAttachmentName");u==null?(document.querySelector("#dialog_invoice_chkSendAttachment").checked=!1,n.style.display="none"):(n.innerText=u.name,n.style.display="block")},buttons:[{text:GetTextByKey("P_WO_ATTACH","Attach"),trigger:function(){var n=i.source.filter(function(n){return n.selected})[0];n!=null&&(u=n)}},{text:GetTextByKey("P_WO_CANCEL","Cancel")}]});c.show(e[0]).then(function(){i.source=s})}}).appendTo(n);n=$("<td><\/td>").appendTo(i);$('<label for="dialog_invoice_chkSendAttachment" data-lgid="P_WO_SENDINVOICEASATTACHMENT" style="user-select: none;">Send Invoice as Attachment<\/label>').appendTo(n);i=$("<tr><\/tr>").appendTo(o);n=$("<td><\/td>").appendTo(i);n=$("<td><\/td>").appendTo(i);$('<span id="dialog_invoice_spanAttachmentName" style="user-select: none; color: gray; display: block; white-space: nowrap; max-width: 300px; overflow: hidden; text-overflow: ellipsis; display: none"><\/span>').appendTo(n);i=$("<tr><\/tr>").appendTo(o);n=$('<td class="label" style="width: unset;"><span data-lgid="P_WO_MESSAGE_COLON">Message:<\/span><\/td>').appendTo(i);n=$("<td><\/td>").appendTo(i);t=$('<select id="dialog_invoice_variables" style="width: 156px;"><\/select>').appendTo(n);t.append('<option value="0">[Site_Name]<\/option>');t.append('<option value="1">[Location]<\/option>');t.append('<option value="14">[Asset]<\/option>');t.append('<option value="4">[VIN]<\/option>');t.append('<option value="2">[Make]<\/option>');t.append('<option value="3">[Model]<\/option>');t.append('<option value="5">[Id_Phone]<\/option>');t.append('<option value="6">[Advisor]<\/option>');t.append('<option value="7">[Company_Name]<\/option>');t.append('<option value="8">[Contact_Name]<\/option>');t.append('<option value="9">[Contact_First_Name]<\/option>');t.append('<option value="10">[Status_Link]<\/option>');t.append('<option value="11">[Technician_Name]<\/option>');t.append('<option value="12">[Work_Order_Number]<\/option>');t.append('<option value="13">[Parts_Order_Number]<\/option>');t.append('<option value="15">[Invoice_Number]<\/option>');t.append('<option value="16">[Invoice_Total_Cost]<\/option>');h=$('<input type="button" id="dialog_invoice_insertfield" data-lgid="P_WO_ADD" value="Add" style="width: auto; height: auto; margin-left: 5px;" tabindex="1" /><br />').appendTo(n);h.on("click",function(){bt()});v=$('<textarea id="dialog_invoice_textmsg" tabindex="1" style="width: 320px; height: 120px; margin-top: 6px;" maxlength="2000"><\/textarea>').appendTo(n);s=$('<div class="dialog-func"><\/div>');e.append(s);s.append('<input type="button" value="Cancel" data-lgid="P_WO_CANCEL" class="dialog-close" tabindex="11" />');btn_publish=$('<input type="button" value="Publish" data-lgid="P_WO_PUBLISH" tabindex="1" />');btn_publish.on("click",function(){si()});return s.append(btn_publish),s.append('<div class="clear"><\/div>'),e.append('<div class="maskbg" style="display: none;"><\/div>'),$(document.body).append(e),e.dialog(function(){et()}),e.applyFleetLanguageText(!0),e}function pt(){var i=$('<div class="dialog" style="display: none;"><\/div>'),r,n,t,c,h,u,e,o,f,s;i.append('<div class="dialog-title"><span class="title" data-lgid="P_WO_ADDATTACHMENT">Add Attachment<\/span><em class="dialog-close"><\/em><\/div>');r=$('<table style="line-height: 30px; margin-left: 10px; margin-right: 10px;"><\/table>');i.append($('<div class="dialog-content"><\/div>').append(r));n=$("<tr><\/tr>").appendTo(r);t=$('<td class="label" style="width: unset;"><span data-lgid="P_WO_CAPTION_COLON">Caption:<\/span><\/td>').appendTo(n);t=$("<td><\/td>").appendTo(n);c=$('<input type="text" id="dialog_invoice_att_notes" maxlength="200" tabindex="1" autocomplete="off" />').appendTo(t);n=$("<tr><\/tr>").appendTo(r);t=$('<td class="label" data-lgid="P_WO_ATTACHMENTS_COLON" style="vertical-align: top; width: unset;">Attachments:<\/td>').appendTo(n);t=$('<td class="cont"><\/td>').appendTo(n);h=$('<input id="dialog_woinvoiceatt_uploadattfile" type="button" value="Add File..." data-lgid="P_FR_ADDFILE" tabindex="1" style="background-color: #0099FF; color: #FFFFFF; height: 20px; width: 200px;" />').appendTo(t);h.on("click",function(){vi()});n=$("<tr><\/tr>").appendTo(r);t=$('<td class="label"><\/td>').appendTo(n);t=$('<td colspan="3"><\/td>').appendTo(n);u=$('<table id="tab_woinvoice_attachments" style="border: 1px solid #a8a8a8; line-height: 25px; width: 320px; display: none;"><\/table>');t.append(u);e=$("<tr><\/tr>");u.append(e);o=$("<td><\/td>");e.append(o);div_att=$('<div style="max-height: 80px; overflow: auto;padding: 0 4px;"><\/div>');o.append(div_att);u=$('<table id="tab_woinvoice_atts" style="table-layout: fixed;"><\/table>');div_att.append(u);f=$('<div class="dialog-func"><\/div>');i.append(f);f.append('<input type="button" value="Cancel" data-lgid="P_WO_CANCEL" class="dialog-close" tabindex="11" />');s=$('<input type="button" value="Save" data-lgid="P_WO_SAVE" tabindex="11" />');s.on("click",function(){tt()});return f.append(s),f.append('<div class="clear"><\/div>'),i.append('<div class="maskbg" style="display: none;"><\/div>'),$(document.body).append(i),i.dialog(function(){nt()}),i.applyFleetLanguageText(!0),i}function wt(){var n=$('<div class="dialog" style="display: none;"><\/div>'),u,t,i,f,o,r,e;n.append('<div class="dialog-title"><span class="title" data-lgid="P_WO_MARKASPAID">Mark as Paid<\/span><em class="dialog-close"><\/em><\/div>');u=$('<table style="margin-left: 10px; margin-right: 10px; margin-top: 10px;">');n.append($('<div class="dialog-content"><\/div>').append(u));t=$("<tr><\/tr>").appendTo(u);i=$('<td class="label" style="width:120px;"><span data-lgid="P_WO_PAYMENTBY_COLON">Payment By:<\/span><\/td>').appendTo(t);i=$("<td><\/td>").appendTo(t);f=$('<select id="dialog_invoice_markpaid_paymentby" style="width: 320px; height: 24px;"><\/select>').appendTo(i);f.append($('<option value="Credit Card">Credit Card<\/option>').text(GetTextByKey("P_WO_CREDITCARD","Credit Card")));f.append($('<option value="Check">Check<\/option>').text(GetTextByKey("P_WO_CHECK","Check")));f.append($('<option value="Cash">Cash<\/option>').text(GetTextByKey("P_WO_CASH","Cash")));t=$("<tr><\/tr>").appendTo(u);i=$('<td class="label" style="width:120px;"><span data-lgid="P_WO_CHECK_COLON">Check #:<\/span><\/td>').appendTo(t);i=$("<td><\/td>").appendTo(t);o=$('<input type="text" id="dialog_invoice_markpaid_number" maxlength="200" tabindex="1" autocomplete="off" />').appendTo(i);r=$('<div class="dialog-func"><\/div>');n.append(r);r.append('<input type="button" value="Cancel" data-lgid="P_WO_CANCEL" class="dialog-close" tabindex="1" />');e=$('<input type="button" id="btn_woinvoice_maikpaid_save" value="OK" data-lgid="P_WO_OK" tabindex="1" />');e.on("click",function(){ki()});return r.append(e),r.append('<div class="clear"><\/div>'),n.append('<div class="maskbg" style="display: none;"><\/div>'),$(document.body).append(n),n.dialog(function(){showmaskbg(!1)}),n.applyFleetLanguageText(!0),n}function bt(){var n=$("#dialog_invoice_variables").find("option:selected").text();$("#dialog_invoice_textmsg").focus();document.execCommand("insertText",!1,n)}function kt(){showmaskbg(!0);o.show();o.css({top:(document.documentElement.clientHeight-o.height())/3,left:(document.documentElement.clientWidth-o.width())/2}).showDialogfixed()}function dt(){showmaskbg(!1);o.hide()}function h(n){(n||(i.option.parent.find(".estimates_div").remove(),i.option.parent.find(".estimates_table").remove()),i.option.workorderid&&i.option.workorderid!="")&&(p||(p=!0,typeof i.option.showloading=="function"&&i.option.showloading(!0),worequest("GetWorkOrderInvoices",i.option.workorderid,function(n){if(p=!1,typeof i.option.showloading=="function"&&i.option.showloading(!1),typeof n=="string"){showAlert(n,GetTextByKey("P_WO_ERROR","Error"));return}if(n.WorkOrderID!=i.option.workorderid){h(!1);return}if(n=n.Data,i.option.parent.find(".estimates_div").remove(),i.option.parent.find(".estimates_table").remove(),n&&n&&n.length>0){b=n;for(var t=0;t<n.length;t++)gt(n[t])}},function(){p=!1;typeof i.option.showloading=="function"&&i.option.showloading(!1)})))}function it(n){n.preventDefault();n.dataTransfer.dropEffect="link"}function rt(n,t){var r,u,f,i,e,o;if(n.preventDefault(),n.stopPropagation(),r=n.dataTransfer,u=[],r.items!==undefined)for(f=0;f<r.items.length;f++)if(i=r.items[f],i.kind==="file"&&(i.webkitGetAsEntry()==null||i.webkitGetAsEntry().isFile)){if(e=i.getAsFile(),e.size==0){alert(GetTextByKey("P_WO_ATTACHMENTSTIPS","Attachment size is 0kb, uploading failed."));return}if(e.size>52428800){alert(GetTextByKey("P_WO_ATTACHMENTSTIPS1","Attachment is too large. Maximum file size is 50 MB."));return}u.push({File:e,Notes:""})}(o=$("#tabinvoice"+t).data("invoice"),o)&&o.Status===0&&u.length>0&&k(u,t)}function ut(n,t){var r,u,f,i,e,o;if(n.stopPropagation(),r=n.clipboardData,u=[],r.items!==undefined)for(f=0;f<r.items.length;f++)if(i=r.items[f],i.kind==="file"&&(i.webkitGetAsEntry()==null||i.webkitGetAsEntry().isFile)){if(e=i.getAsFile(),e.size==0){alert(GetTextByKey("P_WO_ATTACHMENTSTIPS","Attachment size is 0kb, uploading failed."));return}if(e.size>52428800){alert(GetTextByKey("P_WO_ATTACHMENTSTIPS1","Attachment is too large. Maximum file size is 50 MB."));return}u.push({File:e,Notes:""})}(o=$("#tabinvoice"+t).data("invoice"),o)&&o.Status===0&&u.length>0&&k(u,t)}function gt(n){var u=n.Id,g=oi(n.Status),nt=i.option.parent,s=$('<div id="divinvoice'+u+'" class="subtitle estimates_div" style="margin-right:0px;" ><\/div>'),y,h,o,f,r,e,p,v,c,b,a,k,d;s.on("drop",u,function(n){rt(n.originalEvent,n.data)}).on("dragover",function(n){it(n.originalEvent,n.data)}).on("paste",function(n){ut(n.originalEvent,n.data)});if(s.append('<span class="sbutton iconchevronright" target="tabinvoice'+u+'" onclick="OnExpendInTab(this)" style="margin-left: 0; padding-right: 5px;"><\/span>'),s.append('<span class="sttitle" id="span_invoice_number'+u+'">'+n.InvoiceNumber+"<\/span>"),s.append('<span class="sttitle" id="span_invoice_status'+u+'" style="font-weight:bold;">'+g+"<\/span>"),!WOReadOnly){if(n.Status===t.Pending||n.Status===t.PaymentCreated||n.Status===t.Draft){e=$('<input type="button" style="width: auto; height: 24px;margin-left:100px;" />').val(GetTextByKey("P_WO_MARKASPAID","Mark As Paid"));e.on("click",u,function(n){bi(n.data)});s.append(e)}if(n.Status===t.Pending){e=$('<input type="button" style="width: auto; height: 24px;margin-left:20px;" />').val(GetTextByKey("P_WO_REVOKE","Revoke"));e.on("click",u,function(n){ni(n.data)});s.append(e)}if(n.Status==t.Draft||n.Status===t.Pending||n.Status===t.Revoked){y=$('<span class="sbutton icondelete" style="float:right;margin-right: 10px; padding: 0px 0px 0px 5px;" ><\/span>');y.on("click",u,function(n){ri(n.data)});s.append(y)}}s.append("<hr />");nt.append(s);h=n.Status===t.Pending||n.Status===t.PaymentCreated||n.Status===t.Paid||n.Status===t.Revoked||n.Status===t.ManualPaid;o=$('<table id="tabinvoice'+u+'" class="estimates_table" ><\/table>').data("invoice",n).hide();o.on("drop",u,function(n){rt(n.originalEvent,n.data)}).on("dragover",function(n){it(n.originalEvent,n.data)}).on("paste",function(n){ut(n.originalEvent,n.data)});if(nt.append(o),f=$("<tr><\/tr>"),o.append(f),r=$('<td class="label"><\/td>').text(GetTextByKey("P_WO_INVOICENUMBER","Invoice #:")),f.append(r),r=$('<td style="width:150px;"><\/td>'),f.append(r),e=$('<input type="text" id="dialog_invoice_number'+u+'" tabindex="1" maxlength="50" autocomplete="off" />').val(n.InvoiceNumber).change(function(n){return function(){l(n)}}(u)),r.append(e),r=$('<td class="label"><\/td>').text(GetTextByKey("P_WO_OTHERCOST_COLON","Other Cost ($):")),f.append(r),r=$("<td><\/td>"),f.append(r),e=$('<input type="text" id="dialog_invoice_othercost'+u+'" tabindex="1" maxlength="12" autocomplete="off" />').val(locale(n.OtherCost,h)).change(function(n){return function(){l(n)}}(u)),r.append(e),p=$('<td rowspan="7" style="vertical-align: top; padding-left: 20px"><\/td>').attr("id","invoice_payment_tab"+u),f.append(p),n.PaymentItem!=null){if(v="<span><\/span>",n.Status===t.ManualPaid){v=$('<input type="button" style="width: 100px; height: 24px;" />').val(GetTextByKey("P_WO_CANCELPAYMENT","Cancel Payment"));v.on("click",u,function(n){ti(n.data)})}p.empty().append($('<table style="width: 100%; table-layout: fixed"><\/table>').append($("<tr><\/tr>").append($('<td style="width: 150px" class="payment-label"><\/td>').text(GetTextByKey("P_WO_PAYMENTENTEREDBY_COLON","Payment Entered By:")),$('<td style="width: 320px"><\/td>').text(n.PaymentItem.PaymentEnteredByName),$('<td class="payment-label"><\/td>').text(GetTextByKey("P_WO_CUSTOMERNAME","Customer Name:")),$("<td><\/td>").text(n.PaymentItem.CustomerName)),$("<tr><\/tr>").append($('<td style="width: 150px" class="payment-label"><\/td>').text(GetTextByKey("P_WO_PAYMENTTIME","Payment Time:")),$('<td style="width: 320px"><\/td>').text(n.PaymentItem.CreatedLocalStr),$('<td class="payment-label"><\/td>').text(GetTextByKey("P_WO_CUSTOMEREMAIL","Customer Email:")),$("<td><\/td>").text(n.PaymentItem.CustomerEmail)),$("<tr><\/tr>").append($('<td class="payment-label"><\/td>').text(GetTextByKey("P_WO_PAYMENTTYPE_COLON","Payment Type:")),$("<td><\/td>").text(n.PaymentItem.PaymentType),$("<td><\/td>"),$("<td><\/td>")),$("<tr><\/tr>").append($('<td class="payment-label"><\/td>').text(GetTextByKey("P_WO_CHECK_COLON","Check #:")),$("<td><\/td>").text(n.PaymentItem.CheckNumber),$("<td><\/td>"),$("<td><\/td>")),$("<tr><\/tr>").append($('<td class="payment-label"><\/td>').text(GetTextByKey("P_WO_CARDNUMBER","Card Number:")),$("<td><\/td>").text(n.PaymentItem.CardNumber),$('<td class="payment-label"><\/td>').text(GetTextByKey("P_WO_EXPIRATION","Expiration:")),$("<td><\/td>").text(n.PaymentItem.CardExpiration)),$("<tr><\/tr>").append($('<td class="payment-label"><\/td>').text(GetTextByKey("P_WO_CARDTYPE","Card Type:")),$("<td><\/td>").text(n.PaymentItem.CardType),$('<td class="payment-label"><\/td>').text(GetTextByKey("P_WO_COUNTRY_COLON","Country:")),$("<td><\/td>").text(n.PaymentItem.CustomerCountry)),$("<tr><\/tr>").append($('<td class="payment-label"><\/td>').text(GetTextByKey("P_WO_ISSUER","Issuer:")),$('<td style="padding-right: 20px; white-space: nowrap"><\/td>').text(n.PaymentItem.CardIssuer),$('<td style="text-align:right;"><\/td>').append(v),$("<td><\/td>"))))}if(f=$("<tr><\/tr>"),o.append(f),r=$('<td class="label"><\/td>').text(GetTextByKey("P_WO_INVOICETOTALCOST","Invoice Total Cost ($):")),f.append(r),r=$("<td><\/td>"),f.append(r),e=$('<input type="text" id="dialog_invoice_totalcosts'+u+'" tabindex="1" maxlength="12" autocomplete="off" />').val(locale(n.TotalCost,h)).change(function(n){return function(){l(n)}}(u)),r.append(e),r=$('<td class="label"><\/td>').text(GetTextByKey("P_WO_TRAVELTIMECOST_COLON","Travel Time Cost ($):")),f.append(r),r=$("<td><\/td>"),f.append(r),e=$('<input type="text" id="dialog_invoice_traveltimecost'+u+'" tabindex="1" maxlength="12" autocomplete="off" />').val(locale(n.TravelCost,h)).change(function(n){return function(){l(n)}}(u)),r.append(e),f=$("<tr><\/tr>"),o.append(f),r=$('<td class="label"><\/td>').text(GetTextByKey("P_WO_PARTSCOST_COLON","Parts Cost ($):")),f.append(r),r=$("<td><\/td>"),f.append(r),e=$('<input type="text" id="dialog_invoice_partscost'+u+'" tabindex="1" maxlength="12" autocomplete="off" />').val(locale(n.PartsCost,h)).change(function(n){return function(){l(n)}}(u)),r.append(e),r=$('<td class="label"><\/td>').text(GetTextByKey("P_WO_TAXES_COLON","Taxes ($):")),f.append(r),r=$("<td><\/td>"),f.append(r),e=$('<input type="text" id="dialog_invoice_taxes'+u+'" tabindex="1" maxlength="12" autocomplete="off" />').val(locale(n.Taxes,h)).change(function(n){return function(){l(n)}}(u)),r.append(e),f=$("<tr><\/tr>"),o.append(f),r=$('<td class="label"><\/td>').text(GetTextByKey("P_WO_LABORCOST_COLON","Labor Cost ($):")),f.append(r),r=$("<td><\/td>"),f.append(r),e=$('<input type="text" id="dialog_invoice_laborcost'+u+'" tabindex="1" maxlength="12" autocomplete="off" />').val(locale(n.LaborCost,h)).change(function(n){return function(){l(n)}}(u)),r.append(e),r=$('<td class="label"><\/td>').text(GetTextByKey("P_WO_INVOICESTATUS","Invoice Status:")),f.append(r),r=$('<td style="width: 150px"><\/td>'),f.append(r),e=$('<span style="font-weight:bold;" id="dialog_invoice_status'+u+'"><\/span>').text(g),r.append(e),f=$("<tr><\/tr>"),o.append(f),r=$('<td class="label"><\/td>').text(GetTextByKey("P_WO_CUSTOMERVISIBLE_COLON","Customer Visible:")),f.append(r),r=$("<td><\/td>"),f.append(r),e=$('<input type="checkbox" id="dialog_invoice_customervisible'+u+'" tabindex="1" />').prop("checked",n.CustomerVisible),n.Status===t.Draft||n.Status===t.Revoked?e.attr("disabled",!0):e.attr("disabled",!1),e.change(u,function(n){ii(n.data,$(n.target).prop("checked"))}),r.append(e),f=$("<tr><\/tr>"),o.append(f),r=$('<td class="label" style="vertical-align:top;"><\/td>').text(GetTextByKey("P_WOS_NOTES_COLON","Notes:")),f.append(r),r=$('<td colspan="3"><\/td>'),f.append(r),e=$('<textarea id="dialog_invoice_notes'+u+'" tabindex="1" maxlength="500" style="width: 480px; height: 80px; margin-top: 5px;" ><\/textarea>').val(n.Notes).change(function(n){return function(){l(n)}}(u)),r.append(e),n.Status===t.Draft&&(f=$("<tr><\/tr>"),o.append(f),r=$('<td class="label"><\/td>').text(GetTextByKey("P_WO_ATTACHMENTS_COLON"," Attachments:")),f.append(r),r=$('<td colspan="3"><\/td>'),f.append(r),c=$("<div><\/div>"),r.append(c),!WOReadOnly)){b=$('<span class="sbutton iconadd" />').text(GetTextByKey("P_FR_ADDFILE","Add File..."));b.on("click",u,function(n){lt(n.data)});c.append(b)}f=$('<tr id="tr_invoice_atts'+u+'"><\/tr>');o.append(f);r=$('<td class="label" style="vertical-align:top;"><\/td>').text(n.Status===t.Draft?"":GetTextByKey("P_WO_ATTACHMENTS_COLON","Attachments:"));f.append(r);r=$('<td colspan="3"><\/td>');f.append(r);a=$('<table id="tab_invoice_attachments'+u+'" style="border: 1px solid #a8a8a8; line-height: 25px; width: 480px; display: none;"><\/table>');r.append(a);k=$("<tr><\/tr>");a.append(k);d=$("<td><\/td>");k.append(d);c=$('<div style="max-height: 80px; overflow: auto;padding: 0 4px;"><\/div>');d.append(c);a=$('<table id="tab_invoice_atts'+u+'" style="table-layout: fixed;"><\/table>');c.append(a);ct(u);f=$("<tr><\/tr>");o.append(f);r=$('<td colspan="4" style="text-align: right; height: 33px"><\/td>');f.append(r);e=$('<input type="button" style="width: auto; height: 25px;" id="btn_invoice_save'+u+'" />').val(GetTextByKey("P_WO_SAVE","Save")).hide();e.on("click",u,function(n){w(n.data)});r.append(e);e=$('<input type="button" style="width: auto; height: 25px;margin-left:20px;" id="btn_invoice_publish'+u+'" />').val(GetTextByKey("P_WO_PUBLISH","Publish")).hide();e.on("click",{id:u,no:n.InvoiceNumber,cost:n.TotalCost},function(n){ot(n.data)});r.append(e);WOReadOnly||(n.Status===t.Draft&&($("#btn_invoice_publish"+u).show(),$("#btn_invoice_save"+u).show()),n.Status===t.Pending&&$("#btn_invoice_revoke"+u).show(),(n.Status===t.Pending||n.Status===t.PaymentCreated)&&$("#btn_invoice_markaspaid"+u).show());(h||WOReadOnly)&&ei(u,!0);(n.Status===t.PaymentCreated||n.Status===t.Failed)&&($("#span_invoice_status"+u).css("color","red"),$("#dialog_invoice_status"+u).css("color","red"));(n.Status===t.Paid||n.Status===t.ManualPaid)&&($("#span_invoice_status"+u).css("color","#2eda2e"),$("#dialog_invoice_status"+u).css("color","#2eda2e"))}function ni(n){n<=0||showConfirm(GetTextByKey("P_WO_CONFIRM_REVOKE_INVOICE","Do you want to revoke the invoice?"),GetTextByKey("P_WO_REVOKE_INVOICE","Revoke Invoice"),function(){worequest("RevokeWorkOrderInvoice",n,function(n){n==="OK"&&h(!0)},function(){showAlert(GetTextByKey("P_WO_FAILED_REVOKE_INVOICE","Failed to revoke this invoice."),GetTextByKey("P_WO_REVOKE_INVOICE","Revoke Invoice"))})})}function ti(n){n<=0||showConfirm(GetTextByKey("P_WO_AREYOUSUREYOUWANTTOCANCELTHEPAYMENT","Are you sure you want to Cancel the Payment?"),GetTextByKey("P_WO_CANCELINVOICE","Cancel Invoice"),function(){worequest("CancelPayment",n,function(n){n==="OK"&&h()},function(){showAlert(GetTextByKey("P_WO_FAILED_REVOKE_INVOICE","Failed to cancel this payment."),GetTextByKey("P_WO_CANCELINVOICE","Cancel Invoice"))})})}function ii(n,t){n<=0||worequest("ChangeWOInvoiceCustomerVisible",JSON.stringify([n,t?1:0]),function(){},function(){})}function ri(n){n<=0||showConfirm(GetTextByKey("P_WO_CONFIRM_DELETE_INVOICE","Do you want to delete the invoice?"),GetTextByKey("P_WO_DELETE_INVOICE","Delete Invoice"),function(){worequest("DeleteWorkOrderInvoice",n,function(n){n==="OK"&&h(!0)},function(){showAlert(GetTextByKey("P_WO_FAILED_DELETE_INVOICE","Failed to delete this invoice."),GetTextByKey("P_WO_DELETE_INVOICE","Delete Invoice"))})})}function ui(){var r=parseInt($("#dialog_invoice_status").val()),n,i;r==t.Pending?(n=$("#dialog_invoice_number").val(),i=parseFloat($("#dialog_invoice_totalcosts").val()),ot({id:-1,no:n,cost:i})):w("")}function w(n,r){var h=-1,o=0,e=GetTextByKey("P_WO_ADDINVOICE","Add Invoice"),s,u,f,c;if(n>0){if(e=GetTextByKey("P_WO_EDITINVOICE","Edit Invoice"),s=$("#tabinvoice"+n).data("invoice"),!s)return;h=s.Id;o=s.Status}else o=parseInt($("#dialog_invoice_status").val());if(u=n>0?String(n):"",f={Id:h,WorkOrderId:i.option.workorderid,Status:o,InvoiceNumber:$("#dialog_invoice_number"+u).val(),TotalCost:$("#dialog_invoice_totalcosts"+u).val(),OtherCost:$("#dialog_invoice_othercost"+u).val(),PartsCost:$("#dialog_invoice_partscost"+u).val(),TravelCost:$("#dialog_invoice_traveltimecost"+u).val(),LaborCost:$("#dialog_invoice_laborcost"+u).val(),Taxes:$("#dialog_invoice_taxes"+u).val(),Notes:$("#dialog_invoice_notes"+u).val(),CustomerVisible:$("#dialog_invoice_customervisible"+u).prop("checked"),PaymentMethod:$("#dialog_invoice_paymentby"+u).val(),CheckNumber:$("#dialog_invoice_checknumber"+u).val()},isNaN(f.TotalCost)||f.TotalCost<0){showAlert(GetTextByKey("P_WO_TOTALCOST_INVALID","Total cost is not a valid number."),e,function(){$("#dialog_invoice_totalcosts"+u).focus()});return}if(isNaN(f.OtherCost)||f.OtherCost<0){showAlert(GetTextByKey("P_WO_OTHERCOST_INVALID","Other cost is not a valid number."),e,function(){$("#dialog_invoice_othercost"+u).focus()});return}if(isNaN(f.PartsCost)||f.PartsCost<0){showAlert(GetTextByKey("P_WO_PARTSCOST_INVALID","Parts cost is not a valid number."),e,function(){$("#dialog_invoice_partscost"+u).focus()});return}if(isNaN(f.TravelCost)||f.TravelCost<0){showAlert(GetTextByKey("P_WO_TRAVELTIMECOST_INVALID","Travel time cost is not a valid number."),e,function(){$("#dialog_invoice_traveltimecost"+u).focus()});return}if(isNaN(f.LaborCost)||f.LaborCost<0){showAlert(GetTextByKey("P_WO_LABORCOST_INVALID","Labor cost is not a valid number."),e,function(){$("#dialog_invoice_laborcost"+u).focus()});return}if(isNaN(f.Taxes)||f.Taxes<0){showAlert(GetTextByKey("P_WO_TAXES_INVALID","Taxes is not a valid number."),e,function(){$("#dialog_invoice_taxes"+u).focus()});return}if(o==t.Pending&&f.TotalCost<=0){showAlert(GetTextByKey("P_WO_TOTALCOST_MUST_POSITIVE","Total cost must be a positive number."),e,function(){$("#dialog_invoice_totalcosts"+h).focus()});return}o!=t.Pending&&o!=t.ManualPaid||f.CustomerVisible?g(f,n,r,e):(c=GetTextByKey("P_WO_INVOICEWILLNOTBEDISPLAYEDONCUSTOMERFACINPAGE","Invoice will not be displayed on Customer Facing Page.<br/> Do you want to:"),di(c,e,function(){$("#dialog_invoice_customervisible"+u).prop("checked",!0);f.CustomerVisible=!0;g(f,n,r,e)},function(){g(f,n,r,e)},null))}function g(n,t,i,r){var u=t>0?String(t):"",e;$("#btn_invoice_save"+u).attr("disabled",!0);e=JSON.stringify(n);e=htmlencode(e);worequest("SaveWorkOrderInvoice",e,function(e){typeof e=="string"?($("#btn_invoice_save"+u).attr("disabled",!1),showAlert(e,r)):($("#btn_invoice_save"+u).attr("disabled",!1),n.Id=e,t<=0?(f&&f.length>0&&(k(f,e),f=[]),i?i(e):h(!0),dt()):i?i(t):(showAlert(GetTextByKey("P_WO_SAVSUCCESSFULLY","Saved successfully."),r),$("#span_invoice_number"+u).text($("#dialog_invoice_number"+u).val())))},function(n){$("#btn_invoice_save"+u).attr("disabled",!1);console.log(n);showAlert(GetTextByKey("P_WO_FAILED_SAVE_INVOICE","Failed to save invoice."),r)})}function fi(){if(f=[],$("#tab_invoice_atts").empty(),$("#tab_invoice_attachments").hide(),!i.option.workorderid||i.option.workorderid===""){showAlert(GetTextByKey("P_WO_SAVEWORKORDERFIRST","Please save work order first."),GetTextByKey("P_WO_ADDINVOICE","Add Invoice"));return}$("#dialog_invoice_number").val("");$("#dialog_invoice_status").val("0");$("#tr_payment").hide();$("#dialog_invoice_totalcosts").val("");$("#dialog_invoice_othercost").val("");$("#dialog_invoice_partscost").val("");$("#dialog_invoice_traveltimecost").val("");$("#dialog_invoice_laborcost").val("");$("#dialog_invoice_taxes").val("");$("#dialog_invoice_notes").val("");$("#dialog_invoice_customervisible").prop("checked",!1).attr("disabled",!0);$("#dialog_invoice_paymentby").val("Credit Card");$("#dialog_invoice_checknumber").val("");i.option.workorderdata&&($("#dialog_invoice_number").val(i.option.workorderdata.InvoiceNumber||""),$("#dialog_invoice_totalcosts").val(i.option.workorderdata.WorkOrderTotalCost==0?"":i.option.workorderdata.WorkOrderTotalCost),$("#dialog_invoice_othercost").val(i.option.workorderdata.OtherCost==0?"":i.option.workorderdata.OtherCost),$("#dialog_invoice_partscost").val(i.option.workorderdata.PartsCost==0?"":i.option.workorderdata.PartsCost),$("#dialog_invoice_traveltimecost").val(i.option.workorderdata.TravelTimeCost==0?"":workorderdata.TravelTimeCost),$("#dialog_invoice_laborcost").val(i.option.workorderdata.LaborCost==0?"":i.option.workorderdata.LaborCost),$("#dialog_invoice_taxes").val(i.option.workorderdata.Taxes==0?"":i.option.workorderdata.Taxes));kt()}function l(n){$("#tabinvoice"+n).data("changed",!0)}function ei(n,t){$("#dialog_invoice_number"+n).attr("disabled",t);$("#dialog_invoice_totalcosts"+n).attr("disabled",t);$("#dialog_invoice_othercost"+n).attr("disabled",t);$("#dialog_invoice_partscost"+n).attr("disabled",t);$("#dialog_invoice_traveltimecost"+n).attr("disabled",t);$("#dialog_invoice_laborcost"+n).attr("disabled",t);$("#dialog_invoice_taxes"+n).attr("disabled",t);$("#dialog_invoice_notes"+n).attr("disabled",t)}function oi(n){var i="";return n===t.Draft?i=GetTextByKey("P_WO_DRAFT","Draft"):n===t.Pending?i=GetTextByKey("P_WO_AWATING_PAYMENT","Awaiting Payment"):n===t.Cancelled?i=GetTextByKey("P_WO_CANCELLEDBYDEALER","Cancelled by Dealer"):n===t.PaymentCreated?i=GetTextByKey("P_WO_AWATING_PAYMENT","Awaiting Payment"):n===t.Paid||n===t.ManualPaid?i=GetTextByKey("P_WO_CUSTOMER_PAID","Customer Paid"):n===t.Failed?i=GetTextByKey("P_WO_PAYMENT_FAILURE","Payment Failure"):n===t.Revoked?i=GetTextByKey("P_WO_REVOKED","Revoked"):n===100&&(i=""),i}function ft(){r<=0?o.find(".maskbg").show():a.fadeIn(100);$("#dialog_invoice_textmsg").val(WorkorderParams.InvoiceMessage);$("#dialog_invoice_chkSendAttachment").prop("disabled",r<0?f.length<=0:!(b.find(n=>n.Id===r)?.Attachments?.length>0)).prop("checked",!1);$("#dialog_invoice_spanAttachmentName").hide();u=null;s.css({top:(document.documentElement.clientHeight-s.height())/3,left:(document.documentElement.clientWidth-s.width())/2}).showDialogfixed()}function et(){r<=0?o.find(".maskbg").hide():a.fadeOut(100);r=0;s.hide()}function ot(n){d=n;var t=n.id;t<=0?(r=t,ft()):w(t,function(){r=t;ft()})}function si(){var n=$("#tabinvoice"+r).data("changed");r<=0&&(n=!0);n?w(r,st):st(r)}function st(n){var f,w,a,v,o,t,c,r,y,p,g;if(!(n<=0)){if(f=[],w=$("#dialog_invoice_chksendtextmsg").prop("checked"),w&&(a=$("#dialog_invoice_phonenum").val(),a!==""))for(v=a.split(";"),o=0;o<v.length;o++)if(t=v[o],checkPhoneNumber(t)||isEmail(t))f.push({Key:t,Value:t});else if(i.option.customercontacts)for(c=0;c<i.option.customercontacts.length;c++)if((r=i.option.customercontacts[c],!r.OptOut&&!r.OptOut_BC)&&(y=$.trim(r.MobilePhone),p=$.trim(r.Email),r.Name===t)){if(r.ContactPreference=="0"&&checkPhoneNumber(y)){f.push({Key:y,Value:t});break}if(r.ContactPreference=="1"&&isEmail(p)){f.push({Key:p,Value:t});break}}var nt=$("#dialog_invoice_textmsg").val(),tt=$("#dialog_invoice_chkIncludeStatusLink").prop("checked"),l=JSON.stringify([n,d.no,d.cost,i.option.workorderid,JSON.stringify(f),nt,tt?"1":"0"]);l=htmlencode(l);var b=_network.root+"Maintenance/AddWorkOrder.aspx",k="PublishInvoiceToCustomer",e=new FormData;e.append("MethodName",k);e.append("ClientData",l);u!=null&&(Object.prototype.hasOwnProperty.call(u,"id")?(g={Id:u.id,Caption:u.name},e.append("AttaData",htmlencode(JSON.stringify(g)))):e.append("attachment",u.file));s.find(".maskbg").show();$.ajax({url:b,type:"POST",dataType:"json",processData:!1,contentType:!1,cache:!1,data:e,success:function(n){if(n!==""){showAlert(n,GetTextByKey("P_WO_ERROR","Error"));return}h(!0);et()},error:function(n,t,i){showAlert(GetTextByKey("P_WO_FAILED_PUBLISH_INVOICE","Failed to publish this invoice."),GetTextByKey("P_WO_PUBLISH_INVOICE","Publish Invoice"));n?.readyState==0?console.log(n):writelog_ironintel("PublishEstimate",b+".-1."+k+"."+JSON.stringify(l),JSON.stringify(n),t+i)},complete:function(){s.find(".maskbg").hide()}})}}function k(n,t){for(var f,e,r=new FormData,u=[],i=0;i<n.length;i++)r.append("iconFile"+i,n[i].File),u.push(encodeURIComponent(n[i].Notes));f=JSON.stringify([t,JSON.stringify(u)]);r.append("MethodName","AddInvoiceAttachment");r.append("ClientData",f);e="AddWorkOrder.aspx";$.ajax({url:e,type:"POST",dataType:"json",processData:!1,contentType:!1,data:r,"async":!0,success:function(n){n!=="OK"?showAlert(n,GetTextByKey("P_WO_ATTACHMENTFILE","Attachment File")):t>0?(nt(),ht(t)):h(!0)},error:function(){showAlert(GetTextByKey("P_WO_UPLOADFAILED","Upload failed"),GetTextByKey("P_WO_ATTACHMENTFILE","Attachment File"))}})}function ht(n){var t=$("#tabinvoice"+n).data("invoice");t&&($("#tab_invoice_atts"+n).empty(),$("#tab_invoice_attachments"+n).hide(),worequest("GetWorkOrderInvoiceAttachments",t.Id,function(t){if(typeof t=="string"){showAlert(t,GetTextByKey("P_WO_ERROR","Error"));return}t&&t.length>0&&ct(n,t);var i=b.find(t=>t.Id===n);i!=null&&(i.Attachments=t)},function(){}))}function ct(n,i){var e=!1,u,f,o,c;if(i)e=!0;else{if(u=$("#tabinvoice"+n).data("invoice"),!u)return;i=u.Attachments;(u.Status===t.Draft||u.Status===t.Revoked)&&(e=!0)}if($("#tab_invoice_atts"+n).empty(),$("#tab_invoice_attachments"+n).hide(),i&&i.length>0)for($("#tab_invoice_attachments"+n).show(),f=0;f<i.length;f++){var r=i[f],s=$("<tr><\/tr>").attr("id",r.AttachmentId),h=$("<td><\/td>"),l=$("<label style='text-decoration: underline;color: RGB(30,144,255);cursor:pointer;'><\/label>").text(r.Notes===""?r.FileName:r.Notes).click(function(){window.open("../filesvc.ashx?attchid="+this.parentElement.parentElement.id+"&sourceType=woestimateattachment")}),a=$("<span><\/span>").text(r.AddedByName).css("margin-right",5).css("margin-left",5).css("color","black"),v=$("<span><\/span>").text(r.AddedOnLocalStr).css("color","black");h.append(l,a,v);!WOReadOnly&&e&&(o=$('<td style="width:18px;border:none;text-align:center;"><\/td>'),c=$('<span class="sbutton icondelete" style="padding:0;" ><\/span>').click(function(){hi(this.parentElement.parentElement.id,n)}),o.append(c),s.append(o));s.append(h).appendTo($("#tab_invoice_atts"+n))}}function hi(n,t){confirm(GetTextByKey("P_WO_DELETEATTACHMENTTIPS","Are you sure you want to delete the attachment?"))&&worequest("DeleteInvoiceAttachment",n,function(n){n!=="OK"?showAlert(n,GetTextByKey("P_WO_DELETEATTACHMENT","Delete Attachment")):ht(t)},function(){})}function nt(){c<=0?o.find(".maskbg").hide():showmaskbg(!1);v.hide()}function lt(n){e=undefined;c=n;n<=0?o.find(".maskbg").show():showmaskbg(!0);$("#btn_woinvoice_att_save").attr("disabled",!1);$("#tab_woinvoice_atts").empty();$("#tab_woinvoice_attachments").hide();$("#dialog_invoice_att_notes").val("");v.css({top:(document.documentElement.clientHeight-v.height())/3,left:(document.documentElement.clientWidth-v.width())/2}).showDialogfixed()}function ci(n){n.preventDefault();n.dataTransfer.dropEffect="link"}function li(n){var u,i,r,f,t;if(n.preventDefault(),n.stopPropagation(),u=n.dataTransfer,i=[],u.items!==undefined)for(t=0;t<u.items.length;t++)if(r=u.items[t],r.kind==="file"&&(r.webkitGetAsEntry()==null||r.webkitGetAsEntry().isFile)){if(f=r.getAsFile(),f.size==0){alert(GetTextByKey("P_WO_ATTACHMENTSTIPS","Attachment size is 0kb, uploading failed."));return}if(f.size>52428800){alert(GetTextByKey("P_WO_ATTACHMENTSTIPS1","Attachment is too large. Maximum file size is 50 MB."));return}i.push({File:f,Notes:""})}if(i.length>0)for(t=0;t<i.length;t++)e=i[t],tt()}function ai(n){var u,i,r,f,t;if(n.stopPropagation(),u=n.clipboardData,i=[],u.items!==undefined)for(t=0;t<u.items.length;t++)if(r=u.items[t],r.kind==="file"&&(r.webkitGetAsEntry()==null||r.webkitGetAsEntry().isFile)){if(f=r.getAsFile(),f.size==0){alert(GetTextByKey("P_WO_ATTACHMENTSTIPS","Attachment size is 0kb, uploading failed."));return}if(f.size>52428800){alert(GetTextByKey("P_WO_ATTACHMENTSTIPS1","Attachment is too large. Maximum file size is 50 MB."));return}i.push({File:f,Notes:""})}if(i.length>0)for(t=0;t<i.length;t++)e=i[t],tt()}function vi(){var n=$('<input type="file" style="display: none;" />');n.change(function(){var n=this.files,t;if(n.length!=0){if(n[0].size==0)return alert(GetTextByKey("P_WO_ATTACHMENTSTIPS","Attachment size is 0kb, uploading failed.")),!1;if(n[0].size>52428800)return alert(GetTextByKey("P_WO_ATTACHMENTSTIPS1","Attachment is too large. Maximum file size is 50 MB.")),!1;t=$("#dialog_invoice_att_notes").val();e={File:n[0],Notes:t};yi(e)}}).click()}function yi(n){var t,u;$("#tab_woinvoice_atts").empty();$("#tab_woinvoice_attachments").show();var i=$("<tr><\/tr>"),r=$("<td><\/td>"),f=$("<label class='attalabel'><\/label>").text(n.Notes===""?n.File.name:n.Notes);r.append(f);t=$('<td style="width:18px;border:none;text-align:center;"><\/td>');u=$('<span class="sbutton icondelete" style="padding:0;" ><\/span>').click(function(){this.parentElement.parentElement.remove();e=undefined;$("#tab_woinvoice_attachments").hide()});t.append(u);i.append(t);i.append(r).appendTo($("#tab_woinvoice_atts"))}function tt(){if(e){$("#btn_woinvoice_att_save").attr("disabled",!0);var n=$("#dialog_invoice_att_notes").val();e.Notes=n;c<=0?(f.push(e),pi(e),nt(),$("#btn_woinvoice_att_save").attr("disabled",!1)):k([e],c)}}function pi(n){var i=n.Notes,o=n.File,t,e;$("#tab_invoice_attachments").show();var r=$("<tr><\/tr>"),u=$("<td><\/td>"),s=$("<label class='attalabel'><\/label>").text(i===""?o.name:i);u.append(s);t=$('<td style="width:18px;border:none;text-align:center;"><\/td>');e=$('<span class="sbutton icondelete" style="padding:0;" ><\/span>').data("filedata",n).click(function(){this.parentElement.parentElement.remove();var n=$(this).data("filedata");f.splice(f.indexOf(n),1);f.length==0&&$("#tab_invoice_attachments").hide()});t.append(e);r.append(t);r.append(u).appendTo($("#tab_invoice_atts"))}function wi(){showmaskbg(!1);y.hide()}function bi(n){c=n;$("#btn_woinvoice_maikpaid_save").attr("disabled",!1);showmaskbg(!0);$("#dialog_invoice_markpaid_paymentby").val("Credit Card");$("#dialog_invoice_markpaid_number").val("");y.css({top:(document.documentElement.clientHeight-y.height())/3,left:(document.documentElement.clientWidth-y.width())/2}).showDialogfixed()}function ki(){var n=$("#tabinvoice"+c).data("changed");n?w(c,at):at()}function at(){var t=$("#tabinvoice"+c).data("invoice"),i=[t.Id,$("#dialog_invoice_markpaid_paymentby").val(),$("#dialog_invoice_markpaid_number").val()],n=JSON.stringify(i);n=htmlencode(n);$("#dialog_woinvoice_markpaid .maskbg").show();worequest("MarkAsPaid",n,function(n){$("#dialog_woinvoice_markpaid .maskbg").hide();n==="OK"&&(wi(),h(!0))},function(){$("#dialog_woinvoice_markpaid .maskbg").hide()})}function di(n,t,i,r,u){s.find(".maskbg").show();_dialog.showInvoiceConfirm(n,t,function(n){s.find(".maskbg").show();typeof r=="function"&&r(n)},function(n){s.find(".maskbg").show();typeof i=="function"&&i(n)},function(n){s.find(".maskbg").show();typeof u=="function"&&u(n)})}var o,a,p,t;this.option=n||{};var i=this,b=[],r=0,d=null,u=null,f=[],e,c=0;this.changewo=function(n){var t=this.option.workorderid===n;this.option.workorderid=n;h(t)};this.close=function(){o?.remove();a?.remove();s?.remove();v?.remove();y?.remove()};this.setwodata=function(n){this.option.workorderdata=n};this.updatecontact=function(n){var i,r,t,u,f;if(this.option.customercontacts=n,this.option.customercontacts){for(i="",r=0;r<this.option.customercontacts.length;r++)(t=this.option.customercontacts[r],t.OptOut||t.OptOut_BC)||(u=$.trim(t.MobilePhone),f=$.trim(t.Email),(t.ContactPreference=="0"&&checkPhoneNumber(u)||t.ContactPreference=="1"&&isEmail(f))&&(i==""?i=t.Name:i+=";"+t.Name));$("#dialog_invoice_phonenum").val(i)}else $("#dialog_invoice_phonenum").val("")};this.createInvoice=function(n){var t,i;n.addClass("tab_invoices");t=$('<div class="function_title"><\/div>');n.append(t);i=$('<span class="sbutton iconadd" data-lgid="P_WO_ADDINVOICE">Add Invoice<\/span>');i.click(fi);t.append(i);n.applyFleetLanguageText(!0)};this.createInvoice(this.option.parent);o=vt();a=$('<div class="mask_dialog"><\/div>').hide();$(document.body).append(a);var s=yt(),v=pt(),y=wt();p=!1;t={Draft:0,Pending:1,Cancelled:2,PaymentCreated:3,Paid:4,Failed:5,ManualPaid:6,Revoked:10};_dialog.showInvoiceConfirm=function(n,t,i,r,u,f,e){u||(u=r);_dialog.showButtonDialog(n,t,"question",u,[{value:GetTextByKey("P_WO_MARKASCUSTOMERVISIBLE","Mark as Customer Visible"),func:r},{value:GetTextByKey("P_WO_MCONTINUEWITHOUTMAKINGVISIBLE","Continue Without Making Visible"),func:i}],f,e)}});typeof $wosegment!="function"&&($wosegment=function(n){function ft(){var r=$('<div class="dialog" style="display: none;"><\/div>'),i,n,t,u,f;r.append('<div class="dialog-title"><span class="title" id="popupTitle" data-lgid="P_WO_ADDSEGMENT">Add Segment<\/span><em class="dialog-close"><\/em><\/div>');i=$('<table style="line-height: 28px;"><\/table>');r.append($('<div class="dialog-content"><\/div>').append(i));n=$("<tr><\/tr>").appendTo(i);t=$('<td class="label" data-lgid="P_WO_USER_COLON">User:<\/td>').appendTo(n);t=$("<td><\/td>").appendTo(n);v=$('<div id="dialog_segmentuser" tabindex="101" style="width: 320px" class="dropdown"><\/div>').appendTo(t);v.dropdown([],{search:!0,valueKey:"IID",textKey:"DisplayName",parent:".dialog-content"});n=$("<tr><\/tr>").appendTo(i);t=$('<td class="label" data-lgid="P_WO_HOURS_COLON">Hours:<\/td>').appendTo(n);t=$("<td><\/td>").appendTo(n);b=$('<input type="text" id="dialog_segmenthour" tabindex="102" maxlength="200" autocomplete="off" />').appendTo(t);b.keydown(c);n=$("<tr><\/tr>").appendTo(i);t=$('<td class="label" data-lgid="P_WO_JOBSITE_COLON">Jobsite:<\/td>').appendTo(n);t=$("<td><\/td>").appendTo(n);y=$('<div id="dialog_segmentjobsite" tabindex="103" style="width: 320px" class="dropdown"><\/div>').appendTo(t);y.dropdown([],{search:!0,valueKey:"ID",textKey:"Name",parent:".dialog-content"});n=$("<tr><\/tr>").appendTo(i);t=$('<td class="label" data-lgid="P_WO_COST_COLON">Cost:<\/td>').appendTo(n);t=$("<td><\/td>").appendTo(n);k=$('<input type="text" id="dialog_segmentcost" tabindex="104" maxlength="200" autocomplete="off" />').appendTo(t);k.keydown(c);n=$("<tr><\/tr>").appendTo(i);t=$('<td class="label" data-lgid="P_WO_SEGMENTTYPE_COLON">Segment Type:<\/td>').appendTo(n);t=$("<td><\/td>").appendTo(n);p=$('<div id="dialog_segmenttype" tabindex="104" style="width: 320px" class="dropdown"><\/div>').appendTo(t);p.dropdown([],{input:!0,maxlength:50,textKey:"value",parent:".dialog-content"});n=$("<tr><\/tr>").appendTo(i);t=$('<td class="label" data-lgid="P_WO_COMPONENT_COLON">Component:<\/td>').appendTo(n);t=$("<td><\/td>").appendTo(n);w=$('<div id="dialog_segmentcomponent" tabindex="104" style="width: 320px" class="dropdown"><\/div>').appendTo(t);w.dropdown([],{input:!0,maxlength:40,textKey:"value",parent:".dialog-content"});n=$("<tr><\/tr>").appendTo(i);t=$('<td class="label" data-lgid="P_WO_BILLABLE_COLON">Billable:<\/td>').appendTo(n);t=$("<td><\/td>").appendTo(n);it=$('<input type="checkbox" id="dialog_segmentbillable" tabindex="105" />').appendTo(t);n=$("<tr><\/tr>").appendTo(i);t=$('<td class="label" data-lgid="P_WO_COMPLETED_COLON">Completed:<\/td>').appendTo(n);t=$("<td><\/td>").appendTo(n);d=$('<input type="checkbox" id="dialog_segmentcompleted" tabindex="105" />').appendTo(t);n=$("<tr><\/tr>").appendTo(i);t=$('<td class="label" data-lgid="P_WO_COMPLETEDDATE_COLON">Completed Date:<\/td>').appendTo(n);t=$("<td><\/td>").appendTo(n);h=$('<input type="text" id="dialog_segmentcompleteddate" tabindex="106" maxlength="200" autocomplete="off" />').appendTo(t);h.datetimepicker({timepicker:!1,format:"m/d/Y",enterLikeTab:!1,scrollInput:!1,onSelectDate:function(n,t){var i=(new DateFormatter).formatDate(n,"m/d/Y 00:00:00");t.parent().data("val",[i])}});h.change(function(){var n=h.val();n.length>0&&checkDate(n)&&d.prop("checked",!0)});n=$("<tr><\/tr>").appendTo(i);t=$('<td class="label"><span data-lgid="P_WO_DESCRIPTION_COLON">Description:<\/span><span class="redasterisk">*<\/span><\/td>').appendTo(n);t=$("<td><\/td>").appendTo(n);rt=$('<input type="text" id="dialog_segmentdesc" tabindex="107" maxlength="200" autocomplete="off" />').appendTo(t);n=$("<tr><\/tr>").appendTo(i);t=$('<td class="label" data-lgid="P_WO_NOTES_COLON">Notes:<\/td>').appendTo(n);t=$("<td><\/td>").appendTo(n);ut=$('<textarea id="dialog_segmentnotes" maxlength="1000" tabindex="108" style="width: 540px; height: 120px;"><\/textarea>').appendTo(t);u=$('<div class="dialog-func"><\/div>');r.append(u);u.append('<input type="button" value="Cancel" data-lgid="P_WO_CANCEL" class="dialog-close" tabindex="53" />');f=$('<input type="button" value="OK" data-lgid="P_WO_OK" tabindex="52" />');f.on("click",function(){tt("")});return u.append(f),u.append('<div class="clear"><\/div>'),$(document.body).append(r),r.dialog(function(){showmaskbg(!1)}),r.applyFleetLanguageText(!0),r}function c(n){var t=n.which;return t===9||t===8||t===46||t===110||t===190||t===37||t===39||t===55||t===56||t>=48&&t<=57||t>=96&&t<=105?!0:!1}function g(n){worequest("GetSegmentDataSource","",function(t){var u,o,i,r;if(t.Users&&t.Users.length>0&&(l=t.Users,v.dropdownSource(l)),t.JobSites&&t.JobSites.length>0){u=[{ID:"-1",Name:" ",html:" "}];for(o of t.JobSites)u.push(o);a=u;y.dropdownSource(a)}if(t.Components&&t.Components.length>0){i=[];for(r of t.Components)i.push({value:r});f=i;w.dropdownSource(f)}if(t.SegmentTypes&&t.SegmentTypes.length>0){i=[];for(r of t.SegmentTypes)i.push({value:r});e=i;p.dropdownSource(e)}n&&n()},function(n){console.log(n)})}function nt(n){worequest("GetSegmentDataSource1","",function(t){var i,r;if(t.Components&&t.Components.length>0){i=[];for(r of t.Components)i.push({value:r});f=i;$("#dialog_segmentcomponent").dropdownSource(f)}if(t.SegmentTypes&&t.SegmentTypes.length>0){i=[];for(r of t.SegmentTypes)i.push({value:r});e=i;$("#dialog_segmenttype").dropdownSource(e)}n&&n()},function(n){console.log(n)})}function et(n){var t=$("#dialog_segmentcompleteddate"+n).val();t.length>0&&checkDate(t)&&$("#dialog_segmentcompleted"+n).prop("checked",!0)}function ot(n){$("#dialog_segmentcompleteddate"+n).datetimepicker({timepicker:!1,format:"m/d/Y",enterLikeTab:!1,onSelectDate:function(n,t){var i=(new DateFormatter).formatDate(n,"m/d/Y 00:00:00");t.parent().data("val",[i])}});$("#dialog_segmentuser"+n).dropdown(l||[],{search:!0,valueKey:"IID",textKey:"DisplayName"});$("#dialog_segmentjobsite"+n).dropdown(a||[],{search:!0,valueKey:"ID",textKey:"Name"});$("#dialog_segmenttype"+n).dropdown(e||[],{input:!0,maxlength:50,textKey:"value"});$("#dialog_segmentcomponent"+n).dropdown(f||[],{input:!0,maxlength:40,textKey:"value"})}function u(n){(s=0,t.option.parent.find(".segments_table").remove(),t.option.workorderid&&t.option.workorderid!="")&&(o||(o=!0,typeof t.option.showloading=="function"&&t.option.showloading(!0),worequest("GetSegments",t.option.workorderid,function(r){var e,f;if(o=!1,typeof t.option.showloading=="function"&&t.option.showloading(!1),typeof r=="string"){showAlert(r,GetTextByKey("P_WO_ERROR","Error"));return}if(r.WorkOrderID!=t.option.workorderid){u(n);return}if(r=r.Data,s=0,r&&r.length>0){for(i=r,e=0,f=0;f<i.length;f++)e+=i[f].Cost,st(i[f]);$("#dialog_workordercosts").val(e)}else t.option.workorderdata&&$("#dialog_workordercosts").val(t.option.workorderdata.WorkOrderTotalCost==0?"":t.option.workorderdata.WorkOrderTotalCost),i=[],n&&n()},function(){o=!1;typeof t.option.showloading=="function"&&t.option.showloading(!1)})))}function st(n){var l,b,k,a,d,g,nt,it,rt,ut,ft,v,y;s++;var i=n.SegmentID,st=t.option.parent,o=$('<table id="tabsegment_'+i+'" class="segments_table"><\/table>'),p=$("<tr><\/tr>"),w=$('<td class="label" style="font-size:14px;font-weight:500;text-align:left;">'+GetTextByKey("P_WO_SEGMENT","Segment")+" "+s+'<\/td>"');if(!WOReadOnly){l=$('<span class="sbutton icondelete" ><\/span>');l.on("click",i,function(n){ct(n.data)});w.append(l)}b=$('<td><\/td>"');p.append(w).append(b);o.append(p);var r=$("<tr><\/tr>"),f=$('<td class="label">'+GetTextByKey("P_WO_USER_COLON"," User:")+'<\/td>"'),u=$('<td><\/td>"'),ht=$('<div id="dialog_segmentuser'+i+'" class="dropdown"><\/div>').css("width",320);u.append(ht);var h=$('<td class="label">'+GetTextByKey("P_WO_COMPLETED_COLON","Completed:")+'<\/td>"'),e=$('<td><\/td>"'),at=$('<input type="checkbox" id="dialog_segmentcompleted'+i+'" />');e.append(at);r.append(f).append(u).append(h).append(e);o.append(r);r=$("<tr><\/tr>");f=$('<td class="label">'+GetTextByKey("P_WO_HOURS_COLON","Hours:")+'<\/td>"');u=$('<td><\/td>"');k=$('<input type="text" id="dialog_segmenthour'+i+'" maxlength="12" />').keydown(c);u.append(k);h=$('<td class="label">'+GetTextByKey("P_WO_COMPLETEDDATE_COLON","Completed Date:")+'<\/td>"');e=$('<td><\/td>"');a=$('<input type="text" id="dialog_segmentcompleteddate'+i+'" />');a.on("change",i,function(n){et(n.data)});if(e.append(a),r.append(f).append(u).append(h).append(e),o.append(r),r=$("<tr><\/tr>"),f=$('<td class="label">'+GetTextByKey("P_WO_JOBSITE_COLON","Jobsite:")+'<\/td>"'),u=$('<td><\/td>"'),d=$('<div id="dialog_segmentjobsite'+i+'" class="dropdown"><\/div>').css("width",320),u.append(d),h=$('<td class="label"><span>'+GetTextByKey("P_WO_DESCRIPTION_COLON","Description:")+'<\/span><span class="redasterisk">*<\/span><\/td>"'),e=$('<td><\/td>"'),g=$('<input type="text" id="dialog_segmentdesc'+i+'" maxlength="200" />'),e.append(g),r.append(f).append(u).append(h).append(e),o.append(r),r=$("<tr><\/tr>"),f=$('<td class="label">'+GetTextByKey("P_WO_COST_COLON","Cost:")+'<\/td>"'),u=$('<td><\/td>"'),nt=$('<input type="text" id="dialog_segmentcost'+i+'" />').keydown(c),u.append(nt),h=$('<td class="label">'+GetTextByKey("P_WO_NOTES_COLON","Notes:")+'<\/td>"'),e=$('<td rowspan="4"><\/td>"').css("vertical-align","top"),it=$('<textarea id="dialog_segmentnotes'+i+'" maxlength="500" style="width: 450px; height: 120px;"><\/textarea>'),e.append(it),r.append(f).append(u).append(h).append(e),o.append(r),r=$("<tr><\/tr>"),f=$('<td class="label">'+GetTextByKey("P_WO_SEGMENTTYPE_COLON","Segment Type:")+'<\/td>"'),u=$('<td><\/td>"'),rt=$('<div id="dialog_segmenttype'+i+'" class="dropdown"><\/div>').css("width",320),u.append(rt),r.append(f).append(u),o.append(r),r=$("<tr><\/tr>"),f=$('<td class="label">'+GetTextByKey("P_WO_COMPONENT_COLON","Component:")+'<\/td>"'),u=$('<td><\/td>"'),ut=$('<div id="dialog_segmentcomponent'+i+'" class="dropdown"><\/div>').css("width",320),u.append(ut),r.append(f).append(u),o.append(r),r=$("<tr><\/tr>"),f=$('<td class="label">'+GetTextByKey("P_WO_BILLABLE_COLON","Billable:")+'<\/td>"'),u=$('<td><\/td>"'),ft=$('<input type="checkbox" id="dialog_segmentbillable'+i+'" />'),u.append(ft),r.append(f).append(u),o.append(r),!WOReadOnly){r=$("<tr><\/tr>");f=$('<td colspan="4" style="text-align: right;"><\/td>"');v=$('<input type="button" value="Save" style="width:80px;height:25px;" id="btn_savesegment'+i+'" />').val(GetTextByKey("P_WO_SAVE","Save"));v.on("click",i,function(n){tt(n.data)});y=$('<input type="button" value="Cancel" style="width:80px;height:25px;margin-left:10px;" />').val(GetTextByKey("P_WO_CANCEL","Cancel"));y.on("click",i,function(n){lt(n.data)});f.append(v).append(y);r.append(f);o.append(r)}st.append(o);ot(i);$("#tabsegment_"+i).data("segment",n);$("#dialog_segmentuser"+i).dropdownVal(n.UserIID);$("#dialog_segmentdesc"+i).val(n.Description);$("#dialog_segmenthour"+i).val(n.Hours===0?"":n.Hours);$("#dialog_segmentnotes"+i).val(n.Notes);$("#dialog_segmentjobsite"+i).dropdownVal(n.JobsiteID);$("#dialog_segmentcost"+i).val(n.Cost===0?"":n.Cost);$("#dialog_segmenttype"+i).dropdownVal(n.SegmentType);$("#dialog_segmentcompleted"+i).prop("checked",n.Completed);$("#dialog_segmentcompleteddate"+i).val(n.CompletedDateStr);$("#dialog_segmentcomponent"+i).dropdownVal(n.Component);$("#dialog_segmentbillable"+i).prop("checked",n.Billable)}function ht(){if(!t.option.workorderid||t.option.workorderid===""){showAlert(GetTextByKey("P_WO_SAVEWORKORDERFIRST","Please save work order first."),GetTextByKey("P_WO_ADDSEGMENT","Add Segment"));return}$("#dialog_segmentuser").dropdownVal("");$("#dialog_segmentdesc").val("");$("#dialog_segmenthour").val("");$("#dialog_segmentnotes").val("");$("#dialog_segmentjobsite").dropdownVal("");$("#dialog_segmentcost").val("");$("#dialog_segmentcompleted").prop("checked",!1);$("#dialog_segmentcompleteddate").val("");$("#dialog_segmenttype").dropdownVal("");$("#dialog_segmentcomponent").dropdownVal("");$("#dialog_segmentbillable").prop("checked",!1);at()}function ct(n){var t=$("#tabsegment_"+n).data("segment");t&&showConfirm(GetTextByKey("P_WO_DOYOUWANTTODELETETHESEGMENT","Do you want to delete the segment?"),GetTextByKey("P_WO_DELETESEGMENT","Delete Segment"),function(){worequest("DeleteSegment",t.SegmentID,function(){nt(function(){typeof getTotalCost=="function"?u(getTotalCost):u()})},function(){showAlert(GetTextByKey("P_WO_FAILEDDELETESEGMENT","Failed to delete this segment."),GetTextByKey("P_WO_DELETESEGMENT","Delete Segment"))})})}function lt(n){var t=$("#tabsegment_"+n).data("segment");t&&($("#dialog_segmentuser"+n).dropdownVal(t.UserIID),$("#dialog_segmentdesc"+n).val(t.Description),$("#dialog_segmenthour"+n).val(t.Hours),$("#dialog_segmentnotes"+n).val(t.Notes),$("#dialog_segmentjobsite"+n).dropdownVal(t.JobsiteID),$("#dialog_segmentcost"+n).val(t.Cost),$("#dialog_segmentcompleted"+n).prop("checked",t.Completed),$("#dialog_segmentcompleteddate"+n).val(t.CompletedDateStr),$("#dialog_segmenttype"+n).dropdownVal(t.SegmentType),$("#dialog_segmentcomponent"+n).dropdownVal(t.Component),$("#dialog_segmentbillable"+n).prop("checked",t.Billable))}function tt(n){var e,r,i,f;if($("#btn_savesegment"+n).attr("disabled",!0),e=-1,r=GetTextByKey("P_WO_ADDSEGMENT","Add Segment"),n>0&&(r=GetTextByKey("P_WO_EDITSEGMENT","Edit Segment"),e=n),i={SegmentID:e,WorkOrderID:t.option.workorderid,UserIID:$("#dialog_segmentuser"+n).dropdownVal(),Description:$("#dialog_segmentdesc"+n).val(),Hours:$("#dialog_segmenthour"+n).val(),Notes:$("#dialog_segmentnotes"+n).val(),JobsiteID:$("#dialog_segmentjobsite"+n).dropdownVal(),Cost:$("#dialog_segmentcost"+n).val(),Completed:$("#dialog_segmentcompleted"+n).prop("checked"),CompletedDate:$("#dialog_segmentcompleteddate"+n).val(),SegmentType:$("#dialog_segmenttype"+n).dropdownVal(),Component:$("#dialog_segmentcomponent"+n).dropdownVal(),Billable:$("#dialog_segmentbillable"+n).prop("checked")},i.Description===""||i.Description.length==0){showAlert(GetTextByKey("P_WO_DESCRIPTIONREQUIRED","Description is required."),r);$("#btn_savesegment"+n).attr("disabled",!1);return}if(i.Hours!==""){if(isNaN(i.Hours)){showAlert(GetTextByKey("P_WO_HOURSFORMATERROR","Hours format error."),r);$("#btn_savesegment"+n).attr("disabled",!1);return}if(i.Hours<=0){showAlert(GetTextByKey("P_WO_HOURSMUSTBEGREATERTHAN0","Hours must be greater than 0."),r);$("#btn_savesegment"+n).attr("disabled",!1);return}}if(i.Cost!==""){if(isNaN(i.Cost)){showAlert(GetTextByKey("P_WO_COSTFORMATERROR","Cost format error."),r);$("#btn_savesegment"+n).attr("disabled",!1);return}if(i.Cost<=0){showAlert(GetTextByKey("P_WO_COSTMUSTBEGREATERTHAN0","Cost must be greater than 0."),r);$("#btn_savesegment"+n).attr("disabled",!1);return}}i.Cost===""&&(i.Cost=-1);i.Hours===""&&(i.Hours=-1);f=JSON.stringify(i);f=htmlencode(f);worequest("SaveSegment",f,function(t){typeof t=="string"?($("#btn_savesegment"+n).attr("disabled",!1),showAlert(t,r)):($("#btn_savesegment"+n).attr("disabled",!1),n>0&&showAlert(GetTextByKey("P_WO_SAVSUCCESSFULLY","Saved successfully."),r),nt(function(){typeof getTotalCost=="function"?u(getTotalCost):u()}),vt())},function(t){$("#btn_savesegment"+n).attr("disabled",!1);console.log(t);showAlert(GetTextByKey("P_WO_FAILEDTOSAVESEGMENT","Failed to save segment."),r)})}function at(){showmaskbg(!0);r.css({top:(document.documentElement.clientHeight-r.height())/3,left:(document.documentElement.clientWidth-r.width())/2}).showDialogfixed()}function vt(){showmaskbg(!1);r.hide()}var r,i,o,s;this.option=n||{};var t=this,l=[],a=[],f=[],e=[],v,b,y,k,p,w,it,d,h,rt,ut;this.changewo=function(n){this.option.workorderid=n;g(u)};this.close=function(){r?.remove()};this.loadsource=function(){g()};this.setwodata=function(n){this.option.workorderdata=n};this.hasSegment=function(){return i&&i.length>0};this.createSegment=function(n){var t,i;n.addClass("tab_segments");t=$('<div class="function_title"><\/div>');n.append(t);i=$('<span class="sbutton iconadd" data-lgid="P_WO_ADDSEGMENT">Add Segment<\/span>');i.click(ht);t.append(i);n.applyFleetLanguageText(!0)};this.createSegment(this.option.parent);r=ft();i=[];o=!1;s=0});typeof $woalert!="function"&&($woalert=function(n){function et(n){n.DTCAlerts&&n.DTCAlerts.length>0?(o=n.DTCAlerts,y.show(),i(o,r)):(o=[],i(o,r));n.PMAlerts&&n.PMAlerts.length>0?(s=n.PMAlerts,i(s,u),$("#dialog_expectedcost").val(n.AllExpectedCost===0?"":n.AllExpectedCost)):(s=[],i(s,u));n.InspectAlerts&&n.InspectAlerts.length>0?(h=n.InspectAlerts,p.show(),i(h,f)):(h=[],i(h,f));n.OilAlerts&&n.OilAlerts.length>0?(c=n.OilAlerts,w.show(),i(c,e)):(c=[],i(c,e))}function i(n,t){for(var i,r,f=[],u=0;u<n.length;u++){if(i=n[u],v.push(i.AlertID),i.RepeatedAlerts)for(r=0;r<i.RepeatedAlerts.length;r++)v.push(i.RepeatedAlerts[r]);for(r in i)r==="EngineHours"?i.EngineHoursObj={DisplayValue:i.EngineHours==0?"":i.EngineHours,Value:i.EngineHours}:r==="AlertLocalTime"&&(i.AlertLocalTime={DisplayValue:i.AlertLocalTimeStr,Value:i.AlertLocalTime});f.push(i)}t.setData(f)}function ct(){var t,u,i,n;r=createGridView("#dtcalertslist");t=[{name:"Selected",caption:"",valueIndex:"Selected",type:3,css:{width:45,"text-align":"center"}},{name:"EngineHours",caption:GetTextByKey("P_WO_HOURS","Hours"),valueIndex:"EngineHoursObj",css:{width:150,"text-align":"left"}},{name:"AlertType",caption:GetTextByKey("P_WO_ALERTTYPE","Alert Type"),valueIndex:"AlertType",css:{width:150,"text-align":"left"}},{name:"Description",caption:GetTextByKey("P_WO_DESCRIPTION","Description"),valueIndex:"Description",css:{width:480,"text-align":"left"}},{name:"AlertCount",caption:GetTextByKey("P_WO_COUNT","Count"),valueIndex:"AlertCount",css:{width:100,"text-align":"left"}},{name:"AlertLocalTime",caption:GetTextByKey("P_WO_LATESTDATETIME","Latest DateTime"),valueIndex:"AlertLocalTime",css:{width:150,"text-align":"left"}},{name:"Comment",caption:GetTextByKey("P_AM_COMMENT","Comment"),valueIndex:"Comment",css:{width:150,"text-align":"left"}}];u=[];for(i in t)n={},n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!0,n.type=t[i].type,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,u.push(n),n.name==="Selected"?n.allcheck=!0:n.name==="Comment"&&(n.type=NoteColumn,n.readonly=!0);r.multiSelect=!1;r.columns=u;r.init()}function lt(){var t,r,i,n;u=createGridView("#pmaalertslist");t=[{name:"Selected",caption:"",valueIndex:"Selected",type:3,css:{width:45,"text-align":"center"}},{name:"EngineHours",caption:GetTextByKey("P_WO_HOURS","Hours"),valueIndex:"EngineHoursObj",css:{width:150,"text-align":"left"}},{name:"AlertType",caption:GetTextByKey("P_WO_ALERTTYPE","Alert Type"),valueIndex:"AlertType",css:{width:150,"text-align":"left"}},{name:"Description",caption:GetTextByKey("P_WO_DESCRIPTION","Description"),valueIndex:"Description",css:{width:240,"text-align":"left"}},{name:"ServiceDescription",caption:GetTextByKey("P_WO_SERVICEDESCRIPTION","Service Description"),valueIndex:"ServiceDescription",css:{width:240,"text-align":"left"}},{name:"ExpectedCost",caption:GetTextByKey("P_PM_EXPECTEDCOST","Expected Cost"),valueIndex:"ExpectedCost",css:{width:100,"text-align":"left"}},{name:"AlertCount",caption:GetTextByKey("P_WO_COUNT","Count"),valueIndex:"AlertCount",css:{width:100,"text-align":"left"}},{name:"AlertLocalTime",caption:GetTextByKey("P_WO_LATESTDATETIME","Latest DateTime"),valueIndex:"AlertLocalTime",css:{width:150,"text-align":"left"}},{name:"Comment",caption:GetTextByKey("P_AM_COMMENT","Comment"),valueIndex:"Comment",css:{width:150,"text-align":"left"}}];r=[];for(i in t)n={},n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!0,n.type=t[i].type,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,r.push(n),n.name==="Selected"?n.allcheck=!0:n.name==="Comment"&&(n.type=NoteColumn,n.readonly=!0);u.multiSelect=!1;u.columns=r;u.init()}function at(){var t,r,i,n;f=createGridView("#inspectalertslist");t=[{name:"Selected",caption:"",valueIndex:"Selected",type:3,css:{width:45,"text-align":"center"}},{name:"EngineHours",caption:GetTextByKey("P_WO_HOURS","Hours"),valueIndex:"EngineHoursObj",css:{width:150,"text-align":"left"}},{name:"AlertType",caption:GetTextByKey("P_WO_ALERTTYPE","Alert Type"),valueIndex:"AlertType",css:{width:150,"text-align":"left"}},{name:"Description",caption:GetTextByKey("P_WO_DESCRIPTION","Description"),valueIndex:"Description",css:{width:480,"text-align":"left"}},{name:"AlertCount",caption:GetTextByKey("P_WO_COUNT","Count"),valueIndex:"AlertCount",css:{width:100,"text-align":"left"}},{name:"AlertLocalTime",caption:GetTextByKey("P_WO_LATESTDATETIME","Latest DateTime"),valueIndex:"AlertLocalTime",css:{width:150,"text-align":"left"}},{name:"Comment",caption:GetTextByKey("P_AM_COMMENT","Comment"),valueIndex:"Comment",css:{width:150,"text-align":"left"}}];r=[];for(i in t)n={},n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!0,n.type=t[i].type,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,r.push(n),n.name==="Selected"?n.allcheck=!0:n.name==="Comment"&&(n.type=NoteColumn,n.readonly=!0);f.multiSelect=!1;f.columns=r;f.init()}function vt(){var t,r,i,n;e=createGridView("#oilalertslist");t=[{name:"Selected",caption:"",valueIndex:"Selected",type:3,css:{width:45,"text-align":"center"}},{name:"EngineHours",caption:GetTextByKey("P_WO_HOURS","Hours"),valueIndex:"EngineHoursObj",css:{width:150,"text-align":"left"}},{name:"AlertType",caption:GetTextByKey("P_WO_ALERTTYPE","Alert Type"),valueIndex:"AlertType",css:{width:150,"text-align":"left"}},{name:"Description",caption:GetTextByKey("P_WO_DESCRIPTION","Description"),valueIndex:"Description",css:{width:480,"text-align":"left"}},{name:"AlertCount",caption:GetTextByKey("P_WO_COUNT","Count"),valueIndex:"AlertCount",css:{width:100,"text-align":"left"}},{name:"AlertLocalTime",caption:GetTextByKey("P_WO_LATESTDATETIME","Latest DateTime"),valueIndex:"AlertLocalTime",css:{width:150,"text-align":"left"}},{name:"Comment",caption:GetTextByKey("P_AM_COMMENT","Comment"),valueIndex:"Comment",css:{width:150,"text-align":"left"}}];r=[];for(i in t)n={},n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!0,n.type=t[i].type,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,r.push(n),n.name==="Selected"?n.allcheck=!0:n.name==="Comment"&&(n.type=NoteColumn,n.readonly=!0);e.multiSelect=!1;e.columns=r;e.init()}function yt(){var n=$('<div class="dialog" style="display: none;"><\/div>'),i,t,r;n.append('<div class="dialog-title"><span class="title" data-lgid="P_WO_ADDALERTS">Add Alerts<\/span><em class="dialog-close"><\/em><\/div>');i=$('<div id="noneassignedalertlist" style="width:820px; height: 200px;"><\/div>');n.append($('<div class="dialog-content"><\/div>').append(i));t=$('<div class="dialog-func"><\/div>');n.append(t);t.append('<input type="button" value="Cancel" data-lgid="P_WO_CANCEL" class="dialog-close" tabindex="53" style="margin-right: 30px;" />');r=$('<input type="button" value="OK" data-lgid="P_WO_OK" tabindex="52" />');r.on("click",function(){ti()});return t.append(r),t.append('<div class="clear"><\/div>'),$(document.body).append(n),n.dialog(function(){showmaskbg(!1)}),pt(i),n.applyFleetLanguageText(!0),n}function pt(n){var i,u,r,t;l=createGridView(n);i=[{name:"Selected",caption:"",valueIndex:"Selected",type:3,css:{width:45,"text-align":"center"}},{name:"EngineHours",caption:GetTextByKey("P_WO_HOURS","Hours"),valueIndex:"EngineHours",css:{width:80,"text-align":"left"}},{name:"AlertType",caption:GetTextByKey("P_WO_ALERTTYPE","Alert Type"),valueIndex:"AlertType",css:{width:150,"text-align":"left"}},{name:"Description",caption:GetTextByKey("P_WO_DESCRIPTION","Description"),valueIndex:"Description",css:{width:200,"text-align":"left"}},{name:"ServiceDescription",caption:GetTextByKey("P_WO_SERVICEDESCRIPTION","Service Description"),valueIndex:"ServiceDescription",css:{width:200,"text-align":"left"}},{name:"AlertTime",caption:GetTextByKey("P_WO_LATESTDATETIME","Latest DateTime"),valueIndex:"AlertLocalTime",css:{width:125,"text-align":"left"}}];u=[];for(r in i)t={},t.name=i[r].name,t.caption=i[r].caption,t.visible=!0,t.sortable=!0,t.type=i[r].type,t.width=i[r].css.width,t.align=i[r].css["text-align"],t.key=i[r].valueIndex,u.push(t),t.name==="Selected"&&(t.allcheck=!0);l.multiSelect=!1;l.columns=u;l.init()}function ot(){o=[];s=[];h=[];c=[];r.setData([]);u.setData([]);f.setData([]);e.setData([])}function nt(){(v=[],y.hide(),p.hide(),w.hide(),ot(),it)||(it=!0,typeof t.option.showloading=="function"&&t.option.showloading(!0),alertrequest("GETWORKORDERALERTS",t.option.workorderid,function(n){if(it=!1,typeof t.option.showloading=="function"&&t.option.showloading(!1),typeof n=="string"){showAlert(n,GetTextByKey("P_WO_ERROR","Error"));return}if(n.WorkOrderID!=t.option.workorderid){nt();return}n=n.Data;et(n);t.reshowalertgrid()},function(){it=!1;typeof t.option.showloading=="function"&&t.option.showloading(!1)}))}function wt(){showmaskbg(!0);b.css({top:(document.documentElement.clientHeight-b.height())/3,left:(document.documentElement.clientWidth-b.width())/2}).showDialogfixed();l&&l.resize()}function bt(){b.hide();showmaskbg(!1)}function kt(){if(!t.option.workorderid||t.option.workorderid===""){showAlert(GetTextByKey("P_WO_SAVEWORKORDERFIRST","Please save work order first."),GetTextByKey("P_WO_ADDALERTS","Add Alerts"));return}dt()}function dt(){if(!t.option.machineid){showAlert(GetTextByKey("P_WO_PLEASESELECTANASSET","Please select an Asset."),GetTextByKey("P_WO_SENDEMAIL","Send Email"));$("#dialog_machine").focus();return}worequest("GetNoneAssignedAlerts",t.option.machineid,function(n){if(typeof n=="string"){showAlert(n,GetTextByKey("P_WO_ERROR","Error"));return}wt();d=n;gt(d)},function(){})}function gt(n){for(var t,i,u=[],r=0;r<n.length;r++){t=n[r];for(i in t)i==="EngineHours"?t[i]={DisplayValue:t[i]==0?"":t[i],Value:t[i]}:i==="AlertLocalTime"&&(t[i]={DisplayValue:t.AlertLocalTimeStr,Value:t[i]});u.push(t)}l.setData(u)}function st(n,i){worequest("AddOrRemoveAlertsFromWorkOrder",t.option.workorderid+String.fromCharCode(170)+JSON.stringify(i)+String.fromCharCode(170)+n,function(){n&&bt();nt()},function(){})}function ni(){var y=[],l,n,a;if(v=[],o.length>0){for(l=o.length-1;l>=0;l--)if(n=o[l],n.Selected&&(y.push(n.AlertID),o.splice(l,1),n.RepeatedAlerts))for(a=0;a<n.RepeatedAlerts.length;a++)y.push(n.RepeatedAlerts[a]);i(o,r)}if(s.length>0){for(l=s.length-1;l>=0;l--)if(n=s[l],n.Selected&&(y.push(n.AlertID),s.splice(l,1),n.RepeatedAlerts))for(a=0;a<n.RepeatedAlerts.length;a++)y.push(n.RepeatedAlerts[a]);i(s,u)}if(h.length>0){for(l=h.length-1;l>=0;l--)if(n=h[l],n.Selected&&(y.push(n.AlertID),h.splice(l,1),n.RepeatedAlerts))for(a=0;a<n.RepeatedAlerts.length;a++)y.push(n.RepeatedAlerts[a]);i(h,f)}if(c.length>0){for(l=c.length-1;l>=0;l--)if(n=c[l],n.Selected&&(y.push(n.AlertID),c.splice(l,1),n.RepeatedAlerts))for(a=0;a<n.RepeatedAlerts.length;a++)y.push(n.RepeatedAlerts[a]);i(c,e)}if(y.length==0){showAlert(GetTextByKey("P_WO_PLEASESELECTANALERT","Please select an Alert."),GetTextByKey("P_WO_REMOVEALERTS","Remove Alerts"));return}t.option.workorderid&&t.option.workorderid!==""&&st(!1,y)}function ti(){var n=[],i,t;if(d.length>0)for(i in d)t=d[i],t.Selected&&n.push(t.ID);if(n.length==0){showAlert(GetTextByKey("P_WO_PLEASESELECTANALERT","Please select an Alert."),GetTextByKey("P_WO_ADDALERTS","Add Alerts"));return}st(!0,n)}function ii(){var n=$('<div class="dialog" style="display: none;"><\/div>'),i,t,r;n.append('<div class="dialog-title"><span class="title" data-lgid="P_WO_SELECTPLANFORALERT">Select Plan for Alert<\/span><em class="dialog-close"><\/em><\/div>');i=$('<div id="allpmpmalertslist" style="width: 420px; height: 200px;"><\/div>');n.append($('<div class="dialog-content"><\/div>').append(i));t=$('<div class="dialog-func"><\/div>');n.append(t);t.append('<input type="button" value="Cancel" data-lgid="P_WO_CANCEL" class="dialog-close" tabindex="53" style="margin-right: 30px;" />');r=$('<input type="button" value="OK" data-lgid="P_WO_OK" tabindex="52" />');r.on("click",function(){hi()});return t.append(r),t.append('<div class="clear"><\/div>'),$(document.body).append(n),n.dialog(function(){showmaskbg(!1)}),ui(i),n.applyFleetLanguageText(!0),n}function ri(n){a.setData(n)}function ui(n){var i,u,r,t;a=createGridView(n);i=[{name:"Selected",caption:"",valueIndex:"Selected",type:3,css:{width:45,"text-align":"center"}},{name:"Name",caption:GetTextByKey("P_MV_SCHEDULENAME","Schedule Name"),valueIndex:"Name",css:{width:300,"text-align":"left"}}];u=[];for(r in i)t={},t.name=i[r].name,t.caption=i[r].caption,t.visible=!0,t.sortable=!0,t.type=i[r].type,t.width=i[r].css.width,t.align=i[r].css["text-align"],t.key=i[r].valueIndex,u.push(t),t.name==="Selected"&&(t.allcheck=!0);a.multiSelect=!1;a.columns=u;a.init()}function fi(){showmaskbg(!0);k.css({top:(document.documentElement.clientHeight-k.height())/3,left:(document.documentElement.clientWidth-k.width())/2}).showDialogfixed();a&&a.resize()}function ei(){k.hide();showmaskbg(!1)}function oi(){if(!t.option.workorderid||t.option.workorderid===""){showAlert(GetTextByKey("P_WO_SAVEWORKORDERFIRST","Please save work order first."),GetTextByKey("P_WO_ADDALERTS","Add Alerts"));return}si()}function si(){if(!t.option.machineid){showAlert(GetTextByKey("P_WO_PLEASESELECTANASSET","Please select an Asset."),GetTextByKey("P_WO_SENDEMAIL","Send Email"));$("#dialog_machine").focus();return}fi();worequest("GetPMSchedulesByAsset",t.option.machineid,function(n){if(typeof n=="string"){showAlert(n,GetTextByKey("P_WO_ERROR","Error"));return}g=n;ri(g)},function(){})}function hi(){var n=[],r,i;if(g.length>0)for(r in g)i=g[r],i.Selected&&n.push(i.Id);if(n.length==0){showAlert(GetTextByKey("P_WO_PLEASESELECTAPLAN","Please select a plan."),GetTextByKey("P_WO_ADDALERTS","Add Alerts"));return}if(!t.option.machineid){showAlert(GetTextByKey("P_WO_PLEASESELECTANASSET","Please select an Asset."),GetTextByKey("P_WO_SENDEMAIL","Send Email"));$("#dialog_machine").focus();return}worequest("GenerateManualPMAlerts",JSON.stringify([t.option.machineid,t.option.workorderid,JSON.stringify(n)]),function(n){var i,r,t;if(typeof n=="string"){showAlert(n,GetTextByKey("P_WO_ERROR","Error"));return}for(i="",r=0;r<n.length;r++)t=n[r],t.Status==-1?i+=GetTextByKey("P_WO_FAILEDTOGENERATEALERT","Failed to generate alert.")+" ("+t.ScheduleName+")\r\n":t.Status==1?i+=GetTextByKey("P_WO_FAILEDTOGENERATEALERT1","Unable to generate alert because there already exists an unmaintained alert.")+" ("+t.ScheduleName+")\r\n":t.Status==2&&(i+=t.UOM=="hour(s)"?GetTextByKey("P_WO_FAILEDTOGENERATEALERT2","Unable to generate alert until Hour Meter is higher than ")+t.NextTargetValue.toLocaleString()+" "+t.UOM+" ("+t.ScheduleName+")\r\n":t.UOM=="day(s)"?GetTextByKey("P_WO_FAILEDTOGENERATEALERT3","Unable to generate alert until {0} later {1}").replace("{0}",t.NextTargetValue.toLocaleString()+" "+t.UOM).replace("{1}"," ("+t.ScheduleName+")\r\n"):GetTextByKey("P_WO_FAILEDTOGENERATEALERT4","Unable to generate alert until odometer is higher than ")+t.NextTargetValue.toLocaleString()+" "+t.UOM+" ("+t.ScheduleName+")\r\n");i!==""&&showAlert(i,GetTextByKey("P_WO_ERROR","Error"));ei();nt()},function(){})}function ht(){r&&r.resize();u&&u.resize();f&&f.resize();e&&e.resize();l&&l.resize();a&&a.resize()}var t,v,y,tt,p,w,rt,ut,ft,b,k,r,u,f,e,l,d,a,g;this.option=n||{};t=this;v=this.option.alertids?this.option.alertids:[];this.refresh=function(){nt()};this.changewo=function(n,t){this.option.workorderid=n;t&&(this.option.machineid=t);nt()};this.close=function(){b?.remove();k?.remove()};this.changeasset=function(n){this.option.machineid=n};this.getalertids=function(){return v};this.createAlert=function(n){var t,i;WOReadOnly||(t=$('<div class="function_title"><\/div>'),n.append(t),rt=$('<span class="sbutton iconadd" data-lgid="P_WO_ADDALERTS">Add Alerts<\/span>'),rt.click(kt),t.append(rt),ut=$('<span class="sbutton icondelete" data-lgid="P_WO_REMOVEALERTS">Remove Alerts<\/span>'),ut.click(ni),t.append(ut),n.append('<div class="clear"><\/div>'));y=$('<div style="height: 260px;min-width:400px; display: none;"><\/div>');y.append('<div class="subtitle"><span data-lgid="P_WO_DTCALERTS">DTC Alerts<\/span><\/div>');y.append('<div id="dtcalertslist"><\/div>');n.append(y);tt=$('<div style="height: 260px; min-width:400px;"><\/div>');i=$('<div class="subtitle"><\/div>');i.append('<span data-lgid="P_WO_PMALERTS">PM Alerts<\/span>');WOReadOnly||(ft=$('<span class="sbutton iconadd" style="color: black;" data-lgid="P_WO_ADDPMALERTS">Add PM Alerts (Alerts not yet triggered)<\/span>'),ft.click(oi),i.append(ft));tt.append(i);tt.append('<div id="pmaalertslist"><\/div>');n.append(tt);p=$('<div style="height: 260px;min-width:400px; display: none;"><\/div>');p.append('<div class="subtitle"><span data-lgid="P_WO_INSPECTALERTS">Inspect Alerts<\/span><\/div>');p.append('<div id="inspectalertslist"><\/div>');n.append(p);w=$('<div style="height: 260px;min-width:400px; display: none;"><\/div>');w.append('<div class="subtitle"><span data-lgid="P_WO_OILALERTS">Oil Alerts<\/span><\/div>');w.append('<div id="oilalertslist"><\/div>');n.append(w);n.applyFleetLanguageText(!0)};this.createAlert(this.option.parent);ct();lt();at();vt();b=yt();k=ii();var o=[],s=[],h=[],c=[],it=!1;this.getAssetAlerts=function(n){v=[];y.hide();p.hide();w.hide();ot();n&&(t.option.machineid=n);typeof t.option.showloading=="function"&&t.option.showloading(!0);alertrequest("GETASSETALERTS",t.option.machineid+String.fromCharCode(170)+JSON.stringify(v),function(n){if(typeof t.option.showloading=="function"&&t.option.showloading(!1),typeof n=="string"){showAlert(n,GetTextByKey("P_WO_ERROR","Error"));return}n.MachineID==t.option.machineid&&(n=n.Data,et(n))},function(){typeof t.option.showloading=="function"&&t.option.showloading(!1)})};this.reshowalertgrid=function(){setTimeout(function(){$("#dtcalertslist").css("height",240);r&&r.resize();$("#pmaalertslist").css("height",240);u&&u.resize();$("#inspectalertslist").css("height",240);f&&f.resize();$("#oilalertslist").css("height",240);e&&e.resize()})};d=[];g=[];window.onresize=ht;ht()});typeof $woattachment!="function"&&($woattachment=function(n){function si(){var i=$('<div class="dialog" style="display: none;"><\/div>'),r,n,t,c,h,u,e,o,f,s;i.append('<div class="dialog-title"><span class="title" data-lgid="P_WO_ADDATTACHMENT">Add Attachment<\/span><em class="dialog-close"><\/em><\/div>');r=$('<table style="line-height: 30px; margin-left: 10px; margin-right: 10px;"><\/table>');i.append($('<div class="dialog-content"><\/div>').append(r));n=$("<tr><\/tr>").appendTo(r);t=$('<td class="label" style="width: unset;"><span data-lgid="P_WO_CAPTION_COLON">Caption:<\/span><\/td>').appendTo(n);t=$("<td><\/td>").appendTo(n);c=$('<input type="text" id="dialog_wo_att_notes" maxlength="200" tabindex="1" autocomplete="off" />').appendTo(t);n=$("<tr><\/tr>").appendTo(r);t=$('<td class="label" data-lgid="P_WO_ATTACHMENTS_COLON" style="vertical-align: top; width: unset;">Attachments:<\/td>').appendTo(n);t=$('<td class="cont"><\/td>').appendTo(n);h=$('<input id="dialog_wo_att_uploadattfile" type="button" value="Add File..." data-lgid="P_FR_ADDFILE" tabindex="1" style="background-color: #0099FF; color: #FFFFFF; height: 20px; width: 200px;" />').appendTo(t);h.on("click",function(){li()});n=$("<tr><\/tr>").appendTo(r);t=$('<td class="label"><\/td>').appendTo(n);t=$('<td colspan="3"><\/td>').appendTo(n);u=$('<table id="tab_wo_attachments" style="border: 1px solid #a8a8a8; line-height: 25px; width: 320px; display: none;"><\/table>');t.append(u);e=$("<tr><\/tr>");u.append(e);o=$("<td><\/td>");e.append(o);div_att=$('<div style="max-height: 80px; overflow: auto;padding: 0 4px;"><\/div>');o.append(div_att);u=$('<table id="tab_wo_atts" style="table-layout: fixed;"><\/table>');div_att.append(u);f=$('<div class="dialog-func"><\/div>');i.append(f);f.append('<input type="button" value="Cancel" data-lgid="P_WO_CANCEL" class="dialog-close" tabindex="11" />');s=$('<input type="button" value="Save" data-lgid="P_WO_SAVE" tabindex="11" />');s.on("click",function(){vi()});return f.append(s),f.append('<div class="clear"><\/div>'),i.append('<div class="maskbg" style="display: none;"><\/div>'),$(document.body).append(i),i.dialog(function(){wt()}),i.applyFleetLanguageText(!0),i}function wt(){showmaskbg(!1);rt.hide()}function vt(){showmaskbg(!1);at.hideDialog()}function bt(){showmaskbg(!1);v.hide()}function kt(n){showmaskbg(!0);$("#dialog_atta_textmsg").val("");var t=n?n.Notes===""?n.FileName:n.Notes:"";$("#dialog_atta_sendattaname").text(t).attr("title",t);v.data("atta",n);v.css({top:(document.documentElement.clientHeight-v.height())/3,left:(document.documentElement.clientWidth-v.width())/2}).showDialogfixed()}function hi(){var r=$('<div class="dialog" style="display: none;"><\/div>'),u,i,n,s,h,t,o,c,l,f,e;r.append('<div class="dialog-title"><span class="title" data-lgid="P_WO_SENDATTACHMENTS">Send Attachments<\/span><em class="dialog-close"><\/em><\/div>');u=$('<table style="line-height: 30px; margin-left: 10px; margin-right: 10px;"><\/table>');r.append($('<div class="dialog-content"><\/div>').append(u));i=$("<tr><\/tr>").appendTo(u);n=$("<td><\/td>").appendTo(i);$('<div style="font-size: 20px; margin-right: 5px; float: right;"><em class="spanbtn iconmobile" style="font-weight: 900; font-size: 14px; cursor: default; padding-left: 0; padding-right: 3px; padding-top: 0;"><\/em><\/div>').appendTo(n);n=$('<td style="width:350px;"><\/td>').appendTo(i);s=$('<input type="text" id="dialog_atta_phonenum" tabindex="1" autocomplete="off" maxlength="100" style="width: 320px;" />').appendTo(n);i=$("<tr><\/tr>").appendTo(u);n=$('<td style="text-align: right;"><\/td>').appendTo(i);h=$('<input id="dialog_atta_chkIncludeStatusLink" type="checkbox" checked="checked" style="width: unset;" />').appendTo(n);n=$("<td><\/td>").appendTo(i);$('<label for="dialog_atta_chkIncludeStatusLink" data-lgid="P_WO_INCLUDESTATUSLINK" style="user-select: none;">Include Status Link<\/label>').appendTo(n);i=$("<tr><\/tr>").appendTo(u);n=$('<td class="label" style="width: unset;"><span data-lgid="P_WO_MESSAGE_COLON">Message:<\/span><\/td>').appendTo(i);n=$("<td><\/td>").appendTo(i);t=$('<select id="dialog_atta_variables" style="width: 156px;"><\/select>').appendTo(n);t.append('<option value="0">[Site_Name]<\/option>');t.append('<option value="1">[Location]<\/option>');t.append('<option value="14">[Asset]<\/option>');t.append('<option value="4">[VIN]<\/option>');t.append('<option value="2">[Make]<\/option>');t.append('<option value="3">[Model]<\/option>');t.append('<option value="5">[Id_Phone]<\/option>');t.append('<option value="6">[Advisor]<\/option>');t.append('<option value="7">[Company_Name]<\/option>');t.append('<option value="8">[Contact_Name]<\/option>');t.append('<option value="9">[Contact_First_Name]<\/option>');t.append('<option value="10">[Status_Link]<\/option>');t.append('<option value="11">[Technician_Name]<\/option>');t.append('<option value="12">[Work_Order_Number]<\/option>');t.append('<option value="13">[Parts_Order_Number]<\/option>');o=$('<input type="button" id="dialog_atta_insertfield" data-lgid="P_WO_ADD" value="Add" style="width: auto; height: auto; margin-left: 5px;" tabindex="1" /><br />').appendTo(n);o.on("click",function(){ci()});c=$('<textarea id="dialog_atta_textmsg" tabindex="1" style="width: 320px; height: 120px; margin-top: 6px;" maxlength="2000"><\/textarea>').appendTo(n);i=$("<tr><\/tr>").appendTo(u);n=$('<td><div style="font-size: 20px; margin-right: 5px; float: right;"><em class="spanbtn iconlink" style="font-weight: 900; font-size: 14px; cursor: default; padding-left: 0; padding-right: 3px; padding-top: 0;"><\/em><\/div><\/td>').appendTo(i);n=$("<td><\/td>").appendTo(i);l=$('<span id="dialog_atta_sendattaname" class="selector-name" style="width: 300px; overflow: hidden; text-overflow: ellipsis; white-space: pre;display:block;"><\/span>').appendTo(n);f=$('<div class="dialog-func"><\/div>');r.append(f);f.append('<input type="button" value="Cancel" data-lgid="P_WO_CANCEL" class="dialog-close" tabindex="11" />');e=$('<input type="button" value="Send" data-lgid="P_WO_SEND" tabindex="1" />');e.on("click",function(){var n=$("#dialog_atta_phonenum").val();ir(n)});return f.append(e),f.append('<div class="clear"><\/div>'),r.append('<div class="maskbg" style="display: none;"><\/div>'),$(document.body).append(r),r.dialog(function(){bt()}),r.applyFleetLanguageText(!0),r}function ci(){var n=$("#dialog_atta_variables").find("option:selected").text();$("#dialog_atta_textmsg").focus();document.execCommand("insertText",!1,n)}function li(){var n=$('<input type="file" style="display: none;" />');n.change(function(){var n=this.files,t;if(n.length!=0){if(n[0].size==0)return alert(GetTextByKey("P_WO_ATTACHMENTSTIPS","Attachment size is 0kb, uploading failed.")),!1;if(n[0].size>52428800)return alert(GetTextByKey("P_WO_ATTACHMENTSTIPS1","Attachment is too large. Maximum file size is 50 MB.")),!1;t=$("#dialog_wo_att_notes").val();e=n[0];e.Notes=t;ai(e)}}).click()}function ai(n){var t,u;$("#tab_wo_atts").empty();$("#tab_wo_attachments").show();var i=$("<tr><\/tr>"),r=$("<td><\/td>"),f=$("<label class='attalabel'><\/label>").text(n.Notes===""?n.name:n.Notes);r.append(f);t=$('<td style="width:18px;border:none;text-align:center;"><\/td>');u=$('<span class="sbutton icondelete" style="padding:0;" ><\/span>').click(function(){this.parentElement.parentElement.remove();e=null;$("#tab_wo_attachments").hide()});t.append(u);i.append(t);i.append(r).appendTo($("#tab_wo_atts"))}function vi(){if(e){$("#btn_wo_att_save").attr("disabled",!0);var n=$("#dialog_wo_att_notes").val();e.Notes=n;wt();ht([e]);e=null}}function yi(){var n=$('<div class="dialog" style="display: none;"><\/div>'),t;n.append('<div class="dialog-title"><span class="title" data-lgid="P_WO_ATTACHMENTS">Attachments<\/span><em class="dialog-close"><\/em><\/div>');lt=$('<div style="height: 320px; width:420px;"><\/div>');n.append($('<div class="dialog-content"><\/div>').append(lt));t=$('<div class="dialog-func"><\/div>');n.append(t);t.append('<input type="button" value="Cancel" data-lgid="P_WO_CANCEL" class="dialog-close" tabindex="1" style="height: unset;" />');ft=$('<input type="button" value="Print" data-lgid="P_WO_PRINT" tabindex="1" />');ft.on("click",function(){di()});t.append(ft);et=$('<input type="button" value="Download" data-lgid="P_WO_DOWNLOAD" tabindex="1" />');et.on("click",function(){gi()});t.append(et);ot=$('<input type="button" value="OK" data-lgid="P_WO_OK" tabindex="1" />');ot.on("click",function(){bi()});return t.append(ot),t.append('<div class="clear"><\/div>'),n.append('<div class="maskbg" style="display: none;"><\/div>'),$(document.body).append(n),n.dialog(function(){showmaskbg(!1)}),n.applyFleetLanguageText(!0),n}function pi(){var n=$('<input type="file" style="display: none;" multiple="multiple" />');n.change(function(){var n=this.files;n.length>0&&ht(n)}).click()}function ht(n){if(y="",i.option.workorderid)if(showLoading(!0),$(".span_attupload").show(),$(".span_vieuploadmsg").css("margin-left",0),$(".span_vieuploadmsg").show(),r.length>0){for(var t=0;t<n.length;t++)r.push(n[t]);f(0)}else r=n,p(i.option.workorderid);else OnSave(0,function(t){if(i.option.workorderid=t.Id,showLoading(!0),$(".span_attupload").show(),$(".span_vieuploadmsg").css("margin-left",0),$(".span_vieuploadmsg").show(),r.length>0){for(var u=0;u<n.length;u++)r.push(i.option.workorderid,n[u]);f(0)}else r=n,p(i.option.workorderid)})}function p(n){var t,s,u,h;if(n!=i.option.workorderid){r=[];o=-1;return}if(o++,o>=r.length){o--;f(3);r=[];o=-1;$(".span_attupload").hide();$(".span_vieuploadmsg").css("margin-left",200);ct(!0);hideLoading();y!==""&&showAlert(y,GetTextByKey("P_WO_UPLOADFAILED","Upload failed"));return}if(t=r[o],t.name.length>200){f(2,GetTextByKey("P_WO_ATTACHMENTNAMELENGTHCANNOTBEGREATERTHAN","Attachment name length cannot be greater than 200."));p(n);return}if(t.size==0){f(2,GetTextByKey("P_WO_ATTACHMENTSTIPS","Attachment size is 0kb, uploading failed."));p(n);return}if(t.size>52428800){f(2,GetTextByKey("P_WO_ATTACHMENTSTIPS1","Attachment is too large. Maximum file size is 50 MB."));p(n);return}f(0);var e=$(window).height()/2-100,c=$(window).width()/2-100,l=$("#dialogattmask .lable_attuploadname").width();$("#dialogattmask .loading_icon").css({top:e,left:c});$("#dialogattmask .lable_attuploadname").css({top:e+70,left:($(window).width()-l-100)/2});s=JSON.stringify([n,t.Notes]);u=new FormData;u.append("iconFile",t);u.append("MethodName","AddAttachment");u.append("ClientData",s);h="AddWorkOrder.aspx";$.ajax({url:h,type:"POST",dataType:"json",processData:!1,contentType:!1,data:u,"async":!0,success:function(t){t!=="OK"&&showAlert(GetTextByKey("P_WO_UPLOADFAILED","Upload failed"),GetTextByKey("P_WO_ATTACHMENTFILE","Attachment File"));f(1);p(n)},error:function(){f(2,GetTextByKey("P_WO_UPLOADFAILED","Upload failed"));p(n)}})}function f(n,t){var u,i;r.length!=0&&(u=r[o].name,u.length>50&&(u=u.substring(0,49)+"..."),i="",n==0?(i="Uploading "+u+" ("+(o+1)+"/"+r.length+")",$(".lable_attuploadname").text(i)):n==1?(i=u,st.append('<li style="padding-left: 0;height:unset;line-height:24px;"><span class="sbutton iconattsuc">'+i+"<\/span><\/li>")):n==2?(i=u+" - "+t,st.append('<li style="padding-left: 0;height:unset;line-height:24px;"><span class="sbutton iconatterror">'+i+"<\/span><\/li>"),y=y===""?i:y+" \n "+i):n==3&&(i="Upload Completed",i="",$(".lable_attuploadname").text(i)))}function dt(n,t){confirm(GetTextByKey("P_WO_DELETEATTACHMENTTIPS","Are you sure you want to delete the attachment?"))&&worequest("DeleteAttachment",n,function(n){n!=="OK"?showAlert(n,GetTextByKey("P_WO_DELETEATTACHMENT","Delete Attachment")):t.parent().parent().remove()},function(){showAlert(GetTextByKey("P_WO_FAILEDDELETEATTACHMENT","Failed to delete this attachment."),GetTextByKey("P_WO_DELETEATTACHMENT","Delete Attachment"))})}function gt(n){h=n;typeof setCookie=="function"&&setCookie("woattachmentviewtype",h);$(".woattafoldicon").removeClass("iconchevronright").addClass("iconchevrondown");$(".woattafoldtr").show();ni()}function ni(){h||(h=0);parseInt(h)===1?(c.hide(),a.show(),nr(t)):(c.show(),a.hide(),wi(t));$("#dialogattmask").height($(document).outerHeight(!1)).width($(document).outerWidth(!1))}function ct(n){(i.option.workorderid||i.option.machineid)&&(ut||(ut=!0,n||(l.empty(),d.empty(),g.empty(),nt.empty(),tt.empty(),it.empty(),typeof i.option.showloading=="function"&&i.option.showloading(!0)),worequest("GetAttachments",JSON.stringify([i.option.workorderid,i.option.machineid]),function(r){if(ut=!1,n||typeof i.option.showloading=="function"&&i.option.showloading(!1),r&&typeof r!="string"){if(r.WorkOrderID!=i.option.workorderid){ct(!1);return}r=r.Data;t=r;ni(t)}},function(){ut=!1;n||typeof i.option.showloading=="function"&&i.option.showloading(!1)})))}function wi(n){var nt,v,u,t,r,o,h,f,i;if(n.WorkOrderAttachments&&n.WorkOrderAttachments.length>0){for(u=l.children("div"),i=0;i<n.WorkOrderAttachments.length;i++){var t=n.WorkOrderAttachments[i],a=$('<div class="divattp"><\/div>'),r=yt(t,!0);if(AllowCustomer){var y=$('<div style=" margin-top: 15px;"><\/div>'),it=$('<span style="font-weight:500;"><\/span>').text(GetTextByKey("P_WO_AVAILABLETOCUSTOMER","Available to Customer")),p=$('<input type="checkbox" />').prop("checked",t.AvailableToCustomer).click(t,function(n){ti(n.data.AttachmentId,$(this).prop("checked"))});p.data("aid",t.AttachmentId);y.append(p).append(it);a.append(y)}AllowDeleteAtta&&(nt=$('<span class="delete"><\/span>').attr("title",GetTextByKey("P_WO_DELETE","Delete")).click(t,function(n){dt(n.data.AttachmentId,$(n.target))}),r.append(nt));v=$('<span class="attaicon attasend"><\/span>').attr("title",GetTextByKey("P_WO_SEND","Send")).click(t,function(n){kt(n.data)}).css("right",55);r.append(v);$.inArray(t.FileType.toLowerCase(),s)>=0?(o=$('<span class="attaicon attaprint"><\/span>').attr("title",GetTextByKey("P_WO_PRINT","Print")).click(t,function(n){b(n.data.AttachmentType,n.data.AttachmentIdStr)}).css("right",30),r.append(o)):v.css("right",30);h=$('<span class="attaicon attadownload"><\/span>').attr("title",GetTextByKey("P_WO_DOWNLOAD","Download")).click(t,function(n){k(n.data.Url+"&d=1")});r.append(h);a.append(r);var c=t.Notes===""?t.FileName:t.Notes,tt=$('<div style="text-align:center;clear:both;height:25px;"><\/div>'),e=$('<input type="text" style="width: 296px;" class="inp_name" style="height:24px;" maxlength="200"/>').attr("data-ori",c).val(c);e.data("attdata",t);c&&c!=""||e.attr("placeholder","Click to Add caption");tt.append(e);e.focus({AttachmentId:t.AttachmentId,iptcaption:e},function(n){n.data.iptcaption.addClass("focused")});e.blur({div:r,AttachmentId:t.AttachmentId,iptcaption:e,caption:c},function(n){n.data.iptcaption.removeClass("focused");ri(n.data)});e.keydown({div:r,AttachmentId:t.AttachmentId,iptcaption:e,caption:c},function(n){(n.keyCode==13||n.keyCode==9)&&n.data.iptcaption.blur()});a.append(tt);f=u[i];f?(a.insertAfter(f),f.remove()):l.append(a)}for(i=n.WorkOrderAttachments.length;i<u.length;i++)u[i].remove()}else l.empty();if(n.AssetAttachments&&n.AssetAttachments.length>0){for(u=d.children("div"),i=0;i<n.AssetAttachments.length;i++)t=n.AssetAttachments[i],w.indexOf(t.FileType.toLowerCase())>=0&&(t.ThumbnailUrl=t.Url+"&thumb=1"),r=yt(t,!1,300),$.inArray(t.FileType.toLowerCase(),s)>=0&&(o=$('<span class="attaicon attaprint"><\/span>').attr("title",GetTextByKey("P_WO_PRINT","Print")).click(t,function(n){b(n.data.AttachmentType,n.data.AttachmentIdStr)}).css("right",30),r.append(o)),t.FileType.toLowerCase()!="url"&&(h=$('<span class="attaicon attadownload"><\/span>').attr("title",GetTextByKey("P_WO_DOWNLOAD","Download")).click(t,function(n){k(n.data.Url+"&d=1")}),r.append(h)),f=u[i],f?(r.insertAfter(f),f.remove()):d.append(r);for(i=n.AssetAttachments.length;i<u.length;i++)u[i].remove()}else d.empty();if(n.InspectionAttachments&&n.InspectionAttachments.length>0){for(u=g.children("div"),i=0;i<n.InspectionAttachments.length;i++)t=n.InspectionAttachments[i],r=yt(t,!1,300),$.inArray(t.FileType.toLowerCase(),s)>=0&&(o=$('<span class="attaicon attaprint"><\/span>').attr("title",GetTextByKey("P_WO_PRINT","Print")).click(t,function(n){b(n.data.AttachmentType,n.data.AttachmentIdStr)}).css("right",30),r.append(o)),h=$('<span class="attaicon attadownload"><\/span>').attr("title",GetTextByKey("P_WO_DOWNLOAD","Download")).click(t,function(n){k(n.data.Url+"&d=1")}),r.append(h),f=u[i],f?(r.insertAfter(f),f.remove()):g.append(r);for(i=n.AssetAttachments.length;i<u.length;i++)u[i].remove()}else g.empty()}function yt(n,t,i){var r=$('<div class="divatt"><\/div>').attr("title",n.FileName),u,f,e;return t&&r.attr("title",n.Notes===""?n.FileName:n.Notes),n.FileType&&n.FileType!=""||(n.FileType=".jpg"),w.indexOf(n.FileType.toLowerCase())>=0?(u=n.ThumbnailUrl,i>0&&(u+="&size="+i),f=$('<img loading="lazy" class="picture"><\/img>').attr("src",u),f.click(n,function(n){window.open(n.data.Url,"_blank")}),r.append(f)):(e=$('<img loading="lazy" class="picture" />').click(n,function(n){window.open(n.data.Url)}),setAttachemntIcon(n.FileType,e),r.append(e)),r}function ti(n,i){var u={Key:"1",Value:i},r=JSON.stringify(u);r=htmlencode(r);worequest("UpdateWOAttachmentExtension",JSON.stringify([n,r]),function(r){if(r!=="OK"&&showAlert(r,GetTextByKey("P_WO_AVAILABLETOCUSTOMER","Available to Customer")),t&&t.WorkOrderAttachments)for(var u=0;u<t.WorkOrderAttachments.length;u++)if(t.WorkOrderAttachments[u].AttachmentId==n){t.WorkOrderAttachments[u].AvailableToCustomer=i;break}},function(){})}function bi(){var n=[],f,i,e,r;if(u)for(f=u.source||[],i=0;i<f.length;i++)e=f[i],n.push({Id:e.AttachmentIdStr,Visible:e.Selected});r=JSON.stringify(n);r=encodeURIComponent(r);worequest("UpdateWOAttachmentExtensionBatch",r,function(i){var e,r,u,f;if(i!=="OK"){showAlert(i,GetTextByKey("P_WO_AVAILABLETOCUSTOMER","Available to Customer"));return}if(vt(),l!=null&&(e=l.find('input[type="checkbox"]'),e.each(function(){var t=$(this).data("aid"),i;t!=null&&(i=n.find(function(n){return n.Id==t})?.Visible,this.checked=i)})),t&&t.WorkOrderAttachments)for(r=0;r<t.WorkOrderAttachments.length;r++)u=t.WorkOrderAttachments[r],f=n.find(function(n){return n.Id==u.AttachmentId}),f!=null&&(u.AvailableToCustomer=f.Visible)},function(){})}function ki(){var t,r,i,n;u=new GridView(lt);t=[{name:"Selected",caption:"",valueIndex:"Selected",type:3,css:{width:45,"text-align":"center"}},{name:"ThumbnailUrl",caption:"",valueIndex:"ThumbnailUrl",css:{width:42,"text-align":"center"}},{name:"FileName",caption:GetTextByKey("P_WO_NAME","Name"),valueIndex:"FileName",css:{width:280,"text-align":"left"}}];r=[];for(i in t)n={},t[i].type&&(n.type=t[i].type),n.name=t[i].name,n.caption=t[i].caption,n.visible=!0,n.sortable=!0,n.width=t[i].css.width,n.align=t[i].css["text-align"],n.key=t[i].valueIndex,r.push(n),n.name=="Selected"?(n.allcheck=!0,n.sortable=!1):n.name=="ThumbnailUrl"&&(n.type=ThumbnailUrlColumn,n.sortable=!1);u.multiSelect=!0;u.columns=r;u.init()}function pt(n){var f,r,o,h,e,i,c,l;if(t){for(f=at,f.data("loaded")||(f.data("loaded",!0),ki()),ft.css("display",n==0?"":"none"),et.css("display",n==1?"":"none"),ot.css("display",n==2?"":"none"),r=[],t.AssetAttachments&&t.AssetAttachments.length>0&&(r=r.concat(t.AssetAttachments)),t.WorkOrderAttachments&&t.WorkOrderAttachments.length>0&&(r=r.concat(t.WorkOrderAttachments)),t.InspectionAttachments&&t.InspectionAttachments.length>0&&(r=r.concat(t.InspectionAttachments)),o=0,h=[],e=0;e<r.length;e++)(i=r[e],i.FileType.toLowerCase()!="url")&&(c=n==2?i.AttachmentType==2:n==1||$.inArray(i.FileType.toLowerCase(),s)>=0,c&&(l={FileName:i.Notes===""?i.FileName:i.Notes,FileType:i.FileType,Url:i.Url,ThumbnailUrl:i.ThumbnailUrl,AttachmentType:i.AttachmentType,AttachmentIdStr:i.AttachmentIdStr,Selected:n==2&&i.AvailableToCustomer},h.push(l),o++));f.find(".dialog-title span.title").text(GetTextByKey("P_WO_ATTACHMENTS","Attachments")+" ("+o+")");showmaskbg(!0);f.css({top:(document.documentElement.clientHeight-f.height())/3,left:(document.documentElement.clientWidth-f.width())/2}).showDialogfixed();setTimeout(function(){u.setData(h);u.clearHeaderCheckbox()})}}function ii(){var r=[],t,n,i;if(u)for(t=u.source||[],n=0;n<t.length;n++)i=t[n],i.Selected&&r.push(i);return r}function di(){var n=ii(),t,i;if(n&&n.length!=0){if(n&&n.length>0)for(t=0;t<n.length;t++)i=n[t],$.inArray(i.FileType.toLowerCase(),s)>=0&&b(i.AttachmentType,i.AttachmentIdStr);vt()}}function b(n,t){var i=$("<iframe style='display:none;'><\/iframe>");$(document.body).after(i);i.attr("src",_network.root+"Print.aspx?pt=3&at="+n+"&id="+t);i.on("load",function(){setTimeout(function(){i.contents().find("body").css("text-align","center");i.contents().find("img").css("max-height","98%").css("max-width","98%");i[0].contentWindow.print()});setTimeout(function(){i.remove()},6e4)})}function gi(){var n=ii(),t,i;if(n&&n.length!=0){if(n&&n.length>0)for(t=0;t<n.length;t++)i=n[t],k(i.Url+"&d=1");vt()}}function k(n){var t=$("<iframe style='display:none;'><\/iframe>"),i;$(document.body).after(t);t.attr("src",n);worequest("RecordDownloadLog",JSON.stringify([n]),function(){},function(){});i=setInterval(function(){t[0].contentDocument&&(t[0].contentDocument.readyState=="complete"||t[0].contentDocument.readyState==4)&&(t.remove(),clearInterval(i))},5e3)}function ri(n){var f=n.AttachmentId,r=n.iptcaption.val(),u=n.iptcaption.data("attdata"),i;if(u.Notes=r,t&&t.WorkOrderAttachments)for(i=0;i<t.WorkOrderAttachments.length;i++)if(t.WorkOrderAttachments[i].AttachmentId==u.AttachmentId){t.WorkOrderAttachments[i]=u;break}worequest("UpdateWorkOrderAttachmentCaption",JSON.stringify([f,htmlencode(r)]),function(t){t!=="OK"?showAlert(t,GetTextByKey("P_WO_UPDATECAPTION","Update Caption")):(n.div&&n.div.attr("title",r),n.iptcaption.data("caption",r))},function(){})}function nr(n){var u,f,r,i,t;if(n.WorkOrderAttachments&&n.WorkOrderAttachments.length>0){for(i=nt.children("tr"),t=0;t<n.WorkOrderAttachments.length;t++){var u=n.WorkOrderAttachments[t],f=tr(u),r=i[t];r?(f.insertAfter(r),r.remove()):nt.append(f)}for(t=n.WorkOrderAttachments.length;t<i.length;t++)i[t].remove()}else nt.empty();if(n.AssetAttachments&&n.AssetAttachments.length>0){for(i=tt.children("tr"),t=0;t<n.AssetAttachments.length;t++)u=n.AssetAttachments[t],w.indexOf(u.FileType.toLowerCase())>=0&&(u.ThumbnailUrl=u.Url+"&thumb=1"),f=ui(u,60),r=i[t],r?(f.insertAfter(r),r.remove()):tt.append(f);for(t=n.AssetAttachments.length;t<i.length;t++)i[t].remove()}else tt.empty();if(n.InspectionAttachments&&n.InspectionAttachments.length>0){for(i=it.children("tr"),t=0;t<n.InspectionAttachments.length;t++){var u=n.InspectionAttachments[t],f=ui(u,60),r=i[t];r?(f.insertAfter(r),r.remove()):it.append(f)}for(t=n.InspectionAttachments.length;t<i.length;t++)i[t].remove()}else it.empty()}function tr(n){var r=n.Notes===""?n.FileName:n.Notes,u=$('<tr class="tr-attachment-flex-line"><\/tr>').attr("data-id",n.AttachmentId),t,f,e,o,i,h,c,l,a,v;return u.append('<td style="width:30px;"><\/td>'),t=$('<td style="width:60px;"><\/td>'),n.FileType&&n.FileType!=""||(n.FileType=".jpg"),f=$('<div style="width:60px;height:60px;text-align:center;"><\/div>'),t.append(f),w.indexOf(n.FileType.toLowerCase())>=0?(e=$('<img loading="lazy" class="wolist_picture"><\/img>').attr("src",n.ThumbnailUrl),e.click(n,function(n){window.open(n.data.Url,"_blank")}),f.append(e)):(o=$('<img loading="lazy" class="wolist_picture" />').click(n,function(n){window.open(n.data.Url)}),setAttachemntIcon(n.FileType,o),f.append(o)),u.append(t),t=$('<td class="attachment-caption"><\/td>'),i=$('<input type="text" class="inp_name" maxlength="200" style="height:24px;"/>').css("width","100%").attr("data-ori",r).val(r),i.data("attdata",n),r&&r!=""||i.attr("placeholder","Click to Add caption"),t.append(i),i.focus({AttachmentId:n.AttachmentId,iptcaption:i},function(n){n.data.iptcaption.addClass("focused")}),i.blur({AttachmentId:n.AttachmentId,iptcaption:i,caption:r},function(n){n.data.iptcaption.removeClass("focused");ri(n.data)}),i.keydown({AttachmentId:n.AttachmentId,iptcaption:i,caption:r},function(n){(n.keyCode==13||n.keyCode==9)&&n.data.iptcaption.blur()}),u.append(t),t=$('<td style="width:70px;"><\/td>'),AllowCustomer&&(h=$('<input type="checkbox" class="inp_recurring"/>').attr("data-ori",n.AvailableToCustomer).prop("checked",n.AvailableToCustomer),t.append(h),h.click(n,function(n){ti(n.data.AttachmentId,$(this).prop("checked"))})),u.append(t),t=$('<td class="td_funcs" style="width: 132px;text-align:right;"><\/td>'),c=$('<span class="wolist_icon wolist_delete"><\/span>').attr("title",GetTextByKey("P_WO_DELETE","Delete")).click(n,function(n){dt(n.data.AttachmentId,$(n.target))}),t.append(c),l=$('<span class="wolist_icon wolist_attasend"><\/span>').attr("title",GetTextByKey("P_WO_SEND","Send")).click(n,function(n){kt(n.data)}),t.append(l),a=$('<span class="wolist_icon wolist_attadownload"><\/span>').attr("title",GetTextByKey("P_WO_DOWNLOAD","Download")).click(n,function(n){k(n.data.Url+"&d=1")}),t.append(a),$.inArray(n.FileType.toLowerCase(),s)>=0&&(v=$('<span class="wolist_icon wolist_attaprint"><\/span>').attr("title",GetTextByKey("P_WO_PRINT","Print")).click(n,function(n){b(n.data.AttachmentType,n.data.AttachmentIdStr)}),t.append(v)),u.append(t),u}function ui(n,t){var r=$('<tr class="tr-attachment-flex-line"><\/tr>').attr("data-id",n.AttachmentId),i,u,f,e,o,h,c;return r.append('<td style="width:30px;"><\/td>'),i=$('<td style="width:60px;"><\/td>'),n.FileType&&n.FileType!=""||(n.FileType=".jpg"),u=$('<div style="width:60px;height:60px;text-align:center;"><\/div>'),i.append(u),w.indexOf(n.FileType.toLowerCase())>=0?(f=n.ThumbnailUrl,t>0&&(f+="&size="+t),e=$('<img loading="lazy" class="wolist_picture"><\/img>').attr("src",f),e.click(n,function(n){window.open(n.data.Url,"_blank")}),u.append(e)):(o=$('<img loading="lazy" class="wolist_picture" />').click(n,function(n){window.open(n.data.Url)}),setAttachemntIcon(n.FileType,o),u.append(o)),r.append(i),i=$('<td class="attachment-caption"><\/td>').text(n.FileName),r.append(i),i=$('<td class="td_funcs" style="width: 132px;text-align:right;"><\/td>'),n.FileType.toLowerCase()!="url"&&(h=$('<span class="wolist_icon wolist_attadownload"><\/span>').attr("title",GetTextByKey("P_WO_DOWNLOAD","Download")).click(n,function(n){k(n.data.Url+"&d=1")}),i.append(h)),$.inArray(n.FileType.toLowerCase(),s)>=0&&(c=$('<span class="wolist_icon wolist_attaprint"><\/span>').attr("title",GetTextByKey("P_WO_PRINT","Print")).click(n,function(n){b(n.data.AttachmentType,n.data.AttachmentIdStr)}),i.append(c)),r.append(i),r}function ir(n){var n=n,h,f,o,t,s,r,c,l,a,e,b;if(!n||n.trim()==""){showAlert(GetTextByKey("P_WO_PLEASEINPUTTHEPHONENUMBEROREMAL","Please input the phone number or email."),GetTextByKey("P_WO_ERROR","Error"));return}for(h=n.split(";"),f=[],o=0;o<h.length;o++)if(t=h[o],checkPhoneNumber(t)||isEmail(t))f.push({Key:t,Value:t});else if(i.option.customercontacts)for(s=0;s<i.option.customercontacts.length;s++)if((r=i.option.customercontacts[s],!r.OptOut&&!r.OptOut_BC)&&(c=$.trim(r.MobilePhone),l=$.trim(r.Email),r.Name===t)){if(r.ContactPreference=="0"&&checkPhoneNumber(c)){f.push({Key:c,Value:t});break}if(r.ContactPreference=="1"&&isEmail(l)){f.push({Key:l,Value:t});break}}if(a=$("#dialog_atta_textmsg").val(),$.trim(a)==""){showAlert(GetTextByKey("P_WO_PLEASEINPUTTHEMESSAGE","Please input the message."),GetTextByKey("P_WO_ERROR","Error"));return}$("#dialogattmask").show();$("#dialogattmask").css("z-index",1e3);var k=$("#dialog_atta_chkIncludeStatusLink").prop("checked"),y="AddWorkOrder.aspx",p="AddWorkOrderCommunication",u=new FormData;u.append("MethodName",p);u.append("WorkorderId",i.option.workorderid);u.append("PMEmails",JSON.stringify(f));u.append("Comment",encodeURIComponent(a));u.append("IncludeStatusLink",k?"1":"0");e=v.data("atta");b={AttaType:"2",Id:e.AttachmentId,Filename:e.FileName,Caption:e.Notes};u.append("AttaData",encodeURIComponent(JSON.stringify(b)));w.indexOf(e.FileType.toLowerCase())<0&&u.append("IsAttachment","1");$.ajax({url:y,type:"POST",dataType:"json",processData:!1,contentType:!1,cache:!1,data:u,success:function(n){if($("#dialogattmask").hide(),$("#dialogattmask").css("z-index","unset"),n!==""){showAlert(n,GetTextByKey("P_WO_ERROR","Error"));return}bt()},error:function(n,t,i){$("#dialogattmask").hide();$("#dialogattmask").css("z-index","unset");n?.readyState==0?console.log(n):writelog_ironintel("onAddMessage",y+".-1."+p+"."+JSON.stringify(param),JSON.stringify(n),t+i)}})}function fi(n){n.preventDefault();n.dataTransfer.dropEffect="link"}function ei(n){var i,r,u,t,f;if(n.preventDefault(),n.stopPropagation(),i=n.dataTransfer,r=[],i.items!==undefined)for(u=0;u<i.items.length;u++)t=i.items[u],t.kind==="file"&&(t.webkitGetAsEntry()==null||t.webkitGetAsEntry().isFile)&&(f=t.getAsFile(),r.push(f));r.length>0&&ht(r)}function oi(n){var i,r,u,t,f;if(n.stopPropagation(),i=n.clipboardData,r=[],i.items!==undefined)for(u=0;u<i.items.length;u++)t=i.items[u],t.kind==="file"&&(t.webkitGetAsEntry()==null||t.webkitGetAsEntry().isFile)&&(f=t.getAsFile(),r.push(f));r.length>0&&ht(r)}var i,t,h,c,l,d,g,a,nt,tt,it,lt,ft,et,ot,st,e,ut,w,s,u;this.option=n||{};i=this;h=0;h=getCookie("woattachmentviewtype");this.refresh=function(){ct(!0)};this.changewo=function(n,i){var r=t&&this.option.workorderid===n&&this.option.machineid===i;this.option.workorderid=n;i&&(this.option.machineid=i);ct(r)};this.close=function(){at?.remove();rt?.remove();v?.remove()};this.updatecontact=function(n){var i,r,t,u,f;if(this.option.customercontacts=n,this.option.customercontacts){for(i="",r=0;r<this.option.customercontacts.length;r++)(t=this.option.customercontacts[r],t.OptOut||t.OptOut_BC)||(u=$.trim(t.MobilePhone),f=$.trim(t.Email),(t.ContactPreference=="0"&&checkPhoneNumber(u)||t.ContactPreference=="1"&&isEmail(f))&&(i==""?i=t.Name:i+=";"+t.Name));$("#dialog_atta_phonenum").val(i)}else $("#dialog_atta_phonenum").val("")};this.createAttachment=function(n){var u=$('<div class="function_title" style="min-width:470px; white-space:nowrap"><\/div>'),ht,ct,lt,at,k,vt,yt,y,rt,wt,bt,p,ut,ft,f,e,w,o,s,t,kt,et,h,i,dt,r,v,ot,ni,ti,b;n.append(u);ht=$('<span class="sbutton iconadd" data-lgid="P_WO_ADDFILE">Add File<\/span>');ht.click(pi);u.append(ht);this.option.canExport&&(ct=$('<span class="sbutton iconprint" data-lgid="P_WO_PRINT">Print<\/span>'),ct.click(function(){pt(0)}),u.append(ct),lt=$('<span class="sbutton icondownload" data-lgid="P_WO_DOWNLOAD">Download<\/span>'),lt.click(function(){pt(1)}),u.append(lt));AllowCustomer&&(at=$('<span class="sbutton iconaccess" data-lgid="P_WO_CUSTOMERACCESS">Customer Access<\/span>'),at.click(function(){pt(2)}),u.append(at));k=$('<div style="display:inline-block;position: relative;"><\/div>');u.append(k);vt=$('<span class="sbutton iconviewatt" data-lgid="P_WO_VIEW">View<\/span>');k.append(vt);vt.click(function(){if(!$(".panel_holder.attviewtypemenus").is(":visible")){hidePanels();var n=$(this).offset().left,t=$(this).offset().top;return $(".panel_holder.attviewtypemenus").css({opacity:0,left:-35,right:"auto",top:27}).show().animate({opacity:1},100),$(".panel_holder.attviewtypemenus .trigledown").css({left:50,right:"auto",top:-20}),!1}});yt=$('<div class="panel_holder attviewtypemenus"><\/div>');k.append(yt);y=$('<div class="panel" style="min-width: 150px; background-color: white;"><\/div>');yt.append(y);rt=$('<ul class="lefttitlemenu_ul" style="line-height: 32px;"><\/ul>');y.append(rt);wt=$('<li><a style="padding-left: 0;"><span class="sbutton iconlarge" data-lgid="P_WO_LARGE">Large<\/span><\/a><\/li>');wt.click(function(){gt(0)});rt.append(wt);bt=$('<li> <a style="padding-left: 0;"><span class="sbutton iconlist" data-lgid="P_WO_LIST">List<\/span><\/a><\/li>');bt.click(function(){gt(1)});rt.append(bt);y.append('<div class="trigledown"><\/div>');y.append('<div class="trigledown white"><\/div>');c=$("<div><\/div>");n.append(c);p=$('<table class="main_table maintenance" ><\/table>');p.on("drop",function(n){ei(n.originalEvent)}).on("dragover",function(n){fi(n.originalEvent)}).on("paste",function(n){oi(n.originalEvent)});c.append(p);p.append('<tr style="line-height: 35px;"><td class="subtitle"><span class="sbutton iconchevrondown woattafoldicon" target="woaatts_tr" onclick="OnExpendInTab(this)" style="margin-left: 0; padding-right: 5px;"><\/span><span data-lgid="P_WO_WORKORDERATTACHMENTS">Work Order Attachments<\/span><\/td><\/tr>');f=$('<tr id="woaatts_tr" class="tr_intervals woattafoldtr"><\/tr>').appendTo(p);e=$("<td><\/td>").appendTo(f);l=$('<div style="min-height: 80px; overflow: auto; padding-left: 20px;"><\/div>').appendTo(e);ut=$('<table class="main_table maintenance"><\/table>');c.append(ut);ut.append('<tr style="line-height: 35px;"><td class="subtitle"><span class="sbutton iconchevrondown woattafoldicon" target="woassetatts_tr" onclick="OnExpendInTab(this)" style="margin-left: 0; padding-right: 5px;"><\/span><span data-lgid="P_WO_ASSETATTACHMENTS">Asset Attachments<\/span><\/td><\/tr>');f=$('<tr id="woassetatts_tr" class="tr_intervals woattafoldtr"><\/tr>').appendTo(ut);e=$("<td><\/td>").appendTo(f);d=$('<div style="min-height: 80px; overflow: auto; padding-left: 20px;"><\/div>').appendTo(e);ft=$('<table class="main_table maintenance"><\/table>');c.append(ft);ft.append('<tr style="line-height: 35px;"><td class="subtitle"><span class="sbutton iconchevrondown woattafoldicon" target="woiptatts_tr" onclick="OnExpendInTab(this)" style="margin-left: 0; padding-right: 5px;"><\/span><span data-lgid="P_WO_INSPECTIONATTACHMENTS">Inspection Attachments<\/span><\/td><\/tr>');f=$('<tr id="woiptatts_tr" class="tr_intervals woattafoldtr"><\/tr>').appendTo(ft);e=$("<td><\/td>").appendTo(f);g=$('<div style="min-height: 80px; overflow: auto; padding-left: 20px;"><\/div>').appendTo(e);a=$('<div style="display: none;"><\/div>');n.append(a);w=$('<table class="main_table maintenance"><\/table>');w.on("drop",function(n){ei(n.originalEvent)}).on("dragover",function(n){fi(n.originalEvent)}).on("paste",function(n){oi(n.originalEvent)});a.append(w);o=$('<tr style="line-height: 35px;"><\/tr>');w.append(o);s=$('<td class="subtitle"><\/td>');o.append(s);t=$('<div style="display:flex;align-items:center;max-width:835px"><\/div>');s.append(t);t.append('<span class="sbutton iconchevrondown woattafoldicon" target="woattslist_tr" onclick="OnExpendInTab(this)" style="margin-left: 0; padding-right: 5px;"><\/span>');t.append('<span data-lgid="P_WO_WORKORDERATTACHMENTS" style="flex:1 1 auto">Work Order Attachments<\/span>');AllowCustomer?t.append('<span data-lgid="P_WO_AVAILABLETOCUSTOMER" style="width: 240px; color: #333; font-size: 13px">Available to Customer<\/span>'):t.append('<span style="width: 240px; color: #333; font-size: 13px"><\/span>');t.append('<lable class="lable_attuploadname" style="margin-left: 200px;"><\/lable>');o=$('<tr id="woattslist_tr" class="tr_intervals woattafoldtr"><\/tr>');w.append(o);s=$("<td><\/td>");o.append(s);kt=$('<table class="table_intervals"><\/table>');s.append(kt);nt=$("<tbody><\/tbody>").appendTo(kt);et=$('<table class="main_table maintenance"><\/table>');a.append(et);h=$('<tr style="line-height: 35px;"><\/tr>');et.append(h);i=$('<td class="subtitle"><\/td>');h.append(i);i.append('<span class="sbutton iconchevrondown woattafoldicon" target="woassetattslist_tr" onclick="OnExpendInTab(this)" style="margin-left: 0; padding-right: 5px;"><\/span>');i.append('<span data-lgid="P_WO_ASSETATTACHMENTS">Asset Attachments<\/span>');h=$('<tr id="woassetattslist_tr" class="tr_intervals woattafoldtr"><\/tr>');et.append(h);i=$("<td><\/td>");h.append(i);dt=$('<table class="table_intervals"><\/table>');i.append(dt);tt=$("<tbody><\/tbody>").appendTo(dt);r=$('<table class="main_table maintenance"><\/table>');a.append(r);v=$('<tr style="line-height: 35px;"><\/tr>');r.append(v);ot=$('<td class="subtitle"><\/td>');v.append(ot);ot.append('<span class="sbutton iconchevrondown woattafoldicon" target="woiptattslist_tr" onclick="OnExpendInTab(this)" style="margin-left: 0; padding-right: 5px;"><\/span>');ot.append('<span data-lgid="P_WO_INSPECTIONATTACHMENTS">Inspection Attachments<\/span>');v=$('<tr id="woiptattslist_tr" class="tr_intervals woattafoldtr"><\/tr>');r.append(v);r=$("<td><\/td>");v.append(r);ni=$('<table class="table_intervals"><\/table>');r.append(ni);it=$("<tbody><\/tbody>").appendTo(ni);ti=$('<div class="panel_holder attuoloadmsgmenus"><\/div>');n.append(ti);b=$('<div class="panel" style="min-width: 150px; background-color: white; max-width: 480px; max-height: 400px;"><\/div>');ti.append(b);st=$('<ul class="lefttitlemenu_ul"><\/ul>');b.append(st);b.append('<div class="trigledown"><\/div>');b.append('<div class="trigledown white"><\/div>');n.applyFleetLanguageText(!0)};this.createAttachment(this.option.parent);var at=yi(),rt=si(),v=hi();var r=[],o=-1,y="";ut=!1;w=[".jfif",".jpg",".jpeg",".bmp",".png",".tiff",".gif"];s=[".pdf",".jfif",".jpg",".jpeg",".bmp",".png",".tiff",".gif"]});typeof $wocommunication!="function"&&($wocommunication=function(n){var t=this,u,r,f,i;this.customercontacts=[];this.followers=[];this.changewo=function(t,i,r){n.workorderid=t;i&&(n.machineid=i);r&&(n.wo=r);this.updatecontact([]);this.followers=[];this.customer.followers=[];this.getWorkOrderFollowers(t);this.getCommunications(!0);var u=this.customer;u&&n.wo&&(u.companyName=n.wo.CustomerName,u.companyCode=n.wo.CustomerCode,u.setData("companyCode",n.wo.CustomerCode),u.autoUpdates=n.wo.AutoText?.Value)};this.updatecontact=function(n){this.customercontacts=n;this.showCustomerContacts(this.customercontacts)};this.close=function(){};this.resetCommunications=function(){var n=t.customer;typeof n!="undefined"&&(n.text="",n.load())};u=!1;r=0;this.getCommunications=function(i){if(i&&t.resetCommunications(),u){r++;return}(u=!0,n.workorderid&&n.workorderid!="")&&(n.showloading(!0),worequest("GetCommunications",n.workorderid,function(f){(u=!1,n.showloading(!1),typeof f!="string")&&(t.customer?.load(f,t.customercontacts,t.followers),r>0&&(r=0,t.getCommunications(i)))},function(){u=!1;r>0&&(r=0,t.getCommunications(i));n.showloading(!1)}))};this.showCustomerContacts=function(n){var t=this.customer;t!=null&&(t.contacts=n)};this.getCustomerContacts=function(n,i){worequest("GetCustomerContacts",n,function(n){if(typeof n=="string"){showAlert(n,GetTextByKey("P_CUSTOMERRECORD","Customer Record"));i&&i([]);return}if(i){i(n);return}t.showCustomerContacts(n);t.SaveWorkorderContact()},function(){})};this.SaveWorkorderContact=function(i,r){var e=n.workorderid,u,f;e&&e!=""&&(u=n.wo.CustomerId,u||(u=-1),f=JSON.stringify([e,u,JSON.stringify(i??t.customercontacts)]),f=htmlencode(f),worequest("SaveWorkOrderContact",f,function(n){if(typeof r=="function"){r(n);return}if(typeof n=="string"){showAlert(n,GetTextByKey("P_WO_ERROR","Error"));return}},function(){}))};this.SaveWorkOrderFollower=function(i){var u=n.workorderid,r;u&&u!=""&&(r=JSON.stringify([u,JSON.stringify(t.followers)]),r=htmlencode(r),worequest("SaveWorkOrderFollower",r,function(n){if(typeof i=="function")i(n);else if(n!=="OK"){showAlert(n,GetTextByKey("P_WO_ERROR","Error"));return}},function(){}))};this.getWorkOrderFollowers=function(n){worequest("GetWorkOrderFollowers",n,function(n){if(typeof n=="string"){showAlert(n,GetTextByKey("P_CUSTOMERRECORD","Customer Record"));return}t.followers=n;t.customer.followers=t.followers},function(){})};f=!1;i=[];this.getAllFollowers=function(n){worequest("GetAllFollowers","",function(r){if(typeof n=="function")n(r);else{if(typeof r=="string"){showAlert(r,GetTextByKey("P_CUSTOMERRECORD","Customer Record"));return}f=!0;i=r;t.customer.setData("allfollowers",r)}},function(){})};window.customer=this.customer=new window["lib-app"].CustomerCommunication({getText:GetTextByKey,autoUpdates:!1,readonly:WOReadOnly||COMMReadOnly,recordReadonly:!AllowCustomer||WOReadOnly||CRReadOnly,contactCollapsed:spliterProps.contactCollapsed,onMasking:window.parent.onmaskbg,onContactCollapsed:function(n){spliterProps.contactCollapsed=n;localStorage.setItem("spliter_props",JSON.stringify(spliterProps))},onStatusLinkChanged:function(n){this.freeze=!0;var t=document.querySelector("#iframeworkorder").contentWindow?.customer;t!=null&&(t.statusLink=n);this.freeze=!1},onAddMessage:function(){var i=t.customer,u=i?.contacts,f,o,e;if(u==null||u.length===0){i.loading=!1;showAlert(GetTextByKey("P_WO_PLEASEINPUTTHEPHONENUMBEROREMAL","Please input the phone number or email."),GetTextByKey("P_WO_ERROR","Error"));return}if(f=i?.text,$.trim(f)==""){i.loading=!1;showAlert(GetTextByKey("P_WO_PLEASEINPUTTHEMESSAGE","Please input the message."),GetTextByKey("P_WO_ERROR","Error"));return}o=i?.statusLink;n.showloading(!0);var s="Maintenance/WorkOrderMaintenance.aspx",h="AddWorkOrderCommunication",r=new FormData;r.append("MethodName",h);r.append("WorkorderId",n.workorderid);r.append("PMEmails",JSON.stringify(u));r.append("Comment",encodeURIComponent(f));r.append("IncludeStatusLink",o?"1":"0");e=i?.file;e!=null&&r.append("Attachment",e);$.ajax({url:_network.root+s,type:"POST",dataType:"json",processData:!1,contentType:!1,cache:!1,data:r,success:function(t){if(n.showloading(!1),i.loading=!1,t!==""){showAlert(t,GetTextByKey("P_WO_ERROR","Error"));return}i.text="";i.file=null},error:function(t,r,u){n.showloading(!1);i.loading=!1;t?.readyState==0?console.log(t):writelog_ironintel("onAddMessage",s+".-1."+h+"."+JSON.stringify(param),JSON.stringify(t),r+u)}})},onUpdateMessageStatus:function(n){n?.length>0&&worequest("UpdateMessageStatus",JSON.stringify(n),function(n){if(n!=="OK"){ui.showAlert(GetTextByKey("P_WO_ERROR","Error"),n,"error");return}t.getCommunications()})},onMessageStatusClicked:function(n){worequest("GetMessageStatusHistory",String(n.Id),function(n){if(typeof n=="string"){ui.showAlert(GetTextByKey("P_WO_ERROR","Error"),n,"error");return}if(n.length>0){var t=n.map(function(n){return getMessageStatusHistoryText(n)}).join("\n\n");ui.showAlert(n[0].CustomerNumberFormatted,t)}})},onSave:function(n,i){var u,r;i||(u=t.customercontacts.filter(function(t){return t.Id<0?t.Name===n.OldName&&t.MobilePhone===n.OldMobilePhone:t.Id===n.Id})[0]);r=[];for(let i of t.customercontacts)if(i===u){let t={...u,Name:n.Name,ContactPreference:n.ContactPreference,Email:n.Email,MobilePhone:n.MobilePhone,OptOut:n.OptOut,Notes:n.Notes,SaveToCustomer:n.SaveToCustomer};parseInt(t.ContactPreference)==0?t.ContactPreferenceStr=GetTextByKey("P_CR_TEXT","Text"):parseInt(t.ContactPreference)==1?t.ContactPreferenceStr=GetTextByKey("P_CR_EMAIL","Email"):parseInt(t.ContactPreference)==2&&(t.ContactPreferenceStr=GetTextByKey("P_CR_PHONE","Phone"));r.push(t)}else r.push(i);return i&&(n.Id=-1,r.push(n)),new Promise(function(n,i){t.SaveWorkorderContact(r,function(r){if(typeof r=="string")ui.showAlert(GetTextByKey("P_WO_ERROR","Error"),r,"error"),i();else{for(let n of r){const i=t.customercontacts.find(function(t){return t.Id<0?t.Name===n.Name&&t.MobilePhone===n.MobilePhone:t.Id===n.Id});n.selected=i!=null?i.selected:!0}t.showCustomerContacts(t.customercontacts=r);n(r)}})})},onDelete:function(n,i,r){var f,u=t.customercontacts;f=r?u.findIndex(function(n){return n.Id===i.Id}):u.findIndex(function(n){return n.Name===i.Name&&n.MobilePhone===i.MobilePhone});f>=0&&(u.splice(f,1),t.SaveWorkorderContact(),t.showCustomerContacts(u),r&&_network.request("Maintenance/AddCustomerRecord.aspx",-1,"DeleteContact",i.Id,function(){},function(n){console.log(n);ui.showAlert(GetTextByKey("P_WO_ERROR","Error"),GetTextByKey("P_UM_PAGEERROR","An unknown error occurred. Please refresh page."),"error")}))},onChanged:function(n){t.customer.contacts=n},onDeleteFollower:function(n,i){var r=t.followers,u=r.findIndex(function(n){return n.UserIID===i.UserIID});u<0||(r.splice(u,1),t.SaveWorkOrderFollower(),t.customer.followers=r)},onChangeFollower:function(n,i,r,u){var f=t.followers.find(function(n){return n.UserIID===i.UserIID});f!=null&&(f.SendText=r,f.SendEmail=u,t.SaveWorkOrderFollower(),t.customer.followers=followers)},onInitFollower:function(n){if(f&&i?.length>0){for(let t of i)if(t.Email=!1,t.Text=!1,n){var r=n.find(function(n){return n.UserIID.toLowerCase()===t.IID.toLowerCase()});r&&(t.Email=r.SendEmail,t.Text=r.SendText)}return Promise.resolve(i)}return new Promise(function(r){t.getAllFollowers(function(t){Array.isArray(t)&&(f=!0,i=t);for(let t of i)if(t.Email=!1,t.Text=!1,n){var u=n.find(function(n){return n.UserIID.toLowerCase()===t.IID.toLowerCase()});u&&(t.Email=u.SendEmail,t.Text=u.SendText)}r(t)})})},onAddFollower:function(n){var i=t.followers=[];for(let t of n){let n={Id:-1,UserIID:t.IID,Name:t.DisplayName,Email:t.ID,MobilePhone:t.Mobile,SendEmail:t.Email,SendText:t.Text};i.push(n)}return new Promise(function(n,r){t.SaveWorkOrderFollower(function(t){t!=="OK"?(ui.showAlert(GetTextByKey("P_WO_ERROR","Error"),t,"error"),r()):n(i)})})},onOpenSelectCRContacts:function(){return new Promise(function(i){var r=n.wo.CustomerId;if(!r||r===""){setTimeout(function(){i([])},0);return}t.getCustomerContacts(r,function(n){i(n)})})},onSelectCRContacts:function(n){var e,i,u,f;if(t.customercontacts){for(e=[],i=0;i<t.customercontacts.length;i++)t.customercontacts[i].Id>0||e.push(t.customercontacts[i]);t.customercontacts=e}for(i=0;i<n.length;i++){var s=n[i],r={...s},o=!1;if(t.customercontacts)for(u=0;u<t.customercontacts.length;u++)if(f=t.customercontacts[u],f.Name===r.Name&&f.MobilePhone===r.MobilePhone){f.Id=r.Id;o=!0;break}o||t.customercontacts.push(r)}t.showCustomerContacts(t.customercontacts);t.SaveWorkorderContact()}});n.parent.append(this.customer.create())});typeof $wointernal!="function"&&($wointernal=function(n){var t=this;this.changewo=function(t,i){n.workorderid=t;i&&(n.machineid=i);this.getComments(!0)};this.close=function(){};this.updatecontact=function(n){var t=this.internal;t!=null&&(t.contacts=n)};this.resetComments=function(){var n=this.internal;n!=null&&(n.text="",n.load())};this.getComments=function(i){n.showloading(!0);i&&this.resetComments();var r=n.workorderid;r&&r!=""&&worequest("GetComments",r,function(i){(n.showloading(!1),typeof i!="string")&&($("#li_comments").data("loaded",!0),t.internal?.load(i))},function(){n.showloading(!1)})};window.internal=this.internal=new window["lib-app"].InternalComment({getText:GetTextByKey,readonly:WOReadOnly,onAddMessage:openSendICEmail,onAddComment:function(i){var u;if($.trim(i)!=""){n.showloading(!0);var r=new FormData;r.append("MethodName","SendInternalComments");r.append("WorkorderId",workorderid);r.append("Comment",encodeURIComponent(i));u=internal?.file;u!=null&&r.append("Attachment",u);$.ajax({url:_network.root+"Maintenance/AddWorkOrder.aspx",type:"POST",dataType:"json",processData:!1,contentType:!1,cache:!1,data:r,success:function(i){if(n.showloading(!1),t.internal.loading=!1,i!==""){showAlert(i,GetTextByKey("P_WO_ERROR","Error"));return}t.internal.text="";t.internal.file=null;$("#commentsinputcount").text("0/"+$("#dialog_comments").attr("maxlength"))},error:function(){t.internal.loading=!1;n.showloading(!1)}})}},onUpdateMessageStatus:function(n){n?.length>0&&worequest("UpdateMessageStatus",JSON.stringify(n),function(n){if(n!=="OK"){ui.showAlert(GetTextByKey("P_WO_ERROR","Error"),n,"error");return}t.getComments()})},onMessageStatusClicked:function(n){worequest("GetMessageStatusHistory",String(n.Id),function(n){if(typeof n=="string"){ui.showAlert(GetTextByKey("P_WO_ERROR","Error"),n,"error");return}if(n.length>0){var t=n.map(function(n){return getMessageStatusHistoryText(n)}).join("\n\n");ui.showAlert(n[0].CustomerNumberFormatted,t)}})}});n.parent.append(this.internal.create())});typeof $wocrcomment!="function"&&($wocrcomment=function(n){var t=this;this.changewo=function(t,i,r){r&&(n.customerid=r.CustomerId);this.getComments(!0)};this.close=function(){};this.resetComments=function(){var n=this.comment;n!=null&&(n.text="",n.load())};this.getComments=function(i){n.showloading(!0);i&&this.resetComments();var r=n.customerid;if(isNaN(r)||r<=0){n.showloading(!1);t.comment!=null&&(t.comment.load(),t.comment.readonly=!0);return}crrequest("GetCustomerComments",r,function(i){(n.showloading(!1),typeof i!="string")&&($("#li_comments").data("loaded",!0),t.comment!=null&&(t.comment.load(i),t.comment.readonly=CRReadOnly))},function(){n.showloading(!1)})};window.customerComment=this.comment=new window["lib-app"].CustomerRecordComment({getText:GetTextByKey,readonly:CRReadOnly,onAddComment:function(i){if($.trim(i)!=""){var r=JSON.stringify([n.customerid,!1,i]);r=htmlencode(r);n.showloading(!0);crrequest("SubmitComment",r,function(i){if(n.showloading(!1),i!==""){showAlert(i,GetTextByKey("P_FR_ERROR","Error"));return}t.comment.text="";$("#commentsinputcount").text("0/"+$("#dialog_comments").attr("maxlength"));setTimeout(function(){t.getComments()},400)},function(){n.showloading(!1)})}}});n.parent.append(this.comment.create())}); |