credit_rpt_tool.c

来自「在SCO UNIX制定界面程序 可根据文件配制菜单,而不必修改源程序,非常方便」· C语言 代码 · 共 1,130 行 · 第 1/3 页

C
1,130
字号
/****************************************************
 *	信用卡报表 打印工具
 *   EDC交易批次明细报表
 *
 * 最后修改:	周国祥 2001/08/16
 ****************************************************/
#include <stdio.h>
#include <math.h>

#include "all.h"
#include "macro_def.h"
#include "credit_rpt.h"
#include "db_struct_c.h"


BANK_RPT_ITEM	*bank_rpt_item;
int		bank_rpt_cnt;
BANK_RPT_TOTAL	bank_rpt_total={ 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0, 0.0, 0 };
MER_RPT_ITEM	*mer_rpt_item;

int		mer_rpt_cnt;
MER_RPT_TOTAL	mer_rpt_total={ 0.0 , 0 , 0.0 , 0 , 0.0 , 0 , 0.0 };
WD_RPT_ITEM	*wd_rpt_item;
int		wd_rpt_cnt;
WD_RPT_TOTAL	wd_rpt_total={ 0.0 , 0 , 0.0 , 0 };
double	cre_tip;

extern	int	credit_prt_flag;

long	print_enable;
int	line;
int	head_bank_cnt;
char	head_bank_id[12][12];
char	head_host_id[12][3];
char	s_logic_date[11] , e_logic_date[11], logic_date[11], cre_date[11], cre_time[9];
char	s_logic_date1[11] , e_logic_date1[11], logic_date1[11];/* YYYY/MM/DD */
char	file1[128] , file2[128] , mx1[128] , mx2[128] , file3[128], file4[128];

FILE *wd_mx_fp;
FILE *cre_bank_up_mx_fp;
FILE *cre_bank_down_mx_fp;
FILE *mer_total_fp;
FILE *wd_hz_fp;
FILE *cre_bank_up_hz_fp;
FILE *cre_bank_down_hz_fp;
FILE *cre_bank_in_fee_fp;
FILE *cre_bank_out_fee_fp;
FILE *mer_bc_mx_fp;
FILE *edc_bc_mx_fp;
FILE *mer_bhz_fp;
FILE *edc_bhz_fp;
FILE *fp;

extern S_sys_param	sy;
extern S_tran_ls	ls;
char	bank_name[128];

char rpt_file_head[20], rpt_head[20];

void l_type2buf(int in, int old_in, char *flag, char *out)
{
	type2buf(in, out);

	/* flag:离线标志tran_ls.offline_flag */
	if (flag[0] == 'l' || old_in == OFFLINE)
		strcpy(out, "离    线");
}

void FileHead_edc_bc_mx ( )
{
	if ((print_enable&EDC_BC_MX) == 0)
		return;

	if (edc_bc_mx_fp == NULL) {
		edc_bc_mx_fp = fopen("/tmp/.edc_bc_mx", "w+");
		
		if (edc_bc_mx_fp == NULL) 
			return;
	}

	fp = edc_bc_mx_fp;
	
	fprintf(fp, "%10.10s%8.8s%06ld%8.8s%6.6s%08ld |%31s中国银行BTS系统%6.6s\n", "0000000000", "00000000", 0, "00000000", "000000", line++%100000000, " ", rpt_head);
	fprintf(fp, "%10.10s%8.8s%06ld%8.8s%6.6s%08ld |%31sEDC交易批次明细报表\n", "0000000000", "00000000", 0, "00000000", "000000", line++%100000000, " ");
	fprintf(fp, "%10.10s%8.8s%06ld%8.8s%6.6s%08ld |BTS-301%41s清算日期: %s-%s\n", "0000000000", "00000000", 0, "00000000", "000000", line++%100000000 , " ", s_logic_date, e_logic_date);
	get_bank_name(G_bankid, "00", bank_name);
	getdatef(cre_date, "/");
	gettimef(cre_time, ":");
	fprintf(fp, "%10.10s%8.8s%06ld%8.8s%6.6s%08ld |%-5.5s%-55s%s %s\n", "0000000000", "00000000", 0, "00000000", "000000", line++%100000000, G_bankid, bank_name, cre_date, cre_time);
	fprintf(fp, "%10.10s%8.8s%06ld%8.8s%6.6s%08ld | \n", "0000000000", "00000000", 0, "00000000", "000000", line++%100000000);

}

