Esempio n. 1
0
        public void ValidateViewModel()
        {
            GarmentLeftoverWarehouseExpenditureFinishedGoodViewModel viewModel = new GarmentLeftoverWarehouseExpenditureFinishedGoodViewModel()
            {
                Buyer           = null,
                ExpenditureTo   = "JUAL LOKAL",
                ExpenditureDate = DateTimeOffset.MinValue,
                Items           = new List <GarmentLeftoverWarehouseExpenditureFinishedGoodItemViewModel>()
                {
                    new GarmentLeftoverWarehouseExpenditureFinishedGoodItemViewModel()
                }
            };
            var result = viewModel.Validate(null);

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

            GarmentLeftoverWarehouseExpenditureFinishedGoodViewModel viewModel1 = new GarmentLeftoverWarehouseExpenditureFinishedGoodViewModel()
            {
                Buyer            = null,
                ExpenditureTo    = "LAIN-LAIN",
                OtherDescription = "",
                ExpenditureDate  = DateTimeOffset.Now.AddDays(4),
                Items            = new List <GarmentLeftoverWarehouseExpenditureFinishedGoodItemViewModel>()
                {
                    new GarmentLeftoverWarehouseExpenditureFinishedGoodItemViewModel()
                    {
                        ExpenditureQuantity = 6,
                        StockQuantity       = 3
                    }
                }
            };
            var result1 = viewModel1.Validate(null);

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


            GarmentLeftoverWarehouseExpenditureFinishedGoodViewModel viewModel2 = new GarmentLeftoverWarehouseExpenditureFinishedGoodViewModel()
            {
                Buyer            = null,
                ExpenditureTo    = "LAIN-LAIN",
                OtherDescription = "",
                ExpenditureDate  = DateTimeOffset.Now.AddDays(4)
            };
            var result2 = viewModel2.Validate(null);

            Assert.True(result2.Count() > 0);
        }
