view_settle_posls.ec

来自「在SCO UNIX制定界面程序 可根据文件配制菜单,而不必修改源程序,非常方便」· EC 代码 · 共 337 行

EC
337
字号
/*******************************************************
 *	交易明细查询 view_settle_posls()
 *
 * 最后修改:	周国祥 2001/08/16
 *******************************************************/
#include <stdio.h>
#include <curses.h>
#include "all.h"
#include "tool.h"
#include "macro_def.h"

$include "db_struct.h"
$include sqlca;

typedef struct {
	double	normal_amt;
	int	normal_cnt;
	double	refund_amt;
	int	refund_cnt;
	double	adjust_amt;
	int	adjust_cnt;
	double	amt;
	int	cnt;
} Edc_Batch;

EXEC SQL WHENEVER SQLERROR CALL error_handler;
EXEC SQL WHENEVER SQLWARNING CALL warning_handler;
EXEC SQL WHENEVER NOT FOUND CALL notfound_handler;

$S_sys_param	sy;
$S_tran_ls	ls;

char s_date[11], e_date[11];	/* YYYYMMDD use for database opration */
char s_date1[11], e_date1[11];	/* YYYY/MM/DD use for display */
int ch;

void FileHead_edc_mx(FILE *fp, S_sys_param sy)
{
	char	date[11], time[9];
	char	bank_name[128];

	getdatef( date, "/" );
	gettimef( time, ":" );
	fprintf(fp, "%27s中国银行BTS系统信用卡\n", " ");
	fprintf(fp, "%27s   EDC交易情况报表\n", " ");
	fprintf(fp, "%20s查询交易日期: %s--%s\n", " ", s_date1, e_date1 );
	get_bank_name(sy.bank_id, sy.host_id, bank_name);
	fprintf(fp, "%5.5s%-52s%s %s\n\n\n", sy.bank_id, bank_name, date, time);
}

void FileSubHead_edc_mx(FILE *fp, S_tran_ls ls, char *tmp)
{
	fprintf(fp, "商户号: %-15.15s 商户名称: %s\n", ls.merchant_id, tmp);
	fprintf(fp, "EDC 号: %-15.15s 批 次 号: %ld\n", ls.terminal_id, ls.batch_no);
	fprintf(fp, "--------------------------------------------------------------------------------------\n");

	fprintf(fp, "%-19s %8s %14s %14s %6s %-10s %-8s\n", "卡  号", "交易类型",  "交易金额", "原 金 额", "授权码", "交易日期", "交易时间");

	fprintf(fp, "--------------------------------------------------------------------------------------\n");
}

void FileDetail_edc_mx(FILE *fp, S_tran_ls ls)
{
	char tran_name[9];
	
	type2buf( ls.tran_type, tran_name );
	fprintf(fp, "%-19s %8s %14.2lf %14.2lf %6s %4.4s/%2.2s/%2.2s %2.2s:%2.2s:%2.2s\n", ls.card_no, tran_name, ls.tran_amt, ls.void_amt, ls.auth_no, ls.local_sys_date, ls.local_sys_date+4, ls.local_sys_date+6, ls.local_sys_time, ls.local_sys_time+2, ls.local_sys_time+4);

}

void FileTail_edc_mx(FILE *fp, Edc_Batch batch)
{
	fprintf(fp, "--------------------------------------------------------------------------------------\n");
	fprintf(fp, "%-16s %14s %8s %14s %8s\n", "合  计", "交易金额", "交易笔数", "退货金额", "退货笔数");
	fprintf(fp, "%-16s %14.2lf %8d %14.2lf %8d\n\n\n", " ", batch.normal_amt, batch.normal_cnt, batch.refund_amt, batch.refund_cnt);

}

void add_edc_batch(Edc_Batch *pbatch, S_tran_ls ls)
{
	switch (ls.tran_type) {
		case REFUND:
			pbatch->refund_amt += ls.tran_amt;
			pbatch->refund_cnt ++;
			pbatch->amt -= ls.tran_amt;
			pbatch->cnt ++;
			break;
		case ADJUST:
			pbatch->adjust_amt += ls.tran_amt - ls.void_amt;
			pbatch->adjust_cnt ++;
			pbatch->amt += ls.tran_amt - ls.void_amt;
			pbatch->cnt ++;
			break;
		default:
			pbatch->normal_amt += ls.tran_amt;
			pbatch->normal_cnt ++;
			pbatch->amt += ls.tran_amt;
			pbatch->cnt ++;
			break;
	}
}

