små justeringar i visningen av aktiehistorien
This commit is contained in:
@ -61,84 +61,84 @@ public class StockEquityServices : IStockEquityServices
|
|||||||
|
|
||||||
if (note.TransactionType == null && note.StockCode != null) { }
|
if (note.TransactionType == null && note.StockCode != null) { }
|
||||||
else
|
else
|
||||||
|
|
||||||
// Kontrollera om TransactionType är en köpnotering
|
|
||||||
// (ignorera null-värden)
|
|
||||||
|
|
||||||
if (note.TransactionType.ToLower() == "köp")
|
|
||||||
{
|
{
|
||||||
// Skapa en ny aktieinnehavspost baserat på köpnoteringen
|
// Kontrollera om TransactionType är en köpnotering
|
||||||
|
// (ignorera null-värden)
|
||||||
|
|
||||||
var equity = new StockEquity
|
if (note.TransactionType.ToLower() == "köp")
|
||||||
{
|
{
|
||||||
StockCode = note.StockCode,
|
// Skapa en ny aktieinnehavspost baserat på köpnoteringen
|
||||||
Bought = note.TransactionDate,
|
|
||||||
BoughtPrice = note.StockPrice,
|
|
||||||
Quantity = note.StockQuantity,
|
|
||||||
Sold = DateTime.MinValue,
|
|
||||||
SoldPrice = 0m,
|
|
||||||
SoldQuant = 0
|
|
||||||
};
|
|
||||||
_dbContext.Stocks.Add(equity);
|
|
||||||
await _dbContext.SaveChangesAsync();
|
|
||||||
Debug.WriteLine($"Köpnotering: {equity.StockCode} | {equity.Bought} | {equity.BoughtPrice} | {equity.Quantity} | {equity.BoughtPrice * equity.Quantity}");
|
|
||||||
}
|
|
||||||
|
|
||||||
// Kontrollera om TransactionType är en säljnotering
|
var equity = new StockEquity
|
||||||
|
|
||||||
else if (note.TransactionType.ToLower() == "sälj")
|
|
||||||
{
|
|
||||||
var equityList = await _dbContext.Stocks
|
|
||||||
.Where(s => s.StockCode == note.StockCode && s.SoldQuant == 0)
|
|
||||||
.OrderBy(s => s.Quantity).ToListAsync();
|
|
||||||
|
|
||||||
if (equityList != null)
|
|
||||||
{
|
|
||||||
var soldQuant = Math.Abs(note.StockQuantity);
|
|
||||||
foreach (var eq in equityList.OrderBy(e => e.Quantity))
|
|
||||||
{
|
{
|
||||||
if (soldQuant == 0)
|
StockCode = note.StockCode,
|
||||||
|
Bought = note.TransactionDate,
|
||||||
|
BoughtPrice = note.StockPrice,
|
||||||
|
Quantity = note.StockQuantity,
|
||||||
|
Sold = DateTime.MinValue,
|
||||||
|
SoldPrice = 0m,
|
||||||
|
SoldQuant = 0
|
||||||
|
};
|
||||||
|
_dbContext.Stocks.Add(equity);
|
||||||
|
await _dbContext.SaveChangesAsync();
|
||||||
|
Debug.WriteLine($"Köpnotering: {equity.StockCode} | {equity.Bought} | {equity.BoughtPrice} | {equity.Quantity} | {equity.BoughtPrice * equity.Quantity}");
|
||||||
|
}
|
||||||
|
|
||||||
|
// Kontrollera om TransactionType är en säljnotering
|
||||||
|
|
||||||
|
else if (note.TransactionType.ToLower() == "sälj")
|
||||||
|
{
|
||||||
|
var equityList = await _dbContext.Stocks
|
||||||
|
.Where(s => s.StockCode == note.StockCode && s.SoldQuant == 0)
|
||||||
|
.OrderBy(s => s.Quantity).ToListAsync();
|
||||||
|
|
||||||
|
if (equityList != null)
|
||||||
|
{
|
||||||
|
var soldQuant = Math.Abs(note.StockQuantity);
|
||||||
|
foreach (var eq in equityList.OrderBy(e => e.Quantity))
|
||||||
{
|
{
|
||||||
break;
|
if (soldQuant == 0)
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
if (eq.Quantity <= soldQuant)
|
|
||||||
{
|
{
|
||||||
eq.Sold = note.TransactionDate;
|
break;
|
||||||
eq.SoldPrice = note.StockPrice;
|
|
||||||
eq.SoldQuant = eq.Quantity;
|
|
||||||
soldQuant -= eq.Quantity;
|
|
||||||
_dbContext.Stocks.Update(eq);
|
|
||||||
await _dbContext.SaveChangesAsync();
|
|
||||||
Debug.WriteLine($"Säljnotering: {eq.StockCode} | {eq.Sold} | {eq.SoldPrice} | {eq.SoldQuant}");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var splitEquity = new StockEquity
|
if (eq.Quantity <= soldQuant)
|
||||||
{
|
{
|
||||||
StockCode = eq.StockCode,
|
eq.Sold = note.TransactionDate;
|
||||||
Bought = eq.Bought,
|
eq.SoldPrice = note.StockPrice;
|
||||||
BoughtPrice = eq.BoughtPrice,
|
eq.SoldQuant = eq.Quantity;
|
||||||
Quantity = soldQuant,
|
soldQuant -= eq.Quantity;
|
||||||
Sold = note.TransactionDate,
|
_dbContext.Stocks.Update(eq);
|
||||||
SoldPrice = note.StockPrice,
|
await _dbContext.SaveChangesAsync();
|
||||||
SoldQuant = soldQuant
|
Debug.WriteLine($"Säljnotering: {eq.StockCode} | {eq.Sold} | {eq.SoldPrice} | {eq.SoldQuant}");
|
||||||
};
|
}
|
||||||
_dbContext.Stocks.Add(splitEquity);
|
else
|
||||||
await _dbContext.SaveChangesAsync();
|
{
|
||||||
Debug.WriteLine($"Säljnotering (split): {splitEquity.StockCode} | {splitEquity.Bought} | {splitEquity.BoughtPrice} | {splitEquity.SoldQuant} | {splitEquity.Sold} | {splitEquity.SoldPrice} | {splitEquity.SoldQuant}");
|
var splitEquity = new StockEquity
|
||||||
eq.Quantity -= soldQuant;
|
{
|
||||||
_dbContext.Stocks.Update(eq);
|
StockCode = eq.StockCode,
|
||||||
await _dbContext.SaveChangesAsync();
|
Bought = eq.Bought,
|
||||||
Debug.WriteLine($"Säljnotering (split): {eq.StockCode} | {eq.Bought} | {eq.BoughtPrice} | {eq.SoldQuant} | {eq.Sold} | {eq.SoldPrice} | {eq.SoldQuant}");
|
BoughtPrice = eq.BoughtPrice,
|
||||||
soldQuant = 0;
|
Quantity = soldQuant,
|
||||||
|
Sold = note.TransactionDate,
|
||||||
|
SoldPrice = note.StockPrice,
|
||||||
|
SoldQuant = soldQuant
|
||||||
|
};
|
||||||
|
_dbContext.Stocks.Add(splitEquity);
|
||||||
|
await _dbContext.SaveChangesAsync();
|
||||||
|
Debug.WriteLine($"Säljnotering (split): {splitEquity.StockCode} | {splitEquity.Bought} | {splitEquity.BoughtPrice} | {splitEquity.SoldQuant} | {splitEquity.Sold} | {splitEquity.SoldPrice} | {splitEquity.SoldQuant}");
|
||||||
|
eq.Quantity -= soldQuant;
|
||||||
|
_dbContext.Stocks.Update(eq);
|
||||||
|
await _dbContext.SaveChangesAsync();
|
||||||
|
Debug.WriteLine($"Säljnotering (split): {eq.StockCode} | {eq.Bought} | {eq.BoughtPrice} | {eq.SoldQuant} | {eq.Sold} | {eq.SoldPrice} | {eq.SoldQuant}");
|
||||||
|
soldQuant = 0;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
47
StockHistory/frmStockHistoryAnalyse.Designer.cs
generated
47
StockHistory/frmStockHistoryAnalyse.Designer.cs
generated
@ -35,17 +35,17 @@
|
|||||||
lwStocks = new ListView();
|
lwStocks = new ListView();
|
||||||
chStock = new ColumnHeader();
|
chStock = new ColumnHeader();
|
||||||
chBought = new ColumnHeader();
|
chBought = new ColumnHeader();
|
||||||
chPrize = new ColumnHeader();
|
|
||||||
chNumber = new ColumnHeader();
|
chNumber = new ColumnHeader();
|
||||||
|
chPrize = new ColumnHeader();
|
||||||
chValue = new ColumnHeader();
|
chValue = new ColumnHeader();
|
||||||
lblTotalValue = new Label();
|
lblTotalValue = new Label();
|
||||||
lwStockHistory = new ListView();
|
lwStockHistory = new ListView();
|
||||||
histDatum = new ColumnHeader();
|
histAktie = new ColumnHeader();
|
||||||
histKöptSålt = new ColumnHeader();
|
histKöptSålt = new ColumnHeader();
|
||||||
histAntal = new ColumnHeader();
|
histAntal = new ColumnHeader();
|
||||||
histPris = new ColumnHeader();
|
histPris = new ColumnHeader();
|
||||||
histTotBelopp = new ColumnHeader();
|
histTotBelopp = new ColumnHeader();
|
||||||
columnHeader1 = new ColumnHeader();
|
histType = new ColumnHeader();
|
||||||
btnStockHistory = new Button();
|
btnStockHistory = new Button();
|
||||||
SuspendLayout();
|
SuspendLayout();
|
||||||
//
|
//
|
||||||
@ -97,7 +97,7 @@
|
|||||||
//
|
//
|
||||||
// lwStocks
|
// lwStocks
|
||||||
//
|
//
|
||||||
lwStocks.Columns.AddRange(new ColumnHeader[] { chStock, chBought, chPrize, chNumber, chValue });
|
lwStocks.Columns.AddRange(new ColumnHeader[] { chStock, chBought, chNumber, chPrize, chValue });
|
||||||
lwStocks.FullRowSelect = true;
|
lwStocks.FullRowSelect = true;
|
||||||
lwStocks.Location = new Point(111, 103);
|
lwStocks.Location = new Point(111, 103);
|
||||||
lwStocks.Name = "lwStocks";
|
lwStocks.Name = "lwStocks";
|
||||||
@ -115,21 +115,25 @@
|
|||||||
// chBought
|
// chBought
|
||||||
//
|
//
|
||||||
chBought.Text = "Köpt";
|
chBought.Text = "Köpt";
|
||||||
chBought.Width = 100;
|
chBought.Width = 120;
|
||||||
//
|
|
||||||
// chPrize
|
|
||||||
//
|
|
||||||
chPrize.Text = "Köpkurs";
|
|
||||||
chPrize.Width = 100;
|
|
||||||
//
|
//
|
||||||
// chNumber
|
// chNumber
|
||||||
//
|
//
|
||||||
|
chNumber.DisplayIndex = 3;
|
||||||
chNumber.Text = "Antal";
|
chNumber.Text = "Antal";
|
||||||
chNumber.Width = 100;
|
chNumber.TextAlign = HorizontalAlignment.Right;
|
||||||
|
//
|
||||||
|
// chPrize
|
||||||
|
//
|
||||||
|
chPrize.DisplayIndex = 2;
|
||||||
|
chPrize.Text = "Köpkurs";
|
||||||
|
chPrize.TextAlign = HorizontalAlignment.Right;
|
||||||
|
chPrize.Width = 100;
|
||||||
//
|
//
|
||||||
// chValue
|
// chValue
|
||||||
//
|
//
|
||||||
chValue.Text = "Total";
|
chValue.Text = "Total";
|
||||||
|
chValue.TextAlign = HorizontalAlignment.Right;
|
||||||
chValue.Width = 90;
|
chValue.Width = 90;
|
||||||
//
|
//
|
||||||
// lblTotalValue
|
// lblTotalValue
|
||||||
@ -144,7 +148,7 @@
|
|||||||
//
|
//
|
||||||
// lwStockHistory
|
// lwStockHistory
|
||||||
//
|
//
|
||||||
lwStockHistory.Columns.AddRange(new ColumnHeader[] { histDatum, histKöptSålt, histAntal, histPris, histTotBelopp, columnHeader1 });
|
lwStockHistory.Columns.AddRange(new ColumnHeader[] { histAktie, histKöptSålt, histAntal, histPris, histTotBelopp, histType });
|
||||||
lwStockHistory.Location = new Point(113, 311);
|
lwStockHistory.Location = new Point(113, 311);
|
||||||
lwStockHistory.Name = "lwStockHistory";
|
lwStockHistory.Name = "lwStockHistory";
|
||||||
lwStockHistory.Size = new Size(676, 153);
|
lwStockHistory.Size = new Size(676, 153);
|
||||||
@ -152,25 +156,36 @@
|
|||||||
lwStockHistory.UseCompatibleStateImageBehavior = false;
|
lwStockHistory.UseCompatibleStateImageBehavior = false;
|
||||||
lwStockHistory.View = View.Details;
|
lwStockHistory.View = View.Details;
|
||||||
//
|
//
|
||||||
// histDatum
|
// histAktie
|
||||||
//
|
//
|
||||||
histDatum.Text = "Datum";
|
histAktie.Text = "Aktie";
|
||||||
|
histAktie.Width = 100;
|
||||||
//
|
//
|
||||||
// histKöptSålt
|
// histKöptSålt
|
||||||
//
|
//
|
||||||
histKöptSålt.Text = "Köpt/Sålt";
|
histKöptSålt.Text = "Köpt/Sålt";
|
||||||
|
histKöptSålt.Width = 120;
|
||||||
//
|
//
|
||||||
// histAntal
|
// histAntal
|
||||||
//
|
//
|
||||||
histAntal.Text = "Antal";
|
histAntal.Text = "Antal";
|
||||||
|
histAntal.TextAlign = HorizontalAlignment.Right;
|
||||||
//
|
//
|
||||||
// histPris
|
// histPris
|
||||||
//
|
//
|
||||||
histPris.Text = "Betalt/Erhållit";
|
histPris.Text = "Betalt/Erhållit";
|
||||||
|
histPris.TextAlign = HorizontalAlignment.Right;
|
||||||
|
histPris.Width = 100;
|
||||||
//
|
//
|
||||||
// histTotBelopp
|
// histTotBelopp
|
||||||
//
|
//
|
||||||
histTotBelopp.Text = "Summa";
|
histTotBelopp.Text = "Summa";
|
||||||
|
histTotBelopp.TextAlign = HorizontalAlignment.Right;
|
||||||
|
histTotBelopp.Width = 100;
|
||||||
|
//
|
||||||
|
// histType
|
||||||
|
//
|
||||||
|
histType.Text = "K/S/B";
|
||||||
//
|
//
|
||||||
// btnStockHistory
|
// btnStockHistory
|
||||||
//
|
//
|
||||||
@ -220,11 +235,11 @@
|
|||||||
private ColumnHeader chValue;
|
private ColumnHeader chValue;
|
||||||
private ListView lwStockHistory;
|
private ListView lwStockHistory;
|
||||||
private Button btnStockHistory;
|
private Button btnStockHistory;
|
||||||
private ColumnHeader histDatum;
|
private ColumnHeader histAktie;
|
||||||
private ColumnHeader histKöptSålt;
|
private ColumnHeader histKöptSålt;
|
||||||
private ColumnHeader histAntal;
|
private ColumnHeader histAntal;
|
||||||
private ColumnHeader histPris;
|
private ColumnHeader histPris;
|
||||||
private ColumnHeader histTotBelopp;
|
private ColumnHeader histTotBelopp;
|
||||||
private ColumnHeader columnHeader1;
|
private ColumnHeader histType;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -58,15 +58,15 @@ public partial class frmStockHistoryAnalyse : Form
|
|||||||
{
|
{
|
||||||
var item = new ListViewItem(equityTemp.StockCode);
|
var item = new ListViewItem(equityTemp.StockCode);
|
||||||
item.SubItems.Add(equityTemp.Bought.ToString());
|
item.SubItems.Add(equityTemp.Bought.ToString());
|
||||||
item.SubItems.Add(equityTemp.BoughtPrice.ToString());
|
|
||||||
item.SubItems.Add(equityTemp.Quantity.ToString());
|
item.SubItems.Add(equityTemp.Quantity.ToString());
|
||||||
|
item.SubItems.Add(equityTemp.BoughtPrice.ToString());
|
||||||
item.SubItems.Add((equityTemp.TotalValue).ToString("C"));
|
item.SubItems.Add((equityTemp.TotalValue).ToString("C"));
|
||||||
lwStocks.Items.Add(item);
|
lwStocks.Items.Add(item);
|
||||||
}
|
}
|
||||||
equityTemp.StockCode = t.StockCode;
|
equityTemp.StockCode = t.StockCode;
|
||||||
equityTemp.Bought = t.Bought;
|
equityTemp.Bought = t.Bought;
|
||||||
equityTemp.BoughtPrice = t.BoughtPrice;
|
|
||||||
equityTemp.Quantity = t.Quantity;
|
equityTemp.Quantity = t.Quantity;
|
||||||
|
equityTemp.BoughtPrice = t.BoughtPrice;
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -81,8 +81,8 @@ public partial class frmStockHistoryAnalyse : Form
|
|||||||
}
|
}
|
||||||
var l_item = new ListViewItem(equityTemp.StockCode);
|
var l_item = new ListViewItem(equityTemp.StockCode);
|
||||||
l_item.SubItems.Add(equityTemp.Bought.ToString());
|
l_item.SubItems.Add(equityTemp.Bought.ToString());
|
||||||
l_item.SubItems.Add(equityTemp.BoughtPrice.ToString());
|
|
||||||
l_item.SubItems.Add(equityTemp.Quantity.ToString());
|
l_item.SubItems.Add(equityTemp.Quantity.ToString());
|
||||||
|
l_item.SubItems.Add(equityTemp.BoughtPrice.ToString());
|
||||||
l_item.SubItems.Add((equityTemp.TotalValue).ToString("C"));
|
l_item.SubItems.Add((equityTemp.TotalValue).ToString("C"));
|
||||||
lwStocks.Items.Add(l_item);
|
lwStocks.Items.Add(l_item);
|
||||||
}
|
}
|
||||||
@ -110,7 +110,7 @@ public partial class frmStockHistoryAnalyse : Form
|
|||||||
LoadHistoryRecsAsync(item.Text).Wait();
|
LoadHistoryRecsAsync(item.Text).Wait();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
private async Task LoadHistoryRecsAsync(string stockName)
|
private async Task LoadHistoryRecsAsync(string stockName) //, DateTime equityDate)
|
||||||
{
|
{
|
||||||
//MessageBox.Show("Du klickade på: " + item.Text);
|
//MessageBox.Show("Du klickade på: " + item.Text);
|
||||||
var result = _equityServices.GetByCodeAsync(stockName);
|
var result = _equityServices.GetByCodeAsync(stockName);
|
||||||
@ -121,11 +121,12 @@ public partial class frmStockHistoryAnalyse : Form
|
|||||||
{
|
{
|
||||||
var l_item = new ListViewItem(histRec.StockCode);
|
var l_item = new ListViewItem(histRec.StockCode);
|
||||||
l_item.SubItems.Add(histRec.Bought.ToString());
|
l_item.SubItems.Add(histRec.Bought.ToString());
|
||||||
l_item.SubItems.Add(histRec.BoughtPrice.ToString());
|
|
||||||
l_item.SubItems.Add(histRec.Quantity.ToString());
|
l_item.SubItems.Add(histRec.Quantity.ToString());
|
||||||
|
l_item.SubItems.Add(histRec.BoughtPrice.ToString());
|
||||||
Debug.WriteLine(histRec.ToString());
|
Debug.WriteLine(histRec.ToString());
|
||||||
var totval = (histRec.SoldQuant > 0) ? histRec.SoldQuant * histRec.SoldPrice - histRec.BoughtPrice * histRec.Quantity : histRec.BoughtPrice * histRec.Quantity;
|
var totval = (histRec.SoldQuant > 0) ? histRec.SoldQuant * histRec.SoldPrice - histRec.BoughtPrice * histRec.Quantity : histRec.BoughtPrice * histRec.Quantity;
|
||||||
l_item.SubItems.Add((totval).ToString("C"));
|
l_item.SubItems.Add((totval).ToString("C"));
|
||||||
|
l_item.SubItems.Add((histRec.SoldQuant > 0) ? "B" : "K");
|
||||||
lwStockHistory.Items.Add(l_item);
|
lwStockHistory.Items.Add(l_item);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user