123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631 |
- BemsWebApplication.MainDashboardFMS = function (params, viewInfo) {
- "use strict";
- var initialized = false;
- var useBusinessFiltering = ko.observable(false);
- var visiblePopup = ko.observable(false);
- var works = ko.observableArray();
- var works2 = ko.observableArray();
- var works3 = ko.observableArray();
- var eq = BWA.DataUtil.constructEqualFilter,
- and = BWA.DataUtil.andFilter;
- var BFDataSource = BemsWebApplication.db.createDataSource('CmBusinessField'),
- progressDataSource = BemsWebApplication.db.createDataSource('FmsWorkCodeType'),
- chartPieDay = BWA.Chart.Instance('chartPieDayTReport', 'dxPieChart');
- var progresses = ko.observableArray();
-
- var workDataSource = BWA.DataUtil.createDataSource({
- dataSourceOptions: {
- select: [
- 'SiteId', 'WorkRequestId', 'FmsWorkRequest/FmsWorkCodeType/Name',
- 'FmsWorkRequest/WorkTypeId', 'Title', 'OrderDate', 'FmsWorkRequest/WorkProgressId',
- 'CmUser/Name', // 작업지시자
- 'FmsWorkRequest/CmBusinessField/Name',
- 'BusinessFieldId', 'FmsWorkRequest/CmBusinessField/Name', 'FmsWorkRequest/BusinessFieldId'
- ],
- expand: ['FmsWorkRequest',
- 'FmsWorkResult',
- 'FmsWorkResult/CmUser',
- 'FmsWorkResult/IsConfirmed',
- 'FmsWorkResult/ConfirmedDate',
- 'FmsWorkRequest/FmsWorkCodeType',
- 'FmsWorkRequest/CmBusinessField',
- 'FmsWorkRequest/FmsWorkCodeProgress',
- 'CmBusinessField', 'CmUser'],
- extendOptions: {
- forceOriginalField: true,
- }
- },
- }, 'FmsWorkOrder');
- //}, 'FmsWorkRequest');
- // 2016 05 11 추가
- var workDataSource2 = BWA.DataUtil.createDataSource({
- dataSourceOptions: {
- select: [
- 'SiteId', 'WorkRequestId',
- 'StartDate', 'EndDate',
- 'ConfirmedDate', 'ConfirmedUserId', 'IsConfirmed',
- 'CauseClassId', 'Content',
- 'FmsWorkRequest/WorkTypeId',
- 'FmsWorkOrder/Title',
- 'FmsWorkOrder/OrderDate',
- 'FmsWorkRequest/WorkProgressId',
- 'CmUser/Name', // 작업자
- 'FmsWorkRequest/FmsWorkCodeType/Name',
- 'FmsWorkRequest/CmBusinessField/Name',
- 'FmsWorkRequest/FmsWorkCodeProgress/Name',
- 'FmsWorkOrder/BusinessFieldId',
- ],
- expand: [
- 'FmsWorkRequest',
- 'FmsWorkOrder',
- 'FmsWorkRequest/FmsWorkCodeType',
- 'FmsWorkRequest/CmBusinessField',
- 'FmsWorkRequest/FmsWorkCodeProgress',
- 'FmsWorkOrder/CmBusinessField', 'CmUser'],
- extendOptions: {
- forceOriginalField: true
- }
- },
- }, 'FmsWorkResult');
- var AnnounceDataSource = BWA.DataUtil.createDataSource({
- dataSourceOptions: {
- select: [
- 'SiteId',
- 'AnnouncementId',
- 'BusinessFieldId',
- 'CmBusinessField/Name',
- 'Title',
- 'Contents',
- 'RegisterUserId ',
- 'CmUser/Name', // 등록자
- 'AddDate',
- 'UpdateDate',
- 'IsUse',
- 'ReadCount',
- ],
- expand: [
- 'CmBusinessField',
- 'CmUser'
- ],
- extendOptions: {
- forceOriginalField: true
- }
- },
- }, 'CmAnnouncement');
- var initialized_cal = false;
- function handleViewShown() {
- if (initialized === false) {
- BFDataSource.filter([
- eq('SiteId', BWA.UserInfo.SiteId()),//**kgpark
- ]);
- $.when(
- BFDataSource.load(),
- progressDataSource.load()
- ).done(function (BFResult, progressResult) {
- progresses = progressResult[0];
-
- chartPieDay = chartPieDay(BWA.ChartOptions.MainDashboardFMS.getPieChartDayOptions());
- handleSearchInSearchView();
- });
- initialized = true;
- }
- else
- handleSearchInSearchView();
-
- if (initialized_cal === false) {
- holidayCalendar = utils.fullCalendar.create('holidayCalendar', calendarOptions);
- var date = moment();
- currentYear = date.year();
- check_button();
- }
- else
- refreshList_cal();
- }
- function handleSearchInSearchView() {
- if (!useBusinessFiltering) {
- workDataSource2.filter([
- eq('SiteId', BWA.UserInfo.SiteId()),
- and,
- [
- eq('FmsWorkRequest/WorkProgressId', $Code.WorkProgress.WORK_COMPLETE)
- ]
- ]);
- } else {
- workDataSource2.filter([
- eq('SiteId', BWA.UserInfo.SiteId()),
- and,
- [eq('FmsWorkRequest/WorkProgressId', $Code.WorkProgress.WORK_COMPLETE)],
- and,
- [eq('FmsWorkRequest/BusinessFieldId', BWA.UserInfo.BusinessFieldId()), 'or', eq('FmsWorkRequest/BusinessFieldId', 1)]]);
- }
- workDataSource2.load().done(function (workResult) {
- works(workResult);
- });
- if (!useBusinessFiltering) {
- workDataSource2.filter([
- eq('SiteId', BWA.UserInfo.SiteId()),
- and,
- [
- eq('FmsWorkRequest/WorkProgressId', $Code.WorkProgress.WORKING),
- 'or',
- eq('FmsWorkRequest/WorkProgressId', $Code.WorkProgress.WORK_HOLD)
- ]
- ]);
- } else {
- workDataSource2.filter([
- eq('SiteId', BWA.UserInfo.SiteId()),
- and,
- [eq('FmsWorkRequest/WorkProgressId', $Code.WorkProgress.WORKING), 'or', eq('FmsWorkRequest/WorkProgressId', $Code.WorkProgress.WORK_HOLD)],
- and,
- [eq('FmsWorkRequest/BusinessFieldId', BWA.UserInfo.BusinessFieldId()), 'or', eq('FmsWorkRequest/BusinessFieldId', 1)]
- ]);
- }
- workDataSource2.load().done(function (workResult) {
- works2(workResult);
- });
- //공지사항 추가
- if (!useBusinessFiltering) {
- AnnounceDataSource.filter([
- [eq('SiteId', BWA.UserInfo.SiteId()), 'or', eq('SiteId',BemsWebApplication.config.HOSiteId)]
- ]);
- } else {
- AnnounceDataSource.filter([
- [eq('SiteId', BWA.UserInfo.SiteId())],
- and,
- [eq('BusinessFieldId', BWA.UserInfo.BusinessFieldId()), 'or', eq('BusinessFieldId', 1)]
- ]);
- }
-
- AnnounceDataSource.load().done(function (AnnounceResult) {
- works3(AnnounceResult);
- });
- var now_st = new Date();
- now_st = new Date(now_st.getFullYear(), now_st.getMonth(), now_st.getDate(), 0, 0, 0);
- workDataSource.filter([
- [
- eq('SiteId', BWA.UserInfo.SiteId()),
- and,
- ['FmsWorkRequest/WorkProgressId',"<=", $Code.WorkProgress.WORKING],
- //and,
- //['OrderDate', ">=", now_st]
- ]
- ]);
- workDataSource.load().done(function (workResult2) {
- var pieDataArray = [];
- _.each(progresses, function (x) {
- if (x.WorkTypeId() >= 1)
- pieDataArray.push({
- FuelTypeName: x.Name(),
- Value: (x.WorkTypeId() == 1) ? workResult2.length : getWorkProcessCount(workResult2, x.WorkTypeId(), null)
- })
- });
- chartPieDay().option('dataSource', pieDataArray);
- });
- //$("#large-indicator").dxLoadIndicator({
- // height: 60,
- // width: 60
- //});
- }
- function handleViewHidden() {
- visiblePopup(false);
- holidayCalendar.clearEvents(true);
- }
- function handleViewShowing() {
- useBusinessFiltering = BWA.UserInfo.isDependBusinessField(viewInfo.viewName);
- }
- function getWorkProcessCount(datas, type, bf) {
- var cnt = 0;
- _.each(datas, function (x) {
- if (x['SiteId']() == BWA.UserInfo.SiteId() && x['FmsWorkRequest/WorkTypeId']() == type && (bf == null || x['FmsWorkRequest/BusinessFieldId']() == bf)) //**kgpark
-
- cnt++;
- });
- return cnt;
- }
- function refreshList() {
- //dataSource.pageIndex(0);
- //dataSource.load();
- }
- //****************** 달력 조회 ***********************//
- var holidayDataSource = BemsWebApplication.db.createDataSource('CmHoliday', true, true);
- var holidayCustomDataSource = BemsWebApplication.db.createDataSource('CmHolidayCustom', true);
- var holidayWeekendDataSource = BemsWebApplication.db.createDataSource('CmHolidayWeekend', true);
- var checkBox_regular = true, checkBox_legal = true, checkBox_any = true;
- var workScheduleDataSource = BWA.DataUtil.createDataSource({
- dataSourceOptions: {
- select: [
- 'SiteId', 'WorkScheduleId', 'WorkTypeId', 'BusinessFieldId', 'Title', 'FmsWorkSchedule/CycleUnitId',
- 'FmsWorkSchedule/CycleSize', 'FmsWorkSchedule/IsUse', 'FmsWorkSchedule/IsAutoOrder', 'StartWorkDate',
- 'CmUser/Name', 'CmBusinessField/Name', 'FmsWorkResult/EndDate', 'FmsWorkResult/IsConfirmed',
- 'CmPartner/Name', 'FmsWorkSchedule/HolidayWorkTypeId'
- ],
- expand: ['FmsWorkSchedule', 'CmUser', 'CmBusinessField', 'CmPartner', 'FmsWorkResult'],
- extendOptions: {
- forceOriginalField: true
- }
- }
- }, 'FmsWorkRequest');
- var holidaySources;
- var holidayCustomSources;
- var workScheduleSources;
- var cc = new CalendarConverter;
- var holidayWeekendDataViewModel = new BemsWebApplication.CmHolidayWeekendViewModel();
- var loadedYears = [];
- var viewDate = null;
- var currentYear = null;
- var holidays = [];
- var weekends = [];
- var isSaturday = false;
- var isSunday = false;
- var holidayCalendar = null;
- var calendarOptions = {
- selectable: false,
- editable: false,
- //weekends: true,
- weekNumbers: false,
- changedMonth: function (view) {
- var date = view.calendar.getDate();
- viewDate = date; //hcLee 2016 03 21
- if (currentYear !== null && date.year() !== currentYear) {
- currentYear = date.year();
- check_button();
- }
- else {
- applyWeekends(date);
- }
- }
- }
-
- function refreshHolidays(date) {
- holidays = [];
- var currentYear = date.year();
- if (loadedYears.indexOf(currentYear) < 0) {
- loadedYears.push(currentYear);
- var year;
- var month;
- var day;
- var solar;
- $.each(holidaySources, function (i, item) {
- year = currentYear;
- month = item.HolidayMonth() - 1;
- day = item.HolidayDay();
- if (item.IsLunar()) {
- solar = cc.lunar2solar(new Date(year - 1, month, day));
- if (solar.sYear !== year) {
- solar = cc.lunar2solar(new Date(year, month, day));
- }
- year = solar.sYear;
- month = solar.sMonth - 1;
- day = solar.sDay;
- }
- utils.holiday.pushHolidayEventInArray(holidays, item.Name(), moment([year, month, day]), true, undefined, 0);
- });
- $.each(holidayCustomSources, function (i, item) {
- var itemDate = item.HolidayDate();
- if (itemDate.getFullYear() === currentYear) {
- utils.holiday.pushHolidayEventInArray(holidays, item.Name(), moment([itemDate.getFullYear(), itemDate.getMonth(), itemDate.getDate()]), false, undefined, 1);
- }
- });
- $.each(workScheduleSources, function (i, item) {
- var itemDate = item['FmsWorkResult/EndDate']();//추가
- item.Name = item.Title;
- if (itemDate.getFullYear() === currentYear) {
- utils.holiday.pushWorkScheduleEventInArray(holidays, item, moment([itemDate.getFullYear(), itemDate.getMonth(), itemDate.getDate()]), false, undefined, item.WorkTypeId());
- }
- });
- }
- applyWeekends(date);
- }
- function loadHolidays(date) {
- holidays = [];
- loadedYears = [];
- workScheduleDataSource.filter().push('and', eq("SiteId", BWA.UserInfo.SiteId()));
- if (useBusinessFiltering)
- workScheduleDataSource.filter().push('and', [eq('BusinessFieldId', BWA.UserInfo.BusinessFieldId()), 'or', eq('BusinessFieldId', 1)]);
- $.when(
- holidayDataSource.load(),
- holidayCustomDataSource.load(),
- holidayWeekendDataSource.load(),
- workScheduleDataSource.load())//수정
- .done(function (result1, result2, result3, result4) {
- holidaySources = result1[0];
- holidayCustomSources = result2[0];
- var tempworkScheduleSources = result4[0];
- workScheduleSources = [];
- for (var i = 0; i < tempworkScheduleSources.length; i++) {
- if (tempworkScheduleSources[i]['FmsWorkResult/IsConfirmed'] != null) {
- if (tempworkScheduleSources[i]['FmsWorkResult/IsConfirmed']() == true) {
- workScheduleSources.push(tempworkScheduleSources[i]);
- }
- }
- }
- if (result3.length > 0) {
- var weekend = result3[0][0];
- isSaturday = weekend.Saturday();
- isSunday = weekend.Sunday();
- holidayWeekendDataViewModel.SiteId(weekend.SiteId());
- holidayWeekendDataViewModel.Saturday(weekend.Saturday());
- holidayWeekendDataViewModel.Sunday(weekend.Sunday());
- }
- refreshHolidays(date);
- });
- }
- function applyWeekends(date) {
- if (holidayCalendar === null) return;
- if (isSunday == false && isSaturday == false) {
- holidayCalendar.updateEvents(holidays);
- return;
- }
- weekends = utils.holiday.getWeekendHolidays(date, isSaturday, isSunday);
- holidayCalendar.updateEvents(holidays.concat(weekends));
- }
-
- function check_button() {
- $("#checkBox_regular").dxCheckBox({
- text: "정기 점검",
- value: true,
- onValueChanged: function (e) {
- switch (e.value) {
- case true:
- checkBox_regular = true;
- break;
- case false:
- checkBox_regular = false;
- break;
- }
- Data_filter(viewDate);
- }
- });
- $("#checkBox_legal").dxCheckBox({
- text: "법정 검사",
- value: true,
- onValueChanged: function (e) {
- switch (e.value) {
- case true:
- checkBox_legal = true;
- break;
- case false:
- checkBox_legal = false;
- break;
- }
- Data_filter(viewDate);
- }
- });
- $("#checkBox_any").dxCheckBox({
- text: "수시 점검",
- value: true,
- onValueChanged: function (e) {
- switch (e.value) {
- case true:
- checkBox_any = true;
- break;
- case false:
- checkBox_any = false;
- break;
- }
- Data_filter(viewDate);
- }
- });
- Data_filter(viewDate);
- }
- function Data_filter(date) {
- workScheduleDataSource.filter([]);
- if (checkBox_regular) {//1
- if (checkBox_legal) {//2
- if (checkBox_any) {//5
- workScheduleDataSource.filter().push(["WorkTypeId", ">=", 1]);//1,2,5
- }
- else {
- workScheduleDataSource.filter().push([["WorkTypeId", "=", 1], 'or', ["WorkTypeId", "=", 2]]);//1,2
- }
- }
- else {
- if (checkBox_any) {//5
- workScheduleDataSource.filter().push([["WorkTypeId", "=", 1], 'or', ["WorkTypeId", "=", 5]]);//1,5
- }
- else {
- workScheduleDataSource.filter().push(["WorkTypeId", "=", 1]);//1
- }
- }
- }
- else {
- if (checkBox_legal) {//2
- if (checkBox_any) {//5
- workScheduleDataSource.filter().push([["WorkTypeId", "=", 2], 'or', ["WorkTypeId", "=", 5]]);//2,5
- }
- else {
- workScheduleDataSource.filter().push(["WorkTypeId", "=", 2]);//2
- }
- }
- else {
- if (checkBox_any) {//5
- workScheduleDataSource.filter().push(["WorkTypeId", "=", 5]);//5
- }
- else {
- workScheduleDataSource.filter().push(["WorkTypeId", "=", 0]);//0
- }
- }
- }
- loadHolidays(date);
- initialized_cal = true;
- }
- function refreshList_cal() {
- currentYear = viewDate.year();
- Data_filter(viewDate);
- }
- //****************** 달력 조회 ***********************//
- //var viewModel = $.extend(BWA.CommonView.create(params, viewInfo, searchViewOptions, ko.observable(null), handleViewShown, null, handleSearchInSearchView), {
- var viewModel = $.extend(BWA.CommonView.create(params, viewInfo, null, ko.observable(null), handleViewShown), {
- refreshList: refreshList,
- viewShowing: handleViewShowing,
- workDataGridOptions: utils.datagrid.defaultOptions({
- rowClick: function (row) {
- },
- //rowAlternationEnabled: true,
- useNumberColumn: false,
- dataSource: works,
- datagridId: 'gridContainer',
- paging: {
- enabled: true,
- pageSize: 4
- },
- pager: {
- //allowedPageSizes: true,
- showPageSizeSelector: false,
- allowedPageSizes: [4],
- visible: false
- },
- columns: [
- // dataField: 'WorkRequestId', caption: $G('number'), width: '8%', alignment: 'center' },
- { dataField: 'FmsWorkRequest/CmBusinessField/Name', caption: $G('businessFieldName'), width: '15%', alignment: 'center' },
- { dataField: 'FmsWorkRequest/FmsWorkCodeType/Name', caption: $G('workTypeName'), width: '15%', alignment: 'center' },
- {
- dataField: 'FmsWorkOrder/OrderDate', caption: $G('orderedDate'), width: '17.5%', alignment: 'center',
- customizeText: function (cellInfo) {
- return $G.date(cellInfo.value);
- }
- },
- {
- dataField: 'EndDate', caption: '종료일', width: '17.5%', alignment: 'center', sortOrder: 'desc',
- customizeText: function (cellInfo) {
- return $G.date(cellInfo.value);
- }
- },
- { dataField: 'FmsWorkOrder/Title', caption: '작업명', width: '20%', alignment: 'center' },
- { dataField: 'CmUser/Name', caption: '작업지시자', width: '15%', alignment: 'center' },
- ],
- }),
- workDataGridOptions2: utils.datagrid.defaultOptions({
-
- //rowAlternationEnabled: true,
- dataSource: works2,
- datagridId: 'gridContainer2',
- useNumberColumn: false,
- columns: [
- //{ dataField: 'WorkRequestId', caption: $G('number'), width: '8%', alignment: 'center' },
- { dataField: 'FmsWorkRequest/CmBusinessField/Name', caption: $G('businessFieldName'), width: '20%', alignment: 'center' },
- { dataField: 'FmsWorkRequest/FmsWorkCodeType/Name', caption: $G('workTypeName'), width: '20%', alignment: 'center' },
- //{
- // dataField: 'FmsWorkOrder/OrderDate', caption: $G('orderedDate'), width: '15%', alignment: 'center', sortOrder: 'desc',
- // customizeText: function (cellInfo) {
- // return $G.date(cellInfo.value);
- // }
- //},
- {
- dataField: 'EndDate', caption: '종료예정일', width: '30%', alignment: 'center', sortOrder: 'desc',
- customizeText: function (cellInfo) {
- return $G.date(cellInfo.value);
- }
- },
- { dataField: 'FmsWorkOrder/Title', caption: '작업명', width: '30%', alignment: 'center' },
- //{ dataField: 'CmUser/Name', caption: '작업자', width: '10%', alignment: 'center' },
- ],
- paging: {
- enabled: true,
- pageSize: 4
- },
- pager: {
- //allowedPageSizes: true,
- showPageSizeSelector: false,
- allowedPageSizes: [4],
- visible: false
- },
- }),
-
- workDataGridOptions3: utils.datagrid.defaultOptions({
- //rowAlternationEnabled: true,
- dataSource: works3,
- datagridId: 'gridContainer3',
- useNumberColumn: false,
- columns: [
- { dataField: 'CmBusinessField/Name', caption: $G('businessFieldName'), width: '15%', alignment: 'center' },
- { dataField: 'Title', caption: '제목', width: '35%', alignment: 'center' },
- { dataField: 'CmUser/Name', caption: '등록자', width: '20%', alignment: 'center' },
- {
- dataField: 'UpdateDate', caption: '수정일', width: '20%', alignment: 'center', sortOrder: 'desc',
- customizeText: function (cellInfo) {
- return $G.date(cellInfo.value);
- }
- },
- { dataField: 'ReadCount', caption: '조회수', width: '10%', alignment: 'center' },
- ],
- paging: {
- enabled: true,
- pageSize: 4
- },
- pager: {
- //allowedPageSizes: true,
- showPageSizeSelector: false,
- allowedPageSizes: [4],
- visible: false
- },
- rowPrepared: function (rowElement, rowInfo) {
- if (rowInfo.rowType == 'data') {
- var data = rowInfo.data;
- if (data.SiteId() == BemsWebApplication.config.HOSiteId) {
- rowElement.css('background-color', 'rgba(255,0,0,0.1)');
-
- }
- }
- },
- })
- });
-
- return viewModel;
- };
|