傳 票 過 帳

wpeE.jpg (38369 bytes)


原始程式

原始檔-起始
/*---------( FSACP041.C )----過帳-----*/
#include    "W_FSAC.H"
#define SX  28            /*左內框                             */
#define SY  6             /*上內框                             */
#define SC  28            /*內框寬, 多少行                     */

void PassWork(FSACF011_T *p);
void SumAmt();                      /*依Mn月份,計算該月分傳票檔中的金額,筆數*/
void SetAmt();                      /*將WORK計算的金額,筆數拷貝至科目主檔中*/
void SetTx();
void ChkACF011(FSACF011_T *p);      /*檢查該分錄各項是否合理*/
/*================================================================*/
struct
{   char     KEY[8];
    double   AMT[2];       /*金額*/
    int      WNO[2];       /*筆數*/
} WORK;
FSACF001_T   ACF001;
FSACF011_T   ACF011;
int          A;      /*ACF001.AMT 相對的陣列*/
int          Mn;     /*月份                 */
char        *Table="\
                            \
         傳 票 過 帳        \
 ========================== \
   過帳起始月份: -----      \
   過帳結止月份: -----      \
                            \
  F7:確定要過帳,  Esc:放棄  \
                            ";
/*===========================================================================*/
void main()
{
    USetBXYN(Table,SX,SY,SC);
    UDrawBox(   SX-2, SY-1, SX+SC+1, SY+SR+1, V_WBOX, V_W_IN, YES, 3);
    UShowTable( SX,   SY,   SX+SC-1, SY+SR,   Table, V_W_IN);
    GET_NAME;
    do
    {   if(Field==1){ UReadM(BXN(1),&Sday,0,V_WUSR,V_READ); ChkYM(Sday,ON); }
        if(Field==2){ UReadM(BXN(2),&Eday,0,V_WUSR,V_READ); ChkYM(Eday,ON); }
        switch(RetKey)
        {   case LEFT : case UP  : if(--Field<1) Field=4;        break;
            case RIGHT: case DOWN: if(++Field>4) Field=1;        break;
            case ESC   : exit(0);
        }
    }while(RetKey!=F7);
    Sa=ChkYM(Sday,ON);   Sm=Sday.Y*12+Sday.M;      /*Sa=1..24, Sm=年*12+月*/
    Ea=ChkYM(Eday,ON);   Em=Eday.Y*12+Eday.M;
    if( Sa==0 || Ea==0) exit(0);                   /*非系統年度*/

    OPEN_ACF001; OPEN_ACF011;
    UTime(0,OFF);
    SetTx();                        /*設Tx,及檢查結轉是否平衡*/
    UShowSL(SX-6,SY+10,40,"      傳票過帳中, 請稍候:",V_W_IN);
    for(A=Sa,Mn=Sm; A<=Ea; A++,Mn++)
    {   UShowM(SX+22,SY+10,5,Sday,V_ITEM_ON);  if(++Sday.M>12){ Sday.Y++; Sday.M=1; }
        OPEN_WORK;
        SumAmt();                /*依Mn月份,計算該月分傳票檔中的金額,筆數*/
        SetAmt();                /*將WORK計算的金額,筆數拷貝至科目主檔中*/
        Ufk_NotFlush(WORKK);
        Ufk_Close(WORKK);
    }
    UShowSL(SX-6,SY+10,40,"    <<  傳票過帳完畢, 請任按一鍵  >> ",V_WARNING);
    UTime(1,ON);
}
/*===========================================================================*/
void PassWork(FSACF011_T *p)        /*在WORK中累加,金額,筆數*/
{
    memset(&WORK,NULL,sizeof(WORK));     /*先清為空白*/
    strcpy(WORK.KEY,p->AC);              /*依分錄科目號搜尋*/
    Ufk_Read(WORKK,&WORK,NULL);          /*讀取相對應科目,有則累加,無則空*/
    if(p->DC=='D'){ WORK.AMT[0]+=p->AMT; WORK.WNO[0]++; }   /*餘額累加,筆數累加*/
    else          { WORK.AMT[1]+=p->AMT; WORK.WNO[1]++; }
    Ufk_Write(WORKK,&WORK);
    Utx_Search(Tx,p->AC);
    if(Tx->FIND==OFF)
    {   UWait(ON,"傳票編號:%S---- , 主檔無 %S----- 科目",p->KEY,p->AC);
        if(RetKey==ESC) exit(0);
    }
}
/*===========================================================================*/
void SumAmt()               /*依Mn月份,計算該月分傳票檔中的金額,筆數*/
{
    READ1(ACF011)
    {   if((p->YM.Y*12 + p->YM.M) != Mn) continue;   /*一個月一個月處理*/
        ChkACF011(p);                       /*檢查該分錄各項是否合理*/
        PassWork(p);
        if(p->AC[4]<=SPACE) continue;       /*若為總帳科目則continue*/
        memset(&p->AC[4],SPACE,3);          /*明細改為總帳,再加總一次*/
        PassWork(p);
    }
    READ2
}
/*===========================================================================*/
void SetAmt()               /*將WORK計算的金額,筆數拷貝至科目主檔中*/
{   FSACF001_T  *p,*pp;
    long         t,n,r,j,now=0L,s;

    s=sizeof(ACF001);                              /*s=資料結構size*/
    t=filelength(ACF001K->ffd)/s;                  /*t=檔案共幾筆s*/
    n=65530L/s;                                    /*n=64k可切成幾塊s*/
    if((pp=malloc(n*s))==NULL) UFatal("Memory");   /*pp=最大64k的buffer*/
    lseek(ACF001K->ffd,0L,SEEK_SET);               /*檔頭*/
    for(; t>0; t-=r)
    {   if(t>=n) r=n; else r=t;                /*r=本次處理筆數,不會超過64k*/
        read(ACF001K->ffd,pp,s*r);             /*將資料讀進buffer*/
        for(p=pp,j=0; j<r; j++,p++)
        {   if(p->KEY[0]<=SPACE) continue;     /*已刪除*/
            if(p->KEY[0]=='Z') continue;       /*虛科目*/
            if(Ufk_Read(WORKK,&WORK,p->KEY)==OFF) memset(&WORK,NULL,sizeof(WORK));        /*p->KEY於該月Mn無交易*/
            p->AMT[0][A]=WORK.AMT[0];   p->DC_NO[0][A]=WORK.WNO[0];    /*以WORK中的資料取代原本資料*/
            p->AMT[1][A]=WORK.AMT[1];   p->DC_NO[1][A]=WORK.WNO[1];
        }
        lseek(ACF001K->ffd,now,SEEK_SET);
        write(ACF001K->ffd,pp,s*r);            /*整block寫入*/
        now += s*r;
    }
    free(pp);
}
/*===========================================================================*/
void SetTx()             /*設Tx,及檢查(總科目結轉)是否平衡*/
{  double Dsum=0,Csum=0;
   Tx=Utx_Open(47,3,80,24,filelength(ACF001K->ffd)/sizeof(ACF001),8,ON);
   READ1(ACF001)
   {  if(p->KEY[0]=='Z') continue;
      if(p->KEY[4]<=SPACE)
      {  Dsum += p->AMT[0][0];            /*總科目'結轉'金額加總*/
         Csum += p->AMT[1][0];
      }
      Utx_Ins(Tx,"%S----- %S------------------",p->KEY,p->ACN);
   }
   READ2
   if(Dsum != Csum)
   {   UShowS(SX-2,SY+12," *** 上 期 結 轉 不 平 衡 ***   ",V_WARNING);  beep();
       UShowS(SX-2,SY+13,"上期結轉借方金額: ",V_W_IN); UShowD(SX+16,SY+13,14,Dsum,",0",V_W_IN);
       UShowS(SX-2,SY+14,"        貸方金額: ",V_W_IN); UShowD(SX+16,SY+14,14,Csum,",0",V_W_IN);
       UShowS(SX-2,SY+15,"────────────────",V_W_IN);
       UShowS(SX-2,SY+16,"            差額: ",V_W_IN); UShowD(SX+16,SY+16,14,Dsum-Csum,",0",V_W_IN);
   }
}
/*===========================================================================*/
int   Ufk_SetBuf(FKIP *Fk)  /*設定大buffer*/
{   long   bno;

    if(Fk->handle != 7632) UFatal("No Open Fk (setbuf)");
    if(Fk->hasbuf) return Fk->max_row;
    bno=65520L/Fk->frl;
    Fk->ptr = (void **)malloc(sizeof(void *) * bno);
    if(Fk->ptr==NULL) return 0;
    Fk->max_row=bno;
    Fk->mem_row=0;
    Fk->hasbuf=1;      /*1:要flush,2:不flush*/
    return Fk->max_row;
}
/*===========================================================================*/
void ChkACF011(FSACF011_T *p)       /*檢查該分錄各項是否合理*/
{
   if(p->KI!='3' && p->KEY[6]!=1 && memcmp(p->AC,"1101   ",6)==0) /*非轉帳,是現金,1或2非轉帳不可有現金科目*/
   {  UWait(ON,"<%S----> 現金收支傳票不該有現金科目吧!,記得回去訂正",p->KEY);
      if(RetKey==ESC) exit(0);
   }
}
原始檔-結束

Byron Wey  Oct.21.1998


回首頁C之城