A balance sheet consists of several BsPage where each page stores the estimated charges for one invoice.
The class is the manager of all pages: it controls all database updates and supports clients in adding, changing or removing charges.
In order to avoid a misconception: It is possible for clients to manipulate balance pages directly, they will however to not be able to permanently save the changes.
Definition at line 1252 of file balancesheet.h.
typedef std::list<BsPage> OSB_LIB::BalanceSheet::Pages |
OSB_LIB::BalanceSheet::BalanceSheet | ( | const Contract::Oid & | coId = Contract::Oid() |
) | [inline, explicit] |
void OSB_LIB::BalanceSheet::addAdvCharge | ( | const Money & | charge, | |
const DateTime & | valueDate, | |||
const OSB_DB::Session & | session | |||
) |
Add an advance charge.
BsPage::Oid OSB_LIB::BalanceSheet::addOtc | ( | const OnetimeCharge & | otc, | |
const OSB_DB::Session & | session | |||
) |
Add a onetime charge.
otc | Onetime charge to add, the value date is OnetimeCharge::assigned. | |
session | Database session to use for the creation of a new balance page. |
void OSB_LIB::BalanceSheet::addUsage | ( | const CdrList & | cdrs, | |
const OSB_DB::Session & | session | |||
) |
Add a list of CDRs to the balance sheet.
cdrs | STL container with the CDRs to add. | |
session | Database session that is used for the creation of a new balance page. |
void OSB_LIB::BalanceSheet::addUsage | ( | const Cdr & | cdr, | |
const OSB_DB::Session & | session | |||
) |
Add a CDR to the balance sheet.
cdr | Call detail record to add: The value date is the timestamp of the CDR. | |
session | Database session to use for the creation of a new balance page. |
bool OSB_LIB::BalanceSheet::allPages | ( | ) | const [inline] |
Flag if the balance sheet contains all pages.
Definition at line 1296 of file balancesheet.h.
ObjectStatus OSB_LIB::BalanceSheet::checkObjVs | ( | const OSB_DB::Session & | session | ) | const |
Check the object version.
session | Database session to use. |
void OSB_LIB::BalanceSheet::clearRecoveryId | ( | const OSB_DB::Session & | session | ) |
Unset the recovery id.
session | Database session to use. |
OsbException | (BsPage::SetRecoveryFailed) if the update fails for any of the pages. |
void OSB_LIB::BalanceSheet::closeBilledPages | ( | const OSB_DB::Session & | session, | |
const DateTime & | billed, | |||
const Contract & | contract | |||
) |
Close all billed pages.
session | Database session to use. | |
billed | Date and time when the pages were billed: used to set BsPage::closed_. | |
contract | Contract that was billed. It it used to determine if a new page should be opened. |
NotLocked | ||
OsbException | from BsPage::close. |
const Contract::Oid& OSB_LIB::BalanceSheet::coId | ( | ) | const [inline] |
void OSB_LIB::BalanceSheet::commitCdrs | ( | ) |
Remove backup files.
This function removes the backup files created during writeCdrs().
It calls BsPage::commitCdrs() for each page.
NotLocked | ||
OsbException | from BsPage::commitCdrs(). |
bool OSB_LIB::BalanceSheet::createPage | ( | const OSB_DB::Session & | session, | |
const Date & | tsDate | |||
) | [private] |
Create one (or more) balance page.
session | Database session to use. | |
tsDate | Date of the timestamp for which to create the page. |
BillcycleInvalid | After the successful return of this function, the caller should use getOpenPage to retrieve the open balance page for ts. |
a) no page with start date <= ts < end date exists. Because pages are created without gaps, this means that no page beyond ts exists.
-------|--C--|-C/O-|--N--|--N--|-------> t ^ts
b) the page with start date <= ts < end date is closed. Because we know (only) all open pages, other closed pages for later invoice periods may exist:
----|--C--|--O--|--C--|--C--|--N--|----> t ^ts C: closed page O: open page N: new page(s) created by this function.
For a) we have to create all pages since the latest page (or the contract creation date) till ts is the invoice period.
For b) we must create the page after the last closed one.
For both scenarios we can use the end date of the latest page or, if no page exists, the contract creation date as start date for the pages to add. The creation of pages is complete once we have created a page with end date > ts.
In the special situation where the last open balance page belongs to a DateBillcyle that function returns without creating a new page. This is because all charges added to the balance sheet will be assigned to this open page.
In normal operation this function should never be called if this scenario applies: if this happens for whatsoever reason the next call to getOpenPage will fail and result in the exception NoOpenPage.
BsPage* OSB_LIB::BalanceSheet::findPage | ( | const BsPage::Oid & | pageId | ) |
Find a balance page by its id.
pageId | Id of the balance page to find. |
void OSB_LIB::BalanceSheet::getCdrsToRerate | ( | CdrList & | dest | ) |
Read the usage charges of the pages that need rerating.
dest | STL container to store the CDRs. |
Get the open balance page for a time stamp.
Pages& OSB_LIB::BalanceSheet::getPages | ( | ) | [inline] |
bool OSB_LIB::BalanceSheet::insert | ( | const OSB_DB::Session & | session | ) |
Create a new balance sheet entry in database.
session | Database session. |
ObjectStatus OSB_LIB::BalanceSheet::lock | ( | const OSB_DB::Session & | session, | |
bool | noWait = false | |||
) |
Lock the balance sheet.
If locking is successful the object version of the balance sheet is incremented by 1 in the object itself and in the database.
If the function returns objModified it is the decision of the caller to or not to reread balance sheet from the database.
session | Database session. | |
noWait | Flag if the function should not block if the balance sheet is locked otherwise. |
Deadlock | ||
LockFailed |
bool OSB_LIB::BalanceSheet::locked | ( | ) | const [inline] |
long OSB_LIB::BalanceSheet::objVs | ( | ) | const [inline] |
bool OSB_LIB::BalanceSheet::openPage | ( | const OSB_DB::Session & | session, | |
const DateTime & | ts, | |||
const Contract & | contract | |||
) |
Open a new balance page if needed.
session | Database session to use. | |
ts | Date and time for which to create the page. | |
contract | Contract of the balance sheet. |
The second condition is not evaluated strictly. Instead the contract's effective status and date are used. In very rare situations this might result in a "wrongly" opened page in the past, which is later nullified by the billing application.
const Pages& OSB_LIB::BalanceSheet::pages | ( | ) | const [inline] |
bool OSB_LIB::BalanceSheet::read | ( | const OSB_DB::Session & | session, | |
bool | readAll = false | |||
) |
Read the balance sheet from the database.
This includes:
After the pages have been read, they are sorted by descending start date by calling sortPages.
session | Database session to use. | |
readAll | Flag to read closed pages too. |
BillcycleInvalid | if the billcycle type is unknown. |
void OSB_LIB::BalanceSheet::readCdrs | ( | ) |
Read the CDRs for all pages.
bool OSB_LIB::BalanceSheet::readCharges | ( | const OSB_DB::Session & | session, | |
bool | withUsg, | |||
bool | withCdr, | |||
bool | withOtc, | |||
bool | withAdv | |||
) |
Read the charge details for all pages.
The function reads the charge details for the pages of the balance sheet previously retrieved by read().
NOTE that read() calls BsPage::readInfo() for each page, so there's no need to call this member function of the balance page again.
session | Database session to use. | |
withUsg | Flag to read usage charges. | |
withCdr | Flag to read the individual Cdr. | |
withOtc | Flag to read onetime charges. | |
withAdv | Flag to read advance charges. |
// somehow iter points to a page ... Pages::iterator iter = ...; if (withUsg) i->readUsageCharges(session, withCdr);
void OSB_LIB::BalanceSheet::removeUsage | ( | const OSB_DB::Session & | session | ) |
Remove cdrs from the file sysytem and database.
session | Database session to use. |
OsbException | from BsPage::removeUsage(). |
bool OSB_LIB::BalanceSheet::restoreCdrs | ( | OSB_DB::Session & | session | ) |
Restore changed CDRs after a failure.
session | Database session to unset and commit the recovery id to the database. |
bool OSB_LIB::BalanceSheet::saveAdvCharges | ( | const OSB_DB::Session & | session | ) |
Write advance charges to database.
bool OSB_LIB::BalanceSheet::saveOtCharges | ( | const OSB_DB::Session & | session | ) |
Save changes to onetime charges.
session | Database session to use. |
NotLocked |
bool OSB_LIB::BalanceSheet::setUnlocked | ( | ) |
void OSB_LIB::BalanceSheet::sortPages | ( | bool | desc = true |
) |
Sort balance pages by start date.
desc | Flag to sort in descending (true) or ascending (false) order. |
void OSB_LIB::BalanceSheet::totalCharges | ( | BsTotal & | dest, | |
bool | openOnly | |||
) | const |
The summed-up charge totals of all pages.
dest | Balance sheet total list to populate. | |
openOnly | Flag if only open pages should be summed-up. |
void OSB_LIB::BalanceSheet::updateUsage | ( | const OSB_DB::Session & | session | ) |
Update the usage charges.
session | Database session to use. |
NotLocked | ||
OsbException | from BsPage::updateUsage(). |
bool OSB_LIB::BalanceSheet::usageModified | ( | ) | const |
Flag if usage of the balance sheet was modified.
void OSB_LIB::BalanceSheet::writeCdrs | ( | long | recoveryId, | |
OSB_DB::Session & | session, | |||
Asn1Writer & | writer | |||
) |
Write added CDRs to the file system.
recoveryId | Recovery mark to use. | |
session | Session used to write and commit the recovery id to the database. | |
writer | ASN.1 writer to use. |
NotLocked | ||
OsbException | from BsPage::writeCdrs(). |
friend struct OSB_DB::BalanceSheetGw [friend] |
Allow the supporting gateway to set data members directely.
Definition at line 1254 of file balancesheet.h.
bool OSB_LIB::BalanceSheet::allPages_ [private] |
Billcycle::Oid OSB_LIB::BalanceSheet::bcId_ [private] |
Contract::Oid OSB_LIB::BalanceSheet::coId_ [private] |
bool OSB_LIB::BalanceSheet::locked_ [private] |
Indicator if the balance sheet is locked or not.
Use this with care. Since a lock is only released at the end of each database transaction, i.e., through a rollback or commit, the value returned by this function only tells if a lock has been acquired for this balance sheet.
Definition at line 1791 of file balancesheet.h.
Date OSB_LIB::BalanceSheet::nextPageStart_ [private] |
Start date for the next balance page.
This is either the latest end of a balance page or -if no page exists- the creation date of the contract.
If the end date of the latest balance page is not set (DateBillcycle) the value is Date::notSet().
See createPage for a detailed explanation.
Definition at line 1807 of file balancesheet.h.
long OSB_LIB::BalanceSheet::objVs_ [private] |
Object version: incremented by 1 for each database update.
Definition at line 1793 of file balancesheet.h.
Pages OSB_LIB::BalanceSheet::pages_ [private] |