private ReportProfitItem QueryProfit(ReportTranItem stock, DateTime queryDate) { var data = _db.StocksHistory .Where(x => x.StockId == stock.StockId && x.TranDate == queryDate.ToDate()) .Select(x => new { x.StockId, x.ClosingPrice }) .First(); var currentPrice = data.ClosingPrice; var currentTotal = data.ClosingPrice * stock.NumberOfShare; var profit = 0m; if (currentTotal != 0) { profit = stock.Balance + currentTotal; } var reportProfitItem = new ReportProfitItem() { StockId = stock.StockId, StockName = stock.StockName, Date = queryDate, StockPrice = currentPrice, Profit = profit }; return(reportProfitItem); }
private static AccountByMonthExport NewMonthExport(ReportProfitItem p) { AccountByMonthExport e = new AccountByMonthExport(); e.Account = p.Account.Name; e.MonthStart = MonthStart(p.Allocation.Month); e.Year = e.MonthStart.Year; e.Quarter = e.MonthStart.GetQuarter(); e.Month = e.MonthStart.Month; e.CostAllocation = p.Allocation.Cost.GetValueOrDefault(); e.Margin = p.WorkDoneMargin.GetValueOrDefault(); e.BillableDays = p.Allocation.Days.GetValueOrDefault(); e.Profit = e.Margin - e.CostAllocation; e.ForecastDayRate = p.Allocation.DayRate.GetValueOrDefault(); e.ForecastMargin = e.ForecastDayRate * e.BillableDays; return(e); }