void FileHead1_edc_bc_mx ( MER_RPT_ITEM *m_r_item , TER_RPT_ITEM *t_item )
{
	if ( edc_bc_mx_fp == NULL ) return ;
	
	fp = edc_bc_mx_fp;
	
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |商户号: %-15.15s 商户名称: %s\n", m_r_item->m_id, t_item->t_id, t_item->batch_no, "00000000", "000000", line++%100000000,ls.merchant_id, m_r_item->m_name);
	fprintf(fp, "%-15.15s%8.8s%06ld%8.8s%6.6s%08ld |EDC 号: %-8.8s 批 次 号: %ld\n", m_r_item->m_id, t_item->t_id, t_item->batch_no, "00000000", "000000", line++%100000000, ls.terminal_id, ls.batch_no);
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |-------------------------------------------------------------------------------\n", m_r_item->m_id, t_item->t_id, t_item->batch_no, "00000000", "000000", line++%100000000);

	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |%-19s %6s %14s %8s %8s %-10s %-8s\n", m_r_item->m_id, t_item->t_id, t_item->batch_no, "00000000", "000000", line++%100000000, "卡  号", "授权码", "交易金额", "交易类型", "原 类 型", "交易日期", "交易时间");

	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |-------------------------------------------------------------------------------\n", m_r_item->m_id, t_item->t_id, t_item->batch_no, "00000000", "000000", line++%100000000);

}

void FileDetail_edc_bc_mx ()
{
char	buf[10], old[10];
char	date[9], time[7];

	if ( edc_bc_mx_fp == NULL ) return ;
	
	fp = edc_bc_mx_fp;
	
	l_type2buf(ls.tran_type, ls.void_tran_type, ls.offline_flag, buf);

	if (ls.tran_type == POS_VOID)
		l_type2buf(ls.void_tran_type, 0, ls.offline_flag, old);
	else
		old[0] = 0;

	sprintf(date, "%8.8s", ls.local_sys_date);
	sprintf(time, "%6.6s", ls.local_sys_time);

	fprintf(fp, "%-15.15s%8.8s%06ld%8.8s%6.6s%08ld |%-19s %6s %14.2lf %8s %8s %-10s %-8s\n", ls.merchant_id, ls.terminal_id, ls.batch_no, date, time, line++%100000000, ls.card_no, ls.auth_no, ls.tran_amt, buf, old, ls.local_sys_date, ls.local_sys_time);

}

void FileTail_edc_bc_mx ( char *m_id , TER_RPT_ITEM *t_item )
{
	if ( edc_bc_mx_fp == NULL ) return ;
	
	fp = edc_bc_mx_fp;
	
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |-------------------------------------------------------------------------------\n", m_id, t_item->t_id, t_item->batch_no, "99999999", "999999", line++%100000000);

	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |%-13s %14s   %8s %14s   %8s\n", m_id, t_item->t_id, t_item->batch_no, "99999999", "999999", line++%100000000, "合  计", "交易金额", "交易笔数", "退货金额", "退货笔数");

	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |%-13s %14.2lf   %8d %14.2lf   %8d\n", m_id, t_item->t_id, t_item->batch_no, "99999999", "999999", line++%100000000, " ", t_item->pur_amt, t_item->pur_num, t_item->refund_amt, t_item->refund_num);

	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |%-13s %14s   %8s %14s   %8s\n", m_id, t_item->t_id, t_item->batch_no, "99999999", "999999", line++%100000000, " ", "手 续 费", " ", "总 金 额", "总 笔 数");

	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |%-13s %14.2lf   %8s %14.2lf   %8d\n", m_id, t_item->t_id, t_item->batch_no, "99999999", "999999", line++%100000000, " ", t_item->fee, " ", t_item->pur_amt-t_item->refund_amt-t_item->fee , t_item->pur_num+t_item->refund_num);

	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |\n", m_id, t_item->t_id, t_item->batch_no, "99999999", "999999", line++%100000000);
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |\n", m_id, t_item->t_id, t_item->batch_no, "99999999", "999999", line++%100000000);
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |\n", m_id, t_item->t_id, t_item->batch_no, "99999999", "999999", line++%100000000);

}