Esempio n. 2
0
        public void MapToModel()
        {
            GarmentLeftoverWarehouseExpenditureFinishedGoodService service = new GarmentLeftoverWarehouseExpenditureFinishedGoodService(_dbContext(GetCurrentMethod()), GetServiceProvider().Object);

            var data = new GarmentLeftoverWarehouseExpenditureFinishedGoodViewModel
            {
                Buyer = new BuyerViewModel
                {
                    Id   = 1,
                    Code = "Buyer",
                    Name = "Buyer"
                },
                ExpenditureDate  = DateTimeOffset.Now,
                ExpenditureTo    = "JUAL LOKAL",
                Description      = "Remark",
                LocalSalesNoteNo = "LocalSalesNoteNo",
                OtherDescription = "sadd",
                Items            = new List <GarmentLeftoverWarehouseExpenditureFinishedGoodItemViewModel>
                {
                    new GarmentLeftoverWarehouseExpenditureFinishedGoodItemViewModel
                    {
                        RONo = "roNo",
                        Unit = new UnitViewModel
                        {
                            Id   = "1",
                            Code = "Unit",
                            Name = "Unit"
                        },
                        ExpenditureQuantity = 1,
                        StockQuantity       = 2,
                        LeftoverComodity    = new LeftoverComodityViewModel
                        {
                            Id   = 1,
                            Code = "code",
                            Name = "name"
                        }
                    }
                }
            };

            var result = service.MapToModel(data);

            Assert.NotNull(result);
        }
        public GarmentLeftoverWarehouseExpenditureFinishedGoodViewModel MapToViewModel(GarmentLeftoverWarehouseExpenditureFinishedGood model)
        {
            GarmentLeftoverWarehouseExpenditureFinishedGoodViewModel viewModel = new GarmentLeftoverWarehouseExpenditureFinishedGoodViewModel();

            PropertyCopier <GarmentLeftoverWarehouseExpenditureFinishedGood, GarmentLeftoverWarehouseExpenditureFinishedGoodViewModel> .Copy(model, viewModel);

            viewModel.Buyer = new BuyerViewModel
            {
                Id   = model.BuyerId,
                Code = model.BuyerCode,
                Name = model.BuyerName
            };

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


                    viewModelItem.Unit = new UnitViewModel
                    {
                        Id   = modelItem.UnitId.ToString(),
                        Code = modelItem.UnitCode,
                        Name = modelItem.UnitName
                    };

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

                    viewModel.Items.Add(viewModelItem);
                }
            }

            return(viewModel);
        }
        public GarmentLeftoverWarehouseExpenditureFinishedGood MapToModel(GarmentLeftoverWarehouseExpenditureFinishedGoodViewModel viewModel)
        {
            GarmentLeftoverWarehouseExpenditureFinishedGood model = new GarmentLeftoverWarehouseExpenditureFinishedGood();

            PropertyCopier <GarmentLeftoverWarehouseExpenditureFinishedGoodViewModel, GarmentLeftoverWarehouseExpenditureFinishedGood> .Copy(viewModel, model);

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


            model.Items = new List <GarmentLeftoverWarehouseExpenditureFinishedGoodItem>();
            foreach (var viewModelItem in viewModel.Items)
            {
                GarmentLeftoverWarehouseExpenditureFinishedGoodItem modelItem = new GarmentLeftoverWarehouseExpenditureFinishedGoodItem();
                PropertyCopier <GarmentLeftoverWarehouseExpenditureFinishedGoodItemViewModel, GarmentLeftoverWarehouseExpenditureFinishedGoodItem> .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.LeftoverComodity != null)
                {
                    modelItem.LeftoverComodityCode = viewModelItem.LeftoverComodity.Code;
                    modelItem.LeftoverComodityId   = viewModelItem.LeftoverComodity.Id;
                    modelItem.LeftoverComodityName = viewModelItem.LeftoverComodity.Name;
                }

                model.Items.Add(modelItem);
            }

            return(model);
        }
        public MemoryStream GeneratePdfTemplate(GarmentLeftoverWarehouseExpenditureFinishedGoodViewModel 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);
            string       signee   = viewModel.ExpenditureTo == "JUAL LOKAL" ? viewModel.Buyer.Name : "";

            writer.PageEvent = new GarmentLeftoverWarehouseExpenditureSignPDFTemplatePageEvent(signee);

            document.Open();
            #region TITLE
            Paragraph title = new Paragraph("BON KELUAR 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.FinishedGoodExpenditureNo, 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.ExpenditureTo, 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.ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("en-EN")), normal_font);
            tableHeader.AddCell(cellHeaderContentLeft);

            if (viewModel.ExpenditureTo == "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
            {
                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.OtherDescription, normal_font);
                tableHeader.AddCell(cellHeaderContentLeft);
            }

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

            #endregion

            #region BODY
            PdfPTable bodyTable = new PdfPTable(5);
            bodyTable.WidthPercentage = 100;
            bodyTable.SetWidths(new float[] { 1f, 3f, 5f, 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("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);

            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.RONo, normal_font);
                bodyTable.AddCell(bodyTableCellLeftBorder);
                bodyTableCellLeftBorder.Phrase = new Phrase(item.LeftoverComodity.Name, normal_font);
                bodyTable.AddCell(bodyTableCellLeftBorder);
                bodyTableCellRightBorder.Phrase = new Phrase(item.ExpenditureQuantity.ToString(), normal_font);
                bodyTable.AddCell(bodyTableCellRightBorder);
                bodyTableCellLeftBorder.Phrase = new Phrase("PCS", normal_font);
                bodyTable.AddCell(bodyTableCellLeftBorder);

                totalQuantity += item.ExpenditureQuantity;
            }

            bodyTableCellRightBorder.Phrase  = new Phrase("TOTAL", bold_font);
            bodyTableCellRightBorder.Colspan = 3;
            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 = 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.Description, 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);
        }