f0ad4bb5d80286ccb2b44df406c0ea2c99a45d43.svn-base 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605
  1. BemsWebApplication.PriceUsage = function (params, viewInfo) {
  2. var energySelectButton = "power";
  3. var priceDataSource;
  4. var init = false;
  5. var metaResultArray;
  6. var metaResultCnt = 0;
  7. var SiteID = BWA.UserInfo.SiteId();
  8. var endpointSelector = "";
  9. if (BemsWebApplication.config.mode == "production") {
  10. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.production;
  11. } else {
  12. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.local;
  13. }
  14. //탭 표시 요금제 Array 데이터 초기화
  15. var tabsData = [
  16. {
  17. id: "0",
  18. text: "test1"
  19. },
  20. {
  21. id: "1",
  22. text: "test2"
  23. },
  24. {
  25. id: "2",
  26. text: "test3"
  27. }
  28. ];
  29. var compareDataSource = [{
  30. dateTime: "1",
  31. paymentUsage: 0,
  32. measureUsage: 0
  33. }, {
  34. dateTime: "2",
  35. paymentUsage: 0,
  36. measureUsage: 0
  37. }, {
  38. dateTime: "3",
  39. paymentUsage: 0,
  40. measureUsage: 0
  41. }, {
  42. dateTime: "4",
  43. paymentUsage: 0,
  44. measureUsage: 0
  45. }, {
  46. dateTime: "5",
  47. paymentUsage: 0,
  48. measureUsage: 0
  49. }, {
  50. dateTime: "6",
  51. paymentUsage: 0,
  52. measureUsage: 0
  53. }, {
  54. dateTime: "7",
  55. paymentUsage: 0,
  56. measureUsage: 0
  57. }, {
  58. dateTime: "8",
  59. paymentUsage: 0,
  60. measureUsage: 0
  61. }, {
  62. dateTime: "9",
  63. paymentUsage: 0,
  64. measureUsage: 0
  65. }, {
  66. dateTime: "10",
  67. paymentUsage: 0,
  68. measureUsage: 0
  69. }, {
  70. dateTime: "11",
  71. paymentUsage: 0,
  72. measureUsage: 0
  73. }, {
  74. dateTime: "12",
  75. paymentUsage: 0,
  76. measureUsage: 0
  77. }];
  78. function getcompareData(SiteId, FuelTypeId, PayDate) {
  79. for (var i = 0; i < compareDataSource.length; i++) {
  80. compareDataSource[i].dateTime = i + 1;
  81. compareDataSource[i].paymentUsage = 0;
  82. compareDataSource[i].measureUsage = 0;
  83. }
  84. $("#compareChart").dxChart("instance").option('dataSource', compareDataSource);
  85. var opt;
  86. if (FuelTypeId == 1) {
  87. opt = [
  88. { valueField: "paymentUsage", name: "고지서 사용량", color: '#007994' },
  89. { valueField: "measureUsage", name: "실 사용량", color: '#72A7B3' }
  90. ];
  91. } else if (FuelTypeId == 2) {
  92. opt = [
  93. { valueField: "paymentUsage", name: "고지서 사용량", color: '#03C700' },
  94. { valueField: "measureUsage", name: "실 사용량", color: '#90E68E' }
  95. ];
  96. } else if (FuelTypeId == 3) {
  97. opt = [
  98. { valueField: "paymentUsage", name: "고지서 사용량", color: '#FC6D00' },
  99. { valueField: "measureUsage", name: "실 사용량", color: '#FAE0D4' }
  100. ];
  101. } else {
  102. utils.toast.show("에너지원이 선택되지 않았습니다.");
  103. }
  104. $("#compareChart").dxChart("instance").option('series', opt);
  105. var dataSource = new DevExpress.data.DataSource({
  106. store: {
  107. type: "odata",
  108. url: endpointSelector + "/BemsSitePriceHistory"
  109. },
  110. map: function (itemData) {
  111. return {
  112. SiteId: itemData.siteId,
  113. FuelTypeId: itemData.fuelTypeId,
  114. PriceTypeId: itemData.PriceTypeId,
  115. PayDate: itemData.PayDate,
  116. PayCharge: itemData.PayCharge,
  117. PriceValue: itemData.PriceValue
  118. }
  119. },
  120. requireTotalCount: true,
  121. pageSize: 10
  122. });
  123. if (FuelTypeId == 1) {
  124. dataSource.filter([
  125. ["SiteId", "=", SiteId],
  126. "and",
  127. ["FuelTypeId", "=", FuelTypeId],
  128. "and",
  129. ["PayDate", ">=", PayDate.toString() + "01"],
  130. "and",
  131. ["PayDate", "<=", PayDate.toString() + "12"],
  132. "and",
  133. ["PriceTypeId", "=", parseInt($("#tabOptions").dxTabs("instance").option('selectedItem').id)],
  134. "and",
  135. [["PriceCode", "=", "P003"]
  136. ]
  137. ]);
  138. } else if (FuelTypeId == 2) {
  139. dataSource.filter([
  140. ["SiteId", "=", SiteId],
  141. "and",
  142. ["FuelTypeId", "=", FuelTypeId],
  143. "and",
  144. ["PayDate", ">=", PayDate.toString() + "01"],
  145. "and",
  146. ["PayDate", "<=", PayDate.toString() + "12"],
  147. "and",
  148. ["PriceTypeId", "=", parseInt($("#tabOptions").dxTabs("instance").option('selectedItem').id)],
  149. "and",
  150. ["PriceCode", "=", "G001"]
  151. ]);
  152. } else if (FuelTypeId == 3) {
  153. dataSource.filter([
  154. ["SiteId", "=", SiteId],
  155. "and",
  156. ["FuelTypeId", "=", FuelTypeId],
  157. "and",
  158. ["PayDate", ">=", PayDate.toString() + "01"],
  159. "and",
  160. ["PayDate", "<=", PayDate.toString() + "12"],
  161. "and",
  162. ["PriceTypeId", "=", parseInt($("#tabOptions").dxTabs("instance").option('selectedItem').id)],
  163. "and",
  164. ["PriceCode", "=", "W007"]
  165. ]);
  166. } else {
  167. utils.toast.show("선택된 에너지원이 없습니다.");
  168. }
  169. dataSource.group("PayDate");
  170. dataSource.sort({ getter: "PayDate", asc: true });
  171. dataSource.load()
  172. .done(function (result) {
  173. for (var i = 0; i < result.length; i++) {
  174. var month;
  175. if (result[i].items[0].PayDate.substr(4, 1) == "0") {
  176. month = result[i].items[0].PayDate.substr(5, 1);
  177. } else {
  178. month = result[i].items[0].PayDate.substr(4, 2);
  179. }
  180. if (FuelTypeId == 1) {
  181. if (result[i].items[0].PriceValue == "")
  182. result[i].items[0].PriceValue = "0";
  183. compareDataSource[month - 1].paymentUsage = parseFloat(result[i].items[0].PriceValue.replace(/,/gi, ""));
  184. } else {
  185. compareDataSource[month - 1].paymentUsage = parseFloat(result[i].items[0].PriceValue.replace(/,/gi, ""));
  186. }
  187. }
  188. var priceTypeId = parseInt($("#tabOptions").dxTabs("instance").option('selectedItem').id);
  189. var dataSourceFormula = new DevExpress.data.DataSource({
  190. store: {
  191. type: "odata",
  192. url: endpointSelector + "/BemsPriceFormula"
  193. },
  194. requireTotalCount: true,
  195. pageSize: 100
  196. });
  197. dataSourceFormula.filter([
  198. ["SiteId", "=", SiteId],
  199. "and",
  200. ["PriceTypeId", "=", priceTypeId], //전력 시설ID
  201. "and",
  202. ["UseYN", "=", "Y"]
  203. ]);
  204. dataSourceFormula.load()
  205. .done(function (resultFormula) {
  206. var dataSource2 = new DevExpress.data.DataSource({
  207. store: {
  208. type: "odata",
  209. url: endpointSelector + "/BemsFormulaParameter"
  210. },
  211. requireTotalCount: true,
  212. pageSize: 100
  213. });
  214. dataSource2.filter([
  215. ["SiteId", "=", SiteId],
  216. "and",
  217. ["FacilityCode", "=", resultFormula[0].FacilityCode], //전력 시설ID
  218. "and",
  219. ["FormulaId", "=", resultFormula[0].FormulaId],
  220. "and",
  221. ["FacilityTypeId", "=", resultFormula[0].FacilityTypeId]
  222. ]);
  223. dataSource2.sort({ getter: "ParameterId", asc: true });
  224. dataSource2.load()
  225. .done(function (result2) {
  226. metaResultArray = new Array(result2.length);
  227. for (var t in result2) {
  228. metaResultArray[t] = new Array(5);
  229. }
  230. for (var i in result2) {
  231. metaResultArray[i][0] = result2[i].SiteId;
  232. metaResultArray[i][1] = result2[i].FacilityTypeId;
  233. metaResultArray[i][2] = result2[i].FormulaId;
  234. metaResultArray[i][3] = result2[i].ParameterFacilityCode;
  235. metaResultArray[i][4] = result2[i].ParameterPropertyId;
  236. }
  237. getMeasureUsage(SiteId, FuelTypeId, metaResultArray[metaResultCnt], metaResultArray.length, PayDate);
  238. })
  239. .fail(function (error) {
  240. utils.toast.show(error);
  241. });
  242. })
  243. .fail(function (error) {
  244. utils.toast.show(error);
  245. });
  246. })
  247. .fail(function (error) {
  248. utils.toast.show(error);
  249. });
  250. }
  251. function getMeasureUsage(SiteId, FuelTypeId, dataArrayElement, recursiveCnt, payDate) {
  252. var tmpDate = $("#startDatePicker").dxDateBox("instance").option('value');
  253. var dataSourceHistory = new DevExpress.data.DataSource({
  254. store: {
  255. type: "odata",
  256. url: endpointSelector + "/BemsSitePriceHistory"
  257. },
  258. requireTotalCount: true,
  259. pageSize: 1000
  260. });
  261. if (FuelTypeId == 1) {
  262. dataSourceHistory.filter([
  263. ["SiteId", "=", SiteId],
  264. "and",
  265. ["FuelTypeId", "=", FuelTypeId],
  266. "and",
  267. ["PayDate", ">=", payDate.toString() + "01"],
  268. "and",
  269. ["PayDate", "<=", payDate.toString() + "12"],
  270. "and",
  271. ["PriceTypeId", "=", parseInt($("#tabOptions").dxTabs("instance").option('selectedItem').id)],
  272. "and",
  273. [["PriceCode", "=", "P003"]
  274. ]
  275. ]);
  276. } else if (FuelTypeId == 2) {
  277. dataSourceHistory.filter([
  278. ["SiteId", "=", SiteId],
  279. "and",
  280. ["FuelTypeId", "=", FuelTypeId],
  281. "and",
  282. ["PayDate", ">=", payDate.toString() + "01"],
  283. "and",
  284. ["PayDate", "<=", payDate.toString() + "12"],
  285. "and",
  286. ["PriceTypeId", "=", parseInt($("#tabOptions").dxTabs("instance").option('selectedItem').id)],
  287. "and",
  288. ["PriceCode", "=", "G001"]
  289. ]);
  290. } else if (FuelTypeId == 3) {
  291. dataSourceHistory.filter([
  292. ["SiteId", "=", SiteId],
  293. "and",
  294. ["FuelTypeId", "=", FuelTypeId],
  295. "and",
  296. ["PayDate", ">=", payDate.toString() + "01"],
  297. "and",
  298. ["PayDate", "<=", payDate.toString() + "12"],
  299. "and",
  300. ["PriceTypeId", "=", parseInt($("#tabOptions").dxTabs("instance").option('selectedItem').id)],
  301. "and",
  302. ["PriceCode", "=", "W007"]
  303. ]);
  304. } else {
  305. utils.toast.show("선택된 에너지원이 없습니다.");
  306. }
  307. dataSourceHistory.group("PayDate");
  308. dataSourceHistory.sort({ getter: "PayDate", asc: true });
  309. dataSourceHistory.load()
  310. .done(function (resultHistory) {
  311. if (resultHistory.length == 0) {
  312. utils.toast.show("히스토리 데이터가 없습니다.");
  313. }
  314. var dataSource = new DevExpress.data.DataSource({
  315. store: {
  316. type: "odata",
  317. url: endpointSelector + "/BemsMonitoringPointHistoryDaily"
  318. },
  319. requireTotalCount: true,
  320. pageSize: 1000
  321. });
  322. dataSource.filter([
  323. ["SiteId", "=", dataArrayElement[0]],
  324. "and",
  325. ["FacilityCode", "=", dataArrayElement[3]],
  326. "and",
  327. ["PropertyId", "=", dataArrayElement[4]],
  328. "and",
  329. ["CreatedDateTime", ">=", new Date(payDate.toString(), 0, 1, 0, 0, 0)],
  330. "and",
  331. ["CreatedDateTime", "<=", new Date(payDate.toString(), 11, 31, 23, 59, 59)]
  332. ]);
  333. dataSource.sort({ getter: "CreatedDateTime", asc: true });
  334. dataSource.load()
  335. .done(function (result) {
  336. for (var i in result) {
  337. compareDataSource[(result[i].CreatedDateTime.getMonth()).toString()].measureUsage = compareDataSource[(result[i].CreatedDateTime.getMonth()).toString()].measureUsage + parseFloat(result[i].DailyValue.toString());
  338. }
  339. recursiveCnt--;
  340. if (recursiveCnt >= 1) {
  341. metaResultCnt++;
  342. getMeasureUsage(SiteId, FuelTypeId, metaResultArray[metaResultCnt], recursiveCnt, payDate);
  343. } else {
  344. $("#compareChart").dxChart("instance").option('dataSource', compareDataSource);
  345. var maxValue = 0;
  346. for (var i = 0; i < compareDataSource.length; i++) {
  347. if (compareDataSource[i].paymentUsage > maxValue) {
  348. maxValue = compareDataSource[i].paymentUsage;
  349. } else if (compareDataSource[i].measureUsage > maxValue) {
  350. maxValue = compareDataSource[i].measureUsage;
  351. } else {
  352. maxValue = maxValue;
  353. }
  354. }
  355. var valAxis = $("#compareChart").dxChart("instance").option('valueAxis');
  356. valAxis.max = parseInt(maxValue * 1.10);
  357. var tmp = valAxis.max.toString().length - 2;
  358. var zero = "";
  359. for (var i = 0; i < tmp; i++) {
  360. zero = zero + "0";
  361. }
  362. valAxis.max = parseInt(valAxis.max.toString().substr(0, 2) + zero);
  363. valAxis.tickInterval = valAxis.max / 10;
  364. var label;
  365. if (FuelTypeId == 1) {
  366. label = {
  367. customizeText: function () {
  368. return this.value + 'kWh';
  369. }
  370. }
  371. } else {
  372. label = {
  373. customizeText: function () {
  374. return this.value + 'm3';
  375. }
  376. }
  377. }
  378. valAxis.label = label;
  379. $("#compareChart").dxChart("instance").option('valueAxis', valAxis);
  380. metaResultCnt = 0;
  381. }
  382. return true;
  383. })
  384. .fail(function (error) {
  385. utils.toast.show(error);
  386. });
  387. }).fail(function (error) {
  388. utils.toast.show(error);
  389. });
  390. }
  391. function setTabData(SiteID, FuelTypeId) {
  392. var dataSource = new DevExpress.data.DataSource({
  393. store: new DevExpress.data.ODataStore({
  394. url: endpointSelector + "/BemsSitePrice"
  395. }),
  396. expand: ['BemsPriceType'],
  397. requireTotalCount: true,
  398. pageSize: 1000
  399. });
  400. dataSource.filter([
  401. ["SiteID", "=", SiteID],
  402. "and",
  403. ["FuelTypeId", "=", FuelTypeId]
  404. ]);
  405. dataSource.sort({ getter: "FuelTypeId", asc: true });
  406. dataSource.load()
  407. .done(function (result) {
  408. var tmp = [];
  409. tmp.push({ id: result[0].BemsPriceType.PriceTypeId, text: result[0].BemsPriceType.PriceTypeIdDesc });
  410. for (var i = 0; i < result.length; i++) {
  411. var resultCnt;
  412. for (var j = 0; j < tmp.length; j++) {
  413. if (tmp[j].text.indexOf(result[i].BemsPriceType.PriceTypeIdDesc) != -1) {
  414. resultCnt++;
  415. }
  416. }
  417. if (resultCnt == 0)
  418. tmp.push({ id: result[i].BemsPriceType.PriceTypeId, text: result[i].BemsPriceType.PriceTypeIdDesc });
  419. resultCnt = 0;
  420. }
  421. tabsData = tmp;
  422. $("#tabOptions").dxTabs("instance").option('dataSource', tabsData);
  423. if (!init) {
  424. $("#tabOptions").dxTabs("instance").option('selectedIndex', 0);
  425. var tmpDate = $("#startDatePicker").dxDateBox("instance").option('value');
  426. getcompareData(SiteID, FuelTypeId, tmpDate.getFullYear());
  427. init = true;
  428. } else {
  429. $("#tabOptions").dxTabs("instance").option('selectedIndex', 0);
  430. }
  431. });
  432. }
  433. function numberWithCommas(x) {
  434. return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  435. }
  436. function handleViewShown() {
  437. setTabData(SiteID, 1); //초기화 전력 P038 청구요금
  438. $("#powerBtn").css("background-image", "linear-gradient(180deg,#9babc3 0%,#41618c 100%)");
  439. $("#gasBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  440. $("#waterBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  441. }
  442. var searchViewOptions = {
  443. };
  444. function handleSearchInSearchView() {
  445. }
  446. var now = new Date();
  447. var beforeNow = now;
  448. tmpYear = now.getFullYear();
  449. beforeNow.setFullYear(tmpYear - 1);
  450. now = new Date();
  451. var selectEnergy = "전력";
  452. var viewModel = $.extend(BWA.CommonView.create(params, viewInfo, searchViewOptions, ko.observable(null), handleViewShown, null, handleSearchInSearchView),
  453. {
  454. startDatePicker: {
  455. pickerType: "calendar",
  456. value: now,
  457. formatString: "yyyy년",
  458. maxZoomLevel: "decade",
  459. width: "9%",
  460. onValueChanged: function () {
  461. var tmpDate = $("#startDatePicker").dxDateBox("instance").option('value');
  462. if (energySelectButton == "power") {
  463. init = false;
  464. setTabData(SiteID, 1);
  465. } else if (energySelectButton == "gas") {
  466. init = false;
  467. setTabData(SiteID, 2);
  468. } else if (energySelectButton == "water") {
  469. init = false;
  470. setTabData(SiteID, 3);
  471. } else {
  472. utils.toast.show("에너지원이 선택되지 않았습니다.");
  473. }
  474. }
  475. },
  476. compareChart: {
  477. dataSource: compareDataSource,
  478. barWidth: 0.5,
  479. commonSeriesSettings: {
  480. argumentField: "dateTime",
  481. type: "bar"
  482. },
  483. series: ko.observable([
  484. { valueField: "paymentUsage", name: '고지서 사용량', color: '#5F8B95' },
  485. { valueField: "measureUsage", name: '실 사용량', color: '#007994' }
  486. ]),
  487. legend: {
  488. verticalAlignment: "top",
  489. horizontalAlignment: "center",
  490. position: "outside",
  491. border: { visible: false }
  492. },
  493. valueAxis: ko.observable({
  494. visible: true,
  495. label: {
  496. customizeText: function () {
  497. return numberWithCommas(this.value).toString() + 'kWh';
  498. }
  499. },
  500. min: 0,
  501. max: 100000000,
  502. valueType: 'numeric',
  503. tickInterval: 5000000
  504. }),
  505. argumentAxis: ko.observable({
  506. visible: true,
  507. label: {
  508. customizeText: function () {
  509. return this.value + '월';
  510. }
  511. },
  512. min: 1,
  513. max: 12,
  514. valueType: 'numeric',
  515. tickInterval: 1
  516. }),
  517. "export": {
  518. enabled: true
  519. },
  520. tooltip: {
  521. enabled: true,
  522. //format: 'largeNumber',
  523. customizeTooltip: function (point) {
  524. return {
  525. text: numberWithCommas(point.value.toFixed(2))
  526. };
  527. }
  528. }
  529. },
  530. powerButtonClicked: function () {
  531. energySelectButton = "power";
  532. $("#powerBtn").css("background-image", "linear-gradient(180deg,#9babc3 0%,#41618c 100%)");
  533. $("#gasBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  534. $("#waterBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  535. selectEnergy = "전력";
  536. init = false;
  537. setTabData(SiteID, 1);
  538. },
  539. gasButtonClicked: function () {
  540. energySelectButton = "gas";
  541. $("#gasBtn").css("background-image", "linear-gradient(180deg,#9babc3 0%,#41618c 100%)");
  542. $("#powerBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  543. $("#waterBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  544. selectEnergy = "가스";
  545. init = false;
  546. setTabData(SiteID, 2);
  547. },
  548. waterButtonClicked: function () {
  549. energySelectButton = "water";
  550. $("#waterBtn").css("background-image", "linear-gradient(180deg,#9babc3 0%,#41618c 100%)");
  551. $("#gasBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  552. $("#powerBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  553. selectEnergy = "수도";
  554. init = false;
  555. setTabData(SiteID, 3);
  556. },
  557. tabOptions: {
  558. dataSource: tabsData,
  559. height: 20,
  560. selectedIndex: 0,
  561. onSelectionChanged: function (e) {
  562. if (init) {
  563. var FuelTypeId;
  564. if (selectEnergy == "전력") {
  565. FuelTypeId = 1;
  566. } else if (selectEnergy == "가스") {
  567. FuelTypeId = 2;
  568. } else if (selectEnergy == "수도") {
  569. FuelTypeId = 3;
  570. } else {
  571. utils.toast.show("에너지원이 선택되지 않았습니다.");
  572. }
  573. var tmpDate = $("#startDatePicker").dxDateBox("instance").option('value');
  574. var month = tmpDate.getMonth() + 1;
  575. if (month < 10) {
  576. month = "0" + month.toString();
  577. }
  578. getcompareData(SiteID, FuelTypeId, tmpDate.getFullYear());
  579. }
  580. }
  581. }
  582. });
  583. return viewModel;
  584. };