public static SkuInStock Restore(Article in_article, PointOfSale in_pointOfSale) { SkuInStock skuInStock = new SkuInStock() { Article = in_article, PointOfSale = in_pointOfSale }; using SQLiteConnection conn = ConnectionRegistry.Instance.OpenNewConnection(); using SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.Parameters.Add(new SQLiteParameter("@in_articleId", in_article.Id)); cmd.Parameters.Add(new SQLiteParameter("@in_pointOfSaleId", in_pointOfSale.Id)); cmd.CommandText = "select *" + " from cell_in_stock" + " where point_of_sale_id = @in_pointOfSaleId" + " and article_id = @in_articleId"; DataTable table = new DataTable(); using (SQLiteDataAdapter a = new SQLiteDataAdapter(cmd)) a.Fill(table); DressMatrix mtx = in_article.Matrix; CellInStock[,] cells = new CellInStock[mtx.CellsX.Count, mtx.CellsY.Count]; foreach (DataRow row in table.Rows) { int x = mtx.CellsX.IndexOf((string)row["x"]); int y = mtx.CellsY.IndexOf((string)row["y"]); cells[x, y] = CellInStock.Restore((int)(long)row["id"], UnixEpoch.ToDateTime((long)row["modified"]), skuInStock, (string)row["x"], (string)row["y"], (int)(long)row["amount"]); } for (int x = 0; x < mtx.CellsX.Count; x++) { for (int y = 0; y < mtx.CellsY.Count; y++) { if (cells[x, y] == null) { cells[x, y] = CellInStock.Restore(0, DateTime.Now, skuInStock, mtx.CellsX[x], mtx.CellsY[y], 0); } } } skuInStock.SetCells(cells); return(skuInStock); }
public static DocSale CreateNew(DateTime in_timeSold, Article in_article, PointOfSale in_pointOfSale, int in_unitPrice, int in_unitCount, CellInStock in_cell, bool in_paymentByCard) => new DocSale { _timeSold = in_timeSold, _articleId = in_article.Id, _articleName = in_article.Name, _articlePriceOfPurchase = in_article.PriceOfPurchase, _articlePriceOfSell = in_article.PriceOfSell, _pointOfSaleId = in_pointOfSale.Id, _pointOfSaleName = in_pointOfSale.Name, _unitPrice = in_unitPrice, _unitCount = in_unitCount, _cellX = in_cell.X, _cellY = in_cell.Y, _paymentByCard = in_paymentByCard };
public static SkuInStock CreateNew(Article in_article, PointOfSale in_pointOfSale) { SkuInStock result = new SkuInStock() { _article = in_article, _pointOfSale = in_pointOfSale }; DressMatrix mtx = in_article.Matrix; result._cells = new CellInStock[mtx.CellsX.Count, mtx.CellsY.Count]; for (int x = 0; x < mtx.CellsX.Count; x++) { for (int y = 0; y < mtx.CellsY.Count; y++) { result._cells[x, y] = CellInStock.Restore(0, DateTime.Now, result, mtx.CellsX[x], mtx.CellsY[y], 0); } } return(result); }
public static DataTable ReadSalesJournal(PointOfSale in_pointOfSale, DateTime in_dateBegin, DateTime in_dateEnd, ShowRows in_displayMode) { using SQLiteConnection conn = ConnectionRegistry.Instance.OpenNewConnection(); using SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.Parameters.Add(new SQLiteParameter("@in_pointOfSaleId", in_pointOfSale.Id)); cmd.Parameters.Add(new SQLiteParameter("@in_dateBegin", UnixEpoch.FromDateTime(in_dateBegin))); cmd.Parameters.Add(new SQLiteParameter("@in_dateEndNext", UnixEpoch.FromDateTime(in_dateEnd.AddDays(1)))); string wherePayedByCard = string.Empty; if (in_displayMode == ShowRows.OnlyCash || in_displayMode == ShowRows.OnlyCard) { cmd.Parameters.Add(new SQLiteParameter("@in_payedByCard", in_displayMode == ShowRows.OnlyCash ? 0 : 1)); wherePayedByCard = " and s.payment_by_card = @in_payedByCard"; } cmd.CommandText = "select" + " s.id," + " date(s.time_sold, 'unixepoch', 'localtime') as time_sold," + " s.art_name," + " s.art_price_of_purchase," + " s.art_price_of_sell," + " s.unit_price," + " s.unit_count," + " (s.unit_price * s.unit_count) as price_sum," + " s.cell_x," + " s.cell_y" + " from doc_sale s" + " join doc d on d.id = s.id and d.time_cancelled is null" + " where s.point_of_sale_id = @in_pointOfSaleId" + " and @in_dateBegin <= s.time_sold and s.time_sold < @in_dateEndNext" + wherePayedByCard + " order by s.time_sold desc;"; DataTable table = new DataTable(); using (SQLiteDataAdapter a = new SQLiteDataAdapter(cmd)) a.Fill(table); return(table); }
public static Summary GetSummary(PointOfSale in_pointOfSale, DateTime in_dateBegin, DateTime in_dateEnd, ShowRows in_displayMode) { using SQLiteConnection conn = ConnectionRegistry.Instance.OpenNewConnection(); using SQLiteCommand cmd = conn.CreateCommand(); cmd.CommandType = CommandType.Text; cmd.Parameters.Add(new SQLiteParameter("@in_pointOfSaleId", in_pointOfSale.Id)); cmd.Parameters.Add(new SQLiteParameter("@in_dateBegin", UnixEpoch.FromDateTime(in_dateBegin))); cmd.Parameters.Add(new SQLiteParameter("@in_dateEndNext", UnixEpoch.FromDateTime(in_dateEnd.AddDays(1)))); string wherePayedByCard = string.Empty; if (in_displayMode == ShowRows.OnlyCash || in_displayMode == ShowRows.OnlyCard) { cmd.Parameters.Add(new SQLiteParameter("@in_payedByCard", in_displayMode == ShowRows.OnlyCash ? 0 : 1)); wherePayedByCard = " and s.payment_by_card = @in_payedByCard"; } cmd.CommandText = "select" + " COUNT(s.id) as cnt," + " IFNULL(SUM(s.unit_price * s.unit_count), 0) as sm," + " IFNULL(SUM(s.unit_price * s.unit_count - s.art_price_of_purchase * s.unit_count), 0) as profit" + " from doc_sale s" + " join doc d on d.id = s.id and d.time_cancelled is null" + " where s.point_of_sale_id = @in_pointOfSaleId" + " and @in_dateBegin <= s.time_sold and s.time_sold < @in_dateEndNext" + wherePayedByCard; DataTable table = new DataTable(); using (SQLiteDataAdapter a = new SQLiteDataAdapter(cmd)) a.Fill(table); DataRow row = table.Rows[0]; return(new Summary() { Count = (int)(long)row["cnt"], Sum = (int)(long)row["sm"], Profit = (int)(long)row["profit"] }); }