1 /*******************************************************
2  Copyright (C) 2013,2014 Guan Lisheng (guanlisheng@gmail.com)
3 
4  This program is free software; you can redistribute it and/or modify
5  it under the terms of the GNU General Public License as published by
6  the Free Software Foundation; either version 2 of the License, or
7  (at your option) any later version.
8 
9  This program is distributed in the hope that it will be useful,
10  but WITHOUT ANY WARRANTY; without even the implied warranty of
11  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  GNU General Public License for more details.
13 
14  You should have received a copy of the GNU General Public License
15  along with this program; if not, write to the Free Software
16  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  ********************************************************/
18 
19 #ifndef MODEL_CATEGORY_H
20 #define MODEL_CATEGORY_H
21 
22 #include "Model.h"
23 #include "db/DB_Table_Category_V1.h"
24 #include "Model_Subcategory.h"
25 
26 class mmDateRange;
27 class Model_Category : public Model<DB_Table_CATEGORY_V1>
28 {
29 public:
30     using Model<DB_Table_CATEGORY_V1>::get;
31 
32 public:
33     Model_Category();
34     ~Model_Category();
35 
36 public:
37     /**
38     Initialize the global Model_Category table on initial call.
39     Resets the global table on subsequent calls.
40     * Return the static instance address for Model_Category table
41     * Note: Assigning the address to a local variable can destroy the instance.
42     */
43     static Model_Category& instance(wxSQLite3Database* db);
44 
45     /**
46     * Return the static instance address for Model_Category table
47     * Note: Assigning the address to a local variable can destroy the instance.
48     */
49     static Model_Category& instance();
50 
51 private:
52     void initialize();
53 
54 public:
55     /** Return the Data record for the given category name */
56     Data* get(const wxString& name);
57 
58     static const std::map<wxString, std::pair<int, int> > all_categories();
59     static Model_Subcategory::Data_Set sub_category(const Data* r);
60     static Model_Subcategory::Data_Set sub_category(const Data& r);
61     static const wxString full_name(const Data* category, const Model_Subcategory::Data* sub_category = 0);
62     static const wxString full_name(const int &category_id, const int &subcategory_id);
63     static bool is_used(int id, int sub_id = -1);
64     static bool has_income(int id, int sub_id = -1);
65     static void getCategoryStats(
66         std::map<int, std::map<int, std::map<int, double> > > &categoryStats
67         , mmDateRange* date_range, bool ignoreFuture
68         , bool group_by_month = true, bool with_date = true
69         , std::map<int, std::map<int, double> > *budgetAmt = 0);
70 };
71 
72 #endif //
73