bal_rpt.ec

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

EC
126
字号
/*******************************************************
 *	全辖交易平衡报表(bal_rpt)
 *
 * 最后修改:	周国祥 2001/08/16
 *******************************************************/
#include <stdio.h>
#include <math.h>
#include "all.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;

extern char G_cen_bankid[12];
extern char G_bankid[12];

/* same as the struct in net_stat.ec */
typedef struct {
	char	bankid[12];
	char	hostid[3];
	int	credit_cnt;
	double	credit_amt;
	int	rev_credit_cnt;
	double	rev_credit_amt;
	int	debit_cnt;
	double	debit_amt;
	int	rev_debit_cnt;
	double	rev_debit_amt;
	int	tran_cnt;
	int	rev_tran_cnt;
	int	auth_cnt;
	int	cnt;
	double	amt;
} S_stat;

int bal_rpt(char *filename, char *logic_date)
{
	FILE	*fp;
	S_stat	*stat, total;
	int	i, num;

	if (!(fp = fopen(filename, "w"))) {
		daylog(ERROR, "Open %s for write error!", filename);
		return(-1);	/* File operate error */
	}
	if (FileHead_BR(fp, logic_date)) {
		fclose(fp);
		return(-2);	/* Database operate error */
	}
	num = get_stat(&stat, logic_date);
	if (num < 0) {
		fclose(fp);
		return(num);
	}
	memset(&total, 0, sizeof(S_stat));
	for (i = 0; i < num; i++) {
		total.credit_cnt += stat[i].credit_cnt;
		total.credit_amt += stat[i].credit_amt;
		total.rev_credit_cnt += stat[i].rev_credit_cnt;
		total.rev_credit_amt += stat[i].rev_credit_amt;
		total.debit_cnt += stat[i].debit_cnt;
		total.debit_amt += stat[i].debit_amt;
		total.rev_debit_cnt += stat[i].rev_debit_cnt;
		total.rev_debit_amt += stat[i].rev_debit_amt;
		total.tran_cnt += stat[i].tran_cnt;
		total.rev_tran_cnt += stat[i].rev_tran_cnt;
		total.auth_cnt += stat[i].auth_cnt;
		total.cnt += stat[i].cnt;
		total.amt += stat[i].amt;
		FileDetail_BR(fp, stat + i);
	}
	free((void *)stat);

	FileTail_BR(fp, &total);
	fclose(fp);
	return(0);
}

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

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

	getdatef(date, "/");
	gettimef(time, ":");
	fprintf(fp, "%60s中国银行BTS系统\n", " ");
	fprintf(fp, "%60s全辖交易平衡报表\n", " ");
	str2date(logic_date1, logic_date, "/");

	fprintf(fp, "BTS-502%106s清算日期: %s\n", " ", logic_date1);
	get_bank_name(G_bankid, "00", bank_name);
	fprintf(fp, "%-5.5s%-111s%s %s\n", G_bankid, bank_name, date, time);
	fprintf(fp, "---------------------------------------------------------------------------------------------------------------------------------------\n");

	fprintf(fp, "%4s %6s %14s %6s %14s %6s %14s %6s %14s %6s %6s %6s %6s %14s\n", "联行", "贷记", "贷记", "撤消贷", "撤消贷", "借记", "借记", "撤消借", "撤消借", "转帐", "撤消转", "授权", "总笔数", "净金额");
	fprintf(fp, "%4s %6s %14s %6s %14s %6s %14s %6s %14s %6s %6s %6s %6s %14s\n", "行号", "笔数", "金额", "记笔数", "记金额", "笔数", "金额", "记笔数", "记金额", "笔数", "帐笔数", "笔数", "      ", "      ");

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

int FileDetail_BR(FILE *fp, S_stat *pstat)
{
	fprintf(fp, "%-4.4s %6d %14.2lf %6d %14.2lf %6d %14.2lf %6d %14.2lf %6d %6d %6d %6d %14.2lf\n", pstat->bankid, pstat->credit_cnt, pstat->credit_amt, pstat->rev_credit_cnt, pstat->rev_credit_amt, pstat->debit_cnt, pstat->debit_amt, pstat->rev_debit_cnt, pstat->rev_debit_amt, pstat->tran_cnt, pstat->rev_tran_cnt, pstat->auth_cnt, pstat->cnt, pstat->amt);
	return(0);
}

int FileTail_BR(FILE *fp, S_stat *pstat)
{
	fprintf(fp, "---------------------------------------------------------------------------------------------------------------------------------------\n");
	if (pstat->cnt) fprintf(fp, "%-4.4s %6d %14.2lf %6d %14.2lf %6d %14.2lf %6d %14.2lf %6d %6d %6d %6d %14.2lf\n", "合计", pstat->credit_cnt / 2, pstat->credit_amt / 2, pstat->rev_credit_cnt / 2, pstat->rev_credit_amt / 2, pstat->debit_cnt / 2, pstat->debit_amt / 2, pstat->rev_debit_cnt / 2, pstat->rev_debit_amt / 2, pstat->tran_cnt / 2, pstat->rev_tran_cnt / 2, pstat->auth_cnt / 2, pstat->cnt / 2, pstat->amt);
	return(0);
}

⌨️ 快捷键说明

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