原创 光大银行的客户交易流水表程序

2008-7-29 08:14 6667 3 3 分类: 软件与OS

                                                         
 *    Description      : 光大银行日终程序----商户交易流水表    
 *                                                                 
 *    History          :    
 * ------------------------------------------------------------     
    
                                                              



#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <fcntl.h>
#include <setjmp.h>
#include "pberrlog.h"
EXEC SQL INCLUDE SQLCA;
EXEC SQL INCLUDE "pbappdb.h";
#define SQLCODE sqlca.sqlcode


 


int main(int argc, char **argv)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char acctdate[9];
    char instno[5];
     EB_BATCHSLD   BATCHSLD;
    EXEC SQL END   DECLARE SECTION;


    int ret="0";


    strcpy(logfile, "batch/batch");


    ret = ConnectDatabase();
    if( ret != 0 )
    {
   ErrSql(ERR_LVL,0);
   return -1;
    }
    PrintHead();
    /*
    ret="VerifyAndInit"(argc,argv);
    if(ret!=0)
    {
          WriteLog(ERR_LVL,"Init arg Err!");
   return -1;
    }
    */
    memset(acctdate,0x00,sizeof(acctdate));
    memset(instno,0x00,sizeof(instno));
    ret="GetAcctDate"(acctdate,instno);
    if(ret!=0)
    {
          WriteLog(ERR_LVL,"get acctdate  Err!");
   return -1;
    }
    ret="CrtRpt301"(acctdate,instno);
    if(ret==0)
    {
        /*  SetNextStepFlag( &BATCHSLD );*/
 /* 如果一切OK,UPDATE 标志的时候出错怎么办!?*/
    }
    EXEC SQL COMMIT RELEASE;
    PrintTail();
    return ret;
}


/*
 *生成301报表
 *
 */
int CrtRpt301(char *acctdate,char *InstNo)
{
    EXEC SQL BEGIN DECLARE SECTION;
    EB_JOURNAL  journal;
    char        trandate[9];
    char        instno[5];
    char        mercode[16];
    EXEC SQL END DECLARE SECTION;
    int         hisflag="0";
    char        filename[128];
    FILE       *fp;
    int        num="0";
    int        num1=0;
    double     amt1=0.00;
    double     instfee1=0.00;
    double     totalamt1=0.00;
    int        numc1=0;
    double     amtc1=0.00;
    int        num2=0;
    double     amt2=0.00;
    double     instfee2=0.00;
    double     totalamt2=0.00;
    int        numc2=0;
    double     amtc2=0.00;
   


    memset(trandate,0x00,sizeof(trandate));
    memcpy(trandate,acctdate,8);
    if(strlen(trandate)!=8)
    {
         WriteLog(ERR_LVL,"trandate format err![%s]",trandate);
  return -1;
    }



    memset(instno,0x00,sizeof(instno));
    memcpy(instno,InstNo,4);


    memset(filename,0x00,sizeof(filename));
    sprintf(filename,"%s/download/MER_301_%s_%s.rpt",
     getenv("HOME"),instno,trandate);
    fp="fopen"(filename,"w");
    if(fp==NULL)
    {
         WriteLog(ERR_LVL,"open file err![%s]",filename);
  return -1;
    }
   
    printf("trandate=%s\n",trandate);
    EXEC SQL DECLARE cur301 CURSOR for
      select NVL(a.mercode,' '),NVL(a.mername,' '),
      NVL(a.trmcode,' '),NVL(a.acctno,' '),
      NVL(a.outtrancode,' '),NVL(a.trmtrandtime,' '),
      NVL(a.tranamt,0.00),NVL(a.instfee,0.00),
      NVL(a.transtat,' '),NVL(a.trmseqnum,' '),
                    NVL(a.tranatt,' '),NVL(a.stlcurrcode,' '),
      NVL(b.MerRatio,0.00),NVL(b.MerRatio*a.tranamt,0.00),
      NVL(b.CardRatio,0.00)
             from   t_eb_journal a, t_eb_mer_fee_para b
      where  a.acctdate=:trandate
             and    a.mercode=b.mercode
      and    a.stlcurrcode=b.Stages
      and    a.transtat in ('0','1','3')
#ifdef A20080618
             and    inttxncode in ( '610201',/*金卡本代他消费*/
        '610207',/*金卡本代他完成*/
                    '620035',/*金卡本代他消费*/
        '620039',/*金卡本代他完成*/
        '810030',/*借记卡消费*/
        '810033',/*借记卡完成*/
        '210001',/*贷记卡消费*/
        '210005' /*贷记卡完成*/)
#endif
      order  by a.mercode,a.acctdate,a.trmcode;
   if(SQLCODE)
   {
        ErrSql(ERR_LVL,0);
 fclose(fp);
 return -1;
   }
   EXEC SQL OPEN cur301;
   if(SQLCODE)
   {
        ErrSql(ERR_LVL,0);
 fclose(fp);
 return -1;
   }
   while(1)
   {
 memset(&journal,0x00,sizeof(journal));
 EXEC SQL FETCH cur301 into
   :journal.MerCode,
   :journal.MerName,
   :journal.TrmCode,
   :journal.AcctNo,
   :journal.OutTranCode,
   :journal.TrmTranDTime,
                 :journal.TranAmt,
                 :journal.InstFee,
                 :journal.TranStat,
                 :journal.TrmSeqNum,
                 :journal.TranAtt,
                 :journal.StlCurrCode,
                 :journal.Reserve1,
                 :journal.Reserve2,
                 :journal.Reserve3;
        if(SQLCODE==1403)
        {
             print301tail(fp,num1,amt1,instfee1,totalamt1,numc1,amtc1);
      break;
        }
        if(SQLCODE&&SQLCODE!=1403)
        {
              ErrSql(ERR_LVL,0);
       EXEC SQL CLOSE cur301;
       fclose(fp);
       return -1;
        }
        if((num2+numc2)!=0&&strcmp(mercode,journal.MerCode)!=0)
        {
             print301tail(fp,num1,amt1,instfee1,totalamt1,numc1,amtc1);
             num1=0;
             amt1=0.00;
             instfee1=0;
             totalamt1=0.00;
             numc1=0;
             amtc1=0;
             print301head(fp,instno,trandate,((num1+numc1)/50)+1);  
        }
        if((num2+numc2)==0)
        {
             print301head(fp,instno,trandate,((num1+numc1)/50)+1);  
        }
        if(print301body(fp,&journal)!=0)
        {
       EXEC SQL CLOSE cur301;
       fclose(fp);
       return -1;
        }
        if(((num1+numc1)+1)%50==0)
        {
                fprintf(fp," ");
        }
        if(journal.TranStat[0]=='1')
        {
            amtc1+=journal.TranAmt;
            numc1++;
          
            /*
            amtc2+=amtc1;
            numc2+=numc1;
            */
            amtc2+=journal.TranAmt;
            numc2++;
        }
        else
        {
            num1++;
            num2++;
            amt1+=journal.TranAmt;
            instfee1+=journal.InstFee;
            /*
            totalamt1+=(journal.TranAmt+journal.InstFee);
            */
            totalamt1+=(journal.TranAmt-journal.InstFee);
            amt2+=journal.TranAmt;
            instfee2+=journal.InstFee;
            /*
            totalamt2+=(journal.TranAmt+journal.InstFee);
            */
            totalamt2+=(journal.TranAmt-journal.InstFee);
        }
       
        memset(mercode,0x00,sizeof(mercode));
        strcpy(mercode,journal.MerCode);
        memset(&journal,0x00,sizeof(journal));
         num++;
   }
        if(num==0)
        {
             print301head(fp,instno,trandate,((num1+numc1)/50)+1);  
             print301tail(fp,num1,amt1,instfee1,totalamt1,numc1,amtc1);
        }
  
   print301alltail(fp,num2,amt2,instfee2,totalamt2,numc2,amtc2);
   EXEC SQL CLOSE cur301;
   fclose(fp);


    return 0;
}
int print301head(FILE *fp,char *instno,char *trandate,int pageno)
{
    char        year[5];
    char        mon[3];
    char        day[3];


    memset(year,0x00,sizeof(year));
    memset(mon,0x00,sizeof(mon));
    memset(day,0x00,sizeof(day));


    memcpy(year,trandate,4);
    memcpy(mon,trandate+4,2);
    memcpy(day,trandate+6,2);
   
    fprintf(fp,"                                                    中国光大银行分期付款POS日交易流水\n\n");
    fprintf(fp,"报表编号: MER-301\n");
    fprintf(fp,"机构代码: %s          打印日期: %s年%s月%s日                             营业机构:总行信用卡中心     币种:01         第%04.04d页\n",
            instno,year,mon,day,pageno);
    fprintf(fp,"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");
    fprintf(fp,"序号 商户号   商户名称    流水号   交易时间  POS编号   信用卡卡号   商户折扣率  分期期数  分期手续费率  分期手续费  摘要   原交易日期  入帐标志  借贷标志 交易金额 商户折扣金额 清算金额 \n");
    fprintf(fp,"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");  
    return 0;
}
int print301body(FILE *fp,EB_JOURNAL *journal)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char MerName[31];
    char tranname[9];
    char transtat[9];
    EXEC SQL END DECLARE SECTION;


    memset(MerName,0x00,sizeof(MerName));
    memset(tranname,0x00,sizeof(tranname));
    memset(transtat,0x00,sizeof(transtat));


    strcpy(MerName,journal->MerName);
    rtrim(MerName);
    if(strlen(MerName)==0||(strlen(MerName)==1&&MerName[0]=='0'))
    {
        EXEC SQL select NVL(MerName,' ')
                 into   :MerName
                 from   T_EB_MER_INFO
                 where  MerCode=":journal-">MerCode;
        if(SQLCODE)
        {
              ErrSql(ERR_LVL,0);
              /*
              return -1;
              */
        }
    }
    switch(journal->TranAtt[0])
    {
    case  '0':
               strcpy(tranname," 消 费 ");
               break;
    case  '3':
               strcpy(tranname," 完 成 ");
               break;
    default:
               break;
              
    }
    switch(journal->TranStat[0])
    {
    case  '0':
    case  '2':
               strcpy(transtat,"成功");
               break;
    case  '1':
               strcpy(transtat,"撤消");
               break;
    case  '3':
               strcpy(transtat,"成功");
               break;
    default:
               strcpy(transtat,"其他");
               break;
              
    }


    fprintf(fp,"%15.15s %30.30s %8.8s %21.21s  %8.8s   %6.6s     %8.8s    %6.6s  %13.2f  %13.2f  %13.2f      %9.9s \n",
            journal->MerCode,MerName,journal->TrmCode,journal->AcctNo,
            tranname,journal->TrmSeqNum,journal->TrmTranDTime,
            journal->TrmTranDTime+8,journal->TranAmt,journal->InstFee,
            journal->TranAmt-journal->InstFee,transtat,
            journal->StlCurrCode,journal->Reserve1,
            journal->Reserve2,journal->Reserve3);      
    return 0;
}
int print301tail(FILE *fp,int num,double amt,double fee,double totalamt,int numc,double amtc)
{
    fprintf(fp,"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");  
    fprintf(fp,
           "小计: 消费笔数:%7d 消费交易金额:%17.2f 消费回扣金额:%17.2f  消费交易净额:%17.2f\n",
            num,amt,fee,totalamt);
    fprintf(fp,"      撤消笔数:%7d 撤消交易金额:%17.2f\n",
            numc,amtc);


    return 0;


}
int print301alltail(FILE *fp,int num,double amt,double fee,double totalamt,int numc,double amtc)
{
    fprintf(fp,"━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━\n");  
    fprintf(fp,
           "合计: 消费笔数:%7d 消费交易金额:%17.2f 消费回扣金额:%17.2f  消费交易净额:%17.2f\n",
            num,amt,fee,totalamt);
    fprintf(fp,"      撤消笔数:%7d 撤消交易金额:%17.2f\n",
            numc,amtc);
    fprintf(fp," ");
    return 0;
}


 


