📄 cmsb24.sqc
字号:
/******************************************************************** ** 源码文件名称 : cmsB24.SQC ** 函数名称 : cms21B024 ** 所属子系统 : CMS ** 当前文件版本 : 1.0.0.0 ** 作 者 : Richard ** 版本创建日期 : 2005/02/25 ** 功能描述 : 跨行未入帐明细打印 ** 修改记录 : ** 修改人 修改日期 修改日期*********************************************************************/#include "sysdefine.h"#include <stdio.h>#include "pubcom.h"#include "funcapi.h"#include "code.h"#include "attrdef.h"#include "cmscode.h"#include "cmstxdethis.h"#include "cmsmerchantinfo.h"#include "pubbranchinfo.h"#include "errlog.h"EXEC SQL INCLUDE sqlca;char *RptFormatAmt(double amt, char *pstr);#define OVERPAGE 53 /* 满页行数 */ #define OVERLINE 5 /* 换行行数 */ #define LIMIT 50#define NEEDPRTBRCMAX 200 /*需要打印的机构列表最大值*/ struct CMSNEEDPRTBRCLIST { int iSeqNo; /*序号*/ char acBrcClass[2]; /*机构级别*/ char acNeedPrtBrc[10]; /*需要打印的机构列表 */ char acSuperBrc[10]; /*需要打印机构的上级机构 */ int iBrcTranNum; double dBrcTranAmt;};int iTotalClassNum=0;double dTotalClassAmt=0.00;int iTotalNum=0;double dTotalAmt=0.00;char acAmt[31];char acDevName[21];int iDetailSeq=0;#define PRTHEAD \ PRTHEAD0 \ PRTHEAD_FORTAIL \#define PRTHEAD0 \ prtline( fp,"title1:%s", acBankname); \ iLineCount++; \ prtline( fp,"title2:"); \ iLineCount++; \ prtline( fp, "title3:%s|%s|%d", \ pstPubcom->acBrc, acSettleDate, iPage ); \ iLineCount++; \ #define PRTHEAD_FORTAIL \ prtline( fp, "head1:" ); \ iLineCount++; \ prtline( fp, "head2:" ); \ iLineCount++; \ prtline( fp, "body0:" ); \ iLineCount++; \ iLine ++ ; \#define PRTBODY \ if( iLine % OVERPAGE == 0 ) \ { \ PRTFOOT \ PRTHEAD \ } \ strpack(cmstxdethis_devid); \ strpack(cmstxdethis_cardno1); \ strpack(cmstxdethis_cardno2); \ cmstxdethis_cardno1[22]=0x00; \ cmstxdethis_cardno2[22]=0x00; \ cmstxdethis_devid[10]=0x00; \ prtline( fp,"body1:%4d|%-10s|%-22s|%-22s|%17s|%10s|%10s|%6s|%-8s|%-8ld|%-8s|%-14s", \ iDetailSeq,cmstxdethis_devid, \ cmstxdethis_cardno1, cmstxdethis_cardno2, \ RptFormatAmt(cmstxdethis_tranamt,acAmt), \ cmstxdethis_settledate,cmstxdethis_trandate, \ cmstxdethis_frnttime, cmstxdethis_devstan, \ cmstxdethis_serseqno, \ cmstxdethis_frntstan, acTranName); \ iLineCount++; \ iLine ++ ; \ if( iLine % OVERPAGE == 0 || (iLine+1) % OVERPAGE == 0 ) \ { \ PRTFOOT \ PRTHEAD \ } \#define PRTBODYLINE \ prtline( fp, "body0:" ); \ iLineCount++; \ iLine ++ ; \#define PRTBODYLINE_B \ prtline( fp, "body9:" ); \ iLineCount++; \ iLine ++ ; \#define PRTONECLASSSTA \ /*判断如果剩余的纸不够,重新开始一页*/ \ if( (OVERPAGE - iLine % OVERPAGE) < 3 ) \ { \ PRTFOOT \ PRTHEAD \ } else if ( iLine != 1) { \ prtline( fp, "body2:" ); \ iLineCount++; \ iLine ++ ; \ } \ iDetailSeq=1; \ prtline( fp, "body3:%s|%d|%17s|", \ pastNPB->acNeedPrtBrc,pastNPB->iBrcTranNum, \ RptFormatAmt( pastNPB->dBrcTranAmt,acAmt)); \ iLineCount++; \ iLine ++ ; \ if( iLine % OVERPAGE == 0 ) \ { \ PRTFOOT \ PRTHEAD \ } \ #define PRTFIVECLASSSTA \ /*判断如果剩余的纸不够,重新开始一页*/ \ if( (OVERPAGE - iLine % OVERPAGE) < 3 ) \ { \ PRTFOOT \ PRTHEAD \ } else if ( iLine != 1 ) { \ prtline( fp, "body5:" ); \ iLineCount++; \ iLine ++ ; \ } \ prtline( fp, "body6:%d|%17s|", \ iTotalClassNum, RptFormatAmt(dTotalClassAmt,acAmt)); \ iLineCount++; \ iLine ++ ; \ if( iLine % OVERPAGE == 0 ) \ { \ PRTFOOT \ PRTHEAD \ } \#define PRTTOTALSTA \ prtline( fp, "bodyk:" ); \ iLineCount++; \ iLine ++ ; \ prtline( fp, "bodym:%d|%17s", \ iTotalNum, RptFormatAmt(dTotalAmt,acAmt)); \ iLineCount++; \ iLine ++ ; \#define PRTFOOT \ prtline( fp, "tail1:" ); \ iLineCount++; \ prtline( fp, "bottm:%s", \ pstPubcom->acTeller ); \ iLineCount++; \ prtline( fp, "next:%s",pstPubcom->acTranDate ); \ iLineCount++; \ iPage ++ ; iLine = 0 ; \/*程序入口*/int cms21B024(pstPubcom)struct pubcom *pstPubcom;{EXEC SQL BEGIN DECLARE SECTION; char acSettleDate[DATE_LEN + 1 ]; /* 起始日期 */ char acEndDate[DATE_LEN + 1 ]; /* 终止日期 */ char acDevId[DEVID_LEN + 1 ]; /* 设备代码 */ char acDevType[ 2 + 1 ]; /* 设备类型 */ char acWhrStr[ 1024 ];EXEC SQL END DECLARE SECTION; char acBankname[ 41 ]; char acBuffer[9]; FILE *fp,*fmtfp; /* 文件指针 */ char acSelStr[ 301 ]; char acWhrTmp[ 512 ]; int iLineCount = 0 ; int i, iPage, iLine, iBrcSeq, iRet; char acFileName[ 101 ]; char acFmtFile[ 101 ]; int iHaveFlag; /*有效交易记录标志0无 1有*/ int iLineFlag; /*打印行线 0body1 1bodyb*/ char acBrc1[10]; /*交易机构码 */ char acIssueBrc[10]; /*发卡机构码 */ char acCardNo[33]; /*卡号 */ char acDevTranType[3]; /*交易统计类型 */ char acTranName[81]; /*交易名称 */ struct cmstxdethis stCmsTxdetHis; /* 外围交易登记簿历史表 */ struct pubbranchinfo stPubBranchInfo; /* 机构信息表 */ struct CMSNEEDPRTBRCLIST astNeedPrtBrc[ NEEDPRTBRCMAX ],*pastNeedPrtBrc,*pastNPB,*pastTmp; memset( acBrc1, 0x00, sizeof( acBrc1 )); memset( acDevId, 0x00, sizeof( acDevId )); memset( acDevType, 0x00, sizeof( acDevType )); memset( acSettleDate, 0x00, sizeof( acSettleDate )); memset( acEndDate, 0x00, sizeof( acEndDate )); memset( acBuffer, 0x00, sizeof( acBuffer ) ); memset( acSelStr, 0x00, sizeof( acSelStr ) ); memset( acWhrStr, 0x00, sizeof( acWhrStr ) ); memset( &stCmsTxdetHis, 0x00, sizeof( struct cmstxdethis )); memset( acBankname, 0x00, sizeof( acBankname ) ); if ( pubGetBaseInfo("BANKNAME", acBankname ) ) FUNCERR_PRO /* 取数据字典 */ getstring( "cleardate", acSettleDate ); getstring( "Brc1", acBrc1 ); sprintf( g_acTrcMsg,"跨行未入帐明细打印 Date1[%s]Brc1[%s]", acSettleDate,acEndDate ); TRCLOG4 /* **打印权限和范围判断,取得需要打印的机构列表 */ memset( astNeedPrtBrc, 0x00, sizeof(astNeedPrtBrc)); iRet = RptJudgeRightAndList(pstPubcom->acBrc,acBrc1,astNeedPrtBrc); if ( iRet != SUCCESS ) { sprintf( g_acTrcMsg," 要打印的机构不存在或没有权限打印!" ); TRCLOG4 return FAILED; } if( strlen(acBrc1)==0 ) strcpy(acBrc1,pstPubcom->acBrc); fp = (FILE *)BeginFile( pstPubcom, NULL ); if ( fp == NULL ) { strcpy( g_acRspCode, "DPS902" ); pubCrtRspInfo( ); ERRLOG return FAILED ; } sprintf( acFmtFile, "%s/fmt/cmsB24.fmt", getenv("HOME") ); sprintf( g_acFmtFile, acFmtFile ); if( ( fmtfp=fopen(acFmtFile,"r") ) == NULL ) { strcpy( g_acTrcMsg, acFmtFile ); TRCLOG2 ERRLOG goto Exit; } iLine = 0 ; iPage = 1 ; /*打印报表头*/ PRTHEAD /*从序号 1 开始, 0 作为判断用*/ pastNPB=astNeedPrtBrc+1; iLineFlag=0; iDetailSeq=1; /*读取报文体数据*/ for (; pastNPB->acBrcClass[0] != 'E'; pastNPB++) { /*组查询语句*/ sprintf(acWhrStr, "SELECT * FROM cmstxdethis WHERE brc='%s' ",pastNPB->acNeedPrtBrc); if ( strcmp ( acSettleDate, INITDATE ) ) { memset( acWhrTmp, 0x00, sizeof( acWhrTmp ) ); sprintf( acWhrTmp," AND settledate = '%s' AND trandate != '%s' ", acSettleDate, acSettleDate ); strcat( acWhrStr,acWhrTmp); } strcat( acWhrStr, " AND validf='0' "); sprintf(acWhrStr+strlen(acWhrStr), "UNION ALL SELECT * FROM cmstxdet WHERE brc='%s' ",pastNPB->acNeedPrtBrc); if ( strcmp ( acSettleDate, INITDATE ) ) { memset( acWhrTmp, 0x00, sizeof( acWhrTmp ) ); sprintf( acWhrTmp," AND settledate = '%s' AND trandate != '%s' ", acSettleDate, acSettleDate ); strcat( acWhrStr,acWhrTmp); } strcat( acWhrStr, " AND validf='0' ORDER BY trandevtype,trandate,serseqno " ); strcpy( g_acTrcMsg, acWhrStr ); TRCLOG4 EXEC SQL PREPARE pre_txdethis FROM :acWhrStr; EXEC SQL DECLARE cur_txdethis CURSOR FOR pre_txdethis; SQLOPENCUR(cur_txdethis,"cur_txdethis") if(SQLCODE) { sprintf( g_acTrcMsg,"SQLCODE[%d]", SQLCODE); TRCLOG4 strcpy( g_acRspCode, "CMS111" ); pubCrtRspInfo("cmstxdethis",SQLCODE ); ERRLOG goto Exit ; } for( ; ; ) { pubInitCmstxdethis(); EXEC SQL FETCH cur_txdethis INTO R_CMSTXDETHIS; if( SQLCODE == SQLNOTFOUND ) break ; if(SQLCODE) { sprintf( g_acTrcMsg,"SQLCODE[%d]", SQLCODE); TRCLOG4 strcpy( g_acRspCode, "CMS112" ); pubCrtRspInfo("cmstxdethis",SQLCODE ); ERRLOG goto Exit ; } iHaveFlag=0; memset(acTranName,0x00,sizeof(acTranName)); TransMemo( "0031", cmstxdethis_frnttrancode, acTranName); strpack(acTranName); acTranName[14]=0x00; /*打印表体*/ /*判断如果是第一行,不打印分行线 */ if ( iLineFlag == 0 && iLine != 1 ) { PRTBODYLINE } else if ( iLineFlag=1 && iLine != 1 ) { PRTBODYLINE_B iLineFlag=0; } PRTBODY iDetailSeq++; /*加入机构小计*/ pastNPB->iBrcTranNum ++; pastNPB->dBrcTranAmt = pastNPB->dBrcTranAmt +cmstxdethis_tranamt; }/*fetch for*/ SQLCLOSECUR(cur_txdethis,"cur_txdethis") /*打印普通机构的小计,如果该机构没有交易则不打印*/ if ( pastNPB->iBrcTranNum > 0 ) { PRTONECLASSSTA iLineFlag=1; } /*判断是否一级机构,用机构等级来判断*/ if (pastNPB->acBrcClass[0]='3') { pastTmp=pastNPB; while( pastTmp->iSeqNo != 0 ) { pastTmp--; if ( strcmp(pastTmp->acSuperBrc,pastNPB->acNeedPrtBrc)== 0 ) { iTotalClassNum=iTotalClassNum +pastTmp->iBrcTranNum; dTotalClassAmt=dTotalClassAmt +pastTmp->dBrcTranAmt; } else break; } if ( iTotalClassNum > 0 ) { /*下级机构有业务的时候,才累计一级支行的*/ iTotalClassNum=iTotalClassNum + pastNPB->iBrcTranNum; dTotalClassAmt=dTotalClassAmt + pastNPB->dBrcTranAmt; } /*打印一级机构的小计,如果该机构没有交易则不打*/ if ( iTotalClassNum > 0 ) { PRTFIVECLASSSTA iLineFlag=1; } iTotalClassNum=0; dTotalClassAmt=0.00; } else{ } }/*first for*/ /*计算总的合计数*/ pastTmp=pastNPB; pastTmp--; iTotalNum=0; dTotalAmt=0.00; while( pastTmp->iSeqNo != 0 ) { iTotalNum = iTotalNum + pastTmp->iBrcTranNum; dTotalAmt = dTotalAmt + pastTmp->dBrcTranAmt; pastTmp--; } /*打印总的合计数*/ PRTTOTALSTA /*打印表尾*/ PRTFOOT if( iTotalNum == 0 ) { strcpy( g_acRspCode, "999998" ); sprintf( g_acRspMsg, "无满足条件的纪录!" ); ERRLOG goto Exit ; } Exit:
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -