BemsWebApplication.ReportJob = function (params, viewInfo) { var visiblePopup = ko.observable(false); var change = false; var newReport; var seq = 0; var beforeReportFormatId; var beforeFormatName; var beforeSeq; var beforeDateTime; var editor; var rowClick = false; var contentsUnit = 10000; var filePath = "/App_Data/files/report2/"; var popupInit = false; var SiteId = BWA.UserInfo.SiteId(); //권한설정 var hasnotModificationPermission = ko.observable(true); var endpointSelector = ""; if (BemsWebApplication.config.mode == "production") { endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.production; } else { endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.local; } var tempcontent = ""; function getFormatData() { var dataSource = new DevExpress.data.DataSource({ store: { type: "odata", url: endpointSelector + "/BemsReportFormat", }, requireTotalCount: true, pageSize: 1000 }); dataSource.filter([ ["parts", "=", 0] ]); dataSource.sort({ getter: "FormatName", asc: true }); dataSource.load() .done(function (result) { $("#formatSelect").dxSelectBox("instance").option('dataSource', result); $("#formatSelect").dxSelectBox("instance").option('displayExpr', 'FormatName'); $("#formatSelect").dxSelectBox("instance").option('valueExpr', "ReportFormatId"); }) .fail(function (error) { utils.toast.show(error); }); } function getFormatContent() { rowClick = false; var dataSource = new DevExpress.data.DataSource({ store: { type: "odata", url: endpointSelector + "/BemsReportFormat", }, requireTotalCount: true, pageSize: 1000 }); dataSource.filter([ ["ReportFormatId", "=", $("#formatSelect").dxSelectBox("instance").option('value')] ]); dataSource.load() .done(function (result) { var content = ""; for (var i = 0; i < result.length; i++) { content = content + result[i].Content; } editor.doCmd('NewDocument', '1'); if (result.length > 0) { editor.insertContents(content); } else { editor.insertContents(""); } }) .fail(function (error) { utils.toast.show(error); }); } function saveReport() { $("#saveBtn").dxButton("instance").option('disabled', true); $("#delBtn").dxButton("instance").option('disabled', true); $("#confirmBtn").dxButton("instance").option('disabled', true); var dataSource = new DevExpress.data.DataSource({ store: { type: "odata", url: endpointSelector + "/BemsReportHistory", }, requireTotalCount: true, pageSize: 1000 }); dataSource.filter([ ["SiteId", "=", BWA.UserInfo.SiteId()], "and", ["parts", "=", 0] ]); dataSource.sort({ getter: "Seq", desc: true }); dataSource.load() .done(function (result) { if (result.length > 0) { seq = result[0].Seq; } else { seq = 0; } var store = new DevExpress.data.ODataStore({ url: endpointSelector + "/BemsReportHistory", key: ["DateTime", "Seq", "ReportFormatId", "parts"], keyType: { DateTime: "DateTime", Seq: "Int32", ReportFormatId: "Int32", parts: "Int32" } }); if ($("#formatSelect").dxSelectBox("instance").option('value') == null) { utils.toast.show('일지 양식을 선택 해 주세요.', 'error'); $("#saveBtn").dxButton("instance").option('disabled', false); $("#delBtn").dxButton("instance").option('disabled', false); $("#confirmBtn").dxButton("instance").option('disabled', false); return; } if ($("#reportName").dxTextBox("instance").option('value') == "") { utils.toast.show('일지 이름을 입력 해 주세요.', 'error'); $("#saveBtn").dxButton("instance").option('disabled', false); $("#delBtn").dxButton("instance").option('disabled', false); $("#confirmBtn").dxButton("instance").option('disabled', false); return; } var contentData = editor.outputBodyHTML(); if (contentData.substring(7, 14) == "
") { var temp1 = contentData.substring(0, 6); var temp2 = contentData.substring(18, contentData.length); contentData = temp1 + temp2; } var partCnt = 1; if (contentData.length > contentsUnit) { partCnt = parseInt(contentData.length / contentsUnit) + 1; } var contentsArray = new Array(partCnt); var contentLength = contentData.length; for (var i = 0; i < partCnt; i++) { if (contentLength <= contentsUnit) { contentsArray[i] = contentData; } else { if (contentLength <= contentsUnit) { contentsArray[i] = contentData.substr(i * contentsUnit, contentLength - i * contentsUnit); } else { contentsArray[i] = contentData.substr(i * contentsUnit, contentsUnit); } } var tmpDate = new Date(); var fileValue = $("#FILE_TAG").val().split("\\"); var fileName = fileValue[fileValue.length - 1]; // 파일명 var tmpDateFormat = new Date(tmpDate.getFullYear(), tmpDate.getMonth(), tmpDate.getDate(), tmpDate.getHours(), tmpDate.getMinutes(), tmpDate.getSeconds(), 0); var insertData = { SiteId: BWA.UserInfo.SiteId(), Seq: seq + 1, DateTime: tmpDateFormat, ReportName: $("#reportName").dxTextBox("instance").option('value'), ReportFormatId: $("#formatSelect").dxSelectBox("instance").option('value'), FormatName: $("#formatSelect").dxSelectBox("instance").option('text'), Content: contentsArray[i], Writer: BWA.UserInfo.Name(), Confirm1: '', Confirm2: '', parts: i, FileName: fileName }; store.insert(insertData) .done(function (values, key) { utils.toast.show("일지를 작성하였습니다."); }) .fail(function (error) { utils.toast.show("일지 작성이 실패하였습니다.", "error"); }); } uploadFile(); if ((window.navigator.appName == 'Netscape' && window.navigator.userAgent.search('Trident') != -1) || (window.navigator.userAgent.indexOf("msie") != -1)) { $("#FILE_TAG").replaceWith($("#FILE_TAG").clone(true)); $("#FILE_TAG").val(""); } else { $("#FILE_TAG").val(""); } setTimeout(function () { $("#saveBtn").dxButton("instance").option('disabled', false); $("#delBtn").dxButton("instance").option('disabled', false); $("#confirmBtn").dxButton("instance").option('disabled', false); visiblePopup(false); change = true; loadGridReportDate(); }, 100); }) .fail(function (error) { $("#saveBtn").dxButton("instance").option('disabled', false); $("#delBtn").dxButton("instance").option('disabled', false); $("#confirmBtn").dxButton("instance").option('disabled', false); utils.toast.show(error); }); } function modifyReport() { var partsCnt = 0; var id; var formatName = ''; var name = $("#reportName").dxTextBox("instance").option('value'); var Writer = ''; var confirm1 = ''; var confirm2 = ''; var removecnt = 0; var tmpDateFormat = new Date(beforeDateTime.getFullYear(), beforeDateTime.getMonth(), beforeDateTime.getDate(), beforeDateTime.getHours(), beforeDateTime.getMinutes(), beforeDateTime.getSeconds(), 0); var dataSource = new DevExpress.data.DataSource({ store: { type: "odata", url: endpointSelector + "/BemsReportHistory", }, requireTotalCount: true, pageSize: 100 }); dataSource.filter([ ["SiteId", "=", BWA.UserInfo.SiteId()], "and", ["Seq", "=", beforeSeq], "and", ["DateTime", "=", beforeDateTime] ]); dataSource.load() .done(function (result) { partsCnt = result.length; Writer = result[0].Writer; confirm1 = result[0].Confirm1; confirm2 = result[0].Confirm2; id = result[0].ReportFormatId; formatName = result[0].FormatName; var store = new DevExpress.data.ODataStore({ url: endpointSelector + "/BemsReportHistory", key: ["DateTime", "Seq", "ReportFormatId", "parts"], keyType: { DateTime: "DateTime", Seq: "Int32", ReportFormatId: "Int32", parts: "Int32" } }); for (var i = 0; i < partsCnt; i++) { var removeData = { Seq: beforeSeq, DateTime: tmpDateFormat, ReportFormatId: id, parts: i }; store.remove(removeData) .done(function (values, key) { removecnt++; if (removecnt == partsCnt) { var store = new DevExpress.data.ODataStore({ url: endpointSelector + "/BemsReportHistory", key: ["DateTime", "Seq", "ReportFormatId", "parts"], keyType: { DateTime: "DateTime", Seq: "Int32", ReportFormatId: "Int32", parts: "Int32" } }); var contentData = editor.outputBodyHTML(); if (contentData.substring(7, 14) == "") { var temp1 = contentData.substring(0, 6); var temp2 = contentData.substring(18, contentData.length); contentData = temp1 + temp2; } var partCnt = 1; if (contentData.length > contentsUnit) { partCnt = parseInt(contentData.length / contentsUnit) + 1; } var contentsArray = new Array(partCnt); var contentLength = contentData.length; var addcnt = 0; for (var i = 0; i < partCnt; i++) { if (contentLength <= contentsUnit) { contentsArray[i] = contentData; } else { if (contentLength <= contentsUnit) { contentsArray[i] = contentData.substr(i * contentsUnit, contentLength - i * contentsUnit); } else { contentsArray[i] = contentData.substr(i * contentsUnit, contentsUnit); } } var fileValue = $("#FILE_TAG").val().split("\\"); var fileName = fileValue[fileValue.length - 1]; // 파일명 if (fileName == "") { fileName = $("#FILE_DOWN").text(); } var insertData = { SiteId: BWA.UserInfo.SiteId(), Seq: beforeSeq, DateTime: tmpDateFormat, ReportName: name, ReportFormatId: id, FormatName: formatName, Content: contentsArray[i], Writer: Writer, Confirm1: confirm1, Confirm2: confirm2, parts: i, FileName: fileName }; store.insert(insertData) .done(function (values, key) { addcnt++; if (addcnt == partCnt) { utils.toast.show("일지를 수정하였습니다."); $("#saveBtn").dxButton("instance").option('disabled', false); $("#delBtn").dxButton("instance").option('disabled', false); $("#confirmBtn").dxButton("instance").option('disabled', false); visiblePopup(false); change = true; loadGridReportDate(); } }) .fail(function (error) { utils.toast.show("일지 수정이 실패하였습니다.", "error"); $("#saveBtn").dxButton("instance").option('disabled', false); $("#delBtn").dxButton("instance").option('disabled', false); $("#confirmBtn").dxButton("instance").option('disabled', false); visiblePopup(false); }); } uploadFile(); if ((window.navigator.appName == 'Netscape' && window.navigator.userAgent.search('Trident') != -1) || (window.navigator.userAgent.indexOf("msie") != -1)) { $("#FILE_TAG").replaceWith($("#FILE_TAG").clone(true)); $("#FILE_TAG").val(""); } else { $("#FILE_TAG").val(""); } } }) .fail(function (error) { utils.toast.show("일지 수정이 실패하였습니다.", "error"); }); } }).fail(function (error) { utils.toast.show(error); }); $("#saveBtn").dxButton("instance").option('disabled', true); $("#delBtn").dxButton("instance").option('disabled', true); $("#confirmBtn").dxButton("instance").option('disabled', true); } function loadGridReportDate() { var dataSource = new DevExpress.data.DataSource({ store: { type: "odata", url: endpointSelector + "/BemsReportHistory", }, requireTotalCount: true, pageSize: 1000 }); dataSource.filter([ ["SiteId", "=", BWA.UserInfo.SiteId()] , "and", ["parts", "=", 0] ]); dataSource.sort({ getter: "Seq", desc: true }); console.log('ds', dataSource); dataSource.load() .done(function (result) { if (result.length > 0) { seq = result[0].Seq; } else { seq = 0; } if (change) { //$("#gridContainer").dxDataGrid("instance").option('dataSource', result); //$("#gridContainer").dxDataGrid({ // scrolling: { // showScrollbar: "never" // }, // paging: { // pageSize: 20, // enabled: true // }, //}); $("#gridContainer").dxDataGrid("instance").refresh(); change = false; } }) .fail(function (error) { utils.toast.show(error); }); } function deleteReport() { var partsCnt = 0; if (seq == 0) { utils.toast.show('삭제할 일지가 없습니다.', "error"); } else { var dataSource = new DevExpress.data.DataSource({ store: { type: "odata", url: endpointSelector + "/BemsReportHistory", }, requireTotalCount: true, pageSize: 100 }); dataSource.filter([ ["SiteId", "=", BWA.UserInfo.SiteId()], "and", ["Seq", "=", beforeSeq] , "and", ["DateTime", "=", beforeDateTime], ]); dataSource.load() .done(function (result) { var id = result[0].ReportFormatId; partsCnt = result.length; var store = new DevExpress.data.ODataStore({ url: endpointSelector + "/BemsReportHistory", key: ["DateTime", "Seq", "ReportFormatId", "parts"], keyType: { DateTime: "DateTime", Seq: "Int32", ReportFormatId: "Int32", parts: "Int32" } }); var tmpDateFormat = new Date(beforeDateTime.getFullYear(), beforeDateTime.getMonth(), beforeDateTime.getDate(), beforeDateTime.getHours(), beforeDateTime.getMinutes(), beforeDateTime.getSeconds(), 0); for (var i = 0; i < partsCnt; i++) { var removeData = { SiteId: BWA.UserInfo.SiteId(), Seq: beforeSeq, DateTime: tmpDateFormat, ReportFormatId: id, parts: i }; store.remove(removeData) .done(function (values, key) { utils.toast.show("일지를 삭제하였습니다."); }) .fail(function (error) { utils.toast.show("일지 삭제를 실패하였습니다.", "error"); }); } }) .fail(function (error) { utils.toast.show(error); }); $("#saveBtn").dxButton("instance").option('disabled', true); $("#delBtn").dxButton("instance").option('disabled', true); $("#confirmBtn").dxButton("instance").option('disabled', true); setTimeout(function () { $("#saveBtn").dxButton("instance").option('disabled', false); $("#delBtn").dxButton("instance").option('disabled', false); $("#confirmBtn").dxButton("instance").option('disabled', false); visiblePopup(false); change = true; loadGridReportDate(); }, 100); } } function confirmReport() { var confirm1; var partsCnt = 0; if (seq == 0) { utils.toast.show('결재할 일지가 없습니다.', 'error'); } else { var confimcnt = 0; var confimcnt1 = 0; var id = $("#formatSelect").dxSelectBox("instance").option('value'); var dataSource = new DevExpress.data.DataSource({ store: { type: "odata", url: endpointSelector + "/BemsReportHistory", }, requireTotalCount: true, pageSize: 100 }); dataSource.filter([ ["SiteId", "=", BWA.UserInfo.SiteId()], "and", ["Seq", "=", beforeSeq], "and", ["DateTime", "=", beforeDateTime] ]); dataSource.load() .done(function (result) { partsCnt = result.length; var store = new DevExpress.data.ODataStore({ url: endpointSelector + "/BemsReportHistory", key: ["DateTime", "Seq", "ReportFormatId", "parts"], keyType: { DateTime: "DateTime", Seq: "Int32", ReportFormatId: "Int32", parts: "Int32" } }); for (var i = 0; i < partsCnt; i++) { if (BWA.UserInfo.UserGroupName().indexOf('팀장') > -1) { store.update({ DateTime: new Date(beforeDateTime.getFullYear(), beforeDateTime.getMonth(), beforeDateTime.getDate(), beforeDateTime.getHours(), beforeDateTime.getMinutes(), beforeDateTime.getSeconds(), 0), Seq: beforeSeq, ReportFormatId: beforeReportFormatId, parts: i }, { Confirm1: BWA.UserInfo.Name() }) .done(function (values, key) { confimcnt++; if (confimcnt == partsCnt) { utils.toast.show("결재가 진행되었습니다."); confimcnt = 0; } }) .fail(function (error) { utils.toast.show("결재가 실패하였습니다.", "error"); }); } else if (BWA.UserInfo.UserGroupName().indexOf('소장') > -1) { var dataSource = new DevExpress.data.DataSource({ store: { type: "odata", url: endpointSelector + "/BemsReportHistory", }, requireTotalCount: true, pageSize: 1 }); dataSource.filter([ ["SiteId", "=", BWA.UserInfo.SiteId()], "and", ["Seq", "=", beforeSeq], "and", ["DateTime", "=", beforeDateTime] ]); dataSource.load() .done(function (result) { if (result[0].Confirm1 == "") { confirm1 = false; } else { confirm1 = true; } if (confirm1) { for (var i = 0; i < partsCnt; i++) { store.update({ DateTime: new Date(beforeDateTime.getFullYear(), beforeDateTime.getMonth(), beforeDateTime.getDate(), beforeDateTime.getHours(), beforeDateTime.getMinutes(), beforeDateTime.getSeconds(), 0), Seq: beforeSeq, ReportFormatId: beforeReportFormatId, parts: i }, { Confirm2: BWA.UserInfo.Name() }) .done(function (values, key) { confimcnt1++; if (confimcnt1 == partsCnt) { utils.toast.show("결재가 진행되었습니다."); confimcnt1 = 0; } }) .fail(function (error) { utils.toast.show("결재가 실패하였습니다.", "error"); }); } } else { utils.toast.show("팀장 결재가 진행되지 않습니다.", "error"); } }) .fail(function (error) { utils.toast.show(error); }); } else { utils.toast.show("결재자 정보가 명확하지 않습니다.", "error"); } } }) .fail(function (error) { utils.toast.show(error); }); $("#saveBtn").dxButton("instance").option('disabled', true); $("#delBtn").dxButton("instance").option('disabled', true); $("#confirmBtn").dxButton("instance").option('disabled', true); setTimeout(function () { $("#saveBtn").dxButton("instance").option('disabled', false); $("#delBtn").dxButton("instance").option('disabled', false); $("#confirmBtn").dxButton("instance").option('disabled', false); visiblePopup(false); change = true; loadGridReportDate(); }, 100); } } function HideConfirm() { var dataSource = new DevExpress.data.DataSource({ store: { type: "odata", url: endpointSelector + "/BemsReportHistory", }, requireTotalCount: true, pageSize: 1 }); dataSource.filter([ ["SiteId", "=", BWA.UserInfo.SiteId()], "and", ["Seq", "=", beforeSeq], "and", ["DateTime", "=", beforeDateTime] ]); dataSource.load() .done(function (result) { if (BWA.UserInfo.UserGroupName().indexOf('팀장') > -1) { if (result[0].Confirm1 == "") { $("#confirmBtn").dxButton("instance").option("visible", true); } else { $("#confirmBtn").dxButton("instance").option("visible", false); } } if (BWA.UserInfo.UserGroupName().indexOf('소장') > -1) { if (result[0].Confirm2 == "") { $("#confirmBtn").dxButton("instance").option("visible", true); } else { $("#confirmBtn").dxButton("instance").option("visible", false); } } }) .fail(function (error) { utils.toast.show(error); }); } function uploadFile() { if ($("#FILE_TAG")[0].files[0] != null) { var form = $('#FILE_FORM')[0]; var formData = new FormData(form); formData.append("fileObj", $("#FILE_TAG")[0].files[0]); var urlHeader = BemsWebApplication.config.endpoints.api[BemsWebApplication.config.mode]; var url = urlHeader + '/DailyReport/FileUpload?&SiteId=' + SiteId; $.ajax({ url: url, processData: false, contentType: false, data: formData, type: 'POST', success: function (result) { }, error: function (error) { } }); } } var searchViewOptions = { }; var dataSourceOptions = { select: [ 'SiteId', 'Seq', 'DateTime', 'ReportName', 'ReportFormatId', 'FormatName', 'Content', 'Writer', 'Confirm1', 'Confirm2', 'parts', 'FileName' ], filter: [[ ["SiteId", "=", BWA.UserInfo.SiteId()], "and", ["parts", "=", 0] ]] }; var viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'BemsReportHistory', { dataSourceOptions: dataSourceOptions, isUseSiteId: false, columns: [ { dataField: 'Index', width: 100, caption: "번호", alignment: 'center' }, { dataField: 'FormatName', width: 260, caption: "양식", alignment: 'center', cellTemplate: function (element, info) { element.append("