27cb598d97c662c91451ba20a4c6c67ff9cdcd5b.svn-base 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349
  1. BemsWebApplication.ChargePrice = function (params, viewInfo) {
  2. var now = new Date();
  3. var selectEnergy = "전력";
  4. var priceType = new Array(2);
  5. var priceCodes;
  6. function setPriceCodeData(SiteID, FuelTypeId) {
  7. var dataSource = new DevExpress.data.DataSource({
  8. store: new DevExpress.data.ODataStore({
  9. url: 'http://localhost:3403/BemsDataService.svc/BemsSitePrice'
  10. }),
  11. expand: ['BemsPriceCode','BemsPriceType'],
  12. requireTotalCount: true,
  13. pageSize: 100
  14. });
  15. dataSource.filter([
  16. ["SiteID", "=", SiteID],
  17. "and",
  18. ["FuelTypeId", "=", FuelTypeId],
  19. "and",
  20. ["UseYN","=","Y"]
  21. ]);
  22. dataSource.sort({ getter: "PriceCode", asc: true });
  23. dataSource.load()
  24. .done(function (result) {
  25. priceType[0] = result[0].PriceTypeId;
  26. priceType[1] = result[0].BemsPriceType.PriceTypeIdDesc;
  27. $('#priceTypeId').text(priceType[1]);
  28. var tmpDate = $("#startDatePicker").dxDateBox("instance").option('value');
  29. var endDay = 32 - new Date(tmpDate.getFullYear(), tmpDate.getMonth(), 32).getDate();
  30. $("#startDate").dxDateBox("instance").option('value',new Date(tmpDate.getFullYear(),tmpDate.getMonth(),1,0,0,0,0));
  31. $("#endDate").dxDateBox("instance").option('value', new Date(tmpDate.getFullYear(), tmpDate.getMonth(), endDay, 0, 0, 0, 0));
  32. var $detail = $('#detail'); // finds the <detail> element
  33. $('#detail').empty();
  34. priceCodes = new Array();
  35. for (var i = 0; i < result.length; i++) {
  36. priceCodes[i] = result[i].PriceCode;
  37. //<div class="dx-field-label cw-multi-field-label-ex">기본요금</div>
  38. //<div id="labelBaseCharge" class="dx-field-value" data-bind="text: '6,240,000'"></div>
  39. //<div id="txtBaseCharge" style="margin-left: 10px; position: absolute; left: 14%;" data-bind="dxTextBox: { value: '6,240,000' , placeholder: '기본요금' , visible : false}"></div>
  40. $('<div class="fl setText" style="line-height:220%;cursor:default;background:#d5ecfd url(../images/custom/ibems_light/arrow01.png) 5px center no-repeat;padding-left:15px;width:15%;height:32px;"></div>') // creates a new HTML element
  41. .appendTo($detail) // appends a new HTML element to the <body> element
  42. $('<div class="fl setInput" style="margin-left: 10px;width:15%;" data-bind="dxTextBox: {}"></div>')
  43. .appendTo($detail)
  44. .dxTextBox();
  45. if (i % 3 == 2) {
  46. $('<br>').appendTo($detail)
  47. $('<br>').appendTo($detail)
  48. }
  49. }
  50. var setTexts = document.querySelectorAll('.setText');
  51. var setInputs = document.querySelectorAll('.setInput');
  52. for (var i = 0; i < result.length; i++) {
  53. setTexts[i].id = "text" + result[i].PriceCode;
  54. setTexts[i].innerHTML = result[i].BemsPriceCode.PriceCodeDesc;
  55. setInputs[i].id = result[i].PriceCode;
  56. //$('#switch' + i).dxSwitch("instance").option('onText', 'On');
  57. //$('#switch' + i).dxSwitch("instance").option('offText', 'Off');
  58. }
  59. })
  60. .fail(function (error) {
  61. alert(error);
  62. });
  63. }
  64. function getHistoryData(SiteId,FuelTypeId,PayDate) {
  65. var dataSource = new DevExpress.data.DataSource({
  66. store: new DevExpress.data.ODataStore({
  67. url: 'http://localhost:3403/BemsDataService.svc/BemsSitePriceHistory'
  68. }),
  69. expand: ['BemsPriceCode','BemsPriceType'],
  70. requireTotalCount: true,
  71. pageSize: 100
  72. });
  73. dataSource.filter([
  74. ["SiteId", "=", SiteId],
  75. "and",
  76. ["FuelTypeId", "=", FuelTypeId],
  77. "and",
  78. ["PayDate", "=", PayDate]
  79. ]);
  80. dataSource.load()
  81. .done(function (result) {
  82. priceType[0] = result[0].PriceTypeId;
  83. priceType[1] = result[0].BemsPriceType.PriceTypeIdDesc;
  84. $('#priceTypeId').text(priceType[1]);
  85. $('#priceTypeId').text(priceType[1]);
  86. var tmpDate = $("#startDatePicker").dxDateBox("instance").option('value');
  87. var endDay = 32 - new Date(tmpDate.getFullYear(), tmpDate.getMonth(), 32).getDate();
  88. $("#startDate").dxDateBox("instance").option('value', result[0].StartDate);
  89. $("#endDate").dxDateBox("instance").option('value', result[0].EndDate);
  90. $("#startDate").dxDateBox("instance").option('readOnly', true);
  91. $("#endDate").dxDateBox("instance").option('readOnly', true);
  92. var $detail = $('#detail'); // finds the <detail> element
  93. $('#detail').empty();
  94. priceCodes = new Array();
  95. for (var i = 0; i < result.length; i++) {
  96. priceCodes[i] = result[i].PriceCode;
  97. $('<div class="fl setText" style="line-height:220%;cursor:default;background:#d5ecfd url(../images/custom/ibems_light/arrow01.png) 5px center no-repeat;padding-left:15px;width:15%;height:32px;"></div>') // creates a new HTML element
  98. .appendTo($detail) // appends a new HTML element to the <body> element
  99. $('<div class="fl setInput" style="margin-left: 10px;width:15%;" data-bind="dxTextBox: {}"></div>')
  100. .appendTo($detail)
  101. .dxTextBox();
  102. if (i % 3 == 2) {
  103. $('<br>').appendTo($detail)
  104. $('<br>').appendTo($detail)
  105. }
  106. }
  107. var setTexts = document.querySelectorAll('.setText');
  108. var setInputs = document.querySelectorAll('.setInput');
  109. for (var i = 0; i < result.length; i++) {
  110. setTexts[i].id = "text" + result[i].PriceCode;
  111. setTexts[i].innerHTML = result[i].BemsPriceCode.PriceCodeDesc;
  112. setInputs[i].id = result[i].PriceCode;
  113. $('#' + result[i].PriceCode).dxTextBox("instance").option('value', result[i].PriceValue);
  114. $('#' + result[i].PriceCode).dxTextBox("instance").option('readOnly', true);
  115. //$('#switch' + i).dxSwitch("instance").option('offText', 'Off');
  116. }
  117. })
  118. .fail(function (error) {
  119. alert(error);
  120. });
  121. }
  122. function checkHistoryData(SiteId,FuelTypeId,PayDate) {
  123. var dataSource = new DevExpress.data.DataSource({
  124. store: new DevExpress.data.ODataStore({
  125. url: 'http://localhost:3403/BemsDataService.svc/BemsSitePriceHistory'
  126. }),
  127. requireTotalCount: true,
  128. pageSize: 100
  129. });
  130. dataSource.filter([
  131. ["SiteId", "=", SiteId],
  132. "and",
  133. ["FuelTypeId", "=", FuelTypeId],
  134. "and",
  135. ["PayDate", "=", PayDate]
  136. ]);
  137. dataSource.load()
  138. .done(function (result) {
  139. if (result.length == 0) {
  140. $("#modifyBtn").dxButton("instance").option("text", "입력");
  141. setPriceCodeData(BWA.UserInfo.SiteId(), FuelTypeId);
  142. } else {
  143. $("#modifyBtn").dxButton("instance").option("text", "수정");
  144. getHistoryData(BWA.UserInfo.SiteId(), FuelTypeId, PayDate);
  145. }
  146. })
  147. .fail(function (error) {
  148. alert(error);
  149. });
  150. }
  151. function insertSitePriceHistory(SiteId,FuelTypeId,PayDate) {
  152. var store = new DevExpress.data.ODataStore({
  153. url: "http://localhost:3403/BemsDataService.svc/BemsSitePriceHistory",
  154. key: ["SiteId", "FuelTypeId", "PriceTypeId","PriceCode","PayDate"],
  155. keyType: {SiteId:"Int32", FuelTypeId:"Int32", PriceTypeId:"Int32", PriceCode:"String", PayDate:"String"}
  156. });
  157. var failCnt = 0;
  158. var startDate = $("#startDate").dxDateBox("instance").option('value');
  159. var endDate = $("#endDate").dxDateBox("instance").option('value');
  160. for (var i = 0; i < priceCodes.length; i++) {
  161. var priceValue = $("#" + priceCodes[i]).dxTextBox("instance").option('value');
  162. store.insert({
  163. SiteId: SiteId, FuelTypeId: FuelTypeId, PriceTypeId: priceType[0], PriceCode: priceCodes[i], PriceValue: priceValue, PayDate: PayDate, StartDate: startDate, EndDate: endDate, PayCharge: "0"
  164. })
  165. .done(function (key, result) {
  166. //alert(key + "/" + result);
  167. })
  168. .fail(function (error) {
  169. failCnt++;
  170. });
  171. }
  172. if (failCnt > 0) {
  173. alert("저장이 실패했습니다.");
  174. } else {
  175. alert("저장이 완료 되었습니다.");
  176. }
  177. }
  178. function updateSitePriceHistory(SiteId, FuelTypeId, PayDate) {
  179. var failCnt = 0;
  180. var store = new DevExpress.data.ODataStore({
  181. url: "http://localhost:3403/BemsDataService.svc/BemsSitePriceHistory",
  182. key: ["SiteId", "FuelTypeId", "PriceTypeId", "PriceCode", "PayDate"],
  183. keyType: {SiteId:"Int32", FuelTypeId:"Int32", PriceTypeId:"Int32", PriceCode:"String", PayDate:"String"}
  184. });
  185. var startDate = $("#startDate").dxDateBox("instance").option('value');
  186. var endDate = $("#endDate").dxDateBox("instance").option('value');
  187. for (var i = 0; i < priceCodes.length; i++) {
  188. var priceValue = $("#" + priceCodes[i]).dxTextBox("instance").option('value');
  189. store.update({ SiteId: SiteId, FuelTypeId: FuelTypeId, PriceTypeId: priceType[0], PriceCode: priceCodes[i], PayDate: PayDate }, { PriceValue: priceValue, StartDate : startDate, EndDate:endDate })
  190. .done(function (key, result) {
  191. //alert(key + "/" + result);
  192. })
  193. .fail(function (error) {
  194. failCnt++;
  195. });
  196. }
  197. if (failCnt > 0) {
  198. alert("업데이트가 실패했습니다.");
  199. } else {
  200. alert("저장 되었습니다.");
  201. }
  202. }
  203. function disableReadOnly() {
  204. for (var i = 0; i < priceCodes.length; i++) {
  205. $("#" + priceCodes[i]).dxTextBox("instance").option('readOnly', false);
  206. }
  207. $("#startDate").dxDateBox("instance").option('readOnly', false);
  208. $("#endDate").dxDateBox("instance").option('readOnly', false);
  209. }
  210. function handleViewShown() {
  211. var tmpDate = $("#startDatePicker").dxDateBox("instance").option('value');
  212. var month = tmpDate.getMonth() + 1;
  213. if (month < 10) {
  214. month = "0" + month.toString();
  215. }
  216. var endDay = 32 - new Date(tmpDate.getFullYear(), tmpDate.getMonth(), 32).getDate();
  217. checkHistoryData(BWA.UserInfo.SiteId(),1,tmpDate.getFullYear().toString() + month);
  218. }
  219. var searchViewOptions = {
  220. //templete function
  221. };
  222. function handleSearchInSearchView() {
  223. //templete function
  224. }
  225. var viewModel = $.extend(BWA.CommonView.create(params, viewInfo, searchViewOptions, ko.observable(null), handleViewShown, null, handleSearchInSearchView),
  226. {
  227. startDatePicker: {
  228. pickerType: "calendar",
  229. value: now,
  230. formatString: "yyyy년 MM월",
  231. maxZoomLevel: "year",
  232. width: "9%",
  233. onValueChanged: function () {
  234. var tmpDate = $("#startDatePicker").dxDateBox("instance").option('value');
  235. var month = tmpDate.getMonth() + 1;
  236. if (month < 10) {
  237. month = "0" + month.toString();
  238. }
  239. var endDay = 32 - new Date(tmpDate.getFullYear(), tmpDate.getMonth(), 32).getDate();
  240. var FuelTypeId = 0;
  241. if (selectEnergy == "전력") {
  242. FuelTypeId = 1;
  243. } else if (selectEnergy == "가스") {
  244. FuelTypeId = 2;
  245. } else if (selectEnergy == "수도") {
  246. FuelTypeId = 3;
  247. } else {
  248. alert("선택된 에너지원이 없습니다.");
  249. }
  250. checkHistoryData(BWA.UserInfo.SiteId(), FuelTypeId, tmpDate.getFullYear().toString() + month);
  251. }
  252. },
  253. startDate: {
  254. pickerType: "calendar",
  255. value: now,
  256. formatString: "yyyy년 MM월 dd일",
  257. maxZoomLevel: "month",
  258. width: "12%"
  259. },
  260. endDate: {
  261. pickerType: "calendar",
  262. value: now,
  263. formatString: "yyyy년 MM월 dd일",
  264. maxZoomLevel: "month",
  265. width: "12%"
  266. },
  267. powerButtonClicked: function () {
  268. $("#powerBtn").css("background-image", "linear-gradient(180deg,#9babc3 0%,#41618c 100%)");
  269. $("#gasBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  270. $("#waterBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  271. selectEnergy = "전력";
  272. var tmpDate = $("#startDatePicker").dxDateBox("instance").option('value');
  273. var month = tmpDate.getMonth() + 1;
  274. if (month < 10) {
  275. month = "0" + month.toString();
  276. }
  277. var endDay = 32 - new Date(tmpDate.getFullYear(), tmpDate.getMonth(), 32).getDate();
  278. checkHistoryData(BWA.UserInfo.SiteId(), 1, tmpDate.getFullYear().toString() + month);
  279. },
  280. gasButtonClicked: function () {
  281. $("#gasBtn").css("background-image", "linear-gradient(180deg,#9babc3 0%,#41618c 100%)");
  282. $("#powerBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  283. $("#waterBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  284. selectEnergy = "가스";
  285. var tmpDate = $("#startDatePicker").dxDateBox("instance").option('value');
  286. var month = tmpDate.getMonth() + 1;
  287. if (month < 10) {
  288. month = "0" + month.toString();
  289. }
  290. var endDay = 32 - new Date(tmpDate.getFullYear(), tmpDate.getMonth(), 32).getDate();
  291. checkHistoryData(BWA.UserInfo.SiteId(), 2, tmpDate.getFullYear().toString() + month);
  292. },
  293. waterButtonClicked: function () {
  294. $("#waterBtn").css("background-image", "linear-gradient(180deg,#9babc3 0%,#41618c 100%)");
  295. $("#gasBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  296. $("#powerBtn").css("background-image", "linear-gradient(rgb(56,88,130) 0%, rgb(44,68,101)100%)");
  297. selectEnergy = "수도";
  298. var tmpDate = $("#startDatePicker").dxDateBox("instance").option('value');
  299. var month = tmpDate.getMonth() + 1;
  300. if (month < 10) {
  301. month = "0" + month.toString();
  302. }
  303. var endDay = 32 - new Date(tmpDate.getFullYear(), tmpDate.getMonth(), 32).getDate();
  304. checkHistoryData(BWA.UserInfo.SiteId(), 3, tmpDate.getFullYear().toString() + month);
  305. },
  306. modifyButtonClicked: function () {
  307. var FuelTypeId = 0;
  308. if (selectEnergy == "전력") {
  309. FuelTypeId = 1;
  310. } else if (selectEnergy == "가스") {
  311. FuelTypeId = 2;
  312. } else if (selectEnergy == "수도") {
  313. FuelTypeId = 3;
  314. } else {
  315. alert("선택된 에너지원이 없습니다.");
  316. }
  317. var tmpDate = $("#startDatePicker").dxDateBox("instance").option('value');
  318. var month = tmpDate.getMonth() + 1;
  319. if (month < 10) {
  320. month = "0" + month.toString();
  321. }
  322. var payDate = tmpDate.getFullYear().toString() + month;
  323. if ($("#modifyBtn").dxButton("instance").option("text") == "입력") {
  324. insertSitePriceHistory(BWA.UserInfo.SiteId(), FuelTypeId, payDate);
  325. }else if ($("#modifyBtn").dxButton("instance").option("text") == "수정") {
  326. $("#modifyBtn").dxButton("instance").option("text", "확인");
  327. disableReadOnly();
  328. } else if ($("#modifyBtn").dxButton("instance").option("text") == "확인") {
  329. $("#modifyBtn").dxButton("instance").option("text", "수정");
  330. updateSitePriceHistory(BWA.UserInfo.SiteId(), FuelTypeId, payDate);
  331. } else {
  332. alert("선택된 버튼이 없습니다.");
  333. }
  334. }
  335. });
  336. return viewModel;
  337. };