-
Notifications
You must be signed in to change notification settings - Fork 4
/
Select.cs
153 lines (129 loc) · 5.61 KB
/
Select.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Newtonsoft.Json.Linq;
namespace AccountServer {
public class Select : AppModule {
public JObjectEnumerable Account(string term) {
return Database.Query(@"idAccount AS id, AccountName AS value, AcctType AS category, Protected + HideAccount as hide",
like("WHERE HideAccount = 0 or HideAccount is null", "AccountName", term) + " ORDER BY idAccountType, AccountName",
"Account");
}
public JObjectEnumerable AllAccounts(string term) {
return Database.Query(@"idAccount AS id, AccountName AS value, AcctType AS category, HideAccount as hide",
like("", "AccountName", term) + " ORDER BY idAccountType, AccountName",
"Account");
}
public JObjectEnumerable AccountTypes(string term) {
return Database.Query(@"idAccountType AS id, AcctType AS value",
like("", "AcctType", term) + " ORDER BY idAccountType",
"AccountType");
}
public IEnumerable<JObject> AuditTypes() {
for (AuditType t = AuditType.Insert; t <= AuditType.Delete; t++) {
yield return new JObject().AddRange("id", (int)t, "value", t.UnCamel());
}
}
public JObjectEnumerable BankAccount(string term) {
return Database.Query(@"idAccount AS id, AccountName AS value, AcctType AS category, HideAccount AS hide",
like("WHERE AccountTypeId in (" + (int)AcctType.Bank + "," + (int)AcctType.CreditCard + ")", "AccountName", term)
+ " ORDER BY idAccountType, AccountName",
"Account");
}
public JObjectEnumerable BankOrStockAccount(string term) {
return Database.Query(@"idAccount AS id, AccountName AS value, AcctType AS category, HideAccount AS hide",
like("WHERE AccountTypeId in (" + (int)AcctType.Bank + "," + (int)AcctType.CreditCard + "," + (int)AcctType.Investment + ")", "AccountName", term)
+ " ORDER BY idAccountType, AccountName",
"Account");
}
public JObjectEnumerable Customer(string term) {
return Name("C", term);
}
public JObjectEnumerable DocumentType(string term) {
return Database.Query(@"idDocumentType AS id, DocType AS value",
like("", "DocType", term) + " ORDER BY idDocumentType",
"DocumentType");
}
public JObjectEnumerable ExpenseAccount(string term) {
return Database.Query(@"idAccount AS id, AccountName AS value, AcctType AS category, Protected + HideAccount as hide",
like("WHERE AccountTypeId " + Database.In(AcctType.Expense, AcctType.OtherExpense), "AccountName", term) + " ORDER BY idAccountType, AccountName",
"Account");
}
public JObjectEnumerable IncomeAccount(string term) {
return Database.Query(@"idAccount AS id, AccountName AS value, AcctType AS category, Protected + HideAccount as hide",
like("WHERE AccountTypeId = " + (int)AcctType.Income, "AccountName", term) + " ORDER BY idAccountType, AccountName",
"Account");
}
public JObjectEnumerable Name(string term) {
return Database.Query(@"idNameAddress AS id, Name AS value, CASE Type WHEN 'C' THEN 'Customers' WHEN 'S' THEN 'Suppliers' ELSE 'Others' END AS category, Hidden as hide",
like("", "Name", term) + " ORDER BY Type, Name",
"NameAddress");
}
public JObjectEnumerable Name(string nameType, string term) {
return Database.Query(@"idNameAddress AS id, Name AS value, Hidden as hide, Address, Telephone",
like("WHERE Type = " + Database.Quote(nameType), "Name", term) + " ORDER BY Name",
"NameAddress");
}
public IEnumerable<JObject> NameTypes() {
return new JObject [] {
new JObject().AddRange("id", "C", "value", "Customer"),
new JObject().AddRange("id", "S", "value", "Supplier"),
new JObject().AddRange("id", "O", "value", "Other")
};
}
public JObjectEnumerable Other(string term) {
return Name("O", term);
}
public JObjectEnumerable Product(string term) {
return Database.Query(@"idProduct AS id, ProductName AS value, ProductDescription, UnitPrice, VatCodeId, Code, VatDescription, Rate, AccountId, Unit",
like("", "ProductName", term) + " ORDER BY ProductName",
"Product");
}
public JObjectEnumerable ReportGroup(string term) {
return Database.Query(@"ReportGroup AS id, ReportGroup AS value",
like("", "ReportGroup", term) + " GROUP BY ReportGroup ORDER BY ReportGroup",
"Report");
}
public JObjectEnumerable Security(string term) {
return Database.Query(@"idSecurity AS id, SecurityName AS value",
like("", "SecurityName", term) + " ORDER BY SecurityName",
"Security");
}
public JObjectEnumerable Supplier(string term) {
return Name("S", term);
}
public IEnumerable<JObject> VatCode(string term) {
List<JObject> result = Database.Query(@"idVatCode AS id, Code, VatDescription, Rate",
like("", "Code", term) + " ORDER BY Code",
"VatCode").ToList();
foreach (JObject o in result)
o["value"] = o.AsString("Code") + " (" + o.AsDecimal("Rate") + "%)";
result.Insert(0, new JObject().AddRange("id", null,
"value", "",
"Rate", 0));
return result;
}
public IEnumerable<JObject> VatTypes() {
return new JObject[] {
new JObject().AddRange("id", -1, "value", "Sales"),
new JObject().AddRange("id", 1, "value", "Purchases")
};
}
public JObjectEnumerable VatPayments() {
return Database.Query(@"SELECT idDocument as id, DocumentDate as value
FROM Document
JOIN Journal ON DocumentId = idDocument
WHERE AccountId = 8
AND JournalNum = 2
AND DocumentTypeId IN (7, 8, 9, 10)
ORDER BY idDocument");
}
public string like(string sql, string name, string term) {
if (string.IsNullOrEmpty(term)) return sql;
term = name + " LIKE '" + term + "%'";
return string.IsNullOrEmpty(sql) ? "WHERE " + term : sql + " AND " + term;
}
}
}