00001
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035 #ifndef _CHARGETRAITS_H_
00036 #define _CHARGETRAITS_H_
00037
00038
00039
00040 #include <string>
00041
00042
00043 #include "osbid.h"
00044 #include "osbconst.h"
00045 #include "osbutils.h"
00046 #include "money.h"
00047 #include "taxkey.h"
00048
00049
00050
00051 namespace OSB_DB {
00052 class Session;
00053 class ChargeTraitsGw;
00054 }
00055
00056 namespace OSB_LIB {
00057 class RoundRule;
00058 class TaxKey;
00059 class Account;
00060 }
00061
00062
00063
00064 namespace OSB_LIB {
00065
00066
00067
00068 class ChargeTraitsList;
00069
00070
00071
00073 typedef IdPeriod<long> TaxIdVs;
00074
00075
00076
00083 class CtBase {
00089 friend class OSB_DB::ChargeTraitsGw;
00090 friend class ChargeTraitsList;
00091 public:
00095 enum CmStatus { cm_clear, cm_set, cm_grey };
00096 enum CmAttribute { cm_currency, cm_roundRule, cm_accountCode,
00097 cm_numberFormat, cm_chargeType, cm_taxkey,
00098 cm_taxIdVs, cm_lastAttribute };
00099 typedef CmStatus CheckMask[cm_lastAttribute];
00100 public:
00102 typedef Id<CtBase> Oid;
00103 public:
00105 explicit CtBase(const Oid& oid = Oid());
00106
00108 virtual ~CtBase() = 0;
00109
00111
00112 const Oid& oid() const;
00113 const Currency::Oid& currency() const;
00114 const Id<RoundRule>& roundRule() const;
00115 const Id<Account>& accountCode() const;
00116 std::string numberFormat() const;
00117 CmStatus checkMask(CmAttribute a) const;
00119
00125 void setCurrency(const Currency::Oid&);
00126 void setRoundRule(const Id<RoundRule>&);
00127 void setAccountCode(const Id<Account>&);
00128 void setNumberFormat(const std::string&);
00130
00131 protected:
00142 bool match(const CtBase& rhs) const;
00143
00144 protected:
00152 CtBase& operator&=(const CtBase& rhs);
00153
00155 Oid oid_;
00157 Currency::Oid currency_;
00159 Id<RoundRule> roundRule_;
00161 Id<Account> accountCode_;
00163 std::string numberFormat_;
00168 CheckMask checkMask_;
00169 };
00170
00171
00172
00178 class TaxTraits : public CtBase {
00179 public:
00181 explicit TaxTraits(Oid oid =Oid())
00182 : CtBase(oid) {}
00184 ~TaxTraits() {}
00185
00187 void setTaxIdVs(const TaxIdVs&);
00189 TaxIdVs taxIdVs() const { return taxIdVs_; }
00190
00198 TaxTraits& operator&=(const TaxTraits&);
00199
00200 private:
00201 TaxIdVs taxIdVs_;
00202 };
00203
00205 typedef std::map<TaxTraits::Oid, TaxTraits> TaxTraitsList;
00207 typedef TaxTraitsList::iterator TaxTraitsListI;
00208 typedef TaxTraitsList::const_iterator TaxTraitsListCI;
00209
00210
00211
00226 class TheTaxTraitsList {
00227 public:
00234 static TaxTraitsList& instance();
00235
00236 private:
00238 TheTaxTraitsList();
00240 TheTaxTraitsList(const TheTaxTraitsList& rhs);
00241
00243 static TaxTraitsList* instance_;
00244 };
00245
00253 const TaxTraits& getTaxTraits(const TaxTraits::Oid& id);
00254
00255
00256
00262 class ChargeTraits : public CtBase {
00263 public:
00265 explicit ChargeTraits(Oid oid = Oid())
00266 : CtBase(oid) {}
00268 ~ChargeTraits() {}
00269
00270 public:
00272
00273 ChargeType chargeType() const { return chargeType_; }
00274 TaxKey::Oid taxkey() const { return taxkey_; }
00276
00286 bool match(const ChargeTraits& rhs) const;
00287
00289
00290 void setChargeType(const ChargeType&);
00291 void setTaxkey(const TaxKey::Oid&);
00293
00301 ChargeTraits& operator&=(const ChargeTraits&);
00302
00311 bool insert(const OSB_DB::Session& session);
00312
00321 bool remove(const OSB_DB::Session& session);
00322 private:
00327 ChargeType chargeType_;
00333 TaxKey::Oid taxkey_;
00334 };
00335
00336
00337
00349 class ChargeTraitsList {
00350 public:
00352
00353
00354 typedef std::map<ChargeTraits::Oid, ChargeTraits> List;
00356 typedef List::iterator Iterator;
00358 typedef List::const_iterator ConstIterator;
00360 typedef List::size_type SizeType;
00362 typedef List::key_type KeyType;
00364
00366 const List& list() const { return list_; }
00367
00376
00377 Iterator begin() { return list_.begin(); }
00379 Iterator end() { return list_.end(); }
00381 Iterator find(const KeyType& k) { return list_.find(k); }
00383 ConstIterator begin() const { return list_.begin(); }
00385 ConstIterator end() const { return list_.end(); }
00387 ConstIterator find(const KeyType& k) const
00388 { return list_.find(k); }
00390 SizeType size() const { return list_.size(); }
00392
00400 long read(const OSB_DB::Session& session);
00401
00403 bool remove(
00404 OSB_DB::Session& session,
00405 ChargeTraits& ct
00406 );
00407
00419 bool find(ChargeTraits& ct) const;
00420
00431 void getChargeTraits(
00432 OSB_DB::Session& session,
00433 ChargeTraits& ct
00434 );
00435
00444 const ChargeTraits* findChargeTraits(
00445 const ChargeTraits::Oid& id
00446 ) const;
00447
00456 const ChargeTraits& getChargeTraits(
00457 const ChargeTraits::Oid& id
00458 ) const;
00459
00460 private:
00472 ChargeTraits::Oid findMatch(
00473 const ChargeTraits& ct
00474 ) const;
00475
00481 void add(const ChargeTraits& ct);
00482
00485 List list_;
00486 };
00487 }
00488 #endif // #ifndef _CHARGETRAITS_H_