/**
 * admin/payment
 */
var mcare_admin_payment = function(){
	//상속
	mcare_admin.call(this);
	
	var self = this;
	//변수설정
	var $grid = $("#grid"),
		$crudServiceBaseUrl = contextPath + "/admin/payment";
		

	/**
	 * 초기화
	 */
	this.init = function(){
		initGrid();
		addEvent();
	};
	/**
	 * 이벤트 등록
	 */
	var addEvent = function(){

	};

	
	/**
	 * 데이터 소스 설정
	 */
	var setDataSource = function(){
		
		var dataSource = new kendo.data.DataSource({
			transport: {
				read: {
					url: $crudServiceBaseUrl + "/getList.json",
					method: "post",
					dataType: "json",
					contentType: "application/json"
				},
				parameterMap: function( options, operation ){
					return self.util.stringifyJson( options );
				}
			},
			schema: { 
				total : "totalCount",
				data : function(result){
					return result.data;
				},
				model: {
					id: "transValue",
					fields: {
						transValue: { type: "string", editable: false},
						hospitalValue: { type: "string", editable: false},
						msgType: { type: "string", editable: false},
						userId: { type: "string", editable: false},
						amountValue : { type:"number",editable:false},
						transDt : {type:"string",editable:false},
						exameDt : {type:"string",editable:false}
					}
				}
			},
			change: function(e) {
				// update chart
			},
			pageSize: 15,
			serverPaging : true
		});
		
		return dataSource;
	};
	var dataSource = setDataSource();
	/**
	 * 그리드 초기화
	 */
	var initGrid = function(){
		// 그리드 옵션
		var option = {
			dataSource: dataSource,
	        pageable: true,
	        resizable: true,
	        sortable: true,
	        selectable: true,
	        editable: false,
	        height : 520,
	        columns : [
                 { field: "hospitalValue", title: "병원", width: 50, attributes: {style: "text-align: center;"},template:hospitalTemplate} 
                ,{ field: "msgType", title: "승인/취소", width: 60, attributes: {style: "text-align: center;"},template:msgTypeTemplate}
                ,{ field: "userId", title: "환자번호", width: 80, attributes: {style: "text-align: center;"}}
                ,{ field: "amountValue", title: "금액", width: 50, attributes: {style: "text-align: center;"},template:amountValueTemplate}
                ,{ field: "transDt", title: "결제일",width: 80, attributes: {style: "text-align: center;"}}
                ,{ field: "transValue",title:"승인번호",sortable:false, filterable:false, width: 50, attributes: {style: "text-align: center;"}}
                ,{ field: "examDt", title: "진료일",width: 80, attributes: {style: "text-align: center;"},template:examDtTemplate}
	        ]
//	        ,filterable:  {
//    			extra : false, 
//    			operators : {
//    				string : {
//    					contains : " 포함 "
//    				}
//    			}
//    		}
	    };
		function hospitalTemplate(data){
			return data.hospitalValue === "031" ? "본원" : "칠곡";
		};
		function msgTypeTemplate(data){
			return data.msgType === "02" ? "승인" : "취소";
		};
		function examDtTemplate(data){
			return data.examDt !== null ? data.examDt.split(" ")[0] :""; 
		};
		function amountValueTemplate(data){
			return data.amountValue !== null ? $.number( data.amountValue,0,'.',',' ) : "";
		};
		// 그리드 초기화
		self.grid( $grid, option );
	};
	
};
