qsdz_rpt.ec

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

EC
470
字号
/****************************************************
 *	全辖清算明细报表 qsdz_rpt()
 *	全辖清算汇总报表
 *	全辖清算手续费报表
 *	called by gen_qsdz() -- in gen_rpt.ec
 *
 * 最后修改:	周国祥 2001/08/25
 ****************************************************/
#include <stdio.h>
#include <math.h>

#include "all.h"
#include "macro_def.h"

$include "db_struct.h"
$include sqlca;

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

typedef struct {
	char bankid[12];
	char hostid[3];
	char bankname[31];
	double credit_amt;
	double debit_amt;
	int credit_cnt;
	int debit_cnt;
	double amt;
	int cnt;
	int tip_cnt;
	char filename[64];
	FILE *fp;
} S_qs_rpt;

extern int get_son();
extern int check_son();
extern char G_cen_bankid[12];
extern char G_bankid[12];

double in_out(double in)
{
	return((double)(long)((in + 0.005) * 100) / 100);
}

double get_qs_tip(S_tran_ls ls)
{
	double tip;

	switch (ls.tran_type) {
	    case DEPOSIT:
		return(0);
/*
		tip = 0.001 * ls.tran_amt;
		if (tip > 500) tip = 500;
		else if (tip < 5) tip = 5;
		return(in_out(tip / 2));
*/
	    case WITHDRAWAL:
		tip = 0.01 * ls.tran_amt;
		if (tip < 1) tip = 1;
		return(in_out(tip / 2));
	    case PURCHASE:
	    case CONFIRM:
		tip = 0.005 * ls.tran_amt;
		tip = - in_out(tip);
		return(tip);
	    case TRANS_OUT:
		tip = 0.005 * ls.tran_amt;
		if (tip > 500) tip = 500;
		else if (tip < 10) tip = 10;
		return(in_out(tip / 2));
	    default:
		return(0);
	}
}

