/*
 *========================================================================
 *
 *   시스템명 : 요금징수 시스템
 *   파 일 명 : wrk_data_handle.pc
 *   작 성 자 : 조보용
 *   작 성 일 : 2012.09.24
 *   수 정 일 :
 *   설    명 :
 *
 *========================================================================
*/

#include <stdio.h>
#include <unistd.h>
#include <strings.h>
#include <string.h>
#include <iconv.h>
#include "bas_tbl.h"
#include "passraw.h"
#include "wrk_data_def.h"
#include "wrk_end_def.h"
#include "iss_comp.h"

#define _WEBSVR_
#define _ORACLE_

struct hi_comm_ctrl hi_comm_ctrl;
//static struct iss_comp_tbl iss_comp_tbl_f;;

/*
 *========================================================================
 *
 *   함 수 명 : proc_close_pass()
 *   작 성 자 : 조보용
 *   작 성 일 : 2019.06.10
 *   수 정 일 :
 *   설    명 : 야간계수
 *
 *========================================================================
*/

int proc_close_pass(char *target, char *rtn)
{
    struct rcv_lane_data  *rd;
    struct hi_close_pass *pk_in;
    int    iCrjb;
    int    start_sno;
    int    end_sno;
    int    ii, nResult;
    char   tmp[20]; memset(tmp, 0x00, sizeof(tmp));
	char   rBuffer[MAX_STRING_SIZE+1];
	char   mCarNo[3+1];
	
    char in_fare[2+1];
    char in_booth[2+1];
    char in_date[14+1];
	char in_car[16+1];
	char in_carkind[1+1];

	char c_io[1+1];
	//char in_date[8+1];
    //char in_time[6+1];
	
	int  d_seq = 0;
    int  in_count = 0;

    int  ret = 3;

#ifdef _WEBSVR_
	size_t in_size;
	size_t out_size;
	size_t out_buf_left;
	char   orgCarNo[255+1];
	char   szCarNo[255+1];
	char* in_buf;
	char* out_buf;
	
	memset(orgCarNo, 0x00, sizeof(orgCarNo));
	memset(szCarNo, 0x00, sizeof(szCarNo));
	
	iconv_t ic = iconv_open("UTF-8", "EUC-KR");

	if(ic == (iconv_t) -1)
	{
		que_log("###### Not Supported ICONV Code ###### \n");
	}
#endif
    memset(in_fare , 0x00, sizeof(in_fare ));
    memset(in_booth, 0x00, sizeof(in_booth));
    memset(in_date , 0x00, sizeof(in_date ));

    //memset(in_time , 0x00, sizeof(in_time ));

    //rtn = (char *)rBuffer;
    rd = (struct rcv_lane_data *)target;
    pk_in = (struct hi_close_pass *)rd->buf;

    sprintf(in_fare, "%.2s", rd->plz_id);
	//in_fare[2] = '\0';
    sprintf(in_booth, "%.2s", rd->lane_no);
	//in_booth[2] = '\0';
    sprintf(in_date, "%.4s%.2s%.2s%.2s%.2s%.2s", pk_in->year, pk_in->month, pk_in->day, pk_in->hour, pk_in->min, pk_in->sec);
	//in_booth[14] = '\0';
	printf("일련번호[%.6s]\n", pk_in->serial_no);
	d_seq = lb_data2atoi(pk_in->serial_no, 6);
	
	memcpy(in_car, pk_in->car_no, 16);
    del_space(in_car);
	if(strlen(in_car) == 0)
		sprintf(in_car, "????????????");
	//in_car[16] = '\0';

	in_carkind[0] = pk_in->car_kind;
	in_carkind[1] = '\0';

	c_io[0] = pk_in->io_div;
	c_io[1] = '\0';
#if 1
    //del_space(in_car);
que_log("차량번호[%s]\n", in_car);
    sprintf(mCarNo, "%.2s%c", in_car + strlen(in_car) - 6, '\0');
que_log("중간번호[%.2s]\n", mCarNo);
    if(strcmp(mCarNo, "바") == 0 || strcmp(mCarNo, "사") == 0 || strcmp(mCarNo, "아") == 0 || strcmp(mCarNo, "자") == 0)
	{
		if(in_carkind[0] - '0' == 1)
		{
			in_carkind[0] = '6';
			in_carkind[1] = '\0';
		}else if(in_carkind[0] - '0' == 2)
		{
			in_carkind[0] = '7';
			in_carkind[1] = '\0';
		}
		que_log("Get Mid No[%s]", mCarNo);
	}
	//sprintf(tmp, "%s%c", in_car, '\0');
#endif
	//sprintf(in_time, "%.2s%.2s%.2s", pk_in->hour, pk_in->min, pk_in->sec);

    in_count = 1;

//printf("[%s][%s][%s][%s][%d]\n", in_fare, in_booth, in_date, in_time, in_count);

// que_log("[%s][%s][%s][%d][%s][%s][%s]\n", in_fare, in_booth, in_date, d_seq, in_car,  in_carkind, c_io);

#ifdef _WEBSVR_
	sprintf(orgCarNo, "%.16s", in_car);
	if(strlen(orgCarNo) == 0)
	{
		memset(in_car, 0x00, sizeof(in_car));
		sprintf(in_car, "????????????");
	}else
	{
		memset(in_car, 0x00, sizeof(in_car));
		in_size = strlen(orgCarNo);
		out_size = sizeof(wchar_t) * in_size * 4;
			
		in_buf = orgCarNo;
		out_buf = szCarNo;
		out_buf_left = out_size;
			
		nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);
		if(nResult == -1)
		{
			que_log("ICONV FAILED [%d]\n", nResult);
		}

que_log("ICONV in_size[%d] out_size[%d] [%s]\n", in_size, out_size - out_buf_left, szCarNo);
		sprintf(in_car, "%.16s", szCarNo);
	}
	iconv_close(ic);
	sprintf(rBuffer, "%s%s%s%06d%-16s%s%s", in_fare, in_booth, in_date, d_seq, in_car,  in_carkind, c_io);
que_log("1111111 [%s] 111111\n", rBuffer);
	memcpy(rtn, &rBuffer, strlen(rBuffer));
#endif
	
    return(0);
}

/*
 *========================================================================
 *
 *   함 수 명 : proc_hnd_data()
 *   작 성 자 : 조보용
 *   작 성 일 : 2019.06.10
 *   수 정 일 :
 *   설    명 : 처리
 *
 *========================================================================
*/