#define  SQLERRMSG   sqlca.sqlerrm.sqlerrmc
int ErrSql(int logflag,char *file,int line,int flag)
{
    char     msg[513];
    int      bufsize="512";
    int      len="0";
    WriteLog(logflag,file,line,"SQLCODE=[%d],SQLERRMSG[%s]",
                             SQLCODE,SQLERRMSG);
    memset(msg,0x00,sizeof(msg));
/*
    sqlglm(msg,&bufsize,&len);
    msg[len]=0x00;
    WriteLog(logflag,file,line,"MORESQLERRMSG[%s]",msg);
*/


    if(flag)
         EXEC SQL ROLLBACK; 



    return 0;
}


int GetAcctDate(char *acctdate,char *instno)
{
    EXEC SQL BEGIN DECLARE SECTION;
    char trandate[14+1];
    char InstNo[4+1];
    EXEC SQL END DECLARE SECTION;


    memset(trandate,0x00,sizeof(trandate));
    memset(InstNo,0x00,sizeof(InstNo));
    EXEC SQL select HostLastChkDTime,BranchNo
      into   :trandate,:InstNo
      from   T_PB_SYSSTAT;
    if(SQLCODE)
    {
  ErrSql(ERR_LVL,0);
  return -1;
    }
    memcpy(acctdate,trandate,8);
    memcpy(instno,InstNo,4);
    return 0;
}

PARTNER CONTENT

文章评论0条评论)

登录后参与讨论
EE直播间
更多
我要评论
0
3
关闭 站长推荐上一条 /3 下一条