int qsdz_rpt(file1, file2, file3, logic_date, bankid, hostid)
	char *file1;
	char *file2;
	char *file3;
	$parameter char *logic_date;
	char *bankid, *hostid;
{
	$S_tran_ls ls;
	S_qs_rpt rpt[48], total;
	char date[11], time[9];
	char son_bankid[48][12], son_hostid[48][3], cmd[128];
	char sign_bankid[12], sign_hostid[3];
	int i, j, num = 0;
	FILE *fp, *fp_tip;

#ifdef wyz020508_mod
	if (get_son(bankid, hostid, son_bankid, son_hostid) < 0)
		return(-2);
#else
	memset(&son_bankid, 0, sizeof(son_bankid));
	memset(&son_hostid, 0, sizeof(son_hostid));

	if (strcmp(G_cen_bankid, G_bankid)) {
		strcpy(son_bankid[0], G_bankid);
		strcpy(son_hostid[0], "00");
	}
	else {
		if (get_son(bankid, hostid, son_bankid, son_hostid) < 0)
			return(-2);
	}
#endif
	memset(rpt, 0, sizeof(rpt));

	getdatef(date, "/");
	gettimef(time, ":");

	if (!(fp = fopen(file1, "w"))) {
		daylog(ERROR, "Open %s error!", file1);
		return(-1);	/* File operate error */
	}
	if (FileHead_qsdz(fp, logic_date, date, time)) {
		fclose(fp);
		return(-2);	/* Database operate error */
	}
	if (file3[0]) {
		if (!(fp_tip = fopen(file3, "w"))) {
			daylog(ERROR, "Open %s error!", file3);
			fclose(fp);
			return(-1);	/* File operate error */
		}
		if (FileHead_tip(fp_tip, logic_date, date, time)) {
			fclose(fp);
			fclose(fp_tip);
			return(-2);	/* Database operate error */
		}
	}

$ifdef wyz020508_mod;
	$declare qs_cur cursor for
	select * from cur_tran_ls
	where acq_bank_id != iss_bank_id
	and tran_type in (1,2,3,5,6,7,8,9,10,14)
	and saf_flag = '0'
	and tran_flag = '0'
	and manual_flag = 'N'
	and resp_code like '00%'
	and snd_settle_date = :logic_date
	and card_type = '02'
	order by card_no;
$else;
	$declare qs_cur cursor for
	select * from cur_settle_ls
	where acq_bank_id != iss_bank_id
	and manual_flag = 'N'
	and snd_settle_date = :logic_date
	and card_type = '02'
	order by card_no;
$endif;

	$open qs_cur;
	if (SQLCODE) {
		daylog(ERROR, "Open qs_cur error![%d]", SQLCODE);
		fclose(fp);
		if (file3[0]) fclose(fp_tip);
		return(-2);
	}
	while (1) {
		$fetch qs_cur into :ls;
		if (SQLCODE == 100) break;
		if (SQLCODE) {
			daylog(ERROR, "Fetch qs_cur error![%d]", SQLCODE);
			$close qs_cur;
			fclose(fp);
			if (file3[0]) fclose(fp_tip);
			return(-2);
		}
		del_st_space("tran_ls", &ls);

#ifdef wyz020508_mod
#else
		if (strcmp(G_cen_bankid, G_bankid)) {
			get_sign_bank(ls.merchant_id, sign_bankid, sign_hostid);
			DelSpace(sign_bankid);
			if (strcmp(G_bankid, sign_bankid))
				continue;
		}
#endif

		if (add_qs_rpt(0, ls, son_bankid, son_hostid,
			    rpt, &num, logic_date,
			    date, time, file2[0])) {
			$close qs_cur;
			fclose(fp);
			if (file3[0]) fclose(fp_tip);
			return(-1);
		}
		if (add_qs_rpt(1, ls, son_bankid, son_hostid,
			    rpt, &num, logic_date,
			    date, time, file2[0])) {
			$close qs_cur;
			fclose(fp);
			if (file3[0]) fclose(fp_tip);
			return(-1);
		}
	}
	$close qs_cur;

	if (file2[0]) {
		for (i = 0; i < num; i++) {
			fprintf(rpt[i].fp, "--------------------------------------------------------------------------------------------------------------------------------\n");
			fprintf(rpt[i].fp, "%s %s %14.2lf %s %6d %s %14.2lf %s %6d %s %14.2lf %s %6d\n\n", "总  计", "贷记金额", rpt[i].credit_amt, "贷记笔数", rpt[i].credit_cnt, "借记金额", rpt[i].debit_amt,  "借记笔数", rpt[i].debit_cnt, "轧差金额", rpt[i].amt, "笔数", rpt[i].cnt);
			fclose(rpt[i].fp);
		}
		sprintf(cmd, "> %s", file2);
		system(cmd);
	}

	memset(&total, 0, sizeof(total));
	for (i = 0; i < num; i++)
		if (!strcmp(rpt[i].bankid, BOC_CENTER))
			break;
	if (i < num) {
		if (file2[0]) {
			sprintf(cmd, "cat %s >> %s", rpt[i].filename, file2);
			system(cmd);
			unlink(rpt[i].filename);
		}
		FileDetail_qsdz(fp, rpt[i]);
		if (file3[0] && rpt[i].tip_cnt)
			FileDetail_tip(fp_tip, rpt[i]);
		total.credit_amt += rpt[i].credit_amt;
		total.credit_cnt += rpt[i].credit_cnt;
		total.debit_amt += rpt[i].debit_amt;
		total.debit_cnt += rpt[i].debit_cnt;
		total.amt += rpt[i].amt;
		total.cnt += rpt[i].cnt;
		total.tip_cnt += rpt[i].tip_cnt;
		rpt[i].bankid[0] = 0;
	}
	for (i = 0; son_bankid[i][0]; i++) {
		for (j = 0; j < num; j++)
			if (!strcmp(rpt[j].bankid, son_bankid[i]))
				break;
		if (j < num) {
			if (file2[0]) {
				sprintf(cmd, "cat %s >> %s", rpt[j].filename,
					file2);
				system(cmd);
				unlink(rpt[j].filename);
			}
			FileDetail_qsdz(fp, rpt[j]);
			if (file3[0] && rpt[j].tip_cnt)
				FileDetail_tip(fp_tip, rpt[j]);
			total.credit_amt += rpt[j].credit_amt;
			total.credit_cnt += rpt[j].credit_cnt;
			total.debit_amt += rpt[j].debit_amt;
			total.debit_cnt += rpt[j].debit_cnt;
			total.amt += rpt[j].amt;
			total.cnt += rpt[j].cnt;
			total.tip_cnt += rpt[j].tip_cnt;
			rpt[j].bankid[0] = 0;
		}
	}
	FileTail_qsdz(fp, total);
	if (file3[0]) FileTail_tip(fp_tip, total);
	fclose(fp);
	if (file3[0]) fclose(fp_tip);
	return(0);
}