int proc_hnd_data(char *target, char *rtn)
{
    struct rcv_lane_data  *rd;
    struct hi_hnd_data *pk_in;
    int    iCrjb;
    int    start_sno;
    int    end_sno;
    int    ii, nResult;
    char   tmp[20]; memset(tmp, 0x00, sizeof(tmp));
	char   rcv_hnd[2+1];
	char   rBuffer[MAX_STRING_SIZE+1];

    char in_id[4+1];
    char in_fare[2+1];
    char in_booth[2+1];
    char in_date[14+1];
    char in_seqno[9+1];
    char in_rf_seqno[9+1];
    char in_car[16+1];
    char in_collect[2+1];
    char in_army[1+1];

    char in_stop[50+1];
    char in_move[32+1];
    char in_amount[6+1];
    char in_x[4+1];
    char in_y[4+1];
    char in_garo[4+1];
    char in_sero[4+1];
    char in_card_ret[1+1];
    char in_other[1+1];
    char in_rfid_kbn[2+1];
    char in_tag[48+1];
	char in_carkind[1+1];

/* 2019.07.26 감지시간추가 */
    char in_sens_time[6+1];
    char in_collect_new[2+1];

	char c_io[1+1];
	int  d_seq = 0;
    int  ret = 3;

#ifdef _WEBSVR_
	size_t in_size;
	size_t out_size;
	size_t out_buf_left;
	char   orgCarNo[255+1];
	char   szCarNo[255+1];
	char* in_buf;
	char* out_buf;
	
	memset(orgCarNo, 0x00, sizeof(orgCarNo));
	memset(szCarNo, 0x00, sizeof(szCarNo));
	
	iconv_t ic = iconv_open("UTF-8", "EUC-KR");

	if(ic == (iconv_t) -1)
	{
		que_log("###### Not Supported ICONV Code ###### \n");
	}
#endif
    memset(in_id      , 0x00, sizeof(in_id      ));
    memset(in_fare    , 0x00, sizeof(in_fare    ));
    memset(in_booth   , 0x00, sizeof(in_booth   ));
    memset(in_date    , 0x00, sizeof(in_date    ));
    memset(in_seqno   , 0x00, sizeof(in_seqno   ));
    memset(in_rf_seqno, 0x00, sizeof(in_rf_seqno));
    memset(in_car     , 0x00, sizeof(in_car     ));
    memset(in_collect , 0x00, sizeof(in_collect ));
    memset(in_army    , 0x00, sizeof(in_army    ));
    
    memset(in_stop    , 0x00, sizeof(in_stop    ));
    memset(in_move    , 0x00, sizeof(in_move    ));
    memset(in_amount  , 0x00, sizeof(in_amount  ));
    memset(in_x       , 0x00, sizeof(in_x       ));
    memset(in_y       , 0x00, sizeof(in_y       ));
    memset(in_garo    , 0x00, sizeof(in_garo    ));
    memset(in_sero    , 0x00, sizeof(in_sero    ));
    memset(in_card_ret, 0x00, sizeof(in_card_ret));
    memset(in_other   , 0x00, sizeof(in_other   ));
    memset(in_rfid_kbn, 0x00, sizeof(in_rfid_kbn));
    memset(in_tag     , 0x00, sizeof(in_tag     ));
	memset(in_carkind , 0x00, sizeof(in_carkind ));

	memset(in_sens_time , 0x00, sizeof(in_sens_time ));

    //rtn = (char *)rBuffer;
    rd = (struct rcv_lane_data *)target;
    pk_in = (struct hi_hnd_data *)rd->buf;

    sprintf(in_id, "%.4s", pk_in->wrkr_no);
    sprintf(in_fare, "%.2s", pk_in->plz_id);
    sprintf(in_booth, "%.2s", rd->lane_no);
    sprintf(in_date, "%.8s%.2s%.2s%.2s", pk_in->wrk_date, pk_in->hnd_info.hnd_hour, pk_in->hnd_info.hnd_min, pk_in->hnd_info.hnd_sec);

    sprintf(c_io, "%c", pk_in->io_div);

//규칙에 따라 변경
    //sprintf(in_seqno, "%c%.2s%05d", pk_in->plz_id[1], rd->lane_no, lb_data2atoi(pk_in->serial_no, 6)); //10->9
    //sprintf(in_rf_seqno, "%c%.2s%05d", pk_in->plz_id[1], rd->lane_no, lb_data2atoi(pk_in->serial_no, 6));
	sprintf(in_seqno, "%08u", lb_data2atoi(pk_in->serial_no, 6)); //10->9
	sprintf(in_rf_seqno, "%08u", lb_data2atoi(pk_in->serial_no, 6));
	
	d_seq = lb_data2atoi(pk_in->sence_seq_no, 6);

    sprintf(in_car, "%.16s", pk_in->car_no1);
	del_space(in_car);
	
	if(strlen(in_car) == 0)
		strncpy(in_car, "????????????", 12);

    memcpy(rcv_hnd, pk_in->hnd_info.rcpt_hnd, 2);
	rcv_hnd[2] = '\0';
// 숫자
    sprintf(in_amount, "%.6s%c", pk_in->hnd_info.pass_fare, '\0');

    switch(lb_data2atoi(rcv_hnd, 2))
	{
		case 31:
			sprintf(in_carkind, "6");
		break;
		case 36:
			sprintf(in_carkind, "7");
		break;
		default:
		    sprintf(in_carkind, "%c", pk_in->car_kind);
		break;
	}

	if(lb_data2atoi(rcv_hnd, 2) > 19 && lb_data2atoi(rcv_hnd, 2) < 30 || lb_data2atoi(rcv_hnd, 2) > 59 && lb_data2atoi(rcv_hnd, 2) < 70)
	{
		sprintf(in_seqno, "%c%.2s%05d", pk_in->plz_id[1], rd->lane_no, lb_data2atoi(pk_in->serial_no, 6)); //10->9
		sprintf(in_rf_seqno, "%c%.2s%05d", pk_in->plz_id[1], rd->lane_no, lb_data2atoi(pk_in->serial_no, 6));
	}

	//sprintf(tmp, "%.2s%c", pk_in->hnd_info.rcpt_hnd, '\0');
	//sprintf(in_collect, "%.2s", pk_in->hnd_info.rcpt_hnd);

    switch(lb_data2atoi(rcv_hnd, 2))
	{
		case 10:
			sprintf(in_collect, "10");
			break;
		case 11:
		case 12:
		case 13:
		case 14:
			sprintf(in_collect, "11");
			break;
		case 20:
			sprintf(in_collect, "20");
			break;
		case 21:
        case 61:
			sprintf(in_collect, "21");
			break;
		case 22:
			sprintf(in_collect, "22");
			break;
		case 23:
		case 25:
		case 27:
        case 62:
		case 63:
		case 64:
		case 66:
			sprintf(in_collect, "23");
			break;
		case 24:
		case 26:
		case 28:
			sprintf(in_collect, "24");
			break;
		case 30:
			sprintf(in_collect, "30");
			break;
		case 31:
		case 35:
		case 36:
		case 37:
		case 38:
		case 39:
		case 70:
		case 72:
		case 73:
		case 75:
		case 76:
		case 77:
		case 78:
		case 79:
			sprintf(in_collect, "34");
			break;
		case 32:
			sprintf(in_collect, "32");
			break;
		case 33:
			sprintf(in_collect, "33");
			break;
		case 34:
		case 65:
		case 67:
			sprintf(in_collect, "30");
			break;
		case 71:
		case 74:
			sprintf(in_collect, "31");
			break;
		case 40:
		case 41:
			sprintf(in_collect, "40");
			break;
		case 50:
			sprintf(in_collect, "50");
			break;
		case 51:
			sprintf(in_collect, "51");
			break;
		case 52:
			sprintf(in_collect, "52");
			break;
		case 53:
		case 55:
		case 56:
			sprintf(in_collect, "53");
			break;
		case 54:
			sprintf(in_collect, "54");
			break;
        case 60:
            if(lb_data2atoi(in_amount, 6) > 1000)
                sprintf(in_collect, "21");
            else
                sprintf(in_collect, "23");
            break;
		default:
			sprintf(in_collect, "00");
			break;
	}

    in_army[0] = '0';

    sprintf(in_stop, "%.8s_%.2s%.2s%.2s00_%06d%.2s_%c%.2s%c_%s_%c",
            pk_in->wrk_date, pk_in->hnd_info.hnd_hour, pk_in->hnd_info.hnd_min, pk_in->hnd_info.hnd_sec,
            lb_data2atoi(pk_in->serial_no, 6), pk_in->hnd_info.rcpt_hnd, pk_in->plz_id[1], rd->lane_no, pk_in->io_div,
            in_car, pk_in->car_kind);

    in_move[0] =  ' ';

// 숫자
    memcpy(in_x, pk_in->x_point+1, 3);
	in_x[3] = '\0';
// 숫자
    memcpy(in_y, pk_in->y_point+1, 3);
	in_y[3] = '\0';
// 숫자
    memcpy(in_garo, pk_in->img_width+1, 3);
	in_garo[3] = '\0';
// 숫자
    memcpy(in_sero, pk_in->img_heigh+1, 3);
	in_sero[3] = '\0';

    in_card_ret[0] = pk_in->hnd_info.refund_yn;
    //sprintf(in_rfid_kbn, "%c", pk_in->hnd_info.issue_code[0]);

	switch(lb_data2atoi(rcv_hnd, 2))
	{
		case 10:
		case 11:
		case 20:
		case 21:
		case 22:
		case 23:
		case 24:
		case 30:
		case 31:
		case 32:
		case 34:
		case 35:
		case 36:
		case 37:
		case 38:
		case 39:
		case 70:
		case 71:
		case 72:
		case 73:
		case 74:
		case 75:
		case 76:
		case 77:
		case 78:
		case 79:
		case 40:
		case 41:
		case 50:
		case 51:
		case 52:
		case 53:
		case 54:
			sprintf(in_rfid_kbn, "00");
			break;
		case 12:
		case 25:
		case 26:
		case 55:
			sprintf(in_rfid_kbn, "01");
			break;
		case 13:
		case 14:
		case 27:
		case 28:
		case 56:
			sprintf(in_rfid_kbn, "03");
			break;
		case 33:
			sprintf(in_rfid_kbn, "02");
			break;
        case 60:
		case 61:
		case 62:
		case 63:
		case 64:
		case 65:
		case 66:
		case 67:
            sprintf(in_rfid_kbn, "99");
            break;
		default:
			sprintf(in_rfid_kbn, "00");
			break;
	}

	if(lb_data2atoi(tmp, 2) == 53)
		sprintf(in_rfid_kbn, "04");

    snprintf(in_tag, 48+1, "%.4s00%.2s%.2s00%c000000%c0000%.24s", pk_in->wrk_no, rcv_hnd, pk_in->hnd_info.rcpt_div, pk_in->hnd_info.key_yn, pk_in->pre_yn, pk_in->tag_id2);

    in_other[0] = pk_in->wrk_no[3];
#if 1
/* 2019.07.26 감지시간추가 */
    snprintf(in_sens_time, 6+1, "%.6s", pk_in->sence_time);
#endif
/* que_log("처리 [%s][%s][%s][%s][%s][%s]\n", in_id, in_fare, in_booth, in_date, in_seqno, in_rf_seqno);
que_log("처리 [%s][%s][%s][%s][%s][%s]\n", in_car, in_collect, in_army, in_stop, in_move, in_amount);
que_log("처리 [%s][%s][%s][%s][%s][%s]\n", in_x, in_y, in_garo, in_sero, in_card_ret, in_other);
que_log("처리 [%s][%s][%s][%s]\n", in_rfid_kbn, in_tag, in_carkind, in_sens_time);

que_log("처리 [%02x][%02x][%02x][%02x][%02x][%02x]\n", in_id[4], in_fare[2], in_booth[2], in_date[14], in_seqno[9], in_rf_seqno[9]);
que_log("처리 [%02x][%02x][%02x][%02x][%02x][%02x]\n", in_car[16], in_collect[2], in_army[1], in_stop[50], in_move[1], in_amount[6]);
que_log("처리 [%02x][%02x][%02x][%02x][%02x][%02x]\n", in_x[4], in_y[4], in_garo[4], in_sero[4], in_card_ret[1], in_other[1]);
que_log("처리 [%02x][%02x][%02x]\n", in_rfid_kbn[2], in_tag[48], in_carkind[1]); */

//que_log("CAR_KIND[%s]\n", in_carkind);
    sprintf(in_collect_new, "%.2s%c", rcv_hnd, '\0');

#ifdef _WEBSVR_
    del_space(in_car);
	sprintf(orgCarNo, "%.16s", in_car);

	if(strlen(orgCarNo) == 0)
	{
		memset(in_car, 0x00, sizeof(in_car));
		sprintf(in_car, "????????????");
	}else
	{
		memset(in_car, 0x00, sizeof(in_car));
		in_size = strlen(orgCarNo);
		out_size = sizeof(wchar_t) * in_size * 4;
			
		in_buf = orgCarNo;
		out_buf = szCarNo;
		out_buf_left = out_size;
			
		nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);
		if(nResult == -1)
		{
			que_log("ICONV FAILED [%d]\n", nResult);
		}

que_log("ICONV in_size[%d] out_size[%d] [%s]\n", in_size, out_size - out_buf_left, szCarNo);
		sprintf(in_car, "%.16s", szCarNo);
	}
	iconv_close(ic);
	sprintf(rBuffer, "%s%s%s%s%s%s%-16s%s%s00%s%s%s%s%s%s%s%s%-48s%s%s%s%s",
			in_id, in_fare, in_booth, in_date, in_seqno, in_rf_seqno, 
			in_car, in_collect, in_army, in_amount,
			in_x, in_y, in_garo, in_sero, in_card_ret, in_other,
			in_rfid_kbn, in_tag, in_carkind, rcv_hnd, in_sens_time, c_io);
    //sprintf(rBuffer, "%08d", SQLCODE);
	memcpy(rtn, &rBuffer, strlen(rBuffer));
