public string InsertPurchase(InventoryPurchase aInventoryPurchase) { InventoryPurchaseDAO aDao = new InventoryPurchaseDAO(); string sr = aDao.InsertPurchase(aInventoryPurchase); return(sr); }
public List <InventoryPurchase> GetInventoryPurchaseBetweenDate(DateTime fromdate, DateTime todate) { List <InventoryPurchase> aInventoryPurchases = new List <InventoryPurchase>(); try { this.OpenConnection(); string sqlComm = String.Format(SqlQueries.GetQuery(Query.GetInventoryPurchaseBetweenDate), fromdate, todate); IDataReader aReader = this.ExecuteReader(sqlComm); if (aReader != null) { while (aReader.Read()) { InventoryPurchase aInventoryPurchase = new InventoryPurchase(); aInventoryPurchase = ReaderToReadInventoryPurchase(aReader); aInventoryPurchases.Add(aInventoryPurchase); } } } catch (Exception ex) { throw new Exception("GetInventoryPurchaseBetweenDate()", ex); } finally { this.CloseConnection(); } return(aInventoryPurchases); }
public string InsertPurchase(InventoryPurchase aInventoryPurchase) { string sr = string.Empty; try { this.OpenConnection(); string sqlCommand = String.Format(SqlQueries.GetQuery(Query.InsertPurchase), aInventoryPurchase.Category.CategoryId, aInventoryPurchase.Category.CategoryName, aInventoryPurchase.Item.ItemId, aInventoryPurchase.Item.ItemName, aInventoryPurchase.Supplier.SupplierId, aInventoryPurchase.Supplier.Name, aInventoryPurchase.Quantity, aInventoryPurchase.Unit.UnitName, aInventoryPurchase.Price, aInventoryPurchase.Supplier.PaidAmount, aInventoryPurchase.Supplier.AdvanceAmount, aInventoryPurchase.Supplier.DueAmount, aInventoryPurchase.Date, aInventoryPurchase.PaymentType, aInventoryPurchase.CUserInfo.UserName, aInventoryPurchase.ExpireDate); this.ExecuteNonQuery(sqlCommand); sr = "Purchase Insert Sucessfully"; } catch { sr = "Please Try Again"; } finally { this.CloseConnection(); } return(sr); }
private void savePurchasebutton_Click(object sender, EventArgs e) { try { if (expiredateTimePicker.Value.Date == DateTime.Now.Date) { DialogResult result = MessageBox.Show("Do you want to Empty Expire Date?", "Confirmation", MessageBoxButtons.YesNo); if (result == DialogResult.Yes) { } else if (result == DialogResult.No) { return; } } if (pricetextBox.Text.Length != 0 && paidPricetextBox.Text.Length != 0 && quantitytextBox.Text.Length != 0) { InventoryPurchase aInventoryPurchase = new InventoryPurchase(); InventoryCategory aCategory = new InventoryCategory(); InventoryItem aItem = new InventoryItem(); Supplier aSupplier = new Supplier(); Supplier aaSupplier = new Supplier(); Unit aUnit = new Unit(); //Add for purchase record aCategory = (InventoryCategory)categoryNamecomboBox.Items[categoryNamecomboBox.SelectedIndex]; SupplierBLL aSupplierBll = new SupplierBLL(); aSupplier = aSupplierBll.GetSupplierByid(Convert.ToInt32(supplierNamecomboBox.SelectedValue)); // aSupplier = (Supplier) supplierNamecomboBox.Items[supplierNamecomboBox.SelectedIndex]; if (aSupplier.PaidAmount > aSupplier.TotalAmount) { aSupplier.AdvanceAmount = aSupplier.PaidAmount - aSupplier.TotalAmount; } else { aSupplier.DueAmount = aSupplier.TotalAmount - aSupplier.PaidAmount; } aItem = (InventoryItem)itemNamecomboBox.Items[itemNamecomboBox.SelectedIndex]; aInventoryPurchase.Quantity = Convert.ToDouble(quantitytextBox.Text); aInventoryPurchase.Price = Convert.ToDouble(pricetextBox.Text); aInventoryPurchase.Date = DateTime.Now; aInventoryPurchase.Category = aCategory; aInventoryPurchase.Item = aItem; aaSupplier.PaidAmount = Convert.ToDouble(paidPricetextBox.Text); aInventoryPurchase.Supplier = aaSupplier; if (((aSupplier.DueAmount + Convert.ToDouble(pricetextBox.Text) - (Convert.ToDouble(paidPricetextBox.Text) + aSupplier.AdvanceAmount))) >= 0) { aInventoryPurchase.Supplier.DueAmount = aSupplier.DueAmount + Convert.ToDouble(pricetextBox.Text) - (Convert.ToDouble(paidPricetextBox.Text) + aSupplier.AdvanceAmount); } else { aInventoryPurchase.Supplier.DueAmount = 0.0; } if (((Convert.ToDouble(paidPricetextBox.Text) + aSupplier.AdvanceAmount) - (aSupplier.DueAmount + Convert.ToDouble(pricetextBox.Text))) >= 0) { aInventoryPurchase.Supplier.AdvanceAmount = (Convert.ToDouble(paidPricetextBox.Text) + aSupplier.AdvanceAmount) - (aSupplier.DueAmount + Convert.ToDouble(pricetextBox.Text)); } else { aInventoryPurchase.Supplier.AdvanceAmount = 0.0; } aInventoryPurchase.Supplier.Name = aSupplier.Name; aInventoryPurchase.Supplier.SupplierId = aSupplier.SupplierId; aUnit.UnitName = unittypelabel.Text; aInventoryPurchase.Unit = aUnit; CUserInfo aUserInfo = new CUserInfo(); aUserInfo.UserName = RMSGlobal.LogInUserName; aInventoryPurchase.PaymentType = paymentTypecomboBox.SelectedItem.ToString(); aInventoryPurchase.CUserInfo = aUserInfo; if (expiredateTimePicker.Value.Date == DateTime.Now.Date) { } else { aInventoryPurchase.ExpireDate = expiredateTimePicker.Value.Date; } string res = string.Empty; InventoryPurchaseBLL aInventoryPurchaseBll = new InventoryPurchaseBLL(); res = aInventoryPurchaseBll.InsertPurchase(aInventoryPurchase); if (res == "Purchase Insert Sucessfully") { //Add for Supplier Update aSupplier.TotalAmount += Convert.ToDouble(pricetextBox.Text); aSupplier.PaidAmount += Convert.ToDouble(paidPricetextBox.Text); aSupplierBll.UpdateSupplierForPurchase(aSupplier); //Add for Supplier payment report Supplier paymentSupplier = new Supplier(); paymentSupplier.PaidAmount = Convert.ToDouble(paidPricetextBox.Text); paymentSupplier.TotalAmount = Convert.ToDouble(pricetextBox.Text); paymentSupplier.SupplierId = aSupplier.SupplierId; paymentSupplier.PaymentType = paymentTypecomboBox.SelectedItem.ToString(); aSupplierBll.InsertIntosupplier_payment_reportForSupplierPaymentTrack(paymentSupplier); //Add for stock update Stock aStock = new Stock(); aStock.Category = aCategory; aStock.Item = aItem; aStock.Unit = aUnit; aStock.Stocks = Convert.ToDouble(quantitytextBox.Text); aStock.UnitPrice = Convert.ToDouble(pricetextBox.Text) / aStock.Stocks; StockBLL aStockBll = new StockBLL(); aStockBll.InsertStockOrUpdate(aStock); purchaseActionlabel.Visible = true; purchaseActionlabel.Text = res; Clear(); } else { purchaseActionlabel.Visible = true; purchaseActionlabel.Text = res; } } else { purchaseActionlabel.Visible = true; purchaseActionlabel.Text = "Please Check Your Input"; } } catch { MessageBox.Show("Try Again May Be Your Given Input Format Not Correct Please Given Again "); } }
public StockItem InsertStockItem(InventoryPurchase inventoryPurchase, int colorId, int packageId) { StockItem result = null; using (var Conn = new SqlConnection(_connectionString)) { // Open SQL Connection Conn.Open(); // Add stock item using (var Cmd = new SqlCommand(@" insert into Warehouse.StockItems ( StockItemName, SupplierID, UnitPackageID, OuterPackageID, ColorId, LeadTimeDays, QuantityPerOuter, IsChillerStock, TaxRate, UnitPrice, RecommendedRetailPrice, TypicalWeightPerUnit, MarketingComments, LastEditedBy) output INSERTED.StockItemId values ( @StockItemName, 12, 1, @OuterPackageId, @ColorId, 5, 4, 0, 15, @UnitPrice, @RetailPrice, .05, @MarketingComments, 1)", Conn)) { Cmd.Parameters.Add("@StockItemName", SqlDbType.NVarChar); Cmd.Parameters.Add("@OuterPackageId", SqlDbType.Int); Cmd.Parameters.Add("@ColorId", SqlDbType.Int); Cmd.Parameters.Add("@UnitPrice", SqlDbType.Decimal); Cmd.Parameters.Add("@RetailPrice", SqlDbType.Decimal); Cmd.Parameters.Add("@MarketingComments", SqlDbType.NVarChar); Cmd.Parameters["@StockItemName"].Value = inventoryPurchase.StockItemName; Cmd.Parameters["@OuterPackageId"].Value = packageId; Cmd.Parameters["@ColorId"].Value = colorId; Cmd.Parameters["@UnitPrice"].Value = inventoryPurchase.UnitPrice; Cmd.Parameters["@RetailPrice"].Value = inventoryPurchase.RecommendedRetailPrice; Cmd.Parameters["@MarketingComments"].Value = inventoryPurchase.MarketingComments; // Execute SQL Command Int32 id = (Int32)Cmd.ExecuteScalar(); result = new StockItem(); result.ID = id; result.StockItemName = inventoryPurchase.StockItemName; result.ColorID = colorId; result.OuterPackageID = packageId; result.UnitPrice = inventoryPurchase.UnitPrice; result.RecommendedRetailPrice = inventoryPurchase.RecommendedRetailPrice; result.MarketingComments = inventoryPurchase.MarketingComments; } // Add initial holdings using (var Cmd = new SqlCommand(@" insert into Warehouse.StockItemHoldings(StockItemID, QuantityOnHand, BinLocation, LastStocktakeQuantity, LastCostPrice, ReorderLevel, TargetStockLevel, LastEditedBy) values (@StockItemID, 0, 'L-3', 1000, 5.00, 10, 1000, 3)", Conn)) { Cmd.Parameters.Add("@StockItemID", SqlDbType.Int); Cmd.Parameters["@StockItemID"].Value = result.ID; // Execute SQL Command Cmd.ExecuteNonQuery(); } // Add to stock group using (var Cmd = new SqlCommand(@" insert into Warehouse.StockItemStockGroups(StockItemID, StockGroupID, LastEditedBy) values (@StockItemID, 1, 3)", Conn)) { Cmd.Parameters.Add("@StockItemID", SqlDbType.Int); Cmd.Parameters["@StockItemID"].Value = result.ID; // Execute SQL Command Cmd.ExecuteNonQuery(); } Conn.Close(); } return(result); }
private InventoryPurchase ReaderToReadInventoryPurchase(IDataReader aReader) { InventoryPurchase aInventoryPurchase = new InventoryPurchase(); InventoryCategory aCategory = new InventoryCategory(); InventoryItem aItem = new InventoryItem(); Supplier aSupplier = new Supplier(); Unit aUnit = new Unit(); CUserInfo aCUserInfo = new CUserInfo(); try { aCategory.CategoryId = Convert.ToInt32(aReader["category_id"]); } catch { } try { aCategory.CategoryName = aReader["category_name"].ToString(); } catch { } try { aItem.ItemId = Convert.ToInt32(aReader["item_id"]); } catch { } try { aItem.ItemName = (aReader["item_name"]).ToString(); } catch { } try { aSupplier.SupplierId = Convert.ToInt32(aReader["supplier_id"]); } catch { } try { aSupplier.Name = (aReader["supplier_name"]).ToString(); } catch { } try { aInventoryPurchase.PurchaseId = Convert.ToInt32((aReader["purchase_id"])); } catch { } try { aInventoryPurchase.Quantity = Convert.ToDouble((aReader["quantity"])); } catch { } try { aUnit.UnitName = (aReader["unit"]).ToString(); } catch { } try { aInventoryPurchase.Price = Convert.ToDouble((aReader["total_price"])); } catch { } try { aSupplier.PaidAmount = Convert.ToDouble((aReader["paid_amount"])); } catch { } try { aSupplier.AdvanceAmount = Convert.ToDouble((aReader["advance_amount"])); } catch { } try { aSupplier.DueAmount = Convert.ToDouble((aReader["due_amount"])); } catch { } try { aInventoryPurchase.Date = Convert.ToDateTime((aReader["date"])); } catch { } try { aInventoryPurchase.PaymentType = ((aReader["payment_type"])).ToString(); } catch { } try { aCUserInfo.UserName = ((aReader["user_name"])).ToString(); } catch { } try { aInventoryPurchase.ExpireDate = Convert.ToDateTime((aReader["ExpireDate"])); } catch { } aInventoryPurchase.Category = aCategory; aInventoryPurchase.Item = aItem; aInventoryPurchase.Supplier = aSupplier; aInventoryPurchase.Unit = aUnit; aInventoryPurchase.CUserInfo = aCUserInfo; return(aInventoryPurchase); // DateTime aTime = DateTime.Now.AddDays(-1); }