00001
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042
00043
00044
00045
00046
00047
00048
00049
00050 #ifndef _PRICELIST_H_
00051 #define _PRICELIST_H_
00052
00053
00054
00055
00056 #include <string>
00057 #include <list>
00058 #include <map>
00059 #include <iosfwd>
00060
00061
00062 #include "osbid.h"
00063 #include "chrono.h"
00064 #include "chargetraits.h"
00065 #include "decimal.h"
00066 #include "status.h"
00067 #include "osbunit.h"
00068
00069
00070
00071 namespace OSB_DB {
00072 class PricelistGw;
00073 }
00074
00075
00076 namespace OSB_LIB {
00077 class ProductCatalogue;
00078 }
00079
00080
00081
00082 namespace OSB_LIB {
00083
00084
00085
00086
00093 struct SubsChargeDef {
00094 typedef Id<SubsChargeDef> Oid;
00095
00097 SubsChargeDef(const Oid&,
00098 const Status&,
00099 const Decimal&,
00100 const ChargeTraits::Oid&);
00101
00102 Oid id;
00103 Status status;
00104 Decimal charge;
00105 ChargeTraits::Oid ctId;
00106 };
00107
00114 enum SubsFuncType { sfSubFuncOnce = 1 };
00115
00127 class SubsFuncCfg {
00128 friend class OSB_DB::PricelistGw;
00129 friend class ProductCatalogue;
00130 protected:
00131 typedef std::list<SubsChargeDef> ChargeList;
00132 public:
00133 typedef Id<SubsFuncCfg> Oid;
00134
00135 SubsFuncCfg(const Oid& id, SubsFuncType sft) :
00136 id_(id), name_(), des_(), sfType_(sft),
00137 status_('\0'), periodLength_(0) {}
00139 virtual ~SubsFuncCfg() {}
00140
00142 const Oid& oid() const { return id_; }
00144 const std::string& name() const { return name_; }
00145
00147 SubsFuncType sfType() const { return sfType_; }
00148
00150 uint periodLength() const { return periodLength_; }
00151 Unit::Oid unitId() const { return unitId_; }
00152
00154 void addSubsChargeDef(const SubsChargeDef&);
00155 void delSubsChargeDef(const SubsChargeDef::Oid&);
00156
00158 const SubsChargeDef*
00159 findSubsChargeDef(const SubsChargeDef::Oid&) const;
00160
00162 const SubsChargeDef*
00163 findSubsChargeDef(const Status&) const;
00164
00166 const SubsChargeDef*
00167 findSubsChargeDef(const StatusValue& sv) const
00168 {
00169 StatusReason::Oid reason;
00170 return findSubsChargeDef(Status(sv, reason));
00171 }
00172
00173 protected:
00175 SubsFuncCfg(const SubsFuncCfg& rhs) :
00176 id_(rhs.id_), charges_(rhs.charges_) {}
00177
00178 protected:
00179 Oid id_;
00180 std::string name_;
00181 std::string des_;
00182 SubsFuncType sfType_;
00183
00184 char status_;
00185 uint periodLength_;
00186 Unit::Oid unitId_;
00187
00188 ChargeList charges_;
00189
00190 private:
00192 SubsFuncCfg& operator=(const SubsFuncCfg& rhs);
00193
00194
00195 public:
00196 friend std::ostream&
00197 operator<<(std::ostream&,
00198 const SubsFuncCfg&);
00199 virtual std::ostream& prInfo(std::ostream&) const;
00200 };
00201
00206 typedef std::vector<SubsFuncCfg*> SubsFuncCfgs;
00207
00218 class OnetimeChargeDef {
00220 friend class OSB_DB::PricelistGw;
00221 public:
00223 typedef Id<OnetimeChargeDef> Oid;
00224
00226 OnetimeChargeDef() {}
00227
00228 OnetimeChargeDef(
00229 const Oid& oid,
00230 const Decimal& charge,
00231 const ChargeTraits::Oid& ctId
00232 ) : id_(oid), charge_(charge), ctId_(ctId) {}
00233
00234 bool operator==(const OnetimeChargeDef& rhs) const
00235 {
00236 return id_ == rhs.id_;
00237 }
00238
00239 bool operator==(const Oid& id) const { return id_ == id; }
00240
00241 bool operator <(const OnetimeChargeDef& rhs) const
00242 {
00243 return id_ < rhs.id_;
00244 }
00245
00246 bool operator<(const Oid& id) const { return id_ < id; }
00247
00249 const Oid& oid() const { return id_; }
00250
00252 Decimal charge() const { return charge_; }
00253
00255 const ChargeTraits::Oid& ctId() const { return ctId_; }
00256
00258 void setCharge(const Decimal& charge);
00259
00261 void setChargeTraitsId(
00262 const ChargeTraits::Oid& ctId
00263 );
00264
00271 bool read(const OSB_DB::Session& session);
00272
00280 bool insert(const OSB_DB::Session& session);
00281 private:
00282 Oid id_;
00283 Decimal charge_;
00284 ChargeTraits::Oid ctId_;
00285 };
00286
00296 class EventCharges {
00298 friend class OSB_DB::PricelistGw;
00299 public:
00301 enum EventId {
00302 eventUnknown = 0,
00303 eventBilling = 1
00304 };
00305
00313 static EventId toEventId(long ei);
00314
00322 static long toLong(EventId ei);
00323
00325 typedef std::list<OnetimeChargeDef::Oid> ChargeList;
00326
00328 typedef std::map<EventId, ChargeList> EventChargeList;
00329 public:
00331 EventCharges() : chargeList_() {}
00332
00334 int addEventCharge(
00335 EventId eventId,
00336 const OnetimeChargeDef::Oid& ocd);
00337
00339 int removeEventCharge(EventId eventId);
00340
00342 const EventChargeList& eventChargeList() const
00343 {
00344 return chargeList_;
00345 }
00346 private:
00348 EventChargeList chargeList_;
00349 };
00350
00355 class Pricelist {
00357 friend class ProductCatalogue;
00359 friend class OSB_DB::PricelistGw;
00360 public:
00362 typedef Id<Pricelist> Oid;
00363
00365 Pricelist() {}
00366
00368 Pricelist(
00369 const Oid& id,
00370 const std::string& name,
00371 const std::string& des
00372 ) : id_(id), name_(name), des_(des), objVs_(0) {}
00373
00375
00376
00377 const Oid& oid() const { return id_; }
00379 const std::string& name() const { return name_; }
00381 const std::string& desc() const { return des_; }
00383 long objVs() const { return objVs_; }
00385
00387
00388
00389 void setName(const std::string& name) { name_ = name; }
00391 void setDesc(const std::string& desc) { des_ = desc; }
00393 private:
00395 void checkObjVs(const OSB_DB::Session& session);
00396
00403 bool read(const OSB_DB::Session& session);
00404
00411 bool insert(const OSB_DB::Session& session);
00412
00419 bool update(const OSB_DB::Session& session);
00420
00427 bool remove(const OSB_DB::Session& session);
00428 private:
00429 Oid id_;
00430 std::string name_;
00431 std::string des_;
00432 long objVs_;
00433 };
00434
00436 typedef std::vector<Pricelist> Pricelists;
00437
00445 class PricelistCfg {
00447 friend class ProductCatalogue;
00449 friend class OSB_DB::PricelistGw;
00450
00451 public:
00453 typedef std::list<OnetimeChargeDef> OnetimeChargeDefs;
00454
00456 typedef Id<Pricelist> PricelistId;
00457
00459 typedef Id2<PricelistCfg> Oid;
00460
00462 explicit PricelistCfg(const Oid&, const std::string& name = "");
00463 ~PricelistCfg() {}
00464
00465 public:
00470 const Oid& oid() const { return id_; }
00471
00473 const std::string& name() const { return name_; }
00474
00476 long objVs() const { return objVs_; }
00477
00479 const EventCharges& eventCharges() const { return eventCharges_; }
00480
00482 CfgStatus status() const { return status_; }
00483
00485 const Date& releaseDate() const { return releaseDate_; }
00486
00488 const PricelistId pricelistId() const
00489 {
00490 return PricelistId(id_.id1_);
00491 }
00492
00494 const SubsFuncCfg::Oid subsFuncCfgId() const
00495 {
00496 return subsFuncCfgId_;
00497 }
00498
00500 const OnetimeChargeDef* findOnetimeChargeDef(
00501 const OnetimeChargeDef::Oid& chargeId
00502 ) const;
00503
00505 const OnetimeChargeDefs& getOnetimeChargeDefs() const
00506 {
00507 return onetimeCharges_;
00508 }
00509
00511 OnetimeChargeDefs& onetimeChargeDefs()
00512 {
00513 return onetimeCharges_;
00514 }
00515
00520 void setSubsFuncCfg(const SubsFuncCfg::Oid pCfg)
00521 {
00522 subsFuncCfgId_ = pCfg;
00523 }
00524
00526 bool addOnetimeChargeDef(
00527 OSB_DB::Session& session,
00528 OnetimeChargeDef& otc);
00529
00531 int removeEventCharge(EventCharges::EventId eventId);
00532
00534 int addEventCharge(EventCharges::EventId eventId,
00535 const OnetimeChargeDef::Oid& chargeId);
00536 private:
00538 void checkObjVs(const OSB_DB::Session& session);
00539
00546 bool read(const OSB_DB::Session& session);
00547
00555 bool insert(const OSB_DB::Session& session);
00556
00564 bool update(const OSB_DB::Session& session);
00565
00578 bool remove(const OSB_DB::Session& session);
00579
00588 bool check(const OSB_DB::Session& session);
00589
00598 bool release(const OSB_DB::Session& session);
00599
00608 bool revoke(const OSB_DB::Session& session);
00609
00618 bool unfreeze(const OSB_DB::Session& session);
00619 private:
00620 Oid id_;
00621
00622 std::string name_;
00623 long objVs_;
00624 SubsFuncCfg::Oid subsFuncCfgId_;
00625 CfgStatus status_;
00626
00627 Date releaseDate_;
00629 OnetimeChargeDefs onetimeCharges_;
00631 EventCharges eventCharges_;
00632 };
00633
00635 typedef std::vector<PricelistCfg> PricelistCfgs;
00636
00637
00638
00639 inline bool operator==(const OnetimeChargeDef::Oid& id,
00640 const OnetimeChargeDef& rhs)
00641 {
00642 return rhs == id;
00643 }
00644
00645 inline bool operator<(const OnetimeChargeDef::Oid& id,
00646 const OnetimeChargeDef& rhs)
00647 {
00648
00649 return !(rhs == id || rhs < id);
00650 }
00651
00652 }
00653 #endif // #ifndef _PRICELIST_H_