invoicedir.h

Go to the documentation of this file.
00001 // OSB library ********************************************* -*- C++ -*-
00012 /*
00013    AUTHOR(S): Tang Boon Leong (tbl)
00014 
00015    RCS information
00016     $Name: OSB_060808 $
00017     $Revision: 1.32 $
00018 
00019   License
00020    OSB rating and billing library for communication networks
00021    Copyright (C) 2004, 2005, 2006  OSB systems
00022 
00023    This file may be distributed and/or modify under the terms of the
00024    GNU General Public License (GPL) as published by the Free Software
00025    Foundation which is provided in the file LICENSE.GPL included in the
00026    packaging of this file.
00027 
00028    The file is distributed in the hope that it will be useful, but WITHOUT
00029    ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00030    FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00031    for more details.
00032 
00033    Holders of a OSB Commercial License may use this file under the terms
00034    and conditions of this commercial license.
00035  */
00036 #ifndef _INVOICEDIR_H_
00037 #define _INVOICEDIR_H_
00038 
00039 // *********************************************************************
00040 // included header files
00041 // + standard includes
00042 #include <string>
00043 #include <fstream>
00044 #include <map>
00045 #include <vector>
00046 
00047 // + local headers
00048 #include "balancesheet.h"
00049 #include "chrono.h"
00050 #include "amount.h"
00051 
00052 // *********************************************************************
00053 // class declarations
00054 namespace OSB_DB {
00055     class Session;
00056 }
00057 
00058 // ************************************************************************
00059 // namespace extensions
00060 namespace OSB_LIB {
00061 
00062 // *********************************************************************
00063 // type definitions
00064 
00066     const int DIR_MOD = 0777;
00067 
00074     typedef std::map<std::string, long> DirPathNumEntryRecord;
00075 
00076 // *********************************************************************
00077 // class definitions
00078 
00087     struct InvoiceInfo {
00089         enum StatementType {
00091             stInvoice = 'i',
00093             stReconciliation = 'r',
00095             stUnknown = '\0'
00096         };
00097 
00105         static StatementType toStatementType(char st);
00106 
00114         static char toChar(StatementType st);
00115 
00117         InvoiceInfo() {}
00119         ~InvoiceInfo() {}
00120 
00122         std::string invoiceNumber;
00124         BsPage::Oid bsPageId;
00126         Contract::Oid contractId;
00128         StatementType statementType;
00130         Date billDate;
00132         Date dueDate;
00134         Date startDate;
00136         Date endDate;
00138         MoneyList invAmount;
00140         std::string hostName;
00142         std::string fileInfo;
00143     };
00144 
00178     class InvoiceDir {
00179     public:
00185         ~InvoiceDir();
00186 
00198         InvoiceDir(const std::string& basePath, long maxEntry);
00199 
00211         std::ostream& create(const std::string& dirPath,
00212                              const std::string& fileName);
00213 
00221         void deleteCurrentFile();
00222 
00233         void close(const OSB_DB::Session& session,
00234                    const InvoiceInfo&     invInfo);
00235 
00242         void confirm();
00243 
00250         void deleteUnconfirm();
00251 
00257         const std::string& currentFile() { return currentFile_; }
00258 
00264         const std::string& tmpExtension() { return tmpExtension_; }
00265 
00266     private:
00268         std::string dirBase_;
00269 
00271         long maxFileEntry_;
00272 
00274         std::string currentFile_;
00275 
00277         std::string tmpExtension_;
00278 
00280         std::vector<std::string> filesNotCommitted_;
00281 
00283         std::ofstream os_;
00284 
00287         static int threadCounter_;
00288 
00290         static pthread_mutex_t mutex_;
00291 
00293         static DirPathNumEntryRecord dirInfoRecord_;
00294 
00306         void mkTree(const std::string& dirTree, mode_t mode);
00307 
00317         std::string i2a(long i);
00318 
00332         void padding(std::string& str, char pad, int size);
00333 
00334     };
00335 }                                       // namespace OSB_LIB
00336 #endif                                  // #ifndef _INVOICEDIR_H_

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