int add_qs_rpt(flag, ls, son_bankid, son_hostid, rpt, pnum, logic_date, date, time, mx)
	int flag;
	S_tran_ls ls;
	char son_bankid[48][12];
	char son_hostid[48][3];
	S_qs_rpt rpt[48];
	int *pnum;
	char logic_date[11];
	char date[11];
	char time[9];
	int mx;
{
	$char bankid[12], hostid[3], bankname[31];
	double tip;
	int i;
	char logic_date1[11];	/* YYYY/MM/DD */
	char tmp_date[11];	/* YYYY/MM/DD */
	char tmp_time[9];	/* hh:mm:ss */

	if (flag) {
		if (!check_son(ls.iss_bank_id, "00", son_bankid, son_hostid)) {
			strcpy(bankid, BOC_CENTER /*"0004"*/);
			strcpy(hostid, "00");
		} else {
			strcpy(bankid, ls.iss_bank_id);
			strcpy(hostid, "00");
		}
	} else {
		if (!check_son(ls.acq_bank_id, ls.acq_host_id, son_bankid, son_hostid)) {
			strcpy(bankid, BOC_CENTER /*"0004"*/);
			strcpy(hostid, "00");
		} else {
			strcpy(bankid, ls.acq_bank_id);
			strcpy(hostid, ls.acq_host_id);
		}
	}
	for (i = 0; i < *pnum; i++)
		if (!strcmp(bankid, rpt[i].bankid))
			break;
	if (i == *pnum) {
		strcpy(rpt[i].bankid, bankid);
		strcpy(rpt[i].hostid, hostid);
		get_bank_name(bankid, hostid, bankname);
		strcpy(rpt[i].bankname, bankname);
		if (mx) {
			sprintf(rpt[i].filename, "/tmp/.%-4.4s", bankid);
			rpt[i].fp = fopen(rpt[i].filename, "w");
			if (!rpt[i].fp) {
				daylog(ERROR, "Open %s error!",rpt[i].filename);
				for (i = 0; i < *pnum; i++) {
					fclose(rpt[i].fp);
					unlink(rpt[i].filename);
				}
				return(-1);
			}
			fprintf(rpt[i].fp, "%53s中国银行BTS系统借记卡\n", " ");
			fprintf(rpt[i].fp, "%53s全辖清算明细报表\n", " ");
			str2date(logic_date1, logic_date, "/");
			fprintf(rpt[i].fp, "BTS-806%99s清算逻辑日: %s\n", " ", logic_date1);
			fprintf(rpt[i].fp, "%-5.5s%-104s%s %s\n", bankid, bankname, date, time);
			fprintf(rpt[i].fp, "--------------------------------------------------------------------------------------------------------------------------------\n");
			fprintf(rpt[i].fp, "%-21s %-8s %14s %6s %14s %6s %-15s %-8s %-6s %-6s %-10s %-8s\n", "卡  号", "交易类型", "交易金额", "手续费", "清算金额", "授权码", "商户号", "EDC 号", "收单行", "发卡行", "交易日期", "交易时间");
			fprintf(rpt[i].fp, "--------------------------------------------------------------------------------------------------------------------------------\n");
		}
		(*pnum)++;
	}
	tip = get_qs_tip(ls);
	switch (ls.tran_type) {
	    case PURCHASE:
	    case WITHDRAWAL:
	    case CONFIRM:
	    case TRANS_OUT:
		if (flag) {
			rpt[i].debit_cnt++;
			rpt[i].debit_amt += ls.tran_amt + tip;
			rpt[i].cnt++;
			rpt[i].amt -= ls.tran_amt + tip;
			rpt[i].tip_cnt++;
		} else {
			rpt[i].credit_cnt++;
			rpt[i].credit_amt += ls.tran_amt + tip;
			rpt[i].cnt++;
			rpt[i].amt += ls.tran_amt + tip;
		}
		break;
	    case REFUND:
	    case DEPOSIT:
		if (flag) {
			rpt[i].credit_cnt++;
			rpt[i].credit_amt += ls.tran_amt + tip;
			rpt[i].cnt++;
			rpt[i].amt += ls.tran_amt + tip;
			rpt[i].tip_cnt++;
		} else {
			rpt[i].debit_cnt++;
			rpt[i].debit_amt += ls.tran_amt + tip;
			rpt[i].cnt++;
			rpt[i].amt -= ls.tran_amt + tip;
		}
		break;
	}
	if (mx) {
		str2date(tmp_date, ls.local_sys_date, "/");
		str2time(tmp_time, ls.local_sys_time, ":");

		type2buf(ls.tran_type, bankname);
		fprintf(rpt[i].fp, "%-6.6s-%-4.4s-%-9.9s %-8s %14.2lf %6.2lf %14.2lf %6s %-15.15s %-8.8s %-6.6s %-6.6s %-10s %-8s\n", ls.card_no, ls.card_no + 6, ls.card_no + 10, bankname, ls.tran_amt, fabs(tip), ls.tran_amt + tip, ls.auth_no, ls.merchant_id, ls.terminal_id, ls.acq_bank_id, ls.iss_bank_id, tmp_date, tmp_time);
	}
	return(0);
}

