414c076da6e0a9fdd213a65c3ebd8c9062550fcb.svn-base 75 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602
  1. BemsWebApplication.PlanConsumeGoal = function (params, viewInfo) {
  2. 'use strict';
  3. var endpointSelector = "";
  4. if (BemsWebApplication.config.mode == "production") {
  5. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.production;
  6. } else {
  7. endpointSelector = new DevExpress.EndpointSelector(BemsWebApplication.config.endpoints).config.db.local;
  8. }
  9. ////// 전역 변수 설정 부
  10. // 2019.04.17 : 그리드 도표 작업 : 팝업창 추가 ~~~
  11. // 팝업창뷰 보이기 속성 제어용 변수 선언
  12. var DataGridPopup_Visible = ko.observable(false);
  13. // 그래프 출력 이후 엑셀출력을 위한 팝업창을 위해 임시 저장용 배열 선언
  14. var dataArrayresult = ko.observableArray();
  15. // ~~~ 2019.04.17 : 그리드 도표 작업 : 팝업창 추가
  16. var m3calValue;
  17. var applyonoff = false;
  18. var SiteId = BWA.UserInfo.SiteId();
  19. var ServiceTypeId = 1;
  20. var visiblePopup = ko.observable(false);
  21. var dataSource = [{
  22. dateTime: "1",
  23. Prediction: 0, //예측
  24. Goal: 0 //목표
  25. }, {
  26. dateTime: "2",
  27. Prediction: 0,
  28. Goal: 0
  29. }, {
  30. dateTime: "3",
  31. Prediction: 0,
  32. Goal: 0
  33. }, {
  34. dateTime: "4",
  35. Prediction: 0,
  36. Goal: 0
  37. }, {
  38. dateTime: "5",
  39. Prediction: 0,
  40. Goal: 0
  41. }, {
  42. dateTime: "6",
  43. Prediction: 0,
  44. Goal: 0
  45. }, {
  46. dateTime: "7",
  47. Prediction: 0,
  48. Goal: 0
  49. }, {
  50. dateTime: "8",
  51. Prediction: 0,
  52. Goal: 0
  53. }, {
  54. dateTime: "9",
  55. Prediction: 0,
  56. Goal: 0
  57. }, {
  58. dateTime: "10",
  59. Prediction: 0,
  60. Goal: 0
  61. }, {
  62. dateTime: "11",
  63. Prediction: 0,
  64. Goal: 0
  65. }, {
  66. dateTime: "12",
  67. Prediction: 0,
  68. Goal: 0
  69. }, {
  70. dateTime: "13",
  71. Prediction: 0,
  72. Goal: 0
  73. }, {
  74. dateTime: "14",
  75. Prediction: 0,
  76. Goal: 0
  77. }, {
  78. dateTime: "15",
  79. Prediction: 0,
  80. Goal: 0
  81. }, {
  82. dateTime: "16",
  83. Prediction: 0,
  84. Goal: 0
  85. }, {
  86. dateTime: "17",
  87. Prediction: 0,
  88. Goal: 0
  89. }, {
  90. dateTime: "18",
  91. Prediction: 0,
  92. Goal: 0
  93. }, {
  94. dateTime: "19",
  95. Prediction: 0,
  96. Goal: 0
  97. }, {
  98. dateTime: "20",
  99. Prediction: 0,
  100. Goal: 0
  101. }, {
  102. dateTime: "21",
  103. Prediction: 0,
  104. Goal: 0
  105. }, {
  106. dateTime: "22",
  107. Prediction: 0,
  108. Goal: 0
  109. }, {
  110. dateTime: "23",
  111. Prediction: 0,
  112. Goal: 0
  113. }, {
  114. dateTime: "24",
  115. Prediction: 0,
  116. Goal: 0
  117. }, {
  118. dateTime: "25",
  119. Prediction: 0,
  120. Goal: 0
  121. }, {
  122. dateTime: "26",
  123. Prediction: 0,
  124. Goal: 0
  125. }, {
  126. dateTime: "27",
  127. Prediction: 0,
  128. Goal: 0
  129. }, {
  130. dateTime: "28",
  131. Prediction: 0,
  132. Goal: 0
  133. }, {
  134. dateTime: "29",
  135. Prediction: 0,
  136. Goal: 0
  137. }, {
  138. dateTime: "30",
  139. Prediction: 0,
  140. Goal: 0
  141. }, {
  142. dateTime: "31",
  143. Prediction: 0,
  144. Goal: 0
  145. }];
  146. var FuelID = [
  147. { id: 1, fuel: "전기" },
  148. { id: 2, fuel: "가스" },
  149. { id: 3, fuel: "수도" }
  150. ];
  151. var energySelectButton = 1;
  152. var yearSelectButton = "Month";
  153. var TodayAdd = new Date();
  154. var SelectedYear = 0; // 사용자가 선택한 연도
  155. var SelectedMonth = 0; // 사용자가 선택한 월
  156. ////// 전역 변수 설정 부
  157. function numberWithCommas(x) {
  158. return x.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ",");
  159. }
  160. // 2019.04.17 : 해당월의 일수 구하기 ~~~
  161. function LastDayOfMonth(year, month) {
  162. var _firstDayOfMonth = [year, month, 1].join('-');
  163. var _firstDayOfMonthDate = new Date(_firstDayOfMonth);
  164. _firstDayOfMonthDate.setMonth(_firstDayOfMonthDate.getMonth() + 1);
  165. _firstDayOfMonthDate.setDate(_firstDayOfMonthDate.getDate() - 1);
  166. return _firstDayOfMonthDate.getDate();
  167. }
  168. // 2019.04.17 : 해당월의 일수 구하기 ~~~
  169. // 2019.04.17 : 그리드 도표 작업 : 팝업창 추가 ~~~
  170. function DataGridPopup_ButtonClick() {
  171. // DevExpress.ui.notify("날짜가 일치하지 않는 데이타가 존재합니다", "fail", 1000);
  172. DataGridPopup_Visible(true);
  173. }
  174. function handlePopupShown() {
  175. var ArraySize; //해당 월의 길이
  176. dataArrayresult = dataSource.slice();// 데이타소스 복제
  177. if (yearSelectButton == "Month") {
  178. ArraySize = LastDayOfMonth(SelectedYear, SelectedMonth);
  179. viewModel.PlanGoalOptions.columns[0].caption = "일";
  180. }
  181. else {
  182. ArraySize = 12;
  183. viewModel.PlanGoalOptions.columns[0].caption = "월";
  184. }
  185. dataArrayresult.splice(ArraySize, 31 - ArraySize); // 불필요 데이터 삭제
  186. energySelectButton = $("#energySelect").dxSelectBox("instance").option('value');
  187. if (energySelectButton == 1) {
  188. viewModel.PlanGoalOptions.columns[1].caption = "예측 전력(kWh)";
  189. viewModel.PlanGoalOptions.columns[2].caption = "목표 전력(kWh)";
  190. }
  191. else if (energySelectButton == 2) {
  192. viewModel.PlanGoalOptions.columns[1].caption = "예측 가스(m3)";
  193. viewModel.PlanGoalOptions.columns[2].caption = "목표 가스(m3)";
  194. }
  195. else {
  196. viewModel.PlanGoalOptions.columns[1].caption = "예측 수도(m3)";
  197. viewModel.PlanGoalOptions.columns[2].caption = "목표 수도(m3)";
  198. }
  199. $("#PlanGoal_Container").dxDataGrid("instance").option("dataSource", dataArrayresult);
  200. // 팝업창 갱신
  201. DataGridPopup_Visible(true);
  202. }
  203. // ~~~ 2019.04.17 : 그리드 도표 작업 : 팝업창 추가
  204. function handleViewShowing() {
  205. var getTOEDataSource = new DevExpress.data.DataSource({
  206. store: {
  207. type: "odata",
  208. url: endpointSelector + "/BemsFactorToe"
  209. },
  210. requireTotalCount: true,
  211. pageSize: 3
  212. });
  213. getTOEDataSource.load()
  214. .done(function (Result) {
  215. var powertoe, gastoe;
  216. if (Result.length != 0) {
  217. for (var i = 0; i < Result.length; i++) {
  218. if (Result[i].FuelTypeId == 1) {
  219. powertoe = Result[i].TotalFactor;
  220. }
  221. if (Result[i].FuelTypeId == 2) {
  222. gastoe = Result[i].TotalFactor;
  223. }
  224. }
  225. if (powertoe != null && gastoe != null)
  226. m3calValue = gastoe / powertoe;
  227. }
  228. else {
  229. utils.toast.show("[BemsFactorToe] 데이터가 없습니다.");
  230. }
  231. })
  232. .fail(function (error) {
  233. utils.toast.show("[BemsFactorToe] 데이터를 불러오는데 실패 하였습니다.");
  234. });
  235. }
  236. function getAllData() {
  237. for (var i = 0; i < dataSource.length; i++) {
  238. dataSource[i].dateTime = i + 1;
  239. dataSource[i].Prediction = 0;
  240. dataSource[i].Goal = 0;
  241. }
  242. var tmpDate = $("#startDatePicker").dxDateBox("instance").option('value');
  243. $("#sideBarChart").dxChart("instance").option('commonSeriesSettings').type = "stackedBar";
  244. var poweropt = [
  245. { valueField: "Prediction", name: "예측 전력", stack: "prediction", color: '#007994' },
  246. { valueField: "Goal", name: "목표 전력", stack: "goal", color: '#5F8B95' }];
  247. var gasopt = [
  248. { valueField: "Prediction", name: "예측 가스", stack: "prediction", color: '#007994' },
  249. { valueField: "Goal", name: "목표 가스", stack: "goal", color: '#5F8B95' }];
  250. var wateropt = [
  251. { valueField: "Prediction", name: "예측 수도", stack: "prediction", color: '#007994' },
  252. { valueField: "Goal", name: "목표 수도", stack: "goal", color: '#5F8B95' }];
  253. if (energySelectButton == 1) {
  254. $("#sideBarChart").dxChart("instance").option('series', poweropt);
  255. }
  256. else if (energySelectButton == 2) {
  257. $("#sideBarChart").dxChart("instance").option('series', gasopt);
  258. }
  259. else {
  260. $("#sideBarChart").dxChart("instance").option('series', wateropt);
  261. }
  262. // 2019.04.17 사용자가 선택한 연도, 월 업데이트 ~~~
  263. SelectedYear = tmpDate.getFullYear();
  264. SelectedMonth = tmpDate.getMonth() + 1;
  265. // ~~~ 2019.04.17 사용자가 선택한 연도, 월 업데이트
  266. var DataSource = new DevExpress.data.DataSource({
  267. store: {
  268. type: "odata",
  269. url: endpointSelector + "/BemsEnergyDaily"
  270. },
  271. requireTotalCount: true,
  272. pageSize: 400
  273. });
  274. if (yearSelectButton == "Month") {
  275. DataSource.filter([
  276. ["SiteId", "=", SiteId],
  277. "and",
  278. ["ServiceTypeId", "=", ServiceTypeId],
  279. "and",
  280. ["FuelTypeId", "=", energySelectButton], //전력 시설ID
  281. "and",
  282. ["CreatedDate", ">=", new Date(tmpDate.getFullYear(), tmpDate.getMonth(), 1, 0, 0)],
  283. "and",
  284. ["CreatedDate", "<", new Date(tmpDate.getFullYear(), tmpDate.getMonth() + 1, 1, 0, 0)]
  285. ]);
  286. }
  287. else {
  288. DataSource.filter([
  289. ["SiteId", "=", SiteId],
  290. "and",
  291. ["ServiceTypeId", "=", ServiceTypeId],
  292. "and",
  293. ["FuelTypeId", "=", energySelectButton], //전력 시설ID
  294. "and",
  295. ["CreatedDate", ">=", new Date(tmpDate.getFullYear(), 0, 1, 0, 0)],
  296. "and",
  297. ["CreatedDate", "<", new Date(tmpDate.getFullYear() + 1, 0, 1, 0, 0)]
  298. ]);
  299. }
  300. DataSource.sort({ getter: "CreatedDate", asc: true });
  301. DataSource.load()
  302. .done(function (Result) {
  303. if (Result.length != 0) {
  304. if (yearSelectButton == "Month") {
  305. for (var i = 0; i < Result.length; i++) {
  306. if (Result[i].Prediction != null) {
  307. if (energySelectButton != 2) {
  308. dataSource[i].Prediction = Result[i].Prediction;
  309. }
  310. else {
  311. dataSource[i].Prediction = Result[i].Prediction / m3calValue;
  312. }
  313. }
  314. else
  315. dataSource[i].Prediction = 0;
  316. if (Result[i].Goal != null) {
  317. if (energySelectButton != 2) {
  318. dataSource[i].Goal = Result[i].Goal;
  319. }
  320. else {
  321. dataSource[i].Goal = Result[i].Goal / m3calValue;
  322. }
  323. }
  324. else
  325. dataSource[i].Goal = 0;
  326. }
  327. }
  328. else {
  329. for (var i = 0; i < Result.length; i++) {
  330. switch (Result[i].CreatedDate.getMonth()) {
  331. case 0: {
  332. if (Result[i].Prediction != null) {
  333. if (energySelectButton != 2) {
  334. dataSource[0].Prediction += Result[i].Prediction;
  335. }
  336. else {
  337. dataSource[0].Prediction += Result[i].Prediction / m3calValue;
  338. }
  339. }
  340. if (Result[i].Goal != null) {
  341. if (energySelectButton != 2) {
  342. dataSource[0].Goal += Result[i].Goal;
  343. }
  344. else {
  345. dataSource[0].Goal += Result[i].Goal / m3calValue;
  346. }
  347. }
  348. break;
  349. }
  350. case 1: {
  351. if (Result[i].Prediction != null) {
  352. if (energySelectButton != 2) {
  353. dataSource[1].Prediction += Result[i].Prediction;
  354. }
  355. else {
  356. dataSource[1].Prediction += Result[i].Prediction / m3calValue;
  357. }
  358. }
  359. if (Result[i].Goal != null) {
  360. if (energySelectButton != 2) {
  361. dataSource[1].Goal += Result[i].Goal;
  362. }
  363. else {
  364. dataSource[1].Goal += Result[i].Goal / m3calValue;
  365. }
  366. }
  367. break;
  368. }
  369. case 2: {
  370. if (Result[i].Prediction != null) {
  371. if (energySelectButton != 2) {
  372. dataSource[2].Prediction += Result[i].Prediction;
  373. }
  374. else {
  375. dataSource[2].Prediction += Result[i].Prediction / m3calValue;
  376. }
  377. }
  378. if (Result[i].Goal != null) {
  379. if (energySelectButton != 2) {
  380. dataSource[2].Goal += Result[i].Goal;
  381. }
  382. else {
  383. dataSource[2].Goal += Result[i].Goal / m3calValue;
  384. }
  385. }
  386. break;
  387. }
  388. case 3: {
  389. if (Result[i].Prediction != null) {
  390. if (energySelectButton != 2) {
  391. dataSource[3].Prediction += Result[i].Prediction;
  392. }
  393. else {
  394. dataSource[3].Prediction += Result[i].Prediction / m3calValue;
  395. }
  396. }
  397. if (Result[i].Goal != null) {
  398. if (energySelectButton != 2) {
  399. dataSource[3].Goal += Result[i].Goal;
  400. }
  401. else {
  402. dataSource[3].Goal += Result[i].Goal / m3calValue;
  403. }
  404. }
  405. break;
  406. }
  407. case 4: {
  408. if (Result[i].Prediction != null) {
  409. if (energySelectButton != 2) {
  410. dataSource[4].Prediction += Result[i].Prediction;
  411. }
  412. else {
  413. dataSource[4].Prediction += Result[i].Prediction / m3calValue;
  414. }
  415. }
  416. if (Result[i].Goal != null) {
  417. if (energySelectButton != 2) {
  418. dataSource[4].Goal += Result[i].Goal;
  419. }
  420. else {
  421. dataSource[4].Goal += Result[i].Goal / m3calValue;
  422. }
  423. }
  424. break;
  425. }
  426. case 5: {
  427. if (Result[i].Prediction != null) {
  428. if (energySelectButton != 2) {
  429. dataSource[5].Prediction += Result[i].Prediction;
  430. }
  431. else {
  432. dataSource[5].Prediction += Result[i].Prediction / m3calValue;
  433. }
  434. }
  435. if (Result[i].Goal != null) {
  436. if (energySelectButton != 2) {
  437. dataSource[5].Goal += Result[i].Goal;
  438. }
  439. else {
  440. dataSource[5].Goal += Result[i].Goal / m3calValue;
  441. }
  442. }
  443. break;
  444. }
  445. case 6: {
  446. if (Result[i].Prediction != null) {
  447. if (energySelectButton != 2) {
  448. dataSource[6].Prediction += Result[i].Prediction;
  449. }
  450. else {
  451. dataSource[6].Prediction += Result[i].Prediction / m3calValue;
  452. }
  453. }
  454. if (Result[i].Goal != null) {
  455. if (energySelectButton != 2) {
  456. dataSource[6].Goal += Result[i].Goal;
  457. }
  458. else {
  459. dataSource[6].Goal += Result[i].Goal / m3calValue;
  460. }
  461. }
  462. break;
  463. }
  464. case 7: {
  465. if (Result[i].Prediction != null) {
  466. if (energySelectButton != 2) {
  467. dataSource[7].Prediction += Result[i].Prediction;
  468. }
  469. else {
  470. dataSource[7].Prediction += Result[i].Prediction / m3calValue;
  471. }
  472. }
  473. if (Result[i].Goal != null) {
  474. if (energySelectButton != 2) {
  475. dataSource[7].Goal += Result[i].Goal;
  476. }
  477. else {
  478. dataSource[7].Goal += Result[i].Goal / m3calValue;
  479. }
  480. }
  481. break;
  482. }
  483. case 8: {
  484. if (Result[i].Prediction != null) {
  485. if (energySelectButton != 2) {
  486. dataSource[8].Prediction += Result[i].Prediction;
  487. }
  488. else {
  489. dataSource[8].Prediction += Result[i].Prediction / m3calValue;
  490. }
  491. }
  492. if (Result[i].Goal != null) {
  493. if (energySelectButton != 2) {
  494. dataSource[8].Goal += Result[i].Goal;
  495. }
  496. else {
  497. dataSource[8].Goal += Result[i].Goal / m3calValue;
  498. }
  499. }
  500. break;
  501. }
  502. case 9: {
  503. if (Result[i].Prediction != null) {
  504. if (energySelectButton != 2) {
  505. dataSource[9].Prediction += Result[i].Prediction;
  506. }
  507. else {
  508. dataSource[9].Prediction += Result[i].Prediction / m3calValue;
  509. }
  510. }
  511. if (Result[i].Goal != null) {
  512. if (energySelectButton != 2) {
  513. dataSource[9].Goal += Result[i].Goal;
  514. }
  515. else {
  516. dataSource[9].Goal += Result[i].Goal / m3calValue;
  517. }
  518. }
  519. break;
  520. }
  521. case 10: {
  522. if (Result[i].Prediction != null) {
  523. if (energySelectButton != 2) {
  524. dataSource[10].Prediction += Result[i].Prediction;
  525. }
  526. else {
  527. dataSource[10].Prediction += Result[i].Prediction / m3calValue;
  528. }
  529. }
  530. if (Result[i].Goal != null) {
  531. if (energySelectButton != 2) {
  532. dataSource[10].Goal += Result[i].Goal;
  533. }
  534. else {
  535. dataSource[10].Goal += Result[i].Goal / m3calValue;
  536. }
  537. }
  538. break;
  539. }
  540. case 11: {
  541. if (Result[i].Prediction != null) {
  542. if (energySelectButton != 2) {
  543. dataSource[11].Prediction += Result[i].Prediction;
  544. }
  545. else {
  546. dataSource[11].Prediction += Result[i].Prediction / m3calValue;
  547. }
  548. }
  549. if (Result[i].Goal != null) {
  550. if (energySelectButton != 2) {
  551. dataSource[11].Goal += Result[i].Goal;
  552. }
  553. else {
  554. dataSource[11].Goal += Result[i].Goal / m3calValue; // 2019.04.23 오류수정
  555. }
  556. }
  557. break;
  558. }
  559. }
  560. }
  561. }
  562. $("#LoadPanel").dxLoadPanel('instance').option('visible', false);
  563. $("#sideBarChart").dxChart("instance").option('dataSource', dataSource);
  564. }
  565. else {
  566. utils.toast.show("[BemsEnergyDaily]데이터가 없습니다.");
  567. $("#LoadPanel").dxLoadPanel('instance').option('visible', false);
  568. }
  569. })
  570. .fail(function (error) {
  571. utils.toast.show("데이터를 불러오는데 실패 하였습니다.");
  572. $("#LoadPanel").dxLoadPanel('instance').option('visible', false);
  573. });
  574. }
  575. function handleViewShown() {
  576. $("#LoadPanel").dxLoadPanel({
  577. message: '로딩 중...',
  578. showIndicator: true,
  579. visible: false
  580. });
  581. $("#monthBtn").dxButton({
  582. text: "월",
  583. onClick: function () {
  584. $("#LoadPanel").dxLoadPanel('instance').option('visible', true);
  585. yearSelectButton = "Month";
  586. energySelectButton = $("#energySelect").dxSelectBox("instance").option('value');
  587. $("#startDatePicker").dxDateBox("instance").option("formatString", "yyyy년 MM월");
  588. $("#startDatePicker").dxDateBox("instance").option("maxZoomLevel", "year");
  589. $("#monthBtn").css("background-image", "linear-gradient(180deg,#9babc3 0%,#41618c 100%)");
  590. $("#yearBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  591. $("#startDatePicker").dxDateBox("instance").option("width", "140px");
  592. var argAxis = $("#sideBarChart").dxChart("instance").option('argumentAxis');
  593. var tmpDate = $("#startDatePicker").dxDateBox("instance").option('value');
  594. argAxis.max = 32 - new Date(tmpDate.getFullYear(), tmpDate.getMonth(), 32).getDate();
  595. var labelObj = {
  596. customizeText: function () {
  597. return this.value + '일';
  598. }
  599. };
  600. argAxis.label = labelObj;
  601. $("#sideBarChart").dxChart("instance").option('argumentAxis', argAxis);
  602. if (energySelectButton == 1) {
  603. var valAxis = this.chartOptions.valueAxis();
  604. valAxis.min = 0;
  605. //valAxis.max = 15000;
  606. //valAxis.tickInterval = 1000;
  607. var labelObj = {
  608. customizeText: function () {
  609. if (this.value >= 1000 && this.value < 10000) {
  610. this.value = this.value.toString().substring(0, 1) + 'K';
  611. } else if (this.value >= 10000) {
  612. this.value = this.value.toString().substring(0, 2) + 'K';
  613. } else {
  614. this.value = this.value;
  615. }
  616. return this.value + ' kWh';
  617. }
  618. };
  619. valAxis.label = labelObj;
  620. this.chartOptions.valueAxis(valAxis);
  621. }
  622. else if (energySelectButton == 2) {
  623. var valAxis = this.chartOptions.valueAxis();
  624. valAxis.min = 0;
  625. //valAxis.max = 15000;
  626. //valAxis.tickInterval = 200;
  627. var labelObj = {
  628. customizeText: function () {
  629. if (this.value >= 1000 && this.value < 10000) {
  630. this.value = this.value.toString().substring(0, 1) + 'K';
  631. } else if (this.value >= 10000) {
  632. this.value = this.value.toString().substring(0, 2) + 'K';
  633. } else {
  634. this.value = this.value;
  635. }
  636. return this.value + ' m3';
  637. }
  638. };
  639. valAxis.label = labelObj;
  640. this.chartOptions.valueAxis(valAxis);
  641. }
  642. else {
  643. var valAxis = this.chartOptions.valueAxis();
  644. valAxis.min = 0;
  645. //valAxis.max = 100;
  646. //valAxis.tickInterval = 10;
  647. var labelObj = {
  648. customizeText: function () {
  649. if (this.value >= 1000) {
  650. this.value = this.value.toString().substring(0, 1) + 'K';
  651. } else {
  652. this.value = this.value;
  653. }
  654. return this.value + ' m3';
  655. }
  656. };
  657. valAxis.label = labelObj;
  658. this.chartOptions.valueAxis(valAxis);
  659. }
  660. getAllData();
  661. }
  662. });
  663. $("#yearBtn").dxButton({
  664. text: "년",
  665. onClick: function () {
  666. $("#LoadPanel").dxLoadPanel('instance').option('visible', true);
  667. yearSelectButton = "Year";
  668. energySelectButton = $("#energySelect").dxSelectBox("instance").option('value');
  669. $("#startDatePicker").dxDateBox("instance").option("formatString", "yyyy년");
  670. $("#startDatePicker").dxDateBox("instance").option("maxZoomLevel", "decade");
  671. $("#yearBtn").css("background-image", "linear-gradient(180deg,#9babc3 0%,#41618c 100%)");
  672. $("#monthBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  673. $("#startDatePicker").dxDateBox("instance").option("width", "100px");
  674. var argAxis = $("#sideBarChart").dxChart("instance").option('argumentAxis');
  675. argAxis.max = 12;
  676. var labelObj = {
  677. customizeText: function () {
  678. return this.value + '월';
  679. }
  680. };
  681. argAxis.label = labelObj;
  682. $("#sideBarChart").dxChart("instance").option('argumentAxis', argAxis);
  683. if (energySelectButton == 1) {
  684. var valAxis = this.chartOptions.valueAxis();
  685. valAxis.min = 0;
  686. //valAxis.max = 400000;
  687. //valAxis.tickInterval = 50000;
  688. var labelObj = {
  689. customizeText: function () {
  690. if (this.value >= 1000 && this.value < 10000) {
  691. this.value = this.value.toString().substring(0, 1) + 'K';
  692. } else if (this.value >= 10000 && this.value < 100000) {
  693. this.value = this.value.toString().substring(0, 2) + 'K';
  694. } else if (this.value >= 100000) {
  695. this.value = this.value.toString().substring(0, 3) + 'K';
  696. } else {
  697. this.value = this.value;
  698. }
  699. return this.value + ' kWh';
  700. }
  701. };
  702. valAxis.label = labelObj;
  703. this.chartOptions.valueAxis(valAxis);
  704. }
  705. else if (energySelectButton == 2) {
  706. var valAxis = this.chartOptions.valueAxis();
  707. valAxis.min = 0;
  708. //valAxis.max = 400000;
  709. //valAxis.tickInterval = 40000;
  710. var labelObj = {
  711. customizeText: function () {
  712. if (this.value >= 1000 && this.value < 10000) {
  713. this.value = this.value.toString().substring(0, 1) + 'K';
  714. } else if (this.value >= 10000 && this.value < 100000) {
  715. this.value = this.value.toString().substring(0, 2) + 'K';
  716. } else if (this.value >= 100000 && this.value < 1000000) {
  717. this.value = this.value.toString().substring(0, 3) + 'K';
  718. } else if (this.value >= 1000000 && this.value < 10000000) {
  719. this.value = this.value.toString().substring(0, 1) + 'M';
  720. } else if (this.value >= 10000000 && this.value < 100000000) {
  721. this.value = this.value.toString().substring(0, 2) + 'M';
  722. } else if (this.value >= 100000000 && this.value < 1000000000) {
  723. this.value = this.value.toString().substring(0, 3) + 'M';
  724. } else if (this.value >= 1000000000) {
  725. this.value = this.value.toString().substring(0, 4) + 'M';
  726. } else {
  727. this.value = this.value;
  728. }
  729. return this.value + ' m3';
  730. }
  731. };
  732. valAxis.label = labelObj;
  733. this.chartOptions.valueAxis(valAxis);
  734. }
  735. else {
  736. var valAxis = this.chartOptions.valueAxis();
  737. valAxis.min = 0;
  738. //valAxis.max = 2500;
  739. //valAxis.tickInterval = 250;
  740. var labelObj = {
  741. customizeText: function () {
  742. //if (this.value >= 1000 && this.value < 10000) {
  743. // this.value = this.value.toString().substring(0, 1) + 'K';
  744. //} else if (this.value >= 10000) {
  745. // this.value = this.value.toString().substring(0, 2) + 'K';
  746. //} else {
  747. // this.value = this.value;
  748. //}
  749. return this.value + ' m3';
  750. }
  751. };
  752. valAxis.label = labelObj;
  753. this.chartOptions.valueAxis(valAxis);
  754. }
  755. getAllData();
  756. }
  757. });
  758. $("#startDatePicker").dxDateBox({
  759. value: TodayAdd,
  760. maxZoomLevel: 'year',
  761. formatString: "yyyy년 MM월",
  762. onValueChanged: function (data) {
  763. var tmpDate = data.value;
  764. $("#LoadPanel").dxLoadPanel('instance').option('visible', true);
  765. if (yearSelectButton == "Month") {
  766. argAxis.max = 32 - new Date(tmpDate.getFullYear(), tmpDate.getMonth(), 32).getDate();
  767. var labelObj = {
  768. customizeText: function () {
  769. return this.value + '일';
  770. }
  771. };
  772. } else {
  773. argAxis.max = 12;
  774. var labelObj = {
  775. customizeText: function () {
  776. return this.value + '월';
  777. }
  778. };
  779. }
  780. argAxis.label = labelObj;
  781. $("#sideBarChart").dxChart("instance").option('argumentAxis', argAxis);
  782. if (yearSelectButton == "Month") {
  783. if (energySelectButton == 1) {
  784. var valAxis = this.chartOptions.valueAxis();
  785. valAxis.min = 0;
  786. //valAxis.max = 15000;
  787. //valAxis.tickInterval = 1000;
  788. var labelObj = {
  789. customizeText: function () {
  790. if (this.value >= 1000 && this.value < 10000) {
  791. this.value = this.value.toString().substring(0, 1) + 'K';
  792. } else if (this.value >= 10000) {
  793. this.value = this.value.toString().substring(0, 2) + 'K';
  794. } else {
  795. this.value = this.value;
  796. }
  797. return this.value + ' kWh';
  798. }
  799. };
  800. valAxis.label = labelObj;
  801. this.chartOptions.valueAxis(valAxis);
  802. }
  803. else if (energySelectButton == 2) {
  804. var valAxis = this.chartOptions.valueAxis();
  805. valAxis.min = 0;
  806. //valAxis.max = 15000;
  807. //valAxis.tickInterval = 500;
  808. var labelObj = {
  809. customizeText: function () {
  810. if (this.value >= 1000 && this.value < 10000) {
  811. this.value = this.value.toString().substring(0, 1) + 'K';
  812. } else if (this.value >= 10000) {
  813. this.value = this.value.toString().substring(0, 2) + 'K';
  814. } else {
  815. this.value = this.value;
  816. }
  817. return this.value + ' m3';
  818. }
  819. };
  820. valAxis.label = labelObj;
  821. this.chartOptions.valueAxis(valAxis);
  822. }
  823. else {
  824. var valAxis = this.chartOptions.valueAxis();
  825. valAxis.min = 0;
  826. //valAxis.max = 100;
  827. //valAxis.tickInterval = 10;
  828. var labelObj = {
  829. customizeText: function () {
  830. if (this.value >= 1000) {
  831. this.value = this.value.toString().substring(0, 1) + 'K';
  832. } else {
  833. this.value = this.value;
  834. }
  835. return this.value + ' m3';
  836. }
  837. };
  838. valAxis.label = labelObj;
  839. this.chartOptions.valueAxis(valAxis);
  840. }
  841. }
  842. else {
  843. if (energySelectButton == 1) {
  844. var valAxis = this.chartOptions.valueAxis();
  845. valAxis.min = 0;
  846. //valAxis.max = 400000;
  847. //valAxis.tickInterval = 50000;
  848. var labelObj = {
  849. customizeText: function () {
  850. if (this.value >= 1000 && this.value < 10000) {
  851. this.value = this.value.toString().substring(0, 1) + 'K';
  852. } else if (this.value >= 10000 && this.value < 100000) {
  853. this.value = this.value.toString().substring(0, 2) + 'K';
  854. } else if (this.value >= 100000) {
  855. this.value = this.value.toString().substring(0, 3) + 'K';
  856. } else {
  857. this.value = this.value;
  858. }
  859. return this.value + ' kWh';
  860. }
  861. };
  862. valAxis.label = labelObj;
  863. this.chartOptions.valueAxis(valAxis);
  864. }
  865. else if (energySelectButton == 2) {
  866. var valAxis = this.chartOptions.valueAxis();
  867. valAxis.min = 0;
  868. //valAxis.max = 400000;
  869. //valAxis.tickInterval = 40000;
  870. var labelObj = {
  871. customizeText: function () {
  872. if (this.value >= 1000 && this.value < 10000) {
  873. this.value = this.value.toString().substring(0, 1) + 'K';
  874. } else if (this.value >= 10000 && this.value < 100000) {
  875. this.value = this.value.toString().substring(0, 2) + 'K';
  876. } else if (this.value >= 100000 && this.value < 1000000) {
  877. this.value = this.value.toString().substring(0, 3) + 'K';
  878. } else if (this.value >= 1000000 && this.value < 10000000) {
  879. this.value = this.value.toString().substring(0, 1) + 'M';
  880. } else if (this.value >= 10000000 && this.value < 100000000) {
  881. this.value = this.value.toString().substring(0, 2) + 'M';
  882. } else if (this.value >= 100000000 && this.value < 1000000000) {
  883. this.value = this.value.toString().substring(0, 3) + 'M';
  884. } else if (this.value >= 1000000000) {
  885. this.value = this.value.toString().substring(0, 4) + 'M';
  886. } else {
  887. this.value = this.value;
  888. }
  889. return this.value + ' m3';
  890. }
  891. };
  892. valAxis.label = labelObj;
  893. this.chartOptions.valueAxis(valAxis);
  894. }
  895. else {
  896. var valAxis = this.chartOptions.valueAxis();
  897. valAxis.min = 0;
  898. //valAxis.max = 2500;
  899. //valAxis.tickInterval = 250;
  900. var labelObj = {
  901. customizeText: function () {
  902. //if (this.value >= 1000 && this.value < 10000) {
  903. // this.value = this.value.toString().substring(0, 1) + 'K';
  904. //} else if (this.value >= 10000) {
  905. // this.value = this.value.toString().substring(0, 2) + 'K';
  906. //} else {
  907. // this.value = this.value;
  908. //}
  909. return this.value + ' m3';
  910. }
  911. };
  912. valAxis.label = labelObj;
  913. this.chartOptions.valueAxis(valAxis);
  914. }
  915. }
  916. getAllData();
  917. }
  918. });
  919. $("#energySelect").dxSelectBox({
  920. dataSource: FuelID,
  921. displayExpr: "fuel",
  922. valueExpr: "id",
  923. value: energySelectButton,
  924. onValueChanged: function (data) {
  925. $("#LoadPanel").dxLoadPanel('instance').option('visible', true);
  926. var tmpDate = $("#startDatePicker").dxDateBox("instance").option('value');
  927. energySelectButton = data.value;
  928. if (yearSelectButton == "Month") {
  929. argAxis.max = 32 - new Date(tmpDate.getFullYear(), tmpDate.getMonth(), 32).getDate();
  930. var labelObj = {
  931. customizeText: function () {
  932. return this.value + '일';
  933. }
  934. };
  935. } else {
  936. argAxis.max = 12;
  937. var labelObj = {
  938. customizeText: function () {
  939. return this.value + '월';
  940. }
  941. };
  942. }
  943. argAxis.label = labelObj;
  944. $("#sideBarChart").dxChart("instance").option('argumentAxis', argAxis);
  945. if (yearSelectButton == "Month") {
  946. if (energySelectButton == 1) {
  947. var valAxis = this.chartOptions.valueAxis();
  948. valAxis.min = 0;
  949. //valAxis.max = 15000;
  950. //valAxis.tickInterval = 1000;
  951. var labelObj = {
  952. customizeText: function () {
  953. if (this.value >= 1000 && this.value < 10000) {
  954. this.value = this.value.toString().substring(0, 1) + 'K';
  955. } else if (this.value >= 10000) {
  956. this.value = this.value.toString().substring(0, 2) + 'K';
  957. } else {
  958. this.value = this.value;
  959. }
  960. return this.value + ' kWh';
  961. }
  962. };
  963. valAxis.label = labelObj;
  964. this.chartOptions.valueAxis(valAxis);
  965. }
  966. else if (energySelectButton == 2) {
  967. var valAxis = this.chartOptions.valueAxis();
  968. valAxis.min = 0;
  969. //valAxis.max = 15000;
  970. //valAxis.tickInterval = 500;
  971. var labelObj = {
  972. customizeText: function () {
  973. if (this.value >= 1000 && this.value < 10000) {
  974. this.value = this.value.toString().substring(0, 1) + 'K';
  975. } else if (this.value >= 10000) {
  976. this.value = this.value.toString().substring(0, 2) + 'K';
  977. } else {
  978. this.value = this.value;
  979. }
  980. return this.value + ' m3';
  981. }
  982. };
  983. valAxis.label = labelObj;
  984. this.chartOptions.valueAxis(valAxis);
  985. }
  986. else {
  987. var valAxis = this.chartOptions.valueAxis();
  988. valAxis.min = 0;
  989. //valAxis.max = 100;
  990. //valAxis.tickInterval = 10;
  991. var labelObj = {
  992. customizeText: function () {
  993. if (this.value >= 1000) {
  994. this.value = this.value.toString().substring(0, 1) + 'K';
  995. } else {
  996. this.value = this.value;
  997. }
  998. return this.value + ' m3';
  999. }
  1000. };
  1001. valAxis.label = labelObj;
  1002. this.chartOptions.valueAxis(valAxis);
  1003. }
  1004. }
  1005. else {
  1006. if (energySelectButton == 1) {
  1007. var valAxis = this.chartOptions.valueAxis();
  1008. valAxis.min = 0;
  1009. //valAxis.max = 400000;
  1010. //valAxis.tickInterval = 50000;
  1011. var labelObj = {
  1012. customizeText: function () {
  1013. if (this.value >= 1000 && this.value < 10000) {
  1014. this.value = this.value.toString().substring(0, 1) + 'K';
  1015. } else if (this.value >= 10000 && this.value < 100000) {
  1016. this.value = this.value.toString().substring(0, 2) + 'K';
  1017. } else if (this.value >= 100000) {
  1018. this.value = this.value.toString().substring(0, 3) + 'K';
  1019. } else {
  1020. this.value = this.value;
  1021. }
  1022. return this.value + ' kWh';
  1023. }
  1024. };
  1025. valAxis.label = labelObj;
  1026. this.chartOptions.valueAxis(valAxis);
  1027. }
  1028. else if (energySelectButton == 2) {
  1029. var valAxis = this.chartOptions.valueAxis();
  1030. valAxis.min = 0;
  1031. //valAxis.max = 400000;
  1032. //valAxis.tickInterval = 40000;
  1033. var labelObj = {
  1034. customizeText: function () {
  1035. if (this.value >= 1000 && this.value < 10000) {
  1036. this.value = this.value.toString().substring(0, 1) + 'K';
  1037. } else if (this.value >= 10000 && this.value < 100000) {
  1038. this.value = this.value.toString().substring(0, 2) + 'K';
  1039. } else if (this.value >= 100000 && this.value < 1000000) {
  1040. this.value = this.value.toString().substring(0, 3) + 'K';
  1041. } else if (this.value >= 1000000 && this.value < 10000000) {
  1042. this.value = this.value.toString().substring(0, 1) + 'M';
  1043. } else if (this.value >= 10000000 && this.value < 100000000) {
  1044. this.value = this.value.toString().substring(0, 2) + 'M';
  1045. } else if (this.value >= 100000000 && this.value < 1000000000) {
  1046. this.value = this.value.toString().substring(0, 3) + 'M';
  1047. } else if (this.value >= 1000000000) {
  1048. this.value = this.value.toString().substring(0, 4) + 'M';
  1049. } else {
  1050. this.value = this.value;
  1051. }
  1052. return this.value + ' m3';
  1053. }
  1054. };
  1055. valAxis.label = labelObj;
  1056. this.chartOptions.valueAxis(valAxis);
  1057. }
  1058. else {
  1059. var valAxis = this.chartOptions.valueAxis();
  1060. valAxis.min = 0;
  1061. //valAxis.max = 2500;
  1062. //valAxis.tickInterval = 250;
  1063. var labelObj = {
  1064. customizeText: function () {
  1065. //if (this.value >= 1000 && this.value < 10000) {
  1066. // this.value = this.value.toString().substring(0, 1) + 'K';
  1067. //} else if (this.value >= 10000) {
  1068. // this.value = this.value.toString().substring(0, 2) + 'K';
  1069. //} else {
  1070. // this.value = this.value;
  1071. //}
  1072. return this.value + ' m3';
  1073. }
  1074. };
  1075. valAxis.label = labelObj;
  1076. this.chartOptions.valueAxis(valAxis);
  1077. }
  1078. }
  1079. getAllData();
  1080. }
  1081. });
  1082. $("#goalBtn").dxButton({
  1083. text: "에너지원별 목표 설정(예측 대비)",
  1084. onClick: function () {
  1085. visiblePopup(true);
  1086. applyonoff = false;
  1087. }
  1088. });
  1089. $("#LoadPanel").dxLoadPanel('instance').option('visible', true);
  1090. $("#monthBtn").css("background-image", "linear-gradient(180deg,#9babc3 0%,#41618c 100%)");
  1091. $("#yearBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  1092. energySelectButton = 1;
  1093. yearSelectButton = "Month";
  1094. var argAxis = $("#sideBarChart").dxChart("instance").option('argumentAxis');
  1095. var tmpDate = $("#startDatePicker").dxDateBox("instance").option('value');
  1096. if (yearSelectButton == "Month") {
  1097. argAxis.max = 32 - new Date(tmpDate.getFullYear(), tmpDate.getMonth(), 32).getDate();
  1098. var labelObj = {
  1099. customizeText: function () {
  1100. return this.value + '일';
  1101. }
  1102. };
  1103. } else {
  1104. argAxis.max = 12;
  1105. var labelObj = {
  1106. customizeText: function () {
  1107. return this.value + '월';
  1108. }
  1109. };
  1110. }
  1111. argAxis.label = labelObj;
  1112. $("#sideBarChart").dxChart("instance").option('argumentAxis', argAxis);
  1113. $('#monthBtn').trigger('click');
  1114. }
  1115. var searchViewOptions = {
  1116. }
  1117. function handleSearchInSearchView() {
  1118. }
  1119. function getpredictiondata() {
  1120. var applyyear = ($("#Apply_Year").dxDateBox("instance").option('value')).getFullYear();
  1121. var power = 0, gas = 0, water = 0;
  1122. $("#LoadPanel").dxLoadPanel('instance').option('visible', true);
  1123. var GridSource = new DevExpress.data.DataSource({
  1124. store: {
  1125. type: "odata",
  1126. url: endpointSelector + "/BemsEnergyDaily"
  1127. },
  1128. requireTotalCount: true,
  1129. pageSize: 1100
  1130. });
  1131. GridSource.filter([
  1132. ["SiteId", "=", SiteId], //사이트 아이디
  1133. "and",
  1134. ["ServiceTypeId", "=", 1],
  1135. "and",
  1136. ["CreatedDate", ">=", new Date(applyyear, 0, 1, 0, 0, 0)],
  1137. "and",
  1138. ["CreatedDate", "<=", new Date(applyyear, 11, 31, 23, 59, 59)]
  1139. ]);
  1140. GridSource.sort({ getter: "CreatedDate", desc: true }, { getter: "FuelTypeId", ASC: true });
  1141. GridSource.load()
  1142. .done(function (result) {
  1143. if (result.length != 0) {
  1144. var savecnt = 0;
  1145. var YearDayCnt = ((((((new Date(applyyear + 1, 0, 1).getTime()) - (new Date(applyyear, 0, 1).getTime())) / 1000) / 60) / 60) / 24);
  1146. for (var i = 0; i < result.length; i++) {
  1147. var temp_fuel = result[i].FuelTypeId;
  1148. var temp_date = new Date(result[i].CreatedDate);
  1149. var temp_UTC = Date.UTC(temp_date.getFullYear(), temp_date.getMonth(), temp_date.getDate(), 0, 0, 0);
  1150. var temp_date_UTC = new Date(temp_UTC);
  1151. if (temp_fuel == 1) {
  1152. power += result[i].Prediction;
  1153. }
  1154. else if (temp_fuel == 2) {
  1155. gas += result[i].Prediction;
  1156. }
  1157. else {
  1158. water += result[i].Prediction;
  1159. }
  1160. }
  1161. $("#Prediction_Power").dxTextBox("instance").option('value', parseFloat(power.toFixed(2)));
  1162. $("#Prediction_Gas").dxTextBox("instance").option('value', parseFloat(gas.toFixed(2)));
  1163. $("#Prediction_Water").dxTextBox("instance").option('value', parseFloat(water.toFixed(2)));
  1164. $("#LoadPanel").dxLoadPanel('instance').option('visible', false);
  1165. }
  1166. else {
  1167. $("#Prediction_Power").dxTextBox("instance").option('value', null);
  1168. $("#Prediction_Gas").dxTextBox("instance").option('value', null);
  1169. $("#Prediction_Water").dxTextBox("instance").option('value', null);
  1170. $("#LoadPanel").dxLoadPanel('instance').option('visible', false);
  1171. utils.toast.show("[BemsEnergyDaily] 예측값이 없습니다.");
  1172. }
  1173. })
  1174. .fail(function (error) {
  1175. $("#LoadPanel").dxLoadPanel('instance').option('visible', false);
  1176. utils.toast.show(error);
  1177. });
  1178. }
  1179. var viewModel = $.extend(BWA.CommonView.create(params, viewInfo, searchViewOptions, ko.observable(null), handleViewShown, null, handleSearchInSearchView),
  1180. {
  1181. viewShowing: handleViewShowing,
  1182. chartOptions: {
  1183. dataSource: dataSource,
  1184. barWidth: 0.5,
  1185. size: {
  1186. height: 600
  1187. },
  1188. commonSeriesSettings: {
  1189. argumentField: "dateTime",
  1190. type: "bar"
  1191. },
  1192. series: [
  1193. { valueField: "Prediction", name: "예측", color: '#007994' },
  1194. { valueField: "Goal", name: "목표", color: '#5F8B95' }
  1195. ],
  1196. legend: {
  1197. verticalAlignment: "top",
  1198. horizontalAlignment: "center",
  1199. position: "outside",
  1200. border: { visible: false }
  1201. },
  1202. valueAxis: ko.observable({
  1203. visible: true,
  1204. label: {
  1205. customizeText: function () {
  1206. if (this.value >= 1000 && this.value < 10000) {
  1207. this.value = this.value.toString().substring(0, 1) + 'K';
  1208. } else if (this.value >= 10000) {
  1209. this.value = this.value.toString().substring(0, 2) + 'K';
  1210. } else {
  1211. this.value = this.value;
  1212. }
  1213. return this.value + ' kWh';
  1214. }
  1215. },
  1216. min: 0,
  1217. //max: 11000,
  1218. valueType: 'numeric',
  1219. //tickInterval: 1000
  1220. }),
  1221. argumentAxis: ko.observable({
  1222. visible: true,
  1223. label: {
  1224. customizeText: function () {
  1225. return this.value + '일';
  1226. }
  1227. },
  1228. min: 1,
  1229. max: 32 - new Date(TodayAdd.getFullYear, TodayAdd.getMonth, 32).getDate(),
  1230. valueType: 'numeric',
  1231. tickInterval: 1
  1232. }),
  1233. "export": {
  1234. enabled: true
  1235. },
  1236. tooltip: {
  1237. enabled: true,
  1238. customizeTooltip: function (point) {
  1239. return {
  1240. text: numberWithCommas(point.value.toFixed(2))
  1241. };
  1242. }
  1243. }
  1244. },
  1245. // 2019.04.17 : 그리드 도표 작업 : 팝업창 추가
  1246. PlanGoalPopup_ButtonClicked: DataGridPopup_ButtonClick
  1247. // 2019.04.17 : 그리드 도표 작업 : 팝업창 추가
  1248. });
  1249. viewModel.popupOptions = {
  1250. width: 600,
  1251. height: 300,
  1252. visible: visiblePopup,
  1253. dragEnabled: true,
  1254. shading: true,
  1255. closeOnOutsideClick: true,
  1256. shadingColor: 'transparent',
  1257. showTitle: true,
  1258. title: "에너지원 별 목표 설정",
  1259. showCloseButton: true,
  1260. onShowing: function () {
  1261. },
  1262. onShown: function (t, tt) {
  1263. $("#Apply_Year").dxDateBox({
  1264. value: TodayAdd,
  1265. maxZoomLevel: 'decade',
  1266. formatString: "yyyy년",
  1267. onValueChanged: function (data) {
  1268. var tmpDate = data.value;
  1269. if (tmpDate.getFullYear() > (TodayAdd.getFullYear() + 1)) {
  1270. utils.toast.show("선택 연도가 내년보다 클 수 없습니다.");
  1271. $("#Apply_Year").dxDateBox("instance").option('value', TodayAdd);
  1272. return;
  1273. }
  1274. $("#Prediction_Power").dxTextBox("instance").option('value', null);
  1275. $("#Prediction_Gas").dxTextBox("instance").option('value', null);
  1276. $("#Prediction_Water").dxTextBox("instance").option('value', null);
  1277. $("#Apply_Power").dxTextBox("instance").option('value', null);
  1278. $("#Apply_Gas").dxTextBox("instance").option('value', null);
  1279. $("#Apply_Water").dxTextBox("instance").option('value', null);
  1280. $("#Goal_Power").dxTextBox("instance").option('value', null);
  1281. $("#Goal_Gas").dxTextBox("instance").option('value', null);
  1282. $("#Goal_Water").dxTextBox("instance").option('value', null);
  1283. getpredictiondata();
  1284. }
  1285. });
  1286. $("#Goal_Power").dxTextBox({
  1287. readOnly: true
  1288. });
  1289. $("#Goal_Gas").dxTextBox({
  1290. readOnly: true
  1291. });
  1292. $("#Goal_Water").dxTextBox({
  1293. readOnly: true
  1294. });
  1295. $("#Apply_Power").dxTextBox({
  1296. });
  1297. $("#Apply_Gas").dxTextBox({
  1298. });
  1299. $("#Apply_Water").dxTextBox({
  1300. });
  1301. $("#Prediction_Power").dxTextBox({
  1302. });
  1303. $("#Prediction_Gas").dxTextBox({
  1304. });
  1305. $("#Prediction_Water").dxTextBox({
  1306. });
  1307. $("#Apply_Btn").dxButton({
  1308. text: "적용",
  1309. onClick: function () {
  1310. var applyyear = ($("#Apply_Year").dxDateBox("instance").option('value')).getFullYear();
  1311. var applypower = $("#Apply_Power").dxTextBox("instance").option('value');
  1312. if (applypower != "") {
  1313. if (applypower != null)
  1314. applypower = parseFloat(applypower);
  1315. else {
  1316. utils.toast.show("전력 절감량 정보가 잘못되었습니다.");
  1317. return;
  1318. }
  1319. }
  1320. else {
  1321. utils.toast.show("전력 절감량 정보가 잘못되었습니다.");
  1322. return;
  1323. }
  1324. var applygas = $("#Apply_Gas").dxTextBox("instance").option('value');
  1325. if (applygas != "") {
  1326. if (applygas != null)
  1327. applygas = parseFloat(applygas);
  1328. else {
  1329. utils.toast.show("가스 절감량 정보가 잘못되었습니다.");
  1330. return;
  1331. }
  1332. }
  1333. else {
  1334. utils.toast.show("가스 절감량 정보가 잘못되었습니다.");
  1335. return;
  1336. }
  1337. var applywater = $("#Apply_Water").dxTextBox("instance").option('value');
  1338. if (applywater != "") {
  1339. if (applywater != null)
  1340. applywater = parseFloat(applywater);
  1341. else {
  1342. utils.toast.show("수도 절감량 정보가 잘못되었습니다.");
  1343. return;
  1344. }
  1345. }
  1346. else {
  1347. utils.toast.show("수도 절감량 정보가 잘못되었습니다.");
  1348. return;
  1349. }
  1350. var temp_power = 0, temp_gas = 0, temp_water = 0;
  1351. $("#LoadPanel").dxLoadPanel('instance').option('visible', true);
  1352. var GridSource = new DevExpress.data.DataSource({
  1353. store: {
  1354. type: "odata",
  1355. url: endpointSelector + "/BemsEnergyDaily"
  1356. },
  1357. requireTotalCount: true,
  1358. pageSize: 1100
  1359. });
  1360. GridSource.filter([
  1361. ["SiteId", "=", SiteId], //사이트 아이디
  1362. "and",
  1363. ["ServiceTypeId", "=", 1],
  1364. "and",
  1365. ["CreatedDate", ">=", new Date(applyyear, 0, 1, 0, 0, 0)],
  1366. "and",
  1367. ["CreatedDate", "<=", new Date(applyyear, 11, 31, 23, 59, 59)]
  1368. ]);
  1369. GridSource.sort({ getter: "CreatedDate", desc: true }, { getter: "FuelTypeId", ASC: true });
  1370. GridSource.load()
  1371. .done(function (result) {
  1372. if (result.length != 0) {
  1373. var savecnt = 0;
  1374. var YearDayCnt = ((((((new Date(applyyear + 1, 0, 1).getTime()) - (new Date(applyyear, 0, 1).getTime())) / 1000) / 60) / 60) / 24);
  1375. for (var i = 0; i < result.length; i++) {
  1376. var temp_fuel = result[i].FuelTypeId;
  1377. var temp_date = new Date(result[i].CreatedDate);
  1378. var temp_UTC = Date.UTC(temp_date.getFullYear(), temp_date.getMonth(), temp_date.getDate(), 0, 0, 0);
  1379. var temp_date_UTC = new Date(temp_UTC);
  1380. var temp_Prediction = result[i].Prediction;
  1381. if (temp_fuel == 1) {
  1382. temp_power += parseFloat(((result[i].Prediction * (100 - applypower)) / 100).toFixed(2));
  1383. }
  1384. else if (temp_fuel == 2) {
  1385. temp_gas += parseFloat(((result[i].Prediction * (100 - applygas)) / 100).toFixed(2));
  1386. }
  1387. else {
  1388. temp_water += parseFloat(((result[i].Prediction * (100 - applywater)) / 100).toFixed(2));
  1389. }
  1390. }
  1391. $("#Goal_Power").dxTextBox("instance").option('value', parseFloat(temp_power.toFixed(2)));
  1392. $("#Goal_Gas").dxTextBox("instance").option('value', parseFloat(temp_gas.toFixed(2)));
  1393. $("#Goal_Water").dxTextBox("instance").option('value', parseFloat(temp_water.toFixed(2)));
  1394. applyonoff = true;
  1395. $("#LoadPanel").dxLoadPanel('instance').option('visible', false);
  1396. }
  1397. else {
  1398. applyonoff = false;
  1399. $("#LoadPanel").dxLoadPanel('instance').option('visible', false);
  1400. utils.toast.show("[BemsEnergyDaily] 예측값이 없습니다.");
  1401. }
  1402. })
  1403. .fail(function (error) {
  1404. $("#LoadPanel").dxLoadPanel('instance').option('visible', false);
  1405. utils.toast.show(error);
  1406. });
  1407. }
  1408. });
  1409. $("#Save_Btn").dxButton({
  1410. text: "저장",
  1411. onClick: function () {
  1412. if (applyonoff) {
  1413. var applyyear = ($("#Apply_Year").dxDateBox("instance").option('value')).getFullYear();
  1414. var applypower = $("#Apply_Power").dxTextBox("instance").option('value');
  1415. if (applypower != "")
  1416. applypower = parseFloat(applypower);
  1417. var applygas = $("#Apply_Gas").dxTextBox("instance").option('value');
  1418. if (applygas != "")
  1419. applygas = parseFloat(applygas);
  1420. var applywater = $("#Apply_Water").dxTextBox("instance").option('value');
  1421. if (applywater != "")
  1422. applywater = parseFloat(applywater);
  1423. if (applypower == "" || applygas == "" || applywater == "") {
  1424. utils.toast.show("입력 데이터가 잘못되었습니다.");
  1425. return;
  1426. }
  1427. $("#LoadPanel").dxLoadPanel('instance').option('visible', true);
  1428. var GridSource = new DevExpress.data.DataSource({
  1429. store: {
  1430. type: "odata",
  1431. url: endpointSelector + "/BemsEnergyDaily"
  1432. },
  1433. requireTotalCount: true,
  1434. pageSize: 1100
  1435. });
  1436. GridSource.filter([
  1437. ["SiteId", "=", SiteId], //사이트 아이디
  1438. "and",
  1439. ["ServiceTypeId", "=", 1],
  1440. "and",
  1441. ["CreatedDate", ">=", new Date(applyyear, 0, 1, 0, 0, 0)],
  1442. "and",
  1443. ["CreatedDate", "<=", new Date(applyyear, 11, 31, 23, 59, 59)]
  1444. ]);
  1445. GridSource.sort({ getter: "CreatedDate", desc: true }, { getter: "FuelTypeId", ASC: true });
  1446. GridSource.load()
  1447. .done(function (result) {
  1448. if (result.length != 0) {
  1449. var savecnt = 0;
  1450. var YearDayCnt = ((((((new Date(applyyear + 1, 0, 1).getTime()) - (new Date(applyyear, 0, 1).getTime())) / 1000) / 60) / 60) / 24);
  1451. for (var i = 0; i < result.length; i++) {
  1452. var temp_fuel = result[i].FuelTypeId;
  1453. var temp_date = new Date(result[i].CreatedDate);
  1454. var temp_UTC = Date.UTC(temp_date.getFullYear(), temp_date.getMonth(), temp_date.getDate(), 0, 0, 0);
  1455. var temp_date_UTC = new Date(temp_UTC);
  1456. var temp_Prediction = result[i].Prediction;
  1457. if (temp_fuel == 1) {
  1458. var temp_Goal = parseFloat(((result[i].Prediction * (100 - applypower)) / 100).toFixed(2));
  1459. }
  1460. else if (temp_fuel == 2) {
  1461. var temp_Goal = parseFloat(((result[i].Prediction * (100 - applygas)) / 100).toFixed(2));
  1462. }
  1463. else {
  1464. var temp_Goal = parseFloat(((result[i].Prediction * (100 - applywater)) / 100).toFixed(2));
  1465. }
  1466. BWA.api.post('BemsEnergyDaily/UpdatePart2', { //UpdatePart
  1467. SiteId: SiteId,
  1468. BuildingId: 1,
  1469. ServiceTypeId: 1,
  1470. FuelTypeId: temp_fuel,
  1471. CreatedDate: temp_date_UTC,
  1472. Prediction: temp_Prediction,
  1473. Goal: temp_Goal
  1474. }).done(function () {
  1475. savecnt++;
  1476. if (savecnt == YearDayCnt * 3) {
  1477. applyonoff = false;
  1478. utils.toast.show("DB에 저장이 되었습니다.");
  1479. $("#LoadPanel").dxLoadPanel('instance').option('visible', false);
  1480. if (yearSelectButton == "Month")
  1481. $('#monthBtn').trigger('click');
  1482. else
  1483. $('#yearBtn').trigger('click');
  1484. }
  1485. }).fail(function (error) {
  1486. $("#LoadPanel").dxLoadPanel('instance').option('visible', false);
  1487. utils.toast.show("DB에 저장이 실패하였습니다.");
  1488. });
  1489. }
  1490. }
  1491. else {
  1492. $("#LoadPanel").dxLoadPanel('instance').option('visible', false);
  1493. utils.toast.show("[BemsEnergyDaily] 예측값이 없습니다.");
  1494. }
  1495. })
  1496. .fail(function (error) {
  1497. $("#LoadPanel").dxLoadPanel('instance').option('visible', false);
  1498. utils.toast.show(error);
  1499. });
  1500. }
  1501. else {
  1502. $("#LoadPanel").dxLoadPanel('instance').option('visible', false);
  1503. utils.toast.show("적용버튼을 먼저 눌러주시기 바랍니다.");
  1504. }
  1505. }
  1506. });
  1507. $("#Prediction_Power").dxTextBox("instance").option('value', null);
  1508. $("#Prediction_Gas").dxTextBox("instance").option('value', null);
  1509. $("#Prediction_Water").dxTextBox("instance").option('value', null);
  1510. $("#Apply_Power").dxTextBox("instance").option('value', null);
  1511. $("#Apply_Gas").dxTextBox("instance").option('value', null);
  1512. $("#Apply_Water").dxTextBox("instance").option('value', null);
  1513. $("#Goal_Power").dxTextBox("instance").option('value', null);
  1514. $("#Goal_Gas").dxTextBox("instance").option('value', null);
  1515. $("#Goal_Water").dxTextBox("instance").option('value', null);
  1516. getpredictiondata();
  1517. },
  1518. onHidden: function () {
  1519. }
  1520. };
  1521. // 2019.04.17 : 그리드 도표 작업 : 팝업창 추가 ~~~
  1522. // 그래프 도표 팝업창
  1523. viewModel.PlanGoalPopupOptions = {
  1524. width: '480px',
  1525. height: '750px', // cyim 2017.05.30 : 테스트 결과 Devextreme 버그임. px 로 지정하면 초기 출력시 정확하게 가운데에 있지만, auto 설정시 화면아래에 위치하게 됨
  1526. contentTemplate: "content",
  1527. showTitle: true,
  1528. title: "도표",
  1529. visible: DataGridPopup_Visible,
  1530. dragEnabled: true,
  1531. closeOnOutsideClick: true,
  1532. shownAction: handlePopupShown,
  1533. animation: window.utils.popup.createAnimation()
  1534. };
  1535. // 주석이 너무 없음. 나중에 변경 작업을 진행하는 누군가가 시간 소비를 하지 않기 위해...남김
  1536. // 시간 포맷은 그래프에 귀속해야 되므로 포맷은 변경하지 않는 것이 유리함
  1537. // 전기,가스,수도 와 같이 선택적으로 변경해야 된다면 아래와 같이 캡션은 고정하지 말것
  1538. viewModel.PlanGoalOptions = {
  1539. dataSource: dataArrayresult,
  1540. paging: { pageSize: 17 },
  1541. columns: [
  1542. { dataField: 'dateTime', width: '20%', alignment: 'center', },// dataType: 'date', format: 'yyyy-MM-dd HH:mm' },
  1543. { dataField: 'Prediction', width: '40%', alignment: 'center', format: 'fixedPoint', precision: 2 },
  1544. { dataField: 'Goal', width: '40%', alignment: 'center', format: 'fixedPoint', precision: 2 }
  1545. ],
  1546. // 엑셀 출력
  1547. "export": {
  1548. enabled: true,
  1549. fileName: '에너지원별 에너지 사용량 및 목표설정 값'
  1550. }
  1551. };
  1552. // ~~~ 2019.04.17 : 그리드 도표 작업 : 팝업창 추가
  1553. return viewModel;
  1554. };