04f6ed87fc3902f1b7bb009e5678342dbf852418.svn-base 75 KB

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