private StockMovementOptions GetOptions() { StockMovementOptions options = new StockMovementOptions() { SearchValue = tbSeachText.Text, LocationId = ( int? )cbLocations.SelectedValue, UserId = ( int? )cbUsers.SelectedValue, StartDate = dtpStart.Value, EndDate = dtpEnd.Value }; return(options); }
public async Task ExportStockMovementsToPDFAsync(ExportData <IEnumerable <StockMovement>, StockMovementOptions> data) { try { IEnumerable <StockMovement> movements = data.Data; StockMovementOptions options = data?.Options; PDFGenerator pdf = new PDFGenerator(Phrases.StockMovementsLabel, Phrases.StockMovementsListOf); Section section = pdf.CreateDocumentSection(); // Set title pdf.AddParagraph(Phrases.StockMovementsLabel, true, false, 16); if (options != null) { string startDate = (options?.StartDate != default) ? $"{options.StartDate.ShortDate()} - " : ""; string endDate = (options?.EndDate != default) ? options.EndDate.ShortDate() : ""; pdf.AddParagraph($"{Phrases.GlobalDate}: {startDate}{endDate}", false, true); if (!string.IsNullOrEmpty(options.SearchValue)) { Product product = movements.ElementAt(0).Product; pdf.AddParagraph($"{Phrases.GlobalProduct}: {product.Reference} {product.Name}", false, true); } if (options.LocationId != null) { Location location = await AppServices.LocationService.GetByIdAsync(( int )options.LocationId); pdf.AddParagraph($"{Phrases.GlobalLocation}: {location.Name}", false, true); } if (options.UserId != null) { User user = await AppServices.UserService.GetByIdAsync(( int )options.UserId); pdf.AddParagraph($"{Phrases.GlobalUser}: {user.Username}", false, true); } pdf.AddParagraph("", false, false, null, 1); } // Create table and table columns Table table = pdf.CreateTable(); pdf.AddTableColumn(table, ParagraphAlignment.Left); pdf.AddTableColumn(table, ParagraphAlignment.Left); pdf.AddTableColumn(table, ParagraphAlignment.Left); pdf.AddTableColumn(table, ParagraphAlignment.Left); pdf.AddTableColumn(table, ParagraphAlignment.Left); pdf.AddTableColumn(table, ParagraphAlignment.Right); pdf.AddTableColumn(table, ParagraphAlignment.Right); // Create table header Row row = pdf.CreateTableHeaderRow(table); pdf.AddTableRowCell(row, 0, ParagraphAlignment.Left, Phrases.GlobalDate, true); pdf.AddTableRowCell(row, 1, ParagraphAlignment.Left, Phrases.GlobalUser, true); pdf.AddTableRowCell(row, 2, ParagraphAlignment.Left, Phrases.GlobalReference, true); pdf.AddTableRowCell(row, 3, ParagraphAlignment.Left, Phrases.GlobalName, true); pdf.AddTableRowCell(row, 4, ParagraphAlignment.Left, Phrases.GlobalMovement, true); pdf.AddTableRowCell(row, 5, ParagraphAlignment.Right, Phrases.StockMovementQty, true); pdf.AddTableRowCell(row, 6, ParagraphAlignment.Right, Phrases.StockMovementStockAcc, true); // Populate the table rows movements.ToList().ForEach((movement) => { row = table.AddRow(); pdf.AddTableRowCell(row, 0, ParagraphAlignment.Left, movement.CreatedAt.ShortDateWithTime()); pdf.AddTableRowCell(row, 1, ParagraphAlignment.Left, movement.User.Username); pdf.AddTableRowCell(row, 2, ParagraphAlignment.Left, movement.Product.Reference); pdf.AddTableRowCell(row, 3, ParagraphAlignment.Left, movement.Product.Name); pdf.AddTableRowCell(row, 4, ParagraphAlignment.Left, movement.ConcatMovementString()); pdf.AddTableRowCell(row, 5, ParagraphAlignment.Right, movement.Qty.ToString()); pdf.AddTableRowCell(row, 6, ParagraphAlignment.Right, movement.Stock.ToString()); }); // Add the table to the section pdf.AddTableToLastSection(table); // Rendering the document await pdf.GenerateAsync(); } catch { OperationErrorsList errorsList = new OperationErrorsList(); errorsList.AddError("export-stock-movements-error", Phrases.GlobalErrorOperationDB); throw new ServiceErrorException(errorsList); } }
public async Task <IEnumerable <StockMovement> > GetAllAsync(StockMovementOptions options = null) { return(options != null ? await _repository.StockMovements.FindAllOrderedByDescendingWithProductAndUserAsync(options) : await _repository.StockMovements.FindAllOrderedByDescendingWithProductAndUserAsync()); }
public async Task <IEnumerable <StockMovement> > FindAllOrderedByDescendingWithProductAndUserAsync(StockMovementOptions options) { /* * Dynamically Composing Expression Predicates * http://www.albahari.com/nutshell/predicatebuilder.aspx */ IQueryable <StockMovement> queryable = _db.StockMovements.AsNoTracking().Include(x => x.Product).Include(x => x.User); if (!string.IsNullOrEmpty(options.SearchValue)) { string searchValue = options.SearchValue.ToLower(); queryable = queryable .Where(x => x.Product.Reference.ToLower().Contains(searchValue) || x.Product.Name.ToLower().Contains(searchValue)); } if (options.LocationId != null) { queryable = queryable .Where(x => (x.ToLocationId == options.LocationId) || (x.FromLocationId == options.LocationId)); } if (options.UserId != null) { queryable = queryable.Where(x => x.UserId == options.UserId); } if (options.StartDate != default) { queryable = queryable.Where(x => x.CreatedAt >= options.StartDate.SetDateToBeginningOfTheDay()); } if (options.EndDate != default) { queryable = queryable.Where(x => x.CreatedAt <= options.EndDate.SetDateToEndOfTheDay()); } return(await queryable.OrderByDescending(x => x.CreatedAt).ToListAsync()); }