ITP_SALESMNG02010.js 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364
  1. /********************************************************
  2. --------------------------------------------------------
  3. - Object 목록 -
  4. --------------------------------------------------------
  5. * const gridColModel = {} : 화면 Grid Object *
  6. * let pageObj = {} : 화면공통 Object *
  7. * let listObj = {} : 목록화면 Object *
  8. * let modifyObj = {} : 상세화면 Object *
  9. *******************************************************/
  10. /*화면 변수*/
  11. const SALESMNG02010_GRID_ID = '#ITP_SALESMNG02010_jqGrid';
  12. const SALESMNG02010_GRID_LIST = '#ITP_SALESMNG02010_jqGrid_list';
  13. const SALESMNG02010_GRID_PAGER = '#ITP_SALESMNG02010_jqGridPager';
  14. const SALESMNG02010_GRID_EMPTY = '#ITP_SALESMNG02010_jqGridEmpty';
  15. let ITP_FORM_SALESMNG02010_DETAIL_IS_DUPLICATE = false;
  16. let ITP_FORM_SALESMNG02010_DETAIL_IS_WRITING = false;
  17. let SALESMNG02010_DETAIL_GRID_LAST_ROW_ID;
  18. /*API URL*/
  19. let API_GRID_LIST = '/api/sale/mng/item-grid-list';
  20. let LOGIN_AUTH_TYPE_CD;
  21. /*화면 Grid ColModel*/
  22. const gridColModel = {
  23. list: [
  24. {
  25. index: 'VIEW_CD', name: 'viewCd',
  26. label: ITP_MSG_LOCALE.label.viewCd,
  27. width: '10', fixed: false, align: 'center',
  28. sortable: false, hidden: true
  29. },
  30. {
  31. index: 'BRAND_NM', name: 'brandNm',
  32. label: "브랜드",
  33. width: '10', fixed: false, align: 'center',
  34. sortable: false, hidden: true
  35. },
  36. {
  37. index: 'ITEM_ID', name: 'itemId',
  38. label: "품목번호",
  39. width: '13', fixed: false, align: 'center',
  40. sortable: false, hidden: false
  41. },
  42. {
  43. index: 'ITEM_NM', name: 'itemNm',
  44. label: "품목명",
  45. width: '12', fixed: false, align: 'left',
  46. sortable: false, hidden: false, classes: 'ui-ellipsis'
  47. },
  48. {
  49. index: 'WHS_QTY', name: 'whsQty',
  50. label: "구매수량",
  51. width: '10', fixed: false, align: 'right',
  52. sortable: false, editable: false, edittype: 'text',
  53. formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
  54. },
  55. {
  56. index: 'SUPPLY_AMT', name: 'supplyAmt',
  57. label: "공급가액",
  58. width: '10', fixed: false, align: 'right',
  59. sortable: false, editable: false, edittype: 'text',
  60. formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
  61. },
  62. {
  63. index: 'STORE_AMT', name: 'storeAmt',
  64. label: "판매금액",
  65. width: '10', fixed: false, align: 'right',
  66. sortable: false, editable: false, edittype: 'text',
  67. formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
  68. },
  69. {
  70. index: 'INCOME_AMT', name: 'incomeAmt',
  71. label: "수입금액",
  72. width: '10', fixed: false, align: 'right',
  73. sortable: false, editable: false, edittype: 'text',
  74. formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
  75. },
  76. {
  77. index: 'WHS_QTY1', name: 'whsQty1',
  78. label: "반품수량",
  79. width: '10', fixed: false, align: 'right',
  80. sortable: false, editable: false, edittype: 'text',
  81. formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
  82. },
  83. {
  84. index: 'SUPPLY_AMT1', name: 'supplyAmt1',
  85. label: "반품공급가액",
  86. width: '10', fixed: false, align: 'right',
  87. sortable: false, editable: false, edittype: 'text',
  88. formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
  89. },
  90. {
  91. index: 'STORE_AMT1', name: 'storeAmt1',
  92. label: "판품금액",
  93. width: '10', fixed: false, align: 'right',
  94. sortable: false, editable: false, edittype: 'text',
  95. formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
  96. },
  97. {
  98. index: 'INCOME_AMT1', name: 'incomeAmt1',
  99. label: "판품손실",
  100. width: '10', fixed: false, align: 'right',
  101. sortable: false, editable: false, edittype: 'text',
  102. formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
  103. },
  104. {
  105. index: 'TOT_INCOME_AMT', name: 'totIncomeAmt',
  106. label: "총매출금액",
  107. width: '10', fixed: false, align: 'right',
  108. sortable: false, editable: false, edittype: 'text',
  109. formatter:'integer',formatoptions: { defaultValue: '', thousandsSeparator: ',' }
  110. }
  111. ]
  112. };
  113. require(['config'], function() {
  114. require([
  115. 'kakao.map.util'
  116. ], function($) {
  117. pageObj.init();
  118. });
  119. });
  120. /*화면공통 Object*/
  121. let pageObj = {
  122. init: function () {
  123. this.ui.init();
  124. this.event.init();
  125. },
  126. ui: {
  127. init: function () {
  128. this.view();
  129. this.grid();
  130. this.ready();
  131. },
  132. view: function() {
  133. // 버튼 권한설정
  134. fn_proc_btn_auth('SALESMNG02010');
  135. // 공통코드 표시
  136. $('select').each(function() {
  137. if($(this).data('select-code')) {
  138. fn_make_select(CODE_LIST, $(this).data('select-code'), $(this).attr('id'));
  139. }
  140. });
  141. // 조회일자 지정
  142. var now = new Date();
  143. $('#ITP_TAB_SALESMNG02010 .input-group.date').datepicker(ITP_DATE_LANGUAGE);
  144. $('#ITP_FORM_SALESMNG02010_SEARCH_FROM_DT').datepicker('setDate', new Date(now.setMonth(now.getMonth() - 1)));
  145. $('#ITP_FORM_SALESMNG02010_SEARCH_TO_DT').datepicker('setDate', new Date());
  146. // 권한에 따라 매장값 설정
  147. $('#ITP_FORM_SALESMNG02010_SEARCH_BRAND_ID').val(fn_make_user_info.get('brandId'));
  148. LOGIN_AUTH_TYPE_CD = fn_make_user_info.get('authTpCd'); // 권한타입
  149. if(LOGIN_AUTH_TYPE_CD == '50') {
  150. $('#ITP_FORM_SALESMNG02010_SEARCH_STORE_ID').val(fn_make_user_info.get('storeId'));
  151. }
  152. },
  153. grid: function() {
  154. itp_fn_jqgrid_resize(SALESMNG02010_GRID_ID, SALESMNG02010_GRID_LIST, 'lg');
  155. listObj.empty.init();
  156. itp_fn_fire_window_resize();
  157. },
  158. ready: function() {
  159. listObj.init();
  160. }
  161. },
  162. event: {
  163. init: function () {
  164. this.button();
  165. this.change();
  166. },
  167. button: function () {
  168. // 버튼 클릭 이벤트
  169. $('button').each(function() {
  170. var id = $(this).attr('id');
  171. $(this).on('click', function() {
  172. switch (id) {
  173. case 'ITP_BTN_SALESMNG02010_SRH' : listObj.button.search(); break; // 조회 버튼 클릭
  174. case 'ITP_BTN_SALESMNG02010_SEARCH_STORE_POP' : listObj.button.storePop(); break; // 매장검색 팝업
  175. case 'ITP_BTN_SALESMNG02010_SEARCH_ERASE' : listObj.button.storeErase(); break; // 매장 지움
  176. case 'ITP_BTN_SALESMNG02010_EXCEL' : listObj.excelDown(); break; // 엑셀 다운로드
  177. }
  178. });
  179. });
  180. $('body').on('click', function(e) {
  181. });
  182. },
  183. change: function() {
  184. $('#ITP_FORM_SALESMNG02010_SEARCH_STORE_SPPLY_GUBUN').on('change', function() {
  185. var gubunVal = $('#ITP_FORM_SALESMNG02010_SEARCH_STORE_SPPLY_GUBUN').val();
  186. if(gubunVal == '1') { // 매장
  187. $('#ITP_FORM_SALESMNG02010_SEARCH_STORE_SPPLY_NM').attr('placeholder', '매장명');
  188. $(SALESMNG02010_GRID_ID).jqGrid('hideCol', ["spplyNm"]);
  189. $(SALESMNG02010_GRID_ID).jqGrid('showCol', ["storeNm"]);
  190. // $(SALESMNG02010_GRID_ID).setColProp('spplyNm', {hidden: true});
  191. // $(SALESMNG02010_GRID_ID).setColProp('storeNm', {hidden: false});
  192. }
  193. listObj.button.search();
  194. // itp_fn_jqgrid_resize(SALESMNG02010_GRID_ID, SALESMNG02010_GRID_LIST, 'lg');
  195. });
  196. }
  197. },
  198. switchScreen: function(mode) {
  199. if(mode == 'LIST') { // 목록
  200. $('#ITP_BTN_SALESMNG02010_MODIFY').hide();
  201. $('#ITP_BTN_SALESMNG02010_CANCELLIST').hide();
  202. $('#ITP_BTN_SALESMNG02010_DELETE').hide();
  203. $('#ITP_BTN_SALESMNG02010_STTL_END').hide();
  204. if(LOGIN_AUTH_TYPE_CD == '50') { // 매장관리자
  205. $('#ITP_BTN_SALESMNG02010_SEARCH_STORE_POP').hide();
  206. $('#ITP_BTN_SALESMNG02010_SEARCH_ERASE').hide();
  207. } else {
  208. $('#ITP_BTN_SALESMNG02010_SEARCH_STORE_POP').show();
  209. $('#ITP_BTN_SALESMNG02010_SEARCH_ERASE').show();
  210. }
  211. fn_show_btn_auth('#ITP_BTN_SALESMNG02010_SRH');
  212. $('#ITP_AJAX_SALESMNG02010_LIST_CONTAINER').show();
  213. $('#ITP_BTN_SALESMNG02010_EXCEL').show();
  214. }
  215. }
  216. };
  217. /*목록화면 Object*/
  218. let listObj = {
  219. init: function () {
  220. this.grid.init();
  221. },
  222. itp_SALESMNG02010_search: false,
  223. button: {
  224. search: function() {
  225. listObj.itp_SALESMNG02010_search = true;
  226. let param = $('#ITP_FORM_SALESMNG02010_SEARCH').serializeObject();
  227. param.gridSize = $.jgrid.defaults.rowNum;
  228. param.gridPage = $.jgrid.defaults.page;
  229. $(SALESMNG02010_GRID_ID).setGridParam({'postData': JSON.stringify(param)}).trigger('reloadGrid');
  230. },
  231. storePop: function() {
  232. fn_call_popup('biz', 'BIZPOP_BRAND_STORE', '#ITP_ASIDE', function(result) {
  233. // alert(JSON.stringify(result));
  234. $('#ITP_FORM_SALESMNG02010_SEARCH_STORE_ID').val(result[0].storeId);
  235. $('#ITP_FORM_SALESMNG02010_SEARCH_STORE_SPPLY_NM').val(result[0].storeNm);
  236. listObj.button.search();
  237. }, null, 'S');
  238. },
  239. storeErase: function() {
  240. $('#ITP_FORM_SALESMNG02010_SEARCH_STORE_ID').val('');
  241. $('#ITP_FORM_SALESMNG02010_SEARCH_STORE_SPPLY_NM').val('');
  242. listObj.button.search();
  243. }
  244. },
  245. empty: {
  246. init: function() {
  247. var _this = this;
  248. this.push();
  249. $(SALESMNG02010_GRID_EMPTY).on('click', function() {
  250. _this.back();
  251. _this.itp_SALESMNG02010_param.gridSize = $.jgrid.defaults.rowNum;
  252. $(SALESMNG02010_GRID_ID).setGridParam({'postData': JSON.stringify(_this.itp_SALESMNG02010_param)}).trigger('reloadGrid');
  253. });
  254. },
  255. itp_SALESMNG02010_param: {},
  256. push: function() {
  257. let param = $('#ITP_FORM_SALESMNG02010_SEARCH').serializeObject();
  258. listObj.itp_SALESMNG02010_param = param;
  259. },
  260. back: function() {
  261. $('#ITP_FORM_SALESMNG02010_SEARCH_STORE_ID').val(listObj.itp_SALESMNG02010_param.sstoreId);
  262. $('#ITP_FORM_SALESMNG02010_SEARCH_STORE_NM').val(listObj.itp_SALESMNG02010_param.sstoreNm);
  263. $('#ITP_FORM_SALESMNG02010_SEARCH_FROM_DT').val(listObj.itp_SALESMNG02010_param.fromDt);
  264. $('#ITP_FORM_SALESMNG02010_SEARCH_TO_DT').val(listObj.itp_SALESMNG02010_param.toDt);
  265. $('#ITP_FORM_SALESMNG02010_SEARCH_ITEM_NM').val(listObj.itp_SALESMNG02010_param.sitemNm);
  266. }
  267. },
  268. grid: {
  269. init: function () {
  270. // 데이터 없을때
  271. listObj.empty.push();
  272. this.search();
  273. },
  274. colModel: gridColModel.list,
  275. search: function() {
  276. pageObj.switchScreen('LIST');
  277. this.unload();
  278. this.load();
  279. },
  280. load: function() {
  281. let param = $('#ITP_FORM_SALESMNG02010_SEARCH').serializeObject();
  282. param.gridSize = $.jgrid.defaults.rowNum;
  283. var option = {
  284. gridId: SALESMNG02010_GRID_ID,
  285. colModel: gridColModel.list,
  286. param: param,
  287. url: DOMAIN + API_GRID_LIST,
  288. pager: SALESMNG02010_GRID_PAGER,
  289. onCellSelect: function(rowId, cellIdx, cellValue) {
  290. var cm = $(this).jqGrid('getGridParam', 'colModel');
  291. var colNm = cm[cellIdx].name;
  292. if (colNm == 'sttlMgntUnqNo') {
  293. const sttlMgntUnqNoVal = $(this).jqGrid('getCell', rowId, 'sttlMgntUnqNo');
  294. const key = {sttlMgntUnqNo: sttlMgntUnqNoVal, viewCd: 'R'};
  295. var param = $.param(key);
  296. modifyObj.init(param);
  297. }
  298. },
  299. loadComplete: function(data) {
  300. console.log(data);
  301. itp_fn_grid_load_complete(data, SALESMNG02010_GRID_ID, true, 'number', 'SALESMNG02010', listObj.itp_SALESMNG02010_search, listObj.empty, true, data.gridRecords, true);
  302. var ids = $(SALESMNG02010_GRID_ID).getDataIDs();
  303. $.each(ids, function(idx, rowId) {
  304. $(SALESMNG02010_GRID_ID).jqGrid('setCell', rowId, 'sttlMgntUnqNo', '', ITP_GRID_COL_STYLE.link);
  305. });
  306. },
  307. onPaging: function(action) {
  308. itp_fn_grid_paging(SALESMNG02010_GRID_ID, action, param);
  309. }
  310. };
  311. itp_fn_grid_make_remote(option);
  312. $(SALESMNG02010_GRID_ID).jqGrid('setGroupHeaders', {
  313. useColSpanStyle: true,
  314. groupHeaders:[
  315. { startColumnName: 'whsQty', numberOfColumns: 4, titleText: '구매' },
  316. { startColumnName: 'whsQty1', numberOfColumns: 4, titleText: '반품' }
  317. ]
  318. });
  319. },
  320. clearData : function() {
  321. $(SALESMNG02010_GRID_ID).jqGrid('clearGridData', true);
  322. $(SALESMNG02010_GRID_LIST).find('.ui-jqgrid-bdiv').css('min-height', '100px');
  323. $(SALESMNG02010_GRID_EMPTY).html(ITP_MSG_LOCALE.message.grid.noData);
  324. $(SALESMNG02010_GRID_EMPTY).show();
  325. },
  326. unload : function() {
  327. $.jgrid.gridUnload(SALESMNG02010_GRID_ID);
  328. }
  329. },
  330. excelDown: function() {
  331. var param = {
  332. 'url': API_GRID_LIST,
  333. 'param': $('#ITP_FORM_SALESMNG02010_SEARCH').serializeObject(),
  334. 'gridColumns': $(SALESMNG02010_GRID_ID).jqGrid('getGridParam', 'colModel'),
  335. 'fileName': '품목별_매출현황.xlsx',
  336. 'sheetName': '품목별매출현황'
  337. };
  338. itp_fn_remote_to_excel(param);
  339. }
  340. };