public async Task <int> Create(GarmentShippingLocalPriceCuttingNoteViewModel viewModel) { var model = MapToModel(viewModel); int Created = await _repository.InsertAsync(model); return(Created); }
private GarmentShippingLocalPriceCuttingNoteViewModel MapToViewModel(GarmentShippingLocalPriceCuttingNoteModel model) { GarmentShippingLocalPriceCuttingNoteViewModel viewModel = new GarmentShippingLocalPriceCuttingNoteViewModel { Active = model.Active, Id = model.Id, CreatedAgent = model.CreatedAgent, CreatedBy = model.CreatedBy, CreatedUtc = model.CreatedUtc, DeletedAgent = model.DeletedAgent, DeletedBy = model.DeletedBy, DeletedUtc = model.DeletedUtc, IsDeleted = model.IsDeleted, LastModifiedAgent = model.LastModifiedAgent, LastModifiedBy = model.LastModifiedBy, LastModifiedUtc = model.LastModifiedUtc, cuttingPriceNoteNo = model.CuttingPriceNoteNo, date = model.Date, buyer = new Buyer { Id = model.BuyerId, Code = model.BuyerCode, Name = model.BuyerName, }, useVat = model.UseVat, remark = model.Remark, items = (model.Items ?? new List <GarmentShippingLocalPriceCuttingNoteItemModel>()).Select(i => new GarmentShippingLocalPriceCuttingNoteItemViewModel { Active = i.Active, Id = i.Id, CreatedAgent = i.CreatedAgent, CreatedBy = i.CreatedBy, CreatedUtc = i.CreatedUtc, DeletedAgent = i.DeletedAgent, DeletedBy = i.DeletedBy, DeletedUtc = i.DeletedUtc, IsDeleted = i.IsDeleted, LastModifiedAgent = i.LastModifiedAgent, LastModifiedBy = i.LastModifiedBy, LastModifiedUtc = i.LastModifiedUtc, salesNoteId = i.SalesNoteId, salesNoteNo = i.SalesNoteNo, salesAmount = i.SalesAmount, cuttingAmount = i.CuttingAmount, includeVat = i.IncludeVat }).ToList() }; return(viewModel); }
private string GenerateNo(GarmentShippingLocalPriceCuttingNoteViewModel vm) { var year = DateTime.Now.ToString("yy"); var prefix = $"{year}/NPH/"; var lastInvoiceNo = _repository.ReadAll().Where(w => w.CuttingPriceNoteNo.StartsWith(prefix)) .OrderByDescending(o => o.CuttingPriceNoteNo) .Select(s => int.Parse(s.CuttingPriceNoteNo.Replace(prefix, ""))) .FirstOrDefault(); var invoiceNo = $"{prefix}{(lastInvoiceNo + 1).ToString("D5")}"; return(invoiceNo); }
private GarmentShippingLocalPriceCuttingNoteModel MapToModel(GarmentShippingLocalPriceCuttingNoteViewModel vm) { var items = (vm.items ?? new List <GarmentShippingLocalPriceCuttingNoteItemViewModel>()).Select(i => { return(new GarmentShippingLocalPriceCuttingNoteItemModel(i.salesNoteId, i.salesNoteNo, i.salesAmount, i.cuttingAmount, i.includeVat) { Id = i.Id }); }).ToList(); vm.buyer = vm.buyer ?? new Buyer(); return(new GarmentShippingLocalPriceCuttingNoteModel(GenerateNo(vm), vm.date.GetValueOrDefault(), vm.buyer.Id, vm.buyer.Code, vm.buyer.Name, vm.useVat, vm.remark, items) { Id = vm.Id }); }
public MemoryStream GeneratePdfTemplate(GarmentShippingLocalPriceCuttingNoteViewModel viewModel, Buyer buyer, int timeoffset) { const int MARGIN = 20; Font header_font_bold_big = FontFactory.GetFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 12); Font header_font_bold = FontFactory.GetFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 9); Font header_font_bold_underlined = FontFactory.GetFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 10, Font.UNDERLINE); Font header_font = FontFactory.GetFont(BaseFont.COURIER, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 11); Font normal_font = FontFactory.GetFont(BaseFont.COURIER, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Font normal_font_underlined = FontFactory.GetFont(BaseFont.COURIER, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8, Font.UNDERLINE); Font normal_font_bold = FontFactory.GetFont(BaseFont.COURIER_BOLD, BaseFont.CP1250, BaseFont.NOT_EMBEDDED, 8); Document document = new Document(PageSize.A5.Rotate(), MARGIN, MARGIN, MARGIN, MARGIN); MemoryStream stream = new MemoryStream(); PdfWriter writer = PdfWriter.GetInstance(document, stream); document.Open(); #region header PdfPTable tableHeader = new PdfPTable(2); tableHeader.WidthPercentage = 100; tableHeader.SetWidths(new float[] { 3f, 2f }); PdfPCell cellHeaderContent1 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellHeaderContent2 = new PdfPCell() { Border = Rectangle.NO_BORDER }; cellHeaderContent1.AddElement(new Phrase("\n", normal_font)); cellHeaderContent1.AddElement(new Phrase("PT. DAN LIRIS", header_font_bold)); cellHeaderContent1.AddElement(new Phrase("Jl. Merapi No. 23, Kel. Banaran Kec.Grogol Kab. Sukoharjo", normal_font)); cellHeaderContent1.AddElement(new Phrase("Telp : 0271-714400, Fax. 0271-717178", normal_font)); cellHeaderContent1.AddElement(new Phrase("PO. Box. 166 Solo-57100 Indonesia", normal_font)); tableHeader.AddCell(cellHeaderContent1); cellHeaderContent2.AddElement(new Phrase("Sukoharjo, " + viewModel.date.GetValueOrDefault().ToOffset(new TimeSpan(timeoffset, 0, 0)).ToString("dd MMMM yyyy", new System.Globalization.CultureInfo("id-ID")), normal_font)); cellHeaderContent2.AddElement(new Phrase("\n", normal_font)); cellHeaderContent2.AddElement(new Phrase(viewModel.buyer.Name, normal_font)); cellHeaderContent2.AddElement(new Phrase(buyer.Address, normal_font)); tableHeader.AddCell(cellHeaderContent2); document.Add(tableHeader); #endregion #region title Paragraph title = new Paragraph("NOTA POTONGAN", header_font_bold); title.Alignment = Element.ALIGN_CENTER; document.Add(title); Paragraph no = new Paragraph(viewModel.cuttingPriceNoteNo, header_font_bold); no.Alignment = Element.ALIGN_CENTER; document.Add(no); Paragraph location = new Paragraph("SUKOHARJO - JATENG", normal_font_underlined); location.Alignment = Element.ALIGN_RIGHT; document.Add(location); #endregion #region bodyTable PdfPTable tableBody = new PdfPTable(2); tableBody.WidthPercentage = 100; tableBody.SetWidths(new float[] { 5f, 2f }); PdfPCell cellBodyLeft = new PdfPCell() { Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellBodyLeftNoBorder = new PdfPCell() { Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_LEFT }; PdfPCell cellBodyRight = new PdfPCell() { Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellBodyRightNoBorder = new PdfPCell() { Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER, HorizontalAlignment = Element.ALIGN_RIGHT }; PdfPCell cellBodyCenter = new PdfPCell() { Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; cellBodyCenter.Phrase = new Phrase("Description", normal_font); tableBody.AddCell(cellBodyCenter); cellBodyCenter.Phrase = new Phrase("Jumlah", normal_font); cellBodyCenter.Colspan = 1; tableBody.AddCell(cellBodyCenter); double totalPrice = 0; foreach (var item in viewModel.items) { cellBodyLeft.Phrase = new Phrase(item.salesNoteNo, normal_font); tableBody.AddCell(cellBodyLeft); cellBodyRight.Phrase = new Phrase(string.Format("{0:n2}", item.cuttingAmount), normal_font); tableBody.AddCell(cellBodyRight); totalPrice += item.includeVat ? item.cuttingAmount * 100 / 110 : item.cuttingAmount; } double ppn = 0; if (viewModel.useVat) { ppn = totalPrice * 0.1; } double finalPrice = totalPrice + ppn; cellBodyRight.Phrase = new Phrase("Dasar Pengenaan Pajak...............Rp.", normal_font); cellBodyRight.Border = Rectangle.NO_BORDER; tableBody.AddCell(cellBodyRight); cellBodyRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", totalPrice), normal_font); cellBodyRightNoBorder.Border = Rectangle.NO_BORDER; tableBody.AddCell(cellBodyRightNoBorder); cellBodyRight.Phrase = new Phrase("PPN = 10% X Dasar Pengenaan Pajak...Rp.", normal_font); tableBody.AddCell(cellBodyRight); cellBodyRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", ppn), normal_font); cellBodyRightNoBorder.Border = Rectangle.BOTTOM_BORDER; tableBody.AddCell(cellBodyRightNoBorder); cellBodyRight.Phrase = new Phrase("Jumlah..............................Rp.", normal_font); tableBody.AddCell(cellBodyRight); cellBodyRightNoBorder.Phrase = new Phrase(string.Format("{0:n2}", finalPrice), normal_font); cellBodyRightNoBorder.Border = Rectangle.NO_BORDER; tableBody.AddCell(cellBodyRightNoBorder); tableBody.SpacingAfter = 10; tableBody.SpacingBefore = 5; document.Add(tableBody); #endregion #region footer PdfPTable tableFooter = new PdfPTable(2); tableFooter.WidthPercentage = 100; tableFooter.SetWidths(new float[] { 1.5f, 9f }); PdfPCell cellFooterContent1 = new PdfPCell() { Border = Rectangle.NO_BORDER }; PdfPCell cellFooterContent2 = new PdfPCell() { Border = Rectangle.NO_BORDER }; string terbilang = NumberToTextIDN.terbilang(Math.Round(finalPrice, 2)); cellFooterContent1.Phrase = (new Phrase("Terbilang :", normal_font)); tableFooter.AddCell(cellFooterContent1); cellFooterContent2.Phrase = (new Phrase(terbilang + " rupiah", normal_font)); tableFooter.AddCell(cellFooterContent2); cellFooterContent1.Phrase = (new Phrase("Catatan :", normal_font)); tableFooter.AddCell(cellFooterContent1); cellFooterContent2.Phrase = (new Phrase(viewModel.remark, normal_font)); tableFooter.AddCell(cellFooterContent2); tableFooter.SpacingAfter = 10; document.Add(tableFooter); #endregion #region sign PdfPTable tableSign = new PdfPTable(5); tableSign.WidthPercentage = 80; tableSign.SetWidths(new float[] { 1f, 1f, 1f, 1f, 1f }); PdfPCell cellBodySign = new PdfPCell() { Border = Rectangle.BOTTOM_BORDER | Rectangle.TOP_BORDER | Rectangle.LEFT_BORDER | Rectangle.RIGHT_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; PdfPCell cellBodySignNoBorder = new PdfPCell() { Border = Rectangle.NO_BORDER, HorizontalAlignment = Element.ALIGN_CENTER }; cellBodySign.Phrase = new Phrase("Diterima Oleh", normal_font); tableSign.AddCell(cellBodySign); cellBodySignNoBorder.Phrase = new Phrase("", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySign.Phrase = new Phrase("Dibuat Oleh", normal_font); tableSign.AddCell(cellBodySign); cellBodySign.Phrase = new Phrase("Diperiksa Oleh", normal_font); tableSign.AddCell(cellBodySign); cellBodySign.Phrase = new Phrase("Disetujui Oleh", normal_font); tableSign.AddCell(cellBodySign); cellBodySign.Phrase = new Phrase("\n\n\n", normal_font); tableSign.AddCell(cellBodySign); cellBodySignNoBorder.Phrase = new Phrase("\n\n\n", normal_font); tableSign.AddCell(cellBodySignNoBorder); cellBodySign.Phrase = new Phrase("\n\n\n", normal_font); tableSign.AddCell(cellBodySign); cellBodySign.Phrase = new Phrase("\n\n\n", normal_font); tableSign.AddCell(cellBodySign); cellBodySign.Phrase = new Phrase("\n\n\n", normal_font); tableSign.AddCell(cellBodySign); document.Add(tableSign); #endregion document.Close(); byte[] byteInfo = stream.ToArray(); stream.Write(byteInfo, 0, byteInfo.Length); stream.Position = 0; return(stream); }