#endif
	
    return 0;
}

/*
 *========================================================================
 *
 *   함 수 명 : proc_card_data()
 *   작 성 자 : 조보용
 *   작 성 일 : 2019.06.10
 *   수 정 일 :
 *   설    명 : 카드 처리
 *
 *========================================================================
*/

int proc_card_data(char *target, char *rtn)
{
    struct rcv_lane_data  *rd;
    struct hi_crd_hnd_data *pk_in;
    int    iCrjb;
    int    start_sno;
    int    end_sno;
    int    ii, size, stsize;
    char   tmp[10+1]; memset(tmp, 0x00, sizeof(tmp));
	char   path[256]; memset(path, 0x00, sizeof(path));
	char   tmp_iss_cd[7]; memset(tmp_iss_cd, 0x00, sizeof(tmp_iss_cd));
	char   rBuffer[MAX_STRING_SIZE+1];
	FILE  *fp;
	struct iss_comp_tbl iss_comp_tbl_f;
	struct stat file_info;

    char in_id[4+1];
    char in_fare[2+1];
    char in_booth[2+1];
    char in_date[8+1];
    char in_time[6+1];
    char in_seqno[9+1];
    char in_kbn[1+1];
    char in_card[16+1];
    char in_collect[2+1];
    char in_be_amount[8+1];
    char in_amount[8+1];
    char in_re_amount[8+1];
    char in_terminal_id[9+1];
    char in_sam_id[16+1];
    char in_sam_seqno[10+1];
    char in_card_seqno[10+1];
    char in_algorithm_id[2+1];
    char in_key_version[2+1];
    char in_e_cash[2+1];
    char in_sam_tot_seqno[10+1];
    char in_sam_collect_cnt[5+1];
    char in_sam_tot_amount[10+1];
    char in_sign_value[8+1];
    char in_person_code[2+1];
    char in_zipge_id[12+1];
    char in_alias_no[10+1];
    char in_issue_id[7+1];
    int  ret = 3;

    memset(in_id             , 0x00, sizeof(in_id             ));
    memset(in_fare           , 0x00, sizeof(in_fare           ));
    memset(in_booth          , 0x00, sizeof(in_booth          ));
    memset(in_date           , 0x00, sizeof(in_date           ));
    memset(in_time           , 0x00, sizeof(in_time           ));
    memset(in_seqno          , 0x00, sizeof(in_seqno          ));
    memset(in_kbn            , 0x00, sizeof(in_kbn            ));
    memset(in_card           , 0x00, sizeof(in_card           ));
    memset(in_collect        , 0x00, sizeof(in_collect        ));
    memset(in_be_amount      , 0x00, sizeof(in_be_amount      ));
    memset(in_amount         , 0x00, sizeof(in_amount         ));
    memset(in_re_amount      , 0x00, sizeof(in_re_amount      ));
    memset(in_terminal_id    , 0x00, sizeof(in_terminal_id    ));
    memset(in_sam_id         , 0x00, sizeof(in_sam_id         ));
    memset(in_sam_seqno      , 0x00, sizeof(in_sam_seqno      ));
    memset(in_card_seqno     , 0x00, sizeof(in_card_seqno     ));
    memset(in_algorithm_id   , 0x00, sizeof(in_algorithm_id   ));
    memset(in_key_version    , 0x00, sizeof(in_key_version    ));
    memset(in_e_cash         , 0x00, sizeof(in_e_cash         ));
    memset(in_sam_tot_seqno  , 0x00, sizeof(in_sam_tot_seqno  ));
    memset(in_sam_collect_cnt, 0x00, sizeof(in_sam_collect_cnt));
    memset(in_sam_tot_amount , 0x00, sizeof(in_sam_tot_amount ));
    memset(in_sign_value     , 0x00, sizeof(in_sign_value     ));
    memset(in_person_code    , 0x00, sizeof(in_person_code    ));
    memset(in_zipge_id       , 0x00, sizeof(in_zipge_id       ));
    memset(in_alias_no       , 0x00, sizeof(in_alias_no       ));
    memset(in_issue_id       , 0x00, sizeof(in_issue_id       ));

    //rtn = (char *)rBuffer;
    rd = (struct rcv_lane_data *)target;
//que_log("카드처리[%s]\n", rd->buf);
    pk_in = (struct hi_crd_hnd_data *)rd->buf;

    sprintf(in_id, "%.4s", pk_in->wrkr_no);
    sprintf(in_fare, "%.2s", pk_in->plz_id);
    sprintf(in_booth, "%.2s", rd->lane_no);

    sprintf(in_date, "%.8s", pk_in->wrk_date);
    sprintf(in_time, "%.2s%.2s%.2s", pk_in->hnd_hour, pk_in->hnd_min, pk_in->hnd_sec);

//규칙에 따라 변경
    sprintf(tmp, "%.6s%c", pk_in->serial_no, '\0');
    sprintf(in_seqno, "%c%.2s%05d", pk_in->plz_id[1], rd->lane_no, lb_data2atoi(tmp, 6)); //10->9

    memset(tmp, 0x00, sizeof(tmp));
	sprintf(tmp, "%.6s%c", pk_in->rcpt_money, '\0');
    sprintf(in_amount, "%8u", lb_data2atoi(tmp, 6));

    in_kbn[0] = pk_in->pre_div;
//que_log("선후불구분[%cs[%c]\n", in_kbn, pk_in->pre_div);
    sprintf(in_card, "%.16s", pk_in->crd_no);
	sprintf(tmp, "%.2s%c", pk_in->rcpt_div, '\0');
    
    switch(lb_data2atoi(tmp, 2))
	{
		case 10:
			sprintf(in_collect, "10");
			break;
		case 11:
		case 12:
		case 13:
		case 14:
			sprintf(in_collect, "11");
			break;
		case 20:
			sprintf(in_collect, "20");
			break;
		case 21:
        case 61:
			sprintf(in_collect, "21");
			break;
		case 22:
			sprintf(in_collect, "22");
			break;
		case 23:
		case 25:
		case 27:
        case 62:
		case 63:
		case 64:
		case 66:
			sprintf(in_collect, "23");
			break;
		case 24:
		case 26:
		case 28:
			sprintf(in_collect, "24");
			break;
		case 30:
			sprintf(in_collect, "30");
			break;
		case 31:
		case 35:
		case 36:
		case 37:
		case 38:
		case 39:
		case 70:
		case 72:
		case 73:
		case 75:
		case 76:
		case 77:
		case 78:
		case 79:
			sprintf(in_collect, "34");
			break;
		case 32:
			sprintf(in_collect, "32");
			break;
		case 33:
			sprintf(in_collect, "33");
			break;
		case 34:
		case 65:
		case 67:
			sprintf(in_collect, "30");
			break;
		case 71:
		case 74:
			sprintf(in_collect, "31");
			break;
		case 40:
		case 41:
			sprintf(in_collect, "40");
			break;
		case 50:
			sprintf(in_collect, "50");
			break;
		case 51:
			sprintf(in_collect, "51");
			break;
		case 52:
			sprintf(in_collect, "52");
			break;
		case 53:
		case 55:
		case 56:
			sprintf(in_collect, "53");
			break;
		case 54:
			sprintf(in_collect, "54");
			break;
        case 60:
            if(lb_data2atoi(in_amount, 6) > 1000)
                sprintf(in_collect, "21");
            else
                sprintf(in_collect, "23");
            break;
		default:
			sprintf(in_collect, "00");
			break;
	}
	
	sprintf(tmp, "%.8s%c", pk_in->bef_rcpt_balc, '\0');
    sprintf(in_be_amount, "%8u", lb_data2atoi(tmp, 8));
	
	sprintf(tmp, "%.8s%c", pk_in->aft_rcpt_balc, '\0');
	sprintf(in_re_amount, "%8u", lb_data2atoi(tmp, 8));

    sprintf(in_terminal_id, "%.9s", pk_in->terminal_no+1);
    sprintf(in_sam_id, "%.16s", pk_in->psam_id);
#if 1 //Hexa -> Decimal
	sprintf(tmp, "%.8s%c", pk_in->deal_ser_no, '\0');
    sprintf(in_sam_seqno, "%010u", strtoul(tmp, NULL, 16));
#else // Hexa Use
	sprintf(in_sam_seqno, "%.8s%c", pk_in->deal_ser_no, '\0');
#endif

#if 0 //Hexa -> Decimal
	sprintf(tmp, "%.10s%c", pk_in->crd_ser_no, '\0');
	sprintf(in_card_seqno, "%010u", strtoul(tmp, NULL, 16));
#else // Hexa Use(OK)
	sprintf(in_card_seqno, "%.10s%c", pk_in->crd_ser_no, '\0');
#endif
	sprintf(in_algorithm_id, "%.2s", pk_in->alg_id);
    sprintf(in_key_version, "%.2s", pk_in->ind_sign1);
    sprintf(in_e_cash, "%.2s", pk_in->id_center);
#if 1 //Hexa -> Decimal
	sprintf(tmp, "%.8s%c", pk_in->rcpt_deal_ser, '\0');
    sprintf(in_sam_tot_seqno, "%010u", strtoul(tmp, NULL, 16));
#else // Hexa Use
    sprintf(in_sam_tot_seqno, "%.8s%c", pk_in->rcpt_deal_ser, '\0');
#endif
#if 1 //Hexa -> Decimal
	sprintf(tmp, "%.4s%c", pk_in->ind_iss_cnt, '\0');
    sprintf(in_sam_collect_cnt, "%05u", strtoul(tmp, NULL, 16));
#else
	sprintf(in_sam_collect_cnt, "%.4s%c", pk_in->ind_iss_cnt, '\0');
#endif
#if 1
	sprintf(tmp, "%.8s%c", pk_in->deal_tot, '\0');
    sprintf(in_sam_tot_amount, "%010d", strtoul(tmp, NULL, 16));
#else
	sprintf(in_sam_tot_amount, "%.8s%c", pk_in->deal_tot, '\0');
#endif
    sprintf(in_sign_value, "%.8s", pk_in->psam_sign1);
    sprintf(in_person_code, "%.2s", pk_in->another);
    sprintf(in_zipge_id, "9100000000%.2s", rd->lane_no);
#if 0 // Hexa -> Decimal
	sprintf(tmp, "%.10s%c", pk_in->alias_no, '\0');
	sprintf(in_alias_no, "%010u", strtoul(tmp, NULL, 16));
#else
    sprintf(in_alias_no, "%.10s", pk_in->alias_no);
#endif
    sprintf(tmp_iss_cd, "%.6s%c", pk_in->crd_no, '\0');
    stsize = sizeof(struct iss_comp_tbl);
//que_log("BIN_CODE[%.6s]\n", tmp_iss_cd);

    sprintf(in_issue_id, "2000700");

/* que_log("[%s][%s][%s][%s][%s][%s]\n", in_id, in_fare, in_booth, in_date, in_time, in_seqno);
que_log("[%s][%s][%s][%s][%s][%s][%s]\n", in_kbn, in_card, in_collect, in_be_amount, in_amount, in_re_amount, in_terminal_id);
que_log("[%s][%s][%s][%s][%s][%s]\n", in_sam_id, in_sam_seqno, in_card_seqno, in_algorithm_id, in_key_version, in_e_cash);
que_log("[%s][%s][%s][%s][%s][%s]\n", in_sam_tot_seqno, in_sam_collect_cnt, in_sam_tot_amount, in_sign_value, in_person_code, in_zipge_id);
que_log("[%s][%s]\n", in_alias_no, in_issue_id); */

#ifdef _WEBSVR_
	sprintf(rBuffer, "%s%s%s%s%s%s%s%s%s%08d%08d%08d%s%s%s%s%s%s%s%s%s%s%s%s%s%s%s",
			in_id, in_fare, in_booth, in_date, in_time, in_seqno, 
			in_kbn, in_card, in_collect, lb_data2atoi(in_be_amount, 8), lb_data2atoi(in_amount, 8), lb_data2atoi(in_re_amount, 8),
			in_terminal_id, in_sam_id, in_sam_seqno, in_card_seqno, in_algorithm_id, in_key_version, in_e_cash,
			in_sam_tot_seqno, in_sam_collect_cnt, in_sam_tot_amount, in_sign_value, in_person_code, in_zipge_id,
			in_alias_no, in_issue_id);

	//sprintf(rBuffer, "%08d", SQLCODE);
	memcpy(rtn, &rBuffer, strlen(rBuffer));
#endif
    return 0;
}

