Skip to content

Commit a8ec24b

Browse files
committed
ok
1 parent 933f77e commit a8ec24b

File tree

4 files changed

+53
-95
lines changed

4 files changed

+53
-95
lines changed

investmoney/.vs/investmoney/v16/.suo

1 KB
Binary file not shown.
Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,37 @@
1-
using investmoney.src.DAO;
2-
using investmoney.src.Models;
3-
using System;
4-
using System.Collections.Generic;
5-
using System.Linq;
6-
using System.Text;
7-
using System.Threading.Tasks;
8-
9-
namespace investmoney.src.Controllers
10-
{
11-
class TransactionController
12-
{
13-
public List<TransactionModel> LoadUserTransactions(User user)
14-
{
15-
TransactionDao transactions = new TransactionDao();
16-
List<TransactionModel> list = transactions.LoadUserTransactions(user);
17-
return list;
18-
}
19-
1+
using investmoney.src.DAO;
2+
using investmoney.src.Models;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace investmoney.src.Controllers
10+
{
11+
class TransactionController
12+
{
13+
public List<TransactionModel> LoadUserTransactions(User user)
14+
{
15+
TransactionDao transactions = new TransactionDao();
16+
List<TransactionModel> list = transactions.LoadUserTransactions(user);
17+
return list;
18+
}
19+
2020
public int calculateMaked(List<Wallet> wallet, int user,string dia, string mes, string ano)
2121
{
2222
TransactionDao transactions = new TransactionDao();
23-
var list = transactions.calculateMaked(wallet, user, dia, mes, ano);
23+
var list = transactions.calculateMaked(wallet, user, dia, mes, ano);
2424
return list;
25-
25+
2626

2727
}
2828
public int calculateMakedNaoRealizado(List<Wallet> wallet, int user, string dia, string mes, string ano)
2929
{
3030
TransactionDao transactions = new TransactionDao();
31-
var list = transactions.calculateMakedNotRealizado(wallet, user, dia, mes, ano);
31+
var list = transactions.calculateMakedNotRealizado(wallet, user, dia, mes, ano);
3232
return list;
3333

3434

35-
}
36-
}
37-
}
35+
}
36+
}
37+
}

investmoney/investmoney/src/DAO/TransactionDao.cs

