public void validate_Id()
        {
            //Setup
            GarmentLeftoverWarehouseReceiptFinishedGoodViewModel viewModel = new GarmentLeftoverWarehouseReceiptFinishedGoodViewModel()
            {
                Items = new List <GarmentLeftoverWarehouseReceiptFinishedGoodItemViewModel>()
                {
                    new GarmentLeftoverWarehouseReceiptFinishedGoodItemViewModel
                    {
                        ExpenditureGoodNo = "1"
                    }
                }
            };

            Mock <IServiceProvider> serviceProviderMock = new Mock <IServiceProvider>();
            Mock <IGarmentLeftoverWarehouseReceiptFinishedGoodService> IGarmentLeftoverWarehouseReceiptFinishedGoodServiceMock = new Mock <IGarmentLeftoverWarehouseReceiptFinishedGoodService>();

            IGarmentLeftoverWarehouseReceiptFinishedGoodServiceMock.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 <GarmentLeftoverWarehouseReceiptFinishedGood>(new List <GarmentLeftoverWarehouseReceiptFinishedGood>(), 1, new Dictionary <string, string>(), new List <string>()));
            serviceProviderMock.Setup(s => s.GetService(typeof(IGarmentLeftoverWarehouseReceiptFinishedGoodService))).Returns(IGarmentLeftoverWarehouseReceiptFinishedGoodServiceMock.Object);

            ValidationContext validationContext = new ValidationContext(viewModel, serviceProviderMock.Object, null);

            //Act
            var result = viewModel.Validate(validationContext);

            //Assert
            Assert.True(0 < result.Count());
        }
        public void ValidateViewModel()
        {
            GarmentLeftoverWarehouseReceiptFinishedGoodViewModel viewModel = new GarmentLeftoverWarehouseReceiptFinishedGoodViewModel()
            {
                UnitFrom    = null,
                ReceiptDate = DateTimeOffset.MinValue,
                Items       = new List <GarmentLeftoverWarehouseReceiptFinishedGoodItemViewModel>()
                {
                    new GarmentLeftoverWarehouseReceiptFinishedGoodItemViewModel()
                }
            };
            var result = viewModel.Validate(null);

            Assert.True(result.Count() > 0);

            GarmentLeftoverWarehouseReceiptFinishedGoodViewModel viewModel1 = new GarmentLeftoverWarehouseReceiptFinishedGoodViewModel()
            {
                UnitFrom    = null,
                ReceiptDate = DateTimeOffset.Now.AddDays(4),
                Items       = new List <GarmentLeftoverWarehouseReceiptFinishedGoodItemViewModel>()
                {
                    new GarmentLeftoverWarehouseReceiptFinishedGoodItemViewModel()
                }
            };
            var result1 = viewModel1.Validate(null);

            Assert.True(result1.Count() > 0);


            GarmentLeftoverWarehouseReceiptFinishedGoodViewModel viewModel2 = new GarmentLeftoverWarehouseReceiptFinishedGoodViewModel()
            {
                UnitFrom    = null,
                ReceiptDate = DateTimeOffset.Now.AddDays(4)
            };
            var result2 = viewModel2.Validate(null);

            Assert.True(result2.Count() > 0);

            GarmentLeftoverWarehouseReceiptFinishedGoodViewModel viewModel3 = new GarmentLeftoverWarehouseReceiptFinishedGoodViewModel()
            {
                UnitFrom    = null,
                ReceiptDate = DateTimeOffset.Now.AddDays(4),
                Items       = new List <GarmentLeftoverWarehouseReceiptFinishedGoodItemViewModel>()
                {
                    new GarmentLeftoverWarehouseReceiptFinishedGoodItemViewModel()
                    {
                        ExpenditureGoodNo = null,
                        LeftoverComodity  = new LeftoverComodityViewModel
                        {
                            Name = "name",
                            Id   = 1
                        }
                    }
                }
            };
            var result3 = viewModel3.Validate(null);

            Assert.True(result3.Count() > 0);
        }
Esempio n. 3
0
        public GarmentLeftoverWarehouseReceiptFinishedGood MapToModel(GarmentLeftoverWarehouseReceiptFinishedGoodViewModel viewModel)
        {
            GarmentLeftoverWarehouseReceiptFinishedGood model = new GarmentLeftoverWarehouseReceiptFinishedGood();

            PropertyCopier <GarmentLeftoverWarehouseReceiptFinishedGoodViewModel, GarmentLeftoverWarehouseReceiptFinishedGood> .Copy(viewModel, model);

            if (viewModel.UnitFrom != null)
            {
                model.UnitFromId   = long.Parse(viewModel.UnitFrom.Id);
                model.UnitFromCode = viewModel.UnitFrom.Code;
                model.UnitFromName = viewModel.UnitFrom.Name;
            }

            model.Items = new List <GarmentLeftoverWarehouseReceiptFinishedGoodItem>();
            foreach (var viewModelItem in viewModel.Items)
            {
                GarmentLeftoverWarehouseReceiptFinishedGoodItem modelItem = new GarmentLeftoverWarehouseReceiptFinishedGoodItem();
                PropertyCopier <GarmentLeftoverWarehouseReceiptFinishedGoodItemViewModel, GarmentLeftoverWarehouseReceiptFinishedGoodItem> .Copy(viewModelItem, modelItem);

                if (viewModelItem.Size != null)
                {
                    modelItem.SizeId   = viewModelItem.Size.Id;
                    modelItem.SizeName = viewModelItem.Size.Name;
                }

                if (viewModelItem.Uom != null)
                {
                    modelItem.UomId   = long.Parse(viewModelItem.Uom.Id);
                    modelItem.UomUnit = viewModelItem.Uom.Unit;
                }

                if (viewModelItem.LeftoverComodity != null)
                {
                    modelItem.LeftoverComodityCode = viewModelItem.LeftoverComodity.Code;
                    modelItem.LeftoverComodityId   = viewModelItem.LeftoverComodity.Id;
                    modelItem.LeftoverComodityName = viewModelItem.LeftoverComodity.Name;
                }

                if (viewModelItem.Buyer != null)
                {
                    modelItem.BuyerId   = viewModelItem.Buyer.Id;
                    modelItem.BuyerCode = viewModelItem.Buyer.Code;
                    modelItem.BuyerName = viewModelItem.Buyer.Name;
                }

                if (viewModelItem.Comodity != null)
                {
                    modelItem.ComodityId   = viewModelItem.Comodity.Id;
                    modelItem.ComodityCode = viewModelItem.Comodity.Code;
                    modelItem.ComodityName = viewModelItem.Comodity.Name;
                }

                model.Items.Add(modelItem);
            }

            return(model);
        }
        public void MapToModel()
        {
            GarmentLeftoverWarehouseReceiptFinishedGoodService service = new GarmentLeftoverWarehouseReceiptFinishedGoodService(_dbContext(GetCurrentMethod()), GetServiceProvider().Object);

            var data = new GarmentLeftoverWarehouseReceiptFinishedGoodViewModel
            {
                UnitFrom = new UnitViewModel
                {
                    Id   = "1",
                    Code = "Unit",
                    Name = "Unit"
                },
                ExpenditureDate = DateTimeOffset.Now,
                ReceiptDate     = DateTimeOffset.Now,
                Description     = "Remark",
                Carton          = 1,
                ContractNo      = "noContract",
                ExpenditureDesc = "desc",
                Invoice         = "inv",
                Items           = new List <GarmentLeftoverWarehouseReceiptFinishedGoodItemViewModel>
                {
                    new GarmentLeftoverWarehouseReceiptFinishedGoodItemViewModel
                    {
                        ExpenditureGoodItemId = Guid.NewGuid(),
                        Size = new SizeViewModel {
                            Id   = 1,
                            Name = "Size",
                            Code = "Code"
                        },
                        Remark   = "Remark",
                        Quantity = 1,
                        Uom      = new UomViewModel
                        {
                            Id   = "1",
                            Unit = "Uom"
                        },
                        LeftoverComodity = new LeftoverComodityViewModel
                        {
                            Id   = 1,
                            Name = "como",
                            Code = "como"
                        },
                        ExpenditureGoodId = Guid.NewGuid(),
                        ExpenditureGoodNo = "no",
                        Buyer             = new BuyerViewModel
                        {
                            Id   = 1,
                            Code = "Buyer",
                            Name = "Buyer"
                        },
                        Comodity = new ComodityViewModel
                        {
                            Id   = 1,
                            Code = "Comodity",
                            Name = "Comodity"
                        },
                        RONo    = "roNo",
                        Article = "art",
                    }
                }
            };

            var result = service.MapToModel(data);

            Assert.NotNull(result);
        }