/*
 *========================================================================
 *
 *   함 수 명 : proc_wrk_end()
 *   작 성 자 : 조보용
 *   작 성 일 : 2019.06.10
 *   수 정 일 :
 *   설    명 : 근무 종료 처리
 *
 *========================================================================
*/

int proc_wrk_end(char *target, char *rtn)
{
    struct rcv_lane_data  *rd;
    struct  hi_wrk_end *pk_in;
    int     iCrjb;
    int     start_sno;
    int     end_sno;
    int     ii;
	char   rBuffer[MAX_STRING_SIZE+1];
	char   hnd_div[2+1];

    char year[4+1];
    char mon[2+1];
    char day[2+1];

    char in_id[4+1];
    char in_fare[2+1];
    char in_booth[2+1];
    char in_st_date[14+1];
    char in_ed_date[14+1];
    int  in_cash = 0;
    int  in_k_cash = 0;
    int  in_free = 0;
    int  in_minap = 0;
    int  in_coupon = 0;
    int  in_k_coupon = 0;
    int  in_sun = 0;
    int  in_k_sun = 0;
    int  in_who = 0;
    int  in_k_who = 0;
    int  in_sale = 0;
    int  in_k_sale = 0;
    int  in_total_amount = 0;
    int  in_repay_q = 0;
    int  in_repay_m = 0;
	int  in_prp_q = 0;
    int  in_prp_m = 0;
	int  in_k_prp_q = 0;
    int  in_k_prp_m = 0;
    int  in_seqno = 0;
    int  ret = -1;

    memset(year, 0x00, sizeof(year));
    memset(mon , 0x00, sizeof(mon ));
    memset(day , 0x00, sizeof(day ));

    memset(in_id     , 0x00, sizeof(in_id     ));
    memset(in_fare   , 0x00, sizeof(in_fare   ));
    memset(in_booth  , 0x00, sizeof(in_booth  ));
    memset(in_st_date, 0x00, sizeof(in_st_date));
    memset(in_ed_date, 0x00, sizeof(in_ed_date));

    char tmp[10]; memset(tmp, 0x00, sizeof(tmp));

    //rtn = (char *)rBuffer;
    rd = (struct rcv_lane_data *)target;
    pk_in = (struct hi_wrk_end *)rd->buf;
    start_sno = lb_data2atoi(rd->st_snd_no, 10);
    end_sno = lb_data2atoi(pk_in->seq_no, 10);

    sprintf(in_id, "%.4s", pk_in->wrkr_no);
    sprintf(in_fare, "%.2s", rd->plz_id);
    sprintf(in_booth, "%.2s", rd->lane_no);
    sprintf(in_st_date, "%.4s%.2s%.2s%.2s%.2s%.2s",
             pk_in->wrk_start_year, pk_in->wrk_start_month, pk_in->wrk_start_day,
             pk_in->wrk_start_hour, pk_in->wrk_start_min, pk_in->wrk_start_sec);
    sprintf(in_ed_date, "%.4s%.2s%.2s%.2s%.2s%.2s",
             pk_in->wrk_end_year, pk_in->wrk_end_month, pk_in->wrk_end_day,
             pk_in->wrk_end_hour, pk_in->wrk_end_min, pk_in->wrk_end_sec);

/* 검색용 변수 입력 */
    sprintf(year, "%.4s", pk_in->wrk_start_year);
    sprintf(mon, "%.2s", pk_in->wrk_start_month);
    sprintf(day, "%.2s", pk_in->wrk_start_day);

    for(ii = 0; ii < 50; ii++)
    {
        switch(lb_data2atoi(pk_in->hnd_cnt[ii].div, 2))
        {
            case 10:
                in_cash += lb_data2atoi(pk_in->hnd_cnt[ii].cnt, 4);
                break;
            case 11:
            case 12:
            case 13:
            case 14:
                in_k_cash += lb_data2atoi(pk_in->hnd_cnt[ii].cnt, 4);
                break;
            case 30:
            case 31:
            case 32:
            case 33:
            case 34:
            case 35:
            case 36:
            case 37:
            case 38:
            case 39:
            case 70:
            case 71:
			case 72:
			case 73:
            case 74:
            case 75:
            case 76:
            case 77:
            case 78:
            case 79:
                in_free += lb_data2atoi(pk_in->hnd_cnt[ii].cnt, 4);
                break;
            case 40:
            case 41:
            case 65:
			case 67:
                in_minap += lb_data2atoi(pk_in->hnd_cnt[ii].cnt, 4);
                break;
            case 51:
                in_coupon += lb_data2atoi(pk_in->hnd_cnt[ii].cnt, 4);
                break;
            case 53:
            case 55:
            case 56:
                in_k_coupon += lb_data2atoi(pk_in->hnd_cnt[ii].cnt, 4);
                break;
            case 21:
            case 60:
            case 61:
            case 62:
			case 63:
			case 64:
            case 66:
                in_sun += lb_data2atoi(pk_in->hnd_cnt[ii].cnt, 4);
                break;
            case 23:
            case 25:
            case 27:
                in_k_sun += lb_data2atoi(pk_in->hnd_cnt[ii].cnt, 4);
                break;
            case 22:
                in_who += lb_data2atoi(pk_in->hnd_cnt[ii].cnt, 4);
                break;
            case 24:
            case 26:
            case 28:
                in_k_who += lb_data2atoi(pk_in->hnd_cnt[ii].cnt, 4);
                break;
            case 52:
                in_sale += lb_data2atoi(pk_in->hnd_cnt[ii].cnt, 4);
                break;
            case 54:
                in_k_sale += lb_data2atoi(pk_in->hnd_cnt[ii].cnt, 4);
                break;
        }
    }

    in_total_amount = lb_data2atoi(pk_in->tot_fare, 8);
    in_repay_q = lb_data2atoi(pk_in->repay_cnt, 4);
    in_repay_m = lb_data2atoi(pk_in->repay_fare, 8);

	in_seqno = pk_in->wrk_no[3] - '0';

/*    EXEC SQL PREPARE sProc FROM :stmt; */
/*    EXEC SQL EXECUTE sProc USING :pr_out.in_id, :pr_out.in_fare, :pr_out.in_booth, :pr_out.in_st_date, :pr_out.in_ed_date, :pr_out.in_cash, :pr_out.in_k_cash, :pr_out.in_free, :pr_out.in_minap, :pr_out.in_coupon, :pr_out.in_k_coupon, :pr_out.in_sun, :pr_out.in_k_sun, :pr_out.in_who, :pr_out.in_k_who, :pr_out.in_sale, :pr_out.in_k_sale, :pr_out.in_total_amount, :pr_out.in_repay_q, :pr_out.in_repay_m, :pr_out.in_seqno, :ret; */

/*
    EXEC SQL CALL SP_ADJUST_INS(:pr_out.in_id, :pr_out.in_fare, :pr_out.in_booth, :pr_out.in_st_date, :pr_out.in_ed_date,
        :pr_out.in_cash, :pr_out.in_k_cash, :pr_out.in_free, :pr_out.in_minap, :pr_out.in_coupon,
        :pr_out.in_k_coupon, :pr_out.in_sun, :pr_out.in_k_sun, :pr_out.in_who, :pr_out.in_k_who,
        :pr_out.in_sale, :pr_out.in_k_sale, :pr_out.in_total_amount, :pr_out.in_repay_q, :pr_out.in_repay_m,
        :pr_out.in_seqno, :ret);
*/

#ifdef _WEBSVR_

	sprintf(rBuffer, "%s%s%s%s%s%04d%04d%04d%04d%04d%04d%04d%04d%04d%04d%04d%04d%08d%04d%08d%04d%08d%04d%08d%d",
			in_id, in_fare, in_booth, in_st_date, in_ed_date,
			in_cash, in_k_cash, in_free, in_minap, in_coupon, in_k_coupon, in_sun, in_k_sun,
			in_who, in_k_who, in_sale, in_k_sale, in_total_amount, in_repay_q,
			in_repay_m, in_prp_q, in_prp_m, in_k_prp_q, in_k_prp_m, in_seqno);

    //sprintf(rBuffer, "%08d", SQLCODE);
	memcpy(rtn, &rBuffer, strlen(rBuffer));
#endif

    return 0;
}

