4e50a92b95198f47fb216725101b9f34bda08dd0.svn-base 33 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762
  1. BemsWebApplication.PriceCompare2 = function (params, viewInfo) {
  2. var energySelectButton = "power";
  3. var priceDataSource;
  4. var init = false;
  5. var endpointSelector = "";
  6. if (BemsWebApplication.config.mode == "production") {
  7. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.production;
  8. } else {
  9. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.local;
  10. }
  11. //탭 표시 요금제 Array 데이터 초기화
  12. var tabsData = [
  13. {
  14. id: "0",
  15. text: "test1"
  16. },
  17. {
  18. id: "1",
  19. text: "test2"
  20. },
  21. {
  22. id: "2",
  23. text: "test3"
  24. }
  25. ];
  26. var powerDataSource = [{
  27. PriceCode: 'P038',
  28. PriceCodeDesc: "청구요금"
  29. },
  30. {
  31. PriceCode: 'P022',
  32. PriceCodeDesc: "기본요금"
  33. },
  34. {
  35. PriceCode: 'P048',
  36. PriceCodeDesc: "총사용량"
  37. }];
  38. var gasDataSource = [{
  39. PriceCode: 'G005',
  40. PriceCodeDesc: "사용요금"
  41. },
  42. {
  43. PriceCode: 'G004',
  44. PriceCodeDesc: "기본요금"
  45. },
  46. {
  47. PriceCode: 'G001',
  48. PriceCodeDesc: "사용량"
  49. }];
  50. var waterDataSource = [{
  51. PriceCode: 'W006',
  52. PriceCodeDesc: "합계요금"
  53. },
  54. {
  55. PriceCode: 'W001',
  56. PriceCodeDesc: "상수도요금"
  57. },
  58. {
  59. PriceCode: 'W002',
  60. PriceCodeDesc: "하수도요금"
  61. },
  62. {
  63. PriceCode: 'W007',
  64. PriceCodeDesc: "총사용량"
  65. }];
  66. var factorDataSource = [{
  67. PriceCode: 'P038',
  68. PriceCodeDesc: "청구요금"
  69. },
  70. {
  71. PriceCode: 'P022',
  72. PriceCodeDesc: "기본요금"
  73. },
  74. {
  75. PriceCode: 'P048',
  76. PriceCodeDesc: "총사용량"
  77. }];
  78. var compareDataSource = [{
  79. dateTime: "1",
  80. curYear: 0,
  81. preYear: 0
  82. }, {
  83. dateTime: "2",
  84. curYear: 0,
  85. preYear: 0
  86. }, {
  87. dateTime: "3",
  88. curYear: 0,
  89. preYear: 0
  90. }, {
  91. dateTime: "4",
  92. curYear: 0,
  93. preYear: 0
  94. }, {
  95. dateTime: "5",
  96. curYear: 0,
  97. preYear: 0
  98. }, {
  99. dateTime: "6",
  100. curYear: 0,
  101. preYear: 0
  102. }, {
  103. dateTime: "7",
  104. curYear: 0,
  105. preYear: 0
  106. }, {
  107. dateTime: "8",
  108. curYear: 0,
  109. preYear: 0
  110. }, {
  111. dateTime: "9",
  112. curYear: 0,
  113. preYear: 0
  114. }, {
  115. dateTime: "10",
  116. curYear: 0,
  117. preYear: 0
  118. }, {
  119. dateTime: "11",
  120. curYear: 0,
  121. preYear: 0
  122. }, {
  123. dateTime: "12",
  124. curYear: 0,
  125. preYear: 0
  126. }];
  127. function getcompareData(SiteId, FuelTypeId,PayDate) {
  128. var tmpDate = $("#startDatePicker").dxDateBox("instance").option('value');
  129. var curYear = tmpDate.getFullYear();
  130. var tmpDate2 = $("#endDatePicker").dxDateBox("instance").option('value');
  131. var curYear2 = tmpDate2.getFullYear();
  132. for (var i = 0; i < compareDataSource.length; i++) {
  133. compareDataSource[i].dateTime = i + 1;
  134. compareDataSource[i].curYear = 0;
  135. compareDataSource[i].preYear = 0;
  136. }
  137. $("#compareChart").dxChart("instance").option('dataSource', compareDataSource);
  138. var opt;
  139. if (FuelTypeId == 1) {
  140. opt = [
  141. { valueField: "curYear", name: tmpDate.getFullYear(), color: '#007994' },
  142. { valueField: "preYear", name: tmpDate2.getFullYear() , color: '#72A7B3' }
  143. ];
  144. } else if (FuelTypeId == 2) {
  145. opt = [
  146. { valueField: "curYear", name: tmpDate.getFullYear(), color: '#03C700' },
  147. { valueField: "preYear", name: tmpDate2.getFullYear(), color: '#90E68E' }
  148. ];
  149. } else if (FuelTypeId == 3) {
  150. opt = [
  151. { valueField: "curYear", name: tmpDate.getFullYear(), color: '#FC6D00' },
  152. { valueField: "preYear", name: tmpDate2.getFullYear(), color: '#FAE0D4' }
  153. ];
  154. } else {
  155. utils.toast.show("에너지원이 선택되지 않았습니다.");
  156. }
  157. $("#compareChart").dxChart("instance").option('series', opt);
  158. var dataSource = new DevExpress.data.DataSource({
  159. store: {
  160. type: "odata",
  161. url: endpointSelector + "/BemsSitePriceHistory"
  162. },
  163. map: function (itemData) {
  164. return {
  165. SiteId: itemData.siteId,
  166. FuelTypeId: itemData.fuelTypeId,
  167. PriceTypeId: itemData.PriceTypeId,
  168. PayDate: itemData.PayDate,
  169. PayCharge: itemData.PayCharge,
  170. PriceValue: itemData.PriceValue
  171. }
  172. },
  173. requireTotalCount: true,
  174. pageSize: 12
  175. });
  176. if (parseInt($("#tabOptions").dxTabs("instance").option('selectedIndex')) == -1)
  177. parseInt($("#tabOptions").dxTabs("instance").option('selectedIndex', 0))
  178. var priceCode = $("#factorSelect").dxSelectBox("instance").option('value');
  179. if (FuelTypeId == 1 && priceCode == "P048") {
  180. dataSource.filter([
  181. ["SiteId", "=", SiteId],
  182. "and",
  183. ["FuelTypeId", "=", FuelTypeId],
  184. "and",
  185. //["PayDate", ">=", (parseInt(PayDate) - 1).toString() + "01"],
  186. ["PayDate", ">=", curYear.toString() + "01"],
  187. "and",
  188. ["PayDate", "<=", curYear.toString() + "12"],
  189. "and",
  190. ["PriceTypeId", "=", parseInt($("#tabOptions").dxTabs("instance").option('selectedItem').id)],
  191. "and",
  192. [["PriceCode", "=", "P003"]
  193. ]
  194. ]);
  195. } else {
  196. dataSource.filter([
  197. ["SiteId", "=", SiteId],
  198. "and",
  199. ["FuelTypeId", "=", FuelTypeId],
  200. "and",
  201. //["PayDate", ">=", (parseInt(PayDate) - 1).toString() + "01"],
  202. ["PayDate", ">=", curYear.toString() + "01"],
  203. "and",
  204. ["PayDate", "<=", curYear.toString() + "12"],
  205. "and",
  206. ["PriceTypeId", "=", parseInt($("#tabOptions").dxTabs("instance").option('selectedItem').id)],
  207. "and",
  208. ["PriceCode", "=", priceCode]
  209. ]);
  210. }
  211. dataSource.group("PayDate");
  212. dataSource.sort({ getter: "PayDate", asc: true });
  213. dataSource.load()
  214. .done(function (result) {
  215. for (var i = 0; i < result.length; i++) {
  216. var month;
  217. if (result[i].items[0].PayDate.substr(4, 1) == "0") {
  218. month = result[i].items[0].PayDate.substr(5, 1);
  219. } else {
  220. month = result[i].items[0].PayDate.substr(4, 2);
  221. }
  222. //if (curYear == result[i].key.substr(0, 4)) {
  223. if (FuelTypeId == 1 && priceCode == "P048") {
  224. if (result[i].items[0].PriceValue == "")
  225. result[i].items[0].PriceValue = "0";
  226. compareDataSource[month - 1].curYear = parseInt(result[i].items[0].PriceValue.replace(/,/gi, ""));
  227. } else {
  228. compareDataSource[month - 1].curYear = result[i].items[0].PriceValue.replace(/,/gi, "");
  229. }
  230. //compareDataSource[month - 1].curYear = result[0].PayCharge.replace(/,/gi, "");;
  231. //} else if (curYear - 1 == result[i].key.substr(0, 4)) {
  232. // compareDataSource[month - 1].preYear = result[i].items[0].PayCharge.replace(/,/gi, "");;
  233. //}
  234. }
  235. var dataSource2 = new DevExpress.data.DataSource({
  236. store: {
  237. type: "odata",
  238. url: endpointSelector + "/BemsSitePriceHistory"
  239. },
  240. map: function (itemData) {
  241. return {
  242. SiteId: itemData.siteId,
  243. FuelTypeId: itemData.fuelTypeId,
  244. PriceTypeId: itemData.PriceTypeId,
  245. PayDate: itemData.PayDate,
  246. PayCharge: itemData.PayCharge,
  247. PriceValue: itemData.PriceValue
  248. }
  249. },
  250. requireTotalCount: true,
  251. pageSize: 12
  252. });
  253. if (FuelTypeId == 1 && priceCode == "P048") {
  254. dataSource2.filter([
  255. ["SiteId", "=", SiteId],
  256. "and",
  257. ["FuelTypeId", "=", FuelTypeId],
  258. "and",
  259. //["PayDate", ">=", (parseInt(PayDate) - 1).toString() + "01"],
  260. ["PayDate", ">=", curYear2.toString() + "01"],
  261. "and",
  262. ["PayDate", "<=", curYear2.toString() + "12"],
  263. "and",
  264. ["PriceTypeId", "=", parseInt($("#tabOptions").dxTabs("instance").option('selectedItem').id)],
  265. "and",
  266. [["PriceCode", "=", "P003"]
  267. ]
  268. ]);
  269. } else {
  270. dataSource2.filter([
  271. ["SiteId", "=", SiteId],
  272. "and",
  273. ["FuelTypeId", "=", FuelTypeId],
  274. "and",
  275. //["PayDate", ">=", (parseInt(PayDate) - 1).toString() + "01"],
  276. ["PayDate", ">=", curYear2.toString() + "01"],
  277. "and",
  278. ["PayDate", "<=", curYear2.toString() + "12"],
  279. "and",
  280. ["PriceTypeId", "=", parseInt($("#tabOptions").dxTabs("instance").option('selectedItem').id)],
  281. "and",
  282. ["PriceCode", "=", priceCode]
  283. ]);
  284. }
  285. dataSource2.group("PayDate");
  286. dataSource2.sort({ getter: "PayDate", asc: true });
  287. dataSource2.load()
  288. .done(function (result2) {
  289. for (var i = 0; i < result2.length; i++) {
  290. var month;
  291. if (result2[i].items[0].PayDate.substr(4, 1) == "0") {
  292. month = result2[i].items[0].PayDate.substr(5, 1);
  293. } else {
  294. month = result2[i].items[0].PayDate.substr(4, 2);
  295. }
  296. //if (curYear == result[i].key.substr(0, 4)) {
  297. if (FuelTypeId == 1 && priceCode == "P048") {
  298. if (result2[i].items[0].PriceValue == "")
  299. result2[i].items[0].PriceValue = "0";
  300. compareDataSource[month - 1].preYear = parseInt(result2[i].items[0].PriceValue.replace(/,/gi, ""));
  301. } else {
  302. compareDataSource[month - 1].preYear = result2[i].items[0].PriceValue.replace(/,/gi, "");
  303. }
  304. //compareDataSource[month - 1].preYear = result2[0].PayCharge.replace(/,/gi, "");
  305. //} else if (curYear - 1 == result[i].key.substr(0, 4)) {
  306. // compareDataSource[month - 1].preYear = result[i].items[0].PayCharge.replace(/,/gi, "");;
  307. //}
  308. }
  309. $("#compareChart").dxChart("instance").option('dataSource', compareDataSource);
  310. var maxValue = 0;
  311. for (var i = 0; i < compareDataSource.length; i++) {
  312. if (parseFloat(compareDataSource[i].curYear) > maxValue) {
  313. maxValue = compareDataSource[i].curYear;
  314. }
  315. if (parseFloat(compareDataSource[i].preYear) > maxValue) {
  316. maxValue = compareDataSource[i].preYear;
  317. }
  318. }
  319. var valAxis = $("#compareChart").dxChart("instance").option('valueAxis');
  320. valAxis.max = parseInt(maxValue * 1.10);
  321. var tmp = valAxis.max.toString().length - 2;
  322. var zero = "";
  323. for(var i =0; i < tmp;i++){
  324. zero = zero + "0";
  325. }
  326. valAxis.max = parseInt(valAxis.max.toString().substr(0, 2) + zero);
  327. //valAxis.tickInterval = Math.floor(parseInt(maxValue * 1.10)) / 10;
  328. valAxis.tickInterval = valAxis.max / 10;
  329. $("#compareChart").dxChart("instance").option('valueAxis', valAxis);
  330. // $("#compareChart").dxChart({dataSource: compareDataSource});
  331. })
  332. .fail(function (error) {
  333. utils.toast.show(error);
  334. });
  335. })
  336. .fail(function (error) {
  337. utils.toast.show(error);
  338. });
  339. }
  340. function DataDistinct(data) {
  341. var tmpArray = data;
  342. var resultArray;
  343. for (var i = 0; i < tmpArray.length; i++) {
  344. //if(tmpArray[i].){
  345. //}
  346. }
  347. }
  348. function setTabData(SiteID, FuelTypeId, InitPriceCode) {
  349. var tmpDate = $("#startDatePicker").dxDateBox("instance").option('value');
  350. var dataSource = new DevExpress.data.DataSource({
  351. store: new DevExpress.data.ODataStore({
  352. url: endpointSelector + "/BemsSitePrice"
  353. }),
  354. expand: ['BemsPriceType'],
  355. requireTotalCount: true,
  356. pageSize: 1000
  357. });
  358. dataSource.filter([
  359. ["SiteID", "=", SiteID],
  360. "and",
  361. ["FuelTypeId", "=", FuelTypeId]
  362. ]);
  363. dataSource.sort({ getter: "FuelTypeId", asc: true });
  364. dataSource.load()
  365. .done(function (result) {
  366. var tmp = [];
  367. tmp.push({ id: result[0].BemsPriceType.PriceTypeId, text: result[0].BemsPriceType.PriceTypeIdDesc});
  368. for (var i = 0; i < result.length; i++) {
  369. var resultCnt;
  370. for (var j = 0; j < tmp.length; j++) {
  371. if (tmp[j].text.indexOf(result[i].BemsPriceType.PriceTypeIdDesc) != -1) {
  372. resultCnt++;
  373. }
  374. }
  375. if (resultCnt == 0)
  376. tmp.push({ id: result[i].BemsPriceType.PriceTypeId, text: result[i].BemsPriceType.PriceTypeIdDesc});
  377. resultCnt = 0;
  378. }
  379. tabsData = tmp;
  380. $("#tabOptions").dxTabs("instance").option('dataSource', tabsData);
  381. if (!init) {
  382. $("#tabOptions").dxTabs("instance").option('selectedIndex', 0);
  383. init = true;
  384. } else {
  385. }
  386. //getPriceData(BWA.UserInfo.SiteId(), FuelTypeId);
  387. if (InitPriceCode == null)
  388. InitPriceCode = 'P038'; //초기 PriceCode 전력 P038 청구요금
  389. setFactorSelect(InitPriceCode);
  390. getcompareData(BWA.UserInfo.SiteId(), FuelTypeId, tmpDate.getFullYear());
  391. });
  392. }
  393. function setFactorSelect(PriceCode) {
  394. $("#factorSelect").dxSelectBox("instance").option('dataSource', factorDataSource);
  395. $("#factorSelect").dxSelectBox("instance").option('displayExpr', 'PriceCodeDesc');
  396. $("#factorSelect").dxSelectBox("instance").option('valueExpr', "PriceCode");
  397. $("#factorSelect").dxSelectBox("instance").option('value', PriceCode);
  398. }
  399. function numberWithCommas(x) {
  400. return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  401. }
  402. function handleViewShown() {
  403. setTabData(BWA.UserInfo.SiteId(), 1, 'P038'); //초기화 전력 P038 청구요금
  404. //setFactorSelect('P038');
  405. //getPriceData(BWA.UserInfo.SiteId(), 1);
  406. //getcompareData(BWA.UserInfo.SiteId(), 1, tmpDate.getFullYear());
  407. }
  408. var searchViewOptions = {
  409. };
  410. function handleSearchInSearchView() {
  411. }
  412. var now = new Date();
  413. var beforeNow = now;
  414. tmpYear = now.getFullYear();
  415. beforeNow.setFullYear(tmpYear - 1);
  416. now = new Date();
  417. var selectEnergy = "전력";
  418. //var tmpDate = $("#startDatePicker").dxDateBox("instance").option('value');
  419. /*var CustomTheme = {
  420. name: 'CustomTheme'
  421. };
  422. DevExpress.viz.registerTheme(CustomTheme, 'generic.light');*/
  423. //DevExpress.ui.themes.current('generic.dark');
  424. var viewModel = $.extend(BWA.CommonView.create(params, viewInfo, searchViewOptions, ko.observable(null), handleViewShown, null, handleSearchInSearchView),
  425. {
  426. startDatePicker : {
  427. pickerType: "calendar",
  428. value: now,
  429. formatString: "yyyy년",
  430. maxZoomLevel: "decade",
  431. width: "9%",
  432. onValueChanged: function () {
  433. var tmpDate = $("#startDatePicker").dxDateBox("instance").option('value');
  434. var chartSeries = $("#compareChart").dxChart("instance").option('series');
  435. chartSeries[0].name = tmpDate.getFullYear();
  436. //chartSeries[1].name = tmpDate.getFullYear() - 1;
  437. $("#compareChart").dxChart("instance").option('series', chartSeries);
  438. /*for (var i = 0; i < compareDataSource.length; i++) {
  439. compareDataSource[i].curYear = compareDataSource[i].curYear + 1000;
  440. compareDataSource[i].preYear = compareDataSource[i].preYear + 1000;
  441. }
  442. $("#compareChart").dxChart("instance").option('dataSource', compareDataSource);*/
  443. //if ($("#powerBtn").css("background-image") == "linear-gradient(180deg, rgb(155, 171, 195) 0%, rgb(65, 97, 140) 100%)") {
  444. if (energySelectButton == "power") {
  445. //getPriceData(BWA.UserInfo.SiteId(), 1);
  446. //getcompareData(BWA.UserInfo.SiteId(), 1, tmpDate.getFullYear());
  447. init = false;
  448. setTabData(BWA.UserInfo.SiteId(), 1, $("#factorSelect").dxSelectBox("instance").option('value'));
  449. //setFactorSelect('P038');
  450. //} else if ($("#gasBtn").css("background-image") == "linear-gradient(180deg, rgb(155, 171, 195) 0%, rgb(65, 97, 140) 100%)") {
  451. } else if (energySelectButton == "gas") {
  452. //getPriceData(BWA.UserInfo.SiteId(), 2);
  453. //getcompareData(BWA.UserInfo.SiteId(), 2, tmpDate.getFullYear());
  454. init = false;
  455. setTabData(BWA.UserInfo.SiteId(), 2, $("#factorSelect").dxSelectBox("instance").option('value'));
  456. //setFactorSelect('P038');
  457. //} else if ($("#waterBtn").css("background-image") == "linear-gradient(180deg, rgb(155, 171, 195) 0%, rgb(65, 97, 140) 100%)") {
  458. } else if (energySelectButton == "water") {
  459. //getPriceData(BWA.UserInfo.SiteId(), 3);
  460. //getcompareData(BWA.UserInfo.SiteId(), 3, tmpDate.getFullYear());
  461. init = false;
  462. setTabData(BWA.UserInfo.SiteId(), 3, $("#factorSelect").dxSelectBox("instance").option('value'));
  463. //setFactorSelect('P038');
  464. } else {
  465. utils.toast.show("에너지원이 선택되지 않았습니다.");
  466. }
  467. }
  468. },
  469. endDatePicker: {
  470. pickerType: "calendar",
  471. value: beforeNow,
  472. formatString: "yyyy년",
  473. maxZoomLevel: "decade",
  474. width: "9%",
  475. onValueChanged: function () {
  476. var tmpDate = $("#endDatePicker").dxDateBox("instance").option('value');
  477. var chartSeries = $("#compareChart").dxChart("instance").option('series');
  478. //chartSeries[0].name = tmpDate.getFullYear();
  479. chartSeries[1].name = tmpDate.getFullYear();
  480. $("#compareChart").dxChart("instance").option('series', chartSeries);
  481. /*for (var i = 0; i < compareDataSource.length; i++) {
  482. compareDataSource[i].curYear = compareDataSource[i].curYear + 1000;
  483. compareDataSource[i].preYear = compareDataSource[i].preYear + 1000;
  484. }
  485. $("#compareChart").dxChart("instance").option('dataSource', compareDataSource);*/
  486. //if ($("#powerBtn").css("background-image") == "linear-gradient(180deg, rgb(155, 171, 195) 0%, rgb(65, 97, 140) 100%)") {
  487. if (energySelectButton == "power") {
  488. //getPriceData(BWA.UserInfo.SiteId(), 1);
  489. //getcompareData(BWA.UserInfo.SiteId(), 1, tmpDate.getFullYear());
  490. init = false;
  491. setTabData(BWA.UserInfo.SiteId(), 1, $("#factorSelect").dxSelectBox("instance").option('value'));
  492. //setFactorSelect('P038');
  493. //} else if ($("#gasBtn").css("background-image") == "linear-gradient(180deg, rgb(155, 171, 195) 0%, rgb(65, 97, 140) 100%)") {
  494. } else if (energySelectButton == "gas") {
  495. //getPriceData(BWA.UserInfo.SiteId(), 2);
  496. //getcompareData(BWA.UserInfo.SiteId(), 2, tmpDate.getFullYear());
  497. init = false;
  498. setTabData(BWA.UserInfo.SiteId(), 2, $("#factorSelect").dxSelectBox("instance").option('value'));
  499. //setFactorSelect('P038');
  500. //} else if ($("#waterBtn").css("background-image") == "linear-gradient(180deg, rgb(155, 171, 195) 0%, rgb(65, 97, 140) 100%)") {
  501. } else if (energySelectButton == "water") {
  502. //getPriceData(BWA.UserInfo.SiteId(), 3);
  503. //getcompareData(BWA.UserInfo.SiteId(), 3, tmpDate.getFullYear());
  504. init = false;
  505. setTabData(BWA.UserInfo.SiteId(), 3, $("#factorSelect").dxSelectBox("instance").option('value'));
  506. //setFactorSelect('P038');
  507. } else {
  508. utils.toast.show("에너지원이 선택되지 않았습니다.");
  509. }
  510. }
  511. },
  512. compareChart: {
  513. dataSource: compareDataSource,
  514. barWidth: 0.5,
  515. commonSeriesSettings: {
  516. argumentField: "dateTime",
  517. type: "bar"
  518. },
  519. series: ko.observable([
  520. { valueField: "curYear", name: new Date().getFullYear(), color: '#5F8B95' },
  521. { valueField: "preYear", name: new Date().getFullYear() - 1, color: '#007994' }
  522. ]),
  523. legend: {
  524. verticalAlignment: "top",
  525. horizontalAlignment: "center",
  526. position: "outside",
  527. border: { visible: false }
  528. },
  529. valueAxis: ko.observable({
  530. visible: true,
  531. label: {
  532. customizeText: function () {
  533. return numberWithCommas(this.value).toString() + '원';
  534. }
  535. },
  536. min: 0,
  537. max: 100000000,
  538. valueType: 'numeric',
  539. tickInterval: 5000000
  540. }),
  541. argumentAxis: ko.observable({
  542. visible: true,
  543. label: {
  544. customizeText: function () {
  545. return this.value + '월';
  546. }
  547. },
  548. min: 1,
  549. max: 12,
  550. valueType: 'numeric',
  551. tickInterval: 1
  552. }),
  553. "export": {
  554. enabled: true
  555. },
  556. tooltip: {
  557. enabled: true,
  558. //format: 'largeNumber',
  559. customizeTooltip: function (point) {
  560. return {
  561. text: numberWithCommas(point.value.toFixed(2))
  562. };
  563. }
  564. }
  565. },
  566. powerButtonClicked: function () {
  567. energySelectButton = "power";
  568. $("#powerBtn").css("background-image", "linear-gradient(180deg,#9babc3 0%,#41618c 100%)");
  569. $("#gasBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  570. $("#waterBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  571. selectEnergy = "전력";
  572. /*priceDataSource = [
  573. { text: "일반용전력(을)", icon: 'check'},
  574. { text: "산업용전력(을)"},
  575. { text: "심야전력(을)2"}
  576. ];*/
  577. //$("#priceTab").dxTabs("instance").option('items', priceDataSource);
  578. //$("#priceTab").dxTabs("instance").option('selectedIndex', ko.observable(0));
  579. //$("#priceTab").dxTabs("instance").option('tabIndex', ko.observable(0));
  580. //getPriceData(BWA.UserInfo.SiteId(), 1);
  581. //getcompareData(BWA.UserInfo.SiteId(), 1, tmpDate.getFullYear());
  582. init = false;
  583. factorDataSource = powerDataSource;
  584. setTabData(BWA.UserInfo.SiteId(), 1, 'P038'); //P038 전력 청구요금
  585. //setFactorSelect('P038');
  586. },
  587. gasButtonClicked: function () {
  588. energySelectButton = "gas";
  589. $("#gasBtn").css("background-image", "linear-gradient(180deg,#9babc3 0%,#41618c 100%)");
  590. $("#powerBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  591. $("#waterBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  592. selectEnergy = "가스";
  593. /*priceDataSource = [
  594. { text: "가스요금1", icon: 'check' },
  595. { text: "가스요금2" }
  596. ];*/
  597. //$("#priceTab").dxTabs("instance").option('items', priceDataSource);
  598. //$("#priceTab").dxTabs("instance").option('selectedIndex', ko.observable(0));
  599. //$("#priceTab").dxTabs("instance").option('tabIndex', ko.observable(0));
  600. //getPriceData(BWA.UserInfo.SiteId(), 2);
  601. //getcompareData(BWA.UserInfo.SiteId(), 2, tmpDate.getFullYear());
  602. init = false;
  603. factorDataSource = gasDataSource;
  604. setTabData(BWA.UserInfo.SiteId(), 2, 'G005'); //G005 가스 사용요금
  605. //setFactorSelect('P038');
  606. },
  607. waterButtonClicked: function () {
  608. energySelectButton = "water";
  609. $("#waterBtn").css("background-image", "linear-gradient(180deg,#9babc3 0%,#41618c 100%)");
  610. $("#gasBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  611. $("#powerBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  612. selectEnergy = "수도";
  613. /*priceDataSource = [
  614. { text: "수도요금1", icon: 'check' }
  615. ];*/
  616. //$("#priceTab").dxTabs("instance").option('items', priceDataSource);
  617. //$("#priceTab").dxTabs("instance").option('selectedIndex', ko.observable(0));
  618. //$("#priceTab").dxTabs("instance").option('tabIndex', ko.observable(0));
  619. //getPriceData(BWA.UserInfo.SiteId(), 3);
  620. //getcompareData(BWA.UserInfo.SiteId(), 3, tmpDate.getFullYear());
  621. init = false;
  622. factorDataSource = waterDataSource;
  623. setTabData(BWA.UserInfo.SiteId(), 3, 'W006'); //수도 W006 합계요금
  624. //setFactorSelect('P038');
  625. },
  626. tabOptions: {
  627. //theme: 'CustomTheme',
  628. dataSource: tabsData,
  629. height: 20,
  630. //selectedIndex: 0,
  631. onSelectionChanged: function (e) {
  632. //$("#priceSelect").dxSelectBox("instance").option('value', e.addedItems[0].id);
  633. //selectedItem = e.addedItems[0];
  634. if (init) {
  635. var FuelTypeId;
  636. if (selectEnergy == "전력") {
  637. FuelTypeId = 1;
  638. } else if (selectEnergy == "가스") {
  639. FuelTypeId = 2;
  640. } else if (selectEnergy == "수도") {
  641. FuelTypeId = 3;
  642. } else {
  643. utils.toast.show("에너지원이 선택되지 않았습니다.");
  644. }
  645. var tmpDate = $("#startDatePicker").dxDateBox("instance").option('value');
  646. var month = tmpDate.getMonth() + 1;
  647. if (month < 10) {
  648. month = "0" + month.toString();
  649. }
  650. var endDay = 32 - new Date(tmpDate.getFullYear(), tmpDate.getMonth(), 32).getDate();
  651. //$("#tabOptions").dxTabs("instance").option('selectedIndex', 0);
  652. getcompareData(BWA.UserInfo.SiteId(), FuelTypeId, tmpDate.getFullYear());
  653. }
  654. }
  655. },
  656. factorSelect: {
  657. dataSource: factorDataSource,
  658. onValueChanged: function (e) {
  659. var selectFactor = $("#factorSelect").dxSelectBox("instance").option('value');
  660. var FuelTypeId;
  661. if (selectEnergy == "전력") {
  662. FuelTypeId = 1;
  663. if (selectFactor == 'P048') {
  664. var tmp = $("#compareChart").dxChart("instance").option('valueAxis');
  665. tmp.label = {
  666. customizeText: function () {
  667. return numberWithCommas(this.value).toString() + 'kWh';
  668. }
  669. }
  670. $("#compareChart").dxChart("instance").option('valueAxis', tmp);
  671. } else {
  672. var tmp = $("#compareChart").dxChart("instance").option('valueAxis');
  673. tmp.label = {
  674. customizeText: function () {
  675. return numberWithCommas(this.value).toString() + '원';
  676. }
  677. }
  678. $("#compareChart").dxChart("instance").option('valueAxis', tmp);
  679. }
  680. } else if (selectEnergy == "가스") {
  681. FuelTypeId = 2;
  682. if (selectFactor == 'G001') {
  683. var tmp = $("#compareChart").dxChart("instance").option('valueAxis');
  684. tmp.label = {
  685. customizeText: function () {
  686. return numberWithCommas(this.value).toString() + 'm3';
  687. }
  688. }
  689. $("#compareChart").dxChart("instance").option('valueAxis', tmp);
  690. } else {
  691. var tmp = $("#compareChart").dxChart("instance").option('valueAxis');
  692. tmp.label = {
  693. customizeText: function () {
  694. return numberWithCommas(this.value).toString() + '원';
  695. }
  696. }
  697. $("#compareChart").dxChart("instance").option('valueAxis', tmp);
  698. }
  699. } else if (selectEnergy == "수도") {
  700. FuelTypeId = 3;
  701. if (selectFactor == 'W007') {
  702. var tmp = $("#compareChart").dxChart("instance").option('valueAxis');
  703. tmp.label = {
  704. customizeText: function () {
  705. return numberWithCommas(this.value).toString() + 'm3';
  706. }
  707. }
  708. $("#compareChart").dxChart("instance").option('valueAxis', tmp);
  709. } else {
  710. var tmp = $("#compareChart").dxChart("instance").option('valueAxis');
  711. tmp.label = {
  712. customizeText: function () {
  713. return numberWithCommas(this.value).toString() + '원';
  714. }
  715. }
  716. $("#compareChart").dxChart("instance").option('valueAxis', tmp);
  717. }
  718. } else {
  719. utils.toast.show("에너지원이 선택되지 않았습니다.");
  720. }
  721. var tmpDate = $("#startDatePicker").dxDateBox("instance").option('value');
  722. var month = tmpDate.getMonth() + 1;
  723. if (month < 10) {
  724. month = "0" + month.toString();
  725. }
  726. var endDay = 32 - new Date(tmpDate.getFullYear(), tmpDate.getMonth(), 32).getDate();
  727. var test = $("#tabOptions").dxTabs("instance").option('selectedIndex');
  728. getcompareData(BWA.UserInfo.SiteId(), FuelTypeId, tmpDate.getFullYear());
  729. }
  730. }
  731. });
  732. return viewModel;
  733. };