/* 
**
** file name: smfunc.h
**
**
*/

#ifndef SMFUNC__H
#define SMFUNC__H

#include "cdrme.h"
#include "ramdata.h"

/* deal with balance to a nature voice prompt */
void	ProcAmountVoice(char *sp);   
int		MergeVoiceStream(BYTE *dest, int balance, int expire, int code_id, int oper_result);
u_char	GetAccountZoneID(int head, int tail);
int		IsSpanCall(void *shmp);
int		GetServiceCode(void *shmp, char *sptr);
int		GetServiceAction(void *shmp, int code_id);
int		GetAccountPos(void *ptr);
float	GetBalance(_account_info *ptr);
long	GetExpiration(_account_info *ptr);
int		GetOverdraft(_account_info *ptr);
int		GetCMBTimes(_account_info *ptr);
int		UpdateCMBTimes(_account_info *ptr,int times);
int		resetCMBTimes(_account_info *ptr);

void	 UpdateBalance(_state_data 	*stateProc,_account_info *ptr, float charge,CHARGED_FEE *chargeFee);
void	UpdateExpiration(void *ptr);
void	UpdateExpirationFirstCharge(void *ptr);
void	UpdateExpirationFirstInquiry(void *ptr, long valid_time);
int		IsNormalAccount(void *ptr);
int		GetAccountStatus(void *ptr);
int		GetDiscount(int timestamp,u_char discount_id);
 float BillingFormula(_state_data *shmp,_bill_tariff *ptar,int startTime);
float 	TimeToCharge(_state_data *shmp,_bill_tariff *ptar, int duration,int begin_time, int init_bill);
int 	preLeftTime(_state_data 	*shmp,float	balance,_bill_tariff *ptar);
int		GetValidTime(int begin_time, void *ptar, float balance, int init_bill, int overdraft);
float 	caculateMiniCharge(_state_data 	*shmp,_bill_tariff *ptar);
void	EncryptCardHRN(char *card_hrn,u_char *card_pwd);
int		BillingProc(void *shmp, int);
void	SetCallType(void *shmp, int);
float 	ChargeGprsAccountBalance(_state_data	*shmp,int real_duration);
int		IsNormalRechargeCard(void *ptr);
u_short	GetRechargeCardFaceValue(void *ptr);
u_short	GetRechargeCardValidTime(void *ptr);

u_char	GetTariffLacInfo(u_char *cgi);
void	SetLocationInfo(u_char *cgi,u_short portid); 
u_long	GetTimeFunnel(u_short, u_short, u_short);
int		IsEnablePeriodicCharge(int head, int tail);
int		IsEnablePeriodicAction(int head, int tail);

