コード例 #1
0
        public SalesReturnView()
        {
            InitializeComponent();
            var vm = new SalesReturnVM();

            DataContext = vm;
        }
コード例 #2
0
 public async Task <WrapperSalesReturnVM> DeleteSalesReturn([FromBody] SalesReturnVM sales)
 {
     return(await _serviceWrapper.SalesService.DeleteSalesReturn(sales));
 }
コード例 #3
0
        public async Task <WrapperSalesReturnVM> DeleteSalesReturn(SalesReturnVM vm)
        {
            Task <List <Invoice> > invoiceToDelete = _repositoryWrapper
                                                     .Invoice
                                                     .FindAll()
                                                     .Where(x => x.Id == vm.InvoiceId && x.FactoryId == vm.FactoryId)
                                                     .ToListAsync();
            Task <List <StockIn> > stockInToDelete = _repositoryWrapper
                                                     .StockIn
                                                     .FindAll()
                                                     .Where(x => x.InvoiceId == vm.InvoiceId && x.FactoryId == vm.FactoryId)
                                                     .ToListAsync();
            Task <List <Payable> > payableToDelete = _repositoryWrapper
                                                     .Payable
                                                     .FindAll()
                                                     .Where(x => x.InvoiceId == vm.InvoiceId && x.FactoryId == vm.FactoryId)
                                                     .ToListAsync();

            await Task.WhenAll(invoiceToDelete, stockInToDelete, payableToDelete);

            // 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);
            }

            Invoice invDelete     = _repositoryWrapper.Invoice.Delete(invoiceToDelete.Result.ToList().FirstOrDefault());
            StockIn StockInDelete = _repositoryWrapper.StockIn.Delete(stockInToDelete.Result.ToList().FirstOrDefault());
            Payable PayableDelete = _repositoryWrapper.Payable.Delete(payableToDelete.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 GetAllSalesReturn(data));
        }
コード例 #4
0
        public async Task <WrapperSalesReturnVM> GetAllSalesReturn(GetDataListVM getDataListVM)
        {
            // Invoice
            // StockOut
            WrapperSalesReturnVM vm = new WrapperSalesReturnVM();

            List <SalesReturnVM> vmList = new List <SalesReturnVM>();

            Task <List <Invoice> > invoicesT = _repositoryWrapper
                                               .Invoice
                                               .FindAll()
                                               .Include(x => x.Customer)
                                               .Include(x => x.InvoiceType)
                                               .Where(x => x.FactoryId == getDataListVM.FactoryId &&
                                                      x.InvoiceType.Name == TypeInvoice.SalesReturn.ToString())
                                               //.Skip((getDataListVM.PageNumber - 1) * (getDataListVM.PageSize))
                                               //.Take(getDataListVM.PageSize)
                                               .ToListAsync();

            Task <List <StockIn> > stockInT = _repositoryWrapper
                                              .StockIn
                                              .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 <Payable> > payableT = _repositoryWrapper
                                              .Payable
                                              .FindAll()
                                              .Include(x => x.Customer)
                                              .Where(x => x.FactoryId == getDataListVM.FactoryId)
                                              //.Skip((getDataListVM.PageNumber - 1) * (getDataListVM.PageSize))
                                              //.Take(getDataListVM.PageSize)
                                              .ToListAsync();

            await Task.WhenAll(invoicesT, stockInT, payableT);

            List <Invoice> invoiceList = invoicesT.Result.ToList();
            List <StockIn> stockInList = stockInT.Result.ToList();
            List <Payable> payableList = payableT.Result.ToList();

            SalesReturnVM vc = new SalesReturnVM();

            for (int i = 0; i < invoiceList.Count; i++)
            {
                vc = new SalesReturnVM();
                Invoice temp = invoiceList.ElementAt(i);
                vc = _utilService.Mapper.Map <Invoice, SalesReturnVM>(temp, vc);

                var stockIn = stockInList.Where(x => x.InvoiceId ==
                                                temp.Id).ToList().FirstOrDefault();
                if (stockIn != null)
                {
                    vc = _utilService.Mapper.Map <StockIn, SalesReturnVM>(stockIn, vc);
                }

                var payable = payableList.Where(x => x.InvoiceId == temp.Id).ToList().FirstOrDefault();

                if (payable != null)
                {
                    vc = _utilService.Mapper.Map <Payable, SalesReturnVM>(payable, 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);
        }
コード例 #5
0
        public async Task <WrapperSalesReturnVM> AddSalesReturn(SalesReturnVM vm)
        {
            // StockIn
            // Invoice
            // Payable
            // Stock
            Invoice invoiceToAdd = new Invoice();

            invoiceToAdd = _utilService.Mapper.Map <SalesReturnVM, Invoice>(vm);
            _repositoryWrapper.Invoice.Create(invoiceToAdd);
            vm.InvoiceId = invoiceToAdd.Id;


            Stock stockToAdd = new Stock();

            stockToAdd = _utilService.Mapper.Map <SalesReturnVM, 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).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);
            }

            StockIn stockInToAdd = new StockIn();

            stockInToAdd = _utilService.Mapper.Map <SalesReturnVM, StockIn>(vm);


            if (!vm.IsFullyPaid)
            {
                Payable payableToAdd = new Payable();
                payableToAdd = _utilService.Mapper.Map <SalesReturnVM, Payable>(vm);
                _repositoryWrapper.Payable.Create(payableToAdd);
            }

            _repositoryWrapper.StockIn.Create(stockInToAdd);

            if (vm.AmountPaid > 0)
            {
                TblTransaction tblTransactionToAdd = new TblTransaction();
                tblTransactionToAdd = _utilService.Mapper.Map <SalesReturnVM, TblTransaction>(vm);
                _repositoryWrapper.Transaction.Create(tblTransactionToAdd);

                Expense expenseToAdd = new Expense();
                expenseToAdd = _utilService.Mapper.Map <SalesReturnVM, Expense>(vm);
                _repositoryWrapper.Expense.Create(expenseToAdd);
            }


            Task <int> invT         = _repositoryWrapper.Invoice.SaveChangesAsync();
            Task <int> stockInT     = _repositoryWrapper.StockIn.SaveChangesAsync();
            Task <int> stockT       = _repositoryWrapper.Stock.SaveChangesAsync();
            Task <int> payableT     = _repositoryWrapper.Payable.SaveChangesAsync();
            Task <int> transactionT = _repositoryWrapper.Transaction.SaveChangesAsync();
            Task <int> expenseT     = _repositoryWrapper.Expense.SaveChangesAsync();

            await Task.WhenAll(invT, stockInT, stockT, payableT, transactionT, expenseT);



            var data = new GetDataListVM()
            {
                FactoryId  = vm.FactoryId,
                PageSize   = 15,
                PageNumber = 1
            };

            return(await GetAllSalesReturn(data));
        }
コード例 #6
0
 public SalesReturnView()
 {
     InitializeComponent();
     var vm = new SalesReturnVM();
     DataContext = vm;
 }
コード例 #7
0
 public SalesReturnNewEntryVM(SalesReturnVM parentVM)
 {
     _parentVM = parentVM;
 }