public void Validate_Null() { GarmentLeftoverWarehouseExpenditureFabricViewModel viewModel = new GarmentLeftoverWarehouseExpenditureFabricViewModel(); var result = viewModel.Validate(null); Assert.True(result.Count() > 0); }
public void Validate_Items_Quantity_Over() { GarmentLeftoverWarehouseExpenditureFabricViewModel viewModel = new GarmentLeftoverWarehouseExpenditureFabricViewModel { Items = new List <GarmentLeftoverWarehouseExpenditureFabricItemViewModel> { new GarmentLeftoverWarehouseExpenditureFabricItemViewModel { StockId = 1, Quantity = 2 } } }; var mockService = new Mock <IGarmentLeftoverWarehouseExpenditureFabricService>(); mockService.Setup(s => s.CheckStockQuantity(It.IsAny <int>(), It.IsAny <int>())) .Returns(1); var mockSerivceProvider = GetServiceProvider(); mockSerivceProvider.Setup(s => s.GetService(typeof(IGarmentLeftoverWarehouseExpenditureFabricService))) .Returns(mockService.Object); var validationContext = new ValidationContext(viewModel, mockSerivceProvider.Object, null); var result = viewModel.Validate(validationContext); Assert.True(result.Count() > 0); }
public void Validate_Items_Empty() { GarmentLeftoverWarehouseExpenditureFabricViewModel viewModel = new GarmentLeftoverWarehouseExpenditureFabricViewModel { Items = new List <GarmentLeftoverWarehouseExpenditureFabricItemViewModel>() }; var result = viewModel.Validate(null); Assert.True(result.Count() > 0); }
public void Validate_ExpenditureDate_MoreThanToday() { GarmentLeftoverWarehouseExpenditureFabricViewModel viewModel = new GarmentLeftoverWarehouseExpenditureFabricViewModel() { ExpenditureDate = DateTimeOffset.Now.AddDays(4) }; var result = viewModel.Validate(null); Assert.True(result.Count() > 0); }
public void Validate_ExpenditureDate_MinValue() { GarmentLeftoverWarehouseExpenditureFabricViewModel viewModel = new GarmentLeftoverWarehouseExpenditureFabricViewModel() { ExpenditureDate = DateTimeOffset.MinValue }; var result = viewModel.Validate(null); Assert.True(result.Count() > 0); }
public void ValidateViewModel_LAIN_LAIN() { GarmentLeftoverWarehouseExpenditureFabricViewModel viewModel = new GarmentLeftoverWarehouseExpenditureFabricViewModel() { ExpenditureDestination = "LAIN-LAIN", EtcRemark = null }; var result = viewModel.Validate(null); Assert.True(result.Count() > 0); }
public void ValidateViewModel_JUAL_LOKAL() { GarmentLeftoverWarehouseExpenditureFabricViewModel viewModel = new GarmentLeftoverWarehouseExpenditureFabricViewModel() { ExpenditureDestination = "JUAL LOKAL", Buyer = null }; var result = viewModel.Validate(null); Assert.True(result.Count() > 0); }
public void ValidateViewModel_UNIT() { GarmentLeftoverWarehouseExpenditureFabricViewModel viewModel = new GarmentLeftoverWarehouseExpenditureFabricViewModel() { ExpenditureDestination = "UNIT", UnitExpenditure = null }; var result = viewModel.Validate(null); Assert.True(result.Count() > 0); }
public GarmentLeftoverWarehouseExpenditureFabricViewModel MapToViewModel(GarmentLeftoverWarehouseExpenditureFabric model) { GarmentLeftoverWarehouseExpenditureFabricViewModel viewModel = new GarmentLeftoverWarehouseExpenditureFabricViewModel(); PropertyCopier <GarmentLeftoverWarehouseExpenditureFabric, GarmentLeftoverWarehouseExpenditureFabricViewModel> .Copy(model, viewModel); viewModel.UnitExpenditure = new UnitViewModel { Id = model.UnitExpenditureId.ToString(), Code = model.UnitExpenditureCode, Name = model.UnitExpenditureName }; viewModel.Buyer = new BuyerViewModel { Id = model.BuyerId, Code = model.BuyerCode, Name = model.BuyerName }; if (model.Items != null) { viewModel.Items = new List <GarmentLeftoverWarehouseExpenditureFabricItemViewModel>(); foreach (var modelItem in model.Items) { GarmentLeftoverWarehouseExpenditureFabricItemViewModel viewModelItem = new GarmentLeftoverWarehouseExpenditureFabricItemViewModel(); PropertyCopier <GarmentLeftoverWarehouseExpenditureFabricItem, GarmentLeftoverWarehouseExpenditureFabricItemViewModel> .Copy(modelItem, viewModelItem); viewModelItem.Unit = new UnitViewModel { Id = modelItem.UnitId.ToString(), Code = modelItem.UnitCode, Name = modelItem.UnitName }; viewModelItem.Uom = new UomViewModel { Id = modelItem.UomId.ToString(), Unit = modelItem.UomUnit }; viewModel.Items.Add(viewModelItem); } } return(viewModel); }
public void MapToModel() { GarmentLeftoverWarehouseExpenditureFabricService service = new GarmentLeftoverWarehouseExpenditureFabricService(_dbContext(GetCurrentMethod()), GetServiceProvider().Object); var data = new GarmentLeftoverWarehouseExpenditureFabricViewModel { ExpenditureDate = DateTimeOffset.Now, ExpenditureDestination = "SAMPLE", UnitExpenditure = new UnitViewModel { Id = "1", Code = "Unit", Name = "Unit" }, Buyer = new BuyerViewModel { Id = 1, Code = "Code", Name = "Name" }, EtcRemark = "Remark", Remark = "Remark", Items = new List <GarmentLeftoverWarehouseExpenditureFabricItemViewModel> { new GarmentLeftoverWarehouseExpenditureFabricItemViewModel { StockId = 1, Unit = new UnitViewModel { Id = "1", Code = "Unit", Name = "Unit" }, PONo = "PONo", Quantity = 1, Uom = new UomViewModel { Id = "1", Unit = "Uom" } } } }; var result = service.MapToModel(data); Assert.NotNull(result); }
public GarmentLeftoverWarehouseExpenditureFabric MapToModel(GarmentLeftoverWarehouseExpenditureFabricViewModel viewModel) { GarmentLeftoverWarehouseExpenditureFabric model = new GarmentLeftoverWarehouseExpenditureFabric(); PropertyCopier <GarmentLeftoverWarehouseExpenditureFabricViewModel, GarmentLeftoverWarehouseExpenditureFabric> .Copy(viewModel, model); if (viewModel.UnitExpenditure != null) { model.UnitExpenditureId = long.Parse(viewModel.UnitExpenditure.Id); model.UnitExpenditureCode = viewModel.UnitExpenditure.Code; model.UnitExpenditureName = viewModel.UnitExpenditure.Name; } if (viewModel.Buyer != null) { model.BuyerId = viewModel.Buyer.Id; model.BuyerCode = viewModel.Buyer.Code; model.BuyerName = viewModel.Buyer.Name; } model.Items = new List <GarmentLeftoverWarehouseExpenditureFabricItem>(); foreach (var viewModelItem in viewModel.Items) { GarmentLeftoverWarehouseExpenditureFabricItem modelItem = new GarmentLeftoverWarehouseExpenditureFabricItem(); PropertyCopier <GarmentLeftoverWarehouseExpenditureFabricItemViewModel, GarmentLeftoverWarehouseExpenditureFabricItem> .Copy(viewModelItem, modelItem); if (viewModelItem.Unit != null) { modelItem.UnitId = long.Parse(viewModelItem.Unit.Id); modelItem.UnitCode = viewModelItem.Unit.Code; modelItem.UnitName = viewModelItem.Unit.Name; } if (viewModelItem.Uom != null) { modelItem.UomId = long.Parse(viewModelItem.Uom.Id); modelItem.UomUnit = viewModelItem.Uom.Unit; } model.Items.Add(modelItem); } return(model); }
public GarmentLeftoverWarehouseExpenditureFabricViewModel GetNewData() { long nowTicks = DateTimeOffset.Now.Ticks; var data = new GarmentLeftoverWarehouseExpenditureFabricViewModel { Id = 1, ExpenditureNo = "exNo", IsUsed = false, Items = new List <GarmentLeftoverWarehouseExpenditureFabricItemViewModel> { new GarmentLeftoverWarehouseExpenditureFabricItemViewModel { Quantity = 1, } } }; return(data); }
public void Validate_Items_StockId_Duplicate() { GarmentLeftoverWarehouseExpenditureFabricViewModel viewModel = new GarmentLeftoverWarehouseExpenditureFabricViewModel { Items = new List <GarmentLeftoverWarehouseExpenditureFabricItemViewModel> { new GarmentLeftoverWarehouseExpenditureFabricItemViewModel { PONo = "PONo", Uom = new UomViewModel(), StockId = 1 }, new GarmentLeftoverWarehouseExpenditureFabricItemViewModel { PONo = "PONo", Uom = new UomViewModel(), StockId = 1 }, } }; var result = viewModel.Validate(null); Assert.True(result.Count() > 0); }
public MemoryStream GeneratePdfTemplate(GarmentLeftoverWarehouseExpenditureFabricViewModel viewModel, List <GarmentProductViewModel> products) { 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); string signee = viewModel.ExpenditureDestination == "JUAL LOKAL" ? viewModel.Buyer.Name : viewModel.ExpenditureDestination == "UNIT" ? viewModel.UnitExpenditure.Name : viewModel.ExpenditureDestination == "SAMPLE" ? "Bagian Sample" : ""; writer.PageEvent = new GarmentLeftoverWarehouseExpenditureSignPDFTemplatePageEvent(signee); document.Open(); #region TITLE Paragraph title = new Paragraph("BON KELUAR 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.ExpenditureNo, bold_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase("Tujuan", normal_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase(":", normal_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase(viewModel.ExpenditureDestination, 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.ExpenditureDate.GetValueOrDefault().ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("en-EN")), normal_font); tableHeader.AddCell(cellHeaderContentLeft); if (viewModel.ExpenditureDestination == "SAMPLE") { cellHeaderContentLeft.Phrase = new Phrase("", bold_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase("", bold_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase("", bold_font); tableHeader.AddCell(cellHeaderContentLeft); } else if (viewModel.ExpenditureDestination == "JUAL LOKAL") { cellHeaderContentLeft.Phrase = new Phrase("Buyer", normal_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase(":", normal_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase(viewModel.Buyer.Name, normal_font); tableHeader.AddCell(cellHeaderContentLeft); } else if (viewModel.ExpenditureDestination == "UNIT") { cellHeaderContentLeft.Phrase = new Phrase("Unit", normal_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase(":", normal_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase(viewModel.UnitExpenditure.Name, normal_font); tableHeader.AddCell(cellHeaderContentLeft); } else { cellHeaderContentLeft.Phrase = new Phrase("Keterangan Lain-lain", normal_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase(":", normal_font); tableHeader.AddCell(cellHeaderContentLeft); cellHeaderContentLeft.Phrase = new Phrase(viewModel.EtcRemark, 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, 2f, 2f }); 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++; var Product = products.Where(a => a.PONo == item.PONo).FirstOrDefault(); bodyTableCellLeftBorder.Phrase = new Phrase(index.ToString(), normal_font); bodyTable.AddCell(bodyTableCellLeftBorder); bodyTableCellLeftBorder.Phrase = new Phrase(Product.Code, normal_font); bodyTable.AddCell(bodyTableCellLeftBorder); bodyTableCellLeftBorder.Phrase = new Phrase(item.PONo, normal_font); bodyTable.AddCell(bodyTableCellLeftBorder); bodyTableCellLeftBorder.Phrase = new Phrase(Product.Composition, normal_font); bodyTable.AddCell(bodyTableCellLeftBorder); bodyTableCellLeftBorder.Phrase = new Phrase(Product.Const + "; " + Product.Yarn + "; " + Product.Width, normal_font); bodyTable.AddCell(bodyTableCellLeftBorder); bodyTableCellRightBorder.Phrase = new Phrase(item.Quantity.ToString(), normal_font); bodyTable.AddCell(bodyTableCellRightBorder); bodyTableCellLeftBorder.Phrase = new Phrase("MT", 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 = 15f; document.Add(bodyTable); #endregion #region remark PdfPTable tableRemark = new PdfPTable(3); tableRemark.WidthPercentage = 80; tableRemark.HorizontalAlignment = Element.ALIGN_LEFT; tableRemark.SetWidths(new float[] { 1f, 0.1f, 8f }); PdfPCell cellRemarkContentLeft = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellRemarkContentLeft.Phrase = new Phrase("Keterangan", normal_font); tableRemark.AddCell(cellRemarkContentLeft); cellRemarkContentLeft.Phrase = new Phrase(":", normal_font); tableRemark.AddCell(cellRemarkContentLeft); cellRemarkContentLeft.Phrase = new Phrase(viewModel.Remark, normal_font); tableRemark.AddCell(cellRemarkContentLeft); document.Add(tableRemark); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }