private void DistributeOrdinalCommission(int total) { List <DealerInfo> dealers = db.DealerInfos.ToList(); foreach (var item in dealers) { if (item.Designation == "Company" || item.Designation == "A" || item.Designation == "B") { continue; } else { int amount = GetAmountWithDesignation(total, item); if (amount != 0) { AssociationCommission aCommission = new AssociationCommission(); aCommission.SaleId = 0; aCommission.CommissionType = "Ordinal"; aCommission.GoesTo = item.DealerCode; aCommission.Date = DateTime.Now; aCommission.Amount = amount; db.SaveChanges(); } } } }
private Boolean SetAssociateCommission(int s, string dealerCode, float v, DateTime date, int saleAmount, List <SalesCommission> salesCommission) { var dealer = db.DealerInfos.FirstOrDefault(d => d.DealerCode == dealerCode); if (dealerCode == "Company" || dealer.Designation == "Company") { float rate = 26 - v; AssociationCommission aCommission = new AssociationCommission(); aCommission.CommissionType = "Associates"; aCommission.SaleId = s; aCommission.GoesTo = "Company"; aCommission.Amount = Convert.ToInt32((saleAmount * rate) / 100); aCommission.Date = date; db.AssociationCommissions.Add(aCommission); db.SaveChanges(); return(true); } else { //var dealerAssociate = db.DealerInfos.FirstOrDefault(d => d.DealerCode == dealer.AssociateOf); if (dealer.SellAmount >= 4000) { foreach (var item in salesCommission) { if (item.Designation == dealer.Designation) { float rate = item.Percentage - v; AssociationCommission aCommission = new AssociationCommission(); aCommission.CommissionType = "Associates"; aCommission.SaleId = s; aCommission.GoesTo = dealer.DealerCode; aCommission.Amount = Convert.ToInt32((saleAmount * rate) / 100); aCommission.Date = date; v = item.Percentage; db.AssociationCommissions.Add(aCommission); db.SaveChanges(); break; } } return(SetAssociateCommission(s, dealer.AssociateOf, v, date, saleAmount, salesCommission)); } else { return(SetAssociateCommission(s, dealer.AssociateOf, v, date, saleAmount, salesCommission)); } } }