1 /*******************************************************
2 Copyright (C) 2014 Gabriele-V
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 MM_EX_WEBAPP_H_
20 #define MM_EX_WEBAPP_H_
21 
22 #include "defs.h"
23 #include <wx/spinctrl.h>
24 #include <vector>
25 
26 class wxString;
27 //Parameters used in services.php
28 namespace WebAppParam
29 {
30     extern const wxString ServicesPage;
31     extern const wxString ApiExpectedVersion;
32     extern const wxString CheckGuid;
33     extern const wxString CheckApiVersion;
34     extern const wxString DeleteAccount;
35     extern const wxString ImportAccount;
36     extern const wxString DeletePayee;
37     extern const wxString ImportPayee;
38     extern const wxString DeleteCategory;
39     extern const wxString ImportCategory;
40     extern const wxString DeleteOneTransaction;
41     extern const wxString DownloadNewTransaction;
42     extern const wxString DownloadAttachments;
43     extern const wxString DeleteAttachment;
44     extern const wxString MessageSuccedeed;
45     extern const wxString MessageWrongGuid;
46 }
47 
48 class mmWebApp
49 {
50 const static wxString getUrl();
51 const static wxString getGuid();
52 
53 /** Return services page URL with GUID inserted */
54 const static wxString getServicesPageURL();
55 
56 //Internal function
57 const static wxString WebApp_getApiVersion();
58 static int WebApp_SendJson(wxString& Website, const wxString& JsonData, wxString& Output);
59 static bool WebApp_DeleteAllAccount();
60 static bool WebApp_DeleteAllPayee();
61 static bool WebApp_DeleteAllCategory();
62 static wxString WebApp_DownloadOneAttachment(const wxString& AttachmentName, int DesktopTransactionID, int AttachmentNr);
63 
64 public:
65     /*WebApp transaction Structure*/
66     struct webtran_holder
67     {
68         int ID;
69         wxDateTime Date;
70         wxString Account;
71         wxString ToAccount;
72         wxString Status;
73         wxString Type;
74         wxString Payee;
75         wxString Category;
76         wxString SubCategory;
77         double Amount;
78         wxString Notes;
79         wxString Attachments;
80     };
81     typedef std::vector<webtran_holder> WebTranVector;
82 
83     static bool returnResult(int& ErrorCode, wxString& outputMessage);
84 
85     /** Return true if WebApp is enabled */
86     static bool WebApp_CheckEnabled();
87 
88     /** Return true if WebApp Guid is correct */
89     static bool WebApp_CheckGuid();
90 
91     /** Return true if WebApp API Version is correct */
92     static bool WebApp_CheckApiVersion();
93 
94     /** Update all accounts on WebApp */
95     static bool WebApp_UpdateAccount();
96 
97     /** Update all payees on WebApp */
98     static bool WebApp_UpdatePayee();
99 
100     /** Update all categories on WebApp */
101     static bool WebApp_UpdateCategory();
102 
103     /** Download new transaction */
104     static bool WebApp_DownloadNewTransaction(WebTranVector& WebAppTransactions_, const bool& CheckOnly);
105 
106     /** Insert transaction in MMEX desktop, returns transaction ID */
107     static int MMEX_InsertNewTransaction(webtran_holder& WebAppTrans);
108 
109     /** Delete transaction from WebApp */
110     static bool WebApp_DeleteOneTransaction(int WebAppTransactionId);
111 
112     /* Return attachment URL */
113     static wxString WebApp_GetAttachment(const wxString& AttachmentFileName);
114 
115     //FUNCTIONS CALLED IN MMEX TO UPDATE ON CHANGE
116     /** Update all payees on WebApp if enabled */
117     static bool MMEX_WebApp_UpdatePayee();
118 
119     /** Update all accounts on WebApp if enabled */
120     static bool MMEX_WebApp_UpdateAccount();
121 
122     /** Update all categories on WebApp if enabled */
123     static bool MMEX_WebApp_UpdateCategory();
124 };
125 
126 #endif // MM_EX_WEBAPP_H_
127