appltaxes.h

Go to the documentation of this file.
00001 // OSB library ************************************************ -*- C++ -*-
00006 /*
00007   AUTHOR(S): Andreas Huggel (ahu)
00008              Stephan Broennimann (vb)
00009 
00010   RCS information
00011    $Name: OSB_060808 $
00012    $Revision: 1.34 $
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 _APPLTAXES_H_
00032 #define _APPLTAXES_H_
00033 
00034 // ************************************************************************
00035 // included header files
00036 // + standard includes
00037 #include <iosfwd>
00038 #include <vector>
00039 #include <map>
00040 
00041 // + libraries
00042 
00043 // + local headers
00044 #include "osbid.h"
00045 #include "chargetraits.h"
00046 #include "chrono.h"
00047 
00048 // ************************************************************************
00049 // class declarations
00050 namespace OSB_LIB {
00051     class Tax;
00052     class BaseAmount;
00053 }
00054 
00055 namespace OSB_DB {
00056     class Session;
00057 }
00058 
00059 // ************************************************************************
00060 // namespace extensions
00061 namespace OSB_LIB {
00062 
00063 // ************************************************************************
00064 // forward declarations
00065 
00066 // ************************************************************************
00067 // type definitions
00073     const long TK_WILDCARD = 0;
00074 
00078     enum TK_Types {
00079         tk_associateKey  = 0,
00080         tk_contractKey   = 1,
00081         tk_productKey    = 2,
00082         tk_numberOfTypes = 3
00083     };
00084 
00088     const char tk_type[] = { 'a', 'c', 'p' };
00089 
00090 // ************************************************************************
00091 // class definitions
00092 
00093     struct TaxkeyTriplet {
00094         TaxkeyTriplet() {}
00095         TaxkeyTriplet(TaxKey::Oid& a, TaxKey::Oid& c, TaxKey::Oid& p)
00096             { key[tk_associateKey] = a; key[tk_contractKey] = c;
00097               key[tk_productKey] = p; }
00098         bool operator==(const TaxkeyTriplet&) const;
00099         bool operator<(const TaxkeyTriplet&) const;
00100         friend  std::ostream& operator<<(std::ostream&,
00101                                          const TaxkeyTriplet&);
00102 
00103         TaxKey::Oid key[tk_numberOfTypes];
00104     };
00105 
00106     typedef long                                TaxId;
00107     typedef std::map<TaxIdVs, Tax*>             TaxList;
00108     typedef long                                TaxListId;
00109     typedef std::vector<TaxId>                  TaxIdList;
00110     typedef std::map<TaxListId, TaxIdList>      TaxIdLists;
00111     typedef std::vector<TaxKey::Oid>            TaxKeyIdList;
00112     typedef std::map<TaxkeyTriplet, TaxIdList*> TaxkeyTriplets;
00113 
00120     class ApplicableTaxes {
00122         ApplicableTaxes(const ApplicableTaxes&);
00124         ApplicableTaxes& operator=(const ApplicableTaxes&);
00125     public:
00127         ApplicableTaxes() {}
00128 
00136         const TaxIdList* findTaxIdList(const TaxkeyTriplet& tkt) const;
00137 
00145         const TaxIdList& getTaxIdList(const TaxkeyTriplet& tkt) const;
00146 
00154         const Tax* findTax(const TaxIdVs& vsId) const;
00155 
00163         const Tax& getTax(const TaxIdVs& vsId) const;
00164 
00173         const Tax* findTax(TaxId id, const Date& dt) const
00174             { return findTax(TaxIdVs(TaxId(id), dt)); }
00175 
00184         const Tax& getTax(TaxId id, const Date& dt) const
00185             { return getTax(TaxIdVs(TaxId(id), dt)); }
00186 
00188         void initialise(const OSB_DB::Session& session);
00189 
00191         void taxableAmount(
00192                   MoneyList&,
00193             const BaseAmount&,
00194             const TaxIdList&
00195         ) const;
00196 
00198 
00199         long taxIdListsSize()     { return taxIdLists_.size(); }
00200         long taxkeyTripletsSize() { return taxkeyTriplets_.size(); }
00201         long taxListSize()        { return taxList_.size(); }
00203 
00205 
00206         void writeTaxIdLists(std::ostream&) const;
00207         void writeTaxkeyTriplets(std::ostream&) const;
00208         void writeTaxList(std::ostream&) const;
00210 
00211     private:
00213         TaxIdLists taxIdLists_;
00214 
00219         TaxkeyTriplets taxkeyTriplets_;
00220 
00222         TaxList taxList_;
00223     };                                  // class ApplicableTaxes
00224 
00225     // *****************************************************************
00226     // TheApplicableTaxes
00241     class TheApplicableTaxes {
00242     public:
00249         static ApplicableTaxes& instance();
00250 
00251     private:
00253         TheApplicableTaxes();
00255         TheApplicableTaxes(const TheApplicableTaxes& rhs);
00256 
00258         static ApplicableTaxes* instance_;
00259     };
00260 }                                       // namespace OSB_LIB
00261 #endif                                  // #ifndef _APPLTAXES_H_

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