Esempio n. 5
0
        public MemoryStream GeneratePdfTemplate(GarmentLeftoverWarehouseReceiptFinishedGoodViewModel 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 BARANG JADI 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.FinishedGoodReceiptNo, 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("", bold_font);
            tableHeader.AddCell(cellHeaderContentLeft);
            cellHeaderContentLeft.Phrase = new Phrase("", bold_font);
            tableHeader.AddCell(cellHeaderContentLeft);
            cellHeaderContentLeft.Phrase = new Phrase("", bold_font);
            tableHeader.AddCell(cellHeaderContentLeft);



            tableHeader.SpacingAfter = 15f;
            document.Add(tableHeader);

            #endregion

            #region BODY
            PdfPTable bodyTable = new PdfPTable(6);
            bodyTable.WidthPercentage = 100;
            bodyTable.SetWidths(new float[] { 1f, 3f, 3f, 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("DASAR TERIMA", bold_font);
            bodyTable.AddCell(bodyTableCellCenterBorder);
            bodyTableCellCenterBorder.Phrase = new Phrase("NO RO", bold_font);
            bodyTable.AddCell(bodyTableCellCenterBorder);
            bodyTableCellCenterBorder.Phrase = new Phrase("KOMODITI", 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);

            //Dictionary<string, ro> sameRO = new Dictionary<string, ro>();
            //int count = 1;
            //foreach(var item in viewModel.Items)
            //{
            //    if (sameRO.Count == 0)
            //    {
            //        sameRO.Add(item.ExpenditureGoodNo,new ro
            //        {
            //            ExpenditureGoodNo= item.ExpenditureGoodNo,
            //            RONo=item.RONo,
            //            count=count
            //        });
            //    }
            //    else
            //    {
            //        if (sameRO.ContainsKey(item.ExpenditureGoodNo))
            //        {
            //            sameRO[item.ExpenditureGoodNo] = new ro
            //            {
            //                ExpenditureGoodNo = item.ExpenditureGoodNo,
            //                RONo = item.RONo,
            //                count =count++
            //            };
            //        }
            //        else
            //        {
            //            count = 1;
            //            sameRO.Add(item.ExpenditureGoodNo, new ro
            //            {
            //                ExpenditureGoodNo = item.ExpenditureGoodNo,
            //                RONo = item.RONo,
            //                count = count
            //            });
            //        }
            //    }
            //}

            int    index         = 0;
            double totalQuantity = 0;
            foreach (var detail in viewModel.Items)
            {
                index++;
                bodyTableCellLeftBorder.Phrase = new Phrase(index.ToString(), normal_font);
                bodyTable.AddCell(bodyTableCellLeftBorder);
                bodyTableCellLeftBorder.Phrase = new Phrase(detail.ExpenditureGoodNo, normal_font);
                //bodyTableCellLeftBorder.Rowspan = item.count;
                bodyTable.AddCell(bodyTableCellLeftBorder);
                bodyTableCellLeftBorder.Phrase = new Phrase(detail.RONo, normal_font);
                bodyTable.AddCell(bodyTableCellLeftBorder);
                bodyTableCellLeftBorder.Phrase = new Phrase(detail.LeftoverComodity.Name, normal_font);
                bodyTable.AddCell(bodyTableCellLeftBorder);
                bodyTableCellRightBorder.Phrase = new Phrase(detail.Quantity.ToString(), normal_font);
                bodyTable.AddCell(bodyTableCellRightBorder);
                bodyTableCellLeftBorder.Phrase = new Phrase("PCS", normal_font);
                bodyTable.AddCell(bodyTableCellLeftBorder);

                totalQuantity += detail.Quantity;
            }

            bodyTableCellRightBorder.Phrase  = new Phrase("TOTAL", bold_font);
            bodyTableCellRightBorder.Colspan = 4;
            bodyTable.AddCell(bodyTableCellRightBorder);
            bodyTableCellRightBorder.Phrase  = new Phrase(totalQuantity.ToString(), bold_font);
            bodyTableCellRightBorder.Colspan = 1;
            bodyTable.AddCell(bodyTableCellRightBorder);
            bodyTableCellLeftBorder.Phrase = new Phrase("PCS", bold_font);
            bodyTable.AddCell(bodyTableCellLeftBorder);

            bodyTable.SpacingAfter = 25f;
            document.Add(bodyTable);
            #endregion

            document.Close();
            byte[] byteInfo = stream.ToArray();
            stream.Write(byteInfo, 0, byteInfo.Length);
            stream.Position = 0;

            return(stream);
        }
Esempio n. 6
0
        public GarmentLeftoverWarehouseReceiptFinishedGoodViewModel MapToViewModel(GarmentLeftoverWarehouseReceiptFinishedGood model)
        {
            GarmentLeftoverWarehouseReceiptFinishedGoodViewModel viewModel = new GarmentLeftoverWarehouseReceiptFinishedGoodViewModel();

            PropertyCopier <GarmentLeftoverWarehouseReceiptFinishedGood, GarmentLeftoverWarehouseReceiptFinishedGoodViewModel> .Copy(model, viewModel);

            viewModel.UnitFrom = new UnitViewModel
            {
                Id   = model.UnitFromId.ToString(),
                Code = model.UnitFromCode,
                Name = model.UnitFromName
            };


            if (model.Items != null)
            {
                viewModel.Items = new List <GarmentLeftoverWarehouseReceiptFinishedGoodItemViewModel>();
                foreach (var modelItem in model.Items)
                {
                    GarmentLeftoverWarehouseReceiptFinishedGoodItemViewModel viewModelItem = new GarmentLeftoverWarehouseReceiptFinishedGoodItemViewModel();
                    PropertyCopier <GarmentLeftoverWarehouseReceiptFinishedGoodItem, GarmentLeftoverWarehouseReceiptFinishedGoodItemViewModel> .Copy(modelItem, viewModelItem);

                    viewModelItem.Size = new SizeViewModel
                    {
                        Id   = modelItem.SizeId,
                        Name = modelItem.SizeName
                    };

                    viewModelItem.Uom = new UomViewModel
                    {
                        Id   = modelItem.UomId.ToString(),
                        Unit = modelItem.UomUnit
                    };

                    viewModelItem.LeftoverComodity = new LeftoverComodityViewModel
                    {
                        Id   = modelItem.LeftoverComodityId,
                        Name = modelItem.LeftoverComodityName,
                        Code = modelItem.LeftoverComodityCode
                    };

                    viewModelItem.Buyer = new BuyerViewModel
                    {
                        Id   = modelItem.BuyerId,
                        Code = modelItem.BuyerCode,
                        Name = modelItem.BuyerName
                    };

                    viewModelItem.Comodity = new ComodityViewModel
                    {
                        Id   = modelItem.ComodityId,
                        Code = modelItem.ComodityCode,
                        Name = modelItem.ComodityName
                    };

                    viewModel.Items.Add(viewModelItem);
                }
            }

            return(viewModel);
        }