invoice.h

Go to the documentation of this file.
00001 // OSB library ********************************************* -*- C++ -*-
00024 /*
00025   AUTHOR(S): Andreas Huggel (ahu)
00026 
00027   RCS information
00028    $Name: OSB_060808 $
00029    $Revision: 1.83 $
00030 
00031   License
00032    OSB rating and billing library for communication networks
00033    Copyright (C) 2004, 2005, 2006  OSB systems
00034 
00035    This file may be distributed and/or modify under the terms of the
00036    GNU General Public License (GPL) as published by the Free Software
00037    Foundation which is provided in the file LICENSE.GPL included in the
00038    packaging of this file.
00039 
00040    The file is distributed in the hope that it will be useful, but WITHOUT
00041    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00042    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00043    for more details.
00044 
00045    Holders of a OSB Commercial License may use this file under the terms
00046    and conditions of this commercial license.
00047  */
00048 #ifndef _INVOICE_H_
00049 #define _INVOICE_H_
00050 
00051 // *********************************************************************
00052 // included header files
00053 // + standard includes
00054 #include<vector>
00055 
00056 // + local headers
00057 #include "chargetraits.h"
00058 #include "amount.h"
00059 #include "section.h"
00060 #include "contract.h"
00061 #include "product.h"
00062 #include "balancesheet.h"
00063 #include "billingxml.h"
00064 #include "osbunit.h"
00065 
00066 // *********************************************************************
00067 // namespace extensions
00068 namespace OSB_LIB {
00069 
00070     // forward declarations
00071     class Invoice;
00072     class UsageItemBase;
00073     class UsageDetailBase;
00074     class SubsItem;
00075     class TotalItem;
00076     class AssociateInfo;
00077     class SummaryChargesInfo;
00078     class InvoiceInfoItem;
00079     class OnetimeChargeItem;
00080     class BillingXmlBase;
00081     class BillingXml;
00082 
00083 // *********************************************************************
00084 // class definitions
00090     enum ContributesTo
00091     {
00092         ct_nothing    =   0,
00093         ct_invAmounts =   1,
00094         ct_invTotal   =   2,
00095         ct_usgTotal   =   4,
00096         ct_otcTotal   =   8,
00097         ct_subsTotal  =  16
00098     };
00099 
00105     enum TotalContributesTo
00106     {
00107         ct_subTotalOnly = 0,
00108         ct_volumeTotal  = 1
00109     };
00110 
00117     class InvoiceItem {
00119         InvoiceItem(const InvoiceItem& rhs);
00121         InvoiceItem& operator=(const InvoiceItem& rhs);
00122     public:
00128         InvoiceItem(const Section& section)
00129             : section_(section), number_(0) {}
00131         virtual ~InvoiceItem() {}
00152         virtual void writeXml(BillingXmlBase& bXml) const=0;
00158         void setNumber(int n) { number_ = n; }
00164         const Section& section() { return section_; }
00165 
00166     protected:
00169         Section section_;
00170 
00171     private:
00174         int number_;
00175     };
00196     class ItemMap {
00197         ItemMap(const ItemMap&);
00198         ItemMap& operator=(const ItemMap&);
00199     public:
00200         ItemMap() {}
00201         ~ItemMap();
00202 
00203         struct Node {
00204             Node() {}
00205             virtual ~Node() {}
00206             struct Iterator {
00207                 Iterator() {}
00208                 virtual ~Iterator() {}
00209                 virtual void increment() =0;
00210                 virtual Iterator* clone() const =0;
00211                 virtual InvoiceItem* operator*() const =0;
00212                 bool operator==(const Iterator& i) const
00213                 {
00214                     return this->operator*() == *i;
00215                 }
00216             };
00217             virtual Iterator* newIterator() const =0;
00218             virtual void mrproper() =0;
00219             virtual void pbegin(Iterator*) =0;
00220             virtual void pend(Iterator*) =0;
00221         };
00222         // -------------------------------------------------------------
00224         struct Node1 : public Node {
00225             Node1(InvoiceItem* ii) : Node(), invoiceItem_(ii) {}
00227             ~Node1() {}
00228 
00229             struct Iterator : public Node::Iterator {
00230                 Iterator() {}
00231                 explicit Iterator(InvoiceItem* ii) : current_(ii) {}
00232                 void increment() { ++current_; }
00233                 Iterator* clone() const { return new Iterator(*this); };
00234                 InvoiceItem* operator*() const { return current_; }
00235                 InvoiceItem* current_;
00236             };
00237             Iterator* newIterator() const { return new Iterator(); }
00238             void mrproper() { delete invoiceItem_; invoiceItem_ = 0; }
00239             void pbegin(Node::Iterator* ip)
00240             {
00241                 *static_cast<Node1::Iterator*>(ip)
00242                     = Iterator(invoiceItem_);
00243             }
00244             void pend(Node::Iterator* ip)
00245             {
00246                 *static_cast<Node1::Iterator*>(ip)
00247                     = Iterator(invoiceItem_+1);
00248             }
00249             InvoiceItem* invoiceItem_;
00250         };
00251         // -------------------------------------------------------------
00253         template <typename T>
00254           struct NodeM : public Node {
00255             NodeM() {}
00256             NodeM(const T& t, InvoiceItem* ii) { items_[t] = ii; }
00258             ~NodeM() {}
00259             // ---------------------------------------------------------
00260             typedef std::multimap<T, InvoiceItem*> Items;
00261             // ---------------------------------------------------------
00262             struct Iterator : public Node::Iterator {
00263                 Iterator() {}
00264                 explicit Iterator(const typename Items::iterator& ii)
00265                     : current_(ii) {}
00266                 void increment() { ++current_; }
00267                 Iterator* clone() const { return new Iterator(*this); }
00268                 InvoiceItem* operator*() const
00269                 {
00270                     return current_->second;
00271                 }
00272                 typename Items::iterator current_;
00273             };
00274             Iterator* newIterator() const { return new Iterator(); }
00275             void mrproper()
00276             {
00277                 for (typename Items::iterator i = items_.begin();
00278                      i != items_.end(); ++i) {
00279                     delete i->second;
00280                     i->second = 0;
00281                 }
00282             }
00283             void pbegin(Node::Iterator* ip)
00284             {
00285                 *static_cast<typename NodeM<T>::Iterator*>(ip)
00286                       = Iterator(items_.begin());
00287             }
00288             void pend(Node::Iterator* ip)
00289             {
00290                 *static_cast<typename NodeM<T>::Iterator*>(ip)
00291                       = Iterator(items_.end());
00292             }
00293 
00294             Items items_;
00295         };
00296         // -------------------------------------------------------------
00297         typedef std::map<Section, Node*> NodeList;
00298         // -------------------------------------------------------------
00299 
00312         struct Iterator {
00313             Iterator() : sub_(0), end_(0) {}
00314             explicit Iterator(const NodeList::iterator& nli)
00315                 : current_(nli), sub_(0), end_(0) {}
00316             ~Iterator() { if(sub_) delete sub_; if(end_) delete end_; }
00317             Iterator(const Iterator& rhs);
00318             Iterator& operator=(const Iterator& rhs);
00319             bool operator==(const Iterator& rhs) const;
00320             bool operator!=(const Iterator& rhs) const;
00321             Iterator operator++();
00322             Iterator operator++(int);
00323             InvoiceItem* operator*() const;
00324 
00325             NodeList::iterator current_;
00327             mutable Node::Iterator* sub_;
00328             Node::Iterator* end_;
00329         };
00330 
00331         Iterator begin() { return Iterator(nodeList_.begin()); }
00332         Iterator end() { return Iterator(nodeList_.end()); }
00333 
00334         int insert(const Section& s, InvoiceItem* ii);
00335         template<typename T>
00336           int insert(const Section& s, const T& t, InvoiceItem* ii);
00337         Iterator find(const Section& s)
00338         {
00339             return Iterator(nodeList_.find(s));
00340         }
00341 
00342     private:
00343         NodeList nodeList_;
00344     };
00345 
00346     // *****************************************************************
00353     class Invoice {
00355         Invoice(const Invoice&);
00357         Invoice& operator=(const Invoice&);
00358     public:
00360         Invoice() : count_(0) {}
00362         ~Invoice() {}
00363 
00371         void addAmount(BaseAmount& a, ContributesTo flags);
00372 
00374         void setNumber(InvoiceItem& ii) { ii.setNumber(++count_); }
00375 
00377 
00378         const Subtotal& invoiceTotal() const { return invoiceTotal_; }
00379         const Subtotal& usageTotal() const { return usageTotal_; }
00380         const Subtotal& subsTotal() const { return subsTotal_; }
00381         const Subtotal& onetimeChargesTotal() const
00382             { return onetimeChargesTotal_; }
00384         // -------------------------------------------------------------
00392 
00393         template <typename U>
00394          U* newUsageItem(
00395             const Section& section,
00396             ContributesTo flag
00397          );
00398 
00399         // This function is provided to avoid errors in Forte Compiler.
00400         template <typename U>
00401          U* newUsageItem(
00402             const Section& section
00403          );
00404 
00407         template <typename U, typename T>
00408           U* newUsageItem(
00409             const Section& section,
00410             const T& t,
00411             ContributesTo flag
00412           );
00413 
00414         // This function is provided to avoid errors in Forte Compiler.
00415         template <typename U, typename T>
00416           U* newUsageItem(
00417             const Section& section,
00418             const T& t
00419           );
00420         // -------------------------------------------------------------
00422         SubsItem *newSubsItem(
00423             const Section&,
00424             const SubsCharge*,
00425                   ContributesTo =
00426                     ContributesTo(ct_invAmounts|ct_invTotal|
00427                                   ct_subsTotal)
00428         );
00429 
00432         template <typename T>
00433           SubsItem *newSubsItem(
00434             const Section&,
00435             const T&,
00436             const SubsCharge*,
00437                   ContributesTo
00438           );
00439 
00440         // This function is provided to avoid errors in Forte Compiler.
00441         template <typename T>
00442           SubsItem *newSubsItem(
00443             const Section&,
00444             const T&,
00445             const SubsCharge*
00446           );
00447         // -------------------------------------------------------------
00449         OnetimeChargeItem *newOnetimeChargeItem(
00450             const Section&,
00451             const OnetimeCharge*,
00452                   ContributesTo =
00453                         ContributesTo(ct_invAmounts|ct_invTotal|
00454                                       ct_otcTotal)
00455         );
00456 
00459         template <typename T>
00460           OnetimeChargeItem *newOnetimeChargeItem(
00461             const Section&,
00462             const T&,
00463             const OnetimeCharge*,
00464                   ContributesTo
00465           );
00466 
00467         // This function is provided to avoid errors in Forte Compiler.
00468         template <typename T>
00469           OnetimeChargeItem *newOnetimeChargeItem(
00470             const Section&,
00471             const T&,
00472             const OnetimeCharge*
00473           );
00474 
00475         // -------------------------------------------------------------
00477         TotalItem* newTotalItem(
00478             const Section&   section,
00479                   Decimal&   volume,
00480             const Unit::Oid& uId,
00481                   ContributesTo flags = ContributesTo(ct_nothing)
00482         );
00483 
00486         template <typename T>
00487           TotalItem* newTotalItem(
00488             const Section& section,
00489             const T&            t,
00490                   Decimal&      volume,
00491             const Unit::Oid&    uId,
00492                   ContributesTo flags
00493         );
00494 
00495         template <typename T>
00496           TotalItem* newTotalItem(
00497             const Section&   section,
00498             const T&         t,
00499                   Decimal&   volume,
00500             const Unit::Oid& uId
00501         );
00502 
00503         // -------------------------------------------------------------
00505         AssociateInfo* newAssociateInfo(
00506             const Section& section,
00507             const Associate* associate
00508         );
00509 
00512         template <typename T>
00513           AssociateInfo* newAssociateInfo(
00514             const Section& section,
00515             const T& t,
00516             const Associate* associate
00517         );
00518 
00520         SummaryChargesInfo* newSummaryChargesInfo(
00521             const Section& section,
00522             const SummaryCharges* sumCharges
00523         );
00524 
00527         template <typename T>
00528         SummaryChargesInfo* newSummaryChargesInfo(
00529             const Section& section,
00530             const T& t,
00531             const SummaryCharges* sumCharges
00532         );
00533 
00535         InvoiceInfoItem* newInvoiceInfoItem(
00536             const Section& section,
00537             const InvoiceInfo* invInfo
00538         );
00539 
00542         template <typename T>
00543         InvoiceInfoItem* newInvoiceInfoItem(
00544             const Section& section,
00545             const T& t,
00546             const InvoiceInfo* invInfo
00547         );
00549 
00550         // -------------------------------------------------------------
00558         typedef ItemMap::Iterator ItemListI;
00559         ItemListI  itemListBegin()       { return items_.begin(); }
00560         ItemListI  itemListEnd()         { return items_.end(); }
00561         ItemMap::Iterator findItem(const Section& s)
00562         {
00563             return items_.find(s);
00564         }
00566 
00568 
00569         typedef std::vector<SubsItem*> SubsItemList;
00570         typedef SubsItemList::const_iterator SubsItemListCI;
00571         typedef SubsItemList::iterator SubsItemListI;
00572         SubsItemListCI SubsItemListBegin() const
00573             { return subsItems_.begin(); }
00574         SubsItemListI SubsItemListBegin()
00575             { return subsItems_.begin(); }
00576         SubsItemListCI SubsItemListEnd() const
00577             { return subsItems_.end(); }
00578         SubsItemListI SubsItemListEnd()
00579             { return subsItems_.end(); }
00581 
00583 
00584         typedef std::vector<OnetimeChargeItem*> OnetimeChargeItemList;
00585         typedef OnetimeChargeItemList::const_iterator
00586                                        OnetimeChargeItemListCI;
00587         typedef OnetimeChargeItemList::iterator OnetimeChargeItemListI;
00588         OnetimeChargeItemListCI onetimeChargeItemListBegin() const
00589             { return onetimeChargeItems_.begin(); }
00590         OnetimeChargeItemListI onetimeChargeItemListBegin()
00591             { return onetimeChargeItems_.begin(); }
00592         OnetimeChargeItemListCI onetimeChargeItemListEnd() const
00593             { return onetimeChargeItems_.end(); }
00594         OnetimeChargeItemListI onetimeChargeItemListEnd()
00595             { return onetimeChargeItems_.end(); }
00597 
00599 
00600         typedef std::vector<BaseAmount*> AmountList;
00601         typedef AmountList::const_iterator AmountListCI;
00602         typedef AmountList::iterator AmountListI;
00603 
00604         AmountListCI amountListBegin() const
00605             { return invoiceAmounts_.begin(); }
00606         AmountListI amountListBegin()
00607             { return invoiceAmounts_.begin(); }
00608         AmountListCI amountListEnd() const
00609             { return invoiceAmounts_.end(); }
00610         AmountListI amountListEnd()
00611             { return invoiceAmounts_.end(); }
00613     private:
00615         int count_;
00617         ItemMap items_;
00619         SubsItemList subsItems_;
00621         OnetimeChargeItemList onetimeChargeItems_;
00623         AmountList invoiceAmounts_;
00625         Subtotal invoiceTotal_;
00627         Subtotal usageTotal_;
00629         Subtotal subsTotal_;
00631         Subtotal totalTotal_;
00633         Subtotal onetimeChargesTotal_;
00634     };
00635 
00636     // *****************************************************************
00637     // UsageItem and UsageDetail Base Class
00638 
00647     class UsageItemBase : public InvoiceItem {
00649         UsageItemBase(const UsageItemBase& rhs);
00651         UsageItemBase& operator=(const UsageItemBase& rhs);
00652     public:
00654         typedef std::vector<UsageDetailBase*> UsageDetailList;
00655         typedef UsageDetailList::const_iterator UsageDetailListCI;
00656         typedef UsageDetailList::iterator UsageDetailListI;
00657 
00663         UsageItemBase(const Section& section) : InvoiceItem(section) {}
00664 
00671         UsageItemBase(
00672             const Section& section,
00673             const ChargeTraits& ct
00674         ) : InvoiceItem(section), amount(ct) {}
00675 
00677         virtual ~UsageItemBase() {}
00678 
00691         virtual void writeXml(BillingXmlBase& bXml) const = 0;
00692 
00693         // -------------------------------------------------------------
00694         // public data members
00696         Subtotal amount;
00698         UsageDetailList details;
00699     };
00700 
00707     class UsageDetailBase {
00708     public:
00710         UsageDetailBase() : amount() {}
00712         UsageDetailBase(const Amount& a) : amount(a) {}
00714         virtual ~UsageDetailBase() {}
00715 
00727         virtual void writeXml(BillingXmlBase& bXml) const = 0;
00729         Amount amount;
00730     };
00731 
00732     // *****************************************************************
00733     // UsageItem and UsageDetail to handle Usagerecord
00734 
00741     class UsagerecordItem : public UsageItemBase {
00742     public:
00748         UsagerecordItem(const Section& section)
00749               : UsageItemBase(section) {}
00750 
00757         UsagerecordItem(
00758             const Section& section,
00759             const ChargeTraits& ct
00760         ) : UsageItemBase(section, ct) {}
00761 
00763         ~UsagerecordItem();
00774         virtual void writeXml(BillingXmlBase& bXml) const
00775         {
00776             dynamic_cast<BillingXml&>(bXml).writeUsagerecordItem(*this);
00777         }
00778 
00786         UsagerecordDetail* newUsagerecordDetail(const Usagerecord* ur);
00787 
00795         UsagerecordDetail* newUsagerecordDetail(
00796             const Amount& a,
00797             const Usagerecord* ur
00798         );
00799     };
00800 
00801     // *****************************************************************
00802     // UsageItem and UsageDetail to handle SumCdr01
00803 
00810     class SumCdr01Item : public UsageItemBase {
00811     public:
00817         SumCdr01Item(const Section& section)
00818               : UsageItemBase(section) {}
00819 
00826         SumCdr01Item(
00827             const Section& section,
00828             const ChargeTraits& ct
00829         ) : UsageItemBase(section, ct) {}
00830 
00832 
00849         ~SumCdr01Item();
00860         virtual void writeXml(BillingXmlBase& bXml) const
00861         {
00862             dynamic_cast<SumCdr01BillingXml&>(bXml).
00863                 writeSumCdr01Item(*this);
00864         }
00865 
00873         SumCdr01Detail* newSumCdr01Detail(
00874             const SumCdr01* cdr
00875         );
00876 
00884         SumCdr01Detail* newSumCdr01Detail(
00885             const Amount& a,
00886             const SumCdr01* cdr
00887         );
00888     };
00889 
00893     class SumCdr01Detail : public UsageDetailBase {
00894     public:
00896         SumCdr01Detail(
00897             const SumCdr01* cdr =0
00898         ) : UsageDetailBase(), cmCdr(cdr) {}
00899 
00901         SumCdr01Detail(const Amount& a, const SumCdr01* cdr)
00902             : UsageDetailBase(a), cmCdr(cdr) {}
00903 
00915         virtual void writeXml(BillingXmlBase& bXml) const
00916         {
00917             dynamic_cast<SumCdr01BillingXml&>(bXml).
00918                 writeSumCdr01Detail(*this);
00919         }
00921         const SumCdr01* cmCdr;
00922     };
00923 
00924 
00925     // *****************************************************************
00929     class UsagerecordDetail : public UsageDetailBase {
00930     public:
00932         UsagerecordDetail(
00933             const Usagerecord* ur =0
00934         ) : UsageDetailBase(), usagerecord(ur) {}
00935 
00937         UsagerecordDetail(const Amount& a, const Usagerecord* ur)
00938             : UsageDetailBase(a), usagerecord(ur) {}
00939 
00951         virtual void writeXml(BillingXmlBase& bXml) const
00952         {
00953             dynamic_cast<BillingXml&>(bXml).writeUsagerecordDetail(*this);
00954         }
00956         const Usagerecord* usagerecord;
00957     };
00958 
00962     class SubsItem : public InvoiceItem {
00963     public:
00964         SubsItem(const Section& section, const SubsCharge* sc)
00965               : InvoiceItem(section), subsCharge(sc) {}
00966 
00967         virtual void writeXml(BillingXmlBase& bXml) const
00968         {
00969             dynamic_cast<BillingXml&>(bXml).writeSubsItem(*this);
00970         }
00971 
00972         // -------------------------------------------------------------
00973         // public data members
00974         Amount amount;
00975         const SubsCharge* subsCharge;
00976     };
00977 
00978     // *****************************************************************
00980     class OnetimeChargeItem : public InvoiceItem {
00981     public:
00982         OnetimeChargeItem(const Section& section,
00983                           const OnetimeCharge* onetimeCharge):
00984             InvoiceItem(section), onetimeCharge(onetimeCharge) {}
00985 
00986         virtual void writeXml(BillingXmlBase& bXml) const
00987         {
00988             dynamic_cast<BillingXml&>(bXml).writeOtcItem(*this);
00989         }
00990 
00991         // -------------------------------------------------------------
00992         // public data members
00993         Amount         amount;
00994         const OnetimeCharge* onetimeCharge;
00995     };
00996 
01006     class TotalItem : public InvoiceItem {
01007     public:
01008         TotalItem(
01009             const Section&   section,
01010             const Decimal&   vol,
01011             const Unit::Oid& uId
01012         ) : InvoiceItem(section), volume_(vol), unitId_(uId) {}
01013 
01014         virtual void writeXml(BillingXmlBase& bXml) const
01015         {
01016             dynamic_cast<BillingXml&>(bXml).writeTotalItem(*this);
01017         }
01018 
01019         // -------------------------------------------------------------
01020         // public data members
01021         Subtotal amount_;
01022         //TODO: It should be able to handle more than one unit
01023         Decimal     volume_;
01024         Unit::Oid   unitId_;
01025         std::string remark_;
01026     };
01027 
01028     // *****************************************************************
01041     class AssociateInfo : public InvoiceItem {
01042     public:
01043         AssociateInfo(const Section& section, const Associate* ass)
01044             : InvoiceItem(section), associate(ass) {}
01045 
01046         virtual void writeXml(BillingXmlBase& bXml) const
01047         {
01048             dynamic_cast<BillingXml&>(bXml).writeAssociate(*associate);
01049         }
01050         // -------------------------------------------------------------
01051         // public data members
01052         const Associate* associate;
01053     };
01054 
01055     class SummaryChargesInfo : public InvoiceItem {
01056     public:
01057         SummaryChargesInfo(
01058             const Section& section,
01059             const SummaryCharges* sc
01060         ) : InvoiceItem(section), summaryCharges(sc) {}
01061 
01062         virtual void writeXml(BillingXmlBase& bXml) const
01063         {
01064             dynamic_cast<BillingXml&>(bXml).writeSummaryCharges(
01065                 *summaryCharges);
01066         }
01067         // -------------------------------------------------------------
01068         // public data members
01069         const SummaryCharges* summaryCharges;
01070     };
01071 
01072     class InvoiceInfoItem : public InvoiceItem {
01073     public:
01074         InvoiceInfoItem(
01075             const Section& section,
01076             const InvoiceInfo* invInfo
01077         ) : InvoiceItem(section), invoiceInfo(invInfo) {}
01078 
01079         virtual void writeXml(BillingXmlBase& bXml) const
01080         {
01081             dynamic_cast<BillingXml&>(bXml).writeInvoiceInfo(
01082                 *invoiceInfo);
01083         }
01084         // -------------------------------------------------------------
01085         // public data members
01086         const InvoiceInfo* invoiceInfo;
01087     };
01088 
01089 //**********************************************************************
01090 // inline and template definitions
01091 
01092     template<typename T>
01093       int ItemMap::insert(const Section& s, const T& t, InvoiceItem* ii)
01094     {
01095         int rc = 0;
01096         NodeList::iterator nI = nodeList_.find(s);
01097         if (nI == nodeList_.end()) {
01098             Node* np = new NodeM<T>;
01099             nI = nodeList_.insert(std::make_pair(s, np)).first;
01100         }
01101         if (NodeM<T>* nmp = dynamic_cast<NodeM<T>*>(nI->second)) {
01102             nmp->items_.insert(std::make_pair(t, ii));
01103         }
01104         else {
01105             // Section does not have a NodeM<T>. Indicate failure
01106             rc = 1;
01107         }
01108         return rc;
01109     }
01110 
01111     template <typename U>
01112      U* Invoice::newUsageItem(
01113         const Section& section,
01114               ContributesTo flags
01115     )
01116     {
01117         U* ui = new U(section);
01118         int rc = items_.insert(section, ui);
01119         if (rc) {
01120             delete ui;
01121             throw DefException(26) << section.str();
01122         }
01123         setNumber(*ui);
01124         addAmount(ui->amount, flags);
01125         return ui;
01126     }
01127 
01128     template <typename U>
01129      U* Invoice::newUsageItem(
01130         const Section& section
01131     )
01132     {
01133         return newUsageItem<U>(section, ContributesTo(
01134                         ct_invAmounts|ct_invTotal|ct_usgTotal));
01135     }
01136 
01137     template <typename U, typename T>
01138      U* Invoice::newUsageItem(
01139         const Section& section,
01140         const T& t,
01141               ContributesTo flags
01142     )
01143     {
01144         U* ui = new U(section);
01145         int rc = items_.insert(section, t, ui);
01146         if (rc) {
01147             delete ui;
01148             throw DefException(29) << section.str();
01149         }
01150         setNumber(*ui);
01151         addAmount(ui->amount, flags);
01152         return ui;
01153     }
01154 
01155     template <typename U, typename T>
01156      U* Invoice::newUsageItem(
01157         const Section& section,
01158         const T& t
01159     )
01160     {
01161         return newUsageItem<U, T>(section, t, ContributesTo(
01162                         ct_invAmounts|ct_invTotal|ct_usgTotal));
01163     }
01164 
01165     template <typename T>
01166       SubsItem *Invoice::newSubsItem(
01167         const Section& section, const T& t, const SubsCharge* sc,
01168         ContributesTo flags)
01169     {
01170         SubsItem *si = new SubsItem(section, sc);
01171         int rc = items_.insert(section, t, si);
01172         if (rc) {
01173             delete si;
01174             throw DefException(29) << section.str();
01175         }
01176         subsItems_.push_back(si);
01177         setNumber(*si);
01178         addAmount(si->amount, flags);
01179         return si;
01180     }
01181 
01182     template <typename T>
01183       SubsItem *Invoice::newSubsItem(
01184         const Section& section,
01185         const T& t,
01186         const SubsCharge* sc
01187     )
01188     {
01189         return newSubsItem<T>(section, t, sc,
01190                 ContributesTo(ct_invAmounts|ct_invTotal|ct_subsTotal));
01191     }
01192 
01193     template <typename T>
01194       OnetimeChargeItem* Invoice::newOnetimeChargeItem(
01195         const Section& section,
01196         const T& t,
01197         const OnetimeCharge* onetimeCharge,
01198               ContributesTo flags
01199     )
01200     {
01201         OnetimeChargeItem *otc
01202             = new OnetimeChargeItem(section, onetimeCharge);
01203         int rc = items_.insert(section, t, otc);
01204         if (rc) {
01205             delete otc;
01206             throw DefException(29) << section.str();
01207         }
01208         onetimeChargeItems_.push_back(otc);
01209         setNumber(*otc);
01210         addAmount(otc->amount, flags);
01211         return otc;
01212     }
01213 
01214     template <typename T>
01215       OnetimeChargeItem* Invoice::newOnetimeChargeItem(
01216         const Section& section,
01217         const T& t,
01218         const OnetimeCharge* onetimeCharge
01219     )
01220     {
01221         return newOnetimeChargeItem<T>(section, t, onetimeCharge,
01222                 ContributesTo(ct_invAmounts|ct_invTotal|ct_otcTotal));
01223     }
01224 
01225     // Create a new total item and link it to the invoice as specified
01226     // Provided are versions with and without additional sort key
01227     template <typename T>
01228     TotalItem* Invoice::newTotalItem(
01229         const Section&   section,
01230         const T&         t,
01231               Decimal&   volume,
01232         const Unit::Oid& unitId,
01233         ContributesTo    flags
01234     )
01235     {
01236         // Check if unit exists.
01237         if (unitId.unKnown()) {
01238             throw DefException(51) << unitId;
01239         }
01240 
01241         TotalItem* tot = new TotalItem(section, volume, unitId);
01242         int rc = items_.insert(section, t, tot);
01243         if (rc) {
01244             delete tot;
01245             throw DefException(29) << section.str();
01246         }
01247         setNumber(*tot);
01248         addAmount(tot->amount_, flags);
01249         return tot;
01250     }
01251 
01252     template <typename T>
01253     TotalItem* Invoice::newTotalItem(
01254         const Section&   section,
01255         const T&         t,
01256               Decimal&   volume,
01257         const Unit::Oid& unitId
01258     )
01259     {
01260         return newTotalItem<T>(section, t, volume, unitId,
01261                 ContributesTo(ct_nothing));
01262     }
01263 
01264     template <typename T>
01265       AssociateInfo* Invoice::newAssociateInfo(
01266         const Section& section,
01267         const T& t,
01268         const Associate* associate
01269     )
01270     {
01271         AssociateInfo* ii = new AssociateInfo(section, associate);
01272         int rc = items_.insert(section, t, ii);
01273         if (rc) {
01274             delete ii;
01275             throw DefException(29) << section.str();
01276         }
01277         setNumber(*ii);
01278         return ii;
01279     }
01280 
01281     template <typename T>
01282       SummaryChargesInfo* Invoice::newSummaryChargesInfo(
01283         const Section& section,
01284         const T& t,
01285         const SummaryCharges* sumCharges
01286     )
01287     {
01288         SummaryChargesInfo* ii =
01289             new SummaryChargesInfo(section, sumCharges);
01290         int rc = items_.insert(section, t, ii);
01291         if (rc) {
01292             delete ii;
01293             throw DefException(29) << section.str();
01294         }
01295         setNumber(*ii);
01296         return ii;
01297     }
01298 
01299     template <typename T>
01300       InvoiceInfoItem* Invoice::newInvoiceInfoItem(
01301         const Section& section,
01302         const T& t,
01303         const InvoiceInfo* invInfo
01304     )
01305     {
01306         InvoiceInfoItem* ii =
01307             new InvoiceInfoItem(section, invInfo);
01308         int rc = items_.insert(section, t, ii);
01309         if (rc) {
01310             delete ii;
01311             throw DefException(29) << section.str();
01312         }
01313         setNumber(*ii);
01314         return ii;
01315     }
01316 }                                   // namespace OSB_LIB
01317 #endif                              // #ifndef _INVOICE_H_

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