void create_edc_bc_mx ()
{
char cmd[500];

	if ( (print_enable&EDC_BC_MX) == 0 ) return ;

	sprintf ( cmd , "sort -n /tmp/.edc_bc_mx 2>/dev/null | sed \"s/^.*|//\" >%s/prt/%s/%s.edc_bc_mx 2>/dev/null",
		getenv("WORKDIR"),
		G_bankid, rpt_file_head );
	system ( cmd );

	system ( "rm -f /tmp/.edc_bc_mx 2>/dev/null" );
}

void FileHead_mer_bc_mx ( MER_RPT_ITEM *m_r_item , TER_RPT_ITEM *t_item )
{
char	path[128];

	if ((print_enable&MER_BC_MX) == 0) return;

	if ( mer_bc_mx_fp == NULL ) {
		sprintf(path, "/tmp/.mer_bc_mx");
		
		mer_bc_mx_fp = fopen(path, "w+");
		
		if (mer_bc_mx_fp == NULL) 
			return;
	}

	fp = mer_bc_mx_fp;
	
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |%34s中国银行BTS系统%6.6s\n", m_r_item->m_id, "00000000", 0, "00000000", "000000", line++%100000000, " ", rpt_head);
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |%34s商户交易批次明细报表\n", m_r_item->m_id, "00000000", 0, "00000000", "000000", line++%100000000, " ");
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |BTS-701%46s清算日期: %s-%s\n", m_r_item->m_id, "00000000", 0, "00000000", "000000", line++%100000000, " ", s_logic_date, e_logic_date);
	get_bank_name(G_bankid, "00", bank_name);
	getdatef(cre_date, "/");
	gettimef(cre_time, ":");
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |%-5.5s%-50s%s %s\n", m_r_item->m_id, "00000000", 0, "00000000", "000000", line++%100000000, G_bankid, bank_name, cre_date, cre_time);
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |商 户 号: %s\n", m_r_item->m_id, "00000000", 0, "00000000", "000000", line++%100000000, m_r_item->m_id);
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |商户名称: %s\n", m_r_item->m_id, "00000000", 0, "00000000", "000000", line++%100000000, m_r_item->m_name);
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |\n", m_r_item->m_id, "00000000", 0, "00000000", "000000", line++ % 100000000);

}

void FileHead_mer_edc_bc_mx ( MER_RPT_ITEM *m_r_item , TER_RPT_ITEM *t_item )
{
	if ( mer_bc_mx_fp == NULL ) return;
	
	fp = mer_bc_mx_fp;
	
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |EDC 号: %8.8s 批次号: %06ld\n", m_r_item->m_id, t_item->t_id, t_item->batch_no, "00000000", "000000", line++%100000000, t_item->t_id, t_item->batch_no);
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |------------------------------------------------------------------------------------\n", m_r_item->m_id, t_item->t_id, t_item->batch_no, "00000000", "000000", line++%100000000);

	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |%-19s %-4s %6s %14s %-8s %-8s %-10s %-8s\n", m_r_item->m_id, t_item->t_id, t_item->batch_no, "00000000", "000000", line++%100000000, "卡  号", "效期" , "授权号", "交易金额", "交易类型", "原 类 型", "交易日期", "交易时间");

	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |------------------------------------------------------------------------------------\n", m_r_item->m_id, t_item->t_id, t_item->batch_no, "00000000", "000000", line++%100000000);

}