int FileHead_qsdz(FILE *fp, char *logic_date, char *date, char *time)
{
	$S_sys_param sys;
	char	bank_name[128];
	char	logic_date1[11];	/* YYYY/MM/DD */

$ifdef wyz020508_mod;
	$select * into :sys from sys_param;
	if (SQLCODE) {
		daylog(ERROR, "Select sys_param error!");
		return(-1);
	}
	del_st_space("sys_param", &sys);
$else;
$endif;

	fprintf(fp, "%38s中国银行BTS系统借记卡\n", " ");
	fprintf(fp, "%38s全辖清算汇总报表\n", " ");
	str2date(logic_date1, logic_date, "/");
	fprintf(fp, "BTS-805%70s清算逻辑日: %s\n", " ", logic_date1);

	get_bank_name(G_bankid, "00", bank_name);
	fprintf(fp, "%-5.5s%-75s%s %s\n", G_bankid, bank_name, date, time);
	fprintf(fp, "---------------------------------------------------------------------------------------------------\n");

	fprintf(fp, "%-8s %-20s %14s %8s %14s %8s %14s %6s\n",
	"联行行号", "联行名称", "贷记金额", "贷记笔数", "借记金额", "借记笔数", "轧差金额", "笔数");

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

int FileDetail_qsdz(FILE *fp, S_qs_rpt rpt)
{
	fprintf(fp, "%-8.8s %-20.20s %14.2lf %8d %14.2lf %8d %14.2lf %6d\n", rpt.bankid, rpt.bankname, rpt.credit_amt, rpt.credit_cnt, rpt.debit_amt, rpt.debit_cnt, rpt.amt, rpt.cnt);
	return(0);
}

int FileTail_qsdz(FILE *fp, S_qs_rpt rpt)
{
	fprintf(fp, "---------------------------------------------------------------------------------------------------\n");
	if (rpt.cnt)
		fprintf(fp, "%-8.8s %-20s %14.2lf %8d %14.2lf %8d %14.2lf %6d\n", "总    计", " ", rpt.credit_amt, rpt.credit_cnt, rpt.debit_amt, rpt.debit_cnt, rpt.amt, rpt.cnt / 2);
	return(0);
}

int FileHead_tip(FILE *fp, char *logic_date, char *date, char *time)
{
	$S_sys_param sys;
	char	bank_name[128];
	char	logic_date1[11];	/* YYYY/MM/DD */

$ifdef wyz020508_mod;
	$select * into :sys from sys_param;
	if (SQLCODE) {
		daylog(ERROR, "Select sys_param error!");
		return(-1);
	}
	del_st_space("sys_param", &sys);
$else;
$endif;

	fprintf(fp, "%14s中国银行BTS系统借记卡\n", " ");
	fprintf(fp, "%14s全辖清算手续费报表\n", " ");
	str2date(logic_date1, logic_date, "/");
	fprintf(fp, "BTS-807%22s清算逻辑日: %s\n", " ", logic_date1);

	get_bank_name(G_bankid, "00", bank_name);
	fprintf(fp, "%-5.5s%-27.27s%s %s\n", G_bankid, bank_name, date, time);
	fprintf(fp, "---------------------------------------------------\n");

	fprintf(fp, "%-8s %-20s %14s %6s\n", "联行行号", "联行名称", "金额", "笔数");

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

int FileDetail_tip(FILE *fp, S_qs_rpt rpt)
{
	fprintf(fp, "%-8.8s %-20.20s %14.2lf %6d\n", rpt.bankid, rpt.bankname, 0.3 * rpt.tip_cnt, rpt.tip_cnt);
	return(0);
}

int FileTail_tip(FILE *fp, S_qs_rpt rpt)
{
	fprintf(fp, "---------------------------------------------------\n");
	if (rpt.tip_cnt)
		fprintf(fp, "%-8.8s %-20s %14.2lf %6d\n", "总    计", " ", 0.3 * rpt.tip_cnt, rpt.tip_cnt);
	return(0);
}

⌨️ 快捷键说明

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