8d4973d440385f6a33b9c24d5d601a2a0551a1ce.svn-base 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521
  1. BemsWebApplication.setprice2 = function (params, viewInfo) {
  2. //탭 표시 요금제 Array 데이터 초기화
  3. var tabsData = [
  4. {
  5. id: "0",
  6. text: "test1"
  7. },
  8. {
  9. id: "1",
  10. text: "test2"
  11. },
  12. {
  13. id: "2",
  14. text: "test3"
  15. }
  16. ];
  17. //권한설정
  18. var hasnotModificationPermission = ko.observable(true);
  19. var old = false;
  20. //요금제 선택 SelectBox Array데이터 초기화
  21. var priceTypeDataSource = [{
  22. FuelTypeId: 1,
  23. PriceTypeId: 1,
  24. PriceTypeIdDesc: ""
  25. }];
  26. //요금제 항목 데이터 소스 변수 선언
  27. var priceCodeDataSource;
  28. //요금제 업데이트 시 변경전 조건과 변경후 변경값이 다르기 때문에 변경전 요금제를 저장할 용도로 변수 선언
  29. var beforeSelectPriceTypeId;
  30. //에너지원 선택 전역 변수 초기화
  31. var energySelectButton = "power";
  32. var selectFacilityTypeId;
  33. var selectFacilityCode;
  34. var selectFormulaId;
  35. var init = false;
  36. var endpointSelector = "";
  37. if (BemsWebApplication.config.mode == "production") {
  38. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.production;
  39. } else {
  40. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.local;
  41. }
  42. function getSitePrice(SiteID, FuelTypeId, PriceCode) { //현재 요금제 선택된 항목
  43. var dataSource = new DevExpress.data.DataSource({
  44. store: new DevExpress.data.ODataStore({
  45. url: endpointSelector + "/BemsSitePrice"
  46. }),
  47. expand: 'BemsPriceType',
  48. requireTotalCount: true,
  49. pageSize: 100
  50. });
  51. dataSource.filter([
  52. ["SiteID", "=", SiteID],
  53. "and",
  54. ["FuelTypeId", "=", FuelTypeId],
  55. "and",
  56. ["BemsPriceType.PriceTypeIdDesc", "=", $("#tabOptions").dxTabs("instance").option('selectedItem').text]
  57. ]);
  58. dataSource.load()
  59. .done(function (result) {
  60. $("#priceSelect").dxSelectBox("instance").option('value', result[0].BemsPriceType.PriceTypeId);
  61. beforeSelectPriceTypeId = result[0].BemsPriceType.PriceTypeId;
  62. })
  63. .fail(function (error) {
  64. alert(error);
  65. });
  66. }
  67. function getPriceType(FuelTypeId) {//요금제 종류
  68. var dataSource = new DevExpress.data.DataSource({
  69. store: {
  70. type: "odata",
  71. url: endpointSelector + "/BemsPriceType"
  72. },
  73. //map: function (itemData) {
  74. // return {
  75. // PriceTypeId: itemData.PriceTypeId,
  76. // PriceTypeIdDesc: itemData.PriceTypeIdDesc,
  77. // FuelTypeId: itemData.FuelTypeId
  78. // }
  79. //},
  80. requireTotalCount: true,
  81. pageSize: 100
  82. });
  83. dataSource.filter(["FuelTypeId", "=", FuelTypeId]);
  84. dataSource.sort({ getter: "PriceTypeId", asc: true });
  85. dataSource.load()
  86. .done(function (result) {
  87. priceTypeDataSource = result;
  88. $("#priceSelect").dxSelectBox("instance").option('dataSource', priceTypeDataSource);
  89. $("#priceSelect").dxSelectBox("instance").option('displayExpr', 'PriceTypeIdDesc');
  90. $("#priceSelect").dxSelectBox("instance").option('valueExpr', "PriceTypeId");
  91. getSitePrice(BWA.UserInfo.SiteId(), result[0].FuelTypeId);//PriceCode P038 청구요금
  92. })
  93. .fail(function (error) {
  94. alert(error);
  95. });
  96. }
  97. function PriceTypeDataSourceToArray(dataSource) {
  98. var resultArray = new Array(dataSource._items.length);
  99. for (var i = 0; i < dataSource._items.length; i++) {
  100. resultArray[i] = dataSource._items[i].PriceTypeIdDesc;
  101. }
  102. return resultArray;
  103. }
  104. function getPriceCode(FuelTypeId) { //요금제 항목 종류
  105. var dataSource = new DevExpress.data.DataSource({
  106. store: {
  107. type: "odata",
  108. url: endpointSelector + "/BemsPriceCode"
  109. },
  110. map: function (itemData) {
  111. return {
  112. PriceCode: itemData.PriceCode,
  113. PriceCodeDesc: itemData.PriceCodeDesc,
  114. FuelTypeId: itemData.FuelTypeId,
  115. Unit: itemData.Unit
  116. }
  117. },
  118. requireTotalCount: true,
  119. pageSize: 100
  120. });
  121. dataSource.filter(["FuelTypeId", "=", FuelTypeId]);
  122. dataSource.sort({ getter: "PriceCode", asc: true });
  123. dataSource.load()
  124. .done(function (result) {
  125. priceCodeDataSource = result;
  126. var $PriceCodeLayOut = $('#PriceCodeLayOut'); // finds the <PriceCodeLayOut> element
  127. $('#PriceCodeLayOut').empty();
  128. for (var i = 0; i < result.length; i++) {
  129. $('<input type="text" class="fl setInputId" style="width:150px;height:24px;" readonly>') // creates a new HTML element
  130. .appendTo($PriceCodeLayOut) // appends a new HTML element to the <body> element
  131. $('<div class="fl setSwitchId" style="margin-right:22px;">')
  132. .appendTo($PriceCodeLayOut)
  133. .dxSwitch();
  134. if (i % 5 == 4) {
  135. $('<br>').appendTo($PriceCodeLayOut)
  136. $('<br>').appendTo($PriceCodeLayOut)
  137. $('<br>').appendTo($PriceCodeLayOut)
  138. }
  139. }
  140. var setInputIds = document.querySelectorAll('.setInputId');
  141. var setSwitchIds = document.querySelectorAll('.setSwitchId');
  142. for (var i = 0; i < result.length; i++) {
  143. setInputIds[i].id = 'input' + i;
  144. setInputIds[i].value = result[i].PriceCodeDesc;
  145. setSwitchIds[i].id = 'switch' + i;
  146. $('#switch' + i).dxSwitch("instance").option('onText', 'On');
  147. $('#switch' + i).dxSwitch("instance").option('offText', 'Off');
  148. $('#switch' + i).dxSwitch("instance").option('value', true);
  149. }
  150. getPriceCodeYN(BWA.UserInfo.SiteId(), FuelTypeId);
  151. })
  152. .fail(function (error) {
  153. alert(error);
  154. });
  155. }
  156. function getPriceCodeYN(SiteID, FuelTypeId) { //현재 요금제 선택된 항목
  157. var dataSource = new DevExpress.data.DataSource({
  158. store: new DevExpress.data.ODataStore({
  159. url: endpointSelector + "/BemsSitePrice"
  160. }),
  161. expand: 'BemsPriceType',
  162. requireTotalCount: true,
  163. pageSize: 100
  164. });
  165. dataSource.filter([
  166. ["SiteID", "=", SiteID],
  167. "and",
  168. ["FuelTypeId", "=", FuelTypeId],
  169. "and",
  170. ["BemsPriceType.PriceTypeIdDesc", "=", $("#tabOptions").dxTabs("instance").option('selectedItem').text]
  171. ]);
  172. dataSource.sort({ getter: "PriceCode", asc: true });
  173. dataSource.load()
  174. .done(function (result) {
  175. for (var i = 0; i < result.length; i++) {
  176. var tmpYN;
  177. if (result[i].UseYN == "Y") {
  178. tmpYN = true;
  179. } else {
  180. tmpYN = false;
  181. }
  182. $("#switch" + i).dxSwitch("instance").option('value', tmpYN);
  183. }
  184. })
  185. .fail(function (error) {
  186. alert(error);
  187. });
  188. }
  189. function saveSettings() {
  190. var newmenus = [];
  191. var FuelTypeId;
  192. var priceTypeId = parseInt($("#priceSelect").dxSelectBox("instance").option('value'));
  193. if (energySelectButton == "power") {
  194. FuelTypeId = 1;
  195. } else if (energySelectButton == "gas") {
  196. FuelTypeId = 2;
  197. } else {
  198. FuelTypeId = 3;
  199. }
  200. var tmp = parseInt($("#tabOptions").dxTabs("instance").option('selectedIndex'));
  201. var seletctedTabItem = $("#tabOptions").dxTabs("instance").option('selectedItem');
  202. var selectPriceTypeId = parseInt($("#priceSelect").dxSelectBox("instance").option('value'));
  203. var selectPriceTypeIdDesc = $("#priceSelect").dxSelectBox("instance").option('text');
  204. if (selectPriceTypeId == 0) {
  205. utils.toast.show("요금제를 선택해 주세요.");
  206. return;
  207. }
  208. var dataSource = new DevExpress.data.DataSource({
  209. store: new DevExpress.data.ODataStore({
  210. url: endpointSelector + "/BemsSitePrice"
  211. }),
  212. expand: 'BemsPriceType',
  213. requireTotalCount: true,
  214. pageSize: 100
  215. });
  216. dataSource.filter([
  217. ["SiteID", "=", BWA.UserInfo.SiteId()],
  218. "and",
  219. ["FuelTypeId", "=", FuelTypeId]
  220. ]);
  221. dataSource.sort({ getter: "PriceCode", asc: true });
  222. dataSource.load()
  223. .done(function (result) {
  224. for (var i = 0; i < result.length; i++) {
  225. if (result[i].PriceTypeId == priceTypeId) {
  226. old = true;
  227. break;
  228. }
  229. }
  230. if (old)// 기존에 있는 요금표 변경 -> 기존꺼 N
  231. {
  232. BWA.api.post('BemsPriceFormula/Update', { SiteId: BWA.UserInfo.SiteId(), PriceTypeId: selectPriceTypeId, FacilityTypeId: selectFacilityTypeId, FormulaId: selectFormulaId, FacilityCode: selectFacilityCode, UseYN: 'N' }).done(function () {
  233. saving_PriceFormula = true;
  234. if (saving_PriceFormula) {
  235. BWA.api.post('BemsPriceFormula/Update', { SiteId: BWA.UserInfo.SiteId(), PriceTypeId: priceTypeId, FacilityTypeId: selectFacilityTypeId, FormulaId: selectFormulaId, FacilityCode: selectFacilityCode, UseYN: 'Y' }).done(function () {
  236. saving_PriceFormula = false;
  237. }).fail(function (error) {
  238. utils.toast.show(error);
  239. });
  240. }
  241. });
  242. old = false;
  243. }
  244. else {// 새로운 요금표 생성 -> 기존꺼 Y
  245. BWA.api.post('BemsPriceFormula/Update', { SiteId: BWA.UserInfo.SiteId(), PriceTypeId: priceTypeId, FacilityTypeId: selectFacilityTypeId, FormulaId: selectFormulaId, FacilityCode: selectFacilityCode, UseYN: 'Y' }).done(function () { });
  246. }
  247. })
  248. .fail(function (error) {
  249. alert(error);
  250. });
  251. for (var i = 0; i < priceCodeDataSource.length; i++) { //삭제후 저장
  252. var UseYN = $("#switch" + i).dxSwitch("instance").option('value');
  253. if (UseYN == true) {
  254. UseYN = 'Y';
  255. } else {
  256. UseYN = 'N';
  257. }
  258. newmenus.push({
  259. SiteId: BWA.UserInfo.SiteId(),
  260. FuelTypeId: FuelTypeId,
  261. PriceTypeId: selectPriceTypeId,
  262. PriceCode: priceCodeDataSource[i].PriceCode,
  263. UseYN: UseYN,
  264. });
  265. }
  266. for (var i = 0; i < tabsData.length; i++) {
  267. if (selectPriceTypeId == tabsData[i].id) {
  268. if (seletctedTabItem.id != selectPriceTypeId) {
  269. utils.toast.show("존재하고 있는 요금제입니다.");
  270. return;
  271. }
  272. }
  273. }
  274. if (seletctedTabItem.id != 0) {
  275. BWA.api.post('BemsSitePrice/DeleteAll', { SiteID: BWA.UserInfo.SiteId(), PriceTypeId: seletctedTabItem.id }).done(function () {
  276. BWA.api.post('BemsSitePrice/InsertAll', newmenus).done(function () {
  277. newmenus = [];
  278. }).fail(function (error) {
  279. utils.toast.show(error);
  280. });
  281. });
  282. }
  283. else {
  284. BWA.api.post('BemsSitePrice/InsertAll', newmenus).done(function () {
  285. }).fail(function (error) {
  286. utils.toast.show(error);
  287. });
  288. }
  289. tabsData[tmp].id = selectPriceTypeId;
  290. tabsData[tmp].text = selectPriceTypeIdDesc;
  291. $("#tabOptions").dxTabs("instance").option('dataSource', tabsData);
  292. setTimeout(function () { $("#tabOptions").dxTabs("instance").option('selectedIndex', 0) }, 2000);
  293. $("#tabOptions").dxTabs("instance").option('selectedIndex', 0);
  294. utils.toast.show("요금제가 저장 되었습니다.");
  295. }
  296. function getSitePriceData(SiteID, FuelTypeId) {
  297. var dataSource = new DevExpress.data.DataSource({
  298. store: new DevExpress.data.ODataStore({
  299. url: endpointSelector + "/BemsSitePrice"
  300. }),
  301. expand: 'BemsPriceType',
  302. requireTotalCount: true,
  303. pageSize: 1000
  304. });
  305. dataSource.filter([
  306. ["SiteID", "=", SiteID],
  307. "and",
  308. ["FuelTypeId", "=", FuelTypeId]
  309. ]);
  310. dataSource.sort({ getter: "PriceTypeId", asc: true });
  311. dataSource.load()
  312. .done(function (result) {
  313. if (result.length != 0) {
  314. var tmp = [];
  315. var tmpCnt = 0;
  316. tmp.push({ id: result[0].BemsPriceType.PriceTypeId, text: result[0].BemsPriceType.PriceTypeIdDesc });
  317. for (var i = 0; i < result.length; i++) {
  318. if (tmp[tmpCnt].text != result[i].BemsPriceType.PriceTypeIdDesc) {
  319. tmp.push({ id: result[i].BemsPriceType.PriceTypeId, text: result[i].BemsPriceType.PriceTypeIdDesc });
  320. tmpCnt++;
  321. }
  322. }
  323. }
  324. else {
  325. utils.toast.show("작성된 요금제가 없습니다.");
  326. }
  327. tabsData = tmp;
  328. $("#tabOptions").dxTabs("instance").option('dataSource', tabsData);
  329. $("#tabOptions").dxTabs("instance").option('selectedIndex', 0);
  330. getPriceType(FuelTypeId);
  331. getPriceCode(FuelTypeId);
  332. })
  333. .fail(function (error) {
  334. utils.toast.show(error);
  335. });
  336. }
  337. function deletePrice() {
  338. var FuelTypeId;
  339. if (energySelectButton == "power") {
  340. FuelTypeId = 1;
  341. } else if (energySelectButton == "gas") {
  342. FuelTypeId = 2;
  343. } else if (energySelectButton == "water") {
  344. FuelTypeId = 3;
  345. } else {
  346. utils.toast.show("에너지원이 선택되지 않았습니다.");
  347. }
  348. if (tabsData.length == 1) {
  349. utils.toast.show("요금제가 최소 하나 이상이어야 합니다.");
  350. return;
  351. }
  352. var selectPriceTypeId = parseInt($("#priceSelect").dxSelectBox("instance").option('value'));
  353. BWA.api.post('BemsPriceFormula/Update', { SiteId: BWA.UserInfo.SiteId(), PriceTypeId: selectPriceTypeId, FacilityTypeId: selectFacilityTypeId, FormulaId: selectFormulaId, FacilityCode: selectFacilityCode, UseYN: 'N' }).done(function () { });
  354. BWA.api.post('BemsSitePrice/DeleteAll', { SiteID: BWA.UserInfo.SiteId(), PriceTypeId: selectPriceTypeId }).done(function () {
  355. }).fail(function (error) {
  356. utils.toast.show(error);
  357. });
  358. utils.toast.show("요금제가 삭제 되었습니다.");
  359. tabsData.splice(parseInt($("#tabOptions").dxTabs("instance").option('selectedIndex')), 1);
  360. $("#tabOptions").dxTabs("instance").option('dataSource', tabsData);
  361. $("#tabOptions").dxTabs("instance").option('selectedIndex', 0);
  362. }
  363. function SelectBemsPriceFormula() {
  364. var dataSource = new DevExpress.data.DataSource({
  365. store: new DevExpress.data.ODataStore({
  366. url: endpointSelector + "/BemsPriceFormula"
  367. }),
  368. requireTotalCount: true,
  369. pageSize: 100
  370. });
  371. var priceTypeId = $("#priceSelect").dxSelectBox("instance").option('value');
  372. if (priceTypeId == null)
  373. return;
  374. dataSource.filter([
  375. ["SiteId", "=", BWA.UserInfo.SiteId()],
  376. "and",
  377. ["PriceTypeId", "=", priceTypeId]
  378. ]);
  379. dataSource.load()
  380. .done(function (result) {
  381. selectFacilityTypeId = result[0].FacilityTypeId
  382. selectFacilityCode = result[0].FacilityCode
  383. selectFormulaId = result[0].FormulaId
  384. })
  385. .fail(function (error) {
  386. utils.toast.show(error);
  387. });
  388. }
  389. function handleViewShown() {
  390. getSitePriceData(BWA.UserInfo.SiteId(), 1);
  391. $("#powerBtn").css("background-image", "linear-gradient(rgb(155,171,195) 0%,rgb(65,97,140) 100%)");
  392. $("#gasBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  393. $("#waterBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  394. init = true;
  395. }
  396. var searchViewOptions = {
  397. //templete function
  398. };
  399. function handleSearchInSearchView() {
  400. //templete function
  401. }
  402. function handleViewShowing() {
  403. //권한설정
  404. hasnotModificationPermission(!BWA.UserInfo.hasPermissionOfModification(viewInfo.viewName));
  405. }
  406. var viewModel = $.extend(BWA.CommonView.create(params, viewInfo, searchViewOptions, ko.observable(null), handleViewShown, null, handleSearchInSearchView),
  407. {
  408. viewShowing: handleViewShowing,
  409. powerButtonClicked: function () {
  410. energySelectButton = "power";
  411. $("#powerBtn").css("background-image", "linear-gradient(rgb(155,171,195) 0%,rgb(65,97,140) 100%)");//(180deg,#9babc3 0%,#41618c 100%)
  412. $("#gasBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  413. $("#waterBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  414. getSitePriceData(BWA.UserInfo.SiteId(), 1);
  415. },
  416. gasButtonClicked: function () {
  417. energySelectButton = "gas";
  418. $("#gasBtn").css("background-image", "linear-gradient(rgb(155,171,195) 0%,rgb(65,97,140) 100%)");
  419. $("#powerBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  420. $("#waterBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  421. getSitePriceData(BWA.UserInfo.SiteId(), 2);
  422. },
  423. waterButtonClicked: function () {
  424. energySelectButton = "water";
  425. $("#waterBtn").css("background-image", "linear-gradient(rgb(155,171,195) 0%,rgb(65,97,140) 100%)");
  426. $("#gasBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  427. $("#powerBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  428. getSitePriceData(BWA.UserInfo.SiteId(), 3);
  429. },
  430. saveButtonClicked: function () {
  431. DevExpress.ui.dialog.confirm("요금제를 저장 하시겠습니까?", "저장").done(function (dialogResult) {
  432. if (dialogResult)
  433. saveSettings();
  434. });
  435. },
  436. tabOptions: {
  437. dataSource: tabsData,
  438. height: 20,
  439. selectedIndex: 0,
  440. onSelectionChanged: function (e) {
  441. $("#priceSelect").dxSelectBox("instance").option('value', e.addedItems[0].id);
  442. if (e.addedItems[0].id != 0)
  443. SelectBemsPriceFormula();
  444. var FuelTypeId;
  445. if (energySelectButton == "power") {
  446. FuelTypeId = 1;
  447. } else if (energySelectButton == "gas") {
  448. FuelTypeId = 2;
  449. } else if (energySelectButton == "water") {
  450. FuelTypeId = 3;
  451. } else {
  452. utils.toast.show("에너지원이 선택되지 않았습니다.");
  453. }
  454. getPriceCode(FuelTypeId);
  455. }
  456. },
  457. addButtonClicked: function () {
  458. if ((tabsData.length == 5) && (tabsData == null)) {
  459. utils.toast.show("요금제는 추가는 최대 5개까지만 가능합니다.");
  460. } else {
  461. tabsData.push({ id: 0, text: "신규 요금제" });
  462. $("#tabOptions").dxTabs("instance").option('dataSource', tabsData);
  463. $("#tabOptions").dxTabs("instance").option('selectedIndex', tabsData.length - 1);
  464. setTimeout(function () {
  465. $("#tabOptions").dxTabs("instance").option('selectedIndex', tabsData.length - 1);
  466. }, 1000);
  467. }
  468. },
  469. removeButtonClicked: function () {
  470. if (tabsData[tabsData.length - 1].id != 0) {
  471. utils.toast.show("기존 요금제는 요금제 세부설정에서 삭제 가능합니다.");
  472. } else {
  473. tabsData.splice(tabsData.length - 1, 1);
  474. $("#tabOptions").dxTabs("instance").option('dataSource', tabsData);
  475. $("#tabOptions").dxTabs("instance").option('selectedIndex', 0);
  476. }
  477. },
  478. priceSelect: {
  479. dataSource: priceTypeDataSource,
  480. onSelectionChanged: function () {
  481. if (init)
  482. if ($("#priceSelect").dxSelectBox("instance").option('value') != 0)
  483. SelectBemsPriceFormula();
  484. }
  485. },
  486. delButtonClicked: function () {
  487. DevExpress.ui.dialog.confirm("요금제를 삭제 하시겠습니까?", "삭제").done(function (dialogResult) {
  488. if (dialogResult) {
  489. deletePrice();
  490. }
  491. });
  492. },
  493. hasnotModificationPermission: hasnotModificationPermission //권한설정
  494. });
  495. return viewModel;
  496. };