void FileDetail_mer_bc_mx ()
{
char	buf[10], old[10];
char	date[9], time[7];

	if ( mer_bc_mx_fp == NULL ) return ;
	
	fp = mer_bc_mx_fp;

	l_type2buf(ls.tran_type, ls.void_tran_type, ls.offline_flag, buf);

	if (ls.tran_type == POS_VOID)
		l_type2buf(ls.void_tran_type, 0, ls.offline_flag, old);
	else
		old[0] = 0;

	sprintf(date, "%8.8s", ls.local_sys_date);
	sprintf(time, "%6.6s", ls.local_sys_time);

	fprintf(fp, "%-15.15s%8.8s%06ld%8.8s%6.6s%08ld |%-19.19s %4.4s %6s %14.2lf %-8s %-8s %-10s %-8s\n", ls.merchant_id, ls.terminal_id, ls.batch_no, date, time, line++%100000000, ls.card_no, ls.exp_date, ls.auth_no, ls.tran_amt, buf, old, ls.local_sys_date, ls.local_sys_time);

}

void FileTail_mer_bc_mx ( char *m_id , TER_RPT_ITEM *t_item )
{
	if ( mer_bc_mx_fp == NULL ) return ;
	
	fp = mer_bc_mx_fp;
	
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |------------------------------------------------------------------------------------\n", m_id, t_item->t_id, t_item->batch_no, "99999999", "999999", line++%100000000);
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |\n", m_id, t_item->t_id, t_item->batch_no, "99999999", "999999", line++%100000000);
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |\n", m_id, t_item->t_id, t_item->batch_no, "99999999", "999999", line++%100000000);
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |\n", m_id, t_item->t_id, t_item->batch_no, "99999999", "999999", line++%100000000);

}

void FileHead_mer_card_hz ( char *m_id , TER_RPT_ITEM *t_item )
{
	if ( mer_bc_mx_fp == NULL ) return ;
	
	fp = mer_bc_mx_fp;
	
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |%-10s %6s %8s %14s %14s %14s\n", m_id, t_item->t_id, t_item->batch_no, "99999999", "999999", line++%100000000, "卡类", "回扣率", "笔数", "交易金额", "手续费", "交易净额");
	
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |-----------------------------------------------------------------------\n", m_id, t_item->t_id, t_item->batch_no, "99999999", "999999", line++%100000000);

}

void FileDetail_mer_card_hz ( MER_RPT_ITEM *m_r_item , TER_RPT_ITEM *t_item ,\
CARD_ITEM *c_item )
{
char	buf[20];

	if ( mer_bc_mx_fp == NULL ) return ;
	
	fp = mer_bc_mx_fp;
	
	switch ( c_item->card_type ) {
	case	0:	strcpy ( buf , "信用卡" );
			break;
	case	1:	strcpy ( buf , "借记卡" );
			break;
	case	2:	strcpy ( buf , "威士卡" );
			break;
	case	3:	strcpy ( buf , "万事达卡" );
			break;
	case	4:	strcpy ( buf , "运通卡" );
			break;
	case	5:	strcpy ( buf , "大莱卡" );
			break;
	case	6:	strcpy ( buf , "JCB 卡" );
			break;
	default:	strcpy ( buf , "Unkown" );
			break;
	}
	
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |%-10s %3.2lf %% %8ld %14.2lf %14.2lf %14.2lf\n", m_r_item->m_id, t_item->t_id, t_item->batch_no, "99999999", "999999", line++%100000000, buf, m_r_item->fee_percent[c_item->card_type]*100.0, c_item->pur_num, c_item->pur_amt, c_item->fee, c_item->pur_amt-c_item->fee);

}

void FileTail_mer_card_hz ( char *m_id , TER_RPT_ITEM *t_item )
{
	if ( mer_bc_mx_fp == NULL ) return ;
	
	fp = mer_bc_mx_fp;
	
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |-----------------------------------------------------------------------\n", m_id, t_item->t_id, t_item->batch_no, "99999999", "999999", line++%100000000);

	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |%-10s        %8ld %14.2lf %14.2lf %14.2lf\n", m_id, t_item->t_id, t_item->batch_no, "99999999", "999999", line++%100000000, "批次汇总", t_item->pur_num, t_item->pur_amt, t_item->fee, t_item->pur_amt-t_item->fee);
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |\n", m_id, t_item->t_id, t_item->batch_no, "99999999", "999999", line++%100000000);
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |\n", m_id, t_item->t_id, t_item->batch_no, "99999999", "999999", line++%100000000);
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |\n", m_id, t_item->t_id, t_item->batch_no, "99999999", "999999", line++%100000000);
}

