00001
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031 #ifndef _APPLTAXES_H_
00032 #define _APPLTAXES_H_
00033
00034
00035
00036
00037 #include <iosfwd>
00038 #include <vector>
00039 #include <map>
00040
00041
00042
00043
00044 #include "osbid.h"
00045 #include "chargetraits.h"
00046 #include "chrono.h"
00047
00048
00049
00050 namespace OSB_LIB {
00051 class Tax;
00052 class BaseAmount;
00053 }
00054
00055 namespace OSB_DB {
00056 class Session;
00057 }
00058
00059
00060
00061 namespace OSB_LIB {
00062
00063
00064
00065
00066
00067
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
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 };
00224
00225
00226
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 }
00261 #endif // #ifndef _APPLTAXES_H_