public ActionResult List(DateTime dateFrom, DateTime dateTo, int profileId = -1, int roleId = -1) { CommissionManager manager = new CommissionManager(); EmployeeManager empManager = new EmployeeManager(); CommissionCollectionViewModel model = new CommissionCollectionViewModel { SearchDateFrom = dateFrom, SearchDateTo = dateTo, SearchProfileId = profileId, SearchRoleId = roleId }; model = profileId > 0 ? manager.GetCommissionList(model) : manager.GetCommissionList(model, int.Parse(Helper.UserId)); List <LookupModel> lookupEmployee = new List <LookupModel> { new LookupModel { Key = "-1", Value = "---- Employee ----" } }; lookupEmployee.AddRange(empManager.GetLookup()); model.LookupEmployee = lookupEmployee; model.LookupPosition = Helper.LookupPosition; return(PartialView("List", model)); }
public ActionResult Index(int userId = -1) { CommissionManager manager = new CommissionManager(); EmployeeManager empManager = new EmployeeManager(); CommissionCollectionViewModel model = new CommissionCollectionViewModel { SearchDateFrom = new DateTime(DateTime.UtcNow.Year, DateTime.UtcNow.Month, 1), SearchDateTo = DateTime.UtcNow, SearchProfileId = -1, SearchRoleId = -1, CommissionViewCollection = new List <CommissionViewModel>() }; if (userId > 0) { model = manager.GetCommissionList(model, userId); } List <LookupModel> lookupEmployee = new List <LookupModel> { new LookupModel { Key = "-1", Value = "---- Employee ----" } }; lookupEmployee.AddRange(empManager.GetLookup()); model.LookupEmployee = lookupEmployee; model.LookupPosition = Helper.LookupPosition; return(View(model)); }
public ActionResult PrintReport(DateTime dateFrom, DateTime dateTo, int profileId = -1, int roleId = -1) { try { FastReportManager FastReportManager = new FastReportManager(); CommissionManager manager = new CommissionManager(); EmployeeManager empManager = new EmployeeManager(); CommissionCollectionViewModel model = new CommissionCollectionViewModel { SearchDateFrom = dateFrom, SearchDateTo = dateTo, SearchProfileId = profileId, SearchRoleId = roleId }; model = profileId > 0 ? manager.GetCommissionList(model) : manager.GetCommissionList(model, int.Parse(Helper.UserId)); List <LookupModel> lookupEmployee = new List <LookupModel> { new LookupModel { Key = "-1", Value = "---- Employee ----" } }; lookupEmployee.AddRange(empManager.GetLookup()); model.LookupEmployee = lookupEmployee; model.LookupPosition = Helper.LookupPosition; byte[] strm = FastReportManager.GenPDFFile(Request.PhysicalApplicationPath + "Reports/ReportCommission.frx", model).ToArray(); return(File(strm, "application/pdf", "Report.pdf")); } catch (Exception e) { return(null); } }
public List <CommissionMasterReportModel> MapperCommission(CommissionCollectionViewModel commissionModel) { EmployeeDetailViewModel employeeDetailViewModel = _employeeManager.GetEmployeeDetail(commissionModel.SearchProfileId); List <CommissionMasterReportModel> commissionMasterReports = new List <CommissionMasterReportModel>(); List <CommissionReportModel> commissionReportModels = new List <CommissionReportModel>(); CommissionMasterReportModel commissionMasterReport = new CommissionMasterReportModel(); commissionMasterReport.Fullname = employeeDetailViewModel.FirstName + " " + employeeDetailViewModel.LastName; commissionMasterReport.PositionName = "(" + employeeDetailViewModel.PositionName + ")"; commissionMasterReport.SearchDateFrom = commissionModel.SearchDateFrom; commissionMasterReport.SearchDateTo = commissionModel.SearchDateTo; foreach (CommissionViewModel commodel in commissionModel.CommissionViewCollection) { commissionReportModels.Add(new CommissionReportModel { Date = DateTime.Now, PO = commodel.PoDetail.PoNumber, ProductName = commodel.PoDetail.ProductName, ProductTypeName = "(" + commodel.PoDetail.ProductTypeName + ")", CustomerName = commodel.PoDetail.CustomerName, SalesName = commodel.CommissionDetail.SalesName, ComRole = Helper.GetNameFromLookup(commodel.Role, Helper.LookupPosition), Revenue = Math.Round((Decimal)commodel.PoDetail.TotalPrice, 2), Tax = Math.Round((Decimal)commodel.CommissionDetail.Tax, 2), TotalCom = Math.Round((Decimal)commodel.CommissionDetail.Total, 2), NetTotal = Math.Round((Decimal)commodel.CommissionDetail.NetTotal, 2), }); } commissionMasterReport.CommissionsReport = commissionReportModels; commissionMasterReport.SumRevenue = Math.Round((Decimal)commissionModel.SumAllTotalPrice, 2); commissionMasterReport.SumCOM = Math.Round((Decimal)commissionModel.SumAllCommission, 2); commissionMasterReport.SumTax = Math.Round((Decimal)commissionModel.SumAllTax, 2); commissionMasterReport.SumNetTotal = Math.Round((Decimal)commissionModel.SumAllNetTotal, 2); commissionMasterReports.Add(commissionMasterReport); return(commissionMasterReports); }
public CommissionCollectionViewModel GetCommissionList(CommissionCollectionViewModel model = null, int userId = -1) { if (model == null) { model = new CommissionCollectionViewModel(); } // Get Commissions var query = (from po in _unitOfWork.GetRepository <Txn_PO>().GetQueryable(o => o.Status == 1 && model.SearchDateFrom <= o.PoDate && o.PoDate <= model.SearchDateTo) join pod in _unitOfWork.GetRepository <Txn_PODetail>().GetQueryable(o => o.Status == 1) on po.PoId equals pod.PoId join cd in _unitOfWork.GetRepository <Txn_CommissionDetail>().GetQueryable(o => o.Amount > 0) on pod.PoDetailId equals cd.PoDetailId join p in _unitOfWork.GetRepository <Mst_Profile>().GetQueryable() on cd.ProfileId equals p.ProfileId orderby po.PoDate descending select new CommissionViewModel { UserId = p.UserId, Role = cd.Position, PoDetail = new PoDetailModel { PoId = po.PoId, PoNumber = po.PoNumber, PoDate = po.PoDate, //PoFilePath = p.PoFilePath, //InvoiceFilePath = p.InvoiceFilePath, CustomerName = po.CustomerName, PoDetailId = pod.PoDetailId, ProductName = pod.ProductName, ProductBrand = pod.ProductBrand, ProductType = pod.ProductType, //PricePerUnit = pd.PricePerUnit, //ActualPricePerUnit = pd.ActualPricePerUnit, //Amount = pd.Amount, TotalPrice = pod.TotalPrice, //ActualTotalPrice = pd.ActualTotalPrice, //Tax = pd.Tax, //TransportLocation = pd.TransportLocation, //TransportFee = pd.TransportFee, //ParcelFee = pd.ParcelFee, //ServiceFee = pd.ServiceFee, //OtherFee = pd.OtherFee, //CustomerLead = pd.CustomerLead, //CustomerLeadPercentage = pd.CustomerLeadPercentage, //TotalCost = pd.TotalCost, //Profit = pd.Profit, //ProfitPercentage = pd.ProfitPercentage, //Remark = pd.Remark, //Status = pd.Status, }, CommissionDetail = new CommissionDetailModel { CommissionDetailId = cd.CommissionDetailId, PoDetailId = cd.PoDetailId, ProfileId = cd.ProfileId, Position = cd.Position, Rate = cd.Rate, Amount = cd.Amount, WdTax = 0, Total = 0, Tax = 0, NetTotal = 0 } }); // Set Where cause // -- UserId if (userId > 0) { query = query.Where(o => o.UserId == userId); } else if (model.SearchProfileId > 0) { query = query.Where(o => o.CommissionDetail.ProfileId == model.SearchProfileId); } // -- RoleId if (model.SearchRoleId >= 0) { query = query.Where(o => o.Role == model.SearchRoleId); } model.CommissionViewCollection = query.ToList(); // Mapping Id with lookup name for (int i = 0; i < model.CommissionViewCollection.Count; i++) { CommissionViewModel commission = model.CommissionViewCollection[i]; commission.RoleName = Helper.GetNameFromLookup(commission.Role, Helper.LookupPosition); model.CommissionViewCollection[i] = commission; } // Get Commission Detail for find the sale var listCommissionDetail = (from cd in _unitOfWork.GetRepository <Txn_CommissionDetail>().GetQueryable(o => o.Position == 1) join p in _unitOfWork.GetRepository <Mst_Profile>().GetQueryable() on cd.ProfileId equals p.ProfileId select new { cd.PoDetailId, p.FirstName, p.LastName }).ToList(); // Calculate tax and sum tootal decimal sumAllTotalPrice = decimal.Zero; decimal sumAllCommission = decimal.Zero; decimal sumAllWdTax = decimal.Zero; decimal sumAllTotal = decimal.Zero; decimal sumAllTax = decimal.Zero; decimal sumAllNetTotal = decimal.Zero; List <LookupModel> lookupProductType = Helper.LookupProductType; decimal tax = 0.03m; foreach (CommissionViewModel commission in model.CommissionViewCollection) { string productTypeValue = lookupProductType.FirstOrDefault(o => o.Key == commission.PoDetail.ProductType.ToString()).Value; string[] productTypeNameWithTax = productTypeValue.Split(new string[] { "__" }, StringSplitOptions.None); decimal taxPercentage = decimal.Parse(productTypeNameWithTax[1].Replace("%", "")); decimal wdtaxRate = taxPercentage / 100; // Calculate Date commission.PoDetail.ProductTypeName = productTypeNameWithTax[0]; commission.CommissionDetail.WdTax = commission.CommissionDetail.Amount * wdtaxRate; commission.CommissionDetail.Total = commission.CommissionDetail.Amount - commission.CommissionDetail.WdTax; commission.CommissionDetail.Tax = commission.CommissionDetail.Total * tax; commission.CommissionDetail.NetTotal = commission.CommissionDetail.Total - commission.CommissionDetail.Tax; // Sum Data sumAllTotalPrice += commission.PoDetail.TotalPrice; sumAllCommission += commission.CommissionDetail.Amount; sumAllWdTax += commission.CommissionDetail.WdTax; sumAllTotal += commission.CommissionDetail.Total; sumAllTax += commission.CommissionDetail.Tax; sumAllNetTotal += commission.CommissionDetail.NetTotal; // Set sales var temp = listCommissionDetail.FirstOrDefault(o => o.PoDetailId == commission.CommissionDetail.PoDetailId); commission.CommissionDetail.SalesName = temp.FirstName + " " + temp.LastName; } // Set Sum Data model.SumAllTotalPrice = sumAllTotalPrice; model.SumAllCommission = sumAllCommission; model.SumAllWdTax = sumAllWdTax; model.SumAllTotal = sumAllTotal; model.SumAllTax = sumAllTax; model.SumAllNetTotal = sumAllNetTotal; if (userId > 0 && model.CommissionViewCollection.Count > 0) { model.SearchProfileId = model.CommissionViewCollection[0].CommissionDetail.ProfileId; } return(model); }
public MemoryStream GenPDFFile(string reportname, CommissionCollectionViewModel commissionCollectionViewModel) { List <CommissionMasterReportModel> commissionMasterReports = MapperCommission(commissionCollectionViewModel); return(FastReportHelper.ShowData(reportname, commissionMasterReports)); }