void FileHead_mer_bc_mx_total ( MER_RPT_ITEM *m_r_item )
{
	if ( mer_bc_mx_fp == NULL ) return ;
	
	fp = mer_bc_mx_fp;

	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |商户卡汇总表\n", m_r_item->m_id, "99999999", 0, "99999999", "999999", line++%100000000);
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |\n", m_r_item->m_id, "99999999", 0, "99999999", "999999", line++%100000000);
	
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |%-10s %6s %8s %14s %14s %14s\n", m_r_item->m_id, "99999999", 0, "99999999", "999999", line++%100000000, "卡类" , "回扣率", "笔数", "交易金额", "手续费", "交易净额");
	
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |-----------------------------------------------------------------------\n", m_r_item->m_id, "99999999", 0, "99999999", "999999", line++%100000000);

}

void FileDetail_mer_bc_mx_total ( MER_RPT_ITEM *m_r_item , CARD_ITEM *c_item )
{
char	buf[20];

	if ( mer_bc_mx_fp == NULL ) return ;
	
	fp = mer_bc_mx_fp;
	
	switch ( c_item->card_type ) {
	case	0:	strcpy ( buf , "信用卡" );
			break;
	case	1:	strcpy ( buf , "借记卡" );
			break;
	case	2:	strcpy ( buf , "威士卡" );
			break;
	case	3:	strcpy ( buf , "万事达卡" );
			break;
	case	4:	strcpy ( buf , "运通卡" );
			break;
	case	5:	strcpy ( buf , "大莱卡" );
			break;
	case	6:	strcpy ( buf , "JCB 卡" );
			break;
	default:	strcpy ( buf , "Unkown" );
			break;
	}
	
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |%-10s %3.2lf %% %8ld %14.2lf %14.2lf %14.2lf\n", m_r_item->m_id, "99999999", 0, "99999999", "999999", line++%100000000, buf, m_r_item->fee_percent[c_item->card_type]*100.0, c_item->pur_num, c_item->pur_amt, c_item->fee, c_item->pur_amt-c_item->fee);

}
			
void FileTail_mer_bc_mx_total ( MER_RPT_ITEM *m_r_item )
{
	if ( mer_bc_mx_fp == NULL ) return ;
	
	fp = mer_bc_mx_fp;

	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |-----------------------------------------------------------------------\n", m_r_item->m_id, "99999999", 0, "99999999", "999999", line++%100000000);

	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |%-10s        %8ld %14.2lf %14.2lf %14.2lf\n", m_r_item->m_id, "99999999", 0, "99999999", "999999", line++%100000000, "商户汇总", m_r_item->pur_num, m_r_item->pur_amt, m_r_item->fee, m_r_item->pur_amt-m_r_item->fee);
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |\n", m_r_item->m_id, "99999999", 0, "99999999", "999999", line++%100000000);
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |\n", m_r_item->m_id, "99999999", 0, "99999999", "999999", line++%100000000);
	fprintf(fp, "%-15.15s%-8.8s%06ld%8.8s%6.6s%08ld |\n", m_r_item->m_id, "99999999", 0, "99999999", "999999", line++%100000000);
	
}

void create_mer_bc_mx ()
{
char cmd[500];

	if ( (print_enable&MER_BC_MX) == 0 ) return;
	
	sprintf ( cmd , "sort -n /tmp/.mer_bc_mx 2>/dev/null | sed \"s/^.*|//\" 2>/dev/null >%s/prt/%s/%s.mer_bc_mx",
		getenv("WORKDIR"),
		G_bankid, rpt_file_head);

⌨️ 快捷键说明

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