int view_settle_posls()
{
	$S_sys_param sys;
	char cmd[300];
	WINDOW *my_win;
	char filename[128], path[80];
	char mer_id[16], ter_id[11];
	char rpt[120], fileout[200];	
	int mer_cnt, ret, i, ter_cnt;
	static char pflag[3], first=1;

	sprintf(filename, "/tmp/.view_settle_posls.%d", getpid());
	scr_dump(filename);
	
	disp_below("EDC 交易明细查询");
	clear_wline(stdscr, LINES-1);
	h_prompt(LINES-1, 1, "                                                                 < ESC 退出 > ", 0, 0);
	h_prompt(LINES-1, 1, "EDC 交易明细查询", 0, 0);
	my_win = newwin(19, 80, 3, 0);
	mvwprintw(my_win, 0, 0, "━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━");
	wrefresh(my_win);

	set_prompt(PROMPT_OFF);

	getdatef(s_date, "");
	mvwprintw(my_win, 2, 4, "请输入起始日期: [%s]", s_date);
	if (in_item(my_win, "", 2, 21, s_date, 8, NULL, NULL, 0, 0) !=
	    ENTER) goto end_shdz;

	str2date(s_date1, s_date, "/");

	getdatef(e_date, "");

	mvwprintw(my_win, 3, 4, "请输入结束日期: [%s]", e_date);
	if (in_item(my_win, "", 3, 21, e_date, 8, NULL, NULL, 0, 0) !=
	    ENTER) goto end_shdz;
	str2date(e_date1, e_date, "/");
	
	strcpy ( mer_id , "" );	
	mvwprintw(my_win, 4, 4, "请输入商户编号: [%15s]", " ");
	if (in_item(my_win, "", 4, 21, mer_id, 15, NULL, NULL, 0, 0) !=
	    ENTER) goto end_shdz;

	if ( mer_id[0] > '9' || mer_id[0] < '0' )
		mer_cnt = 0;
	else
		mer_cnt = 1;
	
	strcpy ( ter_id , "" );	
	mvwprintw(my_win, 5, 4, "请输入EDC编号: [%8s]", " ");
	if (in_item(my_win, "", 5, 20, ter_id, 8, NULL, NULL, 0, 0) !=
	    ENTER) goto end_shdz;
	
	if ( ter_id[0] > '9' || ter_id[0] < '0' )
		ter_cnt = 0;
	else
		ter_cnt = 1;
		
	strcpy( fileout, "未结帐EDC" );
	ch = strlen( fileout ) + 1;
	strcpy( fileout + ch, "已结帐EDC" );
	ch += strlen( fileout + ch ) + 1;
	strcpy( fileout + ch, "不判是否结帐" );
	ch += strlen( fileout + ch ) + 1;
	strcpy( fileout + ch, "退出" );
	ch = multi_select( my_win, 7, "      请选择查询情况:", fileout, 4, 0, 0, 0, 0 );
	if ( ch == 3 ) 	
		goto end_shdz;
	
	daylog(DEBUG, "正在生成EDC交易情况, 交易日期: %s-%s, 请稍候 ...", s_date1 , e_date1 );

	mvwprintw(my_win, 6, 4, "正在生成EDC交易情况, 请稍候 ...");
	
	wrefresh(my_win);
	
	strcpy(path, getenv("WORKDIR"));
	sprintf(rpt, "%s/prt/edc_view", path);
	
	ret = gen_edc_view( rpt, mer_id , mer_cnt, ter_id , ter_cnt );
	if (ret < 0) {
		h_winprompt(my_win, 17, 4, "查询EDC交易情况出错!", 1, 0);
		goto end_shdz;
	}

	print_file( my_win, 9, 17, 1, rpt );
	/* viewfile( 24, 80, 0, 0, rpt, "" ); */
	wrefresh( my_win );
			
end_shdz:
	delwin(my_win);
	scr_restore(filename);
	unlink(filename);
	return(0);
}


