123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482 |
- BemsWebApplication.EquipRentInfo = function (params, viewInfo) {
- "use strict";
- var codeTypeDataSource = BemsWebApplication.db.createDataSource('FmsEquipmentCodeType', true, false, true),
- codeStateTypeDataSource = BemsWebApplication.db.createDataSource('FmsEquipmentCodeStateType', false, false, true),
- warehouseDataSource = BemsWebApplication.db.createDataSource('FmsMaterialWarehouse', true, false, true);
- var equipmentFactory = BWA.Factory.Equipment;
- var equipmentsDataSource = equipmentFactory.getBasicDataSourceRef({
- dbModeIId: 'FmsEquipmentHistory',
- primaryKeyDataField: 'EquipmentHistoryId'
- });
- var codeTypes = ko.observableArray(),
- codeStateTypes = ko.observableArray(),
- warehouses = ko.observableArray();
- var equipments = ko.observableArray(),
- equipmentsInView = ko.observableArray();
- var equipmentGridView;
- var equipmentDataGridOptions,
- modifiableEquipmentDataGridOptions = undefined;
- var selectedUserData = ko.observable();
- var codeTypesForSearch = ko.observableArray(),
- codeStateTypesForSearch = ko.observableArray(),
- warehousesForSearch = ko.observableArray();
- var deferredForSearch = new $.Deferred();
- var eq = BWA.DataUtil.constructEqualFilter,
- and = BWA.DataUtil.andFilter;
- selectedUserData.subscribe(function (value) {
- viewModel.dataModel.RentUser(value.Name);
- });
- var viewModel;
- var viewOptions = {
- dataSourceOptions: {
- select: [
- 'SiteId',
- 'EquipmentRentId',
- 'RegisterUserId',
- 'RentUser',
- 'Title',
- 'RentDate',
- 'ReturnDueDate',
- 'ReturnFixDate',
- 'EquipmentStateTypeId',
- 'Comment',
- 'CmUser/Name', // 등록자
- 'FmsEquipmentCodeStateType/Name'
- ],
- expand: [
- 'CmUser', 'CmUser1',
- 'FmsEquipmentCodeStateType',
- 'FmsEquipmentHistory'
- ],
- extendOptions: {
- forceOriginalField: true,
- },
- filter: [
- ['SiteId', '=', BWA.UserInfo.SiteId()],
- 'and',
- ['EquipmentStateTypeId', '=', 2]
- ],
- },
- columns: [
- { dataField: 'EquipmentRentId', caption: $G('number'), width: '10%', alignment: 'center', sortOrder: 'desc' },
- { dataField: 'Title', caption: '대여신청명', width: '40%', alignment: 'center' },
- { dataField: 'Comment', caption: '대여사유', width: '40%', alignment: 'center' },
- { dataField: 'RentUser', caption: '대여자', width: '20%', alignment: 'center' },
- {
- dataField: 'RentDate', caption: '대여일', width: '20%', alignment: 'center', dataType: "shortDate", format: "yyyy-MM-dd",
- customizeText: function (cellInfo) {
- return cellInfo.valueText;
- }
- },
- {
- dataField: 'ReturnDueDate', caption: '반납예정일', width: '20%', alignment: 'center', dataType: "shortDate", format: "yyyy-MM-dd",
- customizeText: function (cellInfo) {
- return cellInfo.valueText;
- }
- },
- { dataField: 'CmUser/Name', caption: '관리자', width: '20%', alignment: 'center', visible: false },
- ],
- paging: {
- pageSize: 18,
- enabled: true
- },
- pager: {},
- "export": {
- enabled: true,
- fileName: '공기구 대여 목록',
- },
- onExporting: function (e) {
- e.component.columnOption("EquipmentRentId", "visible", false);
- },
- onExported: function (e) {
- e.component.columnOption("EquipmentRentId", "visible", true);
- },
- sort: { field: "EquipmentRentId", desc: true },
- searchViewItems: [
- { id: 'Title' },
- { id: 'RentUser' },
- { id: 'RentDate', type: 'dateRange', isOnlyDate: true },
- { id: 'ReturnDueDate', type: 'dateRange', isOnlyDate: true }
- ],
- popupWidth: 1200,
- handleViewShowing: function (dataModel) {
- $.when(
- codeStateTypeDataSource.load(),
- codeTypeDataSource.load(),
- warehouseDataSource.load()
- ).done(function (codeStateTypeResult, codeTypeResult, warehouseResult) {
- codeStateTypes(codeStateTypeResult[0]);
- codeTypes(codeTypeResult[0]);
- warehouses(warehouseResult[0]);
- codeStateTypesForSearch($SearchView.createArrayOfSelectBox('EquipmentStateTypeId', codeStateTypes()));
- codeTypesForSearch($SearchView.createArrayOfSelectBox('EquipmentTypeId', codeTypes()));
- warehousesForSearch($SearchView.createArrayOfSelectBox('WarehouseId', warehouses()));
- deferredForSearch.resolve();
- });
- },
- handleViewShown: function (dataModel) {
- },
- handleDataGridRowClick: function (id, dataGrid, clickRow, popupVisible) {
- dataGrid.clearSelection();
- var data = clickRow.data;
- var dataModel = viewModel.dataModel;
- if (data['RentUser'] !== undefined) {
- dataModel.RentUser = $KoSet(dataModel.RentUser, data['RentUser']());
- }
- popupVisible(true);
- },
- handleAfterLoadingModelByKey: function (data, dataViewModel) {
- equipmentsDataSource.filter([
- eq('SiteId', dataViewModel.SiteId()),
- and,
- eq('EquipmentRentId', dataViewModel.EquipmentRentId()),
- and,
- ['IsReturned', '=', false]
- ]);
- equipmentsDataSource.load().done(function (dbEquipments) {
- equipmentsInView(dbEquipments);
- });
- },
- handlePopupShowing: function (isNewInPopup, dataViewModel) {
- $("#gridContainer2").dxDataGrid({
- paging: {
- pageSize: 9,
- enabled: true
- }
- });
- $("#gridContainer3").dxDataGrid({
- paging: {
- pageSize: 9,
- enabled: true
- }
- });
- // 저장 버튼
- var userInfo = BWA.UserInfo;
- if (isNewInPopup()) { // 신규등록인 경우
- dataViewModel.SiteId(userInfo.SiteId());
- dataViewModel.EquipmentStateTypeId(2);
- dataViewModel.RentDate($G.date(new Date()));
- dataViewModel.RegisterUserId(userInfo.UserId());
- dataViewModel.Comment('');
- }
- },
- handlePopupShown: function (isEditMode, isNew, dataViewModel) {
- }
- };
- viewModel = BWA.DataGrid.createViewWithDataGrid(params, viewInfo, 'FmsEquipmentRentInfo', viewOptions);
- var equipPopupToolbarItems = [
- { location: 'before', text: '공기구 대여' },
- {
- location: 'after', widget: 'button', options: {
- text: '공기구추가', icon: 'search', visible: viewModel.isEditModeInPopup,
- clickAction: function () { viewModel.equipmentSearchPopup.show(); }
- }
- },
- {
- location: 'after', widget: 'button', options: {
- text: '공기구삭제', icon: 'remove', type: 'danger', visible: viewModel.isEditModeInPopup,
- clickAction: function () { handleDeleteSelectedEquipments(); }
- }
- },
- {
- location: 'after', widget: 'button', options: {
- text: $G('save'), icon: 'save', visible: viewModel.isEditModeInPopup,
- clickAction: handlePopupButtonSave
- }
- },
- {
- location: 'after', widget: 'button', options: {
- text: $G('close'), icon: 'close',
- clickAction: equipPopupButtonClose
- }
- }
- ];
- equipmentDataGridOptions = utils.datagrid.defaultOptions({
- width: 700,
- pager: {
- showPageSizeSelector: false,
- allowedPageSizes: []
- },
- dataSource: equipmentsInView,
- columns: [
- { dataField: 'Name', caption: '공기구명', width: '35%', alignment: 'center' },
- { dataField: 'FmsEquipment/Standard', caption: '규격', width: '35%', alignment: 'center' },
- { dataField: 'FmsEquipment/FmsMaterialWarehouse/Name', caption: '창고', width: '15%', alignment: 'center' },
- // Detail 에서는 보유수량을 표시하지 않음. 사용자의 혼란 방지
- { dataField: 'CurrentRentCount', caption: '대여수량', width: '15%', alignment: 'center', format: 'currency' }
- ],
- });
- modifiableEquipmentDataGridOptions = utils.datagrid.defaultOptions({
- width: 700,
- pager: {
- showPageSizeSelector: false,
- allowedPageSizes: []
- },
- dataSource: equipments,
- selection: { mode: 'multiple', allowSelectAll: true },
- columns: [
- { dataField: 'Name', caption: '공기구명', width: '30%', alignment: 'center' },
- { dataField: 'Standard', caption: '규격', width: '30%', alignment: 'center' },
- { dataField: 'WarehouseName', caption: '창고', width: '13%', alignment: 'center' },
- { dataField: 'CurrentStockCount', caption: '보유수량', width: '13%', alignment: 'center', format: 'currency' },
- {
- dataField: 'CurrentRentCount', caption: '대여수량', width: '13%', alignment: 'center', format: 'currency',
- cellTemplate: utils.datagrid.getNumberBoxDataGridTemplateFunc({
- min: 1,
- max: 1000000,
- dataField: 'CurrentRentCount',
- convertValueWhenValueChanged: function (value) {
- return Math.max(1, value);
- }
- })
- },
- ],
- cellClick: function (e) {
- utils.datagrid.cellClickEventForDataGridTemplate(e, 'CurrentRentCount');
- },
- contentReadyAction: function (e) {
- equipmentGridView = e.component;
- },
- });
- function handleDeleteSelectedEquipments() {
- var rows = equipmentGridView.getSelectedRowsData();
- if (_.isEmpty(rows)) {
- utils.toast.show('선택된 자재가 없습니다.', 'error');
- return;
- }
- _.each(rows, function (row) {
- var array = equipments();
- var length = array.length;
- var id = row.EquipmentId();
- for (var i = 0 ; i < length ; i++) {
- if (id === array[i].EquipmentId()) {
- equipments().splice(i, 1);
- break;
- }
- }
- });
- equipmentGridView.refresh();
- }
- function equipPopupButtonClose() {
- viewModel.popupVisible(false);
- }
- // 편집모드로 오픈시 데이터 복사
- viewModel.isEditModeInPopup.subscribe(function (isEditMode) {
- if (isEditMode) { equipments(equipmentsInView.slice(0)); }
- });
- viewModel.popupVisible.subscribe(function (visible) {
- if (!visible) {
- // 데이터 초기화
- equipmentsInView([]);
- equipments([]);
- }
- });
- viewModel.userSearchPopup = $UserSearchPopup(viewModel, selectedUserData);
- viewModel.equipmentSearchPopup = BWA.Popup.Equipment.create(viewModel, {
- isMultipleSelect: true,
- onSelectedEquipments: function (selectedEquipments) {
- var equipmentRentId = viewModel.dataModel.EquipmentRentId();
- _.each(selectedEquipments, function (sm) {
- // JD : 팝업에서 전체선택시 추가로 하면 오류 발생함. 이에 대한 회피 코드로 try-catch
- // JD : 근본적인 원인은 시간 관계상 차후로 넘김
- var found = _.some(equipments(), function (m) {
- try {
- return m.EquipmentId() === sm.EquipmentId();
- } catch (e) {
- return m.EquipmentId() === sm.EquipmentId;
- }
- });
- if (found) return;
- // TODO : 여기서 부가적인 값들을 추가해주어야 함
- try {
- equipments.push({
- SiteId: ko.observable(sm.SiteId()),
- EquipmentId: ko.observable(sm.EquipmentId()),
- Name: ko.observable(sm.Name()),
- WarehouseName: ko.observable(sm.WarehouseName()),
- //Name2: ko.observable(sm.),
- CurrentStockCount: ko.observable(sm.CurrentStockCount()),
- CurrentRentCount: ko.observable(1),
- Standard: ko.observable(sm.Standard())
- });
- } catch (e) {
- equipments.push({
- SiteId: ko.observable(sm.SiteId),
- EquipmentId: ko.observable(sm.EquipmentId),
- Name: ko.observable(sm.Name),
- WarehouseName: ko.observable(sm.WarehouseName),
- CurrentStockCount: ko.observable(sm.CurrentStockCount),
- CurrentRentCount: ko.observable(1),
- Standard: ko.observable(sm.Standard)
- });
- }
- });
- equipmentGridView.refresh();
- }
- });
- viewModel.buttonSearchMainContactorUser = function (e) {
- viewModel.userSearchPopup.show();
- }
- function handlePopupButtonSave() {
- // 더블클릭문제로 인한 방어코드
- if (!viewModel.popupVisible()) { return; }
- var dataViewModel = viewModel.dataModel;
- // 저장버튼을 오버라이딩 하였으므로 mandatory 필드가 적용되지 않음. SelfValidation
- if (_.isEmpty(dataViewModel.Title())) {
- utils.toast.show('값을 입력해 주십시오: 제목 ', 'error');
- return;
- }
- if (dataViewModel.ReturnDueDate() == null) {
- utils.toast.show('값을 입력해 주십시오: 반납예정일 ', 'error');
- return;
- }
- if (_.isEmpty(dataViewModel.RentUser())) {
- utils.toast.show('값을 입력해 주십시오: 대여자 ', 'error');
- return;
- }
- if (_.isEmpty(equipments())) {
- utils.toast.show('불출요청한 공기구가 없습니다.', 'error');
- return;
- }
- if ($G.date(dataViewModel.ReturnDueDate()) < dataViewModel.RentDate()) {
- utils.toast.show('반납예정일을 대여일 이후로 설정하시기 바랍니다.', 'error');
- return;
- }
- var tempEquipmentName;
- // 여기서 대여수량과 불출수량 카운트를 각각 확인하여 정상인 경우만...
- var foundExcess = _.some(equipments(), function (m) {
- tempEquipmentName = m.Name();
- return m.CurrentStockCount() < m.CurrentRentCount();
- });
- if (foundExcess) {
- utils.toast.show(tempEquipmentName + '의 대여가능 수량이 초과되었습니다.', 'error');
- return;
- }
- var dataViewModel = viewModel.dataModel;
- if (viewModel.isNewInPopup()) { // insert 인 경우
- BWA.db.FmsEquipmentRentInfo.insert(dataViewModel.toJS()).done(function (values, newId) {
- var array = equipments();
- var postData;
- var parameters = {
- SiteId: newId.SiteId,
- EquipmentRentId: newId.EquipmentRentId
- };
- postData = _.map(array, function (m) {
- return {
- SiteId: newId.SiteId,
- EquipmentId: m.EquipmentId(),
- EquipmentRentId: newId.EquipmentRentId,
- CurrentRentCount: m.CurrentRentCount(),
- EquipmentStateTypeId: 2 // 출고
- // TODO : 필요하다면 아래에 데이터 추가 필요
- };
- });
- BWA.api.post('FmsEquipmentRentInfo/InsertEquipments', postData, parameters).done(
- function () {
- viewModel.popupVisible(false);
- viewModel.gridView().refresh();
- utils.toast.show($G('successDatabaseInsertionMsg'));
- });
- });
- }
- else { // update 경우
- var keys = BWA.db.extractKeysObject('FmsEquipmentRentInfo', dataViewModel);
- BWA.db.FmsEquipmentRentInfo.update(keys, dataViewModel.toJS()).done(function (res) {
- var array = equipments();
- var postData;
- var parameters = {
- SiteId: res.SiteId,
- EquipmentRentId: res.EquipmentRentId
- };
- postData = _.map(array, function (m) {
- return {
- SiteId: res.SiteId,
- EquipmentId: m.EquipmentId(),
- EquipmentRentId: res.EquipmentRentId,
- CurrentRentCount: m.CurrentRentCount(),
- EquipmentStateTypeId: 2 // 출고
- // TODO : 필요하다면 아래에 데이터 추가 필요
- };
- });
- BWA.api.post('FmsEquipmentRentInfo/UpdateEquipments', postData, parameters).done(
- function () {
- viewModel.popupVisible(false);
- viewModel.gridView().refresh();
- utils.toast.show($G('successDatabaseUpdateMsg'));
- });
- });
- }
- };
- viewModel.equipPopupToolbarItems = equipPopupToolbarItems;
- viewModel.dataModel.RentUser = ko.observable();
- viewModel.equipmentDataGridOptions = equipmentDataGridOptions;
- viewModel.modifiableEquipmentDataGridOptions = modifiableEquipmentDataGridOptions;
- viewModel.codeTypes = codeTypes;
- viewModel.codeStateTypes = codeStateTypes;
- viewModel.warehouses = warehouses;
- return viewModel;
- };
|