Lines changed: 19 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -34,46 +34,8 @@ public int calculateMaked(List<Wallet> wallet, int user, string dia, string mes,
3434
var valueTotal = 0.0;
3535

3636
var l = 0.0;
37-
//string sqlV = "SELECT ticker, SUM(amount) as soma, SUM((price * amount)) as vendido, date FROM transactions GROUP BY ticker HAVING DATE(substr(date,7,4)||'-'||substr(date,4,2)||'-'||substr(date,1,2)) BETWEEN DATE('" + dateStart + "') AND DATE('" + dateEnd + "') and type = 'V' and user_id = '" + user + "' ;";
38-
// string sqlC = "SELECT ticker, SUM(amount) as soma, SUM((price * amount)) as vendido, date FROM transactions GROUP BY ticker HAVING DATE(substr(date,7,4)||'-'||substr(date,4,2)||'-'||substr(date,1,2)) BETWEEN DATE('" + dateStart + "') AND DATE('" + dateEnd + "') and type = 'C' and user_id = '" + user + "' ;";
39-
// var vend = connection.Query(sqlV, new DynamicParameters()).AsList();
40-
41-
//var comp = connection.Query(sqlC, new DynamicParameters()).AsList();
42-
ActiveDao activeDa = new ActiveDao();
43-
var activesNames = activeDa.GetActivesNames();
44-
45-
foreach (var item in activesNames)
46-
{
47-
string totalVenda = "SELECT SUM((price * amount)) as soma, SUM(amount) as amount FROM transactions WHERE DATE(substr(date,7,4)||'-'||substr(date,4,2)||'-'||substr(date,1,2)) BETWEEN DATE('" + dateStart + "') AND DATE('" + dateEnd + "') and type = 'V' and user_id = '" + user + "' and ticker = '" + item + "' ;";
48-
var totalVendaImposto = connection.Query<dynamic>(totalVenda, new DynamicParameters());
49-
valueTotal = valueTotal + Convert.ToDouble(totalVendaImposto.First().soma);
50-
51-
string consultaTotal = "SELECT SUM((price * amount)) as soma FROM transactions WHERE DATE(substr(date,7,4)||'-'||substr(date,4,2)||'-'||substr(date,1,2)) BETWEEN DATE('" + dateStart + "') AND DATE('" + dateEnd + "') and type = 'C' and user_id = '" + user + "' and ticker = '" + item + "' ;";
52-
var custoTotal1 = connection.Query<dynamic>(consultaTotal, new DynamicParameters());
53-
54-
var price_medio = custoTotal1.First().soma / totalVendaImposto.First().soma;
55-
ActiveController activeController = new ActiveController();
56-
var ticker = activeController.GetActiveByTicker(item);
57-
var cotacao = Convert.ToDouble(ticker.price); // Convert.ToDouble(ticker.price);
58-
var total = price_medio * totalVendaImposto.First().amount;
59-
var valorMercado = totalVendaImposto.First().amount * cotacao;
60-
var Lucro_prejuizo = Convert.ToDouble(valorMercado) - Convert.ToDouble(total);
61-
l = Lucro_prejuizo + l;
62-
63-
}
64-
if ((valueTotal) > 20000)
65-
{
66-
var imposto = l - (l * 0.15);
67-
68-
return Convert.ToInt32(imposto);
69-
}
70-
else
71-
{
72-
return Convert.ToInt32(l);
73-
}
74-
return Convert.ToInt32(l);
75-
/*
76-
* if (wallet.Count() > 0)
37+
38+
if (wallet.Count() > 0)
7739
{
7840

7941
foreach (var item in wallet)
@@ -125,14 +87,9 @@ public int calculateMaked(List<Wallet> wallet, int user, string dia, string mes,
12587
}
12688

12789

128-
<<<<<<< HEAD
12990
}
13091

13192
return Convert.ToInt32(l);
132-
=======
133-
}*/
134-
135-
>>>>>>> 0712d1bac803ce7321485c1f2b30ab07c1d0224b
13693

13794
}
13895
}
@@ -145,21 +102,23 @@ public int calculateMakedNotRealizado(List<Wallet> wallet, int user, string dia,
145102
{
146103
var dateStart = $"{ano}-{mes}-{dia}";
147104
var dateEnd = $"{ano}-{mes}-30";
148-
var l = 0.0;
149-
var valueTotal = 0.0;
150-
151105

106+
var l = 0.0;
152107
if (wallet.Count() > 0)
153108
{
154109

155110
foreach (var item in wallet)
156111
{
157112
string consultaCompra = "SELECT SUM(amount) as soma, date FROM transactions WHERE DATE(substr(date,7,4)||'-'||substr(date,4,2)||'-'||substr(date,1,2)) BETWEEN DATE('" + dateStart + "') AND DATE('" + dateEnd + "') and type = 'C' and user_id = '" + user + "' and ticker = '" + item.ticker + "' ;";
113+
string consultaVenda = "SELECT SUM(amount) as soma FROM transactions WHERE DATE(substr(date,7,4)||'-'||substr(date,4,2)||'-'||substr(date,1,2)) BETWEEN DATE('" + dateStart + "') AND DATE('" + dateEnd + "') and type = 'V' and user_id = '" + user + "' and ticker = '" + item.ticker + "' ;";
158114
string consultaTotal = "SELECT SUM((price * amount)) as soma FROM transactions WHERE DATE(substr(date,7,4)||'-'||substr(date,4,2)||'-'||substr(date,1,2)) BETWEEN DATE('" + dateStart + "') AND DATE('" + dateEnd + "') and type = 'C' and user_id = '" + user + "' and ticker = '" + item.ticker + "' ;";
159115

116+
var qtdVend = connection.Query<int>("select SUM(amount) as soma from transactions where type = 'V' and user_id = '" + user + "' and ticker = '" + item.ticker + "' and date BETWEEN '01/09/2021' AND '30/09/2021' ", new DynamicParameters());
117+
118+
160119
var qtdComp = connection.Query<dynamic>(consultaCompra, new DynamicParameters());
120+
// "totalcost"
161121
var valorTotal = connection.Query<dynamic>(consultaTotal, new DynamicParameters());
162-
valueTotal = valueTotal + Convert.ToDouble(valorTotal.First().soma);
163122

164123
var price_medio = valorTotal.First().soma / qtdComp.First().soma;
165124
ActiveController activeController = new ActiveController();
@@ -170,6 +129,14 @@ public int calculateMakedNotRealizado(List<Wallet> wallet, int user, string dia,
170129
var valorMercado = item.amount * cotacao;
171130
Console.WriteLine(valorMercado);
172131
var Lucro_prejuizo = valorMercado - custoTotal;
132+
// Console.WriteLine(Lucro_prejuizo);
133+
// ativo, amount, price, average_price, total_cost, market_value, LP, DN
134+
var dn = "N";
135+
var user_id = 1;
136+
// connection.Execute("insert into result (ativo, amount, average_price, price, total_cost, market_value, LP, DN, user_id) values ('" +
137+
// "" + wallet[0].ticker + "', '" + qtdVend.First() + "', '" + price_medio + "', '" + cotacao + "', '" + total + "', '" + valorMercado + "', '" + Lucro_prejuizo + "' , '" + dn + "', '" + user_id + "')");
138+
// var soma = connection.Query<int>("select SUM(LP) as soma from result where user_id = " + user_id + ";", new DynamicParameters());
139+
// Console.WriteLine(soma.First());
173140
if (Lucro_prejuizo == null)
174141
{
175142
l = l + l;
@@ -179,20 +146,11 @@ public int calculateMakedNotRealizado(List<Wallet> wallet, int user, string dia,
179146
l = Lucro_prejuizo + l;
180147
}
181148
}
182-
if ((1 * valueTotal) > 20000)
183-
{
184-
var value = l - (l * 0.15);
185-
//Console.WriteLine(imposto);
186-
return Convert.ToInt32(value);
187-
}
188-
else
189-
{
190-
return Convert.ToInt32(l);
191-
}
192-
149+
return Convert.ToInt32(l);
193150

194151
}
195-
152+
153+
196154
return Convert.ToInt32(l);
197155

198156

investmoney/investmoney/src/Views/Home.Designer.cs

Lines changed: 9 additions & 9 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)