forked from HANYANG/HANYANG_MES
483 lines
18 KiB
JavaScript
483 lines
18 KiB
JavaScript
|
|
//Grid와 함께 사용될 사용자정의 함수
|
|
class Tb_class {
|
|
constructor(){
|
|
let _this = this;
|
|
_this.estimate_ajax_url = "./estimate.ajax.php";
|
|
_this.tblList = "";
|
|
_this.putEstimateModal = "";
|
|
_this.saveExcel = tb_common_funtions.tabu2xls; //엑셀 다운로드
|
|
}
|
|
|
|
//파트너 리스트 로드
|
|
getMainList (sdata) {
|
|
let _this = this;
|
|
let talert = window.setTimeout(function () { _this.tblList.alert("Loading ...") }, 1000); //1초 이상 지연되면 로딩 출력
|
|
ajax_json({
|
|
url: _this.estimate_ajax_url,
|
|
data: { mode: 'getEstimateList',
|
|
BP_NM: sdata?.BP_NM||'',
|
|
EST_UID: sdata?.EST_UID||'',
|
|
SCS_FLG: sdata?.SCS_FLG||'',
|
|
USE_FLG: sdata?.USE_FLG||'',
|
|
OFLD: sdata?.OFLD||'',
|
|
OASC: sdata?.OASC||'',
|
|
LINE_NUM: sdata?.LINE_NUM||'',
|
|
NOW_PAGE: sdata?.NOW_PAGE||'',
|
|
},
|
|
success: function (data) {
|
|
if (data.code) {
|
|
_this.tblList.setData(data.data);
|
|
|
|
//page
|
|
putPagiNation({
|
|
...sdata,
|
|
TARGET: ".tabulator-footer-contents",
|
|
PREB_PAGE: data?.data[0]?.PREB_PAGE,
|
|
NEXB_PAGE: data?.data[0]?.NEXB_PAGE,
|
|
LAST_PAGE: data?.data[0]?.LAST_PAGE,
|
|
PAGE_LISTS: data?.data[0]?.PAGE_LISTS?.split('|'),
|
|
callback: (conf)=>{
|
|
_this.getMainList({
|
|
BP_NM: conf?.BP_NM||'',
|
|
EST_UID: conf?.EST_UID||'',
|
|
SCS_FLG: conf?.SCS_FLG||'',
|
|
USE_FLG: conf?.USE_FLG||'',
|
|
OFLD: conf?.OFLD||'',
|
|
OASC: conf?.OASC||'',
|
|
LINE_NUM: conf?.LINE_NUM||'',
|
|
NOW_PAGE: conf?.NOW_PAGE||'',
|
|
});
|
|
}
|
|
});
|
|
}else{
|
|
kuls_alert(data.mesg);
|
|
}
|
|
},
|
|
error: function (request, status, error) {
|
|
kuls_alert(error.message);
|
|
},
|
|
complete: function () {
|
|
window.clearTimeout(talert);
|
|
_this.tblList.clearAlert();
|
|
_this.setFilter();
|
|
}
|
|
});
|
|
return false;
|
|
};
|
|
|
|
//등록
|
|
setStatus (){
|
|
let _this = this;
|
|
let postdata = {
|
|
'mode': 'setStatus',
|
|
'reqdata': JSON.stringify(_this.tblList.getData().filter( row => row._STATUS_ === 'U' ) ),
|
|
};
|
|
// console.log(_this.tblList.getSelectedData());
|
|
ajax_json({
|
|
url: _this.estimate_ajax_url,
|
|
data: postdata,
|
|
success: function (data) {
|
|
if (data.code) {
|
|
kuls_success("적용 되었습니다.");
|
|
}else{
|
|
kuls_alert(data.mesg);
|
|
}
|
|
},
|
|
error: function (request, status, error) {
|
|
kuls_alert(error.message);
|
|
},
|
|
complete: function () {
|
|
}
|
|
});
|
|
return true;
|
|
};
|
|
|
|
//검색 조건 Clear
|
|
clearInput (){
|
|
let _this = this;
|
|
|
|
let today = new Date();
|
|
_this.setFilter();
|
|
};
|
|
|
|
//sort
|
|
columnSort(e,tgt) {
|
|
let _this = this;
|
|
let sorters = tgt.getTable().getSorters()[0];
|
|
_this.getMainList({..._this.searchData,OFLD:sorters?.field,OASC:sorters?.dir});
|
|
};
|
|
|
|
setFilter () {
|
|
let _this = this;
|
|
return ;
|
|
|
|
_this.tblList.setFilter(function(data){ //필터링
|
|
return (
|
|
true
|
|
&& ( !document.getElementById("S_BP_NM") || ( (data.BP_CD+"|"+data.BP_NM).search(document.getElementById("S_BP_NM").value) !== -1 ) )
|
|
&& ( !document.getElementById("S_SCS_FLG") || ( !document.getElementById("S_SCS_FLG").checked || data.SCS_FLG === 'Y' ) )
|
|
&& ( !document.getElementById("S_USE_FLG") || ( !document.getElementById("S_USE_FLG").checked || data.USE_FLG === 'Y' ) )
|
|
)
|
|
}, '=', true);
|
|
};
|
|
|
|
//Row 클릭 콜백
|
|
rowClick (e, tgt){
|
|
let _this = this;
|
|
if( !e.target.attributes['tabulator-field'] ) return;
|
|
switch( e.target.attributes['tabulator-field'].value ){
|
|
case "SCS_FLG":
|
|
case "USE_FLG":
|
|
return;
|
|
break;
|
|
}
|
|
let row = tgt._row;
|
|
Tb_funcs_est_detail.initModal(row.data.EST_ID);
|
|
};
|
|
|
|
//Cell 클릭 콜백
|
|
cellClick (e, tgt){
|
|
let _this = this;
|
|
switch(tgt.getField()){
|
|
case "SCS_FLG":
|
|
case "USE_FLG":
|
|
tgt.setValue( tgt.getValue() == "Y"?"N":"Y" );
|
|
break;
|
|
}
|
|
};
|
|
|
|
cellEdited(cell) {
|
|
let _this = this;
|
|
let rowval = cell.getData();
|
|
rowval._STATUS_ = rowval._STATUS_||'U';
|
|
cell.getRow().update(rowval);
|
|
};
|
|
|
|
//시작 실행
|
|
init () {
|
|
let _this = this;
|
|
|
|
const fields = [
|
|
{ formatter: "rownum", title: "No", width: "3%", minWidth:50, },
|
|
{ field: "BP_NM", title: "거래처", width: "8%", minWidth:80, headerSort: true,},
|
|
{ field: "EST_UID", title: "견적코드", width: "12%", minWidth:120, headerSort: true,},
|
|
{ field: "EST_TITLE", title: "견적타이틀", width: "22%", minWidth:300, formatter: (cell) => { let title = cell.getValue().replaceAll('\n','<br>'); return title; }},
|
|
{ field: "BP_PRSN_NM", title: "담당자", width: "10%", minWidth:100, headerSort: true, },
|
|
{ field: "EST_AMT", title: "금액", width: "8%", minWidth:80, headerSort: true, formatter: 'money', formatterParams:{precision:0}, },
|
|
{ field: "EST_DATE", title: "견적일", width: "7%", minWidth:80, headerSort: true, },
|
|
{ field: "SCS_FLG", title: "체결여부", width: "5%", minWidth:60, formatter: tb_common_funtions.formatterToggleboxIcon, formatterParams: {checkval:'Y'}, },
|
|
{ field: "MAKE_TM", title: "작성일", width: "7%", minWidth:80, headerSort: true, },
|
|
{ field: "EDIT_TM", title: "수정일", width: "7%", minWidth:80, headerSort: true, },
|
|
{ field: "USE_FLG", title: "사용여부", width: "5%", minWidth:60, formatter: tb_common_funtions.formatterToggleboxGreenIcon, formatterParams: {checkval:'Y'}, },
|
|
{ field: "", title: "다운로드", width: "6%", minWidth:60, formatter: tb_common_funtions.formatterButton, formatterParams: {
|
|
btnClass: 'btn btn-sm btn-success text-white',
|
|
btnTitle: '<i class="bi bi-filetype-xlsx"></i>견적서',
|
|
event: 'click',
|
|
cfunc: (cell)=>{
|
|
excelReport_dm.getEstiExcel(`견적서 (${cell.row.data.EST_UID}).xlsx`,cell.row.data.EST_UID,[cell.row.data.EST_ID]);
|
|
},
|
|
},
|
|
},
|
|
];
|
|
|
|
_this.tblList = new Tabulator("#tblEstimateList",{
|
|
layout: "fitColumns",
|
|
height: "100%",
|
|
data: [], //기본 데이터
|
|
columns: fields, //컬럼 설정
|
|
columnDefaults: { //컬럼 공통 규칙
|
|
sorter:()=>{},
|
|
headerSort: false,
|
|
vertAlign: "middle",
|
|
hozAlign: "center",
|
|
resizable: "header",//Resize 는 헤더에서만 가능
|
|
headerHozAlign: "center", //헤더 정렬
|
|
headerSortTristate: true, //데이터 정렬 => 정/역/초기화
|
|
},
|
|
footerElement:'<ul class="pagination justify-content-center align-items-center mb-1"><li><a class="pn_link npage btn btn-light"><span class="f_page">1</span></a></li></ul>',
|
|
headerSortElement: "<i class='bi'></i>", //정렬 아이콘
|
|
});
|
|
|
|
_this.tblList.on("tableBuilt", () => { //Tabulator 초기 데이터 불러오기 이벤트
|
|
_this.getMainList();
|
|
});
|
|
_this.tblList.on("rowClick", function(e,tgt){ //Tabulator Row Click
|
|
_this.rowClick && _this.rowClick(e,tgt);
|
|
});
|
|
_this.tblList.on("cellClick", function(e,tgt){ //Tabulator Cell Click
|
|
_this.cellClick && _this.cellClick(e,tgt);
|
|
});
|
|
|
|
_this.tblList.on("cellEdited", function(cell){ //Tabulator Cell Click
|
|
_this.cellEdited && _this.cellEdited(cell);
|
|
});
|
|
|
|
_this.tblList.on("headerClick", (e,tgt) => { //Tabulator cell Edited
|
|
_this.columnSort && _this.columnSort(e,tgt);
|
|
});
|
|
|
|
['click','keypress'].forEach(evt => document.querySelector("#bntListSearch").addEventListener(evt,()=>{
|
|
_this.searchData = {
|
|
BP_NM : document.querySelector('#S_BP_NM').value||'',
|
|
EST_UID : document.querySelector('#S_EST_UID').value||'',
|
|
SCS_FLG : document.querySelector('#S_SCS_FLG').checked?'Y':'',
|
|
USE_FLG : document.querySelector('#S_USE_FLG').checked?'Y':'',
|
|
LINE_NUM : document.querySelector('#S_LINE_NUM').value||'',
|
|
NOW_PAGE : 1,
|
|
}; // _this.searchData 는 전체적으로 이용되므로 간략화 금지
|
|
_this.getMainList(_this.searchData);
|
|
}));
|
|
['click','keypress'].forEach(evt => document.querySelector("#btnAddEstimate").addEventListener(evt,()=>{Tb_funcs_est_detail.initModal();}));
|
|
['click','keypress'].forEach(evt => document.querySelector("#btnSaveEstimate").addEventListener(evt,()=>{_this.setStatus();}));
|
|
['click','keypress'].forEach(evt => document.querySelector("#btnExcelDown").addEventListener(evt,()=>{_this.excelDataLoad(_this.tblList,'견적리스트')}));
|
|
['change','keydown','keyup'].forEach(evt => document.querySelectorAll("#S_BP_NM, #S_SCS_FLG, #S_USE_FLG").forEach(tgt=>tgt.addEventListener(evt,()=>{Tb_funcs.setFilter()})));
|
|
};
|
|
|
|
excelDataLoad(table_block, title) { //페이징 처리된 리스트에서 엑셀 전체 다운
|
|
let _this = this;
|
|
let filename = title + "_"+luxon.DateTime.now().toFormat('yyyyMMdd')+".xlsx";
|
|
|
|
ajax_json({
|
|
url: _this.estimate_ajax_url,
|
|
data: {..._this.searchData, mode: 'getEstimateList', LINE_NUM: 999999999 },
|
|
success: function (data) {
|
|
if (data.code) {
|
|
tb_common_funtions.tabu2xls(table_block, filename, title, data.data.map( row => {
|
|
return row;
|
|
} ));
|
|
}else{
|
|
kuls_alert(data.mesg);
|
|
}
|
|
},
|
|
error: function (request, status, error) {
|
|
kuls_alert(error.message);
|
|
},
|
|
complete: function () {}
|
|
});
|
|
}
|
|
}
|
|
|
|
class Tb_class_est_detail {
|
|
constructor(){
|
|
let _this = this;
|
|
_this.estimate_ajax_url = "./estimate.ajax.php";
|
|
_this.tblList = "";
|
|
_this.saveExcel = tb_common_funtions.tabu2xls; //엑셀 다운로드
|
|
_this.EST_ID = "";
|
|
_this.base_info = {
|
|
EST_TEST_EXP: '제외',
|
|
EST_TRAN_COND: '운송은 제외임',
|
|
EST_TAX: '별도',
|
|
EST_PACK_EXP: '제외',
|
|
EST_EXP_DAYS: '15일',
|
|
EST_PAY_COND: '정기결제',
|
|
EST_DEL_LIMT: '협의',
|
|
EST_SUP_COND: '가공+DI보증',
|
|
EST_TEXT: '주> 1. 3.2검사 조건의 견적입니다.\n' +
|
|
' 2. 기상검사를 요구할시는 별도로 협의하는 조건입니다. (검사 관련 확정시에 별도 협의하는 조건입니다.)\n' +
|
|
' 3. UT 및 제품 표면조도는 Ra12.5 견적조건입니다.\n' +
|
|
' 4. 태웅 검사 표준절차서에 준한 견적 조건입니다.\n' +
|
|
' 5. 운송은 제외하는 견적조건입니다.',
|
|
EST_ETC: '1. 분철 반납임\n' +'2. 운송은 제외임',
|
|
};
|
|
}
|
|
|
|
//견적 상세 로드
|
|
async getEstimateInfo (EST_ID, funcs) {
|
|
let _this = this;
|
|
let rval = {};
|
|
await ajax_json({
|
|
url: _this.estimate_ajax_url,
|
|
type: "POST",
|
|
data: {
|
|
mode: 'getEstimateInfo',
|
|
EST_ID,
|
|
},
|
|
success: function (data) {
|
|
if( data.code ){
|
|
funcs && funcs(data.data);
|
|
rval = data.data;
|
|
}else{
|
|
kuls_alert(data.mesg);
|
|
}
|
|
},
|
|
error: function (request, status, error) {
|
|
kuls_alert(error.message);
|
|
},
|
|
complete: function(){
|
|
}
|
|
});
|
|
return rval;
|
|
};
|
|
|
|
setPopForm (data) {
|
|
let _this = this;
|
|
|
|
Object.keys(data).forEach( key => {
|
|
if( key === 'ITEMS' ){
|
|
_this.tblList.setData(data[key]);
|
|
}else{
|
|
let realkey = key;
|
|
if( ['BP_CD','BP_NM','EMP_NO','EMP_NM','EMP_TEL'].includes(key) ){
|
|
realkey = 'EST_'+key;
|
|
}
|
|
if( data[key] != null && document.forms['frmEstimate'].querySelector('[name='+realkey+']') ){
|
|
document.forms['frmEstimate'].querySelector('[name='+realkey+']').setAttribute(['data-defval'], data[key]);
|
|
|
|
if( key === 'EST_ID' ){
|
|
document.forms['frmEstimate'].querySelector('[name=EST_ID]').setAttribute('readonly',true);
|
|
}
|
|
}
|
|
}
|
|
});
|
|
formSetVal(document.forms['frmEstimate']);
|
|
document.querySelector("#EST_AMT_VIEW").innerHTML = currency(data.EST_AMT, {symbol: '', decimal: ',', precision:0}).format();
|
|
};
|
|
|
|
putEstimate = (e) => {
|
|
e.preventDefault();
|
|
|
|
let _this = this;
|
|
|
|
let formdata = form2Json(document.frmEstimate);
|
|
if( formdata['EST_ID_OLD'] ){
|
|
formdata['mode'] = "setEstimate";
|
|
}else{
|
|
formdata['mode'] = "putEstimate";
|
|
}
|
|
|
|
let postdata = _this.tblList.getData().reduce( (nrow, mem, i) => {
|
|
mem._STATUS_ && nrow.push({...mem});
|
|
return nrow;
|
|
}, [] );
|
|
formdata['PRSN'] = JSON.stringify(postdata);
|
|
|
|
ajax_json({
|
|
url: _this.estimate_ajax_url,
|
|
type: "POST",
|
|
data: formdata,
|
|
success: function (data) {
|
|
if( data.code ){
|
|
kuls_success("적용 되었습니다.");
|
|
Tb_funcs.getMainList(Tb_funcs.searchData);
|
|
Tb_funcs.putEstimateModal.delete();
|
|
}else{
|
|
kuls_alert(data.mesg);
|
|
}
|
|
},
|
|
error: function (request, status, error) {
|
|
kuls_alert(error.message);
|
|
},
|
|
complete: function(){
|
|
}
|
|
});
|
|
};
|
|
|
|
revokeData(row){
|
|
let _this = this;
|
|
row.update({USE_FLG:"Y"});
|
|
row.getElement().classList.remove("del-row");
|
|
};
|
|
|
|
initModal( EST_ID ) {
|
|
let _this = this;
|
|
vnLoad( '', './estimate.pop.inc.php', '', function(loadHtml){
|
|
_this.putEstimateModal = kuls_modal(loadHtml, {dontclose:true});
|
|
document.querySelector(".btn_close").addEventListener("click", ()=>_this.putEstimateModal.remove());
|
|
|
|
_this.init( EST_ID );
|
|
});
|
|
};
|
|
|
|
addRow( cnt ) {
|
|
let _this = this;
|
|
for( let a=0 ; a<(cnt||1) ; a++ ){
|
|
_this.tblList.addRow({'_STATUS_':'I', 'USE_FLG':'Y'});
|
|
}
|
|
}
|
|
|
|
delRow(){
|
|
let _this = this;
|
|
_this.tblList.getSelectedRows().forEach( row => {
|
|
row.update({_STATUS_:row.getData()._STATUS_||'U',USE_FLG:'N'});
|
|
row.getElement().classList.add('del-row');
|
|
} );
|
|
}
|
|
|
|
cellEdited(cell) {
|
|
let _this = this;
|
|
let rowval = cell.getData();
|
|
rowval._STATUS_ = rowval._STATUS_||'U';
|
|
switch( cell.getField() ){
|
|
case "EST_DTL_EA" :
|
|
case "EST_DTL_PRC" :
|
|
rowval.EST_DTL_AMT = Number(rowval.EST_DTL_EA) * Number(rowval.EST_DTL_PRC);
|
|
|
|
let sumamt = _this.tblList.getData().filter( row => row.USE_FLG === 'Y' ).reduce( (sum, row) => { sum += Number(row.EST_DTL_AMT); return sum; }, 0 );
|
|
document.querySelector("#EST_AMT").value = sumamt;
|
|
document.querySelector("#EST_AMT_VIEW").innerHTML = currency(sumamt, {symbol: '', decimal: ',', precision:0}).format();
|
|
break;
|
|
}
|
|
cell.getRow().update(rowval);
|
|
};
|
|
|
|
init(EST_ID) {
|
|
let _this = this;
|
|
const fields_member = [
|
|
{ formatter:"rowSelection", titleFormatter: "rowSelection", width: "2%", minWidth:36, headerSort: false, },
|
|
{ field: "EST_DTL_SEQ", title: "순번", width: "5%", minWidth:50, editor:'input', },
|
|
{ field: "EST_DTL_ITEM", title: "품명 및 규격", width: "28%", minWidth:300, editor:'input', },
|
|
{ field: "EST_DTL_MATR", title: "재질", width: "16%", minWidth:14, editor:'input', },
|
|
{ field: "EST_DTL_EA", title: "수량", width: "6%", minWidth:60, editor:'input', formatter: "money", formatterParams:{precision:0}, },
|
|
{ field: "EST_DTL_WGT", title: "중량", width: "10%", minWidth:100, editor:'input', formatter: "money", formatterParams:{precision:0}, },
|
|
{ field: "EST_DTL_PRC", title: "단가", width: "10%", minWidth:100, editor:'input', formatter: "money", formatterParams:{precision:0}, },
|
|
{ field: "EST_DTL_AMT", title: "금액", width: "12%", minWidth:120, formatter: 'money', formatterParams:{precision:0}, },
|
|
];
|
|
|
|
_this.tblList = new Tabulator("#tblEstimateMember",{
|
|
layout: "fitColumns",
|
|
data: [], //기본 데이터
|
|
height: "100%",
|
|
columns: fields_member, //컬럼 설정
|
|
columnDefaults: { //컬럼 공통 규칙
|
|
vertAlign: "middle",
|
|
hozAlign: "center",
|
|
resizable: "header",//Resize 는 헤더에서만 가능
|
|
headerHozAlign: "center", //헤더 정렬
|
|
headerSortTristate: true, //데이터 정렬 => 정/역/초기화
|
|
},
|
|
headerSortElement: "<i class='bi'></i>", //정렬 아이콘
|
|
});
|
|
|
|
_this.tblList.on("cellEdited", function(cell) { //cell modify
|
|
_this.cellEdited && _this.cellEdited(cell);
|
|
});
|
|
_this.tblList.on("cellClick", function(e, tgt) { //cell click
|
|
_this.cellClick && _this.cellClick(tgt);
|
|
});
|
|
_this.tblList.on("rowDeselected", (row) => { //cell 선택해제시
|
|
_this.revokeData && _this.revokeData(row);
|
|
});
|
|
_this.tblList.on("tableBuilt", function(){ //테이블 init 후
|
|
if( EST_ID ){
|
|
_this.getEstimateInfo(EST_ID, (data)=>{_this.setPopForm(data)});
|
|
}else{
|
|
_this.setPopForm(_this.base_info);
|
|
_this.addRow();
|
|
}
|
|
});
|
|
|
|
document.querySelector("form[name=frmEstimate]").addEventListener("submit", _this.putEstimate);
|
|
['click','keypress'].forEach( evt => document.querySelector("#btnGetBp").addEventListener(evt, ()=>{
|
|
popPartnerList({tgt_id:'#EST_BP_CD',tgt_full_name:'#EST_BP_NM',tgt_chname:'#BP_PRSN_NM'});
|
|
} ) );
|
|
['click','keypress'].forEach( evt => document.querySelector("#btnAddItem").addEventListener(evt, ()=>{ _this.addRow(); } ) );
|
|
['click','keypress'].forEach( evt => document.querySelector("#btnAddItem5").addEventListener(evt, ()=>{ _this.addRow(5); } ) );
|
|
['click','keypress'].forEach( evt => document.querySelector("#btnDelItem").addEventListener(evt, ()=>{ _this.delRow(); } ) );
|
|
};
|
|
}
|
|
|
|
const Tb_funcs = new Tb_class();
|
|
const Tb_funcs_est_detail = new Tb_class_est_detail();
|
|
Tb_funcs.init(); |