/*
 *========================================================================
 *
 *   함 수 명 : proc_refund()
 *   작 성 자 : 조보용
 *   작 성 일 : 2019.07.01
 *   수 정 일 :
 *   설    명 : 환불처리 처리
 *
 *========================================================================
*/

int proc_refund(char *target, char *rtn)
{
    struct rcv_lane_data  *rd;
    struct  hi_refund_data *pk_in;
    int     iCrjb;
    int     end_sno;
    int     ii, nResult;
	char   rBuffer[MAX_STRING_SIZE+1];
	char   rcv_hnd[2+1];
	char   tmp_seq[9+1];
	char   tmp[10+1];

    char in_id[4+1];
    char in_fare[2+1];
    char in_booth[2+1];
    char in_date[14+1];
    char in_seqno[9+1];
    char in_rf_seqno[9+1];
    char in_car[16+1];
    char in_collect[2+1];
    char in_army[1+1];

    char in_stop[50+1];
    char in_move[32+1];
    char in_amount[6+1];
    char in_x[4+1];
    char in_y[4+1];
    char in_garo[4+1];
    char in_sero[4+1];
    char in_card_ret[1+1];
    char in_other[1+1];
    char in_rfid_kbn[2+1];
    char in_tag[48+1];
	char in_carkind[1+1];
	char in_sens_time[6+1];
    char in_collect_new[2+1];
	
	char c_io[1+1];
	int  d_seq = 0;
    int  ret = 3;

#ifdef _WEBSVR_
	size_t in_size;
	size_t out_size;
	size_t out_buf_left;
	char   orgCarNo[255+1];
	char   szCarNo[255+1];
	char* in_buf;
	char* out_buf;
	
	memset(orgCarNo, 0x00, sizeof(orgCarNo));
	memset(szCarNo, 0x00, sizeof(szCarNo));
	
	iconv_t ic = iconv_open("UTF-8", "EUC-KR");

	if(ic == (iconv_t) -1)
	{
		que_log("###### Not Supported ICONV Code ###### \n");
	}
#endif
    memset(in_id      , 0x00, sizeof(in_id      ));
    memset(in_fare    , 0x00, sizeof(in_fare    ));
    memset(in_booth   , 0x00, sizeof(in_booth   ));
    memset(in_date    , 0x00, sizeof(in_date    ));
    memset(in_seqno   , 0x00, sizeof(in_seqno   ));
    memset(in_rf_seqno, 0x00, sizeof(in_rf_seqno));
    memset(in_car     , 0x00, sizeof(in_car     ));
    memset(in_collect , 0x00, sizeof(in_collect ));
    memset(in_army    , 0x00, sizeof(in_army    ));
    
    memset(in_stop    , 0x00, sizeof(in_stop    ));
    memset(in_move    , 0x00, sizeof(in_move    ));
    memset(in_amount  , 0x00, sizeof(in_amount  ));
    memset(in_x       , 0x00, sizeof(in_x       ));
    memset(in_y       , 0x00, sizeof(in_y       ));
    memset(in_garo    , 0x00, sizeof(in_garo    ));
    memset(in_sero    , 0x00, sizeof(in_sero    ));
    memset(in_card_ret, 0x00, sizeof(in_card_ret));
    memset(in_other   , 0x00, sizeof(in_other   ));
    memset(in_rfid_kbn, 0x00, sizeof(in_rfid_kbn));
    memset(in_tag     , 0x00, sizeof(in_tag     ));
	memset(in_carkind , 0x00, sizeof(in_carkind ));
	memset(in_sens_time , 0x00, sizeof(in_sens_time ));

    //rtn = (char *)rBuffer;
    rd = (struct rcv_lane_data *)target;
    pk_in = (struct hi_hnd_data *)rd->buf;

    sprintf(in_id, "%.4s", pk_in->wrkr_no);
    sprintf(in_fare, "%.2s", pk_in->plz_id);
    sprintf(in_booth, "%.2s", rd->lane_no);
    sprintf(in_date, "%.8s%.2s%.2s%.2s", pk_in->wrk_date, pk_in->hnd_info.hnd_hour, pk_in->hnd_info.hnd_min, pk_in->hnd_info.hnd_sec);

    sprintf(c_io, "%c", pk_in->io_div);

//규칙에 따라 변경
    //sprintf(in_seqno, "%c%.2s%05d", pk_in->plz_id[1], rd->lane_no, lb_data2atoi(pk_in->serial_no, 6)); //10->9
    //sprintf(in_rf_seqno, "%c%.2s%05d", pk_in->plz_id[1], rd->lane_no, lb_data2atoi(pk_in->serial_no, 6));
	sprintf(in_seqno, "%08u", lb_data2atoi(pk_in->serial_no, 6)); //10->9
	sprintf(in_rf_seqno, "%08u", lb_data2atoi(pk_in->serial_no, 6));
	
	d_seq = lb_data2atoi(pk_in->sence_seq_no, 6);

    sprintf(in_car, "%.16s", pk_in->car_no1);
	del_space(in_car);
	
	if(strlen(in_car) == 0)
		strncpy(in_car, "????????????", 12);

    memcpy(rcv_hnd, pk_in->hnd_info.rcpt_hnd, 2);
	rcv_hnd[2] = '\0';

    switch(lb_data2atoi(rcv_hnd, 2))
	{
		case 31:
			sprintf(in_carkind, "6");
		break;
		case 36:
			sprintf(in_carkind, "7");
		break;
		default:
		    sprintf(in_carkind, "%c", pk_in->car_kind);
		break;
	}

	if(lb_data2atoi(rcv_hnd, 2) > 19 && lb_data2atoi(rcv_hnd, 2) < 30)
	{
		sprintf(in_seqno, "%c%.2s%05d", pk_in->plz_id[1], rd->lane_no, lb_data2atoi(pk_in->serial_no, 6)); //10->9
		sprintf(in_rf_seqno, "%c%.2s%05d", pk_in->plz_id[1], rd->lane_no, lb_data2atoi(pk_in->serial_no, 6));
	}

    switch(lb_data2atoi(rcv_hnd, 2))
	{
		case 10:
			sprintf(in_collect, "10");
			break;
		case 11:
		case 12:
		case 13:
		case 14:
			sprintf(in_collect, "11");
			break;
		case 20:
			sprintf(in_collect, "20");
			break;
		case 21:
			sprintf(in_collect, "21");
			break;
		case 22:
			sprintf(in_collect, "22");
			break;
		case 23:
		case 25:
		case 27:
			sprintf(in_collect, "23");
			break;
		case 24:
		case 26:
		case 28:
			sprintf(in_collect, "24");
			break;
		case 30:
			sprintf(in_collect, "30");
			break;
		case 31:
		case 35:
		case 36:
		case 37:
		case 38:
		case 39:
		case 70:
		case 72:
		case 73:
		case 75:
		case 76:
		case 77:
		case 78:
		case 79:
			sprintf(in_collect, "34");
			break;
		case 32:
			sprintf(in_collect, "32");
			break;
		case 33:
			sprintf(in_collect, "33");
			break;
		case 34:
		case 65:
		case 67:
			sprintf(in_collect, "30");
			break;
		case 71:
		case 74:
			sprintf(in_collect, "31");
			break;
		case 40:
		case 41:
		case 60:
		case 61:
		case 62:
		case 63:
		case 64:
		case 66:
			sprintf(in_collect, "40");
			break;
		case 50:
			sprintf(in_collect, "50");
			break;
		case 51:
			sprintf(in_collect, "51");
			break;
		case 52:
			sprintf(in_collect, "52");
			break;
		case 53:
		case 55:
		case 56:
			sprintf(in_collect, "53");
			break;
		case 54:
			sprintf(in_collect, "54");
			break;
		default:
			sprintf(in_collect, "00");
			break;
	}

    in_army[0] = '0';

    sprintf(in_stop, "%.8s_%.2s%.2s%.2s00_%06d%.2s_%c%.2s%c_%s_%c",
            pk_in->wrk_date, pk_in->hnd_info.hnd_hour, pk_in->hnd_info.hnd_min, pk_in->hnd_info.hnd_sec,
            lb_data2atoi(pk_in->serial_no, 6), pk_in->hnd_info.rcpt_hnd, pk_in->plz_id[1], rd->lane_no, pk_in->io_div,
            in_car, pk_in->car_kind);

    in_move[0] =  ' ';
// 숫자
    sprintf(in_amount, "%.6s", pk_in->hnd_info.pass_fare);

// 숫자
    memcpy(in_x, pk_in->x_point+1, 3);
	in_x[3] = '\0';
// 숫자
    memcpy(in_y, pk_in->y_point+1, 3);
	in_y[3] = '\0';
// 숫자
    memcpy(in_garo, pk_in->img_width+1, 3);
	in_garo[3] = '\0';
// 숫자
    memcpy(in_sero, pk_in->img_heigh+1, 3);
	in_sero[3] = '\0';

    sprintf((char *)in_card_ret, "%c", pk_in->hnd_info.refund_yn);
    //sprintf(in_rfid_kbn, "%c", pk_in->hnd_info.issue_code[0]);

	switch(lb_data2atoi(rcv_hnd, 2))
	{
		case 10:
		case 11:
		case 20:
		case 21:
		case 22:
		case 23:
		case 24:
		case 30:
		case 31:
		case 32:
		case 34:
		case 35:
		case 36:
		case 37:
		case 38:
		case 39:
		case 70:
		case 71:
		case 72:
		case 73:
		case 74:
		case 75:
		case 76:
		case 77:
		case 78:
		case 79:
		case 40:
		case 41:
		case 50:
		case 51:
		case 52:
		case 53:
		case 54:
		case 60:
		case 61:
		case 62:
		case 63:
		case 64:
		case 65:
		case 66:
		case 67:
			sprintf(in_rfid_kbn, "00");
			break;
		case 12:
		case 25:
		case 26:
		case 55:
			sprintf(in_rfid_kbn, "01");
			break;
		case 13:
		case 14:
		case 27:
		case 28:
		case 56:
			sprintf(in_rfid_kbn, "03");
			break;
		case 33:
			sprintf(in_rfid_kbn, "02");
			break;
		default:
			sprintf(in_rfid_kbn, "00");
			break;
	}

	if(lb_data2atoi(tmp, 2) == 53)
		sprintf(in_rfid_kbn, "04");

    snprintf(in_tag, 48+1, "%.24s%.24s", pk_in->tag_id1, pk_in->tag_id2);

    in_other[0] = pk_in->wrk_no[3];
    
	if(in_carkind[0] == '7')
		sprintf(in_rfid_kbn, "02");

    sprintf(in_sens_time, "000000");
	in_sens_time[6] = '\0';

/* que_log("환불처리 [%s][%s][%s][%s][%s][%s]\n", in_id, in_fare, in_booth, in_date, in_seqno, in_rf_seqno);
que_log("환불처리 [%s][%s][%s][%s][%s][%s]\n", in_car, in_collect, in_army, in_stop, in_move, in_amount);
que_log("환불처리 [%s][%s][%s][%s][%s][%s]\n", in_x, in_y, in_garo, in_sero, in_card_ret, in_other);
que_log("환불처리 [%s][%s][%s][%s]\n", in_rfid_kbn, in_tag, in_carkind, in_sens_time);

que_log("환불처리 [%02x][%02x][%02x][%02x][%02x][%02x]\n", in_id[4], in_fare[2], in_booth[2], in_date[14], in_seqno[9], in_rf_seqno[9]);
que_log("환불처리 [%02x][%02x][%02x][%02x][%02x][%02x]\n", in_car[16], in_collect[2], in_army[1], in_stop[50], in_move[1], in_amount[6]);
que_log("환불처리 [%02x][%02x][%02x][%02x][%02x][%02x]\n", in_x[4], in_y[4], in_garo[4], in_sero[4], in_card_ret[1], in_other[1]);
que_log("환불처리 [%02x][%02x][%02x]\n", in_rfid_kbn[2], in_tag[48], in_carkind[1]); */

    sprintf(in_collect_new, "%.2s%c", rcv_hnd, '\0');

#ifdef _WEBSVR_
	sprintf(orgCarNo, "%.16s", in_car);
	if(strlen(orgCarNo) == 0)
	{
		memset(in_car, 0x00, sizeof(in_car));
		sprintf(in_car, "????????????");
	}else
	{
		memset(in_car, 0x00, sizeof(in_car));
		in_size = strlen(orgCarNo);
		out_size = sizeof(wchar_t) * in_size * 4;

		in_buf = orgCarNo;
		out_buf = szCarNo;
		out_buf_left = out_size;
			
		nResult = iconv(ic, (char *)&in_buf, &in_size, (char *)&out_buf, &out_buf_left);
		if(nResult == -1)
		{
			que_log("ICONV FAILED [%d]\n", nResult);
		}

que_log("ICONV in_size[%d] out_size[%d] [%s]\n", in_size, out_size - out_buf_left, szCarNo);
		sprintf(in_car, "%.16s", szCarNo);
	}
	iconv_close(ic);
    
	sprintf(rBuffer, "%s%s%s%s%s%s%-16s%s%s00%s%s%s%s%s%s%s%s%-48s%s%s%s",
			in_id, in_fare, in_booth, in_date, in_seqno, in_rf_seqno, 
			in_car, in_collect, in_army, in_amount,
			in_x, in_y, in_garo, in_sero, in_card_ret, in_other,
			in_rfid_kbn, in_tag, in_carkind, rcv_hnd, in_sens_time);
    //sprintf(rBuffer, "%08d", SQLCODE);
	memcpy(rtn, &rBuffer, strlen(rBuffer));
#endif
	
    return 0;
}
