public ActionResult Create([Bind(Include = "ProductTypeID,TypeName")] ProductType productType) { if (ModelState.IsValid) { db.ProductTypes.Add(productType); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(productType)); }
public ActionResult Create([Bind(Include = "VendorName,Address,MobileNo")] Vendor vendor) { if (ModelState.IsValid) { db.Vendors.Add(vendor); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(vendor)); }
public ActionResult Create([Bind(Include = "CategoryID,CategoryName,Desc")] Category category) { if (ModelState.IsValid) { db.Categories.Add(category); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(category)); }
public ActionResult Create([Bind(Include = "ProductID,ProductName,OrderID,AppxWeight,ActualWeight,Description,IsActive,CreatedDate,CreatedBy,UpdatedDate,Updatedby")] CustomerProduct customerProduct) { if (ModelState.IsValid) { db.CustomerProducts.Add(customerProduct); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customerProduct)); }
public ActionResult Create([Bind(Include = "CustmerName,Address")] Customer customer) { if (ModelState.IsValid) { db.Customers.Add(customer); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(customer)); }
// vendor public List<VendorDetailsModel> AddVendor(VendorDetailsModel vendorModel) { List<VendorDetailsModel> lstvendors = new List<VendorDetailsModel>(); using (ShopDevEntities db = new ShopDevEntities()) { try { vendorModel.BulkByID = vendorModel.BulkByID == null ? 0 : vendorModel.BulkByID; VendorDetail vendordetails = null; if (vendorModel.VendorCode == null) { Vendor vendor = new Vendor { VendorName = vendorModel.VendorName, Address = vendorModel.Address, MobileNo= vendorModel.MobileNo, TotalBulks=1 }; db.Vendors.Add(vendor); db.SaveChanges(); vendorModel.VendorCode = vendor.VendorCode; } if (vendorModel.BuyVendorID > 0) { vendordetails = db.VendorDetails.Where(m => m.BuyVendorID == vendorModel.BuyVendorID).FirstOrDefault(); } else { vendordetails = new VendorDetail(); } vendorModel.CopyProperties(vendordetails); if (vendorModel.BuyVendorID == 0) { db.VendorDetails.Add(vendordetails); } db.SaveChanges(); var lstAllvendors = db.VendorDetails.Where(m => m.BulkByID == vendorModel.BulkByID).ToList(); foreach (var cusprod in lstAllvendors) { VendorDetailsModel objcsproduct = new VendorDetailsModel(); cusprod.CopyProperties(objcsproduct); lstvendors.Add(objcsproduct); } return lstvendors; } catch (Exception) { return lstvendors; } } }
public ActionResult Edit([Bind(Include = "BulkBuyID,CustomerName,Address,TakenAmount,Rate,GWeight,SWeight,Status")] BulkBuy bulkBuy) { if (ModelState.IsValid) { db.Entry(bulkBuy).State = EntityState.Modified; db.SaveChanges(); TempData["Message"] = "Bulk updated Successfully !"; return(RedirectToAction("Index")); } ViewBag.ProductTypeID = new SelectList(db.ProductTypes, "TypeName", "TypeName"); return(View(bulkBuy)); }
public void AddSeller(SellerModel seller) { using (ShopDevEntities db = new ShopDevEntities()) { try { Seller sellerdb = null; if (seller.SellerID == 0) { sellerdb = new Seller(); seller.CopyProperties(sellerdb); db.Sellers.Add(sellerdb); } else { sellerdb = db.Sellers.Where(m => m.SellerID == seller.SellerID).FirstOrDefault(); seller.CopyProperties(sellerdb); } db.SaveChanges(); List <SellerProduct> lstNewproducts = db.SellerProducts.Where(m => m.SellerID == 0).ToList(); lstNewproducts.ForEach(m => m.SellerID = sellerdb.SellerID); foreach (var product in lstNewproducts) { var oldproduct = db.Products.Where(m => m.ProductName == product.ProductName && m.Type == product.Type && m.CategoryID == product.CategoryID).FirstOrDefault(); if (oldproduct != null) { oldproduct.Unit += product.Unit; } else { Product prod = new Product(); prod.ProductName = product.ProductName; prod.ProdDesc = product.Description; prod.Type = product.Type; prod.CategoryID = product.CategoryID; prod.Unit = product.Unit; prod.IsActive = true; db.Products.Add(prod); } } List <SellerInstallment> lstinstallments = db.SellerInstallments.Where(m => m.SellerID == 0).ToList(); lstinstallments.ForEach(m => m.SellerID = sellerdb.SellerID); db.SaveChanges(); } catch { } } }
public List <SellerInstallmentModel> DeleteSellerInstallment(long Id, long sellerID) { List <SellerInstallmentModel> lstinstallments = new List <SellerInstallmentModel>(); using (ShopDevEntities db = new ShopDevEntities()) { try { SellerInstallment installment = GetSellerInstallment(db, Id); db.SellerInstallments.Remove(installment); db.SaveChanges(); var lstproducts = db.SellerInstallments.Where(m => m.SellerID == sellerID).ToList(); foreach (var cusprod in lstproducts) { SellerInstallmentModel objInstallments = new SellerInstallmentModel(); cusprod.CopyProperties(objInstallments); lstinstallments.Add(objInstallments); } } catch (Exception) { } return(lstinstallments); } }
public List<VendorDetailsModel> DeleteVendor(long Id, long bulkBuyID) { List<VendorDetailsModel> lstvendors = new List<VendorDetailsModel>(); using (ShopDevEntities db = new ShopDevEntities()) { try { VendorDetail vendor = GetVendor(db, Id); db.VendorDetails.Remove(vendor); db.SaveChanges(); var lstproducts = db.VendorDetails.Where(m => m.BulkByID == bulkBuyID).ToList(); foreach (var cusprod in lstproducts) { VendorDetailsModel objvendor = new VendorDetailsModel(); cusprod.CopyProperties(objvendor); lstvendors.Add(objvendor); } } catch (Exception) { } return lstvendors; } }
public List <BorrowerInstallmentModel> DeleteBorrowerInstallment(long Id, long buyerID) { List <BorrowerInstallmentModel> lstinstallments = new List <BorrowerInstallmentModel>(); using (ShopDevEntities db = new ShopDevEntities()) { try { BorrowerInstallment installment = GetBorrowerInstallment(db, Id); var borrower = db.Borrowers.Where(m => m.BorrowID == installment.BorrowerID).FirstOrDefault(); var outstandingAmount = borrower.Outstanding; borrower.Outstanding = outstandingAmount == null ? installment.Amount : outstandingAmount + installment.Amount; var interstableAmount = borrower.InterstableAmount; borrower.InterstableAmount = interstableAmount == null ? installment.Amount : interstableAmount + installment.Amount; db.BorrowerInstallments.Remove(installment); db.SaveChanges(); var lstproducts = db.BorrowerInstallments.Where(m => m.BorrowerID == buyerID).ToList(); foreach (var cusprod in lstproducts) { BorrowerInstallmentModel objInstallments = new BorrowerInstallmentModel(); cusprod.CopyProperties(objInstallments); lstinstallments.Add(objInstallments); } } catch (Exception) { } return(lstinstallments); } }
public List<Installments> DeleteDeleteInstallment(long Id, long bulkBuyID) { List<Installments> lstinstallments = new List<Installments>(); using (ShopDevEntities db = new ShopDevEntities()) { try { BulkBuyInstallment installment = GetInstallment(db, Id); var bulkbuy = db.BulkBuys.Where(m => m.BulkBuyID == bulkBuyID).FirstOrDefault(); var outstandingAmount = bulkbuy.OustandingAmont; bulkbuy.OustandingAmont = outstandingAmount == null ? installment.Amount : outstandingAmount + installment.Amount; var interstableAmount = bulkbuy.InterstableAmount; bulkbuy.InterstableAmount = interstableAmount == null ? installment.Amount : interstableAmount + installment.Amount; db.BulkBuyInstallments.Remove(installment); db.SaveChanges(); var lstproducts = db.BulkBuyInstallments.Where(m => m.BulkBuyID == bulkBuyID).ToList(); foreach (var cusprod in lstproducts) { Installments objInstallments = new Installments(); cusprod.CopyProperties(objInstallments); lstinstallments.Add(objInstallments); } } catch (Exception) { } return lstinstallments; } }
public List <CustomerProductModel> DeleteCustomerProduct(long Id, long orderId) { List <CustomerProductModel> lstcsproducts = new List <CustomerProductModel>(); using (ShopDevEntities db = new ShopDevEntities()) { try { CustomerProduct customerProduct = GetCustomerProduct(db, Id); customerProduct.IsActive = false; db.CustomerProducts.Remove(customerProduct); db.SaveChanges(); var lstproducts = db.CustomerProducts.Where(m => m.OrderID == orderId && m.IsActive).ToList(); foreach (var cusprod in lstproducts) { CustomerProductModel objcsproducts = new CustomerProductModel(); cusprod.CopyProperties(objcsproducts); lstcsproducts.Add(objcsproducts); } } catch (Exception) { } return(lstcsproducts); } }
public List<BulkBuyProductsModel> DeleteProduct(long Id, long bulkBuyID) { List<BulkBuyProductsModel> lstbulkproducts = new List<BulkBuyProductsModel>(); using (ShopDevEntities db = new ShopDevEntities()) { try { BulkBuyProduct product = GetProduct(db, Id); db.BulkBuyProducts.Remove(product); db.SaveChanges(); var lstproducts = db.BulkBuyProducts.Where(m => m.BulkBuyID == bulkBuyID).ToList(); foreach (var cusprod in lstproducts) { BulkBuyProductsModel objcsproducts = new BulkBuyProductsModel(); cusprod.CopyProperties(objcsproducts); lstbulkproducts.Add(objcsproducts); } } catch (Exception) { } return lstbulkproducts; } }
public ActionResult DeleteConfirmed(long id) { Seller seller = db.Sellers.Find(id); db.Sellers.Remove(seller); db.SaveChanges(); return(RedirectToAction("Index")); }
public List <BuyerProductModel> AddBuyerProduct(BuyerProductModel productModel) { List <BuyerProductModel> lstcsproducts = new List <BuyerProductModel>(); using (ShopDevEntities db = new ShopDevEntities()) { try { productModel.BuyerID = productModel.BuyerID == null ? 0 : productModel.BuyerID; BuyerProduct buyerproduct = null; int? oldUnits = 0; if (productModel.BuyerProductlD > 0) { buyerproduct = db.BuyerProducts.Where(m => m.BuyerProductlD == productModel.BuyerProductlD).FirstOrDefault(); oldUnits = buyerproduct.Units == null ? 0 : buyerproduct.Units; var diffUnit = oldUnits - productModel.Units; var product = db.Products.Where(m => m.ProductName == productModel.ProductName).FirstOrDefault(); if (product != null) { product.Unit += diffUnit; } } else { buyerproduct = new BuyerProduct(); } productModel.CopyProperties(buyerproduct); if (productModel.BuyerProductlD == 0) { db.BuyerProducts.Add(buyerproduct); if (productModel.BuyerID > 0) { var oldproduct = db.Products.Where(m => m.ProductName == productModel.ProductName && m.Type == productModel.Type).FirstOrDefault(); if (oldproduct != null) { oldproduct.Unit -= productModel.Units; } } } db.SaveChanges(); var lstproducts = db.BuyerProducts.Where(m => m.BuyerID == productModel.BuyerID).ToList(); foreach (var cusprod in lstproducts) { BuyerProductModel objcsproduct = new BuyerProductModel(); cusprod.CopyProperties(objcsproduct); lstcsproducts.Add(objcsproduct); } return(lstcsproducts); } catch (Exception) { return(lstcsproducts); } } }
public ActionResult DeleteConfirmed(long id) { Buyer buyer = db.Buyers.Find(id); db.Buyers.Remove(buyer); db.SaveChanges(); TempData["Message"] = "Buyer deleted Successfully !"; return(RedirectToAction("Index")); }
public ActionResult Create([Bind(Include = "ProductID,ProductName,ProdDesc,IsActive,CategoryID")] Product product, HttpPostedFileBase file) { if (ModelState.IsValid) { if (file != null) { MemoryStream ms = new MemoryStream(); file.InputStream.CopyTo(ms); product.Image = ms.ToArray(); } db.Products.Add(product); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CategoryID = new SelectList(db.Categories, "CategoryID", "CategoryName", product.CategoryID); return(View(product)); }
public void AddOrder(OrderModel orderModel) { using (ShopDevEntities db = new ShopDevEntities()) { try { Order order = null; //if (orderModel.OrderId > 0) //{ // order = GetCustomerProduct(db, customerProductModel.ProductID); //} if (orderModel.OrderId == 0) { order = new Order(); orderModel.CopyProperties(order); db.Orders.Add(order); } else { order = db.Orders.Where(m => m.OrderId == orderModel.OrderId).FirstOrDefault(); orderModel.CopyProperties(order); } db.SaveChanges(); List <CustomerProduct> lstNewproducts = db.CustomerProducts.Where(m => m.OrderID == 0).ToList(); lstNewproducts.ForEach(m => m.OrderID = order.OrderId); //foreach (var product in lstNewproducts) //{ // var oldproduct = db.Products.Where(m => m.ProductName == product.ProductName && m.Type == product.Type && m.CategoryID == product.CategoryID).FirstOrDefault(); // if (oldproduct != null) // { // oldproduct.Unit -= 1; // } //} db.SaveChanges(); } catch { } } }
public void DeleteInitilProducts() { using (ShopDevEntities db = new ShopDevEntities()) { try { var AllInitialInstallments = db.BorrowerInstallments.Where(m => m.BorrowerID == 0).ToList(); db.BorrowerInstallments.RemoveRange(AllInitialInstallments); db.SaveChanges(); } catch { } } }
public void DeleteInitilProducts() { using (ShopDevEntities db = new ShopDevEntities()) { try { var AllInitialVendors = db.VendorDetails.Where(m => m.BulkByID == 0).ToList(); db.VendorDetails.RemoveRange(AllInitialVendors); var AllInitialproducts = db.BulkBuyProducts.Where(m => m.BulkBuyID == 0).ToList(); db.BulkBuyProducts.RemoveRange(AllInitialproducts); var AllInitialInstallments = db.BulkBuyInstallments.Where(m => m.BulkBuyID == 0).ToList(); db.BulkBuyInstallments.RemoveRange(AllInitialInstallments); db.SaveChanges(); } catch { } } }
public List <CustomerProductModel> AddCustomerProduct(CustomerProductModel customerProductModel) { List <CustomerProductModel> lstcsproducts = new List <CustomerProductModel>(); using (ShopDevEntities db = new ShopDevEntities()) { try { customerProductModel.IsActive = true; customerProductModel.OrderID = customerProductModel.OrderID == null ? 0 : customerProductModel.OrderID; CustomerProduct customerProduct = null; if (customerProductModel.ProductID > 0) { customerProduct = GetCustomerProduct(db, customerProductModel.ProductID); } else { customerProduct = new CustomerProduct(); } customerProductModel.CopyProperties(customerProduct); if (customerProductModel.ProductID == 0) { db.CustomerProducts.Add(customerProduct); } db.SaveChanges(); var lstproducts = db.CustomerProducts.Where(m => m.OrderID == customerProductModel.OrderID && m.IsActive).ToList(); foreach (var cusprod in lstproducts) { CustomerProductModel objcsproduct = new CustomerProductModel(); cusprod.CopyProperties(objcsproduct); lstcsproducts.Add(objcsproduct); } return(lstcsproducts); } catch (Exception) { return(lstcsproducts); } } }
public List<BulkBuyProductsModel> AddProduct(BulkBuyProductsModel productModel) { List<BulkBuyProductsModel> lstcsproducts = new List<BulkBuyProductsModel>(); using (ShopDevEntities db = new ShopDevEntities()) { try { productModel.BulkBuyID = productModel.BulkBuyID == null ? 0 : productModel.BulkBuyID; BulkBuyProduct bulkproduct = null; if (productModel.BulkBuyProductID > 0) { bulkproduct = db.BulkBuyProducts.Where(m => m.BulkBuyProductID == productModel.BulkBuyProductID).FirstOrDefault(); } else { bulkproduct = new BulkBuyProduct(); } productModel.CopyProperties(bulkproduct); if (productModel.BulkBuyProductID == 0) { db.BulkBuyProducts.Add(bulkproduct); } db.SaveChanges(); var lstproducts = db.BulkBuyProducts.Where(m => m.BulkBuyID == productModel.BulkBuyID).ToList(); foreach (var cusprod in lstproducts) { BulkBuyProductsModel objcsproduct = new BulkBuyProductsModel(); cusprod.CopyProperties(objcsproduct); lstcsproducts.Add(objcsproduct); } return lstcsproducts; } catch (Exception) { return lstcsproducts; } } }
public List <SellerInstallmentModel> AddSellerInstallment(SellerInstallmentModel installment) { List <SellerInstallmentModel> lstAllinstallments = new List <SellerInstallmentModel>(); using (ShopDevEntities db = new ShopDevEntities()) { try { installment.SellerID = installment.SellerID == null ? 0 : installment.SellerID; SellerInstallment sellerinstDetail = null; if (installment.SellerInstallmentID > 0) { sellerinstDetail = db.SellerInstallments.Where(m => m.SellerInstallmentID == installment.SellerInstallmentID).FirstOrDefault(); } else { sellerinstDetail = new SellerInstallment(); } installment.CopyProperties(sellerinstDetail); if (sellerinstDetail.SellerInstallmentID == 0) { db.SellerInstallments.Add(sellerinstDetail); } db.SaveChanges(); var lstinstallments = db.SellerInstallments.Where(m => m.SellerID == installment.SellerID).ToList(); foreach (var cusprod in lstinstallments) { SellerInstallmentModel objcsproduct = new SellerInstallmentModel(); cusprod.CopyProperties(objcsproduct); lstAllinstallments.Add(objcsproduct); } } catch { } return(lstAllinstallments); } }
public long AddBuyer(BuyerModel buyer) { Buyer buyerdb = null; using (ShopDevEntities db = new ShopDevEntities()) { try { if (buyer.CustomerCode == null) { Customer customer = new Customer { CustmerName = buyer.BuyerName, Address = buyer.Address }; db.Customers.Add(customer); db.SaveChanges(); buyer.CustomerCode = customer.CustCode; } var todayYear = DateTime.Now.Year; var CurrentMonth = DateTime.Now.Month; // calculation for interst if (buyer.InterestRate != null && buyer.InterestRate != 0) { var buyMonth = buyer.BuyDate.Value.Month; var buyYear = buyer.BuyDate.Value.Year; var monthDiff = ((todayYear - buyYear) * 12) + CurrentMonth - buyMonth; decimal?interst = 0; if (buyer.InterstableAmount > 0) { interst = buyer.InterstableAmount * buyer.InterestRate * monthDiff / 100; } else { buyer.InterstableAmount = buyer.DepositeAmount; interst = buyer.DepositeAmount * buyer.InterestRate * monthDiff / 100; } buyer.Interest = interst; buyer.OutstandingAmount = buyer.DepositeAmount + interst; } if (buyer.BuyerID == 0) { buyerdb = new Buyer(); buyer.CopyProperties(buyerdb); db.Buyers.Add(buyerdb); } else { buyerdb = db.Buyers.Where(m => m.BuyerID == buyer.BuyerID).FirstOrDefault(); buyer.CopyProperties(buyerdb); } db.SaveChanges(); List <BuyerProduct> lstNewproducts = db.BuyerProducts.Where(m => m.BuyerID == 0).ToList(); lstNewproducts.ForEach(m => m.BuyerID = buyerdb.BuyerID); foreach (var product in lstNewproducts) { var oldproduct = db.Products.Where(m => m.ProductName == product.ProductName && m.Type == product.Type).FirstOrDefault(); if (oldproduct != null) { oldproduct.Unit -= product.Units; } } List <BuyerInstallment> lstinstallments = db.BuyerInstallments.Where(m => m.BuyerID == 0).ToList(); lstinstallments.ForEach(m => m.BuyerID = buyerdb.BuyerID); db.SaveChanges(); } catch (Exception ex) { } return(buyerdb.BuyerID); } }
public List <BorrowerInstallmentModel> AddBorrowerInstallment(BorrowerInstallmentModel installment) { List <BorrowerInstallmentModel> lstAllinstallments = new List <BorrowerInstallmentModel>(); using (ShopDevEntities db = new ShopDevEntities()) { try { installment.BorrowerID = installment.BorrowerID == null ? 0 : installment.BorrowerID; BorrowerInstallment borrowerinstDetail = null; if (installment.InstallmentID > 0) { borrowerinstDetail = db.BorrowerInstallments.Where(m => m.InstallmentID == installment.InstallmentID).FirstOrDefault(); } else { borrowerinstDetail = new BorrowerInstallment(); } installment.CopyProperties(borrowerinstDetail); if (borrowerinstDetail.InstallmentID == 0) { var borrower = db.Borrowers.Where(m => m.BorrowID == installment.BorrowerID).FirstOrDefault(); if (borrower.Amont > 0) { if (borrower.Interest != null && borrower.Interest != 0) { if (installment.Amount > borrower.Interest) { var interest = borrower.Interest; borrower.Outstanding -= installment.Amount - interest; borrower.Interest = 0; var interstableAmount = borrower.InterstableAmount; borrower.InterstableAmount = interstableAmount == null? installment.Amount - interest: interstableAmount - (installment.Amount - interest); borrowerinstDetail.Description = "Amount cut for Interset" + Convert.ToString(interest) + " and adjust for amunt is " + Convert.ToString(installment.Amount - interest); } else { borrower.Interest -= installment.Amount; borrowerinstDetail.Description = "Amount cut for Interset" + Convert.ToString(installment.Amount) + " and adjust for amunt is 0"; } } else { borrower.InterstableAmount -= installment.Amount; borrower.Outstanding -= installment.Amount; borrowerinstDetail.Description = "Amount cut for Interset 0 and adjust for amunt is " + Convert.ToString(installment.Amount); } borrower.LastInstallmentDate = DateTime.Now; db.SaveChanges(); } db.BorrowerInstallments.Add(borrowerinstDetail); } db.SaveChanges(); var lstinstallments = db.BorrowerInstallments.Where(m => m.BorrowerID == borrowerinstDetail.BorrowerID).ToList(); foreach (var cusprod in lstinstallments) { BorrowerInstallmentModel objcsproduct = new BorrowerInstallmentModel(); cusprod.CopyProperties(objcsproduct); lstAllinstallments.Add(objcsproduct); } } catch { } return(lstAllinstallments); } }
public void CalculateInterest() { using (ShopDevEntities db = new ShopDevEntities()) { var todayYear = DateTime.Now.Year; var CurrentMonth = DateTime.Now.Month; try { // buyer var Allbuyer = db.Buyers.Where(m => m.OutstandingAmount > 0).ToList(); foreach (var buyer in Allbuyer) { int buyMonth = 0; int buyYear = 0; if (buyer.LastInstallmentDate != null) { buyMonth = buyer.LastInstallmentDate.Value.Month; buyYear = buyer.LastInstallmentDate.Value.Year; } else { buyMonth = buyer.BuyDate.Value.Month; buyYear = buyer.BuyDate.Value.Year; } var monthDiff = ((todayYear - buyYear) * 12) + CurrentMonth - buyMonth; var interest = buyer.InterstableAmount * buyer.InterestRate * monthDiff / 100; buyer.Interest = interest; buyer.OutstandingAmount += interest; buyer.InterstableAmount += interest; } // Borrower var AllBorrower = db.Borrowers.Where(m => m.Amont > 0).ToList(); foreach (var borrow in AllBorrower) { int borrowMonth = 0; int borrowYear = 0; if (borrow.LastInstallmentDate != null) { borrowMonth = borrow.LastInstallmentDate.Value.Month; borrowYear = borrow.LastInstallmentDate.Value.Year; } else { borrowMonth = borrow.Date.Value.Month; borrowYear = borrow.Date.Value.Year; } var monthDiff = ((todayYear - borrowYear) * 12) + CurrentMonth - borrowMonth; var interest = borrow.InterstableAmount * borrow.InterestRate * monthDiff / 100; borrow.Interest = interest; borrow.Outstanding += interest; borrow.InterstableAmount += interest; } // Bulks var AllBulks = db.BulkBuys.Where(m => m.OustandingAmont > 0).ToList(); foreach (var bulk in AllBulks) { var buyMonth = bulk.StartDate.Value.Month; var buyYear = bulk.StartDate.Value.Year; var monthDiff = ((todayYear - buyYear) * 12) + CurrentMonth - buyMonth; decimal?interst = 0; interst = bulk.InterstableAmount * bulk.InterestRate * monthDiff / 100; bulk.Interest = interst; bulk.OustandingAmont += interst; bulk.InterstableAmount += interst; } db.SaveChanges(); } catch { } } }
// installments public List<Installments> AddInstallment(Installments installment) { List<Installments> lstAllinstallments = new List<Installments>(); using (ShopDevEntities db = new ShopDevEntities()) { try { installment.BulkBuyID = installment.BulkBuyID == null ? 0 : installment.BulkBuyID; BulkBuyInstallment bulkinstDetail = null; if (installment.InstallmentID > 0) { bulkinstDetail = db.BulkBuyInstallments.Where(m => m.InstallmentID == installment.InstallmentID).FirstOrDefault(); } else { bulkinstDetail = new BulkBuyInstallment(); } installment.CopyProperties(bulkinstDetail); if (installment.InstallmentID == 0) { var bulkBuy = db.BulkBuys.Where(m => m.BulkBuyID == installment.BulkBuyID).FirstOrDefault(); if (bulkBuy.InterstableAmount > 0) { if (bulkBuy.Interest != null && bulkBuy.Interest != 0) { if (installment.Amount > bulkBuy.Interest) { var interest = bulkBuy.Interest; bulkBuy.OustandingAmont -= installment.Amount - interest; bulkBuy.Interest = 0; var interstableAmount = bulkBuy.InterstableAmount; bulkBuy.InterstableAmount = interstableAmount == null ? installment.Amount - interest : interstableAmount - (installment.Amount - interest); bulkinstDetail.Description = "Amount cut for Interset" + Convert.ToString(interest) + " and adjust for amunt is " + Convert.ToString(installment.Amount - interest); } else { bulkBuy.Interest -= installment.Amount; bulkinstDetail.Description = "Amount cut for Interset" + Convert.ToString(installment.Amount) + " and adjust for amunt is 0"; } } else { bulkBuy.OustandingAmont -= installment.Amount; bulkBuy.InterstableAmount -= installment.Amount; bulkinstDetail.Description = "Amount cut for Interset 0 and adjust for amunt is " + Convert.ToString(installment.Amount); } bulkBuy.LastInstallmentDate = DateTime.Now; db.SaveChanges(); } db.BulkBuyInstallments.Add(bulkinstDetail); } db.SaveChanges(); var lstinstallments = db.BulkBuyInstallments.Where(m => m.BulkBuyID == installment.BulkBuyID).ToList(); foreach (var cusprod in lstinstallments) { Installments objcsproduct = new Installments(); cusprod.CopyProperties(objcsproduct); lstAllinstallments.Add(objcsproduct); } } catch { } return lstAllinstallments; } }
public void AddBorrower(BorrowerModel borrower) { using (ShopDevEntities db = new ShopDevEntities()) { try { if (borrower.CustCode == null || borrower.CustCode == 0) { Customer customer = new Customer { CustmerName = borrower.Name, Address = borrower.Address }; db.Customers.Add(customer); db.SaveChanges(); borrower.CustCode = customer.CustCode; } var todayYear = DateTime.Now.Year; var CurrentMonth = DateTime.Now.Month; // calculation for interst if (borrower.InterestRate != null && borrower.InterestRate != 0) { var buyMonth = borrower.Date.Value.Month; var buyYear = borrower.Date.Value.Year; var monthDiff = ((todayYear - buyYear) * 12) + CurrentMonth - buyMonth; decimal?interst = 0; if (borrower.InterstableAmount > 0) { interst = borrower.InterstableAmount * borrower.InterestRate * monthDiff / 100; } else { borrower.InterstableAmount = borrower.Amont; interst = borrower.Amont * borrower.InterestRate * monthDiff / 100; } borrower.Interest = interst; borrower.Outstanding = borrower.Amont + interst; } Borrower borrowerdb = null; if (borrower.BorrowID == 0) { borrowerdb = new Borrower(); borrower.CopyProperties(borrowerdb); db.Borrowers.Add(borrowerdb); } else { borrowerdb = db.Borrowers.Where(m => m.BorrowID == borrower.BorrowID).FirstOrDefault(); borrower.CopyProperties(borrowerdb); } db.SaveChanges(); List <BorrowerInstallment> lstinstallments = db.BorrowerInstallments.Where(m => m.BorrowerID == borrowerdb.BorrowID).ToList(); lstinstallments.ForEach(m => m.BorrowerID = borrowerdb.BorrowID); db.SaveChanges(); } catch { } } }
public void AddBulkBuy(BulkBuyModel BulkInfo) { using (ShopDevEntities db = new ShopDevEntities()) { try { if (BulkInfo.CustomerCode == null) { Customer customer = new Customer { CustmerName = BulkInfo.CustomerName, Address = BulkInfo.Address }; db.Customers.Add(customer); db.SaveChanges(); BulkInfo.CustomerCode = customer.CustCode; } var todayYear = DateTime.Now.Year; var CurrentMonth = DateTime.Now.Month; // calculation for interst if (BulkInfo.InterestRate != null && BulkInfo.InterestRate != 0) { var buyMonth = BulkInfo.StartDate.Value.Month; var buyYear = BulkInfo.StartDate.Value.Year; var monthDiff = ((todayYear - buyYear) * 12) + CurrentMonth - buyMonth; decimal? interst = 0; if (BulkInfo.InterstableAmount > 0) { interst = BulkInfo.InterstableAmount * BulkInfo.InterestRate * monthDiff / 100; } else { BulkInfo.InterstableAmount = BulkInfo.TakenAmount; interst = BulkInfo.TakenAmount * BulkInfo.InterestRate * monthDiff / 100; } BulkInfo.Interest = interst; BulkInfo.OustandingAmont = BulkInfo.TakenAmount + interst; } BulkBuy bulkbuy = null; if (BulkInfo.BulkBuyID == 0) { bulkbuy = new BulkBuy(); BulkInfo.CopyProperties(bulkbuy); db.BulkBuys.Add(bulkbuy); } else { bulkbuy = db.BulkBuys.Where(m => m.BulkBuyID == BulkInfo.BulkBuyID).FirstOrDefault(); BulkInfo.CopyProperties(bulkbuy); } db.SaveChanges(); List<BulkBuyProduct> lstNewproducts = db.BulkBuyProducts.Where(m => m.BulkBuyID == 0).ToList(); lstNewproducts.ForEach(m => m.BulkBuyID = bulkbuy.BulkBuyID); List<VendorDetail> lstvendors = db.VendorDetails.Where(m => m.BulkByID == 0).ToList(); lstvendors.ForEach(m => m.BulkByID = bulkbuy.BulkBuyID); List<BulkBuyInstallment> lstinstallments = db.BulkBuyInstallments.Where(m => m.BulkBuyID == 0).ToList(); lstinstallments.ForEach(m => m.BulkBuyID = bulkbuy.BulkBuyID); db.SaveChanges(); } catch { } } }