public PurchaseReturnView() { InitializeComponent(); var vm = new PurchaseReturnVM(); DataContext = vm; }
public async Task <IActionResult> Create(int?id) { string CompId = User.Claims.Where(r => r.Type == "CompanyID").FirstOrDefault().Value; int CompID = Convert.ToInt32(CompId); if (id == null) { return(NotFound()); } PurchaseReturnVM model = new PurchaseReturnVM(); PurchaseBill purchaseBill = new PurchaseBill(); purchaseBill = await _context.PurchaseBill.Where(r => r.CompanyID == CompID).Include(r => r.Parties).FirstOrDefaultAsync(m => m.PurchaseBillID == id); if (purchaseBill == null) { return(NotFound()); } model.TLandingExpenses = purchaseBill.TLandingExpenses; model.PurchaseImport = purchaseBill.PurchaseImport; model.PurchaseBillID = purchaseBill.PurchaseBillID; model.BillDate_OldBill = purchaseBill.BillDate.ToString("d"); model.ContactNumber_OldBill = purchaseBill.ContactNumber; model.ContactPerson_OldBill = purchaseBill.ContactPerson; model.GrossTotal_OldBill = purchaseBill.GrossTotal; model.NetAmount_OldBill = purchaseBill.NetAmount; if (purchaseBill.PartiesID == null) { model.PartiesID = null; model.PR_S_1 = "Cash Purchase"; } else { model.PartiesID = purchaseBill.PartiesID; model.PR_S_1 = purchaseBill.Parties.PartyName; } model.Remarks_OldBill = purchaseBill.Remarks; model.TDiscount_OldBill = purchaseBill.TDiscount; model.TotalQuantity_OldBill = purchaseBill.TotalQuantity; model.PurchaseBillItem_List = _context.PurchaseBillItem.Include(r => r.Item).Where(r => r.PurchaseBillID == id).ToList(); ViewData["Ids"] = _context.Bank.Select(m => m.BankID).ToList(); ViewData["Name"] = _context.Bank.Select(m => m.BankName).ToList(); ViewData["BankID"] = new SelectList(_context.Bank.Where(r => r.CompanyID == CompID), "BankID", "BankName"); ViewData["CurrencyID"] = new SelectList(_context.Currency.Where(r => r.CompanyID == CompID), "CurrencyID", "CurrencyName", purchaseBill.CurrencyID); //ViewData["PartiesID"] = new SelectList(_context.Parties, "PartiesID", "PartyName", purchaseBill.PartiesID); ViewData["ItemID"] = new SelectList(_context.Item.Where(r => r.CompanyID == CompID), "ItemID", "ItemID"); ViewData["PartiesID"] = new SelectList(_context.Parties.Where(r => r.CompanyID == CompID), "PartiesID", "PartyName"); ViewData["PurchaseBillID"] = new SelectList(_context.PurchaseBill.Where(r => r.CompanyID == CompID), "PurchaseBillID", "PurchaseBillNo"); return(View(model)); }
public async Task <WrapperPurchaseReturnVM> DeletePurchaseReturn([FromBody] PurchaseReturnVM sales) { return(await _serviceWrapper.PurchaseService.DeletePurchaseReturnAsync(sales)); }
public PurchaseReturnNewEntryVM(PurchaseReturnVM parentVM) { _parentVM = parentVM; _purchaseReturnEntryAvailableQuantity = "0"; }
public async Task <WrapperPurchaseReturnVM> DeletePurchaseReturnAsync(PurchaseReturnVM vm) { // StockOut // Invoice // Recievable // Stock Task <List <Invoice> > invoiceToDelete = _repositoryWrapper .Invoice .FindAll() .Where(x => x.Id == vm.InvoiceId && x.FactoryId == vm.FactoryId) .ToListAsync(); Task <List <StockOut> > stockOutToDelete = _repositoryWrapper .StockOut .FindAll() .Where(x => x.InvoiceId == vm.InvoiceId && x.FactoryId == vm.FactoryId) .ToListAsync(); Task <List <Recievable> > recievableToDelete = _repositoryWrapper .Recievable .FindAll() .Where(x => x.InvoiceId == vm.InvoiceId && x.FactoryId == vm.FactoryId) .ToListAsync(); await Task.WhenAll(invoiceToDelete, stockOutToDelete, recievableToDelete); // Stock IEnumerable <Stock> stockList = await _repositoryWrapper.Stock.FindByConditionAsync(x => x.FactoryId == vm.FactoryId && x.ItemId == vm.ItemId); Stock existingStock = stockList.ToList().Where(x => x.ItemId == vm.ItemId).FirstOrDefault(); // IF NOT PRESENT ADD if (existingStock == null) { _utilService.Log("Stock Is Empty. Not Enough Stock available"); throw new StockEmptyException(); //stockToAdd = _utilService.Mapper.Map<SalesItemVM, Stock>(salesVM.ItemList[i]); //_repositoryWrapper.Stock.Create(stockToAdd); } // IF PRESENT UPDATE else { existingStock.Quantity += vm.Quantity; _repositoryWrapper.Stock.Update(existingStock); } _repositoryWrapper.Invoice.Delete(invoiceToDelete.Result.ToList().FirstOrDefault()); _repositoryWrapper.StockOut.Delete(stockOutToDelete.Result.ToList().FirstOrDefault()); _repositoryWrapper.Recievable.Delete(recievableToDelete.Result.ToList().FirstOrDefault()); Task <int> inv = _repositoryWrapper.Invoice.SaveChangesAsync(); Task <int> StockIn = _repositoryWrapper.StockIn.SaveChangesAsync(); Task <int> Stock = _repositoryWrapper.Stock.SaveChangesAsync(); Task <int> Payable = _repositoryWrapper.Payable.SaveChangesAsync(); await Task.WhenAll(inv, StockIn, Payable, Stock); var data = new GetDataListVM() { FactoryId = vm.FactoryId, PageSize = 15, PageNumber = 1 }; return(await GetAllPurchaseReturnAsync(data)); }
public async Task <WrapperPurchaseReturnVM> GetAllPurchaseReturnAsync(GetDataListVM getDataListVM) { // Invoice // StockOut WrapperPurchaseReturnVM vm = new WrapperPurchaseReturnVM(); List <PurchaseReturnVM> vmList = new List <PurchaseReturnVM>(); Task <List <Invoice> > invoicesT = _repositoryWrapper .Invoice .FindAll() .Include(x => x.Supplier) .Include(x => x.InvoiceType) .Where(x => x.FactoryId == getDataListVM.FactoryId && x.InvoiceType.Name == TypeInvoice.PurchaseReturn.ToString()) //.Skip((getDataListVM.PageNumber - 1) * (getDataListVM.PageSize)) //.Take(getDataListVM.PageSize) .ToListAsync(); Task <List <StockOut> > stockOutT = _repositoryWrapper .StockOut .FindAll() .Include(x => x.Item) .ThenInclude(x => x.ItemCategory) .Include(x => x.ItemStatus) .Where(x => x.FactoryId == getDataListVM.FactoryId) //.Skip((getDataListVM.PageNumber - 1) * (getDataListVM.PageSize)) //.Take(getDataListVM.PageSize) .ToListAsync(); Task <List <Recievable> > recievableT = _repositoryWrapper .Recievable .FindAll() .Include(x => x.Supplier) .Where(x => x.FactoryId == getDataListVM.FactoryId) //.Skip((getDataListVM.PageNumber - 1) * (getDataListVM.PageSize)) //.Take(getDataListVM.PageSize) .ToListAsync(); await Task.WhenAll(invoicesT, stockOutT, recievableT); List <Invoice> invoiceList = invoicesT.Result.ToList(); List <StockOut> stockOutList = stockOutT.Result.ToList(); List <Recievable> recievableList = recievableT.Result.ToList(); PurchaseReturnVM vc = new PurchaseReturnVM(); for (int i = 0; i < invoiceList.Count; i++) { vc = new PurchaseReturnVM(); Invoice temp = invoiceList.ElementAt(i); vc = _utilService.Mapper.Map <Invoice, PurchaseReturnVM>(temp, vc); vc = _utilService.Mapper.Map <StockOut, PurchaseReturnVM>(stockOutList.Where(x => x.InvoiceId == temp.Id).ToList().FirstOrDefault(), vc); var recievableAmt = recievableList.Where(x => x.InvoiceId == temp.Id).ToList().FirstOrDefault(); if (recievableAmt != null) { vc = _utilService.Mapper.Map <Recievable, PurchaseReturnVM>(recievableAmt, vc); } vmList.Add(vc); } vm.TotalRecords = vmList.Count; vm.ListOfData = vmList .OrderByDescending(x => x.OccurranceDate) .Skip((getDataListVM.PageNumber - 1) * (getDataListVM.PageSize)) .Take(getDataListVM.PageSize) .ToList(); return(vm); }
public async Task <WrapperPurchaseReturnVM> AddPurchaseReturnAsync(PurchaseReturnVM vm) { // StockOut // Invoice // Recievable // Stock Invoice invoiceToAdd = new Invoice(); invoiceToAdd = _utilService.Mapper.Map <PurchaseReturnVM, Invoice>(vm); _repositoryWrapper.Invoice.Create(invoiceToAdd); vm.InvoiceId = invoiceToAdd.Id; if (!vm.IsFullyPaid) { Recievable RecievableToAdd = new Recievable(); RecievableToAdd = _utilService.Mapper.Map <PurchaseReturnVM, Recievable>(vm); _repositoryWrapper.Recievable.Create(RecievableToAdd); } Stock stockToAdd = new Stock(); stockToAdd = _utilService.Mapper.Map <PurchaseReturnVM, Stock>(vm); // Stock IEnumerable <Stock> stockList = await _repositoryWrapper.Stock.FindByConditionAsync(x => x.FactoryId == vm.FactoryId); Stock existingStock = stockList .ToList() .Where(x => x.ItemId == vm.ItemId && x.FactoryId == vm.FactoryId && x.ItemStatusId == vm.ItemStatusId) .FirstOrDefault(); // IF NOT PRESENT ADD if (existingStock == null) { _utilService.Log("Stock Is Empty. Not Enough Stock available"); throw new StockEmptyException(); //stockToAdd = _utilService.Mapper.Map<SalesItemVM, Stock>(salesVM.ItemList[i]); //_repositoryWrapper.Stock.Create(stockToAdd); } // IF PRESENT UPDATE else { if (existingStock.Quantity < vm.Quantity) { throw new StockEmptyException(); } else { existingStock.Quantity -= vm.Quantity; _repositoryWrapper.Stock.Update(existingStock); } } StockOut stockOutToAdd = new StockOut(); stockOutToAdd = _utilService.Mapper.Map <PurchaseReturnVM, StockOut>(vm); _repositoryWrapper.StockOut.Create(stockOutToAdd); if (vm.AmountRecieved > 0) { TblTransaction tblTransactionToAdd = new TblTransaction(); tblTransactionToAdd = _utilService.Mapper.Map <PurchaseReturnVM, TblTransaction>(vm); _repositoryWrapper.Transaction.Create(tblTransactionToAdd); Income incomeToAdd = new Income(); incomeToAdd = _utilService.Mapper.Map <PurchaseReturnVM, Income>(vm); _repositoryWrapper.Income.Create(incomeToAdd); } Task <int> invT = _repositoryWrapper.Invoice.SaveChangesAsync(); Task <int> stockInT = _repositoryWrapper.StockOut.SaveChangesAsync(); Task <int> stockT = _repositoryWrapper.Stock.SaveChangesAsync(); Task <int> payableT = _repositoryWrapper.Recievable.SaveChangesAsync(); Task <int> transactionT = _repositoryWrapper.Transaction.SaveChangesAsync(); Task <int> incomeT = _repositoryWrapper.Income.SaveChangesAsync(); await Task.WhenAll(invT, stockInT, stockT, payableT, transactionT, incomeT); var data = new GetDataListVM() { FactoryId = vm.FactoryId, PageSize = 15, PageNumber = 1 }; return(await GetAllPurchaseReturnAsync(data)); }