int gen_edc_view ( char *filename, void *mer_list , int mer_cnt, void *ter_list, int ter_cnt )
{
	Edc_Batch batch;	
	$char	sql[2048];
	$char	tmp[128];
	$int	cnt;
	$S_merchant_card s_c;	
	char mer_id[16], ter_id[9];	
	int i;
	long batch_no;
	FILE *fp;
	
	if ( ! ( fp = fopen( filename, "w") ) ) {
		daylog ( ERROR, "Open %s file error !", filename );
		return( -1 );
	}

	$select * into $sy from sys_param;
	if (SQLCODE) {
		daylog(ERROR, "Error select sys_param![%d]", SQLCODE);
		fclose(fp);	
		return(-1);
	}
	
	del_st_space("sys_param", &sy);

	FileHead_edc_mx( fp, sy );	
	
	strcpy(tmp, "cur_tran_ls");

	sprintf ( sql , "select * from %s where acq_bank_id = '%s' and local_sys_date <= '%s' and local_sys_date >= '%s' " , tmp , sy.bank_id, e_date , s_date );
	
	if ( mer_cnt > 0 ) {
		strcpy ( sql+strlen(sql) , "and merchant_id in ( " );
		for ( i=0 ; i < mer_cnt ; i++ ) {
			sprintf ( tmp , "%s," , (char *)((long )mer_list+16*i) );
			strcpy ( sql+strlen(sql) , tmp );
		}
		
		strcpy ( sql+strlen(sql)-1 , ") " );
	}
	
	if ( ter_cnt > 0 ) {
		strcpy ( sql+strlen(sql) , "and terminal_id in ( '" );
		for ( i=0 ; i < ter_cnt ; i++ ) {
			sprintf ( tmp , "%s," , (char *)((long )ter_list+9*i) );
			strcpy ( sql+strlen(sql) , tmp );
		}
		
		strcpy ( sql+strlen(sql)-1 , "') " );
	}

	if ( ch == 0 ) 
		strcat( sql+strlen(sql), "and snd_settle_flag = 'N'" );	
	else
	if ( ch == 1 )
		strcat( sql+strlen(sql), "and snd_settle_flag = 'Y'" );

	strcpy ( sql+strlen(sql) , "and terminal_id not like 'TEL%' and terminal_id not like 'TRM%' and terminal_id not like 'TLX%' and resp_code like '00%' order by merchant_id, terminal_id, batch_no, card_no, auth_no " );

	$prepare s_sql from :sql;
	$declare edc_rpt cursor for s_sql;
	
	if (SQLCODE) {
		daylog(ERROR, "Unable declare edc_rpt cursor![%d]", SQLCODE);
		fclose(fp);	
		return(-1);
	}
	
	$open edc_rpt;
	
	if (SQLCODE) {	
		daylog(ERROR, "Unable open edc_rpt![%d]", SQLCODE);
		fclose(fp);	
		return(-1);
	}
	
	mer_id[0] = ter_id[0] = 0;
	batch_no = -1;
	while (1) {
		$fetch edc_rpt into $ls;
		
		if (SQLCODE == 100) break;
		
		if (SQLCODE < 0) {
			daylog(ERROR, "Error fetch edc_rpt![%d]", SQLCODE);
			$close edc_rpt;
			fclose(fp);
			return(-1);
		}
		
		del_st_space("tran_ls", &ls);

		if (strcmp(ls.merchant_id, mer_id) ||
		    strcmp(ls.terminal_id, ter_id) ||
		    ls.batch_no != batch_no) {
			if (batch_no != -1) {
				FileTail_edc_mx(fp, batch);
			}
			if (strcmp(ls.merchant_id, mer_id)) {
				$select merchant_cname
				into :tmp from merchant_base
				where merchant_id = :ls.merchant_id;
				if (SQLCODE) {
					daylog(WARN, "Fetch name of %s error!",
					       ls.merchant_id);
					strcpy(tmp, "Unknown");
				}
				DelSpace(tmp);
#ifdef Wubin_del_20011207
				$select * into :s_c from merchant_card
				where merchant_id = :ls.merchant_id;
				if (SQLCODE) {
					daylog(WARN, "Fetch fee of %s error!",
					       ls.merchant_id);
				}
				del_st_space("merchant_card", &s_c);
#endif
			}
			memset(&batch, 0, sizeof(Edc_Batch));
			strcpy(mer_id, ls.merchant_id);
			strcpy(ter_id, ls.terminal_id);
			batch_no = ls.batch_no;
			FileSubHead_edc_mx(fp, ls, tmp);
		}
		add_edc_batch(&batch, ls);
		if (fp) FileDetail_edc_mx(fp, ls);
	}
	if (batch_no != -1) 
		FileTail_edc_mx(fp, batch);
	

	$close edc_rpt;

	fclose( fp );
	
	return(0);
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?