public SupplierHistory GetSupplierHistoryOverview(WrapperSupplierHistory list) { SupplierHistory history = new SupplierHistory(); for (int i = 0; i < list.ListOfData.Count; i++) { SupplierHistory temp = list.ListOfData.ElementAt(i); if (temp.Type == "InvoiceItem") { // history.PaidAmount += temp.PaidAmount; // history.PayableAmount += temp.PayableAmount; } else if (temp.Type == "PurchaseItem") { } else if (temp.Type == "ExpenseItem") { history.PaidAmount += temp.PaidAmount; } else if (temp.Type == "IncomeItem") { history.RecievedAmount += temp.RecievedAmount; } else if (temp.Type == "PayableItem") { history.PayableAmount += temp.PayableAmount; } else if (temp.Type == "RecievableItem") { history.RecievableAmount += temp.RecievableAmount; } } return(history); }
private async Task <WrapperSupplierListVM> SetHistoryOverview(WrapperSupplierListVM vm, string FactoryId) { var data = new GetDataListHistory(); //Task<WrapperSupplierHistory>[] listOftask = new Task<WrapperSupplierHistory>[vm.ListOfData.Count]; WrapperSupplierHistory[] listOftask = new WrapperSupplierHistory[vm.ListOfData.Count]; for (int i = 0; i < vm.ListOfData.Count; i++) { SupplierVM temp = vm.ListOfData.ElementAt(i); data.ClientId = temp.Id; data.PageNumber = -1; data.PageSize = -1; data.FactoryId = FactoryId; listOftask[i] = await GetSupplierHistory(data); int len = listOftask[i].ListOfData.Count - 1; vm.ListOfData.ElementAt(i).PaidAmount = listOftask[i].ListOfData[len].PaidAmount; vm.ListOfData.ElementAt(i).RecievableAmount = listOftask[i].ListOfData[len].RecievableAmount; vm.ListOfData.ElementAt(i).RecievedAmount = listOftask[i].ListOfData[len].RecievedAmount; vm.ListOfData.ElementAt(i).PayableAmount = listOftask[i].ListOfData[len].PayableAmount; } // await Task.WhenAll(listOftask); //for (int i = 0; i < vm.ListOfData.Count; i++) //{ // //SupplierHistory te = GetSupplierHistoryOverview(listOftask[i].Result); // SupplierHistory te = GetSupplierHistoryOverview(listOftask[i]); // vm.ListOfData.ElementAt(i).PaidAmount = te.PaidAmount; // vm.ListOfData.ElementAt(i).RecievableAmount = te.RecievableAmount; // vm.ListOfData.ElementAt(i).RecievedAmount = te.RecievedAmount; // vm.ListOfData.ElementAt(i).PayableAmount = te.PayableAmount; //} return(vm); }
public async Task <WrapperSupplierHistory> GetSupplierHistory(GetDataListHistory supplierVM) { WrapperSupplierHistory custHist = new WrapperSupplierHistory(); WrapperSupplierHistory returnCustHist = new WrapperSupplierHistory(); // Purchase -- Sales Invoice Generated // Invoice // Expense -- Payment Invoice Generated Task <List <Purchase> > listPurchaseT = _repositoryWrapper .Purchase .FindAll() .Where(x => x.FactoryId == supplierVM.FactoryId && x.ClientId == supplierVM.ClientId) .Include(x => x.Item) .ThenInclude(x => x.ItemCategory) .ToListAsync(); Task <List <Invoice> > listInvoiceT = _repositoryWrapper .Invoice .FindAll() .Where(x => x.FactoryId == supplierVM.FactoryId && x.ClientId == supplierVM.ClientId) .Include(x => x.InvoiceType) .Where(x => x.InvoiceType.Name == TypeInvoice.Purchase.ToString()) .ToListAsync(); Task <List <Expense> > listExpenseT = _repositoryWrapper .Expense .FindAll() .Where(x => x.FactoryId == supplierVM.FactoryId && x.ClientId == supplierVM.ClientId) .Include(x => x.ExpenseType) //.Where(x => x.ExpenseType.Name == TypeExpense.SupplierPayment.ToString()) .ToListAsync(); Task <List <Income> > listIncomeT = _repositoryWrapper .Income .FindAll() .Where(x => x.FactoryId == supplierVM.FactoryId && x.ClientId == supplierVM.ClientId) .Include(x => x.IncomeType) //.Where(x => x.ExpenseType.Name == TypeExpense.StaffPayment.ToString()) .ToListAsync(); Task <List <Payable> > listPayableT = _repositoryWrapper .Payable .FindAll() .Where(x => x.FactoryId == supplierVM.FactoryId && x.ClientId == supplierVM.ClientId) .ToListAsync(); Task <List <Recievable> > listRecievableT = _repositoryWrapper .Recievable .FindAll() .Where(x => x.FactoryId == supplierVM.FactoryId && x.ClientId == supplierVM.ClientId) .ToListAsync(); await Task.WhenAll(listPurchaseT, listInvoiceT, listExpenseT, listPayableT, listRecievableT); List <SupplierHistory> custHistInvoice = _utilService.Mapper.Map <List <Invoice>, List <SupplierHistory> >(listInvoiceT.Result.ToList()); List <SupplierHistory> custHistExpense = _utilService.Mapper.Map <List <Expense>, List <SupplierHistory> >(listExpenseT.Result.ToList()); List <SupplierHistory> custHistPurchase = _utilService.Mapper.Map <List <Purchase>, List <SupplierHistory> >(listPurchaseT.Result.ToList()); List <SupplierHistory> custHistIncome = _utilService.Mapper.Map <List <Income>, List <SupplierHistory> >(listIncomeT.Result.ToList()); List <SupplierHistory> custHistPayable = _utilService.Mapper.Map <List <Payable>, List <SupplierHistory> >(listPayableT.Result.ToList()); List <SupplierHistory> custHistRecievable = _utilService.Mapper.Map <List <Recievable>, List <SupplierHistory> >(listRecievableT.Result.ToList()); custHist.ListOfData.AddRange(custHistInvoice); custHist.ListOfData.AddRange(custHistExpense); custHist.ListOfData.AddRange(custHistIncome); custHist.ListOfData.AddRange(custHistPayable); custHist.ListOfData.AddRange(custHistRecievable); custHist.ListOfData.OrderByDescending(x => x.OccurranceDate); for (int i = 0; i < custHist.ListOfData.Count(); i++) { IEnumerable <SupplierHistory> tempList = new List <SupplierHistory>(); if (custHist.ListOfData.ElementAt(i).Type == "InvoiceItem") { tempList = custHistPurchase.Where(x => x.InvoiceId == custHist.ListOfData.ElementAt(i).InvoiceId); // custHist.ListOfData.InsertRange(i, tempList); returnCustHist.ListOfData.AddRange(tempList); returnCustHist.ListOfData.Add(custHist.ListOfData.ElementAt(i)); } else { returnCustHist.ListOfData.Add(custHist.ListOfData.ElementAt(i)); } } var staffHist = GetSupplierHistoryOverview(returnCustHist); if (supplierVM.PageSize != -1) { returnCustHist.ListOfData = returnCustHist.ListOfData .Skip((supplierVM.PageNumber - 1) * supplierVM.PageSize) .Take(supplierVM.PageSize) .ToList(); } returnCustHist.ListOfData.Add(staffHist); return(returnCustHist); }