float	GetAccountBalance(int head, int tail);
int		GetUserType(int head, int tail);
int		GetPeriodicTariffFee(int tariff_id,int id);
short	GetPeriodicTariffDate(int tariff_id,int id);
short	GetPeriodicTariffType(int tariff_id,int id);
short	GetPeriodicTariffPeriod(int tariff_id,int id);
void	UpdateAccountBalance(int head, int tail, float charge);
u_long	GetAccountFirstUsedDate(int head, int tail);
int		GetAccountMsisdn(int head, int tail,u_char *msisdn);
short	IsPeriodicChargeDate(int id, int first_used_date);
int		UpdateTariffTable(int zone_id);
void	UpdateOtherTable(void);
void	UpdateAccountFirstUsedDate(int, int);
void	UpdateAccountStatus(int, int, int);
void	UpdateAccountRechargeFail(int, int);
int		GetParamRechargeAttemptLimit();
u_short	GetAccountRechargeFail(int, int);
void	ResetAccountRechargeFail(int, int);
int		IsEnableToCall(int proc_id);
u_short	TStringToID(char *time_buf);
u_short	TStampToID(time_t);
int		CDRStatistics(_tocdr_report *pbuf, float charge, ulong gprsVolume);
int		GprsCDRStatistics(_tocdr_report* pbuf,float f_charge,ulong 	gprsVolume);
int		MsisdnToLong(u_long *ulmsisdn, char *cmsisdn);
void	cstaInstanceCheck();
int		CheckWetherLocalNumber(char *number);
int		GetPeriodicChargeDate(int tariff_id,int id);
int		GetUserInstance(long long head, int *instance);
int		GetUserPos(int *head,long long head1);
int		ConferenceCallBillingProc(void *ptr, int duration);
void	SetRoamingFlag(void *shmp);
int		GetAccountCUG(_account_info *ptr);
int		CheckWetherFamilyNumber(_account_info *caller, _account_info *called);
int		GetAccountFamilyNumberCounter(_account_info *ptr);
int		StoreAccountFamilyNumber(_account_info *ptr,char *msisdn,int index);
int		BillingFamilyNumberChange(_state_data *shmp);
int		IncreaseFamilyNumberChangeCounter(int head, int tail);
int		GetServiceType(_state_data *shmp);
int		GetServiceType_0(_state_data *shmp);
int		GetAccountCosID(_account_info *ptr);
int		SaveDailyReport();
int		GetRechargeCardByIndex(int index,char *card_no);
void	SendManualRechargeCDR(_recharge_card_info *shmp);
int		GetAccountLastCallInfo(_account_info *ptr, _last_call_info *pInfo);
int		GetSubsCapTariffID(_state_data *shmp, int call_type);
void	UpdateSubsCapInfo(_account_info *ptr, int cap_type,float charge, int amount, _state_data *shmp);
void	GetSubsCapInfo(_account_info *ptr,int cap_type, float *balance, int *counter, int type);	
BOOL isPromotionCanBeUsedAtThisPoint(_state_data 	*shmp);
BOOL isPromotionCanBeUsedForRoDebit(_account_info 	*shmp);
double 	GetBalanceWithPromotionControl(_state_data	*stateProc,_account_info *ptr);
int GetAccountBundlePlanInfo(_account_info *ptr, long ret_value[]);
int	UpdateAccountBundlePlanInfo(_account_info *shmp, long set_value[]);
int	subscribe_bundle_plan_send_used_up_info(char *caller_number, SMS_SENTENCE id);

int	GetAccountVoiceID(int head,int tail);

int  cliManipulationFunction(char *caller, char *called);

void playPromptAndCollectVoice(u_short portid,u_short voiceID,u8 inputLen);
void playPromptVoice(u_short portid,u_short voiceID);
int	CallingCardWaitingForSpecialResourceReport(_state_data *shmp);
int CallingCardSendReleaseCall(u_short portid);
int isTransferAllowed(u_short portid);
int isRechargeAllowed(u_short portid);
int transferIddBillingPrefix(char *number);
int poolTransferAccount(_account_info *callerInfo,_account_info *destInfo,float transferedFee);
extern 	void resetPoolSlaveDaily(u_short head,u_short tail);

extern	void increPoolChildCharged(_account_info *ptr,double charged);
extern	void increPoolChildSMS(_account_info *ptr);
extern	void increPoolChildCalls(_account_info *ptr);
extern	BOOL isPromotionCanBeUsedAtThisPoint(_state_data 	*shmp);
extern	float BillingFormula(_state_data *shmp,_bill_tariff *ptar,int startTime);
extern	float TimeToCharge(_state_data *shmp,_bill_tariff *ptar, int duration,int begin_time, int init_bill);
extern	double GetBalanceWithPromotionControl(_state_data 	*stateProc,_account_info *ptr);
extern	float caculateMiniCharge(_state_data 	*shmp,_bill_tariff *ptar);
extern	int preLeftTime(_state_data 	*shmp,float	balance,_bill_tariff *ptar);
extern	void PPSSendUserSMSNotification(int head, int tail,char *msgSend);
extern	u_char getCurrentTier(_state_data 	*shmp,_bill_tariff *ptar);
extern	void ChangeTariffToPoolCallTariff(_state_data *shmp,_bill_tariff 	*ptar);
extern	float getCurrentFee(_state_data 	*shmp);
extern	int isPoolChildReachSMSLimit(_state_data *shmp);
extern  int isPoolChildReachFeeLimit(_account_info *ptr);
extern	int decMasterChildren(_prepaid_info *prepaidInfo);
extern	int IncreasePoolAccountChangeCounter(int head, int tail);
extern 	int increMasterChangeCounter(_prepaid_info *prepaidInfo);
extern 	int getHowManyChildren(_prepaid_info *prepaidInfo);
extern	int BillingChildNumberChange(_state_data *shmp);
extern	int increMasterChildren(_prepaid_info *prepaidInfo);

