account.h

Go to the documentation of this file.
00001 // OSB library ********************************************* -*- C++ -*-
00006 /*
00007   AUTHOR(S): Ashwin Pakramzis (ap)
00008              Ramlan Rusdijanto (rr)
00009 
00010   RCS information
00011     $Name: OSB_060808 $
00012     $Revision: 1.41 $
00013 
00014   License
00015    OSB rating and billing library for communication networks
00016    Copyright (C) 2004, 2005, 2006  OSB systems
00017 
00018    This file may be distributed and/or modify under the terms of the
00019    GNU General Public License (GPL) as published by the Free Software
00020    Foundation which is provided in the file LICENSE.GPL included in the
00021    packaging of this file.
00022 
00023    The file is distributed in the hope that it will be useful, but WITHOUT
00024    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00025    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00026    for more details.
00027 
00028    Holders of a OSB Commercial License may use this file under the terms
00029    and conditions of this commercial license.
00030  */
00031 #ifndef _ACCOUNT_H_
00032 #define _ACCOUNT_H_
00033 
00034 // *********************************************************************
00035 // included header files
00036 // + standard includes
00037 #include <string>
00038 #include <map>
00039 #include <vector>
00040 
00041 // + local headers
00042 #include "osbid.h"
00043 #include "chrono.h"
00044 #include "money.h"
00045 
00046 // *********************************************************************
00047 // class declarations
00048 namespace OSB_DB {
00049     class Session;
00050 }
00051 
00052 namespace OSB_LIB {
00053     class Associate;
00054     class InvoiceInfo;
00055     class Contract;
00056 }
00057 
00058 // *********************************************************************
00059 // namespace extensions
00060 namespace OSB_LIB {
00062     enum AccountType {Assets, Liabilities, Capital};
00063 
00069     struct Account {
00070         typedef Id<Account> Oid;        
00071 
00072         enum Side { credit, debit };
00079         static char toChar(Side sd);
00080 
00082         Account() {}
00090         Account(Oid oid, const std::string& ac, AccountType tp)
00091           : oid_(oid), code_(ac), type_(tp) {}
00092 
00094         Oid oid() const { return oid_; }
00095 
00096         Oid         oid_;               
00097         std::string code_;              
00098         AccountType type_;              
00099     };
00100 
00102     typedef std::map<std::string, Account> AccountList;
00103 
00105     class Transaction {
00106     public:
00108         Transaction() {}
00116         void setAccount(const Account& ac, const Money& m);
00117 
00119         Account account() const { return account_; }
00120 
00126         Money getAmount() const;
00127 
00128         Date          date_;     
00129         std::string   detail_;   
00130         std::string   folio_;    
00131     private:
00132         Account       account_;  
00133         Account::Side side_;     
00134         Money         amount_;   
00135 
00136     };
00137 
00139     typedef std::vector<Transaction> TransactionList;
00140 
00151     class SummaryCharges {
00152     public:
00154         SummaryCharges() {}
00156         void addTransaction(const Transaction& transaction)
00157         {
00158             transactions_.push_back(transaction);
00159         }
00160 
00162         void outstandingBalance(MoneyList& ml) const;
00164         void totalAmountDue(MoneyList& ml) const;
00165 
00167         typedef TransactionList::const_iterator TransactionListCI;
00169         TransactionListCI transactionsBegin() const
00170         {
00171             return transactions_.begin();
00172         }
00174         TransactionListCI transactionsEnd() const
00175         {
00176             return transactions_.end();
00177         }
00178 
00180         MoneyList balanceForward_;
00182         MoneyList currentCharges_;
00183 
00184     private:
00186         TransactionList transactions_;
00187     };                                  // class SummaryCharges
00188 
00195     class AccountInterface {
00196     public:
00198         virtual ~AccountInterface() {}
00210         virtual bool getBalance(
00211             const Associate& associate,
00212             const DateTime&  ts,
00213                   MoneyList& dest) = 0;
00228         virtual long readTransactions(TransactionList& transactions,
00229                                      const Associate& associate,
00230                                      const DateTime& start,
00231                                      const DateTime& end) = 0;
00232 
00239         virtual long getDuedays(
00240             const Associate& associate
00241         ) = 0;
00242 
00255         virtual long writeTransactions(
00256                            const TransactionList& transactions) = 0;
00270         virtual bool writeInvoice(
00271             const Associate&   associate,
00272             const Contract&    contract,
00273             const InvoiceInfo& invInfo
00274         ) = 0;
00275     };          // class AccountInterface
00276 
00283     class GlSummary {
00284     public:
00286         GlSummary() : sequenceNo_(0) {}
00298         void addAmount(
00299             const Account::Oid& accountCode,
00300                   Account::Side side,
00301             const Money&        amount
00302         );
00310         void post(const OSB_DB::Session& s);
00316         void clear();
00317 
00318     private:
00320         struct GlAmounts {
00321             MoneyList credit_;              
00322             MoneyList debit_;               
00323         };
00324 
00326         typedef std::map<Account::Oid, GlAmounts> GlSumBuf;
00327 
00328         GlSumBuf glSumBuf_;         
00329         long sequenceNo_;           
00330     }; // class GlSummary
00331 
00339     class AccountImp : public AccountInterface {
00340     public:
00342         AccountImp(OSB_DB::Session* s) : session_(s){}
00343 
00347         bool getBalance(
00348             const Associate& , // not used: associate,
00349             const DateTime&  , // not used: ts,
00350                   MoneyList&   // not used: dest
00351         )
00352         {
00353             return false;
00354         }
00355 
00359         virtual long readTransactions(
00360                   TransactionList& , // not used: transactions,
00361             const Associate&       , // not used: associate,
00362             const DateTime&        , // not used: start,
00363             const DateTime&          // not used: end
00364         )
00365         {
00366             // Add Sample Data to transactionList
00367             /*
00368              *  Currency::Oid currCode("EUR");
00369              *  Transaction transaction;
00370              *  transaction.date_ = Date(1, Aug, 2001);
00371              *  transaction.detail_ = "Payment by Credit Card";
00372              *  Account account;
00373              *  account.code_ = "xxxx";
00374              *  account.type_ = Assets;
00375              *  transaction.setAccount(account, Money(currCode, -500));
00376              *  transactions.push_back(transaction);
00377              *
00378              *  transaction.date_ = Date(2, Aug, 2001);
00379              *  transaction.detail_ = "Payment by Nets";
00380              *  transaction.setAccount(account, Money(currCode, -99));
00381              *  transactions.push_back(transaction);
00382              */
00383             return 0;
00384         }
00385 
00389         long writeTransactions(
00390             const TransactionList& // not used: transactions
00391         )
00392         {
00393             return 0;
00394         }
00395     private:
00397         OSB_DB::Session* session_;
00398     };                                  // class AccountImp
00399 
00400 }                                       // namespace OSB_LIB
00401 #endif                                  // #ifndef _ACCOUNT_H_

Generated on Sat Sep 2 14:06:31 2006 for OSB Library by  doxygen 1.4.7