public void ValidateViewModel() { GarmentLeftoverWarehouseReceiptFabricViewModel viewModel = new GarmentLeftoverWarehouseReceiptFabricViewModel() { UnitFrom = null, UENNo = null, ReceiptDate = DateTimeOffset.MinValue, Items = new List <GarmentLeftoverWarehouseReceiptFabricItemViewModel>() { new GarmentLeftoverWarehouseReceiptFabricItemViewModel() } }; var result = viewModel.Validate(null); Assert.True(result.Count() > 0); GarmentLeftoverWarehouseReceiptFabricViewModel viewModel1 = new GarmentLeftoverWarehouseReceiptFabricViewModel() { UnitFrom = null, UENNo = null, ReceiptDate = DateTimeOffset.Now.AddDays(4), Items = new List <GarmentLeftoverWarehouseReceiptFabricItemViewModel>() { new GarmentLeftoverWarehouseReceiptFabricItemViewModel() } }; var result1 = viewModel1.Validate(null); Assert.True(result1.Count() > 0); }
public void MapToModel() { GarmentLeftoverWarehouseReceiptFabricService service = new GarmentLeftoverWarehouseReceiptFabricService(_dbContext(GetCurrentMethod()), GetServiceProvider().Object); var data = new GarmentLeftoverWarehouseReceiptFabricViewModel { UnitFrom = new UnitViewModel { Id = "1", Code = "Unit", Name = "Unit" }, UENId = 1, UENNo = "UENNo", StorageFrom = new StorageViewModel { _id = "1", code = "Storage", name = "Storage" }, ExpenditureDate = DateTimeOffset.Now, ReceiptDate = DateTimeOffset.Now, Remark = "Remark", Items = new List <GarmentLeftoverWarehouseReceiptFabricItemViewModel> { new GarmentLeftoverWarehouseReceiptFabricItemViewModel { UENItemId = 1, Product = new ProductViewModel { Id = "1", Code = "Product", Name = "Product" }, ProductRemark = "Remark", FabricRemark = "FabricRemark", Composition = "Composition", Quantity = 1, BasicPrice = 1, Uom = new UomViewModel { Id = "1", Unit = "Uom" } } } }; var result = service.MapToModel(data); Assert.NotNull(result); }
public GarmentLeftoverWarehouseReceiptFabricViewModel MapToViewModel(GarmentLeftoverWarehouseReceiptFabric model) { GarmentLeftoverWarehouseReceiptFabricViewModel viewModel = new GarmentLeftoverWarehouseReceiptFabricViewModel(); PropertyCopier <GarmentLeftoverWarehouseReceiptFabric, GarmentLeftoverWarehouseReceiptFabricViewModel> .Copy(model, viewModel); viewModel.UnitFrom = new UnitViewModel { Id = model.UnitFromId.ToString(), Code = model.UnitFromCode, Name = model.UnitFromName }; viewModel.StorageFrom = new StorageViewModel { _id = model.StorageFromId.ToString(), code = model.StorageFromCode, name = model.StorageFromName }; if (model.Items != null) { viewModel.Items = new List <GarmentLeftoverWarehouseReceiptFabricItemViewModel>(); foreach (var modelItem in model.Items) { GarmentLeftoverWarehouseReceiptFabricItemViewModel viewModelItem = new GarmentLeftoverWarehouseReceiptFabricItemViewModel(); PropertyCopier <GarmentLeftoverWarehouseReceiptFabricItem, GarmentLeftoverWarehouseReceiptFabricItemViewModel> .Copy(modelItem, viewModelItem); viewModelItem.Product = new ProductViewModel { Id = modelItem.ProductId.ToString(), Code = modelItem.ProductCode, Name = modelItem.ProductName }; viewModelItem.Uom = new UomViewModel { Id = modelItem.UomId.ToString(), Unit = modelItem.UomUnit }; viewModel.Items.Add(viewModelItem); } } return(viewModel); }
public GarmentLeftoverWarehouseReceiptFabric MapToModel(GarmentLeftoverWarehouseReceiptFabricViewModel viewModel) { GarmentLeftoverWarehouseReceiptFabric model = new GarmentLeftoverWarehouseReceiptFabric(); PropertyCopier <GarmentLeftoverWarehouseReceiptFabricViewModel, GarmentLeftoverWarehouseReceiptFabric> .Copy(viewModel, model); if (viewModel.UnitFrom != null) { model.UnitFromId = long.Parse(viewModel.UnitFrom.Id); model.UnitFromCode = viewModel.UnitFrom.Code; model.UnitFromName = viewModel.UnitFrom.Name; } if (viewModel.StorageFrom != null) { model.StorageFromId = long.Parse(viewModel.StorageFrom._id); model.StorageFromCode = viewModel.StorageFrom.code; model.StorageFromName = viewModel.StorageFrom.name; } model.Items = new List <GarmentLeftoverWarehouseReceiptFabricItem>(); foreach (var viewModelItem in viewModel.Items) { GarmentLeftoverWarehouseReceiptFabricItem modelItem = new GarmentLeftoverWarehouseReceiptFabricItem(); PropertyCopier <GarmentLeftoverWarehouseReceiptFabricItemViewModel, GarmentLeftoverWarehouseReceiptFabricItem> .Copy(viewModelItem, modelItem); if (viewModelItem.Product != null) { modelItem.ProductId = long.Parse(viewModelItem.Product.Id); modelItem.ProductCode = viewModelItem.Product.Code; modelItem.ProductName = viewModelItem.Product.Name; } if (viewModelItem.Uom != null) { modelItem.UomId = long.Parse(viewModelItem.Uom.Id); modelItem.UomUnit = viewModelItem.Uom.Unit; } model.Items.Add(modelItem); } return(model); }
public void validate_Id() { //Setup GarmentLeftoverWarehouseReceiptFabricViewModel viewModel = new GarmentLeftoverWarehouseReceiptFabricViewModel() { UENNo = "1" }; Mock <IServiceProvider> serviceProviderMock = new Mock <IServiceProvider>(); Mock <IGarmentLeftoverWarehouseReceiptFabricService> GarmentLeftoverWarehouseReceiptFabricMock = new Mock <IGarmentLeftoverWarehouseReceiptFabricService>(); GarmentLeftoverWarehouseReceiptFabricMock.Setup(s => s.Read(It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <List <string> >(), It.IsAny <string>(), It.IsAny <string>())).Returns(new ReadResponse <GarmentLeftoverWarehouseReceiptFabric>(new List <GarmentLeftoverWarehouseReceiptFabric>(), 1, new Dictionary <string, string>(), new List <string>())); serviceProviderMock.Setup(s => s.GetService(typeof(IGarmentLeftoverWarehouseReceiptFabricService))).Returns(GarmentLeftoverWarehouseReceiptFabricMock.Object); ValidationContext validationContext = new ValidationContext(viewModel, serviceProviderMock.Object, null); //Act var result = viewModel.Validate(validationContext); //Assert Assert.True(0 < result.Count()); }
public MemoryStream GeneratePdfTemplate(GarmentLeftoverWarehouseReceiptFabricViewModel viewModel) { const int MARGIN = 20; var timeoffset = 7; Font header_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 14); Font normal_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font body_font = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font normal_font_underlined = FontFactory.GetFont(BaseFont.HELVETICA, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8, Font.UNDERLINE); Font bold_font = FontFactory.GetFont(BaseFont.HELVETICA_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Document document = new Document(PageSize.A5.Rotate(), MARGIN, MARGIN, MARGIN, 70); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); writer.PageEvent = new GarmentLeftoverWarehouseReceiptSignPDFTemplatePageEvent(); document.Open(); #region TITLE Paragraph title = new Paragraph("BON TERIMA FABRIC GUDANG SISA", header_font); title.Alignment = Element.ALIGN_CENTER; document.Add(title); Paragraph danliris = new Paragraph("PT. DANLIRIS", bold_font); document.Add(danliris); Paragraph address = new Paragraph("BANARAN, GROGOL, SUKOHARJO", normal_font); document.Add(address); Paragraph p = new Paragraph(new Chunk(new LineSeparator(0.5F, 100.0F, BaseColor.Black, Element.ALIGN_LEFT, 1))); p.SpacingBefore = -10f; document.Add(p); #endregion #region HEADER PdfPTable tableHeader = new PdfPTable(6); tableHeader.WidthPercentage = 100; tableHeader.HorizontalAlignment = Element.ALIGN_LEFT; tableHeader.SetWidths(new float[] { 2f, 0.1f, 5f, 2f, 0.1f, 4f }); PdfPCell cellHeaderContentLeft = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellHeaderContentLeft.Phrase = new Phrase("NO", bold_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase(":", bold_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase(viewModel.ReceiptNoteNo, bold_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase("Terima dari", normal_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase(":", normal_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase(viewModel.UnitFrom.Name, normal_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase("Tanggal", normal_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase(":", normal_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase(viewModel.ReceiptDate.GetValueOrDefault().ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("en-EN")), normal_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase("Dasar terima", normal_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase(":", normal_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase(viewModel.UENNo, normal_font); tableHeader.AddCell(cellHeaderContentLeft); tableHeader.SpacingAfter = 15f; document.Add(tableHeader); #endregion #region BODY PdfPTable bodyTable = new PdfPTable(7); bodyTable.WidthPercentage = 100; bodyTable.SetWidths(new float[] { 1f, 3f, 3f, 5f, 6f, 3f, 3f }); PdfPCell bodyTableCellRightBorder = new PdfPCell() { MinimumHeight = 15, Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell bodyTableCellLeftBorder = new PdfPCell() { MinimumHeight = 15, Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell bodyTableCellCenterBorder = new PdfPCell() { MinimumHeight = 15, Border = Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER | Rectangle.BOTTOM_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; bodyTableCellCenterBorder.Phrase = new Phrase("NO", bold_font); bodyTable.AddCell(bodyTableCellCenterBorder); bodyTableCellCenterBorder.Phrase = new Phrase("KODE BARANG", bold_font); bodyTable.AddCell(bodyTableCellCenterBorder); bodyTableCellCenterBorder.Phrase = new Phrase("NO. PO", bold_font); bodyTable.AddCell(bodyTableCellCenterBorder); bodyTableCellCenterBorder.Phrase = new Phrase("KOMPOSISI", bold_font); bodyTable.AddCell(bodyTableCellCenterBorder); bodyTableCellCenterBorder.Phrase = new Phrase("CONST,YARN,WIDTH", bold_font); bodyTable.AddCell(bodyTableCellCenterBorder); bodyTableCellCenterBorder.Phrase = new Phrase("QTY", bold_font); bodyTable.AddCell(bodyTableCellCenterBorder); bodyTableCellCenterBorder.Phrase = new Phrase("SAT", bold_font); bodyTable.AddCell(bodyTableCellCenterBorder); int index = 0; double totalQuantity = 0; foreach (var item in viewModel.Items) { index++; bodyTableCellLeftBorder.Phrase = new Phrase(index.ToString(), normal_font); bodyTable.AddCell(bodyTableCellLeftBorder); bodyTableCellLeftBorder.Phrase = new Phrase(item.Product.Code, normal_font); bodyTable.AddCell(bodyTableCellLeftBorder); bodyTableCellLeftBorder.Phrase = new Phrase(item.POSerialNumber, normal_font); bodyTable.AddCell(bodyTableCellLeftBorder); bodyTableCellLeftBorder.Phrase = new Phrase(item.Composition, normal_font); bodyTable.AddCell(bodyTableCellLeftBorder); bodyTableCellLeftBorder.Phrase = new Phrase(item.FabricRemark, normal_font); bodyTable.AddCell(bodyTableCellLeftBorder); bodyTableCellRightBorder.Phrase = new Phrase(item.Quantity.ToString(), normal_font); bodyTable.AddCell(bodyTableCellRightBorder); bodyTableCellLeftBorder.Phrase = new Phrase(item.Uom.Unit, normal_font); bodyTable.AddCell(bodyTableCellLeftBorder); totalQuantity += item.Quantity; } bodyTableCellRightBorder.Phrase = new Phrase("TOTAL", bold_font); bodyTableCellRightBorder.Colspan = 5; bodyTable.AddCell(bodyTableCellRightBorder); bodyTableCellRightBorder.Phrase = new Phrase(totalQuantity.ToString(), bold_font); bodyTableCellRightBorder.Colspan = 1; bodyTable.AddCell(bodyTableCellRightBorder); bodyTableCellLeftBorder.Phrase = new Phrase("MT", bold_font); bodyTable.AddCell(bodyTableCellLeftBorder); bodyTable.SpacingAfter = 25f; document.Add(bodyTable); #endregion #region sign //PdfPTable tableSign = new PdfPTable(2); //tableSign.WidthPercentage = 100; //tableSign.SetWidths(new float[] { 1f, 1f}); //PdfPCell cellBodySignNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; //cellBodySignNoBorder.Phrase = new Phrase("Pengirim,\n\n\n\n\n", normal_font); //tableSign.AddCell(cellBodySignNoBorder); //cellBodySignNoBorder.Phrase = new Phrase("Penerima,\n\n\n\n\n", normal_font); //tableSign.AddCell(cellBodySignNoBorder); //cellBodySignNoBorder.Phrase = new Phrase("(_____________________________)", normal_font); //tableSign.AddCell(cellBodySignNoBorder); //cellBodySignNoBorder.Phrase = new Phrase("(_____________________________)", normal_font); //tableSign.AddCell(cellBodySignNoBorder); //cellBodySignNoBorder.Phrase = new Phrase("Gudang Unit", normal_font); //tableSign.AddCell(cellBodySignNoBorder); //cellBodySignNoBorder.Phrase = new Phrase("Gudang Sisa", normal_font); //tableSign.AddCell(cellBodySignNoBorder); //document.Add(tableSign); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }