ToDo: rework
Every balance sheet will have a usage handler that contains a list of usage that applies to this balance sheet. Each time a balance sheet accept a rated call details record, it will add the cost to itself then pass the call details record to the usage handler for further processing.
Read access and local changes to a balance page are public.
All operations modifying the status of balance page in the database are private, i.e., accessible for BalanceSheet only. This has several reasons:
Definition at line 384 of file balancesheet.h.
typedef Id<BsPage> OSB_LIB::BsPage::Oid |
Status of changes to the CDRs of the page.
It is used to control the behavior of the page in restoreCdrs() and commitCdrs().
Definition at line 440 of file balancesheet.h.
Enumeration to reflect the status of a balance page.
bpUnknown | Unknown status. |
bpNormal | Normal status for balance page. |
bpRerate | Balance page is to be re-rated. |
bpDontBill | Do not bill balance page. |
bpBillingFailed | Billing failed for balance page. |
Definition at line 420 of file balancesheet.h.
Constructor with optional object id.
This is to construct a balance page that will later call read operations to populate its data members.
oid | Object id of the balance sheet to be created. |
OSB_LIB::BsPage::BsPage | ( | const Contract::Oid & | coId, | |
const Billcycle::Oid & | bcId | |||
) |
Constructor to create a new balance sheet.
This function will create an empty balance sheet that is related to the contract passed in.
coId | Contract id of the balance page. | |
bcId | Billcycle id of the balance page. |
OSB_LIB::BsPage::BsPage | ( | const BsPage & | rhs | ) |
Copy constructor.
OSB_LIB::BsPage::~BsPage | ( | ) |
Destructor will delete the usage handler object.
void OSB_LIB::BsPage::addAdvCharge | ( | const Money & | charge | ) |
Add a advance charge (prototype).
void OSB_LIB::BsPage::addCdr | ( | const Cdr & | cdr | ) |
Add a CDR to the page.
This function updates the balance page based on the call details record it receives. Then it passes the call details record to usage handler for further processing.
cdr | Call details record to be added to the balance sheet. |
PageClosed |
void OSB_LIB::BsPage::addOtc | ( | const OnetimeCharge & | otc | ) |
Add a onetime charge to the balance page.
otc | Onetime charge to add. |
PageClosed |
const AdvanceCharges& OSB_LIB::BsPage::advanceCharges | ( | ) | const [inline] |
Advance charges assigned to the page.
Definition at line 567 of file balancesheet.h.
References advanceCharges_.
const Billcycle::Oid& OSB_LIB::BsPage::billcycleId | ( | ) | const [inline] |
Id of the page's bill cycle.
Definition at line 538 of file balancesheet.h.
References billcycleId_.
CdrIo& OSB_LIB::BsPage::cdrIo | ( | ) | const [private] |
const BsTotal& OSB_LIB::BsPage::charges | ( | ) | const [inline] |
Total of charges grouped by currency.
Definition at line 563 of file balancesheet.h.
References charges_.
void OSB_LIB::BsPage::clearRecoveryId | ( | const OSB_DB::Session & | session | ) | [private] |
Unset the recovery id.
session | Database session to use. |
SetRecoveryFailed | If the function throws, recoveryId_ is not changed. If recoveryId_ is 0 (i.e., not set) the function returns immediately. |
void OSB_LIB::BsPage::close | ( | const OSB_DB::Session & | session | ) | [private] |
Close the balance page.
session | Database session to use. |
PageClosed | (evaluated in the gateway). | |
NotFound | ||
NoEndDate |
const DateTime& OSB_LIB::BsPage::closed | ( | ) | const [inline] |
Date when the balance page was closed.
Definition at line 545 of file balancesheet.h.
References closed_.
const Contract::Oid& OSB_LIB::BsPage::coId | ( | ) | const [inline] |
void OSB_LIB::BsPage::commitCdrs | ( | ) | [private] |
Remove backup CDR files.
This function removes the backup files created during writeCdrs().
CommitCdrFailed | Do not call this function if the session that was used to add and save the usage is not commited! |
bool OSB_LIB::BsPage::delOtc | ( | const OnetimeCharge::Oid & | otcId | ) |
Delete a onetime charge of the balance page.
otcId | Object id of the onetime charge to delete. |
PageClosed |
const Date OSB_LIB::BsPage::endDate | ( | ) | const [inline] |
End date of the billing period.
Definition at line 532 of file balancesheet.h.
References endDate_, and OSB_LIB::Date::max().
OnetimeCharge* OSB_LIB::BsPage::find | ( | const OnetimeCharge::Oid & | otcId | ) | [private] |
Find a onetime charge by its id.
const OnetimeCharge* OSB_LIB::BsPage::findOtc | ( | const OnetimeCharge::Oid & | otcId | ) |
Find a onetime charge by its id.
otcId | Id of the onetime charge to find. |
OnetimeCharges& OSB_LIB::BsPage::getOnetimeCharges | ( | ) | [inline] |
Write access to onetime charges.
Definition at line 624 of file balancesheet.h.
References onetimeCharges_.
SubsCharges& OSB_LIB::BsPage::getSubsCharges | ( | ) | [inline] |
Write access to subscription charges.
Definition at line 634 of file balancesheet.h.
References subsCharges_.
void OSB_LIB::BsPage::initialize | ( | ) | [private] |
Initialize "common" data members.
This function initializes all data members that can not be set via a constructor (such as e.g., the object id).
bool OSB_LIB::BsPage::insert | ( | const OSB_DB::Session & | session | ) | [private] |
Create a new balance page in the database.
The function creates an empty balance page in the database, any charges assigned to the page are ignored. The following data members are stored:
coId_, billcycleId_, startDate_ and endDate_.
If successful the following data members are set by the function: oid_ and opened_.
session | Database session. |
OsbException | for any error. |
bool OSB_LIB::BsPage::isOpen | ( | ) | const [inline] |
Balance page open?
Definition at line 547 of file balancesheet.h.
References closed_, and OSB_LIB::DateTime::notSet().
bool OSB_LIB::BsPage::justBilled | ( | ) | const [inline] |
const DateTime& OSB_LIB::BsPage::lastCharged | ( | ) | const [inline] |
Timestamp of the latest charge modification.
Definition at line 553 of file balancesheet.h.
References lastCharged_.
const Oid& OSB_LIB::BsPage::oid | ( | ) | const [inline] |
const OnetimeCharges& OSB_LIB::BsPage::onetimeCharges | ( | ) | const [inline] |
Onetime charges assigned to the page.
Definition at line 572 of file balancesheet.h.
References onetimeCharges_.
const DateTime& OSB_LIB::BsPage::opened | ( | ) | const [inline] |
Date when the balance page was opened.
Definition at line 543 of file balancesheet.h.
References opened_.
void OSB_LIB::BsPage::readAdvanceCharges | ( | const OSB_DB::Session & | session | ) |
Read the advanced charges from database.
This function will populate the balance sheet with advanced charges retrieved from database.
session | Database session to use. |
bool OSB_LIB::BsPage::readAll | ( | const OSB_DB::Session & | session, | |
bool | withCdr | |||
) |
Read all balance page data with all charges.
The function reads the basic information and all charges from the database. It calls the following members in this order (please refer to the documentation there):
session | Database session to use. | |
withCdr | Flag if the individual Cdr should be read. |
OsbException | for any error. |
void OSB_LIB::BsPage::readCdrs | ( | CdrList & | dest | ) |
Read individual CDRs into a CDR list.
dest | STL container to store the CDRs. |
void OSB_LIB::BsPage::readCdrs | ( | ) |
Read the individual CDRs.
void OSB_LIB::BsPage::readCharges | ( | const OSB_DB::Session & | session, | |
bool | withCdr | |||
) |
Read all charges of the balance page.
The function reads all charges of the balance page from the database. It calls the following members in this order (please refer to the documentation there):
session | Database session to use. | |
withCdr | Flag if the individual Cdr should be read. |
OsbException | for any error. |
bool OSB_LIB::BsPage::readInfo | ( | const OSB_DB::Session & | session | ) |
Read the info for a balance page from database.
The function uses the object id of the page to read basic information and the charge totals from the database.
This does not include not the individual charges.
session | Database session to use. |
void OSB_LIB::BsPage::readOnetimeCharges | ( | const OSB_DB::Session & | session | ) |
Read the one time charges from database.
This function will populate the balance sheet with one time charges retrieved from database within the time period stated.
session | Database session to use. |
void OSB_LIB::BsPage::readUsageCharges | ( | const OSB_DB::Session & | session, | |
bool | withCdr | |||
) |
Read the usage charges.
For a balance page that stores summary call details records, this function will populates the usage list with corresponding summary records. To get all related call details records that are related to the summary call details records, set the withCdr parameter to true.
For a balance page that only stores Cdr records, this function, by default, will not populate the call details records into the usage list. This is to avoid storing duplicate Cdr when BsPage::writeCdrs() is called.
In the case where balance page is to be pass to billing module, balance page that only stores call details records will need to have the Cdr related to it. To achieve this, withCdr parameter is used. Set it to true if Cdr should be retrieved else false.
session | Database session. | |
withCdr | Flag if the individual Cdr should be read. |
OsbException | for any error. |
long OSB_LIB::BsPage::recoveryId | ( | ) | const [inline] |
Identifier of recovery action.
See recoveryId_ for details.
Definition at line 561 of file balancesheet.h.
References recoveryId_.
bool OSB_LIB::BsPage::remove | ( | OSB_DB::Session & | session | ) | [private] |
Remove a balance page entry from database.
This function will remove a balance sheet entry and related summary call details record entries (if any) from database. Related Cdrs and the balance sheet directory structure will not be removed.
session | Database session. |
void OSB_LIB::BsPage::removeUsage | ( | const OSB_DB::Session & | session | ) | [private] |
Remove usage charges from the balance sheet.
session | Database session to use. |
UpdateUsageFailed | This function will remove all usage charges and rated cdr files from the balance page. |
bool OSB_LIB::BsPage::rerating | ( | ) | const [inline] |
bool OSB_LIB::BsPage::restoreCdrFiles | ( | OSB_DB::Session & | session | ) | [private] |
Undo previous changes to CDRs.
session | Database session to unset and commit the recovery id to the database. |
bool OSB_LIB::BsPage::restoreCdrs | ( | OSB_DB::Session & | session | ) | [private] |
Restore changed CDRs after a failure.
session | Database session to unset and commit the recovery id to the database. |
If the function returns true, data members tracking the status of the CDR files are reset:
bool OSB_LIB::BsPage::saveAdvCharges | ( | const OSB_DB::Session & | session | ) | [private] |
Store added advance charges in the database (prototype).
bool OSB_LIB::BsPage::saveOtCharges | ( | const OSB_DB::Session & | session | ) | [private] |
Save all changes to onetime charges.
session | Database session to use. |
void OSB_LIB::BsPage::setBilled | ( | ) | [inline] |
Mark the page as billed.
This member is used by the billing application only.
Definition at line 613 of file balancesheet.h.
References justBilled_.
void OSB_LIB::BsPage::setEndDate | ( | const Date & | endDate | ) |
Set the end date (see also endDate_).
endDate | End date of the balance page. If endDate is not set, Date::max() is used. |
void OSB_LIB::BsPage::setRerating | ( | ) |
Mark the page as being rerated.
This member is used for the rating application only (rerating).
bool OSB_LIB::BsPage::setStatus | ( | const OSB_DB::Session & | session, | |
const Status & | status | |||
) |
Change status of balance page.
session | Database session. | |
status | Status of balance page to change to. |
const Date& OSB_LIB::BsPage::startDate | ( | ) | const [inline] |
Start date of the billing period.
Definition at line 530 of file balancesheet.h.
References startDate_.
const Status& OSB_LIB::BsPage::status | ( | ) | const [inline] |
const SubsCharges& OSB_LIB::BsPage::subsCharges | ( | ) | const [inline] |
Subscription charges assigned to the page.
Definition at line 565 of file balancesheet.h.
References subsCharges_.
const SumCdrList* OSB_LIB::BsPage::sumCdrList | ( | ) | const |
Convert to status to long.
status | Status of balance page to convert. |
void OSB_LIB::BsPage::updateUsage | ( | const OSB_DB::Session & | session | ) | [private] |
Update added usage to the database.
session | Database session to use. |
UpdateUsageFailed | The function first save the summary CDRs (if applicable), then sums up the added usage charges in the database. |
bool OSB_LIB::BsPage::updLastCharged | ( | const OSB_DB::Session & | session | ) | [private] |
Set the timestamp for the last charge modification.
session | Database session to use. |
bool OSB_LIB::BsPage::usageModified | ( | ) | const |
Flag if the usage of the page was modified.
void OSB_LIB::BsPage::writeCdrs | ( | long | recoveryId, | |
OSB_DB::Session & | session, | |||
Asn1Writer & | writer | |||
) | [private] |
Write CDRs to file system.
recoveryId | Identifier to use for recovery. | |
session | Session to update and commit the recovery id to the database. | |
writer | ASN.1 writer to use. |
RecoveryNeeded | ||
SetRecoveryFailed | ||
OsbException | if writing of the CDR fails. |
friend class BalanceSheet [friend] |
Provide access for the controlling balance sheet.
Only the balance sheet is allowed to call methods that change the page in datebase.
Also during the creation of a new page, the balance sheet must modify the start and end date.
Definition at line 399 of file balancesheet.h.
friend struct OSB_DB::BalanceSheetGw [friend] |
Balance sheet gateway will need to populate the private data members of balance sheet object.
Definition at line 389 of file balancesheet.h.
Container holding the advance charges.
Definition at line 1089 of file balancesheet.h.
Referenced by advanceCharges().
Billcycle::Oid OSB_LIB::BsPage::billcycleId_ [private] |
CdrFileStatus OSB_LIB::BsPage::cdrFileStatus_ [private] |
CdrIo* OSB_LIB::BsPage::cdrIo_ [mutable, private] |
CdrIo object used to handle the CDR files.
Definition at line 1081 of file balancesheet.h.
CdrList OSB_LIB::BsPage::cdrs_ [private] |
BsTotal OSB_LIB::BsPage::charges_ [private] |
Total of charges grouped by currency.
Definition at line 1070 of file balancesheet.h.
Referenced by charges().
DateTime OSB_LIB::BsPage::closed_ [private] |
Contract::Oid OSB_LIB::BsPage::coId_ [private] |
Contract id where this balance sheet belongs to.
Definition at line 1011 of file balancesheet.h.
Referenced by OSB_LIB::BalanceSheet::coId(), and coId().
Date OSB_LIB::BsPage::endDate_ [private] |
End date of the billing period.
The end date is not meaningful for all billcycle types. If not applicable, it is set to Date::max().
Never modify this data member directly (not even the class itself!), use setEndDate() instead.
Definition at line 1022 of file balancesheet.h.
Referenced by endDate().
bool OSB_LIB::BsPage::justBilled_ [private] |
Flag if the page was just billed.
Definition at line 1030 of file balancesheet.h.
Referenced by justBilled(), and setBilled().
DateTime OSB_LIB::BsPage::lastCharged_ [private] |
Date and time when the charges were last modified.
Definition at line 1036 of file balancesheet.h.
Referenced by lastCharged().
Oid OSB_LIB::BsPage::oid_ [private] |
Database link of balance sheet.
Definition at line 1009 of file balancesheet.h.
Referenced by oid().
Container holding onetime charges.
Definition at line 1091 of file balancesheet.h.
Referenced by getOnetimeCharges(), and onetimeCharges().
DateTime OSB_LIB::BsPage::opened_ [private] |
Date and time when the balance sheet was opened.
Definition at line 1026 of file balancesheet.h.
Referenced by opened().
long OSB_LIB::BsPage::recoveryId_ [private] |
Identifier for CDR recovery.
Possible values are:
0: no recovery needed. <0: recovery from replacement of CDRs. >0: recovery from adding of CDRs.
Definition at line 1067 of file balancesheet.h.
Referenced by recoveryId().
bool OSB_LIB::BsPage::rerating_ [private] |
Flag if the page is being rerated.
Definition at line 1032 of file balancesheet.h.
Referenced by rerating().
Date OSB_LIB::BsPage::startDate_ [private] |
Start date of the billing period.
Definition at line 1013 of file balancesheet.h.
Referenced by startDate().
Status OSB_LIB::BsPage::status_ [private] |
SubsCharges OSB_LIB::BsPage::subsCharges_ [private] |
Container holding the subscription charges.
Definition at line 1087 of file balancesheet.h.
Referenced by getSubsCharges(), and subsCharges().
SumCdrList* OSB_LIB::BsPage::sumCdrs_ [private] |
bool OSB_LIB::BsPage::usageChanged_ [private] |
Usage of the page modified and not updated to database?
The flag is set in all functions that modify the usage charges and cleared in updateUsage().
For the avoidance of doubt: the flag does not track the changes to the CDR files.
Definition at line 1050 of file balancesheet.h.