extern	int getPoolAccountRole(u_short portid);
extern	int CheckWetherPoolNumber(_account_info *caller, _account_info *called);
extern	int isPoolChildReachCallLimit(_state_data *shmp);
extern	void clearTransferInfo(u_short portid);
extern	void clearMasterSlaveInfo(u_short portid);
extern	int isRechargeAllowed(u_short portid);
extern	int chargeOrTransfer(u_short portid);
extern	int getInputtedChoice(_state_data *shmp);
extern	int transferAccountIVRProc(u_short portid);
extern	int masterSlaveIVRProc(u_short portid);
extern	void clearCMBInfo(u_short portid);
extern	int callMebackUSSDProc(u_short portid);
extern	int transferAccountIVRProc(u_short portid);
extern	int smppSendMOSM(char *caller, char *called, u_char *msg,int msgLen,u_char dataCoding);
extern	void SendAccountRealSync_2(_account_info   *accountInfo,double balance,double promotion ,int ocode);
extern	void SendAccountRealSync(DWORD instance,double balance,double promotion, int ocode);
extern	void PPSSendUserSMSNotification(int head, int tail,char *msgSend);
extern	int WaitingForInput(_state_data *shmp,u8 *inputMsg);
extern 	float GetPromotion(_account_info *ptr);
extern 	int GetBalanceWithOutPromotion(int head, int tail);
extern 	u_char *getSmsSentenceNative(SMS_SENTENCE	id,u8 languageType);
extern	int fillMoneyToContent(float balance,char *sms);
extern     float GetAccountBalance(int head, int tail);
extern 	int GetLocalCosID(_account_info *ptr);
extern 	void pps_print_error(u_char logMsisdnFlag,const char *fmt, ...);
extern 	void pps_print_event(u_char logMsisdnFlag,const char *fmt, ...);
extern 	void saveCommand();
extern int GetMOTariffIDWithFreeServiceControl(u_short head,u_short tail);
extern void SendTransferCDR(_account_info *caller_info,_account_info *called_info,float charge);
extern void SendDirectDebitAndRefundCDR(_account_info *caller_info, float charge);
extern void SendSmsDirectDebitAndRefundCDR(_state_data *shmp, int sent_num, int bIsRefund);
extern int SendServiceNotApplied(u_short portid,u8 ussdSmsFlag,u8 serviceNumberPosition);
extern u_long PPS_SET_INTEGER(u_char *pdata, u_char dataLen);
extern float pps_billing_ro_voice(_state_data *shmp, u32 *need_assigned_duration, u32 *new_assigned_bundle);
extern float pps_billing_ro_voice_with_crm(_state_data *shmp, u32 *need_assigned_duration, u32 *new_assigned_bundle);
extern float pps_refund_ro_voice_with_crm(_state_data *shmp, u32 refund_duration, u32 *refund_bundle);
extern float pps_refund_ro_voice(_state_data *shmp, u32 refund_duration, u32 *refund_bundle);
extern int pps_get_ro_voice_quota(_state_data *shmp);
extern int pps_get_account_bundle_mo_voice(_state_data * shmp);
extern int pps_get_account_bundle_mt_voice(_state_data * shmp);
extern int pps_get_account_bundle_mo_sms(_state_data * shmp);
extern void UpdateExpirationForRechargeCard(_account_info *ptr, u_short valid_time, u_short faceValue);
extern int GetCardSystemParamByNearestValue(u_char cos_id, u_short faceValue);
extern void SendSelfcareRechargeCDR(_account_info *user_info, char *pwd, int type, int charge);
extern void SendSelfcareBundleSubCDR(_account_info *user_info, int charge, u32 data_volume, u32 voice_sec);
extern void SendSelfcareTransferCDR(_account_info *caller_info,_account_info *called_info, float charge);
extern int get_transfer_status_normal_flag();
extern int get_not_change_transfer_expiry_date();
extern void UpdateAccountOverdraft(int head, int tail, long overdraft);
extern void ppsgetdaytime_readFormat(char *daytime_buf);
extern int GetAccountPromptInfo();
extern int StoreCDR(_tocdr_report *pcdr);
extern int pps_send_map_close();
extern int pps_debug_map_msg();
extern int smppDecodeSM(char *strIn, char *strOut,int length);
extern int SendUSSDNotify(u_short portid, char *ussd_info);
extern int PutLogFunID(char  *func_name);
extern const char * AsciiTime(char *ptr, time_t time);
extern int fillMoneyAndDate(long balance, char *expire_date, int calltype0, u_char flag, u_char *smMsgBuf);
extern int pps_get_adaptor_flag();
extern int smppSendActivicationInfo(_account_info *caller_info, char *called);
extern int MsisdnToAscii(char *ascii_in, BYTE  *cmsisdn);
extern char* ppsParseSentence(char *sentence,int varNum, char *varStr[]);
extern char *sendPPSNotificationMessage(int head, int tail, int sms_id);
extern void SendPPSGeneralCDR(int head, int tail, int charge, char cdr_type);
extern const char * AsciiTimeYMD(char *ptr, time_t time);
extern int isAccountExpired(_account_info *ptr);
extern int GetCosIDByAccount(_account_info *ptr);
extern void notifyUserTransferResult_1(_account_info *srcUsr, _account_info *dstUsr, int amount, u8 callerOrCalled);
extern int GetCardSystemParam(u_char cos_id,u_short faceValue);
extern int IsPromotionTime(COSTable *cosTableItem, struct timeval tvn);
extern int GetPromotionAmount(COSTable *cosTableItem, int charge);
extern void UpdateAccountPromotionBalance(int head, int tail, float charge);
extern void UpdateAccountPromotionExpiryDay(int head, int tail, int days);
extern int GetPromotionDay(COSTable *cosTableItem, int charge);
extern int subscribe_bundle_plan(_state_data *shmp, char *sms, int method, char *ret_prompt);
extern int getUssdACK(u_short portid,u_char *ussd_data);
extern int ocs_bundle_plan_query(_state_data *shmp, char *sms, int method, char *ret_prompt);
extern int subscribe_bundle_plan_query_info(_state_data *shmp, int operation, int method, char *ret_prompt);
extern int GetUssdServiceType(_state_data *shmp);
extern int get_cos_bundle_control(int cos_id);
extern int GetUssdServiceKey(u_char serviceKey);
extern int UseExternalVC();
extern int send_scf_update_card_data(u_short portid);
extern int RechargeFailedUpdateAccountData(u_short portid);
extern int AssignProcID(int gy_flag);
extern int CheckClearFriendFamilyNumber(int head, int tail, int rent_charge,int rent_id);
extern int pps_update_account_bundle_mt_voice(_state_data *shmp, int seconds);
extern int pps_update_account_bundle_mo_voice(_state_data *shmp, int seconds);
extern int IncreaseFriendFamilyFreeCallDuration(int head, int tail, int duration);
extern int sendPPSTestShortMessage(char *message);
extern int pps_update_account_bundle_mo_sms(_state_data *shmp, int count);
extern int IncreaseFriendFamilyFreeSMSCounter(int head, int tail);
extern int IsEnableToAddEditFavoriteNumber(_state_data *shmp, int flag);
extern int IsFavoriteNumberTypeOk(_state_data *shmp);
extern int AddInterPrefix(char *number);
extern int GetMOTariffData(_state_data *shmp,_bill_tariff *ptar, char *call_no, int zone_id);
extern int GetMTTariffData(_state_data *shmp, u_char tariffID, _bill_tariff *ptar, _account_info *pinfo, _account_info *pcaller);
extern int pps_real_update_file_init();
extern int pps_real_update_file_close();
extern int pps_get_ucbc_number(char *ucbc_number);
extern long GetPromotionExpiration(_account_info *ptr);
extern ulong getSystemCurrencyResolution();
extern int pps_real_update_user_file(int head, int tail);
extern int CountUsedCardForDailyReport(int charge);
extern int GetAccountMsisdnStr(int head, int tail,u_char *msisdn);
extern void ppsListAllSubsMSISDN();
extern int gx_print_all_port_status();
extern int gx_print_stat();
extern int gx_stat_clean_all();
extern int smppSendMsg(u_char *peerNumber,u_char *msg,u_char serviceNumPosition);
extern int UpdateAccountBundlePlanInfoWarningFlag(_state_data *shmp, int flag);
extern void ChangeTariffToCfCugFavTariff(_state_data *shmp, _bill_tariff *ptar);
extern void ChangeTariffToCfCugTariff(_state_data *shmp, _bill_tariff *ptar);
extern void ChangeTariffToCfFavTariff(_state_data *shmp, _bill_tariff *ptar);
extern void ChangeTariffToCfTariff(_state_data *shmp, _bill_tariff *ptar);
extern void ChangeTariffToCugFavTariff(_state_data *shmp, _bill_tariff *ptar);
extern void ChangeTariffToCugTariff(_state_data *shmp, _bill_tariff *ptar);
extern void ChangeTariffToFavoriteCallTariff(_state_data *shmp, _bill_tariff *ptar);
extern void ChangeTariffToMTRoamingTariff(_state_data *shmp, _bill_tariff *ptar);
extern void ChangeTariffToMORoamingTariff(_state_data *shmp, _bill_tariff *ptar);
extern int IsPromotionExpired(_account_info *ptr);
extern int pps_rest_query_process(u_short portid);
extern int SendRestAccountInfoPromptToSrf(u_short portid);
extern int pps_rest_topup_process(u_short portid);
extern int SendRestRechargeInfoPromptToSrf(u_short portid);
extern int pps_rest_query_process(u_short portid);
extern int pps_rest_topup_process(u_short portid);
extern int pps_smpp_state(u_short portid);
extern int pps_rest_transfer_process(u_short portid);
extern int SendTransferSuccessRequest(u_short portid,u8 ussdSmsFlag);
extern int SendPSSREnd(u_short portid,char *ussd_info);
extern int ocs_get_calling_card_cos_id();
extern float ocs_get_calling_card_left_balance(int head, int tail);
extern int ocs_get_calling_card_method();
extern int WaitingForEventsReport_ccc(u_short portid);
extern int WaitingforAnsweredProc_ccc(u_short portid);
extern int CheckCallValidity_ccc(u_short portid);
extern int WaitingForInputCallingCardAccountResponse_ccc(_state_data *shmp);
extern int BillingProc_ccc(_state_data *shmp, int sub_flag0);
extern int IsEnableToCall_ccc(int proc_id);
extern int pps_get_answer_timer_out();
extern void ChargeAccountByRealCallDuration(u_short portid);
extern char *pps_get_service_number(unsigned int num_pos);
extern int OCS_with_external_CRM();
extern void pps_send_rent_charge_to_crm(int head, int tail);
extern void ocs_get_crm_prefix_definition();


#endif


