OSB_LIB::ToBill Class Reference

Collaboration diagram for OSB_LIB::ToBill:

Collaboration graph
[legend]
List of all members.

Detailed Description

Determine contracts to bill.

This class supports the billing application to select the contracts to invoice.

All loading function just wrap to the supporting gateway class OSB_DB::ToBillGw.

Remarks:
Clients of the class should consider the following items:

Definition at line 86 of file tobill.h.

Public Types

Public Member Functions

Static Public Member Functions

Public Attributes


Member Typedef Documentation

typedef std::set< Id<Contract> > OSB_LIB::ToBill::Batch

STL container to store the contract ids that should be billed.

Definition at line 92 of file tobill.h.


Constructor & Destructor Documentation

OSB_LIB::ToBill::ToBill (  )  [inline]

Default constructor.

Definition at line 96 of file tobill.h.

OSB_LIB::ToBill::ToBill ( const Date endDate  )  [inline]

Constructor with end of billed period.

Definition at line 98 of file tobill.h.

OSB_LIB::ToBill::ToBill ( const Id< Billcycle > &  bcId,
const Date endDate,
long  batchSize 
) [inline]

Constructor with bill cycle, end of billed period and batch size.

Definition at line 106 of file tobill.h.


Member Function Documentation

bool OSB_LIB::ToBill::loadContract ( const OSB_DB::Session session,
const Id< Contract > &  coId 
)

Load a single contract for invoicing.

Parameters:
session Database session to use.
coId Id of the contract to load.
Returns:
true if the contract has at least one open balance page to bill, else false.

long OSB_LIB::ToBill::loadContracts ( const OSB_DB::Session session,
const Id< Associate > &  ownerId 
)

Load all contracts owned by an associate.

long OSB_LIB::ToBill::loadContracts ( const OSB_DB::Session session  ) 

Load the next batch of contracts to invoice.

Parameters:
session Database session to use.
Returns:
The number of contracts loaded: batch_.size().
The function determines the next batch of contracts to invoice and stores the result in batch_.

Each of the selected contracts has at least one open BsPage with:

Note:
Performance issues:
The SQL statement sorts by contract id because we need to avoid that contracts for which billing failed are read again and again. (This is the rationale for lastCoId_.)
This requires that the database server retrieves all candidate contracts before returning them.
The following design may overcome this problem:
Provide a flag BsPage::billingFailed and use it as selection criteria (lastCoId_ is then obsolete). Contracts are then read randomly from the database, but who cares. Such a bill status as the welcome side-effect that we do not have to rely on log files to identify problematic contracts and balance pages.

static bool OSB_LIB::ToBill::pageToBill ( BsPage page,
const Id< Billcycle > &  bcId,
const Date endDate 
) [static]

Determine whether a balance page needs billing.

This static member is a service offered to the billing application, which is free to implement its own different rule.

Parameters:
page Balance page to check.
bcId Id of the running billcycle.
endDate End date of the billed period.
Returns:
true if the balance page needs billing, else false.
If the end date of the page is not set and it needs billing, the function sets the end date to endDate.

Instead of complicated explanations the source code is given below:

          // trivial case: page is closed
          if (!page.isOpen()) return false;
          // billcycle specific: skip if the billcyle does not match
          if (bcId.isSet() && page.billcycleId() != bcId) return false;

          // start date after or equal last date billed: skip
          // (if we'd allow for start date = endDate
          // the invoice period would be 0 days.)
          if (page.startDate() >= endDate) return false;
          // end date set and after end of billed period: skip
          if (   Date::notSet() != page.endDate()
              && endDate        <  page.endDate()) return false;

          // if the page is to be billed: set its end date
          if (Date::notSet() == page.endDate()) page.setEndDate(endDate);
          return true;

Remarks:
bcId is not used to create a billcycle object.


Member Data Documentation

Batch OSB_LIB::ToBill::batch_

List of contracts to bill.

Definition at line 168 of file tobill.h.

long OSB_LIB::ToBill::batchSize_

Size of batch to load.

Definition at line 178 of file tobill.h.

Id<Billcycle> OSB_LIB::ToBill::bcId_

Id of the billcycle.

Definition at line 177 of file tobill.h.

Date OSB_LIB::ToBill::endDate_

End date of billed period (not included).

Note:
The maximum end date (included) of the generated invoices will be endDate_ - 1.

Definition at line 176 of file tobill.h.

Id<Contract> OSB_LIB::ToBill::lastCoId_

Last contract loaded.

Definition at line 179 of file tobill.h.


The documentation for this class was generated from the following file:
Generated on Sat Sep 2 14:10:26 2006 for OSB Library by  doxygen 1.4.7