?? fee_rec.c
字號:
#include <string.h>
#include <stdlib.h>
#include <mem.h>
#include <alloc.h>
#include <graphics.h>
#include <bio.inc>
#include <menu.inc>
#include "feedef.h"
void InnerToExt(void);
/* function : calculate InterNational call charge
* called by : all_record_transfer(),imm_record_transfer()
* input : len -- the number length of callee (including the ending fd)
* in_fp -- file pointer to Intern.tmp
* output : write charge to Intern.tmp
* date : 1993.9.28
*/
void Intern_charge(void)
{
UC flag;
UL second, secc;
RATE_STRUCT huge *rate_tmp;
rate_tmp = get_rate(&temp_list.callee[2],IDD); /* get charge rate */
if(rate_tmp == NULL) /* the area No. does not exist */
{
rate.first_rate = 0;
rate.first_time = 60;
rate.formal_rate = 0;
rate.formal_time = 60;
rate.add_fee = 0;
}
else
rate = *rate_tmp;
if(rate.formal_time == 0)
rate.formal_time = 60;
flag = normal_charge_hour(); /* calculate calling time */
if(flag == TRUE)
{
second = (UL)hour*60*60+min*60+sec;
if(second >= 43200L) /* calling time is longer than 12 hours */
second = 180;
}
else /* calling time is too long */
second = 180;
temp_list.time = second; /* calling time */
second += Intern_add.add_time;
temp_list.charge = rate.first_rate; /* calling charge*/
if(second > rate.first_time)
{
secc = (second-rate.first_time)/rate.formal_time;
if( (second-rate.first_time-secc*rate.formal_time) > 0)
secc++;
temp_list.charge += secc*rate.formal_rate;
}
if( ( strcmp("852", rate.area_no) == 0 ) || \
( strcmp("853", rate.area_no) == 0 ) )
{
temp_list.add = (UL) (temp_list.charge*Honkon_add.add_percent/100 \
+Honkon_add.add_rate*((second-1)/rate.formal_time + 1)\
+Honkon_add.add_record + rate.add_fee);
}
else
{
temp_list.add = (UL) (temp_list.charge*Intern_add.add_percent/100 \
+Intern_add.add_rate*((second-1)/rate.formal_time + 1)\
+Intern_add.add_record + rate.add_fee);
}
// temp_list.add = ((temp_list.add+9)/10)*10;
temp_list.charge += temp_list.add;
// temp_list.charge = ((temp_list.charge+9)/10)*10;
temp_list.flag = TRUE;
return;
}
/* function : calculate National call charge
* called by : all_record_transfer(),imm_record_transfer()
* input : len -- the number length of callee (including the ending fd)
* na_fp -- file pointer to Nation.tmp
* output : write charge to Nation.tmp
* date : 1993.9.28
*/
void Nation_charge(void)
{
UC flag;
UL second,sec0,semi_sec0,secc;
RATE_STRUCT huge *rate_tmp;
rate_tmp = get_rate(&temp_list.callee[1],DDD); /* get charge rate */
if(rate_tmp == NULL) /* the area No. does not exist */
{
rate.first_rate = 0;
rate.first_time = 60;
rate.formal_rate = 0;
rate.formal_time = 60;
}
else
rate = *rate_tmp;
strcpy(Distr_name, rate.area_name);
if(rate.formal_time == 0)
rate.formal_time = 60;
flag = nation_charge_hour(); /* calculate calling time */
if(flag == TRUE)
{
sec0 = (UL)hour*60*60+min*60+sec;
semi_sec0 = (UL)semi_hour*60*60+semi_min*60+semi_sec;
second = sec0+semi_sec0;
if(second >= 43200L) /* calling time is longer than 12 hours */
{
second = 180;
sec0 = 180;
semi_sec0 = 0;
}
}
else /* calling time is too long */
{
second = 180;
sec0 = 180;
semi_sec0 = 0;
}
temp_list.time = second;
second += Nation_add.add_time;
sec0 += Nation_add.add_time;
temp_list.charge = rate.first_rate;
if(second > rate.first_time)
{
secc = (second-rate.first_time)/rate.formal_time;
if((second-rate.first_time-secc*rate.formal_time) > 0)
secc++;
temp_list.charge += secc*rate.formal_rate;
}
if(second < 1)
second = 1; /* for if second=0 &&&*/
temp_list.charge = temp_list.charge/2.0*((double)semi_sec0/second) \
+temp_list.charge*((double)sec0/second);
temp_list.add = (UL)(temp_list.charge*Nation_add.add_percent/100 \
+Nation_add.add_rate*((second-1)/rate.formal_time + 1)\
+Nation_add.add_record + rate.add_fee);
// temp_list.add = ((temp_list.add+9)/10)*10;
temp_list.charge += temp_list.add;
// temp_list.charge = ((temp_list.charge+9)/10)*10;
temp_list.flag = TRUE;
return;
}
/* function : calculate Local call charge
* called by : all_record_transfer(),imm_record_transfer()
* input : len -- the number length of callee (including the ending fd)
* lo_fp -- file pointer to loacl.tmp
* output : write charge to Local.tmp
* date : 1993.9.28
*/
void Local_charge(void)
{
UC flag;
UL second,secc;
RATE_STRUCT huge *rate_tmp;
rate_tmp = get_rate(temp_list.callee,LDD); /* get charge rate */
if(rate_tmp == NULL) /* the area No. does not exist */
{
rate.first_rate = 0;
rate.first_time = 60;
rate.formal_rate = 0;
rate.formal_time = 60;
}
else
rate = *rate_tmp;
if(rate.formal_time == 0)
rate.formal_time = 60;
flag = normal_charge_hour(); /* calculate calling time */
if(flag == TRUE)
{
second = (UL)hour*60*60+min*60+sec;
if(second >= 43200L) /* calling time is longer than 12 hours */
second = 180;
}
else /* calling time is too long */
second = 180;
temp_list.time = second; /* calling time */
second += Local_add.add_time;
temp_list.charge = rate.first_rate;
if(second > rate.first_time)
{
secc = (second-rate.first_time)/rate.formal_time;
if((second-rate.first_time-secc*rate.formal_time) > 0)
secc++;
temp_list.charge += secc*rate.formal_rate;
}
if(temp_list.charge == 0)
temp_list.add = 0;
else
temp_list.add = (UL)(temp_list.charge*Local_add.add_percent/100 \
+Local_add.add_rate*((second-1)/rate.formal_time + 1)\
+Local_add.add_record + rate.add_fee);
// temp_list.add = ((temp_list.add+9)/10)*10;
temp_list.charge += temp_list.add;
// temp_list.charge = ((temp_list.charge+9)/10)*10;
temp_list.flag = TRUE;
return;
}
/* function : transfer telephone records to Intern.tmp, Nation.tmp and
* Local.tmp respectively, from pabx.dat
* called by : take_all()
* date : 1993.9.28
*/
void all_record_transfer(void)
{
int i, k;
UC caller[6], mark, flag, w_flag = 0;
FILE *in_fp, *na_fp, *lo_fp, *pabx_fp;
UC port;
UC mode;
UC user[10];
PHONE_STRUCT *phone;
UI SpecLen[2];
flag = load_rate_tab();
if(flag != TRUE) /* *.rat does not exist */
{
message(RATE_FILE_ERR);
return;
}
for(mode =0; mode<2; mode++)
if(Cashflg[mode])
{
flag = load_cash_tbl(mode);
if(flag != 1) /* cash data does not exist */
Cashflg[mode] = 0;
else
Cash_len[mode] = cash_tbl_len(mode);
}
load_special_tbl(0); /* local call definition table */
load_special_tbl(1); /* information call definition table */
SpecLen[0] = special_tbl_len(0); /* local */
SpecLen[1] = special_tbl_len(1); /* information */
load_phone_tbl();
Newlen = phone_tbl_len();
in_fp = fopen("idd.tmp","ab");
na_fp = fopen("ddd.tmp","ab");
lo_fp = fopen("ldd.tmp","ab");
pabx_fp = fopen("pabx.chg","rb");
if(pabx_fp != NULL ) /* the file exists */
{
while(fread(caller,sizeof(UC),1,pabx_fp) == 1)
{
w_flag = 0; /* Reset the error flag */
port = caller[0];
fread(caller,sizeof(UC),1,pabx_fp);
temp_list.year2 = ((caller[0] & 0xF0)>>4)*10+(caller[0] & 0x0F);
temp_list.year2 += 1900;
fread(caller,sizeof(UC),1,pabx_fp);
temp_list.mon2 = cbcd_uc(caller);
fread(caller,sizeof(UC),1,pabx_fp);
temp_list.day2 = cbcd_uc(caller);
temp_list.year1 = temp_list.year2;
temp_list.mon1 = temp_list.mon2;
temp_list.day1 = temp_list.day2;
fread(caller, sizeof(UC), 1, pabx_fp);
temp_list.caller2 = ((caller[0] & 0xF0)>>4)*10+(caller[0] & 0x0F)+PhonesPerPort*port;
InnerToExt();
temp_list.caller1 = temp_list.caller2;
fread(caller,sizeof(UC), 3, pabx_fp);
cbcd_hex(&temp_list.auth_code, caller, 6);
if(caller[0] != 0x0a )
cbcd_hex(&temp_list.auth_code, caller, 6);
else if(caller[0] == 0x0a )
temp_list.auth_code = 0xaaaaaa;
fread(caller,sizeof(UC),1,pabx_fp);
temp_list.hour1 = cbcd_uc(caller);
fread(caller,sizeof(UC),1,pabx_fp);
temp_list.min1 = cbcd_uc(caller);
fread(caller,sizeof(UC),1,pabx_fp);
temp_list.sec1 = cbcd_uc(caller);
fread(caller,sizeof(UC),1,pabx_fp);
temp_list.hour2 = cbcd_uc(caller);
fread(caller,sizeof(UC),1,pabx_fp);
temp_list.min2 = cbcd_uc(caller);
fread(caller,sizeof(UC),1,pabx_fp);
temp_list.sec2 = cbcd_uc(caller);
/* in caller number, if it is National long call, then the
* first 0 is saved as A, if it is an InterNation long call,
* then save the first two 0 as AA. The 0s in the tail are
* saved as 0s
*/
for(i=0, k=0; i<7; i++) /* callee number */
{
fread(caller,1,1,pabx_fp);
if( i == 0 && (caller[0] & 0xf0) == 0)
{
w_flag = 1; /* Set the error flag */
continue;
}
if((caller[0] & 0xf0) == 0) /* 0 in the tail */
break;
else
{
temp_list.callee[k] = (caller[0] & 0xf0)>>4;
if( temp_list.callee[k] > 0x0a)
{
w_flag = 1; /* Set the error flag */
continue;
}
if(temp_list.callee[k] == 0x0a) /* 0 in the head */
temp_list.callee[k] = 0;
k++;
if((caller[0] & 0x0f) == 0)
break;
else /* if((caller[0] & 0x0f) != 0) */
{
temp_list.callee[k] = caller[0] & 0x0f;
if( temp_list.callee[k] > 0x0a)
{
w_flag = 1; /* Set the error flag */
continue;
}
if(temp_list.callee[k] == 0x0a)
temp_list.callee[k] = 0;
k++;
if(k >= 14) /* 14 bytes are enough for callee number */
break;
} /* end of "if((caller[0] & 0x0f) != 0)" */
} /* end of "else if((caller[0] & 0xf0) != 0)" */
} /* end of "for(i=0,k=0;i<8;i++)" */
if(w_flag == 1)
{
for(;;)
{
fread(caller,sizeof(UC),1,pabx_fp);
if(caller[0] == 0xfd) /* end of a phone record */
break;
}
continue;
}
if(k > 14)
k = 14;
for(;k<16;k++)
temp_list.callee[k] = 0xfd;
if(temp_list.callee[0] == 0)
{
if(temp_list.callee[1] == 0)
mark = IDD; /* InterNational */
else
mark = DDD; /* National */
}
else
mark = LDD; /* Local */
for(; ;)
{
fread(caller,sizeof(UC),1,pabx_fp);
if(caller[0] == 0xfd) /* end of a phone record */
break;
}
if(delay_proc(mark) == FALSE)
continue;
// if((temp_list.caller1==0) && (temp_list.caller2==0))
// continue;
just_date();
/* compute week day of day1 and day2 */
week1 = weekday(temp_list.year1,temp_list.mon1,temp_list.day1);
week2 = weekday(temp_list.year2,temp_list.mon2,temp_list.day2);
if(mark==IDD)
{
Intern_charge();
fwrite(&temp_list,sizeof(RECORD_STRUCT),1,in_fp);
/* handle cash in pledge */
if(temp_list.auth_code != 0xaaaaaa) /* auth*/
update_cash(AUTH_CASH);
else
{
ltoa(temp_list.caller2, user, 10); /* int to ASCII string */
phone = binary_search(user); /* locate the phone No */
if( (phone != NULL) && phone->feeflag[4]) /* IDD fee */
update_cash(PHONE_CASH);
}
}
else if(mark==DDD)
{
Nation_charge();
fwrite(&temp_list,sizeof(RECORD_STRUCT),1,na_fp);
/* handle cash in pledge */
if(temp_list.auth_code != 0xaaaaaa) /* auth*/
update_cash(AUTH_CASH);
else
{
ltoa(temp_list.caller2, user, 10); /* int to ASCII string */
phone = binary_search(user); /* locate the phone No */
if( (phone != NULL) && phone->feeflag[3]) /* DDD fee */
update_cash(PHONE_CASH);
}
}
else if(mark==LDD)
{
Local_charge();
fwrite(&temp_list,sizeof(RECORD_STRUCT),1,lo_fp);
/* handle cash in pledge */
if(Usr_typ == NORMAL_USR || Ldd_fflg == YES)
if(temp_list.auth_code != 0xaaaaaa) /* auth*/
update_cash(AUTH_CASH);
else
{
ltoa(temp_list.caller2, user, 10); /* int to ASCII string */
phone = binary_search(user); /* locate the phone No */
if( phone != NULL)
{
UC f1, f2;
f1 = IsSpecialCall(temp_list.callee,SpecLen[0],0);
f2 = IsSpecialCall(temp_list.callee,SpecLen[1],1);
if( (phone->feeflag[1] && f1)
||(phone->feeflag[2] && f2)
||(phone->feeflag[0] && !(f1 && f2) ))
update_cash(PHONE_CASH);
}
}
}
} /* end of "while(!feof(pabx_fp))" */
fclose(pabx_fp);
} /* end of "if(pabx_fp != NULL )" */
fclose(in_fp);
fclose(na_fp);
fclose(lo_fp);
unload_special_tbl(0);
unload_special_tbl(1);
for(mode=0; mode<2; mode++)
if(Cashflg[mode])
{
save_cash_tbl(mode);
unload_cash_tbl(mode);
}
unload_rate_tab();
unload_phone_tbl();
return;
}
/* function : transfer telephone records to Intern.tmp, Nation.tmp and
* Local.tmp respectively, for immediate method
* called by : take_immediate_record()
* date : 1993.9.28
*/
UC imm_record_transfer(UC port)
{
int i, k, mark;
UC flag, phone_no[10];
char auth_name[9];
char *a_name=" ";
RATE_STRUCT huge *rate_tmp;
PHONE_STRUCT *phone;
UC user[10];
UI SpecLen[2];
UC f1, f2;
UC tmp[20], err;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -