private async Task <WrapperListCustomerVM> SetHistoryOverview(WrapperListCustomerVM vm, string FactoryId)
        {
            var data = new GetDataListHistory();

            //Task<WrapperCustomerHistory>[] listOftask = new Task<WrapperCustomerHistory>[vm.ListOfData.Count];
            WrapperCustomerHistory[] listOftask = new WrapperCustomerHistory[vm.ListOfData.Count];
            for (int i = 0; i < vm.ListOfData.Count; i++)
            {
                CustomerVM temp = vm.ListOfData.ElementAt(i);
                data.ClientId   = temp.CustomerId;
                data.PageNumber = -1;
                data.PageSize   = -1;
                data.FactoryId  = FactoryId;
                listOftask[i]   = await GetCustomerHistory(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++)
            //{
            //    //CustomerHistory te = GetCustomerHistoryOverview(listOftask[i].Result);
            //    CustomerHistory te = GetCustomerHistoryOverview(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 <ActionResult <RoleVM> > GetRoleByUserId([FromBody] GetDataListHistory dataParam)
        {
            //var Role = await _context.Role.FindAsync(id);
            IEnumerable <UserRole> roleList = await _repositoryWrapper
                                              .UserRole
                                              .FindAll()
                                              .Where(x => x.UserId == dataParam.ClientId)
                                              .Include(x => x.Role)
                                              .Include(x => x.UserAuthInfo)
                                              .ToListAsync();

            RoleVM roleVM = _utilService.Mapper.Map <Role, RoleVM>(roleList.FirstOrDefault().Role);

            return(roleVM);
        }
 public async Task <WrapperCustomerHistory> GetCustomerHistory([FromBody] GetDataListHistory vm)
 {
     return(await _serviceWrapper.CustomerService.GetCustomerHistory(vm));
 }
 public async Task <WrapperStaffHistory> GetStaffHistory([FromBody] GetDataListHistory vm)
 {
     return(await _serviceWrapper.StaffService.GetStaffHistory(vm));
 }
        public async Task <WrapperCustomerHistory> GetCustomerHistory(GetDataListHistory customerVM)
        {
            WrapperCustomerHistory custHist       = new WrapperCustomerHistory();
            WrapperCustomerHistory returnCustHist = new WrapperCustomerHistory();
            // Sales -- Sales Invoice Generated
            // Invoice
            // Income -- Payment Invoice Generated
            Task <List <Sales> > listSalesT =
                _repositoryWrapper
                .Sales
                .FindAll()
                .Where(x => x.FactoryId == customerVM.FactoryId &&
                       x.ClientId == customerVM.ClientId)
                .Include(x => x.Item)
                .ThenInclude(x => x.ItemCategory)
                .ToListAsync();

            Task <List <Invoice> > listInvoiceT =
                _repositoryWrapper
                .Invoice
                .FindAll()
                .Where(x => x.FactoryId == customerVM.FactoryId &&
                       x.ClientId == customerVM.ClientId)
                .Include(x => x.InvoiceType)
                .Where(x => x.InvoiceType.Name == TypeInvoice.Sales.ToString())
                .ToListAsync();

            Task <List <Income> > listIncomeT =
                _repositoryWrapper
                .Income
                .FindAll()
                .Where(x => x.FactoryId == customerVM.FactoryId &&
                       x.ClientId == customerVM.ClientId)
                .Include(x => x.IncomeType)
                //.Where(x => x.IncomeType.Name == TypeIncome.ClientPaymentRecieved.ToString())
                .ToListAsync();


            Task <List <Expense> > listExpenseT =
                _repositoryWrapper
                .Expense
                .FindAll()
                .Where(x => x.FactoryId == customerVM.FactoryId &&
                       x.ClientId == customerVM.ClientId)
                .Include(x => x.ExpenseType)
                //.Where(x => x.IncomeType.Name == TypeIncome.ClientPaymentRecieved.ToString())
                .ToListAsync();


            Task <List <Payable> > listPayableT =
                _repositoryWrapper
                .Payable
                .FindAll()
                .Where(x => x.FactoryId == customerVM.FactoryId &&
                       x.ClientId == customerVM.ClientId)
                .ToListAsync();

            Task <List <Recievable> > listRecievableT =
                _repositoryWrapper
                .Recievable
                .FindAll()
                .Where(x => x.FactoryId == customerVM.FactoryId &&
                       x.ClientId == customerVM.ClientId)
                .ToListAsync();



            await Task.WhenAll(listSalesT, listInvoiceT, listIncomeT, listExpenseT, listPayableT, listRecievableT);

            List <CustomerHistory> custHistInvoice = _utilService.Mapper.Map <List <Invoice>, List <CustomerHistory> >(listInvoiceT.Result.ToList());
            List <CustomerHistory> custHistIncome  = _utilService.Mapper.Map <List <Income>, List <CustomerHistory> >(listIncomeT.Result.ToList());
            List <CustomerHistory> custHistSales   = _utilService.Mapper.Map <List <Sales>, List <CustomerHistory> >(listSalesT.Result.ToList());
            List <CustomerHistory> custHistExpense = _utilService.Mapper.Map <List <Expense>, List <CustomerHistory> >(listExpenseT.Result.ToList());


            List <CustomerHistory> custHistPayable    = _utilService.Mapper.Map <List <Payable>, List <CustomerHistory> >(listPayableT.Result.ToList());
            List <CustomerHistory> custHistRecievable = _utilService.Mapper.Map <List <Recievable>, List <CustomerHistory> >(listRecievableT.Result.ToList());



            custHist.ListOfData.AddRange(custHistInvoice);
            custHist.ListOfData.AddRange(custHistIncome);
            custHist.ListOfData.AddRange(custHistExpense);
            custHist.ListOfData.AddRange(custHistPayable);
            custHist.ListOfData.AddRange(custHistRecievable);
            custHist.ListOfData = custHist.ListOfData.OrderBy(x => x.OccurranceDate).ToList();
            for (int i = 0; i < custHist.ListOfData.Count(); i++)
            {
                IEnumerable <CustomerHistory> tempList = new List <CustomerHistory>();
                if (custHist.ListOfData.ElementAt(i).Type == "InvoiceItem")
                {
                    tempList = custHistSales.Where(x => x.InvoiceId == custHist.ListOfData.ElementAt(i).InvoiceId);
                    returnCustHist.ListOfData.AddRange(tempList);
                    returnCustHist.ListOfData.Add(custHist.ListOfData.ElementAt(i));
                }
                else
                {
                    returnCustHist.ListOfData.Add(custHist.ListOfData.ElementAt(i));
                }
            }
            var staffHist = GetCustomerHistoryOverview(returnCustHist);


            if (customerVM.PageSize != -1)
            {
                returnCustHist.ListOfData = returnCustHist.ListOfData
                                            .Skip((customerVM.PageNumber - 1) * customerVM.PageSize)
                                            .Take(customerVM.PageSize)
                                            .ToList();
            }

            returnCustHist.ListOfData.Add(staffHist);
            return(returnCustHist);
        }
Exemplo n.º 6
0
        public async Task <WrapperStaffHistory> GetStaffHistory(GetDataListHistory staffVM)
        {
            // Production
            // Expense -- Payment Invoice Generated
            // Invoice

            WrapperStaffHistory       wrapperStaffHistory       = new WrapperStaffHistory();
            WrapperStaffHistory       returnWrapperStaffHistory = new WrapperStaffHistory();
            Task <List <Production> > listProductionT           =
                _repositoryWrapper
                .Production
                .FindAll()
                .Where(x => x.FactoryId == staffVM.FactoryId &&
                       x.StaffId == staffVM.ClientId)
                .Include(x => x.Item)
                .ThenInclude(x => x.ItemCategory)
                .ToListAsync();

            Task <List <Invoice> > listInvoiceT =
                _repositoryWrapper
                .Invoice
                .FindAll()
                .Where(x => x.FactoryId == staffVM.FactoryId &&
                       x.ClientId == staffVM.ClientId)
                .Include(x => x.InvoiceType)
                .Where(x => x.InvoiceType.Name == TypeInvoice.StaffProduction.ToString())
                .ToListAsync();
            Task <List <Expense> > listExpenseT =
                _repositoryWrapper
                .Expense
                .FindAll()
                .Where(x => x.FactoryId == staffVM.FactoryId &&
                       x.ClientId == staffVM.ClientId)
                .Include(x => x.ExpenseType)
                //.Where(x => x.ExpenseType.Name == TypeExpense.StaffPayment.ToString())
                .ToListAsync();
            Task <List <Income> > listIncomeT =
                _repositoryWrapper
                .Income
                .FindAll()
                .Where(x => x.FactoryId == staffVM.FactoryId &&
                       x.ClientId == staffVM.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 == staffVM.FactoryId &&
                       x.ClientId == staffVM.ClientId)
                .ToListAsync();

            Task <List <Recievable> > listRecievableT =
                _repositoryWrapper
                .Recievable
                .FindAll()
                .Where(x => x.FactoryId == staffVM.FactoryId &&
                       x.ClientId == staffVM.ClientId)
                .ToListAsync();



            await Task.WhenAll(listProductionT, listExpenseT, listInvoiceT, listIncomeT, listPayableT, listRecievableT);

            List <StaffHistory> production = _utilService.Mapper.Map <List <Production>, List <StaffHistory> >(listProductionT.Result.ToList());
            List <StaffHistory> expense    = _utilService.Mapper.Map <List <Expense>, List <StaffHistory> >(listExpenseT.Result.ToList());
            List <StaffHistory> invoice    = _utilService.Mapper.Map <List <Invoice>, List <StaffHistory> >(listInvoiceT.Result.ToList());
            List <StaffHistory> income     = _utilService.Mapper.Map <List <Income>, List <StaffHistory> >(listIncomeT.Result.ToList());
            List <StaffHistory> payable    = _utilService.Mapper.Map <List <Payable>, List <StaffHistory> >(listPayableT.Result.ToList());
            List <StaffHistory> recievable = _utilService.Mapper.Map <List <Recievable>, List <StaffHistory> >(listRecievableT.Result.ToList());



            wrapperStaffHistory.ListOfData.AddRange(invoice);
            wrapperStaffHistory.ListOfData.AddRange(expense);
            wrapperStaffHistory.ListOfData.AddRange(income);
            wrapperStaffHistory.ListOfData.AddRange(payable);
            wrapperStaffHistory.ListOfData.AddRange(recievable);

            wrapperStaffHistory.ListOfData = wrapperStaffHistory.ListOfData.OrderByDescending(x => x.OccurranceDate).ToList();
            for (int i = 0; i < wrapperStaffHistory.ListOfData.Count(); i++)
            {
                List <StaffHistory> tempList = new List <StaffHistory>();
                if (wrapperStaffHistory.ListOfData.ElementAt(i).Type == "InvoiceItem")
                {
                    tempList = production.Where(x => x.InvoiceId == wrapperStaffHistory.ListOfData.ElementAt(i).InvoiceId).ToList();
                    returnWrapperStaffHistory.ListOfData.AddRange(tempList);
                    returnWrapperStaffHistory.ListOfData.Add(wrapperStaffHistory.ListOfData.ElementAt(i));
                }
                else
                {
                    returnWrapperStaffHistory.ListOfData.Add(wrapperStaffHistory.ListOfData.ElementAt(i));
                }
            }


            var staffHist = GetStaffHistoryOverview(returnWrapperStaffHistory);

            //  returnWrapperStaffHistory.ListOfData = returnWrapperStaffHistory.ListOfData.OrderByDescending(x => x.OccurranceDate).ToList();
            if (staffVM.PageSize != -1)
            {
                returnWrapperStaffHistory.ListOfData = returnWrapperStaffHistory.ListOfData
                                                       .Skip((staffVM.PageNumber - 1) * staffVM.PageSize)
                                                       .Take(staffVM.PageSize)
                                                       .ToList();
            }


            returnWrapperStaffHistory.ListOfData.Add(staffHist);
            return(returnWrapperStaffHistory);
        }